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 : 302 : 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 : 0 : 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 : : /* A new configuration reverts the RETA to the driver default. */
1996 : 0 : pf->adapter->rss_reta_updated = 0;
1997 : :
1998 : : /* Program the default RETA now while the Rx queue count is known, so that
1999 : : * a query before the port is started reflects the configured queues.
2000 : : */
2001 : 0 : ret = i40e_pf_reset_rss_reta(pf);
2002 [ # # ]: 0 : if (ret)
2003 : : return ret;
2004 : :
2005 : 0 : ret = i40e_dev_init_vlan(dev);
2006 [ # # ]: 0 : if (ret < 0)
2007 : 0 : goto err;
2008 : :
2009 : : /* VMDQ setup.
2010 : : * General PMD call sequence are NIC init, configure,
2011 : : * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
2012 : : * will try to lookup the VSI that specific queue belongs to if VMDQ
2013 : : * applicable. So, VMDQ setting has to be done before
2014 : : * rx/tx_queue_setup(). This function is good to place vmdq_setup.
2015 : : * For RSS setting, it will try to calculate actual configured RX queue
2016 : : * number, which will be available after rx_queue_setup(). dev_start()
2017 : : * function is good to place RSS setup.
2018 : : */
2019 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
2020 : 0 : ret = i40e_vmdq_setup(dev);
2021 [ # # ]: 0 : if (ret)
2022 : 0 : goto err;
2023 : : }
2024 : :
2025 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
2026 : 0 : ret = i40e_dcb_setup(dev);
2027 [ # # ]: 0 : if (ret) {
2028 : 0 : PMD_DRV_LOG(ERR, "failed to configure DCB.");
2029 : 0 : goto err_dcb;
2030 : : }
2031 : : }
2032 : :
2033 : 0 : TAILQ_INIT(&pf->flow_list);
2034 : :
2035 : 0 : return 0;
2036 : :
2037 : : err_dcb:
2038 : : /* need to release vmdq resource if exists */
2039 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2040 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2041 : 0 : pf->vmdq[i].vsi = NULL;
2042 : : }
2043 : 0 : rte_free(pf->vmdq);
2044 : 0 : pf->vmdq = NULL;
2045 : : err:
2046 : : return ret;
2047 : : }
2048 : :
2049 : : void
2050 : 0 : i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
2051 : : {
2052 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2053 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2054 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2055 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2056 : 0 : uint16_t msix_vect = vsi->msix_intr;
2057 : : uint16_t i;
2058 : :
2059 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2060 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2061 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2062 : : rte_wmb();
2063 : : }
2064 : :
2065 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2066 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2067 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2068 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
2069 : 0 : I40E_WRITE_REG(hw,
2070 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2071 : : 0);
2072 : : } else {
2073 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2074 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
2075 : 0 : I40E_WRITE_REG(hw,
2076 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2077 : : msix_vect - 1), 0);
2078 : : }
2079 : : } else {
2080 : : uint32_t reg;
2081 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2082 : 0 : vsi->user_param + (msix_vect - 1);
2083 : :
2084 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2085 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
2086 : : }
2087 : 0 : I40E_WRITE_FLUSH(hw);
2088 : 0 : }
2089 : :
2090 : : static void
2091 : 0 : __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
2092 : : int base_queue, int nb_queue,
2093 : : uint16_t itr_idx)
2094 : : {
2095 : : int i;
2096 : : uint32_t val;
2097 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2098 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2099 : :
2100 : : /* Bind all RX queues to allocated MSIX interrupt */
2101 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
2102 : 0 : val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2103 : 0 : itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
2104 : 0 : ((base_queue + i + 1) <<
2105 : 0 : I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
2106 : 0 : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
2107 : : I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2108 : :
2109 [ # # ]: 0 : if (i == nb_queue - 1)
2110 : 0 : val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
2111 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
2112 : : }
2113 : :
2114 : : /* Write first RX queue to Link list register as the head element */
2115 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2116 : : uint16_t interval =
2117 : : i40e_calc_itr_interval(1, pf->support_multi_driver);
2118 : :
2119 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2120 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2121 : : (base_queue <<
2122 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2123 : : (0x0 <<
2124 : : I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2125 : 0 : I40E_WRITE_REG(hw,
2126 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2127 : : interval);
2128 : : } else {
2129 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2130 : : (base_queue <<
2131 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2132 : : (0x0 <<
2133 : : I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2134 : 0 : I40E_WRITE_REG(hw,
2135 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2136 : : msix_vect - 1),
2137 : : interval);
2138 : : }
2139 : : } else {
2140 : : uint32_t reg;
2141 : :
2142 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2143 : 0 : I40E_WRITE_REG(hw,
2144 : : I40E_VPINT_LNKLST0(vsi->user_param),
2145 : : (base_queue <<
2146 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2147 : : (0x0 <<
2148 : : I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2149 : : } else {
2150 : : /* num_msix_vectors_vf needs to minus irq0 */
2151 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2152 : 0 : vsi->user_param + (msix_vect - 1);
2153 : :
2154 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2155 : : (base_queue <<
2156 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2157 : : (0x0 <<
2158 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2159 : : }
2160 : : }
2161 : :
2162 : 0 : I40E_WRITE_FLUSH(hw);
2163 : 0 : }
2164 : :
2165 : : int
2166 : 0 : i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2167 : : {
2168 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2169 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2170 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2171 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2172 : 0 : uint16_t msix_vect = vsi->msix_intr;
2173 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2174 : : rte_intr_nb_efd_get(intr_handle));
2175 : : uint16_t queue_idx = 0;
2176 : : int record = 0;
2177 : : int i;
2178 : :
2179 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2180 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2181 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2182 : : }
2183 : :
2184 : : /* VF bind interrupt */
2185 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
2186 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2187 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2188 : 0 : return -EINVAL;
2189 : : }
2190 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2191 : 0 : vsi->base_queue, vsi->nb_qps,
2192 : : itr_idx);
2193 : 0 : return 0;
2194 : : }
2195 : :
2196 : : /* PF & VMDq bind interrupt */
2197 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2198 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN) {
2199 : : queue_idx = 0;
2200 : : record = 1;
2201 [ # # ]: 0 : } else if (vsi->type == I40E_VSI_VMDQ2) {
2202 : : struct i40e_vsi *main_vsi =
2203 [ # # ]: 0 : I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2204 : 0 : queue_idx = vsi->base_queue - main_vsi->nb_qps;
2205 : : record = 1;
2206 : : }
2207 : : }
2208 : :
2209 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
2210 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2211 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2212 : 0 : return -EINVAL;
2213 [ # # ]: 0 : } else if (nb_msix <= 1) {
2214 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2215 : : /* allow to share MISC_VEC_ID */
2216 : : msix_vect = I40E_MISC_VEC_ID;
2217 : :
2218 : : /* no enough msix_vect, map all to one */
2219 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2220 : 0 : vsi->base_queue + i,
2221 : 0 : vsi->nb_used_qps - i,
2222 : : itr_idx);
2223 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
2224 : 0 : rte_intr_vec_list_index_set(intr_handle,
2225 : : queue_idx + i, msix_vect);
2226 : : break;
2227 : : }
2228 : : /* 1:1 queue/msix_vect mapping */
2229 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2230 : 0 : vsi->base_queue + i, 1,
2231 : : itr_idx);
2232 [ # # ]: 0 : if (!!record)
2233 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle,
2234 : : queue_idx + i, msix_vect))
2235 : 0 : return -rte_errno;
2236 : :
2237 : 0 : msix_vect++;
2238 : 0 : nb_msix--;
2239 : : }
2240 : :
2241 : : return 0;
2242 : : }
2243 : :
2244 : : void
2245 : 0 : i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2246 : : {
2247 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2248 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2249 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2250 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2251 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2252 : : uint16_t msix_intr, i;
2253 : :
2254 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2255 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2256 : 0 : msix_intr = vsi->msix_intr + i;
2257 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2258 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
2259 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2260 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2261 : : }
2262 : : else
2263 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2264 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
2265 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2266 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2267 : :
2268 : 0 : I40E_WRITE_FLUSH(hw);
2269 : 0 : }
2270 : :
2271 : : void
2272 : 0 : i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2273 : : {
2274 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2275 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2276 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2277 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2278 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2279 : : uint16_t msix_intr, i;
2280 : :
2281 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2282 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2283 : 0 : msix_intr = vsi->msix_intr + i;
2284 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2285 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2286 : : }
2287 : : else
2288 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2289 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2290 : :
2291 : 0 : I40E_WRITE_FLUSH(hw);
2292 : 0 : }
2293 : :
2294 : : static inline uint8_t
2295 : 0 : i40e_parse_link_speeds(uint16_t link_speeds)
2296 : : {
2297 : : uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2298 : :
2299 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2300 : : link_speed |= I40E_LINK_SPEED_40GB;
2301 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2302 : 0 : link_speed |= I40E_LINK_SPEED_25GB;
2303 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2304 : 0 : link_speed |= I40E_LINK_SPEED_20GB;
2305 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2306 : 0 : link_speed |= I40E_LINK_SPEED_10GB;
2307 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2308 : 0 : link_speed |= I40E_LINK_SPEED_1GB;
2309 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2310 : 0 : link_speed |= I40E_LINK_SPEED_100MB;
2311 : :
2312 : 0 : return link_speed;
2313 : : }
2314 : :
2315 : : static int
2316 : 0 : i40e_phy_conf_link(struct i40e_hw *hw,
2317 : : uint8_t abilities,
2318 : : uint8_t force_speed,
2319 : : bool is_up)
2320 : : {
2321 : : enum i40e_status_code status;
2322 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
2323 : : struct i40e_aq_set_phy_config phy_conf;
2324 : : enum i40e_aq_phy_type cnt;
2325 : : uint8_t avail_speed;
2326 : : uint32_t phy_type_mask = 0;
2327 : :
2328 : : const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2329 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2330 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2331 : : I40E_AQ_PHY_FLAG_LOW_POWER;
2332 : : int ret = -ENOTSUP;
2333 : :
2334 : : /* To get phy capabilities of available speeds. */
2335 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2336 : : NULL);
2337 [ # # ]: 0 : if (status) {
2338 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
2339 : : status);
2340 : 0 : return ret;
2341 : : }
2342 : 0 : avail_speed = phy_ab.link_speed;
2343 : :
2344 : : /* To get the current phy config. */
2345 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2346 : : NULL);
2347 [ # # ]: 0 : if (status) {
2348 : 0 : PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d",
2349 : : status);
2350 : 0 : return ret;
2351 : : }
2352 : :
2353 : : /* If link needs to go up and it is in autoneg mode the speed is OK,
2354 : : * no need to set up again.
2355 : : */
2356 [ # # # # : 0 : if (is_up && phy_ab.phy_type != 0 &&
# # ]
2357 : 0 : abilities & I40E_AQ_PHY_AN_ENABLED &&
2358 [ # # ]: 0 : phy_ab.link_speed != 0)
2359 : : return I40E_SUCCESS;
2360 : :
2361 : : memset(&phy_conf, 0, sizeof(phy_conf));
2362 : :
2363 : : /* bits 0-2 use the values from get_phy_abilities_resp */
2364 : 0 : abilities &= ~mask;
2365 : 0 : abilities |= phy_ab.abilities & mask;
2366 : :
2367 : 0 : phy_conf.abilities = abilities;
2368 : :
2369 : : /* If link needs to go up, but the force speed is not supported,
2370 : : * Warn users and config the default available speeds.
2371 : : */
2372 [ # # # # ]: 0 : if (is_up && !(force_speed & avail_speed)) {
2373 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!");
2374 : 0 : phy_conf.link_speed = avail_speed;
2375 : : } else {
2376 [ # # ]: 0 : phy_conf.link_speed = is_up ? force_speed : avail_speed;
2377 : : }
2378 : :
2379 : : /* PHY type mask needs to include each type except PHY type extension */
2380 [ # # ]: 0 : for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2381 : 0 : phy_type_mask |= 1 << cnt;
2382 : :
2383 : : /* use get_phy_abilities_resp value for the rest */
2384 [ # # ]: 0 : phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2385 [ # # ]: 0 : phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2386 : : I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2387 : : I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2388 : : I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2389 : 0 : phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2390 : 0 : phy_conf.eee_capability = phy_ab.eee_capability;
2391 : 0 : phy_conf.eeer = phy_ab.eeer_val;
2392 : 0 : phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2393 : :
2394 : 0 : PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2395 : : phy_ab.abilities, phy_ab.link_speed);
2396 : 0 : PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2397 : : phy_conf.abilities, phy_conf.link_speed);
2398 : :
2399 : 0 : status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2400 [ # # ]: 0 : if (status)
2401 : 0 : return ret;
2402 : :
2403 : : return I40E_SUCCESS;
2404 : : }
2405 : :
2406 : : static int
2407 : 0 : i40e_apply_link_speed(struct rte_eth_dev *dev)
2408 : : {
2409 : : uint8_t speed;
2410 : : uint8_t abilities = 0;
2411 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2412 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
2413 : :
2414 : : abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2415 : : I40E_AQ_PHY_LINK_ENABLED;
2416 : :
2417 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2418 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2419 : : RTE_ETH_LINK_SPEED_25G |
2420 : : RTE_ETH_LINK_SPEED_20G |
2421 : : RTE_ETH_LINK_SPEED_10G |
2422 : : RTE_ETH_LINK_SPEED_1G |
2423 : : RTE_ETH_LINK_SPEED_100M;
2424 : :
2425 : : abilities |= I40E_AQ_PHY_AN_ENABLED;
2426 : : } else {
2427 : : abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2428 : : }
2429 : 0 : speed = i40e_parse_link_speeds(conf->link_speeds);
2430 : :
2431 : 0 : return i40e_phy_conf_link(hw, abilities, speed, true);
2432 : : }
2433 : :
2434 : : static int
2435 : 0 : i40e_dev_start(struct rte_eth_dev *dev)
2436 : : {
2437 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2438 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2439 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2440 : : struct i40e_adapter *ad =
2441 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2442 : : int ret, i;
2443 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2444 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2445 : : uint32_t intr_vector = 0;
2446 : : struct i40e_vsi *vsi;
2447 : : uint16_t nb_rxq, nb_txq;
2448 : : uint16_t max_frame_size;
2449 : :
2450 : 0 : hw->adapter_stopped = 0;
2451 : :
2452 : 0 : rte_intr_disable(intr_handle);
2453 : :
2454 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2455 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2456 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2457 : 0 : intr_vector = dev->data->nb_rx_queues;
2458 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
2459 [ # # ]: 0 : if (ret)
2460 : : return ret;
2461 : : }
2462 : :
2463 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2464 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2465 : 0 : dev->data->nb_rx_queues)) {
2466 : 0 : PMD_INIT_LOG(ERR,
2467 : : "Failed to allocate %d rx_queues intr_vec",
2468 : : dev->data->nb_rx_queues);
2469 : 0 : return -ENOMEM;
2470 : : }
2471 : : }
2472 : :
2473 : : /* Initialize VSI */
2474 : 0 : ret = i40e_dev_rxtx_init(pf);
2475 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2476 : 0 : PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2477 : 0 : return ret;
2478 : : }
2479 : :
2480 : : /* Map queues with MSIX interrupt */
2481 : 0 : main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2482 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2483 : 0 : ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2484 [ # # ]: 0 : if (ret < 0)
2485 : : return ret;
2486 : 0 : i40e_vsi_enable_queues_intr(main_vsi);
2487 : :
2488 : : /* Map VMDQ VSI queues with MSIX interrupt */
2489 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2490 : 0 : pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2491 : 0 : ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2492 : : I40E_ITR_INDEX_DEFAULT);
2493 [ # # ]: 0 : if (ret < 0)
2494 : 0 : return ret;
2495 : 0 : i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2496 : : }
2497 : :
2498 : : /* Enable all queues which have been configured */
2499 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2500 : 0 : ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2501 [ # # ]: 0 : if (ret)
2502 : 0 : goto rx_err;
2503 : : }
2504 : :
2505 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2506 : 0 : ret = i40e_dev_tx_queue_start(dev, nb_txq);
2507 [ # # ]: 0 : if (ret)
2508 : 0 : goto tx_err;
2509 : : }
2510 : :
2511 : : /* Enable receiving broadcast packets */
2512 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2513 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2514 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2515 : :
2516 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2517 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2518 : : true, NULL);
2519 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2520 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2521 : : }
2522 : :
2523 : : /* Enable the VLAN promiscuous mode. */
2524 [ # # ]: 0 : if (pf->vfs) {
2525 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
2526 : 0 : vsi = pf->vfs[i].vsi;
2527 : 0 : i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2528 : : true, NULL);
2529 : : }
2530 : : }
2531 : :
2532 : : /* Disable mac loopback mode */
2533 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE) {
2534 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MODE_NONE, NULL);
2535 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2536 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2537 : 0 : goto tx_err;
2538 : : }
2539 : : }
2540 : :
2541 : : /* Enable mac loopback mode */
2542 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_EN) {
2543 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2544 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC_LOCAL_X722, NULL);
2545 : : else
2546 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC, NULL);
2547 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2548 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2549 : 0 : goto tx_err;
2550 : : }
2551 : : }
2552 : :
2553 : : /* Apply link configure */
2554 : 0 : ret = i40e_apply_link_speed(dev);
2555 [ # # ]: 0 : if (I40E_SUCCESS != ret) {
2556 : 0 : PMD_DRV_LOG(ERR, "Fail to apply link setting");
2557 : 0 : goto tx_err;
2558 : : }
2559 : :
2560 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2561 : 0 : rte_intr_callback_unregister(intr_handle,
2562 : : i40e_dev_interrupt_handler,
2563 : : (void *)dev);
2564 : : /* configure and enable device interrupt */
2565 : : i40e_pf_config_irq0(hw, FALSE);
2566 : 0 : i40e_pf_enable_irq0(hw);
2567 : :
2568 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2569 : 0 : PMD_INIT_LOG(INFO,
2570 : : "lsc won't enable because of no intr multiplex");
2571 : : } else {
2572 : 0 : ret = i40e_aq_set_phy_int_mask(hw,
2573 : : ~(I40E_AQ_EVENT_LINK_UPDOWN |
2574 : : I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2575 : : I40E_AQ_EVENT_MEDIA_NA), NULL);
2576 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2577 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2578 : : }
2579 : :
2580 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2581 : 0 : i40e_dev_link_update(dev, 0);
2582 : 0 : pf->mac_config_on_link_up = !dev->data->dev_link.link_status;
2583 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2584 : : i40e_dev_alarm_handler, dev);
2585 : : } else {
2586 : : /* Block if no interrupt handler can process link-up events, to help
2587 : : * ensure that MAC config is applied when the link is up.
2588 : : */
2589 : 0 : i40e_dev_link_update(dev, !rte_intr_allow_others(intr_handle));
2590 : 0 : pf->mac_config_on_link_up = !dev->data->dev_link.link_status;
2591 : : /* enable uio intr after callback register */
2592 [ # # ]: 0 : if (rte_intr_enable(intr_handle) != 0) {
2593 [ # # ]: 0 : if (rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2594 : : i40e_dev_alarm_handler, dev) != 0)
2595 : 0 : PMD_DRV_LOG(WARNING, "Failed to set alarm");
2596 : : else
2597 : 0 : pf->use_aq_polling = true;
2598 : : }
2599 : : }
2600 : :
2601 : 0 : i40e_filter_restore(pf);
2602 : :
2603 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2604 : 0 : PMD_DRV_LOG(WARNING,
2605 : : "please call hierarchy_commit() "
2606 : : "before starting the port");
2607 : :
2608 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2609 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2610 : : I40E_FRAME_SIZE_MAX;
2611 : 0 : ad->max_pkt_len = max_frame_size;
2612 : :
2613 : : /* Set the max frame size to HW*/
2614 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2615 : :
2616 : 0 : return I40E_SUCCESS;
2617 : :
2618 : 0 : tx_err:
2619 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2620 : 0 : i40e_dev_tx_queue_stop(dev, i);
2621 : 0 : rx_err:
2622 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2623 : 0 : i40e_dev_rx_queue_stop(dev, i);
2624 : :
2625 : : return ret;
2626 : : }
2627 : :
2628 : : static int
2629 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2630 : : {
2631 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2632 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2633 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2634 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2635 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2636 : : int i;
2637 : :
2638 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2639 : : return 0;
2640 : :
2641 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2642 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2643 : 0 : rte_intr_enable(intr_handle);
2644 [ # # ]: 0 : } else if (pf->use_aq_polling) {
2645 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2646 : 0 : pf->use_aq_polling = false;
2647 : : }
2648 : :
2649 : : /* Disable all queues */
2650 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2651 : 0 : i40e_dev_tx_queue_stop(dev, i);
2652 : :
2653 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2654 : 0 : i40e_dev_rx_queue_stop(dev, i);
2655 : :
2656 : : /* un-map queues with interrupt registers */
2657 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2658 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2659 : :
2660 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2661 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2662 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2663 : : }
2664 : :
2665 : : /* Clear all queues and release memory */
2666 : 0 : i40e_dev_clear_queues(dev);
2667 : :
2668 : : /* Set link down */
2669 : : i40e_dev_set_link_down(dev);
2670 : :
2671 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2672 : : /* resume to the default handler */
2673 : 0 : rte_intr_callback_register(intr_handle,
2674 : : i40e_dev_interrupt_handler,
2675 : : (void *)dev);
2676 : :
2677 : : /* Clean datapath event and queue/vec mapping */
2678 : 0 : rte_intr_efd_disable(intr_handle);
2679 : :
2680 : : /* Cleanup vector list */
2681 : 0 : rte_intr_vec_list_free(intr_handle);
2682 : :
2683 : : /* reset hierarchy commit */
2684 : 0 : pf->tm_conf.committed = false;
2685 : :
2686 : 0 : hw->adapter_stopped = 1;
2687 : 0 : dev->data->dev_started = 0;
2688 : :
2689 : 0 : return 0;
2690 : : }
2691 : :
2692 : : static int
2693 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2694 : : {
2695 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2696 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2697 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2698 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2699 : : struct i40e_filter_control_settings settings;
2700 : : struct rte_flow *p_flow;
2701 : : uint32_t reg;
2702 : : int i;
2703 : : int ret;
2704 : 0 : uint8_t aq_fail = 0;
2705 : : int retries = 0;
2706 : :
2707 : 0 : PMD_INIT_FUNC_TRACE();
2708 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2709 : : return 0;
2710 : :
2711 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2712 [ # # ]: 0 : if (ret)
2713 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2714 : :
2715 : :
2716 : 0 : ret = i40e_dev_stop(dev);
2717 : :
2718 : 0 : i40e_dev_free_queues(dev);
2719 : :
2720 : : /* Disable interrupt */
2721 : 0 : i40e_pf_disable_irq0(hw);
2722 : 0 : rte_intr_disable(intr_handle);
2723 : :
2724 : : /* shutdown and destroy the HMC */
2725 : 0 : i40e_shutdown_lan_hmc(hw);
2726 : :
2727 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2728 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2729 : 0 : pf->vmdq[i].vsi = NULL;
2730 : : }
2731 : 0 : rte_free(pf->vmdq);
2732 : 0 : pf->vmdq = NULL;
2733 : :
2734 : : /* release all the existing VSIs and VEBs */
2735 : 0 : i40e_vsi_release(pf->main_vsi);
2736 : :
2737 : : /* shutdown the adminq */
2738 : 0 : i40e_aq_queue_shutdown(hw, true);
2739 : 0 : i40e_shutdown_adminq(hw);
2740 : :
2741 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2742 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2743 : :
2744 : : /* Disable flexible payload in global configuration */
2745 [ # # ]: 0 : if (!pf->support_multi_driver)
2746 : 0 : i40e_flex_payload_reg_set_default(hw);
2747 : :
2748 : : /* force a PF reset to clean anything leftover */
2749 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2750 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2751 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2752 : 0 : I40E_WRITE_FLUSH(hw);
2753 : :
2754 : : /* Clear PXE mode */
2755 : 0 : i40e_clear_pxe_mode(hw);
2756 : :
2757 : : /* Unconfigure filter control */
2758 : : memset(&settings, 0, sizeof(settings));
2759 : 0 : ret = i40e_set_filter_control(hw, &settings);
2760 [ # # ]: 0 : if (ret)
2761 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2762 : : ret);
2763 : :
2764 : : /* Disable flow control */
2765 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2766 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2767 : :
2768 : : /* uninitialize pf host driver */
2769 : 0 : i40e_pf_host_uninit(dev);
2770 : :
2771 : : do {
2772 : 0 : int cb_ret = rte_intr_callback_unregister(intr_handle,
2773 : : i40e_dev_interrupt_handler, dev);
2774 [ # # ]: 0 : if (cb_ret >= 0 || cb_ret == -ENOENT) {
2775 : : break;
2776 [ # # ]: 0 : } else if (cb_ret != -EAGAIN) {
2777 : 0 : PMD_INIT_LOG(ERR,
2778 : : "intr callback unregister failed: %d",
2779 : : cb_ret);
2780 [ # # ]: 0 : if (ret == 0)
2781 : : ret = cb_ret;
2782 : : break;
2783 : : }
2784 : 0 : i40e_msec_delay(500);
2785 [ # # ]: 0 : } while (retries++ < 5);
2786 : :
2787 : 0 : i40e_rm_ethtype_filter_list(pf);
2788 : 0 : i40e_rm_tunnel_filter_list(pf);
2789 : : i40e_rm_fdir_filter_list(pf);
2790 : :
2791 : : /* Remove all flows */
2792 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2793 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2794 : : /* Do not free FDIR flows since they are static allocated */
2795 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2796 : 0 : rte_free(p_flow);
2797 : : }
2798 : :
2799 : : /* release the fdir static allocated memory */
2800 : 0 : i40e_fdir_memory_cleanup(pf);
2801 : :
2802 : : /* Remove all Traffic Manager configuration */
2803 : 0 : i40e_tm_conf_uninit(dev);
2804 : :
2805 : : i40e_clear_automask(pf);
2806 : :
2807 : 0 : hw->adapter_closed = 1;
2808 : 0 : return ret;
2809 : : }
2810 : :
2811 : : /*
2812 : : * Reset PF device only to re-initialize resources in PMD layer
2813 : : */
2814 : : static int
2815 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2816 : : {
2817 : : int ret;
2818 : :
2819 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2820 : : * its VF to make them align with it. The detailed notification
2821 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2822 : : * To avoid unexpected behavior in VF, currently reset of PF with
2823 : : * SR-IOV activation is not supported. It might be supported later.
2824 : : */
2825 [ # # ]: 0 : if (dev->data->sriov.active)
2826 : : return -ENOTSUP;
2827 : :
2828 : 0 : ret = eth_i40e_dev_uninit(dev);
2829 [ # # ]: 0 : if (ret)
2830 : : return ret;
2831 : :
2832 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2833 : :
2834 : 0 : return ret;
2835 : : }
2836 : :
2837 : : static int
2838 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2839 : : {
2840 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2841 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2842 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2843 : : int status;
2844 : :
2845 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2846 : : true, NULL, true);
2847 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2848 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2849 : 0 : return -EAGAIN;
2850 : : }
2851 : :
2852 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2853 : : TRUE, NULL);
2854 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2855 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2856 : : /* Rollback unicast promiscuous mode */
2857 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2858 : : false, NULL, true);
2859 : 0 : return -EAGAIN;
2860 : : }
2861 : :
2862 : : return 0;
2863 : : }
2864 : :
2865 : : static int
2866 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2867 : : {
2868 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2869 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2870 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2871 : : int status;
2872 : :
2873 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2874 : : false, NULL, true);
2875 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2876 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2877 : 0 : return -EAGAIN;
2878 : : }
2879 : :
2880 : : /* must remain in all_multicast mode */
2881 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2882 : : return 0;
2883 : :
2884 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2885 : : false, NULL);
2886 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2887 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2888 : : /* Rollback unicast promiscuous mode */
2889 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2890 : : true, NULL, true);
2891 : 0 : return -EAGAIN;
2892 : : }
2893 : :
2894 : : return 0;
2895 : : }
2896 : :
2897 : : static int
2898 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2899 : : {
2900 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2901 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2902 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2903 : : int ret;
2904 : :
2905 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2906 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2907 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2908 : 0 : return -EAGAIN;
2909 : : }
2910 : :
2911 : : return 0;
2912 : : }
2913 : :
2914 : : static int
2915 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2916 : : {
2917 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2918 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2919 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2920 : : int ret;
2921 : :
2922 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2923 : : return 0; /* must remain in all_multicast mode */
2924 : :
2925 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2926 : 0 : vsi->seid, FALSE, NULL);
2927 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2928 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2929 : 0 : return -EAGAIN;
2930 : : }
2931 : :
2932 : : return 0;
2933 : : }
2934 : :
2935 : : /*
2936 : : * Set device link up.
2937 : : */
2938 : : static int
2939 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2940 : : {
2941 : : /* re-apply link speed setting */
2942 : 0 : return i40e_apply_link_speed(dev);
2943 : : }
2944 : :
2945 : : /*
2946 : : * Set device link down.
2947 : : */
2948 : : static int
2949 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2950 : : {
2951 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2952 : : uint8_t abilities = 0;
2953 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2954 : :
2955 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2956 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2957 : : }
2958 : :
2959 : : static __rte_always_inline void
2960 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2961 : : {
2962 : : /* Link status registers and values*/
2963 : : #define I40E_REG_LINK_UP 0x40000080
2964 : : #define I40E_PRTMAC_MACC 0x001E24E0
2965 : : #define I40E_REG_MACC_25GB 0x00020000
2966 : : #define I40E_REG_SPEED_MASK 0x38000000
2967 : : #define I40E_REG_SPEED_0 0x00000000
2968 : : #define I40E_REG_SPEED_1 0x08000000
2969 : : #define I40E_REG_SPEED_2 0x10000000
2970 : : #define I40E_REG_SPEED_3 0x18000000
2971 : : #define I40E_REG_SPEED_4 0x20000000
2972 : : uint32_t link_speed;
2973 : : uint32_t reg_val;
2974 : :
2975 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2976 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2977 : 0 : reg_val &= I40E_REG_LINK_UP;
2978 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2979 : :
2980 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2981 : : return;
2982 : :
2983 : : /* Parse the link status */
2984 [ # # # # : 0 : switch (link_speed) {
# # ]
2985 : 0 : case I40E_REG_SPEED_0:
2986 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2987 : 0 : break;
2988 : 0 : case I40E_REG_SPEED_1:
2989 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2990 : 0 : break;
2991 : 0 : case I40E_REG_SPEED_2:
2992 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2993 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2994 : : else
2995 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2996 : : break;
2997 : 0 : case I40E_REG_SPEED_3:
2998 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2999 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
3000 : : } else {
3001 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
3002 : :
3003 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
3004 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3005 : : else
3006 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3007 : : }
3008 : : break;
3009 : 0 : case I40E_REG_SPEED_4:
3010 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
3011 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3012 : : else
3013 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3014 : : break;
3015 : 0 : default:
3016 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
3017 : 0 : break;
3018 : : }
3019 : : }
3020 : :
3021 : : static __rte_always_inline void
3022 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
3023 : : bool enable_lse, int wait_to_complete)
3024 : : {
3025 : : #define CHECK_INTERVAL 100 /* 100ms */
3026 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3027 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
3028 : : struct i40e_link_status link_status;
3029 : : int status;
3030 : :
3031 : : memset(&link_status, 0, sizeof(link_status));
3032 : :
3033 : : do {
3034 : : memset(&link_status, 0, sizeof(link_status));
3035 : :
3036 : : /* Get link status information from hardware */
3037 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
3038 : : &link_status, NULL);
3039 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
3040 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3041 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3042 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
3043 : 0 : return;
3044 : : }
3045 : :
3046 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
3047 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
3048 : : break;
3049 : :
3050 : : rte_delay_ms(CHECK_INTERVAL);
3051 [ # # ]: 0 : } while (--rep_cnt);
3052 : :
3053 : : /* Parse the link status */
3054 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
3055 : 0 : case I40E_LINK_SPEED_100MB:
3056 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
3057 : 0 : break;
3058 : 0 : case I40E_LINK_SPEED_1GB:
3059 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
3060 : 0 : break;
3061 : 0 : case I40E_LINK_SPEED_10GB:
3062 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3063 : 0 : break;
3064 : 0 : case I40E_LINK_SPEED_20GB:
3065 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3066 : 0 : break;
3067 : 0 : case I40E_LINK_SPEED_25GB:
3068 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3069 : 0 : break;
3070 : 0 : case I40E_LINK_SPEED_40GB:
3071 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3072 : 0 : break;
3073 : 0 : default:
3074 [ # # ]: 0 : if (link->link_status)
3075 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3076 : : else
3077 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3078 : : break;
3079 : : }
3080 : : }
3081 : :
3082 : : int
3083 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
3084 : : int wait_to_complete)
3085 : : {
3086 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3087 : : struct rte_eth_link link;
3088 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3089 : : int ret;
3090 : :
3091 : : memset(&link, 0, sizeof(link));
3092 : :
3093 : : /* i40e uses full duplex only */
3094 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3095 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3096 : : RTE_ETH_LINK_SPEED_FIXED);
3097 : :
3098 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
3099 : : update_link_reg(hw, &link);
3100 : : else
3101 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
3102 : :
3103 [ # # ]: 0 : if (hw->switch_dev)
3104 : 0 : rte_eth_linkstatus_get(hw->switch_dev, &link);
3105 : :
3106 : : ret = rte_eth_linkstatus_set(dev, &link);
3107 : 0 : i40e_notify_all_vfs_link_status(dev);
3108 : :
3109 : 0 : return ret;
3110 : : }
3111 : :
3112 : : static void
3113 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3114 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
3115 : : uint64_t *stat, uint64_t *prev_stat)
3116 : : {
3117 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3118 : : /* enlarge the limitation when statistics counters overflowed */
3119 [ # # ]: 0 : if (offset_loaded) {
3120 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3121 : 0 : *stat += RTE_BIT64(I40E_48_BIT_WIDTH);
3122 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3123 : : }
3124 : 0 : *prev_stat = *stat;
3125 : 0 : }
3126 : :
3127 : : /* Get all the statistics of a VSI */
3128 : : void
3129 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3130 : : {
3131 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3132 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3133 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3134 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3135 : :
3136 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3137 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3138 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3139 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3140 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3141 : 0 : &nes->rx_unicast);
3142 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3143 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3144 : 0 : &nes->rx_multicast);
3145 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3146 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3147 : 0 : &nes->rx_broadcast);
3148 : : /* exclude CRC bytes */
3149 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3150 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3151 : :
3152 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3153 : : &oes->rx_discards, &nes->rx_discards);
3154 : : /* GLV_REPC not supported */
3155 : : /* GLV_RMPC not supported */
3156 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3157 : : &oes->rx_unknown_protocol,
3158 : : &nes->rx_unknown_protocol);
3159 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3160 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3161 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3162 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3163 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3164 : 0 : &nes->tx_unicast);
3165 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3166 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3167 : 0 : &nes->tx_multicast);
3168 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3169 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3170 : 0 : &nes->tx_broadcast);
3171 : : /* GLV_TDPC not supported */
3172 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3173 : : &oes->tx_errors, &nes->tx_errors);
3174 : 0 : vsi->offset_loaded = true;
3175 : :
3176 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3177 : : vsi->vsi_id);
3178 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3179 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3180 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3181 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3182 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3183 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3184 : : nes->rx_unknown_protocol);
3185 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3186 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3187 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3188 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3189 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3190 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3191 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3192 : : vsi->vsi_id);
3193 : 0 : }
3194 : :
3195 : : static void
3196 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3197 : : {
3198 : : unsigned int i;
3199 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3200 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3201 : :
3202 : : /* Get rx/tx bytes of internal transfer packets */
3203 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3204 : 0 : I40E_GLV_GORCL(hw->port),
3205 : 0 : pf->offset_loaded,
3206 : 0 : &pf->internal_stats_offset.rx_bytes,
3207 : 0 : &pf->internal_stats.rx_bytes,
3208 : : &pf->internal_prev_rx_bytes);
3209 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3210 : 0 : I40E_GLV_GOTCL(hw->port),
3211 : 0 : pf->offset_loaded,
3212 : 0 : &pf->internal_stats_offset.tx_bytes,
3213 : 0 : &pf->internal_stats.tx_bytes,
3214 : : &pf->internal_prev_tx_bytes);
3215 : : /* Get total internal rx packet count */
3216 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3217 : 0 : I40E_GLV_UPRCL(hw->port),
3218 : 0 : pf->offset_loaded,
3219 : 0 : &pf->internal_stats_offset.rx_unicast,
3220 : 0 : &pf->internal_stats.rx_unicast);
3221 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3222 : 0 : I40E_GLV_MPRCL(hw->port),
3223 : 0 : pf->offset_loaded,
3224 : 0 : &pf->internal_stats_offset.rx_multicast,
3225 : 0 : &pf->internal_stats.rx_multicast);
3226 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3227 : 0 : I40E_GLV_BPRCL(hw->port),
3228 : 0 : pf->offset_loaded,
3229 : 0 : &pf->internal_stats_offset.rx_broadcast,
3230 : 0 : &pf->internal_stats.rx_broadcast);
3231 : : /* Get total internal tx packet count */
3232 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3233 : 0 : I40E_GLV_UPTCL(hw->port),
3234 : 0 : pf->offset_loaded,
3235 : 0 : &pf->internal_stats_offset.tx_unicast,
3236 : 0 : &pf->internal_stats.tx_unicast);
3237 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3238 : 0 : I40E_GLV_MPTCL(hw->port),
3239 : 0 : pf->offset_loaded,
3240 : 0 : &pf->internal_stats_offset.tx_multicast,
3241 : 0 : &pf->internal_stats.tx_multicast);
3242 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3243 : 0 : I40E_GLV_BPTCL(hw->port),
3244 : 0 : pf->offset_loaded,
3245 : 0 : &pf->internal_stats_offset.tx_broadcast,
3246 : 0 : &pf->internal_stats.tx_broadcast);
3247 : :
3248 : : /* exclude CRC size */
3249 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3250 : 0 : pf->internal_stats.rx_multicast +
3251 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3252 : :
3253 : : /* Get statistics of struct i40e_eth_stats */
3254 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3255 : 0 : I40E_GLPRT_GORCL(hw->port),
3256 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3257 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3258 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3259 : 0 : I40E_GLPRT_UPRCL(hw->port),
3260 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3261 : 0 : &ns->eth.rx_unicast);
3262 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3263 : 0 : I40E_GLPRT_MPRCL(hw->port),
3264 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3265 : 0 : &ns->eth.rx_multicast);
3266 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3267 : 0 : I40E_GLPRT_BPRCL(hw->port),
3268 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3269 : 0 : &ns->eth.rx_broadcast);
3270 : : /* Workaround: CRC size should not be included in byte statistics,
3271 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3272 : : * packet.
3273 : : */
3274 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3275 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3276 : :
3277 : : /* exclude internal rx bytes
3278 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3279 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3280 : : * value.
3281 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3282 : : */
3283 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3284 : 0 : ns->eth.rx_bytes = 0;
3285 : : else
3286 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3287 : :
3288 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3289 : 0 : ns->eth.rx_unicast = 0;
3290 : : else
3291 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3292 : :
3293 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3294 : 0 : ns->eth.rx_multicast = 0;
3295 : : else
3296 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3297 : :
3298 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3299 : 0 : ns->eth.rx_broadcast = 0;
3300 : : else
3301 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3302 : :
3303 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3304 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3305 : : &ns->eth.rx_discards);
3306 : : /* GLPRT_REPC not supported */
3307 : : /* GLPRT_RMPC not supported */
3308 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3309 : 0 : pf->offset_loaded,
3310 : : &os->eth.rx_unknown_protocol,
3311 : : &ns->eth.rx_unknown_protocol);
3312 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1H(hw->pf_id + I40E_MAX_VF),
3313 : 0 : I40E_GL_RXERR1L(hw->pf_id + I40E_MAX_VF),
3314 : 0 : pf->offset_loaded, &os->rx_err1,
3315 : 0 : &ns->rx_err1);
3316 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3317 : 0 : I40E_GLPRT_GOTCL(hw->port),
3318 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3319 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3320 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3321 : 0 : I40E_GLPRT_UPTCL(hw->port),
3322 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3323 : 0 : &ns->eth.tx_unicast);
3324 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3325 : 0 : I40E_GLPRT_MPTCL(hw->port),
3326 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3327 : 0 : &ns->eth.tx_multicast);
3328 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3329 : 0 : I40E_GLPRT_BPTCL(hw->port),
3330 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3331 : 0 : &ns->eth.tx_broadcast);
3332 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3333 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3334 : :
3335 : : /* exclude internal tx bytes
3336 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3337 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3338 : : * value.
3339 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3340 : : */
3341 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3342 : 0 : ns->eth.tx_bytes = 0;
3343 : : else
3344 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3345 : :
3346 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3347 : 0 : ns->eth.tx_unicast = 0;
3348 : : else
3349 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3350 : :
3351 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3352 : 0 : ns->eth.tx_multicast = 0;
3353 : : else
3354 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3355 : :
3356 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3357 : 0 : ns->eth.tx_broadcast = 0;
3358 : : else
3359 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3360 : :
3361 : : /* GLPRT_TEPC not supported */
3362 : :
3363 : : /* additional port specific stats */
3364 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3365 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3366 : : &ns->tx_dropped_link_down);
3367 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3368 : 0 : pf->offset_loaded, &os->crc_errors,
3369 : : &ns->crc_errors);
3370 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3371 : 0 : pf->offset_loaded, &os->illegal_bytes,
3372 : : &ns->illegal_bytes);
3373 : : /* GLPRT_ERRBC not supported */
3374 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3375 : 0 : pf->offset_loaded, &os->mac_local_faults,
3376 : : &ns->mac_local_faults);
3377 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3378 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3379 : : &ns->mac_remote_faults);
3380 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3381 : 0 : pf->offset_loaded, &os->rx_length_errors,
3382 : : &ns->rx_length_errors);
3383 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3384 : 0 : pf->offset_loaded, &os->link_xon_rx,
3385 : : &ns->link_xon_rx);
3386 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3387 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3388 : : &ns->link_xoff_rx);
3389 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3390 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3391 : 0 : pf->offset_loaded,
3392 : : &os->priority_xon_rx[i],
3393 : : &ns->priority_xon_rx[i]);
3394 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3395 : 0 : pf->offset_loaded,
3396 : : &os->priority_xoff_rx[i],
3397 : : &ns->priority_xoff_rx[i]);
3398 : : }
3399 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3400 : 0 : pf->offset_loaded, &os->link_xon_tx,
3401 : : &ns->link_xon_tx);
3402 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3403 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3404 : : &ns->link_xoff_tx);
3405 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3406 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3407 : 0 : pf->offset_loaded,
3408 : : &os->priority_xon_tx[i],
3409 : : &ns->priority_xon_tx[i]);
3410 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3411 : 0 : pf->offset_loaded,
3412 : : &os->priority_xoff_tx[i],
3413 : : &ns->priority_xoff_tx[i]);
3414 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3415 : 0 : pf->offset_loaded,
3416 : : &os->priority_xon_2_xoff[i],
3417 : : &ns->priority_xon_2_xoff[i]);
3418 : : }
3419 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3420 : 0 : I40E_GLPRT_PRC64L(hw->port),
3421 : 0 : pf->offset_loaded, &os->rx_size_64,
3422 : 0 : &ns->rx_size_64);
3423 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3424 : 0 : I40E_GLPRT_PRC127L(hw->port),
3425 : 0 : pf->offset_loaded, &os->rx_size_127,
3426 : 0 : &ns->rx_size_127);
3427 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3428 : 0 : I40E_GLPRT_PRC255L(hw->port),
3429 : 0 : pf->offset_loaded, &os->rx_size_255,
3430 : 0 : &ns->rx_size_255);
3431 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3432 : 0 : I40E_GLPRT_PRC511L(hw->port),
3433 : 0 : pf->offset_loaded, &os->rx_size_511,
3434 : 0 : &ns->rx_size_511);
3435 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3436 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3437 : 0 : pf->offset_loaded, &os->rx_size_1023,
3438 : 0 : &ns->rx_size_1023);
3439 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3440 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3441 : 0 : pf->offset_loaded, &os->rx_size_1522,
3442 : 0 : &ns->rx_size_1522);
3443 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3444 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3445 : 0 : pf->offset_loaded, &os->rx_size_big,
3446 : 0 : &ns->rx_size_big);
3447 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3448 : 0 : pf->offset_loaded, &os->rx_undersize,
3449 : : &ns->rx_undersize);
3450 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3451 : 0 : pf->offset_loaded, &os->rx_fragments,
3452 : : &ns->rx_fragments);
3453 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3454 : 0 : pf->offset_loaded, &os->rx_oversize,
3455 : : &ns->rx_oversize);
3456 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3457 : 0 : pf->offset_loaded, &os->rx_jabber,
3458 : : &ns->rx_jabber);
3459 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3460 : 0 : I40E_GLPRT_PTC64L(hw->port),
3461 : 0 : pf->offset_loaded, &os->tx_size_64,
3462 : 0 : &ns->tx_size_64);
3463 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3464 : 0 : I40E_GLPRT_PTC127L(hw->port),
3465 : 0 : pf->offset_loaded, &os->tx_size_127,
3466 : 0 : &ns->tx_size_127);
3467 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3468 : 0 : I40E_GLPRT_PTC255L(hw->port),
3469 : 0 : pf->offset_loaded, &os->tx_size_255,
3470 : 0 : &ns->tx_size_255);
3471 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3472 : 0 : I40E_GLPRT_PTC511L(hw->port),
3473 : 0 : pf->offset_loaded, &os->tx_size_511,
3474 : 0 : &ns->tx_size_511);
3475 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3476 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3477 : 0 : pf->offset_loaded, &os->tx_size_1023,
3478 : 0 : &ns->tx_size_1023);
3479 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3480 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3481 : 0 : pf->offset_loaded, &os->tx_size_1522,
3482 : 0 : &ns->tx_size_1522);
3483 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3484 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3485 : 0 : pf->offset_loaded, &os->tx_size_big,
3486 : 0 : &ns->tx_size_big);
3487 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3488 : 0 : pf->offset_loaded,
3489 : : &os->fd_sb_match, &ns->fd_sb_match);
3490 : : /* GLPRT_MSPDC not supported */
3491 : : /* GLPRT_XEC not supported */
3492 : :
3493 : 0 : pf->offset_loaded = true;
3494 : :
3495 [ # # ]: 0 : if (pf->main_vsi)
3496 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3497 : 0 : }
3498 : :
3499 : : /* Get all statistics of a port */
3500 : : static int
3501 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
3502 : : struct eth_queue_stats *qstats __rte_unused)
3503 : : {
3504 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3505 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3506 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3507 : : struct i40e_vsi *vsi;
3508 : : unsigned i;
3509 : :
3510 : : /* call read registers - updates values, now write them to struct */
3511 : 0 : i40e_read_stats_registers(pf, hw);
3512 : :
3513 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3514 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3515 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3516 : 0 : pf->main_vsi->eth_stats.rx_discards -
3517 : 0 : ns->rx_err1;
3518 : 0 : stats->opackets = ns->eth.tx_unicast +
3519 : 0 : ns->eth.tx_multicast +
3520 : 0 : ns->eth.tx_broadcast;
3521 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3522 : 0 : stats->obytes = ns->eth.tx_bytes;
3523 : 0 : stats->oerrors = ns->eth.tx_errors +
3524 : 0 : pf->main_vsi->eth_stats.tx_errors;
3525 : :
3526 : : /* Rx Errors */
3527 : 0 : stats->imissed = ns->eth.rx_discards +
3528 : : pf->main_vsi->eth_stats.rx_discards;
3529 : 0 : stats->ierrors = ns->crc_errors +
3530 : 0 : ns->rx_length_errors + ns->rx_undersize +
3531 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3532 : : ns->rx_err1;
3533 : :
3534 [ # # ]: 0 : if (pf->vfs) {
3535 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3536 : 0 : vsi = pf->vfs[i].vsi;
3537 : 0 : i40e_update_vsi_stats(vsi);
3538 : :
3539 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3540 : 0 : vsi->eth_stats.rx_multicast +
3541 : 0 : vsi->eth_stats.rx_broadcast -
3542 : 0 : vsi->eth_stats.rx_discards);
3543 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3544 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3545 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3546 : : }
3547 : : }
3548 : :
3549 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3550 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3551 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3552 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3553 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3554 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3555 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3556 : : ns->eth.rx_unknown_protocol);
3557 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3558 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3559 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3560 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3561 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3562 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3563 : :
3564 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3565 : : ns->tx_dropped_link_down);
3566 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3567 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3568 : : ns->illegal_bytes);
3569 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3570 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3571 : : ns->mac_local_faults);
3572 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3573 : : ns->mac_remote_faults);
3574 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3575 : : ns->rx_length_errors);
3576 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3577 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3578 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3579 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3580 : : i, ns->priority_xon_rx[i]);
3581 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3582 : : i, ns->priority_xoff_rx[i]);
3583 : : }
3584 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3585 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3586 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3587 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3588 : : i, ns->priority_xon_tx[i]);
3589 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3590 : : i, ns->priority_xoff_tx[i]);
3591 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3592 : : i, ns->priority_xon_2_xoff[i]);
3593 : : }
3594 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3595 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3596 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3597 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3598 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3599 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3600 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3601 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3602 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3603 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3604 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3605 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3606 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3607 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3608 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3609 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3610 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3611 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3612 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3613 : : ns->mac_short_packet_dropped);
3614 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3615 : : ns->checksum_error);
3616 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3617 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3618 : 0 : return 0;
3619 : : }
3620 : :
3621 : : /* Reset the statistics */
3622 : : static int
3623 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3624 : : {
3625 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3626 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3627 : :
3628 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3629 : 0 : pf->offset_loaded = false;
3630 [ # # ]: 0 : if (pf->main_vsi)
3631 : 0 : pf->main_vsi->offset_loaded = false;
3632 : :
3633 : : /* read the stats, reading current register values into offset */
3634 : 0 : i40e_read_stats_registers(pf, hw);
3635 : :
3636 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct i40e_mbuf_stats));
3637 : :
3638 : 0 : return 0;
3639 : : }
3640 : :
3641 : : static uint32_t
3642 : : i40e_xstats_calc_num(void)
3643 : : {
3644 : : return I40E_NB_ETH_XSTATS + I40E_NB_MBUF_XSTATS +
3645 : : I40E_NB_HW_PORT_XSTATS +
3646 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3647 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3648 : : }
3649 : :
3650 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3651 : : struct rte_eth_xstat_name *xstats_names,
3652 : : __rte_unused unsigned limit)
3653 : : {
3654 : : unsigned count = 0;
3655 : : unsigned i, prio;
3656 : :
3657 [ # # ]: 0 : if (xstats_names == NULL)
3658 : : return i40e_xstats_calc_num();
3659 : :
3660 : : /* Note: limit checked in rte_eth_xstats_names() */
3661 : :
3662 : : /* Get stats from i40e_eth_stats struct */
3663 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3664 : 0 : strlcpy(xstats_names[count].name,
3665 : : rte_i40e_stats_strings[i].name,
3666 : : sizeof(xstats_names[count].name));
3667 : 0 : count++;
3668 : : }
3669 : :
3670 : : /* Get stats from i40e_mbuf_stats struct */
3671 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3672 : 0 : strlcpy(xstats_names[count].name,
3673 : : i40e_mbuf_strings[i].name,
3674 : : sizeof(xstats_names[count].name));
3675 : 0 : count++;
3676 : : }
3677 : :
3678 : : /* Get individual stats from i40e_hw_port struct */
3679 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3680 : 0 : strlcpy(xstats_names[count].name,
3681 : : rte_i40e_hw_port_strings[i].name,
3682 : : sizeof(xstats_names[count].name));
3683 : 0 : count++;
3684 : : }
3685 : :
3686 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3687 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3688 : 0 : snprintf(xstats_names[count].name,
3689 : : sizeof(xstats_names[count].name),
3690 : : "rx_priority%u_%s", prio,
3691 : 0 : rte_i40e_rxq_prio_strings[i].name);
3692 : 0 : count++;
3693 : : }
3694 : : }
3695 : :
3696 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3697 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3698 : 0 : snprintf(xstats_names[count].name,
3699 : : sizeof(xstats_names[count].name),
3700 : : "tx_priority%u_%s", prio,
3701 : 0 : rte_i40e_txq_prio_strings[i].name);
3702 : 0 : count++;
3703 : : }
3704 : : }
3705 : 0 : return count;
3706 : : }
3707 : :
3708 : : static void
3709 : : i40e_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
3710 : : struct i40e_mbuf_stats *mbuf_stats)
3711 : : {
3712 : : uint16_t idx;
3713 : : struct ci_tx_queue *txq;
3714 : :
3715 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
3716 : 0 : txq = ethdev->data->tx_queues[idx];
3717 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
3718 : : }
3719 : : }
3720 : :
3721 : : static int
3722 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3723 : : unsigned n)
3724 : : {
3725 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3726 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3727 : : struct i40e_adapter *adapter =
3728 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3729 : : struct i40e_mbuf_stats mbuf_stats = {0};
3730 : : unsigned i, count, prio;
3731 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3732 : :
3733 : : count = i40e_xstats_calc_num();
3734 [ # # ]: 0 : if (n < count)
3735 : : return count;
3736 : :
3737 : 0 : i40e_read_stats_registers(pf, hw);
3738 : :
3739 [ # # ]: 0 : if (xstats == NULL)
3740 : : return 0;
3741 : :
3742 : : count = 0;
3743 : :
3744 [ # # ]: 0 : if (adapter->mbuf_check)
3745 : : i40e_dev_update_mbuf_stats(dev, &mbuf_stats);
3746 : :
3747 : : /* Get stats from i40e_eth_stats struct */
3748 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3749 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3750 : 0 : rte_i40e_stats_strings[i].offset);
3751 : 0 : xstats[count].id = count;
3752 : 0 : count++;
3753 : : }
3754 : :
3755 : : /* Get stats from i40e_mbuf_stats struct */
3756 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3757 : 0 : xstats[count].value = *(uint64_t *)((char *)&mbuf_stats +
3758 : : i40e_mbuf_strings[i].offset);
3759 : 0 : xstats[count].id = count;
3760 : 0 : count++;
3761 : : }
3762 : :
3763 : : /* Get individual stats from i40e_hw_port struct */
3764 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3765 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3766 : 0 : rte_i40e_hw_port_strings[i].offset);
3767 : 0 : xstats[count].id = count;
3768 : 0 : count++;
3769 : : }
3770 : :
3771 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_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_rxq_prio_strings[i].offset +
3776 : 0 : (sizeof(uint64_t) * prio));
3777 : 0 : xstats[count].id = count;
3778 : 0 : count++;
3779 : : }
3780 : : }
3781 : :
3782 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3783 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3784 : 0 : xstats[count].value =
3785 : 0 : *(uint64_t *)(((char *)hw_stats) +
3786 : 0 : rte_i40e_txq_prio_strings[i].offset +
3787 : 0 : (sizeof(uint64_t) * prio));
3788 : 0 : xstats[count].id = count;
3789 : 0 : count++;
3790 : : }
3791 : : }
3792 : :
3793 : 0 : return count;
3794 : : }
3795 : :
3796 : : static int
3797 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3798 : : {
3799 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3800 : : u32 full_ver;
3801 : : u8 ver, patch;
3802 : : u16 build;
3803 : : int ret;
3804 : :
3805 : 0 : full_ver = hw->nvm.oem_ver;
3806 : 0 : ver = (u8)(full_ver >> 24);
3807 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3808 : : patch = (u8)(full_ver & 0xff);
3809 : :
3810 : 0 : ret = snprintf(fw_version, fw_size,
3811 : : "%d.%d%d 0x%08x %d.%d.%d",
3812 : : ((hw->nvm.version >> 12) & 0xf),
3813 : : ((hw->nvm.version >> 4) & 0xff),
3814 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3815 : : ver, build, patch);
3816 [ # # ]: 0 : if (ret < 0)
3817 : : return -EINVAL;
3818 : :
3819 : 0 : ret += 1; /* add the size of '\0' */
3820 [ # # ]: 0 : if (fw_size < (size_t)ret)
3821 : : return ret;
3822 : : else
3823 : 0 : return 0;
3824 : : }
3825 : :
3826 : : /*
3827 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3828 : : * the Rx data path does not hang if the FW LLDP is stopped.
3829 : : * return true if lldp need to stop
3830 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3831 : : */
3832 : : static bool
3833 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3834 : : {
3835 : : double nvm_ver;
3836 : 0 : char ver_str[64] = {0};
3837 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3838 : :
3839 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3840 : : nvm_ver = atof(ver_str);
3841 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3842 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3843 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3844 : : return true;
3845 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3846 : 0 : return true;
3847 : :
3848 : : return false;
3849 : : }
3850 : :
3851 : : static int
3852 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3853 : : {
3854 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3855 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3856 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3857 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3858 : :
3859 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3860 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3861 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3862 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3863 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3864 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3865 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3866 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3867 : 0 : dev_info->rx_queue_offload_capa = 0;
3868 : 0 : dev_info->rx_offload_capa =
3869 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3870 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3871 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3872 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3873 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3874 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3875 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3876 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3877 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3878 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3879 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3880 : :
3881 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3882 : 0 : dev_info->tx_offload_capa =
3883 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3884 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3885 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3886 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3887 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3888 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3889 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3890 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3891 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3892 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3893 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3894 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3895 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3896 : : dev_info->tx_queue_offload_capa;
3897 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
3898 : 0 : dev_info->tx_offload_capa |=
3899 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
3900 : : }
3901 : :
3902 : 0 : dev_info->dev_capa =
3903 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3904 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3905 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3906 : :
3907 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3908 : : sizeof(uint32_t);
3909 : 0 : dev_info->reta_size = pf->hash_lut_size;
3910 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3911 : :
3912 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3913 : : .rx_thresh = {
3914 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3915 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3916 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3917 : : },
3918 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3919 : : .rx_drop_en = 0,
3920 : : .offloads = 0,
3921 : : };
3922 : :
3923 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3924 : : .tx_thresh = {
3925 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3926 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3927 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3928 : : },
3929 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3930 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3931 : : .offloads = 0,
3932 : : };
3933 : :
3934 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3935 : : .nb_max = I40E_MAX_RING_DESC,
3936 : : .nb_min = I40E_MIN_RING_DESC,
3937 : : .nb_align = I40E_ALIGN_RING_DESC,
3938 : : };
3939 : :
3940 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3941 : : .nb_max = I40E_MAX_RING_DESC,
3942 : : .nb_min = I40E_MIN_RING_DESC,
3943 : : .nb_align = I40E_ALIGN_RING_DESC,
3944 : : .nb_seg_max = I40E_TX_MAX_SEG,
3945 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3946 : : };
3947 : :
3948 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3949 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3950 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3951 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3952 : : pf->max_nb_vmdq_vsi;
3953 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3954 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3955 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3956 : : }
3957 : :
3958 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3959 : : /* For XL710 */
3960 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3961 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3962 : 0 : dev_info->default_txportconf.nb_queues = 2;
3963 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3964 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3965 : : else
3966 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3967 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3968 : 0 : dev_info->default_txportconf.ring_size = 1024;
3969 : : else
3970 : 0 : dev_info->default_txportconf.ring_size = 512;
3971 : :
3972 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3973 : : /* For XXV710 */
3974 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3975 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3976 : 0 : dev_info->default_txportconf.nb_queues = 1;
3977 : 0 : dev_info->default_rxportconf.ring_size = 256;
3978 : 0 : dev_info->default_txportconf.ring_size = 256;
3979 : : } else {
3980 : : /* For X710 */
3981 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3982 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3983 : 0 : dev_info->default_txportconf.nb_queues = 1;
3984 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3985 : 0 : dev_info->default_rxportconf.ring_size = 512;
3986 : 0 : dev_info->default_txportconf.ring_size = 256;
3987 : : } else {
3988 : 0 : dev_info->default_rxportconf.ring_size = 256;
3989 : 0 : dev_info->default_txportconf.ring_size = 256;
3990 : : }
3991 : : }
3992 : 0 : dev_info->default_rxportconf.burst_size = 32;
3993 : 0 : dev_info->default_txportconf.burst_size = 32;
3994 : :
3995 : 0 : return 0;
3996 : : }
3997 : :
3998 : : static int
3999 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4000 : : {
4001 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4002 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4003 : 0 : PMD_INIT_FUNC_TRACE();
4004 : :
4005 [ # # ]: 0 : if (on)
4006 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
4007 : : else
4008 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
4009 : : }
4010 : :
4011 : : static int
4012 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
4013 : : enum rte_vlan_type vlan_type,
4014 : : uint16_t tpid, int qinq)
4015 : : {
4016 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4017 : 0 : uint64_t reg_r = 0;
4018 : : uint64_t reg_w = 0;
4019 : : uint16_t reg_id = 3;
4020 : : int ret;
4021 : :
4022 [ # # ]: 0 : if (qinq) {
4023 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4024 : : reg_id = 2;
4025 : : }
4026 : :
4027 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
4028 : : ®_r, NULL);
4029 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4030 : 0 : PMD_DRV_LOG(ERR,
4031 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
4032 : : reg_id);
4033 : 0 : return -EIO;
4034 : : }
4035 : 0 : PMD_DRV_LOG(DEBUG,
4036 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
4037 : : reg_id, reg_r);
4038 : :
4039 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
4040 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
4041 [ # # ]: 0 : if (reg_r == reg_w) {
4042 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
4043 : 0 : return 0;
4044 : : }
4045 : :
4046 : 0 : ret = i40e_aq_debug_write_global_register(hw,
4047 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
4048 : : reg_w, NULL);
4049 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4050 : 0 : PMD_DRV_LOG(ERR,
4051 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
4052 : : reg_id);
4053 : 0 : return -EIO;
4054 : : }
4055 : 0 : PMD_DRV_LOG(DEBUG,
4056 : : "Global register 0x%08x is changed with value 0x%08x",
4057 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
4058 : :
4059 : 0 : return 0;
4060 : : }
4061 : :
4062 : : static int
4063 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
4064 : : enum rte_vlan_type vlan_type,
4065 : : uint16_t tpid)
4066 : : {
4067 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4068 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4069 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
4070 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4071 : : u16 sw_flags = 0, valid_flags = 0;
4072 : : int ret = 0;
4073 : :
4074 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
4075 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
4076 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
4077 : 0 : PMD_DRV_LOG(ERR,
4078 : : "Unsupported vlan type.");
4079 : 0 : return -EINVAL;
4080 : : }
4081 : :
4082 [ # # ]: 0 : if (pf->support_multi_driver) {
4083 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
4084 : 0 : return -ENOTSUP;
4085 : : }
4086 : :
4087 : : /* 802.1ad frames ability is added in NVM API 1.7*/
4088 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
4089 [ # # ]: 0 : if (qinq) {
4090 [ # # ]: 0 : if (pf->fw8_3gt) {
4091 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4092 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4093 : : }
4094 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4095 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
4096 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
4097 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4098 : : } else {
4099 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4100 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4101 : : }
4102 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
4103 : : valid_flags, 0, NULL);
4104 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4105 : 0 : PMD_DRV_LOG(ERR,
4106 : : "Set switch config failed aq_err: %d",
4107 : : hw->aq.asq_last_status);
4108 : : ret = -EIO;
4109 : : }
4110 : : } else
4111 : : /* If NVM API < 1.7, keep the register setting */
4112 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
4113 : : tpid, qinq);
4114 : :
4115 : : return ret;
4116 : : }
4117 : :
4118 : : /* Configure outer vlan stripping on or off in QinQ mode */
4119 : : static int
4120 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
4121 : : {
4122 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4123 : : int ret = I40E_SUCCESS;
4124 : : uint32_t reg;
4125 : :
4126 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
4127 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
4128 : 0 : return -EINVAL;
4129 : : }
4130 : :
4131 : : /* Configure for outer VLAN RX stripping */
4132 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4133 : :
4134 [ # # ]: 0 : if (on)
4135 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
4136 : : else
4137 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4138 : :
4139 : 0 : ret = i40e_aq_debug_write_register(hw,
4140 : 0 : I40E_VSI_TSR(vsi->vsi_id),
4141 : : reg, NULL);
4142 [ # # ]: 0 : if (ret < 0) {
4143 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4144 : : vsi->vsi_id);
4145 : 0 : return I40E_ERR_CONFIG;
4146 : : }
4147 : :
4148 : : return ret;
4149 : : }
4150 : :
4151 : : static int
4152 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4153 : : {
4154 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4155 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4156 : : struct rte_eth_rxmode *rxmode;
4157 : : struct i40e_mac_filter *f;
4158 : : int i, num;
4159 : : void *temp;
4160 : : int ret;
4161 : :
4162 : : rxmode = &dev->data->dev_conf.rxmode;
4163 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4164 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4165 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
4166 : : else
4167 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
4168 : : }
4169 : :
4170 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4171 : : /* Enable or disable VLAN stripping */
4172 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4173 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4174 : : else
4175 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4176 : :
4177 : : /* When VLAN strip is enabled/disabled
4178 : : * after enabling outer VLAN stripping,
4179 : : * outer VLAN stripping gets disabled
4180 : : * as the register gets overridden by
4181 : : * VLAN's strip vsi param update.
4182 : : * Hence, re-enable outer VLAN stripping.
4183 : : */
4184 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4185 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4186 : : }
4187 : :
4188 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4189 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
4190 : : i = 0;
4191 : 0 : num = vsi->mac_num;
4192 : :
4193 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
4194 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
4195 : 0 : return I40E_ERR_NO_MEMORY;
4196 : : }
4197 : :
4198 : : /*
4199 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4200 : : * also change the default behavior to support this feature. To align with
4201 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4202 : : * outer VLAN processing. But it is forbidden for firmware to change the
4203 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4204 : : * switch table. Therefore, we need to clear the MAC table before setting
4205 : : * config, and then restore the MAC table after setting. This feature is
4206 : : * recommended to be used in firmware v8.6.
4207 : : */
4208 : : /* Remove all existing mac */
4209 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4210 : 0 : mac_filter[i] = f->mac_info;
4211 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4212 [ # # ]: 0 : if (ret)
4213 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4214 : 0 : i++;
4215 : : }
4216 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4217 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4218 : : /* Set global registers with default ethertype. */
4219 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4220 : : RTE_ETHER_TYPE_VLAN);
4221 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4222 : : RTE_ETHER_TYPE_VLAN);
4223 : : } else {
4224 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4225 : : }
4226 : : /* Restore all mac */
4227 [ # # ]: 0 : for (i = 0; i < num; i++) {
4228 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4229 [ # # ]: 0 : if (ret)
4230 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4231 : : }
4232 : : }
4233 : :
4234 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4235 : : /* Enable or disable outer VLAN stripping */
4236 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4237 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4238 : : else
4239 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4240 : : }
4241 : :
4242 : : return 0;
4243 : : }
4244 : :
4245 : : static void
4246 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4247 : : __rte_unused uint16_t queue,
4248 : : __rte_unused int on)
4249 : : {
4250 : 0 : PMD_INIT_FUNC_TRACE();
4251 : 0 : }
4252 : :
4253 : : static int
4254 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4255 : : {
4256 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4257 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4258 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4259 : : struct i40e_vsi_vlan_pvid_info info;
4260 : :
4261 : : memset(&info, 0, sizeof(info));
4262 : 0 : info.on = on;
4263 [ # # ]: 0 : if (info.on)
4264 : 0 : info.config.pvid = pvid;
4265 : : else {
4266 : 0 : info.config.reject.tagged =
4267 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4268 : 0 : info.config.reject.untagged =
4269 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4270 : : }
4271 : :
4272 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4273 : : }
4274 : :
4275 : : static int
4276 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4277 : : {
4278 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4279 : 0 : uint32_t mode = i40e_led_get(hw);
4280 : :
4281 [ # # ]: 0 : if (mode == 0)
4282 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4283 : :
4284 : 0 : return 0;
4285 : : }
4286 : :
4287 : : static int
4288 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4289 : : {
4290 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4291 : 0 : uint32_t mode = i40e_led_get(hw);
4292 : :
4293 [ # # ]: 0 : if (mode != 0)
4294 : 0 : i40e_led_set(hw, 0, false);
4295 : :
4296 : 0 : return 0;
4297 : : }
4298 : :
4299 : : static int
4300 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4301 : : {
4302 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4303 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4304 : :
4305 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4306 : :
4307 : : /* read out from register, in case they are modified by other port */
4308 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4309 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4310 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4311 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4312 : :
4313 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4314 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4315 : :
4316 : : /* Return current mode according to actual setting*/
4317 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4318 : 0 : case I40E_FC_FULL:
4319 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4320 : 0 : break;
4321 : 0 : case I40E_FC_TX_PAUSE:
4322 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4323 : 0 : break;
4324 : 0 : case I40E_FC_RX_PAUSE:
4325 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4326 : 0 : break;
4327 : 0 : case I40E_FC_NONE:
4328 : : default:
4329 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4330 : : };
4331 : :
4332 : 0 : return 0;
4333 : : }
4334 : :
4335 : : static int
4336 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4337 : : {
4338 : : uint32_t mflcn_reg, fctrl_reg, reg;
4339 : : uint32_t max_high_water;
4340 : : uint8_t i, aq_failure;
4341 : : int err;
4342 : : struct i40e_hw *hw;
4343 : : struct i40e_pf *pf;
4344 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4345 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4346 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4347 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4348 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4349 : : };
4350 : :
4351 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4352 : :
4353 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4354 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4355 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4356 : 0 : PMD_INIT_LOG(ERR,
4357 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4358 : : max_high_water);
4359 : 0 : return -EINVAL;
4360 : : }
4361 : :
4362 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4363 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4364 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4365 : :
4366 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4367 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4368 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4369 : :
4370 : 0 : PMD_INIT_FUNC_TRACE();
4371 : :
4372 : : /* All the link flow control related enable/disable register
4373 : : * configuration is handle by the F/W
4374 : : */
4375 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4376 [ # # ]: 0 : if (err < 0)
4377 : : return -ENOSYS;
4378 : :
4379 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4380 : : /* Configure flow control refresh threshold,
4381 : : * the value for stat_tx_pause_refresh_timer[8]
4382 : : * is used for global pause operation.
4383 : : */
4384 : :
4385 : 0 : I40E_WRITE_REG(hw,
4386 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4387 : : pf->fc_conf.pause_time);
4388 : :
4389 : : /* configure the timer value included in transmitted pause
4390 : : * frame,
4391 : : * the value for stat_tx_pause_quanta[8] is used for global
4392 : : * pause operation
4393 : : */
4394 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4395 : : pf->fc_conf.pause_time);
4396 : :
4397 : 0 : fctrl_reg = I40E_READ_REG(hw,
4398 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4399 : :
4400 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4401 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4402 : : else
4403 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4404 : :
4405 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4406 : : fctrl_reg);
4407 : : } else {
4408 : : /* Configure pause time (2 TCs per register) */
4409 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4410 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4411 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4412 : :
4413 : : /* Configure flow control refresh threshold value */
4414 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4415 : : pf->fc_conf.pause_time / 2);
4416 : :
4417 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4418 : :
4419 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4420 : : *depending on configuration
4421 : : */
4422 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4423 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4424 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4425 : : } else {
4426 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4427 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4428 : : }
4429 : :
4430 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4431 : : }
4432 : :
4433 [ # # ]: 0 : if (!pf->support_multi_driver) {
4434 : : /* config water marker both based on the packets and bytes */
4435 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4436 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4437 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4438 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4439 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4440 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4441 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4442 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4443 : : << I40E_KILOSHIFT);
4444 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4445 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4446 : : << I40E_KILOSHIFT);
4447 : : } else {
4448 : 0 : PMD_DRV_LOG(ERR,
4449 : : "Water marker configuration is not supported.");
4450 : : }
4451 : :
4452 : 0 : I40E_WRITE_FLUSH(hw);
4453 : :
4454 : 0 : return 0;
4455 : : }
4456 : :
4457 : : static int
4458 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4459 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4460 : : {
4461 : 0 : PMD_INIT_FUNC_TRACE();
4462 : :
4463 : 0 : return -ENOSYS;
4464 : : }
4465 : :
4466 : : /* Add a MAC address, and update filters */
4467 : : static int
4468 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4469 : : struct rte_ether_addr *mac_addr,
4470 : : __rte_unused uint32_t index,
4471 : : uint32_t pool)
4472 : : {
4473 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4474 : : struct i40e_mac_filter_info mac_filter;
4475 : : struct i40e_vsi *vsi;
4476 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4477 : : int ret;
4478 : :
4479 : : /* If VMDQ not enabled or configured, return */
4480 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4481 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4482 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4483 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4484 : : pool);
4485 : 0 : return -ENOTSUP;
4486 : : }
4487 : :
4488 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4489 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4490 : : pool, pf->nb_cfg_vmdq_vsi);
4491 : 0 : return -EINVAL;
4492 : : }
4493 : :
4494 : : memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4495 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4496 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4497 : : else
4498 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4499 : :
4500 [ # # ]: 0 : if (pool == 0)
4501 : 0 : vsi = pf->main_vsi;
4502 : : else
4503 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4504 : :
4505 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4506 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4507 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4508 : 0 : return -ENODEV;
4509 : : }
4510 : : return 0;
4511 : : }
4512 : :
4513 : : /* Remove a MAC address, and update filters */
4514 : : static void
4515 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4516 : : {
4517 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4518 : : struct i40e_vsi *vsi;
4519 : : struct rte_eth_dev_data *data = dev->data;
4520 : : struct rte_ether_addr *macaddr;
4521 : : int ret;
4522 : : uint32_t i;
4523 : : uint64_t pool_sel;
4524 : :
4525 : 0 : macaddr = &(data->mac_addrs[index]);
4526 : :
4527 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ)) {
4528 [ # # ]: 0 : if (i40e_vsi_delete_mac(pf->main_vsi, macaddr) != 0)
4529 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4530 : 0 : return;
4531 : : }
4532 : :
4533 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4534 : :
4535 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4536 [ # # ]: 0 : if (pool_sel & RTE_BIT64(i)) {
4537 [ # # ]: 0 : if (i == 0)
4538 : 0 : vsi = pf->main_vsi;
4539 : : else {
4540 : : /* No VMDQ pool enabled or configured */
4541 [ # # ]: 0 : if (i > pf->nb_cfg_vmdq_vsi) {
4542 : 0 : PMD_DRV_LOG(ERR,
4543 : : "No VMDQ pool enabled/configured");
4544 : 0 : return;
4545 : : }
4546 : 0 : vsi = pf->vmdq[i - 1].vsi;
4547 : : }
4548 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4549 : :
4550 [ # # ]: 0 : if (ret) {
4551 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4552 : 0 : return;
4553 : : }
4554 : : }
4555 : : }
4556 : : }
4557 : :
4558 : : static int
4559 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4560 : : {
4561 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4562 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4563 : : uint32_t reg;
4564 : : int ret;
4565 : :
4566 [ # # ]: 0 : if (!lut)
4567 : : return -EINVAL;
4568 : :
4569 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4570 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4571 : 0 : vsi->type != I40E_VSI_SRIOV,
4572 : : lut, lut_size);
4573 [ # # ]: 0 : if (ret) {
4574 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4575 : 0 : return ret;
4576 : : }
4577 : : } else {
4578 : : uint32_t *lut_dw = (uint32_t *)lut;
4579 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4580 : :
4581 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4582 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4583 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4584 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4585 : : }
4586 : : } else {
4587 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4588 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4589 : : I40E_PFQF_HLUT(i));
4590 : : }
4591 : : }
4592 : :
4593 : : return 0;
4594 : : }
4595 : :
4596 : : int
4597 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4598 : : {
4599 : : struct i40e_pf *pf;
4600 : : struct i40e_hw *hw;
4601 : :
4602 [ # # ]: 0 : if (!vsi || !lut)
4603 : : return -EINVAL;
4604 : :
4605 : 0 : pf = I40E_VSI_TO_PF(vsi);
4606 : 0 : hw = I40E_VSI_TO_HW(vsi);
4607 : :
4608 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4609 : : enum i40e_status_code status;
4610 : :
4611 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4612 : 0 : vsi->type != I40E_VSI_SRIOV,
4613 : : lut, lut_size);
4614 [ # # ]: 0 : if (status) {
4615 : 0 : PMD_DRV_LOG(ERR,
4616 : : "Failed to update RSS lookup table, error status: %d",
4617 : : status);
4618 : 0 : return -EIO;
4619 : : }
4620 : : } else {
4621 : : uint32_t *lut_dw = (uint32_t *)lut;
4622 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4623 : :
4624 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4625 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4626 : 0 : I40E_WRITE_REG(
4627 : : hw,
4628 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4629 : : lut_dw[i]);
4630 : : } else {
4631 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4632 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4633 : : lut_dw[i]);
4634 : : }
4635 : 0 : I40E_WRITE_FLUSH(hw);
4636 : : }
4637 : :
4638 : : return 0;
4639 : : }
4640 : :
4641 : : static int
4642 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4643 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4644 : : uint16_t reta_size)
4645 : : {
4646 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4647 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4648 : : uint16_t idx, shift;
4649 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4650 : : int ret;
4651 : :
4652 : 0 : if (reta_size != lut_size ||
4653 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4654 : 0 : PMD_DRV_LOG(ERR,
4655 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4656 : : reta_size, lut_size);
4657 : 0 : return -EINVAL;
4658 : : }
4659 : :
4660 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4661 [ # # ]: 0 : if (ret)
4662 : : return ret;
4663 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4664 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4665 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4666 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4667 : 0 : lut[i] = reta_conf[idx].reta[shift];
4668 : : }
4669 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4670 : :
4671 : 0 : pf->adapter->rss_reta_updated = 1;
4672 : :
4673 : 0 : return ret;
4674 : : }
4675 : :
4676 : : static int
4677 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4678 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4679 : : uint16_t reta_size)
4680 : : {
4681 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4682 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4683 : : uint16_t idx, shift;
4684 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4685 : : int ret;
4686 : :
4687 : 0 : if (reta_size != lut_size ||
4688 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4689 : 0 : PMD_DRV_LOG(ERR,
4690 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4691 : : reta_size, lut_size);
4692 : 0 : return -EINVAL;
4693 : : }
4694 : :
4695 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4696 [ # # ]: 0 : if (ret)
4697 : : return ret;
4698 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4699 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4700 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4701 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4702 : 0 : reta_conf[idx].reta[shift] = lut[i];
4703 : : }
4704 : :
4705 : : return ret;
4706 : : }
4707 : :
4708 : : /**
4709 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4710 : : * @hw: pointer to the HW structure
4711 : : * @mem: pointer to mem struct to fill out
4712 : : * @size: size of memory requested
4713 : : * @alignment: what to align the allocation to
4714 : : **/
4715 : : enum i40e_status_code
4716 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4717 : : struct i40e_dma_mem *mem,
4718 : : __rte_unused enum i40e_memory_type mtype,
4719 : : u64 size,
4720 : : u32 alignment)
4721 : : {
4722 : : static RTE_ATOMIC(uint64_t) i40e_dma_memzone_id;
4723 : : const struct rte_memzone *mz = NULL;
4724 : : char z_name[RTE_MEMZONE_NAMESIZE];
4725 : :
4726 [ # # ]: 0 : if (!mem)
4727 : : return I40E_ERR_PARAM;
4728 : :
4729 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4730 : : rte_atomic_fetch_add_explicit(&i40e_dma_memzone_id, 1, rte_memory_order_relaxed));
4731 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4732 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4733 [ # # ]: 0 : if (!mz)
4734 : : return I40E_ERR_NO_MEMORY;
4735 : :
4736 : 0 : mem->size = size;
4737 : 0 : mem->va = mz->addr;
4738 : 0 : mem->pa = mz->iova;
4739 : 0 : mem->zone = (const void *)mz;
4740 : 0 : PMD_DRV_LOG(DEBUG,
4741 : : "memzone %s allocated with physical address: %"PRIu64,
4742 : : mz->name, mem->pa);
4743 : :
4744 : 0 : return I40E_SUCCESS;
4745 : : }
4746 : :
4747 : : /**
4748 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4749 : : * @hw: pointer to the HW structure
4750 : : * @mem: ptr to mem struct to free
4751 : : **/
4752 : : enum i40e_status_code
4753 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4754 : : struct i40e_dma_mem *mem)
4755 : : {
4756 [ # # ]: 0 : if (!mem)
4757 : : return I40E_ERR_PARAM;
4758 : :
4759 : 0 : PMD_DRV_LOG(DEBUG,
4760 : : "memzone %s to be freed with physical address: %"PRIu64,
4761 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4762 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4763 : 0 : mem->zone = NULL;
4764 : 0 : mem->va = NULL;
4765 : 0 : mem->pa = (u64)0;
4766 : :
4767 : 0 : return I40E_SUCCESS;
4768 : : }
4769 : :
4770 : : /**
4771 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4772 : : * @hw: pointer to the HW structure
4773 : : * @mem: pointer to mem struct to fill out
4774 : : * @size: size of memory requested
4775 : : **/
4776 : : enum i40e_status_code
4777 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4778 : : struct i40e_virt_mem *mem,
4779 : : u32 size)
4780 : : {
4781 [ # # ]: 0 : if (!mem)
4782 : : return I40E_ERR_PARAM;
4783 : :
4784 : 0 : mem->size = size;
4785 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4786 : :
4787 [ # # ]: 0 : if (mem->va)
4788 : : return I40E_SUCCESS;
4789 : : else
4790 : 0 : return I40E_ERR_NO_MEMORY;
4791 : : }
4792 : :
4793 : : /**
4794 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4795 : : * @hw: pointer to the HW structure
4796 : : * @mem: pointer to mem struct to free
4797 : : **/
4798 : : enum i40e_status_code
4799 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4800 : : struct i40e_virt_mem *mem)
4801 : : {
4802 [ # # ]: 0 : if (!mem)
4803 : : return I40E_ERR_PARAM;
4804 : :
4805 : 0 : rte_free(mem->va);
4806 : 0 : mem->va = NULL;
4807 : :
4808 : 0 : return I40E_SUCCESS;
4809 : : }
4810 : :
4811 : : /**
4812 : : * Get the hardware capabilities, which will be parsed
4813 : : * and saved into struct i40e_hw.
4814 : : */
4815 : : static int
4816 : 0 : i40e_get_cap(struct i40e_hw *hw)
4817 : : {
4818 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4819 : 0 : uint16_t len, size = 0;
4820 : : int ret;
4821 : :
4822 : : /* Calculate a huge enough buff for saving response data temporarily */
4823 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4824 : : I40E_MAX_CAP_ELE_NUM;
4825 : 0 : buf = rte_zmalloc("i40e", len, 0);
4826 [ # # ]: 0 : if (!buf) {
4827 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4828 : 0 : return I40E_ERR_NO_MEMORY;
4829 : : }
4830 : :
4831 : : /* Get, parse the capabilities and save it to hw */
4832 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4833 : : i40e_aqc_opc_list_func_capabilities, NULL);
4834 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4835 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4836 : :
4837 : : /* Free the temporary buffer after being used */
4838 : 0 : rte_free(buf);
4839 : :
4840 : 0 : return ret;
4841 : : }
4842 : :
4843 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4844 : :
4845 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4846 : : const char *value,
4847 : : void *opaque)
4848 : : {
4849 : : struct i40e_pf *pf;
4850 : : unsigned long num;
4851 : : char *end;
4852 : :
4853 : : pf = (struct i40e_pf *)opaque;
4854 : : RTE_SET_USED(key);
4855 : :
4856 : 0 : errno = 0;
4857 : 0 : num = strtoul(value, &end, 0);
4858 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4859 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4860 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4861 : 0 : return -(EINVAL);
4862 : : }
4863 : :
4864 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4865 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4866 : : else
4867 : : /* here return 0 to make next valid same argument work */
4868 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4869 : : "power of 2 and equal or less than 16 !, Now it is "
4870 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4871 : :
4872 : : return 0;
4873 : : }
4874 : :
4875 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4876 : : {
4877 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4878 : : struct rte_kvargs *kvlist;
4879 : : int kvargs_count;
4880 : :
4881 : : /* set default queue number per VF as 4 */
4882 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4883 : :
4884 [ # # ]: 0 : if (dev->device->devargs == NULL)
4885 : : return 0;
4886 : :
4887 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4888 [ # # ]: 0 : if (kvlist == NULL)
4889 : : return -(EINVAL);
4890 : :
4891 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4892 [ # # ]: 0 : if (!kvargs_count) {
4893 : 0 : rte_kvargs_free(kvlist);
4894 : 0 : return 0;
4895 : : }
4896 : :
4897 [ # # ]: 0 : if (kvargs_count > 1)
4898 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4899 : : "the first invalid or last valid one is used !",
4900 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4901 : :
4902 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4903 : : i40e_pf_parse_vf_queue_number_handler, pf);
4904 : :
4905 : 0 : rte_kvargs_free(kvlist);
4906 : :
4907 : 0 : return 0;
4908 : : }
4909 : :
4910 : : static int
4911 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4912 : : {
4913 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4914 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4915 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
4916 : : uint16_t qp_count = 0, vsi_count = 0;
4917 : :
4918 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4919 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4920 : 0 : return -EINVAL;
4921 : : }
4922 : :
4923 : 0 : i40e_pf_config_vf_rxq_number(dev);
4924 : :
4925 : : /* Add the parameter init for LFC */
4926 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4927 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4928 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4929 : :
4930 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4931 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4932 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4933 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4934 : :
4935 : : /* FDir queue/VSI allocation */
4936 : 0 : pf->fdir_qp_offset = 0;
4937 [ # # ]: 0 : if (hw->func_caps.fd) {
4938 : 0 : pf->flags |= I40E_FLAG_FDIR;
4939 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4940 : : } else {
4941 : 0 : pf->fdir_nb_qps = 0;
4942 : : }
4943 : 0 : qp_count += pf->fdir_nb_qps;
4944 : : vsi_count += 1;
4945 : :
4946 : : /* LAN queue/VSI allocation */
4947 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4948 [ # # ]: 0 : if (!hw->func_caps.rss) {
4949 : 0 : pf->lan_nb_qps = 1;
4950 : : } else {
4951 : 0 : pf->flags |= I40E_FLAG_RSS;
4952 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4953 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4954 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4955 : : }
4956 : 0 : qp_count += pf->lan_nb_qps;
4957 : : vsi_count += 1;
4958 : :
4959 : : /* VF queue/VSI allocation */
4960 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4961 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4962 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4963 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4964 : 0 : pf->vf_num = pci_dev->max_vfs;
4965 : 0 : PMD_DRV_LOG(DEBUG,
4966 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4967 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4968 : : } else {
4969 : 0 : pf->vf_nb_qps = 0;
4970 : 0 : pf->vf_num = 0;
4971 : : }
4972 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4973 : 0 : vsi_count += pf->vf_num;
4974 : :
4975 : : /* VMDq queue/VSI allocation */
4976 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4977 : 0 : pf->vmdq_nb_qps = 0;
4978 : 0 : pf->max_nb_vmdq_vsi = 0;
4979 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4980 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4981 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4982 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4983 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4984 : :
4985 : : /* Limit the maximum number of VMDq vsi to the maximum
4986 : : * ethdev can support
4987 : : */
4988 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4989 : : hw->func_caps.num_vsis - vsi_count);
4990 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4991 : : RTE_ETH_64_POOLS);
4992 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4993 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4994 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4995 : 0 : PMD_DRV_LOG(DEBUG,
4996 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4997 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4998 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4999 : : } else {
5000 : 0 : PMD_DRV_LOG(INFO,
5001 : : "No enough queues left for VMDq");
5002 : : }
5003 : : } else {
5004 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
5005 : : }
5006 : : }
5007 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
5008 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
5009 : :
5010 [ # # ]: 0 : if (hw->func_caps.dcb)
5011 : 0 : pf->flags |= I40E_FLAG_DCB;
5012 : :
5013 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
5014 : 0 : PMD_DRV_LOG(ERR,
5015 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
5016 : : qp_count, hw->func_caps.num_tx_qp);
5017 : 0 : return -EINVAL;
5018 : : }
5019 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
5020 : 0 : PMD_DRV_LOG(ERR,
5021 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
5022 : : vsi_count, hw->func_caps.num_vsis);
5023 : 0 : return -EINVAL;
5024 : : }
5025 : :
5026 : : /**
5027 : : * Enable outer VLAN processing if firmware version is greater
5028 : : * than v8.3
5029 : : */
5030 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
5031 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
5032 : 0 : pf->fw8_3gt = true;
5033 : : } else {
5034 : 0 : pf->fw8_3gt = false;
5035 : : }
5036 : :
5037 : : return 0;
5038 : : }
5039 : :
5040 : : static int
5041 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
5042 : : {
5043 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5044 : : struct i40e_aqc_get_switch_config_resp *switch_config;
5045 : : struct i40e_aqc_switch_config_element_resp *element;
5046 : 0 : uint16_t start_seid = 0, num_reported;
5047 : : int ret;
5048 : :
5049 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
5050 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
5051 [ # # ]: 0 : if (!switch_config) {
5052 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
5053 : 0 : return -ENOMEM;
5054 : : }
5055 : :
5056 : : /* Get the switch configurations */
5057 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
5058 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
5059 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5060 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
5061 : 0 : goto fail;
5062 : : }
5063 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
5064 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
5065 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
5066 : 0 : goto fail;
5067 : : }
5068 : :
5069 : : /* Parse the switch configuration elements */
5070 : : element = &(switch_config->element[0]);
5071 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
5072 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
5073 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
5074 : : } else
5075 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
5076 : :
5077 : 0 : fail:
5078 : 0 : rte_free(switch_config);
5079 : :
5080 : 0 : return ret;
5081 : : }
5082 : :
5083 : : static int
5084 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
5085 : : uint32_t num)
5086 : : {
5087 : : struct pool_entry *entry;
5088 : :
5089 [ # # ]: 0 : if (pool == NULL || num == 0)
5090 : : return -EINVAL;
5091 : :
5092 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
5093 [ # # ]: 0 : if (entry == NULL) {
5094 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
5095 : 0 : return -ENOMEM;
5096 : : }
5097 : :
5098 : : /* queue heap initialize */
5099 : 0 : pool->num_free = num;
5100 : 0 : pool->num_alloc = 0;
5101 : 0 : pool->base = base;
5102 : 0 : LIST_INIT(&pool->alloc_list);
5103 : : LIST_INIT(&pool->free_list);
5104 : :
5105 : : /* Initialize element */
5106 : 0 : entry->base = 0;
5107 : 0 : entry->len = num;
5108 : :
5109 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
5110 : 0 : return 0;
5111 : : }
5112 : :
5113 : : static void
5114 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5115 : : {
5116 : : struct pool_entry *entry, *next_entry;
5117 : :
5118 [ # # ]: 0 : if (pool == NULL)
5119 : : return;
5120 : :
5121 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->alloc_list); entry; entry = next_entry) {
5122 : 0 : next_entry = LIST_NEXT(entry, next);
5123 [ # # ]: 0 : LIST_REMOVE(entry, next);
5124 : 0 : rte_free(entry);
5125 : : }
5126 : :
5127 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->free_list); entry; entry = next_entry) {
5128 : 0 : next_entry = LIST_NEXT(entry, next);
5129 [ # # ]: 0 : LIST_REMOVE(entry, next);
5130 : 0 : rte_free(entry);
5131 : : }
5132 : :
5133 : 0 : pool->num_free = 0;
5134 : 0 : pool->num_alloc = 0;
5135 : 0 : pool->base = 0;
5136 : 0 : LIST_INIT(&pool->alloc_list);
5137 : 0 : LIST_INIT(&pool->free_list);
5138 : : }
5139 : :
5140 : : static int
5141 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
5142 : : uint32_t base)
5143 : : {
5144 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5145 : : uint32_t pool_offset;
5146 : : uint16_t len;
5147 : : int insert;
5148 : :
5149 [ # # ]: 0 : if (pool == NULL) {
5150 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5151 : 0 : return -EINVAL;
5152 : : }
5153 : :
5154 : 0 : pool_offset = base - pool->base;
5155 : : /* Lookup in alloc list */
5156 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
5157 [ # # ]: 0 : if (entry->base == pool_offset) {
5158 : : valid_entry = entry;
5159 [ # # ]: 0 : LIST_REMOVE(entry, next);
5160 : 0 : break;
5161 : : }
5162 : : }
5163 : :
5164 : : /* Not find, return */
5165 [ # # ]: 0 : if (valid_entry == NULL) {
5166 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
5167 : 0 : return -EINVAL;
5168 : : }
5169 : :
5170 : : /**
5171 : : * Found it, move it to free list and try to merge.
5172 : : * In order to make merge easier, always sort it by qbase.
5173 : : * Find adjacent prev and last entries.
5174 : : */
5175 : : prev = next = NULL;
5176 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5177 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5178 : : next = entry;
5179 : : break;
5180 : : }
5181 : : prev = entry;
5182 : : }
5183 : :
5184 : : insert = 0;
5185 : 0 : len = valid_entry->len;
5186 : : /* Try to merge with next one*/
5187 [ # # ]: 0 : if (next != NULL) {
5188 : : /* Merge with next one */
5189 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5190 : 0 : next->base = valid_entry->base;
5191 : 0 : next->len += len;
5192 : 0 : rte_free(valid_entry);
5193 : : valid_entry = next;
5194 : : insert = 1;
5195 : : }
5196 : : }
5197 : :
5198 [ # # ]: 0 : if (prev != NULL) {
5199 : : /* Merge with previous one */
5200 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5201 : 0 : prev->len += len;
5202 : : /* If it merge with next one, remove next node */
5203 [ # # ]: 0 : if (insert == 1) {
5204 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5205 : 0 : rte_free(valid_entry);
5206 : : valid_entry = NULL;
5207 : : } else {
5208 : 0 : rte_free(valid_entry);
5209 : : valid_entry = NULL;
5210 : : insert = 1;
5211 : : }
5212 : : }
5213 : : }
5214 : :
5215 : : /* Not find any entry to merge, insert */
5216 [ # # ]: 0 : if (insert == 0) {
5217 [ # # ]: 0 : if (prev != NULL)
5218 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5219 [ # # ]: 0 : else if (next != NULL)
5220 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5221 : : else /* It's empty list, insert to head */
5222 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5223 : : }
5224 : :
5225 : 0 : pool->num_free += len;
5226 : 0 : pool->num_alloc -= len;
5227 : :
5228 : 0 : return 0;
5229 : : }
5230 : :
5231 : : static int
5232 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5233 : : uint16_t num)
5234 : : {
5235 : : struct pool_entry *entry, *valid_entry;
5236 : :
5237 [ # # ]: 0 : if (pool == NULL || num == 0) {
5238 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5239 : 0 : return -EINVAL;
5240 : : }
5241 : :
5242 [ # # ]: 0 : if (pool->num_free < num) {
5243 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5244 : : num, pool->num_free);
5245 : 0 : return -ENOMEM;
5246 : : }
5247 : :
5248 : : valid_entry = NULL;
5249 : : /* Lookup in free list and find most fit one */
5250 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5251 [ # # ]: 0 : if (entry->len >= num) {
5252 : : /* Find best one */
5253 [ # # ]: 0 : if (entry->len == num) {
5254 : : valid_entry = entry;
5255 : : break;
5256 : : }
5257 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5258 : : valid_entry = entry;
5259 : : }
5260 : : }
5261 : :
5262 : : /* Not find one to satisfy the request, return */
5263 [ # # ]: 0 : if (valid_entry == NULL) {
5264 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5265 : 0 : return -ENOMEM;
5266 : : }
5267 : : /**
5268 : : * The entry have equal queue number as requested,
5269 : : * remove it from alloc_list.
5270 : : */
5271 [ # # ]: 0 : if (valid_entry->len == num) {
5272 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5273 : : } else {
5274 : : /**
5275 : : * The entry have more numbers than requested,
5276 : : * create a new entry for alloc_list and minus its
5277 : : * queue base and number in free_list.
5278 : : */
5279 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5280 [ # # ]: 0 : if (entry == NULL) {
5281 : 0 : PMD_DRV_LOG(ERR,
5282 : : "Failed to allocate memory for resource pool");
5283 : 0 : return -ENOMEM;
5284 : : }
5285 : 0 : entry->base = valid_entry->base;
5286 : 0 : entry->len = num;
5287 : 0 : valid_entry->base += num;
5288 : 0 : valid_entry->len -= num;
5289 : : valid_entry = entry;
5290 : : }
5291 : :
5292 : : /* Insert it into alloc list, not sorted */
5293 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5294 : :
5295 : 0 : pool->num_free -= valid_entry->len;
5296 : 0 : pool->num_alloc += valid_entry->len;
5297 : :
5298 : 0 : return valid_entry->base + pool->base;
5299 : : }
5300 : :
5301 : : /**
5302 : : * bitmap_is_subset - Check whether src2 is subset of src1
5303 : : **/
5304 : : static inline int
5305 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5306 : : {
5307 : 0 : return !((src1 ^ src2) & src2);
5308 : : }
5309 : :
5310 : : static enum i40e_status_code
5311 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5312 : : {
5313 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5314 : :
5315 : : /* If DCB is not supported, only default TC is supported */
5316 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5317 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5318 : 0 : return I40E_NOT_SUPPORTED;
5319 : : }
5320 : :
5321 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5322 : 0 : PMD_DRV_LOG(ERR,
5323 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5324 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5325 : 0 : return I40E_NOT_SUPPORTED;
5326 : : }
5327 : : return I40E_SUCCESS;
5328 : : }
5329 : :
5330 : : int
5331 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5332 : : struct i40e_vsi_vlan_pvid_info *info)
5333 : : {
5334 : : struct i40e_hw *hw;
5335 : : struct i40e_vsi_context ctxt;
5336 : : uint8_t vlan_flags = 0;
5337 : : int ret;
5338 : :
5339 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5340 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5341 : 0 : return I40E_ERR_PARAM;
5342 : : }
5343 : :
5344 [ # # ]: 0 : if (info->on) {
5345 : 0 : vsi->info.pvid = info->config.pvid;
5346 : : /**
5347 : : * If insert pvid is enabled, only tagged pkts are
5348 : : * allowed to be sent out.
5349 : : */
5350 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5351 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5352 : : } else {
5353 : 0 : vsi->info.pvid = 0;
5354 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5355 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5356 : :
5357 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5358 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5359 : : }
5360 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5361 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5362 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5363 : 0 : vsi->info.valid_sections =
5364 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5365 : : memset(&ctxt, 0, sizeof(ctxt));
5366 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5367 : 0 : ctxt.seid = vsi->seid;
5368 : :
5369 : 0 : hw = I40E_VSI_TO_HW(vsi);
5370 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5371 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5372 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5373 : :
5374 : : return ret;
5375 : : }
5376 : :
5377 : : static int
5378 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5379 : : {
5380 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5381 : : int i, ret;
5382 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5383 : :
5384 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5385 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5386 : : return ret;
5387 : :
5388 [ # # ]: 0 : if (!vsi->seid) {
5389 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5390 : 0 : return -EINVAL;
5391 : : }
5392 : :
5393 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5394 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5395 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5396 : 0 : tc_bw_data.tc_bw_credits[i] =
5397 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5398 : :
5399 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5400 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5401 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5402 : 0 : return ret;
5403 : : }
5404 : :
5405 : 0 : memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5406 : : sizeof(vsi->info.qs_handle));
5407 : 0 : return I40E_SUCCESS;
5408 : : }
5409 : :
5410 : : static enum i40e_status_code
5411 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5412 : : struct i40e_aqc_vsi_properties_data *info,
5413 : : uint8_t enabled_tcmap)
5414 : : {
5415 : : enum i40e_status_code ret;
5416 : : int i, total_tc = 0;
5417 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5418 : :
5419 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5420 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5421 : : return ret;
5422 : :
5423 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5424 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5425 : 0 : total_tc++;
5426 [ # # ]: 0 : if (total_tc == 0)
5427 : : total_tc = 1;
5428 : 0 : vsi->enabled_tc = enabled_tcmap;
5429 : :
5430 : : /* Number of queues per enabled TC */
5431 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5432 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5433 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5434 : :
5435 : : /* Adjust the queue number to actual queues that can be applied */
5436 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5437 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5438 : :
5439 : : /**
5440 : : * Configure TC and queue mapping parameters, for enabled TC,
5441 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5442 : : * default queue will serve it.
5443 : : */
5444 : : qp_idx = 0;
5445 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5446 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5447 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5448 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5449 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5450 : 0 : qp_idx += qpnum_per_tc;
5451 : : } else
5452 : 0 : info->tc_mapping[i] = 0;
5453 : : }
5454 : :
5455 : : /* Associate queue number with VSI */
5456 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5457 : 0 : info->mapping_flags |=
5458 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5459 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5460 : 0 : info->queue_mapping[i] =
5461 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5462 : : } else {
5463 : 0 : info->mapping_flags |=
5464 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5465 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5466 : : }
5467 : 0 : info->valid_sections |=
5468 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5469 : :
5470 : 0 : return I40E_SUCCESS;
5471 : : }
5472 : :
5473 : : static int
5474 : 0 : i40e_veb_release(struct i40e_veb *veb)
5475 : : {
5476 : : struct i40e_vsi *vsi;
5477 : : struct i40e_hw *hw;
5478 : :
5479 [ # # ]: 0 : if (veb == NULL)
5480 : : return -EINVAL;
5481 : :
5482 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5483 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5484 : 0 : return -EACCES;
5485 : : }
5486 : : /* associate_vsi field is NULL for floating VEB */
5487 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5488 : : vsi = veb->associate_vsi;
5489 : 0 : hw = I40E_VSI_TO_HW(vsi);
5490 : :
5491 : 0 : vsi->uplink_seid = veb->uplink_seid;
5492 : 0 : vsi->veb = NULL;
5493 : : } else {
5494 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5495 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5496 : : }
5497 : :
5498 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5499 : 0 : rte_free(veb);
5500 : 0 : return I40E_SUCCESS;
5501 : : }
5502 : :
5503 : : /* Setup a veb */
5504 : : static struct i40e_veb *
5505 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5506 : : {
5507 : : struct i40e_veb *veb;
5508 : : int ret;
5509 : : struct i40e_hw *hw;
5510 : :
5511 [ # # ]: 0 : if (pf == NULL) {
5512 : 0 : PMD_DRV_LOG(ERR,
5513 : : "veb setup failed, associated PF shouldn't null");
5514 : 0 : return NULL;
5515 : : }
5516 : 0 : hw = I40E_PF_TO_HW(pf);
5517 : :
5518 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5519 [ # # ]: 0 : if (!veb) {
5520 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5521 : 0 : goto fail;
5522 : : }
5523 : :
5524 : 0 : veb->associate_vsi = vsi;
5525 : 0 : veb->associate_pf = pf;
5526 : 0 : TAILQ_INIT(&veb->head);
5527 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5528 : :
5529 : : /* create floating veb if vsi is NULL */
5530 [ # # ]: 0 : if (vsi != NULL) {
5531 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5532 : : I40E_DEFAULT_TCMAP, false,
5533 : 0 : &veb->seid, false, NULL);
5534 : : } else {
5535 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5536 : 0 : true, &veb->seid, false, NULL);
5537 : : }
5538 : :
5539 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5540 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5541 : : hw->aq.asq_last_status);
5542 : 0 : goto fail;
5543 : : }
5544 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5545 : :
5546 : : /* get statistics index */
5547 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5548 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5549 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5550 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5551 : : hw->aq.asq_last_status);
5552 : 0 : goto fail;
5553 : : }
5554 : : /* Get VEB bandwidth, to be implemented */
5555 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5556 [ # # ]: 0 : if (vsi)
5557 : 0 : vsi->uplink_seid = veb->seid;
5558 : :
5559 : : return veb;
5560 : 0 : fail:
5561 : 0 : rte_free(veb);
5562 : 0 : return NULL;
5563 : : }
5564 : :
5565 : : int
5566 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5567 : : {
5568 : : struct i40e_pf *pf;
5569 : : struct i40e_hw *hw;
5570 : : struct i40e_vsi_list *vsi_list;
5571 : : void *temp;
5572 : : int ret;
5573 : : struct i40e_mac_filter *f;
5574 : : uint16_t user_param;
5575 : :
5576 [ # # ]: 0 : if (!vsi)
5577 : : return I40E_SUCCESS;
5578 : :
5579 [ # # ]: 0 : if (!vsi->adapter)
5580 : : return -EFAULT;
5581 : :
5582 : 0 : user_param = vsi->user_param;
5583 : :
5584 : : pf = I40E_VSI_TO_PF(vsi);
5585 : 0 : hw = I40E_VSI_TO_HW(vsi);
5586 : :
5587 : : /* VSI has child to attach, release child first */
5588 [ # # ]: 0 : if (vsi->veb) {
5589 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5590 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5591 : : return -1;
5592 : : }
5593 : 0 : i40e_veb_release(vsi->veb);
5594 : : }
5595 : :
5596 [ # # ]: 0 : if (vsi->floating_veb) {
5597 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5598 : : list, temp) {
5599 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5600 : : return -1;
5601 : : }
5602 : : }
5603 : :
5604 : : /* Remove all macvlan filters of the VSI */
5605 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5606 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5607 : 0 : rte_free(f);
5608 : :
5609 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5610 : 0 : ((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 || vsi->parent_vsi->veb == NULL) {
5614 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5615 : 0 : return I40E_ERR_PARAM;
5616 : : }
5617 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5618 : : &vsi->sib_vsi_list, list);
5619 : :
5620 : : /* Remove all switch element of the VSI */
5621 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5622 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5623 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5624 : : }
5625 : :
5626 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5627 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5628 : : /* Remove vsi from parent's sibling list */
5629 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5630 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5631 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5632 : 0 : return I40E_ERR_PARAM;
5633 : : }
5634 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5635 : : &vsi->sib_vsi_list, list);
5636 : :
5637 : : /* Remove all switch element of the VSI */
5638 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5639 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5640 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5641 : : }
5642 : :
5643 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5644 : :
5645 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5646 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5647 : 0 : rte_free(vsi);
5648 : :
5649 : 0 : return I40E_SUCCESS;
5650 : : }
5651 : :
5652 : : static int
5653 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5654 : : {
5655 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5656 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5657 : : struct i40e_mac_filter_info filter;
5658 : : int ret;
5659 : :
5660 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5661 : : return I40E_ERR_CONFIG;
5662 : : memset(&def_filter, 0, sizeof(def_filter));
5663 : : memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5664 : : ETH_ADDR_LEN);
5665 : : def_filter.vlan_tag = 0;
5666 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5667 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5668 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5669 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5670 : : struct i40e_mac_filter *f;
5671 : : struct rte_ether_addr *mac;
5672 : :
5673 : 0 : PMD_DRV_LOG(DEBUG,
5674 : : "Cannot remove the default macvlan filter");
5675 : : /* It needs to add the permanent mac into mac list */
5676 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5677 [ # # ]: 0 : if (f == NULL) {
5678 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5679 : 0 : return I40E_ERR_NO_MEMORY;
5680 : : }
5681 : : mac = &f->mac_info.mac_addr;
5682 : 0 : memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5683 : : ETH_ADDR_LEN);
5684 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5685 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5686 : 0 : vsi->mac_num++;
5687 : :
5688 : 0 : return ret;
5689 : : }
5690 : : memcpy(&filter.mac_addr,
5691 : 0 : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5692 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5693 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5694 : : }
5695 : :
5696 : : /*
5697 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5698 : : * @vsi: the VSI to be queried
5699 : : *
5700 : : * Returns 0 on success, negative value on failure
5701 : : */
5702 : : static enum i40e_status_code
5703 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5704 : : {
5705 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5706 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5707 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5708 : : i40e_status ret;
5709 : : int i;
5710 : : uint32_t bw_max;
5711 : :
5712 : : memset(&bw_config, 0, sizeof(bw_config));
5713 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5714 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5715 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5716 : : hw->aq.asq_last_status);
5717 : 0 : return ret;
5718 : : }
5719 : :
5720 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5721 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5722 : : &ets_sla_config, NULL);
5723 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5724 : 0 : PMD_DRV_LOG(ERR,
5725 : : "VSI failed to get TC bandwidth configuration %u",
5726 : : hw->aq.asq_last_status);
5727 : 0 : return ret;
5728 : : }
5729 : :
5730 : : /* store and print out BW info */
5731 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5732 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5733 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5734 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5735 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5736 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5737 : : I40E_16_BIT_WIDTH);
5738 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5739 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5740 : 0 : ets_sla_config.share_credits[i];
5741 : 0 : vsi->bw_info.bw_ets_credits[i] =
5742 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5743 : : /* 4 bits per TC, 4th bit is reserved */
5744 : 0 : vsi->bw_info.bw_ets_max[i] =
5745 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5746 : : RTE_LEN2MASK(3, uint8_t));
5747 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5748 : : vsi->bw_info.bw_ets_share_credits[i]);
5749 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5750 : : vsi->bw_info.bw_ets_credits[i]);
5751 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5752 : : vsi->bw_info.bw_ets_max[i]);
5753 : : }
5754 : :
5755 : : return I40E_SUCCESS;
5756 : : }
5757 : :
5758 : : /* i40e_enable_pf_lb
5759 : : * @pf: pointer to the pf structure
5760 : : *
5761 : : * allow loopback on pf
5762 : : */
5763 : : static inline void
5764 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5765 : : {
5766 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5767 : : struct i40e_vsi_context ctxt;
5768 : : int ret;
5769 : :
5770 : : /* Use the FW API if FW >= v5.0 */
5771 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5772 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5773 : 0 : return;
5774 : : }
5775 : :
5776 : : memset(&ctxt, 0, sizeof(ctxt));
5777 : 0 : ctxt.seid = pf->main_vsi_seid;
5778 : 0 : ctxt.pf_num = hw->pf_id;
5779 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5780 [ # # ]: 0 : if (ret) {
5781 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5782 : : ret, hw->aq.asq_last_status);
5783 : 0 : return;
5784 : : }
5785 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5786 : 0 : ctxt.info.valid_sections =
5787 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5788 : 0 : ctxt.info.switch_id |=
5789 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5790 : :
5791 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5792 [ # # ]: 0 : if (ret)
5793 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5794 : : hw->aq.asq_last_status);
5795 : : }
5796 : :
5797 : : /* i40e_pf_set_source_prune
5798 : : * @pf: pointer to the pf structure
5799 : : * @on: Enable/disable source prune
5800 : : *
5801 : : * set source prune on pf
5802 : : */
5803 : : int
5804 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5805 : : {
5806 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5807 : : struct i40e_vsi_context ctxt;
5808 : : int ret;
5809 : :
5810 : : memset(&ctxt, 0, sizeof(ctxt));
5811 : 0 : ctxt.seid = pf->main_vsi_seid;
5812 : 0 : ctxt.pf_num = hw->pf_id;
5813 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5814 [ # # ]: 0 : if (ret) {
5815 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5816 : : ret, hw->aq.asq_last_status);
5817 : 0 : return ret;
5818 : : }
5819 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5820 : 0 : ctxt.info.valid_sections =
5821 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5822 [ # # ]: 0 : if (on)
5823 : 0 : ctxt.info.switch_id &=
5824 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5825 : : else
5826 : 0 : ctxt.info.switch_id |=
5827 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5828 : :
5829 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5830 [ # # ]: 0 : if (ret)
5831 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5832 : : hw->aq.asq_last_status);
5833 : :
5834 : : return ret;
5835 : : }
5836 : :
5837 : : /* Setup a VSI */
5838 : : struct i40e_vsi *
5839 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5840 : : enum i40e_vsi_type type,
5841 : : struct i40e_vsi *uplink_vsi,
5842 : : uint16_t user_param)
5843 : : {
5844 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5845 : : struct i40e_vsi *vsi;
5846 : : struct i40e_mac_filter_info filter;
5847 : : int ret;
5848 : : struct i40e_vsi_context ctxt;
5849 : 0 : struct rte_ether_addr broadcast =
5850 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5851 : :
5852 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5853 : : uplink_vsi == NULL) {
5854 : 0 : PMD_DRV_LOG(ERR,
5855 : : "VSI setup failed, VSI link shouldn't be NULL");
5856 : 0 : return NULL;
5857 : : }
5858 : :
5859 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5860 : 0 : PMD_DRV_LOG(ERR,
5861 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5862 : 0 : return NULL;
5863 : : }
5864 : :
5865 : : /* two situations
5866 : : * 1.type is not MAIN and uplink vsi is not NULL
5867 : : * If uplink vsi didn't setup VEB, create one first under veb field
5868 : : * 2.type is SRIOV and the uplink is NULL
5869 : : * If floating VEB is NULL, create one veb under floating veb field
5870 : : */
5871 : :
5872 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5873 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5874 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5875 : :
5876 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5877 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5878 : 0 : return NULL;
5879 : : }
5880 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5881 : 0 : i40e_enable_pf_lb(pf);
5882 : : }
5883 : :
5884 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5885 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5886 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5887 : :
5888 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5889 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5890 : 0 : return NULL;
5891 : : }
5892 : : }
5893 : :
5894 : : /* source prune is disabled to support VRRP in default*/
5895 : 0 : i40e_pf_set_source_prune(pf, 0);
5896 : :
5897 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5898 [ # # ]: 0 : if (!vsi) {
5899 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5900 : 0 : return NULL;
5901 : : }
5902 : 0 : TAILQ_INIT(&vsi->mac_list);
5903 : 0 : vsi->type = type;
5904 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5905 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5906 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5907 : 0 : vsi->user_param = user_param;
5908 : 0 : vsi->vlan_anti_spoof_on = 0;
5909 : 0 : vsi->vlan_filter_on = 0;
5910 : : /* Allocate queues */
5911 [ # # # # : 0 : switch (vsi->type) {
# ]
5912 : 0 : case I40E_VSI_MAIN :
5913 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5914 : 0 : break;
5915 : 0 : case I40E_VSI_SRIOV :
5916 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5917 : 0 : break;
5918 : 0 : case I40E_VSI_VMDQ2:
5919 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5920 : 0 : break;
5921 : 0 : case I40E_VSI_FDIR:
5922 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5923 : 0 : break;
5924 : 0 : default:
5925 : 0 : goto fail_mem;
5926 : : }
5927 : : /*
5928 : : * The filter status descriptor is reported in rx queue 0,
5929 : : * while the tx queue for fdir filter programming has no
5930 : : * such constraints, can be non-zero queues.
5931 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5932 : : * To make sure it will use queue 0 pair, queue allocation
5933 : : * need be done before this function is called
5934 : : */
5935 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5936 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5937 [ # # ]: 0 : if (ret < 0) {
5938 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5939 : : vsi->seid, ret);
5940 : 0 : goto fail_mem;
5941 : : }
5942 : 0 : vsi->base_queue = ret;
5943 : : } else
5944 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5945 : :
5946 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5947 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5948 [ # # ]: 0 : if (pf->support_multi_driver) {
5949 : : /* If support multi-driver, need to use INT0 instead of
5950 : : * allocating from msix pool. The Msix pool is init from
5951 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5952 : : * to 1 without calling i40e_res_pool_alloc.
5953 : : */
5954 : 0 : vsi->msix_intr = 0;
5955 : 0 : vsi->nb_msix = 1;
5956 : : } else {
5957 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5958 : 0 : RTE_MIN(vsi->nb_qps,
5959 : : RTE_MAX_RXTX_INTR_VEC_ID));
5960 [ # # ]: 0 : if (ret < 0) {
5961 : 0 : PMD_DRV_LOG(ERR,
5962 : : "VSI MAIN %d get heap failed %d",
5963 : : vsi->seid, ret);
5964 : 0 : goto fail_queue_alloc;
5965 : : }
5966 : 0 : vsi->msix_intr = ret;
5967 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5968 : : RTE_MAX_RXTX_INTR_VEC_ID);
5969 : : }
5970 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5971 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5972 [ # # ]: 0 : if (ret < 0) {
5973 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5974 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5975 : 0 : goto fail_queue_alloc;
5976 : 0 : vsi->msix_intr = 0;
5977 : 0 : vsi->nb_msix = 0;
5978 : : } else {
5979 : 0 : vsi->msix_intr = ret;
5980 : 0 : vsi->nb_msix = 1;
5981 : : }
5982 : : } else {
5983 : 0 : vsi->msix_intr = 0;
5984 : 0 : vsi->nb_msix = 0;
5985 : : }
5986 : :
5987 : : /* Add VSI */
5988 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5989 : : /* For main VSI, no need to add since it's default one */
5990 : 0 : vsi->uplink_seid = pf->mac_seid;
5991 : 0 : vsi->seid = pf->main_vsi_seid;
5992 : : /* Bind queues with specific MSIX interrupt */
5993 : : /**
5994 : : * Needs 2 interrupt at least, one for misc cause which will
5995 : : * enabled from OS side, Another for queues binding the
5996 : : * interrupt from device side only.
5997 : : */
5998 : :
5999 : : /* Get default VSI parameters from hardware */
6000 : : memset(&ctxt, 0, sizeof(ctxt));
6001 : 0 : ctxt.seid = vsi->seid;
6002 : 0 : ctxt.pf_num = hw->pf_id;
6003 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6004 : : ctxt.vf_num = 0;
6005 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
6006 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6007 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
6008 : 0 : goto fail_msix_alloc;
6009 : : }
6010 : 0 : vsi->info = ctxt.info;
6011 : 0 : vsi->vsi_id = ctxt.vsi_number;
6012 : 0 : vsi->info.valid_sections = 0;
6013 : :
6014 : : /* Configure tc, enabled TC0 only */
6015 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
6016 : : I40E_SUCCESS) {
6017 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
6018 : 0 : goto fail_msix_alloc;
6019 : : }
6020 : :
6021 : : /* TC, queue mapping */
6022 : : memset(&ctxt, 0, sizeof(ctxt));
6023 : 0 : vsi->info.valid_sections |=
6024 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6025 : 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
6026 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6027 : 0 : ctxt.info = vsi->info;
6028 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6029 : : I40E_DEFAULT_TCMAP);
6030 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6031 : 0 : PMD_DRV_LOG(ERR,
6032 : : "Failed to configure TC queue mapping");
6033 : 0 : goto fail_msix_alloc;
6034 : : }
6035 : 0 : ctxt.seid = vsi->seid;
6036 : 0 : ctxt.pf_num = hw->pf_id;
6037 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6038 : 0 : ctxt.vf_num = 0;
6039 : :
6040 : : /* Update VSI parameters */
6041 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6042 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6043 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
6044 : 0 : goto fail_msix_alloc;
6045 : : }
6046 : :
6047 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
6048 : : sizeof(vsi->info.tc_mapping));
6049 : 0 : memcpy(&vsi->info.queue_mapping,
6050 : : &ctxt.info.queue_mapping,
6051 : : sizeof(vsi->info.queue_mapping));
6052 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
6053 : 0 : vsi->info.valid_sections = 0;
6054 : :
6055 : 0 : memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
6056 : : ETH_ADDR_LEN);
6057 : :
6058 : : /**
6059 : : * Updating default filter settings are necessary to prevent
6060 : : * reception of tagged packets.
6061 : : * Some old firmware configurations load a default macvlan
6062 : : * filter which accepts both tagged and untagged packets.
6063 : : * The updating is to use a normal filter instead if needed.
6064 : : * For NVM 4.2.2 or after, the updating is not needed anymore.
6065 : : * The firmware with correct configurations load the default
6066 : : * macvlan filter which is expected and cannot be removed.
6067 : : */
6068 : 0 : i40e_update_default_filter_setting(vsi);
6069 : 0 : i40e_config_qinq(hw, vsi);
6070 [ # # ]: 0 : } else if (type == I40E_VSI_SRIOV) {
6071 : : memset(&ctxt, 0, sizeof(ctxt));
6072 : : /**
6073 : : * For other VSI, the uplink_seid equals to uplink VSI's
6074 : : * uplink_seid since they share same VEB
6075 : : */
6076 [ # # ]: 0 : if (uplink_vsi == NULL)
6077 : 0 : vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
6078 : : else
6079 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6080 : 0 : ctxt.pf_num = hw->pf_id;
6081 : 0 : ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
6082 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6083 : 0 : ctxt.connection_type = 0x1;
6084 : : ctxt.flags = I40E_AQ_VSI_TYPE_VF;
6085 : :
6086 : : /* Use the VEB configuration if FW >= v5.0 */
6087 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
6088 : : /* Configure switch ID */
6089 : 0 : ctxt.info.valid_sections |=
6090 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6091 : 0 : ctxt.info.switch_id =
6092 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6093 : : }
6094 : :
6095 : : /* Configure port/vlan */
6096 : 0 : ctxt.info.valid_sections |=
6097 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6098 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6099 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6100 : 0 : hw->func_caps.enabled_tcmap);
6101 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6102 : 0 : PMD_DRV_LOG(ERR,
6103 : : "Failed to configure TC queue mapping");
6104 : 0 : goto fail_msix_alloc;
6105 : : }
6106 : :
6107 : 0 : ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
6108 : 0 : ctxt.info.valid_sections |=
6109 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6110 : : /**
6111 : : * Since VSI is not created yet, only configure parameter,
6112 : : * will add vsi below.
6113 : : */
6114 : :
6115 : 0 : i40e_config_qinq(hw, vsi);
6116 [ # # ]: 0 : } else if (type == I40E_VSI_VMDQ2) {
6117 : : memset(&ctxt, 0, sizeof(ctxt));
6118 : : /*
6119 : : * For other VSI, the uplink_seid equals to uplink VSI's
6120 : : * uplink_seid since they share same VEB
6121 : : */
6122 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6123 : 0 : ctxt.pf_num = hw->pf_id;
6124 : : ctxt.vf_num = 0;
6125 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6126 : 0 : ctxt.connection_type = 0x1;
6127 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
6128 : :
6129 : 0 : ctxt.info.valid_sections |=
6130 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6131 : : /* user_param carries flag to enable loop back */
6132 [ # # ]: 0 : if (user_param) {
6133 : : ctxt.info.switch_id =
6134 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
6135 : 0 : ctxt.info.switch_id |=
6136 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6137 : : }
6138 : :
6139 : : /* Configure port/vlan */
6140 : 0 : ctxt.info.valid_sections |=
6141 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6142 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6143 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6144 : : I40E_DEFAULT_TCMAP);
6145 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6146 : 0 : PMD_DRV_LOG(ERR,
6147 : : "Failed to configure TC queue mapping");
6148 : 0 : goto fail_msix_alloc;
6149 : : }
6150 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6151 : 0 : ctxt.info.valid_sections |=
6152 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6153 : : } else if (type == I40E_VSI_FDIR) {
6154 : : memset(&ctxt, 0, sizeof(ctxt));
6155 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6156 : 0 : ctxt.pf_num = hw->pf_id;
6157 : : ctxt.vf_num = 0;
6158 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6159 : 0 : ctxt.connection_type = 0x1; /* regular data port */
6160 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6161 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6162 : : I40E_DEFAULT_TCMAP);
6163 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6164 : 0 : PMD_DRV_LOG(ERR,
6165 : : "Failed to configure TC queue mapping.");
6166 : 0 : goto fail_msix_alloc;
6167 : : }
6168 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6169 : 0 : ctxt.info.valid_sections |=
6170 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6171 : : } else {
6172 : : PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6173 : : goto fail_msix_alloc;
6174 : : }
6175 : :
6176 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN) {
6177 : 0 : ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6178 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6179 : 0 : PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6180 : : hw->aq.asq_last_status);
6181 : 0 : goto fail_msix_alloc;
6182 : : }
6183 [ # # ]: 0 : memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6184 : 0 : vsi->info.valid_sections = 0;
6185 : 0 : vsi->seid = ctxt.seid;
6186 : 0 : vsi->vsi_id = ctxt.vsi_number;
6187 : 0 : vsi->sib_vsi_list.vsi = vsi;
6188 [ # # # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6189 : 0 : TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6190 : : &vsi->sib_vsi_list, list);
6191 : : } else {
6192 : 0 : TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6193 : : &vsi->sib_vsi_list, list);
6194 : : }
6195 : : }
6196 : :
6197 [ # # ]: 0 : if (vsi->type != I40E_VSI_FDIR) {
6198 : : /* MAC/VLAN configuration for non-FDIR VSI*/
6199 : : memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6200 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6201 : :
6202 : 0 : ret = i40e_vsi_add_mac(vsi, &filter);
6203 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6204 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6205 : 0 : goto fail_msix_alloc;
6206 : : }
6207 : : }
6208 : :
6209 : : /* Get VSI BW information */
6210 : 0 : i40e_vsi_get_bw_config(vsi);
6211 : 0 : return vsi;
6212 : 0 : fail_msix_alloc:
6213 : 0 : i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6214 : 0 : fail_queue_alloc:
6215 : 0 : i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6216 : 0 : fail_mem:
6217 : 0 : rte_free(vsi);
6218 : 0 : return NULL;
6219 : : }
6220 : :
6221 : : /* Configure vlan filter on or off */
6222 : : int
6223 : 0 : i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6224 : : {
6225 : : int i, num;
6226 : : struct i40e_mac_filter *f;
6227 : : void *temp;
6228 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
6229 : : enum i40e_mac_filter_type desired_filter;
6230 : : int ret = I40E_SUCCESS;
6231 : :
6232 [ # # ]: 0 : if (on) {
6233 : : /* Filter to match MAC and VLAN */
6234 : : desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6235 : : } else {
6236 : : /* Filter to match only MAC */
6237 : : desired_filter = I40E_MAC_PERFECT_MATCH;
6238 : : }
6239 : :
6240 : 0 : num = vsi->mac_num;
6241 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
6242 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
6243 : 0 : return -1;
6244 : : }
6245 : :
6246 : : i = 0;
6247 : :
6248 : : /* Remove all existing mac */
6249 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6250 : 0 : mac_filter[i] = f->mac_info;
6251 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6252 [ # # ]: 0 : if (ret) {
6253 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6254 : : on ? "enable" : "disable");
6255 : 0 : return ret;
6256 : : }
6257 : 0 : i++;
6258 : : }
6259 : :
6260 : : /* Override with new filter */
6261 [ # # ]: 0 : for (i = 0; i < num; i++) {
6262 : 0 : mac_filter[i].filter_type = desired_filter;
6263 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6264 [ # # ]: 0 : if (ret) {
6265 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6266 : : on ? "enable" : "disable");
6267 : 0 : return ret;
6268 : : }
6269 : : }
6270 : :
6271 : : return 0;
6272 : : }
6273 : :
6274 : : /* Configure vlan stripping on or off */
6275 : : int
6276 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6277 : : {
6278 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6279 : : struct i40e_vsi_context ctxt;
6280 : : uint8_t vlan_flags;
6281 : : int ret = I40E_SUCCESS;
6282 : :
6283 : : /* Check if it has been already on or off */
6284 [ # # ]: 0 : if (vsi->info.valid_sections &
6285 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6286 [ # # ]: 0 : if (on) {
6287 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6288 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6289 : : return 0; /* already on */
6290 : : } else {
6291 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6292 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6293 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6294 : : return 0; /* already off */
6295 : : }
6296 : : }
6297 : :
6298 [ # # ]: 0 : if (on)
6299 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6300 : : else
6301 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6302 : 0 : vsi->info.valid_sections =
6303 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6304 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6305 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6306 : 0 : ctxt.seid = vsi->seid;
6307 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6308 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6309 [ # # ]: 0 : if (ret)
6310 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6311 : : on ? "enable" : "disable");
6312 : :
6313 : : return ret;
6314 : : }
6315 : :
6316 : : static int
6317 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6318 : : {
6319 : 0 : struct rte_eth_dev_data *data = dev->data;
6320 : : int ret;
6321 : : int mask = 0;
6322 : :
6323 : : /* Apply vlan offload setting */
6324 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6325 : : RTE_ETH_QINQ_STRIP_MASK |
6326 : : RTE_ETH_VLAN_FILTER_MASK |
6327 : : RTE_ETH_VLAN_EXTEND_MASK;
6328 : :
6329 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6330 [ # # ]: 0 : if (ret) {
6331 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6332 : 0 : return ret;
6333 : : }
6334 : :
6335 : : /* Apply pvid setting */
6336 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6337 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6338 [ # # ]: 0 : if (ret)
6339 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6340 : :
6341 : : return ret;
6342 : : }
6343 : :
6344 : : static int
6345 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6346 : : {
6347 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6348 : :
6349 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6350 : : }
6351 : :
6352 : : static int
6353 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6354 : : {
6355 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6356 : : struct i40e_link_status link_status;
6357 : : uint32_t rxfc = 0, txfc = 0, reg;
6358 : : uint8_t an_info;
6359 : : int ret;
6360 : :
6361 : : memset(&link_status, 0, sizeof(link_status));
6362 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6363 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6364 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6365 : 0 : goto write_reg; /* Disable flow control */
6366 : : }
6367 : :
6368 : 0 : an_info = hw->phy.link_info.an_info;
6369 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6370 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6371 : : ret = I40E_ERR_NOT_READY;
6372 : 0 : goto write_reg; /* Disable flow control */
6373 : : }
6374 : : /**
6375 : : * If link auto negotiation is enabled, flow control needs to
6376 : : * be configured according to it
6377 : : */
6378 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6379 : 0 : case I40E_LINK_PAUSE_RXTX:
6380 : : rxfc = 1;
6381 : : txfc = 1;
6382 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6383 : 0 : break;
6384 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6385 : : rxfc = 1;
6386 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6387 : 0 : break;
6388 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6389 : : txfc = 1;
6390 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6391 : 0 : break;
6392 : 0 : default:
6393 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6394 : 0 : break;
6395 : : }
6396 : :
6397 : 0 : write_reg:
6398 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6399 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6400 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6401 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6402 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6403 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6404 : :
6405 : 0 : return ret;
6406 : : }
6407 : :
6408 : : /* PF setup */
6409 : : static int
6410 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6411 : : {
6412 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6413 : : struct i40e_filter_control_settings settings;
6414 : : struct i40e_vsi *vsi;
6415 : : int ret;
6416 : :
6417 : : /* Clear all stats counters */
6418 : 0 : pf->offset_loaded = FALSE;
6419 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6420 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6421 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6422 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6423 : :
6424 : 0 : ret = i40e_pf_get_switch_config(pf);
6425 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6426 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6427 : 0 : return ret;
6428 : : }
6429 : :
6430 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6431 [ # # ]: 0 : if (ret)
6432 : 0 : PMD_INIT_LOG(WARNING,
6433 : : "failed to allocate switch domain for device %d", ret);
6434 : :
6435 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6436 : : /* make queue allocated first, let FDIR use queue pair 0*/
6437 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6438 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6439 : 0 : PMD_DRV_LOG(ERR,
6440 : : "queue allocation fails for FDIR: ret =%d",
6441 : : ret);
6442 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6443 : : }
6444 : : }
6445 : : /* main VSI setup */
6446 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6447 [ # # ]: 0 : if (!vsi) {
6448 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6449 : 0 : return I40E_ERR_NOT_READY;
6450 : : }
6451 [ # # ]: 0 : pf->main_vsi = vsi;
6452 : :
6453 : : /* Configure filter control */
6454 : : memset(&settings, 0, sizeof(settings));
6455 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6456 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6457 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6458 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6459 : : else {
6460 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6461 : : hw->func_caps.rss_table_size);
6462 : 0 : return I40E_ERR_PARAM;
6463 : : }
6464 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6465 : : hw->func_caps.rss_table_size);
6466 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6467 : :
6468 : : /* Enable ethtype and macvlan filters */
6469 : 0 : settings.enable_ethtype = TRUE;
6470 : 0 : settings.enable_macvlan = TRUE;
6471 : 0 : ret = i40e_set_filter_control(hw, &settings);
6472 [ # # ]: 0 : if (ret)
6473 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6474 : : ret);
6475 : :
6476 : : /* Update flow control according to the auto negotiation */
6477 : 0 : i40e_update_flow_control(hw);
6478 : :
6479 : 0 : return I40E_SUCCESS;
6480 : : }
6481 : :
6482 : : int
6483 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6484 : : {
6485 : : uint32_t reg;
6486 : : uint16_t j;
6487 : :
6488 : : /**
6489 : : * Set or clear TX Queue Disable flags,
6490 : : * which is required by hardware.
6491 : : */
6492 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6493 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6494 : :
6495 : : /* Wait until the request is finished */
6496 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6497 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6498 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6499 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6500 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6501 : : & 0x1))) {
6502 : : break;
6503 : : }
6504 : : }
6505 [ # # ]: 0 : if (on) {
6506 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6507 : : return I40E_SUCCESS; /* already on, skip next steps */
6508 : :
6509 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6510 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6511 : : } else {
6512 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6513 : : return I40E_SUCCESS; /* already off, skip next steps */
6514 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6515 : : }
6516 : : /* Write the register */
6517 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6518 : : /* Check the result */
6519 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6520 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6521 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6522 [ # # ]: 0 : if (on) {
6523 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6524 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6525 : : break;
6526 : : } else {
6527 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6528 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6529 : : break;
6530 : : }
6531 : : }
6532 : : /* Check if it is timeout */
6533 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6534 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6535 : : (on ? "enable" : "disable"), q_idx);
6536 : 0 : return I40E_ERR_TIMEOUT;
6537 : : }
6538 : :
6539 : : return I40E_SUCCESS;
6540 : : }
6541 : :
6542 : : int
6543 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6544 : : {
6545 : : uint32_t reg;
6546 : : uint16_t j;
6547 : :
6548 : : /* Wait until the request is finished */
6549 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6550 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6551 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6552 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6553 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6554 : : break;
6555 : : }
6556 : :
6557 [ # # ]: 0 : if (on) {
6558 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6559 : : return I40E_SUCCESS; /* Already on, skip next steps */
6560 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6561 : : } else {
6562 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6563 : : return I40E_SUCCESS; /* Already off, skip next steps */
6564 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6565 : : }
6566 : :
6567 : : /* Write the register */
6568 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6569 : : /* Check the result */
6570 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6571 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6572 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6573 [ # # ]: 0 : if (on) {
6574 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6575 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6576 : : break;
6577 : : } else {
6578 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6579 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6580 : : break;
6581 : : }
6582 : : }
6583 : :
6584 : : /* Check if it is timeout */
6585 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6586 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6587 : : (on ? "enable" : "disable"), q_idx);
6588 : 0 : return I40E_ERR_TIMEOUT;
6589 : : }
6590 : :
6591 : : return I40E_SUCCESS;
6592 : : }
6593 : :
6594 : : /* Initialize VSI for TX */
6595 : : static int
6596 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6597 : : {
6598 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6599 : : uint16_t i;
6600 : : uint32_t ret = I40E_SUCCESS;
6601 : : struct ci_tx_queue *txq;
6602 : :
6603 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6604 : 0 : txq = data->tx_queues[i];
6605 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6606 : 0 : continue;
6607 : 0 : ret = i40e_tx_queue_init(txq);
6608 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6609 : : break;
6610 : : }
6611 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6612 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6613 : :
6614 : 0 : return ret;
6615 : : }
6616 : :
6617 : : /* Initialize VSI for RX */
6618 : : static int
6619 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6620 : : {
6621 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6622 : : int ret = I40E_SUCCESS;
6623 : : uint16_t i;
6624 : : struct ci_rx_queue *rxq;
6625 : :
6626 : 0 : i40e_pf_config_rss(pf);
6627 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6628 : 0 : rxq = data->rx_queues[i];
6629 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6630 : 0 : continue;
6631 : :
6632 : 0 : ret = i40e_rx_queue_init(rxq);
6633 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6634 : 0 : PMD_DRV_LOG(ERR,
6635 : : "Failed to do RX queue initialization");
6636 : 0 : break;
6637 : : }
6638 : : }
6639 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6640 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6641 : :
6642 : 0 : return ret;
6643 : : }
6644 : :
6645 : : static int
6646 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6647 : : {
6648 : : int err;
6649 : :
6650 : 0 : err = i40e_dev_tx_init(pf);
6651 [ # # ]: 0 : if (err) {
6652 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6653 : 0 : return err;
6654 : : }
6655 : 0 : err = i40e_dev_rx_init(pf);
6656 [ # # ]: 0 : if (err) {
6657 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6658 : 0 : return err;
6659 : : }
6660 : :
6661 : : return err;
6662 : : }
6663 : :
6664 : : static int
6665 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6666 : : {
6667 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6668 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6669 : : int i, err, conf_vsis, j, loop;
6670 : : struct i40e_vsi *vsi;
6671 : : struct i40e_vmdq_info *vmdq_info;
6672 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6673 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6674 : :
6675 : : /*
6676 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6677 : : * avoid race condition in VSI creation/destroy.
6678 : : */
6679 : 0 : i40e_pf_disable_irq0(hw);
6680 : :
6681 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6682 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6683 : 0 : return -ENOTSUP;
6684 : : }
6685 : :
6686 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6687 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6688 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6689 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6690 : : pf->max_nb_vmdq_vsi);
6691 : 0 : return -ENOTSUP;
6692 : : }
6693 : :
6694 [ # # ]: 0 : if (pf->vmdq != NULL) {
6695 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6696 : 0 : return 0;
6697 : : }
6698 : :
6699 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6700 : : sizeof(*vmdq_info) * conf_vsis, 0);
6701 : :
6702 [ # # ]: 0 : if (pf->vmdq == NULL) {
6703 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6704 : 0 : return -ENOMEM;
6705 : : }
6706 : :
6707 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6708 : :
6709 : : /* Create VMDQ VSI */
6710 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6711 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6712 : 0 : vmdq_conf->enable_loop_back);
6713 [ # # ]: 0 : if (vsi == NULL) {
6714 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6715 : : err = -1;
6716 : 0 : goto err_vsi_setup;
6717 : : }
6718 : 0 : vmdq_info = &pf->vmdq[i];
6719 : 0 : vmdq_info->pf = pf;
6720 : 0 : vmdq_info->vsi = vsi;
6721 : : }
6722 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6723 : :
6724 : : /* Configure Vlan */
6725 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6726 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6727 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6728 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & RTE_BIT64(j)) {
6729 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6730 : : vmdq_conf->pool_map[i].vlan_id, j);
6731 : :
6732 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6733 : 0 : vmdq_conf->pool_map[i].vlan_id);
6734 [ # # ]: 0 : if (err) {
6735 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6736 : : err = -1;
6737 : 0 : goto err_vsi_setup;
6738 : : }
6739 : : }
6740 : : }
6741 : : }
6742 : :
6743 : 0 : i40e_pf_enable_irq0(hw);
6744 : :
6745 : 0 : return 0;
6746 : :
6747 : : err_vsi_setup:
6748 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6749 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6750 : : break;
6751 : : else
6752 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6753 : :
6754 : 0 : rte_free(pf->vmdq);
6755 : 0 : pf->vmdq = NULL;
6756 : 0 : i40e_pf_enable_irq0(hw);
6757 : 0 : return err;
6758 : : }
6759 : :
6760 : : static void
6761 : : i40e_stat_update_32(struct i40e_hw *hw,
6762 : : uint32_t reg,
6763 : : bool offset_loaded,
6764 : : uint64_t *offset,
6765 : : uint64_t *stat)
6766 : : {
6767 : : uint64_t new_data;
6768 : :
6769 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6770 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6771 : 0 : *offset = new_data;
6772 : :
6773 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6774 : 0 : *stat = (uint64_t)(new_data - *offset);
6775 : : else
6776 : 0 : *stat = (uint64_t)((new_data +
6777 : : RTE_BIT64(I40E_32_BIT_WIDTH)) - *offset);
6778 : : }
6779 : :
6780 : : static void
6781 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6782 : : uint32_t hireg,
6783 : : uint32_t loreg,
6784 : : bool offset_loaded,
6785 : : uint64_t *offset,
6786 : : uint64_t *stat)
6787 : : {
6788 : : uint64_t new_data;
6789 : :
6790 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6791 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6792 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6793 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6794 : : } else {
6795 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6796 : : }
6797 : :
6798 [ # # ]: 0 : if (!offset_loaded)
6799 : 0 : *offset = new_data;
6800 : :
6801 [ # # ]: 0 : if (new_data >= *offset)
6802 : 0 : *stat = new_data - *offset;
6803 : : else
6804 : 0 : *stat = (uint64_t)((new_data +
6805 : : RTE_BIT64(I40E_48_BIT_WIDTH)) - *offset);
6806 : :
6807 : 0 : *stat &= I40E_48_BIT_MASK;
6808 : 0 : }
6809 : :
6810 : : /* Disable IRQ0 */
6811 : : void
6812 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6813 : : {
6814 : : /* Disable all interrupt types */
6815 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6816 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6817 : 0 : I40E_WRITE_FLUSH(hw);
6818 : 0 : }
6819 : :
6820 : : /* Enable IRQ0 */
6821 : : void
6822 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6823 : : {
6824 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6825 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6826 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6827 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6828 : 0 : I40E_WRITE_FLUSH(hw);
6829 : 0 : }
6830 : :
6831 : : static void
6832 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6833 : : {
6834 : : /* read pending request and disable first */
6835 : 0 : i40e_pf_disable_irq0(hw);
6836 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6837 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6838 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6839 : :
6840 : : if (no_queue)
6841 : : /* Link no queues with irq0 */
6842 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6843 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6844 : : }
6845 : :
6846 : : static void
6847 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6848 : : {
6849 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6850 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6851 : : int i;
6852 : : uint16_t abs_vf_id;
6853 : : uint32_t index, offset, val;
6854 : :
6855 [ # # ]: 0 : if (!pf->vfs)
6856 : : return;
6857 : : /**
6858 : : * Try to find which VF trigger a reset, use absolute VF id to access
6859 : : * since the reg is global register.
6860 : : */
6861 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6862 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6863 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6864 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6865 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6866 : : /* VFR event occurred */
6867 [ # # ]: 0 : if (val & (0x1 << offset)) {
6868 : : int ret;
6869 : :
6870 : : /* Clear the event first */
6871 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6872 : : (0x1 << offset));
6873 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6874 : : /**
6875 : : * Only notify a VF reset event occurred,
6876 : : * don't trigger another SW reset
6877 : : */
6878 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6879 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6880 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6881 : : }
6882 : : }
6883 : : }
6884 : :
6885 : : static void
6886 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6887 : : {
6888 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6889 : : int i;
6890 : :
6891 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6892 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6893 : 0 : }
6894 : :
6895 : : static void
6896 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6897 : : {
6898 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6899 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6900 : : struct i40e_arq_event_info info;
6901 : : uint16_t pending, opcode;
6902 : 0 : uint8_t msg_buf[I40E_AQ_BUF_SZ] = {0};
6903 : : int ret;
6904 : :
6905 : 0 : info.buf_len = sizeof(msg_buf);
6906 : 0 : info.msg_buf = msg_buf;
6907 : :
6908 : 0 : pending = 1;
6909 [ # # ]: 0 : while (pending) {
6910 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6911 : :
6912 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6913 : 0 : PMD_DRV_LOG(INFO,
6914 : : "Failed to read msg from AdminQ, aq_err: %u",
6915 : : hw->aq.asq_last_status);
6916 : 0 : break;
6917 : : }
6918 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6919 : :
6920 [ # # # ]: 0 : switch (opcode) {
6921 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6922 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6923 : 0 : i40e_pf_host_handle_vf_msg(dev,
6924 : 0 : rte_le_to_cpu_16(info.desc.retval),
6925 : : rte_le_to_cpu_32(info.desc.cookie_high),
6926 : : rte_le_to_cpu_32(info.desc.cookie_low),
6927 : 0 : info.msg_buf,
6928 : 0 : info.msg_len);
6929 : 0 : break;
6930 : 0 : case i40e_aqc_opc_get_link_status:
6931 : 0 : ret = i40e_dev_link_update(dev, 0);
6932 : : /* Some devices require MAC config to be applied when the link comes up. */
6933 [ # # ]: 0 : if (!ret) {
6934 [ # # # # ]: 0 : if (pf->mac_config_on_link_up && dev->data->dev_link.link_status) {
6935 : : uint16_t max_frame_size;
6936 : :
6937 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
6938 : : dev->data->mtu + I40E_ETH_OVERHEAD :
6939 : : I40E_FRAME_SIZE_MAX;
6940 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE,
6941 : : false, 0, NULL);
6942 : 0 : pf->mac_config_on_link_up = false;
6943 : : }
6944 : 0 : rte_eth_dev_callback_process(dev,
6945 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6946 : : }
6947 : : break;
6948 : 0 : default:
6949 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6950 : : opcode);
6951 : 0 : break;
6952 : : }
6953 : : }
6954 : 0 : }
6955 : :
6956 : : static void
6957 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6958 : : {
6959 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6960 : : #define I40E_MDD_CLEAR16 0xFFFF
6961 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6962 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6963 : : bool mdd_detected = false;
6964 : : struct i40e_pf_vf *vf;
6965 : : uint32_t reg;
6966 : : int i;
6967 : :
6968 : : /* find what triggered the MDD event */
6969 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6970 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6971 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6972 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6973 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6974 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6975 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6976 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6977 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6978 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6979 : 0 : hw->func_caps.base_queue;
6980 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6981 : : "queue %d PF number 0x%02x VF number 0x%02x device %s",
6982 : : event, queue, pf_num, vf_num, dev->data->name);
6983 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6984 : : mdd_detected = true;
6985 : : }
6986 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6987 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6988 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6989 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6990 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6991 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6992 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6993 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6994 : 0 : hw->func_caps.base_queue;
6995 : :
6996 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6997 : : "queue %d of function 0x%02x device %s",
6998 : : event, queue, func, dev->data->name);
6999 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
7000 : : mdd_detected = true;
7001 : : }
7002 : :
7003 [ # # ]: 0 : if (mdd_detected) {
7004 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
7005 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7006 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
7007 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF");
7008 : : }
7009 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
7010 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7011 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
7012 : : I40E_MDD_CLEAR16);
7013 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF");
7014 : : }
7015 : : }
7016 : :
7017 : : /* see if one of the VFs needs its hand slapped */
7018 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
7019 : 0 : vf = &pf->vfs[i];
7020 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
7021 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7022 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
7023 : : I40E_MDD_CLEAR16);
7024 : 0 : vf->num_mdd_events++;
7025 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
7026 : : PRIu64 "times",
7027 : : i, vf->num_mdd_events);
7028 : : }
7029 : :
7030 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
7031 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7032 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
7033 : : I40E_MDD_CLEAR16);
7034 : 0 : vf->num_mdd_events++;
7035 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
7036 : : PRIu64 "times",
7037 : : i, vf->num_mdd_events);
7038 : : }
7039 : : }
7040 : 0 : }
7041 : :
7042 : : /**
7043 : : * Interrupt handler triggered by NIC for handling
7044 : : * specific interrupt.
7045 : : *
7046 : : * @param handle
7047 : : * Pointer to interrupt handle.
7048 : : * @param param
7049 : : * The address of parameter (struct rte_eth_dev *) registered before.
7050 : : *
7051 : : * @return
7052 : : * void
7053 : : */
7054 : : static void
7055 : 0 : i40e_dev_interrupt_handler(void *param)
7056 : : {
7057 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7058 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7059 : : uint32_t icr0;
7060 : :
7061 : : /* Disable interrupt */
7062 : 0 : i40e_pf_disable_irq0(hw);
7063 : :
7064 : : /* read out interrupt causes */
7065 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7066 : :
7067 : : /* No interrupt event indicated */
7068 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
7069 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
7070 : 0 : goto done;
7071 : : }
7072 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7073 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7074 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7075 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7076 : 0 : i40e_handle_mdd_event(dev);
7077 : : }
7078 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7079 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7080 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7081 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7082 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7083 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7084 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7085 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7086 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7087 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7088 : :
7089 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7090 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7091 : 0 : i40e_dev_handle_vfr_event(dev);
7092 : : }
7093 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7094 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7095 : 0 : i40e_dev_handle_aq_msg(dev);
7096 : : }
7097 : :
7098 : 0 : done:
7099 : : /* Enable interrupt */
7100 : 0 : i40e_pf_enable_irq0(hw);
7101 : 0 : }
7102 : :
7103 : : static void
7104 : 0 : i40e_dev_alarm_handler(void *param)
7105 : : {
7106 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7107 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7108 : : uint32_t icr0;
7109 : :
7110 : : /* Disable interrupt */
7111 : 0 : i40e_pf_disable_irq0(hw);
7112 : :
7113 : : /* read out interrupt causes */
7114 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7115 : :
7116 : : /* No interrupt event indicated */
7117 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
7118 : 0 : goto done;
7119 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7120 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7121 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7122 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7123 : 0 : i40e_handle_mdd_event(dev);
7124 : : }
7125 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7126 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7127 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7128 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7129 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7130 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7131 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7132 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7133 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7134 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7135 : :
7136 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7137 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7138 : 0 : i40e_dev_handle_vfr_event(dev);
7139 : : }
7140 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7141 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7142 : 0 : i40e_dev_handle_aq_msg(dev);
7143 : : }
7144 : :
7145 : 0 : done:
7146 : : /* Enable interrupt */
7147 : 0 : i40e_pf_enable_irq0(hw);
7148 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7149 : : i40e_dev_alarm_handler, dev);
7150 : 0 : }
7151 : :
7152 : : int
7153 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7154 : : struct i40e_macvlan_filter *filter,
7155 : : int total)
7156 : : {
7157 : : int ele_num, ele_buff_size;
7158 : : int num, actual_num, i;
7159 : : uint16_t flags;
7160 : : int ret = I40E_SUCCESS;
7161 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7162 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7163 : : struct i40e_aqc_add_macvlan_element_data *req_list =
7164 : : (struct i40e_aqc_add_macvlan_element_data *)aq_buff;
7165 : :
7166 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7167 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7168 : 0 : return I40E_ERR_NO_MEMORY;
7169 : : }
7170 : :
7171 [ # # ]: 0 : if (filter == NULL || total == 0)
7172 : : return I40E_ERR_PARAM;
7173 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7174 : : ele_buff_size = hw->aq.asq_buf_size;
7175 : :
7176 : : num = 0;
7177 : : do {
7178 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7179 : 0 : memset(req_list, 0, ele_buff_size);
7180 : :
7181 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7182 : 0 : memcpy(req_list[i].mac_addr,
7183 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7184 : 0 : req_list[i].vlan_tag =
7185 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7186 : :
7187 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7188 : : case I40E_MAC_PERFECT_MATCH:
7189 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7190 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7191 : : break;
7192 : : case I40E_MACVLAN_PERFECT_MATCH:
7193 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7194 : : break;
7195 : : case I40E_MAC_HASH_MATCH:
7196 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7197 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7198 : : break;
7199 : : case I40E_MACVLAN_HASH_MATCH:
7200 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7201 : : break;
7202 : 0 : default:
7203 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7204 : 0 : return I40E_ERR_PARAM;
7205 : : }
7206 : :
7207 : 0 : req_list[i].queue_number = 0;
7208 : :
7209 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7210 : : }
7211 : :
7212 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7213 : : actual_num, NULL);
7214 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7215 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7216 : 0 : return ret;
7217 : : }
7218 : 0 : num += actual_num;
7219 [ # # ]: 0 : } while (num < total);
7220 : : return I40E_SUCCESS;
7221 : : }
7222 : :
7223 : : int
7224 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7225 : : struct i40e_macvlan_filter *filter,
7226 : : int total)
7227 : : {
7228 : : int ele_num, ele_buff_size;
7229 : : int num, actual_num, i;
7230 : : uint16_t flags;
7231 : : int ret = I40E_SUCCESS;
7232 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7233 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7234 : : struct i40e_aqc_remove_macvlan_element_data *req_list =
7235 : : (struct i40e_aqc_remove_macvlan_element_data *)aq_buff;
7236 : : enum i40e_admin_queue_err aq_status;
7237 : :
7238 [ # # ]: 0 : if (filter == NULL || total == 0)
7239 : : return I40E_ERR_PARAM;
7240 : :
7241 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7242 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7243 : 0 : return I40E_ERR_NO_MEMORY;
7244 : : }
7245 : :
7246 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7247 : : ele_buff_size = hw->aq.asq_buf_size;
7248 : :
7249 : : num = 0;
7250 : : do {
7251 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7252 : 0 : memset(req_list, 0, ele_buff_size);
7253 : :
7254 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7255 : 0 : memcpy(req_list[i].mac_addr,
7256 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7257 : 0 : req_list[i].vlan_tag =
7258 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7259 : :
7260 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7261 : : case I40E_MAC_PERFECT_MATCH:
7262 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7263 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7264 : : break;
7265 : : case I40E_MACVLAN_PERFECT_MATCH:
7266 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7267 : : break;
7268 : : case I40E_MAC_HASH_MATCH:
7269 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7270 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7271 : : break;
7272 : : case I40E_MACVLAN_HASH_MATCH:
7273 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7274 : : break;
7275 : 0 : default:
7276 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7277 : 0 : return I40E_ERR_PARAM;
7278 : : }
7279 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7280 : : }
7281 : :
7282 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7283 : : actual_num, NULL, &aq_status);
7284 : :
7285 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7286 : : /* Do not report as an error when firmware returns ENOENT */
7287 [ # # ]: 0 : if (aq_status != I40E_AQ_RC_ENOENT) {
7288 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7289 : 0 : return ret;
7290 : : }
7291 : : }
7292 : 0 : num += actual_num;
7293 [ # # ]: 0 : } while (num < total);
7294 : :
7295 : : return I40E_SUCCESS;
7296 : : }
7297 : :
7298 : : /* Find out specific MAC filter */
7299 : : static struct i40e_mac_filter *
7300 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7301 : : struct rte_ether_addr *macaddr)
7302 : : {
7303 : : struct i40e_mac_filter *f;
7304 : :
7305 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7306 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7307 : : return f;
7308 : : }
7309 : :
7310 : : return NULL;
7311 : : }
7312 : :
7313 : : static bool
7314 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7315 : : uint16_t vlan_id)
7316 : : {
7317 : : uint32_t vid_idx, vid_bit;
7318 : :
7319 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7320 : : return 0;
7321 : :
7322 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7323 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7324 : :
7325 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7326 : : return 1;
7327 : : else
7328 : : return 0;
7329 : : }
7330 : :
7331 : : static void
7332 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7333 : : uint16_t vlan_id, bool on)
7334 : : {
7335 : : uint32_t vid_idx, vid_bit;
7336 : :
7337 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7338 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7339 : :
7340 [ # # ]: 0 : if (on)
7341 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7342 : : else
7343 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7344 : : }
7345 : :
7346 : : void
7347 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7348 : : uint16_t vlan_id, bool on)
7349 : : {
7350 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7351 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7352 : : int ret;
7353 : :
7354 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7355 : 0 : return;
7356 : :
7357 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7358 : :
7359 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7360 : : return;
7361 : :
7362 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7363 : :
7364 [ # # ]: 0 : if (on) {
7365 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7366 : : &vlan_data, 1, NULL);
7367 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7368 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7369 : : } else {
7370 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7371 : : &vlan_data, 1, NULL);
7372 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7373 : 0 : PMD_DRV_LOG(ERR,
7374 : : "Failed to remove vlan filter");
7375 : : }
7376 : : }
7377 : :
7378 : : /**
7379 : : * Find all vlan options for specific mac addr,
7380 : : * return with actual vlan found.
7381 : : */
7382 : : int
7383 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7384 : : struct i40e_macvlan_filter *mv_f,
7385 : : int num, struct rte_ether_addr *addr)
7386 : : {
7387 : : int i;
7388 : : uint32_t j, k;
7389 : :
7390 : : /**
7391 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7392 : : * although the code looks complex.
7393 : : */
7394 [ # # ]: 0 : if (num < vsi->vlan_num)
7395 : : return I40E_ERR_PARAM;
7396 : :
7397 : : i = 0;
7398 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7399 [ # # ]: 0 : if (vsi->vfta[j]) {
7400 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7401 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7402 [ # # ]: 0 : if (i > num - 1) {
7403 : 0 : PMD_DRV_LOG(ERR,
7404 : : "vlan number doesn't match");
7405 : 0 : return I40E_ERR_PARAM;
7406 : : }
7407 : 0 : memcpy(&mv_f[i].macaddr,
7408 : : addr, ETH_ADDR_LEN);
7409 : 0 : mv_f[i].vlan_id =
7410 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7411 : 0 : i++;
7412 : : }
7413 : : }
7414 : : }
7415 : : }
7416 : : return I40E_SUCCESS;
7417 : : }
7418 : :
7419 : : static inline int
7420 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7421 : : struct i40e_macvlan_filter *mv_f,
7422 : : int num,
7423 : : uint16_t vlan)
7424 : : {
7425 : : int i = 0;
7426 : : struct i40e_mac_filter *f;
7427 : :
7428 [ # # ]: 0 : if (num < vsi->mac_num)
7429 : : return I40E_ERR_PARAM;
7430 : :
7431 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7432 [ # # ]: 0 : if (i > num - 1) {
7433 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7434 : 0 : return I40E_ERR_PARAM;
7435 : : }
7436 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7437 : : ETH_ADDR_LEN);
7438 : 0 : mv_f[i].vlan_id = vlan;
7439 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7440 : 0 : i++;
7441 : : }
7442 : :
7443 : : return I40E_SUCCESS;
7444 : : }
7445 : :
7446 : : static int
7447 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7448 : : {
7449 : : int i, j, num;
7450 : : struct i40e_mac_filter *f;
7451 : : struct i40e_macvlan_filter *mv_f;
7452 : : int ret = I40E_SUCCESS;
7453 : :
7454 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7455 : : return I40E_ERR_PARAM;
7456 : :
7457 : : /* Case that no vlan is set */
7458 [ # # ]: 0 : if (vsi->vlan_num == 0)
7459 : 0 : num = vsi->mac_num;
7460 : : else
7461 : 0 : num = vsi->mac_num * vsi->vlan_num;
7462 : :
7463 : 0 : mv_f = calloc(num, sizeof(*mv_f));
7464 [ # # ]: 0 : if (mv_f == NULL) {
7465 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7466 : 0 : return I40E_ERR_NO_MEMORY;
7467 : : }
7468 : :
7469 : : i = 0;
7470 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7471 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7472 : 0 : memcpy(&mv_f[i].macaddr,
7473 : 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7474 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7475 : 0 : mv_f[i].vlan_id = 0;
7476 : 0 : i++;
7477 : : }
7478 : : } else {
7479 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7480 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7481 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7482 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7483 : 0 : goto DONE;
7484 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7485 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7486 : : i += vsi->vlan_num;
7487 : : }
7488 : : }
7489 : :
7490 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7491 : 0 : DONE:
7492 : 0 : free(mv_f);
7493 : :
7494 : 0 : return ret;
7495 : : }
7496 : :
7497 : : int
7498 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7499 : : {
7500 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7501 : : int mac_num;
7502 : : int ret = I40E_SUCCESS;
7503 : :
7504 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7505 : : return I40E_ERR_PARAM;
7506 : :
7507 : : /* If it's already set, just return */
7508 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7509 : : return I40E_SUCCESS;
7510 : :
7511 : 0 : mac_num = vsi->mac_num;
7512 : :
7513 [ # # ]: 0 : if (mac_num == 0) {
7514 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7515 : 0 : return I40E_ERR_PARAM;
7516 : : }
7517 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7518 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7519 : 0 : return I40E_ERR_PARAM;
7520 : : }
7521 : :
7522 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7523 : :
7524 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7525 : : return ret;
7526 : :
7527 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7528 : :
7529 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7530 : : return ret;
7531 : :
7532 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7533 : :
7534 : 0 : vsi->vlan_num++;
7535 : 0 : return I40E_SUCCESS;
7536 : : }
7537 : :
7538 : : int
7539 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7540 : : {
7541 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7542 : : int mac_num;
7543 : : int ret = I40E_SUCCESS;
7544 : :
7545 : : /**
7546 : : * Vlan 0 is the generic filter for untagged packets
7547 : : * and can't be removed.
7548 : : */
7549 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7550 : : return I40E_ERR_PARAM;
7551 : :
7552 : : /* If can't find it, just return */
7553 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7554 : : return I40E_ERR_PARAM;
7555 : :
7556 : 0 : mac_num = vsi->mac_num;
7557 : :
7558 [ # # ]: 0 : if (mac_num == 0) {
7559 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7560 : 0 : return I40E_ERR_PARAM;
7561 : : }
7562 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7563 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7564 : 0 : return I40E_ERR_PARAM;
7565 : : }
7566 : :
7567 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7568 : :
7569 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7570 : : return ret;
7571 : :
7572 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7573 : :
7574 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7575 : : return ret;
7576 : :
7577 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7578 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7579 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7580 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7581 : : return ret;
7582 : :
7583 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7584 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7585 : : return ret;
7586 : : }
7587 : :
7588 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7589 : :
7590 : 0 : vsi->vlan_num--;
7591 : 0 : return I40E_SUCCESS;
7592 : : }
7593 : :
7594 : : int
7595 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7596 : : {
7597 : : struct i40e_mac_filter *f;
7598 : : struct i40e_macvlan_filter *mv_f;
7599 : : int i, vlan_num = 0;
7600 : : int ret = I40E_SUCCESS;
7601 : :
7602 : : /* If it's add and we've config it, return */
7603 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7604 [ # # ]: 0 : if (f != NULL)
7605 : : return I40E_SUCCESS;
7606 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7607 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7608 : :
7609 : : /**
7610 : : * If vlan_num is 0, that's the first time to add mac,
7611 : : * set mask for vlan_id 0.
7612 : : */
7613 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7614 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7615 : 0 : vsi->vlan_num = 1;
7616 : : }
7617 : 0 : vlan_num = vsi->vlan_num;
7618 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7619 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7620 : : vlan_num = 1;
7621 : :
7622 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7623 [ # # ]: 0 : if (mv_f == NULL) {
7624 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7625 : 0 : return I40E_ERR_NO_MEMORY;
7626 : : }
7627 : :
7628 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7629 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7630 : 0 : memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7631 : : ETH_ADDR_LEN);
7632 : : }
7633 : :
7634 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7635 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7636 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7637 : : &mac_filter->mac_addr);
7638 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7639 : 0 : goto DONE;
7640 : : }
7641 : :
7642 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7643 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7644 : 0 : goto DONE;
7645 : :
7646 : : /* Add the mac addr into mac list */
7647 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7648 [ # # ]: 0 : if (f == NULL) {
7649 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7650 : : ret = I40E_ERR_NO_MEMORY;
7651 : 0 : goto DONE;
7652 : : }
7653 : 0 : memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7654 : : ETH_ADDR_LEN);
7655 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7656 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7657 : 0 : vsi->mac_num++;
7658 : :
7659 : : ret = I40E_SUCCESS;
7660 : 0 : DONE:
7661 : 0 : free(mv_f);
7662 : :
7663 : 0 : return ret;
7664 : : }
7665 : :
7666 : : int
7667 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7668 : : {
7669 : : struct i40e_mac_filter *f;
7670 : : struct i40e_macvlan_filter *mv_f;
7671 : : int i, vlan_num;
7672 : : enum i40e_mac_filter_type filter_type;
7673 : : int ret = I40E_SUCCESS;
7674 : :
7675 : : /* Can't find it, return an error */
7676 : : f = i40e_find_mac_filter(vsi, addr);
7677 [ # # ]: 0 : if (f == NULL)
7678 : : return I40E_ERR_PARAM;
7679 : :
7680 : 0 : vlan_num = vsi->vlan_num;
7681 : 0 : filter_type = f->mac_info.filter_type;
7682 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7683 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7684 [ # # ]: 0 : if (vlan_num == 0) {
7685 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7686 : 0 : return I40E_ERR_PARAM;
7687 : : }
7688 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7689 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7690 : : vlan_num = 1;
7691 : :
7692 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7693 [ # # ]: 0 : if (mv_f == NULL) {
7694 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7695 : 0 : return I40E_ERR_NO_MEMORY;
7696 : : }
7697 : :
7698 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7699 : 0 : mv_f[i].filter_type = filter_type;
7700 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7701 : : ETH_ADDR_LEN);
7702 : : }
7703 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7704 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7705 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7706 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7707 : 0 : goto DONE;
7708 : : }
7709 : :
7710 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7711 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7712 : 0 : goto DONE;
7713 : :
7714 : : /* Remove the mac addr into mac list */
7715 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7716 : 0 : rte_free(f);
7717 : 0 : vsi->mac_num--;
7718 : :
7719 : : ret = I40E_SUCCESS;
7720 : 0 : DONE:
7721 : 0 : free(mv_f);
7722 : 0 : return ret;
7723 : : }
7724 : :
7725 : : /* Configure hash enable flags for RSS */
7726 : : uint64_t
7727 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7728 : : {
7729 : : uint64_t hena = 0;
7730 : : int i;
7731 : :
7732 [ # # ]: 0 : if (!flags)
7733 : : return hena;
7734 : :
7735 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7736 [ # # ]: 0 : if (flags & RTE_BIT64(i))
7737 : 0 : hena |= adapter->pctypes_tbl[i];
7738 : : }
7739 : :
7740 : : return hena;
7741 : : }
7742 : :
7743 : : /* Parse the hash enable flags */
7744 : : uint64_t
7745 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7746 : : {
7747 : : uint64_t rss_hf = 0;
7748 : :
7749 [ # # ]: 0 : if (!flags)
7750 : : return rss_hf;
7751 : : int i;
7752 : :
7753 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7754 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7755 : 0 : rss_hf |= RTE_BIT64(i);
7756 : : }
7757 : : return rss_hf;
7758 : : }
7759 : :
7760 : : /* Disable RSS */
7761 : : void
7762 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7763 : : {
7764 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7765 : :
7766 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7767 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7768 : 0 : I40E_WRITE_FLUSH(hw);
7769 : 0 : }
7770 : :
7771 : : int
7772 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7773 : : {
7774 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7775 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7776 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7777 : : I40E_VFQF_HKEY_MAX_INDEX :
7778 : : I40E_PFQF_HKEY_MAX_INDEX;
7779 : :
7780 [ # # ]: 0 : if (!key || key_len == 0) {
7781 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7782 : 0 : return 0;
7783 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7784 : : sizeof(uint32_t)) {
7785 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7786 : 0 : return -EINVAL;
7787 : : }
7788 : :
7789 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7790 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7791 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7792 : : enum i40e_status_code status =
7793 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7794 : :
7795 [ # # ]: 0 : if (status) {
7796 : 0 : PMD_DRV_LOG(ERR,
7797 : : "Failed to configure RSS key via AQ, error status: %d",
7798 : : status);
7799 : 0 : return -EIO;
7800 : : }
7801 : : } else {
7802 : : uint32_t *hash_key = (uint32_t *)key;
7803 : : uint16_t i;
7804 : :
7805 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7806 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7807 : 0 : I40E_WRITE_REG(
7808 : : hw,
7809 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7810 : : hash_key[i]);
7811 : :
7812 : : } else {
7813 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7814 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7815 : : hash_key[i]);
7816 : : }
7817 : 0 : I40E_WRITE_FLUSH(hw);
7818 : : }
7819 : :
7820 : : return 0;
7821 : : }
7822 : :
7823 : : static int
7824 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7825 : : {
7826 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7827 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7828 : : uint32_t reg;
7829 : : int ret;
7830 : :
7831 [ # # ]: 0 : if (!key || !key_len)
7832 : : return 0;
7833 : :
7834 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7835 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7836 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7837 [ # # ]: 0 : if (ret) {
7838 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7839 : 0 : return ret;
7840 : : }
7841 : : } else {
7842 : : uint32_t *key_dw = (uint32_t *)key;
7843 : : uint16_t i;
7844 : :
7845 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7846 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7847 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7848 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7849 : : }
7850 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7851 : : sizeof(uint32_t);
7852 : : } else {
7853 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7854 : 0 : reg = I40E_PFQF_HKEY(i);
7855 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7856 : : }
7857 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7858 : : sizeof(uint32_t);
7859 : : }
7860 : : }
7861 : : return 0;
7862 : : }
7863 : :
7864 : : static int
7865 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7866 : : {
7867 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7868 : : uint64_t hena;
7869 : : int ret;
7870 : :
7871 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7872 : 0 : rss_conf->rss_key_len);
7873 [ # # ]: 0 : if (ret)
7874 : : return ret;
7875 : :
7876 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7877 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7878 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7879 : 0 : I40E_WRITE_FLUSH(hw);
7880 : :
7881 : 0 : return 0;
7882 : : }
7883 : :
7884 : : static int
7885 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7886 : : struct rte_eth_rss_conf *rss_conf)
7887 : : {
7888 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7889 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7890 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7891 : : uint64_t hena;
7892 : :
7893 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7894 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7895 : :
7896 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7897 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7898 : : return -EINVAL;
7899 : 0 : return 0; /* Nothing to do */
7900 : : }
7901 : : /* RSS enabled */
7902 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7903 : : return -EINVAL;
7904 : :
7905 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7906 : : }
7907 : :
7908 : : static int
7909 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7910 : : struct rte_eth_rss_conf *rss_conf)
7911 : : {
7912 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7913 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7914 : : uint64_t hena;
7915 : : int ret;
7916 : :
7917 [ # # ]: 0 : if (!rss_conf)
7918 : : return -EINVAL;
7919 : :
7920 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7921 : : &rss_conf->rss_key_len);
7922 [ # # ]: 0 : if (ret)
7923 : : return ret;
7924 : :
7925 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7926 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7927 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7928 : :
7929 : 0 : return 0;
7930 : : }
7931 : :
7932 : : static int
7933 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7934 : : {
7935 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7936 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7937 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7938 : 0 : break;
7939 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7940 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7941 : 0 : break;
7942 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7943 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7944 : 0 : break;
7945 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7946 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7947 : 0 : break;
7948 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7949 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7950 : 0 : break;
7951 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7952 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7953 : 0 : break;
7954 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7955 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7956 : 0 : break;
7957 : 0 : default:
7958 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7959 : 0 : return -EINVAL;
7960 : : }
7961 : :
7962 : : return 0;
7963 : : }
7964 : :
7965 : : /* Convert tunnel filter structure */
7966 : : static int
7967 [ # # ]: 0 : i40e_tunnel_filter_convert(
7968 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7969 : : struct i40e_tunnel_filter *tunnel_filter)
7970 : : {
7971 : : rte_ether_addr_copy((struct rte_ether_addr *)
7972 : : &cld_filter->element.outer_mac,
7973 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7974 : : rte_ether_addr_copy((struct rte_ether_addr *)
7975 : : &cld_filter->element.inner_mac,
7976 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7977 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7978 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7979 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7980 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7981 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7982 : : else
7983 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7984 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7985 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7986 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7987 : 0 : memcpy(tunnel_filter->input.general_fields,
7988 : 0 : cld_filter->general_fields,
7989 : : sizeof(cld_filter->general_fields));
7990 : :
7991 : 0 : return 0;
7992 : : }
7993 : :
7994 : : /* Check if there exists the tunnel filter */
7995 : : struct i40e_tunnel_filter *
7996 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7997 : : const struct i40e_tunnel_filter_input *input)
7998 : : {
7999 : : int ret;
8000 : :
8001 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
8002 [ # # ]: 0 : if (ret < 0)
8003 : : return NULL;
8004 : :
8005 : 0 : return tunnel_rule->hash_map[ret];
8006 : : }
8007 : :
8008 : : /* Add a tunnel filter into the SW list */
8009 : : static int
8010 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
8011 : : struct i40e_tunnel_filter *tunnel_filter)
8012 : : {
8013 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8014 : : int ret;
8015 : :
8016 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
8017 [ # # ]: 0 : if (ret < 0) {
8018 : 0 : PMD_DRV_LOG(ERR,
8019 : : "Failed to insert tunnel filter to hash table %d!",
8020 : : ret);
8021 : 0 : return ret;
8022 : : }
8023 : 0 : rule->hash_map[ret] = tunnel_filter;
8024 : :
8025 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
8026 : :
8027 : 0 : return 0;
8028 : : }
8029 : :
8030 : : /* Delete a tunnel filter from the SW list */
8031 : : int
8032 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
8033 : : struct i40e_tunnel_filter_input *input)
8034 : : {
8035 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8036 : : struct i40e_tunnel_filter *tunnel_filter;
8037 : : int ret;
8038 : :
8039 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
8040 [ # # ]: 0 : if (ret < 0) {
8041 : 0 : PMD_DRV_LOG(ERR,
8042 : : "Failed to delete tunnel filter to hash table %d!",
8043 : : ret);
8044 : 0 : return ret;
8045 : : }
8046 : 0 : tunnel_filter = rule->hash_map[ret];
8047 : 0 : rule->hash_map[ret] = NULL;
8048 : :
8049 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
8050 : 0 : rte_free(tunnel_filter);
8051 : :
8052 : 0 : return 0;
8053 : : }
8054 : :
8055 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8056 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8057 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
8058 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8059 : : #define I40E_TR_GRE_KEY_MASK 0x400
8060 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8061 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8062 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
8063 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
8064 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
8065 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
8066 : : #define I40E_TR_L4_TYPE_TCP 0x2
8067 : : #define I40E_TR_L4_TYPE_UDP 0x4
8068 : : #define I40E_TR_L4_TYPE_SCTP 0x8
8069 : :
8070 : : static enum
8071 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8072 : : {
8073 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8074 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8075 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8076 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8077 : : enum i40e_status_code status = I40E_SUCCESS;
8078 : :
8079 [ # # ]: 0 : if (pf->support_multi_driver) {
8080 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8081 : 0 : return I40E_NOT_SUPPORTED;
8082 : : }
8083 : :
8084 : : memset(&filter_replace, 0,
8085 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8086 : : memset(&filter_replace_buf, 0,
8087 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8088 : :
8089 : : /* create L1 filter */
8090 : 0 : filter_replace.old_filter_type =
8091 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8092 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8093 : : filter_replace.tr_bit = 0;
8094 : :
8095 : : /* Prepare the buffer, 3 entries */
8096 : : filter_replace_buf.data[0] =
8097 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8098 : 0 : filter_replace_buf.data[0] |=
8099 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8100 : 0 : filter_replace_buf.data[2] = 0xFF;
8101 : 0 : filter_replace_buf.data[3] = 0xFF;
8102 : : filter_replace_buf.data[4] =
8103 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8104 : 0 : filter_replace_buf.data[4] |=
8105 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8106 : 0 : filter_replace_buf.data[7] = 0xF0;
8107 : : filter_replace_buf.data[8]
8108 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8109 : 0 : filter_replace_buf.data[8] |=
8110 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8111 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8112 : : I40E_TR_GENEVE_KEY_MASK |
8113 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8114 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8115 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8116 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
8117 : :
8118 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8119 : : &filter_replace_buf);
8120 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8121 [ # # ]: 0 : filter_replace.new_filter_type))
8122 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8123 : : " original: 0x%x, new: 0x%x",
8124 : : dev->device->name,
8125 : : filter_replace.old_filter_type,
8126 : : filter_replace.new_filter_type);
8127 : :
8128 : : return status;
8129 : : }
8130 : :
8131 : : static enum
8132 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8133 : : {
8134 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8135 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8136 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8137 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8138 : : enum i40e_status_code status = I40E_SUCCESS;
8139 : :
8140 [ # # ]: 0 : if (pf->support_multi_driver) {
8141 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8142 : 0 : return I40E_NOT_SUPPORTED;
8143 : : }
8144 : :
8145 : : /* For MPLSoUDP */
8146 : : memset(&filter_replace, 0,
8147 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8148 : : memset(&filter_replace_buf, 0,
8149 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8150 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8151 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8152 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8153 : 0 : filter_replace.new_filter_type =
8154 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8155 : : /* Prepare the buffer, 2 entries */
8156 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8157 : 0 : filter_replace_buf.data[0] |=
8158 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8159 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8160 : 0 : filter_replace_buf.data[4] |=
8161 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8162 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8163 : : &filter_replace_buf);
8164 [ # # ]: 0 : if (status < 0)
8165 : : return status;
8166 : 0 : if (filter_replace.old_filter_type !=
8167 [ # # ]: 0 : filter_replace.new_filter_type)
8168 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8169 : : " original: 0x%x, new: 0x%x",
8170 : : dev->device->name,
8171 : : filter_replace.old_filter_type,
8172 : : filter_replace.new_filter_type);
8173 : :
8174 : : /* For MPLSoGRE */
8175 : : memset(&filter_replace, 0,
8176 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8177 : : memset(&filter_replace_buf, 0,
8178 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8179 : :
8180 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8181 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8182 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8183 : 0 : filter_replace.new_filter_type =
8184 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8185 : : /* Prepare the buffer, 2 entries */
8186 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8187 : 0 : filter_replace_buf.data[0] |=
8188 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8189 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8190 : 0 : filter_replace_buf.data[4] |=
8191 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8192 : :
8193 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8194 : : &filter_replace_buf);
8195 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8196 [ # # ]: 0 : filter_replace.new_filter_type))
8197 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8198 : : " original: 0x%x, new: 0x%x",
8199 : : dev->device->name,
8200 : : filter_replace.old_filter_type,
8201 : : filter_replace.new_filter_type);
8202 : :
8203 : : return status;
8204 : : }
8205 : :
8206 : : static enum i40e_status_code
8207 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8208 : : {
8209 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8210 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8211 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8212 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8213 : : enum i40e_status_code status = I40E_SUCCESS;
8214 : :
8215 [ # # ]: 0 : if (pf->support_multi_driver) {
8216 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8217 : 0 : return I40E_NOT_SUPPORTED;
8218 : : }
8219 : :
8220 : : /* For GTP-C */
8221 : : memset(&filter_replace, 0,
8222 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8223 : : memset(&filter_replace_buf, 0,
8224 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8225 : : /* create L1 filter */
8226 : 0 : filter_replace.old_filter_type =
8227 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8228 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8229 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8230 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8231 : : /* Prepare the buffer, 2 entries */
8232 : : filter_replace_buf.data[0] =
8233 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8234 : 0 : filter_replace_buf.data[0] |=
8235 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8236 : 0 : filter_replace_buf.data[2] = 0xFF;
8237 : 0 : filter_replace_buf.data[3] = 0xFF;
8238 : : filter_replace_buf.data[4] =
8239 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8240 : 0 : filter_replace_buf.data[4] |=
8241 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8242 : 0 : filter_replace_buf.data[6] = 0xFF;
8243 : 0 : filter_replace_buf.data[7] = 0xFF;
8244 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8245 : : &filter_replace_buf);
8246 [ # # ]: 0 : if (status < 0)
8247 : : return status;
8248 : 0 : if (filter_replace.old_filter_type !=
8249 [ # # ]: 0 : filter_replace.new_filter_type)
8250 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8251 : : " original: 0x%x, new: 0x%x",
8252 : : dev->device->name,
8253 : : filter_replace.old_filter_type,
8254 : : filter_replace.new_filter_type);
8255 : :
8256 : : /* for GTP-U */
8257 : : memset(&filter_replace, 0,
8258 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8259 : : memset(&filter_replace_buf, 0,
8260 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8261 : : /* create L1 filter */
8262 : 0 : filter_replace.old_filter_type =
8263 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8264 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8265 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8266 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8267 : : /* Prepare the buffer, 2 entries */
8268 : : filter_replace_buf.data[0] =
8269 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8270 : 0 : filter_replace_buf.data[0] |=
8271 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8272 : 0 : filter_replace_buf.data[2] = 0xFF;
8273 : 0 : filter_replace_buf.data[3] = 0xFF;
8274 : : filter_replace_buf.data[4] =
8275 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8276 : 0 : filter_replace_buf.data[4] |=
8277 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8278 : 0 : filter_replace_buf.data[6] = 0xFF;
8279 : 0 : filter_replace_buf.data[7] = 0xFF;
8280 : :
8281 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8282 : : &filter_replace_buf);
8283 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8284 [ # # ]: 0 : filter_replace.new_filter_type))
8285 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8286 : : " original: 0x%x, new: 0x%x",
8287 : : dev->device->name,
8288 : : filter_replace.old_filter_type,
8289 : : filter_replace.new_filter_type);
8290 : :
8291 : : return status;
8292 : : }
8293 : :
8294 : : static enum
8295 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8296 : : {
8297 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8298 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8299 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8300 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8301 : : enum i40e_status_code status = I40E_SUCCESS;
8302 : :
8303 [ # # ]: 0 : if (pf->support_multi_driver) {
8304 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8305 : 0 : return I40E_NOT_SUPPORTED;
8306 : : }
8307 : :
8308 : : /* for GTP-C */
8309 : : memset(&filter_replace, 0,
8310 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8311 : : memset(&filter_replace_buf, 0,
8312 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8313 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8314 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8315 : 0 : filter_replace.new_filter_type =
8316 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8317 : : /* Prepare the buffer, 2 entries */
8318 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8319 : 0 : filter_replace_buf.data[0] |=
8320 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8321 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8322 : 0 : filter_replace_buf.data[4] |=
8323 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8324 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8325 : : &filter_replace_buf);
8326 [ # # ]: 0 : if (status < 0)
8327 : : return status;
8328 : 0 : if (filter_replace.old_filter_type !=
8329 [ # # ]: 0 : filter_replace.new_filter_type)
8330 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8331 : : " original: 0x%x, new: 0x%x",
8332 : : dev->device->name,
8333 : : filter_replace.old_filter_type,
8334 : : filter_replace.new_filter_type);
8335 : :
8336 : : /* for GTP-U */
8337 : : memset(&filter_replace, 0,
8338 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8339 : : memset(&filter_replace_buf, 0,
8340 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8341 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8342 : 0 : filter_replace.old_filter_type =
8343 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8344 : 0 : filter_replace.new_filter_type =
8345 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8346 : : /* Prepare the buffer, 2 entries */
8347 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8348 : 0 : filter_replace_buf.data[0] |=
8349 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8350 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8351 : 0 : filter_replace_buf.data[4] |=
8352 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8353 : :
8354 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8355 : : &filter_replace_buf);
8356 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8357 [ # # ]: 0 : filter_replace.new_filter_type))
8358 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8359 : : " original: 0x%x, new: 0x%x",
8360 : : dev->device->name,
8361 : : filter_replace.old_filter_type,
8362 : : filter_replace.new_filter_type);
8363 : :
8364 : : return status;
8365 : : }
8366 : :
8367 : : static enum i40e_status_code
8368 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8369 : : enum i40e_l4_port_type l4_port_type)
8370 : : {
8371 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8372 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8373 : : enum i40e_status_code status = I40E_SUCCESS;
8374 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8375 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8376 : :
8377 [ # # ]: 0 : if (pf->support_multi_driver) {
8378 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8379 : 0 : return I40E_NOT_SUPPORTED;
8380 : : }
8381 : :
8382 : : memset(&filter_replace, 0,
8383 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8384 : : memset(&filter_replace_buf, 0,
8385 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8386 : :
8387 : : /* create L1 filter */
8388 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8389 : 0 : filter_replace.old_filter_type =
8390 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8391 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8392 : 0 : filter_replace_buf.data[8] =
8393 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8394 : : } else {
8395 : 0 : filter_replace.old_filter_type =
8396 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8397 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8398 : 0 : filter_replace_buf.data[8] =
8399 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8400 : : }
8401 : :
8402 : : filter_replace.tr_bit = 0;
8403 : : /* Prepare the buffer, 3 entries */
8404 : : filter_replace_buf.data[0] =
8405 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8406 : 0 : filter_replace_buf.data[0] |=
8407 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8408 : : filter_replace_buf.data[2] = 0x00;
8409 : 0 : filter_replace_buf.data[3] =
8410 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8411 : : filter_replace_buf.data[4] =
8412 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8413 : 0 : filter_replace_buf.data[4] |=
8414 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8415 : : filter_replace_buf.data[5] = 0x00;
8416 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8417 : : I40E_TR_L4_TYPE_TCP |
8418 : : I40E_TR_L4_TYPE_SCTP;
8419 : : filter_replace_buf.data[7] = 0x00;
8420 : 0 : filter_replace_buf.data[8] |=
8421 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8422 : : filter_replace_buf.data[9] = 0x00;
8423 : 0 : filter_replace_buf.data[10] = 0xFF;
8424 : 0 : filter_replace_buf.data[11] = 0xFF;
8425 : :
8426 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8427 : : &filter_replace_buf);
8428 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8429 [ # # ]: 0 : filter_replace.new_filter_type)
8430 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8431 : : " original: 0x%x, new: 0x%x",
8432 : : dev->device->name,
8433 : : filter_replace.old_filter_type,
8434 : : filter_replace.new_filter_type);
8435 : :
8436 : : return status;
8437 : : }
8438 : :
8439 : : static enum i40e_status_code
8440 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8441 : : enum i40e_l4_port_type l4_port_type)
8442 : : {
8443 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8444 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8445 : : enum i40e_status_code status = I40E_SUCCESS;
8446 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8447 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8448 : :
8449 [ # # ]: 0 : if (pf->support_multi_driver) {
8450 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8451 : 0 : return I40E_NOT_SUPPORTED;
8452 : : }
8453 : :
8454 : : memset(&filter_replace, 0,
8455 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8456 : : memset(&filter_replace_buf, 0,
8457 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8458 : :
8459 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8460 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8461 : 0 : filter_replace.new_filter_type =
8462 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8463 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8464 : : } else {
8465 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8466 : 0 : filter_replace.new_filter_type =
8467 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8468 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8469 : : }
8470 : :
8471 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8472 : : filter_replace.tr_bit = 0;
8473 : : /* Prepare the buffer, 2 entries */
8474 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8475 : 0 : filter_replace_buf.data[0] |=
8476 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8477 : 0 : filter_replace_buf.data[4] |=
8478 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8479 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8480 : : &filter_replace_buf);
8481 : :
8482 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8483 [ # # ]: 0 : filter_replace.new_filter_type)
8484 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8485 : : " original: 0x%x, new: 0x%x",
8486 : : dev->device->name,
8487 : : filter_replace.old_filter_type,
8488 : : filter_replace.new_filter_type);
8489 : :
8490 : : return status;
8491 : : }
8492 : :
8493 : : int
8494 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8495 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8496 : : uint8_t add)
8497 : : {
8498 : : uint16_t ip_type;
8499 : : uint32_t ipv4_addr, ipv4_addr_le;
8500 : : uint8_t i, tun_type = 0;
8501 : : /* internal variable to convert ipv6 byte order */
8502 : : uint32_t convert_ipv6[4];
8503 : : int val, ret = 0;
8504 : : struct i40e_pf_vf *vf = NULL;
8505 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8506 : : struct i40e_vsi *vsi;
8507 : 0 : struct i40e_aqc_cloud_filters_element_bb cld_filter = {0};
8508 [ # # ]: 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8509 : : struct i40e_tunnel_filter *node;
8510 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8511 : : uint32_t teid_le;
8512 : : bool big_buffer = 0;
8513 : :
8514 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8515 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
8516 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8517 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
8518 : :
8519 : 0 : cld_filter.element.inner_vlan =
8520 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8521 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8522 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8523 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8524 : : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8525 : : memcpy(&cld_filter.element.ipaddr.v4.data,
8526 : : &ipv4_addr_le,
8527 : : sizeof(cld_filter.element.ipaddr.v4.data));
8528 : : } else {
8529 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8530 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8531 : 0 : convert_ipv6[i] =
8532 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8533 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8534 : : }
8535 : : memcpy(&cld_filter.element.ipaddr.v6.data,
8536 : : &convert_ipv6,
8537 : : sizeof(cld_filter.element.ipaddr.v6.data));
8538 : : }
8539 : :
8540 : : /* check tunneled type */
8541 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8542 : : case I40E_TUNNEL_TYPE_VXLAN:
8543 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8544 : : break;
8545 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8546 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8547 : 0 : break;
8548 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8549 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8550 : 0 : break;
8551 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8552 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8553 : 0 : i40e_replace_mpls_l1_filter(pf);
8554 : 0 : i40e_replace_mpls_cloud_filter(pf);
8555 : 0 : pf->mpls_replace_flag = 1;
8556 : : }
8557 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8558 : 0 : 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 : : 0x40;
8564 : : big_buffer = 1;
8565 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8566 : 0 : break;
8567 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8568 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8569 : 0 : i40e_replace_mpls_l1_filter(pf);
8570 : 0 : i40e_replace_mpls_cloud_filter(pf);
8571 : 0 : pf->mpls_replace_flag = 1;
8572 : : }
8573 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8574 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8575 : 0 : teid_le >> 4;
8576 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8577 : 0 : (teid_le & 0xF) << 12;
8578 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8579 : : 0x0;
8580 : : big_buffer = 1;
8581 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8582 : 0 : break;
8583 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8584 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8585 : 0 : i40e_replace_gtp_l1_filter(pf);
8586 : 0 : i40e_replace_gtp_cloud_filter(pf);
8587 : 0 : pf->gtp_replace_flag = 1;
8588 : : }
8589 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8590 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8591 : 0 : (teid_le >> 16) & 0xFFFF;
8592 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8593 : : teid_le & 0xFFFF;
8594 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8595 : : 0x0;
8596 : : big_buffer = 1;
8597 : 0 : break;
8598 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8599 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8600 : 0 : i40e_replace_gtp_l1_filter(pf);
8601 : 0 : i40e_replace_gtp_cloud_filter(pf);
8602 : 0 : pf->gtp_replace_flag = 1;
8603 : : }
8604 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8605 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8606 : 0 : (teid_le >> 16) & 0xFFFF;
8607 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8608 : : teid_le & 0xFFFF;
8609 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8610 : : 0x0;
8611 : : big_buffer = 1;
8612 : 0 : break;
8613 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8614 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8615 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8616 [ # # ]: 0 : if (ret < 0) {
8617 : 0 : PMD_DRV_LOG(ERR, "Failed to create QinQ tunnel filter.");
8618 : : /* ret is a raw i40e_status_code, not an errno */
8619 : 0 : return -ENOTSUP;
8620 : : }
8621 : 0 : pf->qinq_replace_flag = 1;
8622 : : }
8623 : : /* Add in the General fields the values of
8624 : : * the Outer and Inner VLAN
8625 : : * Big Buffer should be set, see changes in
8626 : : * i40e_aq_add_cloud_filters
8627 : : */
8628 : 0 : cld_filter.general_fields[0] = tunnel_filter->inner_vlan;
8629 : 0 : cld_filter.general_fields[1] = tunnel_filter->outer_vlan;
8630 : : big_buffer = 1;
8631 : 0 : break;
8632 : 0 : case I40E_CLOUD_TYPE_UDP:
8633 : : case I40E_CLOUD_TYPE_TCP:
8634 : : case I40E_CLOUD_TYPE_SCTP:
8635 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8636 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8637 : 0 : i40e_replace_port_l1_filter(pf,
8638 : : tunnel_filter->l4_port_type);
8639 : 0 : i40e_replace_port_cloud_filter(pf,
8640 : : tunnel_filter->l4_port_type);
8641 : 0 : pf->sport_replace_flag = 1;
8642 : : }
8643 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8644 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8645 : : I40E_DIRECTION_INGRESS_KEY;
8646 : :
8647 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8648 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8649 : : I40E_TR_L4_TYPE_UDP;
8650 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8651 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8652 : : I40E_TR_L4_TYPE_TCP;
8653 : : else
8654 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8655 : : I40E_TR_L4_TYPE_SCTP;
8656 : :
8657 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8658 : 0 : (teid_le >> 16) & 0xFFFF;
8659 : : big_buffer = 1;
8660 : : } else {
8661 [ # # ]: 0 : if (!pf->dport_replace_flag) {
8662 : 0 : i40e_replace_port_l1_filter(pf,
8663 : : tunnel_filter->l4_port_type);
8664 : 0 : i40e_replace_port_cloud_filter(pf,
8665 : : tunnel_filter->l4_port_type);
8666 : 0 : pf->dport_replace_flag = 1;
8667 : : }
8668 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8669 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8670 : : I40E_DIRECTION_INGRESS_KEY;
8671 : :
8672 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8673 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8674 : : I40E_TR_L4_TYPE_UDP;
8675 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8676 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8677 : : I40E_TR_L4_TYPE_TCP;
8678 : : else
8679 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8680 : : I40E_TR_L4_TYPE_SCTP;
8681 : :
8682 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8683 : 0 : (teid_le >> 16) & 0xFFFF;
8684 : : big_buffer = 1;
8685 : : }
8686 : :
8687 : : break;
8688 : 0 : default:
8689 : : /* Other tunnel types is not supported. */
8690 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8691 : 0 : return -EINVAL;
8692 : : }
8693 : :
8694 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8695 : 0 : cld_filter.element.flags =
8696 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8697 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8698 : 0 : cld_filter.element.flags =
8699 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8700 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8701 : 0 : cld_filter.element.flags =
8702 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8703 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8704 : 0 : cld_filter.element.flags =
8705 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8706 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8707 : 0 : cld_filter.element.flags |=
8708 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8709 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8710 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8711 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8712 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8713 : 0 : cld_filter.element.flags |=
8714 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8715 : : else
8716 : 0 : cld_filter.element.flags |=
8717 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8718 : : } else {
8719 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8720 : : &cld_filter.element.flags);
8721 [ # # ]: 0 : if (val < 0) {
8722 : : return -EINVAL;
8723 : : }
8724 : : }
8725 : :
8726 : 0 : cld_filter.element.flags |=
8727 : 0 : rte_cpu_to_le_16(I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE | ip_type |
8728 : : (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8729 : 0 : cld_filter.element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8730 : 0 : cld_filter.element.queue_number =
8731 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8732 : :
8733 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8734 : 0 : vsi = pf->main_vsi;
8735 : : else {
8736 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8737 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8738 : 0 : return -EINVAL;
8739 : : }
8740 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8741 : 0 : vsi = vf->vsi;
8742 : : }
8743 : :
8744 : : /* Check if there is the filter in SW list */
8745 : : memset(&check_filter, 0, sizeof(check_filter));
8746 : 0 : i40e_tunnel_filter_convert(&cld_filter, &check_filter);
8747 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8748 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8749 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8750 [ # # ]: 0 : if (add && node) {
8751 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8752 : 0 : return -EINVAL;
8753 : : }
8754 : :
8755 [ # # ]: 0 : if (!add && !node) {
8756 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8757 : 0 : return -EINVAL;
8758 : : }
8759 : :
8760 [ # # ]: 0 : if (add) {
8761 : : struct i40e_tunnel_filter *tunnel;
8762 : :
8763 [ # # ]: 0 : if (big_buffer)
8764 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8765 : 0 : vsi->seid, &cld_filter, 1);
8766 : : else
8767 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8768 : 0 : vsi->seid, &cld_filter.element, 1);
8769 [ # # ]: 0 : if (ret < 0) {
8770 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8771 : 0 : return -ENOTSUP;
8772 : : }
8773 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8774 [ # # ]: 0 : if (tunnel == NULL) {
8775 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8776 : 0 : return -ENOMEM;
8777 : : }
8778 : :
8779 : : memcpy(tunnel, &check_filter, sizeof(check_filter));
8780 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8781 [ # # ]: 0 : if (ret < 0)
8782 : 0 : rte_free(tunnel);
8783 : : } else {
8784 [ # # ]: 0 : if (big_buffer)
8785 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8786 : 0 : hw, vsi->seid, &cld_filter, 1);
8787 : : else
8788 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8789 : : &cld_filter.element, 1);
8790 [ # # ]: 0 : if (ret < 0) {
8791 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8792 : 0 : return -ENOTSUP;
8793 : : }
8794 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8795 : : }
8796 : :
8797 : : return ret;
8798 : : }
8799 : :
8800 : : static int
8801 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8802 : : {
8803 : : uint8_t i;
8804 : :
8805 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8806 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8807 : : return i;
8808 : : }
8809 : :
8810 : : return -1;
8811 : : }
8812 : :
8813 : : static int
8814 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8815 : : {
8816 : : int idx, ret;
8817 : 0 : uint8_t filter_idx = 0;
8818 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8819 : :
8820 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8821 : :
8822 : : /* Check if port already exists */
8823 [ # # ]: 0 : if (idx >= 0) {
8824 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8825 : 0 : return -EINVAL;
8826 : : }
8827 : :
8828 : : /* Now check if there is space to add the new port */
8829 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8830 [ # # ]: 0 : if (idx < 0) {
8831 : 0 : PMD_DRV_LOG(ERR,
8832 : : "Maximum number of UDP ports reached, not adding port %d",
8833 : : port);
8834 : 0 : return -ENOSPC;
8835 : : }
8836 : :
8837 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8838 : : &filter_idx, NULL);
8839 [ # # ]: 0 : if (ret < 0) {
8840 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8841 : 0 : return -1;
8842 : : }
8843 : :
8844 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8845 : : port, filter_idx);
8846 : :
8847 : : /* New port: add it and mark its index in the bitmap */
8848 : 0 : pf->vxlan_ports[idx] = port;
8849 : 0 : pf->vxlan_bitmap |= (1 << idx);
8850 : :
8851 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8852 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8853 : :
8854 : : return 0;
8855 : : }
8856 : :
8857 : : static int
8858 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8859 : : {
8860 : : int idx;
8861 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8862 : :
8863 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8864 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8865 : 0 : return -EINVAL;
8866 : : }
8867 : :
8868 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8869 : :
8870 [ # # ]: 0 : if (idx < 0) {
8871 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8872 : 0 : return -EINVAL;
8873 : : }
8874 : :
8875 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8876 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8877 : 0 : return -1;
8878 : : }
8879 : :
8880 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8881 : : port, idx);
8882 : :
8883 : 0 : pf->vxlan_ports[idx] = 0;
8884 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8885 : :
8886 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8887 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8888 : :
8889 : : return 0;
8890 : : }
8891 : :
8892 : : /* Add UDP tunneling port */
8893 : : static int
8894 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8895 : : struct rte_eth_udp_tunnel *udp_tunnel)
8896 : : {
8897 : : int ret = 0;
8898 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8899 : :
8900 [ # # ]: 0 : if (udp_tunnel == NULL)
8901 : : return -EINVAL;
8902 : :
8903 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8904 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8905 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8906 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8907 : 0 : break;
8908 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8909 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8910 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8911 : 0 : break;
8912 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8913 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8914 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8915 : : ret = -1;
8916 : 0 : break;
8917 : :
8918 : 0 : default:
8919 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8920 : : ret = -1;
8921 : 0 : break;
8922 : : }
8923 : :
8924 : : return ret;
8925 : : }
8926 : :
8927 : : /* Remove UDP tunneling port */
8928 : : static int
8929 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8930 : : struct rte_eth_udp_tunnel *udp_tunnel)
8931 : : {
8932 : : int ret = 0;
8933 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8934 : :
8935 [ # # ]: 0 : if (udp_tunnel == NULL)
8936 : : return -EINVAL;
8937 : :
8938 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8939 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8940 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8941 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8942 : 0 : break;
8943 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8944 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8945 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8946 : : ret = -1;
8947 : 0 : break;
8948 : 0 : default:
8949 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8950 : : ret = -1;
8951 : 0 : break;
8952 : : }
8953 : :
8954 : : return ret;
8955 : : }
8956 : :
8957 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8958 : : uint16_t
8959 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8960 : : {
8961 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8962 : : int i;
8963 : : uint16_t num;
8964 : : struct ci_rx_queue *rxq;
8965 : :
8966 : : num = 0;
8967 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8968 : 0 : rxq = data->rx_queues[i];
8969 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8970 : 0 : num++;
8971 : : else
8972 : : break;
8973 : : }
8974 : :
8975 : 0 : return num;
8976 : : }
8977 : :
8978 : : /* Reset the global configure of hash function and input sets */
8979 : : static void
8980 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8981 : : {
8982 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8983 : : uint32_t reg, reg_val;
8984 : : int i;
8985 : :
8986 : : /* Reset global RSS function sets */
8987 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8988 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8989 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8990 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8991 : : }
8992 : :
8993 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8994 : : uint64_t inset;
8995 : : int j, pctype;
8996 : :
8997 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
8998 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8999 : : else
9000 : : pctype = i;
9001 : :
9002 : : /* Reset pctype insets */
9003 : 0 : inset = i40e_get_default_input_set(i);
9004 [ # # ]: 0 : if (inset) {
9005 : 0 : pf->hash_input_set[pctype] = inset;
9006 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
9007 : : inset);
9008 : :
9009 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
9010 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
9011 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
9012 : 0 : i40e_check_write_global_reg(hw, reg,
9013 : 0 : (uint32_t)(inset >> 32));
9014 : :
9015 : : /* Clear unused mask registers of the pctype */
9016 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
9017 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
9018 : 0 : i40e_check_write_global_reg(hw, reg, 0);
9019 : : }
9020 : : }
9021 : :
9022 : : /* Reset pctype symmetric sets */
9023 : 0 : reg = I40E_GLQF_HSYM(pctype);
9024 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
9025 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
9026 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
9027 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
9028 : : }
9029 : : }
9030 : 0 : I40E_WRITE_FLUSH(hw);
9031 : 0 : }
9032 : :
9033 : : int
9034 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
9035 : : {
9036 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
9037 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
9038 : : uint32_t i;
9039 : : uint16_t num;
9040 : :
9041 : : /* If both VMDQ and RSS enabled, not all of PF queues are
9042 : : * configured. It's necessary to calculate the actual PF
9043 : : * queues that are configured.
9044 : : */
9045 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
9046 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
9047 : : else
9048 : 0 : num = pf->dev_data->nb_rx_queues;
9049 : :
9050 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
9051 [ # # ]: 0 : if (num <= 0)
9052 : : return 0;
9053 : :
9054 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
9055 : 0 : lut[i] = (uint8_t)(i % num);
9056 : :
9057 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
9058 : : }
9059 : :
9060 : : int
9061 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
9062 : : {
9063 : : uint8_t key_buf[I40E_RSS_KEY_LEN];
9064 : : const uint8_t *rss_key;
9065 : :
9066 : : /* Reset key */
9067 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
9068 [ # # # # ]: 0 : if (!rss_key || pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < sizeof(key_buf))
9069 : : rss_key = i40e_rss_key_default;
9070 : :
9071 : : /*
9072 : : * adminq does not guarantee const-ness of RSS key once a command is sent down, so make a
9073 : : * local copy.
9074 : : */
9075 : : memcpy(&key_buf, rss_key, sizeof(key_buf));
9076 : :
9077 : 0 : return i40e_set_rss_key(pf->main_vsi, key_buf, sizeof(key_buf));
9078 : : }
9079 : :
9080 : : static int
9081 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
9082 : : {
9083 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9084 : :
9085 : : int ret;
9086 : :
9087 : 0 : pf->hash_filter_enabled = 0;
9088 : 0 : i40e_pf_disable_rss(pf);
9089 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
9090 : :
9091 [ # # ]: 0 : if (!pf->support_multi_driver)
9092 : 0 : i40e_pf_global_rss_reset(pf);
9093 : :
9094 : : /* Reset RETA table */
9095 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
9096 : 0 : ret = i40e_pf_reset_rss_reta(pf);
9097 [ # # ]: 0 : if (ret)
9098 : : return ret;
9099 : : }
9100 : :
9101 : 0 : return i40e_pf_reset_rss_key(pf);
9102 : : }
9103 : :
9104 : : /* Configure RSS */
9105 : : int
9106 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
9107 : : {
9108 : : struct i40e_hw *hw;
9109 : : enum rte_eth_rx_mq_mode mq_mode;
9110 : : uint64_t rss_hf, hena;
9111 : : int ret;
9112 : :
9113 : 0 : ret = i40e_pf_rss_reset(pf);
9114 [ # # ]: 0 : if (ret) {
9115 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9116 : 0 : return ret;
9117 : : }
9118 : :
9119 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9120 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9121 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
9122 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9123 : : return 0;
9124 : :
9125 : 0 : hw = I40E_PF_TO_HW(pf);
9126 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
9127 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9128 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9129 : 0 : I40E_WRITE_FLUSH(hw);
9130 : :
9131 : 0 : return 0;
9132 : : }
9133 : :
9134 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9135 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9136 : : int
9137 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9138 : : {
9139 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9140 : : uint32_t val, reg;
9141 : : int ret = -EINVAL;
9142 : :
9143 [ # # ]: 0 : if (pf->support_multi_driver) {
9144 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9145 : 0 : return -ENOTSUP;
9146 : : }
9147 : :
9148 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9149 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9150 : :
9151 [ # # ]: 0 : if (len == 3) {
9152 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9153 [ # # ]: 0 : } else if (len == 4) {
9154 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9155 : : } else {
9156 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9157 : 0 : return ret;
9158 : : }
9159 : :
9160 [ # # ]: 0 : if (reg != val) {
9161 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9162 : : I40E_GL_PRS_FVBM(2),
9163 : : reg, NULL);
9164 [ # # ]: 0 : if (ret != 0)
9165 : : return ret;
9166 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9167 : : "with value 0x%08x",
9168 : : I40E_GL_PRS_FVBM(2), reg);
9169 : : } else {
9170 : : ret = 0;
9171 : : }
9172 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9173 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9174 : :
9175 : 0 : return ret;
9176 : : }
9177 : :
9178 : : /* Set the symmetric hash enable configurations per port */
9179 : : void
9180 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9181 : : {
9182 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9183 : :
9184 [ # # ]: 0 : if (enable > 0) {
9185 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9186 : : return;
9187 : :
9188 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9189 : : } else {
9190 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9191 : : return;
9192 : :
9193 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9194 : : }
9195 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9196 : 0 : I40E_WRITE_FLUSH(hw);
9197 : : }
9198 : :
9199 : : /**
9200 : : * Valid input sets for hash and flow director filters per PCTYPE
9201 : : */
9202 : : static uint64_t
9203 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9204 : : enum rte_filter_type filter)
9205 : : {
9206 : : uint64_t valid;
9207 : :
9208 : : static const uint64_t valid_hash_inset_table[] = {
9209 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9210 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9211 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9212 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9213 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9214 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9215 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9216 : : I40E_INSET_FLEX_PAYLOAD,
9217 : : [I40E_FILTER_PCTYPE_NONF_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_UNICAST_IPV4_UDP] =
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_FLEX_PAYLOAD,
9235 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
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_FLEX_PAYLOAD,
9244 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
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_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9253 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
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_SRC_PORT | I40E_INSET_DST_PORT |
9261 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9262 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9263 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9264 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9265 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9266 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9267 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9268 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9269 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9270 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9271 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9272 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9273 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9274 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9275 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9276 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9277 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9278 : : I40E_INSET_FLEX_PAYLOAD,
9279 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9280 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9281 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9282 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9283 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9284 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9285 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9286 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9287 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9288 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9289 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9290 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9291 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9292 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9293 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9294 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9295 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
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_MULTICAST_IPV6_UDP] =
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_TCP] =
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_TCP_FLAGS |
9321 : : I40E_INSET_FLEX_PAYLOAD,
9322 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
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_SRC_PORT |
9329 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9330 : : I40E_INSET_FLEX_PAYLOAD,
9331 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9332 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9333 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9334 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9335 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9336 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9337 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9338 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9339 : : I40E_INSET_FLEX_PAYLOAD,
9340 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9341 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9342 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9343 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9344 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9345 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9346 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9347 : : I40E_INSET_FLEX_PAYLOAD,
9348 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9349 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9350 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9351 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9352 : : I40E_INSET_FLEX_PAYLOAD,
9353 : : };
9354 : :
9355 : : /**
9356 : : * Flow director supports only fields defined in
9357 : : * union rte_eth_fdir_flow.
9358 : : */
9359 : : static const uint64_t valid_fdir_inset_table[] = {
9360 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9361 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9362 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9363 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9364 : : I40E_INSET_IPV4_TTL,
9365 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9366 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9367 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9368 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9369 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9370 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9371 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9372 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9373 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9374 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9375 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9376 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9377 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9378 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9379 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9380 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9381 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9382 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9383 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9384 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9385 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9386 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9387 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9388 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9389 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9390 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9391 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9392 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9393 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9394 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9395 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9396 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9397 : : I40E_INSET_SCTP_VT,
9398 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9399 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9400 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9401 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9402 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9403 : : I40E_INSET_IPV4_TTL,
9404 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9405 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9406 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9407 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9408 : : I40E_INSET_IPV6_HOP_LIMIT,
9409 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9410 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9411 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9412 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9413 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9414 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9415 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9416 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9417 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9418 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9419 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9420 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9421 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9422 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9423 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9424 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9425 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9426 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9427 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9428 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9429 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9430 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9431 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9432 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9433 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9434 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9435 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9436 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9437 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9438 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9439 : : I40E_INSET_SCTP_VT,
9440 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9441 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9442 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9443 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9444 : : I40E_INSET_IPV6_HOP_LIMIT,
9445 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9446 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9447 : : I40E_INSET_LAST_ETHER_TYPE,
9448 : : };
9449 : :
9450 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9451 : : return 0;
9452 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9453 : 0 : valid = valid_hash_inset_table[pctype];
9454 : : else
9455 : 0 : valid = valid_fdir_inset_table[pctype];
9456 : :
9457 : : return valid;
9458 : : }
9459 : :
9460 : : /**
9461 : : * Validate if the input set is allowed for a specific PCTYPE
9462 : : */
9463 : : int
9464 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9465 : : enum rte_filter_type filter, uint64_t inset)
9466 : : {
9467 : : uint64_t valid;
9468 : :
9469 : : valid = i40e_get_valid_input_set(pctype, filter);
9470 [ # # ]: 0 : if (inset & (~valid))
9471 : 0 : return -EINVAL;
9472 : :
9473 : : return 0;
9474 : : }
9475 : :
9476 : : /* default input set fields combination per pctype */
9477 : : uint64_t
9478 : 0 : i40e_get_default_input_set(uint16_t pctype)
9479 : : {
9480 : : static const uint64_t default_inset_table[] = {
9481 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9482 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9483 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9484 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9485 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9486 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9487 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9488 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9489 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9490 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9491 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9492 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9493 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9494 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9495 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9496 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9497 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9498 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9499 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9500 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9501 : : I40E_INSET_SCTP_VT,
9502 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9503 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9504 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9505 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9506 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9507 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9508 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9509 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9510 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9511 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9512 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9513 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9514 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9515 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9516 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9517 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9518 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9519 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9520 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9521 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9522 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9523 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9524 : : I40E_INSET_SCTP_VT,
9525 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9526 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9527 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9528 : : I40E_INSET_LAST_ETHER_TYPE,
9529 : : };
9530 : :
9531 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9532 : : return 0;
9533 : :
9534 : 0 : return default_inset_table[pctype];
9535 : : }
9536 : :
9537 : : /**
9538 : : * Translate the input set from bit masks to register aware bit masks
9539 : : * and vice versa
9540 : : */
9541 : : uint64_t
9542 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9543 : : {
9544 : : uint64_t val = 0;
9545 : : uint16_t i;
9546 : :
9547 : : struct inset_map {
9548 : : uint64_t inset;
9549 : : uint64_t inset_reg;
9550 : : };
9551 : :
9552 : : static const struct inset_map inset_map_common[] = {
9553 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9554 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9555 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9556 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9557 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9558 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9559 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9560 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9561 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9562 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9563 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9564 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9565 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9566 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9567 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9568 : : {I40E_INSET_TUNNEL_DMAC,
9569 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9570 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9571 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9572 : : {I40E_INSET_TUNNEL_SRC_PORT,
9573 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9574 : : {I40E_INSET_TUNNEL_DST_PORT,
9575 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9576 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9577 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9578 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9579 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9580 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9581 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9582 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9583 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9584 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9585 : : };
9586 : :
9587 : : /* some different registers map in x722*/
9588 : : static const struct inset_map inset_map_diff_x722[] = {
9589 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9590 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9591 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9592 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9593 : : };
9594 : :
9595 : : static const struct inset_map inset_map_diff_not_x722[] = {
9596 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9597 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9598 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9599 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9600 : : };
9601 : :
9602 [ # # ]: 0 : if (input == 0)
9603 : : return val;
9604 : :
9605 : : /* Translate input set to register aware inset */
9606 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9607 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9608 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9609 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9610 : : }
9611 : : } else {
9612 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9613 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9614 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9615 : : }
9616 : : }
9617 : :
9618 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9619 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9620 : 0 : val |= inset_map_common[i].inset_reg;
9621 : : }
9622 : :
9623 : : return val;
9624 : : }
9625 : :
9626 : : static int
9627 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9628 : : uint32_t pit_reg_count, uint32_t hdr_off)
9629 : : {
9630 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9631 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9632 : : uint32_t i, reg_val, src_off, count;
9633 : :
9634 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9635 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9636 : :
9637 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9638 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9639 : :
9640 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9641 : : break;
9642 : : }
9643 : :
9644 [ # # ]: 0 : if (i >= pit_reg_end) {
9645 : 0 : PMD_DRV_LOG(ERR,
9646 : : "Hardware GLQF_PIT configuration does not support this field mask");
9647 : 0 : return -1;
9648 : : }
9649 : :
9650 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9651 : : }
9652 : :
9653 : : int
9654 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9655 : : uint32_t *mask, uint8_t nb_elem)
9656 : : {
9657 : : static const uint64_t mask_inset[] = {
9658 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9659 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9660 : :
9661 : : static const struct {
9662 : : uint64_t inset;
9663 : : uint32_t mask;
9664 : : uint32_t offset;
9665 : : } inset_mask_offset_map[] = {
9666 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9667 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9668 : :
9669 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9670 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9671 : :
9672 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9673 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9674 : :
9675 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9676 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9677 : :
9678 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9679 : : offsetof(struct rte_ipv6_hdr, proto) },
9680 : :
9681 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9682 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9683 : : };
9684 : :
9685 : : uint32_t i;
9686 : : int idx = 0;
9687 : :
9688 [ # # ]: 0 : assert(mask);
9689 [ # # ]: 0 : if (!inset)
9690 : : return 0;
9691 : :
9692 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9693 : : /* Clear the inset bit, if no MASK is required,
9694 : : * for example proto + ttl
9695 : : */
9696 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9697 : 0 : inset &= ~mask_inset[i];
9698 [ # # ]: 0 : if (!inset)
9699 : : return 0;
9700 : : }
9701 : : }
9702 : :
9703 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9704 : : uint32_t pit_start, pit_count;
9705 : : int offset;
9706 : :
9707 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9708 : 0 : continue;
9709 : :
9710 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9711 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9712 : : I40E_INSET_IPV4_TTL)) {
9713 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9714 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9715 : : } else {
9716 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9717 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9718 : : }
9719 : :
9720 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9721 : 0 : inset_mask_offset_map[i].offset);
9722 : :
9723 [ # # ]: 0 : if (offset < 0)
9724 : : return -EINVAL;
9725 : :
9726 [ # # ]: 0 : if (idx >= nb_elem) {
9727 : 0 : PMD_DRV_LOG(ERR,
9728 : : "Configuration of inset mask out of range %u",
9729 : : nb_elem);
9730 : 0 : return -ERANGE;
9731 : : }
9732 : :
9733 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9734 : : inset_mask_offset_map[i].mask);
9735 : 0 : idx++;
9736 : : }
9737 : :
9738 : : return idx;
9739 : : }
9740 : :
9741 : : void
9742 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9743 : : {
9744 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9745 : :
9746 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9747 [ # # ]: 0 : if (reg != val)
9748 : 0 : i40e_write_rx_ctl(hw, addr, val);
9749 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9750 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9751 : 0 : }
9752 : :
9753 : : void
9754 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9755 : : {
9756 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9757 : 0 : struct rte_eth_dev_data *dev_data =
9758 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9759 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9760 : :
9761 [ # # ]: 0 : if (reg != val) {
9762 : 0 : i40e_write_rx_ctl(hw, addr, val);
9763 : 0 : PMD_DRV_LOG(INFO,
9764 : : "i40e device %s changed global register [0x%08x]."
9765 : : " original: 0x%08x, new: 0x%08x",
9766 : : dev->device->name, addr, reg,
9767 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9768 : : }
9769 : 0 : }
9770 : :
9771 : : static void
9772 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9773 : : {
9774 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9775 : : enum i40e_filter_pctype pctype;
9776 : : uint64_t input_set, inset_reg;
9777 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9778 : : int num, i;
9779 : : uint16_t flow_type;
9780 : :
9781 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9782 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9783 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9784 : :
9785 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9786 : 0 : continue;
9787 : :
9788 : 0 : input_set = i40e_get_default_input_set(pctype);
9789 : :
9790 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9791 : : I40E_INSET_MASK_NUM_REG);
9792 [ # # ]: 0 : if (num < 0)
9793 : 0 : return;
9794 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9795 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9796 : 0 : return;
9797 : : }
9798 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9799 : : input_set);
9800 : :
9801 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9802 : : (uint32_t)(inset_reg & UINT32_MAX));
9803 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9804 : 0 : (uint32_t)((inset_reg >>
9805 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9806 [ # # ]: 0 : if (!pf->support_multi_driver) {
9807 : 0 : i40e_check_write_global_reg(hw,
9808 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9809 : : (uint32_t)(inset_reg & UINT32_MAX));
9810 : 0 : i40e_check_write_global_reg(hw,
9811 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9812 : : (uint32_t)((inset_reg >>
9813 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9814 : :
9815 [ # # ]: 0 : for (i = 0; i < num; i++) {
9816 : 0 : i40e_check_write_global_reg(hw,
9817 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9818 : : mask_reg[i]);
9819 : 0 : i40e_check_write_global_reg(hw,
9820 : : I40E_GLQF_HASH_MSK(i, pctype),
9821 : : mask_reg[i]);
9822 : : }
9823 : : /*clear unused mask registers of the pctype */
9824 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9825 : 0 : i40e_check_write_global_reg(hw,
9826 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9827 : : 0);
9828 : 0 : i40e_check_write_global_reg(hw,
9829 : : I40E_GLQF_HASH_MSK(i, pctype),
9830 : : 0);
9831 : : }
9832 : : } else {
9833 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9834 : : }
9835 : 0 : I40E_WRITE_FLUSH(hw);
9836 : :
9837 : : /* store the default input set */
9838 [ # # ]: 0 : if (!pf->support_multi_driver)
9839 : 0 : pf->hash_input_set[pctype] = input_set;
9840 : 0 : pf->fdir.input_set[pctype] = input_set;
9841 : : }
9842 : : }
9843 : :
9844 : : int
9845 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9846 : : uint32_t pctype, bool add)
9847 : : {
9848 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9849 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9850 : : uint64_t inset_reg = 0;
9851 : : int num, i;
9852 : :
9853 [ # # ]: 0 : if (pf->support_multi_driver) {
9854 : 0 : PMD_DRV_LOG(ERR,
9855 : : "Modify input set is not permitted when multi-driver enabled.");
9856 : 0 : return -EPERM;
9857 : : }
9858 : :
9859 : : /* For X722, get translated pctype in fd pctype register */
9860 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9861 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9862 : :
9863 [ # # ]: 0 : if (add) {
9864 : : /* get inset value in register */
9865 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9866 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9867 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9868 : 0 : input_set |= pf->hash_input_set[pctype];
9869 : : }
9870 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9871 : : I40E_INSET_MASK_NUM_REG);
9872 [ # # ]: 0 : if (num < 0)
9873 : : return -EINVAL;
9874 : :
9875 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9876 : :
9877 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9878 : : (uint32_t)(inset_reg & UINT32_MAX));
9879 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9880 : 0 : (uint32_t)((inset_reg >>
9881 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9882 : :
9883 [ # # ]: 0 : for (i = 0; i < num; i++)
9884 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9885 : : mask_reg[i]);
9886 : : /*clear unused mask registers of the pctype */
9887 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9888 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9889 : : 0);
9890 : 0 : I40E_WRITE_FLUSH(hw);
9891 : :
9892 : 0 : pf->hash_input_set[pctype] = input_set;
9893 : 0 : return 0;
9894 : : }
9895 : :
9896 : : /* Convert ethertype filter structure */
9897 : : static int
9898 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9899 : : struct i40e_ethertype_filter *filter)
9900 : : {
9901 : 0 : memcpy(&filter->input.mac_addr, &input->mac_addr,
9902 : : RTE_ETHER_ADDR_LEN);
9903 : 0 : filter->input.ether_type = input->ether_type;
9904 : 0 : filter->flags = input->flags;
9905 : 0 : filter->queue = input->queue;
9906 : :
9907 : : return 0;
9908 : : }
9909 : :
9910 : : /* Check if there exists the ethertype filter */
9911 : : struct i40e_ethertype_filter *
9912 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9913 : : const struct i40e_ethertype_filter_input *input)
9914 : : {
9915 : : int ret;
9916 : :
9917 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9918 [ # # ]: 0 : if (ret < 0)
9919 : : return NULL;
9920 : :
9921 : 0 : return ethertype_rule->hash_map[ret];
9922 : : }
9923 : :
9924 : : /* Add ethertype filter in SW list */
9925 : : static int
9926 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9927 : : struct i40e_ethertype_filter *filter)
9928 : : {
9929 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9930 : : int ret;
9931 : :
9932 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9933 [ # # ]: 0 : if (ret < 0) {
9934 : 0 : PMD_DRV_LOG(ERR,
9935 : : "Failed to insert ethertype filter"
9936 : : " to hash table %d!",
9937 : : ret);
9938 : 0 : return ret;
9939 : : }
9940 : 0 : rule->hash_map[ret] = filter;
9941 : :
9942 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9943 : :
9944 : 0 : return 0;
9945 : : }
9946 : :
9947 : : /* Delete ethertype filter in SW list */
9948 : : int
9949 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9950 : : struct i40e_ethertype_filter_input *input)
9951 : : {
9952 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9953 : : struct i40e_ethertype_filter *filter;
9954 : : int ret;
9955 : :
9956 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9957 [ # # ]: 0 : if (ret < 0) {
9958 : 0 : PMD_DRV_LOG(ERR,
9959 : : "Failed to delete ethertype filter"
9960 : : " to hash table %d!",
9961 : : ret);
9962 : 0 : return ret;
9963 : : }
9964 : 0 : filter = rule->hash_map[ret];
9965 : 0 : rule->hash_map[ret] = NULL;
9966 : :
9967 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9968 : 0 : rte_free(filter);
9969 : :
9970 : 0 : return 0;
9971 : : }
9972 : :
9973 : : /*
9974 : : * Configure ethertype filter, which can director packet by filtering
9975 : : * with mac address and ether_type or only ether_type
9976 : : */
9977 : : int
9978 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9979 : : struct rte_eth_ethertype_filter *filter,
9980 : : bool add)
9981 : : {
9982 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9983 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9984 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9985 : : struct i40e_ethertype_filter check_filter;
9986 : : struct i40e_control_filter_stats stats;
9987 : : uint16_t flags = 0;
9988 : : int ret;
9989 : :
9990 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9991 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9992 : 0 : return -EINVAL;
9993 : : }
9994 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9995 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9996 : 0 : PMD_DRV_LOG(ERR,
9997 : : "unsupported ether_type(0x%04x) in control packet filter.",
9998 : : filter->ether_type);
9999 : 0 : return -EINVAL;
10000 : : }
10001 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
10002 : 0 : PMD_DRV_LOG(WARNING,
10003 : : "filter vlan ether_type in first tag is not supported.");
10004 : :
10005 : : /* Check if there is the filter in SW list */
10006 : : memset(&check_filter, 0, sizeof(check_filter));
10007 : : i40e_ethertype_filter_convert(filter, &check_filter);
10008 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
10009 : : &check_filter.input);
10010 [ # # ]: 0 : if (add && node) {
10011 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
10012 : 0 : return -EINVAL;
10013 : : }
10014 : :
10015 [ # # ]: 0 : if (!add && !node) {
10016 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
10017 : 0 : return -EINVAL;
10018 : : }
10019 : :
10020 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
10021 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
10022 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
10023 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
10024 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
10025 : :
10026 : : memset(&stats, 0, sizeof(stats));
10027 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
10028 : 0 : filter->mac_addr.addr_bytes,
10029 : 0 : filter->ether_type, flags,
10030 : 0 : pf->main_vsi->seid,
10031 : 0 : filter->queue, add, &stats, NULL);
10032 : :
10033 : 0 : PMD_DRV_LOG(INFO,
10034 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10035 : : ret, stats.mac_etype_used, stats.etype_used,
10036 : : stats.mac_etype_free, stats.etype_free);
10037 [ # # ]: 0 : if (ret < 0)
10038 : : return -ENOSYS;
10039 : :
10040 : : /* Add or delete a filter in SW list */
10041 [ # # ]: 0 : if (add) {
10042 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
10043 : : sizeof(*ethertype_filter), 0);
10044 [ # # ]: 0 : if (ethertype_filter == NULL) {
10045 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10046 : 0 : return -ENOMEM;
10047 : : }
10048 : :
10049 : : memcpy(ethertype_filter, &check_filter,
10050 : : sizeof(check_filter));
10051 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10052 [ # # ]: 0 : if (ret < 0)
10053 : 0 : rte_free(ethertype_filter);
10054 : : } else {
10055 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10056 : : }
10057 : :
10058 : : return ret;
10059 : : }
10060 : :
10061 : : static int
10062 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
10063 : : const struct rte_flow_ops **ops)
10064 : : {
10065 [ # # ]: 0 : if (dev == NULL)
10066 : : return -EINVAL;
10067 : :
10068 : 0 : *ops = &i40e_flow_ops;
10069 : 0 : return 0;
10070 : : }
10071 : :
10072 : : /*
10073 : : * Check and enable Extended Tag.
10074 : : * Enabling Extended Tag is important for 40G performance.
10075 : : */
10076 : : static void
10077 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
10078 : : {
10079 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
10080 : 0 : uint32_t buf = 0;
10081 : : int ret;
10082 : :
10083 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10084 : : PCI_DEV_CAP_REG);
10085 [ # # ]: 0 : if (ret < 0) {
10086 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10087 : : PCI_DEV_CAP_REG);
10088 : 0 : return;
10089 : : }
10090 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10091 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10092 : 0 : return;
10093 : : }
10094 : :
10095 : 0 : buf = 0;
10096 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10097 : : PCI_DEV_CTRL_REG);
10098 [ # # ]: 0 : if (ret < 0) {
10099 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10100 : : PCI_DEV_CTRL_REG);
10101 : 0 : return;
10102 : : }
10103 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10104 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10105 : 0 : return;
10106 : : }
10107 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10108 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10109 : : PCI_DEV_CTRL_REG);
10110 [ # # ]: 0 : if (ret < 0) {
10111 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10112 : : PCI_DEV_CTRL_REG);
10113 : 0 : return;
10114 : : }
10115 : : }
10116 : :
10117 : : /*
10118 : : * As some registers wouldn't be reset unless a global hardware reset,
10119 : : * hardware initialization is needed to put those registers into an
10120 : : * expected initial state.
10121 : : */
10122 : : static void
10123 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
10124 : : {
10125 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10126 : :
10127 : 0 : i40e_enable_extended_tag(dev);
10128 : :
10129 : : /* clear the PF Queue Filter control register */
10130 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10131 : :
10132 : : /* Disable symmetric hash per port */
10133 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10134 : 0 : }
10135 : :
10136 : : /*
10137 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10138 : : * however this function will return only one highest pctype index,
10139 : : * which is not quite correct. This is known problem of i40e driver
10140 : : * and needs to be fixed later.
10141 : : */
10142 : : enum i40e_filter_pctype
10143 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10144 : : {
10145 : : int i;
10146 : : uint64_t pctype_mask;
10147 : :
10148 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10149 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10150 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10151 [ # # ]: 0 : if (pctype_mask & RTE_BIT64(i))
10152 : 0 : return (enum i40e_filter_pctype)i;
10153 : : }
10154 : : }
10155 : : return I40E_FILTER_PCTYPE_INVALID;
10156 : : }
10157 : :
10158 : : uint16_t
10159 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10160 : : enum i40e_filter_pctype pctype)
10161 : : {
10162 : : uint16_t flowtype;
10163 : 0 : uint64_t pctype_mask = RTE_BIT64(pctype);
10164 : :
10165 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10166 : 0 : flowtype++) {
10167 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10168 : 0 : return flowtype;
10169 : : }
10170 : :
10171 : : return RTE_ETH_FLOW_UNKNOWN;
10172 : : }
10173 : :
10174 : : /*
10175 : : * On X710, performance number is far from the expectation on recent firmware
10176 : : * versions; on XL710, performance number is also far from the expectation on
10177 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10178 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10179 : : * address. The fix for this issue may not be integrated in the following
10180 : : * firmware version. So the workaround in software driver is needed. It needs
10181 : : * to modify the initial values of 3 internal only registers for both X710 and
10182 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10183 : : * workaround can be removed when it is fixed in firmware in the future.
10184 : : */
10185 : :
10186 : : /* For both X710 and XL710 */
10187 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10188 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10189 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10190 : :
10191 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10192 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10193 : :
10194 : : /* For X722 */
10195 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10196 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10197 : :
10198 : : /* For X710 */
10199 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10200 : : /* For XL710 */
10201 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10202 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10203 : :
10204 : : /*
10205 : : * GL_SWR_PM_UP_THR:
10206 : : * The value is not impacted from the link speed, its value is set according
10207 : : * to the total number of ports for a better pipe-monitor configuration.
10208 : : */
10209 : : static bool
10210 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10211 : : {
10212 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10213 : : .device_id = (dev), \
10214 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10215 : :
10216 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10217 : : .device_id = (dev), \
10218 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10219 : :
10220 : : static const struct {
10221 : : uint16_t device_id;
10222 : : uint32_t val;
10223 : : } swr_pm_table[] = {
10224 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10225 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10226 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10227 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10228 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10229 : :
10230 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10231 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10232 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10233 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10234 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10235 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10236 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10237 : : };
10238 : : uint32_t i;
10239 : :
10240 [ # # ]: 0 : if (value == NULL) {
10241 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10242 : 0 : return false;
10243 : : }
10244 : :
10245 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10246 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10247 : 0 : *value = swr_pm_table[i].val;
10248 : :
10249 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10250 : : "value - 0x%08x",
10251 : : hw->device_id, *value);
10252 : 0 : return true;
10253 : : }
10254 : : }
10255 : :
10256 : : return false;
10257 : : }
10258 : :
10259 : : static int
10260 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10261 : : {
10262 : : enum i40e_status_code status;
10263 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10264 : : int ret = -ENOTSUP;
10265 : : int retries = 0;
10266 : :
10267 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10268 : : NULL);
10269 : :
10270 [ # # ]: 0 : while (status) {
10271 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10272 : : status);
10273 : 0 : retries++;
10274 : 0 : rte_delay_us(100000);
10275 [ # # ]: 0 : if (retries < 5)
10276 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10277 : : true, &phy_ab, NULL);
10278 : : else
10279 : : return ret;
10280 : : }
10281 : : return 0;
10282 : : }
10283 : :
10284 : : static void
10285 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10286 : : {
10287 : : static struct {
10288 : : uint32_t addr;
10289 : : uint64_t val;
10290 : : } reg_table[] = {
10291 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10292 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10293 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10294 : : };
10295 : : uint64_t reg;
10296 : : uint32_t i;
10297 : : int ret;
10298 : :
10299 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10300 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10301 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10302 : 0 : reg_table[i].val =
10303 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10304 : : else /* For X710/XL710/XXV710 */
10305 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10306 : 0 : reg_table[i].val =
10307 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10308 : : else
10309 : 0 : reg_table[i].val =
10310 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10311 : : }
10312 : :
10313 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10314 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10315 : 0 : reg_table[i].val =
10316 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10317 : : else /* For X710/XL710/XXV710 */
10318 : 0 : reg_table[i].val =
10319 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10320 : : }
10321 : :
10322 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10323 : : uint32_t cfg_val;
10324 : :
10325 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10326 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10327 : : "GL_SWR_PM_UP_THR value fixup",
10328 : : hw->device_id);
10329 : 0 : continue;
10330 : : }
10331 : :
10332 : 0 : reg_table[i].val = cfg_val;
10333 : : }
10334 : :
10335 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10336 : : ®, NULL);
10337 [ # # ]: 0 : if (ret < 0) {
10338 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10339 : : reg_table[i].addr);
10340 : 0 : break;
10341 : : }
10342 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10343 : : reg_table[i].addr, reg);
10344 [ # # ]: 0 : if (reg == reg_table[i].val)
10345 : 0 : continue;
10346 : :
10347 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10348 : : reg_table[i].val, NULL);
10349 [ # # ]: 0 : if (ret < 0) {
10350 : 0 : PMD_DRV_LOG(ERR,
10351 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10352 : : reg_table[i].val, reg_table[i].addr);
10353 : 0 : break;
10354 : : }
10355 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10356 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10357 : : }
10358 : 0 : }
10359 : :
10360 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10361 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10362 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10363 : : static int
10364 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10365 : : {
10366 : : uint32_t reg;
10367 : : int ret;
10368 : :
10369 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10370 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10371 : 0 : return -EINVAL;
10372 : : }
10373 : :
10374 : : /* Configure for double VLAN RX stripping */
10375 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10376 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10377 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10378 : 0 : ret = i40e_aq_debug_write_register(hw,
10379 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10380 : : reg, NULL);
10381 [ # # ]: 0 : if (ret < 0) {
10382 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10383 : : vsi->vsi_id);
10384 : 0 : return I40E_ERR_CONFIG;
10385 : : }
10386 : : }
10387 : :
10388 : : /* Configure for double VLAN TX insertion */
10389 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10390 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10391 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10392 : 0 : ret = i40e_aq_debug_write_register(hw,
10393 : 0 : I40E_VSI_L2TAGSTXVALID(
10394 : : vsi->vsi_id), reg, NULL);
10395 [ # # ]: 0 : if (ret < 0) {
10396 : 0 : PMD_DRV_LOG(ERR,
10397 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10398 : : vsi->vsi_id);
10399 : 0 : return I40E_ERR_CONFIG;
10400 : : }
10401 : : }
10402 : :
10403 : : return 0;
10404 : : }
10405 : :
10406 : : static uint64_t
10407 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10408 : : {
10409 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10410 : : uint64_t systim_cycles;
10411 : :
10412 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10413 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10414 [ # # ]: 0 : << 32;
10415 : :
10416 : : return systim_cycles;
10417 : : }
10418 : :
10419 : : static uint64_t
10420 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10421 : : {
10422 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10423 : : uint64_t rx_tstamp;
10424 : :
10425 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10426 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10427 [ # # ]: 0 : << 32;
10428 : :
10429 : : return rx_tstamp;
10430 : : }
10431 : :
10432 : : static uint64_t
10433 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10434 : : {
10435 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10436 : : uint64_t tx_tstamp;
10437 : :
10438 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10439 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10440 [ # # ]: 0 : << 32;
10441 : :
10442 : : return tx_tstamp;
10443 : : }
10444 : :
10445 : : static void
10446 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10447 : : {
10448 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10449 : : struct i40e_adapter *adapter = dev->data->dev_private;
10450 : : struct rte_eth_link link;
10451 : : uint32_t tsync_inc_l;
10452 : : uint32_t tsync_inc_h;
10453 : :
10454 : : /* Get current link speed. */
10455 : 0 : i40e_dev_link_update(dev, 1);
10456 : 0 : rte_eth_linkstatus_get(dev, &link);
10457 : :
10458 [ # # # # ]: 0 : switch (link.link_speed) {
10459 : : case RTE_ETH_SPEED_NUM_40G:
10460 : : case RTE_ETH_SPEED_NUM_25G:
10461 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10462 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10463 : : break;
10464 : 0 : case RTE_ETH_SPEED_NUM_10G:
10465 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10466 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10467 : 0 : break;
10468 : 0 : case RTE_ETH_SPEED_NUM_1G:
10469 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10470 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10471 : 0 : break;
10472 : 0 : default:
10473 : : tsync_inc_l = 0x0;
10474 : : tsync_inc_h = 0x0;
10475 : : }
10476 : :
10477 : : /* Set the timesync increment value. */
10478 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10479 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10480 : :
10481 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10482 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10483 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10484 : :
10485 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10486 : : adapter->systime_tc.cc_shift = 0;
10487 : : adapter->systime_tc.nsec_mask = 0;
10488 : :
10489 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10490 : : adapter->rx_tstamp_tc.cc_shift = 0;
10491 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10492 : :
10493 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10494 : : adapter->tx_tstamp_tc.cc_shift = 0;
10495 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10496 : 0 : }
10497 : :
10498 : : static int
10499 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10500 : : {
10501 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10502 : :
10503 : 0 : adapter->systime_tc.nsec += delta;
10504 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10505 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10506 : :
10507 : 0 : return 0;
10508 : : }
10509 : :
10510 : : static int
10511 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10512 : : {
10513 : : uint64_t ns;
10514 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10515 : :
10516 : : ns = rte_timespec_to_ns(ts);
10517 : :
10518 : : /* Set the timecounters to a new value. */
10519 : 0 : adapter->systime_tc.nsec = ns;
10520 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10521 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10522 : :
10523 : 0 : return 0;
10524 : : }
10525 : :
10526 : : static int
10527 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10528 : : {
10529 : : uint64_t ns, systime_cycles;
10530 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10531 : :
10532 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10533 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10534 : 0 : *ts = rte_ns_to_timespec(ns);
10535 : :
10536 : 0 : return 0;
10537 : : }
10538 : :
10539 : : static int
10540 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10541 : : {
10542 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10543 : : uint32_t tsync_ctl_l;
10544 : : uint32_t tsync_ctl_h;
10545 : : struct timespec ts;
10546 : :
10547 : : memset(&ts, 0, sizeof(struct timespec));
10548 : :
10549 : : /* Stop the timesync system time. */
10550 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10551 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10552 : : /* Reset the timesync system time value. */
10553 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10554 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10555 : :
10556 : 0 : i40e_start_timecounters(dev);
10557 : :
10558 : : /* Clear timesync registers. */
10559 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10560 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10561 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10562 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10563 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10564 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10565 : :
10566 : : /* Enable timestamping of PTP packets. */
10567 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10568 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10569 : :
10570 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10571 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10572 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10573 : :
10574 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10575 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10576 : :
10577 : : /* i40e uses zero-based timestamping so only adjust timecounter */
10578 : : i40e_timesync_write_time(dev, &ts);
10579 : :
10580 : 0 : return 0;
10581 : : }
10582 : :
10583 : : static int
10584 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10585 : : {
10586 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10587 : : uint32_t tsync_ctl_l;
10588 : : uint32_t tsync_ctl_h;
10589 : :
10590 : : /* Disable timestamping of transmitted PTP packets. */
10591 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10592 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10593 : :
10594 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10595 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10596 : :
10597 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10598 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10599 : :
10600 : : /* Reset the timesync increment value. */
10601 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10602 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10603 : :
10604 : 0 : return 0;
10605 : : }
10606 : :
10607 : : static int
10608 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10609 : : struct timespec *timestamp, uint32_t flags)
10610 : : {
10611 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10612 : : struct i40e_adapter *adapter = dev->data->dev_private;
10613 : : uint32_t sync_status;
10614 : 0 : uint32_t index = flags & 0x03;
10615 : : uint64_t rx_tstamp_cycles;
10616 : : uint64_t ns;
10617 : :
10618 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10619 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10620 : : return -EINVAL;
10621 : :
10622 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10623 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10624 : 0 : *timestamp = rte_ns_to_timespec(ns);
10625 : :
10626 : 0 : return 0;
10627 : : }
10628 : :
10629 : : static int
10630 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10631 : : struct timespec *timestamp)
10632 : : {
10633 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10634 : : struct i40e_adapter *adapter = dev->data->dev_private;
10635 : : uint32_t sync_status;
10636 : : uint64_t tx_tstamp_cycles;
10637 : : uint64_t ns;
10638 : :
10639 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10640 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10641 : : return -EINVAL;
10642 : :
10643 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10644 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10645 : 0 : *timestamp = rte_ns_to_timespec(ns);
10646 : :
10647 : 0 : return 0;
10648 : : }
10649 : :
10650 : : /*
10651 : : * i40e_parse_dcb_configure - parse dcb configure from user
10652 : : * @dev: the device being configured
10653 : : * @dcb_cfg: pointer of the result of parse
10654 : : * @*tc_map: bit map of enabled traffic classes
10655 : : *
10656 : : * Returns 0 on success, negative value on failure
10657 : : */
10658 : : static int
10659 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10660 : : struct i40e_dcbx_config *dcb_cfg,
10661 : : uint8_t *tc_map)
10662 : : {
10663 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10664 : : uint8_t i, tc_bw, bw_lf;
10665 : :
10666 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10667 : :
10668 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10669 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10670 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10671 : 0 : return -EINVAL;
10672 : : }
10673 : :
10674 : : /* assume each tc has the same bw */
10675 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10676 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10677 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10678 : : /* to ensure the sum of tcbw is equal to 100 */
10679 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10680 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10681 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10682 : :
10683 : : /* assume each tc has the same Transmission Selection Algorithm */
10684 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10685 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10686 : :
10687 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10688 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10689 : 0 : dcb_rx_conf->dcb_tc[i];
10690 : :
10691 : : /* FW needs one App to configure HW */
10692 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10693 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10694 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10695 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10696 : :
10697 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10698 : 0 : *tc_map = 1; /* tc0 only */
10699 : : else
10700 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10701 : :
10702 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10703 : 0 : dcb_cfg->pfc.willing = 0;
10704 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10705 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10706 : : }
10707 : : return 0;
10708 : : }
10709 : :
10710 : :
10711 : : static enum i40e_status_code
10712 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10713 : : struct i40e_aqc_vsi_properties_data *info,
10714 : : uint8_t enabled_tcmap)
10715 : : {
10716 : : enum i40e_status_code ret;
10717 : : int i, total_tc = 0;
10718 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10719 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10720 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10721 : : uint16_t used_queues;
10722 : :
10723 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10724 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10725 : : return ret;
10726 : :
10727 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10728 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10729 : 0 : total_tc++;
10730 : : }
10731 [ # # ]: 0 : if (total_tc == 0)
10732 : : total_tc = 1;
10733 : 0 : vsi->enabled_tc = enabled_tcmap;
10734 : :
10735 : : /* different VSI has different queues assigned */
10736 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10737 : 0 : used_queues = dev_data->nb_rx_queues -
10738 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10739 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10740 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10741 : : else {
10742 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10743 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10744 : : }
10745 : :
10746 : 0 : qpnum_per_tc = used_queues / total_tc;
10747 : : /* Number of queues per enabled TC */
10748 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10749 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10750 : 0 : return I40E_ERR_INVALID_QP_ID;
10751 : : }
10752 : 0 : qpnum_per_tc = RTE_MIN((uint16_t)i40e_align_floor(qpnum_per_tc),
10753 : : I40E_MAX_Q_PER_TC);
10754 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10755 : :
10756 : : /**
10757 : : * Configure TC and queue mapping parameters, for enabled TC,
10758 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10759 : : * default queue will serve it.
10760 : : */
10761 : : qp_idx = 0;
10762 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10763 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10764 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10765 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10766 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10767 : 0 : qp_idx += qpnum_per_tc;
10768 : : } else
10769 : 0 : info->tc_mapping[i] = 0;
10770 : : }
10771 : :
10772 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10773 : : if (vsi->type == I40E_VSI_SRIOV) {
10774 : : info->mapping_flags |=
10775 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10776 : : for (i = 0; i < vsi->nb_qps; i++)
10777 : : info->queue_mapping[i] =
10778 : : rte_cpu_to_le_16(vsi->base_queue + i);
10779 : : } else {
10780 : 0 : info->mapping_flags |=
10781 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10782 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10783 : : }
10784 : 0 : info->valid_sections |=
10785 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10786 : :
10787 : 0 : return I40E_SUCCESS;
10788 : : }
10789 : :
10790 : : /*
10791 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10792 : : * @veb: VEB to be configured
10793 : : * @tc_map: enabled TC bitmap
10794 : : *
10795 : : * Returns 0 on success, negative value on failure
10796 : : */
10797 : : static enum i40e_status_code
10798 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10799 : : {
10800 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10801 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10802 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10803 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10804 : : enum i40e_status_code ret = I40E_SUCCESS;
10805 : : int i;
10806 : : uint32_t bw_max;
10807 : :
10808 : : /* Check if enabled_tc is same as existing or new TCs */
10809 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10810 : : return ret;
10811 : :
10812 : : /* configure tc bandwidth */
10813 : : memset(&veb_bw, 0, sizeof(veb_bw));
10814 : 0 : veb_bw.tc_valid_bits = tc_map;
10815 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10816 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10817 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10818 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10819 : : }
10820 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10821 : : &veb_bw, NULL);
10822 [ # # ]: 0 : if (ret) {
10823 : 0 : PMD_INIT_LOG(ERR,
10824 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10825 : : hw->aq.asq_last_status);
10826 : 0 : return ret;
10827 : : }
10828 : :
10829 : : memset(&ets_query, 0, sizeof(ets_query));
10830 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10831 : : &ets_query, NULL);
10832 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10833 : 0 : PMD_DRV_LOG(ERR,
10834 : : "Failed to get switch_comp ETS configuration %u",
10835 : : hw->aq.asq_last_status);
10836 : 0 : return ret;
10837 : : }
10838 : : memset(&bw_query, 0, sizeof(bw_query));
10839 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10840 : : &bw_query, NULL);
10841 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10842 : 0 : PMD_DRV_LOG(ERR,
10843 : : "Failed to get switch_comp bandwidth configuration %u",
10844 : : hw->aq.asq_last_status);
10845 : 0 : return ret;
10846 : : }
10847 : :
10848 : : /* store and print out BW info */
10849 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10850 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10851 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10852 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10853 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10854 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10855 : : I40E_16_BIT_WIDTH);
10856 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10857 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10858 : 0 : bw_query.tc_bw_share_credits[i];
10859 : 0 : veb->bw_info.bw_ets_credits[i] =
10860 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10861 : : /* 4 bits per TC, 4th bit is reserved */
10862 : 0 : veb->bw_info.bw_ets_max[i] =
10863 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10864 : : RTE_LEN2MASK(3, uint8_t));
10865 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10866 : : veb->bw_info.bw_ets_share_credits[i]);
10867 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10868 : : veb->bw_info.bw_ets_credits[i]);
10869 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10870 : : veb->bw_info.bw_ets_max[i]);
10871 : : }
10872 : :
10873 : 0 : veb->enabled_tc = tc_map;
10874 : :
10875 : 0 : return ret;
10876 : : }
10877 : :
10878 : :
10879 : : /*
10880 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10881 : : * @vsi: VSI to be configured
10882 : : * @tc_map: enabled TC bitmap
10883 : : *
10884 : : * Returns 0 on success, negative value on failure
10885 : : */
10886 : : static enum i40e_status_code
10887 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10888 : : {
10889 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10890 : : struct i40e_vsi_context ctxt;
10891 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10892 : : enum i40e_status_code ret = I40E_SUCCESS;
10893 : : int i;
10894 : :
10895 : : /* Check if enabled_tc is same as existing or new TCs */
10896 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10897 : : return ret;
10898 : :
10899 : : /* configure tc bandwidth */
10900 : : memset(&bw_data, 0, sizeof(bw_data));
10901 : 0 : bw_data.tc_valid_bits = tc_map;
10902 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10903 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10904 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10905 : 0 : bw_data.tc_bw_credits[i] = 1;
10906 : : }
10907 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10908 [ # # ]: 0 : if (ret) {
10909 : 0 : PMD_INIT_LOG(ERR,
10910 : : "AQ command Config VSI BW allocation per TC failed = %d",
10911 : : hw->aq.asq_last_status);
10912 : 0 : goto out;
10913 : : }
10914 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10915 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10916 : :
10917 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10918 : 0 : ctxt.seid = vsi->seid;
10919 : 0 : ctxt.pf_num = hw->pf_id;
10920 : 0 : ctxt.vf_num = 0;
10921 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10922 : 0 : ctxt.info = vsi->info;
10923 : 0 : i40e_get_cap(hw);
10924 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10925 [ # # ]: 0 : if (ret)
10926 : 0 : goto out;
10927 : :
10928 : : /* Update the VSI after updating the VSI queue-mapping information */
10929 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10930 [ # # ]: 0 : if (ret) {
10931 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10932 : : hw->aq.asq_last_status);
10933 : 0 : goto out;
10934 : : }
10935 : : /* update the local VSI info with updated queue map */
10936 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10937 : : sizeof(vsi->info.tc_mapping));
10938 : 0 : memcpy(&vsi->info.queue_mapping,
10939 : : &ctxt.info.queue_mapping,
10940 : : sizeof(vsi->info.queue_mapping));
10941 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10942 : 0 : vsi->info.valid_sections = 0;
10943 : :
10944 : : /* query and update current VSI BW information */
10945 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10946 [ # # ]: 0 : if (ret) {
10947 : 0 : PMD_INIT_LOG(ERR,
10948 : : "Failed updating vsi bw info, err %s aq_err %s",
10949 : : i40e_stat_str(hw, ret),
10950 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10951 : 0 : goto out;
10952 : : }
10953 : :
10954 : 0 : vsi->enabled_tc = tc_map;
10955 : :
10956 : : out:
10957 : : return ret;
10958 : : }
10959 : :
10960 : : /*
10961 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10962 : : * @pf: pf the configuration is taken on
10963 : : * @new_cfg: new configuration
10964 : : * @tc_map: enabled TC bitmap
10965 : : *
10966 : : * Returns 0 on success, negative value on failure
10967 : : */
10968 : : static enum i40e_status_code
10969 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10970 : : struct i40e_dcbx_config *new_cfg,
10971 : : uint8_t tc_map)
10972 : : {
10973 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10974 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10975 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10976 : : struct i40e_vsi_list *vsi_list;
10977 : : enum i40e_status_code ret;
10978 : : int i;
10979 : : uint32_t val;
10980 : :
10981 : : /* Use the FW API if FW > v4.4*/
10982 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10983 : : (hw->aq.fw_maj_ver >= 5))) {
10984 : 0 : PMD_INIT_LOG(ERR,
10985 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10986 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10987 : : }
10988 : :
10989 : : /* Check if need reconfiguration */
10990 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10991 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10992 : 0 : return I40E_SUCCESS;
10993 : : }
10994 : :
10995 : : /* Copy the new config to the current config */
10996 : 0 : *old_cfg = *new_cfg;
10997 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10998 : 0 : ret = i40e_set_dcb_config(hw);
10999 [ # # ]: 0 : if (ret) {
11000 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
11001 : : i40e_stat_str(hw, ret),
11002 : : i40e_aq_str(hw, hw->aq.asq_last_status));
11003 : 0 : return ret;
11004 : : }
11005 : : /* set receive Arbiter to RR mode and ETS scheme by default */
11006 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
11007 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
11008 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
11009 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
11010 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
11011 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
11012 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
11013 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
11014 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
11015 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
11016 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
11017 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
11018 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
11019 : : }
11020 : : /* get local mib to check whether it is configured correctly */
11021 : : /* IEEE mode */
11022 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
11023 : : /* Get Local DCB Config */
11024 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
11025 : : &hw->local_dcbx_config);
11026 : :
11027 : : /* if Veb is created, need to update TC of it at first */
11028 [ # # ]: 0 : if (main_vsi->veb) {
11029 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11030 [ # # ]: 0 : if (ret)
11031 : 0 : PMD_INIT_LOG(WARNING,
11032 : : "Failed configuring TC for VEB seid=%d",
11033 : : main_vsi->veb->seid);
11034 : : }
11035 : : /* Update each VSI */
11036 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
11037 [ # # ]: 0 : if (main_vsi->veb) {
11038 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11039 : : /* Beside main VSI and VMDQ VSIs, only enable default
11040 : : * TC for other VSIs
11041 : : */
11042 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11043 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11044 : : tc_map);
11045 : : else
11046 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11047 : : I40E_DEFAULT_TCMAP);
11048 [ # # ]: 0 : if (ret)
11049 : 0 : PMD_INIT_LOG(WARNING,
11050 : : "Failed configuring TC for VSI seid=%d",
11051 : : vsi_list->vsi->seid);
11052 : : /* continue */
11053 : : }
11054 : : }
11055 : : return I40E_SUCCESS;
11056 : : }
11057 : :
11058 : : /*
11059 : : * i40e_dcb_init_configure - initial dcb config
11060 : : * @dev: device being configured
11061 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
11062 : : *
11063 : : * Returns 0 on success, negative value on failure
11064 : : */
11065 : : int
11066 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11067 : : {
11068 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11069 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11070 : : int i, ret = 0;
11071 : :
11072 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11073 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11074 : 0 : return -ENOTSUP;
11075 : : }
11076 : :
11077 : : /* DCB initialization:
11078 : : * Update DCB configuration from the Firmware and configure
11079 : : * LLDP MIB change event.
11080 : : */
11081 [ # # ]: 0 : if (sw_dcb == TRUE) {
11082 : : /* Stopping lldp is necessary for DPDK, but it will cause
11083 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
11084 : : * for successful initialization of DCB is that LLDP is
11085 : : * enabled. So it is needed to start lldp before DCB init
11086 : : * and stop it after initialization.
11087 : : */
11088 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11089 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11090 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11091 : :
11092 : 0 : ret = i40e_init_dcb(hw, true);
11093 : : /* If lldp agent is stopped, the return value from
11094 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11095 : : * adminq status. Otherwise, it should return success.
11096 : : */
11097 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11098 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11099 : 0 : memset(&hw->local_dcbx_config, 0,
11100 : : sizeof(struct i40e_dcbx_config));
11101 : : /* set dcb default configuration */
11102 : : hw->local_dcbx_config.etscfg.willing = 0;
11103 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
11104 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11105 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
11106 : : I40E_IEEE_TSA_ETS;
11107 : : /* all UPs mapping to TC0 */
11108 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11109 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11110 : 0 : hw->local_dcbx_config.etsrec =
11111 : : hw->local_dcbx_config.etscfg;
11112 : : hw->local_dcbx_config.pfc.willing = 0;
11113 : 0 : hw->local_dcbx_config.pfc.pfccap =
11114 : : I40E_MAX_TRAFFIC_CLASS;
11115 : : /* FW needs one App to configure HW */
11116 : 0 : hw->local_dcbx_config.numapps = 1;
11117 : 0 : hw->local_dcbx_config.app[0].selector =
11118 : : I40E_APP_SEL_ETHTYPE;
11119 : 0 : hw->local_dcbx_config.app[0].priority = 3;
11120 : 0 : hw->local_dcbx_config.app[0].protocolid =
11121 : : I40E_APP_PROTOID_FCOE;
11122 : 0 : ret = i40e_set_dcb_config(hw);
11123 [ # # ]: 0 : if (ret) {
11124 : 0 : PMD_INIT_LOG(ERR,
11125 : : "default dcb config fails. err = %d, aq_err = %d.",
11126 : : ret, hw->aq.asq_last_status);
11127 : 0 : return -ENOSYS;
11128 : : }
11129 : : } else {
11130 : 0 : PMD_INIT_LOG(ERR,
11131 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
11132 : : ret, hw->aq.asq_last_status);
11133 : 0 : return -ENOTSUP;
11134 : : }
11135 : :
11136 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
11137 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11138 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11139 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11140 : : }
11141 : : } else {
11142 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11143 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11144 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11145 : :
11146 : 0 : ret = i40e_init_dcb(hw, true);
11147 [ # # ]: 0 : if (!ret) {
11148 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11149 : 0 : PMD_INIT_LOG(ERR,
11150 : : "HW doesn't support DCBX offload.");
11151 : 0 : return -ENOTSUP;
11152 : : }
11153 : : } else {
11154 : 0 : PMD_INIT_LOG(ERR,
11155 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11156 : : ret, hw->aq.asq_last_status);
11157 : 0 : return -ENOTSUP;
11158 : : }
11159 : : }
11160 : : return 0;
11161 : : }
11162 : :
11163 : : /*
11164 : : * i40e_dcb_setup - setup dcb related config
11165 : : * @dev: device being configured
11166 : : *
11167 : : * Returns 0 on success, negative value on failure
11168 : : */
11169 : : static int
11170 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11171 : : {
11172 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11173 : : struct i40e_dcbx_config dcb_cfg;
11174 : 0 : uint8_t tc_map = 0;
11175 : : int ret = 0;
11176 : :
11177 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11178 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11179 : 0 : return -ENOTSUP;
11180 : : }
11181 : :
11182 [ # # ]: 0 : if (pf->vf_num != 0)
11183 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11184 : :
11185 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11186 [ # # ]: 0 : if (ret) {
11187 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11188 : 0 : return -EINVAL;
11189 : : }
11190 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11191 [ # # ]: 0 : if (ret) {
11192 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11193 : 0 : return -ENOSYS;
11194 : : }
11195 : :
11196 : : return 0;
11197 : : }
11198 : :
11199 : : static int
11200 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11201 : : struct rte_eth_dcb_info *dcb_info)
11202 : : {
11203 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11204 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11205 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11206 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11207 : : uint16_t bsf, tc_mapping;
11208 : : int i, j = 0;
11209 : :
11210 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11211 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11212 : : else
11213 : 0 : dcb_info->nb_tcs = 1;
11214 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11215 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11216 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11217 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11218 : :
11219 : : /* get queue mapping if vmdq is disabled */
11220 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11221 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11222 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11223 : 0 : continue;
11224 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11225 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11226 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11227 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11228 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11229 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11230 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11231 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11232 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11233 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11234 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11235 : : }
11236 : : return 0;
11237 : : }
11238 : :
11239 : : /* get queue mapping if vmdq is enabled */
11240 : : do {
11241 : 0 : vsi = pf->vmdq[j].vsi;
11242 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11243 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11244 : 0 : continue;
11245 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11246 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11247 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11248 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11249 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11250 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11251 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11252 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11253 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11254 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11255 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11256 : : }
11257 : 0 : j++;
11258 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11259 : : return 0;
11260 : : }
11261 : :
11262 : : static int
11263 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11264 : : {
11265 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11266 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11267 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11268 : : uint16_t msix_intr;
11269 : :
11270 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11271 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11272 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11273 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11274 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11275 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11276 : : else
11277 : 0 : I40E_WRITE_REG(hw,
11278 : : I40E_PFINT_DYN_CTLN(msix_intr -
11279 : : I40E_RX_VEC_START),
11280 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11281 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11282 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11283 : :
11284 : 0 : I40E_WRITE_FLUSH(hw);
11285 : 0 : rte_intr_ack(pci_dev->intr_handle);
11286 : :
11287 : 0 : return 0;
11288 : : }
11289 : :
11290 : : static int
11291 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11292 : : {
11293 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11294 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11295 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11296 : : uint16_t msix_intr;
11297 : :
11298 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11299 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11300 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11301 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11302 : : else
11303 : 0 : I40E_WRITE_REG(hw,
11304 : : I40E_PFINT_DYN_CTLN(msix_intr -
11305 : : I40E_RX_VEC_START),
11306 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11307 : 0 : I40E_WRITE_FLUSH(hw);
11308 : :
11309 : 0 : return 0;
11310 : : }
11311 : :
11312 : : /**
11313 : : * This function is used to check if the register is valid.
11314 : : * Below is the valid registers list for X722 only:
11315 : : * 0x2b800--0x2bb00
11316 : : * 0x38700--0x38a00
11317 : : * 0x3d800--0x3db00
11318 : : * 0x208e00--0x209000
11319 : : * 0x20be00--0x20c000
11320 : : * 0x263c00--0x264000
11321 : : * 0x265c00--0x266000
11322 : : */
11323 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11324 : : {
11325 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11326 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11327 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11328 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11329 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11330 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11331 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11332 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11333 : : return 0;
11334 : : else
11335 : 0 : return 1;
11336 : : }
11337 : :
11338 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11339 : : struct rte_dev_reg_info *regs)
11340 : : {
11341 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11342 : 0 : uint32_t *ptr_data = regs->data;
11343 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11344 : : const struct i40e_reg_info *reg_info;
11345 : :
11346 [ # # ]: 0 : if (ptr_data == NULL) {
11347 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11348 : 0 : regs->width = sizeof(uint32_t);
11349 : 0 : return 0;
11350 : : }
11351 : :
11352 : : /* The first few registers have to be read using AQ operations */
11353 : : reg_idx = 0;
11354 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11355 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11356 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11357 : : for (arr_idx2 = 0;
11358 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11359 : 0 : arr_idx2++) {
11360 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11361 : 0 : arr_idx2 * reg_info->stride2;
11362 : 0 : reg_offset += reg_info->base_addr;
11363 : 0 : ptr_data[reg_offset >> 2] =
11364 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11365 : : }
11366 : : }
11367 : :
11368 : : /* The remaining registers can be read using primitives */
11369 : : reg_idx = 0;
11370 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11371 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11372 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11373 : : for (arr_idx2 = 0;
11374 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11375 : 0 : arr_idx2++) {
11376 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11377 : 0 : arr_idx2 * reg_info->stride2;
11378 : 0 : reg_offset += reg_info->base_addr;
11379 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11380 : 0 : ptr_data[reg_offset >> 2] = 0;
11381 : : else
11382 : 0 : ptr_data[reg_offset >> 2] =
11383 : 0 : I40E_READ_REG(hw, reg_offset);
11384 : : }
11385 : : }
11386 : :
11387 : : return 0;
11388 : : }
11389 : :
11390 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11391 : : {
11392 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11393 : :
11394 : : /* Convert word count to byte count */
11395 : 0 : return hw->nvm.sr_size << 1;
11396 : : }
11397 : :
11398 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11399 : : struct rte_dev_eeprom_info *eeprom)
11400 : : {
11401 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11402 : 0 : uint16_t *data = eeprom->data;
11403 : : uint32_t offset, length;
11404 : : uint16_t cnt_words;
11405 : : int ret_code;
11406 : :
11407 : 0 : offset = eeprom->offset >> 1;
11408 : 0 : length = eeprom->length >> 1;
11409 : 0 : cnt_words = length;
11410 : :
11411 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11412 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11413 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11414 : 0 : return -EINVAL;
11415 : : }
11416 : :
11417 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11418 : :
11419 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11420 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11421 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11422 : 0 : return -EIO;
11423 : : }
11424 : :
11425 : : return 0;
11426 : : }
11427 : :
11428 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11429 : : struct rte_eth_dev_module_info *modinfo)
11430 : : {
11431 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11432 : 0 : uint32_t sff8472_comp = 0;
11433 : 0 : uint32_t sff8472_swap = 0;
11434 : 0 : uint32_t sff8636_rev = 0;
11435 : : i40e_status status;
11436 : : uint32_t type = 0;
11437 : :
11438 : : /* Check if firmware supports reading module EEPROM. */
11439 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11440 : 0 : PMD_DRV_LOG(ERR,
11441 : : "Module EEPROM memory read not supported. "
11442 : : "Please update the NVM image.");
11443 : 0 : return -EINVAL;
11444 : : }
11445 : :
11446 : 0 : status = i40e_update_link_info(hw);
11447 [ # # ]: 0 : if (status)
11448 : : return -EIO;
11449 : :
11450 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11451 : 0 : PMD_DRV_LOG(ERR,
11452 : : "Cannot read module EEPROM memory. "
11453 : : "No module connected.");
11454 : 0 : return -EINVAL;
11455 : : }
11456 : :
11457 : 0 : type = hw->phy.link_info.module_type[0];
11458 : :
11459 [ # # # # ]: 0 : switch (type) {
11460 : 0 : case I40E_MODULE_TYPE_SFP:
11461 : 0 : status = i40e_aq_get_phy_register(hw,
11462 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11463 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11464 : : I40E_MODULE_SFF_8472_COMP,
11465 : : &sff8472_comp, NULL);
11466 [ # # ]: 0 : if (status)
11467 : : return -EIO;
11468 : :
11469 : 0 : status = i40e_aq_get_phy_register(hw,
11470 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11471 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11472 : : I40E_MODULE_SFF_8472_SWAP,
11473 : : &sff8472_swap, NULL);
11474 [ # # ]: 0 : if (status)
11475 : : return -EIO;
11476 : :
11477 : : /* Check if the module requires address swap to access
11478 : : * the other EEPROM memory page.
11479 : : */
11480 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11481 : 0 : PMD_DRV_LOG(WARNING,
11482 : : "Module address swap to access "
11483 : : "page 0xA2 is not supported.");
11484 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11485 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11486 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11487 : : /* Module is not SFF-8472 compliant */
11488 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11489 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11490 : : } else {
11491 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11492 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11493 : : }
11494 : : break;
11495 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11496 : : /* Read from memory page 0. */
11497 : 0 : status = i40e_aq_get_phy_register(hw,
11498 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11499 : : 0, 1,
11500 : : I40E_MODULE_REVISION_ADDR,
11501 : : &sff8636_rev, NULL);
11502 [ # # ]: 0 : if (status)
11503 : : return -EIO;
11504 : : /* Determine revision compliance byte */
11505 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11506 : : /* Module is SFF-8636 compliant */
11507 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11508 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11509 : : } else {
11510 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11511 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11512 : : }
11513 : : break;
11514 : 0 : case I40E_MODULE_TYPE_QSFP28:
11515 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11516 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11517 : 0 : break;
11518 : 0 : default:
11519 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized");
11520 : 0 : return -EINVAL;
11521 : : }
11522 : : return 0;
11523 : : }
11524 : :
11525 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11526 : : struct rte_dev_eeprom_info *info)
11527 : : {
11528 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11529 : : bool is_sfp = false;
11530 : : i40e_status status;
11531 : : uint8_t *data;
11532 : 0 : uint32_t value = 0;
11533 : : uint32_t i;
11534 : :
11535 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11536 : : is_sfp = true;
11537 : :
11538 : 0 : data = info->data;
11539 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11540 : 0 : u32 offset = i + info->offset;
11541 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11542 : :
11543 : : /* Check if we need to access the other memory page */
11544 [ # # ]: 0 : if (is_sfp) {
11545 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11546 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11547 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11548 : : }
11549 : : } else {
11550 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11551 : : /* Compute memory page number and offset. */
11552 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11553 : 0 : addr++;
11554 : : }
11555 : : }
11556 : 0 : status = i40e_aq_get_phy_register(hw,
11557 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11558 : : addr, 1, offset, &value, NULL);
11559 [ # # ]: 0 : if (status)
11560 : : return -EIO;
11561 : 0 : data[i] = (uint8_t)value;
11562 : : }
11563 : : return 0;
11564 : : }
11565 : :
11566 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11567 : : struct rte_ether_addr *mac_addr)
11568 : : {
11569 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11570 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11571 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11572 : : struct i40e_mac_filter_info mac_filter;
11573 : : struct i40e_mac_filter *f;
11574 : : int ret;
11575 : :
11576 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11577 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11578 : 0 : return -EINVAL;
11579 : : }
11580 : :
11581 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11582 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11583 : : &f->mac_info.mac_addr))
11584 : : break;
11585 : : }
11586 : :
11587 [ # # ]: 0 : if (f == NULL) {
11588 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11589 : 0 : return -EIO;
11590 : : }
11591 : :
11592 : 0 : mac_filter = f->mac_info;
11593 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11594 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11595 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11596 : 0 : return -EIO;
11597 : : }
11598 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11599 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11600 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11601 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11602 : 0 : return -EIO;
11603 : : }
11604 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11605 : :
11606 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11607 : 0 : mac_addr->addr_bytes, NULL);
11608 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11609 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11610 : 0 : return -EIO;
11611 : : }
11612 : :
11613 : : return 0;
11614 : : }
11615 : :
11616 : : static int
11617 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11618 : : {
11619 : : /* mtu setting is forbidden if port is start */
11620 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11621 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11622 : : dev->data->port_id);
11623 : 0 : return -EBUSY;
11624 : : }
11625 : :
11626 : : return 0;
11627 : : }
11628 : :
11629 : : /* Restore ethertype filter */
11630 : : static void
11631 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11632 : : {
11633 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11634 : : struct i40e_ethertype_filter_list
11635 : : *ethertype_list = &pf->ethertype.ethertype_list;
11636 : : struct i40e_ethertype_filter *f;
11637 : : struct i40e_control_filter_stats stats;
11638 : : uint16_t flags;
11639 : :
11640 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11641 : : flags = 0;
11642 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11643 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11644 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11645 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11646 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11647 : :
11648 : : memset(&stats, 0, sizeof(stats));
11649 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11650 : 0 : f->input.mac_addr.addr_bytes,
11651 : 0 : f->input.ether_type,
11652 : 0 : flags, pf->main_vsi->seid,
11653 : 0 : f->queue, 1, &stats, NULL);
11654 : : }
11655 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11656 : : " mac_etype_used = %u, etype_used = %u,"
11657 : : " mac_etype_free = %u, etype_free = %u",
11658 : : stats.mac_etype_used, stats.etype_used,
11659 : : stats.mac_etype_free, stats.etype_free);
11660 : 0 : }
11661 : :
11662 : : /* Restore tunnel filter */
11663 : : static void
11664 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11665 : : {
11666 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11667 : : struct i40e_vsi *vsi;
11668 : : struct i40e_pf_vf *vf;
11669 : : struct i40e_tunnel_filter_list
11670 : : *tunnel_list = &pf->tunnel.tunnel_list;
11671 : : struct i40e_tunnel_filter *f;
11672 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11673 : : bool big_buffer = 0;
11674 : :
11675 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11676 [ # # ]: 0 : if (!f->is_to_vf)
11677 : 0 : vsi = pf->main_vsi;
11678 : : else {
11679 : 0 : vf = &pf->vfs[f->vf_id];
11680 : 0 : vsi = vf->vsi;
11681 : : }
11682 : : memset(&cld_filter, 0, sizeof(cld_filter));
11683 : : rte_ether_addr_copy((struct rte_ether_addr *)
11684 : : &f->input.outer_mac,
11685 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11686 : : rte_ether_addr_copy((struct rte_ether_addr *)
11687 : : &f->input.inner_mac,
11688 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11689 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11690 : 0 : cld_filter.element.flags = f->input.flags;
11691 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11692 : 0 : cld_filter.element.queue_number = f->queue;
11693 : : memcpy(cld_filter.general_fields,
11694 [ # # ]: 0 : f->input.general_fields,
11695 : : sizeof(f->input.general_fields));
11696 : :
11697 [ # # ]: 0 : if (((f->input.flags &
11698 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11699 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11700 : : ((f->input.flags &
11701 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11702 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11703 : : ((f->input.flags &
11704 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11705 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11706 : : big_buffer = 1;
11707 : :
11708 [ # # ]: 0 : if (big_buffer)
11709 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11710 : 0 : vsi->seid, &cld_filter, 1);
11711 : : else
11712 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11713 : : &cld_filter.element, 1);
11714 : : }
11715 : 0 : }
11716 : :
11717 : : static void
11718 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11719 : : {
11720 : 0 : i40e_ethertype_filter_restore(pf);
11721 : 0 : i40e_tunnel_filter_restore(pf);
11722 : 0 : i40e_fdir_filter_restore(pf);
11723 : 0 : (void)i40e_hash_filter_restore(pf);
11724 : 0 : }
11725 : :
11726 : : bool
11727 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11728 : : {
11729 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11730 : 0 : return false;
11731 : :
11732 : : return true;
11733 : : }
11734 : :
11735 : : bool
11736 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11737 : : {
11738 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11739 : : }
11740 : :
11741 : : struct i40e_customized_pctype*
11742 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11743 : : {
11744 : : int i;
11745 : :
11746 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11747 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11748 : 0 : return &pf->customized_pctype[i];
11749 : : }
11750 : : return NULL;
11751 : : }
11752 : :
11753 : : static int
11754 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11755 : : uint32_t pkg_size, uint32_t proto_num,
11756 : : struct rte_pmd_i40e_proto_info *proto,
11757 : : enum rte_pmd_i40e_package_op op)
11758 : : {
11759 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11760 : : uint32_t pctype_num;
11761 : 0 : struct rte_pmd_i40e_ptype_info pctype[I40E_CUSTOMIZED_MAX] = {0};
11762 : : struct i40e_customized_pctype *new_pctype = NULL;
11763 : : uint8_t proto_id;
11764 : : uint8_t pctype_value;
11765 : : char name[64];
11766 : : uint32_t i, j, n;
11767 : : int ret;
11768 : :
11769 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11770 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11771 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11772 : 0 : return -1;
11773 : : }
11774 : :
11775 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11776 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11777 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11778 [ # # ]: 0 : if (ret) {
11779 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11780 : 0 : return -1;
11781 : : }
11782 [ # # ]: 0 : if (!pctype_num) {
11783 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11784 : 0 : return -1;
11785 : : }
11786 : :
11787 [ # # ]: 0 : if (pctype_num > RTE_DIM(pctype)) {
11788 : 0 : PMD_DRV_LOG(ERR, "Pctype number exceeds maximum supported");
11789 : 0 : return -1;
11790 : : }
11791 : : /* get information about new pctype list */
11792 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11793 : : (uint8_t *)pctype, sizeof(pctype),
11794 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11795 [ # # ]: 0 : if (ret) {
11796 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11797 : 0 : return -1;
11798 : : }
11799 : :
11800 : : /* Update customized pctype. */
11801 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11802 : 0 : pctype_value = pctype[i].ptype_id;
11803 : : memset(name, 0, sizeof(name));
11804 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11805 : 0 : proto_id = pctype[i].protocols[j];
11806 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11807 : 0 : continue;
11808 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11809 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11810 : : continue;
11811 : 0 : strlcat(name, proto[n].name, sizeof(name));
11812 : 0 : strlcat(name, "_", sizeof(name));
11813 : 0 : break;
11814 : : }
11815 : : }
11816 : 0 : name[strlen(name) - 1] = '\0';
11817 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11818 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11819 : : new_pctype =
11820 : 0 : i40e_find_customized_pctype(pf,
11821 : : I40E_CUSTOMIZED_GTPC);
11822 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11823 : : new_pctype =
11824 : 0 : i40e_find_customized_pctype(pf,
11825 : : I40E_CUSTOMIZED_GTPU_IPV4);
11826 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11827 : : new_pctype =
11828 : 0 : i40e_find_customized_pctype(pf,
11829 : : I40E_CUSTOMIZED_GTPU_IPV6);
11830 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11831 : : new_pctype =
11832 : 0 : i40e_find_customized_pctype(pf,
11833 : : I40E_CUSTOMIZED_GTPU);
11834 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11835 : : new_pctype =
11836 : 0 : i40e_find_customized_pctype(pf,
11837 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11838 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11839 : : new_pctype =
11840 : 0 : i40e_find_customized_pctype(pf,
11841 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11842 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11843 : : new_pctype =
11844 : 0 : i40e_find_customized_pctype(pf,
11845 : : I40E_CUSTOMIZED_ESP_IPV4);
11846 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11847 : : new_pctype =
11848 : 0 : i40e_find_customized_pctype(pf,
11849 : : I40E_CUSTOMIZED_ESP_IPV6);
11850 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11851 : : new_pctype =
11852 : 0 : i40e_find_customized_pctype(pf,
11853 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11854 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11855 : : new_pctype =
11856 : 0 : i40e_find_customized_pctype(pf,
11857 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11858 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11859 : : new_pctype =
11860 : 0 : i40e_find_customized_pctype(pf,
11861 : : I40E_CUSTOMIZED_AH_IPV4);
11862 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11863 : : new_pctype =
11864 : 0 : i40e_find_customized_pctype(pf,
11865 : : I40E_CUSTOMIZED_AH_IPV6);
11866 [ # # ]: 0 : if (new_pctype) {
11867 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11868 : 0 : new_pctype->pctype = pctype_value;
11869 : 0 : new_pctype->valid = true;
11870 : : } else {
11871 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11872 : 0 : new_pctype->valid = false;
11873 : : }
11874 : : }
11875 : : }
11876 : :
11877 : : return 0;
11878 : : }
11879 : :
11880 : : static int
11881 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11882 : : uint32_t pkg_size, uint32_t proto_num,
11883 : : struct rte_pmd_i40e_proto_info *proto,
11884 : : enum rte_pmd_i40e_package_op op)
11885 : : {
11886 : 0 : struct rte_pmd_i40e_ptype_mapping ptype_mapping[I40E_MAX_PKT_TYPE] = {0};
11887 : 0 : uint16_t port_id = dev->data->port_id;
11888 : : uint32_t ptype_num;
11889 : 0 : struct rte_pmd_i40e_ptype_info ptype[I40E_MAX_PKT_TYPE] = {0};
11890 : : uint8_t proto_id;
11891 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11892 : : uint32_t i, j, n;
11893 : : bool in_tunnel;
11894 : : int ret;
11895 : :
11896 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11897 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11898 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11899 : 0 : return -1;
11900 : : }
11901 : :
11902 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11903 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11904 : 0 : return 0;
11905 : : }
11906 : :
11907 : : /* get information about new ptype num */
11908 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11909 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11910 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11911 [ # # ]: 0 : if (ret) {
11912 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11913 : 0 : return ret;
11914 : : }
11915 [ # # ]: 0 : if (!ptype_num) {
11916 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11917 : 0 : return -1;
11918 : : }
11919 : :
11920 [ # # ]: 0 : if (ptype_num > RTE_DIM(ptype)) {
11921 : 0 : PMD_DRV_LOG(ERR, "Too many ptypes");
11922 : 0 : return -1;
11923 : : }
11924 : :
11925 : : /* get information about new ptype list */
11926 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11927 : : (uint8_t *)ptype, sizeof(ptype),
11928 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11929 [ # # ]: 0 : if (ret) {
11930 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11931 : 0 : return ret;
11932 : : }
11933 : :
11934 : : /* Update ptype mapping table. */
11935 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11936 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11937 : 0 : ptype_mapping[i].sw_ptype = 0;
11938 : : in_tunnel = false;
11939 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11940 : 0 : proto_id = ptype[i].protocols[j];
11941 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11942 : 0 : continue;
11943 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11944 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11945 : : continue;
11946 : 0 : strlcpy(name, proto[n].name, sizeof(name));
11947 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11948 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11949 : 0 : ptype_mapping[i].sw_ptype |=
11950 : : RTE_PTYPE_L2_ETHER_PPPOE;
11951 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11952 : : !in_tunnel) {
11953 : 0 : ptype_mapping[i].sw_ptype |=
11954 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11955 : 0 : ptype_mapping[i].sw_ptype |=
11956 : : RTE_PTYPE_L4_FRAG;
11957 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11958 : : in_tunnel) {
11959 : 0 : ptype_mapping[i].sw_ptype |=
11960 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11961 : 0 : ptype_mapping[i].sw_ptype |=
11962 : : RTE_PTYPE_INNER_L4_FRAG;
11963 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11964 : 0 : ptype_mapping[i].sw_ptype |=
11965 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11966 : : in_tunnel = true;
11967 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11968 : : !in_tunnel)
11969 : 0 : ptype_mapping[i].sw_ptype |=
11970 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11971 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11972 : : in_tunnel)
11973 : 0 : ptype_mapping[i].sw_ptype |=
11974 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11975 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11976 : : !in_tunnel) {
11977 : 0 : ptype_mapping[i].sw_ptype |=
11978 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11979 : 0 : ptype_mapping[i].sw_ptype |=
11980 : : RTE_PTYPE_L4_FRAG;
11981 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11982 : : in_tunnel) {
11983 : 0 : ptype_mapping[i].sw_ptype |=
11984 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11985 : 0 : ptype_mapping[i].sw_ptype |=
11986 : : RTE_PTYPE_INNER_L4_FRAG;
11987 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
11988 : 0 : ptype_mapping[i].sw_ptype |=
11989 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11990 : : in_tunnel = true;
11991 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
11992 : : !in_tunnel)
11993 : 0 : ptype_mapping[i].sw_ptype |=
11994 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11995 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
11996 : : in_tunnel)
11997 : 0 : ptype_mapping[i].sw_ptype |=
11998 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11999 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
12000 : : !in_tunnel)
12001 : 0 : ptype_mapping[i].sw_ptype |=
12002 : : RTE_PTYPE_L4_UDP;
12003 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
12004 : : in_tunnel)
12005 : 0 : ptype_mapping[i].sw_ptype |=
12006 : : RTE_PTYPE_INNER_L4_UDP;
12007 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
12008 : : !in_tunnel)
12009 : 0 : ptype_mapping[i].sw_ptype |=
12010 : : RTE_PTYPE_L4_TCP;
12011 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
12012 : : in_tunnel)
12013 : 0 : ptype_mapping[i].sw_ptype |=
12014 : : RTE_PTYPE_INNER_L4_TCP;
12015 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
12016 : : !in_tunnel)
12017 : 0 : ptype_mapping[i].sw_ptype |=
12018 : : RTE_PTYPE_L4_SCTP;
12019 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
12020 : : in_tunnel)
12021 : 0 : ptype_mapping[i].sw_ptype |=
12022 : : RTE_PTYPE_INNER_L4_SCTP;
12023 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12024 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12025 : : !in_tunnel)
12026 : 0 : ptype_mapping[i].sw_ptype |=
12027 : : RTE_PTYPE_L4_ICMP;
12028 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12029 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12030 : : in_tunnel)
12031 : 0 : ptype_mapping[i].sw_ptype |=
12032 : : RTE_PTYPE_INNER_L4_ICMP;
12033 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
12034 : 0 : ptype_mapping[i].sw_ptype |=
12035 : : RTE_PTYPE_TUNNEL_GTPC;
12036 : : in_tunnel = true;
12037 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
12038 : 0 : ptype_mapping[i].sw_ptype |=
12039 : : RTE_PTYPE_TUNNEL_GTPU;
12040 : : in_tunnel = true;
12041 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
12042 : 0 : ptype_mapping[i].sw_ptype |=
12043 : : RTE_PTYPE_TUNNEL_ESP;
12044 : : in_tunnel = true;
12045 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
12046 : 0 : ptype_mapping[i].sw_ptype |=
12047 : : RTE_PTYPE_TUNNEL_GRENAT;
12048 : : in_tunnel = true;
12049 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12050 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
12051 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
12052 : 0 : ptype_mapping[i].sw_ptype |=
12053 : : RTE_PTYPE_TUNNEL_L2TP;
12054 : : in_tunnel = true;
12055 : : }
12056 : :
12057 : : break;
12058 : : }
12059 : : }
12060 : : }
12061 : :
12062 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12063 : : ptype_num, 0);
12064 [ # # ]: 0 : if (ret)
12065 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12066 : :
12067 : : return ret;
12068 : : }
12069 : :
12070 : : void
12071 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12072 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12073 : : {
12074 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12075 : : uint32_t proto_num;
12076 : : struct rte_pmd_i40e_proto_info *proto;
12077 : : uint32_t buff_size;
12078 : : uint32_t i;
12079 : : int ret;
12080 : :
12081 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12082 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12083 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
12084 : 0 : return;
12085 : : }
12086 : :
12087 : : /* get information about protocol number */
12088 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12089 : : (uint8_t *)&proto_num, sizeof(proto_num),
12090 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12091 [ # # ]: 0 : if (ret) {
12092 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
12093 : 0 : return;
12094 : : }
12095 [ # # ]: 0 : if (!proto_num) {
12096 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
12097 : 0 : return;
12098 : : }
12099 : :
12100 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12101 : 0 : proto = calloc(proto_num, sizeof(struct rte_pmd_i40e_proto_info));
12102 [ # # ]: 0 : if (!proto) {
12103 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
12104 : 0 : return;
12105 : : }
12106 : :
12107 : : /* get information about protocol list */
12108 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12109 : : (uint8_t *)proto, buff_size,
12110 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12111 [ # # ]: 0 : if (ret) {
12112 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
12113 : 0 : free(proto);
12114 : 0 : return;
12115 : : }
12116 : :
12117 : : /* Check if GTP is supported. */
12118 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12119 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12120 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12121 : 0 : pf->gtp_support = true;
12122 : : else
12123 : 0 : pf->gtp_support = false;
12124 : : break;
12125 : : }
12126 : : }
12127 : :
12128 : : /* Check if ESP is supported. */
12129 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12130 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12131 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12132 : 0 : pf->esp_support = true;
12133 : : else
12134 : 0 : pf->esp_support = false;
12135 : : break;
12136 : : }
12137 : : }
12138 : :
12139 : : /* Update customized pctype info */
12140 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12141 : : proto_num, proto, op);
12142 [ # # ]: 0 : if (ret)
12143 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12144 : :
12145 : : /* Update customized ptype info */
12146 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12147 : : proto_num, proto, op);
12148 [ # # ]: 0 : if (ret)
12149 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12150 : :
12151 : 0 : free(proto);
12152 : : }
12153 : :
12154 : : /* Create a QinQ cloud filter
12155 : : *
12156 : : * The Fortville NIC has limited resources for tunnel filters,
12157 : : * so we can only reuse existing filters.
12158 : : *
12159 : : * In step 1 we define which Field Vector fields can be used for
12160 : : * filter types.
12161 : : * As we do not have the inner tag defined as a field,
12162 : : * we have to define it first, by reusing one of L1 entries.
12163 : : *
12164 : : * In step 2 we are replacing one of existing filter types with
12165 : : * a new one for QinQ.
12166 : : * As we reusing L1 and replacing L2, some of the default filter
12167 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12168 : : *
12169 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12170 : : *
12171 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12172 : : * later when we define the cloud filter.
12173 : : * a. Valid_flags.replace_cloud = 0
12174 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12175 : : * c. New_filter = 0x10
12176 : : * d. TR bit = 0xff (optional, not used here)
12177 : : * e. Buffer – 2 entries:
12178 : : * i. Byte 0 = 8 (outer vlan FV index).
12179 : : * Byte 1 = 0 (rsv)
12180 : : * Byte 2-3 = 0x0fff
12181 : : * ii. Byte 0 = 37 (inner vlan FV index).
12182 : : * Byte 1 =0 (rsv)
12183 : : * Byte 2-3 = 0x0fff
12184 : : *
12185 : : * Step 2:
12186 : : * 2. Create cloud filter using two L1 filters entries: stag and
12187 : : * new filter(outer vlan+ inner vlan)
12188 : : * a. Valid_flags.replace_cloud = 1
12189 : : * b. Old_filter = 1 (instead of outer IP)
12190 : : * c. New_filter = 0x10
12191 : : * d. Buffer – 2 entries:
12192 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12193 : : * Byte 1-3 = 0 (rsv)
12194 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12195 : : * Byte 9-11 = 0 (rsv)
12196 : : */
12197 : : static int
12198 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12199 : : {
12200 : : int ret = -ENOTSUP;
12201 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12202 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12203 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12204 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12205 : :
12206 [ # # ]: 0 : if (pf->support_multi_driver) {
12207 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12208 : 0 : return ret;
12209 : : }
12210 : :
12211 : : /* Init */
12212 : : memset(&filter_replace, 0,
12213 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12214 : : memset(&filter_replace_buf, 0,
12215 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12216 : :
12217 : : /* create L1 filter */
12218 : 0 : filter_replace.old_filter_type =
12219 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12220 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12221 : : filter_replace.tr_bit = 0;
12222 : :
12223 : : /* Prepare the buffer, 2 entries */
12224 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12225 : 0 : filter_replace_buf.data[0] |=
12226 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12227 : : /* Field Vector 12b mask */
12228 : 0 : filter_replace_buf.data[2] = 0xff;
12229 : 0 : filter_replace_buf.data[3] = 0x0f;
12230 : : filter_replace_buf.data[4] =
12231 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12232 : 0 : filter_replace_buf.data[4] |=
12233 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12234 : : /* Field Vector 12b mask */
12235 : 0 : filter_replace_buf.data[6] = 0xff;
12236 : 0 : filter_replace_buf.data[7] = 0x0f;
12237 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12238 : : &filter_replace_buf);
12239 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12240 : : return ret;
12241 : :
12242 : 0 : if (filter_replace.old_filter_type !=
12243 [ # # ]: 0 : filter_replace.new_filter_type)
12244 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12245 : : " original: 0x%x, new: 0x%x",
12246 : : dev->device->name,
12247 : : filter_replace.old_filter_type,
12248 : : filter_replace.new_filter_type);
12249 : :
12250 : : /* Apply the second L2 cloud filter */
12251 : : memset(&filter_replace, 0,
12252 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12253 : : memset(&filter_replace_buf, 0,
12254 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12255 : :
12256 : : /* create L2 filter, input for L2 filter will be L1 filter */
12257 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12258 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12259 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12260 : :
12261 : : /* Prepare the buffer, 2 entries */
12262 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12263 : 0 : filter_replace_buf.data[0] |=
12264 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12265 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12266 : 0 : filter_replace_buf.data[4] |=
12267 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12268 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12269 : : &filter_replace_buf);
12270 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12271 [ # # ]: 0 : filter_replace.new_filter_type))
12272 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12273 : : " original: 0x%x, new: 0x%x",
12274 : : dev->device->name,
12275 : : filter_replace.old_filter_type,
12276 : : filter_replace.new_filter_type);
12277 : :
12278 : : return ret;
12279 : : }
12280 : :
12281 : : static int
12282 : 0 : i40e_fec_get_capability(struct rte_eth_dev *dev,
12283 : : struct rte_eth_fec_capa *speed_fec_capa, __rte_unused unsigned int num)
12284 : : {
12285 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12286 : :
12287 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12288 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12289 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12290 : : " firmware. Please update the NVM image.");
12291 : 0 : return -ENOTSUP;
12292 : : }
12293 : :
12294 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_25G_SFP28 ||
12295 : : hw->device_id == I40E_DEV_ID_25G_B) {
12296 [ # # ]: 0 : if (speed_fec_capa) {
12297 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12298 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
12299 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
12300 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12301 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12302 : : }
12303 : :
12304 : : /* since HW only supports 25G */
12305 : 0 : return 1;
12306 [ # # ]: 0 : } else if (hw->device_id == I40E_DEV_ID_KX_X722) {
12307 [ # # ]: 0 : if (speed_fec_capa) {
12308 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12309 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12310 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12311 : : }
12312 : 0 : return 1;
12313 : : }
12314 : :
12315 : : return -ENOTSUP;
12316 : : }
12317 : :
12318 : : static int
12319 : 0 : i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
12320 : : {
12321 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12322 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12323 : 0 : struct i40e_link_status link_status = {0};
12324 : : uint8_t current_fec_mode = 0, fec_config = 0;
12325 : : bool link_up, enable_lse;
12326 : : int ret = 0;
12327 : :
12328 : 0 : enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
12329 : : /* Get link info */
12330 : 0 : ret = i40e_aq_get_link_info(hw, enable_lse, &link_status, NULL);
12331 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
12332 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
12333 : : ret);
12334 : 0 : return -ENOTSUP;
12335 : : }
12336 : :
12337 : 0 : link_up = link_status.link_info & I40E_AQ_LINK_UP;
12338 : :
12339 : 0 : ret = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12340 : : NULL);
12341 [ # # ]: 0 : if (ret) {
12342 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12343 : : ret);
12344 : 0 : return -ENOTSUP;
12345 : : }
12346 : :
12347 : : /**
12348 : : * If link is down and AUTO is enabled, AUTO is returned,
12349 : : * otherwise, configured FEC mode is returned.
12350 : : * If link is up, current FEC mode is returned.
12351 : : */
12352 : 0 : fec_config = abilities.fec_cfg_curr_mod_ext_info
12353 : : & I40E_AQ_PHY_FEC_CONFIG_MASK;
12354 : 0 : current_fec_mode = link_status.fec_info;
12355 : :
12356 [ # # ]: 0 : if (link_up) {
12357 [ # # # # ]: 0 : switch (current_fec_mode) {
12358 : 0 : case I40E_AQ_CONFIG_FEC_KR_ENA:
12359 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12360 : 0 : break;
12361 : 0 : case I40E_AQ_CONFIG_FEC_RS_ENA:
12362 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12363 : 0 : break;
12364 : 0 : case 0:
12365 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12366 : 0 : break;
12367 : : default:
12368 : : return -EINVAL;
12369 : : }
12370 : 0 : return 0;
12371 : : }
12372 : :
12373 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_AUTO) {
12374 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO);
12375 : 0 : return 0;
12376 : : }
12377 : :
12378 : : uint32_t temp_fec_capa = 0;
12379 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_KR)
12380 : : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12381 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_RS)
12382 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12383 : : if (temp_fec_capa == 0)
12384 : : temp_fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12385 : :
12386 : 0 : *fec_capa = temp_fec_capa;
12387 : 0 : return 0;
12388 : : }
12389 : :
12390 : : static int
12391 : 0 : i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
12392 : : {
12393 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12394 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12395 : 0 : struct i40e_aq_set_phy_config config = {0};
12396 : : enum i40e_status_code status;
12397 : : uint8_t req_fec = 0, fec_auto = 0, fec_kr = 0, fec_rs = 0;
12398 : :
12399 : 0 : if (hw->device_id != I40E_DEV_ID_25G_SFP28 &&
12400 [ # # ]: 0 : hw->device_id != I40E_DEV_ID_25G_B &&
12401 : : hw->device_id != I40E_DEV_ID_KX_X722) {
12402 : : return -ENOTSUP;
12403 : : }
12404 : :
12405 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12406 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12407 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12408 : : " firmware. Please update the NVM image.");
12409 : 0 : return -ENOTSUP;
12410 : : }
12411 : :
12412 : : /**
12413 : : * Copy the current user PHY configuration. The current user PHY
12414 : : * configuration is initialized during probe from PHY capabilities
12415 : : * software mode, and updated on set PHY configuration.
12416 : : */
12417 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12418 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) | RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
12419 : : return -EINVAL;
12420 : :
12421 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
12422 : : fec_auto = 1;
12423 : :
12424 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
12425 : : fec_kr = 1;
12426 : :
12427 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
12428 : : fec_rs = 1;
12429 : :
12430 [ # # ]: 0 : if (fec_auto) {
12431 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12432 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: AUTO");
12433 : 0 : return -EINVAL;
12434 : : }
12435 [ # # ]: 0 : if (fec_kr || fec_rs) {
12436 [ # # ]: 0 : if (fec_kr)
12437 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12438 : : I40E_AQ_SET_FEC_REQUEST_KR;
12439 [ # # ]: 0 : if (fec_rs) {
12440 : : if (hw->mac.type == I40E_MAC_X722) {
12441 : : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12442 : : return -EINVAL;
12443 : : }
12444 : 0 : req_fec |= I40E_AQ_SET_FEC_ABILITY_RS |
12445 : : I40E_AQ_SET_FEC_REQUEST_RS;
12446 : : }
12447 : : } else {
12448 : : if (hw->mac.type == I40E_MAC_X722) {
12449 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12450 : : I40E_AQ_SET_FEC_REQUEST_KR;
12451 : : } else {
12452 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12453 : : I40E_AQ_SET_FEC_REQUEST_KR |
12454 : : I40E_AQ_SET_FEC_ABILITY_RS |
12455 : : I40E_AQ_SET_FEC_REQUEST_RS;
12456 : : }
12457 : : }
12458 : : } else {
12459 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
12460 [ # # ]: 0 : if (fec_kr) {
12461 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12462 : : I40E_AQ_SET_FEC_REQUEST_KR;
12463 : : } else {
12464 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12465 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12466 : 0 : return -EINVAL;
12467 : : }
12468 : : req_fec = I40E_AQ_SET_FEC_ABILITY_RS |
12469 : : I40E_AQ_SET_FEC_REQUEST_RS;
12470 : : }
12471 : : } else {
12472 : : return -EINVAL;
12473 : : }
12474 : : }
12475 : :
12476 : : /* Get the current phy config */
12477 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12478 : : NULL);
12479 [ # # ]: 0 : if (status) {
12480 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12481 : : status);
12482 : 0 : return -ENOTSUP;
12483 : : }
12484 : :
12485 [ # # ]: 0 : if (abilities.fec_cfg_curr_mod_ext_info != req_fec) {
12486 : 0 : config.phy_type = abilities.phy_type;
12487 : 0 : config.abilities = abilities.abilities |
12488 : : I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
12489 : 0 : config.phy_type_ext = abilities.phy_type_ext;
12490 : 0 : config.link_speed = abilities.link_speed;
12491 : 0 : config.eee_capability = abilities.eee_capability;
12492 : 0 : config.eeer = abilities.eeer_val;
12493 : 0 : config.low_power_ctrl = abilities.d3_lpan;
12494 : 0 : config.fec_config = req_fec & I40E_AQ_PHY_FEC_CONFIG_MASK;
12495 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
12496 [ # # ]: 0 : if (status) {
12497 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12498 : : status);
12499 : 0 : return -ENOTSUP;
12500 : : }
12501 : : }
12502 : :
12503 : 0 : status = i40e_update_link_info(hw);
12504 [ # # ]: 0 : if (status) {
12505 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12506 : : status);
12507 : 0 : return -ENOTSUP;
12508 : : }
12509 : :
12510 : : return 0;
12511 : : }
12512 : :
12513 [ - + ]: 302 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12514 [ - + ]: 302 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12515 : : #ifdef RTE_ETHDEV_DEBUG_RX
12516 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12517 : : #endif
12518 : : #ifdef RTE_ETHDEV_DEBUG_TX
12519 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12520 : : #endif
12521 : :
12522 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12523 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12524 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12525 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12526 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|