Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <ctype.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : : #include <assert.h>
14 : :
15 : : #include <rte_common.h>
16 : : #include <rte_eal.h>
17 : : #include <rte_string_fns.h>
18 : : #include <rte_pci.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ether.h>
21 : : #include <ethdev_driver.h>
22 : : #include <ethdev_pci.h>
23 : : #include <rte_memzone.h>
24 : : #include <rte_malloc.h>
25 : : #include <rte_memcpy.h>
26 : : #include <rte_alarm.h>
27 : : #include <dev_driver.h>
28 : : #include <rte_tailq.h>
29 : : #include <rte_hash_crc.h>
30 : : #include <rte_bitmap.h>
31 : : #include <rte_os_shim.h>
32 : :
33 : : #include "i40e_logs.h"
34 : : #include "base/i40e_prototype.h"
35 : : #include "base/i40e_adminq_cmd.h"
36 : : #include "base/i40e_type.h"
37 : : #include "base/i40e_register.h"
38 : : #include "base/i40e_dcb.h"
39 : : #include "i40e_ethdev.h"
40 : : #include "i40e_rxtx.h"
41 : : #include "i40e_pf.h"
42 : : #include "i40e_regs.h"
43 : : #include "rte_pmd_i40e.h"
44 : : #include "i40e_hash.h"
45 : :
46 : : #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
47 : : #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
48 : : #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
49 : : #define ETH_I40E_QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
50 : : #define ETH_I40E_VF_MSG_CFG "vf_msg_cfg"
51 : :
52 : : #define I40E_CLEAR_PXE_WAIT_MS 200
53 : : #define I40E_VSI_TSR_QINQ_STRIP 0x4010
54 : : #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
55 : :
56 : : /* Maximun number of capability elements */
57 : : #define I40E_MAX_CAP_ELE_NUM 128
58 : :
59 : : /* Wait count and interval */
60 : : #define I40E_CHK_Q_ENA_COUNT 1000
61 : : #define I40E_CHK_Q_ENA_INTERVAL_US 1000
62 : :
63 : : /* Maximun number of VSI */
64 : : #define I40E_MAX_NUM_VSIS (384UL)
65 : :
66 : : #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
67 : :
68 : : /* Flow control default timer */
69 : : #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
70 : :
71 : : /* Flow control enable fwd bit */
72 : : #define I40E_PRTMAC_FWD_CTRL 0x00000001
73 : :
74 : : /* Receive Packet Buffer size */
75 : : #define I40E_RXPBSIZE (968 * 1024)
76 : :
77 : : /* Kilobytes shift */
78 : : #define I40E_KILOSHIFT 10
79 : :
80 : : /* Flow control default high water */
81 : : #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
82 : :
83 : : /* Flow control default low water */
84 : : #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
85 : :
86 : : /* Receive Average Packet Size in Byte*/
87 : : #define I40E_PACKET_AVERAGE_SIZE 128
88 : :
89 : : /* Mask of PF interrupt causes */
90 : : #define I40E_PFINT_ICR0_ENA_MASK ( \
91 : : I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
92 : : I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
93 : : I40E_PFINT_ICR0_ENA_GRST_MASK | \
94 : : I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
95 : : I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
96 : : I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
97 : : I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
98 : : I40E_PFINT_ICR0_ENA_VFLR_MASK | \
99 : : I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
100 : :
101 : : #define I40E_FLOW_TYPES ( \
102 : : (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
103 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
104 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
105 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
106 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
107 : : (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
108 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
109 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
110 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
111 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
112 : : (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
113 : :
114 : : /* Additional timesync values. */
115 : : #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
116 : : #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
117 : : #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
118 : : #define I40E_PRTTSYN_TSYNENA 0x80000000
119 : : #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
120 : : #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
121 : :
122 : : /**
123 : : * Below are values for writing un-exposed registers suggested
124 : : * by silicon experts
125 : : */
126 : : /* Destination MAC address */
127 : : #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
128 : : /* Source MAC address */
129 : : #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
130 : : /* Outer (S-Tag) VLAN tag in the outer L2 header */
131 : : #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
132 : : /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
133 : : #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
134 : : /* Single VLAN tag in the inner L2 header */
135 : : #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
136 : : /* Source IPv4 address */
137 : : #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
138 : : /* Destination IPv4 address */
139 : : #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
140 : : /* Source IPv4 address for X722 */
141 : : #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
142 : : /* Destination IPv4 address for X722 */
143 : : #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
144 : : /* IPv4 Protocol for X722 */
145 : : #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
146 : : /* IPv4 Time to Live for X722 */
147 : : #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
148 : : /* IPv4 Type of Service (TOS) */
149 : : #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
150 : : /* IPv4 Protocol */
151 : : #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
152 : : /* IPv4 Time to Live */
153 : : #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
154 : : /* Source IPv6 address */
155 : : #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
156 : : /* Destination IPv6 address */
157 : : #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
158 : : /* IPv6 Traffic Class (TC) */
159 : : #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
160 : : /* IPv6 Next Header */
161 : : #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
162 : : /* IPv6 Hop Limit */
163 : : #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
164 : : /* Source L4 port */
165 : : #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
166 : : /* Destination L4 port */
167 : : #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
168 : : /* SCTP verification tag */
169 : : #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
170 : : /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
171 : : #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
172 : : /* Source port of tunneling UDP */
173 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
174 : : /* Destination port of tunneling UDP */
175 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
176 : : /* UDP Tunneling ID, NVGRE/GRE key */
177 : : #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
178 : : /* Last ether type */
179 : : #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
180 : : /* Tunneling outer destination IPv4 address */
181 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
182 : : /* Tunneling outer destination IPv6 address */
183 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
184 : : /* 1st word of flex payload */
185 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
186 : : /* 2nd word of flex payload */
187 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
188 : : /* 3rd word of flex payload */
189 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
190 : : /* 4th word of flex payload */
191 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
192 : : /* 5th word of flex payload */
193 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
194 : : /* 6th word of flex payload */
195 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
196 : : /* 7th word of flex payload */
197 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
198 : : /* 8th word of flex payload */
199 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
200 : : /* all 8 words flex payload */
201 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
202 : : #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
203 : :
204 : : #define I40E_TRANSLATE_INSET 0
205 : : #define I40E_TRANSLATE_REG 1
206 : :
207 : : #define I40E_INSET_IPV4_TOS_MASK 0x0000FF00UL
208 : : #define I40E_INSET_IPV4_TTL_MASK 0x000000FFUL
209 : : #define I40E_INSET_IPV4_PROTO_MASK 0x0000FF00UL
210 : : #define I40E_INSET_IPV6_TC_MASK 0x0000F00FUL
211 : : #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x0000FF00UL
212 : : #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000000FFUL
213 : :
214 : : /* PCI offset for querying capability */
215 : : #define PCI_DEV_CAP_REG 0xA4
216 : : /* PCI offset for enabling/disabling Extended Tag */
217 : : #define PCI_DEV_CTRL_REG 0xA8
218 : : /* Bit mask of Extended Tag capability */
219 : : #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
220 : : /* Bit shift of Extended Tag enable/disable */
221 : : #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
222 : : /* Bit mask of Extended Tag enable/disable */
223 : : #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
224 : :
225 : : #define I40E_GLQF_PIT_IPV4_START 2
226 : : #define I40E_GLQF_PIT_IPV4_COUNT 2
227 : : #define I40E_GLQF_PIT_IPV6_START 4
228 : : #define I40E_GLQF_PIT_IPV6_COUNT 2
229 : :
230 : : #define I40E_GLQF_PIT_SOURCE_OFF_GET(a) \
231 : : (((a) & I40E_GLQF_PIT_SOURCE_OFF_MASK) >> \
232 : : I40E_GLQF_PIT_SOURCE_OFF_SHIFT)
233 : :
234 : : #define I40E_GLQF_PIT_DEST_OFF_GET(a) \
235 : : (((a) & I40E_GLQF_PIT_DEST_OFF_MASK) >> \
236 : : I40E_GLQF_PIT_DEST_OFF_SHIFT)
237 : :
238 : : #define I40E_GLQF_PIT_FSIZE_GET(a) (((a) & I40E_GLQF_PIT_FSIZE_MASK) >> \
239 : : I40E_GLQF_PIT_FSIZE_SHIFT)
240 : :
241 : : #define I40E_GLQF_PIT_BUILD(off, mask) (((off) << 16) | (mask))
242 : : #define I40E_FDIR_FIELD_OFFSET(a) ((a) >> 1)
243 : :
244 : : static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
245 : : static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
246 : : static int i40e_dev_configure(struct rte_eth_dev *dev);
247 : : static int i40e_dev_start(struct rte_eth_dev *dev);
248 : : static int i40e_dev_stop(struct rte_eth_dev *dev);
249 : : static int i40e_dev_close(struct rte_eth_dev *dev);
250 : : static int i40e_dev_reset(struct rte_eth_dev *dev);
251 : : static int i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
252 : : static int i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
253 : : static int i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
254 : : static int i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
255 : : static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
256 : : static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
257 : : static int i40e_dev_stats_get(struct rte_eth_dev *dev,
258 : : struct rte_eth_stats *stats);
259 : : static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
260 : : struct rte_eth_xstat *xstats, unsigned n);
261 : : static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
262 : : struct rte_eth_xstat_name *xstats_names,
263 : : unsigned limit);
264 : : static int i40e_dev_stats_reset(struct rte_eth_dev *dev);
265 : : static int i40e_fw_version_get(struct rte_eth_dev *dev,
266 : : char *fw_version, size_t fw_size);
267 : : static int i40e_dev_info_get(struct rte_eth_dev *dev,
268 : : struct rte_eth_dev_info *dev_info);
269 : : static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
270 : : uint16_t vlan_id,
271 : : int on);
272 : : static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
273 : : enum rte_vlan_type vlan_type,
274 : : uint16_t tpid);
275 : : static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
276 : : static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
277 : : uint16_t queue,
278 : : int on);
279 : : static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
280 : : static int i40e_dev_led_on(struct rte_eth_dev *dev);
281 : : static int i40e_dev_led_off(struct rte_eth_dev *dev);
282 : : static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
283 : : struct rte_eth_fc_conf *fc_conf);
284 : : static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
285 : : struct rte_eth_fc_conf *fc_conf);
286 : : static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
287 : : struct rte_eth_pfc_conf *pfc_conf);
288 : : static int i40e_macaddr_add(struct rte_eth_dev *dev,
289 : : struct rte_ether_addr *mac_addr,
290 : : uint32_t index,
291 : : uint32_t pool);
292 : : static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
293 : : static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
294 : : struct rte_eth_rss_reta_entry64 *reta_conf,
295 : : uint16_t reta_size);
296 : : static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
297 : : struct rte_eth_rss_reta_entry64 *reta_conf,
298 : : uint16_t reta_size);
299 : :
300 : : static int i40e_get_cap(struct i40e_hw *hw);
301 : : static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
302 : : static int i40e_pf_setup(struct i40e_pf *pf);
303 : : static int i40e_dev_rxtx_init(struct i40e_pf *pf);
304 : : static int i40e_vmdq_setup(struct rte_eth_dev *dev);
305 : : static int i40e_dcb_setup(struct rte_eth_dev *dev);
306 : : static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
307 : : bool offset_loaded, uint64_t *offset, uint64_t *stat);
308 : : static void i40e_stat_update_48(struct i40e_hw *hw,
309 : : uint32_t hireg,
310 : : uint32_t loreg,
311 : : bool offset_loaded,
312 : : uint64_t *offset,
313 : : uint64_t *stat);
314 : : static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
315 : : static void i40e_dev_interrupt_handler(void *param);
316 : : static void i40e_dev_alarm_handler(void *param);
317 : : static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
318 : : uint32_t base, uint32_t num);
319 : : static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
320 : : static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
321 : : uint32_t base);
322 : : static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
323 : : uint16_t num);
324 : : static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
325 : : static int i40e_veb_release(struct i40e_veb *veb);
326 : : static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
327 : : struct i40e_vsi *vsi);
328 : : static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
329 : : static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
330 : : struct i40e_macvlan_filter *mv_f,
331 : : int num,
332 : : uint16_t vlan);
333 : : static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
334 : : static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
335 : : struct rte_eth_rss_conf *rss_conf);
336 : : static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
337 : : struct rte_eth_rss_conf *rss_conf);
338 : : static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
339 : : struct rte_eth_udp_tunnel *udp_tunnel);
340 : : static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
341 : : struct rte_eth_udp_tunnel *udp_tunnel);
342 : : static void i40e_filter_input_set_init(struct i40e_pf *pf);
343 : : static int i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
344 : : const struct rte_flow_ops **ops);
345 : : static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
346 : : struct rte_eth_dcb_info *dcb_info);
347 : : static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
348 : : static void i40e_configure_registers(struct i40e_hw *hw);
349 : : static void i40e_hw_init(struct rte_eth_dev *dev);
350 : : static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
351 : :
352 : : static int i40e_timesync_enable(struct rte_eth_dev *dev);
353 : : static int i40e_timesync_disable(struct rte_eth_dev *dev);
354 : : static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
355 : : struct timespec *timestamp,
356 : : uint32_t flags);
357 : : static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
358 : : struct timespec *timestamp);
359 : : static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
360 : :
361 : : static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
362 : :
363 : : static int i40e_timesync_read_time(struct rte_eth_dev *dev,
364 : : struct timespec *timestamp);
365 : : static int i40e_timesync_write_time(struct rte_eth_dev *dev,
366 : : const struct timespec *timestamp);
367 : :
368 : : static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
369 : : uint16_t queue_id);
370 : : static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
371 : : uint16_t queue_id);
372 : :
373 : : static int i40e_get_regs(struct rte_eth_dev *dev,
374 : : struct rte_dev_reg_info *regs);
375 : :
376 : : static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
377 : :
378 : : static int i40e_get_eeprom(struct rte_eth_dev *dev,
379 : : struct rte_dev_eeprom_info *eeprom);
380 : :
381 : : static int i40e_get_module_info(struct rte_eth_dev *dev,
382 : : struct rte_eth_dev_module_info *modinfo);
383 : : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
384 : : struct rte_dev_eeprom_info *info);
385 : :
386 : : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
387 : : struct rte_ether_addr *mac_addr);
388 : :
389 : : static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
390 : :
391 : : static int i40e_ethertype_filter_convert(
392 : : const struct rte_eth_ethertype_filter *input,
393 : : struct i40e_ethertype_filter *filter);
394 : : static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
395 : : struct i40e_ethertype_filter *filter);
396 : :
397 : : static int i40e_tunnel_filter_convert(
398 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
399 : : struct i40e_tunnel_filter *tunnel_filter);
400 : : static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
401 : : struct i40e_tunnel_filter *tunnel_filter);
402 : : static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
403 : :
404 : : static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
405 : : static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
406 : : static void i40e_filter_restore(struct i40e_pf *pf);
407 : : static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
408 : :
409 : : static const char *const valid_keys[] = {
410 : : ETH_I40E_FLOATING_VEB_ARG,
411 : : ETH_I40E_FLOATING_VEB_LIST_ARG,
412 : : ETH_I40E_SUPPORT_MULTI_DRIVER,
413 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG,
414 : : ETH_I40E_VF_MSG_CFG,
415 : : NULL};
416 : :
417 : : static const struct rte_pci_id pci_id_i40e_map[] = {
418 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
419 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
420 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
421 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
422 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
423 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
424 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
425 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
426 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
427 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
428 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
429 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
430 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
431 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
432 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
433 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
434 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
435 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
436 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
437 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
438 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
439 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
440 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
441 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
442 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_BC) },
443 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
444 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
445 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722_A) },
446 : : { .vendor_id = 0, /* sentinel */ },
447 : : };
448 : :
449 : : static const struct eth_dev_ops i40e_eth_dev_ops = {
450 : : .dev_configure = i40e_dev_configure,
451 : : .dev_start = i40e_dev_start,
452 : : .dev_stop = i40e_dev_stop,
453 : : .dev_close = i40e_dev_close,
454 : : .dev_reset = i40e_dev_reset,
455 : : .promiscuous_enable = i40e_dev_promiscuous_enable,
456 : : .promiscuous_disable = i40e_dev_promiscuous_disable,
457 : : .allmulticast_enable = i40e_dev_allmulticast_enable,
458 : : .allmulticast_disable = i40e_dev_allmulticast_disable,
459 : : .dev_set_link_up = i40e_dev_set_link_up,
460 : : .dev_set_link_down = i40e_dev_set_link_down,
461 : : .link_update = i40e_dev_link_update,
462 : : .stats_get = i40e_dev_stats_get,
463 : : .xstats_get = i40e_dev_xstats_get,
464 : : .xstats_get_names = i40e_dev_xstats_get_names,
465 : : .stats_reset = i40e_dev_stats_reset,
466 : : .xstats_reset = i40e_dev_stats_reset,
467 : : .fw_version_get = i40e_fw_version_get,
468 : : .dev_infos_get = i40e_dev_info_get,
469 : : .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
470 : : .vlan_filter_set = i40e_vlan_filter_set,
471 : : .vlan_tpid_set = i40e_vlan_tpid_set,
472 : : .vlan_offload_set = i40e_vlan_offload_set,
473 : : .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
474 : : .vlan_pvid_set = i40e_vlan_pvid_set,
475 : : .rx_queue_start = i40e_dev_rx_queue_start,
476 : : .rx_queue_stop = i40e_dev_rx_queue_stop,
477 : : .tx_queue_start = i40e_dev_tx_queue_start,
478 : : .tx_queue_stop = i40e_dev_tx_queue_stop,
479 : : .rx_queue_setup = i40e_dev_rx_queue_setup,
480 : : .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
481 : : .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
482 : : .rx_queue_release = i40e_dev_rx_queue_release,
483 : : .tx_queue_setup = i40e_dev_tx_queue_setup,
484 : : .tx_queue_release = i40e_dev_tx_queue_release,
485 : : .dev_led_on = i40e_dev_led_on,
486 : : .dev_led_off = i40e_dev_led_off,
487 : : .flow_ctrl_get = i40e_flow_ctrl_get,
488 : : .flow_ctrl_set = i40e_flow_ctrl_set,
489 : : .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
490 : : .mac_addr_add = i40e_macaddr_add,
491 : : .mac_addr_remove = i40e_macaddr_remove,
492 : : .reta_update = i40e_dev_rss_reta_update,
493 : : .reta_query = i40e_dev_rss_reta_query,
494 : : .rss_hash_update = i40e_dev_rss_hash_update,
495 : : .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
496 : : .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
497 : : .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
498 : : .flow_ops_get = i40e_dev_flow_ops_get,
499 : : .rxq_info_get = i40e_rxq_info_get,
500 : : .txq_info_get = i40e_txq_info_get,
501 : : .recycle_rxq_info_get = i40e_recycle_rxq_info_get,
502 : : .rx_burst_mode_get = i40e_rx_burst_mode_get,
503 : : .tx_burst_mode_get = i40e_tx_burst_mode_get,
504 : : .timesync_enable = i40e_timesync_enable,
505 : : .timesync_disable = i40e_timesync_disable,
506 : : .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
507 : : .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
508 : : .get_dcb_info = i40e_dev_get_dcb_info,
509 : : .timesync_adjust_time = i40e_timesync_adjust_time,
510 : : .timesync_read_time = i40e_timesync_read_time,
511 : : .timesync_write_time = i40e_timesync_write_time,
512 : : .get_reg = i40e_get_regs,
513 : : .get_eeprom_length = i40e_get_eeprom_length,
514 : : .get_eeprom = i40e_get_eeprom,
515 : : .get_module_info = i40e_get_module_info,
516 : : .get_module_eeprom = i40e_get_module_eeprom,
517 : : .mac_addr_set = i40e_set_default_mac_addr,
518 : : .mtu_set = i40e_dev_mtu_set,
519 : : .tm_ops_get = i40e_tm_ops_get,
520 : : .tx_done_cleanup = i40e_tx_done_cleanup,
521 : : .get_monitor_addr = i40e_get_monitor_addr,
522 : : };
523 : :
524 : : /* store statistics names and its offset in stats structure */
525 : : struct rte_i40e_xstats_name_off {
526 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
527 : : int offset;
528 : : };
529 : :
530 : : static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
531 : : {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
532 : : {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
533 : : {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
534 : : {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
535 : : {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
536 : : rx_unknown_protocol)},
537 : : {"rx_size_error_packets", offsetof(struct i40e_pf, rx_err1) -
538 : : offsetof(struct i40e_pf, stats)},
539 : : {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
540 : : {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
541 : : {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
542 : : {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
543 : : };
544 : :
545 : : #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
546 : : sizeof(rte_i40e_stats_strings[0]))
547 : :
548 : : static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
549 : : {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
550 : : tx_dropped_link_down)},
551 : : {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
552 : : {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
553 : : illegal_bytes)},
554 : : {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
555 : : {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
556 : : mac_local_faults)},
557 : : {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
558 : : mac_remote_faults)},
559 : : {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
560 : : rx_length_errors)},
561 : : {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
562 : : {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
563 : : {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
564 : : {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
565 : : {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
566 : : {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
567 : : rx_size_127)},
568 : : {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
569 : : rx_size_255)},
570 : : {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
571 : : rx_size_511)},
572 : : {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
573 : : rx_size_1023)},
574 : : {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
575 : : rx_size_1522)},
576 : : {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
577 : : rx_size_big)},
578 : : {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
579 : : rx_undersize)},
580 : : {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
581 : : rx_oversize)},
582 : : {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
583 : : mac_short_packet_dropped)},
584 : : {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
585 : : rx_fragments)},
586 : : {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
587 : : {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
588 : : {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
589 : : tx_size_127)},
590 : : {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
591 : : tx_size_255)},
592 : : {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
593 : : tx_size_511)},
594 : : {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
595 : : tx_size_1023)},
596 : : {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
597 : : tx_size_1522)},
598 : : {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
599 : : tx_size_big)},
600 : : {"rx_flow_director_atr_match_packets",
601 : : offsetof(struct i40e_hw_port_stats, fd_atr_match)},
602 : : {"rx_flow_director_sb_match_packets",
603 : : offsetof(struct i40e_hw_port_stats, fd_sb_match)},
604 : : {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
605 : : tx_lpi_status)},
606 : : {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
607 : : rx_lpi_status)},
608 : : {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
609 : : tx_lpi_count)},
610 : : {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
611 : : rx_lpi_count)},
612 : : };
613 : :
614 : : #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
615 : : sizeof(rte_i40e_hw_port_strings[0]))
616 : :
617 : : static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
618 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
619 : : priority_xon_rx)},
620 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
621 : : priority_xoff_rx)},
622 : : };
623 : :
624 : : #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
625 : : sizeof(rte_i40e_rxq_prio_strings[0]))
626 : :
627 : : static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
628 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
629 : : priority_xon_tx)},
630 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
631 : : priority_xoff_tx)},
632 : : {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
633 : : priority_xon_2_xoff)},
634 : : };
635 : :
636 : : #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
637 : : sizeof(rte_i40e_txq_prio_strings[0]))
638 : :
639 : : static int
640 : 0 : eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
641 : : struct rte_pci_device *pci_dev)
642 : : {
643 : : char name[RTE_ETH_NAME_MAX_LEN];
644 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
645 : : int i, retval;
646 : :
647 [ # # ]: 0 : if (pci_dev->device.devargs) {
648 : 0 : retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
649 : : ð_da);
650 [ # # ]: 0 : if (retval)
651 : : return retval;
652 : : }
653 : :
654 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0 &&
655 [ # # ]: 0 : eth_da.type != RTE_ETH_REPRESENTOR_VF) {
656 : 0 : PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
657 : : pci_dev->device.devargs->args);
658 : 0 : return -ENOTSUP;
659 : : }
660 : :
661 : 0 : retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
662 : : sizeof(struct i40e_adapter),
663 : : eth_dev_pci_specific_init, pci_dev,
664 : : eth_i40e_dev_init, NULL);
665 : :
666 [ # # # # ]: 0 : if (retval || eth_da.nb_representor_ports < 1)
667 : : return retval;
668 : :
669 : : /* probe VF representor ports */
670 : 0 : struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
671 : : pci_dev->device.name);
672 : :
673 [ # # ]: 0 : if (pf_ethdev == NULL)
674 : : return -ENODEV;
675 : :
676 [ # # ]: 0 : for (i = 0; i < eth_da.nb_representor_ports; i++) {
677 : 0 : struct i40e_vf_representor representor = {
678 : 0 : .vf_id = eth_da.representor_ports[i],
679 : 0 : .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
680 : 0 : pf_ethdev->data->dev_private)->switch_domain_id,
681 : : .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
682 : : pf_ethdev->data->dev_private)
683 : : };
684 : :
685 : : /* representor port net_bdf_port */
686 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
687 : : pci_dev->device.name, eth_da.representor_ports[i]);
688 : :
689 : 0 : retval = rte_eth_dev_create(&pci_dev->device, name,
690 : : sizeof(struct i40e_vf_representor), NULL, NULL,
691 : : i40e_vf_representor_init, &representor);
692 : :
693 [ # # ]: 0 : if (retval)
694 : 0 : PMD_DRV_LOG(ERR, "failed to create i40e vf "
695 : : "representor %s.", name);
696 : : }
697 : :
698 : : return 0;
699 : : }
700 : :
701 : 0 : static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
702 : : {
703 : : struct rte_eth_dev *ethdev;
704 : :
705 : 0 : ethdev = rte_eth_dev_allocated(pci_dev->device.name);
706 [ # # ]: 0 : if (!ethdev)
707 : : return 0;
708 : :
709 [ # # ]: 0 : if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
710 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
711 : : i40e_vf_representor_uninit);
712 : : else
713 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
714 : : eth_i40e_dev_uninit);
715 : : }
716 : :
717 : : static struct rte_pci_driver rte_i40e_pmd = {
718 : : .id_table = pci_id_i40e_map,
719 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
720 : : .probe = eth_i40e_pci_probe,
721 : : .remove = eth_i40e_pci_remove,
722 : : };
723 : :
724 : : static inline void
725 : 0 : i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
726 : : uint32_t reg_val)
727 : : {
728 : : uint32_t ori_reg_val;
729 : 0 : struct rte_eth_dev_data *dev_data =
730 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
731 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
732 : :
733 : 0 : ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
734 : 0 : i40e_write_rx_ctl(hw, reg_addr, reg_val);
735 [ # # ]: 0 : if (ori_reg_val != reg_val)
736 : 0 : PMD_DRV_LOG(WARNING,
737 : : "i40e device %s changed global register [0x%08x]."
738 : : " original: 0x%08x, new: 0x%08x",
739 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
740 : 0 : }
741 : :
742 : 235 : RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
743 : : RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
744 : : RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
745 : :
746 : : #ifndef I40E_GLQF_ORT
747 : : #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
748 : : #endif
749 : : #ifndef I40E_GLQF_PIT
750 : : #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
751 : : #endif
752 : : #ifndef I40E_GLQF_L3_MAP
753 : : #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
754 : : #endif
755 : :
756 : 0 : static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
757 : : {
758 : : /*
759 : : * Initialize registers for parsing packet type of QinQ
760 : : * This should be removed from code once proper
761 : : * configuration API is added to avoid configuration conflicts
762 : : * between ports of the same device.
763 : : */
764 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
765 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
766 : 0 : }
767 : :
768 : : static inline void i40e_config_automask(struct i40e_pf *pf)
769 : : {
770 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
771 : : uint32_t val;
772 : :
773 : : /* INTENA flag is not auto-cleared for interrupt */
774 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
775 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
776 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
777 : :
778 : : /* If support multi-driver, PF will use INT0. */
779 [ # # ]: 0 : if (!pf->support_multi_driver)
780 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
781 : :
782 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
783 : : }
784 : :
785 : : static inline void i40e_clear_automask(struct i40e_pf *pf)
786 : : {
787 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
788 : : uint32_t val;
789 : :
790 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
791 : 0 : val &= ~(I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
792 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK);
793 : :
794 [ # # ]: 0 : if (!pf->support_multi_driver)
795 : 0 : val &= ~I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
796 : :
797 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
798 : : }
799 : :
800 : : #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
801 : :
802 : : /*
803 : : * Add a ethertype filter to drop all flow control frames transmitted
804 : : * from VSIs.
805 : : */
806 : : static void
807 : 0 : i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
808 : : {
809 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
810 : : uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
811 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
812 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
813 : : int ret;
814 : :
815 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
816 : : I40E_FLOW_CONTROL_ETHERTYPE, flags,
817 : 0 : pf->main_vsi_seid, 0,
818 : : TRUE, NULL, NULL);
819 [ # # ]: 0 : if (ret)
820 : 0 : PMD_INIT_LOG(ERR,
821 : : "Failed to add filter to drop flow control frames from VSIs.");
822 : 0 : }
823 : :
824 : : static int
825 : 0 : floating_veb_list_handler(__rte_unused const char *key,
826 : : const char *floating_veb_value,
827 : : void *opaque)
828 : : {
829 : : int idx = 0;
830 : : unsigned int count = 0;
831 : 0 : char *end = NULL;
832 : : int min, max;
833 : : bool *vf_floating_veb = opaque;
834 : :
835 [ # # ]: 0 : while (isblank(*floating_veb_value))
836 : 0 : floating_veb_value++;
837 : :
838 : : /* Reset floating VEB configuration for VFs */
839 [ # # ]: 0 : for (idx = 0; idx < I40E_MAX_VF; idx++)
840 : 0 : vf_floating_veb[idx] = false;
841 : :
842 : : min = I40E_MAX_VF;
843 : : do {
844 [ # # ]: 0 : while (isblank(*floating_veb_value))
845 : 0 : floating_veb_value++;
846 [ # # ]: 0 : if (*floating_veb_value == '\0')
847 : : return -1;
848 : 0 : errno = 0;
849 : 0 : idx = strtoul(floating_veb_value, &end, 10);
850 [ # # # # ]: 0 : if (errno || end == NULL)
851 : : return -1;
852 [ # # ]: 0 : if (idx < 0)
853 : : return -1;
854 [ # # ]: 0 : while (isblank(*end))
855 : 0 : end++;
856 [ # # ]: 0 : if (*end == '-') {
857 : : min = idx;
858 [ # # ]: 0 : } else if ((*end == ';') || (*end == '\0')) {
859 : : max = idx;
860 [ # # ]: 0 : if (min == I40E_MAX_VF)
861 : : min = idx;
862 : : if (max >= I40E_MAX_VF)
863 : : max = I40E_MAX_VF - 1;
864 [ # # ]: 0 : for (idx = min; idx <= max; idx++) {
865 : 0 : vf_floating_veb[idx] = true;
866 : 0 : count++;
867 : : }
868 : : min = I40E_MAX_VF;
869 : : } else {
870 : : return -1;
871 : : }
872 : 0 : floating_veb_value = end + 1;
873 [ # # ]: 0 : } while (*end != '\0');
874 : :
875 [ # # ]: 0 : if (count == 0)
876 : 0 : return -1;
877 : :
878 : : return 0;
879 : : }
880 : :
881 : : static void
882 : 0 : config_vf_floating_veb(struct rte_devargs *devargs,
883 : : uint16_t floating_veb,
884 : : bool *vf_floating_veb)
885 : : {
886 : : struct rte_kvargs *kvlist;
887 : : int i;
888 : : const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
889 : :
890 [ # # ]: 0 : if (!floating_veb)
891 : : return;
892 : : /* All the VFs attach to the floating VEB by default
893 : : * when the floating VEB is enabled.
894 : : */
895 [ # # ]: 0 : for (i = 0; i < I40E_MAX_VF; i++)
896 : 0 : vf_floating_veb[i] = true;
897 : :
898 [ # # ]: 0 : if (devargs == NULL)
899 : : return;
900 : :
901 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
902 [ # # ]: 0 : if (kvlist == NULL)
903 : : return;
904 : :
905 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_list)) {
906 : 0 : rte_kvargs_free(kvlist);
907 : 0 : return;
908 : : }
909 : : /* When the floating_veb_list parameter exists, all the VFs
910 : : * will attach to the legacy VEB firstly, then configure VFs
911 : : * to the floating VEB according to the floating_veb_list.
912 : : */
913 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_list,
914 : : floating_veb_list_handler,
915 : : vf_floating_veb) < 0) {
916 : 0 : rte_kvargs_free(kvlist);
917 : 0 : return;
918 : : }
919 : 0 : rte_kvargs_free(kvlist);
920 : : }
921 : :
922 : : static int
923 : 0 : i40e_check_floating_handler(__rte_unused const char *key,
924 : : const char *value,
925 : : __rte_unused void *opaque)
926 : : {
927 [ # # ]: 0 : if (strcmp(value, "1"))
928 : 0 : return -1;
929 : :
930 : : return 0;
931 : : }
932 : :
933 : : static int
934 : 0 : is_floating_veb_supported(struct rte_devargs *devargs)
935 : : {
936 : : struct rte_kvargs *kvlist;
937 : : const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
938 : :
939 [ # # ]: 0 : if (devargs == NULL)
940 : : return 0;
941 : :
942 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
943 [ # # ]: 0 : if (kvlist == NULL)
944 : : return 0;
945 : :
946 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_key)) {
947 : 0 : rte_kvargs_free(kvlist);
948 : 0 : return 0;
949 : : }
950 : : /* Floating VEB is enabled when there's key-value:
951 : : * enable_floating_veb=1
952 : : */
953 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_key,
954 : : i40e_check_floating_handler, NULL) < 0) {
955 : 0 : rte_kvargs_free(kvlist);
956 : 0 : return 0;
957 : : }
958 : 0 : rte_kvargs_free(kvlist);
959 : :
960 : 0 : return 1;
961 : : }
962 : :
963 : : static void
964 : 0 : config_floating_veb(struct rte_eth_dev *dev)
965 : : {
966 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
967 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
968 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
969 : :
970 [ # # ]: 0 : memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
971 : :
972 [ # # ]: 0 : if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
973 : 0 : pf->floating_veb =
974 : 0 : is_floating_veb_supported(pci_dev->device.devargs);
975 : 0 : config_vf_floating_veb(pci_dev->device.devargs,
976 : : pf->floating_veb,
977 : : pf->floating_veb_list);
978 : : } else {
979 : 0 : pf->floating_veb = false;
980 : : }
981 : 0 : }
982 : :
983 : : #define I40E_L2_TAGS_S_TAG_SHIFT 1
984 : : #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
985 : :
986 : : static int
987 : 0 : i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
988 : : {
989 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
990 : : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
991 : : char ethertype_hash_name[RTE_HASH_NAMESIZE];
992 : : int ret;
993 : :
994 : 0 : struct rte_hash_parameters ethertype_hash_params = {
995 : : .name = ethertype_hash_name,
996 : : .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
997 : : .key_len = sizeof(struct i40e_ethertype_filter_input),
998 : : .hash_func = rte_hash_crc,
999 : : .hash_func_init_val = 0,
1000 : 0 : .socket_id = rte_socket_id(),
1001 : : };
1002 : :
1003 : : /* Initialize ethertype filter rule list and hash */
1004 : 0 : TAILQ_INIT(ðertype_rule->ethertype_list);
1005 : 0 : snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
1006 : 0 : "ethertype_%s", dev->device->name);
1007 : 0 : ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
1008 [ # # ]: 0 : if (!ethertype_rule->hash_table) {
1009 : 0 : PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
1010 : 0 : return -EINVAL;
1011 : : }
1012 : 0 : ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
1013 : : sizeof(struct i40e_ethertype_filter *) *
1014 : : I40E_MAX_ETHERTYPE_FILTER_NUM,
1015 : : 0);
1016 [ # # ]: 0 : if (!ethertype_rule->hash_map) {
1017 : 0 : PMD_INIT_LOG(ERR,
1018 : : "Failed to allocate memory for ethertype hash map!");
1019 : : ret = -ENOMEM;
1020 : 0 : goto err_ethertype_hash_map_alloc;
1021 : : }
1022 : :
1023 : : return 0;
1024 : :
1025 : : err_ethertype_hash_map_alloc:
1026 : 0 : rte_hash_free(ethertype_rule->hash_table);
1027 : :
1028 : 0 : return ret;
1029 : : }
1030 : :
1031 : : static int
1032 : 0 : i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1033 : : {
1034 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1035 : : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1036 : : char tunnel_hash_name[RTE_HASH_NAMESIZE];
1037 : : int ret;
1038 : :
1039 : 0 : struct rte_hash_parameters tunnel_hash_params = {
1040 : : .name = tunnel_hash_name,
1041 : : .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1042 : : .key_len = sizeof(struct i40e_tunnel_filter_input),
1043 : : .hash_func = rte_hash_crc,
1044 : : .hash_func_init_val = 0,
1045 : 0 : .socket_id = rte_socket_id(),
1046 : : };
1047 : :
1048 : : /* Initialize tunnel filter rule list and hash */
1049 : 0 : TAILQ_INIT(&tunnel_rule->tunnel_list);
1050 : 0 : snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1051 : 0 : "tunnel_%s", dev->device->name);
1052 : 0 : tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1053 [ # # ]: 0 : if (!tunnel_rule->hash_table) {
1054 : 0 : PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1055 : 0 : return -EINVAL;
1056 : : }
1057 : 0 : tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1058 : : sizeof(struct i40e_tunnel_filter *) *
1059 : : I40E_MAX_TUNNEL_FILTER_NUM,
1060 : : 0);
1061 [ # # ]: 0 : if (!tunnel_rule->hash_map) {
1062 : 0 : PMD_INIT_LOG(ERR,
1063 : : "Failed to allocate memory for tunnel hash map!");
1064 : : ret = -ENOMEM;
1065 : 0 : goto err_tunnel_hash_map_alloc;
1066 : : }
1067 : :
1068 : : return 0;
1069 : :
1070 : : err_tunnel_hash_map_alloc:
1071 : 0 : rte_hash_free(tunnel_rule->hash_table);
1072 : :
1073 : 0 : return ret;
1074 : : }
1075 : :
1076 : : static int
1077 : 0 : i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1078 : : {
1079 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1080 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1081 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1082 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
1083 : 0 : uint32_t alloc = hw->func_caps.fd_filters_guaranteed;
1084 : 0 : uint32_t best = hw->func_caps.fd_filters_best_effort;
1085 : : enum i40e_filter_pctype pctype;
1086 : : struct rte_bitmap *bmp = NULL;
1087 : : uint32_t bmp_size;
1088 : : void *mem = NULL;
1089 : : uint32_t i = 0;
1090 : : int ret;
1091 : :
1092 : 0 : struct rte_hash_parameters fdir_hash_params = {
1093 : : .name = fdir_hash_name,
1094 : : .entries = I40E_MAX_FDIR_FILTER_NUM,
1095 : : .key_len = sizeof(struct i40e_fdir_input),
1096 : : .hash_func = rte_hash_crc,
1097 : : .hash_func_init_val = 0,
1098 : 0 : .socket_id = rte_socket_id(),
1099 : : };
1100 : :
1101 : : /* Initialize flow director filter rule list and hash */
1102 : 0 : TAILQ_INIT(&fdir_info->fdir_list);
1103 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1104 : 0 : "fdir_%s", dev->device->name);
1105 : 0 : fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1106 [ # # ]: 0 : if (!fdir_info->hash_table) {
1107 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1108 : 0 : return -EINVAL;
1109 : : }
1110 : :
1111 : 0 : fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1112 : : sizeof(struct i40e_fdir_filter *) *
1113 : : I40E_MAX_FDIR_FILTER_NUM,
1114 : : 0);
1115 [ # # ]: 0 : if (!fdir_info->hash_map) {
1116 : 0 : PMD_INIT_LOG(ERR,
1117 : : "Failed to allocate memory for fdir hash map!");
1118 : : ret = -ENOMEM;
1119 : 0 : goto err_fdir_hash_map_alloc;
1120 : : }
1121 : :
1122 : 0 : fdir_info->fdir_filter_array = rte_zmalloc("fdir_filter",
1123 : : sizeof(struct i40e_fdir_filter) *
1124 : : I40E_MAX_FDIR_FILTER_NUM,
1125 : : 0);
1126 : :
1127 [ # # ]: 0 : if (!fdir_info->fdir_filter_array) {
1128 : 0 : PMD_INIT_LOG(ERR,
1129 : : "Failed to allocate memory for fdir filter array!");
1130 : : ret = -ENOMEM;
1131 : 0 : goto err_fdir_filter_array_alloc;
1132 : : }
1133 : :
1134 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1135 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++)
1136 : 0 : pf->fdir.flow_count[pctype] = 0;
1137 : :
1138 : 0 : fdir_info->fdir_space_size = alloc + best;
1139 : 0 : fdir_info->fdir_actual_cnt = 0;
1140 : 0 : fdir_info->fdir_guarantee_total_space = alloc;
1141 : 0 : fdir_info->fdir_guarantee_free_space =
1142 : : fdir_info->fdir_guarantee_total_space;
1143 : :
1144 : 0 : PMD_DRV_LOG(INFO, "FDIR guarantee space: %u, best_effort space %u.", alloc, best);
1145 : :
1146 : 0 : fdir_info->fdir_flow_pool.pool =
1147 : 0 : rte_zmalloc("i40e_fdir_entry",
1148 : : sizeof(struct i40e_fdir_entry) *
1149 : 0 : fdir_info->fdir_space_size,
1150 : : 0);
1151 : :
1152 [ # # ]: 0 : if (!fdir_info->fdir_flow_pool.pool) {
1153 : 0 : PMD_INIT_LOG(ERR,
1154 : : "Failed to allocate memory for bitmap flow!");
1155 : : ret = -ENOMEM;
1156 : 0 : goto err_fdir_bitmap_flow_alloc;
1157 : : }
1158 : :
1159 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1160 : 0 : fdir_info->fdir_flow_pool.pool[i].idx = i;
1161 : :
1162 : : bmp_size =
1163 : 0 : rte_bitmap_get_memory_footprint(fdir_info->fdir_space_size);
1164 : 0 : mem = rte_zmalloc("fdir_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
1165 [ # # ]: 0 : if (mem == NULL) {
1166 : 0 : PMD_INIT_LOG(ERR,
1167 : : "Failed to allocate memory for fdir bitmap!");
1168 : : ret = -ENOMEM;
1169 : 0 : goto err_fdir_mem_alloc;
1170 : : }
1171 : 0 : bmp = rte_bitmap_init(fdir_info->fdir_space_size, mem, bmp_size);
1172 [ # # ]: 0 : if (bmp == NULL) {
1173 : 0 : PMD_INIT_LOG(ERR,
1174 : : "Failed to initialization fdir bitmap!");
1175 : : ret = -ENOMEM;
1176 : 0 : goto err_fdir_bmp_alloc;
1177 : : }
1178 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1179 : 0 : rte_bitmap_set(bmp, i);
1180 : :
1181 : 0 : fdir_info->fdir_flow_pool.bitmap = bmp;
1182 : :
1183 : 0 : return 0;
1184 : :
1185 : : err_fdir_bmp_alloc:
1186 : 0 : rte_free(mem);
1187 : 0 : err_fdir_mem_alloc:
1188 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1189 : 0 : err_fdir_bitmap_flow_alloc:
1190 : 0 : rte_free(fdir_info->fdir_filter_array);
1191 : 0 : err_fdir_filter_array_alloc:
1192 : 0 : rte_free(fdir_info->hash_map);
1193 : 0 : err_fdir_hash_map_alloc:
1194 : 0 : rte_hash_free(fdir_info->hash_table);
1195 : :
1196 : 0 : return ret;
1197 : : }
1198 : :
1199 : : static void
1200 : : i40e_init_customized_info(struct i40e_pf *pf)
1201 : : {
1202 : : int i;
1203 : :
1204 : : /* Initialize customized pctype */
1205 [ # # ]: 0 : for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1206 : 0 : pf->customized_pctype[i].index = i;
1207 : 0 : pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1208 : 0 : pf->customized_pctype[i].valid = false;
1209 : : }
1210 : :
1211 : 0 : pf->gtp_support = false;
1212 : 0 : pf->esp_support = false;
1213 : : }
1214 : :
1215 : : static void
1216 : 0 : i40e_init_filter_invalidation(struct i40e_pf *pf)
1217 : : {
1218 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1219 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1220 : : uint32_t glqf_ctl_reg = 0;
1221 : :
1222 : 0 : glqf_ctl_reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
1223 [ # # ]: 0 : if (!pf->support_multi_driver) {
1224 : 0 : fdir_info->fdir_invalprio = 1;
1225 : 0 : glqf_ctl_reg |= I40E_GLQF_CTL_INVALPRIO_MASK;
1226 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO set to guaranteed first");
1227 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_CTL, glqf_ctl_reg);
1228 : : } else {
1229 [ # # ]: 0 : if (glqf_ctl_reg & I40E_GLQF_CTL_INVALPRIO_MASK) {
1230 : 0 : fdir_info->fdir_invalprio = 1;
1231 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: guaranteed first");
1232 : : } else {
1233 : 0 : fdir_info->fdir_invalprio = 0;
1234 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: shared first");
1235 : : }
1236 : : }
1237 : 0 : }
1238 : :
1239 : : void
1240 : 0 : i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1241 : : {
1242 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1243 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1244 : 0 : struct i40e_queue_regions *info = &pf->queue_region;
1245 : : uint16_t i;
1246 : :
1247 [ # # ]: 0 : for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1248 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1249 : :
1250 : : memset(info, 0, sizeof(struct i40e_queue_regions));
1251 : 0 : }
1252 : :
1253 : : static int
1254 : 0 : i40e_parse_multi_drv_handler(__rte_unused const char *key,
1255 : : const char *value,
1256 : : void *opaque)
1257 : : {
1258 : : struct i40e_pf *pf;
1259 : : unsigned long support_multi_driver;
1260 : : char *end;
1261 : :
1262 : : pf = (struct i40e_pf *)opaque;
1263 : :
1264 : 0 : errno = 0;
1265 : 0 : support_multi_driver = strtoul(value, &end, 10);
1266 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
1267 : 0 : PMD_DRV_LOG(WARNING, "Wrong global configuration");
1268 : 0 : return -(EINVAL);
1269 : : }
1270 : :
1271 [ # # ]: 0 : if (support_multi_driver == 1 || support_multi_driver == 0)
1272 : 0 : pf->support_multi_driver = (bool)support_multi_driver;
1273 : : else
1274 : 0 : PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1275 : : "enable global configuration by default."
1276 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1277 : : return 0;
1278 : : }
1279 : :
1280 : : static int
1281 : 0 : i40e_support_multi_driver(struct rte_eth_dev *dev)
1282 : : {
1283 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1284 : : struct rte_kvargs *kvlist;
1285 : : int kvargs_count;
1286 : :
1287 : : /* Enable global configuration by default */
1288 : 0 : pf->support_multi_driver = false;
1289 : :
1290 [ # # ]: 0 : if (!dev->device->devargs)
1291 : : return 0;
1292 : :
1293 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1294 [ # # ]: 0 : if (!kvlist)
1295 : : return -EINVAL;
1296 : :
1297 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1298 [ # # ]: 0 : if (!kvargs_count) {
1299 : 0 : rte_kvargs_free(kvlist);
1300 : 0 : return 0;
1301 : : }
1302 : :
1303 [ # # ]: 0 : if (kvargs_count > 1)
1304 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1305 : : "the first invalid or last valid one is used !",
1306 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1307 : :
1308 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1309 : : i40e_parse_multi_drv_handler, pf) < 0) {
1310 : 0 : rte_kvargs_free(kvlist);
1311 : 0 : return -EINVAL;
1312 : : }
1313 : :
1314 : 0 : rte_kvargs_free(kvlist);
1315 : 0 : return 0;
1316 : : }
1317 : :
1318 : : static int
1319 : 0 : i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1320 : : uint32_t reg_addr, uint64_t reg_val,
1321 : : struct i40e_asq_cmd_details *cmd_details)
1322 : : {
1323 : : uint64_t ori_reg_val;
1324 : 0 : struct rte_eth_dev_data *dev_data =
1325 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
1326 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
1327 : : int ret;
1328 : :
1329 : 0 : ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1330 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1331 : 0 : PMD_DRV_LOG(ERR,
1332 : : "Fail to debug read from 0x%08x",
1333 : : reg_addr);
1334 : 0 : return -EIO;
1335 : : }
1336 : :
1337 [ # # ]: 0 : if (ori_reg_val != reg_val)
1338 : 0 : PMD_DRV_LOG(WARNING,
1339 : : "i40e device %s changed global register [0x%08x]."
1340 : : " original: 0x%"PRIx64", after: 0x%"PRIx64,
1341 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
1342 : :
1343 : 0 : return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1344 : : }
1345 : :
1346 : : static int
1347 : 0 : read_vf_msg_config(__rte_unused const char *key,
1348 : : const char *value,
1349 : : void *opaque)
1350 : : {
1351 : : struct i40e_vf_msg_cfg *cfg = opaque;
1352 : :
1353 [ # # ]: 0 : if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1354 : : &cfg->ignore_second) != 3) {
1355 : : memset(cfg, 0, sizeof(*cfg));
1356 : 0 : PMD_DRV_LOG(ERR, "format error! example: "
1357 : : "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1358 : 0 : return -EINVAL;
1359 : : }
1360 : :
1361 : : /*
1362 : : * If the message validation function been enabled, the 'period'
1363 : : * and 'ignore_second' must greater than 0.
1364 : : */
1365 [ # # # # : 0 : if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
# # ]
1366 : : memset(cfg, 0, sizeof(*cfg));
1367 : 0 : PMD_DRV_LOG(ERR, "%s error! the second and third"
1368 : : " number must be greater than 0!",
1369 : : ETH_I40E_VF_MSG_CFG);
1370 : 0 : return -EINVAL;
1371 : : }
1372 : :
1373 : : return 0;
1374 : : }
1375 : :
1376 : : static int
1377 [ # # ]: 0 : i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1378 : : struct i40e_vf_msg_cfg *msg_cfg)
1379 : : {
1380 : : struct rte_kvargs *kvlist;
1381 : : int kvargs_count;
1382 : : int ret = 0;
1383 : :
1384 : : memset(msg_cfg, 0, sizeof(*msg_cfg));
1385 : :
1386 [ # # ]: 0 : if (!dev->device->devargs)
1387 : : return ret;
1388 : :
1389 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1390 [ # # ]: 0 : if (!kvlist)
1391 : : return -EINVAL;
1392 : :
1393 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1394 [ # # ]: 0 : if (!kvargs_count)
1395 : 0 : goto free_end;
1396 : :
1397 [ # # ]: 0 : if (kvargs_count > 1) {
1398 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1399 : : ETH_I40E_VF_MSG_CFG);
1400 : : ret = -EINVAL;
1401 : 0 : goto free_end;
1402 : : }
1403 : :
1404 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1405 : : read_vf_msg_config, msg_cfg) < 0)
1406 : : ret = -EINVAL;
1407 : :
1408 : 0 : free_end:
1409 : 0 : rte_kvargs_free(kvlist);
1410 : 0 : return ret;
1411 : : }
1412 : :
1413 : : #define I40E_ALARM_INTERVAL 50000 /* us */
1414 : :
1415 : : static int
1416 : 0 : eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1417 : : {
1418 : : struct rte_pci_device *pci_dev;
1419 : : struct rte_intr_handle *intr_handle;
1420 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1421 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1422 : : struct i40e_vsi *vsi;
1423 : : int ret;
1424 : : uint32_t len, val;
1425 : 0 : uint8_t aq_fail = 0;
1426 : :
1427 : 0 : PMD_INIT_FUNC_TRACE();
1428 : :
1429 : 0 : dev->dev_ops = &i40e_eth_dev_ops;
1430 : 0 : dev->rx_queue_count = i40e_dev_rx_queue_count;
1431 : 0 : dev->rx_descriptor_status = i40e_dev_rx_descriptor_status;
1432 : 0 : dev->tx_descriptor_status = i40e_dev_tx_descriptor_status;
1433 : 0 : dev->rx_pkt_burst = i40e_recv_pkts;
1434 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts;
1435 : 0 : dev->tx_pkt_prepare = i40e_prep_pkts;
1436 : :
1437 : : /* for secondary processes, we don't initialise any further as primary
1438 : : * has already done this work. Only check we don't need a different
1439 : : * RX function */
1440 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1441 : 0 : i40e_set_rx_function(dev);
1442 : 0 : i40e_set_tx_function(dev);
1443 : 0 : return 0;
1444 : : }
1445 : 0 : i40e_set_default_ptype_table(dev);
1446 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1447 : 0 : intr_handle = pci_dev->intr_handle;
1448 : :
1449 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
1450 : :
1451 : 0 : pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1452 : 0 : pf->dev_data = dev->data;
1453 : :
1454 : 0 : hw->back = I40E_PF_TO_ADAPTER(pf);
1455 : 0 : hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1456 [ # # ]: 0 : if (!hw->hw_addr) {
1457 : 0 : PMD_INIT_LOG(ERR,
1458 : : "Hardware is not available, as address is NULL");
1459 : 0 : return -ENODEV;
1460 : : }
1461 : :
1462 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1463 : 0 : hw->device_id = pci_dev->id.device_id;
1464 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1465 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1466 : 0 : hw->bus.device = pci_dev->addr.devid;
1467 : 0 : hw->bus.func = pci_dev->addr.function;
1468 : 0 : hw->adapter_stopped = 0;
1469 : 0 : hw->adapter_closed = 0;
1470 : :
1471 : : /* Init switch device pointer */
1472 : 0 : hw->switch_dev = NULL;
1473 : :
1474 : : /*
1475 : : * Switch Tag value should not be identical to either the First Tag
1476 : : * or Second Tag values. So set something other than common Ethertype
1477 : : * for internal switching.
1478 : : */
1479 : 0 : hw->switch_tag = 0xffff;
1480 : :
1481 : : val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1482 [ # # ]: 0 : if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1483 : 0 : PMD_INIT_LOG(ERR, "\nERROR: "
1484 : : "Firmware recovery mode detected. Limiting functionality.\n"
1485 : : "Refer to the Intel(R) Ethernet Adapters and Devices "
1486 : : "User Guide for details on firmware recovery mode.");
1487 : 0 : return -EIO;
1488 : : }
1489 : :
1490 : 0 : i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1491 : : /* Check if need to support multi-driver */
1492 : 0 : i40e_support_multi_driver(dev);
1493 : :
1494 : : /* Make sure all is clean before doing PF reset */
1495 : 0 : i40e_clear_hw(hw);
1496 : :
1497 : : /* Reset here to make sure all is clean for each PF */
1498 : 0 : ret = i40e_pf_reset(hw);
1499 [ # # ]: 0 : if (ret) {
1500 : 0 : PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1501 : 0 : return ret;
1502 : : }
1503 : :
1504 : : /* Initialize the shared code (base driver) */
1505 : 0 : ret = i40e_init_shared_code(hw);
1506 [ # # ]: 0 : if (ret) {
1507 : 0 : PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1508 : 0 : return ret;
1509 : : }
1510 : :
1511 : : /* Initialize the parameters for adminq */
1512 : : i40e_init_adminq_parameter(hw);
1513 : 0 : ret = i40e_init_adminq(hw);
1514 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1515 : 0 : PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1516 : 0 : return -EIO;
1517 : : }
1518 : : /* Firmware of SFP x722 does not support 802.1ad frames ability */
1519 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_SFP_X722 ||
1520 : : hw->device_id == I40E_DEV_ID_SFP_I_X722)
1521 : 0 : hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1522 : :
1523 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1524 : : hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1525 : : hw->aq.api_maj_ver, hw->aq.api_min_ver,
1526 : : ((hw->nvm.version >> 12) & 0xf),
1527 : : ((hw->nvm.version >> 4) & 0xff),
1528 : : (hw->nvm.version & 0xf), hw->nvm.eetrack);
1529 : :
1530 : : /* Initialize the hardware */
1531 : 0 : i40e_hw_init(dev);
1532 : :
1533 : : i40e_config_automask(pf);
1534 : :
1535 : 0 : i40e_set_default_pctype_table(dev);
1536 : :
1537 : : /*
1538 : : * To work around the NVM issue, initialize registers
1539 : : * for packet type of QinQ by software.
1540 : : * It should be removed once issues are fixed in NVM.
1541 : : */
1542 [ # # ]: 0 : if (!pf->support_multi_driver)
1543 : 0 : i40e_GLQF_reg_init(hw);
1544 : :
1545 : : /* Initialize the input set for filters (hash and fd) to default value */
1546 : 0 : i40e_filter_input_set_init(pf);
1547 : :
1548 : : /* initialise the L3_MAP register */
1549 [ # # ]: 0 : if (!pf->support_multi_driver) {
1550 : 0 : ret = i40e_aq_debug_write_global_register(hw,
1551 : : I40E_GLQF_L3_MAP(40),
1552 : : 0x00000028, NULL);
1553 [ # # ]: 0 : if (ret)
1554 : 0 : PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1555 : : ret);
1556 : 0 : PMD_INIT_LOG(DEBUG,
1557 : : "Global register 0x%08x is changed with 0x28",
1558 : : I40E_GLQF_L3_MAP(40));
1559 : : }
1560 : :
1561 : : /* Need the special FW version to support floating VEB */
1562 : 0 : config_floating_veb(dev);
1563 : : /* Clear PXE mode */
1564 : 0 : i40e_clear_pxe_mode(hw);
1565 : 0 : i40e_dev_sync_phy_type(hw);
1566 : :
1567 : : /*
1568 : : * On X710, performance number is far from the expectation on recent
1569 : : * firmware versions. The fix for this issue may not be integrated in
1570 : : * the following firmware version. So the workaround in software driver
1571 : : * is needed. It needs to modify the initial values of 3 internal only
1572 : : * registers. Note that the workaround can be removed when it is fixed
1573 : : * in firmware in the future.
1574 : : */
1575 : 0 : i40e_configure_registers(hw);
1576 : :
1577 : : /* Get hw capabilities */
1578 : 0 : ret = i40e_get_cap(hw);
1579 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1580 : 0 : PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1581 : 0 : goto err_get_capabilities;
1582 : : }
1583 : :
1584 : : /* Initialize parameters for PF */
1585 : 0 : ret = i40e_pf_parameter_init(dev);
1586 [ # # ]: 0 : if (ret != 0) {
1587 : 0 : PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1588 : 0 : goto err_parameter_init;
1589 : : }
1590 : :
1591 : : /* Initialize the queue management */
1592 : 0 : ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1593 [ # # ]: 0 : if (ret < 0) {
1594 : 0 : PMD_INIT_LOG(ERR, "Failed to init queue pool");
1595 : 0 : goto err_qp_pool_init;
1596 : : }
1597 : 0 : ret = i40e_res_pool_init(&pf->msix_pool, 1,
1598 : 0 : hw->func_caps.num_msix_vectors - 1);
1599 [ # # ]: 0 : if (ret < 0) {
1600 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1601 : 0 : goto err_msix_pool_init;
1602 : : }
1603 : :
1604 : : /* Initialize lan hmc */
1605 : 0 : ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1606 : : hw->func_caps.num_rx_qp, 0, 0);
1607 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1608 : 0 : PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1609 : 0 : goto err_init_lan_hmc;
1610 : : }
1611 : :
1612 : : /* Configure lan hmc */
1613 : 0 : ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1614 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1615 : 0 : PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1616 : 0 : goto err_configure_lan_hmc;
1617 : : }
1618 : :
1619 : : /* Get and check the mac address */
1620 : 0 : i40e_get_mac_addr(hw, hw->mac.addr);
1621 [ # # ]: 0 : if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1622 : 0 : PMD_INIT_LOG(ERR, "mac address is not valid");
1623 : : ret = -EIO;
1624 : 0 : goto err_get_mac_addr;
1625 : : }
1626 : : /* Copy the permanent MAC address */
1627 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1628 : : (struct rte_ether_addr *)hw->mac.perm_addr);
1629 : :
1630 : : /* Disable flow control */
1631 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
1632 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
1633 : :
1634 : : /* Set the global registers with default ether type value */
1635 [ # # ]: 0 : if (!pf->support_multi_driver) {
1636 : 0 : ret = i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
1637 : : RTE_ETHER_TYPE_VLAN);
1638 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1639 : 0 : PMD_INIT_LOG(ERR,
1640 : : "Failed to set the default outer "
1641 : : "VLAN ether type");
1642 : 0 : goto err_setup_pf_switch;
1643 : : }
1644 : : }
1645 : :
1646 : : /* PF setup, which includes VSI setup */
1647 : 0 : ret = i40e_pf_setup(pf);
1648 [ # # ]: 0 : if (ret) {
1649 : 0 : PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1650 : 0 : goto err_setup_pf_switch;
1651 : : }
1652 : :
1653 : 0 : vsi = pf->main_vsi;
1654 : :
1655 : : /* Disable double vlan by default */
1656 : : i40e_vsi_config_double_vlan(vsi, FALSE);
1657 : :
1658 : : /* Disable S-TAG identification when floating_veb is disabled */
1659 [ # # ]: 0 : if (!pf->floating_veb) {
1660 : 0 : ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1661 [ # # ]: 0 : if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1662 : 0 : ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1663 : 0 : I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1664 : : }
1665 : : }
1666 : :
1667 [ # # ]: 0 : if (!vsi->max_macaddrs)
1668 : : len = RTE_ETHER_ADDR_LEN;
1669 : : else
1670 : 0 : len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1671 : :
1672 : : /* Should be after VSI initialized */
1673 : 0 : dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1674 [ # # ]: 0 : if (!dev->data->mac_addrs) {
1675 : 0 : PMD_INIT_LOG(ERR,
1676 : : "Failed to allocated memory for storing mac address");
1677 : 0 : goto err_mac_alloc;
1678 : : }
1679 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1680 : : &dev->data->mac_addrs[0]);
1681 : :
1682 : : /* Init dcb to sw mode by default */
1683 : 0 : ret = i40e_dcb_init_configure(dev, TRUE);
1684 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1685 : 0 : PMD_INIT_LOG(INFO, "Failed to init dcb.");
1686 : 0 : pf->flags &= ~I40E_FLAG_DCB;
1687 : : }
1688 : : /* Update HW struct after DCB configuration */
1689 : 0 : i40e_get_cap(hw);
1690 : :
1691 : : /* initialize pf host driver to setup SRIOV resource if applicable */
1692 : 0 : i40e_pf_host_init(dev);
1693 : :
1694 : : /* register callback func to eal lib */
1695 : 0 : rte_intr_callback_register(intr_handle,
1696 : : i40e_dev_interrupt_handler, dev);
1697 : :
1698 : : /* configure and enable device interrupt */
1699 : : i40e_pf_config_irq0(hw, TRUE);
1700 : 0 : i40e_pf_enable_irq0(hw);
1701 : :
1702 : : /* enable uio intr after callback register */
1703 : 0 : rte_intr_enable(intr_handle);
1704 : :
1705 : : /* By default disable flexible payload in global configuration */
1706 [ # # ]: 0 : if (!pf->support_multi_driver)
1707 : 0 : i40e_flex_payload_reg_set_default(hw);
1708 : :
1709 : : /*
1710 : : * Add an ethertype filter to drop all flow control frames transmitted
1711 : : * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1712 : : * frames to wire.
1713 : : */
1714 : 0 : i40e_add_tx_flow_control_drop_filter(pf);
1715 : :
1716 : : /* initialize RSS rule list */
1717 : 0 : TAILQ_INIT(&pf->rss_config_list);
1718 : :
1719 : : /* initialize Traffic Manager configuration */
1720 : 0 : i40e_tm_conf_init(dev);
1721 : :
1722 : : /* Initialize customized information */
1723 : : i40e_init_customized_info(pf);
1724 : :
1725 : : /* Initialize the filter invalidation configuration */
1726 : 0 : i40e_init_filter_invalidation(pf);
1727 : :
1728 : 0 : ret = i40e_init_ethtype_filter_list(dev);
1729 [ # # ]: 0 : if (ret < 0)
1730 : 0 : goto err_init_ethtype_filter_list;
1731 : 0 : ret = i40e_init_tunnel_filter_list(dev);
1732 [ # # ]: 0 : if (ret < 0)
1733 : 0 : goto err_init_tunnel_filter_list;
1734 : 0 : ret = i40e_init_fdir_filter_list(dev);
1735 [ # # ]: 0 : if (ret < 0)
1736 : 0 : goto err_init_fdir_filter_list;
1737 : :
1738 : : /* initialize queue region configuration */
1739 : 0 : i40e_init_queue_region_conf(dev);
1740 : :
1741 : : /* reset all stats of the device, including pf and main vsi */
1742 : 0 : i40e_dev_stats_reset(dev);
1743 : :
1744 : 0 : return 0;
1745 : :
1746 : : err_init_fdir_filter_list:
1747 : 0 : rte_hash_free(pf->tunnel.hash_table);
1748 : 0 : rte_free(pf->tunnel.hash_map);
1749 : 0 : err_init_tunnel_filter_list:
1750 : 0 : rte_hash_free(pf->ethertype.hash_table);
1751 : 0 : rte_free(pf->ethertype.hash_map);
1752 : 0 : err_init_ethtype_filter_list:
1753 : 0 : rte_intr_callback_unregister(intr_handle,
1754 : : i40e_dev_interrupt_handler, dev);
1755 : 0 : rte_free(dev->data->mac_addrs);
1756 : 0 : dev->data->mac_addrs = NULL;
1757 : 0 : err_mac_alloc:
1758 : 0 : i40e_vsi_release(pf->main_vsi);
1759 : 0 : err_setup_pf_switch:
1760 : 0 : err_get_mac_addr:
1761 : 0 : err_configure_lan_hmc:
1762 : 0 : (void)i40e_shutdown_lan_hmc(hw);
1763 : 0 : err_init_lan_hmc:
1764 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
1765 : 0 : err_msix_pool_init:
1766 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
1767 : 0 : err_qp_pool_init:
1768 : 0 : err_parameter_init:
1769 : 0 : err_get_capabilities:
1770 : 0 : (void)i40e_shutdown_adminq(hw);
1771 : :
1772 : 0 : return ret;
1773 : : }
1774 : :
1775 : : static void
1776 : 0 : i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1777 : : {
1778 : : struct i40e_ethertype_filter *p_ethertype;
1779 : : struct i40e_ethertype_rule *ethertype_rule;
1780 : :
1781 : : ethertype_rule = &pf->ethertype;
1782 : : /* Remove all ethertype filter rules and hash */
1783 : 0 : rte_free(ethertype_rule->hash_map);
1784 : 0 : rte_hash_free(ethertype_rule->hash_table);
1785 : :
1786 [ # # ]: 0 : while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1787 [ # # ]: 0 : TAILQ_REMOVE(ðertype_rule->ethertype_list,
1788 : : p_ethertype, rules);
1789 : 0 : rte_free(p_ethertype);
1790 : : }
1791 : 0 : }
1792 : :
1793 : : static void
1794 : 0 : i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1795 : : {
1796 : : struct i40e_tunnel_filter *p_tunnel;
1797 : : struct i40e_tunnel_rule *tunnel_rule;
1798 : :
1799 : : tunnel_rule = &pf->tunnel;
1800 : : /* Remove all tunnel director rules and hash */
1801 : 0 : rte_free(tunnel_rule->hash_map);
1802 : 0 : rte_hash_free(tunnel_rule->hash_table);
1803 : :
1804 [ # # ]: 0 : while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1805 [ # # ]: 0 : TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1806 : 0 : rte_free(p_tunnel);
1807 : : }
1808 : 0 : }
1809 : :
1810 : : static void
1811 : : i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1812 : : {
1813 : : struct i40e_fdir_filter *p_fdir;
1814 : : struct i40e_fdir_info *fdir_info;
1815 : :
1816 : : fdir_info = &pf->fdir;
1817 : :
1818 : : /* Remove all flow director rules */
1819 [ # # ]: 0 : while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list)))
1820 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1821 : : }
1822 : :
1823 : : static void
1824 : 0 : i40e_fdir_memory_cleanup(struct i40e_pf *pf)
1825 : : {
1826 : : struct i40e_fdir_info *fdir_info;
1827 : :
1828 : : fdir_info = &pf->fdir;
1829 : :
1830 : : /* flow director memory cleanup */
1831 : 0 : rte_free(fdir_info->hash_map);
1832 : 0 : rte_hash_free(fdir_info->hash_table);
1833 : 0 : rte_free(fdir_info->fdir_flow_pool.bitmap);
1834 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1835 : 0 : rte_free(fdir_info->fdir_filter_array);
1836 : 0 : }
1837 : :
1838 : 0 : void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1839 : : {
1840 : : /*
1841 : : * Disable by default flexible payload
1842 : : * for corresponding L2/L3/L4 layers.
1843 : : */
1844 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1845 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1846 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1847 : 0 : }
1848 : :
1849 : : static int
1850 : 0 : eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1851 : : {
1852 : : struct i40e_hw *hw;
1853 : :
1854 : 0 : PMD_INIT_FUNC_TRACE();
1855 : :
1856 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1857 : : return 0;
1858 : :
1859 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1860 : :
1861 [ # # ]: 0 : if (hw->adapter_closed == 0)
1862 : 0 : i40e_dev_close(dev);
1863 : :
1864 : : return 0;
1865 : : }
1866 : :
1867 : : static int
1868 : 0 : i40e_dev_configure(struct rte_eth_dev *dev)
1869 : : {
1870 : 0 : struct i40e_adapter *ad =
1871 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1872 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1873 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1874 : 0 : enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1875 : : int i, ret;
1876 : :
1877 : 0 : ret = i40e_dev_sync_phy_type(hw);
1878 [ # # ]: 0 : if (ret)
1879 : : return ret;
1880 : :
1881 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
1882 : : * bulk allocation or vector Rx preconditions we will reset it.
1883 : : */
1884 : 0 : ad->rx_bulk_alloc_allowed = true;
1885 : 0 : ad->rx_vec_allowed = true;
1886 : 0 : ad->tx_simple_allowed = true;
1887 : 0 : ad->tx_vec_allowed = true;
1888 : :
1889 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1890 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1891 : :
1892 : 0 : ret = i40e_dev_init_vlan(dev);
1893 [ # # ]: 0 : if (ret < 0)
1894 : 0 : goto err;
1895 : :
1896 : : /* VMDQ setup.
1897 : : * General PMD call sequence are NIC init, configure,
1898 : : * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1899 : : * will try to lookup the VSI that specific queue belongs to if VMDQ
1900 : : * applicable. So, VMDQ setting has to be done before
1901 : : * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1902 : : * For RSS setting, it will try to calculate actual configured RX queue
1903 : : * number, which will be available after rx_queue_setup(). dev_start()
1904 : : * function is good to place RSS setup.
1905 : : */
1906 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
1907 : 0 : ret = i40e_vmdq_setup(dev);
1908 [ # # ]: 0 : if (ret)
1909 : 0 : goto err;
1910 : : }
1911 : :
1912 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
1913 : 0 : ret = i40e_dcb_setup(dev);
1914 [ # # ]: 0 : if (ret) {
1915 : 0 : PMD_DRV_LOG(ERR, "failed to configure DCB.");
1916 : 0 : goto err_dcb;
1917 : : }
1918 : : }
1919 : :
1920 : 0 : TAILQ_INIT(&pf->flow_list);
1921 : :
1922 : 0 : return 0;
1923 : :
1924 : : err_dcb:
1925 : : /* need to release vmdq resource if exists */
1926 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1927 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
1928 : 0 : pf->vmdq[i].vsi = NULL;
1929 : : }
1930 : 0 : rte_free(pf->vmdq);
1931 : 0 : pf->vmdq = NULL;
1932 : : err:
1933 : : return ret;
1934 : : }
1935 : :
1936 : : void
1937 : 0 : i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1938 : : {
1939 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
1940 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1941 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1942 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1943 : 0 : uint16_t msix_vect = vsi->msix_intr;
1944 : : uint16_t i;
1945 : :
1946 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
1947 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1948 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1949 : : rte_wmb();
1950 : : }
1951 : :
1952 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
1953 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
1954 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1955 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1956 : 0 : I40E_WRITE_REG(hw,
1957 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1958 : : 0);
1959 : : } else {
1960 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1961 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1962 : 0 : I40E_WRITE_REG(hw,
1963 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1964 : : msix_vect - 1), 0);
1965 : : }
1966 : : } else {
1967 : : uint32_t reg;
1968 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1969 : 0 : vsi->user_param + (msix_vect - 1);
1970 : :
1971 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1972 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1973 : : }
1974 : 0 : I40E_WRITE_FLUSH(hw);
1975 : 0 : }
1976 : :
1977 : : static void
1978 : 0 : __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1979 : : int base_queue, int nb_queue,
1980 : : uint16_t itr_idx)
1981 : : {
1982 : : int i;
1983 : : uint32_t val;
1984 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1985 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1986 : :
1987 : : /* Bind all RX queues to allocated MSIX interrupt */
1988 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
1989 : 0 : val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1990 : 0 : itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
1991 : 0 : ((base_queue + i + 1) <<
1992 : 0 : I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1993 : 0 : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1994 : : I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1995 : :
1996 [ # # ]: 0 : if (i == nb_queue - 1)
1997 : 0 : val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1998 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1999 : : }
2000 : :
2001 : : /* Write first RX queue to Link list register as the head element */
2002 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2003 : : uint16_t interval =
2004 : : i40e_calc_itr_interval(1, pf->support_multi_driver);
2005 : :
2006 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2007 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2008 : : (base_queue <<
2009 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2010 : : (0x0 <<
2011 : : I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2012 : 0 : I40E_WRITE_REG(hw,
2013 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2014 : : interval);
2015 : : } else {
2016 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2017 : : (base_queue <<
2018 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2019 : : (0x0 <<
2020 : : I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2021 : 0 : I40E_WRITE_REG(hw,
2022 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2023 : : msix_vect - 1),
2024 : : interval);
2025 : : }
2026 : : } else {
2027 : : uint32_t reg;
2028 : :
2029 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2030 : 0 : I40E_WRITE_REG(hw,
2031 : : I40E_VPINT_LNKLST0(vsi->user_param),
2032 : : (base_queue <<
2033 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2034 : : (0x0 <<
2035 : : I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2036 : : } else {
2037 : : /* num_msix_vectors_vf needs to minus irq0 */
2038 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2039 : 0 : vsi->user_param + (msix_vect - 1);
2040 : :
2041 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2042 : : (base_queue <<
2043 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2044 : : (0x0 <<
2045 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2046 : : }
2047 : : }
2048 : :
2049 : 0 : I40E_WRITE_FLUSH(hw);
2050 : 0 : }
2051 : :
2052 : : int
2053 : 0 : i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2054 : : {
2055 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2056 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2057 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2058 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2059 : 0 : uint16_t msix_vect = vsi->msix_intr;
2060 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2061 : : rte_intr_nb_efd_get(intr_handle));
2062 : : uint16_t queue_idx = 0;
2063 : : int record = 0;
2064 : : int i;
2065 : :
2066 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2067 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2068 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2069 : : }
2070 : :
2071 : : /* VF bind interrupt */
2072 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
2073 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2074 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2075 : 0 : return -EINVAL;
2076 : : }
2077 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2078 : 0 : vsi->base_queue, vsi->nb_qps,
2079 : : itr_idx);
2080 : 0 : return 0;
2081 : : }
2082 : :
2083 : : /* PF & VMDq bind interrupt */
2084 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2085 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN) {
2086 : : queue_idx = 0;
2087 : : record = 1;
2088 [ # # ]: 0 : } else if (vsi->type == I40E_VSI_VMDQ2) {
2089 : : struct i40e_vsi *main_vsi =
2090 [ # # ]: 0 : I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2091 : 0 : queue_idx = vsi->base_queue - main_vsi->nb_qps;
2092 : : record = 1;
2093 : : }
2094 : : }
2095 : :
2096 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
2097 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2098 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2099 : 0 : return -EINVAL;
2100 [ # # ]: 0 : } else if (nb_msix <= 1) {
2101 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2102 : : /* allow to share MISC_VEC_ID */
2103 : : msix_vect = I40E_MISC_VEC_ID;
2104 : :
2105 : : /* no enough msix_vect, map all to one */
2106 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2107 : 0 : vsi->base_queue + i,
2108 : 0 : vsi->nb_used_qps - i,
2109 : : itr_idx);
2110 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
2111 : 0 : rte_intr_vec_list_index_set(intr_handle,
2112 : : queue_idx + i, msix_vect);
2113 : : break;
2114 : : }
2115 : : /* 1:1 queue/msix_vect mapping */
2116 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2117 : 0 : vsi->base_queue + i, 1,
2118 : : itr_idx);
2119 [ # # ]: 0 : if (!!record)
2120 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle,
2121 : : queue_idx + i, msix_vect))
2122 : 0 : return -rte_errno;
2123 : :
2124 : 0 : msix_vect++;
2125 : 0 : nb_msix--;
2126 : : }
2127 : :
2128 : : return 0;
2129 : : }
2130 : :
2131 : : void
2132 : 0 : i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2133 : : {
2134 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2135 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2136 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2137 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2138 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2139 : : uint16_t msix_intr, i;
2140 : :
2141 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2142 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2143 : 0 : msix_intr = vsi->msix_intr + i;
2144 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2145 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
2146 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2147 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2148 : : }
2149 : : else
2150 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2151 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
2152 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2153 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2154 : :
2155 : 0 : I40E_WRITE_FLUSH(hw);
2156 : 0 : }
2157 : :
2158 : : void
2159 : 0 : i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2160 : : {
2161 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2162 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2163 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2164 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2165 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2166 : : uint16_t msix_intr, i;
2167 : :
2168 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2169 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2170 : 0 : msix_intr = vsi->msix_intr + i;
2171 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2172 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2173 : : }
2174 : : else
2175 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2176 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2177 : :
2178 : 0 : I40E_WRITE_FLUSH(hw);
2179 : 0 : }
2180 : :
2181 : : static inline uint8_t
2182 : 0 : i40e_parse_link_speeds(uint16_t link_speeds)
2183 : : {
2184 : : uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2185 : :
2186 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2187 : : link_speed |= I40E_LINK_SPEED_40GB;
2188 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2189 : 0 : link_speed |= I40E_LINK_SPEED_25GB;
2190 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2191 : 0 : link_speed |= I40E_LINK_SPEED_20GB;
2192 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2193 : 0 : link_speed |= I40E_LINK_SPEED_10GB;
2194 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2195 : 0 : link_speed |= I40E_LINK_SPEED_1GB;
2196 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2197 : 0 : link_speed |= I40E_LINK_SPEED_100MB;
2198 : :
2199 : 0 : return link_speed;
2200 : : }
2201 : :
2202 : : static int
2203 : 0 : i40e_phy_conf_link(struct i40e_hw *hw,
2204 : : uint8_t abilities,
2205 : : uint8_t force_speed,
2206 : : bool is_up)
2207 : : {
2208 : : enum i40e_status_code status;
2209 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
2210 : : struct i40e_aq_set_phy_config phy_conf;
2211 : : enum i40e_aq_phy_type cnt;
2212 : : uint8_t avail_speed;
2213 : : uint32_t phy_type_mask = 0;
2214 : :
2215 : : const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2216 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2217 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2218 : : I40E_AQ_PHY_FLAG_LOW_POWER;
2219 : : int ret = -ENOTSUP;
2220 : :
2221 : : /* To get phy capabilities of available speeds. */
2222 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2223 : : NULL);
2224 [ # # ]: 0 : if (status) {
2225 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d\n",
2226 : : status);
2227 : 0 : return ret;
2228 : : }
2229 : 0 : avail_speed = phy_ab.link_speed;
2230 : :
2231 : : /* To get the current phy config. */
2232 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2233 : : NULL);
2234 [ # # ]: 0 : if (status) {
2235 : 0 : PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d\n",
2236 : : status);
2237 : 0 : return ret;
2238 : : }
2239 : :
2240 : : /* If link needs to go up and it is in autoneg mode the speed is OK,
2241 : : * no need to set up again.
2242 : : */
2243 [ # # # # : 0 : if (is_up && phy_ab.phy_type != 0 &&
# # ]
2244 : 0 : abilities & I40E_AQ_PHY_AN_ENABLED &&
2245 [ # # ]: 0 : phy_ab.link_speed != 0)
2246 : : return I40E_SUCCESS;
2247 : :
2248 : : memset(&phy_conf, 0, sizeof(phy_conf));
2249 : :
2250 : : /* bits 0-2 use the values from get_phy_abilities_resp */
2251 : 0 : abilities &= ~mask;
2252 : 0 : abilities |= phy_ab.abilities & mask;
2253 : :
2254 : 0 : phy_conf.abilities = abilities;
2255 : :
2256 : : /* If link needs to go up, but the force speed is not supported,
2257 : : * Warn users and config the default available speeds.
2258 : : */
2259 [ # # # # ]: 0 : if (is_up && !(force_speed & avail_speed)) {
2260 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!\n");
2261 : 0 : phy_conf.link_speed = avail_speed;
2262 : : } else {
2263 [ # # ]: 0 : phy_conf.link_speed = is_up ? force_speed : avail_speed;
2264 : : }
2265 : :
2266 : : /* PHY type mask needs to include each type except PHY type extension */
2267 [ # # ]: 0 : for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2268 : 0 : phy_type_mask |= 1 << cnt;
2269 : :
2270 : : /* use get_phy_abilities_resp value for the rest */
2271 [ # # ]: 0 : phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2272 [ # # ]: 0 : phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2273 : : I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2274 : : I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2275 : : I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2276 : 0 : phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2277 : 0 : phy_conf.eee_capability = phy_ab.eee_capability;
2278 : 0 : phy_conf.eeer = phy_ab.eeer_val;
2279 : 0 : phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2280 : :
2281 : 0 : PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2282 : : phy_ab.abilities, phy_ab.link_speed);
2283 : 0 : PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2284 : : phy_conf.abilities, phy_conf.link_speed);
2285 : :
2286 : 0 : status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2287 [ # # ]: 0 : if (status)
2288 : 0 : return ret;
2289 : :
2290 : : return I40E_SUCCESS;
2291 : : }
2292 : :
2293 : : static int
2294 : 0 : i40e_apply_link_speed(struct rte_eth_dev *dev)
2295 : : {
2296 : : uint8_t speed;
2297 : : uint8_t abilities = 0;
2298 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2299 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
2300 : :
2301 : : abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2302 : : I40E_AQ_PHY_LINK_ENABLED;
2303 : :
2304 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2305 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2306 : : RTE_ETH_LINK_SPEED_25G |
2307 : : RTE_ETH_LINK_SPEED_20G |
2308 : : RTE_ETH_LINK_SPEED_10G |
2309 : : RTE_ETH_LINK_SPEED_1G |
2310 : : RTE_ETH_LINK_SPEED_100M;
2311 : :
2312 : : abilities |= I40E_AQ_PHY_AN_ENABLED;
2313 : : } else {
2314 : : abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2315 : : }
2316 : 0 : speed = i40e_parse_link_speeds(conf->link_speeds);
2317 : :
2318 : 0 : return i40e_phy_conf_link(hw, abilities, speed, true);
2319 : : }
2320 : :
2321 : : static int
2322 : 0 : i40e_dev_start(struct rte_eth_dev *dev)
2323 : : {
2324 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2325 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2326 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2327 : : int ret, i;
2328 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2329 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2330 : : uint32_t intr_vector = 0;
2331 : : struct i40e_vsi *vsi;
2332 : : uint16_t nb_rxq, nb_txq;
2333 : : uint16_t max_frame_size;
2334 : :
2335 : 0 : hw->adapter_stopped = 0;
2336 : :
2337 : 0 : rte_intr_disable(intr_handle);
2338 : :
2339 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2340 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2341 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2342 : 0 : intr_vector = dev->data->nb_rx_queues;
2343 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
2344 [ # # ]: 0 : if (ret)
2345 : : return ret;
2346 : : }
2347 : :
2348 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2349 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2350 : 0 : dev->data->nb_rx_queues)) {
2351 : 0 : PMD_INIT_LOG(ERR,
2352 : : "Failed to allocate %d rx_queues intr_vec",
2353 : : dev->data->nb_rx_queues);
2354 : 0 : return -ENOMEM;
2355 : : }
2356 : : }
2357 : :
2358 : : /* Initialize VSI */
2359 : 0 : ret = i40e_dev_rxtx_init(pf);
2360 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2361 : 0 : PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2362 : 0 : return ret;
2363 : : }
2364 : :
2365 : : /* Map queues with MSIX interrupt */
2366 : 0 : main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2367 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2368 : 0 : ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2369 [ # # ]: 0 : if (ret < 0)
2370 : : return ret;
2371 : 0 : i40e_vsi_enable_queues_intr(main_vsi);
2372 : :
2373 : : /* Map VMDQ VSI queues with MSIX interrupt */
2374 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2375 : 0 : pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2376 : 0 : ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2377 : : I40E_ITR_INDEX_DEFAULT);
2378 [ # # ]: 0 : if (ret < 0)
2379 : 0 : return ret;
2380 : 0 : i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2381 : : }
2382 : :
2383 : : /* Enable all queues which have been configured */
2384 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2385 : 0 : ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2386 [ # # ]: 0 : if (ret)
2387 : 0 : goto rx_err;
2388 : : }
2389 : :
2390 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2391 : 0 : ret = i40e_dev_tx_queue_start(dev, nb_txq);
2392 [ # # ]: 0 : if (ret)
2393 : 0 : goto tx_err;
2394 : : }
2395 : :
2396 : : /* Enable receiving broadcast packets */
2397 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2398 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2399 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2400 : :
2401 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2402 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2403 : : true, NULL);
2404 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2405 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2406 : : }
2407 : :
2408 : : /* Enable the VLAN promiscuous mode. */
2409 [ # # ]: 0 : if (pf->vfs) {
2410 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
2411 : 0 : vsi = pf->vfs[i].vsi;
2412 : 0 : i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2413 : : true, NULL);
2414 : : }
2415 : : }
2416 : :
2417 : : /* Disable mac loopback mode */
2418 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE) {
2419 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MODE_NONE, NULL);
2420 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2421 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2422 : 0 : goto tx_err;
2423 : : }
2424 : : }
2425 : :
2426 : : /* Enable mac loopback mode */
2427 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_EN) {
2428 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2429 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC_LOCAL_X722, NULL);
2430 : : else
2431 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC, NULL);
2432 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2433 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2434 : 0 : goto tx_err;
2435 : : }
2436 : : }
2437 : :
2438 : : /* Apply link configure */
2439 : 0 : ret = i40e_apply_link_speed(dev);
2440 [ # # ]: 0 : if (I40E_SUCCESS != ret) {
2441 : 0 : PMD_DRV_LOG(ERR, "Fail to apply link setting");
2442 : 0 : goto tx_err;
2443 : : }
2444 : :
2445 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2446 : 0 : rte_intr_callback_unregister(intr_handle,
2447 : : i40e_dev_interrupt_handler,
2448 : : (void *)dev);
2449 : : /* configure and enable device interrupt */
2450 : : i40e_pf_config_irq0(hw, FALSE);
2451 : 0 : i40e_pf_enable_irq0(hw);
2452 : :
2453 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2454 : 0 : PMD_INIT_LOG(INFO,
2455 : : "lsc won't enable because of no intr multiplex");
2456 : : } else {
2457 : 0 : ret = i40e_aq_set_phy_int_mask(hw,
2458 : : ~(I40E_AQ_EVENT_LINK_UPDOWN |
2459 : : I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2460 : : I40E_AQ_EVENT_MEDIA_NA), NULL);
2461 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2462 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2463 : :
2464 : : /* Call get_link_info aq command to enable/disable LSE */
2465 : 0 : i40e_dev_link_update(dev, 1);
2466 : : }
2467 : :
2468 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2469 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2470 : : i40e_dev_alarm_handler, dev);
2471 : : } else {
2472 : : /* enable uio intr after callback register */
2473 : 0 : rte_intr_enable(intr_handle);
2474 : : }
2475 : :
2476 : 0 : i40e_filter_restore(pf);
2477 : :
2478 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2479 : 0 : PMD_DRV_LOG(WARNING,
2480 : : "please call hierarchy_commit() "
2481 : : "before starting the port");
2482 : :
2483 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2484 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2485 : : I40E_FRAME_SIZE_MAX;
2486 : :
2487 : : /* Set the max frame size to HW*/
2488 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2489 : :
2490 : 0 : return I40E_SUCCESS;
2491 : :
2492 : 0 : tx_err:
2493 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2494 : 0 : i40e_dev_tx_queue_stop(dev, i);
2495 : 0 : rx_err:
2496 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2497 : 0 : i40e_dev_rx_queue_stop(dev, i);
2498 : :
2499 : : return ret;
2500 : : }
2501 : :
2502 : : static int
2503 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2504 : : {
2505 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2506 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2507 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2508 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2509 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2510 : : int i;
2511 : :
2512 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2513 : : return 0;
2514 : :
2515 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2516 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2517 : 0 : rte_intr_enable(intr_handle);
2518 : : }
2519 : :
2520 : : /* Disable all queues */
2521 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2522 : 0 : i40e_dev_tx_queue_stop(dev, i);
2523 : :
2524 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2525 : 0 : i40e_dev_rx_queue_stop(dev, i);
2526 : :
2527 : : /* un-map queues with interrupt registers */
2528 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2529 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2530 : :
2531 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2532 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2533 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2534 : : }
2535 : :
2536 : : /* Clear all queues and release memory */
2537 : 0 : i40e_dev_clear_queues(dev);
2538 : :
2539 : : /* Set link down */
2540 : : i40e_dev_set_link_down(dev);
2541 : :
2542 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2543 : : /* resume to the default handler */
2544 : 0 : rte_intr_callback_register(intr_handle,
2545 : : i40e_dev_interrupt_handler,
2546 : : (void *)dev);
2547 : :
2548 : : /* Clean datapath event and queue/vec mapping */
2549 : 0 : rte_intr_efd_disable(intr_handle);
2550 : :
2551 : : /* Cleanup vector list */
2552 : 0 : rte_intr_vec_list_free(intr_handle);
2553 : :
2554 : : /* reset hierarchy commit */
2555 : 0 : pf->tm_conf.committed = false;
2556 : :
2557 : 0 : hw->adapter_stopped = 1;
2558 : 0 : dev->data->dev_started = 0;
2559 : :
2560 : 0 : pf->adapter->rss_reta_updated = 0;
2561 : :
2562 : 0 : return 0;
2563 : : }
2564 : :
2565 : : static int
2566 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2567 : : {
2568 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2569 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2570 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2571 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2572 : : struct i40e_filter_control_settings settings;
2573 : : struct rte_flow *p_flow;
2574 : : uint32_t reg;
2575 : : int i;
2576 : : int ret;
2577 : 0 : uint8_t aq_fail = 0;
2578 : : int retries = 0;
2579 : :
2580 : 0 : PMD_INIT_FUNC_TRACE();
2581 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2582 : : return 0;
2583 : :
2584 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2585 [ # # ]: 0 : if (ret)
2586 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2587 : :
2588 : :
2589 : 0 : ret = i40e_dev_stop(dev);
2590 : :
2591 : 0 : i40e_dev_free_queues(dev);
2592 : :
2593 : : /* Disable interrupt */
2594 : 0 : i40e_pf_disable_irq0(hw);
2595 : 0 : rte_intr_disable(intr_handle);
2596 : :
2597 : : /* shutdown and destroy the HMC */
2598 : 0 : i40e_shutdown_lan_hmc(hw);
2599 : :
2600 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2601 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2602 : 0 : pf->vmdq[i].vsi = NULL;
2603 : : }
2604 : 0 : rte_free(pf->vmdq);
2605 : 0 : pf->vmdq = NULL;
2606 : :
2607 : : /* release all the existing VSIs and VEBs */
2608 : 0 : i40e_vsi_release(pf->main_vsi);
2609 : :
2610 : : /* shutdown the adminq */
2611 : 0 : i40e_aq_queue_shutdown(hw, true);
2612 : 0 : i40e_shutdown_adminq(hw);
2613 : :
2614 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2615 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2616 : :
2617 : : /* Disable flexible payload in global configuration */
2618 [ # # ]: 0 : if (!pf->support_multi_driver)
2619 : 0 : i40e_flex_payload_reg_set_default(hw);
2620 : :
2621 : : /* force a PF reset to clean anything leftover */
2622 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2623 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2624 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2625 : 0 : I40E_WRITE_FLUSH(hw);
2626 : :
2627 : : /* Clear PXE mode */
2628 : 0 : i40e_clear_pxe_mode(hw);
2629 : :
2630 : : /* Unconfigure filter control */
2631 : : memset(&settings, 0, sizeof(settings));
2632 : 0 : ret = i40e_set_filter_control(hw, &settings);
2633 [ # # ]: 0 : if (ret)
2634 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2635 : : ret);
2636 : :
2637 : : /* Disable flow control */
2638 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2639 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2640 : :
2641 : : /* uninitialize pf host driver */
2642 : 0 : i40e_pf_host_uninit(dev);
2643 : :
2644 : : do {
2645 : 0 : ret = rte_intr_callback_unregister(intr_handle,
2646 : : i40e_dev_interrupt_handler, dev);
2647 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
2648 : : break;
2649 [ # # ]: 0 : } else if (ret != -EAGAIN) {
2650 : 0 : PMD_INIT_LOG(ERR,
2651 : : "intr callback unregister failed: %d",
2652 : : ret);
2653 : : }
2654 : 0 : i40e_msec_delay(500);
2655 [ # # ]: 0 : } while (retries++ < 5);
2656 : :
2657 : 0 : i40e_rm_ethtype_filter_list(pf);
2658 : 0 : i40e_rm_tunnel_filter_list(pf);
2659 : : i40e_rm_fdir_filter_list(pf);
2660 : :
2661 : : /* Remove all flows */
2662 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2663 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2664 : : /* Do not free FDIR flows since they are static allocated */
2665 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2666 : 0 : rte_free(p_flow);
2667 : : }
2668 : :
2669 : : /* release the fdir static allocated memory */
2670 : 0 : i40e_fdir_memory_cleanup(pf);
2671 : :
2672 : : /* Remove all Traffic Manager configuration */
2673 : 0 : i40e_tm_conf_uninit(dev);
2674 : :
2675 : : i40e_clear_automask(pf);
2676 : :
2677 : 0 : hw->adapter_closed = 1;
2678 : 0 : return ret;
2679 : : }
2680 : :
2681 : : /*
2682 : : * Reset PF device only to re-initialize resources in PMD layer
2683 : : */
2684 : : static int
2685 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2686 : : {
2687 : : int ret;
2688 : :
2689 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2690 : : * its VF to make them align with it. The detailed notification
2691 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2692 : : * To avoid unexpected behavior in VF, currently reset of PF with
2693 : : * SR-IOV activation is not supported. It might be supported later.
2694 : : */
2695 [ # # ]: 0 : if (dev->data->sriov.active)
2696 : : return -ENOTSUP;
2697 : :
2698 : 0 : ret = eth_i40e_dev_uninit(dev);
2699 [ # # ]: 0 : if (ret)
2700 : : return ret;
2701 : :
2702 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2703 : :
2704 : 0 : return ret;
2705 : : }
2706 : :
2707 : : static int
2708 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2709 : : {
2710 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2711 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2712 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2713 : : int status;
2714 : :
2715 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2716 : : true, NULL, true);
2717 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2718 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2719 : 0 : return -EAGAIN;
2720 : : }
2721 : :
2722 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2723 : : TRUE, NULL);
2724 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2725 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2726 : : /* Rollback unicast promiscuous mode */
2727 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2728 : : false, NULL, true);
2729 : 0 : return -EAGAIN;
2730 : : }
2731 : :
2732 : : return 0;
2733 : : }
2734 : :
2735 : : static int
2736 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2737 : : {
2738 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2739 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2740 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2741 : : int status;
2742 : :
2743 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2744 : : false, NULL, true);
2745 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2746 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2747 : 0 : return -EAGAIN;
2748 : : }
2749 : :
2750 : : /* must remain in all_multicast mode */
2751 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2752 : : return 0;
2753 : :
2754 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2755 : : false, NULL);
2756 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2757 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2758 : : /* Rollback unicast promiscuous mode */
2759 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2760 : : true, NULL, true);
2761 : 0 : return -EAGAIN;
2762 : : }
2763 : :
2764 : : return 0;
2765 : : }
2766 : :
2767 : : static int
2768 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2769 : : {
2770 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2771 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2772 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2773 : : int ret;
2774 : :
2775 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2776 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2777 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2778 : 0 : return -EAGAIN;
2779 : : }
2780 : :
2781 : : return 0;
2782 : : }
2783 : :
2784 : : static int
2785 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2786 : : {
2787 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2788 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2789 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2790 : : int ret;
2791 : :
2792 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2793 : : return 0; /* must remain in all_multicast mode */
2794 : :
2795 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2796 : 0 : vsi->seid, FALSE, NULL);
2797 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2798 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2799 : 0 : return -EAGAIN;
2800 : : }
2801 : :
2802 : : return 0;
2803 : : }
2804 : :
2805 : : /*
2806 : : * Set device link up.
2807 : : */
2808 : : static int
2809 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2810 : : {
2811 : : /* re-apply link speed setting */
2812 : 0 : return i40e_apply_link_speed(dev);
2813 : : }
2814 : :
2815 : : /*
2816 : : * Set device link down.
2817 : : */
2818 : : static int
2819 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2820 : : {
2821 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2822 : : uint8_t abilities = 0;
2823 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2824 : :
2825 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2826 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2827 : : }
2828 : :
2829 : : static __rte_always_inline void
2830 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2831 : : {
2832 : : /* Link status registers and values*/
2833 : : #define I40E_REG_LINK_UP 0x40000080
2834 : : #define I40E_PRTMAC_MACC 0x001E24E0
2835 : : #define I40E_REG_MACC_25GB 0x00020000
2836 : : #define I40E_REG_SPEED_MASK 0x38000000
2837 : : #define I40E_REG_SPEED_0 0x00000000
2838 : : #define I40E_REG_SPEED_1 0x08000000
2839 : : #define I40E_REG_SPEED_2 0x10000000
2840 : : #define I40E_REG_SPEED_3 0x18000000
2841 : : #define I40E_REG_SPEED_4 0x20000000
2842 : : uint32_t link_speed;
2843 : : uint32_t reg_val;
2844 : :
2845 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2846 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2847 : 0 : reg_val &= I40E_REG_LINK_UP;
2848 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2849 : :
2850 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2851 : : return;
2852 : :
2853 : : /* Parse the link status */
2854 [ # # # # : 0 : switch (link_speed) {
# # ]
2855 : 0 : case I40E_REG_SPEED_0:
2856 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2857 : 0 : break;
2858 : 0 : case I40E_REG_SPEED_1:
2859 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2860 : 0 : break;
2861 : 0 : case I40E_REG_SPEED_2:
2862 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2863 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2864 : : else
2865 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2866 : : break;
2867 : 0 : case I40E_REG_SPEED_3:
2868 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2869 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
2870 : : } else {
2871 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2872 : :
2873 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
2874 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2875 : : else
2876 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2877 : : }
2878 : : break;
2879 : 0 : case I40E_REG_SPEED_4:
2880 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2881 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2882 : : else
2883 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
2884 : : break;
2885 : 0 : default:
2886 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2887 : 0 : break;
2888 : : }
2889 : : }
2890 : :
2891 : : static __rte_always_inline void
2892 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
2893 : : bool enable_lse, int wait_to_complete)
2894 : : {
2895 : : #define CHECK_INTERVAL 100 /* 100ms */
2896 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2897 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
2898 : : struct i40e_link_status link_status;
2899 : : int status;
2900 : :
2901 : : memset(&link_status, 0, sizeof(link_status));
2902 : :
2903 : : do {
2904 : : memset(&link_status, 0, sizeof(link_status));
2905 : :
2906 : : /* Get link status information from hardware */
2907 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
2908 : : &link_status, NULL);
2909 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
2910 : : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
2911 : : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2912 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
2913 : 0 : return;
2914 : : }
2915 : :
2916 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
2917 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
2918 : : break;
2919 : :
2920 : : rte_delay_ms(CHECK_INTERVAL);
2921 [ # # ]: 0 : } while (--rep_cnt);
2922 : :
2923 : : /* Parse the link status */
2924 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
2925 : 0 : case I40E_LINK_SPEED_100MB:
2926 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2927 : 0 : break;
2928 : 0 : case I40E_LINK_SPEED_1GB:
2929 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2930 : 0 : break;
2931 : 0 : case I40E_LINK_SPEED_10GB:
2932 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2933 : 0 : break;
2934 : 0 : case I40E_LINK_SPEED_20GB:
2935 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
2936 : 0 : break;
2937 : 0 : case I40E_LINK_SPEED_25GB:
2938 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2939 : 0 : break;
2940 : 0 : case I40E_LINK_SPEED_40GB:
2941 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2942 : 0 : break;
2943 : 0 : default:
2944 [ # # ]: 0 : if (link->link_status)
2945 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
2946 : : else
2947 : : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
2948 : : break;
2949 : : }
2950 : : }
2951 : :
2952 : : int
2953 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
2954 : : int wait_to_complete)
2955 : : {
2956 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2957 : : struct rte_eth_link link;
2958 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2959 : : int ret;
2960 : :
2961 : : memset(&link, 0, sizeof(link));
2962 : :
2963 : : /* i40e uses full duplex only */
2964 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2965 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2966 : : RTE_ETH_LINK_SPEED_FIXED);
2967 : :
2968 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
2969 : : update_link_reg(hw, &link);
2970 : : else
2971 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
2972 : :
2973 [ # # ]: 0 : if (hw->switch_dev)
2974 : : rte_eth_linkstatus_get(hw->switch_dev, &link);
2975 : :
2976 : : ret = rte_eth_linkstatus_set(dev, &link);
2977 : 0 : i40e_notify_all_vfs_link_status(dev);
2978 : :
2979 : 0 : return ret;
2980 : : }
2981 : :
2982 : : static void
2983 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
2984 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
2985 : : uint64_t *stat, uint64_t *prev_stat)
2986 : : {
2987 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
2988 : : /* enlarge the limitation when statistics counters overflowed */
2989 [ # # ]: 0 : if (offset_loaded) {
2990 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
2991 : 0 : *stat += (uint64_t)1 << I40E_48_BIT_WIDTH;
2992 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
2993 : : }
2994 : 0 : *prev_stat = *stat;
2995 : 0 : }
2996 : :
2997 : : /* Get all the statistics of a VSI */
2998 : : void
2999 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3000 : : {
3001 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3002 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3003 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3004 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3005 : :
3006 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3007 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3008 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3009 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3010 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3011 : 0 : &nes->rx_unicast);
3012 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3013 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3014 : 0 : &nes->rx_multicast);
3015 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3016 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3017 : 0 : &nes->rx_broadcast);
3018 : : /* exclude CRC bytes */
3019 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3020 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3021 : :
3022 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3023 : : &oes->rx_discards, &nes->rx_discards);
3024 : : /* GLV_REPC not supported */
3025 : : /* GLV_RMPC not supported */
3026 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3027 : : &oes->rx_unknown_protocol,
3028 : : &nes->rx_unknown_protocol);
3029 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3030 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3031 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3032 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3033 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3034 : 0 : &nes->tx_unicast);
3035 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3036 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3037 : 0 : &nes->tx_multicast);
3038 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3039 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3040 : 0 : &nes->tx_broadcast);
3041 : : /* GLV_TDPC not supported */
3042 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3043 : : &oes->tx_errors, &nes->tx_errors);
3044 : 0 : vsi->offset_loaded = true;
3045 : :
3046 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3047 : : vsi->vsi_id);
3048 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3049 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3050 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3051 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3052 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3053 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3054 : : nes->rx_unknown_protocol);
3055 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3056 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3057 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3058 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3059 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3060 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3061 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3062 : : vsi->vsi_id);
3063 : 0 : }
3064 : :
3065 : : static void
3066 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3067 : : {
3068 : : unsigned int i;
3069 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3070 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3071 : :
3072 : : /* Get rx/tx bytes of internal transfer packets */
3073 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3074 : 0 : I40E_GLV_GORCL(hw->port),
3075 : 0 : pf->offset_loaded,
3076 : 0 : &pf->internal_stats_offset.rx_bytes,
3077 : 0 : &pf->internal_stats.rx_bytes,
3078 : : &pf->internal_prev_rx_bytes);
3079 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3080 : 0 : I40E_GLV_GOTCL(hw->port),
3081 : 0 : pf->offset_loaded,
3082 : 0 : &pf->internal_stats_offset.tx_bytes,
3083 : 0 : &pf->internal_stats.tx_bytes,
3084 : : &pf->internal_prev_tx_bytes);
3085 : : /* Get total internal rx packet count */
3086 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3087 : 0 : I40E_GLV_UPRCL(hw->port),
3088 : 0 : pf->offset_loaded,
3089 : 0 : &pf->internal_stats_offset.rx_unicast,
3090 : 0 : &pf->internal_stats.rx_unicast);
3091 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3092 : 0 : I40E_GLV_MPRCL(hw->port),
3093 : 0 : pf->offset_loaded,
3094 : 0 : &pf->internal_stats_offset.rx_multicast,
3095 : 0 : &pf->internal_stats.rx_multicast);
3096 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3097 : 0 : I40E_GLV_BPRCL(hw->port),
3098 : 0 : pf->offset_loaded,
3099 : 0 : &pf->internal_stats_offset.rx_broadcast,
3100 : 0 : &pf->internal_stats.rx_broadcast);
3101 : : /* Get total internal tx packet count */
3102 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3103 : 0 : I40E_GLV_UPTCL(hw->port),
3104 : 0 : pf->offset_loaded,
3105 : 0 : &pf->internal_stats_offset.tx_unicast,
3106 : 0 : &pf->internal_stats.tx_unicast);
3107 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3108 : 0 : I40E_GLV_MPTCL(hw->port),
3109 : 0 : pf->offset_loaded,
3110 : 0 : &pf->internal_stats_offset.tx_multicast,
3111 : 0 : &pf->internal_stats.tx_multicast);
3112 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3113 : 0 : I40E_GLV_BPTCL(hw->port),
3114 : 0 : pf->offset_loaded,
3115 : 0 : &pf->internal_stats_offset.tx_broadcast,
3116 : 0 : &pf->internal_stats.tx_broadcast);
3117 : :
3118 : : /* exclude CRC size */
3119 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3120 : 0 : pf->internal_stats.rx_multicast +
3121 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3122 : :
3123 : : /* Get statistics of struct i40e_eth_stats */
3124 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3125 : 0 : I40E_GLPRT_GORCL(hw->port),
3126 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3127 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3128 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3129 : 0 : I40E_GLPRT_UPRCL(hw->port),
3130 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3131 : 0 : &ns->eth.rx_unicast);
3132 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3133 : 0 : I40E_GLPRT_MPRCL(hw->port),
3134 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3135 : 0 : &ns->eth.rx_multicast);
3136 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3137 : 0 : I40E_GLPRT_BPRCL(hw->port),
3138 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3139 : 0 : &ns->eth.rx_broadcast);
3140 : : /* Workaround: CRC size should not be included in byte statistics,
3141 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3142 : : * packet.
3143 : : */
3144 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3145 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3146 : :
3147 : : /* exclude internal rx bytes
3148 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3149 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3150 : : * value.
3151 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3152 : : */
3153 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3154 : 0 : ns->eth.rx_bytes = 0;
3155 : : else
3156 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3157 : :
3158 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3159 : 0 : ns->eth.rx_unicast = 0;
3160 : : else
3161 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3162 : :
3163 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3164 : 0 : ns->eth.rx_multicast = 0;
3165 : : else
3166 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3167 : :
3168 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3169 : 0 : ns->eth.rx_broadcast = 0;
3170 : : else
3171 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3172 : :
3173 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3174 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3175 : : &ns->eth.rx_discards);
3176 : : /* GLPRT_REPC not supported */
3177 : : /* GLPRT_RMPC not supported */
3178 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3179 : 0 : pf->offset_loaded,
3180 : : &os->eth.rx_unknown_protocol,
3181 : : &ns->eth.rx_unknown_protocol);
3182 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1_H(hw->pf_id + I40E_MAX_VF),
3183 : 0 : I40E_GL_RXERR1_L(hw->pf_id + I40E_MAX_VF),
3184 : 0 : pf->offset_loaded, &pf->rx_err1_offset,
3185 : 0 : &pf->rx_err1);
3186 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3187 : 0 : I40E_GLPRT_GOTCL(hw->port),
3188 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3189 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3190 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3191 : 0 : I40E_GLPRT_UPTCL(hw->port),
3192 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3193 : 0 : &ns->eth.tx_unicast);
3194 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3195 : 0 : I40E_GLPRT_MPTCL(hw->port),
3196 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3197 : 0 : &ns->eth.tx_multicast);
3198 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3199 : 0 : I40E_GLPRT_BPTCL(hw->port),
3200 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3201 : 0 : &ns->eth.tx_broadcast);
3202 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3203 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3204 : :
3205 : : /* exclude internal tx bytes
3206 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3207 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3208 : : * value.
3209 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3210 : : */
3211 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3212 : 0 : ns->eth.tx_bytes = 0;
3213 : : else
3214 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3215 : :
3216 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3217 : 0 : ns->eth.tx_unicast = 0;
3218 : : else
3219 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3220 : :
3221 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3222 : 0 : ns->eth.tx_multicast = 0;
3223 : : else
3224 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3225 : :
3226 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3227 : 0 : ns->eth.tx_broadcast = 0;
3228 : : else
3229 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3230 : :
3231 : : /* GLPRT_TEPC not supported */
3232 : :
3233 : : /* additional port specific stats */
3234 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3235 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3236 : : &ns->tx_dropped_link_down);
3237 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3238 : 0 : pf->offset_loaded, &os->crc_errors,
3239 : : &ns->crc_errors);
3240 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3241 : 0 : pf->offset_loaded, &os->illegal_bytes,
3242 : : &ns->illegal_bytes);
3243 : : /* GLPRT_ERRBC not supported */
3244 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3245 : 0 : pf->offset_loaded, &os->mac_local_faults,
3246 : : &ns->mac_local_faults);
3247 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3248 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3249 : : &ns->mac_remote_faults);
3250 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3251 : 0 : pf->offset_loaded, &os->rx_length_errors,
3252 : : &ns->rx_length_errors);
3253 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3254 : 0 : pf->offset_loaded, &os->link_xon_rx,
3255 : : &ns->link_xon_rx);
3256 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3257 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3258 : : &ns->link_xoff_rx);
3259 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3260 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3261 : 0 : pf->offset_loaded,
3262 : : &os->priority_xon_rx[i],
3263 : : &ns->priority_xon_rx[i]);
3264 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3265 : 0 : pf->offset_loaded,
3266 : : &os->priority_xoff_rx[i],
3267 : : &ns->priority_xoff_rx[i]);
3268 : : }
3269 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3270 : 0 : pf->offset_loaded, &os->link_xon_tx,
3271 : : &ns->link_xon_tx);
3272 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3273 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3274 : : &ns->link_xoff_tx);
3275 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3276 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3277 : 0 : pf->offset_loaded,
3278 : : &os->priority_xon_tx[i],
3279 : : &ns->priority_xon_tx[i]);
3280 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3281 : 0 : pf->offset_loaded,
3282 : : &os->priority_xoff_tx[i],
3283 : : &ns->priority_xoff_tx[i]);
3284 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3285 : 0 : pf->offset_loaded,
3286 : : &os->priority_xon_2_xoff[i],
3287 : : &ns->priority_xon_2_xoff[i]);
3288 : : }
3289 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3290 : 0 : I40E_GLPRT_PRC64L(hw->port),
3291 : 0 : pf->offset_loaded, &os->rx_size_64,
3292 : 0 : &ns->rx_size_64);
3293 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3294 : 0 : I40E_GLPRT_PRC127L(hw->port),
3295 : 0 : pf->offset_loaded, &os->rx_size_127,
3296 : 0 : &ns->rx_size_127);
3297 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3298 : 0 : I40E_GLPRT_PRC255L(hw->port),
3299 : 0 : pf->offset_loaded, &os->rx_size_255,
3300 : 0 : &ns->rx_size_255);
3301 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3302 : 0 : I40E_GLPRT_PRC511L(hw->port),
3303 : 0 : pf->offset_loaded, &os->rx_size_511,
3304 : 0 : &ns->rx_size_511);
3305 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3306 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3307 : 0 : pf->offset_loaded, &os->rx_size_1023,
3308 : 0 : &ns->rx_size_1023);
3309 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3310 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3311 : 0 : pf->offset_loaded, &os->rx_size_1522,
3312 : 0 : &ns->rx_size_1522);
3313 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3314 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3315 : 0 : pf->offset_loaded, &os->rx_size_big,
3316 : 0 : &ns->rx_size_big);
3317 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3318 : 0 : pf->offset_loaded, &os->rx_undersize,
3319 : : &ns->rx_undersize);
3320 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3321 : 0 : pf->offset_loaded, &os->rx_fragments,
3322 : : &ns->rx_fragments);
3323 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3324 : 0 : pf->offset_loaded, &os->rx_oversize,
3325 : : &ns->rx_oversize);
3326 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3327 : 0 : pf->offset_loaded, &os->rx_jabber,
3328 : : &ns->rx_jabber);
3329 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3330 : 0 : I40E_GLPRT_PTC64L(hw->port),
3331 : 0 : pf->offset_loaded, &os->tx_size_64,
3332 : 0 : &ns->tx_size_64);
3333 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3334 : 0 : I40E_GLPRT_PTC127L(hw->port),
3335 : 0 : pf->offset_loaded, &os->tx_size_127,
3336 : 0 : &ns->tx_size_127);
3337 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3338 : 0 : I40E_GLPRT_PTC255L(hw->port),
3339 : 0 : pf->offset_loaded, &os->tx_size_255,
3340 : 0 : &ns->tx_size_255);
3341 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3342 : 0 : I40E_GLPRT_PTC511L(hw->port),
3343 : 0 : pf->offset_loaded, &os->tx_size_511,
3344 : 0 : &ns->tx_size_511);
3345 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3346 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3347 : 0 : pf->offset_loaded, &os->tx_size_1023,
3348 : 0 : &ns->tx_size_1023);
3349 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3350 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3351 : 0 : pf->offset_loaded, &os->tx_size_1522,
3352 : 0 : &ns->tx_size_1522);
3353 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3354 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3355 : 0 : pf->offset_loaded, &os->tx_size_big,
3356 : 0 : &ns->tx_size_big);
3357 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3358 : 0 : pf->offset_loaded,
3359 : : &os->fd_sb_match, &ns->fd_sb_match);
3360 : : /* GLPRT_MSPDC not supported */
3361 : : /* GLPRT_XEC not supported */
3362 : :
3363 : 0 : pf->offset_loaded = true;
3364 : :
3365 [ # # ]: 0 : if (pf->main_vsi)
3366 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3367 : 0 : }
3368 : :
3369 : : /* Get all statistics of a port */
3370 : : static int
3371 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3372 : : {
3373 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3374 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3375 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3376 : : struct i40e_vsi *vsi;
3377 : : unsigned i;
3378 : :
3379 : : /* call read registers - updates values, now write them to struct */
3380 : 0 : i40e_read_stats_registers(pf, hw);
3381 : :
3382 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3383 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3384 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3385 : 0 : pf->main_vsi->eth_stats.rx_discards -
3386 : 0 : pf->rx_err1;
3387 : 0 : stats->opackets = ns->eth.tx_unicast +
3388 : 0 : ns->eth.tx_multicast +
3389 : 0 : ns->eth.tx_broadcast;
3390 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3391 : 0 : stats->obytes = ns->eth.tx_bytes;
3392 : 0 : stats->oerrors = ns->eth.tx_errors +
3393 : 0 : pf->main_vsi->eth_stats.tx_errors;
3394 : :
3395 : : /* Rx Errors */
3396 : 0 : stats->imissed = ns->eth.rx_discards +
3397 : : pf->main_vsi->eth_stats.rx_discards;
3398 : 0 : stats->ierrors = ns->crc_errors +
3399 : 0 : ns->rx_length_errors + ns->rx_undersize +
3400 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3401 : : pf->rx_err1;
3402 : :
3403 [ # # ]: 0 : if (pf->vfs) {
3404 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3405 : 0 : vsi = pf->vfs[i].vsi;
3406 : 0 : i40e_update_vsi_stats(vsi);
3407 : :
3408 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3409 : 0 : vsi->eth_stats.rx_multicast +
3410 : 0 : vsi->eth_stats.rx_broadcast -
3411 : 0 : vsi->eth_stats.rx_discards);
3412 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3413 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3414 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3415 : : }
3416 : : }
3417 : :
3418 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3419 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3420 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3421 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3422 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3423 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3424 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3425 : : ns->eth.rx_unknown_protocol);
3426 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3427 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3428 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3429 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3430 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3431 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3432 : :
3433 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3434 : : ns->tx_dropped_link_down);
3435 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3436 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3437 : : ns->illegal_bytes);
3438 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3439 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3440 : : ns->mac_local_faults);
3441 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3442 : : ns->mac_remote_faults);
3443 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3444 : : ns->rx_length_errors);
3445 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3446 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3447 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3448 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3449 : : i, ns->priority_xon_rx[i]);
3450 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3451 : : i, ns->priority_xoff_rx[i]);
3452 : : }
3453 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3454 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3455 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3456 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3457 : : i, ns->priority_xon_tx[i]);
3458 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3459 : : i, ns->priority_xoff_tx[i]);
3460 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3461 : : i, ns->priority_xon_2_xoff[i]);
3462 : : }
3463 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3464 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3465 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3466 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3467 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3468 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3469 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3470 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3471 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3472 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3473 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3474 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3475 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3476 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3477 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3478 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3479 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3480 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3481 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3482 : : ns->mac_short_packet_dropped);
3483 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3484 : : ns->checksum_error);
3485 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3486 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3487 : 0 : return 0;
3488 : : }
3489 : :
3490 : : /* Reset the statistics */
3491 : : static int
3492 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3493 : : {
3494 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3495 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3496 : :
3497 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3498 : 0 : pf->offset_loaded = false;
3499 [ # # ]: 0 : if (pf->main_vsi)
3500 : 0 : pf->main_vsi->offset_loaded = false;
3501 : :
3502 : : /* read the stats, reading current register values into offset */
3503 : 0 : i40e_read_stats_registers(pf, hw);
3504 : :
3505 : 0 : return 0;
3506 : : }
3507 : :
3508 : : static uint32_t
3509 : : i40e_xstats_calc_num(void)
3510 : : {
3511 : : return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3512 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3513 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3514 : : }
3515 : :
3516 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3517 : : struct rte_eth_xstat_name *xstats_names,
3518 : : __rte_unused unsigned limit)
3519 : : {
3520 : : unsigned count = 0;
3521 : : unsigned i, prio;
3522 : :
3523 [ # # ]: 0 : if (xstats_names == NULL)
3524 : : return i40e_xstats_calc_num();
3525 : :
3526 : : /* Note: limit checked in rte_eth_xstats_names() */
3527 : :
3528 : : /* Get stats from i40e_eth_stats struct */
3529 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3530 : 0 : strlcpy(xstats_names[count].name,
3531 : : rte_i40e_stats_strings[i].name,
3532 : : sizeof(xstats_names[count].name));
3533 : 0 : count++;
3534 : : }
3535 : :
3536 : : /* Get individual stats from i40e_hw_port struct */
3537 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3538 : 0 : strlcpy(xstats_names[count].name,
3539 : : rte_i40e_hw_port_strings[i].name,
3540 : : sizeof(xstats_names[count].name));
3541 : 0 : count++;
3542 : : }
3543 : :
3544 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3545 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3546 : 0 : snprintf(xstats_names[count].name,
3547 : : sizeof(xstats_names[count].name),
3548 : : "rx_priority%u_%s", prio,
3549 : 0 : rte_i40e_rxq_prio_strings[i].name);
3550 : 0 : count++;
3551 : : }
3552 : : }
3553 : :
3554 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3555 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3556 : 0 : snprintf(xstats_names[count].name,
3557 : : sizeof(xstats_names[count].name),
3558 : : "tx_priority%u_%s", prio,
3559 : 0 : rte_i40e_txq_prio_strings[i].name);
3560 : 0 : count++;
3561 : : }
3562 : : }
3563 : 0 : return count;
3564 : : }
3565 : :
3566 : : static int
3567 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3568 : : unsigned n)
3569 : : {
3570 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3571 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3572 : : unsigned i, count, prio;
3573 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3574 : :
3575 : : count = i40e_xstats_calc_num();
3576 [ # # ]: 0 : if (n < count)
3577 : : return count;
3578 : :
3579 : 0 : i40e_read_stats_registers(pf, hw);
3580 : :
3581 [ # # ]: 0 : if (xstats == NULL)
3582 : : return 0;
3583 : :
3584 : : count = 0;
3585 : :
3586 : : /* Get stats from i40e_eth_stats struct */
3587 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3588 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3589 : 0 : rte_i40e_stats_strings[i].offset);
3590 : 0 : xstats[count].id = count;
3591 : 0 : count++;
3592 : : }
3593 : :
3594 : : /* Get individual stats from i40e_hw_port struct */
3595 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3596 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3597 : 0 : rte_i40e_hw_port_strings[i].offset);
3598 : 0 : xstats[count].id = count;
3599 : 0 : count++;
3600 : : }
3601 : :
3602 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3603 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3604 : 0 : xstats[count].value =
3605 : 0 : *(uint64_t *)(((char *)hw_stats) +
3606 : 0 : rte_i40e_rxq_prio_strings[i].offset +
3607 : 0 : (sizeof(uint64_t) * prio));
3608 : 0 : xstats[count].id = count;
3609 : 0 : count++;
3610 : : }
3611 : : }
3612 : :
3613 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3614 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3615 : 0 : xstats[count].value =
3616 : 0 : *(uint64_t *)(((char *)hw_stats) +
3617 : 0 : rte_i40e_txq_prio_strings[i].offset +
3618 : 0 : (sizeof(uint64_t) * prio));
3619 : 0 : xstats[count].id = count;
3620 : 0 : count++;
3621 : : }
3622 : : }
3623 : :
3624 : 0 : return count;
3625 : : }
3626 : :
3627 : : static int
3628 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3629 : : {
3630 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3631 : : u32 full_ver;
3632 : : u8 ver, patch;
3633 : : u16 build;
3634 : : int ret;
3635 : :
3636 : 0 : full_ver = hw->nvm.oem_ver;
3637 : 0 : ver = (u8)(full_ver >> 24);
3638 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3639 : : patch = (u8)(full_ver & 0xff);
3640 : :
3641 : 0 : ret = snprintf(fw_version, fw_size,
3642 : : "%d.%d%d 0x%08x %d.%d.%d",
3643 : : ((hw->nvm.version >> 12) & 0xf),
3644 : : ((hw->nvm.version >> 4) & 0xff),
3645 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3646 : : ver, build, patch);
3647 [ # # ]: 0 : if (ret < 0)
3648 : : return -EINVAL;
3649 : :
3650 : 0 : ret += 1; /* add the size of '\0' */
3651 [ # # ]: 0 : if (fw_size < (size_t)ret)
3652 : : return ret;
3653 : : else
3654 : 0 : return 0;
3655 : : }
3656 : :
3657 : : /*
3658 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3659 : : * the Rx data path does not hang if the FW LLDP is stopped.
3660 : : * return true if lldp need to stop
3661 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3662 : : */
3663 : : static bool
3664 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3665 : : {
3666 : : double nvm_ver;
3667 : 0 : char ver_str[64] = {0};
3668 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3669 : :
3670 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3671 : : nvm_ver = atof(ver_str);
3672 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3673 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3674 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3675 : : return true;
3676 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3677 : 0 : return true;
3678 : :
3679 : : return false;
3680 : : }
3681 : :
3682 : : static int
3683 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3684 : : {
3685 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3686 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3687 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3688 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3689 : :
3690 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3691 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3692 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3693 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3694 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3695 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3696 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3697 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3698 : 0 : dev_info->rx_queue_offload_capa = 0;
3699 : 0 : dev_info->rx_offload_capa =
3700 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3701 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3702 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3703 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3704 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3705 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3706 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3707 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3708 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3709 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3710 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3711 : :
3712 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3713 : 0 : dev_info->tx_offload_capa =
3714 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3715 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3716 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3717 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3718 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3719 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3720 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3721 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3722 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3723 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3724 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3725 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3726 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3727 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
3728 : : dev_info->tx_queue_offload_capa;
3729 : 0 : dev_info->dev_capa =
3730 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3731 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3732 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3733 : :
3734 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3735 : : sizeof(uint32_t);
3736 : 0 : dev_info->reta_size = pf->hash_lut_size;
3737 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3738 : :
3739 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3740 : : .rx_thresh = {
3741 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3742 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3743 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3744 : : },
3745 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3746 : : .rx_drop_en = 0,
3747 : : .offloads = 0,
3748 : : };
3749 : :
3750 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3751 : : .tx_thresh = {
3752 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3753 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3754 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3755 : : },
3756 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3757 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3758 : : .offloads = 0,
3759 : : };
3760 : :
3761 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3762 : : .nb_max = I40E_MAX_RING_DESC,
3763 : : .nb_min = I40E_MIN_RING_DESC,
3764 : : .nb_align = I40E_ALIGN_RING_DESC,
3765 : : };
3766 : :
3767 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3768 : : .nb_max = I40E_MAX_RING_DESC,
3769 : : .nb_min = I40E_MIN_RING_DESC,
3770 : : .nb_align = I40E_ALIGN_RING_DESC,
3771 : : .nb_seg_max = I40E_TX_MAX_SEG,
3772 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3773 : : };
3774 : :
3775 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3776 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3777 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3778 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3779 : : pf->max_nb_vmdq_vsi;
3780 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3781 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3782 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3783 : : }
3784 : :
3785 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3786 : : /* For XL710 */
3787 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3788 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3789 : 0 : dev_info->default_txportconf.nb_queues = 2;
3790 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3791 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3792 : : else
3793 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3794 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3795 : 0 : dev_info->default_txportconf.ring_size = 1024;
3796 : : else
3797 : 0 : dev_info->default_txportconf.ring_size = 512;
3798 : :
3799 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3800 : : /* For XXV710 */
3801 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3802 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3803 : 0 : dev_info->default_txportconf.nb_queues = 1;
3804 : 0 : dev_info->default_rxportconf.ring_size = 256;
3805 : 0 : dev_info->default_txportconf.ring_size = 256;
3806 : : } else {
3807 : : /* For X710 */
3808 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3809 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3810 : 0 : dev_info->default_txportconf.nb_queues = 1;
3811 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3812 : 0 : dev_info->default_rxportconf.ring_size = 512;
3813 : 0 : dev_info->default_txportconf.ring_size = 256;
3814 : : } else {
3815 : 0 : dev_info->default_rxportconf.ring_size = 256;
3816 : 0 : dev_info->default_txportconf.ring_size = 256;
3817 : : }
3818 : : }
3819 : 0 : dev_info->default_rxportconf.burst_size = 32;
3820 : 0 : dev_info->default_txportconf.burst_size = 32;
3821 : :
3822 : 0 : return 0;
3823 : : }
3824 : :
3825 : : static int
3826 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3827 : : {
3828 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3829 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3830 : 0 : PMD_INIT_FUNC_TRACE();
3831 : :
3832 [ # # ]: 0 : if (on)
3833 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
3834 : : else
3835 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
3836 : : }
3837 : :
3838 : : static int
3839 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3840 : : enum rte_vlan_type vlan_type,
3841 : : uint16_t tpid, int qinq)
3842 : : {
3843 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3844 : 0 : uint64_t reg_r = 0;
3845 : : uint64_t reg_w = 0;
3846 : : uint16_t reg_id = 3;
3847 : : int ret;
3848 : :
3849 [ # # ]: 0 : if (qinq) {
3850 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3851 : : reg_id = 2;
3852 : : }
3853 : :
3854 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3855 : : ®_r, NULL);
3856 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
3857 : 0 : PMD_DRV_LOG(ERR,
3858 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3859 : : reg_id);
3860 : 0 : return -EIO;
3861 : : }
3862 : 0 : PMD_DRV_LOG(DEBUG,
3863 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3864 : : reg_id, reg_r);
3865 : :
3866 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3867 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3868 [ # # ]: 0 : if (reg_r == reg_w) {
3869 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
3870 : 0 : return 0;
3871 : : }
3872 : :
3873 : 0 : ret = i40e_aq_debug_write_global_register(hw,
3874 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
3875 : : reg_w, NULL);
3876 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
3877 : 0 : PMD_DRV_LOG(ERR,
3878 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3879 : : reg_id);
3880 : 0 : return -EIO;
3881 : : }
3882 : 0 : PMD_DRV_LOG(DEBUG,
3883 : : "Global register 0x%08x is changed with value 0x%08x",
3884 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3885 : :
3886 : 0 : return 0;
3887 : : }
3888 : :
3889 : : static int
3890 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3891 : : enum rte_vlan_type vlan_type,
3892 : : uint16_t tpid)
3893 : : {
3894 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3895 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3896 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
3897 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3898 : : u16 sw_flags = 0, valid_flags = 0;
3899 : : int ret = 0;
3900 : :
3901 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
3902 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
3903 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
3904 : 0 : PMD_DRV_LOG(ERR,
3905 : : "Unsupported vlan type.");
3906 : 0 : return -EINVAL;
3907 : : }
3908 : :
3909 [ # # ]: 0 : if (pf->support_multi_driver) {
3910 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3911 : 0 : return -ENOTSUP;
3912 : : }
3913 : :
3914 : : /* 802.1ad frames ability is added in NVM API 1.7*/
3915 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3916 [ # # ]: 0 : if (qinq) {
3917 [ # # ]: 0 : if (pf->fw8_3gt) {
3918 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
3919 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
3920 : : }
3921 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3922 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
3923 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
3924 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
3925 : : } else {
3926 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3927 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
3928 : : }
3929 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
3930 : : valid_flags, 0, NULL);
3931 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
3932 : 0 : PMD_DRV_LOG(ERR,
3933 : : "Set switch config failed aq_err: %d",
3934 : : hw->aq.asq_last_status);
3935 : : ret = -EIO;
3936 : : }
3937 : : } else
3938 : : /* If NVM API < 1.7, keep the register setting */
3939 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3940 : : tpid, qinq);
3941 : :
3942 : : return ret;
3943 : : }
3944 : :
3945 : : /* Configure outer vlan stripping on or off in QinQ mode */
3946 : : static int
3947 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
3948 : : {
3949 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3950 : : int ret = I40E_SUCCESS;
3951 : : uint32_t reg;
3952 : :
3953 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
3954 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
3955 : 0 : return -EINVAL;
3956 : : }
3957 : :
3958 : : /* Configure for outer VLAN RX stripping */
3959 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
3960 : :
3961 [ # # ]: 0 : if (on)
3962 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
3963 : : else
3964 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
3965 : :
3966 : 0 : ret = i40e_aq_debug_write_register(hw,
3967 : 0 : I40E_VSI_TSR(vsi->vsi_id),
3968 : : reg, NULL);
3969 [ # # ]: 0 : if (ret < 0) {
3970 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
3971 : : vsi->vsi_id);
3972 : 0 : return I40E_ERR_CONFIG;
3973 : : }
3974 : :
3975 : : return ret;
3976 : : }
3977 : :
3978 : : static int
3979 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3980 : : {
3981 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3982 : : struct i40e_mac_filter_info *mac_filter;
3983 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3984 : : struct rte_eth_rxmode *rxmode;
3985 : : struct i40e_mac_filter *f;
3986 : : int i, num;
3987 : : void *temp;
3988 : : int ret;
3989 : :
3990 : : rxmode = &dev->data->dev_conf.rxmode;
3991 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
3992 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
3993 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
3994 : : else
3995 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
3996 : : }
3997 : :
3998 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
3999 : : /* Enable or disable VLAN stripping */
4000 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4001 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4002 : : else
4003 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4004 : : }
4005 : :
4006 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4007 : : i = 0;
4008 : 0 : num = vsi->mac_num;
4009 : 0 : mac_filter = rte_zmalloc("mac_filter_info_data",
4010 : : num * sizeof(*mac_filter), 0);
4011 [ # # ]: 0 : if (mac_filter == NULL) {
4012 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
4013 : 0 : return I40E_ERR_NO_MEMORY;
4014 : : }
4015 : :
4016 : : /*
4017 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4018 : : * also change the default behavior to support this feature. To align with
4019 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4020 : : * outer VLAN processing. But it is forbidden for firmware to change the
4021 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4022 : : * switch table. Therefore, we need to clear the MAC table before setting
4023 : : * config, and then restore the MAC table after setting. This feature is
4024 : : * recommended to be used in firmware v8.6.
4025 : : */
4026 : : /* Remove all existing mac */
4027 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4028 : 0 : mac_filter[i] = f->mac_info;
4029 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4030 [ # # ]: 0 : if (ret)
4031 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4032 : 0 : i++;
4033 : : }
4034 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4035 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4036 : : /* Set global registers with default ethertype. */
4037 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4038 : : RTE_ETHER_TYPE_VLAN);
4039 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4040 : : RTE_ETHER_TYPE_VLAN);
4041 : : } else {
4042 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4043 : : }
4044 : : /* Restore all mac */
4045 [ # # ]: 0 : for (i = 0; i < num; i++) {
4046 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4047 [ # # ]: 0 : if (ret)
4048 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4049 : : }
4050 : 0 : rte_free(mac_filter);
4051 : : }
4052 : :
4053 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4054 : : /* Enable or disable outer VLAN stripping */
4055 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4056 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4057 : : else
4058 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4059 : : }
4060 : :
4061 : : return 0;
4062 : : }
4063 : :
4064 : : static void
4065 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4066 : : __rte_unused uint16_t queue,
4067 : : __rte_unused int on)
4068 : : {
4069 : 0 : PMD_INIT_FUNC_TRACE();
4070 : 0 : }
4071 : :
4072 : : static int
4073 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4074 : : {
4075 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4076 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4077 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4078 : : struct i40e_vsi_vlan_pvid_info info;
4079 : :
4080 : : memset(&info, 0, sizeof(info));
4081 : 0 : info.on = on;
4082 [ # # ]: 0 : if (info.on)
4083 : 0 : info.config.pvid = pvid;
4084 : : else {
4085 : 0 : info.config.reject.tagged =
4086 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4087 : 0 : info.config.reject.untagged =
4088 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4089 : : }
4090 : :
4091 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4092 : : }
4093 : :
4094 : : static int
4095 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4096 : : {
4097 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4098 : 0 : uint32_t mode = i40e_led_get(hw);
4099 : :
4100 [ # # ]: 0 : if (mode == 0)
4101 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4102 : :
4103 : 0 : return 0;
4104 : : }
4105 : :
4106 : : static int
4107 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4108 : : {
4109 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4110 : 0 : uint32_t mode = i40e_led_get(hw);
4111 : :
4112 [ # # ]: 0 : if (mode != 0)
4113 : 0 : i40e_led_set(hw, 0, false);
4114 : :
4115 : 0 : return 0;
4116 : : }
4117 : :
4118 : : static int
4119 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4120 : : {
4121 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4122 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4123 : :
4124 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4125 : :
4126 : : /* read out from register, in case they are modified by other port */
4127 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4128 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4129 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4130 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4131 : :
4132 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4133 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4134 : :
4135 : : /* Return current mode according to actual setting*/
4136 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4137 : 0 : case I40E_FC_FULL:
4138 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4139 : 0 : break;
4140 : 0 : case I40E_FC_TX_PAUSE:
4141 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4142 : 0 : break;
4143 : 0 : case I40E_FC_RX_PAUSE:
4144 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4145 : 0 : break;
4146 : 0 : case I40E_FC_NONE:
4147 : : default:
4148 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4149 : : };
4150 : :
4151 : 0 : return 0;
4152 : : }
4153 : :
4154 : : static int
4155 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4156 : : {
4157 : : uint32_t mflcn_reg, fctrl_reg, reg;
4158 : : uint32_t max_high_water;
4159 : : uint8_t i, aq_failure;
4160 : : int err;
4161 : : struct i40e_hw *hw;
4162 : : struct i40e_pf *pf;
4163 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4164 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4165 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4166 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4167 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4168 : : };
4169 : :
4170 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4171 : :
4172 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4173 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4174 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4175 : 0 : PMD_INIT_LOG(ERR,
4176 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4177 : : max_high_water);
4178 : 0 : return -EINVAL;
4179 : : }
4180 : :
4181 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4182 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4183 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4184 : :
4185 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4186 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4187 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4188 : :
4189 : 0 : PMD_INIT_FUNC_TRACE();
4190 : :
4191 : : /* All the link flow control related enable/disable register
4192 : : * configuration is handle by the F/W
4193 : : */
4194 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4195 [ # # ]: 0 : if (err < 0)
4196 : : return -ENOSYS;
4197 : :
4198 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4199 : : /* Configure flow control refresh threshold,
4200 : : * the value for stat_tx_pause_refresh_timer[8]
4201 : : * is used for global pause operation.
4202 : : */
4203 : :
4204 : 0 : I40E_WRITE_REG(hw,
4205 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4206 : : pf->fc_conf.pause_time);
4207 : :
4208 : : /* configure the timer value included in transmitted pause
4209 : : * frame,
4210 : : * the value for stat_tx_pause_quanta[8] is used for global
4211 : : * pause operation
4212 : : */
4213 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4214 : : pf->fc_conf.pause_time);
4215 : :
4216 : 0 : fctrl_reg = I40E_READ_REG(hw,
4217 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4218 : :
4219 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4220 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4221 : : else
4222 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4223 : :
4224 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4225 : : fctrl_reg);
4226 : : } else {
4227 : : /* Configure pause time (2 TCs per register) */
4228 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4229 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4230 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4231 : :
4232 : : /* Configure flow control refresh threshold value */
4233 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4234 : : pf->fc_conf.pause_time / 2);
4235 : :
4236 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4237 : :
4238 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4239 : : *depending on configuration
4240 : : */
4241 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4242 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4243 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4244 : : } else {
4245 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4246 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4247 : : }
4248 : :
4249 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4250 : : }
4251 : :
4252 [ # # ]: 0 : if (!pf->support_multi_driver) {
4253 : : /* config water marker both based on the packets and bytes */
4254 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4255 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4256 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4257 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4258 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4259 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4260 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4261 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4262 : : << I40E_KILOSHIFT);
4263 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4264 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4265 : : << I40E_KILOSHIFT);
4266 : : } else {
4267 : 0 : PMD_DRV_LOG(ERR,
4268 : : "Water marker configuration is not supported.");
4269 : : }
4270 : :
4271 : 0 : I40E_WRITE_FLUSH(hw);
4272 : :
4273 : 0 : return 0;
4274 : : }
4275 : :
4276 : : static int
4277 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4278 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4279 : : {
4280 : 0 : PMD_INIT_FUNC_TRACE();
4281 : :
4282 : 0 : return -ENOSYS;
4283 : : }
4284 : :
4285 : : /* Add a MAC address, and update filters */
4286 : : static int
4287 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4288 : : struct rte_ether_addr *mac_addr,
4289 : : __rte_unused uint32_t index,
4290 : : uint32_t pool)
4291 : : {
4292 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4293 : : struct i40e_mac_filter_info mac_filter;
4294 : : struct i40e_vsi *vsi;
4295 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4296 : : int ret;
4297 : :
4298 : : /* If VMDQ not enabled or configured, return */
4299 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4300 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4301 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4302 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4303 : : pool);
4304 : 0 : return -ENOTSUP;
4305 : : }
4306 : :
4307 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4308 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4309 : : pool, pf->nb_cfg_vmdq_vsi);
4310 : 0 : return -EINVAL;
4311 : : }
4312 : :
4313 : : rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4314 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4315 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4316 : : else
4317 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4318 : :
4319 [ # # ]: 0 : if (pool == 0)
4320 : 0 : vsi = pf->main_vsi;
4321 : : else
4322 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4323 : :
4324 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4325 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4326 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4327 : 0 : return -ENODEV;
4328 : : }
4329 : : return 0;
4330 : : }
4331 : :
4332 : : /* Remove a MAC address, and update filters */
4333 : : static void
4334 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4335 : : {
4336 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4337 : : struct i40e_vsi *vsi;
4338 : : struct rte_eth_dev_data *data = dev->data;
4339 : : struct rte_ether_addr *macaddr;
4340 : : int ret;
4341 : : uint32_t i;
4342 : : uint64_t pool_sel;
4343 : :
4344 : 0 : macaddr = &(data->mac_addrs[index]);
4345 : :
4346 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4347 : :
4348 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4349 [ # # ]: 0 : if (pool_sel & (1ULL << i)) {
4350 [ # # ]: 0 : if (i == 0)
4351 : 0 : vsi = pf->main_vsi;
4352 : : else {
4353 : : /* No VMDQ pool enabled or configured */
4354 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ) ||
4355 [ # # ]: 0 : (i > pf->nb_cfg_vmdq_vsi)) {
4356 : 0 : PMD_DRV_LOG(ERR,
4357 : : "No VMDQ pool enabled/configured");
4358 : 0 : return;
4359 : : }
4360 : 0 : vsi = pf->vmdq[i - 1].vsi;
4361 : : }
4362 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4363 : :
4364 [ # # ]: 0 : if (ret) {
4365 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4366 : 0 : return;
4367 : : }
4368 : : }
4369 : : }
4370 : : }
4371 : :
4372 : : static int
4373 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4374 : : {
4375 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4376 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4377 : : uint32_t reg;
4378 : : int ret;
4379 : :
4380 [ # # ]: 0 : if (!lut)
4381 : : return -EINVAL;
4382 : :
4383 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4384 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4385 : 0 : vsi->type != I40E_VSI_SRIOV,
4386 : : lut, lut_size);
4387 [ # # ]: 0 : if (ret) {
4388 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4389 : 0 : return ret;
4390 : : }
4391 : : } else {
4392 : : uint32_t *lut_dw = (uint32_t *)lut;
4393 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4394 : :
4395 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4396 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4397 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4398 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4399 : : }
4400 : : } else {
4401 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4402 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4403 : : I40E_PFQF_HLUT(i));
4404 : : }
4405 : : }
4406 : :
4407 : : return 0;
4408 : : }
4409 : :
4410 : : int
4411 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4412 : : {
4413 : : struct i40e_pf *pf;
4414 : : struct i40e_hw *hw;
4415 : :
4416 [ # # ]: 0 : if (!vsi || !lut)
4417 : : return -EINVAL;
4418 : :
4419 : 0 : pf = I40E_VSI_TO_PF(vsi);
4420 : 0 : hw = I40E_VSI_TO_HW(vsi);
4421 : :
4422 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4423 : : enum i40e_status_code status;
4424 : :
4425 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4426 : 0 : vsi->type != I40E_VSI_SRIOV,
4427 : : lut, lut_size);
4428 [ # # ]: 0 : if (status) {
4429 : 0 : PMD_DRV_LOG(ERR,
4430 : : "Failed to update RSS lookup table, error status: %d",
4431 : : status);
4432 : 0 : return -EIO;
4433 : : }
4434 : : } else {
4435 : : uint32_t *lut_dw = (uint32_t *)lut;
4436 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4437 : :
4438 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4439 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4440 : 0 : I40E_WRITE_REG(
4441 : : hw,
4442 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4443 : : lut_dw[i]);
4444 : : } else {
4445 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4446 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4447 : : lut_dw[i]);
4448 : : }
4449 : 0 : I40E_WRITE_FLUSH(hw);
4450 : : }
4451 : :
4452 : : return 0;
4453 : : }
4454 : :
4455 : : static int
4456 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4457 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4458 : : uint16_t reta_size)
4459 : : {
4460 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4461 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4462 : : uint16_t idx, shift;
4463 : : uint8_t *lut;
4464 : : int ret;
4465 : :
4466 : 0 : if (reta_size != lut_size ||
4467 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4468 : 0 : PMD_DRV_LOG(ERR,
4469 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4470 : : reta_size, lut_size);
4471 : 0 : return -EINVAL;
4472 : : }
4473 : :
4474 : 0 : lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4475 [ # # ]: 0 : if (!lut) {
4476 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
4477 : 0 : return -ENOMEM;
4478 : : }
4479 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4480 [ # # ]: 0 : if (ret)
4481 : 0 : goto out;
4482 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4483 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4484 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4485 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
4486 : 0 : lut[i] = reta_conf[idx].reta[shift];
4487 : : }
4488 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4489 : :
4490 : 0 : pf->adapter->rss_reta_updated = 1;
4491 : :
4492 : 0 : out:
4493 : 0 : rte_free(lut);
4494 : :
4495 : 0 : return ret;
4496 : : }
4497 : :
4498 : : static int
4499 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4500 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4501 : : uint16_t reta_size)
4502 : : {
4503 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4504 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4505 : : uint16_t idx, shift;
4506 : : uint8_t *lut;
4507 : : int ret;
4508 : :
4509 : 0 : if (reta_size != lut_size ||
4510 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4511 : 0 : PMD_DRV_LOG(ERR,
4512 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4513 : : reta_size, lut_size);
4514 : 0 : return -EINVAL;
4515 : : }
4516 : :
4517 : 0 : lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4518 [ # # ]: 0 : if (!lut) {
4519 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
4520 : 0 : return -ENOMEM;
4521 : : }
4522 : :
4523 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4524 [ # # ]: 0 : if (ret)
4525 : 0 : goto out;
4526 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4527 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4528 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4529 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
4530 : 0 : reta_conf[idx].reta[shift] = lut[i];
4531 : : }
4532 : :
4533 : 0 : out:
4534 : 0 : rte_free(lut);
4535 : :
4536 : 0 : return ret;
4537 : : }
4538 : :
4539 : : /**
4540 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4541 : : * @hw: pointer to the HW structure
4542 : : * @mem: pointer to mem struct to fill out
4543 : : * @size: size of memory requested
4544 : : * @alignment: what to align the allocation to
4545 : : **/
4546 : : enum i40e_status_code
4547 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4548 : : struct i40e_dma_mem *mem,
4549 : : u64 size,
4550 : : u32 alignment)
4551 : : {
4552 : : static uint64_t i40e_dma_memzone_id;
4553 : : const struct rte_memzone *mz = NULL;
4554 : : char z_name[RTE_MEMZONE_NAMESIZE];
4555 : :
4556 [ # # ]: 0 : if (!mem)
4557 : : return I40E_ERR_PARAM;
4558 : :
4559 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4560 : : __atomic_fetch_add(&i40e_dma_memzone_id, 1, __ATOMIC_RELAXED));
4561 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4562 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4563 [ # # ]: 0 : if (!mz)
4564 : : return I40E_ERR_NO_MEMORY;
4565 : :
4566 : 0 : mem->size = size;
4567 : 0 : mem->va = mz->addr;
4568 : 0 : mem->pa = mz->iova;
4569 : 0 : mem->zone = (const void *)mz;
4570 : 0 : PMD_DRV_LOG(DEBUG,
4571 : : "memzone %s allocated with physical address: %"PRIu64,
4572 : : mz->name, mem->pa);
4573 : :
4574 : 0 : return I40E_SUCCESS;
4575 : : }
4576 : :
4577 : : /**
4578 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4579 : : * @hw: pointer to the HW structure
4580 : : * @mem: ptr to mem struct to free
4581 : : **/
4582 : : enum i40e_status_code
4583 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4584 : : struct i40e_dma_mem *mem)
4585 : : {
4586 [ # # ]: 0 : if (!mem)
4587 : : return I40E_ERR_PARAM;
4588 : :
4589 : 0 : PMD_DRV_LOG(DEBUG,
4590 : : "memzone %s to be freed with physical address: %"PRIu64,
4591 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4592 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4593 : 0 : mem->zone = NULL;
4594 : 0 : mem->va = NULL;
4595 : 0 : mem->pa = (u64)0;
4596 : :
4597 : 0 : return I40E_SUCCESS;
4598 : : }
4599 : :
4600 : : /**
4601 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4602 : : * @hw: pointer to the HW structure
4603 : : * @mem: pointer to mem struct to fill out
4604 : : * @size: size of memory requested
4605 : : **/
4606 : : enum i40e_status_code
4607 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4608 : : struct i40e_virt_mem *mem,
4609 : : u32 size)
4610 : : {
4611 [ # # ]: 0 : if (!mem)
4612 : : return I40E_ERR_PARAM;
4613 : :
4614 : 0 : mem->size = size;
4615 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4616 : :
4617 [ # # ]: 0 : if (mem->va)
4618 : : return I40E_SUCCESS;
4619 : : else
4620 : 0 : return I40E_ERR_NO_MEMORY;
4621 : : }
4622 : :
4623 : : /**
4624 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4625 : : * @hw: pointer to the HW structure
4626 : : * @mem: pointer to mem struct to free
4627 : : **/
4628 : : enum i40e_status_code
4629 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4630 : : struct i40e_virt_mem *mem)
4631 : : {
4632 [ # # ]: 0 : if (!mem)
4633 : : return I40E_ERR_PARAM;
4634 : :
4635 : 0 : rte_free(mem->va);
4636 : 0 : mem->va = NULL;
4637 : :
4638 : 0 : return I40E_SUCCESS;
4639 : : }
4640 : :
4641 : : /**
4642 : : * Get the hardware capabilities, which will be parsed
4643 : : * and saved into struct i40e_hw.
4644 : : */
4645 : : static int
4646 : 0 : i40e_get_cap(struct i40e_hw *hw)
4647 : : {
4648 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4649 : 0 : uint16_t len, size = 0;
4650 : : int ret;
4651 : :
4652 : : /* Calculate a huge enough buff for saving response data temporarily */
4653 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4654 : : I40E_MAX_CAP_ELE_NUM;
4655 : 0 : buf = rte_zmalloc("i40e", len, 0);
4656 [ # # ]: 0 : if (!buf) {
4657 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4658 : 0 : return I40E_ERR_NO_MEMORY;
4659 : : }
4660 : :
4661 : : /* Get, parse the capabilities and save it to hw */
4662 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4663 : : i40e_aqc_opc_list_func_capabilities, NULL);
4664 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4665 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4666 : :
4667 : : /* Free the temporary buffer after being used */
4668 : 0 : rte_free(buf);
4669 : :
4670 : 0 : return ret;
4671 : : }
4672 : :
4673 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4674 : :
4675 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4676 : : const char *value,
4677 : : void *opaque)
4678 : : {
4679 : : struct i40e_pf *pf;
4680 : : unsigned long num;
4681 : : char *end;
4682 : :
4683 : : pf = (struct i40e_pf *)opaque;
4684 : : RTE_SET_USED(key);
4685 : :
4686 : 0 : errno = 0;
4687 : 0 : num = strtoul(value, &end, 0);
4688 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4689 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4690 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4691 : 0 : return -(EINVAL);
4692 : : }
4693 : :
4694 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4695 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4696 : : else
4697 : : /* here return 0 to make next valid same argument work */
4698 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4699 : : "power of 2 and equal or less than 16 !, Now it is "
4700 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4701 : :
4702 : : return 0;
4703 : : }
4704 : :
4705 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4706 : : {
4707 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4708 : : struct rte_kvargs *kvlist;
4709 : : int kvargs_count;
4710 : :
4711 : : /* set default queue number per VF as 4 */
4712 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4713 : :
4714 [ # # ]: 0 : if (dev->device->devargs == NULL)
4715 : : return 0;
4716 : :
4717 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4718 [ # # ]: 0 : if (kvlist == NULL)
4719 : : return -(EINVAL);
4720 : :
4721 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4722 [ # # ]: 0 : if (!kvargs_count) {
4723 : 0 : rte_kvargs_free(kvlist);
4724 : 0 : return 0;
4725 : : }
4726 : :
4727 [ # # ]: 0 : if (kvargs_count > 1)
4728 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4729 : : "the first invalid or last valid one is used !",
4730 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4731 : :
4732 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4733 : : i40e_pf_parse_vf_queue_number_handler, pf);
4734 : :
4735 : 0 : rte_kvargs_free(kvlist);
4736 : :
4737 : 0 : return 0;
4738 : : }
4739 : :
4740 : : static int
4741 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4742 : : {
4743 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4744 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4745 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4746 : : uint16_t qp_count = 0, vsi_count = 0;
4747 : :
4748 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4749 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4750 : 0 : return -EINVAL;
4751 : : }
4752 : :
4753 : 0 : i40e_pf_config_vf_rxq_number(dev);
4754 : :
4755 : : /* Add the parameter init for LFC */
4756 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4757 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4758 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4759 : :
4760 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4761 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4762 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4763 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4764 : :
4765 : : /* FDir queue/VSI allocation */
4766 : 0 : pf->fdir_qp_offset = 0;
4767 [ # # ]: 0 : if (hw->func_caps.fd) {
4768 : 0 : pf->flags |= I40E_FLAG_FDIR;
4769 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4770 : : } else {
4771 : 0 : pf->fdir_nb_qps = 0;
4772 : : }
4773 : 0 : qp_count += pf->fdir_nb_qps;
4774 : : vsi_count += 1;
4775 : :
4776 : : /* LAN queue/VSI allocation */
4777 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4778 [ # # ]: 0 : if (!hw->func_caps.rss) {
4779 : 0 : pf->lan_nb_qps = 1;
4780 : : } else {
4781 : 0 : pf->flags |= I40E_FLAG_RSS;
4782 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4783 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4784 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4785 : : }
4786 : 0 : qp_count += pf->lan_nb_qps;
4787 : : vsi_count += 1;
4788 : :
4789 : : /* VF queue/VSI allocation */
4790 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4791 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4792 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4793 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4794 : 0 : pf->vf_num = pci_dev->max_vfs;
4795 : 0 : PMD_DRV_LOG(DEBUG,
4796 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4797 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4798 : : } else {
4799 : 0 : pf->vf_nb_qps = 0;
4800 : 0 : pf->vf_num = 0;
4801 : : }
4802 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4803 : 0 : vsi_count += pf->vf_num;
4804 : :
4805 : : /* VMDq queue/VSI allocation */
4806 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4807 : 0 : pf->vmdq_nb_qps = 0;
4808 : 0 : pf->max_nb_vmdq_vsi = 0;
4809 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4810 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4811 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4812 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4813 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4814 : :
4815 : : /* Limit the maximum number of VMDq vsi to the maximum
4816 : : * ethdev can support
4817 : : */
4818 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4819 : : hw->func_caps.num_vsis - vsi_count);
4820 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4821 : : RTE_ETH_64_POOLS);
4822 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4823 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4824 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4825 : 0 : PMD_DRV_LOG(DEBUG,
4826 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4827 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4828 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4829 : : } else {
4830 : 0 : PMD_DRV_LOG(INFO,
4831 : : "No enough queues left for VMDq");
4832 : : }
4833 : : } else {
4834 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4835 : : }
4836 : : }
4837 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4838 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
4839 : :
4840 [ # # ]: 0 : if (hw->func_caps.dcb)
4841 : 0 : pf->flags |= I40E_FLAG_DCB;
4842 : :
4843 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
4844 : 0 : PMD_DRV_LOG(ERR,
4845 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4846 : : qp_count, hw->func_caps.num_tx_qp);
4847 : 0 : return -EINVAL;
4848 : : }
4849 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
4850 : 0 : PMD_DRV_LOG(ERR,
4851 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4852 : : vsi_count, hw->func_caps.num_vsis);
4853 : 0 : return -EINVAL;
4854 : : }
4855 : :
4856 : : /**
4857 : : * Enable outer VLAN processing if firmware version is greater
4858 : : * than v8.3
4859 : : */
4860 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
4861 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
4862 : 0 : pf->fw8_3gt = true;
4863 : : } else {
4864 : 0 : pf->fw8_3gt = false;
4865 : : }
4866 : :
4867 : : return 0;
4868 : : }
4869 : :
4870 : : static int
4871 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
4872 : : {
4873 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4874 : : struct i40e_aqc_get_switch_config_resp *switch_config;
4875 : : struct i40e_aqc_switch_config_element_resp *element;
4876 : 0 : uint16_t start_seid = 0, num_reported;
4877 : : int ret;
4878 : :
4879 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4880 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4881 [ # # ]: 0 : if (!switch_config) {
4882 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
4883 : 0 : return -ENOMEM;
4884 : : }
4885 : :
4886 : : /* Get the switch configurations */
4887 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
4888 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
4889 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4890 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4891 : 0 : goto fail;
4892 : : }
4893 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4894 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
4895 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4896 : 0 : goto fail;
4897 : : }
4898 : :
4899 : : /* Parse the switch configuration elements */
4900 : : element = &(switch_config->element[0]);
4901 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4902 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4903 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4904 : : } else
4905 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
4906 : :
4907 : 0 : fail:
4908 : 0 : rte_free(switch_config);
4909 : :
4910 : 0 : return ret;
4911 : : }
4912 : :
4913 : : static int
4914 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4915 : : uint32_t num)
4916 : : {
4917 : : struct pool_entry *entry;
4918 : :
4919 [ # # ]: 0 : if (pool == NULL || num == 0)
4920 : : return -EINVAL;
4921 : :
4922 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4923 [ # # ]: 0 : if (entry == NULL) {
4924 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4925 : 0 : return -ENOMEM;
4926 : : }
4927 : :
4928 : : /* queue heap initialize */
4929 : 0 : pool->num_free = num;
4930 : 0 : pool->num_alloc = 0;
4931 : 0 : pool->base = base;
4932 : 0 : LIST_INIT(&pool->alloc_list);
4933 : : LIST_INIT(&pool->free_list);
4934 : :
4935 : : /* Initialize element */
4936 : 0 : entry->base = 0;
4937 : 0 : entry->len = num;
4938 : :
4939 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
4940 : 0 : return 0;
4941 : : }
4942 : :
4943 : : static void
4944 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
4945 : : {
4946 : : struct pool_entry *entry, *next_entry;
4947 : :
4948 [ # # ]: 0 : if (pool == NULL)
4949 : : return;
4950 : :
4951 : 0 : for (entry = LIST_FIRST(&pool->alloc_list);
4952 [ # # ]: 0 : entry && (next_entry = LIST_NEXT(entry, next), 1);
4953 : : entry = next_entry) {
4954 [ # # ]: 0 : LIST_REMOVE(entry, next);
4955 : 0 : rte_free(entry);
4956 : : }
4957 : :
4958 : 0 : for (entry = LIST_FIRST(&pool->free_list);
4959 [ # # ]: 0 : entry && (next_entry = LIST_NEXT(entry, next), 1);
4960 : : entry = next_entry) {
4961 [ # # ]: 0 : LIST_REMOVE(entry, next);
4962 : 0 : rte_free(entry);
4963 : : }
4964 : :
4965 : 0 : pool->num_free = 0;
4966 : 0 : pool->num_alloc = 0;
4967 : 0 : pool->base = 0;
4968 : 0 : LIST_INIT(&pool->alloc_list);
4969 : 0 : LIST_INIT(&pool->free_list);
4970 : : }
4971 : :
4972 : : static int
4973 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
4974 : : uint32_t base)
4975 : : {
4976 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
4977 : : uint32_t pool_offset;
4978 : : uint16_t len;
4979 : : int insert;
4980 : :
4981 [ # # ]: 0 : if (pool == NULL) {
4982 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
4983 : 0 : return -EINVAL;
4984 : : }
4985 : :
4986 : 0 : pool_offset = base - pool->base;
4987 : : /* Lookup in alloc list */
4988 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
4989 [ # # ]: 0 : if (entry->base == pool_offset) {
4990 : : valid_entry = entry;
4991 [ # # ]: 0 : LIST_REMOVE(entry, next);
4992 : 0 : break;
4993 : : }
4994 : : }
4995 : :
4996 : : /* Not find, return */
4997 [ # # ]: 0 : if (valid_entry == NULL) {
4998 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
4999 : 0 : return -EINVAL;
5000 : : }
5001 : :
5002 : : /**
5003 : : * Found it, move it to free list and try to merge.
5004 : : * In order to make merge easier, always sort it by qbase.
5005 : : * Find adjacent prev and last entries.
5006 : : */
5007 : : prev = next = NULL;
5008 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5009 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5010 : : next = entry;
5011 : : break;
5012 : : }
5013 : : prev = entry;
5014 : : }
5015 : :
5016 : : insert = 0;
5017 : 0 : len = valid_entry->len;
5018 : : /* Try to merge with next one*/
5019 [ # # ]: 0 : if (next != NULL) {
5020 : : /* Merge with next one */
5021 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5022 : 0 : next->base = valid_entry->base;
5023 : 0 : next->len += len;
5024 : 0 : rte_free(valid_entry);
5025 : : valid_entry = next;
5026 : : insert = 1;
5027 : : }
5028 : : }
5029 : :
5030 [ # # ]: 0 : if (prev != NULL) {
5031 : : /* Merge with previous one */
5032 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5033 : 0 : prev->len += len;
5034 : : /* If it merge with next one, remove next node */
5035 [ # # ]: 0 : if (insert == 1) {
5036 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5037 : 0 : rte_free(valid_entry);
5038 : : valid_entry = NULL;
5039 : : } else {
5040 : 0 : rte_free(valid_entry);
5041 : : valid_entry = NULL;
5042 : : insert = 1;
5043 : : }
5044 : : }
5045 : : }
5046 : :
5047 : : /* Not find any entry to merge, insert */
5048 [ # # ]: 0 : if (insert == 0) {
5049 [ # # ]: 0 : if (prev != NULL)
5050 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5051 [ # # ]: 0 : else if (next != NULL)
5052 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5053 : : else /* It's empty list, insert to head */
5054 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5055 : : }
5056 : :
5057 : 0 : pool->num_free += len;
5058 : 0 : pool->num_alloc -= len;
5059 : :
5060 : 0 : return 0;
5061 : : }
5062 : :
5063 : : static int
5064 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5065 : : uint16_t num)
5066 : : {
5067 : : struct pool_entry *entry, *valid_entry;
5068 : :
5069 [ # # ]: 0 : if (pool == NULL || num == 0) {
5070 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5071 : 0 : return -EINVAL;
5072 : : }
5073 : :
5074 [ # # ]: 0 : if (pool->num_free < num) {
5075 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5076 : : num, pool->num_free);
5077 : 0 : return -ENOMEM;
5078 : : }
5079 : :
5080 : : valid_entry = NULL;
5081 : : /* Lookup in free list and find most fit one */
5082 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5083 [ # # ]: 0 : if (entry->len >= num) {
5084 : : /* Find best one */
5085 [ # # ]: 0 : if (entry->len == num) {
5086 : : valid_entry = entry;
5087 : : break;
5088 : : }
5089 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5090 : : valid_entry = entry;
5091 : : }
5092 : : }
5093 : :
5094 : : /* Not find one to satisfy the request, return */
5095 [ # # ]: 0 : if (valid_entry == NULL) {
5096 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5097 : 0 : return -ENOMEM;
5098 : : }
5099 : : /**
5100 : : * The entry have equal queue number as requested,
5101 : : * remove it from alloc_list.
5102 : : */
5103 [ # # ]: 0 : if (valid_entry->len == num) {
5104 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5105 : : } else {
5106 : : /**
5107 : : * The entry have more numbers than requested,
5108 : : * create a new entry for alloc_list and minus its
5109 : : * queue base and number in free_list.
5110 : : */
5111 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5112 [ # # ]: 0 : if (entry == NULL) {
5113 : 0 : PMD_DRV_LOG(ERR,
5114 : : "Failed to allocate memory for resource pool");
5115 : 0 : return -ENOMEM;
5116 : : }
5117 : 0 : entry->base = valid_entry->base;
5118 : 0 : entry->len = num;
5119 : 0 : valid_entry->base += num;
5120 : 0 : valid_entry->len -= num;
5121 : : valid_entry = entry;
5122 : : }
5123 : :
5124 : : /* Insert it into alloc list, not sorted */
5125 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5126 : :
5127 : 0 : pool->num_free -= valid_entry->len;
5128 : 0 : pool->num_alloc += valid_entry->len;
5129 : :
5130 : 0 : return valid_entry->base + pool->base;
5131 : : }
5132 : :
5133 : : /**
5134 : : * bitmap_is_subset - Check whether src2 is subset of src1
5135 : : **/
5136 : : static inline int
5137 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5138 : : {
5139 : 0 : return !((src1 ^ src2) & src2);
5140 : : }
5141 : :
5142 : : static enum i40e_status_code
5143 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5144 : : {
5145 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5146 : :
5147 : : /* If DCB is not supported, only default TC is supported */
5148 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5149 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5150 : 0 : return I40E_NOT_SUPPORTED;
5151 : : }
5152 : :
5153 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5154 : 0 : PMD_DRV_LOG(ERR,
5155 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5156 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5157 : 0 : return I40E_NOT_SUPPORTED;
5158 : : }
5159 : : return I40E_SUCCESS;
5160 : : }
5161 : :
5162 : : int
5163 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5164 : : struct i40e_vsi_vlan_pvid_info *info)
5165 : : {
5166 : : struct i40e_hw *hw;
5167 : : struct i40e_vsi_context ctxt;
5168 : : uint8_t vlan_flags = 0;
5169 : : int ret;
5170 : :
5171 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5172 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5173 : 0 : return I40E_ERR_PARAM;
5174 : : }
5175 : :
5176 [ # # ]: 0 : if (info->on) {
5177 : 0 : vsi->info.pvid = info->config.pvid;
5178 : : /**
5179 : : * If insert pvid is enabled, only tagged pkts are
5180 : : * allowed to be sent out.
5181 : : */
5182 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5183 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5184 : : } else {
5185 : 0 : vsi->info.pvid = 0;
5186 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5187 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5188 : :
5189 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5190 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5191 : : }
5192 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5193 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5194 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5195 [ # # ]: 0 : vsi->info.valid_sections =
5196 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5197 : : memset(&ctxt, 0, sizeof(ctxt));
5198 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5199 : 0 : ctxt.seid = vsi->seid;
5200 : :
5201 : 0 : hw = I40E_VSI_TO_HW(vsi);
5202 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5203 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5204 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5205 : :
5206 : : return ret;
5207 : : }
5208 : :
5209 : : static int
5210 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5211 : : {
5212 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5213 : : int i, ret;
5214 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5215 : :
5216 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5217 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5218 : : return ret;
5219 : :
5220 [ # # ]: 0 : if (!vsi->seid) {
5221 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5222 : 0 : return -EINVAL;
5223 : : }
5224 : :
5225 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5226 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5227 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5228 : 0 : tc_bw_data.tc_bw_credits[i] =
5229 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5230 : :
5231 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5232 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5233 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5234 : 0 : return ret;
5235 : : }
5236 : :
5237 [ # # ]: 0 : rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5238 : : sizeof(vsi->info.qs_handle));
5239 : : return I40E_SUCCESS;
5240 : : }
5241 : :
5242 : : static enum i40e_status_code
5243 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5244 : : struct i40e_aqc_vsi_properties_data *info,
5245 : : uint8_t enabled_tcmap)
5246 : : {
5247 : : enum i40e_status_code ret;
5248 : : int i, total_tc = 0;
5249 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5250 : :
5251 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5252 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5253 : : return ret;
5254 : :
5255 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5256 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5257 : 0 : total_tc++;
5258 [ # # ]: 0 : if (total_tc == 0)
5259 : : total_tc = 1;
5260 : 0 : vsi->enabled_tc = enabled_tcmap;
5261 : :
5262 : : /* Number of queues per enabled TC */
5263 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5264 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5265 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5266 : :
5267 : : /* Adjust the queue number to actual queues that can be applied */
5268 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5269 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5270 : :
5271 : : /**
5272 : : * Configure TC and queue mapping parameters, for enabled TC,
5273 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5274 : : * default queue will serve it.
5275 : : */
5276 : : qp_idx = 0;
5277 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5278 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5279 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5280 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5281 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5282 : 0 : qp_idx += qpnum_per_tc;
5283 : : } else
5284 : 0 : info->tc_mapping[i] = 0;
5285 : : }
5286 : :
5287 : : /* Associate queue number with VSI */
5288 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5289 : 0 : info->mapping_flags |=
5290 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5291 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5292 : 0 : info->queue_mapping[i] =
5293 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5294 : : } else {
5295 : 0 : info->mapping_flags |=
5296 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5297 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5298 : : }
5299 : 0 : info->valid_sections |=
5300 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5301 : :
5302 : 0 : return I40E_SUCCESS;
5303 : : }
5304 : :
5305 : : static int
5306 : 0 : i40e_veb_release(struct i40e_veb *veb)
5307 : : {
5308 : : struct i40e_vsi *vsi;
5309 : : struct i40e_hw *hw;
5310 : :
5311 [ # # ]: 0 : if (veb == NULL)
5312 : : return -EINVAL;
5313 : :
5314 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5315 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5316 : 0 : return -EACCES;
5317 : : }
5318 : : /* associate_vsi field is NULL for floating VEB */
5319 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5320 : : vsi = veb->associate_vsi;
5321 : 0 : hw = I40E_VSI_TO_HW(vsi);
5322 : :
5323 : 0 : vsi->uplink_seid = veb->uplink_seid;
5324 : 0 : vsi->veb = NULL;
5325 : : } else {
5326 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5327 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5328 : : }
5329 : :
5330 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5331 : 0 : rte_free(veb);
5332 : 0 : return I40E_SUCCESS;
5333 : : }
5334 : :
5335 : : /* Setup a veb */
5336 : : static struct i40e_veb *
5337 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5338 : : {
5339 : : struct i40e_veb *veb;
5340 : : int ret;
5341 : : struct i40e_hw *hw;
5342 : :
5343 [ # # ]: 0 : if (pf == NULL) {
5344 : 0 : PMD_DRV_LOG(ERR,
5345 : : "veb setup failed, associated PF shouldn't null");
5346 : 0 : return NULL;
5347 : : }
5348 : 0 : hw = I40E_PF_TO_HW(pf);
5349 : :
5350 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5351 [ # # ]: 0 : if (!veb) {
5352 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5353 : 0 : goto fail;
5354 : : }
5355 : :
5356 : 0 : veb->associate_vsi = vsi;
5357 : 0 : veb->associate_pf = pf;
5358 : 0 : TAILQ_INIT(&veb->head);
5359 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5360 : :
5361 : : /* create floating veb if vsi is NULL */
5362 [ # # ]: 0 : if (vsi != NULL) {
5363 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5364 : : I40E_DEFAULT_TCMAP, false,
5365 : 0 : &veb->seid, false, NULL);
5366 : : } else {
5367 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5368 : 0 : true, &veb->seid, false, NULL);
5369 : : }
5370 : :
5371 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5372 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5373 : : hw->aq.asq_last_status);
5374 : 0 : goto fail;
5375 : : }
5376 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5377 : :
5378 : : /* get statistics index */
5379 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5380 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5381 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5382 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5383 : : hw->aq.asq_last_status);
5384 : 0 : goto fail;
5385 : : }
5386 : : /* Get VEB bandwidth, to be implemented */
5387 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5388 [ # # ]: 0 : if (vsi)
5389 : 0 : vsi->uplink_seid = veb->seid;
5390 : :
5391 : : return veb;
5392 : 0 : fail:
5393 : 0 : rte_free(veb);
5394 : 0 : return NULL;
5395 : : }
5396 : :
5397 : : int
5398 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5399 : : {
5400 : : struct i40e_pf *pf;
5401 : : struct i40e_hw *hw;
5402 : : struct i40e_vsi_list *vsi_list;
5403 : : void *temp;
5404 : : int ret;
5405 : : struct i40e_mac_filter *f;
5406 : : uint16_t user_param;
5407 : :
5408 [ # # ]: 0 : if (!vsi)
5409 : : return I40E_SUCCESS;
5410 : :
5411 [ # # ]: 0 : if (!vsi->adapter)
5412 : : return -EFAULT;
5413 : :
5414 : 0 : user_param = vsi->user_param;
5415 : :
5416 : : pf = I40E_VSI_TO_PF(vsi);
5417 : 0 : hw = I40E_VSI_TO_HW(vsi);
5418 : :
5419 : : /* VSI has child to attach, release child first */
5420 [ # # ]: 0 : if (vsi->veb) {
5421 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5422 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5423 : : return -1;
5424 : : }
5425 : 0 : i40e_veb_release(vsi->veb);
5426 : : }
5427 : :
5428 [ # # ]: 0 : if (vsi->floating_veb) {
5429 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5430 : : list, temp) {
5431 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5432 : : return -1;
5433 : : }
5434 : : }
5435 : :
5436 : : /* Remove all macvlan filters of the VSI */
5437 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5438 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5439 : 0 : rte_free(f);
5440 : :
5441 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5442 : 0 : ((vsi->type != I40E_VSI_SRIOV) ||
5443 [ # # ]: 0 : !pf->floating_veb_list[user_param])) {
5444 : : /* Remove vsi from parent's sibling list */
5445 [ # # # # ]: 0 : if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5446 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5447 : 0 : return I40E_ERR_PARAM;
5448 : : }
5449 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5450 : : &vsi->sib_vsi_list, list);
5451 : :
5452 : : /* Remove all switch element of the VSI */
5453 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5454 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5455 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5456 : : }
5457 : :
5458 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5459 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5460 : : /* Remove vsi from parent's sibling list */
5461 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5462 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5463 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5464 : 0 : return I40E_ERR_PARAM;
5465 : : }
5466 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5467 : : &vsi->sib_vsi_list, list);
5468 : :
5469 : : /* Remove all switch element of the VSI */
5470 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5471 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5472 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5473 : : }
5474 : :
5475 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5476 : :
5477 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5478 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5479 : 0 : rte_free(vsi);
5480 : :
5481 : 0 : return I40E_SUCCESS;
5482 : : }
5483 : :
5484 : : static int
5485 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5486 : : {
5487 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5488 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5489 : : struct i40e_mac_filter_info filter;
5490 : : int ret;
5491 : :
5492 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5493 : : return I40E_ERR_CONFIG;
5494 : : memset(&def_filter, 0, sizeof(def_filter));
5495 [ # # ]: 0 : rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5496 : : ETH_ADDR_LEN);
5497 : : def_filter.vlan_tag = 0;
5498 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5499 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5500 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5501 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5502 : : struct i40e_mac_filter *f;
5503 : : struct rte_ether_addr *mac;
5504 : :
5505 : 0 : PMD_DRV_LOG(DEBUG,
5506 : : "Cannot remove the default macvlan filter");
5507 : : /* It needs to add the permanent mac into mac list */
5508 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5509 [ # # ]: 0 : if (f == NULL) {
5510 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5511 : 0 : return I40E_ERR_NO_MEMORY;
5512 : : }
5513 : : mac = &f->mac_info.mac_addr;
5514 [ # # ]: 0 : rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5515 : : ETH_ADDR_LEN);
5516 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5517 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5518 : 0 : vsi->mac_num++;
5519 : :
5520 : 0 : return ret;
5521 : : }
5522 : : rte_memcpy(&filter.mac_addr,
5523 : : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5524 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5525 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5526 : : }
5527 : :
5528 : : /*
5529 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5530 : : * @vsi: the VSI to be queried
5531 : : *
5532 : : * Returns 0 on success, negative value on failure
5533 : : */
5534 : : static enum i40e_status_code
5535 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5536 : : {
5537 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5538 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5539 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5540 : : i40e_status ret;
5541 : : int i;
5542 : : uint32_t bw_max;
5543 : :
5544 : : memset(&bw_config, 0, sizeof(bw_config));
5545 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5546 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5547 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5548 : : hw->aq.asq_last_status);
5549 : 0 : return ret;
5550 : : }
5551 : :
5552 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5553 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5554 : : &ets_sla_config, NULL);
5555 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5556 : 0 : PMD_DRV_LOG(ERR,
5557 : : "VSI failed to get TC bandwidth configuration %u",
5558 : : hw->aq.asq_last_status);
5559 : 0 : return ret;
5560 : : }
5561 : :
5562 : : /* store and print out BW info */
5563 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5564 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5565 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5566 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5567 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5568 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5569 : : I40E_16_BIT_WIDTH);
5570 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5571 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5572 : 0 : ets_sla_config.share_credits[i];
5573 : 0 : vsi->bw_info.bw_ets_credits[i] =
5574 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5575 : : /* 4 bits per TC, 4th bit is reserved */
5576 : 0 : vsi->bw_info.bw_ets_max[i] =
5577 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5578 : : RTE_LEN2MASK(3, uint8_t));
5579 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5580 : : vsi->bw_info.bw_ets_share_credits[i]);
5581 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5582 : : vsi->bw_info.bw_ets_credits[i]);
5583 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5584 : : vsi->bw_info.bw_ets_max[i]);
5585 : : }
5586 : :
5587 : : return I40E_SUCCESS;
5588 : : }
5589 : :
5590 : : /* i40e_enable_pf_lb
5591 : : * @pf: pointer to the pf structure
5592 : : *
5593 : : * allow loopback on pf
5594 : : */
5595 : : static inline void
5596 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5597 : : {
5598 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5599 : : struct i40e_vsi_context ctxt;
5600 : : int ret;
5601 : :
5602 : : /* Use the FW API if FW >= v5.0 */
5603 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5604 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5605 : 0 : return;
5606 : : }
5607 : :
5608 : : memset(&ctxt, 0, sizeof(ctxt));
5609 : 0 : ctxt.seid = pf->main_vsi_seid;
5610 : 0 : ctxt.pf_num = hw->pf_id;
5611 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5612 [ # # ]: 0 : if (ret) {
5613 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5614 : : ret, hw->aq.asq_last_status);
5615 : 0 : return;
5616 : : }
5617 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5618 : 0 : ctxt.info.valid_sections =
5619 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5620 : 0 : ctxt.info.switch_id |=
5621 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5622 : :
5623 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5624 [ # # ]: 0 : if (ret)
5625 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5626 : : hw->aq.asq_last_status);
5627 : : }
5628 : :
5629 : : /* i40e_pf_set_source_prune
5630 : : * @pf: pointer to the pf structure
5631 : : * @on: Enable/disable source prune
5632 : : *
5633 : : * set source prune on pf
5634 : : */
5635 : : int
5636 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5637 : : {
5638 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5639 : : struct i40e_vsi_context ctxt;
5640 : : int ret;
5641 : :
5642 : : memset(&ctxt, 0, sizeof(ctxt));
5643 : 0 : ctxt.seid = pf->main_vsi_seid;
5644 : 0 : ctxt.pf_num = hw->pf_id;
5645 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5646 [ # # ]: 0 : if (ret) {
5647 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5648 : : ret, hw->aq.asq_last_status);
5649 : 0 : return ret;
5650 : : }
5651 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5652 : 0 : ctxt.info.valid_sections =
5653 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5654 [ # # ]: 0 : if (on)
5655 : 0 : ctxt.info.switch_id &=
5656 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5657 : : else
5658 : 0 : ctxt.info.switch_id |=
5659 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5660 : :
5661 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5662 [ # # ]: 0 : if (ret)
5663 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5664 : : hw->aq.asq_last_status);
5665 : :
5666 : : return ret;
5667 : : }
5668 : :
5669 : : /* Setup a VSI */
5670 : : struct i40e_vsi *
5671 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5672 : : enum i40e_vsi_type type,
5673 : : struct i40e_vsi *uplink_vsi,
5674 : : uint16_t user_param)
5675 : : {
5676 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5677 : : struct i40e_vsi *vsi;
5678 : : struct i40e_mac_filter_info filter;
5679 : : int ret;
5680 : : struct i40e_vsi_context ctxt;
5681 : 0 : struct rte_ether_addr broadcast =
5682 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5683 : :
5684 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5685 : : uplink_vsi == NULL) {
5686 : 0 : PMD_DRV_LOG(ERR,
5687 : : "VSI setup failed, VSI link shouldn't be NULL");
5688 : 0 : return NULL;
5689 : : }
5690 : :
5691 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5692 : 0 : PMD_DRV_LOG(ERR,
5693 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5694 : 0 : return NULL;
5695 : : }
5696 : :
5697 : : /* two situations
5698 : : * 1.type is not MAIN and uplink vsi is not NULL
5699 : : * If uplink vsi didn't setup VEB, create one first under veb field
5700 : : * 2.type is SRIOV and the uplink is NULL
5701 : : * If floating VEB is NULL, create one veb under floating veb field
5702 : : */
5703 : :
5704 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5705 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5706 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5707 : :
5708 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5709 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5710 : 0 : return NULL;
5711 : : }
5712 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5713 : 0 : i40e_enable_pf_lb(pf);
5714 : : }
5715 : :
5716 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5717 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5718 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5719 : :
5720 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5721 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5722 : 0 : return NULL;
5723 : : }
5724 : : }
5725 : :
5726 : : /* source prune is disabled to support VRRP in default*/
5727 : 0 : i40e_pf_set_source_prune(pf, 0);
5728 : :
5729 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5730 [ # # ]: 0 : if (!vsi) {
5731 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5732 : 0 : return NULL;
5733 : : }
5734 : 0 : TAILQ_INIT(&vsi->mac_list);
5735 : 0 : vsi->type = type;
5736 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5737 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5738 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5739 : 0 : vsi->user_param = user_param;
5740 : 0 : vsi->vlan_anti_spoof_on = 0;
5741 : 0 : vsi->vlan_filter_on = 0;
5742 : : /* Allocate queues */
5743 [ # # # # : 0 : switch (vsi->type) {
# ]
5744 : 0 : case I40E_VSI_MAIN :
5745 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5746 : 0 : break;
5747 : 0 : case I40E_VSI_SRIOV :
5748 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5749 : 0 : break;
5750 : 0 : case I40E_VSI_VMDQ2:
5751 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5752 : 0 : break;
5753 : 0 : case I40E_VSI_FDIR:
5754 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5755 : 0 : break;
5756 : 0 : default:
5757 : 0 : goto fail_mem;
5758 : : }
5759 : : /*
5760 : : * The filter status descriptor is reported in rx queue 0,
5761 : : * while the tx queue for fdir filter programming has no
5762 : : * such constraints, can be non-zero queues.
5763 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5764 : : * To make sure it will use queue 0 pair, queue allocation
5765 : : * need be done before this function is called
5766 : : */
5767 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5768 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5769 [ # # ]: 0 : if (ret < 0) {
5770 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5771 : : vsi->seid, ret);
5772 : 0 : goto fail_mem;
5773 : : }
5774 : 0 : vsi->base_queue = ret;
5775 : : } else
5776 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5777 : :
5778 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5779 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5780 [ # # ]: 0 : if (pf->support_multi_driver) {
5781 : : /* If support multi-driver, need to use INT0 instead of
5782 : : * allocating from msix pool. The Msix pool is init from
5783 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5784 : : * to 1 without calling i40e_res_pool_alloc.
5785 : : */
5786 : 0 : vsi->msix_intr = 0;
5787 : 0 : vsi->nb_msix = 1;
5788 : : } else {
5789 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5790 : 0 : RTE_MIN(vsi->nb_qps,
5791 : : RTE_MAX_RXTX_INTR_VEC_ID));
5792 [ # # ]: 0 : if (ret < 0) {
5793 : 0 : PMD_DRV_LOG(ERR,
5794 : : "VSI MAIN %d get heap failed %d",
5795 : : vsi->seid, ret);
5796 : 0 : goto fail_queue_alloc;
5797 : : }
5798 : 0 : vsi->msix_intr = ret;
5799 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5800 : : RTE_MAX_RXTX_INTR_VEC_ID);
5801 : : }
5802 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5803 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5804 [ # # ]: 0 : if (ret < 0) {
5805 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5806 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5807 : 0 : goto fail_queue_alloc;
5808 : 0 : vsi->msix_intr = 0;
5809 : 0 : vsi->nb_msix = 0;
5810 : : } else {
5811 : 0 : vsi->msix_intr = ret;
5812 : 0 : vsi->nb_msix = 1;
5813 : : }
5814 : : } else {
5815 : 0 : vsi->msix_intr = 0;
5816 : 0 : vsi->nb_msix = 0;
5817 : : }
5818 : :
5819 : : /* Add VSI */
5820 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5821 : : /* For main VSI, no need to add since it's default one */
5822 : 0 : vsi->uplink_seid = pf->mac_seid;
5823 : 0 : vsi->seid = pf->main_vsi_seid;
5824 : : /* Bind queues with specific MSIX interrupt */
5825 : : /**
5826 : : * Needs 2 interrupt at least, one for misc cause which will
5827 : : * enabled from OS side, Another for queues binding the
5828 : : * interrupt from device side only.
5829 : : */
5830 : :
5831 : : /* Get default VSI parameters from hardware */
5832 : : memset(&ctxt, 0, sizeof(ctxt));
5833 : 0 : ctxt.seid = vsi->seid;
5834 : 0 : ctxt.pf_num = hw->pf_id;
5835 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5836 : : ctxt.vf_num = 0;
5837 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5838 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5839 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
5840 : 0 : goto fail_msix_alloc;
5841 : : }
5842 [ # # ]: 0 : rte_memcpy(&vsi->info, &ctxt.info,
5843 : : sizeof(struct i40e_aqc_vsi_properties_data));
5844 : 0 : vsi->vsi_id = ctxt.vsi_number;
5845 : 0 : vsi->info.valid_sections = 0;
5846 : :
5847 : : /* Configure tc, enabled TC0 only */
5848 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5849 : : I40E_SUCCESS) {
5850 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5851 : 0 : goto fail_msix_alloc;
5852 : : }
5853 : :
5854 : : /* TC, queue mapping */
5855 : : memset(&ctxt, 0, sizeof(ctxt));
5856 : 0 : vsi->info.valid_sections |=
5857 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5858 [ # # ]: 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5859 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5860 : : rte_memcpy(&ctxt.info, &vsi->info,
5861 : : sizeof(struct i40e_aqc_vsi_properties_data));
5862 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5863 : : I40E_DEFAULT_TCMAP);
5864 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5865 : 0 : PMD_DRV_LOG(ERR,
5866 : : "Failed to configure TC queue mapping");
5867 : 0 : goto fail_msix_alloc;
5868 : : }
5869 : 0 : ctxt.seid = vsi->seid;
5870 : 0 : ctxt.pf_num = hw->pf_id;
5871 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5872 : 0 : ctxt.vf_num = 0;
5873 : :
5874 : : /* Update VSI parameters */
5875 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5876 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5877 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5878 : 0 : goto fail_msix_alloc;
5879 : : }
5880 : :
5881 : : rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5882 : : sizeof(vsi->info.tc_mapping));
5883 : : rte_memcpy(&vsi->info.queue_mapping,
5884 : : &ctxt.info.queue_mapping,
5885 : : sizeof(vsi->info.queue_mapping));
5886 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
5887 : 0 : vsi->info.valid_sections = 0;
5888 : :
5889 [ # # ]: 0 : rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5890 : : ETH_ADDR_LEN);
5891 : :
5892 : : /**
5893 : : * Updating default filter settings are necessary to prevent
5894 : : * reception of tagged packets.
5895 : : * Some old firmware configurations load a default macvlan
5896 : : * filter which accepts both tagged and untagged packets.
5897 : : * The updating is to use a normal filter instead if needed.
5898 : : * For NVM 4.2.2 or after, the updating is not needed anymore.
5899 : : * The firmware with correct configurations load the default
5900 : : * macvlan filter which is expected and cannot be removed.
5901 : : */
5902 : 0 : i40e_update_default_filter_setting(vsi);
5903 : 0 : i40e_config_qinq(hw, vsi);
5904 [ # # ]: 0 : } else if (type == I40E_VSI_SRIOV) {
5905 : : memset(&ctxt, 0, sizeof(ctxt));
5906 : : /**
5907 : : * For other VSI, the uplink_seid equals to uplink VSI's
5908 : : * uplink_seid since they share same VEB
5909 : : */
5910 [ # # ]: 0 : if (uplink_vsi == NULL)
5911 : 0 : vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5912 : : else
5913 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
5914 : 0 : ctxt.pf_num = hw->pf_id;
5915 : 0 : ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5916 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5917 : 0 : ctxt.connection_type = 0x1;
5918 : : ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5919 : :
5920 : : /* Use the VEB configuration if FW >= v5.0 */
5921 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
5922 : : /* Configure switch ID */
5923 : 0 : ctxt.info.valid_sections |=
5924 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5925 : 0 : ctxt.info.switch_id =
5926 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5927 : : }
5928 : :
5929 : : /* Configure port/vlan */
5930 : 0 : ctxt.info.valid_sections |=
5931 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5932 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5933 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5934 : 0 : hw->func_caps.enabled_tcmap);
5935 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5936 : 0 : PMD_DRV_LOG(ERR,
5937 : : "Failed to configure TC queue mapping");
5938 : 0 : goto fail_msix_alloc;
5939 : : }
5940 : :
5941 : 0 : ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5942 : 0 : ctxt.info.valid_sections |=
5943 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5944 : : /**
5945 : : * Since VSI is not created yet, only configure parameter,
5946 : : * will add vsi below.
5947 : : */
5948 : :
5949 : 0 : i40e_config_qinq(hw, vsi);
5950 [ # # ]: 0 : } else if (type == I40E_VSI_VMDQ2) {
5951 : : memset(&ctxt, 0, sizeof(ctxt));
5952 : : /*
5953 : : * For other VSI, the uplink_seid equals to uplink VSI's
5954 : : * uplink_seid since they share same VEB
5955 : : */
5956 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
5957 : 0 : ctxt.pf_num = hw->pf_id;
5958 : : ctxt.vf_num = 0;
5959 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5960 : 0 : ctxt.connection_type = 0x1;
5961 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5962 : :
5963 : 0 : ctxt.info.valid_sections |=
5964 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5965 : : /* user_param carries flag to enable loop back */
5966 [ # # ]: 0 : if (user_param) {
5967 : : ctxt.info.switch_id =
5968 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5969 : 0 : ctxt.info.switch_id |=
5970 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5971 : : }
5972 : :
5973 : : /* Configure port/vlan */
5974 : 0 : ctxt.info.valid_sections |=
5975 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5976 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5977 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5978 : : I40E_DEFAULT_TCMAP);
5979 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5980 : 0 : PMD_DRV_LOG(ERR,
5981 : : "Failed to configure TC queue mapping");
5982 : 0 : goto fail_msix_alloc;
5983 : : }
5984 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5985 : 0 : ctxt.info.valid_sections |=
5986 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5987 : : } else if (type == I40E_VSI_FDIR) {
5988 : : memset(&ctxt, 0, sizeof(ctxt));
5989 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
5990 : 0 : ctxt.pf_num = hw->pf_id;
5991 : : ctxt.vf_num = 0;
5992 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5993 : 0 : ctxt.connection_type = 0x1; /* regular data port */
5994 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5995 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5996 : : I40E_DEFAULT_TCMAP);
5997 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5998 : 0 : PMD_DRV_LOG(ERR,
5999 : : "Failed to configure TC queue mapping.");
6000 : 0 : goto fail_msix_alloc;
6001 : : }
6002 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6003 : 0 : ctxt.info.valid_sections |=
6004 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6005 : : } else {
6006 : : PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6007 : : goto fail_msix_alloc;
6008 : : }
6009 : :
6010 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN) {
6011 : 0 : ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6012 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6013 : 0 : PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6014 : : hw->aq.asq_last_status);
6015 : 0 : goto fail_msix_alloc;
6016 : : }
6017 [ # # ]: 0 : memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6018 : 0 : vsi->info.valid_sections = 0;
6019 : 0 : vsi->seid = ctxt.seid;
6020 : 0 : vsi->vsi_id = ctxt.vsi_number;
6021 : 0 : vsi->sib_vsi_list.vsi = vsi;
6022 [ # # # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6023 : 0 : TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6024 : : &vsi->sib_vsi_list, list);
6025 : : } else {
6026 : 0 : TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6027 : : &vsi->sib_vsi_list, list);
6028 : : }
6029 : : }
6030 : :
6031 [ # # ]: 0 : if (vsi->type != I40E_VSI_FDIR) {
6032 : : /* MAC/VLAN configuration for non-FDIR VSI*/
6033 : : rte_memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6034 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6035 : :
6036 : 0 : ret = i40e_vsi_add_mac(vsi, &filter);
6037 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6038 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6039 : 0 : goto fail_msix_alloc;
6040 : : }
6041 : : }
6042 : :
6043 : : /* Get VSI BW information */
6044 : 0 : i40e_vsi_get_bw_config(vsi);
6045 : 0 : return vsi;
6046 : 0 : fail_msix_alloc:
6047 : 0 : i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6048 : 0 : fail_queue_alloc:
6049 : 0 : i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6050 : 0 : fail_mem:
6051 : 0 : rte_free(vsi);
6052 : 0 : return NULL;
6053 : : }
6054 : :
6055 : : /* Configure vlan filter on or off */
6056 : : int
6057 : 0 : i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6058 : : {
6059 : : int i, num;
6060 : : struct i40e_mac_filter *f;
6061 : : void *temp;
6062 : : struct i40e_mac_filter_info *mac_filter;
6063 : : enum i40e_mac_filter_type desired_filter;
6064 : : int ret = I40E_SUCCESS;
6065 : :
6066 [ # # ]: 0 : if (on) {
6067 : : /* Filter to match MAC and VLAN */
6068 : : desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6069 : : } else {
6070 : : /* Filter to match only MAC */
6071 : : desired_filter = I40E_MAC_PERFECT_MATCH;
6072 : : }
6073 : :
6074 : 0 : num = vsi->mac_num;
6075 : :
6076 : 0 : mac_filter = rte_zmalloc("mac_filter_info_data",
6077 : : num * sizeof(*mac_filter), 0);
6078 [ # # ]: 0 : if (mac_filter == NULL) {
6079 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
6080 : 0 : return I40E_ERR_NO_MEMORY;
6081 : : }
6082 : :
6083 : : i = 0;
6084 : :
6085 : : /* Remove all existing mac */
6086 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6087 : 0 : mac_filter[i] = f->mac_info;
6088 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6089 [ # # ]: 0 : if (ret) {
6090 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6091 : : on ? "enable" : "disable");
6092 : 0 : goto DONE;
6093 : : }
6094 : 0 : i++;
6095 : : }
6096 : :
6097 : : /* Override with new filter */
6098 [ # # ]: 0 : for (i = 0; i < num; i++) {
6099 : 0 : mac_filter[i].filter_type = desired_filter;
6100 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6101 [ # # ]: 0 : if (ret) {
6102 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6103 : : on ? "enable" : "disable");
6104 : 0 : goto DONE;
6105 : : }
6106 : : }
6107 : :
6108 : 0 : DONE:
6109 : 0 : rte_free(mac_filter);
6110 : 0 : return ret;
6111 : : }
6112 : :
6113 : : /* Configure vlan stripping on or off */
6114 : : int
6115 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6116 : : {
6117 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6118 : : struct i40e_vsi_context ctxt;
6119 : : uint8_t vlan_flags;
6120 : : int ret = I40E_SUCCESS;
6121 : :
6122 : : /* Check if it has been already on or off */
6123 [ # # ]: 0 : if (vsi->info.valid_sections &
6124 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6125 [ # # ]: 0 : if (on) {
6126 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6127 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6128 : : return 0; /* already on */
6129 : : } else {
6130 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6131 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6132 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6133 : : return 0; /* already off */
6134 : : }
6135 : : }
6136 : :
6137 [ # # ]: 0 : if (on)
6138 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6139 : : else
6140 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6141 : 0 : vsi->info.valid_sections =
6142 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6143 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6144 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6145 : 0 : ctxt.seid = vsi->seid;
6146 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6147 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6148 [ # # ]: 0 : if (ret)
6149 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6150 : : on ? "enable" : "disable");
6151 : :
6152 : : return ret;
6153 : : }
6154 : :
6155 : : static int
6156 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6157 : : {
6158 : 0 : struct rte_eth_dev_data *data = dev->data;
6159 : : int ret;
6160 : : int mask = 0;
6161 : :
6162 : : /* Apply vlan offload setting */
6163 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6164 : : RTE_ETH_QINQ_STRIP_MASK |
6165 : : RTE_ETH_VLAN_FILTER_MASK |
6166 : : RTE_ETH_VLAN_EXTEND_MASK;
6167 : :
6168 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6169 [ # # ]: 0 : if (ret) {
6170 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6171 : 0 : return ret;
6172 : : }
6173 : :
6174 : : /* Apply pvid setting */
6175 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6176 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6177 [ # # ]: 0 : if (ret)
6178 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6179 : :
6180 : : return ret;
6181 : : }
6182 : :
6183 : : static int
6184 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6185 : : {
6186 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6187 : :
6188 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6189 : : }
6190 : :
6191 : : static int
6192 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6193 : : {
6194 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6195 : : struct i40e_link_status link_status;
6196 : : uint32_t rxfc = 0, txfc = 0, reg;
6197 : : uint8_t an_info;
6198 : : int ret;
6199 : :
6200 : : memset(&link_status, 0, sizeof(link_status));
6201 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6202 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6203 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6204 : 0 : goto write_reg; /* Disable flow control */
6205 : : }
6206 : :
6207 : 0 : an_info = hw->phy.link_info.an_info;
6208 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6209 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6210 : : ret = I40E_ERR_NOT_READY;
6211 : 0 : goto write_reg; /* Disable flow control */
6212 : : }
6213 : : /**
6214 : : * If link auto negotiation is enabled, flow control needs to
6215 : : * be configured according to it
6216 : : */
6217 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6218 : 0 : case I40E_LINK_PAUSE_RXTX:
6219 : : rxfc = 1;
6220 : : txfc = 1;
6221 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6222 : 0 : break;
6223 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6224 : : rxfc = 1;
6225 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6226 : 0 : break;
6227 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6228 : : txfc = 1;
6229 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6230 : 0 : break;
6231 : 0 : default:
6232 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6233 : 0 : break;
6234 : : }
6235 : :
6236 : 0 : write_reg:
6237 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6238 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6239 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6240 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6241 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6242 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6243 : :
6244 : 0 : return ret;
6245 : : }
6246 : :
6247 : : /* PF setup */
6248 : : static int
6249 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6250 : : {
6251 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6252 : : struct i40e_filter_control_settings settings;
6253 : : struct i40e_vsi *vsi;
6254 : : int ret;
6255 : :
6256 : : /* Clear all stats counters */
6257 : 0 : pf->offset_loaded = FALSE;
6258 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6259 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6260 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6261 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6262 : 0 : pf->rx_err1 = 0;
6263 : 0 : pf->rx_err1_offset = 0;
6264 : :
6265 : 0 : ret = i40e_pf_get_switch_config(pf);
6266 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6267 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6268 : 0 : return ret;
6269 : : }
6270 : :
6271 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6272 [ # # ]: 0 : if (ret)
6273 : 0 : PMD_INIT_LOG(WARNING,
6274 : : "failed to allocate switch domain for device %d", ret);
6275 : :
6276 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6277 : : /* make queue allocated first, let FDIR use queue pair 0*/
6278 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6279 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6280 : 0 : PMD_DRV_LOG(ERR,
6281 : : "queue allocation fails for FDIR: ret =%d",
6282 : : ret);
6283 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6284 : : }
6285 : : }
6286 : : /* main VSI setup */
6287 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6288 [ # # ]: 0 : if (!vsi) {
6289 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6290 : 0 : return I40E_ERR_NOT_READY;
6291 : : }
6292 [ # # ]: 0 : pf->main_vsi = vsi;
6293 : :
6294 : : /* Configure filter control */
6295 : : memset(&settings, 0, sizeof(settings));
6296 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6297 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6298 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6299 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6300 : : else {
6301 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6302 : : hw->func_caps.rss_table_size);
6303 : 0 : return I40E_ERR_PARAM;
6304 : : }
6305 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6306 : : hw->func_caps.rss_table_size);
6307 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6308 : :
6309 : : /* Enable ethtype and macvlan filters */
6310 : 0 : settings.enable_ethtype = TRUE;
6311 : 0 : settings.enable_macvlan = TRUE;
6312 : 0 : ret = i40e_set_filter_control(hw, &settings);
6313 [ # # ]: 0 : if (ret)
6314 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6315 : : ret);
6316 : :
6317 : : /* Update flow control according to the auto negotiation */
6318 : 0 : i40e_update_flow_control(hw);
6319 : :
6320 : 0 : return I40E_SUCCESS;
6321 : : }
6322 : :
6323 : : int
6324 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6325 : : {
6326 : : uint32_t reg;
6327 : : uint16_t j;
6328 : :
6329 : : /**
6330 : : * Set or clear TX Queue Disable flags,
6331 : : * which is required by hardware.
6332 : : */
6333 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6334 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6335 : :
6336 : : /* Wait until the request is finished */
6337 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6338 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6339 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6340 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6341 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6342 : : & 0x1))) {
6343 : : break;
6344 : : }
6345 : : }
6346 [ # # ]: 0 : if (on) {
6347 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6348 : : return I40E_SUCCESS; /* already on, skip next steps */
6349 : :
6350 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6351 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6352 : : } else {
6353 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6354 : : return I40E_SUCCESS; /* already off, skip next steps */
6355 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6356 : : }
6357 : : /* Write the register */
6358 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6359 : : /* Check the result */
6360 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6361 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6362 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6363 [ # # ]: 0 : if (on) {
6364 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6365 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6366 : : break;
6367 : : } else {
6368 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6369 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6370 : : break;
6371 : : }
6372 : : }
6373 : : /* Check if it is timeout */
6374 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6375 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6376 : : (on ? "enable" : "disable"), q_idx);
6377 : 0 : return I40E_ERR_TIMEOUT;
6378 : : }
6379 : :
6380 : : return I40E_SUCCESS;
6381 : : }
6382 : :
6383 : : int
6384 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6385 : : {
6386 : : uint32_t reg;
6387 : : uint16_t j;
6388 : :
6389 : : /* Wait until the request is finished */
6390 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6391 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6392 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6393 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6394 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6395 : : break;
6396 : : }
6397 : :
6398 [ # # ]: 0 : if (on) {
6399 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6400 : : return I40E_SUCCESS; /* Already on, skip next steps */
6401 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6402 : : } else {
6403 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6404 : : return I40E_SUCCESS; /* Already off, skip next steps */
6405 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6406 : : }
6407 : :
6408 : : /* Write the register */
6409 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6410 : : /* Check the result */
6411 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6412 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6413 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6414 [ # # ]: 0 : if (on) {
6415 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6416 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6417 : : break;
6418 : : } else {
6419 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6420 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6421 : : break;
6422 : : }
6423 : : }
6424 : :
6425 : : /* Check if it is timeout */
6426 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6427 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6428 : : (on ? "enable" : "disable"), q_idx);
6429 : 0 : return I40E_ERR_TIMEOUT;
6430 : : }
6431 : :
6432 : : return I40E_SUCCESS;
6433 : : }
6434 : :
6435 : : /* Initialize VSI for TX */
6436 : : static int
6437 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6438 : : {
6439 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6440 : : uint16_t i;
6441 : : uint32_t ret = I40E_SUCCESS;
6442 : : struct i40e_tx_queue *txq;
6443 : :
6444 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6445 : 0 : txq = data->tx_queues[i];
6446 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6447 : 0 : continue;
6448 : 0 : ret = i40e_tx_queue_init(txq);
6449 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6450 : : break;
6451 : : }
6452 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6453 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6454 : :
6455 : 0 : return ret;
6456 : : }
6457 : :
6458 : : /* Initialize VSI for RX */
6459 : : static int
6460 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6461 : : {
6462 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6463 : : int ret = I40E_SUCCESS;
6464 : : uint16_t i;
6465 : : struct i40e_rx_queue *rxq;
6466 : :
6467 : 0 : i40e_pf_config_rss(pf);
6468 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6469 : 0 : rxq = data->rx_queues[i];
6470 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6471 : 0 : continue;
6472 : :
6473 : 0 : ret = i40e_rx_queue_init(rxq);
6474 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6475 : 0 : PMD_DRV_LOG(ERR,
6476 : : "Failed to do RX queue initialization");
6477 : 0 : break;
6478 : : }
6479 : : }
6480 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6481 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6482 : :
6483 : 0 : return ret;
6484 : : }
6485 : :
6486 : : static int
6487 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6488 : : {
6489 : : int err;
6490 : :
6491 : 0 : err = i40e_dev_tx_init(pf);
6492 [ # # ]: 0 : if (err) {
6493 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6494 : 0 : return err;
6495 : : }
6496 : 0 : err = i40e_dev_rx_init(pf);
6497 [ # # ]: 0 : if (err) {
6498 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6499 : 0 : return err;
6500 : : }
6501 : :
6502 : : return err;
6503 : : }
6504 : :
6505 : : static int
6506 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6507 : : {
6508 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6509 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6510 : : int i, err, conf_vsis, j, loop;
6511 : : struct i40e_vsi *vsi;
6512 : : struct i40e_vmdq_info *vmdq_info;
6513 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6514 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6515 : :
6516 : : /*
6517 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6518 : : * avoid race condition in VSI creation/destroy.
6519 : : */
6520 : 0 : i40e_pf_disable_irq0(hw);
6521 : :
6522 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6523 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6524 : 0 : return -ENOTSUP;
6525 : : }
6526 : :
6527 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6528 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6529 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6530 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6531 : : pf->max_nb_vmdq_vsi);
6532 : 0 : return -ENOTSUP;
6533 : : }
6534 : :
6535 [ # # ]: 0 : if (pf->vmdq != NULL) {
6536 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6537 : 0 : return 0;
6538 : : }
6539 : :
6540 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6541 : : sizeof(*vmdq_info) * conf_vsis, 0);
6542 : :
6543 [ # # ]: 0 : if (pf->vmdq == NULL) {
6544 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6545 : 0 : return -ENOMEM;
6546 : : }
6547 : :
6548 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6549 : :
6550 : : /* Create VMDQ VSI */
6551 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6552 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6553 : 0 : vmdq_conf->enable_loop_back);
6554 [ # # ]: 0 : if (vsi == NULL) {
6555 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6556 : : err = -1;
6557 : 0 : goto err_vsi_setup;
6558 : : }
6559 : 0 : vmdq_info = &pf->vmdq[i];
6560 : 0 : vmdq_info->pf = pf;
6561 : 0 : vmdq_info->vsi = vsi;
6562 : : }
6563 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6564 : :
6565 : : /* Configure Vlan */
6566 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6567 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6568 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6569 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6570 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6571 : : vmdq_conf->pool_map[i].vlan_id, j);
6572 : :
6573 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6574 : 0 : vmdq_conf->pool_map[i].vlan_id);
6575 [ # # ]: 0 : if (err) {
6576 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6577 : : err = -1;
6578 : 0 : goto err_vsi_setup;
6579 : : }
6580 : : }
6581 : : }
6582 : : }
6583 : :
6584 : 0 : i40e_pf_enable_irq0(hw);
6585 : :
6586 : 0 : return 0;
6587 : :
6588 : : err_vsi_setup:
6589 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6590 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6591 : : break;
6592 : : else
6593 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6594 : :
6595 : 0 : rte_free(pf->vmdq);
6596 : 0 : pf->vmdq = NULL;
6597 : 0 : i40e_pf_enable_irq0(hw);
6598 : 0 : return err;
6599 : : }
6600 : :
6601 : : static void
6602 : : i40e_stat_update_32(struct i40e_hw *hw,
6603 : : uint32_t reg,
6604 : : bool offset_loaded,
6605 : : uint64_t *offset,
6606 : : uint64_t *stat)
6607 : : {
6608 : : uint64_t new_data;
6609 : :
6610 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6611 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6612 : 0 : *offset = new_data;
6613 : :
6614 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6615 : 0 : *stat = (uint64_t)(new_data - *offset);
6616 : : else
6617 : 0 : *stat = (uint64_t)((new_data +
6618 : : ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6619 : : }
6620 : :
6621 : : static void
6622 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6623 : : uint32_t hireg,
6624 : : uint32_t loreg,
6625 : : bool offset_loaded,
6626 : : uint64_t *offset,
6627 : : uint64_t *stat)
6628 : : {
6629 : : uint64_t new_data;
6630 : :
6631 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6632 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6633 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6634 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6635 : : } else {
6636 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6637 : : }
6638 : :
6639 [ # # ]: 0 : if (!offset_loaded)
6640 : 0 : *offset = new_data;
6641 : :
6642 [ # # ]: 0 : if (new_data >= *offset)
6643 : 0 : *stat = new_data - *offset;
6644 : : else
6645 : 0 : *stat = (uint64_t)((new_data +
6646 : : ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6647 : :
6648 : 0 : *stat &= I40E_48_BIT_MASK;
6649 : 0 : }
6650 : :
6651 : : /* Disable IRQ0 */
6652 : : void
6653 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6654 : : {
6655 : : /* Disable all interrupt types */
6656 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6657 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6658 : 0 : I40E_WRITE_FLUSH(hw);
6659 : 0 : }
6660 : :
6661 : : /* Enable IRQ0 */
6662 : : void
6663 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6664 : : {
6665 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6666 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6667 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6668 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6669 : 0 : I40E_WRITE_FLUSH(hw);
6670 : 0 : }
6671 : :
6672 : : static void
6673 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6674 : : {
6675 : : /* read pending request and disable first */
6676 : 0 : i40e_pf_disable_irq0(hw);
6677 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6678 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6679 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6680 : :
6681 : : if (no_queue)
6682 : : /* Link no queues with irq0 */
6683 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6684 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6685 : : }
6686 : :
6687 : : static void
6688 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6689 : : {
6690 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6691 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6692 : : int i;
6693 : : uint16_t abs_vf_id;
6694 : : uint32_t index, offset, val;
6695 : :
6696 [ # # ]: 0 : if (!pf->vfs)
6697 : : return;
6698 : : /**
6699 : : * Try to find which VF trigger a reset, use absolute VF id to access
6700 : : * since the reg is global register.
6701 : : */
6702 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6703 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6704 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6705 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6706 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6707 : : /* VFR event occurred */
6708 [ # # ]: 0 : if (val & (0x1 << offset)) {
6709 : : int ret;
6710 : :
6711 : : /* Clear the event first */
6712 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6713 : : (0x1 << offset));
6714 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6715 : : /**
6716 : : * Only notify a VF reset event occurred,
6717 : : * don't trigger another SW reset
6718 : : */
6719 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6720 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6721 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6722 : : }
6723 : : }
6724 : : }
6725 : :
6726 : : static void
6727 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6728 : : {
6729 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6730 : : int i;
6731 : :
6732 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6733 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6734 : 0 : }
6735 : :
6736 : : static void
6737 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6738 : : {
6739 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6740 : : struct i40e_arq_event_info info;
6741 : : uint16_t pending, opcode;
6742 : : int ret;
6743 : :
6744 : 0 : info.buf_len = I40E_AQ_BUF_SZ;
6745 : 0 : info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6746 [ # # ]: 0 : if (!info.msg_buf) {
6747 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate mem");
6748 : 0 : return;
6749 : : }
6750 : :
6751 : 0 : pending = 1;
6752 [ # # ]: 0 : while (pending) {
6753 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6754 : :
6755 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6756 : 0 : PMD_DRV_LOG(INFO,
6757 : : "Failed to read msg from AdminQ, aq_err: %u",
6758 : : hw->aq.asq_last_status);
6759 : 0 : break;
6760 : : }
6761 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6762 : :
6763 [ # # # ]: 0 : switch (opcode) {
6764 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6765 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6766 : 0 : i40e_pf_host_handle_vf_msg(dev,
6767 : 0 : rte_le_to_cpu_16(info.desc.retval),
6768 : : rte_le_to_cpu_32(info.desc.cookie_high),
6769 : : rte_le_to_cpu_32(info.desc.cookie_low),
6770 : 0 : info.msg_buf,
6771 : 0 : info.msg_len);
6772 : 0 : break;
6773 : 0 : case i40e_aqc_opc_get_link_status:
6774 : 0 : ret = i40e_dev_link_update(dev, 0);
6775 [ # # ]: 0 : if (!ret)
6776 : 0 : rte_eth_dev_callback_process(dev,
6777 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6778 : : break;
6779 : 0 : default:
6780 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6781 : : opcode);
6782 : 0 : break;
6783 : : }
6784 : : }
6785 : 0 : rte_free(info.msg_buf);
6786 : : }
6787 : :
6788 : : static void
6789 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6790 : : {
6791 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6792 : : #define I40E_MDD_CLEAR16 0xFFFF
6793 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6794 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6795 : : bool mdd_detected = false;
6796 : : struct i40e_pf_vf *vf;
6797 : : uint32_t reg;
6798 : : int i;
6799 : :
6800 : : /* find what triggered the MDD event */
6801 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6802 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6803 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6804 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6805 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6806 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6807 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6808 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6809 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6810 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6811 : 0 : hw->func_caps.base_queue;
6812 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6813 : : "queue %d PF number 0x%02x VF number 0x%02x device %s\n",
6814 : : event, queue, pf_num, vf_num, dev->data->name);
6815 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6816 : : mdd_detected = true;
6817 : : }
6818 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6819 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6820 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6821 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6822 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6823 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6824 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6825 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6826 : 0 : hw->func_caps.base_queue;
6827 : :
6828 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6829 : : "queue %d of function 0x%02x device %s\n",
6830 : : event, queue, func, dev->data->name);
6831 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6832 : : mdd_detected = true;
6833 : : }
6834 : :
6835 [ # # ]: 0 : if (mdd_detected) {
6836 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6837 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6838 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6839 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF\n");
6840 : : }
6841 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6842 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6843 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6844 : : I40E_MDD_CLEAR16);
6845 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF\n");
6846 : : }
6847 : : }
6848 : :
6849 : : /* see if one of the VFs needs its hand slapped */
6850 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6851 : 0 : vf = &pf->vfs[i];
6852 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6853 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6854 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6855 : : I40E_MDD_CLEAR16);
6856 : 0 : vf->num_mdd_events++;
6857 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6858 : : PRIu64 "times\n",
6859 : : i, vf->num_mdd_events);
6860 : : }
6861 : :
6862 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
6863 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6864 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
6865 : : I40E_MDD_CLEAR16);
6866 : 0 : vf->num_mdd_events++;
6867 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
6868 : : PRIu64 "times\n",
6869 : : i, vf->num_mdd_events);
6870 : : }
6871 : : }
6872 : 0 : }
6873 : :
6874 : : /**
6875 : : * Interrupt handler triggered by NIC for handling
6876 : : * specific interrupt.
6877 : : *
6878 : : * @param handle
6879 : : * Pointer to interrupt handle.
6880 : : * @param param
6881 : : * The address of parameter (struct rte_eth_dev *) registered before.
6882 : : *
6883 : : * @return
6884 : : * void
6885 : : */
6886 : : static void
6887 : 0 : i40e_dev_interrupt_handler(void *param)
6888 : : {
6889 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6890 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6891 : : uint32_t icr0;
6892 : :
6893 : : /* Disable interrupt */
6894 : 0 : i40e_pf_disable_irq0(hw);
6895 : :
6896 : : /* read out interrupt causes */
6897 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6898 : :
6899 : : /* No interrupt event indicated */
6900 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6901 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
6902 : 0 : goto done;
6903 : : }
6904 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6905 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6906 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6907 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6908 : 0 : i40e_handle_mdd_event(dev);
6909 : : }
6910 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6911 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6912 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6913 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6914 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6915 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6916 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6917 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
6918 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6919 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6920 : :
6921 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6922 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6923 : 0 : i40e_dev_handle_vfr_event(dev);
6924 : : }
6925 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6926 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
6927 : 0 : i40e_dev_handle_aq_msg(dev);
6928 : : }
6929 : :
6930 : 0 : done:
6931 : : /* Enable interrupt */
6932 : 0 : i40e_pf_enable_irq0(hw);
6933 : 0 : }
6934 : :
6935 : : static void
6936 : 0 : i40e_dev_alarm_handler(void *param)
6937 : : {
6938 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6939 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6940 : : uint32_t icr0;
6941 : :
6942 : : /* Disable interrupt */
6943 : 0 : i40e_pf_disable_irq0(hw);
6944 : :
6945 : : /* read out interrupt causes */
6946 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6947 : :
6948 : : /* No interrupt event indicated */
6949 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
6950 : 0 : goto done;
6951 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6952 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6953 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6954 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6955 : 0 : i40e_handle_mdd_event(dev);
6956 : : }
6957 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6958 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6959 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6960 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6961 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6962 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6963 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6964 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
6965 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6966 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6967 : :
6968 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6969 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6970 : 0 : i40e_dev_handle_vfr_event(dev);
6971 : : }
6972 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6973 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
6974 : 0 : i40e_dev_handle_aq_msg(dev);
6975 : : }
6976 : :
6977 : 0 : done:
6978 : : /* Enable interrupt */
6979 : 0 : i40e_pf_enable_irq0(hw);
6980 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
6981 : : i40e_dev_alarm_handler, dev);
6982 : 0 : }
6983 : :
6984 : : int
6985 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
6986 : : struct i40e_macvlan_filter *filter,
6987 : : int total)
6988 : : {
6989 : : int ele_num, ele_buff_size;
6990 : : int num, actual_num, i;
6991 : : uint16_t flags;
6992 : : int ret = I40E_SUCCESS;
6993 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6994 : : struct i40e_aqc_add_macvlan_element_data *req_list;
6995 : :
6996 [ # # ]: 0 : if (filter == NULL || total == 0)
6997 : : return I40E_ERR_PARAM;
6998 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6999 : : ele_buff_size = hw->aq.asq_buf_size;
7000 : :
7001 : 0 : req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
7002 [ # # ]: 0 : if (req_list == NULL) {
7003 : 0 : PMD_DRV_LOG(ERR, "Fail to allocate memory");
7004 : 0 : return I40E_ERR_NO_MEMORY;
7005 : : }
7006 : :
7007 : : num = 0;
7008 : : do {
7009 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7010 : : memset(req_list, 0, ele_buff_size);
7011 : :
7012 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7013 : 0 : rte_memcpy(req_list[i].mac_addr,
7014 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7015 : 0 : req_list[i].vlan_tag =
7016 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7017 : :
7018 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7019 : : case I40E_MAC_PERFECT_MATCH:
7020 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7021 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7022 : : break;
7023 : : case I40E_MACVLAN_PERFECT_MATCH:
7024 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7025 : : break;
7026 : : case I40E_MAC_HASH_MATCH:
7027 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7028 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7029 : : break;
7030 : : case I40E_MACVLAN_HASH_MATCH:
7031 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7032 : : break;
7033 : 0 : default:
7034 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7035 : : ret = I40E_ERR_PARAM;
7036 : 0 : goto DONE;
7037 : : }
7038 : :
7039 : 0 : req_list[i].queue_number = 0;
7040 : :
7041 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7042 : : }
7043 : :
7044 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7045 : : actual_num, NULL);
7046 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7047 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7048 : 0 : goto DONE;
7049 : : }
7050 : 0 : num += actual_num;
7051 [ # # ]: 0 : } while (num < total);
7052 : :
7053 : 0 : DONE:
7054 : 0 : rte_free(req_list);
7055 : 0 : return ret;
7056 : : }
7057 : :
7058 : : int
7059 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7060 : : struct i40e_macvlan_filter *filter,
7061 : : int total)
7062 : : {
7063 : : int ele_num, ele_buff_size;
7064 : : int num, actual_num, i;
7065 : : uint16_t flags;
7066 : : int ret = I40E_SUCCESS;
7067 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7068 : : struct i40e_aqc_remove_macvlan_element_data *req_list;
7069 : : enum i40e_admin_queue_err aq_status;
7070 : :
7071 [ # # ]: 0 : if (filter == NULL || total == 0)
7072 : : return I40E_ERR_PARAM;
7073 : :
7074 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7075 : : ele_buff_size = hw->aq.asq_buf_size;
7076 : :
7077 : 0 : req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
7078 [ # # ]: 0 : if (req_list == NULL) {
7079 : 0 : PMD_DRV_LOG(ERR, "Fail to allocate memory");
7080 : 0 : return I40E_ERR_NO_MEMORY;
7081 : : }
7082 : :
7083 : : num = 0;
7084 : : do {
7085 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7086 : : memset(req_list, 0, ele_buff_size);
7087 : :
7088 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7089 : 0 : rte_memcpy(req_list[i].mac_addr,
7090 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7091 : 0 : req_list[i].vlan_tag =
7092 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7093 : :
7094 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7095 : : case I40E_MAC_PERFECT_MATCH:
7096 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7097 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7098 : : break;
7099 : : case I40E_MACVLAN_PERFECT_MATCH:
7100 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7101 : : break;
7102 : : case I40E_MAC_HASH_MATCH:
7103 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7104 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7105 : : break;
7106 : : case I40E_MACVLAN_HASH_MATCH:
7107 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7108 : : break;
7109 : 0 : default:
7110 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7111 : : ret = I40E_ERR_PARAM;
7112 : 0 : goto DONE;
7113 : : }
7114 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7115 : : }
7116 : :
7117 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7118 : : actual_num, NULL, &aq_status);
7119 : :
7120 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7121 : : /* Do not report as an error when firmware returns ENOENT */
7122 [ # # ]: 0 : if (aq_status == I40E_AQ_RC_ENOENT) {
7123 : : ret = I40E_SUCCESS;
7124 : : } else {
7125 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7126 : 0 : goto DONE;
7127 : : }
7128 : : }
7129 : 0 : num += actual_num;
7130 [ # # ]: 0 : } while (num < total);
7131 : :
7132 : 0 : DONE:
7133 : 0 : rte_free(req_list);
7134 : 0 : return ret;
7135 : : }
7136 : :
7137 : : /* Find out specific MAC filter */
7138 : : static struct i40e_mac_filter *
7139 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7140 : : struct rte_ether_addr *macaddr)
7141 : : {
7142 : : struct i40e_mac_filter *f;
7143 : :
7144 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7145 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7146 : : return f;
7147 : : }
7148 : :
7149 : : return NULL;
7150 : : }
7151 : :
7152 : : static bool
7153 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7154 : : uint16_t vlan_id)
7155 : : {
7156 : : uint32_t vid_idx, vid_bit;
7157 : :
7158 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7159 : : return 0;
7160 : :
7161 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7162 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7163 : :
7164 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7165 : : return 1;
7166 : : else
7167 : : return 0;
7168 : : }
7169 : :
7170 : : static void
7171 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7172 : : uint16_t vlan_id, bool on)
7173 : : {
7174 : : uint32_t vid_idx, vid_bit;
7175 : :
7176 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7177 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7178 : :
7179 [ # # ]: 0 : if (on)
7180 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7181 : : else
7182 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7183 : : }
7184 : :
7185 : : void
7186 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7187 : : uint16_t vlan_id, bool on)
7188 : : {
7189 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7190 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7191 : : int ret;
7192 : :
7193 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7194 : 0 : return;
7195 : :
7196 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7197 : :
7198 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7199 : : return;
7200 : :
7201 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7202 : :
7203 [ # # ]: 0 : if (on) {
7204 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7205 : : &vlan_data, 1, NULL);
7206 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7207 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7208 : : } else {
7209 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7210 : : &vlan_data, 1, NULL);
7211 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7212 : 0 : PMD_DRV_LOG(ERR,
7213 : : "Failed to remove vlan filter");
7214 : : }
7215 : : }
7216 : :
7217 : : /**
7218 : : * Find all vlan options for specific mac addr,
7219 : : * return with actual vlan found.
7220 : : */
7221 : : int
7222 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7223 : : struct i40e_macvlan_filter *mv_f,
7224 : : int num, struct rte_ether_addr *addr)
7225 : : {
7226 : : int i;
7227 : : uint32_t j, k;
7228 : :
7229 : : /**
7230 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7231 : : * although the code looks complex.
7232 : : */
7233 [ # # ]: 0 : if (num < vsi->vlan_num)
7234 : : return I40E_ERR_PARAM;
7235 : :
7236 : : i = 0;
7237 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7238 [ # # ]: 0 : if (vsi->vfta[j]) {
7239 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7240 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7241 [ # # ]: 0 : if (i > num - 1) {
7242 : 0 : PMD_DRV_LOG(ERR,
7243 : : "vlan number doesn't match");
7244 : 0 : return I40E_ERR_PARAM;
7245 : : }
7246 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr,
7247 : : addr, ETH_ADDR_LEN);
7248 : 0 : mv_f[i].vlan_id =
7249 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7250 : 0 : i++;
7251 : : }
7252 : : }
7253 : : }
7254 : : }
7255 : : return I40E_SUCCESS;
7256 : : }
7257 : :
7258 : : static inline int
7259 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7260 : : struct i40e_macvlan_filter *mv_f,
7261 : : int num,
7262 : : uint16_t vlan)
7263 : : {
7264 : : int i = 0;
7265 : : struct i40e_mac_filter *f;
7266 : :
7267 [ # # ]: 0 : if (num < vsi->mac_num)
7268 : : return I40E_ERR_PARAM;
7269 : :
7270 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7271 [ # # ]: 0 : if (i > num - 1) {
7272 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7273 : 0 : return I40E_ERR_PARAM;
7274 : : }
7275 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7276 : : ETH_ADDR_LEN);
7277 : 0 : mv_f[i].vlan_id = vlan;
7278 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7279 : 0 : i++;
7280 : : }
7281 : :
7282 : : return I40E_SUCCESS;
7283 : : }
7284 : :
7285 : : static int
7286 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7287 : : {
7288 : : int i, j, num;
7289 : : struct i40e_mac_filter *f;
7290 : : struct i40e_macvlan_filter *mv_f;
7291 : : int ret = I40E_SUCCESS;
7292 : :
7293 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7294 : : return I40E_ERR_PARAM;
7295 : :
7296 : : /* Case that no vlan is set */
7297 [ # # ]: 0 : if (vsi->vlan_num == 0)
7298 : 0 : num = vsi->mac_num;
7299 : : else
7300 : 0 : num = vsi->mac_num * vsi->vlan_num;
7301 : :
7302 : 0 : mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
7303 [ # # ]: 0 : if (mv_f == NULL) {
7304 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7305 : 0 : return I40E_ERR_NO_MEMORY;
7306 : : }
7307 : :
7308 : : i = 0;
7309 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7310 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7311 : 0 : rte_memcpy(&mv_f[i].macaddr,
7312 [ # # ]: 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7313 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7314 : 0 : mv_f[i].vlan_id = 0;
7315 : 0 : i++;
7316 : : }
7317 : : } else {
7318 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7319 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7320 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7321 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7322 : 0 : goto DONE;
7323 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7324 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7325 : : i += vsi->vlan_num;
7326 : : }
7327 : : }
7328 : :
7329 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7330 : 0 : DONE:
7331 : 0 : rte_free(mv_f);
7332 : :
7333 : 0 : return ret;
7334 : : }
7335 : :
7336 : : int
7337 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7338 : : {
7339 : : struct i40e_macvlan_filter *mv_f;
7340 : : int mac_num;
7341 : : int ret = I40E_SUCCESS;
7342 : :
7343 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7344 : : return I40E_ERR_PARAM;
7345 : :
7346 : : /* If it's already set, just return */
7347 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7348 : : return I40E_SUCCESS;
7349 : :
7350 : 0 : mac_num = vsi->mac_num;
7351 : :
7352 [ # # ]: 0 : if (mac_num == 0) {
7353 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7354 : 0 : return I40E_ERR_PARAM;
7355 : : }
7356 : :
7357 : 0 : mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7358 : :
7359 [ # # ]: 0 : if (mv_f == NULL) {
7360 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7361 : 0 : return I40E_ERR_NO_MEMORY;
7362 : : }
7363 : :
7364 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7365 : :
7366 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7367 : 0 : goto DONE;
7368 : :
7369 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7370 : :
7371 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7372 : 0 : goto DONE;
7373 : :
7374 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7375 : :
7376 : 0 : vsi->vlan_num++;
7377 : : ret = I40E_SUCCESS;
7378 : 0 : DONE:
7379 : 0 : rte_free(mv_f);
7380 : 0 : return ret;
7381 : : }
7382 : :
7383 : : int
7384 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7385 : : {
7386 : : struct i40e_macvlan_filter *mv_f;
7387 : : int mac_num;
7388 : : int ret = I40E_SUCCESS;
7389 : :
7390 : : /**
7391 : : * Vlan 0 is the generic filter for untagged packets
7392 : : * and can't be removed.
7393 : : */
7394 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7395 : : return I40E_ERR_PARAM;
7396 : :
7397 : : /* If can't find it, just return */
7398 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7399 : : return I40E_ERR_PARAM;
7400 : :
7401 : 0 : mac_num = vsi->mac_num;
7402 : :
7403 [ # # ]: 0 : if (mac_num == 0) {
7404 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7405 : 0 : return I40E_ERR_PARAM;
7406 : : }
7407 : :
7408 : 0 : mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7409 : :
7410 [ # # ]: 0 : if (mv_f == NULL) {
7411 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7412 : 0 : return I40E_ERR_NO_MEMORY;
7413 : : }
7414 : :
7415 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7416 : :
7417 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7418 : 0 : goto DONE;
7419 : :
7420 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7421 : :
7422 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7423 : 0 : goto DONE;
7424 : :
7425 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7426 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7427 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7428 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7429 : 0 : goto DONE;
7430 : :
7431 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7432 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7433 : 0 : goto DONE;
7434 : : }
7435 : :
7436 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7437 : :
7438 : 0 : vsi->vlan_num--;
7439 : : ret = I40E_SUCCESS;
7440 : 0 : DONE:
7441 : 0 : rte_free(mv_f);
7442 : 0 : return ret;
7443 : : }
7444 : :
7445 : : int
7446 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7447 : : {
7448 : : struct i40e_mac_filter *f;
7449 : : struct i40e_macvlan_filter *mv_f;
7450 : : int i, vlan_num = 0;
7451 : : int ret = I40E_SUCCESS;
7452 : :
7453 : : /* If it's add and we've config it, return */
7454 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7455 [ # # ]: 0 : if (f != NULL)
7456 : : return I40E_SUCCESS;
7457 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7458 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7459 : :
7460 : : /**
7461 : : * If vlan_num is 0, that's the first time to add mac,
7462 : : * set mask for vlan_id 0.
7463 : : */
7464 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7465 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7466 : 0 : vsi->vlan_num = 1;
7467 : : }
7468 : 0 : vlan_num = vsi->vlan_num;
7469 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7470 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7471 : : vlan_num = 1;
7472 : :
7473 : 0 : mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7474 [ # # ]: 0 : if (mv_f == NULL) {
7475 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7476 : 0 : return I40E_ERR_NO_MEMORY;
7477 : : }
7478 : :
7479 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7480 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7481 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7482 : : ETH_ADDR_LEN);
7483 : : }
7484 : :
7485 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7486 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7487 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7488 : : &mac_filter->mac_addr);
7489 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7490 : 0 : goto DONE;
7491 : : }
7492 : :
7493 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7494 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7495 : 0 : goto DONE;
7496 : :
7497 : : /* Add the mac addr into mac list */
7498 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7499 [ # # ]: 0 : if (f == NULL) {
7500 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7501 : : ret = I40E_ERR_NO_MEMORY;
7502 : 0 : goto DONE;
7503 : : }
7504 [ # # ]: 0 : rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7505 : : ETH_ADDR_LEN);
7506 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7507 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7508 : 0 : vsi->mac_num++;
7509 : :
7510 : : ret = I40E_SUCCESS;
7511 : 0 : DONE:
7512 : 0 : rte_free(mv_f);
7513 : :
7514 : 0 : return ret;
7515 : : }
7516 : :
7517 : : int
7518 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7519 : : {
7520 : : struct i40e_mac_filter *f;
7521 : : struct i40e_macvlan_filter *mv_f;
7522 : : int i, vlan_num;
7523 : : enum i40e_mac_filter_type filter_type;
7524 : : int ret = I40E_SUCCESS;
7525 : :
7526 : : /* Can't find it, return an error */
7527 : : f = i40e_find_mac_filter(vsi, addr);
7528 [ # # ]: 0 : if (f == NULL)
7529 : : return I40E_ERR_PARAM;
7530 : :
7531 : 0 : vlan_num = vsi->vlan_num;
7532 : 0 : filter_type = f->mac_info.filter_type;
7533 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7534 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7535 [ # # ]: 0 : if (vlan_num == 0) {
7536 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7537 : 0 : return I40E_ERR_PARAM;
7538 : : }
7539 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7540 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7541 : : vlan_num = 1;
7542 : :
7543 : 0 : mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7544 [ # # ]: 0 : if (mv_f == NULL) {
7545 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7546 : 0 : return I40E_ERR_NO_MEMORY;
7547 : : }
7548 : :
7549 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7550 : 0 : mv_f[i].filter_type = filter_type;
7551 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7552 : : ETH_ADDR_LEN);
7553 : : }
7554 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7555 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7556 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7557 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7558 : 0 : goto DONE;
7559 : : }
7560 : :
7561 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7562 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7563 : 0 : goto DONE;
7564 : :
7565 : : /* Remove the mac addr into mac list */
7566 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7567 : 0 : rte_free(f);
7568 : 0 : vsi->mac_num--;
7569 : :
7570 : : ret = I40E_SUCCESS;
7571 : 0 : DONE:
7572 : 0 : rte_free(mv_f);
7573 : 0 : return ret;
7574 : : }
7575 : :
7576 : : /* Configure hash enable flags for RSS */
7577 : : uint64_t
7578 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7579 : : {
7580 : : uint64_t hena = 0;
7581 : : int i;
7582 : :
7583 [ # # ]: 0 : if (!flags)
7584 : : return hena;
7585 : :
7586 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7587 [ # # ]: 0 : if (flags & (1ULL << i))
7588 : 0 : hena |= adapter->pctypes_tbl[i];
7589 : : }
7590 : :
7591 : : return hena;
7592 : : }
7593 : :
7594 : : /* Parse the hash enable flags */
7595 : : uint64_t
7596 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7597 : : {
7598 : : uint64_t rss_hf = 0;
7599 : :
7600 [ # # ]: 0 : if (!flags)
7601 : : return rss_hf;
7602 : : int i;
7603 : :
7604 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7605 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7606 : 0 : rss_hf |= (1ULL << i);
7607 : : }
7608 : : return rss_hf;
7609 : : }
7610 : :
7611 : : /* Disable RSS */
7612 : : void
7613 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7614 : : {
7615 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7616 : :
7617 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7618 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7619 : 0 : I40E_WRITE_FLUSH(hw);
7620 : 0 : }
7621 : :
7622 : : int
7623 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7624 : : {
7625 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7626 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7627 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7628 : : I40E_VFQF_HKEY_MAX_INDEX :
7629 : : I40E_PFQF_HKEY_MAX_INDEX;
7630 : :
7631 [ # # ]: 0 : if (!key || key_len == 0) {
7632 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7633 : 0 : return 0;
7634 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7635 : : sizeof(uint32_t)) {
7636 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7637 : 0 : return -EINVAL;
7638 : : }
7639 : :
7640 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7641 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7642 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7643 : : enum i40e_status_code status =
7644 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7645 : :
7646 [ # # ]: 0 : if (status) {
7647 : 0 : PMD_DRV_LOG(ERR,
7648 : : "Failed to configure RSS key via AQ, error status: %d",
7649 : : status);
7650 : 0 : return -EIO;
7651 : : }
7652 : : } else {
7653 : : uint32_t *hash_key = (uint32_t *)key;
7654 : : uint16_t i;
7655 : :
7656 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7657 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7658 : 0 : I40E_WRITE_REG(
7659 : : hw,
7660 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7661 : : hash_key[i]);
7662 : :
7663 : : } else {
7664 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7665 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7666 : : hash_key[i]);
7667 : : }
7668 : 0 : I40E_WRITE_FLUSH(hw);
7669 : : }
7670 : :
7671 : : return 0;
7672 : : }
7673 : :
7674 : : static int
7675 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7676 : : {
7677 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7678 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7679 : : uint32_t reg;
7680 : : int ret;
7681 : :
7682 [ # # ]: 0 : if (!key || !key_len)
7683 : : return 0;
7684 : :
7685 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7686 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7687 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7688 [ # # ]: 0 : if (ret) {
7689 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7690 : 0 : return ret;
7691 : : }
7692 : : } else {
7693 : : uint32_t *key_dw = (uint32_t *)key;
7694 : : uint16_t i;
7695 : :
7696 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7697 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7698 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7699 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7700 : : }
7701 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7702 : : sizeof(uint32_t);
7703 : : } else {
7704 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7705 : 0 : reg = I40E_PFQF_HKEY(i);
7706 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7707 : : }
7708 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7709 : : sizeof(uint32_t);
7710 : : }
7711 : : }
7712 : : return 0;
7713 : : }
7714 : :
7715 : : static int
7716 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7717 : : {
7718 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7719 : : uint64_t hena;
7720 : : int ret;
7721 : :
7722 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7723 : 0 : rss_conf->rss_key_len);
7724 [ # # ]: 0 : if (ret)
7725 : : return ret;
7726 : :
7727 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7728 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7729 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7730 : 0 : I40E_WRITE_FLUSH(hw);
7731 : :
7732 : 0 : return 0;
7733 : : }
7734 : :
7735 : : static int
7736 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7737 : : struct rte_eth_rss_conf *rss_conf)
7738 : : {
7739 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7740 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7741 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7742 : : uint64_t hena;
7743 : :
7744 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7745 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7746 : :
7747 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7748 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7749 : : return -EINVAL;
7750 : 0 : return 0; /* Nothing to do */
7751 : : }
7752 : : /* RSS enabled */
7753 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7754 : : return -EINVAL;
7755 : :
7756 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7757 : : }
7758 : :
7759 : : static int
7760 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7761 : : struct rte_eth_rss_conf *rss_conf)
7762 : : {
7763 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7764 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7765 : : uint64_t hena;
7766 : : int ret;
7767 : :
7768 [ # # ]: 0 : if (!rss_conf)
7769 : : return -EINVAL;
7770 : :
7771 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7772 : : &rss_conf->rss_key_len);
7773 [ # # ]: 0 : if (ret)
7774 : : return ret;
7775 : :
7776 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7777 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7778 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7779 : :
7780 : 0 : return 0;
7781 : : }
7782 : :
7783 : : static int
7784 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7785 : : {
7786 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7787 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7788 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7789 : 0 : break;
7790 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7791 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7792 : 0 : break;
7793 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7794 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7795 : 0 : break;
7796 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7797 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7798 : 0 : break;
7799 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7800 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7801 : 0 : break;
7802 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7803 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7804 : 0 : break;
7805 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7806 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7807 : 0 : break;
7808 : 0 : default:
7809 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7810 : 0 : return -EINVAL;
7811 : : }
7812 : :
7813 : : return 0;
7814 : : }
7815 : :
7816 : : /* Convert tunnel filter structure */
7817 : : static int
7818 [ # # ]: 0 : i40e_tunnel_filter_convert(
7819 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7820 : : struct i40e_tunnel_filter *tunnel_filter)
7821 : : {
7822 : : rte_ether_addr_copy((struct rte_ether_addr *)
7823 : : &cld_filter->element.outer_mac,
7824 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7825 : : rte_ether_addr_copy((struct rte_ether_addr *)
7826 : : &cld_filter->element.inner_mac,
7827 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7828 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7829 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7830 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7831 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7832 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7833 : : else
7834 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7835 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7836 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7837 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7838 : 0 : rte_memcpy(tunnel_filter->input.general_fields,
7839 [ # # ]: 0 : cld_filter->general_fields,
7840 : : sizeof(cld_filter->general_fields));
7841 : :
7842 : 0 : return 0;
7843 : : }
7844 : :
7845 : : /* Check if there exists the tunnel filter */
7846 : : struct i40e_tunnel_filter *
7847 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7848 : : const struct i40e_tunnel_filter_input *input)
7849 : : {
7850 : : int ret;
7851 : :
7852 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7853 [ # # ]: 0 : if (ret < 0)
7854 : : return NULL;
7855 : :
7856 : 0 : return tunnel_rule->hash_map[ret];
7857 : : }
7858 : :
7859 : : /* Add a tunnel filter into the SW list */
7860 : : static int
7861 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7862 : : struct i40e_tunnel_filter *tunnel_filter)
7863 : : {
7864 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7865 : : int ret;
7866 : :
7867 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7868 [ # # ]: 0 : if (ret < 0) {
7869 : 0 : PMD_DRV_LOG(ERR,
7870 : : "Failed to insert tunnel filter to hash table %d!",
7871 : : ret);
7872 : 0 : return ret;
7873 : : }
7874 : 0 : rule->hash_map[ret] = tunnel_filter;
7875 : :
7876 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7877 : :
7878 : 0 : return 0;
7879 : : }
7880 : :
7881 : : /* Delete a tunnel filter from the SW list */
7882 : : int
7883 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7884 : : struct i40e_tunnel_filter_input *input)
7885 : : {
7886 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7887 : : struct i40e_tunnel_filter *tunnel_filter;
7888 : : int ret;
7889 : :
7890 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
7891 [ # # ]: 0 : if (ret < 0) {
7892 : 0 : PMD_DRV_LOG(ERR,
7893 : : "Failed to delete tunnel filter to hash table %d!",
7894 : : ret);
7895 : 0 : return ret;
7896 : : }
7897 : 0 : tunnel_filter = rule->hash_map[ret];
7898 : 0 : rule->hash_map[ret] = NULL;
7899 : :
7900 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7901 : 0 : rte_free(tunnel_filter);
7902 : :
7903 : 0 : return 0;
7904 : : }
7905 : :
7906 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
7907 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
7908 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
7909 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
7910 : : #define I40E_TR_GRE_KEY_MASK 0x400
7911 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
7912 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
7913 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
7914 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
7915 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
7916 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
7917 : : #define I40E_TR_L4_TYPE_TCP 0x2
7918 : : #define I40E_TR_L4_TYPE_UDP 0x4
7919 : : #define I40E_TR_L4_TYPE_SCTP 0x8
7920 : :
7921 : : static enum
7922 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
7923 : : {
7924 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7925 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7926 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7927 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
7928 : : enum i40e_status_code status = I40E_SUCCESS;
7929 : :
7930 [ # # ]: 0 : if (pf->support_multi_driver) {
7931 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7932 : 0 : return I40E_NOT_SUPPORTED;
7933 : : }
7934 : :
7935 : : memset(&filter_replace, 0,
7936 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7937 : : memset(&filter_replace_buf, 0,
7938 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7939 : :
7940 : : /* create L1 filter */
7941 : 0 : filter_replace.old_filter_type =
7942 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7943 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
7944 : : filter_replace.tr_bit = 0;
7945 : :
7946 : : /* Prepare the buffer, 3 entries */
7947 : : filter_replace_buf.data[0] =
7948 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7949 : 0 : filter_replace_buf.data[0] |=
7950 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7951 : 0 : filter_replace_buf.data[2] = 0xFF;
7952 : 0 : filter_replace_buf.data[3] = 0xFF;
7953 : : filter_replace_buf.data[4] =
7954 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7955 : 0 : filter_replace_buf.data[4] |=
7956 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7957 : 0 : filter_replace_buf.data[7] = 0xF0;
7958 : : filter_replace_buf.data[8]
7959 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
7960 : 0 : filter_replace_buf.data[8] |=
7961 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7962 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
7963 : : I40E_TR_GENEVE_KEY_MASK |
7964 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
7965 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
7966 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
7967 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
7968 : :
7969 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7970 : : &filter_replace_buf);
7971 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
7972 [ # # ]: 0 : filter_replace.new_filter_type))
7973 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
7974 : : " original: 0x%x, new: 0x%x",
7975 : : dev->device->name,
7976 : : filter_replace.old_filter_type,
7977 : : filter_replace.new_filter_type);
7978 : :
7979 : : return status;
7980 : : }
7981 : :
7982 : : static enum
7983 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
7984 : : {
7985 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7986 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7987 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7988 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
7989 : : enum i40e_status_code status = I40E_SUCCESS;
7990 : :
7991 [ # # ]: 0 : if (pf->support_multi_driver) {
7992 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
7993 : 0 : return I40E_NOT_SUPPORTED;
7994 : : }
7995 : :
7996 : : /* For MPLSoUDP */
7997 : : memset(&filter_replace, 0,
7998 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7999 : : memset(&filter_replace_buf, 0,
8000 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8001 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8002 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8003 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8004 : 0 : filter_replace.new_filter_type =
8005 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8006 : : /* Prepare the buffer, 2 entries */
8007 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8008 : 0 : filter_replace_buf.data[0] |=
8009 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8010 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8011 : 0 : filter_replace_buf.data[4] |=
8012 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8013 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8014 : : &filter_replace_buf);
8015 [ # # ]: 0 : if (status < 0)
8016 : : return status;
8017 : 0 : if (filter_replace.old_filter_type !=
8018 [ # # ]: 0 : filter_replace.new_filter_type)
8019 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8020 : : " original: 0x%x, new: 0x%x",
8021 : : dev->device->name,
8022 : : filter_replace.old_filter_type,
8023 : : filter_replace.new_filter_type);
8024 : :
8025 : : /* For MPLSoGRE */
8026 : : memset(&filter_replace, 0,
8027 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8028 : : memset(&filter_replace_buf, 0,
8029 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8030 : :
8031 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8032 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8033 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8034 : 0 : filter_replace.new_filter_type =
8035 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8036 : : /* Prepare the buffer, 2 entries */
8037 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8038 : 0 : filter_replace_buf.data[0] |=
8039 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8040 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8041 : 0 : filter_replace_buf.data[4] |=
8042 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8043 : :
8044 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8045 : : &filter_replace_buf);
8046 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8047 [ # # ]: 0 : filter_replace.new_filter_type))
8048 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8049 : : " original: 0x%x, new: 0x%x",
8050 : : dev->device->name,
8051 : : filter_replace.old_filter_type,
8052 : : filter_replace.new_filter_type);
8053 : :
8054 : : return status;
8055 : : }
8056 : :
8057 : : static enum i40e_status_code
8058 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8059 : : {
8060 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8061 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8062 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8063 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8064 : : enum i40e_status_code status = I40E_SUCCESS;
8065 : :
8066 [ # # ]: 0 : if (pf->support_multi_driver) {
8067 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8068 : 0 : return I40E_NOT_SUPPORTED;
8069 : : }
8070 : :
8071 : : /* For GTP-C */
8072 : : memset(&filter_replace, 0,
8073 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8074 : : memset(&filter_replace_buf, 0,
8075 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8076 : : /* create L1 filter */
8077 : 0 : filter_replace.old_filter_type =
8078 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8079 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8080 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8081 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8082 : : /* Prepare the buffer, 2 entries */
8083 : : filter_replace_buf.data[0] =
8084 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8085 : 0 : filter_replace_buf.data[0] |=
8086 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8087 : 0 : filter_replace_buf.data[2] = 0xFF;
8088 : 0 : filter_replace_buf.data[3] = 0xFF;
8089 : : filter_replace_buf.data[4] =
8090 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8091 : 0 : filter_replace_buf.data[4] |=
8092 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8093 : 0 : filter_replace_buf.data[6] = 0xFF;
8094 : 0 : filter_replace_buf.data[7] = 0xFF;
8095 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8096 : : &filter_replace_buf);
8097 [ # # ]: 0 : if (status < 0)
8098 : : return status;
8099 : 0 : if (filter_replace.old_filter_type !=
8100 [ # # ]: 0 : filter_replace.new_filter_type)
8101 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8102 : : " original: 0x%x, new: 0x%x",
8103 : : dev->device->name,
8104 : : filter_replace.old_filter_type,
8105 : : filter_replace.new_filter_type);
8106 : :
8107 : : /* for GTP-U */
8108 : : memset(&filter_replace, 0,
8109 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8110 : : memset(&filter_replace_buf, 0,
8111 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8112 : : /* create L1 filter */
8113 : 0 : filter_replace.old_filter_type =
8114 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8115 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8116 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8117 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8118 : : /* Prepare the buffer, 2 entries */
8119 : : filter_replace_buf.data[0] =
8120 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8121 : 0 : filter_replace_buf.data[0] |=
8122 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8123 : 0 : filter_replace_buf.data[2] = 0xFF;
8124 : 0 : filter_replace_buf.data[3] = 0xFF;
8125 : : filter_replace_buf.data[4] =
8126 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8127 : 0 : filter_replace_buf.data[4] |=
8128 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8129 : 0 : filter_replace_buf.data[6] = 0xFF;
8130 : 0 : filter_replace_buf.data[7] = 0xFF;
8131 : :
8132 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8133 : : &filter_replace_buf);
8134 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8135 [ # # ]: 0 : filter_replace.new_filter_type))
8136 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8137 : : " original: 0x%x, new: 0x%x",
8138 : : dev->device->name,
8139 : : filter_replace.old_filter_type,
8140 : : filter_replace.new_filter_type);
8141 : :
8142 : : return status;
8143 : : }
8144 : :
8145 : : static enum
8146 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8147 : : {
8148 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8149 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8150 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8151 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8152 : : enum i40e_status_code status = I40E_SUCCESS;
8153 : :
8154 [ # # ]: 0 : if (pf->support_multi_driver) {
8155 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8156 : 0 : return I40E_NOT_SUPPORTED;
8157 : : }
8158 : :
8159 : : /* for GTP-C */
8160 : : memset(&filter_replace, 0,
8161 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8162 : : memset(&filter_replace_buf, 0,
8163 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8164 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8165 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8166 : 0 : filter_replace.new_filter_type =
8167 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8168 : : /* Prepare the buffer, 2 entries */
8169 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8170 : 0 : filter_replace_buf.data[0] |=
8171 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8172 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8173 : 0 : filter_replace_buf.data[4] |=
8174 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8175 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8176 : : &filter_replace_buf);
8177 [ # # ]: 0 : if (status < 0)
8178 : : return status;
8179 : 0 : if (filter_replace.old_filter_type !=
8180 [ # # ]: 0 : filter_replace.new_filter_type)
8181 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8182 : : " original: 0x%x, new: 0x%x",
8183 : : dev->device->name,
8184 : : filter_replace.old_filter_type,
8185 : : filter_replace.new_filter_type);
8186 : :
8187 : : /* for GTP-U */
8188 : : memset(&filter_replace, 0,
8189 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8190 : : memset(&filter_replace_buf, 0,
8191 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8192 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8193 : 0 : filter_replace.old_filter_type =
8194 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8195 : 0 : filter_replace.new_filter_type =
8196 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8197 : : /* Prepare the buffer, 2 entries */
8198 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8199 : 0 : filter_replace_buf.data[0] |=
8200 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8201 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8202 : 0 : filter_replace_buf.data[4] |=
8203 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8204 : :
8205 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8206 : : &filter_replace_buf);
8207 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8208 [ # # ]: 0 : filter_replace.new_filter_type))
8209 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8210 : : " original: 0x%x, new: 0x%x",
8211 : : dev->device->name,
8212 : : filter_replace.old_filter_type,
8213 : : filter_replace.new_filter_type);
8214 : :
8215 : : return status;
8216 : : }
8217 : :
8218 : : static enum i40e_status_code
8219 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8220 : : enum i40e_l4_port_type l4_port_type)
8221 : : {
8222 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8223 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8224 : : enum i40e_status_code status = I40E_SUCCESS;
8225 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8226 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8227 : :
8228 [ # # ]: 0 : if (pf->support_multi_driver) {
8229 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8230 : 0 : return I40E_NOT_SUPPORTED;
8231 : : }
8232 : :
8233 : : memset(&filter_replace, 0,
8234 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8235 : : memset(&filter_replace_buf, 0,
8236 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8237 : :
8238 : : /* create L1 filter */
8239 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8240 : 0 : filter_replace.old_filter_type =
8241 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8242 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8243 : 0 : filter_replace_buf.data[8] =
8244 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8245 : : } else {
8246 : 0 : filter_replace.old_filter_type =
8247 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8248 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8249 : 0 : filter_replace_buf.data[8] =
8250 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8251 : : }
8252 : :
8253 : : filter_replace.tr_bit = 0;
8254 : : /* Prepare the buffer, 3 entries */
8255 : : filter_replace_buf.data[0] =
8256 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8257 : 0 : filter_replace_buf.data[0] |=
8258 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8259 : : filter_replace_buf.data[2] = 0x00;
8260 : 0 : filter_replace_buf.data[3] =
8261 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8262 : : filter_replace_buf.data[4] =
8263 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8264 : 0 : filter_replace_buf.data[4] |=
8265 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8266 : : filter_replace_buf.data[5] = 0x00;
8267 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8268 : : I40E_TR_L4_TYPE_TCP |
8269 : : I40E_TR_L4_TYPE_SCTP;
8270 : : filter_replace_buf.data[7] = 0x00;
8271 : 0 : filter_replace_buf.data[8] |=
8272 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8273 : : filter_replace_buf.data[9] = 0x00;
8274 : 0 : filter_replace_buf.data[10] = 0xFF;
8275 : 0 : filter_replace_buf.data[11] = 0xFF;
8276 : :
8277 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8278 : : &filter_replace_buf);
8279 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8280 [ # # ]: 0 : filter_replace.new_filter_type)
8281 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8282 : : " original: 0x%x, new: 0x%x",
8283 : : dev->device->name,
8284 : : filter_replace.old_filter_type,
8285 : : filter_replace.new_filter_type);
8286 : :
8287 : : return status;
8288 : : }
8289 : :
8290 : : static enum i40e_status_code
8291 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8292 : : enum i40e_l4_port_type l4_port_type)
8293 : : {
8294 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8295 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8296 : : enum i40e_status_code status = I40E_SUCCESS;
8297 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8298 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8299 : :
8300 [ # # ]: 0 : if (pf->support_multi_driver) {
8301 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8302 : 0 : return I40E_NOT_SUPPORTED;
8303 : : }
8304 : :
8305 : : memset(&filter_replace, 0,
8306 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8307 : : memset(&filter_replace_buf, 0,
8308 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8309 : :
8310 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8311 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8312 : 0 : filter_replace.new_filter_type =
8313 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8314 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8315 : : } else {
8316 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8317 : 0 : filter_replace.new_filter_type =
8318 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8319 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8320 : : }
8321 : :
8322 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8323 : : filter_replace.tr_bit = 0;
8324 : : /* Prepare the buffer, 2 entries */
8325 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8326 : 0 : filter_replace_buf.data[0] |=
8327 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8328 : 0 : filter_replace_buf.data[4] |=
8329 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8330 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8331 : : &filter_replace_buf);
8332 : :
8333 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8334 [ # # ]: 0 : filter_replace.new_filter_type)
8335 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8336 : : " original: 0x%x, new: 0x%x",
8337 : : dev->device->name,
8338 : : filter_replace.old_filter_type,
8339 : : filter_replace.new_filter_type);
8340 : :
8341 : : return status;
8342 : : }
8343 : :
8344 : : int
8345 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8346 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8347 : : uint8_t add)
8348 : : {
8349 : : uint16_t ip_type;
8350 : : uint32_t ipv4_addr, ipv4_addr_le;
8351 : : uint8_t i, tun_type = 0;
8352 : : /* internal variable to convert ipv6 byte order */
8353 : : uint32_t convert_ipv6[4];
8354 : : int val, ret = 0;
8355 : : struct i40e_pf_vf *vf = NULL;
8356 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8357 : : struct i40e_vsi *vsi;
8358 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter;
8359 : : struct i40e_aqc_cloud_filters_element_bb *pfilter;
8360 : 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8361 : : struct i40e_tunnel_filter *tunnel, *node;
8362 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8363 : : uint32_t teid_le;
8364 : : bool big_buffer = 0;
8365 : :
8366 : 0 : cld_filter = rte_zmalloc("tunnel_filter",
8367 : : sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
8368 : : 0);
8369 : :
8370 [ # # ]: 0 : if (cld_filter == NULL) {
8371 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8372 : 0 : return -ENOMEM;
8373 : : }
8374 : : pfilter = cld_filter;
8375 : :
8376 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8377 : : (struct rte_ether_addr *)&pfilter->element.outer_mac);
8378 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8379 : : (struct rte_ether_addr *)&pfilter->element.inner_mac);
8380 : :
8381 : 0 : pfilter->element.inner_vlan =
8382 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8383 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8384 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8385 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8386 : 0 : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8387 [ # # ]: 0 : rte_memcpy(&pfilter->element.ipaddr.v4.data,
8388 : : &ipv4_addr_le,
8389 : : sizeof(pfilter->element.ipaddr.v4.data));
8390 : : } else {
8391 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8392 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8393 : 0 : convert_ipv6[i] =
8394 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8395 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8396 : : }
8397 [ # # ]: 0 : rte_memcpy(&pfilter->element.ipaddr.v6.data,
8398 : : &convert_ipv6,
8399 : : sizeof(pfilter->element.ipaddr.v6.data));
8400 : : }
8401 : :
8402 : : /* check tunneled type */
8403 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8404 : : case I40E_TUNNEL_TYPE_VXLAN:
8405 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8406 : : break;
8407 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8408 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8409 : 0 : break;
8410 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8411 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8412 : 0 : break;
8413 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8414 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8415 : 0 : i40e_replace_mpls_l1_filter(pf);
8416 : 0 : i40e_replace_mpls_cloud_filter(pf);
8417 : 0 : pf->mpls_replace_flag = 1;
8418 : : }
8419 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8420 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8421 : 0 : teid_le >> 4;
8422 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8423 : 0 : (teid_le & 0xF) << 12;
8424 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8425 : : 0x40;
8426 : : big_buffer = 1;
8427 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8428 : 0 : break;
8429 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8430 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8431 : 0 : i40e_replace_mpls_l1_filter(pf);
8432 : 0 : i40e_replace_mpls_cloud_filter(pf);
8433 : 0 : pf->mpls_replace_flag = 1;
8434 : : }
8435 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8436 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8437 : 0 : teid_le >> 4;
8438 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8439 : 0 : (teid_le & 0xF) << 12;
8440 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8441 : : 0x0;
8442 : : big_buffer = 1;
8443 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8444 : 0 : break;
8445 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8446 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8447 : 0 : i40e_replace_gtp_l1_filter(pf);
8448 : 0 : i40e_replace_gtp_cloud_filter(pf);
8449 : 0 : pf->gtp_replace_flag = 1;
8450 : : }
8451 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8452 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8453 : 0 : (teid_le >> 16) & 0xFFFF;
8454 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8455 : : teid_le & 0xFFFF;
8456 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8457 : : 0x0;
8458 : : big_buffer = 1;
8459 : 0 : break;
8460 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8461 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8462 : 0 : i40e_replace_gtp_l1_filter(pf);
8463 : 0 : i40e_replace_gtp_cloud_filter(pf);
8464 : 0 : pf->gtp_replace_flag = 1;
8465 : : }
8466 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8467 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8468 : 0 : (teid_le >> 16) & 0xFFFF;
8469 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8470 : : teid_le & 0xFFFF;
8471 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8472 : : 0x0;
8473 : : big_buffer = 1;
8474 : 0 : break;
8475 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8476 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8477 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8478 [ # # ]: 0 : if (ret < 0)
8479 : 0 : PMD_DRV_LOG(DEBUG,
8480 : : "QinQ tunnel filter already created.");
8481 : 0 : pf->qinq_replace_flag = 1;
8482 : : }
8483 : : /* Add in the General fields the values of
8484 : : * the Outer and Inner VLAN
8485 : : * Big Buffer should be set, see changes in
8486 : : * i40e_aq_add_cloud_filters
8487 : : */
8488 : 0 : pfilter->general_fields[0] = tunnel_filter->inner_vlan;
8489 : 0 : pfilter->general_fields[1] = tunnel_filter->outer_vlan;
8490 : : big_buffer = 1;
8491 : 0 : break;
8492 : 0 : case I40E_CLOUD_TYPE_UDP:
8493 : : case I40E_CLOUD_TYPE_TCP:
8494 : : case I40E_CLOUD_TYPE_SCTP:
8495 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8496 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8497 : 0 : i40e_replace_port_l1_filter(pf,
8498 : : tunnel_filter->l4_port_type);
8499 : 0 : i40e_replace_port_cloud_filter(pf,
8500 : : tunnel_filter->l4_port_type);
8501 : 0 : pf->sport_replace_flag = 1;
8502 : : }
8503 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8504 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8505 : : I40E_DIRECTION_INGRESS_KEY;
8506 : :
8507 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8508 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8509 : : I40E_TR_L4_TYPE_UDP;
8510 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8511 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8512 : : I40E_TR_L4_TYPE_TCP;
8513 : : else
8514 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8515 : : I40E_TR_L4_TYPE_SCTP;
8516 : :
8517 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8518 : 0 : (teid_le >> 16) & 0xFFFF;
8519 : : big_buffer = 1;
8520 : : } else {
8521 [ # # ]: 0 : if (!pf->dport_replace_flag) {
8522 : 0 : i40e_replace_port_l1_filter(pf,
8523 : : tunnel_filter->l4_port_type);
8524 : 0 : i40e_replace_port_cloud_filter(pf,
8525 : : tunnel_filter->l4_port_type);
8526 : 0 : pf->dport_replace_flag = 1;
8527 : : }
8528 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8529 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8530 : : I40E_DIRECTION_INGRESS_KEY;
8531 : :
8532 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8533 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8534 : : I40E_TR_L4_TYPE_UDP;
8535 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8536 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8537 : : I40E_TR_L4_TYPE_TCP;
8538 : : else
8539 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8540 : : I40E_TR_L4_TYPE_SCTP;
8541 : :
8542 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8543 : 0 : (teid_le >> 16) & 0xFFFF;
8544 : : big_buffer = 1;
8545 : : }
8546 : :
8547 : : break;
8548 : 0 : default:
8549 : : /* Other tunnel types is not supported. */
8550 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8551 : 0 : rte_free(cld_filter);
8552 : 0 : return -EINVAL;
8553 : : }
8554 : :
8555 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8556 : 0 : pfilter->element.flags =
8557 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8558 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8559 : 0 : pfilter->element.flags =
8560 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8561 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8562 : 0 : pfilter->element.flags =
8563 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8564 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8565 : 0 : pfilter->element.flags =
8566 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8567 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8568 : 0 : pfilter->element.flags |=
8569 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8570 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8571 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8572 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8573 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8574 : 0 : pfilter->element.flags |=
8575 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8576 : : else
8577 : 0 : pfilter->element.flags |=
8578 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8579 : : } else {
8580 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8581 : : &pfilter->element.flags);
8582 [ # # ]: 0 : if (val < 0) {
8583 : 0 : rte_free(cld_filter);
8584 : 0 : return -EINVAL;
8585 : : }
8586 : : }
8587 : :
8588 : 0 : pfilter->element.flags |= rte_cpu_to_le_16(
8589 : : I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
8590 : : ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8591 : 0 : pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8592 : 0 : pfilter->element.queue_number =
8593 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8594 : :
8595 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8596 : 0 : vsi = pf->main_vsi;
8597 : : else {
8598 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8599 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8600 : 0 : rte_free(cld_filter);
8601 : 0 : return -EINVAL;
8602 : : }
8603 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8604 : 0 : vsi = vf->vsi;
8605 : : }
8606 : :
8607 : : /* Check if there is the filter in SW list */
8608 : : memset(&check_filter, 0, sizeof(check_filter));
8609 : 0 : i40e_tunnel_filter_convert(cld_filter, &check_filter);
8610 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8611 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8612 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8613 [ # # ]: 0 : if (add && node) {
8614 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8615 : 0 : rte_free(cld_filter);
8616 : 0 : return -EINVAL;
8617 : : }
8618 : :
8619 [ # # ]: 0 : if (!add && !node) {
8620 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8621 : 0 : rte_free(cld_filter);
8622 : 0 : return -EINVAL;
8623 : : }
8624 : :
8625 [ # # ]: 0 : if (add) {
8626 [ # # ]: 0 : if (big_buffer)
8627 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8628 : 0 : vsi->seid, cld_filter, 1);
8629 : : else
8630 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8631 : 0 : vsi->seid, &cld_filter->element, 1);
8632 [ # # ]: 0 : if (ret < 0) {
8633 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8634 : 0 : rte_free(cld_filter);
8635 : 0 : return -ENOTSUP;
8636 : : }
8637 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8638 [ # # ]: 0 : if (tunnel == NULL) {
8639 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8640 : 0 : rte_free(cld_filter);
8641 : 0 : return -ENOMEM;
8642 : : }
8643 : :
8644 : : rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8645 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8646 [ # # ]: 0 : if (ret < 0)
8647 : 0 : rte_free(tunnel);
8648 : : } else {
8649 [ # # ]: 0 : if (big_buffer)
8650 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8651 : 0 : hw, vsi->seid, cld_filter, 1);
8652 : : else
8653 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8654 : : &cld_filter->element, 1);
8655 [ # # ]: 0 : if (ret < 0) {
8656 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8657 : 0 : rte_free(cld_filter);
8658 : 0 : return -ENOTSUP;
8659 : : }
8660 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8661 : : }
8662 : :
8663 : 0 : rte_free(cld_filter);
8664 : 0 : return ret;
8665 : : }
8666 : :
8667 : : static int
8668 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8669 : : {
8670 : : uint8_t i;
8671 : :
8672 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8673 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8674 : : return i;
8675 : : }
8676 : :
8677 : : return -1;
8678 : : }
8679 : :
8680 : : static int
8681 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8682 : : {
8683 : : int idx, ret;
8684 : 0 : uint8_t filter_idx = 0;
8685 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8686 : :
8687 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8688 : :
8689 : : /* Check if port already exists */
8690 [ # # ]: 0 : if (idx >= 0) {
8691 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8692 : 0 : return -EINVAL;
8693 : : }
8694 : :
8695 : : /* Now check if there is space to add the new port */
8696 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8697 [ # # ]: 0 : if (idx < 0) {
8698 : 0 : PMD_DRV_LOG(ERR,
8699 : : "Maximum number of UDP ports reached, not adding port %d",
8700 : : port);
8701 : 0 : return -ENOSPC;
8702 : : }
8703 : :
8704 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8705 : : &filter_idx, NULL);
8706 [ # # ]: 0 : if (ret < 0) {
8707 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8708 : 0 : return -1;
8709 : : }
8710 : :
8711 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8712 : : port, filter_idx);
8713 : :
8714 : : /* New port: add it and mark its index in the bitmap */
8715 : 0 : pf->vxlan_ports[idx] = port;
8716 : 0 : pf->vxlan_bitmap |= (1 << idx);
8717 : :
8718 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8719 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8720 : :
8721 : : return 0;
8722 : : }
8723 : :
8724 : : static int
8725 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8726 : : {
8727 : : int idx;
8728 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8729 : :
8730 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8731 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8732 : 0 : return -EINVAL;
8733 : : }
8734 : :
8735 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8736 : :
8737 [ # # ]: 0 : if (idx < 0) {
8738 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8739 : 0 : return -EINVAL;
8740 : : }
8741 : :
8742 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8743 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8744 : 0 : return -1;
8745 : : }
8746 : :
8747 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8748 : : port, idx);
8749 : :
8750 : 0 : pf->vxlan_ports[idx] = 0;
8751 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8752 : :
8753 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8754 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8755 : :
8756 : : return 0;
8757 : : }
8758 : :
8759 : : /* Add UDP tunneling port */
8760 : : static int
8761 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8762 : : struct rte_eth_udp_tunnel *udp_tunnel)
8763 : : {
8764 : : int ret = 0;
8765 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8766 : :
8767 [ # # ]: 0 : if (udp_tunnel == NULL)
8768 : : return -EINVAL;
8769 : :
8770 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8771 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8772 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8773 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8774 : 0 : break;
8775 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8776 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8777 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8778 : 0 : break;
8779 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8780 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8781 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8782 : : ret = -1;
8783 : 0 : break;
8784 : :
8785 : 0 : default:
8786 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8787 : : ret = -1;
8788 : 0 : break;
8789 : : }
8790 : :
8791 : : return ret;
8792 : : }
8793 : :
8794 : : /* Remove UDP tunneling port */
8795 : : static int
8796 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8797 : : struct rte_eth_udp_tunnel *udp_tunnel)
8798 : : {
8799 : : int ret = 0;
8800 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8801 : :
8802 [ # # ]: 0 : if (udp_tunnel == NULL)
8803 : : return -EINVAL;
8804 : :
8805 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8806 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8807 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8808 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8809 : 0 : break;
8810 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8811 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8812 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8813 : : ret = -1;
8814 : 0 : break;
8815 : 0 : default:
8816 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8817 : : ret = -1;
8818 : 0 : break;
8819 : : }
8820 : :
8821 : : return ret;
8822 : : }
8823 : :
8824 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8825 : : int
8826 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8827 : : {
8828 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8829 : : int i, num;
8830 : : struct i40e_rx_queue *rxq;
8831 : :
8832 : : num = 0;
8833 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8834 : 0 : rxq = data->rx_queues[i];
8835 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8836 : 0 : num++;
8837 : : else
8838 : : break;
8839 : : }
8840 : :
8841 : 0 : return num;
8842 : : }
8843 : :
8844 : : /* Reset the global configure of hash function and input sets */
8845 : : static void
8846 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8847 : : {
8848 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8849 : : uint32_t reg, reg_val;
8850 : : int i;
8851 : :
8852 : : /* Reset global RSS function sets */
8853 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8854 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8855 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8856 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8857 : : }
8858 : :
8859 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8860 : : uint64_t inset;
8861 : : int j, pctype;
8862 : :
8863 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
8864 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8865 : : else
8866 : : pctype = i;
8867 : :
8868 : : /* Reset pctype insets */
8869 : 0 : inset = i40e_get_default_input_set(i);
8870 [ # # ]: 0 : if (inset) {
8871 : 0 : pf->hash_input_set[pctype] = inset;
8872 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
8873 : : inset);
8874 : :
8875 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
8876 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
8877 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
8878 : 0 : i40e_check_write_global_reg(hw, reg,
8879 : 0 : (uint32_t)(inset >> 32));
8880 : :
8881 : : /* Clear unused mask registers of the pctype */
8882 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
8883 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
8884 : 0 : i40e_check_write_global_reg(hw, reg, 0);
8885 : : }
8886 : : }
8887 : :
8888 : : /* Reset pctype symmetric sets */
8889 : 0 : reg = I40E_GLQF_HSYM(pctype);
8890 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
8891 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8892 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
8893 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
8894 : : }
8895 : : }
8896 : 0 : I40E_WRITE_FLUSH(hw);
8897 : 0 : }
8898 : :
8899 : : int
8900 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
8901 : : {
8902 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
8903 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
8904 : : uint32_t i;
8905 : : int num;
8906 : :
8907 : : /* If both VMDQ and RSS enabled, not all of PF queues are
8908 : : * configured. It's necessary to calculate the actual PF
8909 : : * queues that are configured.
8910 : : */
8911 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
8912 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
8913 : : else
8914 : 0 : num = pf->dev_data->nb_rx_queues;
8915 : :
8916 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8917 [ # # ]: 0 : if (num <= 0)
8918 : : return 0;
8919 : :
8920 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
8921 : 0 : lut[i] = (uint8_t)(i % (uint32_t)num);
8922 : :
8923 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
8924 : : }
8925 : :
8926 : : int
8927 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
8928 : : {
8929 : : const uint8_t key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8930 : : sizeof(uint32_t);
8931 : : uint8_t *rss_key;
8932 : :
8933 : : /* Reset key */
8934 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
8935 [ # # ]: 0 : if (!rss_key ||
8936 [ # # ]: 0 : pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < key_len) {
8937 : : static uint32_t rss_key_default[] = {0x6b793944,
8938 : : 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8939 : : 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8940 : : 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8941 : :
8942 : : rss_key = (uint8_t *)rss_key_default;
8943 : : }
8944 : :
8945 : 0 : return i40e_set_rss_key(pf->main_vsi, rss_key, key_len);
8946 : : }
8947 : :
8948 : : static int
8949 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
8950 : : {
8951 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8952 : :
8953 : : int ret;
8954 : :
8955 : 0 : pf->hash_filter_enabled = 0;
8956 : 0 : i40e_pf_disable_rss(pf);
8957 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
8958 : :
8959 [ # # ]: 0 : if (!pf->support_multi_driver)
8960 : 0 : i40e_pf_global_rss_reset(pf);
8961 : :
8962 : : /* Reset RETA table */
8963 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
8964 : 0 : ret = i40e_pf_reset_rss_reta(pf);
8965 [ # # ]: 0 : if (ret)
8966 : : return ret;
8967 : : }
8968 : :
8969 : 0 : return i40e_pf_reset_rss_key(pf);
8970 : : }
8971 : :
8972 : : /* Configure RSS */
8973 : : int
8974 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
8975 : : {
8976 : : struct i40e_hw *hw;
8977 : : enum rte_eth_rx_mq_mode mq_mode;
8978 : : uint64_t rss_hf, hena;
8979 : : int ret;
8980 : :
8981 : 0 : ret = i40e_pf_rss_reset(pf);
8982 [ # # ]: 0 : if (ret) {
8983 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
8984 : 0 : return ret;
8985 : : }
8986 : :
8987 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
8988 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
8989 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
8990 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
8991 : : return 0;
8992 : :
8993 : 0 : hw = I40E_PF_TO_HW(pf);
8994 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
8995 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
8996 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
8997 : 0 : I40E_WRITE_FLUSH(hw);
8998 : :
8999 : 0 : return 0;
9000 : : }
9001 : :
9002 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9003 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9004 : : int
9005 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9006 : : {
9007 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9008 : : uint32_t val, reg;
9009 : : int ret = -EINVAL;
9010 : :
9011 [ # # ]: 0 : if (pf->support_multi_driver) {
9012 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9013 : 0 : return -ENOTSUP;
9014 : : }
9015 : :
9016 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9017 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9018 : :
9019 [ # # ]: 0 : if (len == 3) {
9020 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9021 [ # # ]: 0 : } else if (len == 4) {
9022 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9023 : : } else {
9024 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9025 : 0 : return ret;
9026 : : }
9027 : :
9028 [ # # ]: 0 : if (reg != val) {
9029 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9030 : : I40E_GL_PRS_FVBM(2),
9031 : : reg, NULL);
9032 [ # # ]: 0 : if (ret != 0)
9033 : : return ret;
9034 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9035 : : "with value 0x%08x",
9036 : : I40E_GL_PRS_FVBM(2), reg);
9037 : : } else {
9038 : : ret = 0;
9039 : : }
9040 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9041 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9042 : :
9043 : 0 : return ret;
9044 : : }
9045 : :
9046 : : /* Set the symmetric hash enable configurations per port */
9047 : : void
9048 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9049 : : {
9050 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9051 : :
9052 [ # # ]: 0 : if (enable > 0) {
9053 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9054 : : return;
9055 : :
9056 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9057 : : } else {
9058 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9059 : : return;
9060 : :
9061 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9062 : : }
9063 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9064 : 0 : I40E_WRITE_FLUSH(hw);
9065 : : }
9066 : :
9067 : : /**
9068 : : * Valid input sets for hash and flow director filters per PCTYPE
9069 : : */
9070 : : static uint64_t
9071 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9072 : : enum rte_filter_type filter)
9073 : : {
9074 : : uint64_t valid;
9075 : :
9076 : : static const uint64_t valid_hash_inset_table[] = {
9077 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9078 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9079 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9080 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9081 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9082 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9083 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9084 : : I40E_INSET_FLEX_PAYLOAD,
9085 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9086 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9087 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9088 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9089 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9090 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9091 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9092 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9093 : : I40E_INSET_FLEX_PAYLOAD,
9094 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9095 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9096 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9097 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9098 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9099 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9100 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9101 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9102 : : I40E_INSET_FLEX_PAYLOAD,
9103 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9104 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9105 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9106 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9107 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9108 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9109 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9110 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9111 : : I40E_INSET_FLEX_PAYLOAD,
9112 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9113 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9114 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9115 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9116 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9117 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9118 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9119 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9120 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9121 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9122 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9123 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9124 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9125 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9126 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9127 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9128 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9129 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9130 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9131 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9132 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9133 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9134 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9135 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9136 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9137 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9138 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9139 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9140 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9141 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9142 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9143 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9144 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9145 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9146 : : I40E_INSET_FLEX_PAYLOAD,
9147 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9148 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9149 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9150 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9151 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9152 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9153 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9154 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9155 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9156 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9157 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9158 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9159 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9160 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9161 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9162 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9163 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9164 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9165 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9166 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9167 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9168 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9169 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9170 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9171 : : I40E_INSET_FLEX_PAYLOAD,
9172 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9173 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9174 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9175 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9176 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9177 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9178 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9179 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9180 : : I40E_INSET_FLEX_PAYLOAD,
9181 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9182 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9183 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9184 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9185 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9186 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9187 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9188 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9189 : : I40E_INSET_FLEX_PAYLOAD,
9190 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9191 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9192 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9193 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9194 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9195 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9196 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9197 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9198 : : I40E_INSET_FLEX_PAYLOAD,
9199 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9200 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9201 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9202 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9203 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9204 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9205 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9206 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9207 : : I40E_INSET_FLEX_PAYLOAD,
9208 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9209 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9210 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9211 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9212 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9213 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9214 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9215 : : I40E_INSET_FLEX_PAYLOAD,
9216 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9217 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9218 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9219 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9220 : : I40E_INSET_FLEX_PAYLOAD,
9221 : : };
9222 : :
9223 : : /**
9224 : : * Flow director supports only fields defined in
9225 : : * union rte_eth_fdir_flow.
9226 : : */
9227 : : static const uint64_t valid_fdir_inset_table[] = {
9228 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9229 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9230 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9231 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9232 : : I40E_INSET_IPV4_TTL,
9233 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9234 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9235 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9236 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9237 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9238 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9239 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9240 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9241 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9242 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9243 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9244 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9245 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9246 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9247 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9248 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9249 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9250 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9251 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9252 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9253 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9254 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9255 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9256 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9257 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9258 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9259 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9260 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9261 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9262 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9263 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9264 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9265 : : I40E_INSET_SCTP_VT,
9266 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9267 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9268 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9269 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9270 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9271 : : I40E_INSET_IPV4_TTL,
9272 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9273 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9274 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9275 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9276 : : I40E_INSET_IPV6_HOP_LIMIT,
9277 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9278 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9279 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9280 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9281 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9282 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9283 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9284 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9285 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9286 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9287 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9288 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9289 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9290 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9291 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9292 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9293 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9294 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9295 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9296 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9297 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9298 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9299 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9300 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9301 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9302 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9303 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9304 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9305 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9306 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9307 : : I40E_INSET_SCTP_VT,
9308 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9309 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9310 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9311 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9312 : : I40E_INSET_IPV6_HOP_LIMIT,
9313 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9314 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9315 : : I40E_INSET_LAST_ETHER_TYPE,
9316 : : };
9317 : :
9318 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9319 : : return 0;
9320 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9321 : 0 : valid = valid_hash_inset_table[pctype];
9322 : : else
9323 : 0 : valid = valid_fdir_inset_table[pctype];
9324 : :
9325 : : return valid;
9326 : : }
9327 : :
9328 : : /**
9329 : : * Validate if the input set is allowed for a specific PCTYPE
9330 : : */
9331 : : int
9332 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9333 : : enum rte_filter_type filter, uint64_t inset)
9334 : : {
9335 : : uint64_t valid;
9336 : :
9337 : : valid = i40e_get_valid_input_set(pctype, filter);
9338 [ # # ]: 0 : if (inset & (~valid))
9339 : 0 : return -EINVAL;
9340 : :
9341 : : return 0;
9342 : : }
9343 : :
9344 : : /* default input set fields combination per pctype */
9345 : : uint64_t
9346 : 0 : i40e_get_default_input_set(uint16_t pctype)
9347 : : {
9348 : : static const uint64_t default_inset_table[] = {
9349 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9350 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9351 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9352 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9353 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9354 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9355 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9356 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9357 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9358 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9359 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9360 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9361 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9362 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9363 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9364 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9365 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9366 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9367 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9368 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9369 : : I40E_INSET_SCTP_VT,
9370 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9371 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9372 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9373 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9374 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9375 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9376 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9377 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9378 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9379 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9380 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9381 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9382 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9383 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9384 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9385 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9386 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9387 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9388 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9389 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9390 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9391 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9392 : : I40E_INSET_SCTP_VT,
9393 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9394 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9395 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9396 : : I40E_INSET_LAST_ETHER_TYPE,
9397 : : };
9398 : :
9399 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9400 : : return 0;
9401 : :
9402 : 0 : return default_inset_table[pctype];
9403 : : }
9404 : :
9405 : : /**
9406 : : * Translate the input set from bit masks to register aware bit masks
9407 : : * and vice versa
9408 : : */
9409 : : uint64_t
9410 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9411 : : {
9412 : : uint64_t val = 0;
9413 : : uint16_t i;
9414 : :
9415 : : struct inset_map {
9416 : : uint64_t inset;
9417 : : uint64_t inset_reg;
9418 : : };
9419 : :
9420 : : static const struct inset_map inset_map_common[] = {
9421 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9422 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9423 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9424 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9425 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9426 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9427 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9428 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9429 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9430 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9431 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9432 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9433 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9434 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9435 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9436 : : {I40E_INSET_TUNNEL_DMAC,
9437 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9438 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9439 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9440 : : {I40E_INSET_TUNNEL_SRC_PORT,
9441 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9442 : : {I40E_INSET_TUNNEL_DST_PORT,
9443 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9444 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9445 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9446 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9447 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9448 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9449 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9450 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9451 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9452 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9453 : : };
9454 : :
9455 : : /* some different registers map in x722*/
9456 : : static const struct inset_map inset_map_diff_x722[] = {
9457 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9458 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9459 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9460 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9461 : : };
9462 : :
9463 : : static const struct inset_map inset_map_diff_not_x722[] = {
9464 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9465 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9466 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9467 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9468 : : };
9469 : :
9470 [ # # ]: 0 : if (input == 0)
9471 : : return val;
9472 : :
9473 : : /* Translate input set to register aware inset */
9474 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9475 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9476 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9477 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9478 : : }
9479 : : } else {
9480 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9481 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9482 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9483 : : }
9484 : : }
9485 : :
9486 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9487 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9488 : 0 : val |= inset_map_common[i].inset_reg;
9489 : : }
9490 : :
9491 : : return val;
9492 : : }
9493 : :
9494 : : static int
9495 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9496 : : uint32_t pit_reg_count, uint32_t hdr_off)
9497 : : {
9498 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9499 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9500 : : uint32_t i, reg_val, src_off, count;
9501 : :
9502 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9503 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9504 : :
9505 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9506 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9507 : :
9508 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9509 : : break;
9510 : : }
9511 : :
9512 [ # # ]: 0 : if (i >= pit_reg_end) {
9513 : 0 : PMD_DRV_LOG(ERR,
9514 : : "Hardware GLQF_PIT configuration does not support this field mask");
9515 : 0 : return -1;
9516 : : }
9517 : :
9518 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9519 : : }
9520 : :
9521 : : int
9522 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9523 : : uint32_t *mask, uint8_t nb_elem)
9524 : : {
9525 : : static const uint64_t mask_inset[] = {
9526 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9527 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9528 : :
9529 : : static const struct {
9530 : : uint64_t inset;
9531 : : uint32_t mask;
9532 : : uint32_t offset;
9533 : : } inset_mask_offset_map[] = {
9534 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9535 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9536 : :
9537 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9538 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9539 : :
9540 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9541 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9542 : :
9543 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9544 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9545 : :
9546 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9547 : : offsetof(struct rte_ipv6_hdr, proto) },
9548 : :
9549 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9550 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9551 : : };
9552 : :
9553 : : uint32_t i;
9554 : : int idx = 0;
9555 : :
9556 [ # # ]: 0 : assert(mask);
9557 [ # # ]: 0 : if (!inset)
9558 : : return 0;
9559 : :
9560 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9561 : : /* Clear the inset bit, if no MASK is required,
9562 : : * for example proto + ttl
9563 : : */
9564 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9565 : 0 : inset &= ~mask_inset[i];
9566 [ # # ]: 0 : if (!inset)
9567 : : return 0;
9568 : : }
9569 : : }
9570 : :
9571 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9572 : : uint32_t pit_start, pit_count;
9573 : : int offset;
9574 : :
9575 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9576 : 0 : continue;
9577 : :
9578 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9579 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9580 : : I40E_INSET_IPV4_TTL)) {
9581 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9582 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9583 : : } else {
9584 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9585 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9586 : : }
9587 : :
9588 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9589 : 0 : inset_mask_offset_map[i].offset);
9590 : :
9591 [ # # ]: 0 : if (offset < 0)
9592 : : return -EINVAL;
9593 : :
9594 [ # # ]: 0 : if (idx >= nb_elem) {
9595 : 0 : PMD_DRV_LOG(ERR,
9596 : : "Configuration of inset mask out of range %u",
9597 : : nb_elem);
9598 : 0 : return -ERANGE;
9599 : : }
9600 : :
9601 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9602 : : inset_mask_offset_map[i].mask);
9603 : 0 : idx++;
9604 : : }
9605 : :
9606 : : return idx;
9607 : : }
9608 : :
9609 : : void
9610 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9611 : : {
9612 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9613 : :
9614 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9615 [ # # ]: 0 : if (reg != val)
9616 : 0 : i40e_write_rx_ctl(hw, addr, val);
9617 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9618 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9619 : 0 : }
9620 : :
9621 : : void
9622 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9623 : : {
9624 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9625 : 0 : struct rte_eth_dev_data *dev_data =
9626 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9627 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9628 : :
9629 [ # # ]: 0 : if (reg != val) {
9630 : 0 : i40e_write_rx_ctl(hw, addr, val);
9631 : 0 : PMD_DRV_LOG(WARNING,
9632 : : "i40e device %s changed global register [0x%08x]."
9633 : : " original: 0x%08x, new: 0x%08x",
9634 : : dev->device->name, addr, reg,
9635 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9636 : : }
9637 : 0 : }
9638 : :
9639 : : static void
9640 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9641 : : {
9642 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9643 : : enum i40e_filter_pctype pctype;
9644 : : uint64_t input_set, inset_reg;
9645 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9646 : : int num, i;
9647 : : uint16_t flow_type;
9648 : :
9649 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9650 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9651 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9652 : :
9653 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9654 : 0 : continue;
9655 : :
9656 : 0 : input_set = i40e_get_default_input_set(pctype);
9657 : :
9658 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9659 : : I40E_INSET_MASK_NUM_REG);
9660 [ # # ]: 0 : if (num < 0)
9661 : 0 : return;
9662 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9663 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9664 : 0 : return;
9665 : : }
9666 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9667 : : input_set);
9668 : :
9669 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9670 : : (uint32_t)(inset_reg & UINT32_MAX));
9671 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9672 : 0 : (uint32_t)((inset_reg >>
9673 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9674 [ # # ]: 0 : if (!pf->support_multi_driver) {
9675 : 0 : i40e_check_write_global_reg(hw,
9676 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9677 : : (uint32_t)(inset_reg & UINT32_MAX));
9678 : 0 : i40e_check_write_global_reg(hw,
9679 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9680 : : (uint32_t)((inset_reg >>
9681 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9682 : :
9683 [ # # ]: 0 : for (i = 0; i < num; i++) {
9684 : 0 : i40e_check_write_global_reg(hw,
9685 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9686 : : mask_reg[i]);
9687 : 0 : i40e_check_write_global_reg(hw,
9688 : : I40E_GLQF_HASH_MSK(i, pctype),
9689 : : mask_reg[i]);
9690 : : }
9691 : : /*clear unused mask registers of the pctype */
9692 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9693 : 0 : i40e_check_write_global_reg(hw,
9694 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9695 : : 0);
9696 : 0 : i40e_check_write_global_reg(hw,
9697 : : I40E_GLQF_HASH_MSK(i, pctype),
9698 : : 0);
9699 : : }
9700 : : } else {
9701 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9702 : : }
9703 : 0 : I40E_WRITE_FLUSH(hw);
9704 : :
9705 : : /* store the default input set */
9706 [ # # ]: 0 : if (!pf->support_multi_driver)
9707 : 0 : pf->hash_input_set[pctype] = input_set;
9708 : 0 : pf->fdir.input_set[pctype] = input_set;
9709 : : }
9710 : : }
9711 : :
9712 : : int
9713 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9714 : : uint32_t pctype, bool add)
9715 : : {
9716 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9717 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9718 : : uint64_t inset_reg = 0;
9719 : : int num, i;
9720 : :
9721 [ # # ]: 0 : if (pf->support_multi_driver) {
9722 : 0 : PMD_DRV_LOG(ERR,
9723 : : "Modify input set is not permitted when multi-driver enabled.");
9724 : 0 : return -EPERM;
9725 : : }
9726 : :
9727 : : /* For X722, get translated pctype in fd pctype register */
9728 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9729 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9730 : :
9731 [ # # ]: 0 : if (add) {
9732 : : /* get inset value in register */
9733 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9734 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9735 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9736 : 0 : input_set |= pf->hash_input_set[pctype];
9737 : : }
9738 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9739 : : I40E_INSET_MASK_NUM_REG);
9740 [ # # ]: 0 : if (num < 0)
9741 : : return -EINVAL;
9742 : :
9743 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9744 : :
9745 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9746 : : (uint32_t)(inset_reg & UINT32_MAX));
9747 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9748 : 0 : (uint32_t)((inset_reg >>
9749 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9750 : :
9751 [ # # ]: 0 : for (i = 0; i < num; i++)
9752 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9753 : : mask_reg[i]);
9754 : : /*clear unused mask registers of the pctype */
9755 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9756 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9757 : : 0);
9758 : 0 : I40E_WRITE_FLUSH(hw);
9759 : :
9760 : 0 : pf->hash_input_set[pctype] = input_set;
9761 : 0 : return 0;
9762 : : }
9763 : :
9764 : : /* Convert ethertype filter structure */
9765 : : static int
9766 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9767 : : struct i40e_ethertype_filter *filter)
9768 : : {
9769 [ # # ]: 0 : rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
9770 : : RTE_ETHER_ADDR_LEN);
9771 : 0 : filter->input.ether_type = input->ether_type;
9772 : 0 : filter->flags = input->flags;
9773 : 0 : filter->queue = input->queue;
9774 : :
9775 : : return 0;
9776 : : }
9777 : :
9778 : : /* Check if there exists the ethertype filter */
9779 : : struct i40e_ethertype_filter *
9780 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9781 : : const struct i40e_ethertype_filter_input *input)
9782 : : {
9783 : : int ret;
9784 : :
9785 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9786 [ # # ]: 0 : if (ret < 0)
9787 : : return NULL;
9788 : :
9789 : 0 : return ethertype_rule->hash_map[ret];
9790 : : }
9791 : :
9792 : : /* Add ethertype filter in SW list */
9793 : : static int
9794 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9795 : : struct i40e_ethertype_filter *filter)
9796 : : {
9797 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9798 : : int ret;
9799 : :
9800 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9801 [ # # ]: 0 : if (ret < 0) {
9802 : 0 : PMD_DRV_LOG(ERR,
9803 : : "Failed to insert ethertype filter"
9804 : : " to hash table %d!",
9805 : : ret);
9806 : 0 : return ret;
9807 : : }
9808 : 0 : rule->hash_map[ret] = filter;
9809 : :
9810 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9811 : :
9812 : 0 : return 0;
9813 : : }
9814 : :
9815 : : /* Delete ethertype filter in SW list */
9816 : : int
9817 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9818 : : struct i40e_ethertype_filter_input *input)
9819 : : {
9820 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9821 : : struct i40e_ethertype_filter *filter;
9822 : : int ret;
9823 : :
9824 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9825 [ # # ]: 0 : if (ret < 0) {
9826 : 0 : PMD_DRV_LOG(ERR,
9827 : : "Failed to delete ethertype filter"
9828 : : " to hash table %d!",
9829 : : ret);
9830 : 0 : return ret;
9831 : : }
9832 : 0 : filter = rule->hash_map[ret];
9833 : 0 : rule->hash_map[ret] = NULL;
9834 : :
9835 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9836 : 0 : rte_free(filter);
9837 : :
9838 : 0 : return 0;
9839 : : }
9840 : :
9841 : : /*
9842 : : * Configure ethertype filter, which can director packet by filtering
9843 : : * with mac address and ether_type or only ether_type
9844 : : */
9845 : : int
9846 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9847 : : struct rte_eth_ethertype_filter *filter,
9848 : : bool add)
9849 : : {
9850 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9851 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9852 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9853 : : struct i40e_ethertype_filter check_filter;
9854 : : struct i40e_control_filter_stats stats;
9855 : : uint16_t flags = 0;
9856 : : int ret;
9857 : :
9858 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9859 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9860 : 0 : return -EINVAL;
9861 : : }
9862 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9863 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9864 : 0 : PMD_DRV_LOG(ERR,
9865 : : "unsupported ether_type(0x%04x) in control packet filter.",
9866 : : filter->ether_type);
9867 : 0 : return -EINVAL;
9868 : : }
9869 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
9870 : 0 : PMD_DRV_LOG(WARNING,
9871 : : "filter vlan ether_type in first tag is not supported.");
9872 : :
9873 : : /* Check if there is the filter in SW list */
9874 : : memset(&check_filter, 0, sizeof(check_filter));
9875 : : i40e_ethertype_filter_convert(filter, &check_filter);
9876 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9877 : : &check_filter.input);
9878 [ # # ]: 0 : if (add && node) {
9879 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9880 : 0 : return -EINVAL;
9881 : : }
9882 : :
9883 [ # # ]: 0 : if (!add && !node) {
9884 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9885 : 0 : return -EINVAL;
9886 : : }
9887 : :
9888 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9889 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9890 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9891 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9892 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9893 : :
9894 : : memset(&stats, 0, sizeof(stats));
9895 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
9896 : 0 : filter->mac_addr.addr_bytes,
9897 : 0 : filter->ether_type, flags,
9898 : 0 : pf->main_vsi->seid,
9899 : 0 : filter->queue, add, &stats, NULL);
9900 : :
9901 : 0 : PMD_DRV_LOG(INFO,
9902 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
9903 : : ret, stats.mac_etype_used, stats.etype_used,
9904 : : stats.mac_etype_free, stats.etype_free);
9905 [ # # ]: 0 : if (ret < 0)
9906 : : return -ENOSYS;
9907 : :
9908 : : /* Add or delete a filter in SW list */
9909 [ # # ]: 0 : if (add) {
9910 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
9911 : : sizeof(*ethertype_filter), 0);
9912 [ # # ]: 0 : if (ethertype_filter == NULL) {
9913 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
9914 : 0 : return -ENOMEM;
9915 : : }
9916 : :
9917 : : rte_memcpy(ethertype_filter, &check_filter,
9918 : : sizeof(check_filter));
9919 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
9920 [ # # ]: 0 : if (ret < 0)
9921 : 0 : rte_free(ethertype_filter);
9922 : : } else {
9923 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
9924 : : }
9925 : :
9926 : : return ret;
9927 : : }
9928 : :
9929 : : static int
9930 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
9931 : : const struct rte_flow_ops **ops)
9932 : : {
9933 [ # # ]: 0 : if (dev == NULL)
9934 : : return -EINVAL;
9935 : :
9936 : 0 : *ops = &i40e_flow_ops;
9937 : 0 : return 0;
9938 : : }
9939 : :
9940 : : /*
9941 : : * Check and enable Extended Tag.
9942 : : * Enabling Extended Tag is important for 40G performance.
9943 : : */
9944 : : static void
9945 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
9946 : : {
9947 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
9948 : 0 : uint32_t buf = 0;
9949 : : int ret;
9950 : :
9951 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9952 : : PCI_DEV_CAP_REG);
9953 [ # # ]: 0 : if (ret < 0) {
9954 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9955 : : PCI_DEV_CAP_REG);
9956 : 0 : return;
9957 : : }
9958 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
9959 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
9960 : 0 : return;
9961 : : }
9962 : :
9963 : 0 : buf = 0;
9964 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9965 : : PCI_DEV_CTRL_REG);
9966 [ # # ]: 0 : if (ret < 0) {
9967 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9968 : : PCI_DEV_CTRL_REG);
9969 : 0 : return;
9970 : : }
9971 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
9972 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
9973 : 0 : return;
9974 : : }
9975 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
9976 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
9977 : : PCI_DEV_CTRL_REG);
9978 [ # # ]: 0 : if (ret < 0) {
9979 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
9980 : : PCI_DEV_CTRL_REG);
9981 : 0 : return;
9982 : : }
9983 : : }
9984 : :
9985 : : /*
9986 : : * As some registers wouldn't be reset unless a global hardware reset,
9987 : : * hardware initialization is needed to put those registers into an
9988 : : * expected initial state.
9989 : : */
9990 : : static void
9991 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
9992 : : {
9993 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9994 : :
9995 : 0 : i40e_enable_extended_tag(dev);
9996 : :
9997 : : /* clear the PF Queue Filter control register */
9998 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
9999 : :
10000 : : /* Disable symmetric hash per port */
10001 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10002 : 0 : }
10003 : :
10004 : : /*
10005 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10006 : : * however this function will return only one highest pctype index,
10007 : : * which is not quite correct. This is known problem of i40e driver
10008 : : * and needs to be fixed later.
10009 : : */
10010 : : enum i40e_filter_pctype
10011 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10012 : : {
10013 : : int i;
10014 : : uint64_t pctype_mask;
10015 : :
10016 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10017 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10018 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10019 [ # # ]: 0 : if (pctype_mask & (1ULL << i))
10020 : 0 : return (enum i40e_filter_pctype)i;
10021 : : }
10022 : : }
10023 : : return I40E_FILTER_PCTYPE_INVALID;
10024 : : }
10025 : :
10026 : : uint16_t
10027 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10028 : : enum i40e_filter_pctype pctype)
10029 : : {
10030 : : uint16_t flowtype;
10031 : 0 : uint64_t pctype_mask = 1ULL << pctype;
10032 : :
10033 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10034 : 0 : flowtype++) {
10035 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10036 : 0 : return flowtype;
10037 : : }
10038 : :
10039 : : return RTE_ETH_FLOW_UNKNOWN;
10040 : : }
10041 : :
10042 : : /*
10043 : : * On X710, performance number is far from the expectation on recent firmware
10044 : : * versions; on XL710, performance number is also far from the expectation on
10045 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10046 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10047 : : * address. The fix for this issue may not be integrated in the following
10048 : : * firmware version. So the workaround in software driver is needed. It needs
10049 : : * to modify the initial values of 3 internal only registers for both X710 and
10050 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10051 : : * workaround can be removed when it is fixed in firmware in the future.
10052 : : */
10053 : :
10054 : : /* For both X710 and XL710 */
10055 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10056 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10057 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10058 : :
10059 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10060 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10061 : :
10062 : : /* For X722 */
10063 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10064 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10065 : :
10066 : : /* For X710 */
10067 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10068 : : /* For XL710 */
10069 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10070 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10071 : :
10072 : : /*
10073 : : * GL_SWR_PM_UP_THR:
10074 : : * The value is not impacted from the link speed, its value is set according
10075 : : * to the total number of ports for a better pipe-monitor configuration.
10076 : : */
10077 : : static bool
10078 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10079 : : {
10080 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10081 : : .device_id = (dev), \
10082 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10083 : :
10084 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10085 : : .device_id = (dev), \
10086 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10087 : :
10088 : : static const struct {
10089 : : uint16_t device_id;
10090 : : uint32_t val;
10091 : : } swr_pm_table[] = {
10092 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10093 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10094 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10095 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10096 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10097 : :
10098 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10099 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10100 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10101 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10102 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10103 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10104 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10105 : : };
10106 : : uint32_t i;
10107 : :
10108 [ # # ]: 0 : if (value == NULL) {
10109 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10110 : 0 : return false;
10111 : : }
10112 : :
10113 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10114 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10115 : 0 : *value = swr_pm_table[i].val;
10116 : :
10117 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10118 : : "value - 0x%08x",
10119 : : hw->device_id, *value);
10120 : 0 : return true;
10121 : : }
10122 : : }
10123 : :
10124 : : return false;
10125 : : }
10126 : :
10127 : : static int
10128 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10129 : : {
10130 : : enum i40e_status_code status;
10131 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10132 : : int ret = -ENOTSUP;
10133 : : int retries = 0;
10134 : :
10135 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10136 : : NULL);
10137 : :
10138 [ # # ]: 0 : while (status) {
10139 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10140 : : status);
10141 : 0 : retries++;
10142 : 0 : rte_delay_us(100000);
10143 [ # # ]: 0 : if (retries < 5)
10144 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10145 : : true, &phy_ab, NULL);
10146 : : else
10147 : : return ret;
10148 : : }
10149 : : return 0;
10150 : : }
10151 : :
10152 : : static void
10153 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10154 : : {
10155 : : static struct {
10156 : : uint32_t addr;
10157 : : uint64_t val;
10158 : : } reg_table[] = {
10159 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10160 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10161 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10162 : : };
10163 : : uint64_t reg;
10164 : : uint32_t i;
10165 : : int ret;
10166 : :
10167 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10168 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10169 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10170 : 0 : reg_table[i].val =
10171 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10172 : : else /* For X710/XL710/XXV710 */
10173 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10174 : 0 : reg_table[i].val =
10175 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10176 : : else
10177 : 0 : reg_table[i].val =
10178 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10179 : : }
10180 : :
10181 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10182 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10183 : 0 : reg_table[i].val =
10184 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10185 : : else /* For X710/XL710/XXV710 */
10186 : 0 : reg_table[i].val =
10187 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10188 : : }
10189 : :
10190 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10191 : : uint32_t cfg_val;
10192 : :
10193 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10194 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10195 : : "GL_SWR_PM_UP_THR value fixup",
10196 : : hw->device_id);
10197 : 0 : continue;
10198 : : }
10199 : :
10200 : 0 : reg_table[i].val = cfg_val;
10201 : : }
10202 : :
10203 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10204 : : ®, NULL);
10205 [ # # ]: 0 : if (ret < 0) {
10206 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10207 : : reg_table[i].addr);
10208 : 0 : break;
10209 : : }
10210 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10211 : : reg_table[i].addr, reg);
10212 [ # # ]: 0 : if (reg == reg_table[i].val)
10213 : 0 : continue;
10214 : :
10215 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10216 : : reg_table[i].val, NULL);
10217 [ # # ]: 0 : if (ret < 0) {
10218 : 0 : PMD_DRV_LOG(ERR,
10219 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10220 : : reg_table[i].val, reg_table[i].addr);
10221 : 0 : break;
10222 : : }
10223 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10224 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10225 : : }
10226 : 0 : }
10227 : :
10228 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10229 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10230 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10231 : : static int
10232 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10233 : : {
10234 : : uint32_t reg;
10235 : : int ret;
10236 : :
10237 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10238 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10239 : 0 : return -EINVAL;
10240 : : }
10241 : :
10242 : : /* Configure for double VLAN RX stripping */
10243 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10244 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10245 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10246 : 0 : ret = i40e_aq_debug_write_register(hw,
10247 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10248 : : reg, NULL);
10249 [ # # ]: 0 : if (ret < 0) {
10250 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10251 : : vsi->vsi_id);
10252 : 0 : return I40E_ERR_CONFIG;
10253 : : }
10254 : : }
10255 : :
10256 : : /* Configure for double VLAN TX insertion */
10257 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10258 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10259 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10260 : 0 : ret = i40e_aq_debug_write_register(hw,
10261 : 0 : I40E_VSI_L2TAGSTXVALID(
10262 : : vsi->vsi_id), reg, NULL);
10263 [ # # ]: 0 : if (ret < 0) {
10264 : 0 : PMD_DRV_LOG(ERR,
10265 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10266 : : vsi->vsi_id);
10267 : 0 : return I40E_ERR_CONFIG;
10268 : : }
10269 : : }
10270 : :
10271 : : return 0;
10272 : : }
10273 : :
10274 : : static uint64_t
10275 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10276 : : {
10277 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10278 : : uint64_t systim_cycles;
10279 : :
10280 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10281 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10282 [ # # ]: 0 : << 32;
10283 : :
10284 : : return systim_cycles;
10285 : : }
10286 : :
10287 : : static uint64_t
10288 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10289 : : {
10290 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10291 : : uint64_t rx_tstamp;
10292 : :
10293 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10294 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10295 [ # # ]: 0 : << 32;
10296 : :
10297 : : return rx_tstamp;
10298 : : }
10299 : :
10300 : : static uint64_t
10301 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10302 : : {
10303 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10304 : : uint64_t tx_tstamp;
10305 : :
10306 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10307 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10308 [ # # ]: 0 : << 32;
10309 : :
10310 : : return tx_tstamp;
10311 : : }
10312 : :
10313 : : static void
10314 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10315 : : {
10316 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10317 : : struct i40e_adapter *adapter = dev->data->dev_private;
10318 : : struct rte_eth_link link;
10319 : : uint32_t tsync_inc_l;
10320 : : uint32_t tsync_inc_h;
10321 : :
10322 : : /* Get current link speed. */
10323 : 0 : i40e_dev_link_update(dev, 1);
10324 : : rte_eth_linkstatus_get(dev, &link);
10325 : :
10326 [ # # # # ]: 0 : switch (link.link_speed) {
10327 : : case RTE_ETH_SPEED_NUM_40G:
10328 : : case RTE_ETH_SPEED_NUM_25G:
10329 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10330 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10331 : : break;
10332 : 0 : case RTE_ETH_SPEED_NUM_10G:
10333 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10334 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10335 : 0 : break;
10336 : 0 : case RTE_ETH_SPEED_NUM_1G:
10337 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10338 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10339 : 0 : break;
10340 : 0 : default:
10341 : : tsync_inc_l = 0x0;
10342 : : tsync_inc_h = 0x0;
10343 : : }
10344 : :
10345 : : /* Set the timesync increment value. */
10346 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10347 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10348 : :
10349 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10350 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10351 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10352 : :
10353 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10354 : : adapter->systime_tc.cc_shift = 0;
10355 : : adapter->systime_tc.nsec_mask = 0;
10356 : :
10357 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10358 : : adapter->rx_tstamp_tc.cc_shift = 0;
10359 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10360 : :
10361 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10362 : : adapter->tx_tstamp_tc.cc_shift = 0;
10363 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10364 : 0 : }
10365 : :
10366 : : static int
10367 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10368 : : {
10369 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10370 : :
10371 : 0 : adapter->systime_tc.nsec += delta;
10372 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10373 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10374 : :
10375 : 0 : return 0;
10376 : : }
10377 : :
10378 : : static int
10379 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10380 : : {
10381 : : uint64_t ns;
10382 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10383 : :
10384 : : ns = rte_timespec_to_ns(ts);
10385 : :
10386 : : /* Set the timecounters to a new value. */
10387 : 0 : adapter->systime_tc.nsec = ns;
10388 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10389 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10390 : :
10391 : 0 : return 0;
10392 : : }
10393 : :
10394 : : static int
10395 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10396 : : {
10397 : : uint64_t ns, systime_cycles;
10398 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10399 : :
10400 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10401 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10402 : 0 : *ts = rte_ns_to_timespec(ns);
10403 : :
10404 : 0 : return 0;
10405 : : }
10406 : :
10407 : : static int
10408 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10409 : : {
10410 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10411 : : uint32_t tsync_ctl_l;
10412 : : uint32_t tsync_ctl_h;
10413 : :
10414 : : /* Stop the timesync system time. */
10415 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10416 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10417 : : /* Reset the timesync system time value. */
10418 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10419 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10420 : :
10421 : 0 : i40e_start_timecounters(dev);
10422 : :
10423 : : /* Clear timesync registers. */
10424 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10425 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10426 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10427 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10428 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10429 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10430 : :
10431 : : /* Enable timestamping of PTP packets. */
10432 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10433 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10434 : :
10435 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10436 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10437 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10438 : :
10439 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10440 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10441 : :
10442 : 0 : return 0;
10443 : : }
10444 : :
10445 : : static int
10446 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10447 : : {
10448 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10449 : : uint32_t tsync_ctl_l;
10450 : : uint32_t tsync_ctl_h;
10451 : :
10452 : : /* Disable timestamping of transmitted PTP packets. */
10453 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10454 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10455 : :
10456 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10457 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10458 : :
10459 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10460 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10461 : :
10462 : : /* Reset the timesync increment value. */
10463 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10464 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10465 : :
10466 : 0 : return 0;
10467 : : }
10468 : :
10469 : : static int
10470 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10471 : : struct timespec *timestamp, uint32_t flags)
10472 : : {
10473 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10474 : : struct i40e_adapter *adapter = dev->data->dev_private;
10475 : : uint32_t sync_status;
10476 : 0 : uint32_t index = flags & 0x03;
10477 : : uint64_t rx_tstamp_cycles;
10478 : : uint64_t ns;
10479 : :
10480 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10481 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10482 : : return -EINVAL;
10483 : :
10484 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10485 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10486 : 0 : *timestamp = rte_ns_to_timespec(ns);
10487 : :
10488 : 0 : return 0;
10489 : : }
10490 : :
10491 : : static int
10492 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10493 : : struct timespec *timestamp)
10494 : : {
10495 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10496 : : struct i40e_adapter *adapter = dev->data->dev_private;
10497 : : uint32_t sync_status;
10498 : : uint64_t tx_tstamp_cycles;
10499 : : uint64_t ns;
10500 : :
10501 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10502 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10503 : : return -EINVAL;
10504 : :
10505 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10506 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10507 : 0 : *timestamp = rte_ns_to_timespec(ns);
10508 : :
10509 : 0 : return 0;
10510 : : }
10511 : :
10512 : : /*
10513 : : * i40e_parse_dcb_configure - parse dcb configure from user
10514 : : * @dev: the device being configured
10515 : : * @dcb_cfg: pointer of the result of parse
10516 : : * @*tc_map: bit map of enabled traffic classes
10517 : : *
10518 : : * Returns 0 on success, negative value on failure
10519 : : */
10520 : : static int
10521 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10522 : : struct i40e_dcbx_config *dcb_cfg,
10523 : : uint8_t *tc_map)
10524 : : {
10525 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10526 : : uint8_t i, tc_bw, bw_lf;
10527 : :
10528 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10529 : :
10530 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10531 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10532 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10533 : 0 : return -EINVAL;
10534 : : }
10535 : :
10536 : : /* assume each tc has the same bw */
10537 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10538 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10539 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10540 : : /* to ensure the sum of tcbw is equal to 100 */
10541 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10542 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10543 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10544 : :
10545 : : /* assume each tc has the same Transmission Selection Algorithm */
10546 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10547 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10548 : :
10549 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10550 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10551 : 0 : dcb_rx_conf->dcb_tc[i];
10552 : :
10553 : : /* FW needs one App to configure HW */
10554 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10555 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10556 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10557 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10558 : :
10559 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10560 : 0 : *tc_map = 1; /* tc0 only */
10561 : : else
10562 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10563 : :
10564 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10565 : 0 : dcb_cfg->pfc.willing = 0;
10566 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10567 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10568 : : }
10569 : : return 0;
10570 : : }
10571 : :
10572 : :
10573 : : static enum i40e_status_code
10574 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10575 : : struct i40e_aqc_vsi_properties_data *info,
10576 : : uint8_t enabled_tcmap)
10577 : : {
10578 : : enum i40e_status_code ret;
10579 : : int i, total_tc = 0;
10580 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10581 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10582 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10583 : : uint16_t used_queues;
10584 : :
10585 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10586 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10587 : : return ret;
10588 : :
10589 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10590 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10591 : 0 : total_tc++;
10592 : : }
10593 [ # # ]: 0 : if (total_tc == 0)
10594 : : total_tc = 1;
10595 : 0 : vsi->enabled_tc = enabled_tcmap;
10596 : :
10597 : : /* different VSI has different queues assigned */
10598 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10599 : 0 : used_queues = dev_data->nb_rx_queues -
10600 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10601 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10602 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10603 : : else {
10604 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10605 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10606 : : }
10607 : :
10608 : 0 : qpnum_per_tc = used_queues / total_tc;
10609 : : /* Number of queues per enabled TC */
10610 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10611 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10612 : 0 : return I40E_ERR_INVALID_QP_ID;
10613 : : }
10614 : 0 : qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
10615 : : I40E_MAX_Q_PER_TC);
10616 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10617 : :
10618 : : /**
10619 : : * Configure TC and queue mapping parameters, for enabled TC,
10620 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10621 : : * default queue will serve it.
10622 : : */
10623 : : qp_idx = 0;
10624 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10625 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10626 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10627 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10628 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10629 : 0 : qp_idx += qpnum_per_tc;
10630 : : } else
10631 : 0 : info->tc_mapping[i] = 0;
10632 : : }
10633 : :
10634 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10635 : : if (vsi->type == I40E_VSI_SRIOV) {
10636 : : info->mapping_flags |=
10637 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10638 : : for (i = 0; i < vsi->nb_qps; i++)
10639 : : info->queue_mapping[i] =
10640 : : rte_cpu_to_le_16(vsi->base_queue + i);
10641 : : } else {
10642 : 0 : info->mapping_flags |=
10643 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10644 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10645 : : }
10646 : 0 : info->valid_sections |=
10647 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10648 : :
10649 : 0 : return I40E_SUCCESS;
10650 : : }
10651 : :
10652 : : /*
10653 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10654 : : * @veb: VEB to be configured
10655 : : * @tc_map: enabled TC bitmap
10656 : : *
10657 : : * Returns 0 on success, negative value on failure
10658 : : */
10659 : : static enum i40e_status_code
10660 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10661 : : {
10662 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10663 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10664 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10665 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10666 : : enum i40e_status_code ret = I40E_SUCCESS;
10667 : : int i;
10668 : : uint32_t bw_max;
10669 : :
10670 : : /* Check if enabled_tc is same as existing or new TCs */
10671 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10672 : : return ret;
10673 : :
10674 : : /* configure tc bandwidth */
10675 : : memset(&veb_bw, 0, sizeof(veb_bw));
10676 : 0 : veb_bw.tc_valid_bits = tc_map;
10677 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10678 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10679 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10680 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10681 : : }
10682 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10683 : : &veb_bw, NULL);
10684 [ # # ]: 0 : if (ret) {
10685 : 0 : PMD_INIT_LOG(ERR,
10686 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10687 : : hw->aq.asq_last_status);
10688 : 0 : return ret;
10689 : : }
10690 : :
10691 : : memset(&ets_query, 0, sizeof(ets_query));
10692 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10693 : : &ets_query, NULL);
10694 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10695 : 0 : PMD_DRV_LOG(ERR,
10696 : : "Failed to get switch_comp ETS configuration %u",
10697 : : hw->aq.asq_last_status);
10698 : 0 : return ret;
10699 : : }
10700 : : memset(&bw_query, 0, sizeof(bw_query));
10701 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10702 : : &bw_query, NULL);
10703 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10704 : 0 : PMD_DRV_LOG(ERR,
10705 : : "Failed to get switch_comp bandwidth configuration %u",
10706 : : hw->aq.asq_last_status);
10707 : 0 : return ret;
10708 : : }
10709 : :
10710 : : /* store and print out BW info */
10711 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10712 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10713 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10714 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10715 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10716 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10717 : : I40E_16_BIT_WIDTH);
10718 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10719 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10720 : 0 : bw_query.tc_bw_share_credits[i];
10721 : 0 : veb->bw_info.bw_ets_credits[i] =
10722 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10723 : : /* 4 bits per TC, 4th bit is reserved */
10724 : 0 : veb->bw_info.bw_ets_max[i] =
10725 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10726 : : RTE_LEN2MASK(3, uint8_t));
10727 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10728 : : veb->bw_info.bw_ets_share_credits[i]);
10729 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10730 : : veb->bw_info.bw_ets_credits[i]);
10731 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10732 : : veb->bw_info.bw_ets_max[i]);
10733 : : }
10734 : :
10735 : 0 : veb->enabled_tc = tc_map;
10736 : :
10737 : 0 : return ret;
10738 : : }
10739 : :
10740 : :
10741 : : /*
10742 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10743 : : * @vsi: VSI to be configured
10744 : : * @tc_map: enabled TC bitmap
10745 : : *
10746 : : * Returns 0 on success, negative value on failure
10747 : : */
10748 : : static enum i40e_status_code
10749 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10750 : : {
10751 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10752 : : struct i40e_vsi_context ctxt;
10753 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10754 : : enum i40e_status_code ret = I40E_SUCCESS;
10755 : : int i;
10756 : :
10757 : : /* Check if enabled_tc is same as existing or new TCs */
10758 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10759 : : return ret;
10760 : :
10761 : : /* configure tc bandwidth */
10762 : : memset(&bw_data, 0, sizeof(bw_data));
10763 : 0 : bw_data.tc_valid_bits = tc_map;
10764 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10765 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10766 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10767 : 0 : bw_data.tc_bw_credits[i] = 1;
10768 : : }
10769 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10770 [ # # ]: 0 : if (ret) {
10771 : 0 : PMD_INIT_LOG(ERR,
10772 : : "AQ command Config VSI BW allocation per TC failed = %d",
10773 : : hw->aq.asq_last_status);
10774 : 0 : goto out;
10775 : : }
10776 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10777 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10778 : :
10779 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10780 : 0 : ctxt.seid = vsi->seid;
10781 : 0 : ctxt.pf_num = hw->pf_id;
10782 : 0 : ctxt.vf_num = 0;
10783 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10784 : 0 : ctxt.info = vsi->info;
10785 : 0 : i40e_get_cap(hw);
10786 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10787 [ # # ]: 0 : if (ret)
10788 : 0 : goto out;
10789 : :
10790 : : /* Update the VSI after updating the VSI queue-mapping information */
10791 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10792 [ # # ]: 0 : if (ret) {
10793 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10794 : : hw->aq.asq_last_status);
10795 : 0 : goto out;
10796 : : }
10797 : : /* update the local VSI info with updated queue map */
10798 : : rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10799 : : sizeof(vsi->info.tc_mapping));
10800 : : rte_memcpy(&vsi->info.queue_mapping,
10801 : : &ctxt.info.queue_mapping,
10802 : : sizeof(vsi->info.queue_mapping));
10803 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10804 : 0 : vsi->info.valid_sections = 0;
10805 : :
10806 : : /* query and update current VSI BW information */
10807 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10808 [ # # ]: 0 : if (ret) {
10809 : 0 : PMD_INIT_LOG(ERR,
10810 : : "Failed updating vsi bw info, err %s aq_err %s",
10811 : : i40e_stat_str(hw, ret),
10812 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10813 : 0 : goto out;
10814 : : }
10815 : :
10816 : 0 : vsi->enabled_tc = tc_map;
10817 : :
10818 : : out:
10819 : : return ret;
10820 : : }
10821 : :
10822 : : /*
10823 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10824 : : * @pf: pf the configuration is taken on
10825 : : * @new_cfg: new configuration
10826 : : * @tc_map: enabled TC bitmap
10827 : : *
10828 : : * Returns 0 on success, negative value on failure
10829 : : */
10830 : : static enum i40e_status_code
10831 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10832 : : struct i40e_dcbx_config *new_cfg,
10833 : : uint8_t tc_map)
10834 : : {
10835 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10836 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10837 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10838 : : struct i40e_vsi_list *vsi_list;
10839 : : enum i40e_status_code ret;
10840 : : int i;
10841 : : uint32_t val;
10842 : :
10843 : : /* Use the FW API if FW > v4.4*/
10844 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10845 : : (hw->aq.fw_maj_ver >= 5))) {
10846 : 0 : PMD_INIT_LOG(ERR,
10847 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10848 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10849 : : }
10850 : :
10851 : : /* Check if need reconfiguration */
10852 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10853 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10854 : 0 : return I40E_SUCCESS;
10855 : : }
10856 : :
10857 : : /* Copy the new config to the current config */
10858 : 0 : *old_cfg = *new_cfg;
10859 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10860 : 0 : ret = i40e_set_dcb_config(hw);
10861 [ # # ]: 0 : if (ret) {
10862 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10863 : : i40e_stat_str(hw, ret),
10864 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10865 : 0 : return ret;
10866 : : }
10867 : : /* set receive Arbiter to RR mode and ETS scheme by default */
10868 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10869 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10870 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10871 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10872 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10873 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10874 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10875 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10876 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10877 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10878 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10879 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10880 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10881 : : }
10882 : : /* get local mib to check whether it is configured correctly */
10883 : : /* IEEE mode */
10884 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10885 : : /* Get Local DCB Config */
10886 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10887 : : &hw->local_dcbx_config);
10888 : :
10889 : : /* if Veb is created, need to update TC of it at first */
10890 [ # # ]: 0 : if (main_vsi->veb) {
10891 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
10892 [ # # ]: 0 : if (ret)
10893 : 0 : PMD_INIT_LOG(WARNING,
10894 : : "Failed configuring TC for VEB seid=%d",
10895 : : main_vsi->veb->seid);
10896 : : }
10897 : : /* Update each VSI */
10898 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
10899 [ # # ]: 0 : if (main_vsi->veb) {
10900 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
10901 : : /* Beside main VSI and VMDQ VSIs, only enable default
10902 : : * TC for other VSIs
10903 : : */
10904 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
10905 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
10906 : : tc_map);
10907 : : else
10908 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
10909 : : I40E_DEFAULT_TCMAP);
10910 [ # # ]: 0 : if (ret)
10911 : 0 : PMD_INIT_LOG(WARNING,
10912 : : "Failed configuring TC for VSI seid=%d",
10913 : : vsi_list->vsi->seid);
10914 : : /* continue */
10915 : : }
10916 : : }
10917 : : return I40E_SUCCESS;
10918 : : }
10919 : :
10920 : : /*
10921 : : * i40e_dcb_init_configure - initial dcb config
10922 : : * @dev: device being configured
10923 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
10924 : : *
10925 : : * Returns 0 on success, negative value on failure
10926 : : */
10927 : : int
10928 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
10929 : : {
10930 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10931 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10932 : : int i, ret = 0;
10933 : :
10934 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
10935 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
10936 : 0 : return -ENOTSUP;
10937 : : }
10938 : :
10939 : : /* DCB initialization:
10940 : : * Update DCB configuration from the Firmware and configure
10941 : : * LLDP MIB change event.
10942 : : */
10943 [ # # ]: 0 : if (sw_dcb == TRUE) {
10944 : : /* Stopping lldp is necessary for DPDK, but it will cause
10945 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
10946 : : * for successful initialization of DCB is that LLDP is
10947 : : * enabled. So it is needed to start lldp before DCB init
10948 : : * and stop it after initialization.
10949 : : */
10950 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
10951 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10952 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
10953 : :
10954 : 0 : ret = i40e_init_dcb(hw, true);
10955 : : /* If lldp agent is stopped, the return value from
10956 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
10957 : : * adminq status. Otherwise, it should return success.
10958 : : */
10959 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
10960 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
10961 : 0 : memset(&hw->local_dcbx_config, 0,
10962 : : sizeof(struct i40e_dcbx_config));
10963 : : /* set dcb default configuration */
10964 : : hw->local_dcbx_config.etscfg.willing = 0;
10965 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
10966 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
10967 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
10968 : : I40E_IEEE_TSA_ETS;
10969 : : /* all UPs mapping to TC0 */
10970 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10971 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
10972 : 0 : hw->local_dcbx_config.etsrec =
10973 : : hw->local_dcbx_config.etscfg;
10974 : : hw->local_dcbx_config.pfc.willing = 0;
10975 : 0 : hw->local_dcbx_config.pfc.pfccap =
10976 : : I40E_MAX_TRAFFIC_CLASS;
10977 : : /* FW needs one App to configure HW */
10978 : 0 : hw->local_dcbx_config.numapps = 1;
10979 : 0 : hw->local_dcbx_config.app[0].selector =
10980 : : I40E_APP_SEL_ETHTYPE;
10981 : 0 : hw->local_dcbx_config.app[0].priority = 3;
10982 : 0 : hw->local_dcbx_config.app[0].protocolid =
10983 : : I40E_APP_PROTOID_FCOE;
10984 : 0 : ret = i40e_set_dcb_config(hw);
10985 [ # # ]: 0 : if (ret) {
10986 : 0 : PMD_INIT_LOG(ERR,
10987 : : "default dcb config fails. err = %d, aq_err = %d.",
10988 : : ret, hw->aq.asq_last_status);
10989 : 0 : return -ENOSYS;
10990 : : }
10991 : : } else {
10992 : 0 : PMD_INIT_LOG(ERR,
10993 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
10994 : : ret, hw->aq.asq_last_status);
10995 : 0 : return -ENOTSUP;
10996 : : }
10997 : :
10998 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
10999 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11000 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11001 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11002 : : }
11003 : : } else {
11004 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11005 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11006 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11007 : :
11008 : 0 : ret = i40e_init_dcb(hw, true);
11009 [ # # ]: 0 : if (!ret) {
11010 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11011 : 0 : PMD_INIT_LOG(ERR,
11012 : : "HW doesn't support DCBX offload.");
11013 : 0 : return -ENOTSUP;
11014 : : }
11015 : : } else {
11016 : 0 : PMD_INIT_LOG(ERR,
11017 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11018 : : ret, hw->aq.asq_last_status);
11019 : 0 : return -ENOTSUP;
11020 : : }
11021 : : }
11022 : : return 0;
11023 : : }
11024 : :
11025 : : /*
11026 : : * i40e_dcb_setup - setup dcb related config
11027 : : * @dev: device being configured
11028 : : *
11029 : : * Returns 0 on success, negative value on failure
11030 : : */
11031 : : static int
11032 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11033 : : {
11034 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11035 : : struct i40e_dcbx_config dcb_cfg;
11036 : 0 : uint8_t tc_map = 0;
11037 : : int ret = 0;
11038 : :
11039 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11040 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11041 : 0 : return -ENOTSUP;
11042 : : }
11043 : :
11044 [ # # ]: 0 : if (pf->vf_num != 0)
11045 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11046 : :
11047 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11048 [ # # ]: 0 : if (ret) {
11049 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11050 : 0 : return -EINVAL;
11051 : : }
11052 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11053 [ # # ]: 0 : if (ret) {
11054 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11055 : 0 : return -ENOSYS;
11056 : : }
11057 : :
11058 : : return 0;
11059 : : }
11060 : :
11061 : : static int
11062 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11063 : : struct rte_eth_dcb_info *dcb_info)
11064 : : {
11065 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11066 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11067 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11068 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11069 : : uint16_t bsf, tc_mapping;
11070 : : int i, j = 0;
11071 : :
11072 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11073 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11074 : : else
11075 : 0 : dcb_info->nb_tcs = 1;
11076 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11077 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11078 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11079 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11080 : :
11081 : : /* get queue mapping if vmdq is disabled */
11082 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11083 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11084 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11085 : 0 : continue;
11086 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11087 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11088 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11089 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11090 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11091 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11092 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11093 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11094 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11095 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11096 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11097 : : }
11098 : : return 0;
11099 : : }
11100 : :
11101 : : /* get queue mapping if vmdq is enabled */
11102 : : do {
11103 : 0 : vsi = pf->vmdq[j].vsi;
11104 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11105 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11106 : 0 : continue;
11107 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11108 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11109 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11110 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11111 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11112 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11113 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11114 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11115 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11116 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11117 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11118 : : }
11119 : 0 : j++;
11120 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11121 : : return 0;
11122 : : }
11123 : :
11124 : : static int
11125 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11126 : : {
11127 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11128 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11129 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11130 : : uint16_t msix_intr;
11131 : :
11132 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11133 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11134 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11135 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11136 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11137 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11138 : : else
11139 : 0 : I40E_WRITE_REG(hw,
11140 : : I40E_PFINT_DYN_CTLN(msix_intr -
11141 : : I40E_RX_VEC_START),
11142 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11143 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11144 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11145 : :
11146 : 0 : I40E_WRITE_FLUSH(hw);
11147 : 0 : rte_intr_ack(pci_dev->intr_handle);
11148 : :
11149 : 0 : return 0;
11150 : : }
11151 : :
11152 : : static int
11153 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11154 : : {
11155 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11156 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11157 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11158 : : uint16_t msix_intr;
11159 : :
11160 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11161 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11162 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11163 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11164 : : else
11165 : 0 : I40E_WRITE_REG(hw,
11166 : : I40E_PFINT_DYN_CTLN(msix_intr -
11167 : : I40E_RX_VEC_START),
11168 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11169 : 0 : I40E_WRITE_FLUSH(hw);
11170 : :
11171 : 0 : return 0;
11172 : : }
11173 : :
11174 : : /**
11175 : : * This function is used to check if the register is valid.
11176 : : * Below is the valid registers list for X722 only:
11177 : : * 0x2b800--0x2bb00
11178 : : * 0x38700--0x38a00
11179 : : * 0x3d800--0x3db00
11180 : : * 0x208e00--0x209000
11181 : : * 0x20be00--0x20c000
11182 : : * 0x263c00--0x264000
11183 : : * 0x265c00--0x266000
11184 : : */
11185 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11186 : : {
11187 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11188 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11189 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11190 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11191 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11192 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11193 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11194 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11195 : : return 0;
11196 : : else
11197 : 0 : return 1;
11198 : : }
11199 : :
11200 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11201 : : struct rte_dev_reg_info *regs)
11202 : : {
11203 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11204 : 0 : uint32_t *ptr_data = regs->data;
11205 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11206 : : const struct i40e_reg_info *reg_info;
11207 : :
11208 [ # # ]: 0 : if (ptr_data == NULL) {
11209 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11210 : 0 : regs->width = sizeof(uint32_t);
11211 : 0 : return 0;
11212 : : }
11213 : :
11214 : : /* The first few registers have to be read using AQ operations */
11215 : : reg_idx = 0;
11216 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11217 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11218 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11219 : : for (arr_idx2 = 0;
11220 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11221 : 0 : arr_idx2++) {
11222 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11223 : 0 : arr_idx2 * reg_info->stride2;
11224 : 0 : reg_offset += reg_info->base_addr;
11225 : 0 : ptr_data[reg_offset >> 2] =
11226 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11227 : : }
11228 : : }
11229 : :
11230 : : /* The remaining registers can be read using primitives */
11231 : : reg_idx = 0;
11232 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11233 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11234 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11235 : : for (arr_idx2 = 0;
11236 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11237 : 0 : arr_idx2++) {
11238 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11239 : 0 : arr_idx2 * reg_info->stride2;
11240 : 0 : reg_offset += reg_info->base_addr;
11241 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11242 : 0 : ptr_data[reg_offset >> 2] = 0;
11243 : : else
11244 : 0 : ptr_data[reg_offset >> 2] =
11245 : 0 : I40E_READ_REG(hw, reg_offset);
11246 : : }
11247 : : }
11248 : :
11249 : : return 0;
11250 : : }
11251 : :
11252 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11253 : : {
11254 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11255 : :
11256 : : /* Convert word count to byte count */
11257 : 0 : return hw->nvm.sr_size << 1;
11258 : : }
11259 : :
11260 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11261 : : struct rte_dev_eeprom_info *eeprom)
11262 : : {
11263 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11264 : 0 : uint16_t *data = eeprom->data;
11265 : : uint16_t offset, length, cnt_words;
11266 : : int ret_code;
11267 : :
11268 : 0 : offset = eeprom->offset >> 1;
11269 : 0 : length = eeprom->length >> 1;
11270 : 0 : cnt_words = length;
11271 : :
11272 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11273 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11274 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11275 : 0 : return -EINVAL;
11276 : : }
11277 : :
11278 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11279 : :
11280 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11281 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11282 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11283 : 0 : return -EIO;
11284 : : }
11285 : :
11286 : : return 0;
11287 : : }
11288 : :
11289 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11290 : : struct rte_eth_dev_module_info *modinfo)
11291 : : {
11292 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11293 : 0 : uint32_t sff8472_comp = 0;
11294 : 0 : uint32_t sff8472_swap = 0;
11295 : 0 : uint32_t sff8636_rev = 0;
11296 : : i40e_status status;
11297 : : uint32_t type = 0;
11298 : :
11299 : : /* Check if firmware supports reading module EEPROM. */
11300 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11301 : 0 : PMD_DRV_LOG(ERR,
11302 : : "Module EEPROM memory read not supported. "
11303 : : "Please update the NVM image.\n");
11304 : 0 : return -EINVAL;
11305 : : }
11306 : :
11307 : 0 : status = i40e_update_link_info(hw);
11308 [ # # ]: 0 : if (status)
11309 : : return -EIO;
11310 : :
11311 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11312 : 0 : PMD_DRV_LOG(ERR,
11313 : : "Cannot read module EEPROM memory. "
11314 : : "No module connected.\n");
11315 : 0 : return -EINVAL;
11316 : : }
11317 : :
11318 : 0 : type = hw->phy.link_info.module_type[0];
11319 : :
11320 [ # # # # ]: 0 : switch (type) {
11321 : 0 : case I40E_MODULE_TYPE_SFP:
11322 : 0 : status = i40e_aq_get_phy_register(hw,
11323 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11324 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11325 : : I40E_MODULE_SFF_8472_COMP,
11326 : : &sff8472_comp, NULL);
11327 [ # # ]: 0 : if (status)
11328 : : return -EIO;
11329 : :
11330 : 0 : status = i40e_aq_get_phy_register(hw,
11331 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11332 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11333 : : I40E_MODULE_SFF_8472_SWAP,
11334 : : &sff8472_swap, NULL);
11335 [ # # ]: 0 : if (status)
11336 : : return -EIO;
11337 : :
11338 : : /* Check if the module requires address swap to access
11339 : : * the other EEPROM memory page.
11340 : : */
11341 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11342 : 0 : PMD_DRV_LOG(WARNING,
11343 : : "Module address swap to access "
11344 : : "page 0xA2 is not supported.\n");
11345 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11346 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11347 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11348 : : /* Module is not SFF-8472 compliant */
11349 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11350 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11351 : : } else {
11352 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11353 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11354 : : }
11355 : : break;
11356 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11357 : : /* Read from memory page 0. */
11358 : 0 : status = i40e_aq_get_phy_register(hw,
11359 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11360 : : 0, 1,
11361 : : I40E_MODULE_REVISION_ADDR,
11362 : : &sff8636_rev, NULL);
11363 [ # # ]: 0 : if (status)
11364 : : return -EIO;
11365 : : /* Determine revision compliance byte */
11366 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11367 : : /* Module is SFF-8636 compliant */
11368 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11369 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11370 : : } else {
11371 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11372 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11373 : : }
11374 : : break;
11375 : 0 : case I40E_MODULE_TYPE_QSFP28:
11376 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11377 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11378 : 0 : break;
11379 : 0 : default:
11380 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized\n");
11381 : 0 : return -EINVAL;
11382 : : }
11383 : : return 0;
11384 : : }
11385 : :
11386 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11387 : : struct rte_dev_eeprom_info *info)
11388 : : {
11389 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11390 : : bool is_sfp = false;
11391 : : i40e_status status;
11392 : : uint8_t *data;
11393 : 0 : uint32_t value = 0;
11394 : : uint32_t i;
11395 : :
11396 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11397 : : is_sfp = true;
11398 : :
11399 : 0 : data = info->data;
11400 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11401 : 0 : u32 offset = i + info->offset;
11402 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11403 : :
11404 : : /* Check if we need to access the other memory page */
11405 [ # # ]: 0 : if (is_sfp) {
11406 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11407 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11408 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11409 : : }
11410 : : } else {
11411 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11412 : : /* Compute memory page number and offset. */
11413 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11414 : 0 : addr++;
11415 : : }
11416 : : }
11417 : 0 : status = i40e_aq_get_phy_register(hw,
11418 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11419 : : addr, 1, offset, &value, NULL);
11420 [ # # ]: 0 : if (status)
11421 : : return -EIO;
11422 : 0 : data[i] = (uint8_t)value;
11423 : : }
11424 : : return 0;
11425 : : }
11426 : :
11427 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11428 : : struct rte_ether_addr *mac_addr)
11429 : : {
11430 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11431 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11432 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11433 : : struct i40e_mac_filter_info mac_filter;
11434 : : struct i40e_mac_filter *f;
11435 : : int ret;
11436 : :
11437 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11438 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11439 : 0 : return -EINVAL;
11440 : : }
11441 : :
11442 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11443 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11444 : : &f->mac_info.mac_addr))
11445 : : break;
11446 : : }
11447 : :
11448 [ # # ]: 0 : if (f == NULL) {
11449 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11450 : 0 : return -EIO;
11451 : : }
11452 : :
11453 : 0 : mac_filter = f->mac_info;
11454 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11455 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11456 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11457 : 0 : return -EIO;
11458 : : }
11459 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11460 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11461 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11462 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11463 : 0 : return -EIO;
11464 : : }
11465 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11466 : :
11467 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11468 : 0 : mac_addr->addr_bytes, NULL);
11469 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11470 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11471 : 0 : return -EIO;
11472 : : }
11473 : :
11474 : : return 0;
11475 : : }
11476 : :
11477 : : static int
11478 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11479 : : {
11480 : : /* mtu setting is forbidden if port is start */
11481 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11482 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11483 : : dev->data->port_id);
11484 : 0 : return -EBUSY;
11485 : : }
11486 : :
11487 : : return 0;
11488 : : }
11489 : :
11490 : : /* Restore ethertype filter */
11491 : : static void
11492 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11493 : : {
11494 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11495 : : struct i40e_ethertype_filter_list
11496 : : *ethertype_list = &pf->ethertype.ethertype_list;
11497 : : struct i40e_ethertype_filter *f;
11498 : : struct i40e_control_filter_stats stats;
11499 : : uint16_t flags;
11500 : :
11501 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11502 : : flags = 0;
11503 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11504 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11505 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11506 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11507 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11508 : :
11509 : : memset(&stats, 0, sizeof(stats));
11510 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11511 : 0 : f->input.mac_addr.addr_bytes,
11512 : 0 : f->input.ether_type,
11513 : 0 : flags, pf->main_vsi->seid,
11514 : 0 : f->queue, 1, &stats, NULL);
11515 : : }
11516 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11517 : : " mac_etype_used = %u, etype_used = %u,"
11518 : : " mac_etype_free = %u, etype_free = %u",
11519 : : stats.mac_etype_used, stats.etype_used,
11520 : : stats.mac_etype_free, stats.etype_free);
11521 : 0 : }
11522 : :
11523 : : /* Restore tunnel filter */
11524 : : static void
11525 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11526 : : {
11527 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11528 : : struct i40e_vsi *vsi;
11529 : : struct i40e_pf_vf *vf;
11530 : : struct i40e_tunnel_filter_list
11531 : : *tunnel_list = &pf->tunnel.tunnel_list;
11532 : : struct i40e_tunnel_filter *f;
11533 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11534 : : bool big_buffer = 0;
11535 : :
11536 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11537 [ # # ]: 0 : if (!f->is_to_vf)
11538 : 0 : vsi = pf->main_vsi;
11539 : : else {
11540 : 0 : vf = &pf->vfs[f->vf_id];
11541 : 0 : vsi = vf->vsi;
11542 : : }
11543 : : memset(&cld_filter, 0, sizeof(cld_filter));
11544 : : rte_ether_addr_copy((struct rte_ether_addr *)
11545 : : &f->input.outer_mac,
11546 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11547 : : rte_ether_addr_copy((struct rte_ether_addr *)
11548 : : &f->input.inner_mac,
11549 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11550 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11551 : 0 : cld_filter.element.flags = f->input.flags;
11552 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11553 : 0 : cld_filter.element.queue_number = f->queue;
11554 : : rte_memcpy(cld_filter.general_fields,
11555 [ # # ]: 0 : f->input.general_fields,
11556 : : sizeof(f->input.general_fields));
11557 : :
11558 [ # # ]: 0 : if (((f->input.flags &
11559 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11560 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11561 : : ((f->input.flags &
11562 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11563 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11564 : : ((f->input.flags &
11565 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11566 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11567 : : big_buffer = 1;
11568 : :
11569 [ # # ]: 0 : if (big_buffer)
11570 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11571 : 0 : vsi->seid, &cld_filter, 1);
11572 : : else
11573 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11574 : : &cld_filter.element, 1);
11575 : : }
11576 : 0 : }
11577 : :
11578 : : static void
11579 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11580 : : {
11581 : 0 : i40e_ethertype_filter_restore(pf);
11582 : 0 : i40e_tunnel_filter_restore(pf);
11583 : 0 : i40e_fdir_filter_restore(pf);
11584 : 0 : (void)i40e_hash_filter_restore(pf);
11585 : 0 : }
11586 : :
11587 : : bool
11588 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11589 : : {
11590 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11591 : 0 : return false;
11592 : :
11593 : : return true;
11594 : : }
11595 : :
11596 : : bool
11597 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11598 : : {
11599 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11600 : : }
11601 : :
11602 : : struct i40e_customized_pctype*
11603 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11604 : : {
11605 : : int i;
11606 : :
11607 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11608 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11609 : 0 : return &pf->customized_pctype[i];
11610 : : }
11611 : : return NULL;
11612 : : }
11613 : :
11614 : : static int
11615 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11616 : : uint32_t pkg_size, uint32_t proto_num,
11617 : : struct rte_pmd_i40e_proto_info *proto,
11618 : : enum rte_pmd_i40e_package_op op)
11619 : : {
11620 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11621 : : uint32_t pctype_num;
11622 : : struct rte_pmd_i40e_ptype_info *pctype;
11623 : : uint32_t buff_size;
11624 : : struct i40e_customized_pctype *new_pctype = NULL;
11625 : : uint8_t proto_id;
11626 : : uint8_t pctype_value;
11627 : : char name[64];
11628 : : uint32_t i, j, n;
11629 : : int ret;
11630 : :
11631 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11632 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11633 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11634 : 0 : return -1;
11635 : : }
11636 : :
11637 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11638 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11639 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11640 [ # # ]: 0 : if (ret) {
11641 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11642 : 0 : return -1;
11643 : : }
11644 [ # # ]: 0 : if (!pctype_num) {
11645 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11646 : 0 : return -1;
11647 : : }
11648 : :
11649 : 0 : buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
11650 : 0 : pctype = rte_zmalloc("new_pctype", buff_size, 0);
11651 [ # # ]: 0 : if (!pctype) {
11652 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11653 : 0 : return -1;
11654 : : }
11655 : : /* get information about new pctype list */
11656 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11657 : : (uint8_t *)pctype, buff_size,
11658 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11659 [ # # ]: 0 : if (ret) {
11660 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11661 : 0 : rte_free(pctype);
11662 : 0 : return -1;
11663 : : }
11664 : :
11665 : : /* Update customized pctype. */
11666 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11667 : 0 : pctype_value = pctype[i].ptype_id;
11668 : : memset(name, 0, sizeof(name));
11669 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11670 : 0 : proto_id = pctype[i].protocols[j];
11671 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11672 : 0 : continue;
11673 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11674 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11675 : : continue;
11676 : 0 : strlcat(name, proto[n].name, sizeof(name));
11677 : 0 : strlcat(name, "_", sizeof(name));
11678 : 0 : break;
11679 : : }
11680 : : }
11681 : 0 : name[strlen(name) - 1] = '\0';
11682 : 0 : PMD_DRV_LOG(INFO, "name = %s\n", name);
11683 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11684 : : new_pctype =
11685 : 0 : i40e_find_customized_pctype(pf,
11686 : : I40E_CUSTOMIZED_GTPC);
11687 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11688 : : new_pctype =
11689 : 0 : i40e_find_customized_pctype(pf,
11690 : : I40E_CUSTOMIZED_GTPU_IPV4);
11691 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11692 : : new_pctype =
11693 : 0 : i40e_find_customized_pctype(pf,
11694 : : I40E_CUSTOMIZED_GTPU_IPV6);
11695 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11696 : : new_pctype =
11697 : 0 : i40e_find_customized_pctype(pf,
11698 : : I40E_CUSTOMIZED_GTPU);
11699 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11700 : : new_pctype =
11701 : 0 : i40e_find_customized_pctype(pf,
11702 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11703 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11704 : : new_pctype =
11705 : 0 : i40e_find_customized_pctype(pf,
11706 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11707 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11708 : : new_pctype =
11709 : 0 : i40e_find_customized_pctype(pf,
11710 : : I40E_CUSTOMIZED_ESP_IPV4);
11711 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11712 : : new_pctype =
11713 : 0 : i40e_find_customized_pctype(pf,
11714 : : I40E_CUSTOMIZED_ESP_IPV6);
11715 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11716 : : new_pctype =
11717 : 0 : i40e_find_customized_pctype(pf,
11718 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11719 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11720 : : new_pctype =
11721 : 0 : i40e_find_customized_pctype(pf,
11722 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11723 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11724 : : new_pctype =
11725 : 0 : i40e_find_customized_pctype(pf,
11726 : : I40E_CUSTOMIZED_AH_IPV4);
11727 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11728 : : new_pctype =
11729 : 0 : i40e_find_customized_pctype(pf,
11730 : : I40E_CUSTOMIZED_AH_IPV6);
11731 [ # # ]: 0 : if (new_pctype) {
11732 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11733 : 0 : new_pctype->pctype = pctype_value;
11734 : 0 : new_pctype->valid = true;
11735 : : } else {
11736 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11737 : 0 : new_pctype->valid = false;
11738 : : }
11739 : : }
11740 : : }
11741 : :
11742 : 0 : rte_free(pctype);
11743 : 0 : return 0;
11744 : : }
11745 : :
11746 : : static int
11747 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11748 : : uint32_t pkg_size, uint32_t proto_num,
11749 : : struct rte_pmd_i40e_proto_info *proto,
11750 : : enum rte_pmd_i40e_package_op op)
11751 : : {
11752 : : struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
11753 : 0 : uint16_t port_id = dev->data->port_id;
11754 : : uint32_t ptype_num;
11755 : : struct rte_pmd_i40e_ptype_info *ptype;
11756 : : uint32_t buff_size;
11757 : : uint8_t proto_id;
11758 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11759 : : uint32_t i, j, n;
11760 : : bool in_tunnel;
11761 : : int ret;
11762 : :
11763 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11764 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11765 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11766 : 0 : return -1;
11767 : : }
11768 : :
11769 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11770 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11771 : 0 : return 0;
11772 : : }
11773 : :
11774 : : /* get information about new ptype num */
11775 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11776 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11777 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11778 [ # # ]: 0 : if (ret) {
11779 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11780 : 0 : return ret;
11781 : : }
11782 [ # # ]: 0 : if (!ptype_num) {
11783 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11784 : 0 : return -1;
11785 : : }
11786 : :
11787 : 0 : buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
11788 : 0 : ptype = rte_zmalloc("new_ptype", buff_size, 0);
11789 [ # # ]: 0 : if (!ptype) {
11790 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11791 : 0 : return -1;
11792 : : }
11793 : :
11794 : : /* get information about new ptype list */
11795 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11796 : : (uint8_t *)ptype, buff_size,
11797 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11798 [ # # ]: 0 : if (ret) {
11799 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11800 : 0 : rte_free(ptype);
11801 : 0 : return ret;
11802 : : }
11803 : :
11804 : 0 : buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
11805 : 0 : ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
11806 [ # # ]: 0 : if (!ptype_mapping) {
11807 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11808 : 0 : rte_free(ptype);
11809 : 0 : return -1;
11810 : : }
11811 : :
11812 : : /* Update ptype mapping table. */
11813 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11814 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11815 : 0 : ptype_mapping[i].sw_ptype = 0;
11816 : : in_tunnel = false;
11817 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11818 : 0 : proto_id = ptype[i].protocols[j];
11819 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11820 : 0 : continue;
11821 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11822 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11823 : : continue;
11824 : : memset(name, 0, sizeof(name));
11825 : 0 : strcpy(name, proto[n].name);
11826 : 0 : PMD_DRV_LOG(INFO, "name = %s\n", name);
11827 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11828 : 0 : ptype_mapping[i].sw_ptype |=
11829 : : RTE_PTYPE_L2_ETHER_PPPOE;
11830 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11831 : : !in_tunnel) {
11832 : 0 : ptype_mapping[i].sw_ptype |=
11833 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11834 : 0 : ptype_mapping[i].sw_ptype |=
11835 : : RTE_PTYPE_L4_FRAG;
11836 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11837 : : in_tunnel) {
11838 : 0 : ptype_mapping[i].sw_ptype |=
11839 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11840 : 0 : ptype_mapping[i].sw_ptype |=
11841 : : RTE_PTYPE_INNER_L4_FRAG;
11842 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11843 : 0 : ptype_mapping[i].sw_ptype |=
11844 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11845 : : in_tunnel = true;
11846 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11847 : : !in_tunnel)
11848 : 0 : ptype_mapping[i].sw_ptype |=
11849 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11850 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11851 : : in_tunnel)
11852 : 0 : ptype_mapping[i].sw_ptype |=
11853 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11854 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11855 : : !in_tunnel) {
11856 : 0 : ptype_mapping[i].sw_ptype |=
11857 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11858 : 0 : ptype_mapping[i].sw_ptype |=
11859 : : RTE_PTYPE_L4_FRAG;
11860 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11861 : : in_tunnel) {
11862 : 0 : ptype_mapping[i].sw_ptype |=
11863 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11864 : 0 : ptype_mapping[i].sw_ptype |=
11865 : : RTE_PTYPE_INNER_L4_FRAG;
11866 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
11867 : 0 : ptype_mapping[i].sw_ptype |=
11868 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11869 : : in_tunnel = true;
11870 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
11871 : : !in_tunnel)
11872 : 0 : ptype_mapping[i].sw_ptype |=
11873 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11874 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
11875 : : in_tunnel)
11876 : 0 : ptype_mapping[i].sw_ptype |=
11877 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11878 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11879 : : !in_tunnel)
11880 : 0 : ptype_mapping[i].sw_ptype |=
11881 : : RTE_PTYPE_L4_UDP;
11882 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11883 : : in_tunnel)
11884 : 0 : ptype_mapping[i].sw_ptype |=
11885 : : RTE_PTYPE_INNER_L4_UDP;
11886 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11887 : : !in_tunnel)
11888 : 0 : ptype_mapping[i].sw_ptype |=
11889 : : RTE_PTYPE_L4_TCP;
11890 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11891 : : in_tunnel)
11892 : 0 : ptype_mapping[i].sw_ptype |=
11893 : : RTE_PTYPE_INNER_L4_TCP;
11894 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11895 : : !in_tunnel)
11896 : 0 : ptype_mapping[i].sw_ptype |=
11897 : : RTE_PTYPE_L4_SCTP;
11898 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11899 : : in_tunnel)
11900 : 0 : ptype_mapping[i].sw_ptype |=
11901 : : RTE_PTYPE_INNER_L4_SCTP;
11902 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
11903 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
11904 : : !in_tunnel)
11905 : 0 : ptype_mapping[i].sw_ptype |=
11906 : : RTE_PTYPE_L4_ICMP;
11907 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
11908 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
11909 : : in_tunnel)
11910 : 0 : ptype_mapping[i].sw_ptype |=
11911 : : RTE_PTYPE_INNER_L4_ICMP;
11912 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
11913 : 0 : ptype_mapping[i].sw_ptype |=
11914 : : RTE_PTYPE_TUNNEL_GTPC;
11915 : : in_tunnel = true;
11916 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
11917 : 0 : ptype_mapping[i].sw_ptype |=
11918 : : RTE_PTYPE_TUNNEL_GTPU;
11919 : : in_tunnel = true;
11920 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
11921 : 0 : ptype_mapping[i].sw_ptype |=
11922 : : RTE_PTYPE_TUNNEL_ESP;
11923 : : in_tunnel = true;
11924 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
11925 : 0 : ptype_mapping[i].sw_ptype |=
11926 : : RTE_PTYPE_TUNNEL_GRENAT;
11927 : : in_tunnel = true;
11928 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
11929 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
11930 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
11931 : 0 : ptype_mapping[i].sw_ptype |=
11932 : : RTE_PTYPE_TUNNEL_L2TP;
11933 : : in_tunnel = true;
11934 : : }
11935 : :
11936 : : break;
11937 : : }
11938 : : }
11939 : : }
11940 : :
11941 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
11942 : : ptype_num, 0);
11943 [ # # ]: 0 : if (ret)
11944 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
11945 : :
11946 : 0 : rte_free(ptype_mapping);
11947 : 0 : rte_free(ptype);
11948 : 0 : return ret;
11949 : : }
11950 : :
11951 : : void
11952 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
11953 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
11954 : : {
11955 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11956 : : uint32_t proto_num;
11957 : : struct rte_pmd_i40e_proto_info *proto;
11958 : : uint32_t buff_size;
11959 : : uint32_t i;
11960 : : int ret;
11961 : :
11962 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11963 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11964 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11965 : 0 : return;
11966 : : }
11967 : :
11968 : : /* get information about protocol number */
11969 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11970 : : (uint8_t *)&proto_num, sizeof(proto_num),
11971 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
11972 [ # # ]: 0 : if (ret) {
11973 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
11974 : 0 : return;
11975 : : }
11976 [ # # ]: 0 : if (!proto_num) {
11977 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
11978 : 0 : return;
11979 : : }
11980 : :
11981 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
11982 : 0 : proto = rte_zmalloc("new_proto", buff_size, 0);
11983 [ # # ]: 0 : if (!proto) {
11984 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11985 : 0 : return;
11986 : : }
11987 : :
11988 : : /* get information about protocol list */
11989 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11990 : : (uint8_t *)proto, buff_size,
11991 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
11992 [ # # ]: 0 : if (ret) {
11993 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
11994 : 0 : rte_free(proto);
11995 : 0 : return;
11996 : : }
11997 : :
11998 : : /* Check if GTP is supported. */
11999 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12000 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12001 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12002 : 0 : pf->gtp_support = true;
12003 : : else
12004 : 0 : pf->gtp_support = false;
12005 : : break;
12006 : : }
12007 : : }
12008 : :
12009 : : /* Check if ESP is supported. */
12010 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12011 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12012 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12013 : 0 : pf->esp_support = true;
12014 : : else
12015 : 0 : pf->esp_support = false;
12016 : : break;
12017 : : }
12018 : : }
12019 : :
12020 : : /* Update customized pctype info */
12021 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12022 : : proto_num, proto, op);
12023 [ # # ]: 0 : if (ret)
12024 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12025 : :
12026 : : /* Update customized ptype info */
12027 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12028 : : proto_num, proto, op);
12029 [ # # ]: 0 : if (ret)
12030 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12031 : :
12032 : 0 : rte_free(proto);
12033 : : }
12034 : :
12035 : : /* Create a QinQ cloud filter
12036 : : *
12037 : : * The Fortville NIC has limited resources for tunnel filters,
12038 : : * so we can only reuse existing filters.
12039 : : *
12040 : : * In step 1 we define which Field Vector fields can be used for
12041 : : * filter types.
12042 : : * As we do not have the inner tag defined as a field,
12043 : : * we have to define it first, by reusing one of L1 entries.
12044 : : *
12045 : : * In step 2 we are replacing one of existing filter types with
12046 : : * a new one for QinQ.
12047 : : * As we reusing L1 and replacing L2, some of the default filter
12048 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12049 : : *
12050 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12051 : : *
12052 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12053 : : * later when we define the cloud filter.
12054 : : * a. Valid_flags.replace_cloud = 0
12055 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12056 : : * c. New_filter = 0x10
12057 : : * d. TR bit = 0xff (optional, not used here)
12058 : : * e. Buffer – 2 entries:
12059 : : * i. Byte 0 = 8 (outer vlan FV index).
12060 : : * Byte 1 = 0 (rsv)
12061 : : * Byte 2-3 = 0x0fff
12062 : : * ii. Byte 0 = 37 (inner vlan FV index).
12063 : : * Byte 1 =0 (rsv)
12064 : : * Byte 2-3 = 0x0fff
12065 : : *
12066 : : * Step 2:
12067 : : * 2. Create cloud filter using two L1 filters entries: stag and
12068 : : * new filter(outer vlan+ inner vlan)
12069 : : * a. Valid_flags.replace_cloud = 1
12070 : : * b. Old_filter = 1 (instead of outer IP)
12071 : : * c. New_filter = 0x10
12072 : : * d. Buffer – 2 entries:
12073 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12074 : : * Byte 1-3 = 0 (rsv)
12075 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12076 : : * Byte 9-11 = 0 (rsv)
12077 : : */
12078 : : static int
12079 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12080 : : {
12081 : : int ret = -ENOTSUP;
12082 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12083 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12084 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12085 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12086 : :
12087 [ # # ]: 0 : if (pf->support_multi_driver) {
12088 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12089 : 0 : return ret;
12090 : : }
12091 : :
12092 : : /* Init */
12093 : : memset(&filter_replace, 0,
12094 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12095 : : memset(&filter_replace_buf, 0,
12096 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12097 : :
12098 : : /* create L1 filter */
12099 : 0 : filter_replace.old_filter_type =
12100 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12101 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12102 : : filter_replace.tr_bit = 0;
12103 : :
12104 : : /* Prepare the buffer, 2 entries */
12105 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12106 : 0 : filter_replace_buf.data[0] |=
12107 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12108 : : /* Field Vector 12b mask */
12109 : 0 : filter_replace_buf.data[2] = 0xff;
12110 : 0 : filter_replace_buf.data[3] = 0x0f;
12111 : : filter_replace_buf.data[4] =
12112 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12113 : 0 : filter_replace_buf.data[4] |=
12114 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12115 : : /* Field Vector 12b mask */
12116 : 0 : filter_replace_buf.data[6] = 0xff;
12117 : 0 : filter_replace_buf.data[7] = 0x0f;
12118 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12119 : : &filter_replace_buf);
12120 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12121 : : return ret;
12122 : :
12123 : 0 : if (filter_replace.old_filter_type !=
12124 [ # # ]: 0 : filter_replace.new_filter_type)
12125 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12126 : : " original: 0x%x, new: 0x%x",
12127 : : dev->device->name,
12128 : : filter_replace.old_filter_type,
12129 : : filter_replace.new_filter_type);
12130 : :
12131 : : /* Apply the second L2 cloud filter */
12132 : : memset(&filter_replace, 0,
12133 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12134 : : memset(&filter_replace_buf, 0,
12135 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12136 : :
12137 : : /* create L2 filter, input for L2 filter will be L1 filter */
12138 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12139 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12140 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12141 : :
12142 : : /* Prepare the buffer, 2 entries */
12143 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12144 : 0 : filter_replace_buf.data[0] |=
12145 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12146 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12147 : 0 : filter_replace_buf.data[4] |=
12148 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12149 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12150 : : &filter_replace_buf);
12151 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12152 [ # # ]: 0 : filter_replace.new_filter_type))
12153 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12154 : : " original: 0x%x, new: 0x%x",
12155 : : dev->device->name,
12156 : : filter_replace.old_filter_type,
12157 : : filter_replace.new_filter_type);
12158 : :
12159 : : return ret;
12160 : : }
12161 : :
12162 [ - + ]: 235 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12163 [ - + ]: 235 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12164 : : #ifdef RTE_ETHDEV_DEBUG_RX
12165 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12166 : : #endif
12167 : : #ifdef RTE_ETHDEV_DEBUG_TX
12168 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12169 : : #endif
12170 : :
12171 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12172 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12173 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12174 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12175 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|