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 : 303 : 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 : if (rte_intr_enable(intr_handle) != 0) {
2583 [ # # ]: 0 : if (rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2584 : : i40e_dev_alarm_handler, dev) != 0)
2585 : 0 : PMD_DRV_LOG(WARNING, "Failed to set alarm");
2586 : : else
2587 : 0 : pf->use_aq_polling = true;
2588 : : }
2589 : : }
2590 : :
2591 : 0 : i40e_filter_restore(pf);
2592 : :
2593 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2594 : 0 : PMD_DRV_LOG(WARNING,
2595 : : "please call hierarchy_commit() "
2596 : : "before starting the port");
2597 : :
2598 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2599 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2600 : : I40E_FRAME_SIZE_MAX;
2601 : 0 : ad->max_pkt_len = max_frame_size;
2602 : :
2603 : : /* Set the max frame size to HW*/
2604 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2605 : :
2606 : 0 : return I40E_SUCCESS;
2607 : :
2608 : 0 : tx_err:
2609 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2610 : 0 : i40e_dev_tx_queue_stop(dev, i);
2611 : 0 : rx_err:
2612 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2613 : 0 : i40e_dev_rx_queue_stop(dev, i);
2614 : :
2615 : : return ret;
2616 : : }
2617 : :
2618 : : static int
2619 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2620 : : {
2621 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2622 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2623 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2624 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2625 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2626 : : int i;
2627 : :
2628 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2629 : : return 0;
2630 : :
2631 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2632 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2633 : 0 : rte_intr_enable(intr_handle);
2634 [ # # ]: 0 : } else if (pf->use_aq_polling) {
2635 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2636 : 0 : pf->use_aq_polling = false;
2637 : : }
2638 : :
2639 : : /* Disable all queues */
2640 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2641 : 0 : i40e_dev_tx_queue_stop(dev, i);
2642 : :
2643 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2644 : 0 : i40e_dev_rx_queue_stop(dev, i);
2645 : :
2646 : : /* un-map queues with interrupt registers */
2647 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2648 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2649 : :
2650 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2651 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2652 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2653 : : }
2654 : :
2655 : : /* Clear all queues and release memory */
2656 : 0 : i40e_dev_clear_queues(dev);
2657 : :
2658 : : /* Set link down */
2659 : : i40e_dev_set_link_down(dev);
2660 : :
2661 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2662 : : /* resume to the default handler */
2663 : 0 : rte_intr_callback_register(intr_handle,
2664 : : i40e_dev_interrupt_handler,
2665 : : (void *)dev);
2666 : :
2667 : : /* Clean datapath event and queue/vec mapping */
2668 : 0 : rte_intr_efd_disable(intr_handle);
2669 : :
2670 : : /* Cleanup vector list */
2671 : 0 : rte_intr_vec_list_free(intr_handle);
2672 : :
2673 : : /* reset hierarchy commit */
2674 : 0 : pf->tm_conf.committed = false;
2675 : :
2676 : 0 : hw->adapter_stopped = 1;
2677 : 0 : dev->data->dev_started = 0;
2678 : :
2679 : 0 : pf->adapter->rss_reta_updated = 0;
2680 : :
2681 : 0 : return 0;
2682 : : }
2683 : :
2684 : : static int
2685 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2686 : : {
2687 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2688 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2689 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2690 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2691 : : struct i40e_filter_control_settings settings;
2692 : : struct rte_flow *p_flow;
2693 : : uint32_t reg;
2694 : : int i;
2695 : : int ret;
2696 : 0 : uint8_t aq_fail = 0;
2697 : : int retries = 0;
2698 : :
2699 : 0 : PMD_INIT_FUNC_TRACE();
2700 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2701 : : return 0;
2702 : :
2703 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2704 [ # # ]: 0 : if (ret)
2705 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2706 : :
2707 : :
2708 : 0 : ret = i40e_dev_stop(dev);
2709 : :
2710 : 0 : i40e_dev_free_queues(dev);
2711 : :
2712 : : /* Disable interrupt */
2713 : 0 : i40e_pf_disable_irq0(hw);
2714 : 0 : rte_intr_disable(intr_handle);
2715 : :
2716 : : /* shutdown and destroy the HMC */
2717 : 0 : i40e_shutdown_lan_hmc(hw);
2718 : :
2719 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2720 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2721 : 0 : pf->vmdq[i].vsi = NULL;
2722 : : }
2723 : 0 : rte_free(pf->vmdq);
2724 : 0 : pf->vmdq = NULL;
2725 : :
2726 : : /* release all the existing VSIs and VEBs */
2727 : 0 : i40e_vsi_release(pf->main_vsi);
2728 : :
2729 : : /* shutdown the adminq */
2730 : 0 : i40e_aq_queue_shutdown(hw, true);
2731 : 0 : i40e_shutdown_adminq(hw);
2732 : :
2733 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2734 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2735 : :
2736 : : /* Disable flexible payload in global configuration */
2737 [ # # ]: 0 : if (!pf->support_multi_driver)
2738 : 0 : i40e_flex_payload_reg_set_default(hw);
2739 : :
2740 : : /* force a PF reset to clean anything leftover */
2741 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2742 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2743 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2744 : 0 : I40E_WRITE_FLUSH(hw);
2745 : :
2746 : : /* Clear PXE mode */
2747 : 0 : i40e_clear_pxe_mode(hw);
2748 : :
2749 : : /* Unconfigure filter control */
2750 : : memset(&settings, 0, sizeof(settings));
2751 : 0 : ret = i40e_set_filter_control(hw, &settings);
2752 [ # # ]: 0 : if (ret)
2753 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2754 : : ret);
2755 : :
2756 : : /* Disable flow control */
2757 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2758 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2759 : :
2760 : : /* uninitialize pf host driver */
2761 : 0 : i40e_pf_host_uninit(dev);
2762 : :
2763 : : do {
2764 : 0 : ret = rte_intr_callback_unregister(intr_handle,
2765 : : i40e_dev_interrupt_handler, dev);
2766 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
2767 : : break;
2768 [ # # ]: 0 : } else if (ret != -EAGAIN) {
2769 : 0 : PMD_INIT_LOG(ERR,
2770 : : "intr callback unregister failed: %d",
2771 : : ret);
2772 : : }
2773 : 0 : i40e_msec_delay(500);
2774 [ # # ]: 0 : } while (retries++ < 5);
2775 : :
2776 : 0 : i40e_rm_ethtype_filter_list(pf);
2777 : 0 : i40e_rm_tunnel_filter_list(pf);
2778 : : i40e_rm_fdir_filter_list(pf);
2779 : :
2780 : : /* Remove all flows */
2781 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2782 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2783 : : /* Do not free FDIR flows since they are static allocated */
2784 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2785 : 0 : rte_free(p_flow);
2786 : : }
2787 : :
2788 : : /* release the fdir static allocated memory */
2789 : 0 : i40e_fdir_memory_cleanup(pf);
2790 : :
2791 : : /* Remove all Traffic Manager configuration */
2792 : 0 : i40e_tm_conf_uninit(dev);
2793 : :
2794 : : i40e_clear_automask(pf);
2795 : :
2796 : 0 : hw->adapter_closed = 1;
2797 : 0 : return ret;
2798 : : }
2799 : :
2800 : : /*
2801 : : * Reset PF device only to re-initialize resources in PMD layer
2802 : : */
2803 : : static int
2804 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2805 : : {
2806 : : int ret;
2807 : :
2808 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2809 : : * its VF to make them align with it. The detailed notification
2810 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2811 : : * To avoid unexpected behavior in VF, currently reset of PF with
2812 : : * SR-IOV activation is not supported. It might be supported later.
2813 : : */
2814 [ # # ]: 0 : if (dev->data->sriov.active)
2815 : : return -ENOTSUP;
2816 : :
2817 : 0 : ret = eth_i40e_dev_uninit(dev);
2818 [ # # ]: 0 : if (ret)
2819 : : return ret;
2820 : :
2821 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2822 : :
2823 : 0 : return ret;
2824 : : }
2825 : :
2826 : : static int
2827 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2828 : : {
2829 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2830 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2831 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2832 : : int status;
2833 : :
2834 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2835 : : true, NULL, true);
2836 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2837 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2838 : 0 : return -EAGAIN;
2839 : : }
2840 : :
2841 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2842 : : TRUE, NULL);
2843 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2844 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2845 : : /* Rollback unicast promiscuous mode */
2846 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2847 : : false, NULL, true);
2848 : 0 : return -EAGAIN;
2849 : : }
2850 : :
2851 : : return 0;
2852 : : }
2853 : :
2854 : : static int
2855 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2856 : : {
2857 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2858 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2859 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2860 : : int status;
2861 : :
2862 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2863 : : false, NULL, true);
2864 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2865 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2866 : 0 : return -EAGAIN;
2867 : : }
2868 : :
2869 : : /* must remain in all_multicast mode */
2870 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2871 : : return 0;
2872 : :
2873 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2874 : : false, NULL);
2875 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2876 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2877 : : /* Rollback unicast promiscuous mode */
2878 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2879 : : true, NULL, true);
2880 : 0 : return -EAGAIN;
2881 : : }
2882 : :
2883 : : return 0;
2884 : : }
2885 : :
2886 : : static int
2887 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2888 : : {
2889 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2890 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2891 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2892 : : int ret;
2893 : :
2894 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2895 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2896 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2897 : 0 : return -EAGAIN;
2898 : : }
2899 : :
2900 : : return 0;
2901 : : }
2902 : :
2903 : : static int
2904 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2905 : : {
2906 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2907 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2908 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2909 : : int ret;
2910 : :
2911 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2912 : : return 0; /* must remain in all_multicast mode */
2913 : :
2914 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2915 : 0 : vsi->seid, FALSE, NULL);
2916 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2917 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2918 : 0 : return -EAGAIN;
2919 : : }
2920 : :
2921 : : return 0;
2922 : : }
2923 : :
2924 : : /*
2925 : : * Set device link up.
2926 : : */
2927 : : static int
2928 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2929 : : {
2930 : : /* re-apply link speed setting */
2931 : 0 : return i40e_apply_link_speed(dev);
2932 : : }
2933 : :
2934 : : /*
2935 : : * Set device link down.
2936 : : */
2937 : : static int
2938 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2939 : : {
2940 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2941 : : uint8_t abilities = 0;
2942 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2943 : :
2944 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2945 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2946 : : }
2947 : :
2948 : : static __rte_always_inline void
2949 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2950 : : {
2951 : : /* Link status registers and values*/
2952 : : #define I40E_REG_LINK_UP 0x40000080
2953 : : #define I40E_PRTMAC_MACC 0x001E24E0
2954 : : #define I40E_REG_MACC_25GB 0x00020000
2955 : : #define I40E_REG_SPEED_MASK 0x38000000
2956 : : #define I40E_REG_SPEED_0 0x00000000
2957 : : #define I40E_REG_SPEED_1 0x08000000
2958 : : #define I40E_REG_SPEED_2 0x10000000
2959 : : #define I40E_REG_SPEED_3 0x18000000
2960 : : #define I40E_REG_SPEED_4 0x20000000
2961 : : uint32_t link_speed;
2962 : : uint32_t reg_val;
2963 : :
2964 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2965 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2966 : 0 : reg_val &= I40E_REG_LINK_UP;
2967 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2968 : :
2969 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2970 : : return;
2971 : :
2972 : : /* Parse the link status */
2973 [ # # # # : 0 : switch (link_speed) {
# # ]
2974 : 0 : case I40E_REG_SPEED_0:
2975 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2976 : 0 : break;
2977 : 0 : case I40E_REG_SPEED_1:
2978 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2979 : 0 : break;
2980 : 0 : case I40E_REG_SPEED_2:
2981 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2982 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2983 : : else
2984 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2985 : : break;
2986 : 0 : case I40E_REG_SPEED_3:
2987 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2988 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
2989 : : } else {
2990 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2991 : :
2992 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
2993 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2994 : : else
2995 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2996 : : }
2997 : : break;
2998 : 0 : case I40E_REG_SPEED_4:
2999 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
3000 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3001 : : else
3002 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3003 : : break;
3004 : 0 : default:
3005 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
3006 : 0 : break;
3007 : : }
3008 : : }
3009 : :
3010 : : static __rte_always_inline void
3011 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
3012 : : bool enable_lse, int wait_to_complete)
3013 : : {
3014 : : #define CHECK_INTERVAL 100 /* 100ms */
3015 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3016 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
3017 : : struct i40e_link_status link_status;
3018 : : int status;
3019 : :
3020 : : memset(&link_status, 0, sizeof(link_status));
3021 : :
3022 : : do {
3023 : : memset(&link_status, 0, sizeof(link_status));
3024 : :
3025 : : /* Get link status information from hardware */
3026 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
3027 : : &link_status, NULL);
3028 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
3029 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3030 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3031 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
3032 : 0 : return;
3033 : : }
3034 : :
3035 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
3036 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
3037 : : break;
3038 : :
3039 : : rte_delay_ms(CHECK_INTERVAL);
3040 [ # # ]: 0 : } while (--rep_cnt);
3041 : :
3042 : : /* Parse the link status */
3043 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
3044 : 0 : case I40E_LINK_SPEED_100MB:
3045 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
3046 : 0 : break;
3047 : 0 : case I40E_LINK_SPEED_1GB:
3048 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
3049 : 0 : break;
3050 : 0 : case I40E_LINK_SPEED_10GB:
3051 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3052 : 0 : break;
3053 : 0 : case I40E_LINK_SPEED_20GB:
3054 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3055 : 0 : break;
3056 : 0 : case I40E_LINK_SPEED_25GB:
3057 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3058 : 0 : break;
3059 : 0 : case I40E_LINK_SPEED_40GB:
3060 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3061 : 0 : break;
3062 : 0 : default:
3063 [ # # ]: 0 : if (link->link_status)
3064 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3065 : : else
3066 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3067 : : break;
3068 : : }
3069 : : }
3070 : :
3071 : : int
3072 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
3073 : : int wait_to_complete)
3074 : : {
3075 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3076 : : struct rte_eth_link link;
3077 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3078 : : int ret;
3079 : :
3080 : : memset(&link, 0, sizeof(link));
3081 : :
3082 : : /* i40e uses full duplex only */
3083 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3084 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3085 : : RTE_ETH_LINK_SPEED_FIXED);
3086 : :
3087 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
3088 : : update_link_reg(hw, &link);
3089 : : else
3090 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
3091 : :
3092 [ # # ]: 0 : if (hw->switch_dev)
3093 : 0 : rte_eth_linkstatus_get(hw->switch_dev, &link);
3094 : :
3095 : : ret = rte_eth_linkstatus_set(dev, &link);
3096 : 0 : i40e_notify_all_vfs_link_status(dev);
3097 : :
3098 : 0 : return ret;
3099 : : }
3100 : :
3101 : : static void
3102 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3103 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
3104 : : uint64_t *stat, uint64_t *prev_stat)
3105 : : {
3106 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3107 : : /* enlarge the limitation when statistics counters overflowed */
3108 [ # # ]: 0 : if (offset_loaded) {
3109 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3110 : 0 : *stat += RTE_BIT64(I40E_48_BIT_WIDTH);
3111 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3112 : : }
3113 : 0 : *prev_stat = *stat;
3114 : 0 : }
3115 : :
3116 : : /* Get all the statistics of a VSI */
3117 : : void
3118 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3119 : : {
3120 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3121 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3122 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3123 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3124 : :
3125 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3126 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3127 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3128 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3129 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3130 : 0 : &nes->rx_unicast);
3131 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3132 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3133 : 0 : &nes->rx_multicast);
3134 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3135 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3136 : 0 : &nes->rx_broadcast);
3137 : : /* exclude CRC bytes */
3138 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3139 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3140 : :
3141 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3142 : : &oes->rx_discards, &nes->rx_discards);
3143 : : /* GLV_REPC not supported */
3144 : : /* GLV_RMPC not supported */
3145 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3146 : : &oes->rx_unknown_protocol,
3147 : : &nes->rx_unknown_protocol);
3148 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3149 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3150 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3151 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3152 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3153 : 0 : &nes->tx_unicast);
3154 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3155 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3156 : 0 : &nes->tx_multicast);
3157 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3158 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3159 : 0 : &nes->tx_broadcast);
3160 : : /* GLV_TDPC not supported */
3161 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3162 : : &oes->tx_errors, &nes->tx_errors);
3163 : 0 : vsi->offset_loaded = true;
3164 : :
3165 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3166 : : vsi->vsi_id);
3167 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3168 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3169 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3170 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3171 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3172 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3173 : : nes->rx_unknown_protocol);
3174 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3175 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3176 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3177 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3178 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3179 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3180 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3181 : : vsi->vsi_id);
3182 : 0 : }
3183 : :
3184 : : static void
3185 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3186 : : {
3187 : : unsigned int i;
3188 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3189 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3190 : :
3191 : : /* Get rx/tx bytes of internal transfer packets */
3192 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3193 : 0 : I40E_GLV_GORCL(hw->port),
3194 : 0 : pf->offset_loaded,
3195 : 0 : &pf->internal_stats_offset.rx_bytes,
3196 : 0 : &pf->internal_stats.rx_bytes,
3197 : : &pf->internal_prev_rx_bytes);
3198 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3199 : 0 : I40E_GLV_GOTCL(hw->port),
3200 : 0 : pf->offset_loaded,
3201 : 0 : &pf->internal_stats_offset.tx_bytes,
3202 : 0 : &pf->internal_stats.tx_bytes,
3203 : : &pf->internal_prev_tx_bytes);
3204 : : /* Get total internal rx packet count */
3205 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3206 : 0 : I40E_GLV_UPRCL(hw->port),
3207 : 0 : pf->offset_loaded,
3208 : 0 : &pf->internal_stats_offset.rx_unicast,
3209 : 0 : &pf->internal_stats.rx_unicast);
3210 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3211 : 0 : I40E_GLV_MPRCL(hw->port),
3212 : 0 : pf->offset_loaded,
3213 : 0 : &pf->internal_stats_offset.rx_multicast,
3214 : 0 : &pf->internal_stats.rx_multicast);
3215 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3216 : 0 : I40E_GLV_BPRCL(hw->port),
3217 : 0 : pf->offset_loaded,
3218 : 0 : &pf->internal_stats_offset.rx_broadcast,
3219 : 0 : &pf->internal_stats.rx_broadcast);
3220 : : /* Get total internal tx packet count */
3221 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3222 : 0 : I40E_GLV_UPTCL(hw->port),
3223 : 0 : pf->offset_loaded,
3224 : 0 : &pf->internal_stats_offset.tx_unicast,
3225 : 0 : &pf->internal_stats.tx_unicast);
3226 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3227 : 0 : I40E_GLV_MPTCL(hw->port),
3228 : 0 : pf->offset_loaded,
3229 : 0 : &pf->internal_stats_offset.tx_multicast,
3230 : 0 : &pf->internal_stats.tx_multicast);
3231 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3232 : 0 : I40E_GLV_BPTCL(hw->port),
3233 : 0 : pf->offset_loaded,
3234 : 0 : &pf->internal_stats_offset.tx_broadcast,
3235 : 0 : &pf->internal_stats.tx_broadcast);
3236 : :
3237 : : /* exclude CRC size */
3238 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3239 : 0 : pf->internal_stats.rx_multicast +
3240 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3241 : :
3242 : : /* Get statistics of struct i40e_eth_stats */
3243 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3244 : 0 : I40E_GLPRT_GORCL(hw->port),
3245 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3246 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3247 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3248 : 0 : I40E_GLPRT_UPRCL(hw->port),
3249 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3250 : 0 : &ns->eth.rx_unicast);
3251 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3252 : 0 : I40E_GLPRT_MPRCL(hw->port),
3253 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3254 : 0 : &ns->eth.rx_multicast);
3255 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3256 : 0 : I40E_GLPRT_BPRCL(hw->port),
3257 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3258 : 0 : &ns->eth.rx_broadcast);
3259 : : /* Workaround: CRC size should not be included in byte statistics,
3260 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3261 : : * packet.
3262 : : */
3263 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3264 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3265 : :
3266 : : /* exclude internal rx bytes
3267 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3268 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3269 : : * value.
3270 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3271 : : */
3272 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3273 : 0 : ns->eth.rx_bytes = 0;
3274 : : else
3275 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3276 : :
3277 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3278 : 0 : ns->eth.rx_unicast = 0;
3279 : : else
3280 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3281 : :
3282 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3283 : 0 : ns->eth.rx_multicast = 0;
3284 : : else
3285 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3286 : :
3287 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3288 : 0 : ns->eth.rx_broadcast = 0;
3289 : : else
3290 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3291 : :
3292 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3293 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3294 : : &ns->eth.rx_discards);
3295 : : /* GLPRT_REPC not supported */
3296 : : /* GLPRT_RMPC not supported */
3297 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3298 : 0 : pf->offset_loaded,
3299 : : &os->eth.rx_unknown_protocol,
3300 : : &ns->eth.rx_unknown_protocol);
3301 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1H(hw->pf_id + I40E_MAX_VF),
3302 : 0 : I40E_GL_RXERR1L(hw->pf_id + I40E_MAX_VF),
3303 : 0 : pf->offset_loaded, &os->rx_err1,
3304 : 0 : &ns->rx_err1);
3305 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3306 : 0 : I40E_GLPRT_GOTCL(hw->port),
3307 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3308 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3309 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3310 : 0 : I40E_GLPRT_UPTCL(hw->port),
3311 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3312 : 0 : &ns->eth.tx_unicast);
3313 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3314 : 0 : I40E_GLPRT_MPTCL(hw->port),
3315 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3316 : 0 : &ns->eth.tx_multicast);
3317 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3318 : 0 : I40E_GLPRT_BPTCL(hw->port),
3319 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3320 : 0 : &ns->eth.tx_broadcast);
3321 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3322 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3323 : :
3324 : : /* exclude internal tx bytes
3325 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3326 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3327 : : * value.
3328 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3329 : : */
3330 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3331 : 0 : ns->eth.tx_bytes = 0;
3332 : : else
3333 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3334 : :
3335 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3336 : 0 : ns->eth.tx_unicast = 0;
3337 : : else
3338 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3339 : :
3340 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3341 : 0 : ns->eth.tx_multicast = 0;
3342 : : else
3343 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3344 : :
3345 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3346 : 0 : ns->eth.tx_broadcast = 0;
3347 : : else
3348 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3349 : :
3350 : : /* GLPRT_TEPC not supported */
3351 : :
3352 : : /* additional port specific stats */
3353 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3354 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3355 : : &ns->tx_dropped_link_down);
3356 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3357 : 0 : pf->offset_loaded, &os->crc_errors,
3358 : : &ns->crc_errors);
3359 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3360 : 0 : pf->offset_loaded, &os->illegal_bytes,
3361 : : &ns->illegal_bytes);
3362 : : /* GLPRT_ERRBC not supported */
3363 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3364 : 0 : pf->offset_loaded, &os->mac_local_faults,
3365 : : &ns->mac_local_faults);
3366 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3367 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3368 : : &ns->mac_remote_faults);
3369 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3370 : 0 : pf->offset_loaded, &os->rx_length_errors,
3371 : : &ns->rx_length_errors);
3372 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3373 : 0 : pf->offset_loaded, &os->link_xon_rx,
3374 : : &ns->link_xon_rx);
3375 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3376 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3377 : : &ns->link_xoff_rx);
3378 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3379 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3380 : 0 : pf->offset_loaded,
3381 : : &os->priority_xon_rx[i],
3382 : : &ns->priority_xon_rx[i]);
3383 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3384 : 0 : pf->offset_loaded,
3385 : : &os->priority_xoff_rx[i],
3386 : : &ns->priority_xoff_rx[i]);
3387 : : }
3388 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3389 : 0 : pf->offset_loaded, &os->link_xon_tx,
3390 : : &ns->link_xon_tx);
3391 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3392 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3393 : : &ns->link_xoff_tx);
3394 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3395 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3396 : 0 : pf->offset_loaded,
3397 : : &os->priority_xon_tx[i],
3398 : : &ns->priority_xon_tx[i]);
3399 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3400 : 0 : pf->offset_loaded,
3401 : : &os->priority_xoff_tx[i],
3402 : : &ns->priority_xoff_tx[i]);
3403 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3404 : 0 : pf->offset_loaded,
3405 : : &os->priority_xon_2_xoff[i],
3406 : : &ns->priority_xon_2_xoff[i]);
3407 : : }
3408 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3409 : 0 : I40E_GLPRT_PRC64L(hw->port),
3410 : 0 : pf->offset_loaded, &os->rx_size_64,
3411 : 0 : &ns->rx_size_64);
3412 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3413 : 0 : I40E_GLPRT_PRC127L(hw->port),
3414 : 0 : pf->offset_loaded, &os->rx_size_127,
3415 : 0 : &ns->rx_size_127);
3416 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3417 : 0 : I40E_GLPRT_PRC255L(hw->port),
3418 : 0 : pf->offset_loaded, &os->rx_size_255,
3419 : 0 : &ns->rx_size_255);
3420 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3421 : 0 : I40E_GLPRT_PRC511L(hw->port),
3422 : 0 : pf->offset_loaded, &os->rx_size_511,
3423 : 0 : &ns->rx_size_511);
3424 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3425 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3426 : 0 : pf->offset_loaded, &os->rx_size_1023,
3427 : 0 : &ns->rx_size_1023);
3428 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3429 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3430 : 0 : pf->offset_loaded, &os->rx_size_1522,
3431 : 0 : &ns->rx_size_1522);
3432 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3433 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3434 : 0 : pf->offset_loaded, &os->rx_size_big,
3435 : 0 : &ns->rx_size_big);
3436 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3437 : 0 : pf->offset_loaded, &os->rx_undersize,
3438 : : &ns->rx_undersize);
3439 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3440 : 0 : pf->offset_loaded, &os->rx_fragments,
3441 : : &ns->rx_fragments);
3442 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3443 : 0 : pf->offset_loaded, &os->rx_oversize,
3444 : : &ns->rx_oversize);
3445 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3446 : 0 : pf->offset_loaded, &os->rx_jabber,
3447 : : &ns->rx_jabber);
3448 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3449 : 0 : I40E_GLPRT_PTC64L(hw->port),
3450 : 0 : pf->offset_loaded, &os->tx_size_64,
3451 : 0 : &ns->tx_size_64);
3452 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3453 : 0 : I40E_GLPRT_PTC127L(hw->port),
3454 : 0 : pf->offset_loaded, &os->tx_size_127,
3455 : 0 : &ns->tx_size_127);
3456 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3457 : 0 : I40E_GLPRT_PTC255L(hw->port),
3458 : 0 : pf->offset_loaded, &os->tx_size_255,
3459 : 0 : &ns->tx_size_255);
3460 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3461 : 0 : I40E_GLPRT_PTC511L(hw->port),
3462 : 0 : pf->offset_loaded, &os->tx_size_511,
3463 : 0 : &ns->tx_size_511);
3464 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3465 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3466 : 0 : pf->offset_loaded, &os->tx_size_1023,
3467 : 0 : &ns->tx_size_1023);
3468 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3469 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3470 : 0 : pf->offset_loaded, &os->tx_size_1522,
3471 : 0 : &ns->tx_size_1522);
3472 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3473 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3474 : 0 : pf->offset_loaded, &os->tx_size_big,
3475 : 0 : &ns->tx_size_big);
3476 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3477 : 0 : pf->offset_loaded,
3478 : : &os->fd_sb_match, &ns->fd_sb_match);
3479 : : /* GLPRT_MSPDC not supported */
3480 : : /* GLPRT_XEC not supported */
3481 : :
3482 : 0 : pf->offset_loaded = true;
3483 : :
3484 [ # # ]: 0 : if (pf->main_vsi)
3485 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3486 : 0 : }
3487 : :
3488 : : /* Get all statistics of a port */
3489 : : static int
3490 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
3491 : : struct eth_queue_stats *qstats __rte_unused)
3492 : : {
3493 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3494 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3495 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3496 : : struct i40e_vsi *vsi;
3497 : : unsigned i;
3498 : :
3499 : : /* call read registers - updates values, now write them to struct */
3500 : 0 : i40e_read_stats_registers(pf, hw);
3501 : :
3502 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3503 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3504 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3505 : 0 : pf->main_vsi->eth_stats.rx_discards -
3506 : 0 : ns->rx_err1;
3507 : 0 : stats->opackets = ns->eth.tx_unicast +
3508 : 0 : ns->eth.tx_multicast +
3509 : 0 : ns->eth.tx_broadcast;
3510 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3511 : 0 : stats->obytes = ns->eth.tx_bytes;
3512 : 0 : stats->oerrors = ns->eth.tx_errors +
3513 : 0 : pf->main_vsi->eth_stats.tx_errors;
3514 : :
3515 : : /* Rx Errors */
3516 : 0 : stats->imissed = ns->eth.rx_discards +
3517 : : pf->main_vsi->eth_stats.rx_discards;
3518 : 0 : stats->ierrors = ns->crc_errors +
3519 : 0 : ns->rx_length_errors + ns->rx_undersize +
3520 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3521 : : ns->rx_err1;
3522 : :
3523 [ # # ]: 0 : if (pf->vfs) {
3524 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3525 : 0 : vsi = pf->vfs[i].vsi;
3526 : 0 : i40e_update_vsi_stats(vsi);
3527 : :
3528 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3529 : 0 : vsi->eth_stats.rx_multicast +
3530 : 0 : vsi->eth_stats.rx_broadcast -
3531 : 0 : vsi->eth_stats.rx_discards);
3532 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3533 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3534 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3535 : : }
3536 : : }
3537 : :
3538 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3539 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3540 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3541 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3542 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3543 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3544 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3545 : : ns->eth.rx_unknown_protocol);
3546 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3547 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3548 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3549 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3550 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3551 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3552 : :
3553 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3554 : : ns->tx_dropped_link_down);
3555 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3556 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3557 : : ns->illegal_bytes);
3558 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3559 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3560 : : ns->mac_local_faults);
3561 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3562 : : ns->mac_remote_faults);
3563 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3564 : : ns->rx_length_errors);
3565 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3566 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3567 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3568 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3569 : : i, ns->priority_xon_rx[i]);
3570 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3571 : : i, ns->priority_xoff_rx[i]);
3572 : : }
3573 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3574 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3575 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3576 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3577 : : i, ns->priority_xon_tx[i]);
3578 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3579 : : i, ns->priority_xoff_tx[i]);
3580 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3581 : : i, ns->priority_xon_2_xoff[i]);
3582 : : }
3583 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3584 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3585 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3586 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3587 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3588 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3589 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3590 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3591 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3592 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3593 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3594 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3595 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3596 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3597 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3598 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3599 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3600 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3601 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3602 : : ns->mac_short_packet_dropped);
3603 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3604 : : ns->checksum_error);
3605 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3606 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3607 : 0 : return 0;
3608 : : }
3609 : :
3610 : : /* Reset the statistics */
3611 : : static int
3612 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3613 : : {
3614 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3615 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3616 : :
3617 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3618 : 0 : pf->offset_loaded = false;
3619 [ # # ]: 0 : if (pf->main_vsi)
3620 : 0 : pf->main_vsi->offset_loaded = false;
3621 : :
3622 : : /* read the stats, reading current register values into offset */
3623 : 0 : i40e_read_stats_registers(pf, hw);
3624 : :
3625 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct i40e_mbuf_stats));
3626 : :
3627 : 0 : return 0;
3628 : : }
3629 : :
3630 : : static uint32_t
3631 : : i40e_xstats_calc_num(void)
3632 : : {
3633 : : return I40E_NB_ETH_XSTATS + I40E_NB_MBUF_XSTATS +
3634 : : I40E_NB_HW_PORT_XSTATS +
3635 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3636 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3637 : : }
3638 : :
3639 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3640 : : struct rte_eth_xstat_name *xstats_names,
3641 : : __rte_unused unsigned limit)
3642 : : {
3643 : : unsigned count = 0;
3644 : : unsigned i, prio;
3645 : :
3646 [ # # ]: 0 : if (xstats_names == NULL)
3647 : : return i40e_xstats_calc_num();
3648 : :
3649 : : /* Note: limit checked in rte_eth_xstats_names() */
3650 : :
3651 : : /* Get stats from i40e_eth_stats struct */
3652 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3653 : 0 : strlcpy(xstats_names[count].name,
3654 : : rte_i40e_stats_strings[i].name,
3655 : : sizeof(xstats_names[count].name));
3656 : 0 : count++;
3657 : : }
3658 : :
3659 : : /* Get stats from i40e_mbuf_stats struct */
3660 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3661 : 0 : strlcpy(xstats_names[count].name,
3662 : : i40e_mbuf_strings[i].name,
3663 : : sizeof(xstats_names[count].name));
3664 : 0 : count++;
3665 : : }
3666 : :
3667 : : /* Get individual stats from i40e_hw_port struct */
3668 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3669 : 0 : strlcpy(xstats_names[count].name,
3670 : : rte_i40e_hw_port_strings[i].name,
3671 : : sizeof(xstats_names[count].name));
3672 : 0 : count++;
3673 : : }
3674 : :
3675 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3676 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3677 : 0 : snprintf(xstats_names[count].name,
3678 : : sizeof(xstats_names[count].name),
3679 : : "rx_priority%u_%s", prio,
3680 : 0 : rte_i40e_rxq_prio_strings[i].name);
3681 : 0 : count++;
3682 : : }
3683 : : }
3684 : :
3685 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3686 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3687 : 0 : snprintf(xstats_names[count].name,
3688 : : sizeof(xstats_names[count].name),
3689 : : "tx_priority%u_%s", prio,
3690 : 0 : rte_i40e_txq_prio_strings[i].name);
3691 : 0 : count++;
3692 : : }
3693 : : }
3694 : 0 : return count;
3695 : : }
3696 : :
3697 : : static void
3698 : : i40e_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
3699 : : struct i40e_mbuf_stats *mbuf_stats)
3700 : : {
3701 : : uint16_t idx;
3702 : : struct ci_tx_queue *txq;
3703 : :
3704 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
3705 : 0 : txq = ethdev->data->tx_queues[idx];
3706 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
3707 : : }
3708 : : }
3709 : :
3710 : : static int
3711 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3712 : : unsigned n)
3713 : : {
3714 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3715 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3716 : : struct i40e_adapter *adapter =
3717 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3718 : : struct i40e_mbuf_stats mbuf_stats = {0};
3719 : : unsigned i, count, prio;
3720 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3721 : :
3722 : : count = i40e_xstats_calc_num();
3723 [ # # ]: 0 : if (n < count)
3724 : : return count;
3725 : :
3726 : 0 : i40e_read_stats_registers(pf, hw);
3727 : :
3728 [ # # ]: 0 : if (xstats == NULL)
3729 : : return 0;
3730 : :
3731 : : count = 0;
3732 : :
3733 [ # # ]: 0 : if (adapter->mbuf_check)
3734 : : i40e_dev_update_mbuf_stats(dev, &mbuf_stats);
3735 : :
3736 : : /* Get stats from i40e_eth_stats struct */
3737 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3738 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3739 : 0 : rte_i40e_stats_strings[i].offset);
3740 : 0 : xstats[count].id = count;
3741 : 0 : count++;
3742 : : }
3743 : :
3744 : : /* Get stats from i40e_mbuf_stats struct */
3745 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3746 : 0 : xstats[count].value = *(uint64_t *)((char *)&mbuf_stats +
3747 : : i40e_mbuf_strings[i].offset);
3748 : 0 : xstats[count].id = count;
3749 : 0 : count++;
3750 : : }
3751 : :
3752 : : /* Get individual stats from i40e_hw_port struct */
3753 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3754 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3755 : 0 : rte_i40e_hw_port_strings[i].offset);
3756 : 0 : xstats[count].id = count;
3757 : 0 : count++;
3758 : : }
3759 : :
3760 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3761 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3762 : 0 : xstats[count].value =
3763 : 0 : *(uint64_t *)(((char *)hw_stats) +
3764 : 0 : rte_i40e_rxq_prio_strings[i].offset +
3765 : 0 : (sizeof(uint64_t) * prio));
3766 : 0 : xstats[count].id = count;
3767 : 0 : count++;
3768 : : }
3769 : : }
3770 : :
3771 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3772 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3773 : 0 : xstats[count].value =
3774 : 0 : *(uint64_t *)(((char *)hw_stats) +
3775 : 0 : rte_i40e_txq_prio_strings[i].offset +
3776 : 0 : (sizeof(uint64_t) * prio));
3777 : 0 : xstats[count].id = count;
3778 : 0 : count++;
3779 : : }
3780 : : }
3781 : :
3782 : 0 : return count;
3783 : : }
3784 : :
3785 : : static int
3786 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3787 : : {
3788 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3789 : : u32 full_ver;
3790 : : u8 ver, patch;
3791 : : u16 build;
3792 : : int ret;
3793 : :
3794 : 0 : full_ver = hw->nvm.oem_ver;
3795 : 0 : ver = (u8)(full_ver >> 24);
3796 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3797 : : patch = (u8)(full_ver & 0xff);
3798 : :
3799 : 0 : ret = snprintf(fw_version, fw_size,
3800 : : "%d.%d%d 0x%08x %d.%d.%d",
3801 : : ((hw->nvm.version >> 12) & 0xf),
3802 : : ((hw->nvm.version >> 4) & 0xff),
3803 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3804 : : ver, build, patch);
3805 [ # # ]: 0 : if (ret < 0)
3806 : : return -EINVAL;
3807 : :
3808 : 0 : ret += 1; /* add the size of '\0' */
3809 [ # # ]: 0 : if (fw_size < (size_t)ret)
3810 : : return ret;
3811 : : else
3812 : 0 : return 0;
3813 : : }
3814 : :
3815 : : /*
3816 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3817 : : * the Rx data path does not hang if the FW LLDP is stopped.
3818 : : * return true if lldp need to stop
3819 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3820 : : */
3821 : : static bool
3822 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3823 : : {
3824 : : double nvm_ver;
3825 : 0 : char ver_str[64] = {0};
3826 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3827 : :
3828 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3829 : : nvm_ver = atof(ver_str);
3830 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3831 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3832 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3833 : : return true;
3834 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3835 : 0 : return true;
3836 : :
3837 : : return false;
3838 : : }
3839 : :
3840 : : static int
3841 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3842 : : {
3843 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3844 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3845 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3846 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3847 : :
3848 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3849 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3850 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3851 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3852 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3853 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3854 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3855 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3856 : 0 : dev_info->rx_queue_offload_capa = 0;
3857 : 0 : dev_info->rx_offload_capa =
3858 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3859 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3860 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3861 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3862 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3863 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3864 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3865 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3866 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3867 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3868 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3869 : :
3870 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3871 : 0 : dev_info->tx_offload_capa =
3872 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3873 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3874 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3875 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3876 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3877 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3878 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3879 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3880 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3881 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3882 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3883 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3884 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3885 : : dev_info->tx_queue_offload_capa;
3886 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
3887 : 0 : dev_info->tx_offload_capa |=
3888 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
3889 : : }
3890 : :
3891 : 0 : dev_info->dev_capa =
3892 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3893 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3894 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3895 : :
3896 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3897 : : sizeof(uint32_t);
3898 : 0 : dev_info->reta_size = pf->hash_lut_size;
3899 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3900 : :
3901 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3902 : : .rx_thresh = {
3903 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3904 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3905 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3906 : : },
3907 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3908 : : .rx_drop_en = 0,
3909 : : .offloads = 0,
3910 : : };
3911 : :
3912 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3913 : : .tx_thresh = {
3914 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3915 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3916 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3917 : : },
3918 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3919 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3920 : : .offloads = 0,
3921 : : };
3922 : :
3923 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3924 : : .nb_max = I40E_MAX_RING_DESC,
3925 : : .nb_min = I40E_MIN_RING_DESC,
3926 : : .nb_align = I40E_ALIGN_RING_DESC,
3927 : : };
3928 : :
3929 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3930 : : .nb_max = I40E_MAX_RING_DESC,
3931 : : .nb_min = I40E_MIN_RING_DESC,
3932 : : .nb_align = I40E_ALIGN_RING_DESC,
3933 : : .nb_seg_max = I40E_TX_MAX_SEG,
3934 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3935 : : };
3936 : :
3937 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3938 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3939 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3940 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3941 : : pf->max_nb_vmdq_vsi;
3942 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3943 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3944 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3945 : : }
3946 : :
3947 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3948 : : /* For XL710 */
3949 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3950 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3951 : 0 : dev_info->default_txportconf.nb_queues = 2;
3952 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3953 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3954 : : else
3955 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3956 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3957 : 0 : dev_info->default_txportconf.ring_size = 1024;
3958 : : else
3959 : 0 : dev_info->default_txportconf.ring_size = 512;
3960 : :
3961 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3962 : : /* For XXV710 */
3963 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3964 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3965 : 0 : dev_info->default_txportconf.nb_queues = 1;
3966 : 0 : dev_info->default_rxportconf.ring_size = 256;
3967 : 0 : dev_info->default_txportconf.ring_size = 256;
3968 : : } else {
3969 : : /* For X710 */
3970 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3971 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3972 : 0 : dev_info->default_txportconf.nb_queues = 1;
3973 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3974 : 0 : dev_info->default_rxportconf.ring_size = 512;
3975 : 0 : dev_info->default_txportconf.ring_size = 256;
3976 : : } else {
3977 : 0 : dev_info->default_rxportconf.ring_size = 256;
3978 : 0 : dev_info->default_txportconf.ring_size = 256;
3979 : : }
3980 : : }
3981 : 0 : dev_info->default_rxportconf.burst_size = 32;
3982 : 0 : dev_info->default_txportconf.burst_size = 32;
3983 : :
3984 : 0 : return 0;
3985 : : }
3986 : :
3987 : : static int
3988 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3989 : : {
3990 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3991 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3992 : 0 : PMD_INIT_FUNC_TRACE();
3993 : :
3994 [ # # ]: 0 : if (on)
3995 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
3996 : : else
3997 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
3998 : : }
3999 : :
4000 : : static int
4001 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
4002 : : enum rte_vlan_type vlan_type,
4003 : : uint16_t tpid, int qinq)
4004 : : {
4005 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4006 : 0 : uint64_t reg_r = 0;
4007 : : uint64_t reg_w = 0;
4008 : : uint16_t reg_id = 3;
4009 : : int ret;
4010 : :
4011 [ # # ]: 0 : if (qinq) {
4012 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4013 : : reg_id = 2;
4014 : : }
4015 : :
4016 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
4017 : : ®_r, NULL);
4018 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4019 : 0 : PMD_DRV_LOG(ERR,
4020 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
4021 : : reg_id);
4022 : 0 : return -EIO;
4023 : : }
4024 : 0 : PMD_DRV_LOG(DEBUG,
4025 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
4026 : : reg_id, reg_r);
4027 : :
4028 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
4029 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
4030 [ # # ]: 0 : if (reg_r == reg_w) {
4031 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
4032 : 0 : return 0;
4033 : : }
4034 : :
4035 : 0 : ret = i40e_aq_debug_write_global_register(hw,
4036 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
4037 : : reg_w, NULL);
4038 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4039 : 0 : PMD_DRV_LOG(ERR,
4040 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
4041 : : reg_id);
4042 : 0 : return -EIO;
4043 : : }
4044 : 0 : PMD_DRV_LOG(DEBUG,
4045 : : "Global register 0x%08x is changed with value 0x%08x",
4046 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
4047 : :
4048 : 0 : return 0;
4049 : : }
4050 : :
4051 : : static int
4052 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
4053 : : enum rte_vlan_type vlan_type,
4054 : : uint16_t tpid)
4055 : : {
4056 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4057 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4058 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
4059 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4060 : : u16 sw_flags = 0, valid_flags = 0;
4061 : : int ret = 0;
4062 : :
4063 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
4064 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
4065 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
4066 : 0 : PMD_DRV_LOG(ERR,
4067 : : "Unsupported vlan type.");
4068 : 0 : return -EINVAL;
4069 : : }
4070 : :
4071 [ # # ]: 0 : if (pf->support_multi_driver) {
4072 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
4073 : 0 : return -ENOTSUP;
4074 : : }
4075 : :
4076 : : /* 802.1ad frames ability is added in NVM API 1.7*/
4077 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
4078 [ # # ]: 0 : if (qinq) {
4079 [ # # ]: 0 : if (pf->fw8_3gt) {
4080 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4081 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4082 : : }
4083 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4084 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
4085 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
4086 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4087 : : } else {
4088 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4089 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4090 : : }
4091 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
4092 : : valid_flags, 0, NULL);
4093 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4094 : 0 : PMD_DRV_LOG(ERR,
4095 : : "Set switch config failed aq_err: %d",
4096 : : hw->aq.asq_last_status);
4097 : : ret = -EIO;
4098 : : }
4099 : : } else
4100 : : /* If NVM API < 1.7, keep the register setting */
4101 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
4102 : : tpid, qinq);
4103 : :
4104 : : return ret;
4105 : : }
4106 : :
4107 : : /* Configure outer vlan stripping on or off in QinQ mode */
4108 : : static int
4109 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
4110 : : {
4111 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4112 : : int ret = I40E_SUCCESS;
4113 : : uint32_t reg;
4114 : :
4115 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
4116 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
4117 : 0 : return -EINVAL;
4118 : : }
4119 : :
4120 : : /* Configure for outer VLAN RX stripping */
4121 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4122 : :
4123 [ # # ]: 0 : if (on)
4124 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
4125 : : else
4126 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4127 : :
4128 : 0 : ret = i40e_aq_debug_write_register(hw,
4129 : 0 : I40E_VSI_TSR(vsi->vsi_id),
4130 : : reg, NULL);
4131 [ # # ]: 0 : if (ret < 0) {
4132 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4133 : : vsi->vsi_id);
4134 : 0 : return I40E_ERR_CONFIG;
4135 : : }
4136 : :
4137 : : return ret;
4138 : : }
4139 : :
4140 : : static int
4141 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4142 : : {
4143 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4144 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4145 : : struct rte_eth_rxmode *rxmode;
4146 : : struct i40e_mac_filter *f;
4147 : : int i, num;
4148 : : void *temp;
4149 : : int ret;
4150 : :
4151 : : rxmode = &dev->data->dev_conf.rxmode;
4152 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4153 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4154 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
4155 : : else
4156 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
4157 : : }
4158 : :
4159 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4160 : : /* Enable or disable VLAN stripping */
4161 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4162 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4163 : : else
4164 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4165 : :
4166 : : /* When VLAN strip is enabled/disabled
4167 : : * after enabling outer VLAN stripping,
4168 : : * outer VLAN stripping gets disabled
4169 : : * as the register gets overridden by
4170 : : * VLAN's strip vsi param update.
4171 : : * Hence, re-enable outer VLAN stripping.
4172 : : */
4173 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4174 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4175 : : }
4176 : :
4177 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4178 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
4179 : : i = 0;
4180 : 0 : num = vsi->mac_num;
4181 : :
4182 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
4183 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
4184 : 0 : return I40E_ERR_NO_MEMORY;
4185 : : }
4186 : :
4187 : : /*
4188 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4189 : : * also change the default behavior to support this feature. To align with
4190 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4191 : : * outer VLAN processing. But it is forbidden for firmware to change the
4192 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4193 : : * switch table. Therefore, we need to clear the MAC table before setting
4194 : : * config, and then restore the MAC table after setting. This feature is
4195 : : * recommended to be used in firmware v8.6.
4196 : : */
4197 : : /* Remove all existing mac */
4198 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4199 : 0 : mac_filter[i] = f->mac_info;
4200 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4201 [ # # ]: 0 : if (ret)
4202 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4203 : 0 : i++;
4204 : : }
4205 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4206 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4207 : : /* Set global registers with default ethertype. */
4208 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4209 : : RTE_ETHER_TYPE_VLAN);
4210 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4211 : : RTE_ETHER_TYPE_VLAN);
4212 : : } else {
4213 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4214 : : }
4215 : : /* Restore all mac */
4216 [ # # ]: 0 : for (i = 0; i < num; i++) {
4217 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4218 [ # # ]: 0 : if (ret)
4219 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4220 : : }
4221 : : }
4222 : :
4223 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4224 : : /* Enable or disable outer VLAN stripping */
4225 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4226 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4227 : : else
4228 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4229 : : }
4230 : :
4231 : : return 0;
4232 : : }
4233 : :
4234 : : static void
4235 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4236 : : __rte_unused uint16_t queue,
4237 : : __rte_unused int on)
4238 : : {
4239 : 0 : PMD_INIT_FUNC_TRACE();
4240 : 0 : }
4241 : :
4242 : : static int
4243 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4244 : : {
4245 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4246 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4247 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4248 : : struct i40e_vsi_vlan_pvid_info info;
4249 : :
4250 : : memset(&info, 0, sizeof(info));
4251 : 0 : info.on = on;
4252 [ # # ]: 0 : if (info.on)
4253 : 0 : info.config.pvid = pvid;
4254 : : else {
4255 : 0 : info.config.reject.tagged =
4256 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4257 : 0 : info.config.reject.untagged =
4258 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4259 : : }
4260 : :
4261 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4262 : : }
4263 : :
4264 : : static int
4265 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4266 : : {
4267 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4268 : 0 : uint32_t mode = i40e_led_get(hw);
4269 : :
4270 [ # # ]: 0 : if (mode == 0)
4271 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4272 : :
4273 : 0 : return 0;
4274 : : }
4275 : :
4276 : : static int
4277 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4278 : : {
4279 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4280 : 0 : uint32_t mode = i40e_led_get(hw);
4281 : :
4282 [ # # ]: 0 : if (mode != 0)
4283 : 0 : i40e_led_set(hw, 0, false);
4284 : :
4285 : 0 : return 0;
4286 : : }
4287 : :
4288 : : static int
4289 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4290 : : {
4291 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4292 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4293 : :
4294 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4295 : :
4296 : : /* read out from register, in case they are modified by other port */
4297 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4298 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4299 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4300 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4301 : :
4302 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4303 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4304 : :
4305 : : /* Return current mode according to actual setting*/
4306 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4307 : 0 : case I40E_FC_FULL:
4308 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4309 : 0 : break;
4310 : 0 : case I40E_FC_TX_PAUSE:
4311 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4312 : 0 : break;
4313 : 0 : case I40E_FC_RX_PAUSE:
4314 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4315 : 0 : break;
4316 : 0 : case I40E_FC_NONE:
4317 : : default:
4318 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4319 : : };
4320 : :
4321 : 0 : return 0;
4322 : : }
4323 : :
4324 : : static int
4325 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4326 : : {
4327 : : uint32_t mflcn_reg, fctrl_reg, reg;
4328 : : uint32_t max_high_water;
4329 : : uint8_t i, aq_failure;
4330 : : int err;
4331 : : struct i40e_hw *hw;
4332 : : struct i40e_pf *pf;
4333 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4334 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4335 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4336 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4337 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4338 : : };
4339 : :
4340 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4341 : :
4342 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4343 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4344 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4345 : 0 : PMD_INIT_LOG(ERR,
4346 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4347 : : max_high_water);
4348 : 0 : return -EINVAL;
4349 : : }
4350 : :
4351 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4352 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4353 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4354 : :
4355 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4356 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4357 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4358 : :
4359 : 0 : PMD_INIT_FUNC_TRACE();
4360 : :
4361 : : /* All the link flow control related enable/disable register
4362 : : * configuration is handle by the F/W
4363 : : */
4364 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4365 [ # # ]: 0 : if (err < 0)
4366 : : return -ENOSYS;
4367 : :
4368 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4369 : : /* Configure flow control refresh threshold,
4370 : : * the value for stat_tx_pause_refresh_timer[8]
4371 : : * is used for global pause operation.
4372 : : */
4373 : :
4374 : 0 : I40E_WRITE_REG(hw,
4375 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4376 : : pf->fc_conf.pause_time);
4377 : :
4378 : : /* configure the timer value included in transmitted pause
4379 : : * frame,
4380 : : * the value for stat_tx_pause_quanta[8] is used for global
4381 : : * pause operation
4382 : : */
4383 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4384 : : pf->fc_conf.pause_time);
4385 : :
4386 : 0 : fctrl_reg = I40E_READ_REG(hw,
4387 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4388 : :
4389 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4390 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4391 : : else
4392 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4393 : :
4394 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4395 : : fctrl_reg);
4396 : : } else {
4397 : : /* Configure pause time (2 TCs per register) */
4398 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4399 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4400 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4401 : :
4402 : : /* Configure flow control refresh threshold value */
4403 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4404 : : pf->fc_conf.pause_time / 2);
4405 : :
4406 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4407 : :
4408 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4409 : : *depending on configuration
4410 : : */
4411 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4412 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4413 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4414 : : } else {
4415 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4416 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4417 : : }
4418 : :
4419 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4420 : : }
4421 : :
4422 [ # # ]: 0 : if (!pf->support_multi_driver) {
4423 : : /* config water marker both based on the packets and bytes */
4424 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4425 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4426 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4427 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4428 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4429 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4430 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4431 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4432 : : << I40E_KILOSHIFT);
4433 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4434 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4435 : : << I40E_KILOSHIFT);
4436 : : } else {
4437 : 0 : PMD_DRV_LOG(ERR,
4438 : : "Water marker configuration is not supported.");
4439 : : }
4440 : :
4441 : 0 : I40E_WRITE_FLUSH(hw);
4442 : :
4443 : 0 : return 0;
4444 : : }
4445 : :
4446 : : static int
4447 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4448 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4449 : : {
4450 : 0 : PMD_INIT_FUNC_TRACE();
4451 : :
4452 : 0 : return -ENOSYS;
4453 : : }
4454 : :
4455 : : /* Add a MAC address, and update filters */
4456 : : static int
4457 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4458 : : struct rte_ether_addr *mac_addr,
4459 : : __rte_unused uint32_t index,
4460 : : uint32_t pool)
4461 : : {
4462 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4463 : : struct i40e_mac_filter_info mac_filter;
4464 : : struct i40e_vsi *vsi;
4465 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4466 : : int ret;
4467 : :
4468 : : /* If VMDQ not enabled or configured, return */
4469 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4470 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4471 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4472 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4473 : : pool);
4474 : 0 : return -ENOTSUP;
4475 : : }
4476 : :
4477 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4478 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4479 : : pool, pf->nb_cfg_vmdq_vsi);
4480 : 0 : return -EINVAL;
4481 : : }
4482 : :
4483 : : memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4484 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4485 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4486 : : else
4487 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4488 : :
4489 [ # # ]: 0 : if (pool == 0)
4490 : 0 : vsi = pf->main_vsi;
4491 : : else
4492 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4493 : :
4494 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4495 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4496 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4497 : 0 : return -ENODEV;
4498 : : }
4499 : : return 0;
4500 : : }
4501 : :
4502 : : /* Remove a MAC address, and update filters */
4503 : : static void
4504 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4505 : : {
4506 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4507 : : struct i40e_vsi *vsi;
4508 : : struct rte_eth_dev_data *data = dev->data;
4509 : : struct rte_ether_addr *macaddr;
4510 : : int ret;
4511 : : uint32_t i;
4512 : : uint64_t pool_sel;
4513 : :
4514 : 0 : macaddr = &(data->mac_addrs[index]);
4515 : :
4516 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4517 : :
4518 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4519 [ # # ]: 0 : if (pool_sel & RTE_BIT64(i)) {
4520 [ # # ]: 0 : if (i == 0)
4521 : 0 : vsi = pf->main_vsi;
4522 : : else {
4523 : : /* No VMDQ pool enabled or configured */
4524 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ) ||
4525 [ # # ]: 0 : (i > pf->nb_cfg_vmdq_vsi)) {
4526 : 0 : PMD_DRV_LOG(ERR,
4527 : : "No VMDQ pool enabled/configured");
4528 : 0 : return;
4529 : : }
4530 : 0 : vsi = pf->vmdq[i - 1].vsi;
4531 : : }
4532 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4533 : :
4534 [ # # ]: 0 : if (ret) {
4535 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4536 : 0 : return;
4537 : : }
4538 : : }
4539 : : }
4540 : : }
4541 : :
4542 : : static int
4543 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4544 : : {
4545 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4546 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4547 : : uint32_t reg;
4548 : : int ret;
4549 : :
4550 [ # # ]: 0 : if (!lut)
4551 : : return -EINVAL;
4552 : :
4553 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4554 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4555 : 0 : vsi->type != I40E_VSI_SRIOV,
4556 : : lut, lut_size);
4557 [ # # ]: 0 : if (ret) {
4558 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4559 : 0 : return ret;
4560 : : }
4561 : : } else {
4562 : : uint32_t *lut_dw = (uint32_t *)lut;
4563 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4564 : :
4565 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4566 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4567 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4568 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4569 : : }
4570 : : } else {
4571 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4572 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4573 : : I40E_PFQF_HLUT(i));
4574 : : }
4575 : : }
4576 : :
4577 : : return 0;
4578 : : }
4579 : :
4580 : : int
4581 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4582 : : {
4583 : : struct i40e_pf *pf;
4584 : : struct i40e_hw *hw;
4585 : :
4586 [ # # ]: 0 : if (!vsi || !lut)
4587 : : return -EINVAL;
4588 : :
4589 : 0 : pf = I40E_VSI_TO_PF(vsi);
4590 : 0 : hw = I40E_VSI_TO_HW(vsi);
4591 : :
4592 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4593 : : enum i40e_status_code status;
4594 : :
4595 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4596 : 0 : vsi->type != I40E_VSI_SRIOV,
4597 : : lut, lut_size);
4598 [ # # ]: 0 : if (status) {
4599 : 0 : PMD_DRV_LOG(ERR,
4600 : : "Failed to update RSS lookup table, error status: %d",
4601 : : status);
4602 : 0 : return -EIO;
4603 : : }
4604 : : } else {
4605 : : uint32_t *lut_dw = (uint32_t *)lut;
4606 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4607 : :
4608 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4609 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4610 : 0 : I40E_WRITE_REG(
4611 : : hw,
4612 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4613 : : lut_dw[i]);
4614 : : } else {
4615 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4616 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4617 : : lut_dw[i]);
4618 : : }
4619 : 0 : I40E_WRITE_FLUSH(hw);
4620 : : }
4621 : :
4622 : : return 0;
4623 : : }
4624 : :
4625 : : static int
4626 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4627 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4628 : : uint16_t reta_size)
4629 : : {
4630 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4631 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4632 : : uint16_t idx, shift;
4633 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4634 : : int ret;
4635 : :
4636 : 0 : if (reta_size != lut_size ||
4637 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4638 : 0 : PMD_DRV_LOG(ERR,
4639 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4640 : : reta_size, lut_size);
4641 : 0 : return -EINVAL;
4642 : : }
4643 : :
4644 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4645 [ # # ]: 0 : if (ret)
4646 : : return ret;
4647 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4648 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4649 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4650 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4651 : 0 : lut[i] = reta_conf[idx].reta[shift];
4652 : : }
4653 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4654 : :
4655 : 0 : pf->adapter->rss_reta_updated = 1;
4656 : :
4657 : 0 : return ret;
4658 : : }
4659 : :
4660 : : static int
4661 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4662 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4663 : : uint16_t reta_size)
4664 : : {
4665 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4666 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4667 : : uint16_t idx, shift;
4668 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4669 : : int ret;
4670 : :
4671 : 0 : if (reta_size != lut_size ||
4672 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4673 : 0 : PMD_DRV_LOG(ERR,
4674 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4675 : : reta_size, lut_size);
4676 : 0 : return -EINVAL;
4677 : : }
4678 : :
4679 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4680 [ # # ]: 0 : if (ret)
4681 : : return ret;
4682 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4683 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4684 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4685 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4686 : 0 : reta_conf[idx].reta[shift] = lut[i];
4687 : : }
4688 : :
4689 : : return ret;
4690 : : }
4691 : :
4692 : : /**
4693 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4694 : : * @hw: pointer to the HW structure
4695 : : * @mem: pointer to mem struct to fill out
4696 : : * @size: size of memory requested
4697 : : * @alignment: what to align the allocation to
4698 : : **/
4699 : : enum i40e_status_code
4700 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4701 : : struct i40e_dma_mem *mem,
4702 : : __rte_unused enum i40e_memory_type mtype,
4703 : : u64 size,
4704 : : u32 alignment)
4705 : : {
4706 : : static RTE_ATOMIC(uint64_t) i40e_dma_memzone_id;
4707 : : const struct rte_memzone *mz = NULL;
4708 : : char z_name[RTE_MEMZONE_NAMESIZE];
4709 : :
4710 [ # # ]: 0 : if (!mem)
4711 : : return I40E_ERR_PARAM;
4712 : :
4713 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4714 : : rte_atomic_fetch_add_explicit(&i40e_dma_memzone_id, 1, rte_memory_order_relaxed));
4715 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4716 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4717 [ # # ]: 0 : if (!mz)
4718 : : return I40E_ERR_NO_MEMORY;
4719 : :
4720 : 0 : mem->size = size;
4721 : 0 : mem->va = mz->addr;
4722 : 0 : mem->pa = mz->iova;
4723 : 0 : mem->zone = (const void *)mz;
4724 : 0 : PMD_DRV_LOG(DEBUG,
4725 : : "memzone %s allocated with physical address: %"PRIu64,
4726 : : mz->name, mem->pa);
4727 : :
4728 : 0 : return I40E_SUCCESS;
4729 : : }
4730 : :
4731 : : /**
4732 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4733 : : * @hw: pointer to the HW structure
4734 : : * @mem: ptr to mem struct to free
4735 : : **/
4736 : : enum i40e_status_code
4737 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4738 : : struct i40e_dma_mem *mem)
4739 : : {
4740 [ # # ]: 0 : if (!mem)
4741 : : return I40E_ERR_PARAM;
4742 : :
4743 : 0 : PMD_DRV_LOG(DEBUG,
4744 : : "memzone %s to be freed with physical address: %"PRIu64,
4745 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4746 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4747 : 0 : mem->zone = NULL;
4748 : 0 : mem->va = NULL;
4749 : 0 : mem->pa = (u64)0;
4750 : :
4751 : 0 : return I40E_SUCCESS;
4752 : : }
4753 : :
4754 : : /**
4755 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4756 : : * @hw: pointer to the HW structure
4757 : : * @mem: pointer to mem struct to fill out
4758 : : * @size: size of memory requested
4759 : : **/
4760 : : enum i40e_status_code
4761 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4762 : : struct i40e_virt_mem *mem,
4763 : : u32 size)
4764 : : {
4765 [ # # ]: 0 : if (!mem)
4766 : : return I40E_ERR_PARAM;
4767 : :
4768 : 0 : mem->size = size;
4769 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4770 : :
4771 [ # # ]: 0 : if (mem->va)
4772 : : return I40E_SUCCESS;
4773 : : else
4774 : 0 : return I40E_ERR_NO_MEMORY;
4775 : : }
4776 : :
4777 : : /**
4778 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4779 : : * @hw: pointer to the HW structure
4780 : : * @mem: pointer to mem struct to free
4781 : : **/
4782 : : enum i40e_status_code
4783 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4784 : : struct i40e_virt_mem *mem)
4785 : : {
4786 [ # # ]: 0 : if (!mem)
4787 : : return I40E_ERR_PARAM;
4788 : :
4789 : 0 : rte_free(mem->va);
4790 : 0 : mem->va = NULL;
4791 : :
4792 : 0 : return I40E_SUCCESS;
4793 : : }
4794 : :
4795 : : /**
4796 : : * Get the hardware capabilities, which will be parsed
4797 : : * and saved into struct i40e_hw.
4798 : : */
4799 : : static int
4800 : 0 : i40e_get_cap(struct i40e_hw *hw)
4801 : : {
4802 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4803 : 0 : uint16_t len, size = 0;
4804 : : int ret;
4805 : :
4806 : : /* Calculate a huge enough buff for saving response data temporarily */
4807 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4808 : : I40E_MAX_CAP_ELE_NUM;
4809 : 0 : buf = rte_zmalloc("i40e", len, 0);
4810 [ # # ]: 0 : if (!buf) {
4811 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4812 : 0 : return I40E_ERR_NO_MEMORY;
4813 : : }
4814 : :
4815 : : /* Get, parse the capabilities and save it to hw */
4816 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4817 : : i40e_aqc_opc_list_func_capabilities, NULL);
4818 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4819 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4820 : :
4821 : : /* Free the temporary buffer after being used */
4822 : 0 : rte_free(buf);
4823 : :
4824 : 0 : return ret;
4825 : : }
4826 : :
4827 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4828 : :
4829 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4830 : : const char *value,
4831 : : void *opaque)
4832 : : {
4833 : : struct i40e_pf *pf;
4834 : : unsigned long num;
4835 : : char *end;
4836 : :
4837 : : pf = (struct i40e_pf *)opaque;
4838 : : RTE_SET_USED(key);
4839 : :
4840 : 0 : errno = 0;
4841 : 0 : num = strtoul(value, &end, 0);
4842 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4843 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4844 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4845 : 0 : return -(EINVAL);
4846 : : }
4847 : :
4848 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4849 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4850 : : else
4851 : : /* here return 0 to make next valid same argument work */
4852 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4853 : : "power of 2 and equal or less than 16 !, Now it is "
4854 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4855 : :
4856 : : return 0;
4857 : : }
4858 : :
4859 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4860 : : {
4861 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4862 : : struct rte_kvargs *kvlist;
4863 : : int kvargs_count;
4864 : :
4865 : : /* set default queue number per VF as 4 */
4866 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4867 : :
4868 [ # # ]: 0 : if (dev->device->devargs == NULL)
4869 : : return 0;
4870 : :
4871 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4872 [ # # ]: 0 : if (kvlist == NULL)
4873 : : return -(EINVAL);
4874 : :
4875 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4876 [ # # ]: 0 : if (!kvargs_count) {
4877 : 0 : rte_kvargs_free(kvlist);
4878 : 0 : return 0;
4879 : : }
4880 : :
4881 [ # # ]: 0 : if (kvargs_count > 1)
4882 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4883 : : "the first invalid or last valid one is used !",
4884 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4885 : :
4886 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4887 : : i40e_pf_parse_vf_queue_number_handler, pf);
4888 : :
4889 : 0 : rte_kvargs_free(kvlist);
4890 : :
4891 : 0 : return 0;
4892 : : }
4893 : :
4894 : : static int
4895 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4896 : : {
4897 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4898 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4899 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
4900 : : uint16_t qp_count = 0, vsi_count = 0;
4901 : :
4902 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4903 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4904 : 0 : return -EINVAL;
4905 : : }
4906 : :
4907 : 0 : i40e_pf_config_vf_rxq_number(dev);
4908 : :
4909 : : /* Add the parameter init for LFC */
4910 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4911 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4912 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4913 : :
4914 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4915 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4916 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4917 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4918 : :
4919 : : /* FDir queue/VSI allocation */
4920 : 0 : pf->fdir_qp_offset = 0;
4921 [ # # ]: 0 : if (hw->func_caps.fd) {
4922 : 0 : pf->flags |= I40E_FLAG_FDIR;
4923 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4924 : : } else {
4925 : 0 : pf->fdir_nb_qps = 0;
4926 : : }
4927 : 0 : qp_count += pf->fdir_nb_qps;
4928 : : vsi_count += 1;
4929 : :
4930 : : /* LAN queue/VSI allocation */
4931 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4932 [ # # ]: 0 : if (!hw->func_caps.rss) {
4933 : 0 : pf->lan_nb_qps = 1;
4934 : : } else {
4935 : 0 : pf->flags |= I40E_FLAG_RSS;
4936 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4937 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4938 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4939 : : }
4940 : 0 : qp_count += pf->lan_nb_qps;
4941 : : vsi_count += 1;
4942 : :
4943 : : /* VF queue/VSI allocation */
4944 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4945 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4946 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4947 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4948 : 0 : pf->vf_num = pci_dev->max_vfs;
4949 : 0 : PMD_DRV_LOG(DEBUG,
4950 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4951 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4952 : : } else {
4953 : 0 : pf->vf_nb_qps = 0;
4954 : 0 : pf->vf_num = 0;
4955 : : }
4956 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4957 : 0 : vsi_count += pf->vf_num;
4958 : :
4959 : : /* VMDq queue/VSI allocation */
4960 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4961 : 0 : pf->vmdq_nb_qps = 0;
4962 : 0 : pf->max_nb_vmdq_vsi = 0;
4963 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4964 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4965 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4966 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4967 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4968 : :
4969 : : /* Limit the maximum number of VMDq vsi to the maximum
4970 : : * ethdev can support
4971 : : */
4972 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4973 : : hw->func_caps.num_vsis - vsi_count);
4974 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4975 : : RTE_ETH_64_POOLS);
4976 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4977 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4978 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4979 : 0 : PMD_DRV_LOG(DEBUG,
4980 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4981 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4982 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4983 : : } else {
4984 : 0 : PMD_DRV_LOG(INFO,
4985 : : "No enough queues left for VMDq");
4986 : : }
4987 : : } else {
4988 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4989 : : }
4990 : : }
4991 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4992 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
4993 : :
4994 [ # # ]: 0 : if (hw->func_caps.dcb)
4995 : 0 : pf->flags |= I40E_FLAG_DCB;
4996 : :
4997 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
4998 : 0 : PMD_DRV_LOG(ERR,
4999 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
5000 : : qp_count, hw->func_caps.num_tx_qp);
5001 : 0 : return -EINVAL;
5002 : : }
5003 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
5004 : 0 : PMD_DRV_LOG(ERR,
5005 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
5006 : : vsi_count, hw->func_caps.num_vsis);
5007 : 0 : return -EINVAL;
5008 : : }
5009 : :
5010 : : /**
5011 : : * Enable outer VLAN processing if firmware version is greater
5012 : : * than v8.3
5013 : : */
5014 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
5015 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
5016 : 0 : pf->fw8_3gt = true;
5017 : : } else {
5018 : 0 : pf->fw8_3gt = false;
5019 : : }
5020 : :
5021 : : return 0;
5022 : : }
5023 : :
5024 : : static int
5025 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
5026 : : {
5027 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5028 : : struct i40e_aqc_get_switch_config_resp *switch_config;
5029 : : struct i40e_aqc_switch_config_element_resp *element;
5030 : 0 : uint16_t start_seid = 0, num_reported;
5031 : : int ret;
5032 : :
5033 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
5034 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
5035 [ # # ]: 0 : if (!switch_config) {
5036 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
5037 : 0 : return -ENOMEM;
5038 : : }
5039 : :
5040 : : /* Get the switch configurations */
5041 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
5042 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
5043 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5044 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
5045 : 0 : goto fail;
5046 : : }
5047 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
5048 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
5049 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
5050 : 0 : goto fail;
5051 : : }
5052 : :
5053 : : /* Parse the switch configuration elements */
5054 : : element = &(switch_config->element[0]);
5055 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
5056 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
5057 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
5058 : : } else
5059 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
5060 : :
5061 : 0 : fail:
5062 : 0 : rte_free(switch_config);
5063 : :
5064 : 0 : return ret;
5065 : : }
5066 : :
5067 : : static int
5068 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
5069 : : uint32_t num)
5070 : : {
5071 : : struct pool_entry *entry;
5072 : :
5073 [ # # ]: 0 : if (pool == NULL || num == 0)
5074 : : return -EINVAL;
5075 : :
5076 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
5077 [ # # ]: 0 : if (entry == NULL) {
5078 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
5079 : 0 : return -ENOMEM;
5080 : : }
5081 : :
5082 : : /* queue heap initialize */
5083 : 0 : pool->num_free = num;
5084 : 0 : pool->num_alloc = 0;
5085 : 0 : pool->base = base;
5086 : 0 : LIST_INIT(&pool->alloc_list);
5087 : : LIST_INIT(&pool->free_list);
5088 : :
5089 : : /* Initialize element */
5090 : 0 : entry->base = 0;
5091 : 0 : entry->len = num;
5092 : :
5093 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
5094 : 0 : return 0;
5095 : : }
5096 : :
5097 : : static void
5098 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5099 : : {
5100 : : struct pool_entry *entry, *next_entry;
5101 : :
5102 [ # # ]: 0 : if (pool == NULL)
5103 : : return;
5104 : :
5105 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->alloc_list); entry; entry = next_entry) {
5106 : 0 : next_entry = LIST_NEXT(entry, next);
5107 [ # # ]: 0 : LIST_REMOVE(entry, next);
5108 : 0 : rte_free(entry);
5109 : : }
5110 : :
5111 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->free_list); entry; entry = next_entry) {
5112 : 0 : next_entry = LIST_NEXT(entry, next);
5113 [ # # ]: 0 : LIST_REMOVE(entry, next);
5114 : 0 : rte_free(entry);
5115 : : }
5116 : :
5117 : 0 : pool->num_free = 0;
5118 : 0 : pool->num_alloc = 0;
5119 : 0 : pool->base = 0;
5120 : 0 : LIST_INIT(&pool->alloc_list);
5121 : 0 : LIST_INIT(&pool->free_list);
5122 : : }
5123 : :
5124 : : static int
5125 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
5126 : : uint32_t base)
5127 : : {
5128 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5129 : : uint32_t pool_offset;
5130 : : uint16_t len;
5131 : : int insert;
5132 : :
5133 [ # # ]: 0 : if (pool == NULL) {
5134 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5135 : 0 : return -EINVAL;
5136 : : }
5137 : :
5138 : 0 : pool_offset = base - pool->base;
5139 : : /* Lookup in alloc list */
5140 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
5141 [ # # ]: 0 : if (entry->base == pool_offset) {
5142 : : valid_entry = entry;
5143 [ # # ]: 0 : LIST_REMOVE(entry, next);
5144 : 0 : break;
5145 : : }
5146 : : }
5147 : :
5148 : : /* Not find, return */
5149 [ # # ]: 0 : if (valid_entry == NULL) {
5150 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
5151 : 0 : return -EINVAL;
5152 : : }
5153 : :
5154 : : /**
5155 : : * Found it, move it to free list and try to merge.
5156 : : * In order to make merge easier, always sort it by qbase.
5157 : : * Find adjacent prev and last entries.
5158 : : */
5159 : : prev = next = NULL;
5160 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5161 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5162 : : next = entry;
5163 : : break;
5164 : : }
5165 : : prev = entry;
5166 : : }
5167 : :
5168 : : insert = 0;
5169 : 0 : len = valid_entry->len;
5170 : : /* Try to merge with next one*/
5171 [ # # ]: 0 : if (next != NULL) {
5172 : : /* Merge with next one */
5173 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5174 : 0 : next->base = valid_entry->base;
5175 : 0 : next->len += len;
5176 : 0 : rte_free(valid_entry);
5177 : : valid_entry = next;
5178 : : insert = 1;
5179 : : }
5180 : : }
5181 : :
5182 [ # # ]: 0 : if (prev != NULL) {
5183 : : /* Merge with previous one */
5184 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5185 : 0 : prev->len += len;
5186 : : /* If it merge with next one, remove next node */
5187 [ # # ]: 0 : if (insert == 1) {
5188 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5189 : 0 : rte_free(valid_entry);
5190 : : valid_entry = NULL;
5191 : : } else {
5192 : 0 : rte_free(valid_entry);
5193 : : valid_entry = NULL;
5194 : : insert = 1;
5195 : : }
5196 : : }
5197 : : }
5198 : :
5199 : : /* Not find any entry to merge, insert */
5200 [ # # ]: 0 : if (insert == 0) {
5201 [ # # ]: 0 : if (prev != NULL)
5202 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5203 [ # # ]: 0 : else if (next != NULL)
5204 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5205 : : else /* It's empty list, insert to head */
5206 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5207 : : }
5208 : :
5209 : 0 : pool->num_free += len;
5210 : 0 : pool->num_alloc -= len;
5211 : :
5212 : 0 : return 0;
5213 : : }
5214 : :
5215 : : static int
5216 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5217 : : uint16_t num)
5218 : : {
5219 : : struct pool_entry *entry, *valid_entry;
5220 : :
5221 [ # # ]: 0 : if (pool == NULL || num == 0) {
5222 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5223 : 0 : return -EINVAL;
5224 : : }
5225 : :
5226 [ # # ]: 0 : if (pool->num_free < num) {
5227 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5228 : : num, pool->num_free);
5229 : 0 : return -ENOMEM;
5230 : : }
5231 : :
5232 : : valid_entry = NULL;
5233 : : /* Lookup in free list and find most fit one */
5234 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5235 [ # # ]: 0 : if (entry->len >= num) {
5236 : : /* Find best one */
5237 [ # # ]: 0 : if (entry->len == num) {
5238 : : valid_entry = entry;
5239 : : break;
5240 : : }
5241 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5242 : : valid_entry = entry;
5243 : : }
5244 : : }
5245 : :
5246 : : /* Not find one to satisfy the request, return */
5247 [ # # ]: 0 : if (valid_entry == NULL) {
5248 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5249 : 0 : return -ENOMEM;
5250 : : }
5251 : : /**
5252 : : * The entry have equal queue number as requested,
5253 : : * remove it from alloc_list.
5254 : : */
5255 [ # # ]: 0 : if (valid_entry->len == num) {
5256 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5257 : : } else {
5258 : : /**
5259 : : * The entry have more numbers than requested,
5260 : : * create a new entry for alloc_list and minus its
5261 : : * queue base and number in free_list.
5262 : : */
5263 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5264 [ # # ]: 0 : if (entry == NULL) {
5265 : 0 : PMD_DRV_LOG(ERR,
5266 : : "Failed to allocate memory for resource pool");
5267 : 0 : return -ENOMEM;
5268 : : }
5269 : 0 : entry->base = valid_entry->base;
5270 : 0 : entry->len = num;
5271 : 0 : valid_entry->base += num;
5272 : 0 : valid_entry->len -= num;
5273 : : valid_entry = entry;
5274 : : }
5275 : :
5276 : : /* Insert it into alloc list, not sorted */
5277 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5278 : :
5279 : 0 : pool->num_free -= valid_entry->len;
5280 : 0 : pool->num_alloc += valid_entry->len;
5281 : :
5282 : 0 : return valid_entry->base + pool->base;
5283 : : }
5284 : :
5285 : : /**
5286 : : * bitmap_is_subset - Check whether src2 is subset of src1
5287 : : **/
5288 : : static inline int
5289 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5290 : : {
5291 : 0 : return !((src1 ^ src2) & src2);
5292 : : }
5293 : :
5294 : : static enum i40e_status_code
5295 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5296 : : {
5297 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5298 : :
5299 : : /* If DCB is not supported, only default TC is supported */
5300 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5301 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5302 : 0 : return I40E_NOT_SUPPORTED;
5303 : : }
5304 : :
5305 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5306 : 0 : PMD_DRV_LOG(ERR,
5307 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5308 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5309 : 0 : return I40E_NOT_SUPPORTED;
5310 : : }
5311 : : return I40E_SUCCESS;
5312 : : }
5313 : :
5314 : : int
5315 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5316 : : struct i40e_vsi_vlan_pvid_info *info)
5317 : : {
5318 : : struct i40e_hw *hw;
5319 : : struct i40e_vsi_context ctxt;
5320 : : uint8_t vlan_flags = 0;
5321 : : int ret;
5322 : :
5323 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5324 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5325 : 0 : return I40E_ERR_PARAM;
5326 : : }
5327 : :
5328 [ # # ]: 0 : if (info->on) {
5329 : 0 : vsi->info.pvid = info->config.pvid;
5330 : : /**
5331 : : * If insert pvid is enabled, only tagged pkts are
5332 : : * allowed to be sent out.
5333 : : */
5334 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5335 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5336 : : } else {
5337 : 0 : vsi->info.pvid = 0;
5338 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5339 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5340 : :
5341 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5342 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5343 : : }
5344 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5345 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5346 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5347 : 0 : vsi->info.valid_sections =
5348 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5349 : : memset(&ctxt, 0, sizeof(ctxt));
5350 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5351 : 0 : ctxt.seid = vsi->seid;
5352 : :
5353 : 0 : hw = I40E_VSI_TO_HW(vsi);
5354 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5355 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5356 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5357 : :
5358 : : return ret;
5359 : : }
5360 : :
5361 : : static int
5362 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5363 : : {
5364 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5365 : : int i, ret;
5366 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5367 : :
5368 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5369 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5370 : : return ret;
5371 : :
5372 [ # # ]: 0 : if (!vsi->seid) {
5373 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5374 : 0 : return -EINVAL;
5375 : : }
5376 : :
5377 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5378 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5379 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5380 : 0 : tc_bw_data.tc_bw_credits[i] =
5381 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5382 : :
5383 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5384 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5385 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5386 : 0 : return ret;
5387 : : }
5388 : :
5389 : 0 : memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5390 : : sizeof(vsi->info.qs_handle));
5391 : 0 : return I40E_SUCCESS;
5392 : : }
5393 : :
5394 : : static enum i40e_status_code
5395 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5396 : : struct i40e_aqc_vsi_properties_data *info,
5397 : : uint8_t enabled_tcmap)
5398 : : {
5399 : : enum i40e_status_code ret;
5400 : : int i, total_tc = 0;
5401 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5402 : :
5403 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5404 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5405 : : return ret;
5406 : :
5407 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5408 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5409 : 0 : total_tc++;
5410 [ # # ]: 0 : if (total_tc == 0)
5411 : : total_tc = 1;
5412 : 0 : vsi->enabled_tc = enabled_tcmap;
5413 : :
5414 : : /* Number of queues per enabled TC */
5415 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5416 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5417 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5418 : :
5419 : : /* Adjust the queue number to actual queues that can be applied */
5420 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5421 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5422 : :
5423 : : /**
5424 : : * Configure TC and queue mapping parameters, for enabled TC,
5425 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5426 : : * default queue will serve it.
5427 : : */
5428 : : qp_idx = 0;
5429 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5430 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5431 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5432 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5433 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5434 : 0 : qp_idx += qpnum_per_tc;
5435 : : } else
5436 : 0 : info->tc_mapping[i] = 0;
5437 : : }
5438 : :
5439 : : /* Associate queue number with VSI */
5440 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5441 : 0 : info->mapping_flags |=
5442 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5443 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5444 : 0 : info->queue_mapping[i] =
5445 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5446 : : } else {
5447 : 0 : info->mapping_flags |=
5448 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5449 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5450 : : }
5451 : 0 : info->valid_sections |=
5452 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5453 : :
5454 : 0 : return I40E_SUCCESS;
5455 : : }
5456 : :
5457 : : static int
5458 : 0 : i40e_veb_release(struct i40e_veb *veb)
5459 : : {
5460 : : struct i40e_vsi *vsi;
5461 : : struct i40e_hw *hw;
5462 : :
5463 [ # # ]: 0 : if (veb == NULL)
5464 : : return -EINVAL;
5465 : :
5466 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5467 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5468 : 0 : return -EACCES;
5469 : : }
5470 : : /* associate_vsi field is NULL for floating VEB */
5471 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5472 : : vsi = veb->associate_vsi;
5473 : 0 : hw = I40E_VSI_TO_HW(vsi);
5474 : :
5475 : 0 : vsi->uplink_seid = veb->uplink_seid;
5476 : 0 : vsi->veb = NULL;
5477 : : } else {
5478 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5479 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5480 : : }
5481 : :
5482 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5483 : 0 : rte_free(veb);
5484 : 0 : return I40E_SUCCESS;
5485 : : }
5486 : :
5487 : : /* Setup a veb */
5488 : : static struct i40e_veb *
5489 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5490 : : {
5491 : : struct i40e_veb *veb;
5492 : : int ret;
5493 : : struct i40e_hw *hw;
5494 : :
5495 [ # # ]: 0 : if (pf == NULL) {
5496 : 0 : PMD_DRV_LOG(ERR,
5497 : : "veb setup failed, associated PF shouldn't null");
5498 : 0 : return NULL;
5499 : : }
5500 : 0 : hw = I40E_PF_TO_HW(pf);
5501 : :
5502 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5503 [ # # ]: 0 : if (!veb) {
5504 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5505 : 0 : goto fail;
5506 : : }
5507 : :
5508 : 0 : veb->associate_vsi = vsi;
5509 : 0 : veb->associate_pf = pf;
5510 : 0 : TAILQ_INIT(&veb->head);
5511 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5512 : :
5513 : : /* create floating veb if vsi is NULL */
5514 [ # # ]: 0 : if (vsi != NULL) {
5515 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5516 : : I40E_DEFAULT_TCMAP, false,
5517 : 0 : &veb->seid, false, NULL);
5518 : : } else {
5519 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5520 : 0 : true, &veb->seid, false, NULL);
5521 : : }
5522 : :
5523 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5524 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5525 : : hw->aq.asq_last_status);
5526 : 0 : goto fail;
5527 : : }
5528 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5529 : :
5530 : : /* get statistics index */
5531 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5532 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5533 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5534 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5535 : : hw->aq.asq_last_status);
5536 : 0 : goto fail;
5537 : : }
5538 : : /* Get VEB bandwidth, to be implemented */
5539 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5540 [ # # ]: 0 : if (vsi)
5541 : 0 : vsi->uplink_seid = veb->seid;
5542 : :
5543 : : return veb;
5544 : 0 : fail:
5545 : 0 : rte_free(veb);
5546 : 0 : return NULL;
5547 : : }
5548 : :
5549 : : int
5550 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5551 : : {
5552 : : struct i40e_pf *pf;
5553 : : struct i40e_hw *hw;
5554 : : struct i40e_vsi_list *vsi_list;
5555 : : void *temp;
5556 : : int ret;
5557 : : struct i40e_mac_filter *f;
5558 : : uint16_t user_param;
5559 : :
5560 [ # # ]: 0 : if (!vsi)
5561 : : return I40E_SUCCESS;
5562 : :
5563 [ # # ]: 0 : if (!vsi->adapter)
5564 : : return -EFAULT;
5565 : :
5566 : 0 : user_param = vsi->user_param;
5567 : :
5568 : : pf = I40E_VSI_TO_PF(vsi);
5569 : 0 : hw = I40E_VSI_TO_HW(vsi);
5570 : :
5571 : : /* VSI has child to attach, release child first */
5572 [ # # ]: 0 : if (vsi->veb) {
5573 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5574 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5575 : : return -1;
5576 : : }
5577 : 0 : i40e_veb_release(vsi->veb);
5578 : : }
5579 : :
5580 [ # # ]: 0 : if (vsi->floating_veb) {
5581 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5582 : : list, temp) {
5583 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5584 : : return -1;
5585 : : }
5586 : : }
5587 : :
5588 : : /* Remove all macvlan filters of the VSI */
5589 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5590 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5591 : 0 : rte_free(f);
5592 : :
5593 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5594 : 0 : ((vsi->type != I40E_VSI_SRIOV) ||
5595 [ # # ]: 0 : !pf->floating_veb_list[user_param])) {
5596 : : /* Remove vsi from parent's sibling list */
5597 [ # # # # ]: 0 : if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5598 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5599 : 0 : return I40E_ERR_PARAM;
5600 : : }
5601 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5602 : : &vsi->sib_vsi_list, list);
5603 : :
5604 : : /* Remove all switch element of the VSI */
5605 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5606 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5607 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5608 : : }
5609 : :
5610 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5611 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5612 : : /* Remove vsi from parent's sibling list */
5613 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5614 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5615 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5616 : 0 : return I40E_ERR_PARAM;
5617 : : }
5618 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5619 : : &vsi->sib_vsi_list, list);
5620 : :
5621 : : /* Remove all switch element of the VSI */
5622 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5623 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5624 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5625 : : }
5626 : :
5627 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5628 : :
5629 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5630 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5631 : 0 : rte_free(vsi);
5632 : :
5633 : 0 : return I40E_SUCCESS;
5634 : : }
5635 : :
5636 : : static int
5637 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5638 : : {
5639 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5640 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5641 : : struct i40e_mac_filter_info filter;
5642 : : int ret;
5643 : :
5644 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5645 : : return I40E_ERR_CONFIG;
5646 : : memset(&def_filter, 0, sizeof(def_filter));
5647 : : memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5648 : : ETH_ADDR_LEN);
5649 : : def_filter.vlan_tag = 0;
5650 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5651 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5652 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5653 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5654 : : struct i40e_mac_filter *f;
5655 : : struct rte_ether_addr *mac;
5656 : :
5657 : 0 : PMD_DRV_LOG(DEBUG,
5658 : : "Cannot remove the default macvlan filter");
5659 : : /* It needs to add the permanent mac into mac list */
5660 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5661 [ # # ]: 0 : if (f == NULL) {
5662 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5663 : 0 : return I40E_ERR_NO_MEMORY;
5664 : : }
5665 : : mac = &f->mac_info.mac_addr;
5666 : 0 : memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5667 : : ETH_ADDR_LEN);
5668 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5669 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5670 : 0 : vsi->mac_num++;
5671 : :
5672 : 0 : return ret;
5673 : : }
5674 : : memcpy(&filter.mac_addr,
5675 : 0 : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5676 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5677 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5678 : : }
5679 : :
5680 : : /*
5681 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5682 : : * @vsi: the VSI to be queried
5683 : : *
5684 : : * Returns 0 on success, negative value on failure
5685 : : */
5686 : : static enum i40e_status_code
5687 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5688 : : {
5689 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5690 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5691 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5692 : : i40e_status ret;
5693 : : int i;
5694 : : uint32_t bw_max;
5695 : :
5696 : : memset(&bw_config, 0, sizeof(bw_config));
5697 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5698 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5699 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5700 : : hw->aq.asq_last_status);
5701 : 0 : return ret;
5702 : : }
5703 : :
5704 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5705 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5706 : : &ets_sla_config, NULL);
5707 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5708 : 0 : PMD_DRV_LOG(ERR,
5709 : : "VSI failed to get TC bandwidth configuration %u",
5710 : : hw->aq.asq_last_status);
5711 : 0 : return ret;
5712 : : }
5713 : :
5714 : : /* store and print out BW info */
5715 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5716 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5717 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5718 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5719 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5720 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5721 : : I40E_16_BIT_WIDTH);
5722 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5723 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5724 : 0 : ets_sla_config.share_credits[i];
5725 : 0 : vsi->bw_info.bw_ets_credits[i] =
5726 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5727 : : /* 4 bits per TC, 4th bit is reserved */
5728 : 0 : vsi->bw_info.bw_ets_max[i] =
5729 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5730 : : RTE_LEN2MASK(3, uint8_t));
5731 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5732 : : vsi->bw_info.bw_ets_share_credits[i]);
5733 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5734 : : vsi->bw_info.bw_ets_credits[i]);
5735 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5736 : : vsi->bw_info.bw_ets_max[i]);
5737 : : }
5738 : :
5739 : : return I40E_SUCCESS;
5740 : : }
5741 : :
5742 : : /* i40e_enable_pf_lb
5743 : : * @pf: pointer to the pf structure
5744 : : *
5745 : : * allow loopback on pf
5746 : : */
5747 : : static inline void
5748 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5749 : : {
5750 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5751 : : struct i40e_vsi_context ctxt;
5752 : : int ret;
5753 : :
5754 : : /* Use the FW API if FW >= v5.0 */
5755 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5756 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5757 : 0 : return;
5758 : : }
5759 : :
5760 : : memset(&ctxt, 0, sizeof(ctxt));
5761 : 0 : ctxt.seid = pf->main_vsi_seid;
5762 : 0 : ctxt.pf_num = hw->pf_id;
5763 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5764 [ # # ]: 0 : if (ret) {
5765 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5766 : : ret, hw->aq.asq_last_status);
5767 : 0 : return;
5768 : : }
5769 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5770 : 0 : ctxt.info.valid_sections =
5771 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5772 : 0 : ctxt.info.switch_id |=
5773 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5774 : :
5775 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5776 [ # # ]: 0 : if (ret)
5777 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5778 : : hw->aq.asq_last_status);
5779 : : }
5780 : :
5781 : : /* i40e_pf_set_source_prune
5782 : : * @pf: pointer to the pf structure
5783 : : * @on: Enable/disable source prune
5784 : : *
5785 : : * set source prune on pf
5786 : : */
5787 : : int
5788 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5789 : : {
5790 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5791 : : struct i40e_vsi_context ctxt;
5792 : : int ret;
5793 : :
5794 : : memset(&ctxt, 0, sizeof(ctxt));
5795 : 0 : ctxt.seid = pf->main_vsi_seid;
5796 : 0 : ctxt.pf_num = hw->pf_id;
5797 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5798 [ # # ]: 0 : if (ret) {
5799 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5800 : : ret, hw->aq.asq_last_status);
5801 : 0 : return ret;
5802 : : }
5803 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5804 : 0 : ctxt.info.valid_sections =
5805 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5806 [ # # ]: 0 : if (on)
5807 : 0 : ctxt.info.switch_id &=
5808 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5809 : : else
5810 : 0 : ctxt.info.switch_id |=
5811 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5812 : :
5813 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5814 [ # # ]: 0 : if (ret)
5815 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5816 : : hw->aq.asq_last_status);
5817 : :
5818 : : return ret;
5819 : : }
5820 : :
5821 : : /* Setup a VSI */
5822 : : struct i40e_vsi *
5823 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5824 : : enum i40e_vsi_type type,
5825 : : struct i40e_vsi *uplink_vsi,
5826 : : uint16_t user_param)
5827 : : {
5828 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5829 : : struct i40e_vsi *vsi;
5830 : : struct i40e_mac_filter_info filter;
5831 : : int ret;
5832 : : struct i40e_vsi_context ctxt;
5833 : 0 : struct rte_ether_addr broadcast =
5834 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5835 : :
5836 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5837 : : uplink_vsi == NULL) {
5838 : 0 : PMD_DRV_LOG(ERR,
5839 : : "VSI setup failed, VSI link shouldn't be NULL");
5840 : 0 : return NULL;
5841 : : }
5842 : :
5843 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5844 : 0 : PMD_DRV_LOG(ERR,
5845 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5846 : 0 : return NULL;
5847 : : }
5848 : :
5849 : : /* two situations
5850 : : * 1.type is not MAIN and uplink vsi is not NULL
5851 : : * If uplink vsi didn't setup VEB, create one first under veb field
5852 : : * 2.type is SRIOV and the uplink is NULL
5853 : : * If floating VEB is NULL, create one veb under floating veb field
5854 : : */
5855 : :
5856 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5857 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5858 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5859 : :
5860 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5861 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5862 : 0 : return NULL;
5863 : : }
5864 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5865 : 0 : i40e_enable_pf_lb(pf);
5866 : : }
5867 : :
5868 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5869 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5870 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5871 : :
5872 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5873 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5874 : 0 : return NULL;
5875 : : }
5876 : : }
5877 : :
5878 : : /* source prune is disabled to support VRRP in default*/
5879 : 0 : i40e_pf_set_source_prune(pf, 0);
5880 : :
5881 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5882 [ # # ]: 0 : if (!vsi) {
5883 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5884 : 0 : return NULL;
5885 : : }
5886 : 0 : TAILQ_INIT(&vsi->mac_list);
5887 : 0 : vsi->type = type;
5888 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5889 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5890 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5891 : 0 : vsi->user_param = user_param;
5892 : 0 : vsi->vlan_anti_spoof_on = 0;
5893 : 0 : vsi->vlan_filter_on = 0;
5894 : : /* Allocate queues */
5895 [ # # # # : 0 : switch (vsi->type) {
# ]
5896 : 0 : case I40E_VSI_MAIN :
5897 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5898 : 0 : break;
5899 : 0 : case I40E_VSI_SRIOV :
5900 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5901 : 0 : break;
5902 : 0 : case I40E_VSI_VMDQ2:
5903 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5904 : 0 : break;
5905 : 0 : case I40E_VSI_FDIR:
5906 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5907 : 0 : break;
5908 : 0 : default:
5909 : 0 : goto fail_mem;
5910 : : }
5911 : : /*
5912 : : * The filter status descriptor is reported in rx queue 0,
5913 : : * while the tx queue for fdir filter programming has no
5914 : : * such constraints, can be non-zero queues.
5915 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5916 : : * To make sure it will use queue 0 pair, queue allocation
5917 : : * need be done before this function is called
5918 : : */
5919 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5920 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5921 [ # # ]: 0 : if (ret < 0) {
5922 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5923 : : vsi->seid, ret);
5924 : 0 : goto fail_mem;
5925 : : }
5926 : 0 : vsi->base_queue = ret;
5927 : : } else
5928 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5929 : :
5930 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5931 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5932 [ # # ]: 0 : if (pf->support_multi_driver) {
5933 : : /* If support multi-driver, need to use INT0 instead of
5934 : : * allocating from msix pool. The Msix pool is init from
5935 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5936 : : * to 1 without calling i40e_res_pool_alloc.
5937 : : */
5938 : 0 : vsi->msix_intr = 0;
5939 : 0 : vsi->nb_msix = 1;
5940 : : } else {
5941 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5942 : 0 : RTE_MIN(vsi->nb_qps,
5943 : : RTE_MAX_RXTX_INTR_VEC_ID));
5944 [ # # ]: 0 : if (ret < 0) {
5945 : 0 : PMD_DRV_LOG(ERR,
5946 : : "VSI MAIN %d get heap failed %d",
5947 : : vsi->seid, ret);
5948 : 0 : goto fail_queue_alloc;
5949 : : }
5950 : 0 : vsi->msix_intr = ret;
5951 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5952 : : RTE_MAX_RXTX_INTR_VEC_ID);
5953 : : }
5954 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5955 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5956 [ # # ]: 0 : if (ret < 0) {
5957 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5958 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5959 : 0 : goto fail_queue_alloc;
5960 : 0 : vsi->msix_intr = 0;
5961 : 0 : vsi->nb_msix = 0;
5962 : : } else {
5963 : 0 : vsi->msix_intr = ret;
5964 : 0 : vsi->nb_msix = 1;
5965 : : }
5966 : : } else {
5967 : 0 : vsi->msix_intr = 0;
5968 : 0 : vsi->nb_msix = 0;
5969 : : }
5970 : :
5971 : : /* Add VSI */
5972 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5973 : : /* For main VSI, no need to add since it's default one */
5974 : 0 : vsi->uplink_seid = pf->mac_seid;
5975 : 0 : vsi->seid = pf->main_vsi_seid;
5976 : : /* Bind queues with specific MSIX interrupt */
5977 : : /**
5978 : : * Needs 2 interrupt at least, one for misc cause which will
5979 : : * enabled from OS side, Another for queues binding the
5980 : : * interrupt from device side only.
5981 : : */
5982 : :
5983 : : /* Get default VSI parameters from hardware */
5984 : : memset(&ctxt, 0, sizeof(ctxt));
5985 : 0 : ctxt.seid = vsi->seid;
5986 : 0 : ctxt.pf_num = hw->pf_id;
5987 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5988 : : ctxt.vf_num = 0;
5989 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5990 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5991 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
5992 : 0 : goto fail_msix_alloc;
5993 : : }
5994 : 0 : vsi->info = ctxt.info;
5995 : 0 : vsi->vsi_id = ctxt.vsi_number;
5996 : 0 : vsi->info.valid_sections = 0;
5997 : :
5998 : : /* Configure tc, enabled TC0 only */
5999 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
6000 : : I40E_SUCCESS) {
6001 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
6002 : 0 : goto fail_msix_alloc;
6003 : : }
6004 : :
6005 : : /* TC, queue mapping */
6006 : : memset(&ctxt, 0, sizeof(ctxt));
6007 : 0 : vsi->info.valid_sections |=
6008 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6009 : 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
6010 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6011 : 0 : ctxt.info = vsi->info;
6012 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6013 : : I40E_DEFAULT_TCMAP);
6014 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6015 : 0 : PMD_DRV_LOG(ERR,
6016 : : "Failed to configure TC queue mapping");
6017 : 0 : goto fail_msix_alloc;
6018 : : }
6019 : 0 : ctxt.seid = vsi->seid;
6020 : 0 : ctxt.pf_num = hw->pf_id;
6021 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6022 : 0 : ctxt.vf_num = 0;
6023 : :
6024 : : /* Update VSI parameters */
6025 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6026 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6027 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
6028 : 0 : goto fail_msix_alloc;
6029 : : }
6030 : :
6031 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
6032 : : sizeof(vsi->info.tc_mapping));
6033 : 0 : memcpy(&vsi->info.queue_mapping,
6034 : : &ctxt.info.queue_mapping,
6035 : : sizeof(vsi->info.queue_mapping));
6036 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
6037 : 0 : vsi->info.valid_sections = 0;
6038 : :
6039 : 0 : memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
6040 : : ETH_ADDR_LEN);
6041 : :
6042 : : /**
6043 : : * Updating default filter settings are necessary to prevent
6044 : : * reception of tagged packets.
6045 : : * Some old firmware configurations load a default macvlan
6046 : : * filter which accepts both tagged and untagged packets.
6047 : : * The updating is to use a normal filter instead if needed.
6048 : : * For NVM 4.2.2 or after, the updating is not needed anymore.
6049 : : * The firmware with correct configurations load the default
6050 : : * macvlan filter which is expected and cannot be removed.
6051 : : */
6052 : 0 : i40e_update_default_filter_setting(vsi);
6053 : 0 : i40e_config_qinq(hw, vsi);
6054 [ # # ]: 0 : } else if (type == I40E_VSI_SRIOV) {
6055 : : memset(&ctxt, 0, sizeof(ctxt));
6056 : : /**
6057 : : * For other VSI, the uplink_seid equals to uplink VSI's
6058 : : * uplink_seid since they share same VEB
6059 : : */
6060 [ # # ]: 0 : if (uplink_vsi == NULL)
6061 : 0 : vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
6062 : : else
6063 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6064 : 0 : ctxt.pf_num = hw->pf_id;
6065 : 0 : ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
6066 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6067 : 0 : ctxt.connection_type = 0x1;
6068 : : ctxt.flags = I40E_AQ_VSI_TYPE_VF;
6069 : :
6070 : : /* Use the VEB configuration if FW >= v5.0 */
6071 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
6072 : : /* Configure switch ID */
6073 : 0 : ctxt.info.valid_sections |=
6074 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6075 : 0 : ctxt.info.switch_id =
6076 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6077 : : }
6078 : :
6079 : : /* Configure port/vlan */
6080 : 0 : ctxt.info.valid_sections |=
6081 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6082 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6083 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6084 : 0 : hw->func_caps.enabled_tcmap);
6085 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6086 : 0 : PMD_DRV_LOG(ERR,
6087 : : "Failed to configure TC queue mapping");
6088 : 0 : goto fail_msix_alloc;
6089 : : }
6090 : :
6091 : 0 : ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
6092 : 0 : ctxt.info.valid_sections |=
6093 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6094 : : /**
6095 : : * Since VSI is not created yet, only configure parameter,
6096 : : * will add vsi below.
6097 : : */
6098 : :
6099 : 0 : i40e_config_qinq(hw, vsi);
6100 [ # # ]: 0 : } else if (type == I40E_VSI_VMDQ2) {
6101 : : memset(&ctxt, 0, sizeof(ctxt));
6102 : : /*
6103 : : * For other VSI, the uplink_seid equals to uplink VSI's
6104 : : * uplink_seid since they share same VEB
6105 : : */
6106 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6107 : 0 : ctxt.pf_num = hw->pf_id;
6108 : : ctxt.vf_num = 0;
6109 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6110 : 0 : ctxt.connection_type = 0x1;
6111 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
6112 : :
6113 : 0 : ctxt.info.valid_sections |=
6114 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6115 : : /* user_param carries flag to enable loop back */
6116 [ # # ]: 0 : if (user_param) {
6117 : : ctxt.info.switch_id =
6118 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
6119 : 0 : ctxt.info.switch_id |=
6120 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6121 : : }
6122 : :
6123 : : /* Configure port/vlan */
6124 : 0 : ctxt.info.valid_sections |=
6125 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6126 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6127 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6128 : : I40E_DEFAULT_TCMAP);
6129 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6130 : 0 : PMD_DRV_LOG(ERR,
6131 : : "Failed to configure TC queue mapping");
6132 : 0 : goto fail_msix_alloc;
6133 : : }
6134 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6135 : 0 : ctxt.info.valid_sections |=
6136 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6137 : : } else if (type == I40E_VSI_FDIR) {
6138 : : memset(&ctxt, 0, sizeof(ctxt));
6139 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6140 : 0 : ctxt.pf_num = hw->pf_id;
6141 : : ctxt.vf_num = 0;
6142 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6143 : 0 : ctxt.connection_type = 0x1; /* regular data port */
6144 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6145 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6146 : : I40E_DEFAULT_TCMAP);
6147 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6148 : 0 : PMD_DRV_LOG(ERR,
6149 : : "Failed to configure TC queue mapping.");
6150 : 0 : goto fail_msix_alloc;
6151 : : }
6152 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6153 : 0 : ctxt.info.valid_sections |=
6154 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6155 : : } else {
6156 : : PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6157 : : goto fail_msix_alloc;
6158 : : }
6159 : :
6160 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN) {
6161 : 0 : ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6162 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6163 : 0 : PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6164 : : hw->aq.asq_last_status);
6165 : 0 : goto fail_msix_alloc;
6166 : : }
6167 [ # # ]: 0 : memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6168 : 0 : vsi->info.valid_sections = 0;
6169 : 0 : vsi->seid = ctxt.seid;
6170 : 0 : vsi->vsi_id = ctxt.vsi_number;
6171 : 0 : vsi->sib_vsi_list.vsi = vsi;
6172 [ # # # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6173 : 0 : TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6174 : : &vsi->sib_vsi_list, list);
6175 : : } else {
6176 : 0 : TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6177 : : &vsi->sib_vsi_list, list);
6178 : : }
6179 : : }
6180 : :
6181 [ # # ]: 0 : if (vsi->type != I40E_VSI_FDIR) {
6182 : : /* MAC/VLAN configuration for non-FDIR VSI*/
6183 : : memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6184 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6185 : :
6186 : 0 : ret = i40e_vsi_add_mac(vsi, &filter);
6187 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6188 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6189 : 0 : goto fail_msix_alloc;
6190 : : }
6191 : : }
6192 : :
6193 : : /* Get VSI BW information */
6194 : 0 : i40e_vsi_get_bw_config(vsi);
6195 : 0 : return vsi;
6196 : 0 : fail_msix_alloc:
6197 : 0 : i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6198 : 0 : fail_queue_alloc:
6199 : 0 : i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6200 : 0 : fail_mem:
6201 : 0 : rte_free(vsi);
6202 : 0 : return NULL;
6203 : : }
6204 : :
6205 : : /* Configure vlan filter on or off */
6206 : : int
6207 : 0 : i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6208 : : {
6209 : : int i, num;
6210 : : struct i40e_mac_filter *f;
6211 : : void *temp;
6212 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
6213 : : enum i40e_mac_filter_type desired_filter;
6214 : : int ret = I40E_SUCCESS;
6215 : :
6216 [ # # ]: 0 : if (on) {
6217 : : /* Filter to match MAC and VLAN */
6218 : : desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6219 : : } else {
6220 : : /* Filter to match only MAC */
6221 : : desired_filter = I40E_MAC_PERFECT_MATCH;
6222 : : }
6223 : :
6224 : 0 : num = vsi->mac_num;
6225 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
6226 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
6227 : 0 : return -1;
6228 : : }
6229 : :
6230 : : i = 0;
6231 : :
6232 : : /* Remove all existing mac */
6233 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6234 : 0 : mac_filter[i] = f->mac_info;
6235 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6236 [ # # ]: 0 : if (ret) {
6237 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6238 : : on ? "enable" : "disable");
6239 : 0 : return ret;
6240 : : }
6241 : 0 : i++;
6242 : : }
6243 : :
6244 : : /* Override with new filter */
6245 [ # # ]: 0 : for (i = 0; i < num; i++) {
6246 : 0 : mac_filter[i].filter_type = desired_filter;
6247 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6248 [ # # ]: 0 : if (ret) {
6249 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6250 : : on ? "enable" : "disable");
6251 : 0 : return ret;
6252 : : }
6253 : : }
6254 : :
6255 : : return 0;
6256 : : }
6257 : :
6258 : : /* Configure vlan stripping on or off */
6259 : : int
6260 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6261 : : {
6262 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6263 : : struct i40e_vsi_context ctxt;
6264 : : uint8_t vlan_flags;
6265 : : int ret = I40E_SUCCESS;
6266 : :
6267 : : /* Check if it has been already on or off */
6268 [ # # ]: 0 : if (vsi->info.valid_sections &
6269 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6270 [ # # ]: 0 : if (on) {
6271 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6272 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6273 : : return 0; /* already on */
6274 : : } else {
6275 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6276 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6277 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6278 : : return 0; /* already off */
6279 : : }
6280 : : }
6281 : :
6282 [ # # ]: 0 : if (on)
6283 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6284 : : else
6285 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6286 : 0 : vsi->info.valid_sections =
6287 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6288 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6289 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6290 : 0 : ctxt.seid = vsi->seid;
6291 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6292 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6293 [ # # ]: 0 : if (ret)
6294 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6295 : : on ? "enable" : "disable");
6296 : :
6297 : : return ret;
6298 : : }
6299 : :
6300 : : static int
6301 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6302 : : {
6303 : 0 : struct rte_eth_dev_data *data = dev->data;
6304 : : int ret;
6305 : : int mask = 0;
6306 : :
6307 : : /* Apply vlan offload setting */
6308 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6309 : : RTE_ETH_QINQ_STRIP_MASK |
6310 : : RTE_ETH_VLAN_FILTER_MASK |
6311 : : RTE_ETH_VLAN_EXTEND_MASK;
6312 : :
6313 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6314 [ # # ]: 0 : if (ret) {
6315 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6316 : 0 : return ret;
6317 : : }
6318 : :
6319 : : /* Apply pvid setting */
6320 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6321 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6322 [ # # ]: 0 : if (ret)
6323 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6324 : :
6325 : : return ret;
6326 : : }
6327 : :
6328 : : static int
6329 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6330 : : {
6331 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6332 : :
6333 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6334 : : }
6335 : :
6336 : : static int
6337 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6338 : : {
6339 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6340 : : struct i40e_link_status link_status;
6341 : : uint32_t rxfc = 0, txfc = 0, reg;
6342 : : uint8_t an_info;
6343 : : int ret;
6344 : :
6345 : : memset(&link_status, 0, sizeof(link_status));
6346 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6347 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6348 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6349 : 0 : goto write_reg; /* Disable flow control */
6350 : : }
6351 : :
6352 : 0 : an_info = hw->phy.link_info.an_info;
6353 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6354 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6355 : : ret = I40E_ERR_NOT_READY;
6356 : 0 : goto write_reg; /* Disable flow control */
6357 : : }
6358 : : /**
6359 : : * If link auto negotiation is enabled, flow control needs to
6360 : : * be configured according to it
6361 : : */
6362 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6363 : 0 : case I40E_LINK_PAUSE_RXTX:
6364 : : rxfc = 1;
6365 : : txfc = 1;
6366 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6367 : 0 : break;
6368 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6369 : : rxfc = 1;
6370 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6371 : 0 : break;
6372 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6373 : : txfc = 1;
6374 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6375 : 0 : break;
6376 : 0 : default:
6377 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6378 : 0 : break;
6379 : : }
6380 : :
6381 : 0 : write_reg:
6382 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6383 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6384 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6385 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6386 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6387 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6388 : :
6389 : 0 : return ret;
6390 : : }
6391 : :
6392 : : /* PF setup */
6393 : : static int
6394 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6395 : : {
6396 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6397 : : struct i40e_filter_control_settings settings;
6398 : : struct i40e_vsi *vsi;
6399 : : int ret;
6400 : :
6401 : : /* Clear all stats counters */
6402 : 0 : pf->offset_loaded = FALSE;
6403 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6404 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6405 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6406 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6407 : :
6408 : 0 : ret = i40e_pf_get_switch_config(pf);
6409 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6410 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6411 : 0 : return ret;
6412 : : }
6413 : :
6414 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6415 [ # # ]: 0 : if (ret)
6416 : 0 : PMD_INIT_LOG(WARNING,
6417 : : "failed to allocate switch domain for device %d", ret);
6418 : :
6419 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6420 : : /* make queue allocated first, let FDIR use queue pair 0*/
6421 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6422 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6423 : 0 : PMD_DRV_LOG(ERR,
6424 : : "queue allocation fails for FDIR: ret =%d",
6425 : : ret);
6426 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6427 : : }
6428 : : }
6429 : : /* main VSI setup */
6430 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6431 [ # # ]: 0 : if (!vsi) {
6432 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6433 : 0 : return I40E_ERR_NOT_READY;
6434 : : }
6435 [ # # ]: 0 : pf->main_vsi = vsi;
6436 : :
6437 : : /* Configure filter control */
6438 : : memset(&settings, 0, sizeof(settings));
6439 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6440 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6441 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6442 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6443 : : else {
6444 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6445 : : hw->func_caps.rss_table_size);
6446 : 0 : return I40E_ERR_PARAM;
6447 : : }
6448 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6449 : : hw->func_caps.rss_table_size);
6450 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6451 : :
6452 : : /* Enable ethtype and macvlan filters */
6453 : 0 : settings.enable_ethtype = TRUE;
6454 : 0 : settings.enable_macvlan = TRUE;
6455 : 0 : ret = i40e_set_filter_control(hw, &settings);
6456 [ # # ]: 0 : if (ret)
6457 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6458 : : ret);
6459 : :
6460 : : /* Update flow control according to the auto negotiation */
6461 : 0 : i40e_update_flow_control(hw);
6462 : :
6463 : 0 : return I40E_SUCCESS;
6464 : : }
6465 : :
6466 : : int
6467 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6468 : : {
6469 : : uint32_t reg;
6470 : : uint16_t j;
6471 : :
6472 : : /**
6473 : : * Set or clear TX Queue Disable flags,
6474 : : * which is required by hardware.
6475 : : */
6476 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6477 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6478 : :
6479 : : /* Wait until the request is finished */
6480 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6481 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6482 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6483 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6484 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6485 : : & 0x1))) {
6486 : : break;
6487 : : }
6488 : : }
6489 [ # # ]: 0 : if (on) {
6490 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6491 : : return I40E_SUCCESS; /* already on, skip next steps */
6492 : :
6493 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6494 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6495 : : } else {
6496 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6497 : : return I40E_SUCCESS; /* already off, skip next steps */
6498 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6499 : : }
6500 : : /* Write the register */
6501 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6502 : : /* Check the result */
6503 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6504 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6505 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6506 [ # # ]: 0 : if (on) {
6507 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6508 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6509 : : break;
6510 : : } else {
6511 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6512 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6513 : : break;
6514 : : }
6515 : : }
6516 : : /* Check if it is timeout */
6517 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6518 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6519 : : (on ? "enable" : "disable"), q_idx);
6520 : 0 : return I40E_ERR_TIMEOUT;
6521 : : }
6522 : :
6523 : : return I40E_SUCCESS;
6524 : : }
6525 : :
6526 : : int
6527 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6528 : : {
6529 : : uint32_t reg;
6530 : : uint16_t j;
6531 : :
6532 : : /* Wait until the request is finished */
6533 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6534 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6535 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6536 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6537 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6538 : : break;
6539 : : }
6540 : :
6541 [ # # ]: 0 : if (on) {
6542 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6543 : : return I40E_SUCCESS; /* Already on, skip next steps */
6544 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6545 : : } else {
6546 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6547 : : return I40E_SUCCESS; /* Already off, skip next steps */
6548 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6549 : : }
6550 : :
6551 : : /* Write the register */
6552 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6553 : : /* Check the result */
6554 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6555 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6556 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6557 [ # # ]: 0 : if (on) {
6558 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6559 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6560 : : break;
6561 : : } else {
6562 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6563 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6564 : : break;
6565 : : }
6566 : : }
6567 : :
6568 : : /* Check if it is timeout */
6569 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6570 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6571 : : (on ? "enable" : "disable"), q_idx);
6572 : 0 : return I40E_ERR_TIMEOUT;
6573 : : }
6574 : :
6575 : : return I40E_SUCCESS;
6576 : : }
6577 : :
6578 : : /* Initialize VSI for TX */
6579 : : static int
6580 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6581 : : {
6582 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6583 : : uint16_t i;
6584 : : uint32_t ret = I40E_SUCCESS;
6585 : : struct ci_tx_queue *txq;
6586 : :
6587 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6588 : 0 : txq = data->tx_queues[i];
6589 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6590 : 0 : continue;
6591 : 0 : ret = i40e_tx_queue_init(txq);
6592 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6593 : : break;
6594 : : }
6595 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6596 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6597 : :
6598 : 0 : return ret;
6599 : : }
6600 : :
6601 : : /* Initialize VSI for RX */
6602 : : static int
6603 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6604 : : {
6605 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6606 : : int ret = I40E_SUCCESS;
6607 : : uint16_t i;
6608 : : struct ci_rx_queue *rxq;
6609 : :
6610 : 0 : i40e_pf_config_rss(pf);
6611 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6612 : 0 : rxq = data->rx_queues[i];
6613 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6614 : 0 : continue;
6615 : :
6616 : 0 : ret = i40e_rx_queue_init(rxq);
6617 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6618 : 0 : PMD_DRV_LOG(ERR,
6619 : : "Failed to do RX queue initialization");
6620 : 0 : break;
6621 : : }
6622 : : }
6623 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6624 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6625 : :
6626 : 0 : return ret;
6627 : : }
6628 : :
6629 : : static int
6630 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6631 : : {
6632 : : int err;
6633 : :
6634 : 0 : err = i40e_dev_tx_init(pf);
6635 [ # # ]: 0 : if (err) {
6636 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6637 : 0 : return err;
6638 : : }
6639 : 0 : err = i40e_dev_rx_init(pf);
6640 [ # # ]: 0 : if (err) {
6641 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6642 : 0 : return err;
6643 : : }
6644 : :
6645 : : return err;
6646 : : }
6647 : :
6648 : : static int
6649 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6650 : : {
6651 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6652 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6653 : : int i, err, conf_vsis, j, loop;
6654 : : struct i40e_vsi *vsi;
6655 : : struct i40e_vmdq_info *vmdq_info;
6656 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6657 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6658 : :
6659 : : /*
6660 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6661 : : * avoid race condition in VSI creation/destroy.
6662 : : */
6663 : 0 : i40e_pf_disable_irq0(hw);
6664 : :
6665 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6666 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6667 : 0 : return -ENOTSUP;
6668 : : }
6669 : :
6670 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6671 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6672 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6673 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6674 : : pf->max_nb_vmdq_vsi);
6675 : 0 : return -ENOTSUP;
6676 : : }
6677 : :
6678 [ # # ]: 0 : if (pf->vmdq != NULL) {
6679 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6680 : 0 : return 0;
6681 : : }
6682 : :
6683 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6684 : : sizeof(*vmdq_info) * conf_vsis, 0);
6685 : :
6686 [ # # ]: 0 : if (pf->vmdq == NULL) {
6687 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6688 : 0 : return -ENOMEM;
6689 : : }
6690 : :
6691 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6692 : :
6693 : : /* Create VMDQ VSI */
6694 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6695 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6696 : 0 : vmdq_conf->enable_loop_back);
6697 [ # # ]: 0 : if (vsi == NULL) {
6698 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6699 : : err = -1;
6700 : 0 : goto err_vsi_setup;
6701 : : }
6702 : 0 : vmdq_info = &pf->vmdq[i];
6703 : 0 : vmdq_info->pf = pf;
6704 : 0 : vmdq_info->vsi = vsi;
6705 : : }
6706 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6707 : :
6708 : : /* Configure Vlan */
6709 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6710 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6711 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6712 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & RTE_BIT64(j)) {
6713 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6714 : : vmdq_conf->pool_map[i].vlan_id, j);
6715 : :
6716 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6717 : 0 : vmdq_conf->pool_map[i].vlan_id);
6718 [ # # ]: 0 : if (err) {
6719 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6720 : : err = -1;
6721 : 0 : goto err_vsi_setup;
6722 : : }
6723 : : }
6724 : : }
6725 : : }
6726 : :
6727 : 0 : i40e_pf_enable_irq0(hw);
6728 : :
6729 : 0 : return 0;
6730 : :
6731 : : err_vsi_setup:
6732 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6733 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6734 : : break;
6735 : : else
6736 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6737 : :
6738 : 0 : rte_free(pf->vmdq);
6739 : 0 : pf->vmdq = NULL;
6740 : 0 : i40e_pf_enable_irq0(hw);
6741 : 0 : return err;
6742 : : }
6743 : :
6744 : : static void
6745 : : i40e_stat_update_32(struct i40e_hw *hw,
6746 : : uint32_t reg,
6747 : : bool offset_loaded,
6748 : : uint64_t *offset,
6749 : : uint64_t *stat)
6750 : : {
6751 : : uint64_t new_data;
6752 : :
6753 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6754 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6755 : 0 : *offset = new_data;
6756 : :
6757 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6758 : 0 : *stat = (uint64_t)(new_data - *offset);
6759 : : else
6760 : 0 : *stat = (uint64_t)((new_data +
6761 : : RTE_BIT64(I40E_32_BIT_WIDTH)) - *offset);
6762 : : }
6763 : :
6764 : : static void
6765 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6766 : : uint32_t hireg,
6767 : : uint32_t loreg,
6768 : : bool offset_loaded,
6769 : : uint64_t *offset,
6770 : : uint64_t *stat)
6771 : : {
6772 : : uint64_t new_data;
6773 : :
6774 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6775 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6776 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6777 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6778 : : } else {
6779 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6780 : : }
6781 : :
6782 [ # # ]: 0 : if (!offset_loaded)
6783 : 0 : *offset = new_data;
6784 : :
6785 [ # # ]: 0 : if (new_data >= *offset)
6786 : 0 : *stat = new_data - *offset;
6787 : : else
6788 : 0 : *stat = (uint64_t)((new_data +
6789 : : RTE_BIT64(I40E_48_BIT_WIDTH)) - *offset);
6790 : :
6791 : 0 : *stat &= I40E_48_BIT_MASK;
6792 : 0 : }
6793 : :
6794 : : /* Disable IRQ0 */
6795 : : void
6796 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6797 : : {
6798 : : /* Disable all interrupt types */
6799 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6800 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6801 : 0 : I40E_WRITE_FLUSH(hw);
6802 : 0 : }
6803 : :
6804 : : /* Enable IRQ0 */
6805 : : void
6806 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6807 : : {
6808 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6809 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6810 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6811 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6812 : 0 : I40E_WRITE_FLUSH(hw);
6813 : 0 : }
6814 : :
6815 : : static void
6816 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6817 : : {
6818 : : /* read pending request and disable first */
6819 : 0 : i40e_pf_disable_irq0(hw);
6820 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6821 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6822 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6823 : :
6824 : : if (no_queue)
6825 : : /* Link no queues with irq0 */
6826 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6827 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6828 : : }
6829 : :
6830 : : static void
6831 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6832 : : {
6833 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6834 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6835 : : int i;
6836 : : uint16_t abs_vf_id;
6837 : : uint32_t index, offset, val;
6838 : :
6839 [ # # ]: 0 : if (!pf->vfs)
6840 : : return;
6841 : : /**
6842 : : * Try to find which VF trigger a reset, use absolute VF id to access
6843 : : * since the reg is global register.
6844 : : */
6845 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6846 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6847 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6848 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6849 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6850 : : /* VFR event occurred */
6851 [ # # ]: 0 : if (val & (0x1 << offset)) {
6852 : : int ret;
6853 : :
6854 : : /* Clear the event first */
6855 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6856 : : (0x1 << offset));
6857 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6858 : : /**
6859 : : * Only notify a VF reset event occurred,
6860 : : * don't trigger another SW reset
6861 : : */
6862 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6863 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6864 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6865 : : }
6866 : : }
6867 : : }
6868 : :
6869 : : static void
6870 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6871 : : {
6872 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6873 : : int i;
6874 : :
6875 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6876 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6877 : 0 : }
6878 : :
6879 : : static void
6880 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6881 : : {
6882 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6883 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6884 : : struct i40e_arq_event_info info;
6885 : : uint16_t pending, opcode;
6886 : 0 : uint8_t msg_buf[I40E_AQ_BUF_SZ] = {0};
6887 : : int ret;
6888 : :
6889 : 0 : info.buf_len = sizeof(msg_buf);
6890 : 0 : info.msg_buf = msg_buf;
6891 : :
6892 : 0 : pending = 1;
6893 [ # # ]: 0 : while (pending) {
6894 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6895 : :
6896 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6897 : 0 : PMD_DRV_LOG(INFO,
6898 : : "Failed to read msg from AdminQ, aq_err: %u",
6899 : : hw->aq.asq_last_status);
6900 : 0 : break;
6901 : : }
6902 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6903 : :
6904 [ # # # ]: 0 : switch (opcode) {
6905 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6906 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6907 : 0 : i40e_pf_host_handle_vf_msg(dev,
6908 : 0 : rte_le_to_cpu_16(info.desc.retval),
6909 : : rte_le_to_cpu_32(info.desc.cookie_high),
6910 : : rte_le_to_cpu_32(info.desc.cookie_low),
6911 : 0 : info.msg_buf,
6912 : 0 : info.msg_len);
6913 : 0 : break;
6914 : 0 : case i40e_aqc_opc_get_link_status:
6915 : 0 : ret = i40e_dev_link_update(dev, 0);
6916 : : /* Some devices require MAC config to be applied when the link comes up. */
6917 [ # # ]: 0 : if (!ret) {
6918 [ # # # # ]: 0 : if (pf->mac_config_on_link_up && dev->data->dev_link.link_status) {
6919 : : uint16_t max_frame_size;
6920 : :
6921 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
6922 : : dev->data->mtu + I40E_ETH_OVERHEAD :
6923 : : I40E_FRAME_SIZE_MAX;
6924 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE,
6925 : : false, 0, NULL);
6926 : 0 : pf->mac_config_on_link_up = false;
6927 : : }
6928 : 0 : rte_eth_dev_callback_process(dev,
6929 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6930 : : }
6931 : : break;
6932 : 0 : default:
6933 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6934 : : opcode);
6935 : 0 : break;
6936 : : }
6937 : : }
6938 : 0 : }
6939 : :
6940 : : static void
6941 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6942 : : {
6943 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6944 : : #define I40E_MDD_CLEAR16 0xFFFF
6945 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6946 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6947 : : bool mdd_detected = false;
6948 : : struct i40e_pf_vf *vf;
6949 : : uint32_t reg;
6950 : : int i;
6951 : :
6952 : : /* find what triggered the MDD event */
6953 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6954 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6955 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6956 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6957 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6958 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6959 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6960 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6961 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6962 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6963 : 0 : hw->func_caps.base_queue;
6964 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6965 : : "queue %d PF number 0x%02x VF number 0x%02x device %s",
6966 : : event, queue, pf_num, vf_num, dev->data->name);
6967 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6968 : : mdd_detected = true;
6969 : : }
6970 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6971 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6972 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6973 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6974 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6975 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6976 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6977 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6978 : 0 : hw->func_caps.base_queue;
6979 : :
6980 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6981 : : "queue %d of function 0x%02x device %s",
6982 : : event, queue, func, dev->data->name);
6983 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6984 : : mdd_detected = true;
6985 : : }
6986 : :
6987 [ # # ]: 0 : if (mdd_detected) {
6988 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6989 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6990 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6991 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF");
6992 : : }
6993 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6994 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6995 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6996 : : I40E_MDD_CLEAR16);
6997 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF");
6998 : : }
6999 : : }
7000 : :
7001 : : /* see if one of the VFs needs its hand slapped */
7002 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
7003 : 0 : vf = &pf->vfs[i];
7004 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
7005 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7006 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
7007 : : I40E_MDD_CLEAR16);
7008 : 0 : vf->num_mdd_events++;
7009 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
7010 : : PRIu64 "times",
7011 : : i, vf->num_mdd_events);
7012 : : }
7013 : :
7014 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
7015 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7016 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
7017 : : I40E_MDD_CLEAR16);
7018 : 0 : vf->num_mdd_events++;
7019 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
7020 : : PRIu64 "times",
7021 : : i, vf->num_mdd_events);
7022 : : }
7023 : : }
7024 : 0 : }
7025 : :
7026 : : /**
7027 : : * Interrupt handler triggered by NIC for handling
7028 : : * specific interrupt.
7029 : : *
7030 : : * @param handle
7031 : : * Pointer to interrupt handle.
7032 : : * @param param
7033 : : * The address of parameter (struct rte_eth_dev *) registered before.
7034 : : *
7035 : : * @return
7036 : : * void
7037 : : */
7038 : : static void
7039 : 0 : i40e_dev_interrupt_handler(void *param)
7040 : : {
7041 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7042 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7043 : : uint32_t icr0;
7044 : :
7045 : : /* Disable interrupt */
7046 : 0 : i40e_pf_disable_irq0(hw);
7047 : :
7048 : : /* read out interrupt causes */
7049 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7050 : :
7051 : : /* No interrupt event indicated */
7052 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
7053 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
7054 : 0 : goto done;
7055 : : }
7056 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7057 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7058 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7059 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7060 : 0 : i40e_handle_mdd_event(dev);
7061 : : }
7062 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7063 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7064 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7065 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7066 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7067 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7068 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7069 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7070 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7071 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7072 : :
7073 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7074 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7075 : 0 : i40e_dev_handle_vfr_event(dev);
7076 : : }
7077 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7078 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7079 : 0 : i40e_dev_handle_aq_msg(dev);
7080 : : }
7081 : :
7082 : 0 : done:
7083 : : /* Enable interrupt */
7084 : 0 : i40e_pf_enable_irq0(hw);
7085 : 0 : }
7086 : :
7087 : : static void
7088 : 0 : i40e_dev_alarm_handler(void *param)
7089 : : {
7090 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7091 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7092 : : uint32_t icr0;
7093 : :
7094 : : /* Disable interrupt */
7095 : 0 : i40e_pf_disable_irq0(hw);
7096 : :
7097 : : /* read out interrupt causes */
7098 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7099 : :
7100 : : /* No interrupt event indicated */
7101 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
7102 : 0 : goto done;
7103 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7104 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7105 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7106 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7107 : 0 : i40e_handle_mdd_event(dev);
7108 : : }
7109 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7110 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7111 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7112 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7113 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7114 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7115 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7116 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7117 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7118 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7119 : :
7120 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7121 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7122 : 0 : i40e_dev_handle_vfr_event(dev);
7123 : : }
7124 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7125 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7126 : 0 : i40e_dev_handle_aq_msg(dev);
7127 : : }
7128 : :
7129 : 0 : done:
7130 : : /* Enable interrupt */
7131 : 0 : i40e_pf_enable_irq0(hw);
7132 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7133 : : i40e_dev_alarm_handler, dev);
7134 : 0 : }
7135 : :
7136 : : int
7137 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7138 : : struct i40e_macvlan_filter *filter,
7139 : : int total)
7140 : : {
7141 : : int ele_num, ele_buff_size;
7142 : : int num, actual_num, i;
7143 : : uint16_t flags;
7144 : : int ret = I40E_SUCCESS;
7145 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7146 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7147 : : struct i40e_aqc_add_macvlan_element_data *req_list =
7148 : : (struct i40e_aqc_add_macvlan_element_data *)aq_buff;
7149 : :
7150 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7151 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7152 : 0 : return I40E_ERR_NO_MEMORY;
7153 : : }
7154 : :
7155 [ # # ]: 0 : if (filter == NULL || total == 0)
7156 : : return I40E_ERR_PARAM;
7157 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7158 : : ele_buff_size = hw->aq.asq_buf_size;
7159 : :
7160 : : num = 0;
7161 : : do {
7162 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7163 : 0 : memset(req_list, 0, ele_buff_size);
7164 : :
7165 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7166 : 0 : memcpy(req_list[i].mac_addr,
7167 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7168 : 0 : req_list[i].vlan_tag =
7169 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7170 : :
7171 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7172 : : case I40E_MAC_PERFECT_MATCH:
7173 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7174 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7175 : : break;
7176 : : case I40E_MACVLAN_PERFECT_MATCH:
7177 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7178 : : break;
7179 : : case I40E_MAC_HASH_MATCH:
7180 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7181 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7182 : : break;
7183 : : case I40E_MACVLAN_HASH_MATCH:
7184 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7185 : : break;
7186 : 0 : default:
7187 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7188 : 0 : return I40E_ERR_PARAM;
7189 : : }
7190 : :
7191 : 0 : req_list[i].queue_number = 0;
7192 : :
7193 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7194 : : }
7195 : :
7196 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7197 : : actual_num, NULL);
7198 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7199 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7200 : 0 : return ret;
7201 : : }
7202 : 0 : num += actual_num;
7203 [ # # ]: 0 : } while (num < total);
7204 : : return I40E_SUCCESS;
7205 : : }
7206 : :
7207 : : int
7208 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7209 : : struct i40e_macvlan_filter *filter,
7210 : : int total)
7211 : : {
7212 : : int ele_num, ele_buff_size;
7213 : : int num, actual_num, i;
7214 : : uint16_t flags;
7215 : : int ret = I40E_SUCCESS;
7216 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7217 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7218 : : struct i40e_aqc_remove_macvlan_element_data *req_list =
7219 : : (struct i40e_aqc_remove_macvlan_element_data *)aq_buff;
7220 : : enum i40e_admin_queue_err aq_status;
7221 : :
7222 [ # # ]: 0 : if (filter == NULL || total == 0)
7223 : : return I40E_ERR_PARAM;
7224 : :
7225 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7226 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7227 : 0 : return I40E_ERR_NO_MEMORY;
7228 : : }
7229 : :
7230 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7231 : : ele_buff_size = hw->aq.asq_buf_size;
7232 : :
7233 : : num = 0;
7234 : : do {
7235 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7236 : 0 : memset(req_list, 0, ele_buff_size);
7237 : :
7238 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7239 : 0 : memcpy(req_list[i].mac_addr,
7240 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7241 : 0 : req_list[i].vlan_tag =
7242 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7243 : :
7244 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7245 : : case I40E_MAC_PERFECT_MATCH:
7246 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7247 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7248 : : break;
7249 : : case I40E_MACVLAN_PERFECT_MATCH:
7250 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7251 : : break;
7252 : : case I40E_MAC_HASH_MATCH:
7253 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7254 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7255 : : break;
7256 : : case I40E_MACVLAN_HASH_MATCH:
7257 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7258 : : break;
7259 : 0 : default:
7260 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7261 : 0 : return I40E_ERR_PARAM;
7262 : : }
7263 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7264 : : }
7265 : :
7266 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7267 : : actual_num, NULL, &aq_status);
7268 : :
7269 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7270 : : /* Do not report as an error when firmware returns ENOENT */
7271 [ # # ]: 0 : if (aq_status != I40E_AQ_RC_ENOENT) {
7272 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7273 : 0 : return ret;
7274 : : }
7275 : : }
7276 : 0 : num += actual_num;
7277 [ # # ]: 0 : } while (num < total);
7278 : :
7279 : : return I40E_SUCCESS;
7280 : : }
7281 : :
7282 : : /* Find out specific MAC filter */
7283 : : static struct i40e_mac_filter *
7284 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7285 : : struct rte_ether_addr *macaddr)
7286 : : {
7287 : : struct i40e_mac_filter *f;
7288 : :
7289 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7290 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7291 : : return f;
7292 : : }
7293 : :
7294 : : return NULL;
7295 : : }
7296 : :
7297 : : static bool
7298 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7299 : : uint16_t vlan_id)
7300 : : {
7301 : : uint32_t vid_idx, vid_bit;
7302 : :
7303 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7304 : : return 0;
7305 : :
7306 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7307 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7308 : :
7309 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7310 : : return 1;
7311 : : else
7312 : : return 0;
7313 : : }
7314 : :
7315 : : static void
7316 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7317 : : uint16_t vlan_id, bool on)
7318 : : {
7319 : : uint32_t vid_idx, vid_bit;
7320 : :
7321 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7322 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7323 : :
7324 [ # # ]: 0 : if (on)
7325 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7326 : : else
7327 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7328 : : }
7329 : :
7330 : : void
7331 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7332 : : uint16_t vlan_id, bool on)
7333 : : {
7334 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7335 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7336 : : int ret;
7337 : :
7338 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7339 : 0 : return;
7340 : :
7341 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7342 : :
7343 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7344 : : return;
7345 : :
7346 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7347 : :
7348 [ # # ]: 0 : if (on) {
7349 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7350 : : &vlan_data, 1, NULL);
7351 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7352 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7353 : : } else {
7354 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7355 : : &vlan_data, 1, NULL);
7356 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7357 : 0 : PMD_DRV_LOG(ERR,
7358 : : "Failed to remove vlan filter");
7359 : : }
7360 : : }
7361 : :
7362 : : /**
7363 : : * Find all vlan options for specific mac addr,
7364 : : * return with actual vlan found.
7365 : : */
7366 : : int
7367 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7368 : : struct i40e_macvlan_filter *mv_f,
7369 : : int num, struct rte_ether_addr *addr)
7370 : : {
7371 : : int i;
7372 : : uint32_t j, k;
7373 : :
7374 : : /**
7375 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7376 : : * although the code looks complex.
7377 : : */
7378 [ # # ]: 0 : if (num < vsi->vlan_num)
7379 : : return I40E_ERR_PARAM;
7380 : :
7381 : : i = 0;
7382 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7383 [ # # ]: 0 : if (vsi->vfta[j]) {
7384 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7385 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7386 [ # # ]: 0 : if (i > num - 1) {
7387 : 0 : PMD_DRV_LOG(ERR,
7388 : : "vlan number doesn't match");
7389 : 0 : return I40E_ERR_PARAM;
7390 : : }
7391 : 0 : memcpy(&mv_f[i].macaddr,
7392 : : addr, ETH_ADDR_LEN);
7393 : 0 : mv_f[i].vlan_id =
7394 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7395 : 0 : i++;
7396 : : }
7397 : : }
7398 : : }
7399 : : }
7400 : : return I40E_SUCCESS;
7401 : : }
7402 : :
7403 : : static inline int
7404 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7405 : : struct i40e_macvlan_filter *mv_f,
7406 : : int num,
7407 : : uint16_t vlan)
7408 : : {
7409 : : int i = 0;
7410 : : struct i40e_mac_filter *f;
7411 : :
7412 [ # # ]: 0 : if (num < vsi->mac_num)
7413 : : return I40E_ERR_PARAM;
7414 : :
7415 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7416 [ # # ]: 0 : if (i > num - 1) {
7417 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7418 : 0 : return I40E_ERR_PARAM;
7419 : : }
7420 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7421 : : ETH_ADDR_LEN);
7422 : 0 : mv_f[i].vlan_id = vlan;
7423 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7424 : 0 : i++;
7425 : : }
7426 : :
7427 : : return I40E_SUCCESS;
7428 : : }
7429 : :
7430 : : static int
7431 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7432 : : {
7433 : : int i, j, num;
7434 : : struct i40e_mac_filter *f;
7435 : : struct i40e_macvlan_filter *mv_f;
7436 : : int ret = I40E_SUCCESS;
7437 : :
7438 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7439 : : return I40E_ERR_PARAM;
7440 : :
7441 : : /* Case that no vlan is set */
7442 [ # # ]: 0 : if (vsi->vlan_num == 0)
7443 : 0 : num = vsi->mac_num;
7444 : : else
7445 : 0 : num = vsi->mac_num * vsi->vlan_num;
7446 : :
7447 : 0 : mv_f = calloc(num, sizeof(*mv_f));
7448 [ # # ]: 0 : if (mv_f == NULL) {
7449 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7450 : 0 : return I40E_ERR_NO_MEMORY;
7451 : : }
7452 : :
7453 : : i = 0;
7454 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7455 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7456 : 0 : memcpy(&mv_f[i].macaddr,
7457 : 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7458 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7459 : 0 : mv_f[i].vlan_id = 0;
7460 : 0 : i++;
7461 : : }
7462 : : } else {
7463 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7464 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7465 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7466 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7467 : 0 : goto DONE;
7468 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7469 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7470 : : i += vsi->vlan_num;
7471 : : }
7472 : : }
7473 : :
7474 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7475 : 0 : DONE:
7476 : 0 : free(mv_f);
7477 : :
7478 : 0 : return ret;
7479 : : }
7480 : :
7481 : : int
7482 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7483 : : {
7484 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7485 : : int mac_num;
7486 : : int ret = I40E_SUCCESS;
7487 : :
7488 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7489 : : return I40E_ERR_PARAM;
7490 : :
7491 : : /* If it's already set, just return */
7492 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7493 : : return I40E_SUCCESS;
7494 : :
7495 : 0 : mac_num = vsi->mac_num;
7496 : :
7497 [ # # ]: 0 : if (mac_num == 0) {
7498 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7499 : 0 : return I40E_ERR_PARAM;
7500 : : }
7501 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7502 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7503 : 0 : return I40E_ERR_PARAM;
7504 : : }
7505 : :
7506 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7507 : :
7508 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7509 : : return ret;
7510 : :
7511 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7512 : :
7513 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7514 : : return ret;
7515 : :
7516 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7517 : :
7518 : 0 : vsi->vlan_num++;
7519 : 0 : return I40E_SUCCESS;
7520 : : }
7521 : :
7522 : : int
7523 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7524 : : {
7525 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7526 : : int mac_num;
7527 : : int ret = I40E_SUCCESS;
7528 : :
7529 : : /**
7530 : : * Vlan 0 is the generic filter for untagged packets
7531 : : * and can't be removed.
7532 : : */
7533 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7534 : : return I40E_ERR_PARAM;
7535 : :
7536 : : /* If can't find it, just return */
7537 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7538 : : return I40E_ERR_PARAM;
7539 : :
7540 : 0 : mac_num = vsi->mac_num;
7541 : :
7542 [ # # ]: 0 : if (mac_num == 0) {
7543 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7544 : 0 : return I40E_ERR_PARAM;
7545 : : }
7546 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7547 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7548 : 0 : return I40E_ERR_PARAM;
7549 : : }
7550 : :
7551 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7552 : :
7553 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7554 : : return ret;
7555 : :
7556 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7557 : :
7558 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7559 : : return ret;
7560 : :
7561 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7562 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7563 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7564 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7565 : : return ret;
7566 : :
7567 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7568 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7569 : : return ret;
7570 : : }
7571 : :
7572 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7573 : :
7574 : 0 : vsi->vlan_num--;
7575 : 0 : return I40E_SUCCESS;
7576 : : }
7577 : :
7578 : : int
7579 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7580 : : {
7581 : : struct i40e_mac_filter *f;
7582 : : struct i40e_macvlan_filter *mv_f;
7583 : : int i, vlan_num = 0;
7584 : : int ret = I40E_SUCCESS;
7585 : :
7586 : : /* If it's add and we've config it, return */
7587 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7588 [ # # ]: 0 : if (f != NULL)
7589 : : return I40E_SUCCESS;
7590 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7591 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7592 : :
7593 : : /**
7594 : : * If vlan_num is 0, that's the first time to add mac,
7595 : : * set mask for vlan_id 0.
7596 : : */
7597 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7598 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7599 : 0 : vsi->vlan_num = 1;
7600 : : }
7601 : 0 : vlan_num = vsi->vlan_num;
7602 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7603 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7604 : : vlan_num = 1;
7605 : :
7606 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7607 [ # # ]: 0 : if (mv_f == NULL) {
7608 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7609 : 0 : return I40E_ERR_NO_MEMORY;
7610 : : }
7611 : :
7612 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7613 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7614 : 0 : memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7615 : : ETH_ADDR_LEN);
7616 : : }
7617 : :
7618 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7619 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7620 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7621 : : &mac_filter->mac_addr);
7622 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7623 : 0 : goto DONE;
7624 : : }
7625 : :
7626 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7627 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7628 : 0 : goto DONE;
7629 : :
7630 : : /* Add the mac addr into mac list */
7631 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7632 [ # # ]: 0 : if (f == NULL) {
7633 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7634 : : ret = I40E_ERR_NO_MEMORY;
7635 : 0 : goto DONE;
7636 : : }
7637 : 0 : memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7638 : : ETH_ADDR_LEN);
7639 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7640 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7641 : 0 : vsi->mac_num++;
7642 : :
7643 : : ret = I40E_SUCCESS;
7644 : 0 : DONE:
7645 : 0 : free(mv_f);
7646 : :
7647 : 0 : return ret;
7648 : : }
7649 : :
7650 : : int
7651 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7652 : : {
7653 : : struct i40e_mac_filter *f;
7654 : : struct i40e_macvlan_filter *mv_f;
7655 : : int i, vlan_num;
7656 : : enum i40e_mac_filter_type filter_type;
7657 : : int ret = I40E_SUCCESS;
7658 : :
7659 : : /* Can't find it, return an error */
7660 : : f = i40e_find_mac_filter(vsi, addr);
7661 [ # # ]: 0 : if (f == NULL)
7662 : : return I40E_ERR_PARAM;
7663 : :
7664 : 0 : vlan_num = vsi->vlan_num;
7665 : 0 : filter_type = f->mac_info.filter_type;
7666 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7667 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7668 [ # # ]: 0 : if (vlan_num == 0) {
7669 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7670 : 0 : return I40E_ERR_PARAM;
7671 : : }
7672 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7673 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7674 : : vlan_num = 1;
7675 : :
7676 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7677 [ # # ]: 0 : if (mv_f == NULL) {
7678 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7679 : 0 : return I40E_ERR_NO_MEMORY;
7680 : : }
7681 : :
7682 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7683 : 0 : mv_f[i].filter_type = filter_type;
7684 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7685 : : ETH_ADDR_LEN);
7686 : : }
7687 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7688 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7689 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7690 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7691 : 0 : goto DONE;
7692 : : }
7693 : :
7694 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7695 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7696 : 0 : goto DONE;
7697 : :
7698 : : /* Remove the mac addr into mac list */
7699 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7700 : 0 : rte_free(f);
7701 : 0 : vsi->mac_num--;
7702 : :
7703 : : ret = I40E_SUCCESS;
7704 : 0 : DONE:
7705 : 0 : free(mv_f);
7706 : 0 : return ret;
7707 : : }
7708 : :
7709 : : /* Configure hash enable flags for RSS */
7710 : : uint64_t
7711 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7712 : : {
7713 : : uint64_t hena = 0;
7714 : : int i;
7715 : :
7716 [ # # ]: 0 : if (!flags)
7717 : : return hena;
7718 : :
7719 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7720 [ # # ]: 0 : if (flags & RTE_BIT64(i))
7721 : 0 : hena |= adapter->pctypes_tbl[i];
7722 : : }
7723 : :
7724 : : return hena;
7725 : : }
7726 : :
7727 : : /* Parse the hash enable flags */
7728 : : uint64_t
7729 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7730 : : {
7731 : : uint64_t rss_hf = 0;
7732 : :
7733 [ # # ]: 0 : if (!flags)
7734 : : return rss_hf;
7735 : : int i;
7736 : :
7737 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7738 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7739 : 0 : rss_hf |= RTE_BIT64(i);
7740 : : }
7741 : : return rss_hf;
7742 : : }
7743 : :
7744 : : /* Disable RSS */
7745 : : void
7746 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7747 : : {
7748 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7749 : :
7750 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7751 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7752 : 0 : I40E_WRITE_FLUSH(hw);
7753 : 0 : }
7754 : :
7755 : : int
7756 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7757 : : {
7758 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7759 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7760 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7761 : : I40E_VFQF_HKEY_MAX_INDEX :
7762 : : I40E_PFQF_HKEY_MAX_INDEX;
7763 : :
7764 [ # # ]: 0 : if (!key || key_len == 0) {
7765 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7766 : 0 : return 0;
7767 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7768 : : sizeof(uint32_t)) {
7769 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7770 : 0 : return -EINVAL;
7771 : : }
7772 : :
7773 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7774 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7775 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7776 : : enum i40e_status_code status =
7777 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7778 : :
7779 [ # # ]: 0 : if (status) {
7780 : 0 : PMD_DRV_LOG(ERR,
7781 : : "Failed to configure RSS key via AQ, error status: %d",
7782 : : status);
7783 : 0 : return -EIO;
7784 : : }
7785 : : } else {
7786 : : uint32_t *hash_key = (uint32_t *)key;
7787 : : uint16_t i;
7788 : :
7789 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7790 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7791 : 0 : I40E_WRITE_REG(
7792 : : hw,
7793 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7794 : : hash_key[i]);
7795 : :
7796 : : } else {
7797 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7798 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7799 : : hash_key[i]);
7800 : : }
7801 : 0 : I40E_WRITE_FLUSH(hw);
7802 : : }
7803 : :
7804 : : return 0;
7805 : : }
7806 : :
7807 : : static int
7808 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7809 : : {
7810 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7811 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7812 : : uint32_t reg;
7813 : : int ret;
7814 : :
7815 [ # # ]: 0 : if (!key || !key_len)
7816 : : return 0;
7817 : :
7818 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7819 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7820 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7821 [ # # ]: 0 : if (ret) {
7822 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7823 : 0 : return ret;
7824 : : }
7825 : : } else {
7826 : : uint32_t *key_dw = (uint32_t *)key;
7827 : : uint16_t i;
7828 : :
7829 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7830 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7831 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7832 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7833 : : }
7834 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7835 : : sizeof(uint32_t);
7836 : : } else {
7837 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7838 : 0 : reg = I40E_PFQF_HKEY(i);
7839 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7840 : : }
7841 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7842 : : sizeof(uint32_t);
7843 : : }
7844 : : }
7845 : : return 0;
7846 : : }
7847 : :
7848 : : static int
7849 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7850 : : {
7851 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7852 : : uint64_t hena;
7853 : : int ret;
7854 : :
7855 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7856 : 0 : rss_conf->rss_key_len);
7857 [ # # ]: 0 : if (ret)
7858 : : return ret;
7859 : :
7860 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7861 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7862 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7863 : 0 : I40E_WRITE_FLUSH(hw);
7864 : :
7865 : 0 : return 0;
7866 : : }
7867 : :
7868 : : static int
7869 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7870 : : struct rte_eth_rss_conf *rss_conf)
7871 : : {
7872 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7873 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7874 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7875 : : uint64_t hena;
7876 : :
7877 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7878 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7879 : :
7880 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7881 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7882 : : return -EINVAL;
7883 : 0 : return 0; /* Nothing to do */
7884 : : }
7885 : : /* RSS enabled */
7886 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7887 : : return -EINVAL;
7888 : :
7889 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7890 : : }
7891 : :
7892 : : static int
7893 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7894 : : struct rte_eth_rss_conf *rss_conf)
7895 : : {
7896 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7897 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7898 : : uint64_t hena;
7899 : : int ret;
7900 : :
7901 [ # # ]: 0 : if (!rss_conf)
7902 : : return -EINVAL;
7903 : :
7904 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7905 : : &rss_conf->rss_key_len);
7906 [ # # ]: 0 : if (ret)
7907 : : return ret;
7908 : :
7909 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7910 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7911 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7912 : :
7913 : 0 : return 0;
7914 : : }
7915 : :
7916 : : static int
7917 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7918 : : {
7919 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7920 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7921 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7922 : 0 : break;
7923 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7924 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7925 : 0 : break;
7926 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7927 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7928 : 0 : break;
7929 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7930 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7931 : 0 : break;
7932 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7933 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7934 : 0 : break;
7935 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7936 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7937 : 0 : break;
7938 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7939 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7940 : 0 : break;
7941 : 0 : default:
7942 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7943 : 0 : return -EINVAL;
7944 : : }
7945 : :
7946 : : return 0;
7947 : : }
7948 : :
7949 : : /* Convert tunnel filter structure */
7950 : : static int
7951 [ # # ]: 0 : i40e_tunnel_filter_convert(
7952 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7953 : : struct i40e_tunnel_filter *tunnel_filter)
7954 : : {
7955 : : rte_ether_addr_copy((struct rte_ether_addr *)
7956 : : &cld_filter->element.outer_mac,
7957 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7958 : : rte_ether_addr_copy((struct rte_ether_addr *)
7959 : : &cld_filter->element.inner_mac,
7960 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7961 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7962 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7963 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7964 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7965 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7966 : : else
7967 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7968 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7969 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7970 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7971 : 0 : memcpy(tunnel_filter->input.general_fields,
7972 : 0 : cld_filter->general_fields,
7973 : : sizeof(cld_filter->general_fields));
7974 : :
7975 : 0 : return 0;
7976 : : }
7977 : :
7978 : : /* Check if there exists the tunnel filter */
7979 : : struct i40e_tunnel_filter *
7980 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7981 : : const struct i40e_tunnel_filter_input *input)
7982 : : {
7983 : : int ret;
7984 : :
7985 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7986 [ # # ]: 0 : if (ret < 0)
7987 : : return NULL;
7988 : :
7989 : 0 : return tunnel_rule->hash_map[ret];
7990 : : }
7991 : :
7992 : : /* Add a tunnel filter into the SW list */
7993 : : static int
7994 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7995 : : struct i40e_tunnel_filter *tunnel_filter)
7996 : : {
7997 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7998 : : int ret;
7999 : :
8000 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
8001 [ # # ]: 0 : if (ret < 0) {
8002 : 0 : PMD_DRV_LOG(ERR,
8003 : : "Failed to insert tunnel filter to hash table %d!",
8004 : : ret);
8005 : 0 : return ret;
8006 : : }
8007 : 0 : rule->hash_map[ret] = tunnel_filter;
8008 : :
8009 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
8010 : :
8011 : 0 : return 0;
8012 : : }
8013 : :
8014 : : /* Delete a tunnel filter from the SW list */
8015 : : int
8016 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
8017 : : struct i40e_tunnel_filter_input *input)
8018 : : {
8019 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8020 : : struct i40e_tunnel_filter *tunnel_filter;
8021 : : int ret;
8022 : :
8023 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
8024 [ # # ]: 0 : if (ret < 0) {
8025 : 0 : PMD_DRV_LOG(ERR,
8026 : : "Failed to delete tunnel filter to hash table %d!",
8027 : : ret);
8028 : 0 : return ret;
8029 : : }
8030 : 0 : tunnel_filter = rule->hash_map[ret];
8031 : 0 : rule->hash_map[ret] = NULL;
8032 : :
8033 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
8034 : 0 : rte_free(tunnel_filter);
8035 : :
8036 : 0 : return 0;
8037 : : }
8038 : :
8039 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8040 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8041 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
8042 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8043 : : #define I40E_TR_GRE_KEY_MASK 0x400
8044 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8045 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8046 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
8047 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
8048 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
8049 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
8050 : : #define I40E_TR_L4_TYPE_TCP 0x2
8051 : : #define I40E_TR_L4_TYPE_UDP 0x4
8052 : : #define I40E_TR_L4_TYPE_SCTP 0x8
8053 : :
8054 : : static enum
8055 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8056 : : {
8057 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8058 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8059 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8060 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8061 : : enum i40e_status_code status = I40E_SUCCESS;
8062 : :
8063 [ # # ]: 0 : if (pf->support_multi_driver) {
8064 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8065 : 0 : return I40E_NOT_SUPPORTED;
8066 : : }
8067 : :
8068 : : memset(&filter_replace, 0,
8069 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8070 : : memset(&filter_replace_buf, 0,
8071 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8072 : :
8073 : : /* create L1 filter */
8074 : 0 : filter_replace.old_filter_type =
8075 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8076 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8077 : : filter_replace.tr_bit = 0;
8078 : :
8079 : : /* Prepare the buffer, 3 entries */
8080 : : filter_replace_buf.data[0] =
8081 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8082 : 0 : filter_replace_buf.data[0] |=
8083 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8084 : 0 : filter_replace_buf.data[2] = 0xFF;
8085 : 0 : filter_replace_buf.data[3] = 0xFF;
8086 : : filter_replace_buf.data[4] =
8087 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8088 : 0 : filter_replace_buf.data[4] |=
8089 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8090 : 0 : filter_replace_buf.data[7] = 0xF0;
8091 : : filter_replace_buf.data[8]
8092 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8093 : 0 : filter_replace_buf.data[8] |=
8094 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8095 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8096 : : I40E_TR_GENEVE_KEY_MASK |
8097 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8098 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8099 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8100 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
8101 : :
8102 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8103 : : &filter_replace_buf);
8104 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8105 [ # # ]: 0 : filter_replace.new_filter_type))
8106 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8107 : : " original: 0x%x, new: 0x%x",
8108 : : dev->device->name,
8109 : : filter_replace.old_filter_type,
8110 : : filter_replace.new_filter_type);
8111 : :
8112 : : return status;
8113 : : }
8114 : :
8115 : : static enum
8116 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8117 : : {
8118 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8119 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8120 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8121 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8122 : : enum i40e_status_code status = I40E_SUCCESS;
8123 : :
8124 [ # # ]: 0 : if (pf->support_multi_driver) {
8125 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8126 : 0 : return I40E_NOT_SUPPORTED;
8127 : : }
8128 : :
8129 : : /* For MPLSoUDP */
8130 : : memset(&filter_replace, 0,
8131 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8132 : : memset(&filter_replace_buf, 0,
8133 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8134 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8135 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8136 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8137 : 0 : filter_replace.new_filter_type =
8138 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8139 : : /* Prepare the buffer, 2 entries */
8140 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8141 : 0 : filter_replace_buf.data[0] |=
8142 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8143 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8144 : 0 : filter_replace_buf.data[4] |=
8145 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8146 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8147 : : &filter_replace_buf);
8148 [ # # ]: 0 : if (status < 0)
8149 : : return status;
8150 : 0 : if (filter_replace.old_filter_type !=
8151 [ # # ]: 0 : filter_replace.new_filter_type)
8152 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8153 : : " original: 0x%x, new: 0x%x",
8154 : : dev->device->name,
8155 : : filter_replace.old_filter_type,
8156 : : filter_replace.new_filter_type);
8157 : :
8158 : : /* For MPLSoGRE */
8159 : : memset(&filter_replace, 0,
8160 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8161 : : memset(&filter_replace_buf, 0,
8162 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8163 : :
8164 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8165 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8166 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8167 : 0 : filter_replace.new_filter_type =
8168 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8169 : : /* Prepare the buffer, 2 entries */
8170 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8171 : 0 : filter_replace_buf.data[0] |=
8172 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8173 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8174 : 0 : filter_replace_buf.data[4] |=
8175 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8176 : :
8177 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8178 : : &filter_replace_buf);
8179 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8180 [ # # ]: 0 : filter_replace.new_filter_type))
8181 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8182 : : " original: 0x%x, new: 0x%x",
8183 : : dev->device->name,
8184 : : filter_replace.old_filter_type,
8185 : : filter_replace.new_filter_type);
8186 : :
8187 : : return status;
8188 : : }
8189 : :
8190 : : static enum i40e_status_code
8191 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8192 : : {
8193 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8194 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8195 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8196 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8197 : : enum i40e_status_code status = I40E_SUCCESS;
8198 : :
8199 [ # # ]: 0 : if (pf->support_multi_driver) {
8200 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8201 : 0 : return I40E_NOT_SUPPORTED;
8202 : : }
8203 : :
8204 : : /* For GTP-C */
8205 : : memset(&filter_replace, 0,
8206 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8207 : : memset(&filter_replace_buf, 0,
8208 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8209 : : /* create L1 filter */
8210 : 0 : filter_replace.old_filter_type =
8211 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8212 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8213 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8214 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8215 : : /* Prepare the buffer, 2 entries */
8216 : : filter_replace_buf.data[0] =
8217 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8218 : 0 : filter_replace_buf.data[0] |=
8219 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8220 : 0 : filter_replace_buf.data[2] = 0xFF;
8221 : 0 : filter_replace_buf.data[3] = 0xFF;
8222 : : filter_replace_buf.data[4] =
8223 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8224 : 0 : filter_replace_buf.data[4] |=
8225 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8226 : 0 : filter_replace_buf.data[6] = 0xFF;
8227 : 0 : filter_replace_buf.data[7] = 0xFF;
8228 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8229 : : &filter_replace_buf);
8230 [ # # ]: 0 : if (status < 0)
8231 : : return status;
8232 : 0 : if (filter_replace.old_filter_type !=
8233 [ # # ]: 0 : filter_replace.new_filter_type)
8234 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8235 : : " original: 0x%x, new: 0x%x",
8236 : : dev->device->name,
8237 : : filter_replace.old_filter_type,
8238 : : filter_replace.new_filter_type);
8239 : :
8240 : : /* for GTP-U */
8241 : : memset(&filter_replace, 0,
8242 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8243 : : memset(&filter_replace_buf, 0,
8244 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8245 : : /* create L1 filter */
8246 : 0 : filter_replace.old_filter_type =
8247 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8248 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8249 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8250 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8251 : : /* Prepare the buffer, 2 entries */
8252 : : filter_replace_buf.data[0] =
8253 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8254 : 0 : filter_replace_buf.data[0] |=
8255 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8256 : 0 : filter_replace_buf.data[2] = 0xFF;
8257 : 0 : filter_replace_buf.data[3] = 0xFF;
8258 : : filter_replace_buf.data[4] =
8259 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8260 : 0 : filter_replace_buf.data[4] |=
8261 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8262 : 0 : filter_replace_buf.data[6] = 0xFF;
8263 : 0 : filter_replace_buf.data[7] = 0xFF;
8264 : :
8265 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8266 : : &filter_replace_buf);
8267 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8268 [ # # ]: 0 : filter_replace.new_filter_type))
8269 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8270 : : " original: 0x%x, new: 0x%x",
8271 : : dev->device->name,
8272 : : filter_replace.old_filter_type,
8273 : : filter_replace.new_filter_type);
8274 : :
8275 : : return status;
8276 : : }
8277 : :
8278 : : static enum
8279 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8280 : : {
8281 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8282 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8283 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8284 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8285 : : enum i40e_status_code status = I40E_SUCCESS;
8286 : :
8287 [ # # ]: 0 : if (pf->support_multi_driver) {
8288 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8289 : 0 : return I40E_NOT_SUPPORTED;
8290 : : }
8291 : :
8292 : : /* for GTP-C */
8293 : : memset(&filter_replace, 0,
8294 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8295 : : memset(&filter_replace_buf, 0,
8296 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8297 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8298 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8299 : 0 : filter_replace.new_filter_type =
8300 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8301 : : /* Prepare the buffer, 2 entries */
8302 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8303 : 0 : filter_replace_buf.data[0] |=
8304 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8305 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8306 : 0 : filter_replace_buf.data[4] |=
8307 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8308 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8309 : : &filter_replace_buf);
8310 [ # # ]: 0 : if (status < 0)
8311 : : return status;
8312 : 0 : if (filter_replace.old_filter_type !=
8313 [ # # ]: 0 : filter_replace.new_filter_type)
8314 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8315 : : " original: 0x%x, new: 0x%x",
8316 : : dev->device->name,
8317 : : filter_replace.old_filter_type,
8318 : : filter_replace.new_filter_type);
8319 : :
8320 : : /* for GTP-U */
8321 : : memset(&filter_replace, 0,
8322 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8323 : : memset(&filter_replace_buf, 0,
8324 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8325 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8326 : 0 : filter_replace.old_filter_type =
8327 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8328 : 0 : filter_replace.new_filter_type =
8329 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8330 : : /* Prepare the buffer, 2 entries */
8331 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8332 : 0 : filter_replace_buf.data[0] |=
8333 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8334 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8335 : 0 : filter_replace_buf.data[4] |=
8336 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8337 : :
8338 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8339 : : &filter_replace_buf);
8340 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8341 [ # # ]: 0 : filter_replace.new_filter_type))
8342 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8343 : : " original: 0x%x, new: 0x%x",
8344 : : dev->device->name,
8345 : : filter_replace.old_filter_type,
8346 : : filter_replace.new_filter_type);
8347 : :
8348 : : return status;
8349 : : }
8350 : :
8351 : : static enum i40e_status_code
8352 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8353 : : enum i40e_l4_port_type l4_port_type)
8354 : : {
8355 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8356 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8357 : : enum i40e_status_code status = I40E_SUCCESS;
8358 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8359 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8360 : :
8361 [ # # ]: 0 : if (pf->support_multi_driver) {
8362 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8363 : 0 : return I40E_NOT_SUPPORTED;
8364 : : }
8365 : :
8366 : : memset(&filter_replace, 0,
8367 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8368 : : memset(&filter_replace_buf, 0,
8369 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8370 : :
8371 : : /* create L1 filter */
8372 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8373 : 0 : filter_replace.old_filter_type =
8374 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8375 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8376 : 0 : filter_replace_buf.data[8] =
8377 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8378 : : } else {
8379 : 0 : filter_replace.old_filter_type =
8380 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8381 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8382 : 0 : filter_replace_buf.data[8] =
8383 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8384 : : }
8385 : :
8386 : : filter_replace.tr_bit = 0;
8387 : : /* Prepare the buffer, 3 entries */
8388 : : filter_replace_buf.data[0] =
8389 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8390 : 0 : filter_replace_buf.data[0] |=
8391 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8392 : : filter_replace_buf.data[2] = 0x00;
8393 : 0 : filter_replace_buf.data[3] =
8394 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8395 : : filter_replace_buf.data[4] =
8396 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8397 : 0 : filter_replace_buf.data[4] |=
8398 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8399 : : filter_replace_buf.data[5] = 0x00;
8400 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8401 : : I40E_TR_L4_TYPE_TCP |
8402 : : I40E_TR_L4_TYPE_SCTP;
8403 : : filter_replace_buf.data[7] = 0x00;
8404 : 0 : filter_replace_buf.data[8] |=
8405 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8406 : : filter_replace_buf.data[9] = 0x00;
8407 : 0 : filter_replace_buf.data[10] = 0xFF;
8408 : 0 : filter_replace_buf.data[11] = 0xFF;
8409 : :
8410 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8411 : : &filter_replace_buf);
8412 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8413 [ # # ]: 0 : filter_replace.new_filter_type)
8414 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8415 : : " original: 0x%x, new: 0x%x",
8416 : : dev->device->name,
8417 : : filter_replace.old_filter_type,
8418 : : filter_replace.new_filter_type);
8419 : :
8420 : : return status;
8421 : : }
8422 : :
8423 : : static enum i40e_status_code
8424 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8425 : : enum i40e_l4_port_type l4_port_type)
8426 : : {
8427 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8428 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8429 : : enum i40e_status_code status = I40E_SUCCESS;
8430 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8431 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8432 : :
8433 [ # # ]: 0 : if (pf->support_multi_driver) {
8434 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8435 : 0 : return I40E_NOT_SUPPORTED;
8436 : : }
8437 : :
8438 : : memset(&filter_replace, 0,
8439 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8440 : : memset(&filter_replace_buf, 0,
8441 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8442 : :
8443 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8444 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8445 : 0 : filter_replace.new_filter_type =
8446 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8447 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8448 : : } else {
8449 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8450 : 0 : filter_replace.new_filter_type =
8451 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8452 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8453 : : }
8454 : :
8455 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8456 : : filter_replace.tr_bit = 0;
8457 : : /* Prepare the buffer, 2 entries */
8458 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8459 : 0 : filter_replace_buf.data[0] |=
8460 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8461 : 0 : filter_replace_buf.data[4] |=
8462 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8463 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8464 : : &filter_replace_buf);
8465 : :
8466 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8467 [ # # ]: 0 : filter_replace.new_filter_type)
8468 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8469 : : " original: 0x%x, new: 0x%x",
8470 : : dev->device->name,
8471 : : filter_replace.old_filter_type,
8472 : : filter_replace.new_filter_type);
8473 : :
8474 : : return status;
8475 : : }
8476 : :
8477 : : int
8478 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8479 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8480 : : uint8_t add)
8481 : : {
8482 : : uint16_t ip_type;
8483 : : uint32_t ipv4_addr, ipv4_addr_le;
8484 : : uint8_t i, tun_type = 0;
8485 : : /* internal variable to convert ipv6 byte order */
8486 : : uint32_t convert_ipv6[4];
8487 : : int val, ret = 0;
8488 : : struct i40e_pf_vf *vf = NULL;
8489 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8490 : : struct i40e_vsi *vsi;
8491 : 0 : struct i40e_aqc_cloud_filters_element_bb cld_filter = {0};
8492 [ # # ]: 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8493 : : struct i40e_tunnel_filter *node;
8494 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8495 : : uint32_t teid_le;
8496 : : bool big_buffer = 0;
8497 : :
8498 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8499 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
8500 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8501 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
8502 : :
8503 : 0 : cld_filter.element.inner_vlan =
8504 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8505 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8506 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8507 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8508 : : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8509 : : memcpy(&cld_filter.element.ipaddr.v4.data,
8510 : : &ipv4_addr_le,
8511 : : sizeof(cld_filter.element.ipaddr.v4.data));
8512 : : } else {
8513 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8514 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8515 : 0 : convert_ipv6[i] =
8516 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8517 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8518 : : }
8519 : : memcpy(&cld_filter.element.ipaddr.v6.data,
8520 : : &convert_ipv6,
8521 : : sizeof(cld_filter.element.ipaddr.v6.data));
8522 : : }
8523 : :
8524 : : /* check tunneled type */
8525 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8526 : : case I40E_TUNNEL_TYPE_VXLAN:
8527 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8528 : : break;
8529 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8530 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8531 : 0 : break;
8532 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8533 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8534 : 0 : break;
8535 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8536 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8537 : 0 : i40e_replace_mpls_l1_filter(pf);
8538 : 0 : i40e_replace_mpls_cloud_filter(pf);
8539 : 0 : pf->mpls_replace_flag = 1;
8540 : : }
8541 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8542 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8543 : 0 : teid_le >> 4;
8544 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8545 : 0 : (teid_le & 0xF) << 12;
8546 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8547 : : 0x40;
8548 : : big_buffer = 1;
8549 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8550 : 0 : break;
8551 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8552 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8553 : 0 : i40e_replace_mpls_l1_filter(pf);
8554 : 0 : i40e_replace_mpls_cloud_filter(pf);
8555 : 0 : pf->mpls_replace_flag = 1;
8556 : : }
8557 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8558 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8559 : 0 : teid_le >> 4;
8560 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8561 : 0 : (teid_le & 0xF) << 12;
8562 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8563 : : 0x0;
8564 : : big_buffer = 1;
8565 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8566 : 0 : break;
8567 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8568 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8569 : 0 : i40e_replace_gtp_l1_filter(pf);
8570 : 0 : i40e_replace_gtp_cloud_filter(pf);
8571 : 0 : pf->gtp_replace_flag = 1;
8572 : : }
8573 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8574 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8575 : 0 : (teid_le >> 16) & 0xFFFF;
8576 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8577 : : teid_le & 0xFFFF;
8578 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8579 : : 0x0;
8580 : : big_buffer = 1;
8581 : 0 : break;
8582 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8583 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8584 : 0 : i40e_replace_gtp_l1_filter(pf);
8585 : 0 : i40e_replace_gtp_cloud_filter(pf);
8586 : 0 : pf->gtp_replace_flag = 1;
8587 : : }
8588 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8589 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8590 : 0 : (teid_le >> 16) & 0xFFFF;
8591 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8592 : : teid_le & 0xFFFF;
8593 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8594 : : 0x0;
8595 : : big_buffer = 1;
8596 : 0 : break;
8597 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8598 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8599 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8600 [ # # ]: 0 : if (ret < 0)
8601 : 0 : PMD_DRV_LOG(DEBUG,
8602 : : "QinQ tunnel filter already created.");
8603 : 0 : pf->qinq_replace_flag = 1;
8604 : : }
8605 : : /* Add in the General fields the values of
8606 : : * the Outer and Inner VLAN
8607 : : * Big Buffer should be set, see changes in
8608 : : * i40e_aq_add_cloud_filters
8609 : : */
8610 : 0 : cld_filter.general_fields[0] = tunnel_filter->inner_vlan;
8611 : 0 : cld_filter.general_fields[1] = tunnel_filter->outer_vlan;
8612 : : big_buffer = 1;
8613 : 0 : break;
8614 : 0 : case I40E_CLOUD_TYPE_UDP:
8615 : : case I40E_CLOUD_TYPE_TCP:
8616 : : case I40E_CLOUD_TYPE_SCTP:
8617 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8618 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8619 : 0 : i40e_replace_port_l1_filter(pf,
8620 : : tunnel_filter->l4_port_type);
8621 : 0 : i40e_replace_port_cloud_filter(pf,
8622 : : tunnel_filter->l4_port_type);
8623 : 0 : pf->sport_replace_flag = 1;
8624 : : }
8625 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8626 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8627 : : I40E_DIRECTION_INGRESS_KEY;
8628 : :
8629 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8630 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8631 : : I40E_TR_L4_TYPE_UDP;
8632 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8633 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8634 : : I40E_TR_L4_TYPE_TCP;
8635 : : else
8636 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8637 : : I40E_TR_L4_TYPE_SCTP;
8638 : :
8639 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8640 : 0 : (teid_le >> 16) & 0xFFFF;
8641 : : big_buffer = 1;
8642 : : } else {
8643 [ # # ]: 0 : if (!pf->dport_replace_flag) {
8644 : 0 : i40e_replace_port_l1_filter(pf,
8645 : : tunnel_filter->l4_port_type);
8646 : 0 : i40e_replace_port_cloud_filter(pf,
8647 : : tunnel_filter->l4_port_type);
8648 : 0 : pf->dport_replace_flag = 1;
8649 : : }
8650 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8651 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8652 : : I40E_DIRECTION_INGRESS_KEY;
8653 : :
8654 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8655 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8656 : : I40E_TR_L4_TYPE_UDP;
8657 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8658 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8659 : : I40E_TR_L4_TYPE_TCP;
8660 : : else
8661 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8662 : : I40E_TR_L4_TYPE_SCTP;
8663 : :
8664 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8665 : 0 : (teid_le >> 16) & 0xFFFF;
8666 : : big_buffer = 1;
8667 : : }
8668 : :
8669 : : break;
8670 : 0 : default:
8671 : : /* Other tunnel types is not supported. */
8672 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8673 : 0 : return -EINVAL;
8674 : : }
8675 : :
8676 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8677 : 0 : cld_filter.element.flags =
8678 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8679 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8680 : 0 : cld_filter.element.flags =
8681 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8682 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8683 : 0 : cld_filter.element.flags =
8684 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8685 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8686 : 0 : cld_filter.element.flags =
8687 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8688 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8689 : 0 : cld_filter.element.flags |=
8690 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8691 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8692 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8693 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8694 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8695 : 0 : cld_filter.element.flags |=
8696 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8697 : : else
8698 : 0 : cld_filter.element.flags |=
8699 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8700 : : } else {
8701 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8702 : : &cld_filter.element.flags);
8703 [ # # ]: 0 : if (val < 0) {
8704 : : return -EINVAL;
8705 : : }
8706 : : }
8707 : :
8708 : 0 : cld_filter.element.flags |=
8709 : 0 : rte_cpu_to_le_16(I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE | ip_type |
8710 : : (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8711 : 0 : cld_filter.element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8712 : 0 : cld_filter.element.queue_number =
8713 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8714 : :
8715 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8716 : 0 : vsi = pf->main_vsi;
8717 : : else {
8718 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8719 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8720 : 0 : return -EINVAL;
8721 : : }
8722 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8723 : 0 : vsi = vf->vsi;
8724 : : }
8725 : :
8726 : : /* Check if there is the filter in SW list */
8727 : : memset(&check_filter, 0, sizeof(check_filter));
8728 : 0 : i40e_tunnel_filter_convert(&cld_filter, &check_filter);
8729 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8730 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8731 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8732 [ # # ]: 0 : if (add && node) {
8733 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8734 : 0 : return -EINVAL;
8735 : : }
8736 : :
8737 [ # # ]: 0 : if (!add && !node) {
8738 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8739 : 0 : return -EINVAL;
8740 : : }
8741 : :
8742 [ # # ]: 0 : if (add) {
8743 : : struct i40e_tunnel_filter *tunnel;
8744 : :
8745 [ # # ]: 0 : if (big_buffer)
8746 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8747 : 0 : vsi->seid, &cld_filter, 1);
8748 : : else
8749 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8750 : 0 : vsi->seid, &cld_filter.element, 1);
8751 [ # # ]: 0 : if (ret < 0) {
8752 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8753 : 0 : return -ENOTSUP;
8754 : : }
8755 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8756 [ # # ]: 0 : if (tunnel == NULL) {
8757 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8758 : 0 : return -ENOMEM;
8759 : : }
8760 : :
8761 : : memcpy(tunnel, &check_filter, sizeof(check_filter));
8762 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8763 [ # # ]: 0 : if (ret < 0)
8764 : 0 : rte_free(tunnel);
8765 : : } else {
8766 [ # # ]: 0 : if (big_buffer)
8767 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8768 : 0 : hw, vsi->seid, &cld_filter, 1);
8769 : : else
8770 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8771 : : &cld_filter.element, 1);
8772 [ # # ]: 0 : if (ret < 0) {
8773 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8774 : 0 : return -ENOTSUP;
8775 : : }
8776 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8777 : : }
8778 : :
8779 : : return ret;
8780 : : }
8781 : :
8782 : : static int
8783 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8784 : : {
8785 : : uint8_t i;
8786 : :
8787 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8788 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8789 : : return i;
8790 : : }
8791 : :
8792 : : return -1;
8793 : : }
8794 : :
8795 : : static int
8796 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8797 : : {
8798 : : int idx, ret;
8799 : 0 : uint8_t filter_idx = 0;
8800 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8801 : :
8802 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8803 : :
8804 : : /* Check if port already exists */
8805 [ # # ]: 0 : if (idx >= 0) {
8806 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8807 : 0 : return -EINVAL;
8808 : : }
8809 : :
8810 : : /* Now check if there is space to add the new port */
8811 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8812 [ # # ]: 0 : if (idx < 0) {
8813 : 0 : PMD_DRV_LOG(ERR,
8814 : : "Maximum number of UDP ports reached, not adding port %d",
8815 : : port);
8816 : 0 : return -ENOSPC;
8817 : : }
8818 : :
8819 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8820 : : &filter_idx, NULL);
8821 [ # # ]: 0 : if (ret < 0) {
8822 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8823 : 0 : return -1;
8824 : : }
8825 : :
8826 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8827 : : port, filter_idx);
8828 : :
8829 : : /* New port: add it and mark its index in the bitmap */
8830 : 0 : pf->vxlan_ports[idx] = port;
8831 : 0 : pf->vxlan_bitmap |= (1 << idx);
8832 : :
8833 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8834 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8835 : :
8836 : : return 0;
8837 : : }
8838 : :
8839 : : static int
8840 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8841 : : {
8842 : : int idx;
8843 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8844 : :
8845 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8846 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8847 : 0 : return -EINVAL;
8848 : : }
8849 : :
8850 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8851 : :
8852 [ # # ]: 0 : if (idx < 0) {
8853 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8854 : 0 : return -EINVAL;
8855 : : }
8856 : :
8857 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8858 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8859 : 0 : return -1;
8860 : : }
8861 : :
8862 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8863 : : port, idx);
8864 : :
8865 : 0 : pf->vxlan_ports[idx] = 0;
8866 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8867 : :
8868 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8869 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8870 : :
8871 : : return 0;
8872 : : }
8873 : :
8874 : : /* Add UDP tunneling port */
8875 : : static int
8876 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8877 : : struct rte_eth_udp_tunnel *udp_tunnel)
8878 : : {
8879 : : int ret = 0;
8880 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8881 : :
8882 [ # # ]: 0 : if (udp_tunnel == NULL)
8883 : : return -EINVAL;
8884 : :
8885 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8886 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8887 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8888 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8889 : 0 : break;
8890 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8891 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8892 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8893 : 0 : break;
8894 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8895 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8896 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8897 : : ret = -1;
8898 : 0 : break;
8899 : :
8900 : 0 : default:
8901 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8902 : : ret = -1;
8903 : 0 : break;
8904 : : }
8905 : :
8906 : : return ret;
8907 : : }
8908 : :
8909 : : /* Remove UDP tunneling port */
8910 : : static int
8911 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8912 : : struct rte_eth_udp_tunnel *udp_tunnel)
8913 : : {
8914 : : int ret = 0;
8915 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8916 : :
8917 [ # # ]: 0 : if (udp_tunnel == NULL)
8918 : : return -EINVAL;
8919 : :
8920 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8921 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8922 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8923 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8924 : 0 : break;
8925 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8926 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8927 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8928 : : ret = -1;
8929 : 0 : break;
8930 : 0 : default:
8931 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8932 : : ret = -1;
8933 : 0 : break;
8934 : : }
8935 : :
8936 : : return ret;
8937 : : }
8938 : :
8939 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8940 : : uint16_t
8941 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8942 : : {
8943 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8944 : : int i;
8945 : : uint16_t num;
8946 : : struct ci_rx_queue *rxq;
8947 : :
8948 : : num = 0;
8949 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8950 : 0 : rxq = data->rx_queues[i];
8951 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8952 : 0 : num++;
8953 : : else
8954 : : break;
8955 : : }
8956 : :
8957 : 0 : return num;
8958 : : }
8959 : :
8960 : : /* Reset the global configure of hash function and input sets */
8961 : : static void
8962 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8963 : : {
8964 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8965 : : uint32_t reg, reg_val;
8966 : : int i;
8967 : :
8968 : : /* Reset global RSS function sets */
8969 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8970 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8971 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8972 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8973 : : }
8974 : :
8975 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8976 : : uint64_t inset;
8977 : : int j, pctype;
8978 : :
8979 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
8980 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8981 : : else
8982 : : pctype = i;
8983 : :
8984 : : /* Reset pctype insets */
8985 : 0 : inset = i40e_get_default_input_set(i);
8986 [ # # ]: 0 : if (inset) {
8987 : 0 : pf->hash_input_set[pctype] = inset;
8988 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
8989 : : inset);
8990 : :
8991 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
8992 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
8993 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
8994 : 0 : i40e_check_write_global_reg(hw, reg,
8995 : 0 : (uint32_t)(inset >> 32));
8996 : :
8997 : : /* Clear unused mask registers of the pctype */
8998 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
8999 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
9000 : 0 : i40e_check_write_global_reg(hw, reg, 0);
9001 : : }
9002 : : }
9003 : :
9004 : : /* Reset pctype symmetric sets */
9005 : 0 : reg = I40E_GLQF_HSYM(pctype);
9006 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
9007 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
9008 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
9009 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
9010 : : }
9011 : : }
9012 : 0 : I40E_WRITE_FLUSH(hw);
9013 : 0 : }
9014 : :
9015 : : int
9016 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
9017 : : {
9018 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
9019 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
9020 : : uint32_t i;
9021 : : uint16_t num;
9022 : :
9023 : : /* If both VMDQ and RSS enabled, not all of PF queues are
9024 : : * configured. It's necessary to calculate the actual PF
9025 : : * queues that are configured.
9026 : : */
9027 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
9028 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
9029 : : else
9030 : 0 : num = pf->dev_data->nb_rx_queues;
9031 : :
9032 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
9033 [ # # ]: 0 : if (num <= 0)
9034 : : return 0;
9035 : :
9036 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
9037 : 0 : lut[i] = (uint8_t)(i % num);
9038 : :
9039 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
9040 : : }
9041 : :
9042 : : int
9043 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
9044 : : {
9045 : : uint8_t key_buf[I40E_RSS_KEY_LEN];
9046 : : const uint8_t *rss_key;
9047 : :
9048 : : /* Reset key */
9049 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
9050 [ # # # # ]: 0 : if (!rss_key || pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < sizeof(key_buf))
9051 : : rss_key = i40e_rss_key_default;
9052 : :
9053 : : /*
9054 : : * adminq does not guarantee const-ness of RSS key once a command is sent down, so make a
9055 : : * local copy.
9056 : : */
9057 : : memcpy(&key_buf, rss_key, sizeof(key_buf));
9058 : :
9059 : 0 : return i40e_set_rss_key(pf->main_vsi, key_buf, sizeof(key_buf));
9060 : : }
9061 : :
9062 : : static int
9063 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
9064 : : {
9065 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9066 : :
9067 : : int ret;
9068 : :
9069 : 0 : pf->hash_filter_enabled = 0;
9070 : 0 : i40e_pf_disable_rss(pf);
9071 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
9072 : :
9073 [ # # ]: 0 : if (!pf->support_multi_driver)
9074 : 0 : i40e_pf_global_rss_reset(pf);
9075 : :
9076 : : /* Reset RETA table */
9077 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
9078 : 0 : ret = i40e_pf_reset_rss_reta(pf);
9079 [ # # ]: 0 : if (ret)
9080 : : return ret;
9081 : : }
9082 : :
9083 : 0 : return i40e_pf_reset_rss_key(pf);
9084 : : }
9085 : :
9086 : : /* Configure RSS */
9087 : : int
9088 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
9089 : : {
9090 : : struct i40e_hw *hw;
9091 : : enum rte_eth_rx_mq_mode mq_mode;
9092 : : uint64_t rss_hf, hena;
9093 : : int ret;
9094 : :
9095 : 0 : ret = i40e_pf_rss_reset(pf);
9096 [ # # ]: 0 : if (ret) {
9097 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9098 : 0 : return ret;
9099 : : }
9100 : :
9101 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9102 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9103 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
9104 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9105 : : return 0;
9106 : :
9107 : 0 : hw = I40E_PF_TO_HW(pf);
9108 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
9109 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9110 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9111 : 0 : I40E_WRITE_FLUSH(hw);
9112 : :
9113 : 0 : return 0;
9114 : : }
9115 : :
9116 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9117 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9118 : : int
9119 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9120 : : {
9121 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9122 : : uint32_t val, reg;
9123 : : int ret = -EINVAL;
9124 : :
9125 [ # # ]: 0 : if (pf->support_multi_driver) {
9126 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9127 : 0 : return -ENOTSUP;
9128 : : }
9129 : :
9130 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9131 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9132 : :
9133 [ # # ]: 0 : if (len == 3) {
9134 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9135 [ # # ]: 0 : } else if (len == 4) {
9136 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9137 : : } else {
9138 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9139 : 0 : return ret;
9140 : : }
9141 : :
9142 [ # # ]: 0 : if (reg != val) {
9143 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9144 : : I40E_GL_PRS_FVBM(2),
9145 : : reg, NULL);
9146 [ # # ]: 0 : if (ret != 0)
9147 : : return ret;
9148 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9149 : : "with value 0x%08x",
9150 : : I40E_GL_PRS_FVBM(2), reg);
9151 : : } else {
9152 : : ret = 0;
9153 : : }
9154 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9155 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9156 : :
9157 : 0 : return ret;
9158 : : }
9159 : :
9160 : : /* Set the symmetric hash enable configurations per port */
9161 : : void
9162 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9163 : : {
9164 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9165 : :
9166 [ # # ]: 0 : if (enable > 0) {
9167 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9168 : : return;
9169 : :
9170 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9171 : : } else {
9172 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9173 : : return;
9174 : :
9175 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9176 : : }
9177 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9178 : 0 : I40E_WRITE_FLUSH(hw);
9179 : : }
9180 : :
9181 : : /**
9182 : : * Valid input sets for hash and flow director filters per PCTYPE
9183 : : */
9184 : : static uint64_t
9185 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9186 : : enum rte_filter_type filter)
9187 : : {
9188 : : uint64_t valid;
9189 : :
9190 : : static const uint64_t valid_hash_inset_table[] = {
9191 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9192 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9193 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9194 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9195 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9196 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9197 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9198 : : I40E_INSET_FLEX_PAYLOAD,
9199 : : [I40E_FILTER_PCTYPE_NONF_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_UNICAST_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_MULTICAST_IPV4_UDP] =
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_FLEX_PAYLOAD,
9226 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
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_TCP_SYN_NO_ACK] =
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_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9244 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
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_SRC_PORT | I40E_INSET_DST_PORT |
9252 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9253 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9254 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9255 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9256 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9257 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9258 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9259 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9260 : : I40E_INSET_FLEX_PAYLOAD,
9261 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9262 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9263 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9264 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9265 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9266 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9267 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9268 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9269 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9270 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9271 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9272 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9273 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9274 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9275 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9276 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9277 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_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_MULTICAST_IPV6_UDP] =
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] =
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_TCP_SYN_NO_ACK] =
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_TCP_FLAGS |
9312 : : I40E_INSET_FLEX_PAYLOAD,
9313 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
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_SRC_PORT |
9320 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9321 : : I40E_INSET_FLEX_PAYLOAD,
9322 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9323 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9324 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9325 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9326 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9327 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9328 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9329 : : I40E_INSET_FLEX_PAYLOAD,
9330 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9331 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9332 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9333 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9334 : : I40E_INSET_FLEX_PAYLOAD,
9335 : : };
9336 : :
9337 : : /**
9338 : : * Flow director supports only fields defined in
9339 : : * union rte_eth_fdir_flow.
9340 : : */
9341 : : static const uint64_t valid_fdir_inset_table[] = {
9342 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9343 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9344 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9345 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9346 : : I40E_INSET_IPV4_TTL,
9347 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9348 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9349 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9350 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9351 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9352 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9353 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9354 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9355 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9356 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9357 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9358 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9359 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9360 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9361 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9362 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9363 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9364 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9365 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9366 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9367 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9368 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9369 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9370 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9371 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9372 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9373 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9374 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9375 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9376 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9377 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9378 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9379 : : I40E_INSET_SCTP_VT,
9380 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9381 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9382 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9383 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9384 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9385 : : I40E_INSET_IPV4_TTL,
9386 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9387 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9388 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9389 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9390 : : I40E_INSET_IPV6_HOP_LIMIT,
9391 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9392 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9393 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9394 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9395 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9396 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9397 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9398 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9399 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9400 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9401 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9402 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9403 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9404 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9405 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9406 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9407 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9408 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9409 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9410 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9411 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9412 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9413 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9414 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9415 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9416 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9417 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9418 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9419 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9420 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9421 : : I40E_INSET_SCTP_VT,
9422 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9423 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9424 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9425 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9426 : : I40E_INSET_IPV6_HOP_LIMIT,
9427 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9428 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9429 : : I40E_INSET_LAST_ETHER_TYPE,
9430 : : };
9431 : :
9432 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9433 : : return 0;
9434 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9435 : 0 : valid = valid_hash_inset_table[pctype];
9436 : : else
9437 : 0 : valid = valid_fdir_inset_table[pctype];
9438 : :
9439 : : return valid;
9440 : : }
9441 : :
9442 : : /**
9443 : : * Validate if the input set is allowed for a specific PCTYPE
9444 : : */
9445 : : int
9446 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9447 : : enum rte_filter_type filter, uint64_t inset)
9448 : : {
9449 : : uint64_t valid;
9450 : :
9451 : : valid = i40e_get_valid_input_set(pctype, filter);
9452 [ # # ]: 0 : if (inset & (~valid))
9453 : 0 : return -EINVAL;
9454 : :
9455 : : return 0;
9456 : : }
9457 : :
9458 : : /* default input set fields combination per pctype */
9459 : : uint64_t
9460 : 0 : i40e_get_default_input_set(uint16_t pctype)
9461 : : {
9462 : : static const uint64_t default_inset_table[] = {
9463 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9464 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9465 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9466 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9467 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9468 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9469 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9470 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9471 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9472 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9473 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9474 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9475 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9476 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9477 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9478 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9479 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9480 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9481 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9482 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9483 : : I40E_INSET_SCTP_VT,
9484 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9485 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9486 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9487 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9488 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9489 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9490 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9491 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9492 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9493 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9494 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9495 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9496 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9497 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9498 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9499 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9500 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9501 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9502 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9503 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9504 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9505 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9506 : : I40E_INSET_SCTP_VT,
9507 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9508 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9509 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9510 : : I40E_INSET_LAST_ETHER_TYPE,
9511 : : };
9512 : :
9513 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9514 : : return 0;
9515 : :
9516 : 0 : return default_inset_table[pctype];
9517 : : }
9518 : :
9519 : : /**
9520 : : * Translate the input set from bit masks to register aware bit masks
9521 : : * and vice versa
9522 : : */
9523 : : uint64_t
9524 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9525 : : {
9526 : : uint64_t val = 0;
9527 : : uint16_t i;
9528 : :
9529 : : struct inset_map {
9530 : : uint64_t inset;
9531 : : uint64_t inset_reg;
9532 : : };
9533 : :
9534 : : static const struct inset_map inset_map_common[] = {
9535 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9536 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9537 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9538 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9539 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9540 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9541 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9542 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9543 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9544 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9545 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9546 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9547 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9548 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9549 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9550 : : {I40E_INSET_TUNNEL_DMAC,
9551 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9552 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9553 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9554 : : {I40E_INSET_TUNNEL_SRC_PORT,
9555 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9556 : : {I40E_INSET_TUNNEL_DST_PORT,
9557 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9558 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9559 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9560 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9561 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9562 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9563 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9564 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9565 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9566 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9567 : : };
9568 : :
9569 : : /* some different registers map in x722*/
9570 : : static const struct inset_map inset_map_diff_x722[] = {
9571 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9572 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9573 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9574 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9575 : : };
9576 : :
9577 : : static const struct inset_map inset_map_diff_not_x722[] = {
9578 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9579 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9580 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9581 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9582 : : };
9583 : :
9584 [ # # ]: 0 : if (input == 0)
9585 : : return val;
9586 : :
9587 : : /* Translate input set to register aware inset */
9588 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9589 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9590 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9591 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9592 : : }
9593 : : } else {
9594 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9595 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9596 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9597 : : }
9598 : : }
9599 : :
9600 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9601 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9602 : 0 : val |= inset_map_common[i].inset_reg;
9603 : : }
9604 : :
9605 : : return val;
9606 : : }
9607 : :
9608 : : static int
9609 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9610 : : uint32_t pit_reg_count, uint32_t hdr_off)
9611 : : {
9612 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9613 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9614 : : uint32_t i, reg_val, src_off, count;
9615 : :
9616 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9617 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9618 : :
9619 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9620 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9621 : :
9622 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9623 : : break;
9624 : : }
9625 : :
9626 [ # # ]: 0 : if (i >= pit_reg_end) {
9627 : 0 : PMD_DRV_LOG(ERR,
9628 : : "Hardware GLQF_PIT configuration does not support this field mask");
9629 : 0 : return -1;
9630 : : }
9631 : :
9632 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9633 : : }
9634 : :
9635 : : int
9636 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9637 : : uint32_t *mask, uint8_t nb_elem)
9638 : : {
9639 : : static const uint64_t mask_inset[] = {
9640 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9641 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9642 : :
9643 : : static const struct {
9644 : : uint64_t inset;
9645 : : uint32_t mask;
9646 : : uint32_t offset;
9647 : : } inset_mask_offset_map[] = {
9648 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9649 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9650 : :
9651 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9652 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9653 : :
9654 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9655 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9656 : :
9657 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9658 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9659 : :
9660 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9661 : : offsetof(struct rte_ipv6_hdr, proto) },
9662 : :
9663 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9664 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9665 : : };
9666 : :
9667 : : uint32_t i;
9668 : : int idx = 0;
9669 : :
9670 [ # # ]: 0 : assert(mask);
9671 [ # # ]: 0 : if (!inset)
9672 : : return 0;
9673 : :
9674 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9675 : : /* Clear the inset bit, if no MASK is required,
9676 : : * for example proto + ttl
9677 : : */
9678 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9679 : 0 : inset &= ~mask_inset[i];
9680 [ # # ]: 0 : if (!inset)
9681 : : return 0;
9682 : : }
9683 : : }
9684 : :
9685 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9686 : : uint32_t pit_start, pit_count;
9687 : : int offset;
9688 : :
9689 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9690 : 0 : continue;
9691 : :
9692 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9693 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9694 : : I40E_INSET_IPV4_TTL)) {
9695 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9696 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9697 : : } else {
9698 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9699 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9700 : : }
9701 : :
9702 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9703 : 0 : inset_mask_offset_map[i].offset);
9704 : :
9705 [ # # ]: 0 : if (offset < 0)
9706 : : return -EINVAL;
9707 : :
9708 [ # # ]: 0 : if (idx >= nb_elem) {
9709 : 0 : PMD_DRV_LOG(ERR,
9710 : : "Configuration of inset mask out of range %u",
9711 : : nb_elem);
9712 : 0 : return -ERANGE;
9713 : : }
9714 : :
9715 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9716 : : inset_mask_offset_map[i].mask);
9717 : 0 : idx++;
9718 : : }
9719 : :
9720 : : return idx;
9721 : : }
9722 : :
9723 : : void
9724 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9725 : : {
9726 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9727 : :
9728 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9729 [ # # ]: 0 : if (reg != val)
9730 : 0 : i40e_write_rx_ctl(hw, addr, val);
9731 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9732 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9733 : 0 : }
9734 : :
9735 : : void
9736 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9737 : : {
9738 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9739 : 0 : struct rte_eth_dev_data *dev_data =
9740 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9741 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9742 : :
9743 [ # # ]: 0 : if (reg != val) {
9744 : 0 : i40e_write_rx_ctl(hw, addr, val);
9745 : 0 : PMD_DRV_LOG(INFO,
9746 : : "i40e device %s changed global register [0x%08x]."
9747 : : " original: 0x%08x, new: 0x%08x",
9748 : : dev->device->name, addr, reg,
9749 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9750 : : }
9751 : 0 : }
9752 : :
9753 : : static void
9754 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9755 : : {
9756 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9757 : : enum i40e_filter_pctype pctype;
9758 : : uint64_t input_set, inset_reg;
9759 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9760 : : int num, i;
9761 : : uint16_t flow_type;
9762 : :
9763 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9764 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9765 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9766 : :
9767 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9768 : 0 : continue;
9769 : :
9770 : 0 : input_set = i40e_get_default_input_set(pctype);
9771 : :
9772 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9773 : : I40E_INSET_MASK_NUM_REG);
9774 [ # # ]: 0 : if (num < 0)
9775 : 0 : return;
9776 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9777 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9778 : 0 : return;
9779 : : }
9780 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9781 : : input_set);
9782 : :
9783 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9784 : : (uint32_t)(inset_reg & UINT32_MAX));
9785 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9786 : 0 : (uint32_t)((inset_reg >>
9787 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9788 [ # # ]: 0 : if (!pf->support_multi_driver) {
9789 : 0 : i40e_check_write_global_reg(hw,
9790 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9791 : : (uint32_t)(inset_reg & UINT32_MAX));
9792 : 0 : i40e_check_write_global_reg(hw,
9793 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9794 : : (uint32_t)((inset_reg >>
9795 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9796 : :
9797 [ # # ]: 0 : for (i = 0; i < num; i++) {
9798 : 0 : i40e_check_write_global_reg(hw,
9799 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9800 : : mask_reg[i]);
9801 : 0 : i40e_check_write_global_reg(hw,
9802 : : I40E_GLQF_HASH_MSK(i, pctype),
9803 : : mask_reg[i]);
9804 : : }
9805 : : /*clear unused mask registers of the pctype */
9806 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9807 : 0 : i40e_check_write_global_reg(hw,
9808 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9809 : : 0);
9810 : 0 : i40e_check_write_global_reg(hw,
9811 : : I40E_GLQF_HASH_MSK(i, pctype),
9812 : : 0);
9813 : : }
9814 : : } else {
9815 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9816 : : }
9817 : 0 : I40E_WRITE_FLUSH(hw);
9818 : :
9819 : : /* store the default input set */
9820 [ # # ]: 0 : if (!pf->support_multi_driver)
9821 : 0 : pf->hash_input_set[pctype] = input_set;
9822 : 0 : pf->fdir.input_set[pctype] = input_set;
9823 : : }
9824 : : }
9825 : :
9826 : : int
9827 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9828 : : uint32_t pctype, bool add)
9829 : : {
9830 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9831 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9832 : : uint64_t inset_reg = 0;
9833 : : int num, i;
9834 : :
9835 [ # # ]: 0 : if (pf->support_multi_driver) {
9836 : 0 : PMD_DRV_LOG(ERR,
9837 : : "Modify input set is not permitted when multi-driver enabled.");
9838 : 0 : return -EPERM;
9839 : : }
9840 : :
9841 : : /* For X722, get translated pctype in fd pctype register */
9842 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9843 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9844 : :
9845 [ # # ]: 0 : if (add) {
9846 : : /* get inset value in register */
9847 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9848 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9849 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9850 : 0 : input_set |= pf->hash_input_set[pctype];
9851 : : }
9852 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9853 : : I40E_INSET_MASK_NUM_REG);
9854 [ # # ]: 0 : if (num < 0)
9855 : : return -EINVAL;
9856 : :
9857 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9858 : :
9859 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9860 : : (uint32_t)(inset_reg & UINT32_MAX));
9861 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9862 : 0 : (uint32_t)((inset_reg >>
9863 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9864 : :
9865 [ # # ]: 0 : for (i = 0; i < num; i++)
9866 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9867 : : mask_reg[i]);
9868 : : /*clear unused mask registers of the pctype */
9869 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9870 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9871 : : 0);
9872 : 0 : I40E_WRITE_FLUSH(hw);
9873 : :
9874 : 0 : pf->hash_input_set[pctype] = input_set;
9875 : 0 : return 0;
9876 : : }
9877 : :
9878 : : /* Convert ethertype filter structure */
9879 : : static int
9880 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9881 : : struct i40e_ethertype_filter *filter)
9882 : : {
9883 : 0 : memcpy(&filter->input.mac_addr, &input->mac_addr,
9884 : : RTE_ETHER_ADDR_LEN);
9885 : 0 : filter->input.ether_type = input->ether_type;
9886 : 0 : filter->flags = input->flags;
9887 : 0 : filter->queue = input->queue;
9888 : :
9889 : : return 0;
9890 : : }
9891 : :
9892 : : /* Check if there exists the ethertype filter */
9893 : : struct i40e_ethertype_filter *
9894 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9895 : : const struct i40e_ethertype_filter_input *input)
9896 : : {
9897 : : int ret;
9898 : :
9899 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9900 [ # # ]: 0 : if (ret < 0)
9901 : : return NULL;
9902 : :
9903 : 0 : return ethertype_rule->hash_map[ret];
9904 : : }
9905 : :
9906 : : /* Add ethertype filter in SW list */
9907 : : static int
9908 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9909 : : struct i40e_ethertype_filter *filter)
9910 : : {
9911 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9912 : : int ret;
9913 : :
9914 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9915 [ # # ]: 0 : if (ret < 0) {
9916 : 0 : PMD_DRV_LOG(ERR,
9917 : : "Failed to insert ethertype filter"
9918 : : " to hash table %d!",
9919 : : ret);
9920 : 0 : return ret;
9921 : : }
9922 : 0 : rule->hash_map[ret] = filter;
9923 : :
9924 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9925 : :
9926 : 0 : return 0;
9927 : : }
9928 : :
9929 : : /* Delete ethertype filter in SW list */
9930 : : int
9931 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9932 : : struct i40e_ethertype_filter_input *input)
9933 : : {
9934 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9935 : : struct i40e_ethertype_filter *filter;
9936 : : int ret;
9937 : :
9938 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9939 [ # # ]: 0 : if (ret < 0) {
9940 : 0 : PMD_DRV_LOG(ERR,
9941 : : "Failed to delete ethertype filter"
9942 : : " to hash table %d!",
9943 : : ret);
9944 : 0 : return ret;
9945 : : }
9946 : 0 : filter = rule->hash_map[ret];
9947 : 0 : rule->hash_map[ret] = NULL;
9948 : :
9949 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9950 : 0 : rte_free(filter);
9951 : :
9952 : 0 : return 0;
9953 : : }
9954 : :
9955 : : /*
9956 : : * Configure ethertype filter, which can director packet by filtering
9957 : : * with mac address and ether_type or only ether_type
9958 : : */
9959 : : int
9960 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9961 : : struct rte_eth_ethertype_filter *filter,
9962 : : bool add)
9963 : : {
9964 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9965 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9966 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9967 : : struct i40e_ethertype_filter check_filter;
9968 : : struct i40e_control_filter_stats stats;
9969 : : uint16_t flags = 0;
9970 : : int ret;
9971 : :
9972 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9973 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9974 : 0 : return -EINVAL;
9975 : : }
9976 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9977 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9978 : 0 : PMD_DRV_LOG(ERR,
9979 : : "unsupported ether_type(0x%04x) in control packet filter.",
9980 : : filter->ether_type);
9981 : 0 : return -EINVAL;
9982 : : }
9983 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
9984 : 0 : PMD_DRV_LOG(WARNING,
9985 : : "filter vlan ether_type in first tag is not supported.");
9986 : :
9987 : : /* Check if there is the filter in SW list */
9988 : : memset(&check_filter, 0, sizeof(check_filter));
9989 : : i40e_ethertype_filter_convert(filter, &check_filter);
9990 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9991 : : &check_filter.input);
9992 [ # # ]: 0 : if (add && node) {
9993 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9994 : 0 : return -EINVAL;
9995 : : }
9996 : :
9997 [ # # ]: 0 : if (!add && !node) {
9998 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9999 : 0 : return -EINVAL;
10000 : : }
10001 : :
10002 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
10003 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
10004 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
10005 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
10006 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
10007 : :
10008 : : memset(&stats, 0, sizeof(stats));
10009 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
10010 : 0 : filter->mac_addr.addr_bytes,
10011 : 0 : filter->ether_type, flags,
10012 : 0 : pf->main_vsi->seid,
10013 : 0 : filter->queue, add, &stats, NULL);
10014 : :
10015 : 0 : PMD_DRV_LOG(INFO,
10016 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10017 : : ret, stats.mac_etype_used, stats.etype_used,
10018 : : stats.mac_etype_free, stats.etype_free);
10019 [ # # ]: 0 : if (ret < 0)
10020 : : return -ENOSYS;
10021 : :
10022 : : /* Add or delete a filter in SW list */
10023 [ # # ]: 0 : if (add) {
10024 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
10025 : : sizeof(*ethertype_filter), 0);
10026 [ # # ]: 0 : if (ethertype_filter == NULL) {
10027 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10028 : 0 : return -ENOMEM;
10029 : : }
10030 : :
10031 : : memcpy(ethertype_filter, &check_filter,
10032 : : sizeof(check_filter));
10033 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10034 [ # # ]: 0 : if (ret < 0)
10035 : 0 : rte_free(ethertype_filter);
10036 : : } else {
10037 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10038 : : }
10039 : :
10040 : : return ret;
10041 : : }
10042 : :
10043 : : static int
10044 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
10045 : : const struct rte_flow_ops **ops)
10046 : : {
10047 [ # # ]: 0 : if (dev == NULL)
10048 : : return -EINVAL;
10049 : :
10050 : 0 : *ops = &i40e_flow_ops;
10051 : 0 : return 0;
10052 : : }
10053 : :
10054 : : /*
10055 : : * Check and enable Extended Tag.
10056 : : * Enabling Extended Tag is important for 40G performance.
10057 : : */
10058 : : static void
10059 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
10060 : : {
10061 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
10062 : 0 : uint32_t buf = 0;
10063 : : int ret;
10064 : :
10065 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10066 : : PCI_DEV_CAP_REG);
10067 [ # # ]: 0 : if (ret < 0) {
10068 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10069 : : PCI_DEV_CAP_REG);
10070 : 0 : return;
10071 : : }
10072 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10073 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10074 : 0 : return;
10075 : : }
10076 : :
10077 : 0 : buf = 0;
10078 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10079 : : PCI_DEV_CTRL_REG);
10080 [ # # ]: 0 : if (ret < 0) {
10081 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10082 : : PCI_DEV_CTRL_REG);
10083 : 0 : return;
10084 : : }
10085 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10086 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10087 : 0 : return;
10088 : : }
10089 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10090 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10091 : : PCI_DEV_CTRL_REG);
10092 [ # # ]: 0 : if (ret < 0) {
10093 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10094 : : PCI_DEV_CTRL_REG);
10095 : 0 : return;
10096 : : }
10097 : : }
10098 : :
10099 : : /*
10100 : : * As some registers wouldn't be reset unless a global hardware reset,
10101 : : * hardware initialization is needed to put those registers into an
10102 : : * expected initial state.
10103 : : */
10104 : : static void
10105 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
10106 : : {
10107 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10108 : :
10109 : 0 : i40e_enable_extended_tag(dev);
10110 : :
10111 : : /* clear the PF Queue Filter control register */
10112 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10113 : :
10114 : : /* Disable symmetric hash per port */
10115 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10116 : 0 : }
10117 : :
10118 : : /*
10119 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10120 : : * however this function will return only one highest pctype index,
10121 : : * which is not quite correct. This is known problem of i40e driver
10122 : : * and needs to be fixed later.
10123 : : */
10124 : : enum i40e_filter_pctype
10125 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10126 : : {
10127 : : int i;
10128 : : uint64_t pctype_mask;
10129 : :
10130 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10131 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10132 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10133 [ # # ]: 0 : if (pctype_mask & RTE_BIT64(i))
10134 : 0 : return (enum i40e_filter_pctype)i;
10135 : : }
10136 : : }
10137 : : return I40E_FILTER_PCTYPE_INVALID;
10138 : : }
10139 : :
10140 : : uint16_t
10141 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10142 : : enum i40e_filter_pctype pctype)
10143 : : {
10144 : : uint16_t flowtype;
10145 : 0 : uint64_t pctype_mask = RTE_BIT64(pctype);
10146 : :
10147 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10148 : 0 : flowtype++) {
10149 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10150 : 0 : return flowtype;
10151 : : }
10152 : :
10153 : : return RTE_ETH_FLOW_UNKNOWN;
10154 : : }
10155 : :
10156 : : /*
10157 : : * On X710, performance number is far from the expectation on recent firmware
10158 : : * versions; on XL710, performance number is also far from the expectation on
10159 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10160 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10161 : : * address. The fix for this issue may not be integrated in the following
10162 : : * firmware version. So the workaround in software driver is needed. It needs
10163 : : * to modify the initial values of 3 internal only registers for both X710 and
10164 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10165 : : * workaround can be removed when it is fixed in firmware in the future.
10166 : : */
10167 : :
10168 : : /* For both X710 and XL710 */
10169 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10170 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10171 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10172 : :
10173 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10174 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10175 : :
10176 : : /* For X722 */
10177 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10178 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10179 : :
10180 : : /* For X710 */
10181 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10182 : : /* For XL710 */
10183 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10184 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10185 : :
10186 : : /*
10187 : : * GL_SWR_PM_UP_THR:
10188 : : * The value is not impacted from the link speed, its value is set according
10189 : : * to the total number of ports for a better pipe-monitor configuration.
10190 : : */
10191 : : static bool
10192 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10193 : : {
10194 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10195 : : .device_id = (dev), \
10196 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10197 : :
10198 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10199 : : .device_id = (dev), \
10200 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10201 : :
10202 : : static const struct {
10203 : : uint16_t device_id;
10204 : : uint32_t val;
10205 : : } swr_pm_table[] = {
10206 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10207 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10208 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10209 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10210 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10211 : :
10212 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10213 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10214 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10215 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10216 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10217 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10218 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10219 : : };
10220 : : uint32_t i;
10221 : :
10222 [ # # ]: 0 : if (value == NULL) {
10223 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10224 : 0 : return false;
10225 : : }
10226 : :
10227 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10228 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10229 : 0 : *value = swr_pm_table[i].val;
10230 : :
10231 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10232 : : "value - 0x%08x",
10233 : : hw->device_id, *value);
10234 : 0 : return true;
10235 : : }
10236 : : }
10237 : :
10238 : : return false;
10239 : : }
10240 : :
10241 : : static int
10242 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10243 : : {
10244 : : enum i40e_status_code status;
10245 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10246 : : int ret = -ENOTSUP;
10247 : : int retries = 0;
10248 : :
10249 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10250 : : NULL);
10251 : :
10252 [ # # ]: 0 : while (status) {
10253 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10254 : : status);
10255 : 0 : retries++;
10256 : 0 : rte_delay_us(100000);
10257 [ # # ]: 0 : if (retries < 5)
10258 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10259 : : true, &phy_ab, NULL);
10260 : : else
10261 : : return ret;
10262 : : }
10263 : : return 0;
10264 : : }
10265 : :
10266 : : static void
10267 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10268 : : {
10269 : : static struct {
10270 : : uint32_t addr;
10271 : : uint64_t val;
10272 : : } reg_table[] = {
10273 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10274 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10275 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10276 : : };
10277 : : uint64_t reg;
10278 : : uint32_t i;
10279 : : int ret;
10280 : :
10281 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10282 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10283 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10284 : 0 : reg_table[i].val =
10285 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10286 : : else /* For X710/XL710/XXV710 */
10287 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10288 : 0 : reg_table[i].val =
10289 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10290 : : else
10291 : 0 : reg_table[i].val =
10292 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10293 : : }
10294 : :
10295 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10296 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10297 : 0 : reg_table[i].val =
10298 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10299 : : else /* For X710/XL710/XXV710 */
10300 : 0 : reg_table[i].val =
10301 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10302 : : }
10303 : :
10304 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10305 : : uint32_t cfg_val;
10306 : :
10307 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10308 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10309 : : "GL_SWR_PM_UP_THR value fixup",
10310 : : hw->device_id);
10311 : 0 : continue;
10312 : : }
10313 : :
10314 : 0 : reg_table[i].val = cfg_val;
10315 : : }
10316 : :
10317 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10318 : : ®, NULL);
10319 [ # # ]: 0 : if (ret < 0) {
10320 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10321 : : reg_table[i].addr);
10322 : 0 : break;
10323 : : }
10324 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10325 : : reg_table[i].addr, reg);
10326 [ # # ]: 0 : if (reg == reg_table[i].val)
10327 : 0 : continue;
10328 : :
10329 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10330 : : reg_table[i].val, NULL);
10331 [ # # ]: 0 : if (ret < 0) {
10332 : 0 : PMD_DRV_LOG(ERR,
10333 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10334 : : reg_table[i].val, reg_table[i].addr);
10335 : 0 : break;
10336 : : }
10337 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10338 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10339 : : }
10340 : 0 : }
10341 : :
10342 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10343 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10344 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10345 : : static int
10346 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10347 : : {
10348 : : uint32_t reg;
10349 : : int ret;
10350 : :
10351 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10352 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10353 : 0 : return -EINVAL;
10354 : : }
10355 : :
10356 : : /* Configure for double VLAN RX stripping */
10357 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10358 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10359 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10360 : 0 : ret = i40e_aq_debug_write_register(hw,
10361 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10362 : : reg, NULL);
10363 [ # # ]: 0 : if (ret < 0) {
10364 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10365 : : vsi->vsi_id);
10366 : 0 : return I40E_ERR_CONFIG;
10367 : : }
10368 : : }
10369 : :
10370 : : /* Configure for double VLAN TX insertion */
10371 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10372 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10373 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10374 : 0 : ret = i40e_aq_debug_write_register(hw,
10375 : 0 : I40E_VSI_L2TAGSTXVALID(
10376 : : vsi->vsi_id), reg, NULL);
10377 [ # # ]: 0 : if (ret < 0) {
10378 : 0 : PMD_DRV_LOG(ERR,
10379 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10380 : : vsi->vsi_id);
10381 : 0 : return I40E_ERR_CONFIG;
10382 : : }
10383 : : }
10384 : :
10385 : : return 0;
10386 : : }
10387 : :
10388 : : static uint64_t
10389 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10390 : : {
10391 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10392 : : uint64_t systim_cycles;
10393 : :
10394 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10395 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10396 [ # # ]: 0 : << 32;
10397 : :
10398 : : return systim_cycles;
10399 : : }
10400 : :
10401 : : static uint64_t
10402 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10403 : : {
10404 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10405 : : uint64_t rx_tstamp;
10406 : :
10407 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10408 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10409 [ # # ]: 0 : << 32;
10410 : :
10411 : : return rx_tstamp;
10412 : : }
10413 : :
10414 : : static uint64_t
10415 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10416 : : {
10417 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10418 : : uint64_t tx_tstamp;
10419 : :
10420 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10421 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10422 [ # # ]: 0 : << 32;
10423 : :
10424 : : return tx_tstamp;
10425 : : }
10426 : :
10427 : : static void
10428 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10429 : : {
10430 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10431 : : struct i40e_adapter *adapter = dev->data->dev_private;
10432 : : struct rte_eth_link link;
10433 : : uint32_t tsync_inc_l;
10434 : : uint32_t tsync_inc_h;
10435 : :
10436 : : /* Get current link speed. */
10437 : 0 : i40e_dev_link_update(dev, 1);
10438 : 0 : rte_eth_linkstatus_get(dev, &link);
10439 : :
10440 [ # # # # ]: 0 : switch (link.link_speed) {
10441 : : case RTE_ETH_SPEED_NUM_40G:
10442 : : case RTE_ETH_SPEED_NUM_25G:
10443 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10444 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10445 : : break;
10446 : 0 : case RTE_ETH_SPEED_NUM_10G:
10447 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10448 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10449 : 0 : break;
10450 : 0 : case RTE_ETH_SPEED_NUM_1G:
10451 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10452 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10453 : 0 : break;
10454 : 0 : default:
10455 : : tsync_inc_l = 0x0;
10456 : : tsync_inc_h = 0x0;
10457 : : }
10458 : :
10459 : : /* Set the timesync increment value. */
10460 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10461 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10462 : :
10463 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10464 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10465 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10466 : :
10467 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10468 : : adapter->systime_tc.cc_shift = 0;
10469 : : adapter->systime_tc.nsec_mask = 0;
10470 : :
10471 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10472 : : adapter->rx_tstamp_tc.cc_shift = 0;
10473 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10474 : :
10475 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10476 : : adapter->tx_tstamp_tc.cc_shift = 0;
10477 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10478 : 0 : }
10479 : :
10480 : : static int
10481 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10482 : : {
10483 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10484 : :
10485 : 0 : adapter->systime_tc.nsec += delta;
10486 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10487 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10488 : :
10489 : 0 : return 0;
10490 : : }
10491 : :
10492 : : static int
10493 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10494 : : {
10495 : : uint64_t ns;
10496 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10497 : :
10498 : : ns = rte_timespec_to_ns(ts);
10499 : :
10500 : : /* Set the timecounters to a new value. */
10501 : 0 : adapter->systime_tc.nsec = ns;
10502 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10503 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10504 : :
10505 : 0 : return 0;
10506 : : }
10507 : :
10508 : : static int
10509 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10510 : : {
10511 : : uint64_t ns, systime_cycles;
10512 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10513 : :
10514 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10515 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10516 : 0 : *ts = rte_ns_to_timespec(ns);
10517 : :
10518 : 0 : return 0;
10519 : : }
10520 : :
10521 : : static int
10522 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10523 : : {
10524 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10525 : : uint32_t tsync_ctl_l;
10526 : : uint32_t tsync_ctl_h;
10527 : : struct timespec ts;
10528 : :
10529 : : memset(&ts, 0, sizeof(struct timespec));
10530 : :
10531 : : /* Stop the timesync system time. */
10532 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10533 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10534 : : /* Reset the timesync system time value. */
10535 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10536 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10537 : :
10538 : 0 : i40e_start_timecounters(dev);
10539 : :
10540 : : /* Clear timesync registers. */
10541 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10542 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10543 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10544 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10545 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10546 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10547 : :
10548 : : /* Enable timestamping of PTP packets. */
10549 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10550 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10551 : :
10552 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10553 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10554 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10555 : :
10556 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10557 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10558 : :
10559 : : /* i40e uses zero-based timestamping so only adjust timecounter */
10560 : : i40e_timesync_write_time(dev, &ts);
10561 : :
10562 : 0 : return 0;
10563 : : }
10564 : :
10565 : : static int
10566 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10567 : : {
10568 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10569 : : uint32_t tsync_ctl_l;
10570 : : uint32_t tsync_ctl_h;
10571 : :
10572 : : /* Disable timestamping of transmitted PTP packets. */
10573 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10574 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10575 : :
10576 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10577 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10578 : :
10579 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10580 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10581 : :
10582 : : /* Reset the timesync increment value. */
10583 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10584 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10585 : :
10586 : 0 : return 0;
10587 : : }
10588 : :
10589 : : static int
10590 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10591 : : struct timespec *timestamp, uint32_t flags)
10592 : : {
10593 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10594 : : struct i40e_adapter *adapter = dev->data->dev_private;
10595 : : uint32_t sync_status;
10596 : 0 : uint32_t index = flags & 0x03;
10597 : : uint64_t rx_tstamp_cycles;
10598 : : uint64_t ns;
10599 : :
10600 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10601 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10602 : : return -EINVAL;
10603 : :
10604 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10605 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10606 : 0 : *timestamp = rte_ns_to_timespec(ns);
10607 : :
10608 : 0 : return 0;
10609 : : }
10610 : :
10611 : : static int
10612 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10613 : : struct timespec *timestamp)
10614 : : {
10615 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10616 : : struct i40e_adapter *adapter = dev->data->dev_private;
10617 : : uint32_t sync_status;
10618 : : uint64_t tx_tstamp_cycles;
10619 : : uint64_t ns;
10620 : :
10621 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10622 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10623 : : return -EINVAL;
10624 : :
10625 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10626 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10627 : 0 : *timestamp = rte_ns_to_timespec(ns);
10628 : :
10629 : 0 : return 0;
10630 : : }
10631 : :
10632 : : /*
10633 : : * i40e_parse_dcb_configure - parse dcb configure from user
10634 : : * @dev: the device being configured
10635 : : * @dcb_cfg: pointer of the result of parse
10636 : : * @*tc_map: bit map of enabled traffic classes
10637 : : *
10638 : : * Returns 0 on success, negative value on failure
10639 : : */
10640 : : static int
10641 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10642 : : struct i40e_dcbx_config *dcb_cfg,
10643 : : uint8_t *tc_map)
10644 : : {
10645 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10646 : : uint8_t i, tc_bw, bw_lf;
10647 : :
10648 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10649 : :
10650 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10651 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10652 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10653 : 0 : return -EINVAL;
10654 : : }
10655 : :
10656 : : /* assume each tc has the same bw */
10657 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10658 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10659 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10660 : : /* to ensure the sum of tcbw is equal to 100 */
10661 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10662 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10663 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10664 : :
10665 : : /* assume each tc has the same Transmission Selection Algorithm */
10666 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10667 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10668 : :
10669 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10670 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10671 : 0 : dcb_rx_conf->dcb_tc[i];
10672 : :
10673 : : /* FW needs one App to configure HW */
10674 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10675 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10676 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10677 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10678 : :
10679 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10680 : 0 : *tc_map = 1; /* tc0 only */
10681 : : else
10682 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10683 : :
10684 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10685 : 0 : dcb_cfg->pfc.willing = 0;
10686 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10687 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10688 : : }
10689 : : return 0;
10690 : : }
10691 : :
10692 : :
10693 : : static enum i40e_status_code
10694 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10695 : : struct i40e_aqc_vsi_properties_data *info,
10696 : : uint8_t enabled_tcmap)
10697 : : {
10698 : : enum i40e_status_code ret;
10699 : : int i, total_tc = 0;
10700 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10701 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10702 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10703 : : uint16_t used_queues;
10704 : :
10705 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10706 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10707 : : return ret;
10708 : :
10709 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10710 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10711 : 0 : total_tc++;
10712 : : }
10713 [ # # ]: 0 : if (total_tc == 0)
10714 : : total_tc = 1;
10715 : 0 : vsi->enabled_tc = enabled_tcmap;
10716 : :
10717 : : /* different VSI has different queues assigned */
10718 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10719 : 0 : used_queues = dev_data->nb_rx_queues -
10720 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10721 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10722 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10723 : : else {
10724 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10725 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10726 : : }
10727 : :
10728 : 0 : qpnum_per_tc = used_queues / total_tc;
10729 : : /* Number of queues per enabled TC */
10730 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10731 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10732 : 0 : return I40E_ERR_INVALID_QP_ID;
10733 : : }
10734 : 0 : qpnum_per_tc = RTE_MIN((uint16_t)i40e_align_floor(qpnum_per_tc),
10735 : : I40E_MAX_Q_PER_TC);
10736 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10737 : :
10738 : : /**
10739 : : * Configure TC and queue mapping parameters, for enabled TC,
10740 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10741 : : * default queue will serve it.
10742 : : */
10743 : : qp_idx = 0;
10744 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10745 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10746 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10747 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10748 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10749 : 0 : qp_idx += qpnum_per_tc;
10750 : : } else
10751 : 0 : info->tc_mapping[i] = 0;
10752 : : }
10753 : :
10754 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10755 : : if (vsi->type == I40E_VSI_SRIOV) {
10756 : : info->mapping_flags |=
10757 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10758 : : for (i = 0; i < vsi->nb_qps; i++)
10759 : : info->queue_mapping[i] =
10760 : : rte_cpu_to_le_16(vsi->base_queue + i);
10761 : : } else {
10762 : 0 : info->mapping_flags |=
10763 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10764 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10765 : : }
10766 : 0 : info->valid_sections |=
10767 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10768 : :
10769 : 0 : return I40E_SUCCESS;
10770 : : }
10771 : :
10772 : : /*
10773 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10774 : : * @veb: VEB to be configured
10775 : : * @tc_map: enabled TC bitmap
10776 : : *
10777 : : * Returns 0 on success, negative value on failure
10778 : : */
10779 : : static enum i40e_status_code
10780 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10781 : : {
10782 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10783 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10784 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10785 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10786 : : enum i40e_status_code ret = I40E_SUCCESS;
10787 : : int i;
10788 : : uint32_t bw_max;
10789 : :
10790 : : /* Check if enabled_tc is same as existing or new TCs */
10791 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10792 : : return ret;
10793 : :
10794 : : /* configure tc bandwidth */
10795 : : memset(&veb_bw, 0, sizeof(veb_bw));
10796 : 0 : veb_bw.tc_valid_bits = tc_map;
10797 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10798 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10799 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10800 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10801 : : }
10802 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10803 : : &veb_bw, NULL);
10804 [ # # ]: 0 : if (ret) {
10805 : 0 : PMD_INIT_LOG(ERR,
10806 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10807 : : hw->aq.asq_last_status);
10808 : 0 : return ret;
10809 : : }
10810 : :
10811 : : memset(&ets_query, 0, sizeof(ets_query));
10812 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10813 : : &ets_query, NULL);
10814 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10815 : 0 : PMD_DRV_LOG(ERR,
10816 : : "Failed to get switch_comp ETS configuration %u",
10817 : : hw->aq.asq_last_status);
10818 : 0 : return ret;
10819 : : }
10820 : : memset(&bw_query, 0, sizeof(bw_query));
10821 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10822 : : &bw_query, NULL);
10823 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10824 : 0 : PMD_DRV_LOG(ERR,
10825 : : "Failed to get switch_comp bandwidth configuration %u",
10826 : : hw->aq.asq_last_status);
10827 : 0 : return ret;
10828 : : }
10829 : :
10830 : : /* store and print out BW info */
10831 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10832 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10833 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10834 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10835 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10836 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10837 : : I40E_16_BIT_WIDTH);
10838 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10839 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10840 : 0 : bw_query.tc_bw_share_credits[i];
10841 : 0 : veb->bw_info.bw_ets_credits[i] =
10842 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10843 : : /* 4 bits per TC, 4th bit is reserved */
10844 : 0 : veb->bw_info.bw_ets_max[i] =
10845 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10846 : : RTE_LEN2MASK(3, uint8_t));
10847 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10848 : : veb->bw_info.bw_ets_share_credits[i]);
10849 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10850 : : veb->bw_info.bw_ets_credits[i]);
10851 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10852 : : veb->bw_info.bw_ets_max[i]);
10853 : : }
10854 : :
10855 : 0 : veb->enabled_tc = tc_map;
10856 : :
10857 : 0 : return ret;
10858 : : }
10859 : :
10860 : :
10861 : : /*
10862 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10863 : : * @vsi: VSI to be configured
10864 : : * @tc_map: enabled TC bitmap
10865 : : *
10866 : : * Returns 0 on success, negative value on failure
10867 : : */
10868 : : static enum i40e_status_code
10869 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10870 : : {
10871 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10872 : : struct i40e_vsi_context ctxt;
10873 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10874 : : enum i40e_status_code ret = I40E_SUCCESS;
10875 : : int i;
10876 : :
10877 : : /* Check if enabled_tc is same as existing or new TCs */
10878 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10879 : : return ret;
10880 : :
10881 : : /* configure tc bandwidth */
10882 : : memset(&bw_data, 0, sizeof(bw_data));
10883 : 0 : bw_data.tc_valid_bits = tc_map;
10884 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10885 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10886 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10887 : 0 : bw_data.tc_bw_credits[i] = 1;
10888 : : }
10889 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10890 [ # # ]: 0 : if (ret) {
10891 : 0 : PMD_INIT_LOG(ERR,
10892 : : "AQ command Config VSI BW allocation per TC failed = %d",
10893 : : hw->aq.asq_last_status);
10894 : 0 : goto out;
10895 : : }
10896 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10897 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10898 : :
10899 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10900 : 0 : ctxt.seid = vsi->seid;
10901 : 0 : ctxt.pf_num = hw->pf_id;
10902 : 0 : ctxt.vf_num = 0;
10903 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10904 : 0 : ctxt.info = vsi->info;
10905 : 0 : i40e_get_cap(hw);
10906 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10907 [ # # ]: 0 : if (ret)
10908 : 0 : goto out;
10909 : :
10910 : : /* Update the VSI after updating the VSI queue-mapping information */
10911 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10912 [ # # ]: 0 : if (ret) {
10913 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10914 : : hw->aq.asq_last_status);
10915 : 0 : goto out;
10916 : : }
10917 : : /* update the local VSI info with updated queue map */
10918 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10919 : : sizeof(vsi->info.tc_mapping));
10920 : 0 : memcpy(&vsi->info.queue_mapping,
10921 : : &ctxt.info.queue_mapping,
10922 : : sizeof(vsi->info.queue_mapping));
10923 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10924 : 0 : vsi->info.valid_sections = 0;
10925 : :
10926 : : /* query and update current VSI BW information */
10927 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10928 [ # # ]: 0 : if (ret) {
10929 : 0 : PMD_INIT_LOG(ERR,
10930 : : "Failed updating vsi bw info, err %s aq_err %s",
10931 : : i40e_stat_str(hw, ret),
10932 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10933 : 0 : goto out;
10934 : : }
10935 : :
10936 : 0 : vsi->enabled_tc = tc_map;
10937 : :
10938 : : out:
10939 : : return ret;
10940 : : }
10941 : :
10942 : : /*
10943 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10944 : : * @pf: pf the configuration is taken on
10945 : : * @new_cfg: new configuration
10946 : : * @tc_map: enabled TC bitmap
10947 : : *
10948 : : * Returns 0 on success, negative value on failure
10949 : : */
10950 : : static enum i40e_status_code
10951 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10952 : : struct i40e_dcbx_config *new_cfg,
10953 : : uint8_t tc_map)
10954 : : {
10955 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10956 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10957 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10958 : : struct i40e_vsi_list *vsi_list;
10959 : : enum i40e_status_code ret;
10960 : : int i;
10961 : : uint32_t val;
10962 : :
10963 : : /* Use the FW API if FW > v4.4*/
10964 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10965 : : (hw->aq.fw_maj_ver >= 5))) {
10966 : 0 : PMD_INIT_LOG(ERR,
10967 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10968 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10969 : : }
10970 : :
10971 : : /* Check if need reconfiguration */
10972 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10973 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10974 : 0 : return I40E_SUCCESS;
10975 : : }
10976 : :
10977 : : /* Copy the new config to the current config */
10978 : 0 : *old_cfg = *new_cfg;
10979 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10980 : 0 : ret = i40e_set_dcb_config(hw);
10981 [ # # ]: 0 : if (ret) {
10982 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10983 : : i40e_stat_str(hw, ret),
10984 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10985 : 0 : return ret;
10986 : : }
10987 : : /* set receive Arbiter to RR mode and ETS scheme by default */
10988 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10989 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10990 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10991 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10992 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10993 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10994 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10995 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10996 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10997 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10998 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10999 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
11000 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
11001 : : }
11002 : : /* get local mib to check whether it is configured correctly */
11003 : : /* IEEE mode */
11004 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
11005 : : /* Get Local DCB Config */
11006 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
11007 : : &hw->local_dcbx_config);
11008 : :
11009 : : /* if Veb is created, need to update TC of it at first */
11010 [ # # ]: 0 : if (main_vsi->veb) {
11011 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11012 [ # # ]: 0 : if (ret)
11013 : 0 : PMD_INIT_LOG(WARNING,
11014 : : "Failed configuring TC for VEB seid=%d",
11015 : : main_vsi->veb->seid);
11016 : : }
11017 : : /* Update each VSI */
11018 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
11019 [ # # ]: 0 : if (main_vsi->veb) {
11020 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11021 : : /* Beside main VSI and VMDQ VSIs, only enable default
11022 : : * TC for other VSIs
11023 : : */
11024 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11025 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11026 : : tc_map);
11027 : : else
11028 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11029 : : I40E_DEFAULT_TCMAP);
11030 [ # # ]: 0 : if (ret)
11031 : 0 : PMD_INIT_LOG(WARNING,
11032 : : "Failed configuring TC for VSI seid=%d",
11033 : : vsi_list->vsi->seid);
11034 : : /* continue */
11035 : : }
11036 : : }
11037 : : return I40E_SUCCESS;
11038 : : }
11039 : :
11040 : : /*
11041 : : * i40e_dcb_init_configure - initial dcb config
11042 : : * @dev: device being configured
11043 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
11044 : : *
11045 : : * Returns 0 on success, negative value on failure
11046 : : */
11047 : : int
11048 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11049 : : {
11050 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11051 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11052 : : int i, ret = 0;
11053 : :
11054 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11055 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11056 : 0 : return -ENOTSUP;
11057 : : }
11058 : :
11059 : : /* DCB initialization:
11060 : : * Update DCB configuration from the Firmware and configure
11061 : : * LLDP MIB change event.
11062 : : */
11063 [ # # ]: 0 : if (sw_dcb == TRUE) {
11064 : : /* Stopping lldp is necessary for DPDK, but it will cause
11065 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
11066 : : * for successful initialization of DCB is that LLDP is
11067 : : * enabled. So it is needed to start lldp before DCB init
11068 : : * and stop it after initialization.
11069 : : */
11070 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11071 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11072 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11073 : :
11074 : 0 : ret = i40e_init_dcb(hw, true);
11075 : : /* If lldp agent is stopped, the return value from
11076 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11077 : : * adminq status. Otherwise, it should return success.
11078 : : */
11079 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11080 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11081 : 0 : memset(&hw->local_dcbx_config, 0,
11082 : : sizeof(struct i40e_dcbx_config));
11083 : : /* set dcb default configuration */
11084 : : hw->local_dcbx_config.etscfg.willing = 0;
11085 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
11086 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11087 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
11088 : : I40E_IEEE_TSA_ETS;
11089 : : /* all UPs mapping to TC0 */
11090 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11091 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11092 : 0 : hw->local_dcbx_config.etsrec =
11093 : : hw->local_dcbx_config.etscfg;
11094 : : hw->local_dcbx_config.pfc.willing = 0;
11095 : 0 : hw->local_dcbx_config.pfc.pfccap =
11096 : : I40E_MAX_TRAFFIC_CLASS;
11097 : : /* FW needs one App to configure HW */
11098 : 0 : hw->local_dcbx_config.numapps = 1;
11099 : 0 : hw->local_dcbx_config.app[0].selector =
11100 : : I40E_APP_SEL_ETHTYPE;
11101 : 0 : hw->local_dcbx_config.app[0].priority = 3;
11102 : 0 : hw->local_dcbx_config.app[0].protocolid =
11103 : : I40E_APP_PROTOID_FCOE;
11104 : 0 : ret = i40e_set_dcb_config(hw);
11105 [ # # ]: 0 : if (ret) {
11106 : 0 : PMD_INIT_LOG(ERR,
11107 : : "default dcb config fails. err = %d, aq_err = %d.",
11108 : : ret, hw->aq.asq_last_status);
11109 : 0 : return -ENOSYS;
11110 : : }
11111 : : } else {
11112 : 0 : PMD_INIT_LOG(ERR,
11113 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
11114 : : ret, hw->aq.asq_last_status);
11115 : 0 : return -ENOTSUP;
11116 : : }
11117 : :
11118 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
11119 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11120 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11121 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11122 : : }
11123 : : } else {
11124 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11125 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11126 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11127 : :
11128 : 0 : ret = i40e_init_dcb(hw, true);
11129 [ # # ]: 0 : if (!ret) {
11130 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11131 : 0 : PMD_INIT_LOG(ERR,
11132 : : "HW doesn't support DCBX offload.");
11133 : 0 : return -ENOTSUP;
11134 : : }
11135 : : } else {
11136 : 0 : PMD_INIT_LOG(ERR,
11137 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11138 : : ret, hw->aq.asq_last_status);
11139 : 0 : return -ENOTSUP;
11140 : : }
11141 : : }
11142 : : return 0;
11143 : : }
11144 : :
11145 : : /*
11146 : : * i40e_dcb_setup - setup dcb related config
11147 : : * @dev: device being configured
11148 : : *
11149 : : * Returns 0 on success, negative value on failure
11150 : : */
11151 : : static int
11152 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11153 : : {
11154 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11155 : : struct i40e_dcbx_config dcb_cfg;
11156 : 0 : uint8_t tc_map = 0;
11157 : : int ret = 0;
11158 : :
11159 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11160 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11161 : 0 : return -ENOTSUP;
11162 : : }
11163 : :
11164 [ # # ]: 0 : if (pf->vf_num != 0)
11165 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11166 : :
11167 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11168 [ # # ]: 0 : if (ret) {
11169 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11170 : 0 : return -EINVAL;
11171 : : }
11172 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11173 [ # # ]: 0 : if (ret) {
11174 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11175 : 0 : return -ENOSYS;
11176 : : }
11177 : :
11178 : : return 0;
11179 : : }
11180 : :
11181 : : static int
11182 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11183 : : struct rte_eth_dcb_info *dcb_info)
11184 : : {
11185 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11186 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11187 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11188 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11189 : : uint16_t bsf, tc_mapping;
11190 : : int i, j = 0;
11191 : :
11192 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11193 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11194 : : else
11195 : 0 : dcb_info->nb_tcs = 1;
11196 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11197 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11198 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11199 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11200 : :
11201 : : /* get queue mapping if vmdq is disabled */
11202 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11203 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11204 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11205 : 0 : continue;
11206 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11207 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11208 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11209 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11210 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11211 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11212 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11213 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11214 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11215 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11216 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11217 : : }
11218 : : return 0;
11219 : : }
11220 : :
11221 : : /* get queue mapping if vmdq is enabled */
11222 : : do {
11223 : 0 : vsi = pf->vmdq[j].vsi;
11224 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11225 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11226 : 0 : continue;
11227 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11228 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11229 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11230 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11231 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11232 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11233 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11234 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11235 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11236 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11237 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11238 : : }
11239 : 0 : j++;
11240 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11241 : : return 0;
11242 : : }
11243 : :
11244 : : static int
11245 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11246 : : {
11247 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11248 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11249 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11250 : : uint16_t msix_intr;
11251 : :
11252 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11253 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11254 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11255 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11256 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11257 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11258 : : else
11259 : 0 : I40E_WRITE_REG(hw,
11260 : : I40E_PFINT_DYN_CTLN(msix_intr -
11261 : : I40E_RX_VEC_START),
11262 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11263 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11264 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11265 : :
11266 : 0 : I40E_WRITE_FLUSH(hw);
11267 : 0 : rte_intr_ack(pci_dev->intr_handle);
11268 : :
11269 : 0 : return 0;
11270 : : }
11271 : :
11272 : : static int
11273 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11274 : : {
11275 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11276 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11277 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11278 : : uint16_t msix_intr;
11279 : :
11280 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11281 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11282 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11283 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11284 : : else
11285 : 0 : I40E_WRITE_REG(hw,
11286 : : I40E_PFINT_DYN_CTLN(msix_intr -
11287 : : I40E_RX_VEC_START),
11288 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11289 : 0 : I40E_WRITE_FLUSH(hw);
11290 : :
11291 : 0 : return 0;
11292 : : }
11293 : :
11294 : : /**
11295 : : * This function is used to check if the register is valid.
11296 : : * Below is the valid registers list for X722 only:
11297 : : * 0x2b800--0x2bb00
11298 : : * 0x38700--0x38a00
11299 : : * 0x3d800--0x3db00
11300 : : * 0x208e00--0x209000
11301 : : * 0x20be00--0x20c000
11302 : : * 0x263c00--0x264000
11303 : : * 0x265c00--0x266000
11304 : : */
11305 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11306 : : {
11307 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11308 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11309 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11310 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11311 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11312 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11313 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11314 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11315 : : return 0;
11316 : : else
11317 : 0 : return 1;
11318 : : }
11319 : :
11320 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11321 : : struct rte_dev_reg_info *regs)
11322 : : {
11323 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11324 : 0 : uint32_t *ptr_data = regs->data;
11325 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11326 : : const struct i40e_reg_info *reg_info;
11327 : :
11328 [ # # ]: 0 : if (ptr_data == NULL) {
11329 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11330 : 0 : regs->width = sizeof(uint32_t);
11331 : 0 : return 0;
11332 : : }
11333 : :
11334 : : /* The first few registers have to be read using AQ operations */
11335 : : reg_idx = 0;
11336 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11337 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11338 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11339 : : for (arr_idx2 = 0;
11340 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11341 : 0 : arr_idx2++) {
11342 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11343 : 0 : arr_idx2 * reg_info->stride2;
11344 : 0 : reg_offset += reg_info->base_addr;
11345 : 0 : ptr_data[reg_offset >> 2] =
11346 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11347 : : }
11348 : : }
11349 : :
11350 : : /* The remaining registers can be read using primitives */
11351 : : reg_idx = 0;
11352 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11353 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11354 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11355 : : for (arr_idx2 = 0;
11356 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11357 : 0 : arr_idx2++) {
11358 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11359 : 0 : arr_idx2 * reg_info->stride2;
11360 : 0 : reg_offset += reg_info->base_addr;
11361 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11362 : 0 : ptr_data[reg_offset >> 2] = 0;
11363 : : else
11364 : 0 : ptr_data[reg_offset >> 2] =
11365 : 0 : I40E_READ_REG(hw, reg_offset);
11366 : : }
11367 : : }
11368 : :
11369 : : return 0;
11370 : : }
11371 : :
11372 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11373 : : {
11374 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11375 : :
11376 : : /* Convert word count to byte count */
11377 : 0 : return hw->nvm.sr_size << 1;
11378 : : }
11379 : :
11380 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11381 : : struct rte_dev_eeprom_info *eeprom)
11382 : : {
11383 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11384 : 0 : uint16_t *data = eeprom->data;
11385 : : uint32_t offset, length;
11386 : : uint16_t cnt_words;
11387 : : int ret_code;
11388 : :
11389 : 0 : offset = eeprom->offset >> 1;
11390 : 0 : length = eeprom->length >> 1;
11391 : 0 : cnt_words = length;
11392 : :
11393 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11394 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11395 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11396 : 0 : return -EINVAL;
11397 : : }
11398 : :
11399 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11400 : :
11401 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11402 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11403 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11404 : 0 : return -EIO;
11405 : : }
11406 : :
11407 : : return 0;
11408 : : }
11409 : :
11410 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11411 : : struct rte_eth_dev_module_info *modinfo)
11412 : : {
11413 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11414 : 0 : uint32_t sff8472_comp = 0;
11415 : 0 : uint32_t sff8472_swap = 0;
11416 : 0 : uint32_t sff8636_rev = 0;
11417 : : i40e_status status;
11418 : : uint32_t type = 0;
11419 : :
11420 : : /* Check if firmware supports reading module EEPROM. */
11421 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11422 : 0 : PMD_DRV_LOG(ERR,
11423 : : "Module EEPROM memory read not supported. "
11424 : : "Please update the NVM image.");
11425 : 0 : return -EINVAL;
11426 : : }
11427 : :
11428 : 0 : status = i40e_update_link_info(hw);
11429 [ # # ]: 0 : if (status)
11430 : : return -EIO;
11431 : :
11432 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11433 : 0 : PMD_DRV_LOG(ERR,
11434 : : "Cannot read module EEPROM memory. "
11435 : : "No module connected.");
11436 : 0 : return -EINVAL;
11437 : : }
11438 : :
11439 : 0 : type = hw->phy.link_info.module_type[0];
11440 : :
11441 [ # # # # ]: 0 : switch (type) {
11442 : 0 : case I40E_MODULE_TYPE_SFP:
11443 : 0 : status = i40e_aq_get_phy_register(hw,
11444 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11445 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11446 : : I40E_MODULE_SFF_8472_COMP,
11447 : : &sff8472_comp, NULL);
11448 [ # # ]: 0 : if (status)
11449 : : return -EIO;
11450 : :
11451 : 0 : status = i40e_aq_get_phy_register(hw,
11452 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11453 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11454 : : I40E_MODULE_SFF_8472_SWAP,
11455 : : &sff8472_swap, NULL);
11456 [ # # ]: 0 : if (status)
11457 : : return -EIO;
11458 : :
11459 : : /* Check if the module requires address swap to access
11460 : : * the other EEPROM memory page.
11461 : : */
11462 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11463 : 0 : PMD_DRV_LOG(WARNING,
11464 : : "Module address swap to access "
11465 : : "page 0xA2 is not supported.");
11466 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11467 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11468 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11469 : : /* Module is not SFF-8472 compliant */
11470 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11471 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11472 : : } else {
11473 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11474 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11475 : : }
11476 : : break;
11477 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11478 : : /* Read from memory page 0. */
11479 : 0 : status = i40e_aq_get_phy_register(hw,
11480 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11481 : : 0, 1,
11482 : : I40E_MODULE_REVISION_ADDR,
11483 : : &sff8636_rev, NULL);
11484 [ # # ]: 0 : if (status)
11485 : : return -EIO;
11486 : : /* Determine revision compliance byte */
11487 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11488 : : /* Module is SFF-8636 compliant */
11489 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11490 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11491 : : } else {
11492 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11493 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11494 : : }
11495 : : break;
11496 : 0 : case I40E_MODULE_TYPE_QSFP28:
11497 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11498 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11499 : 0 : break;
11500 : 0 : default:
11501 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized");
11502 : 0 : return -EINVAL;
11503 : : }
11504 : : return 0;
11505 : : }
11506 : :
11507 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11508 : : struct rte_dev_eeprom_info *info)
11509 : : {
11510 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11511 : : bool is_sfp = false;
11512 : : i40e_status status;
11513 : : uint8_t *data;
11514 : 0 : uint32_t value = 0;
11515 : : uint32_t i;
11516 : :
11517 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11518 : : is_sfp = true;
11519 : :
11520 : 0 : data = info->data;
11521 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11522 : 0 : u32 offset = i + info->offset;
11523 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11524 : :
11525 : : /* Check if we need to access the other memory page */
11526 [ # # ]: 0 : if (is_sfp) {
11527 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11528 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11529 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11530 : : }
11531 : : } else {
11532 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11533 : : /* Compute memory page number and offset. */
11534 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11535 : 0 : addr++;
11536 : : }
11537 : : }
11538 : 0 : status = i40e_aq_get_phy_register(hw,
11539 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11540 : : addr, 1, offset, &value, NULL);
11541 [ # # ]: 0 : if (status)
11542 : : return -EIO;
11543 : 0 : data[i] = (uint8_t)value;
11544 : : }
11545 : : return 0;
11546 : : }
11547 : :
11548 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11549 : : struct rte_ether_addr *mac_addr)
11550 : : {
11551 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11552 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11553 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11554 : : struct i40e_mac_filter_info mac_filter;
11555 : : struct i40e_mac_filter *f;
11556 : : int ret;
11557 : :
11558 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11559 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11560 : 0 : return -EINVAL;
11561 : : }
11562 : :
11563 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11564 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11565 : : &f->mac_info.mac_addr))
11566 : : break;
11567 : : }
11568 : :
11569 [ # # ]: 0 : if (f == NULL) {
11570 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11571 : 0 : return -EIO;
11572 : : }
11573 : :
11574 : 0 : mac_filter = f->mac_info;
11575 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11576 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11577 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11578 : 0 : return -EIO;
11579 : : }
11580 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11581 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11582 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11583 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11584 : 0 : return -EIO;
11585 : : }
11586 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11587 : :
11588 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11589 : 0 : mac_addr->addr_bytes, NULL);
11590 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11591 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11592 : 0 : return -EIO;
11593 : : }
11594 : :
11595 : : return 0;
11596 : : }
11597 : :
11598 : : static int
11599 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11600 : : {
11601 : : /* mtu setting is forbidden if port is start */
11602 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11603 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11604 : : dev->data->port_id);
11605 : 0 : return -EBUSY;
11606 : : }
11607 : :
11608 : : return 0;
11609 : : }
11610 : :
11611 : : /* Restore ethertype filter */
11612 : : static void
11613 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11614 : : {
11615 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11616 : : struct i40e_ethertype_filter_list
11617 : : *ethertype_list = &pf->ethertype.ethertype_list;
11618 : : struct i40e_ethertype_filter *f;
11619 : : struct i40e_control_filter_stats stats;
11620 : : uint16_t flags;
11621 : :
11622 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11623 : : flags = 0;
11624 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11625 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11626 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11627 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11628 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11629 : :
11630 : : memset(&stats, 0, sizeof(stats));
11631 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11632 : 0 : f->input.mac_addr.addr_bytes,
11633 : 0 : f->input.ether_type,
11634 : 0 : flags, pf->main_vsi->seid,
11635 : 0 : f->queue, 1, &stats, NULL);
11636 : : }
11637 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11638 : : " mac_etype_used = %u, etype_used = %u,"
11639 : : " mac_etype_free = %u, etype_free = %u",
11640 : : stats.mac_etype_used, stats.etype_used,
11641 : : stats.mac_etype_free, stats.etype_free);
11642 : 0 : }
11643 : :
11644 : : /* Restore tunnel filter */
11645 : : static void
11646 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11647 : : {
11648 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11649 : : struct i40e_vsi *vsi;
11650 : : struct i40e_pf_vf *vf;
11651 : : struct i40e_tunnel_filter_list
11652 : : *tunnel_list = &pf->tunnel.tunnel_list;
11653 : : struct i40e_tunnel_filter *f;
11654 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11655 : : bool big_buffer = 0;
11656 : :
11657 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11658 [ # # ]: 0 : if (!f->is_to_vf)
11659 : 0 : vsi = pf->main_vsi;
11660 : : else {
11661 : 0 : vf = &pf->vfs[f->vf_id];
11662 : 0 : vsi = vf->vsi;
11663 : : }
11664 : : memset(&cld_filter, 0, sizeof(cld_filter));
11665 : : rte_ether_addr_copy((struct rte_ether_addr *)
11666 : : &f->input.outer_mac,
11667 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11668 : : rte_ether_addr_copy((struct rte_ether_addr *)
11669 : : &f->input.inner_mac,
11670 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11671 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11672 : 0 : cld_filter.element.flags = f->input.flags;
11673 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11674 : 0 : cld_filter.element.queue_number = f->queue;
11675 : : memcpy(cld_filter.general_fields,
11676 [ # # ]: 0 : f->input.general_fields,
11677 : : sizeof(f->input.general_fields));
11678 : :
11679 [ # # ]: 0 : if (((f->input.flags &
11680 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11681 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11682 : : ((f->input.flags &
11683 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11684 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11685 : : ((f->input.flags &
11686 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11687 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11688 : : big_buffer = 1;
11689 : :
11690 [ # # ]: 0 : if (big_buffer)
11691 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11692 : 0 : vsi->seid, &cld_filter, 1);
11693 : : else
11694 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11695 : : &cld_filter.element, 1);
11696 : : }
11697 : 0 : }
11698 : :
11699 : : static void
11700 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11701 : : {
11702 : 0 : i40e_ethertype_filter_restore(pf);
11703 : 0 : i40e_tunnel_filter_restore(pf);
11704 : 0 : i40e_fdir_filter_restore(pf);
11705 : 0 : (void)i40e_hash_filter_restore(pf);
11706 : 0 : }
11707 : :
11708 : : bool
11709 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11710 : : {
11711 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11712 : 0 : return false;
11713 : :
11714 : : return true;
11715 : : }
11716 : :
11717 : : bool
11718 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11719 : : {
11720 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11721 : : }
11722 : :
11723 : : struct i40e_customized_pctype*
11724 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11725 : : {
11726 : : int i;
11727 : :
11728 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11729 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11730 : 0 : return &pf->customized_pctype[i];
11731 : : }
11732 : : return NULL;
11733 : : }
11734 : :
11735 : : static int
11736 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11737 : : uint32_t pkg_size, uint32_t proto_num,
11738 : : struct rte_pmd_i40e_proto_info *proto,
11739 : : enum rte_pmd_i40e_package_op op)
11740 : : {
11741 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11742 : : uint32_t pctype_num;
11743 : 0 : struct rte_pmd_i40e_ptype_info pctype[I40E_CUSTOMIZED_MAX] = {0};
11744 : : struct i40e_customized_pctype *new_pctype = NULL;
11745 : : uint8_t proto_id;
11746 : : uint8_t pctype_value;
11747 : : char name[64];
11748 : : uint32_t i, j, n;
11749 : : int ret;
11750 : :
11751 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11752 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11753 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11754 : 0 : return -1;
11755 : : }
11756 : :
11757 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11758 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11759 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11760 [ # # ]: 0 : if (ret) {
11761 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11762 : 0 : return -1;
11763 : : }
11764 [ # # ]: 0 : if (!pctype_num) {
11765 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11766 : 0 : return -1;
11767 : : }
11768 : :
11769 [ # # ]: 0 : if (pctype_num > RTE_DIM(pctype)) {
11770 : 0 : PMD_DRV_LOG(ERR, "Pctype number exceeds maximum supported");
11771 : 0 : return -1;
11772 : : }
11773 : : /* get information about new pctype list */
11774 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11775 : : (uint8_t *)pctype, sizeof(pctype),
11776 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11777 [ # # ]: 0 : if (ret) {
11778 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11779 : 0 : return -1;
11780 : : }
11781 : :
11782 : : /* Update customized pctype. */
11783 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11784 : 0 : pctype_value = pctype[i].ptype_id;
11785 : : memset(name, 0, sizeof(name));
11786 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11787 : 0 : proto_id = pctype[i].protocols[j];
11788 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11789 : 0 : continue;
11790 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11791 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11792 : : continue;
11793 : 0 : strlcat(name, proto[n].name, sizeof(name));
11794 : 0 : strlcat(name, "_", sizeof(name));
11795 : 0 : break;
11796 : : }
11797 : : }
11798 : 0 : name[strlen(name) - 1] = '\0';
11799 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11800 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11801 : : new_pctype =
11802 : 0 : i40e_find_customized_pctype(pf,
11803 : : I40E_CUSTOMIZED_GTPC);
11804 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11805 : : new_pctype =
11806 : 0 : i40e_find_customized_pctype(pf,
11807 : : I40E_CUSTOMIZED_GTPU_IPV4);
11808 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11809 : : new_pctype =
11810 : 0 : i40e_find_customized_pctype(pf,
11811 : : I40E_CUSTOMIZED_GTPU_IPV6);
11812 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11813 : : new_pctype =
11814 : 0 : i40e_find_customized_pctype(pf,
11815 : : I40E_CUSTOMIZED_GTPU);
11816 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11817 : : new_pctype =
11818 : 0 : i40e_find_customized_pctype(pf,
11819 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11820 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11821 : : new_pctype =
11822 : 0 : i40e_find_customized_pctype(pf,
11823 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11824 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11825 : : new_pctype =
11826 : 0 : i40e_find_customized_pctype(pf,
11827 : : I40E_CUSTOMIZED_ESP_IPV4);
11828 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11829 : : new_pctype =
11830 : 0 : i40e_find_customized_pctype(pf,
11831 : : I40E_CUSTOMIZED_ESP_IPV6);
11832 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11833 : : new_pctype =
11834 : 0 : i40e_find_customized_pctype(pf,
11835 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11836 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11837 : : new_pctype =
11838 : 0 : i40e_find_customized_pctype(pf,
11839 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11840 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11841 : : new_pctype =
11842 : 0 : i40e_find_customized_pctype(pf,
11843 : : I40E_CUSTOMIZED_AH_IPV4);
11844 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11845 : : new_pctype =
11846 : 0 : i40e_find_customized_pctype(pf,
11847 : : I40E_CUSTOMIZED_AH_IPV6);
11848 [ # # ]: 0 : if (new_pctype) {
11849 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11850 : 0 : new_pctype->pctype = pctype_value;
11851 : 0 : new_pctype->valid = true;
11852 : : } else {
11853 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11854 : 0 : new_pctype->valid = false;
11855 : : }
11856 : : }
11857 : : }
11858 : :
11859 : : return 0;
11860 : : }
11861 : :
11862 : : static int
11863 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11864 : : uint32_t pkg_size, uint32_t proto_num,
11865 : : struct rte_pmd_i40e_proto_info *proto,
11866 : : enum rte_pmd_i40e_package_op op)
11867 : : {
11868 : 0 : struct rte_pmd_i40e_ptype_mapping ptype_mapping[I40E_MAX_PKT_TYPE] = {0};
11869 : 0 : uint16_t port_id = dev->data->port_id;
11870 : : uint32_t ptype_num;
11871 : 0 : struct rte_pmd_i40e_ptype_info ptype[I40E_MAX_PKT_TYPE] = {0};
11872 : : uint8_t proto_id;
11873 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11874 : : uint32_t i, j, n;
11875 : : bool in_tunnel;
11876 : : int ret;
11877 : :
11878 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11879 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11880 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11881 : 0 : return -1;
11882 : : }
11883 : :
11884 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11885 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11886 : 0 : return 0;
11887 : : }
11888 : :
11889 : : /* get information about new ptype num */
11890 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11891 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11892 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11893 [ # # ]: 0 : if (ret) {
11894 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11895 : 0 : return ret;
11896 : : }
11897 [ # # ]: 0 : if (!ptype_num) {
11898 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11899 : 0 : return -1;
11900 : : }
11901 : :
11902 [ # # ]: 0 : if (ptype_num > RTE_DIM(ptype)) {
11903 : 0 : PMD_DRV_LOG(ERR, "Too many ptypes");
11904 : 0 : return -1;
11905 : : }
11906 : :
11907 : : /* get information about new ptype list */
11908 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11909 : : (uint8_t *)ptype, sizeof(ptype),
11910 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11911 [ # # ]: 0 : if (ret) {
11912 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11913 : 0 : return ret;
11914 : : }
11915 : :
11916 : : /* Update ptype mapping table. */
11917 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11918 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11919 : 0 : ptype_mapping[i].sw_ptype = 0;
11920 : : in_tunnel = false;
11921 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11922 : 0 : proto_id = ptype[i].protocols[j];
11923 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11924 : 0 : continue;
11925 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11926 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11927 : : continue;
11928 : 0 : strlcpy(name, proto[n].name, sizeof(name));
11929 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11930 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11931 : 0 : ptype_mapping[i].sw_ptype |=
11932 : : RTE_PTYPE_L2_ETHER_PPPOE;
11933 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11934 : : !in_tunnel) {
11935 : 0 : ptype_mapping[i].sw_ptype |=
11936 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11937 : 0 : ptype_mapping[i].sw_ptype |=
11938 : : RTE_PTYPE_L4_FRAG;
11939 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11940 : : in_tunnel) {
11941 : 0 : ptype_mapping[i].sw_ptype |=
11942 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11943 : 0 : ptype_mapping[i].sw_ptype |=
11944 : : RTE_PTYPE_INNER_L4_FRAG;
11945 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11946 : 0 : ptype_mapping[i].sw_ptype |=
11947 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11948 : : in_tunnel = true;
11949 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11950 : : !in_tunnel)
11951 : 0 : ptype_mapping[i].sw_ptype |=
11952 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11953 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11954 : : in_tunnel)
11955 : 0 : ptype_mapping[i].sw_ptype |=
11956 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11957 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11958 : : !in_tunnel) {
11959 : 0 : ptype_mapping[i].sw_ptype |=
11960 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11961 : 0 : ptype_mapping[i].sw_ptype |=
11962 : : RTE_PTYPE_L4_FRAG;
11963 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11964 : : in_tunnel) {
11965 : 0 : ptype_mapping[i].sw_ptype |=
11966 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11967 : 0 : ptype_mapping[i].sw_ptype |=
11968 : : RTE_PTYPE_INNER_L4_FRAG;
11969 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
11970 : 0 : ptype_mapping[i].sw_ptype |=
11971 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11972 : : in_tunnel = true;
11973 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
11974 : : !in_tunnel)
11975 : 0 : ptype_mapping[i].sw_ptype |=
11976 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11977 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
11978 : : in_tunnel)
11979 : 0 : ptype_mapping[i].sw_ptype |=
11980 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11981 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11982 : : !in_tunnel)
11983 : 0 : ptype_mapping[i].sw_ptype |=
11984 : : RTE_PTYPE_L4_UDP;
11985 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11986 : : in_tunnel)
11987 : 0 : ptype_mapping[i].sw_ptype |=
11988 : : RTE_PTYPE_INNER_L4_UDP;
11989 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11990 : : !in_tunnel)
11991 : 0 : ptype_mapping[i].sw_ptype |=
11992 : : RTE_PTYPE_L4_TCP;
11993 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11994 : : in_tunnel)
11995 : 0 : ptype_mapping[i].sw_ptype |=
11996 : : RTE_PTYPE_INNER_L4_TCP;
11997 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11998 : : !in_tunnel)
11999 : 0 : ptype_mapping[i].sw_ptype |=
12000 : : RTE_PTYPE_L4_SCTP;
12001 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
12002 : : in_tunnel)
12003 : 0 : ptype_mapping[i].sw_ptype |=
12004 : : RTE_PTYPE_INNER_L4_SCTP;
12005 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12006 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12007 : : !in_tunnel)
12008 : 0 : ptype_mapping[i].sw_ptype |=
12009 : : RTE_PTYPE_L4_ICMP;
12010 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12011 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12012 : : in_tunnel)
12013 : 0 : ptype_mapping[i].sw_ptype |=
12014 : : RTE_PTYPE_INNER_L4_ICMP;
12015 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
12016 : 0 : ptype_mapping[i].sw_ptype |=
12017 : : RTE_PTYPE_TUNNEL_GTPC;
12018 : : in_tunnel = true;
12019 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
12020 : 0 : ptype_mapping[i].sw_ptype |=
12021 : : RTE_PTYPE_TUNNEL_GTPU;
12022 : : in_tunnel = true;
12023 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
12024 : 0 : ptype_mapping[i].sw_ptype |=
12025 : : RTE_PTYPE_TUNNEL_ESP;
12026 : : in_tunnel = true;
12027 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
12028 : 0 : ptype_mapping[i].sw_ptype |=
12029 : : RTE_PTYPE_TUNNEL_GRENAT;
12030 : : in_tunnel = true;
12031 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12032 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
12033 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
12034 : 0 : ptype_mapping[i].sw_ptype |=
12035 : : RTE_PTYPE_TUNNEL_L2TP;
12036 : : in_tunnel = true;
12037 : : }
12038 : :
12039 : : break;
12040 : : }
12041 : : }
12042 : : }
12043 : :
12044 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12045 : : ptype_num, 0);
12046 [ # # ]: 0 : if (ret)
12047 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12048 : :
12049 : : return ret;
12050 : : }
12051 : :
12052 : : void
12053 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12054 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12055 : : {
12056 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12057 : : uint32_t proto_num;
12058 : : struct rte_pmd_i40e_proto_info *proto;
12059 : : uint32_t buff_size;
12060 : : uint32_t i;
12061 : : int ret;
12062 : :
12063 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12064 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12065 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
12066 : 0 : return;
12067 : : }
12068 : :
12069 : : /* get information about protocol number */
12070 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12071 : : (uint8_t *)&proto_num, sizeof(proto_num),
12072 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12073 [ # # ]: 0 : if (ret) {
12074 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
12075 : 0 : return;
12076 : : }
12077 [ # # ]: 0 : if (!proto_num) {
12078 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
12079 : 0 : return;
12080 : : }
12081 : :
12082 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12083 : 0 : proto = calloc(proto_num, sizeof(struct rte_pmd_i40e_proto_info));
12084 [ # # ]: 0 : if (!proto) {
12085 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
12086 : 0 : return;
12087 : : }
12088 : :
12089 : : /* get information about protocol list */
12090 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12091 : : (uint8_t *)proto, buff_size,
12092 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12093 [ # # ]: 0 : if (ret) {
12094 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
12095 : 0 : free(proto);
12096 : 0 : return;
12097 : : }
12098 : :
12099 : : /* Check if GTP is supported. */
12100 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12101 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12102 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12103 : 0 : pf->gtp_support = true;
12104 : : else
12105 : 0 : pf->gtp_support = false;
12106 : : break;
12107 : : }
12108 : : }
12109 : :
12110 : : /* Check if ESP is supported. */
12111 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12112 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12113 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12114 : 0 : pf->esp_support = true;
12115 : : else
12116 : 0 : pf->esp_support = false;
12117 : : break;
12118 : : }
12119 : : }
12120 : :
12121 : : /* Update customized pctype info */
12122 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12123 : : proto_num, proto, op);
12124 [ # # ]: 0 : if (ret)
12125 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12126 : :
12127 : : /* Update customized ptype info */
12128 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12129 : : proto_num, proto, op);
12130 [ # # ]: 0 : if (ret)
12131 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12132 : :
12133 : 0 : free(proto);
12134 : : }
12135 : :
12136 : : /* Create a QinQ cloud filter
12137 : : *
12138 : : * The Fortville NIC has limited resources for tunnel filters,
12139 : : * so we can only reuse existing filters.
12140 : : *
12141 : : * In step 1 we define which Field Vector fields can be used for
12142 : : * filter types.
12143 : : * As we do not have the inner tag defined as a field,
12144 : : * we have to define it first, by reusing one of L1 entries.
12145 : : *
12146 : : * In step 2 we are replacing one of existing filter types with
12147 : : * a new one for QinQ.
12148 : : * As we reusing L1 and replacing L2, some of the default filter
12149 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12150 : : *
12151 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12152 : : *
12153 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12154 : : * later when we define the cloud filter.
12155 : : * a. Valid_flags.replace_cloud = 0
12156 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12157 : : * c. New_filter = 0x10
12158 : : * d. TR bit = 0xff (optional, not used here)
12159 : : * e. Buffer – 2 entries:
12160 : : * i. Byte 0 = 8 (outer vlan FV index).
12161 : : * Byte 1 = 0 (rsv)
12162 : : * Byte 2-3 = 0x0fff
12163 : : * ii. Byte 0 = 37 (inner vlan FV index).
12164 : : * Byte 1 =0 (rsv)
12165 : : * Byte 2-3 = 0x0fff
12166 : : *
12167 : : * Step 2:
12168 : : * 2. Create cloud filter using two L1 filters entries: stag and
12169 : : * new filter(outer vlan+ inner vlan)
12170 : : * a. Valid_flags.replace_cloud = 1
12171 : : * b. Old_filter = 1 (instead of outer IP)
12172 : : * c. New_filter = 0x10
12173 : : * d. Buffer – 2 entries:
12174 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12175 : : * Byte 1-3 = 0 (rsv)
12176 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12177 : : * Byte 9-11 = 0 (rsv)
12178 : : */
12179 : : static int
12180 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12181 : : {
12182 : : int ret = -ENOTSUP;
12183 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12184 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12185 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12186 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12187 : :
12188 [ # # ]: 0 : if (pf->support_multi_driver) {
12189 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12190 : 0 : return ret;
12191 : : }
12192 : :
12193 : : /* Init */
12194 : : memset(&filter_replace, 0,
12195 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12196 : : memset(&filter_replace_buf, 0,
12197 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12198 : :
12199 : : /* create L1 filter */
12200 : 0 : filter_replace.old_filter_type =
12201 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12202 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12203 : : filter_replace.tr_bit = 0;
12204 : :
12205 : : /* Prepare the buffer, 2 entries */
12206 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12207 : 0 : filter_replace_buf.data[0] |=
12208 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12209 : : /* Field Vector 12b mask */
12210 : 0 : filter_replace_buf.data[2] = 0xff;
12211 : 0 : filter_replace_buf.data[3] = 0x0f;
12212 : : filter_replace_buf.data[4] =
12213 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12214 : 0 : filter_replace_buf.data[4] |=
12215 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12216 : : /* Field Vector 12b mask */
12217 : 0 : filter_replace_buf.data[6] = 0xff;
12218 : 0 : filter_replace_buf.data[7] = 0x0f;
12219 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12220 : : &filter_replace_buf);
12221 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12222 : : return ret;
12223 : :
12224 : 0 : if (filter_replace.old_filter_type !=
12225 [ # # ]: 0 : filter_replace.new_filter_type)
12226 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12227 : : " original: 0x%x, new: 0x%x",
12228 : : dev->device->name,
12229 : : filter_replace.old_filter_type,
12230 : : filter_replace.new_filter_type);
12231 : :
12232 : : /* Apply the second L2 cloud filter */
12233 : : memset(&filter_replace, 0,
12234 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12235 : : memset(&filter_replace_buf, 0,
12236 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12237 : :
12238 : : /* create L2 filter, input for L2 filter will be L1 filter */
12239 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12240 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12241 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12242 : :
12243 : : /* Prepare the buffer, 2 entries */
12244 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12245 : 0 : filter_replace_buf.data[0] |=
12246 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12247 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12248 : 0 : filter_replace_buf.data[4] |=
12249 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12250 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12251 : : &filter_replace_buf);
12252 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12253 [ # # ]: 0 : filter_replace.new_filter_type))
12254 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12255 : : " original: 0x%x, new: 0x%x",
12256 : : dev->device->name,
12257 : : filter_replace.old_filter_type,
12258 : : filter_replace.new_filter_type);
12259 : :
12260 : : return ret;
12261 : : }
12262 : :
12263 : : static int
12264 : 0 : i40e_fec_get_capability(struct rte_eth_dev *dev,
12265 : : struct rte_eth_fec_capa *speed_fec_capa, __rte_unused unsigned int num)
12266 : : {
12267 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12268 : :
12269 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12270 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12271 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12272 : : " firmware. Please update the NVM image.");
12273 : 0 : return -ENOTSUP;
12274 : : }
12275 : :
12276 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_25G_SFP28 ||
12277 : : hw->device_id == I40E_DEV_ID_25G_B) {
12278 [ # # ]: 0 : if (speed_fec_capa) {
12279 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12280 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
12281 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
12282 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12283 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12284 : : }
12285 : :
12286 : : /* since HW only supports 25G */
12287 : 0 : return 1;
12288 [ # # ]: 0 : } else if (hw->device_id == I40E_DEV_ID_KX_X722) {
12289 [ # # ]: 0 : if (speed_fec_capa) {
12290 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12291 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12292 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12293 : : }
12294 : 0 : return 1;
12295 : : }
12296 : :
12297 : : return -ENOTSUP;
12298 : : }
12299 : :
12300 : : static int
12301 : 0 : i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
12302 : : {
12303 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12304 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12305 : 0 : struct i40e_link_status link_status = {0};
12306 : : uint8_t current_fec_mode = 0, fec_config = 0;
12307 : : bool link_up, enable_lse;
12308 : : int ret = 0;
12309 : :
12310 : 0 : enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
12311 : : /* Get link info */
12312 : 0 : ret = i40e_aq_get_link_info(hw, enable_lse, &link_status, NULL);
12313 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
12314 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
12315 : : ret);
12316 : 0 : return -ENOTSUP;
12317 : : }
12318 : :
12319 : 0 : link_up = link_status.link_info & I40E_AQ_LINK_UP;
12320 : :
12321 : 0 : ret = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12322 : : NULL);
12323 [ # # ]: 0 : if (ret) {
12324 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12325 : : ret);
12326 : 0 : return -ENOTSUP;
12327 : : }
12328 : :
12329 : : /**
12330 : : * If link is down and AUTO is enabled, AUTO is returned,
12331 : : * otherwise, configured FEC mode is returned.
12332 : : * If link is up, current FEC mode is returned.
12333 : : */
12334 : 0 : fec_config = abilities.fec_cfg_curr_mod_ext_info
12335 : : & I40E_AQ_PHY_FEC_CONFIG_MASK;
12336 : 0 : current_fec_mode = link_status.fec_info;
12337 : :
12338 [ # # ]: 0 : if (link_up) {
12339 [ # # # # ]: 0 : switch (current_fec_mode) {
12340 : 0 : case I40E_AQ_CONFIG_FEC_KR_ENA:
12341 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12342 : 0 : break;
12343 : 0 : case I40E_AQ_CONFIG_FEC_RS_ENA:
12344 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12345 : 0 : break;
12346 : 0 : case 0:
12347 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12348 : 0 : break;
12349 : : default:
12350 : : return -EINVAL;
12351 : : }
12352 : 0 : return 0;
12353 : : }
12354 : :
12355 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_AUTO) {
12356 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO);
12357 : 0 : return 0;
12358 : : }
12359 : :
12360 : : uint32_t temp_fec_capa = 0;
12361 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_KR)
12362 : : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12363 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_RS)
12364 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12365 : : if (temp_fec_capa == 0)
12366 : : temp_fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12367 : :
12368 : 0 : *fec_capa = temp_fec_capa;
12369 : 0 : return 0;
12370 : : }
12371 : :
12372 : : static int
12373 : 0 : i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
12374 : : {
12375 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12376 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12377 : 0 : struct i40e_aq_set_phy_config config = {0};
12378 : : enum i40e_status_code status;
12379 : : uint8_t req_fec = 0, fec_auto = 0, fec_kr = 0, fec_rs = 0;
12380 : :
12381 : 0 : if (hw->device_id != I40E_DEV_ID_25G_SFP28 &&
12382 [ # # ]: 0 : hw->device_id != I40E_DEV_ID_25G_B &&
12383 : : hw->device_id != I40E_DEV_ID_KX_X722) {
12384 : : return -ENOTSUP;
12385 : : }
12386 : :
12387 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12388 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12389 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12390 : : " firmware. Please update the NVM image.");
12391 : 0 : return -ENOTSUP;
12392 : : }
12393 : :
12394 : : /**
12395 : : * Copy the current user PHY configuration. The current user PHY
12396 : : * configuration is initialized during probe from PHY capabilities
12397 : : * software mode, and updated on set PHY configuration.
12398 : : */
12399 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12400 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) | RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
12401 : : return -EINVAL;
12402 : :
12403 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
12404 : : fec_auto = 1;
12405 : :
12406 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
12407 : : fec_kr = 1;
12408 : :
12409 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
12410 : : fec_rs = 1;
12411 : :
12412 [ # # ]: 0 : if (fec_auto) {
12413 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12414 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: AUTO");
12415 : 0 : return -EINVAL;
12416 : : }
12417 [ # # ]: 0 : if (fec_kr || fec_rs) {
12418 [ # # ]: 0 : if (fec_kr)
12419 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12420 : : I40E_AQ_SET_FEC_REQUEST_KR;
12421 [ # # ]: 0 : if (fec_rs) {
12422 : : if (hw->mac.type == I40E_MAC_X722) {
12423 : : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12424 : : return -EINVAL;
12425 : : }
12426 : 0 : req_fec |= I40E_AQ_SET_FEC_ABILITY_RS |
12427 : : I40E_AQ_SET_FEC_REQUEST_RS;
12428 : : }
12429 : : } else {
12430 : : if (hw->mac.type == I40E_MAC_X722) {
12431 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12432 : : I40E_AQ_SET_FEC_REQUEST_KR;
12433 : : } else {
12434 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12435 : : I40E_AQ_SET_FEC_REQUEST_KR |
12436 : : I40E_AQ_SET_FEC_ABILITY_RS |
12437 : : I40E_AQ_SET_FEC_REQUEST_RS;
12438 : : }
12439 : : }
12440 : : } else {
12441 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
12442 [ # # ]: 0 : if (fec_kr) {
12443 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12444 : : I40E_AQ_SET_FEC_REQUEST_KR;
12445 : : } else {
12446 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12447 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12448 : 0 : return -EINVAL;
12449 : : }
12450 : : req_fec = I40E_AQ_SET_FEC_ABILITY_RS |
12451 : : I40E_AQ_SET_FEC_REQUEST_RS;
12452 : : }
12453 : : } else {
12454 : : return -EINVAL;
12455 : : }
12456 : : }
12457 : :
12458 : : /* Get the current phy config */
12459 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12460 : : NULL);
12461 [ # # ]: 0 : if (status) {
12462 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12463 : : status);
12464 : 0 : return -ENOTSUP;
12465 : : }
12466 : :
12467 [ # # ]: 0 : if (abilities.fec_cfg_curr_mod_ext_info != req_fec) {
12468 : 0 : config.phy_type = abilities.phy_type;
12469 : 0 : config.abilities = abilities.abilities |
12470 : : I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
12471 : 0 : config.phy_type_ext = abilities.phy_type_ext;
12472 : 0 : config.link_speed = abilities.link_speed;
12473 : 0 : config.eee_capability = abilities.eee_capability;
12474 : 0 : config.eeer = abilities.eeer_val;
12475 : 0 : config.low_power_ctrl = abilities.d3_lpan;
12476 : 0 : config.fec_config = req_fec & I40E_AQ_PHY_FEC_CONFIG_MASK;
12477 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
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 : :
12485 : 0 : status = i40e_update_link_info(hw);
12486 [ # # ]: 0 : if (status) {
12487 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12488 : : status);
12489 : 0 : return -ENOTSUP;
12490 : : }
12491 : :
12492 : : return 0;
12493 : : }
12494 : :
12495 [ - + ]: 303 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12496 [ - + ]: 303 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12497 : : #ifdef RTE_ETHDEV_DEBUG_RX
12498 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12499 : : #endif
12500 : : #ifdef RTE_ETHDEV_DEBUG_TX
12501 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12502 : : #endif
12503 : :
12504 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12505 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12506 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12507 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12508 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|