Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Intel Corporation
3 : : */
4 : :
5 : : #include <rte_string_fns.h>
6 : : #include <ethdev_pci.h>
7 : :
8 : : #include <ctype.h>
9 : : #include <fcntl.h>
10 : : #include <stdio.h>
11 : : #include <sys/types.h>
12 : : #include <sys/stat.h>
13 : : #include <unistd.h>
14 : : #include <math.h>
15 : :
16 : : #include <rte_tailq.h>
17 : : #include <rte_os_shim.h>
18 : :
19 : : #include "eal_firmware.h"
20 : :
21 : : #include "base/ice_sched.h"
22 : : #include "base/ice_flow.h"
23 : : #include "base/ice_dcb.h"
24 : : #include "base/ice_common.h"
25 : : #include "base/ice_ptp_hw.h"
26 : :
27 : : #include "ice_ethdev.h"
28 : : #include "ice_rxtx.h"
29 : : #include "ice_generic_flow.h"
30 : :
31 : : /* devargs */
32 : : #define ICE_SAFE_MODE_SUPPORT_ARG "safe-mode-support"
33 : : #define ICE_DEFAULT_MAC_DISABLE "default-mac-disable"
34 : : #define ICE_PROTO_XTR_ARG "proto_xtr"
35 : : #define ICE_FIELD_OFFS_ARG "field_offs"
36 : : #define ICE_FIELD_NAME_ARG "field_name"
37 : : #define ICE_HW_DEBUG_MASK_ARG "hw_debug_mask"
38 : : #define ICE_ONE_PPS_OUT_ARG "pps_out"
39 : : #define ICE_RX_LOW_LATENCY_ARG "rx_low_latency"
40 : : #define ICE_MBUF_CHECK_ARG "mbuf_check"
41 : : #define ICE_DDP_FILENAME_ARG "ddp_pkg_file"
42 : : #define ICE_DDP_LOAD_SCHED_ARG "ddp_load_sched_topo"
43 : : #define ICE_TM_LEVELS_ARG "tm_sched_levels"
44 : : #define ICE_SOURCE_PRUNE_ARG "source-prune"
45 : : #define ICE_LINK_STATE_ON_CLOSE "link_state_on_close"
46 : :
47 : : #define ICE_CYCLECOUNTER_MASK 0xffffffffffffffffULL
48 : :
49 : : static const char * const ice_valid_args[] = {
50 : : ICE_SAFE_MODE_SUPPORT_ARG,
51 : : ICE_PROTO_XTR_ARG,
52 : : ICE_FIELD_OFFS_ARG,
53 : : ICE_FIELD_NAME_ARG,
54 : : ICE_HW_DEBUG_MASK_ARG,
55 : : ICE_ONE_PPS_OUT_ARG,
56 : : ICE_RX_LOW_LATENCY_ARG,
57 : : ICE_DEFAULT_MAC_DISABLE,
58 : : ICE_MBUF_CHECK_ARG,
59 : : ICE_DDP_FILENAME_ARG,
60 : : ICE_DDP_LOAD_SCHED_ARG,
61 : : ICE_TM_LEVELS_ARG,
62 : : ICE_SOURCE_PRUNE_ARG,
63 : : ICE_LINK_STATE_ON_CLOSE,
64 : : NULL
65 : : };
66 : :
67 : : #define PPS_OUT_DELAY_NS 1
68 : :
69 : : /* Maximum number of VSI */
70 : : #define ICE_MAX_NUM_VSIS (768UL)
71 : :
72 : : struct proto_xtr_ol_flag {
73 : : const struct rte_mbuf_dynflag param;
74 : : bool required;
75 : : };
76 : :
77 : : static bool ice_proto_xtr_hw_support[PROTO_XTR_MAX];
78 : :
79 : : static struct proto_xtr_ol_flag ice_proto_xtr_ol_flag_params[] = {
80 : : [PROTO_XTR_VLAN] = {
81 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" }},
82 : : [PROTO_XTR_IPV4] = {
83 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" }},
84 : : [PROTO_XTR_IPV6] = {
85 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" }},
86 : : [PROTO_XTR_IPV6_FLOW] = {
87 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" }},
88 : : [PROTO_XTR_TCP] = {
89 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" }},
90 : : [PROTO_XTR_IP_OFFSET] = {
91 : : .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" }}
92 : : };
93 : :
94 : : enum ice_link_state_on_close {
95 : : ICE_LINK_DOWN,
96 : : ICE_LINK_UP,
97 : : ICE_LINK_INITIAL,
98 : : };
99 : :
100 : : #define ICE_OS_DEFAULT_PKG_NAME "ICE OS Default Package"
101 : : #define ICE_COMMS_PKG_NAME "ICE COMMS Package"
102 : : #define ICE_MAX_RES_DESC_NUM 1024
103 : :
104 : : #define ICE_MAC_E810_MAX_WATERMARK 143744U
105 : : #define ICE_MAC_E830_MAX_WATERMARK 259103U
106 : : #define ICE_MAC_TC_MAX_WATERMARK (((hw)->mac_type == ICE_MAC_E830) ? \
107 : : ICE_MAC_E830_MAX_WATERMARK : ICE_MAC_E810_MAX_WATERMARK)
108 : :
109 : : #define ICE_RSS_LUT_GLOBAL_QUEUE_NB 64
110 : :
111 : : static int ice_dev_configure(struct rte_eth_dev *dev);
112 : : static int ice_dev_start(struct rte_eth_dev *dev);
113 : : static int ice_dev_stop(struct rte_eth_dev *dev);
114 : : static int ice_dev_close(struct rte_eth_dev *dev);
115 : : static int ice_dev_reset(struct rte_eth_dev *dev);
116 : : static int ice_dev_info_get(struct rte_eth_dev *dev,
117 : : struct rte_eth_dev_info *dev_info);
118 : : static int ice_phy_conf_link(struct ice_hw *hw,
119 : : u16 force_speed,
120 : : bool link_up);
121 : : static int ice_link_update(struct rte_eth_dev *dev,
122 : : int wait_to_complete);
123 : : static int ice_dev_set_link_up(struct rte_eth_dev *dev);
124 : : static int ice_dev_set_link_down(struct rte_eth_dev *dev);
125 : : static int ice_dev_led_on(struct rte_eth_dev *dev);
126 : : static int ice_dev_led_off(struct rte_eth_dev *dev);
127 : :
128 : : static int ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
129 : : static int ice_vlan_offload_set(struct rte_eth_dev *dev, int mask);
130 : : static int ice_rss_reta_update(struct rte_eth_dev *dev,
131 : : struct rte_eth_rss_reta_entry64 *reta_conf,
132 : : uint16_t reta_size);
133 : : static int ice_rss_reta_query(struct rte_eth_dev *dev,
134 : : struct rte_eth_rss_reta_entry64 *reta_conf,
135 : : uint16_t reta_size);
136 : : static int ice_rss_hash_update(struct rte_eth_dev *dev,
137 : : struct rte_eth_rss_conf *rss_conf);
138 : : static int ice_rss_hash_conf_get(struct rte_eth_dev *dev,
139 : : struct rte_eth_rss_conf *rss_conf);
140 : : static int ice_promisc_enable(struct rte_eth_dev *dev);
141 : : static int ice_promisc_disable(struct rte_eth_dev *dev);
142 : : static int ice_allmulti_enable(struct rte_eth_dev *dev);
143 : : static int ice_allmulti_disable(struct rte_eth_dev *dev);
144 : : static int ice_vlan_filter_set(struct rte_eth_dev *dev,
145 : : uint16_t vlan_id,
146 : : int on);
147 : : static int ice_macaddr_set(struct rte_eth_dev *dev,
148 : : struct rte_ether_addr *mac_addr);
149 : : static int ice_macaddr_add(struct rte_eth_dev *dev,
150 : : struct rte_ether_addr *mac_addr,
151 : : __rte_unused uint32_t index,
152 : : uint32_t pool);
153 : : static void ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
154 : : static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
155 : : uint16_t queue_id);
156 : : static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
157 : : uint16_t queue_id);
158 : : static int ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
159 : : size_t fw_size);
160 : : static int ice_vlan_pvid_set(struct rte_eth_dev *dev,
161 : : uint16_t pvid, int on);
162 : : static int ice_vlan_tpid_set(struct rte_eth_dev *dev,
163 : : enum rte_vlan_type vlan_type,
164 : : uint16_t tpid);
165 : : static int ice_get_eeprom_length(struct rte_eth_dev *dev);
166 : : static int ice_get_eeprom(struct rte_eth_dev *dev,
167 : : struct rte_dev_eeprom_info *eeprom);
168 : : static int ice_get_module_info(struct rte_eth_dev *dev,
169 : : struct rte_eth_dev_module_info *modinfo);
170 : : static int ice_get_module_eeprom(struct rte_eth_dev *dev,
171 : : struct rte_dev_eeprom_info *info);
172 : : static int ice_stats_get(struct rte_eth_dev *dev,
173 : : struct rte_eth_stats *stats, struct eth_queue_stats *qstats);
174 : : static int ice_stats_reset(struct rte_eth_dev *dev);
175 : : static int ice_xstats_get(struct rte_eth_dev *dev,
176 : : struct rte_eth_xstat *xstats, unsigned int n);
177 : : static int ice_xstats_get_names(struct rte_eth_dev *dev,
178 : : struct rte_eth_xstat_name *xstats_names,
179 : : unsigned int limit);
180 : : static int ice_dev_flow_ops_get(struct rte_eth_dev *dev,
181 : : const struct rte_flow_ops **ops);
182 : : static int ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
183 : : struct rte_eth_udp_tunnel *udp_tunnel);
184 : : static int ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
185 : : struct rte_eth_udp_tunnel *udp_tunnel);
186 : : static int ice_timesync_enable(struct rte_eth_dev *dev);
187 : : static int ice_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
188 : : struct timespec *timestamp,
189 : : uint32_t flags);
190 : : static int ice_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
191 : : struct timespec *timestamp);
192 : : static int ice_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
193 : : static int ice_timesync_adjust_freq(struct rte_eth_dev *dev, int64_t ppm);
194 : : static int ice_timesync_read_time(struct rte_eth_dev *dev,
195 : : struct timespec *timestamp);
196 : : static int ice_timesync_write_time(struct rte_eth_dev *dev,
197 : : const struct timespec *timestamp);
198 : : static int ice_timesync_disable(struct rte_eth_dev *dev);
199 : : static int ice_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
200 : : static int ice_fec_get_capability(struct rte_eth_dev *dev, struct rte_eth_fec_capa *speed_fec_capa,
201 : : unsigned int num);
202 : : static int ice_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa);
203 : : static int ice_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa);
204 : : static const uint32_t *ice_buffer_split_supported_hdr_ptypes_get(struct rte_eth_dev *dev,
205 : : size_t *no_of_elements);
206 : : static int ice_get_dcb_info(struct rte_eth_dev *dev, struct rte_eth_dcb_info *dcb_info);
207 : : static int ice_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf);
208 : :
209 : : static const struct rte_pci_id pci_id_ice_map[] = {
210 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_BACKPLANE) },
211 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_SFP) },
212 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_10G_BASE_T) },
213 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_1GBE) },
214 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_QSFP) },
215 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) },
216 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_QSFP) },
217 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_SFP) },
218 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_BACKPLANE) },
219 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_QSFP) },
220 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_SFP) },
221 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_BACKPLANE) },
222 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_QSFP) },
223 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SFP) },
224 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_10G_BASE_T) },
225 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SGMII) },
226 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822_SI_DFLT) },
227 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_BACKPLANE) },
228 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_QSFP) },
229 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SFP) },
230 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_10G_BASE_T) },
231 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SGMII) },
232 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_BACKPLANE) },
233 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SFP) },
234 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_10G_BASE_T) },
235 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SGMII) },
236 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E824S) },
237 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E825C_BACKPLANE) },
238 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E825C_QSFP) },
239 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E825C_SFP) },
240 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_C825X) },
241 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E825C_SGMII) },
242 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_BACKPLANE) },
243 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_QSFP56) },
244 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_SFP) },
245 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830C_BACKPLANE) },
246 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_L_BACKPLANE) },
247 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830C_QSFP) },
248 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_L_QSFP) },
249 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830C_SFP) },
250 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E830_L_SFP) },
251 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835CC_BACKPLANE), },
252 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835CC_QSFP56), },
253 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835CC_SFP), },
254 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835C_BACKPLANE), },
255 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835C_QSFP), },
256 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835C_SFP), },
257 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835_L_BACKPLANE), },
258 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835_L_QSFP), },
259 : : { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E835_L_SFP), },
260 : : { .vendor_id = 0, /* sentinel */ },
261 : : };
262 : :
263 : : static int
264 : 0 : ice_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
265 : : void *arg)
266 : : {
267 [ # # ]: 0 : if (!arg)
268 : : return -EINVAL;
269 : :
270 : 0 : *(const void **)arg = &ice_tm_ops;
271 : :
272 : 0 : return 0;
273 : : }
274 : :
275 : : static const struct eth_dev_ops ice_eth_dev_ops = {
276 : : .dev_configure = ice_dev_configure,
277 : : .dev_start = ice_dev_start,
278 : : .dev_stop = ice_dev_stop,
279 : : .dev_close = ice_dev_close,
280 : : .dev_reset = ice_dev_reset,
281 : : .dev_set_link_up = ice_dev_set_link_up,
282 : : .dev_set_link_down = ice_dev_set_link_down,
283 : : .dev_led_on = ice_dev_led_on,
284 : : .dev_led_off = ice_dev_led_off,
285 : : .rx_queue_start = ice_rx_queue_start,
286 : : .rx_queue_stop = ice_rx_queue_stop,
287 : : .tx_queue_start = ice_tx_queue_start,
288 : : .tx_queue_stop = ice_tx_queue_stop,
289 : : .rx_queue_setup = ice_rx_queue_setup,
290 : : .rx_queue_release = ice_dev_rx_queue_release,
291 : : .tx_queue_setup = ice_tx_queue_setup,
292 : : .tx_queue_release = ice_dev_tx_queue_release,
293 : : .dev_infos_get = ice_dev_info_get,
294 : : .dev_supported_ptypes_get = ice_dev_supported_ptypes_get,
295 : : .link_update = ice_link_update,
296 : : .mtu_set = ice_mtu_set,
297 : : .mac_addr_set = ice_macaddr_set,
298 : : .mac_addr_add = ice_macaddr_add,
299 : : .mac_addr_remove = ice_macaddr_remove,
300 : : .vlan_filter_set = ice_vlan_filter_set,
301 : : .vlan_offload_set = ice_vlan_offload_set,
302 : : .reta_update = ice_rss_reta_update,
303 : : .reta_query = ice_rss_reta_query,
304 : : .rss_hash_update = ice_rss_hash_update,
305 : : .rss_hash_conf_get = ice_rss_hash_conf_get,
306 : : .promiscuous_enable = ice_promisc_enable,
307 : : .promiscuous_disable = ice_promisc_disable,
308 : : .allmulticast_enable = ice_allmulti_enable,
309 : : .allmulticast_disable = ice_allmulti_disable,
310 : : .rx_queue_intr_enable = ice_rx_queue_intr_enable,
311 : : .rx_queue_intr_disable = ice_rx_queue_intr_disable,
312 : : .fw_version_get = ice_fw_version_get,
313 : : .vlan_pvid_set = ice_vlan_pvid_set,
314 : : .vlan_tpid_set = ice_vlan_tpid_set,
315 : : .rxq_info_get = ice_rxq_info_get,
316 : : .txq_info_get = ice_txq_info_get,
317 : : .rx_burst_mode_get = ice_rx_burst_mode_get,
318 : : .tx_burst_mode_get = ice_tx_burst_mode_get,
319 : : .get_eeprom_length = ice_get_eeprom_length,
320 : : .get_eeprom = ice_get_eeprom,
321 : : .get_module_info = ice_get_module_info,
322 : : .get_module_eeprom = ice_get_module_eeprom,
323 : : .stats_get = ice_stats_get,
324 : : .stats_reset = ice_stats_reset,
325 : : .xstats_get = ice_xstats_get,
326 : : .xstats_get_names = ice_xstats_get_names,
327 : : .xstats_reset = ice_stats_reset,
328 : : .flow_ops_get = ice_dev_flow_ops_get,
329 : : .udp_tunnel_port_add = ice_dev_udp_tunnel_port_add,
330 : : .udp_tunnel_port_del = ice_dev_udp_tunnel_port_del,
331 : : .tx_done_cleanup = ice_tx_done_cleanup,
332 : : .get_monitor_addr = ice_get_monitor_addr,
333 : : .timesync_enable = ice_timesync_enable,
334 : : .timesync_read_rx_timestamp = ice_timesync_read_rx_timestamp,
335 : : .timesync_read_tx_timestamp = ice_timesync_read_tx_timestamp,
336 : : .timesync_adjust_time = ice_timesync_adjust_time,
337 : : .timesync_adjust_freq = ice_timesync_adjust_freq,
338 : : .timesync_read_time = ice_timesync_read_time,
339 : : .timesync_write_time = ice_timesync_write_time,
340 : : .timesync_disable = ice_timesync_disable,
341 : : .read_clock = ice_read_clock,
342 : : .tm_ops_get = ice_tm_ops_get,
343 : : .fec_get_capability = ice_fec_get_capability,
344 : : .fec_get = ice_fec_get,
345 : : .fec_set = ice_fec_set,
346 : : .buffer_split_supported_hdr_ptypes_get = ice_buffer_split_supported_hdr_ptypes_get,
347 : : .get_dcb_info = ice_get_dcb_info,
348 : : .priority_flow_ctrl_set = ice_priority_flow_ctrl_set,
349 : : };
350 : :
351 : : /* store statistics names and its offset in stats structure */
352 : : struct ice_xstats_name_off {
353 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
354 : : unsigned int offset;
355 : : };
356 : :
357 : : static const struct ice_xstats_name_off ice_stats_strings[] = {
358 : : {"rx_unicast_packets", offsetof(struct ice_eth_stats, rx_unicast)},
359 : : {"rx_multicast_packets", offsetof(struct ice_eth_stats, rx_multicast)},
360 : : {"rx_broadcast_packets", offsetof(struct ice_eth_stats, rx_broadcast)},
361 : : {"rx_dropped_packets", offsetof(struct ice_eth_stats, rx_discards)},
362 : : {"rx_unknown_protocol_packets", offsetof(struct ice_eth_stats,
363 : : rx_unknown_protocol)},
364 : : {"tx_unicast_packets", offsetof(struct ice_eth_stats, tx_unicast)},
365 : : {"tx_multicast_packets", offsetof(struct ice_eth_stats, tx_multicast)},
366 : : {"tx_broadcast_packets", offsetof(struct ice_eth_stats, tx_broadcast)},
367 : : {"tx_dropped_packets", offsetof(struct ice_eth_stats, tx_discards)},
368 : : };
369 : :
370 : : #define ICE_NB_ETH_XSTATS (sizeof(ice_stats_strings) / \
371 : : sizeof(ice_stats_strings[0]))
372 : :
373 : : static const struct ice_xstats_name_off ice_mbuf_strings[] = {
374 : : {"tx_mbuf_error_packets", offsetof(struct ice_mbuf_stats, tx_pkt_errors)},
375 : : };
376 : :
377 : : #define ICE_NB_MBUF_XSTATS (sizeof(ice_mbuf_strings) / sizeof(ice_mbuf_strings[0]))
378 : :
379 : : static const struct ice_xstats_name_off ice_hw_port_strings[] = {
380 : : {"tx_link_down_dropped", offsetof(struct ice_hw_port_stats,
381 : : tx_dropped_link_down)},
382 : : {"rx_crc_errors", offsetof(struct ice_hw_port_stats, crc_errors)},
383 : : {"rx_illegal_byte_errors", offsetof(struct ice_hw_port_stats,
384 : : illegal_bytes)},
385 : : {"rx_error_bytes", offsetof(struct ice_hw_port_stats, error_bytes)},
386 : : {"mac_local_errors", offsetof(struct ice_hw_port_stats,
387 : : mac_local_faults)},
388 : : {"mac_remote_errors", offsetof(struct ice_hw_port_stats,
389 : : mac_remote_faults)},
390 : : {"rx_len_errors", offsetof(struct ice_hw_port_stats,
391 : : rx_len_errors)},
392 : : {"tx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_tx)},
393 : : {"rx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_rx)},
394 : : {"tx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_tx)},
395 : : {"rx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_rx)},
396 : : {"priority_xon_rx_tc0", offsetof(struct ice_hw_port_stats, priority_xon_rx[0])},
397 : : {"priority_xon_rx_tc1", offsetof(struct ice_hw_port_stats, priority_xon_rx[1])},
398 : : {"priority_xon_rx_tc2", offsetof(struct ice_hw_port_stats, priority_xon_rx[2])},
399 : : {"priority_xon_rx_tc3", offsetof(struct ice_hw_port_stats, priority_xon_rx[3])},
400 : : {"priority_xon_rx_tc4", offsetof(struct ice_hw_port_stats, priority_xon_rx[4])},
401 : : {"priority_xon_rx_tc5", offsetof(struct ice_hw_port_stats, priority_xon_rx[5])},
402 : : {"priority_xon_rx_tc6", offsetof(struct ice_hw_port_stats, priority_xon_rx[6])},
403 : : {"priority_xon_rx_tc7", offsetof(struct ice_hw_port_stats, priority_xon_rx[7])},
404 : : {"priority_xoff_rx_tc0", offsetof(struct ice_hw_port_stats, priority_xoff_rx[0])},
405 : : {"priority_xoff_rx_tc1", offsetof(struct ice_hw_port_stats, priority_xoff_rx[1])},
406 : : {"priority_xoff_rx_tc2", offsetof(struct ice_hw_port_stats, priority_xoff_rx[2])},
407 : : {"priority_xoff_rx_tc3", offsetof(struct ice_hw_port_stats, priority_xoff_rx[3])},
408 : : {"priority_xoff_rx_tc4", offsetof(struct ice_hw_port_stats, priority_xoff_rx[4])},
409 : : {"priority_xoff_rx_tc5", offsetof(struct ice_hw_port_stats, priority_xoff_rx[5])},
410 : : {"priority_xoff_rx_tc6", offsetof(struct ice_hw_port_stats, priority_xoff_rx[6])},
411 : : {"priority_xoff_rx_tc7", offsetof(struct ice_hw_port_stats, priority_xoff_rx[7])},
412 : : {"priority_xon_tx_tc0", offsetof(struct ice_hw_port_stats, priority_xon_tx[0])},
413 : : {"priority_xon_tx_tc1", offsetof(struct ice_hw_port_stats, priority_xon_tx[1])},
414 : : {"priority_xon_tx_tc2", offsetof(struct ice_hw_port_stats, priority_xon_tx[2])},
415 : : {"priority_xon_tx_tc3", offsetof(struct ice_hw_port_stats, priority_xon_tx[3])},
416 : : {"priority_xon_tx_tc4", offsetof(struct ice_hw_port_stats, priority_xon_tx[4])},
417 : : {"priority_xon_tx_tc5", offsetof(struct ice_hw_port_stats, priority_xon_tx[5])},
418 : : {"priority_xon_tx_tc6", offsetof(struct ice_hw_port_stats, priority_xon_tx[6])},
419 : : {"priority_xon_tx_tc7", offsetof(struct ice_hw_port_stats, priority_xon_tx[7])},
420 : : {"priority_xoff_tx_tc0", offsetof(struct ice_hw_port_stats, priority_xoff_tx[0])},
421 : : {"priority_xoff_tx_tc1", offsetof(struct ice_hw_port_stats, priority_xoff_tx[1])},
422 : : {"priority_xoff_tx_tc2", offsetof(struct ice_hw_port_stats, priority_xoff_tx[2])},
423 : : {"priority_xoff_tx_tc3", offsetof(struct ice_hw_port_stats, priority_xoff_tx[3])},
424 : : {"priority_xoff_tx_tc4", offsetof(struct ice_hw_port_stats, priority_xoff_tx[4])},
425 : : {"priority_xoff_tx_tc5", offsetof(struct ice_hw_port_stats, priority_xoff_tx[5])},
426 : : {"priority_xoff_tx_tc6", offsetof(struct ice_hw_port_stats, priority_xoff_tx[6])},
427 : : {"priority_xoff_tx_tc7", offsetof(struct ice_hw_port_stats, priority_xoff_tx[7])},
428 : : {"priority_xon_2_xoff_tc0", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[0])},
429 : : {"priority_xon_2_xoff_tc1", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[1])},
430 : : {"priority_xon_2_xoff_tc2", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[2])},
431 : : {"priority_xon_2_xoff_tc3", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[3])},
432 : : {"priority_xon_2_xoff_tc4", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[4])},
433 : : {"priority_xon_2_xoff_tc5", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[5])},
434 : : {"priority_xon_2_xoff_tc6", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[6])},
435 : : {"priority_xon_2_xoff_tc7", offsetof(struct ice_hw_port_stats, priority_xon_2_xoff[7])},
436 : : {"rx_size_64_packets", offsetof(struct ice_hw_port_stats, rx_size_64)},
437 : : {"rx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
438 : : rx_size_127)},
439 : : {"rx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
440 : : rx_size_255)},
441 : : {"rx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
442 : : rx_size_511)},
443 : : {"rx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
444 : : rx_size_1023)},
445 : : {"rx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
446 : : rx_size_1522)},
447 : : {"rx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
448 : : rx_size_big)},
449 : : {"rx_undersized_errors", offsetof(struct ice_hw_port_stats,
450 : : rx_undersize)},
451 : : {"rx_oversize_errors", offsetof(struct ice_hw_port_stats,
452 : : rx_oversize)},
453 : : {"rx_mac_short_pkt_dropped", offsetof(struct ice_hw_port_stats,
454 : : mac_short_pkt_dropped)},
455 : : {"rx_fragmented_errors", offsetof(struct ice_hw_port_stats,
456 : : rx_fragments)},
457 : : {"rx_jabber_errors", offsetof(struct ice_hw_port_stats, rx_jabber)},
458 : : {"tx_size_64_packets", offsetof(struct ice_hw_port_stats, tx_size_64)},
459 : : {"tx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
460 : : tx_size_127)},
461 : : {"tx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
462 : : tx_size_255)},
463 : : {"tx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
464 : : tx_size_511)},
465 : : {"tx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
466 : : tx_size_1023)},
467 : : {"tx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
468 : : tx_size_1522)},
469 : : {"tx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
470 : : tx_size_big)},
471 : : };
472 : :
473 : : #define ICE_NB_HW_PORT_XSTATS (sizeof(ice_hw_port_strings) / \
474 : : sizeof(ice_hw_port_strings[0]))
475 : :
476 : : static void
477 : : ice_init_controlq_parameter(struct ice_hw *hw)
478 : : {
479 : : /* fields for adminq */
480 : 0 : hw->adminq.num_rq_entries = ICE_ADMINQ_LEN;
481 : 0 : hw->adminq.num_sq_entries = ICE_ADMINQ_LEN;
482 : 0 : hw->adminq.rq_buf_size = ICE_ADMINQ_BUF_SZ;
483 : 0 : hw->adminq.sq_buf_size = ICE_ADMINQ_BUF_SZ;
484 : :
485 : : /* fields for mailboxq, DPDK used as PF host */
486 : 0 : hw->mailboxq.num_rq_entries = ICE_MAILBOXQ_LEN;
487 : 0 : hw->mailboxq.num_sq_entries = ICE_MAILBOXQ_LEN;
488 : 0 : hw->mailboxq.rq_buf_size = ICE_MAILBOXQ_BUF_SZ;
489 : 0 : hw->mailboxq.sq_buf_size = ICE_MAILBOXQ_BUF_SZ;
490 : :
491 : : /* fields for sideband queue */
492 : 0 : hw->sbq.num_rq_entries = ICE_SBQ_LEN;
493 : 0 : hw->sbq.num_sq_entries = ICE_SBQ_LEN;
494 : 0 : hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
495 : 0 : hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
496 : :
497 : : }
498 : :
499 : : static int
500 : 0 : lookup_proto_xtr_type(const char *xtr_name)
501 : : {
502 : : static struct {
503 : : const char *name;
504 : : enum proto_xtr_type type;
505 : : } xtr_type_map[] = {
506 : : { "vlan", PROTO_XTR_VLAN },
507 : : { "ipv4", PROTO_XTR_IPV4 },
508 : : { "ipv6", PROTO_XTR_IPV6 },
509 : : { "ipv6_flow", PROTO_XTR_IPV6_FLOW },
510 : : { "tcp", PROTO_XTR_TCP },
511 : : { "ip_offset", PROTO_XTR_IP_OFFSET },
512 : : };
513 : : uint32_t i;
514 : :
515 [ # # ]: 0 : for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
516 [ # # ]: 0 : if (strcmp(xtr_name, xtr_type_map[i].name) == 0)
517 : 0 : return xtr_type_map[i].type;
518 : : }
519 : :
520 : : return -1;
521 : : }
522 : :
523 : : /*
524 : : * Parse elem, the elem could be single number/range or '(' ')' group
525 : : * 1) A single number elem, it's just a simple digit. e.g. 9
526 : : * 2) A single range elem, two digits with a '-' between. e.g. 2-6
527 : : * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
528 : : * Within group elem, '-' used for a range separator;
529 : : * ',' used for a single number.
530 : : */
531 : : static int
532 : 0 : parse_queue_set(const char *input, int xtr_type, struct ice_devargs *devargs)
533 : : {
534 : : const char *str = input;
535 : 0 : char *end = NULL;
536 : : uint32_t min, max;
537 : : uint32_t idx;
538 : :
539 [ # # ]: 0 : while (isblank(*str))
540 : 0 : str++;
541 : :
542 [ # # # # ]: 0 : if (!isdigit(*str) && *str != '(')
543 : : return -1;
544 : :
545 : : /* process single number or single range of number */
546 [ # # ]: 0 : if (*str != '(') {
547 : 0 : errno = 0;
548 : 0 : idx = strtoul(str, &end, 10);
549 [ # # # # : 0 : if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
# # ]
550 : : return -1;
551 : :
552 [ # # ]: 0 : while (isblank(*end))
553 : 0 : end++;
554 : :
555 : : min = idx;
556 : : max = idx;
557 : :
558 : : /* process single <number>-<number> */
559 [ # # ]: 0 : if (*end == '-') {
560 : 0 : end++;
561 [ # # ]: 0 : while (isblank(*end))
562 : 0 : end++;
563 [ # # ]: 0 : if (!isdigit(*end))
564 : : return -1;
565 : :
566 : 0 : errno = 0;
567 : 0 : idx = strtoul(end, &end, 10);
568 [ # # # # : 0 : if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
# # ]
569 : : return -1;
570 : :
571 : : max = idx;
572 [ # # ]: 0 : while (isblank(*end))
573 : 0 : end++;
574 : : }
575 : :
576 [ # # ]: 0 : if (*end != ':')
577 : : return -1;
578 : :
579 : 0 : for (idx = RTE_MIN(min, max);
580 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
581 : 0 : devargs->proto_xtr[idx] = xtr_type;
582 : :
583 : : return 0;
584 : : }
585 : :
586 : : /* process set within bracket */
587 : 0 : str++;
588 [ # # ]: 0 : while (isblank(*str))
589 : 0 : str++;
590 [ # # ]: 0 : if (*str == '\0')
591 : : return -1;
592 : :
593 : : min = ICE_MAX_QUEUE_NUM;
594 : : do {
595 : : /* go ahead to the first digit */
596 [ # # ]: 0 : while (isblank(*str))
597 : 0 : str++;
598 [ # # ]: 0 : if (!isdigit(*str))
599 : : return -1;
600 : :
601 : : /* get the digit value */
602 : 0 : errno = 0;
603 : 0 : idx = strtoul(str, &end, 10);
604 [ # # # # : 0 : if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
# # ]
605 : : return -1;
606 : :
607 : : /* go ahead to separator '-',',' and ')' */
608 [ # # ]: 0 : while (isblank(*end))
609 : 0 : end++;
610 [ # # ]: 0 : if (*end == '-') {
611 [ # # ]: 0 : if (min == ICE_MAX_QUEUE_NUM)
612 : : min = idx;
613 : : else /* avoid continuous '-' */
614 : : return -1;
615 [ # # ]: 0 : } else if (*end == ',' || *end == ')') {
616 : : max = idx;
617 [ # # ]: 0 : if (min == ICE_MAX_QUEUE_NUM)
618 : : min = idx;
619 : :
620 : 0 : for (idx = RTE_MIN(min, max);
621 [ # # ]: 0 : idx <= RTE_MAX(min, max); idx++)
622 : 0 : devargs->proto_xtr[idx] = xtr_type;
623 : :
624 : : min = ICE_MAX_QUEUE_NUM;
625 : : } else {
626 : : return -1;
627 : : }
628 : :
629 : 0 : str = end + 1;
630 [ # # ]: 0 : } while (*end != ')' && *end != '\0');
631 : :
632 : : return 0;
633 : : }
634 : :
635 : : static int
636 : 0 : parse_queue_proto_xtr(const char *queues, struct ice_devargs *devargs)
637 : : {
638 : : const char *queue_start;
639 : : uint32_t idx;
640 : : int xtr_type;
641 : : char xtr_name[32];
642 : :
643 [ # # ]: 0 : while (isblank(*queues))
644 : 0 : queues++;
645 : :
646 [ # # ]: 0 : if (*queues != '[') {
647 : 0 : xtr_type = lookup_proto_xtr_type(queues);
648 [ # # ]: 0 : if (xtr_type < 0)
649 : : return -1;
650 : :
651 : 0 : devargs->proto_xtr_dflt = xtr_type;
652 : :
653 : 0 : return 0;
654 : : }
655 : :
656 : 0 : queues++;
657 : : do {
658 [ # # ]: 0 : while (isblank(*queues))
659 : 0 : queues++;
660 [ # # ]: 0 : if (*queues == '\0')
661 : : return -1;
662 : :
663 : : queue_start = queues;
664 : :
665 : : /* go across a complete bracket */
666 [ # # ]: 0 : if (*queue_start == '(') {
667 : 0 : queues += strcspn(queues, ")");
668 [ # # ]: 0 : if (*queues != ')')
669 : : return -1;
670 : : }
671 : :
672 : : /* scan the separator ':' */
673 : 0 : queues += strcspn(queues, ":");
674 [ # # ]: 0 : if (*queues++ != ':')
675 : : return -1;
676 [ # # ]: 0 : while (isblank(*queues))
677 : 0 : queues++;
678 : :
679 : 0 : for (idx = 0; ; idx++) {
680 [ # # # # ]: 0 : if (isblank(queues[idx]) ||
681 [ # # ]: 0 : queues[idx] == ',' ||
682 [ # # ]: 0 : queues[idx] == ']' ||
683 : : queues[idx] == '\0')
684 : : break;
685 : :
686 [ # # ]: 0 : if (idx > sizeof(xtr_name) - 2)
687 : : return -1;
688 : :
689 : 0 : xtr_name[idx] = queues[idx];
690 : : }
691 : 0 : xtr_name[idx] = '\0';
692 : 0 : xtr_type = lookup_proto_xtr_type(xtr_name);
693 [ # # ]: 0 : if (xtr_type < 0)
694 : : return -1;
695 : :
696 : : queues += idx;
697 : :
698 [ # # # # : 0 : while (isblank(*queues) || *queues == ',' || *queues == ']')
# # ]
699 : 0 : queues++;
700 : :
701 [ # # ]: 0 : if (parse_queue_set(queue_start, xtr_type, devargs) < 0)
702 : : return -1;
703 [ # # ]: 0 : } while (*queues != '\0');
704 : :
705 : : return 0;
706 : : }
707 : :
708 : : static int
709 : 0 : handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
710 : : void *extra_args)
711 : : {
712 : : struct ice_devargs *devargs = extra_args;
713 : :
714 [ # # ]: 0 : if (value == NULL || extra_args == NULL)
715 : : return -EINVAL;
716 : :
717 [ # # ]: 0 : if (parse_queue_proto_xtr(value, devargs) < 0) {
718 : 0 : PMD_DRV_LOG(ERR,
719 : : "The protocol extraction parameter is wrong : '%s'",
720 : : value);
721 : 0 : return -1;
722 : : }
723 : :
724 : : return 0;
725 : : }
726 : :
727 : : static int
728 : 0 : handle_field_offs_arg(__rte_unused const char *key, const char *value,
729 : : void *offs_args)
730 : : {
731 : : uint8_t *offset = offs_args;
732 : :
733 [ # # ]: 0 : if (value == NULL || offs_args == NULL)
734 : : return -EINVAL;
735 : :
736 [ # # ]: 0 : if (!isdigit(*value))
737 : : return -1;
738 : :
739 : 0 : *offset = atoi(value);
740 : :
741 : 0 : return 0;
742 : : }
743 : :
744 : : static int
745 : 0 : handle_field_name_arg(__rte_unused const char *key, const char *value,
746 : : void *name_args)
747 : : {
748 : : char *name = name_args;
749 : : int ret;
750 : :
751 [ # # ]: 0 : if (name == NULL || name_args == NULL)
752 : : return -EINVAL;
753 [ # # ]: 0 : if (isdigit(*value))
754 : : return -1;
755 : :
756 : : ret = strlcpy(name, value, RTE_MBUF_DYN_NAMESIZE);
757 [ # # ]: 0 : if (ret < 0 || ret >= RTE_MBUF_DYN_NAMESIZE) {
758 : 0 : PMD_DRV_LOG(ERR,
759 : : "The protocol extraction field name too long : '%s'",
760 : : name);
761 : 0 : return -1;
762 : : }
763 : : return 0;
764 : : }
765 : :
766 : : static int
767 : 0 : handle_ddp_filename_arg(__rte_unused const char *key, const char *value, void *name_args)
768 : : {
769 : : const char **filename = name_args;
770 [ # # ]: 0 : if (strlen(value) >= ICE_MAX_PKG_FILENAME_SIZE) {
771 : 0 : PMD_DRV_LOG(ERR, "The DDP package filename is too long : '%s'", value);
772 : 0 : return -1;
773 : : }
774 : 0 : *filename = strdup(value);
775 : 0 : return 0;
776 : : }
777 : :
778 : : static void
779 : 0 : ice_check_proto_xtr_support(struct ice_hw *hw)
780 : : {
781 : : #define FLX_REG(val, fld, idx) \
782 : : (((val) & GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_M) >> \
783 : : GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_S)
784 : : static struct {
785 : : uint32_t rxdid;
786 : : uint8_t opcode;
787 : : uint8_t protid_0;
788 : : uint8_t protid_1;
789 : : } xtr_sets[] = {
790 : : [PROTO_XTR_VLAN] = { ICE_RXDID_COMMS_AUX_VLAN,
791 : : ICE_RX_OPC_EXTRACT,
792 : : ICE_PROT_EVLAN_O, ICE_PROT_VLAN_O},
793 : : [PROTO_XTR_IPV4] = { ICE_RXDID_COMMS_AUX_IPV4,
794 : : ICE_RX_OPC_EXTRACT,
795 : : ICE_PROT_IPV4_OF_OR_S,
796 : : ICE_PROT_IPV4_OF_OR_S },
797 : : [PROTO_XTR_IPV6] = { ICE_RXDID_COMMS_AUX_IPV6,
798 : : ICE_RX_OPC_EXTRACT,
799 : : ICE_PROT_IPV6_OF_OR_S,
800 : : ICE_PROT_IPV6_OF_OR_S },
801 : : [PROTO_XTR_IPV6_FLOW] = { ICE_RXDID_COMMS_AUX_IPV6_FLOW,
802 : : ICE_RX_OPC_EXTRACT,
803 : : ICE_PROT_IPV6_OF_OR_S,
804 : : ICE_PROT_IPV6_OF_OR_S },
805 : : [PROTO_XTR_TCP] = { ICE_RXDID_COMMS_AUX_TCP,
806 : : ICE_RX_OPC_EXTRACT,
807 : : ICE_PROT_TCP_IL, ICE_PROT_ID_INVAL },
808 : : [PROTO_XTR_IP_OFFSET] = { ICE_RXDID_COMMS_AUX_IP_OFFSET,
809 : : ICE_RX_OPC_PROTID,
810 : : ICE_PROT_IPV4_OF_OR_S,
811 : : ICE_PROT_IPV6_OF_OR_S },
812 : : };
813 : : uint32_t i;
814 : :
815 [ # # ]: 0 : for (i = 0; i < RTE_DIM(xtr_sets); i++) {
816 : 0 : uint32_t rxdid = xtr_sets[i].rxdid;
817 : : uint32_t v;
818 : :
819 [ # # ]: 0 : if (xtr_sets[i].protid_0 != ICE_PROT_ID_INVAL) {
820 : 0 : v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_4(rxdid));
821 : :
822 [ # # ]: 0 : if (FLX_REG(v, PROT_MDID, 4) == xtr_sets[i].protid_0 &&
823 [ # # ]: 0 : FLX_REG(v, RXDID_OPCODE, 4) == xtr_sets[i].opcode)
824 : 0 : ice_proto_xtr_hw_support[i] = true;
825 : : }
826 : :
827 [ # # ]: 0 : if (xtr_sets[i].protid_1 != ICE_PROT_ID_INVAL) {
828 : 0 : v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_5(rxdid));
829 : :
830 [ # # ]: 0 : if (FLX_REG(v, PROT_MDID, 5) == xtr_sets[i].protid_1 &&
831 [ # # ]: 0 : FLX_REG(v, RXDID_OPCODE, 5) == xtr_sets[i].opcode)
832 : 0 : ice_proto_xtr_hw_support[i] = true;
833 : : }
834 : : }
835 : 0 : }
836 : :
837 : : static int
838 : 0 : ice_res_pool_init(struct ice_res_pool_info *pool, uint32_t base,
839 : : uint32_t num)
840 : : {
841 : : struct pool_entry *entry;
842 : :
843 [ # # ]: 0 : if (!pool || !num)
844 : : return -EINVAL;
845 : :
846 : 0 : entry = rte_zmalloc(NULL, sizeof(*entry), 0);
847 [ # # ]: 0 : if (!entry) {
848 : 0 : PMD_INIT_LOG(ERR,
849 : : "Failed to allocate memory for resource pool");
850 : 0 : return -ENOMEM;
851 : : }
852 : :
853 : : /* queue heap initialize */
854 : 0 : pool->num_free = num;
855 : 0 : pool->num_alloc = 0;
856 : 0 : pool->base = base;
857 : 0 : LIST_INIT(&pool->alloc_list);
858 : : LIST_INIT(&pool->free_list);
859 : :
860 : : /* Initialize element */
861 : 0 : entry->base = 0;
862 : 0 : entry->len = num;
863 : :
864 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
865 : 0 : return 0;
866 : : }
867 : :
868 : : static int
869 : 0 : ice_res_pool_alloc(struct ice_res_pool_info *pool,
870 : : uint16_t num)
871 : : {
872 : : struct pool_entry *entry, *valid_entry;
873 : :
874 [ # # ]: 0 : if (!pool || !num) {
875 : 0 : PMD_INIT_LOG(ERR, "Invalid parameter");
876 : 0 : return -EINVAL;
877 : : }
878 : :
879 [ # # ]: 0 : if (pool->num_free < num) {
880 : 0 : PMD_INIT_LOG(ERR, "No resource. ask:%u, available:%u",
881 : : num, pool->num_free);
882 : 0 : return -ENOMEM;
883 : : }
884 : :
885 : : valid_entry = NULL;
886 : : /* Lookup in free list and find most fit one */
887 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
888 [ # # ]: 0 : if (entry->len >= num) {
889 : : /* Find best one */
890 [ # # ]: 0 : if (entry->len == num) {
891 : : valid_entry = entry;
892 : : break;
893 : : }
894 [ # # ]: 0 : if (!valid_entry ||
895 [ # # ]: 0 : valid_entry->len > entry->len)
896 : : valid_entry = entry;
897 : : }
898 : : }
899 : :
900 : : /* Not find one to satisfy the request, return */
901 [ # # ]: 0 : if (!valid_entry) {
902 : 0 : PMD_INIT_LOG(ERR, "No valid entry found");
903 : 0 : return -ENOMEM;
904 : : }
905 : : /**
906 : : * The entry have equal queue number as requested,
907 : : * remove it from alloc_list.
908 : : */
909 [ # # ]: 0 : if (valid_entry->len == num) {
910 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
911 : : } else {
912 : : /**
913 : : * The entry have more numbers than requested,
914 : : * create a new entry for alloc_list and minus its
915 : : * queue base and number in free_list.
916 : : */
917 : 0 : entry = rte_zmalloc(NULL, sizeof(*entry), 0);
918 [ # # ]: 0 : if (!entry) {
919 : 0 : PMD_INIT_LOG(ERR,
920 : : "Failed to allocate memory for "
921 : : "resource pool");
922 : 0 : return -ENOMEM;
923 : : }
924 : 0 : entry->base = valid_entry->base;
925 : 0 : entry->len = num;
926 : 0 : valid_entry->base += num;
927 : 0 : valid_entry->len -= num;
928 : : valid_entry = entry;
929 : : }
930 : :
931 : : /* Insert it into alloc list, not sorted */
932 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
933 : :
934 : 0 : pool->num_free -= valid_entry->len;
935 : 0 : pool->num_alloc += valid_entry->len;
936 : :
937 : 0 : return valid_entry->base + pool->base;
938 : : }
939 : :
940 : : static void
941 : 0 : ice_res_pool_destroy(struct ice_res_pool_info *pool)
942 : : {
943 : : struct pool_entry *entry, *next_entry;
944 : :
945 [ # # ]: 0 : if (!pool)
946 : : return;
947 : :
948 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->alloc_list); entry; entry = next_entry) {
949 : 0 : next_entry = LIST_NEXT(entry, next);
950 [ # # ]: 0 : LIST_REMOVE(entry, next);
951 : 0 : rte_free(entry);
952 : : }
953 : :
954 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->free_list); entry; entry = next_entry) {
955 : 0 : next_entry = LIST_NEXT(entry, next);
956 [ # # ]: 0 : LIST_REMOVE(entry, next);
957 : 0 : rte_free(entry);
958 : : }
959 : :
960 : 0 : pool->num_free = 0;
961 : 0 : pool->num_alloc = 0;
962 : 0 : pool->base = 0;
963 : 0 : LIST_INIT(&pool->alloc_list);
964 : 0 : LIST_INIT(&pool->free_list);
965 : : }
966 : :
967 : : static void
968 : : ice_vsi_config_default_rss(struct ice_aqc_vsi_props *info)
969 : : {
970 : : /* Set VSI LUT selection */
971 : : info->q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI &
972 : : ICE_AQ_VSI_Q_OPT_RSS_LUT_M;
973 : : /* Set Hash scheme */
974 : : info->q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_TPLZ &
975 : : ICE_AQ_VSI_Q_OPT_RSS_HASH_M;
976 : : /* enable TC */
977 : 0 : info->q_opt_tc = ICE_AQ_VSI_Q_OPT_TC_OVR_M;
978 : : }
979 : :
980 : : static int
981 : 0 : ice_vsi_config_tc_queue_mapping(struct ice_hw *hw, struct ice_vsi *vsi,
982 : : struct ice_aqc_vsi_props *info,
983 : : uint8_t enabled_tcmap)
984 : : {
985 : : uint16_t fls, qp_idx;
986 : :
987 : : /* default tc 0 now. Multi-TC supporting need to be done later.
988 : : * Configure TC and queue mapping parameters, for enabled TC,
989 : : * allocate qpnum_per_tc queues to this traffic.
990 : : */
991 [ # # ]: 0 : if (enabled_tcmap != 0x01) {
992 : 0 : PMD_INIT_LOG(ERR, "only TC0 is supported");
993 : 0 : return -ENOTSUP;
994 : : }
995 : :
996 : : /* vector 0 is reserved and 1 vector for ctrl vsi */
997 [ # # ]: 0 : if (vsi->adapter->hw.func_caps.common_cap.num_msix_vectors < 2) {
998 : 0 : vsi->nb_qps = 0;
999 : : } else {
1000 : 0 : vsi->nb_qps = RTE_MIN(vsi->nb_qps, ICE_MAX_Q_PER_TC);
1001 : 0 : vsi->nb_qps = RTE_MIN(vsi->nb_qps,
1002 : : (uint16_t)vsi->adapter->hw.func_caps.common_cap.num_msix_vectors - 2);
1003 : :
1004 : : /* cap max QPs to what the HW reports as num-children for each layer.
1005 : : * Multiply num_children for each layer from the entry_point layer to
1006 : : * the qgroup, or second-last layer.
1007 : : * Avoid any potential overflow by using uint32_t type and breaking loop
1008 : : * once we have a number greater than the already configured max.
1009 : : */
1010 : : uint32_t max_sched_vsi_nodes = 1;
1011 [ # # ]: 0 : for (uint8_t i = hw->sw_entry_point_layer; i < hw->num_tx_sched_layers - 1; i++) {
1012 : 0 : max_sched_vsi_nodes *= hw->max_children[i];
1013 [ # # ]: 0 : if (max_sched_vsi_nodes >= vsi->nb_qps)
1014 : : break;
1015 : : }
1016 : 0 : vsi->nb_qps = RTE_MIN(vsi->nb_qps, max_sched_vsi_nodes);
1017 : : }
1018 : :
1019 : : /* nb_qps(hex) -> fls */
1020 : : /* 0000 -> 0 */
1021 : : /* 0001 -> 0 */
1022 : : /* 0002 -> 1 */
1023 : : /* 0003 ~ 0004 -> 2 */
1024 : : /* 0005 ~ 0008 -> 3 */
1025 : : /* 0009 ~ 0010 -> 4 */
1026 : : /* 0011 ~ 0020 -> 5 */
1027 : : /* 0021 ~ 0040 -> 6 */
1028 : : /* 0041 ~ 0080 -> 7 */
1029 : : /* 0081 ~ 0100 -> 8 */
1030 [ # # # # ]: 0 : fls = (vsi->nb_qps == 0) ? 0 : rte_fls_u32(vsi->nb_qps - 1);
1031 : :
1032 : : qp_idx = 0;
1033 : : /* Set tc and queue mapping with VSI */
1034 : 0 : info->tc_mapping[0] = rte_cpu_to_le_16((qp_idx <<
1035 : : ICE_AQ_VSI_TC_Q_OFFSET_S) |
1036 : : (fls << ICE_AQ_VSI_TC_Q_NUM_S));
1037 : :
1038 : : /* Associate queue number with VSI */
1039 : 0 : info->mapping_flags |= rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
1040 : 0 : info->q_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
1041 : 0 : info->q_mapping[1] = rte_cpu_to_le_16(vsi->nb_qps);
1042 : 0 : info->valid_sections |=
1043 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
1044 : : /* Set the info.ingress_table and info.egress_table
1045 : : * for UP translate table. Now just set it to 1:1 map by default
1046 : : * -- 0b 111 110 101 100 011 010 001 000 == 0xFAC688
1047 : : */
1048 : : #define ICE_TC_QUEUE_TABLE_DFLT 0x00FAC688
1049 : 0 : info->ingress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
1050 : 0 : info->egress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
1051 : 0 : info->outer_up_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
1052 : 0 : return 0;
1053 : : }
1054 : :
1055 : : static int
1056 : 0 : ice_init_mac_address(struct rte_eth_dev *dev)
1057 : : {
1058 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1059 : 0 : struct ice_adapter *ad = (struct ice_adapter *)hw->back;
1060 : :
1061 [ # # ]: 0 : if (!rte_is_unicast_ether_addr
1062 [ # # ]: 0 : ((struct rte_ether_addr *)hw->port_info[0].mac.lan_addr)) {
1063 : 0 : PMD_INIT_LOG(ERR, "Invalid MAC address");
1064 : 0 : return -EINVAL;
1065 : : }
1066 : :
1067 : : rte_ether_addr_copy(
1068 : : (struct rte_ether_addr *)hw->port_info[0].mac.lan_addr,
1069 : : (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr);
1070 : :
1071 : 0 : dev->data->mac_addrs =
1072 : 0 : rte_zmalloc(NULL, sizeof(struct rte_ether_addr) * ICE_NUM_MACADDR_MAX, 0);
1073 [ # # ]: 0 : if (!dev->data->mac_addrs) {
1074 : 0 : PMD_INIT_LOG(ERR,
1075 : : "Failed to allocate memory to store mac address");
1076 : 0 : return -ENOMEM;
1077 : : }
1078 : : /* store it to dev data */
1079 [ # # ]: 0 : if (ad->devargs.default_mac_disable != 1)
1080 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)hw->port_info[0].mac.perm_addr,
1081 : : &dev->data->mac_addrs[0]);
1082 : : return 0;
1083 : : }
1084 : :
1085 : : /* Find out specific MAC filter */
1086 : : static struct ice_mac_filter *
1087 : : ice_find_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *macaddr)
1088 : : {
1089 : : struct ice_mac_filter *f;
1090 : :
1091 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
1092 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
1093 : : return f;
1094 : : }
1095 : :
1096 : : return NULL;
1097 : : }
1098 : :
1099 : : static int
1100 : 0 : ice_add_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
1101 : : {
1102 : : struct ice_fltr_list_entry *m_list_itr = NULL;
1103 : : struct ice_mac_filter *f;
1104 : : struct LIST_HEAD_TYPE list_head;
1105 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
1106 : 0 : struct ice_adapter *ad = (struct ice_adapter *)hw->back;
1107 : : int ret = 0;
1108 : :
1109 [ # # # # ]: 0 : if (ad->devargs.default_mac_disable == 1 && rte_is_same_ether_addr(mac_addr,
1110 [ # # ]: 0 : (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr)) {
1111 : 0 : PMD_DRV_LOG(ERR, "This Default MAC filter is disabled.");
1112 : 0 : return 0;
1113 : : }
1114 : : /* If it's added and configured, return */
1115 : : f = ice_find_mac_filter(vsi, mac_addr);
1116 [ # # ]: 0 : if (f) {
1117 : 0 : PMD_DRV_LOG(INFO, "This MAC filter already exists.");
1118 : 0 : return 0;
1119 : : }
1120 : :
1121 : 0 : INIT_LIST_HEAD(&list_head);
1122 : :
1123 : : m_list_itr = (struct ice_fltr_list_entry *)
1124 : 0 : ice_malloc(hw, sizeof(*m_list_itr));
1125 [ # # ]: 0 : if (!m_list_itr) {
1126 : : ret = -ENOMEM;
1127 : 0 : goto DONE;
1128 : : }
1129 [ # # ]: 0 : ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
1130 : : mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
1131 : 0 : m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1132 : 0 : m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1133 : 0 : m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
1134 : 0 : m_list_itr->fltr_info.flag = ICE_FLTR_TX;
1135 : 0 : m_list_itr->fltr_info.vsi_handle = vsi->idx;
1136 : :
1137 [ # # ]: 0 : LIST_ADD(&m_list_itr->list_entry, &list_head);
1138 : :
1139 : : /* Add the mac */
1140 : 0 : ret = ice_add_mac(hw, &list_head);
1141 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1142 : 0 : PMD_DRV_LOG(ERR, "Failed to add MAC filter");
1143 : : ret = -EINVAL;
1144 : 0 : goto DONE;
1145 : : }
1146 : : /* Add the mac addr into mac list */
1147 : 0 : f = rte_zmalloc(NULL, sizeof(*f), 0);
1148 [ # # ]: 0 : if (!f) {
1149 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
1150 : : ret = -ENOMEM;
1151 : 0 : goto DONE;
1152 : : }
1153 : : rte_ether_addr_copy(mac_addr, &f->mac_info.mac_addr);
1154 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
1155 : 0 : vsi->mac_num++;
1156 : :
1157 : : ret = 0;
1158 : :
1159 : 0 : DONE:
1160 : 0 : rte_free(m_list_itr);
1161 : 0 : return ret;
1162 : : }
1163 : :
1164 : : static int
1165 : 0 : ice_remove_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
1166 : : {
1167 : : struct ice_fltr_list_entry *m_list_itr = NULL;
1168 : : struct ice_mac_filter *f;
1169 : : struct LIST_HEAD_TYPE list_head;
1170 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
1171 : : int ret = 0;
1172 : :
1173 : : /* Can't find it, return an error */
1174 : : f = ice_find_mac_filter(vsi, mac_addr);
1175 [ # # ]: 0 : if (!f)
1176 : : return -EINVAL;
1177 : :
1178 : 0 : INIT_LIST_HEAD(&list_head);
1179 : :
1180 : : m_list_itr = (struct ice_fltr_list_entry *)
1181 : 0 : ice_malloc(hw, sizeof(*m_list_itr));
1182 [ # # ]: 0 : if (!m_list_itr) {
1183 : : ret = -ENOMEM;
1184 : 0 : goto DONE;
1185 : : }
1186 [ # # ]: 0 : ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
1187 : : mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
1188 : 0 : m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1189 : 0 : m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1190 : 0 : m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
1191 : 0 : m_list_itr->fltr_info.flag = ICE_FLTR_TX;
1192 : 0 : m_list_itr->fltr_info.vsi_handle = vsi->idx;
1193 : :
1194 [ # # ]: 0 : LIST_ADD(&m_list_itr->list_entry, &list_head);
1195 : :
1196 : : /* remove the mac filter */
1197 : 0 : ret = ice_remove_mac(hw, &list_head);
1198 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1199 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
1200 : : ret = -EINVAL;
1201 : 0 : goto DONE;
1202 : : }
1203 : :
1204 : : /* Remove the mac addr from mac list */
1205 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
1206 : 0 : rte_free(f);
1207 : 0 : vsi->mac_num--;
1208 : :
1209 : : ret = 0;
1210 : 0 : DONE:
1211 : 0 : rte_free(m_list_itr);
1212 : 0 : return ret;
1213 : : }
1214 : :
1215 : : /* Find out specific VLAN filter */
1216 : : static struct ice_vlan_filter *
1217 : : ice_find_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1218 : : {
1219 : : struct ice_vlan_filter *f;
1220 : :
1221 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->vlan_list, next) {
1222 [ # # # # ]: 0 : if (vlan->tpid == f->vlan_info.vlan.tpid &&
1223 [ # # # # ]: 0 : vlan->vid == f->vlan_info.vlan.vid)
1224 : : return f;
1225 : : }
1226 : :
1227 : : return NULL;
1228 : : }
1229 : :
1230 : : static int
1231 : 0 : ice_add_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1232 : : {
1233 : : struct ice_fltr_list_entry *v_list_itr = NULL;
1234 : : struct ice_vlan_filter *f;
1235 : : struct LIST_HEAD_TYPE list_head;
1236 : : struct ice_hw *hw;
1237 : : int ret = 0;
1238 : :
1239 [ # # # # ]: 0 : if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1240 : : return -EINVAL;
1241 : :
1242 : 0 : hw = ICE_VSI_TO_HW(vsi);
1243 : :
1244 : : /* If it's added and configured, return. */
1245 : : f = ice_find_vlan_filter(vsi, vlan);
1246 [ # # ]: 0 : if (f) {
1247 : 0 : PMD_DRV_LOG(INFO, "This VLAN filter already exists.");
1248 : 0 : return 0;
1249 : : }
1250 : :
1251 [ # # ]: 0 : if (!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on)
1252 : : return 0;
1253 : :
1254 : 0 : INIT_LIST_HEAD(&list_head);
1255 : :
1256 : : v_list_itr = (struct ice_fltr_list_entry *)
1257 : 0 : ice_malloc(hw, sizeof(*v_list_itr));
1258 [ # # ]: 0 : if (!v_list_itr) {
1259 : : ret = -ENOMEM;
1260 : 0 : goto DONE;
1261 : : }
1262 : 0 : v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1263 : 0 : v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1264 : 0 : v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1265 : 0 : v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1266 : 0 : v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1267 : 0 : v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1268 : 0 : v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1269 : 0 : v_list_itr->fltr_info.vsi_handle = vsi->idx;
1270 : :
1271 [ # # ]: 0 : LIST_ADD(&v_list_itr->list_entry, &list_head);
1272 : :
1273 : : /* Add the vlan */
1274 : 0 : ret = ice_add_vlan(hw, &list_head);
1275 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1276 : 0 : PMD_DRV_LOG(ERR, "Failed to add VLAN filter");
1277 : : ret = -EINVAL;
1278 : 0 : goto DONE;
1279 : : }
1280 : :
1281 : : /* Add vlan into vlan list */
1282 : 0 : f = rte_zmalloc(NULL, sizeof(*f), 0);
1283 [ # # ]: 0 : if (!f) {
1284 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
1285 : : ret = -ENOMEM;
1286 : 0 : goto DONE;
1287 : : }
1288 : 0 : f->vlan_info.vlan.tpid = vlan->tpid;
1289 : 0 : f->vlan_info.vlan.vid = vlan->vid;
1290 : 0 : TAILQ_INSERT_TAIL(&vsi->vlan_list, f, next);
1291 : 0 : vsi->vlan_num++;
1292 : :
1293 : : ret = 0;
1294 : :
1295 : 0 : DONE:
1296 : 0 : rte_free(v_list_itr);
1297 : 0 : return ret;
1298 : : }
1299 : :
1300 : : static int
1301 : 0 : ice_remove_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1302 : : {
1303 : : struct ice_fltr_list_entry *v_list_itr = NULL;
1304 : : struct ice_vlan_filter *f;
1305 : : struct LIST_HEAD_TYPE list_head;
1306 : : struct ice_hw *hw;
1307 : : int ret = 0;
1308 : :
1309 [ # # # # ]: 0 : if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1310 : : return -EINVAL;
1311 : :
1312 : 0 : hw = ICE_VSI_TO_HW(vsi);
1313 : :
1314 : : /* Can't find it, return an error */
1315 : : f = ice_find_vlan_filter(vsi, vlan);
1316 [ # # ]: 0 : if (!f)
1317 : : return -EINVAL;
1318 : :
1319 : 0 : INIT_LIST_HEAD(&list_head);
1320 : :
1321 : : v_list_itr = (struct ice_fltr_list_entry *)
1322 : 0 : ice_malloc(hw, sizeof(*v_list_itr));
1323 [ # # ]: 0 : if (!v_list_itr) {
1324 : : ret = -ENOMEM;
1325 : 0 : goto DONE;
1326 : : }
1327 : :
1328 : 0 : v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1329 : 0 : v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1330 : 0 : v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1331 : 0 : v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1332 : 0 : v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1333 : 0 : v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1334 : 0 : v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1335 : 0 : v_list_itr->fltr_info.vsi_handle = vsi->idx;
1336 : :
1337 [ # # ]: 0 : LIST_ADD(&v_list_itr->list_entry, &list_head);
1338 : :
1339 : : /* remove the vlan filter */
1340 : 0 : ret = ice_remove_vlan(hw, &list_head);
1341 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1342 : 0 : PMD_DRV_LOG(ERR, "Failed to remove VLAN filter");
1343 : : ret = -EINVAL;
1344 : 0 : goto DONE;
1345 : : }
1346 : :
1347 : : /* Remove the vlan id from vlan list */
1348 [ # # ]: 0 : TAILQ_REMOVE(&vsi->vlan_list, f, next);
1349 : 0 : rte_free(f);
1350 : 0 : vsi->vlan_num--;
1351 : :
1352 : : ret = 0;
1353 : 0 : DONE:
1354 : 0 : rte_free(v_list_itr);
1355 : 0 : return ret;
1356 : : }
1357 : :
1358 : : static int
1359 : 0 : ice_remove_all_mac_vlan_filters(struct ice_vsi *vsi)
1360 : : {
1361 : : struct ice_mac_filter *m_f;
1362 : : struct ice_vlan_filter *v_f;
1363 : : void *temp;
1364 : : int ret = 0;
1365 : :
1366 [ # # # # ]: 0 : if (!vsi || !vsi->mac_num)
1367 : : return -EINVAL;
1368 : :
1369 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(m_f, &vsi->mac_list, next, temp) {
1370 : 0 : ret = ice_remove_mac_filter(vsi, &m_f->mac_info.mac_addr);
1371 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1372 : : ret = -EINVAL;
1373 : 0 : goto DONE;
1374 : : }
1375 : : }
1376 : :
1377 [ # # ]: 0 : if (vsi->vlan_num == 0)
1378 : : return 0;
1379 : :
1380 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(v_f, &vsi->vlan_list, next, temp) {
1381 : 0 : ret = ice_remove_vlan_filter(vsi, &v_f->vlan_info.vlan);
1382 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1383 : : ret = -EINVAL;
1384 : 0 : goto DONE;
1385 : : }
1386 : : }
1387 : :
1388 : 0 : DONE:
1389 : : return ret;
1390 : : }
1391 : :
1392 : : /* Enable IRQ0 */
1393 : : static void
1394 : 0 : ice_pf_enable_irq0(struct ice_hw *hw)
1395 : : {
1396 : : /* reset the registers */
1397 : 0 : ICE_WRITE_REG(hw, PFINT_OICR_ENA, 0);
1398 : 0 : ICE_READ_REG(hw, PFINT_OICR);
1399 : :
1400 : : /* Enable all OICR causes except link-state-change: LSC is delivered
1401 : : * as an unsolicited AdminQ get-link-status notification.
1402 : : */
1403 : 0 : ICE_WRITE_REG(hw, PFINT_OICR_ENA,
1404 : : (uint32_t)(PFINT_OICR_ENA_INT_ENA_M &
1405 : : (~PFINT_OICR_LINK_STAT_CHANGE_M)));
1406 : :
1407 : 0 : ICE_WRITE_REG(hw, PFINT_OICR_CTL,
1408 : : (0 & PFINT_OICR_CTL_MSIX_INDX_M) |
1409 : : ((0 << PFINT_OICR_CTL_ITR_INDX_S) &
1410 : : PFINT_OICR_CTL_ITR_INDX_M) |
1411 : : PFINT_OICR_CTL_CAUSE_ENA_M);
1412 : :
1413 : 0 : ICE_WRITE_REG(hw, PFINT_FW_CTL,
1414 : : (0 & PFINT_FW_CTL_MSIX_INDX_M) |
1415 : : ((0 << PFINT_FW_CTL_ITR_INDX_S) &
1416 : : PFINT_FW_CTL_ITR_INDX_M) |
1417 : : PFINT_FW_CTL_CAUSE_ENA_M);
1418 : :
1419 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
1420 : : GLINT_DYN_CTL_INTENA_M |
1421 : : GLINT_DYN_CTL_CLEARPBA_M |
1422 : : GLINT_DYN_CTL_ITR_INDX_M);
1423 : :
1424 : 0 : ice_flush(hw);
1425 : 0 : }
1426 : :
1427 : : /* Disable IRQ0 */
1428 : : static void
1429 : : ice_pf_disable_irq0(struct ice_hw *hw)
1430 : : {
1431 : : /* Disable all interrupt types */
1432 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
1433 : 0 : ice_flush(hw);
1434 : : }
1435 : :
1436 : : static void
1437 : 0 : ice_handle_aq_msg(struct rte_eth_dev *dev)
1438 : : {
1439 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1440 : 0 : struct ice_ctl_q_info *cq = &hw->adminq;
1441 : 0 : unsigned char buf[ICE_AQ_MAX_BUF_LEN] = {0};
1442 : 0 : struct ice_rq_event_info event = {
1443 : : .msg_buf = buf,
1444 : : .buf_len = sizeof(buf),
1445 : : };
1446 : : uint16_t pending, opcode;
1447 : : int ret;
1448 : :
1449 : 0 : pending = 1;
1450 [ # # ]: 0 : while (pending) {
1451 : 0 : ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1452 : :
1453 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1454 [ # # ]: 0 : if (hw->adminq.sq_last_status != 0)
1455 : 0 : PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ, adminq_err: %u",
1456 : : hw->adminq.sq_last_status);
1457 : : break;
1458 : : }
1459 : 0 : opcode = rte_le_to_cpu_16(event.desc.opcode);
1460 : :
1461 [ # # ]: 0 : switch (opcode) {
1462 : 0 : case ice_aqc_opc_get_link_status:
1463 : 0 : ret = ice_link_update(dev, 0);
1464 [ # # ]: 0 : if (!ret)
1465 : 0 : rte_eth_dev_callback_process
1466 : : (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1467 : : break;
1468 : 0 : default:
1469 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
1470 : : opcode);
1471 : 0 : break;
1472 : : }
1473 : : }
1474 : 0 : }
1475 : :
1476 : : /**
1477 : : * Interrupt handler triggered by NIC for handling
1478 : : * specific interrupt.
1479 : : *
1480 : : * @param handle
1481 : : * Pointer to interrupt handle.
1482 : : * @param param
1483 : : * The address of parameter (struct rte_eth_dev *) registered before.
1484 : : *
1485 : : * @return
1486 : : * void
1487 : : */
1488 : : static void
1489 : 0 : ice_interrupt_handler(void *param)
1490 : : {
1491 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1492 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1493 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
1494 : : uint32_t oicr;
1495 : : uint32_t reg;
1496 : : uint8_t pf_num;
1497 : : uint8_t event;
1498 : : uint16_t queue;
1499 : :
1500 : : /* Disable interrupt */
1501 : : ice_pf_disable_irq0(hw);
1502 : :
1503 : : /* read out interrupt causes */
1504 : 0 : oicr = ICE_READ_REG(hw, PFINT_OICR);
1505 : :
1506 : : /* No interrupt event indicated */
1507 [ # # ]: 0 : if (!(oicr & PFINT_OICR_INTEVENT_M)) {
1508 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
1509 : 0 : goto done;
1510 : : }
1511 : :
1512 : : /* Always drain the AdminQ on any misc interrupt. */
1513 : 0 : ice_handle_aq_msg(dev);
1514 : :
1515 [ # # ]: 0 : if (oicr & PFINT_OICR_MAL_DETECT_M) {
1516 : 0 : PMD_DRV_LOG(WARNING, "OICR: MDD event");
1517 : 0 : reg = ICE_READ_REG(hw, GL_MDET_TX_PQM);
1518 [ # # ]: 0 : if (reg & GL_MDET_TX_PQM_VALID_M) {
1519 : 0 : pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1520 : : GL_MDET_TX_PQM_PF_NUM_S;
1521 : 0 : event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1522 : : GL_MDET_TX_PQM_MAL_TYPE_S;
1523 : 0 : queue = (reg & GL_MDET_TX_PQM_QNUM_M) >>
1524 : : GL_MDET_TX_PQM_QNUM_S;
1525 : :
1526 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1527 : : "%d by PQM on TX queue %d PF# %d",
1528 : : event, queue, pf_num);
1529 : : }
1530 : :
1531 : 0 : reg = ICE_READ_REG(hw, GL_MDET_TX_TCLAN);
1532 [ # # ]: 0 : if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1533 : 0 : pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1534 : : GL_MDET_TX_TCLAN_PF_NUM_S;
1535 : 0 : event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1536 : : GL_MDET_TX_TCLAN_MAL_TYPE_S;
1537 : 0 : queue = (reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1538 : : GL_MDET_TX_TCLAN_QNUM_S;
1539 : :
1540 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1541 : : "%d by TCLAN on TX queue %d PF# %d",
1542 : : event, queue, pf_num);
1543 : : }
1544 : :
1545 : 0 : reg = ICE_READ_REG(hw, GL_MDET_TX_TDPU);
1546 [ # # ]: 0 : if (reg & GL_MDET_TX_TDPU_VALID_M) {
1547 : 0 : pf_num = (reg & GL_MDET_TX_TDPU_PF_NUM_M) >>
1548 : : GL_MDET_TX_TDPU_PF_NUM_S;
1549 : 0 : event = (reg & GL_MDET_TX_TDPU_MAL_TYPE_M) >>
1550 : : GL_MDET_TX_TDPU_MAL_TYPE_S;
1551 : 0 : queue = (reg & GL_MDET_TX_TDPU_QNUM_M) >>
1552 : : GL_MDET_TX_TDPU_QNUM_S;
1553 : :
1554 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1555 : : "%d by TDPU on TX queue %d PF# %d",
1556 : : event, queue, pf_num);
1557 : : }
1558 : : }
1559 : 0 : done:
1560 : : /* Enable interrupt */
1561 : 0 : ice_pf_enable_irq0(hw);
1562 : 0 : rte_intr_ack(pci_dev->intr_handle);
1563 : :
1564 : : /* Re-drain AdminQ to catch events that arrived during the CLEARPBA window */
1565 : 0 : ice_handle_aq_msg(dev);
1566 : 0 : }
1567 : :
1568 : : static void
1569 : 0 : ice_init_proto_xtr(struct rte_eth_dev *dev)
1570 : : {
1571 : 0 : struct ice_adapter *ad =
1572 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1573 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1574 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1575 : : const struct proto_xtr_ol_flag *ol_flag;
1576 : : bool proto_xtr_enable = false;
1577 : : int offset, field_offs;
1578 : : uint16_t i;
1579 : :
1580 : 0 : pf->proto_xtr = rte_zmalloc(NULL, pf->lan_nb_qps, 0);
1581 [ # # ]: 0 : if (unlikely(pf->proto_xtr == NULL)) {
1582 : 0 : PMD_DRV_LOG(ERR, "No memory for setting up protocol extraction table");
1583 : 0 : return;
1584 : : }
1585 : :
1586 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
1587 [ # # ]: 0 : pf->proto_xtr[i] = ad->devargs.proto_xtr[i] != PROTO_XTR_NONE ?
1588 : : ad->devargs.proto_xtr[i] :
1589 : : ad->devargs.proto_xtr_dflt;
1590 : :
1591 [ # # ]: 0 : if (pf->proto_xtr[i] != PROTO_XTR_NONE) {
1592 : : uint8_t type = pf->proto_xtr[i];
1593 : :
1594 : 0 : ice_proto_xtr_ol_flag_params[type].required = true;
1595 : : proto_xtr_enable = true;
1596 : : }
1597 : : }
1598 : :
1599 [ # # ]: 0 : if (likely(!proto_xtr_enable)) {
1600 : 0 : ad->devargs.xtr_field_offs = -1;
1601 : 0 : return;
1602 : : }
1603 : :
1604 : 0 : ice_check_proto_xtr_support(hw);
1605 : :
1606 : : /*check mbuf dynfield*/
1607 : 0 : field_offs = rte_mbuf_dynfield_lookup(ad->devargs.xtr_field_name, NULL);
1608 [ # # ]: 0 : if (ad->devargs.xtr_field_offs == field_offs) {
1609 : 0 : PMD_DRV_LOG(DEBUG,
1610 : : "Protocol extraction metadata offset in mbuf is : %d",
1611 : : ad->devargs.xtr_field_offs);
1612 : : } else {
1613 : 0 : PMD_DRV_LOG(ERR, "Invalid field offset or name, no match dynfield, [%d],[%s]",
1614 : : ad->devargs.xtr_field_offs, ad->devargs.xtr_field_name);
1615 : 0 : ad->devargs.xtr_field_offs = -1;
1616 : 0 : return;
1617 : : }
1618 : :
1619 : 0 : PMD_DRV_LOG(DEBUG,
1620 : : "Protocol extraction metadata offset in mbuf is : %d",
1621 : : ad->devargs.xtr_field_offs);
1622 : :
1623 [ # # ]: 0 : for (i = 0; i < RTE_DIM(ice_proto_xtr_ol_flag_params); i++) {
1624 : 0 : ol_flag = &ice_proto_xtr_ol_flag_params[i];
1625 : :
1626 : 0 : ad->devargs.xtr_flag_offs[i] = 0xff;
1627 : :
1628 [ # # ]: 0 : if (!ol_flag->required)
1629 : 0 : continue;
1630 : :
1631 [ # # ]: 0 : if (!ice_proto_xtr_hw_support[i]) {
1632 : 0 : PMD_DRV_LOG(ERR,
1633 : : "Protocol extraction type %u is not supported in hardware",
1634 : : i);
1635 : 0 : ad->devargs.xtr_field_offs = -1;
1636 : 0 : break;
1637 : : }
1638 : :
1639 : 0 : offset = rte_mbuf_dynflag_register(&ol_flag->param);
1640 [ # # ]: 0 : if (unlikely(offset == -1)) {
1641 : 0 : PMD_DRV_LOG(ERR,
1642 : : "Protocol extraction offload '%s' failed to register with error %d",
1643 : : ol_flag->param.name, -rte_errno);
1644 : :
1645 : 0 : ad->devargs.xtr_field_offs = -1;
1646 : 0 : break;
1647 : : }
1648 : :
1649 : 0 : PMD_DRV_LOG(DEBUG,
1650 : : "Protocol extraction offload '%s' offset in mbuf is : %d",
1651 : : ol_flag->param.name, offset);
1652 : :
1653 : 0 : ad->devargs.xtr_flag_offs[i] = offset;
1654 : : }
1655 : : }
1656 : :
1657 : : /* Initialize SW parameters of PF */
1658 : : static int
1659 : 0 : ice_pf_sw_init(struct rte_eth_dev *dev)
1660 : : {
1661 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1662 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1663 : :
1664 : 0 : pf->lan_nb_qp_max =
1665 : 0 : (uint16_t)RTE_MIN(hw->func_caps.common_cap.num_txq,
1666 : : hw->func_caps.common_cap.num_rxq);
1667 : :
1668 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
1669 : :
1670 : 0 : ice_init_proto_xtr(dev);
1671 : :
1672 [ # # ]: 0 : if (hw->func_caps.fd_fltr_guar > 0 ||
1673 [ # # ]: 0 : hw->func_caps.fd_fltr_best_effort > 0) {
1674 : 0 : pf->flags |= ICE_FLAG_FDIR;
1675 : 0 : pf->fdir_nb_qps = ICE_DEFAULT_QP_NUM_FDIR;
1676 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max - pf->fdir_nb_qps;
1677 : : } else {
1678 : 0 : pf->fdir_nb_qps = 0;
1679 : : }
1680 : 0 : pf->fdir_qp_offset = 0;
1681 : :
1682 : 0 : return 0;
1683 : : }
1684 : :
1685 : : struct ice_vsi *
1686 : 0 : ice_setup_vsi(struct ice_pf *pf, enum ice_vsi_type type)
1687 : : {
1688 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1689 : : struct ice_vsi *vsi = NULL;
1690 : : struct ice_vsi_ctx vsi_ctx;
1691 : : int ret;
1692 : 0 : struct rte_ether_addr broadcast = {
1693 : : .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
1694 : : struct rte_ether_addr mac_addr;
1695 : 0 : uint16_t max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1696 : : uint8_t tc_bitmap = 0x1;
1697 : : uint16_t cfg;
1698 : 0 : struct ice_adapter *ad = (struct ice_adapter *)hw->back;
1699 : :
1700 : : /* hw->num_lports = 1 in NIC mode */
1701 : 0 : vsi = rte_zmalloc(NULL, sizeof(struct ice_vsi), 0);
1702 [ # # ]: 0 : if (!vsi)
1703 : : return NULL;
1704 : :
1705 : 0 : vsi->idx = pf->next_vsi_idx;
1706 : 0 : pf->next_vsi_idx++;
1707 : 0 : vsi->type = type;
1708 : 0 : vsi->adapter = ICE_PF_TO_ADAPTER(pf);
1709 : 0 : vsi->max_macaddrs = ICE_NUM_MACADDR_MAX;
1710 : 0 : vsi->vlan_anti_spoof_on = 0;
1711 : 0 : vsi->vlan_filter_on = 1;
1712 : 0 : TAILQ_INIT(&vsi->mac_list);
1713 : 0 : TAILQ_INIT(&vsi->vlan_list);
1714 : :
1715 : : /* Be sync with RTE_ETH_RSS_RETA_SIZE_x maximum value definition */
1716 : 0 : pf->hash_lut_size = hw->func_caps.common_cap.rss_table_size >
1717 : 0 : RTE_ETH_RSS_RETA_SIZE_512 ? RTE_ETH_RSS_RETA_SIZE_512 :
1718 : : hw->func_caps.common_cap.rss_table_size;
1719 : 0 : pf->flags |= ICE_FLAG_RSS_AQ_CAPABLE;
1720 : :
1721 : : /* Defines the type of outer tag expected */
1722 [ # # # ]: 0 : pf->outer_ethertype = RTE_ETHER_TYPE_VLAN;
1723 : :
1724 : : memset(&vsi_ctx, 0, sizeof(vsi_ctx));
1725 [ # # # ]: 0 : switch (type) {
1726 : 0 : case ICE_VSI_PF:
1727 : 0 : vsi->nb_qps = pf->lan_nb_qps;
1728 : 0 : vsi->base_queue = 1;
1729 : : ice_vsi_config_default_rss(&vsi_ctx.info);
1730 : 0 : vsi_ctx.alloc_from_pool = true;
1731 : 0 : vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1732 : : /* switch_id is queried by get_switch_config aq, which is done
1733 : : * by ice_init_hw
1734 : : */
1735 : 0 : vsi_ctx.info.sw_id = hw->port_info->sw_id;
1736 : : /* Source Prune */
1737 [ # # ]: 0 : if (ad->devargs.source_prune != 1) {
1738 : : /* Disable source prune to support VRRP
1739 : : * when source-prune devarg is not set
1740 : : */
1741 : : vsi_ctx.info.sw_flags =
1742 : : ICE_AQ_VSI_SW_FLAG_LOCAL_LB;
1743 : 0 : vsi_ctx.info.sw_flags |=
1744 : : ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
1745 : : }
1746 : : cfg = ICE_AQ_VSI_PROP_SW_VALID;
1747 : 0 : vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1748 : 0 : vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1749 : : /* Allow all untagged or tagged packets */
1750 : : vsi_ctx.info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
1751 : 0 : vsi_ctx.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
1752 : 0 : vsi_ctx.info.q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF |
1753 : : ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
1754 [ # # ]: 0 : if (ice_is_dvm_ena(hw)) {
1755 : : vsi_ctx.info.outer_vlan_flags =
1756 : : (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
1757 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
1758 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M;
1759 : : vsi_ctx.info.outer_vlan_flags |=
1760 : : (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
1761 : : ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
1762 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M;
1763 : 0 : vsi_ctx.info.outer_vlan_flags |=
1764 : : (ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
1765 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S);
1766 : : }
1767 : :
1768 : : /* FDIR */
1769 : : cfg = ICE_AQ_VSI_PROP_SECURITY_VALID |
1770 : : ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1771 : 0 : vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1772 : : cfg = ICE_AQ_VSI_FD_ENABLE;
1773 : 0 : vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1774 : 0 : vsi_ctx.info.max_fd_fltr_dedicated =
1775 : 0 : rte_cpu_to_le_16(hw->func_caps.fd_fltr_guar);
1776 : 0 : vsi_ctx.info.max_fd_fltr_shared =
1777 : 0 : rte_cpu_to_le_16(hw->func_caps.fd_fltr_best_effort);
1778 : :
1779 : : /* Enable VLAN/UP trip */
1780 : 0 : ret = ice_vsi_config_tc_queue_mapping(hw, vsi,
1781 : : &vsi_ctx.info,
1782 : : ICE_DEFAULT_TCMAP);
1783 [ # # ]: 0 : if (ret) {
1784 : 0 : PMD_INIT_LOG(ERR,
1785 : : "tc queue mapping with vsi failed, "
1786 : : "err = %d",
1787 : : ret);
1788 : 0 : goto fail_mem;
1789 : : }
1790 : :
1791 : : break;
1792 : 0 : case ICE_VSI_CTRL:
1793 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
1794 : 0 : vsi->base_queue = ICE_FDIR_QUEUE_ID;
1795 : 0 : vsi_ctx.alloc_from_pool = true;
1796 : 0 : vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1797 : :
1798 : : cfg = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1799 : 0 : vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1800 : : cfg = ICE_AQ_VSI_FD_PROG_ENABLE;
1801 : 0 : vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1802 : 0 : vsi_ctx.info.sw_id = hw->port_info->sw_id;
1803 : 0 : vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1804 : 0 : ret = ice_vsi_config_tc_queue_mapping(hw, vsi,
1805 : : &vsi_ctx.info,
1806 : : ICE_DEFAULT_TCMAP);
1807 [ # # ]: 0 : if (ret) {
1808 : 0 : PMD_INIT_LOG(ERR,
1809 : : "tc queue mapping with vsi failed, "
1810 : : "err = %d",
1811 : : ret);
1812 : 0 : goto fail_mem;
1813 : : }
1814 : : break;
1815 : 0 : default:
1816 : : /* for other types of VSI */
1817 : 0 : PMD_INIT_LOG(ERR, "other types of VSI not supported");
1818 : 0 : goto fail_mem;
1819 : : }
1820 : :
1821 : : /* VF has MSIX interrupt in VF range, don't allocate here */
1822 [ # # ]: 0 : if (type == ICE_VSI_PF) {
1823 : 0 : ret = ice_res_pool_alloc(&pf->msix_pool,
1824 : 0 : RTE_MIN(vsi->nb_qps,
1825 : : RTE_MAX_RXTX_INTR_VEC_ID));
1826 [ # # ]: 0 : if (ret < 0) {
1827 : 0 : PMD_INIT_LOG(ERR, "VSI MAIN %d get heap failed %d",
1828 : : vsi->vsi_id, ret);
1829 : : }
1830 : 0 : vsi->msix_intr = ret;
1831 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
1832 : : } else if (type == ICE_VSI_CTRL) {
1833 : 0 : ret = ice_res_pool_alloc(&pf->msix_pool, 1);
1834 [ # # ]: 0 : if (ret < 0) {
1835 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d",
1836 : : vsi->vsi_id, ret);
1837 : : }
1838 : 0 : vsi->msix_intr = ret;
1839 : 0 : vsi->nb_msix = 1;
1840 : : } else {
1841 : : vsi->msix_intr = 0;
1842 : : vsi->nb_msix = 0;
1843 : : }
1844 : 0 : ret = ice_add_vsi(hw, vsi->idx, &vsi_ctx, NULL);
1845 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
1846 : 0 : PMD_INIT_LOG(ERR, "add vsi failed, err = %d", ret);
1847 : 0 : goto fail_mem;
1848 : : }
1849 : : /* store vsi information is SW structure */
1850 : 0 : vsi->vsi_id = vsi_ctx.vsi_num;
1851 : 0 : vsi->info = vsi_ctx.info;
1852 : 0 : pf->vsis_allocated = vsi_ctx.vsis_allocd;
1853 : 0 : pf->vsis_unallocated = vsi_ctx.vsis_unallocated;
1854 : :
1855 [ # # ]: 0 : if (type == ICE_VSI_PF) {
1856 : : /* MAC configuration */
1857 : : rte_ether_addr_copy((struct rte_ether_addr *)
1858 : 0 : hw->port_info->mac.perm_addr,
1859 : : &pf->dev_addr);
1860 : :
1861 : : rte_ether_addr_copy(&pf->dev_addr, &mac_addr);
1862 : 0 : ret = ice_add_mac_filter(vsi, &mac_addr);
1863 [ # # ]: 0 : if (ret != ICE_SUCCESS)
1864 : 0 : PMD_INIT_LOG(ERR, "Failed to add dflt MAC filter");
1865 : :
1866 : : rte_ether_addr_copy(&broadcast, &mac_addr);
1867 : 0 : ret = ice_add_mac_filter(vsi, &mac_addr);
1868 [ # # ]: 0 : if (ret != ICE_SUCCESS)
1869 : 0 : PMD_INIT_LOG(ERR, "Failed to add MAC filter");
1870 : : }
1871 : :
1872 : : /* At the beginning, only TC0. */
1873 : : /* What we need here is the maximum number of the TX queues.
1874 : : * Currently vsi->nb_qps means it.
1875 : : * Correct it if any change.
1876 : : */
1877 : 0 : max_txqs[0] = vsi->nb_qps;
1878 : 0 : ret = ice_cfg_vsi_lan(hw->port_info, vsi->idx,
1879 : : tc_bitmap, max_txqs);
1880 [ # # ]: 0 : if (ret != ICE_SUCCESS)
1881 : 0 : PMD_INIT_LOG(ERR, "Failed to config vsi sched");
1882 : :
1883 : : return vsi;
1884 : 0 : fail_mem:
1885 : 0 : rte_free(vsi);
1886 : 0 : pf->next_vsi_idx--;
1887 : 0 : return NULL;
1888 : : }
1889 : :
1890 : : static int
1891 : 0 : ice_send_driver_ver(struct ice_hw *hw)
1892 : : {
1893 : : struct ice_driver_ver dv;
1894 : :
1895 : : /* we don't have driver version use 0 for dummy */
1896 : 0 : dv.major_ver = 0;
1897 : 0 : dv.minor_ver = 0;
1898 : 0 : dv.build_ver = 0;
1899 : 0 : dv.subbuild_ver = 0;
1900 : : strncpy((char *)dv.driver_string, "dpdk", sizeof(dv.driver_string));
1901 : :
1902 : 0 : return ice_aq_send_driver_ver(hw, &dv, NULL);
1903 : : }
1904 : :
1905 : : static int
1906 : 0 : ice_pf_setup(struct ice_pf *pf)
1907 : : {
1908 : 0 : struct ice_adapter *ad = ICE_PF_TO_ADAPTER(pf);
1909 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1910 : : struct ice_vsi *vsi;
1911 : : uint16_t unused;
1912 : :
1913 : : /* Clear all stats counters */
1914 : 0 : pf->offset_loaded = false;
1915 : 0 : memset(&pf->stats, 0, sizeof(struct ice_hw_port_stats));
1916 : 0 : memset(&pf->stats_offset, 0, sizeof(struct ice_hw_port_stats));
1917 : 0 : memset(&pf->internal_stats, 0, sizeof(struct ice_eth_stats));
1918 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct ice_eth_stats));
1919 : :
1920 : : /* force guaranteed filter pool for PF */
1921 : 0 : ice_alloc_fd_guar_item(hw, &unused,
1922 : 0 : hw->func_caps.fd_fltr_guar);
1923 : : /* force shared filter pool for PF */
1924 : 0 : ice_alloc_fd_shrd_item(hw, &unused,
1925 : 0 : hw->func_caps.fd_fltr_best_effort);
1926 : :
1927 : 0 : vsi = ice_setup_vsi(pf, ICE_VSI_PF);
1928 [ # # ]: 0 : if (!vsi) {
1929 : 0 : PMD_INIT_LOG(ERR, "Failed to add vsi for PF");
1930 : 0 : return -EINVAL;
1931 : : }
1932 : :
1933 : : /* set the number of hidden Tx scheduler layers. If no devargs parameter to
1934 : : * set the number of exposed levels, the default is to expose all levels,
1935 : : * except the TC layer.
1936 : : *
1937 : : * If the number of exposed levels is set, we check that it's not greater
1938 : : * than the HW can provide (in which case we do nothing except log a warning),
1939 : : * and then set the hidden layers to be the total number of levels minus the
1940 : : * requested visible number.
1941 : : */
1942 : 0 : pf->tm_conf.hidden_layers = hw->port_info->has_tc;
1943 [ # # ]: 0 : if (ad->devargs.tm_exposed_levels != 0) {
1944 : 0 : const uint8_t avail_layers = hw->num_tx_sched_layers - hw->port_info->has_tc;
1945 : : const uint8_t req_layers = ad->devargs.tm_exposed_levels;
1946 [ # # ]: 0 : if (req_layers > avail_layers) {
1947 : 0 : PMD_INIT_LOG(WARNING, "The number of TM scheduler exposed levels exceeds the number of supported levels (%u)",
1948 : : avail_layers);
1949 : 0 : PMD_INIT_LOG(WARNING, "Setting scheduler layers to %u", avail_layers);
1950 : : } else {
1951 : 0 : pf->tm_conf.hidden_layers = hw->num_tx_sched_layers - req_layers;
1952 : : }
1953 : : }
1954 : :
1955 : 0 : pf->main_vsi = vsi;
1956 : : rte_spinlock_init(&pf->link_lock);
1957 : :
1958 : 0 : return 0;
1959 : : }
1960 : :
1961 : : static enum ice_pkg_type
1962 : 0 : ice_load_pkg_type(struct ice_hw *hw)
1963 : : {
1964 : : enum ice_pkg_type package_type;
1965 : :
1966 : : /* store the activated package type (OS default or Comms) */
1967 [ # # ]: 0 : if (!strncmp((char *)hw->active_pkg_name, ICE_OS_DEFAULT_PKG_NAME,
1968 : : ICE_PKG_NAME_SIZE))
1969 : : package_type = ICE_PKG_TYPE_OS_DEFAULT;
1970 [ # # ]: 0 : else if (!strncmp((char *)hw->active_pkg_name, ICE_COMMS_PKG_NAME,
1971 : : ICE_PKG_NAME_SIZE))
1972 : : package_type = ICE_PKG_TYPE_COMMS;
1973 : : else
1974 : : package_type = ICE_PKG_TYPE_UNKNOWN;
1975 : :
1976 [ # # ]: 0 : PMD_INIT_LOG(NOTICE, "Active package is: %d.%d.%d.%d, %s (%s VLAN mode)",
1977 : : hw->active_pkg_ver.major, hw->active_pkg_ver.minor,
1978 : : hw->active_pkg_ver.update, hw->active_pkg_ver.draft,
1979 : : hw->active_pkg_name,
1980 : : ice_is_dvm_ena(hw) ? "double" : "single");
1981 : :
1982 : 0 : return package_type;
1983 : : }
1984 : :
1985 : 0 : static int ice_read_customized_path(char *pkg_file, uint16_t buff_len)
1986 : : {
1987 : : int fp, n;
1988 : :
1989 : : fp = open(ICE_PKG_FILE_CUSTOMIZED_PATH, O_RDONLY);
1990 [ # # ]: 0 : if (fp < 0) {
1991 : 0 : PMD_INIT_LOG(INFO, "Failed to read CUSTOMIZED_PATH");
1992 : 0 : return -EIO;
1993 : : }
1994 : :
1995 [ # # ]: 0 : n = read(fp, pkg_file, buff_len - 1);
1996 [ # # ]: 0 : if (n > 0) {
1997 [ # # ]: 0 : if (pkg_file[n - 1] == '\n')
1998 : 0 : n--;
1999 : 0 : pkg_file[n] = '\0';
2000 : : }
2001 : :
2002 : 0 : close(fp);
2003 : 0 : return n;
2004 : : }
2005 : :
2006 : : static int
2007 : 0 : ice_firmware_read(const char *file, void *buf, size_t *bufsz)
2008 : : {
2009 : 0 : int ret = rte_firmware_read(file, buf, bufsz);
2010 : :
2011 [ # # ]: 0 : if (ret < 0)
2012 : 0 : PMD_INIT_LOG(DEBUG, "Cannot read DDP file %s", file);
2013 : :
2014 : 0 : return ret;
2015 : : }
2016 : :
2017 : 0 : int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)
2018 : : {
2019 : 0 : struct ice_hw *hw = &adapter->hw;
2020 : : char pkg_file[ICE_MAX_PKG_FILENAME_SIZE];
2021 : : char customized_path[ICE_MAX_PKG_FILENAME_SIZE];
2022 : : char opt_ddp_filename[ICE_MAX_PKG_FILENAME_SIZE];
2023 : : void *buf;
2024 : : size_t bufsz;
2025 : : int err;
2026 : :
2027 : : /* first read any explicitly referenced DDP file*/
2028 [ # # ]: 0 : if (adapter->devargs.ddp_filename != NULL) {
2029 : : strlcpy(pkg_file, adapter->devargs.ddp_filename, sizeof(pkg_file));
2030 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0) {
2031 : 0 : goto load_fw;
2032 : : } else {
2033 : 0 : PMD_INIT_LOG(ERR, "Cannot load DDP file: %s", pkg_file);
2034 : 0 : return -1;
2035 : : }
2036 : : }
2037 : :
2038 : : memset(opt_ddp_filename, 0, ICE_MAX_PKG_FILENAME_SIZE);
2039 : : snprintf(opt_ddp_filename, ICE_MAX_PKG_FILENAME_SIZE,
2040 : : "ice-%016" PRIx64 ".pkg", dsn);
2041 : :
2042 [ # # ]: 0 : if (ice_read_customized_path(customized_path, ICE_MAX_PKG_FILENAME_SIZE) > 0) {
2043 [ # # ]: 0 : if (use_dsn) {
2044 : : snprintf(pkg_file, RTE_DIM(pkg_file), "%s/%s",
2045 : : customized_path, opt_ddp_filename);
2046 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0)
2047 : 0 : goto load_fw;
2048 : : }
2049 : : snprintf(pkg_file, RTE_DIM(pkg_file), "%s/%s", customized_path, "ice.pkg");
2050 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0)
2051 : 0 : goto load_fw;
2052 : : }
2053 : :
2054 [ # # ]: 0 : if (!use_dsn)
2055 : 0 : goto no_dsn;
2056 : :
2057 : : strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_UPDATES,
2058 : : ICE_MAX_PKG_FILENAME_SIZE);
2059 : : strcat(pkg_file, opt_ddp_filename);
2060 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0)
2061 : 0 : goto load_fw;
2062 : :
2063 : : strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_DEFAULT,
2064 : : ICE_MAX_PKG_FILENAME_SIZE);
2065 : : strcat(pkg_file, opt_ddp_filename);
2066 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0)
2067 : 0 : goto load_fw;
2068 : :
2069 : 0 : no_dsn:
2070 : : strncpy(pkg_file, ICE_PKG_FILE_UPDATES, ICE_MAX_PKG_FILENAME_SIZE);
2071 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) == 0)
2072 : 0 : goto load_fw;
2073 : :
2074 : : strncpy(pkg_file, ICE_PKG_FILE_DEFAULT, ICE_MAX_PKG_FILENAME_SIZE);
2075 [ # # ]: 0 : if (ice_firmware_read(pkg_file, &buf, &bufsz) < 0) {
2076 : 0 : PMD_INIT_LOG(ERR, "Failed to load default DDP package " ICE_PKG_FILE_DEFAULT);
2077 : 0 : return -1;
2078 : : }
2079 : :
2080 : 0 : load_fw:
2081 : 0 : PMD_INIT_LOG(DEBUG, "DDP package name: %s", pkg_file);
2082 : :
2083 : 0 : err = ice_copy_and_init_pkg(hw, buf, bufsz, adapter->devargs.ddp_load_sched);
2084 [ # # ]: 0 : if (!ice_is_init_pkg_successful(err)) {
2085 : 0 : PMD_INIT_LOG(ERR, "Failed to load DDP package: %d", err);
2086 : 0 : free(buf);
2087 : 0 : return -1;
2088 : : }
2089 : :
2090 : : /* store the loaded pkg type info */
2091 : 0 : adapter->active_pkg_type = ice_load_pkg_type(hw);
2092 : :
2093 : 0 : free(buf);
2094 : 0 : return 0;
2095 : : }
2096 : :
2097 : : static void
2098 : 0 : ice_base_queue_get(struct ice_pf *pf)
2099 : : {
2100 : : uint32_t reg;
2101 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
2102 : :
2103 : 0 : reg = ICE_READ_REG(hw, PFLAN_RX_QALLOC);
2104 [ # # ]: 0 : if (reg & PFLAN_RX_QALLOC_VALID_M) {
2105 : 0 : pf->base_queue = reg & PFLAN_RX_QALLOC_FIRSTQ_M;
2106 : : } else {
2107 : 0 : PMD_INIT_LOG(WARNING, "Failed to get Rx base queue"
2108 : : " index");
2109 : : }
2110 : 0 : }
2111 : :
2112 : : static int
2113 : 0 : parse_bool(const char *key, const char *value, void *args)
2114 : : {
2115 : : int *i = args;
2116 : :
2117 [ # # # # ]: 0 : if (value == NULL || value[0] == '\0') {
2118 : 0 : PMD_DRV_LOG(WARNING, "key:\"%s\", requires a value, which must be 0 or 1", key);
2119 : 0 : return -1;
2120 : : }
2121 [ # # # # ]: 0 : if (value[1] != '\0' || (value[0] != '0' && value[0] != '1')) {
2122 : 0 : PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", value must be 0 or 1",
2123 : : value, key);
2124 : 0 : return -1;
2125 : : }
2126 : :
2127 : 0 : *i = (value[0] == '1');
2128 : 0 : return 0;
2129 : : }
2130 : :
2131 : : static int
2132 : 0 : parse_u64(const char *key, const char *value, void *args)
2133 : : {
2134 : : u64 *num = (u64 *)args;
2135 : : u64 tmp;
2136 : :
2137 : 0 : errno = 0;
2138 : 0 : tmp = strtoull(value, NULL, 16);
2139 [ # # ]: 0 : if (errno) {
2140 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64",
2141 : : key, value);
2142 : 0 : return -1;
2143 : : }
2144 : :
2145 : 0 : *num = tmp;
2146 : :
2147 : 0 : return 0;
2148 : : }
2149 : :
2150 : : static int
2151 : 0 : parse_tx_sched_levels(const char *key, const char *value, void *args)
2152 : : {
2153 : : uint8_t *num = args;
2154 : : long tmp;
2155 : : char *endptr;
2156 : :
2157 : 0 : errno = 0;
2158 : 0 : tmp = strtol(value, &endptr, 0);
2159 : : /* the value needs two stage validation, since the actual number of available
2160 : : * levels is not known at this point. Initially just validate that it is in
2161 : : * the correct range, between 3 and 8. Later validation will check that the
2162 : : * available layers on a particular port is higher than the value specified here.
2163 : : */
2164 [ # # # # ]: 0 : if (errno || *endptr != '\0' ||
2165 [ # # ]: 0 : tmp < (ICE_VSI_LAYER_OFFSET - 1) || tmp >= ICE_TM_MAX_LAYERS) {
2166 : 0 : PMD_DRV_LOG(WARNING, "%s: Invalid value \"%s\", should be in range [%d, %d]",
2167 : : key, value, ICE_VSI_LAYER_OFFSET - 1, ICE_TM_MAX_LAYERS - 1);
2168 : 0 : return -1;
2169 : : }
2170 : :
2171 : 0 : *num = tmp;
2172 : :
2173 : 0 : return 0;
2174 : : }
2175 : :
2176 : : static int
2177 : 0 : parse_link_state_on_close(const char *key, const char *value, void *args)
2178 : : {
2179 : : int *state = args, ret = 0;
2180 : :
2181 [ # # ]: 0 : if (value == NULL || state == NULL)
2182 : : return -EINVAL;
2183 : :
2184 [ # # ]: 0 : if (strcmp(value, "down") == 0) {
2185 : 0 : *state = ICE_LINK_DOWN;
2186 [ # # ]: 0 : } else if (strcmp(value, "up") == 0) {
2187 : 0 : *state = ICE_LINK_UP;
2188 [ # # ]: 0 : } else if (strcmp(value, "initial") == 0) {
2189 : 0 : *state = ICE_LINK_INITIAL;
2190 : : } else {
2191 : : ret = -EINVAL;
2192 : 0 : PMD_DRV_LOG(WARNING, "%s: Invalid value \"%s\", "
2193 : : "should be \"down\" \"up\" or \"initial\"", key, value);
2194 : : }
2195 : :
2196 : : return ret;
2197 : : }
2198 : :
2199 : : static int
2200 : : lookup_pps_type(const char *pps_name)
2201 : : {
2202 : : static struct {
2203 : : const char *name;
2204 : : enum pps_type type;
2205 : : } pps_type_map[] = {
2206 : : { "pin", PPS_PIN },
2207 : : };
2208 : :
2209 : : uint32_t i;
2210 : :
2211 : : for (i = 0; i < RTE_DIM(pps_type_map); i++) {
2212 : 0 : if (strcmp(pps_name, pps_type_map[i].name) == 0)
2213 : 0 : return pps_type_map[i].type;
2214 : : }
2215 : :
2216 : : return -1;
2217 : : }
2218 : :
2219 : : static int
2220 : 0 : parse_pin_set(const char *input, int pps_type, struct ice_devargs *devargs)
2221 : : {
2222 : : const char *str = input;
2223 : 0 : char *end = NULL;
2224 : : uint32_t idx;
2225 : :
2226 [ # # ]: 0 : while (isblank(*str))
2227 : 0 : str++;
2228 : :
2229 [ # # ]: 0 : if (!isdigit(*str))
2230 : : return -1;
2231 : :
2232 [ # # ]: 0 : if (pps_type == PPS_PIN) {
2233 : 0 : idx = strtoul(str, &end, 10);
2234 [ # # # # ]: 0 : if (end == NULL || idx >= ICE_MAX_PIN_NUM)
2235 : : return -1;
2236 [ # # ]: 0 : while (isblank(*end))
2237 : 0 : end++;
2238 [ # # ]: 0 : if (*end != ']')
2239 : : return -1;
2240 : :
2241 : 0 : devargs->pin_idx = idx;
2242 : 0 : devargs->pps_out_ena = 1;
2243 : :
2244 : 0 : return 0;
2245 : : }
2246 : :
2247 : : return -1;
2248 : : }
2249 : :
2250 : : static int
2251 : 0 : parse_pps_out_parameter(const char *pins, struct ice_devargs *devargs)
2252 : : {
2253 : : const char *pin_start;
2254 : : uint32_t idx;
2255 : : int pps_type;
2256 : : char pps_name[32];
2257 : :
2258 [ # # ]: 0 : while (isblank(*pins))
2259 : 0 : pins++;
2260 : :
2261 : 0 : pins++;
2262 [ # # ]: 0 : while (isblank(*pins))
2263 : 0 : pins++;
2264 [ # # ]: 0 : if (*pins == '\0')
2265 : : return -1;
2266 : :
2267 : 0 : for (idx = 0; ; idx++) {
2268 [ # # # # ]: 0 : if (isblank(pins[idx]) ||
2269 [ # # ]: 0 : pins[idx] == ':' ||
2270 : : pins[idx] == '\0')
2271 : : break;
2272 : :
2273 : 0 : pps_name[idx] = pins[idx];
2274 : : }
2275 [ # # ]: 0 : pps_name[idx] = '\0';
2276 : : pps_type = lookup_pps_type(pps_name);
2277 [ # # ]: 0 : if (pps_type < 0)
2278 : : return -1;
2279 : :
2280 : : pins += idx;
2281 : :
2282 : 0 : pins += strcspn(pins, ":");
2283 [ # # ]: 0 : if (*pins++ != ':')
2284 : : return -1;
2285 [ # # ]: 0 : while (isblank(*pins))
2286 : 0 : pins++;
2287 : :
2288 : : pin_start = pins;
2289 : :
2290 : : while (isblank(*pins))
2291 : : pins++;
2292 : :
2293 [ # # ]: 0 : if (parse_pin_set(pin_start, pps_type, devargs) < 0)
2294 : 0 : return -1;
2295 : :
2296 : : return 0;
2297 : : }
2298 : :
2299 : : static int
2300 : 0 : handle_pps_out_arg(__rte_unused const char *key, const char *value,
2301 : : void *extra_args)
2302 : : {
2303 : : struct ice_devargs *devargs = extra_args;
2304 : :
2305 [ # # ]: 0 : if (value == NULL || extra_args == NULL)
2306 : : return -EINVAL;
2307 : :
2308 [ # # ]: 0 : if (parse_pps_out_parameter(value, devargs) < 0) {
2309 : 0 : PMD_DRV_LOG(ERR,
2310 : : "The GPIO pin parameter is wrong : '%s'",
2311 : : value);
2312 : 0 : return -1;
2313 : : }
2314 : :
2315 : : return 0;
2316 : : }
2317 : :
2318 : : static int
2319 : 0 : ice_parse_mbuf_check(__rte_unused const char *key, const char *value, void *args)
2320 : : {
2321 : : char *cur;
2322 : : char *tmp;
2323 : : int str_len;
2324 : : int valid_len;
2325 : :
2326 : : int ret = 0;
2327 : : uint64_t *mc_flags = args;
2328 : 0 : char *str2 = strdup(value);
2329 [ # # ]: 0 : if (str2 == NULL)
2330 : : return -1;
2331 : :
2332 : 0 : str_len = strlen(str2);
2333 [ # # ]: 0 : if (str_len == 0) {
2334 : : ret = -1;
2335 : 0 : goto err_end;
2336 : : }
2337 : :
2338 : : /* Try stripping the outer square brackets of the parameter string. */
2339 : : str_len = strlen(str2);
2340 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
2341 [ # # ]: 0 : if (str_len < 3) {
2342 : : ret = -1;
2343 : 0 : goto err_end;
2344 : : }
2345 : 0 : valid_len = str_len - 2;
2346 : 0 : memmove(str2, str2 + 1, valid_len);
2347 : 0 : memset(str2 + valid_len, '\0', 2);
2348 : : }
2349 : :
2350 : 0 : cur = strtok_r(str2, ",", &tmp);
2351 [ # # ]: 0 : while (cur != NULL) {
2352 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
2353 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_MBUF;
2354 [ # # ]: 0 : else if (!strcmp(cur, "size"))
2355 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_SIZE;
2356 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
2357 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_SEGMENT;
2358 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
2359 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_OFFLOAD;
2360 : : else
2361 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
2362 : 0 : cur = strtok_r(NULL, ",", &tmp);
2363 : : }
2364 : :
2365 : 0 : err_end:
2366 : 0 : free(str2);
2367 : 0 : return ret;
2368 : : }
2369 : :
2370 : 0 : static int ice_parse_devargs(struct rte_eth_dev *dev)
2371 : : {
2372 : 0 : struct ice_adapter *ad =
2373 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2374 : 0 : struct rte_devargs *devargs = dev->device->devargs;
2375 : : struct rte_kvargs *kvlist;
2376 : : int ret;
2377 : :
2378 [ # # ]: 0 : if (devargs == NULL)
2379 : : return 0;
2380 : :
2381 : 0 : kvlist = rte_kvargs_parse(devargs->args, ice_valid_args);
2382 [ # # ]: 0 : if (kvlist == NULL) {
2383 : 0 : PMD_INIT_LOG(ERR, "Invalid kvargs key");
2384 : 0 : return -EINVAL;
2385 : : }
2386 : :
2387 : 0 : ad->devargs.proto_xtr_dflt = PROTO_XTR_NONE;
2388 : 0 : memset(ad->devargs.proto_xtr, PROTO_XTR_NONE,
2389 : : sizeof(ad->devargs.proto_xtr));
2390 : :
2391 : 0 : ret = rte_kvargs_process(kvlist, ICE_PROTO_XTR_ARG,
2392 : 0 : &handle_proto_xtr_arg, &ad->devargs);
2393 [ # # ]: 0 : if (ret)
2394 : 0 : goto bail;
2395 : :
2396 : 0 : ret = rte_kvargs_process(kvlist, ICE_FIELD_OFFS_ARG,
2397 : 0 : &handle_field_offs_arg, &ad->devargs.xtr_field_offs);
2398 [ # # ]: 0 : if (ret)
2399 : 0 : goto bail;
2400 : :
2401 : 0 : ret = rte_kvargs_process(kvlist, ICE_FIELD_NAME_ARG,
2402 : 0 : &handle_field_name_arg, &ad->devargs.xtr_field_name);
2403 [ # # ]: 0 : if (ret)
2404 : 0 : goto bail;
2405 : :
2406 : 0 : ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG,
2407 : 0 : &parse_bool, &ad->devargs.safe_mode_support);
2408 [ # # ]: 0 : if (ret)
2409 : 0 : goto bail;
2410 : :
2411 : 0 : ret = rte_kvargs_process(kvlist, ICE_DEFAULT_MAC_DISABLE,
2412 : 0 : &parse_bool, &ad->devargs.default_mac_disable);
2413 [ # # ]: 0 : if (ret)
2414 : 0 : goto bail;
2415 : :
2416 : 0 : ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG,
2417 : 0 : &parse_u64, &ad->hw.debug_mask);
2418 [ # # ]: 0 : if (ret)
2419 : 0 : goto bail;
2420 : :
2421 : 0 : ret = rte_kvargs_process(kvlist, ICE_ONE_PPS_OUT_ARG,
2422 : : &handle_pps_out_arg, &ad->devargs);
2423 [ # # ]: 0 : if (ret)
2424 : 0 : goto bail;
2425 : :
2426 : 0 : ret = rte_kvargs_process(kvlist, ICE_MBUF_CHECK_ARG,
2427 : 0 : &ice_parse_mbuf_check, &ad->devargs.mbuf_check);
2428 [ # # ]: 0 : if (ret)
2429 : 0 : goto bail;
2430 : :
2431 : 0 : ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG,
2432 : 0 : &parse_bool, &ad->devargs.rx_low_latency);
2433 [ # # ]: 0 : if (ret)
2434 : 0 : goto bail;
2435 : :
2436 : 0 : ret = rte_kvargs_process(kvlist, ICE_DDP_FILENAME_ARG,
2437 : 0 : &handle_ddp_filename_arg, &ad->devargs.ddp_filename);
2438 [ # # ]: 0 : if (ret)
2439 : 0 : goto bail;
2440 : :
2441 : 0 : ret = rte_kvargs_process(kvlist, ICE_DDP_LOAD_SCHED_ARG,
2442 : 0 : &parse_bool, &ad->devargs.ddp_load_sched);
2443 [ # # ]: 0 : if (ret)
2444 : 0 : goto bail;
2445 : :
2446 : 0 : ret = rte_kvargs_process(kvlist, ICE_TM_LEVELS_ARG,
2447 : 0 : &parse_tx_sched_levels, &ad->devargs.tm_exposed_levels);
2448 [ # # ]: 0 : if (ret)
2449 : 0 : goto bail;
2450 : :
2451 : 0 : ret = rte_kvargs_process(kvlist, ICE_SOURCE_PRUNE_ARG,
2452 : 0 : &parse_bool, &ad->devargs.source_prune);
2453 [ # # ]: 0 : if (ret)
2454 : 0 : goto bail;
2455 : :
2456 : 0 : ret = rte_kvargs_process(kvlist, ICE_LINK_STATE_ON_CLOSE,
2457 : 0 : &parse_link_state_on_close, &ad->devargs.link_state_on_close);
2458 : :
2459 : 0 : bail:
2460 : 0 : rte_kvargs_free(kvlist);
2461 : 0 : return ret;
2462 : : }
2463 : :
2464 : : static int
2465 : 0 : ice_get_hw_res(struct ice_hw *hw, uint16_t res_type,
2466 : : uint16_t num, uint16_t desc_id,
2467 : : uint16_t *prof_buf, uint16_t *num_prof)
2468 : : {
2469 : : struct ice_aqc_res_elem *resp_buf;
2470 : : int ret;
2471 : : uint16_t buf_len;
2472 : : bool res_shared = 1;
2473 : : struct ice_aq_desc aq_desc;
2474 : : struct ice_sq_cd *cd = NULL;
2475 : : struct ice_aqc_get_allocd_res_desc *cmd =
2476 : : &aq_desc.params.get_res_desc;
2477 : :
2478 : 0 : buf_len = sizeof(*resp_buf) * num;
2479 : 0 : resp_buf = ice_malloc(hw, buf_len);
2480 [ # # ]: 0 : if (!resp_buf)
2481 : : return -ENOMEM;
2482 : :
2483 : 0 : ice_fill_dflt_direct_cmd_desc(&aq_desc,
2484 : : ice_aqc_opc_get_allocd_res_desc);
2485 : :
2486 : 0 : cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2487 : : ICE_AQC_RES_TYPE_M) | (res_shared ?
2488 : : ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2489 : 0 : cmd->ops.cmd.first_desc = CPU_TO_LE16(desc_id);
2490 : :
2491 : 0 : ret = ice_aq_send_cmd(hw, &aq_desc, resp_buf, buf_len, cd);
2492 [ # # ]: 0 : if (!ret)
2493 : 0 : *num_prof = LE16_TO_CPU(cmd->ops.resp.num_desc);
2494 : : else
2495 : 0 : goto exit;
2496 : :
2497 : 0 : ice_memcpy(prof_buf, resp_buf, sizeof(*resp_buf) *
2498 : : (*num_prof), ICE_NONDMA_TO_NONDMA);
2499 : :
2500 : 0 : exit:
2501 : 0 : rte_free(resp_buf);
2502 : 0 : return ret;
2503 : : }
2504 : : static int
2505 : 0 : ice_cleanup_resource(struct ice_hw *hw, uint16_t res_type)
2506 : : {
2507 : : int ret;
2508 : : uint16_t prof_id;
2509 : : uint16_t prof_buf[ICE_MAX_RES_DESC_NUM];
2510 : : uint16_t first_desc = 1;
2511 : 0 : uint16_t num_prof = 0;
2512 : :
2513 : 0 : ret = ice_get_hw_res(hw, res_type, ICE_MAX_RES_DESC_NUM,
2514 : : first_desc, prof_buf, &num_prof);
2515 [ # # ]: 0 : if (ret) {
2516 : 0 : PMD_INIT_LOG(ERR, "Failed to get fxp resource");
2517 : 0 : return ret;
2518 : : }
2519 : :
2520 [ # # ]: 0 : for (prof_id = 0; prof_id < num_prof; prof_id++) {
2521 : 0 : ret = ice_free_hw_res(hw, res_type, 1, &prof_buf[prof_id]);
2522 [ # # ]: 0 : if (ret) {
2523 : 0 : PMD_INIT_LOG(ERR, "Failed to free fxp resource");
2524 : 0 : return ret;
2525 : : }
2526 : : }
2527 : : return 0;
2528 : : }
2529 : :
2530 : : static int
2531 : 0 : ice_reset_fxp_resource(struct ice_hw *hw)
2532 : : {
2533 : : int ret;
2534 : :
2535 : 0 : ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID);
2536 [ # # ]: 0 : if (ret) {
2537 : 0 : PMD_INIT_LOG(ERR, "Failed to clearup fdir resource");
2538 : 0 : return ret;
2539 : : }
2540 : :
2541 : 0 : ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID);
2542 [ # # ]: 0 : if (ret) {
2543 : 0 : PMD_INIT_LOG(ERR, "Failed to clearup rss resource");
2544 : 0 : return ret;
2545 : : }
2546 : :
2547 : : return 0;
2548 : : }
2549 : :
2550 : : static void
2551 : : ice_rss_ctx_init(struct ice_pf *pf)
2552 : : {
2553 : 0 : memset(&pf->hash_ctx, 0, sizeof(pf->hash_ctx));
2554 : : }
2555 : :
2556 : : static uint64_t
2557 : : ice_get_supported_rxdid(struct ice_hw *hw)
2558 : : {
2559 : : uint64_t supported_rxdid = 0; /* bitmap for supported RXDID */
2560 : : uint32_t regval;
2561 : : int i;
2562 : :
2563 : : supported_rxdid |= RTE_BIT64(ICE_RXDID_LEGACY_1);
2564 : :
2565 [ # # ]: 0 : for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2566 : 0 : regval = ICE_READ_REG(hw, GLFLXP_RXDID_FLAGS(i, 0));
2567 : 0 : if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2568 [ # # ]: 0 : & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2569 : 0 : supported_rxdid |= RTE_BIT64(i);
2570 : : }
2571 : : return supported_rxdid;
2572 : : }
2573 : :
2574 : 0 : static void ice_ptp_init_info(struct rte_eth_dev *dev)
2575 : : {
2576 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2577 : : struct ice_adapter *ad =
2578 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2579 : :
2580 [ # # # # ]: 0 : switch (hw->phy_model) {
2581 : 0 : case ICE_PHY_ETH56G:
2582 : 0 : ad->ptp_tx_block = hw->pf_id;
2583 : 0 : ad->ptp_tx_index = 0;
2584 : 0 : break;
2585 : 0 : case ICE_PHY_E810:
2586 : : case ICE_PHY_E830:
2587 : 0 : ad->ptp_tx_block = hw->port_info->lport;
2588 : 0 : ad->ptp_tx_index = 0;
2589 : 0 : break;
2590 : 0 : case ICE_PHY_E822:
2591 : 0 : ad->ptp_tx_block = hw->pf_id / ICE_PORTS_PER_QUAD;
2592 : 0 : ad->ptp_tx_index = (hw->pf_id % ICE_PORTS_PER_QUAD) *
2593 : : ICE_PORTS_PER_PHY_E822 * ICE_QUADS_PER_PHY_E822;
2594 : 0 : break;
2595 : 0 : default:
2596 : 0 : PMD_DRV_LOG(WARNING, "Unsupported PHY model");
2597 : 0 : break;
2598 : : }
2599 : 0 : }
2600 : :
2601 : : static int
2602 : 0 : ice_dev_init(struct rte_eth_dev *dev)
2603 : : {
2604 : : struct rte_pci_device *pci_dev;
2605 : : struct rte_intr_handle *intr_handle;
2606 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2607 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2608 : : struct ice_adapter *ad =
2609 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2610 : : struct ice_vsi *vsi;
2611 : : int ret;
2612 : : #ifndef RTE_EXEC_ENV_WINDOWS
2613 : : off_t pos;
2614 : : uint32_t dsn_low, dsn_high;
2615 : : uint64_t dsn;
2616 : : bool use_dsn;
2617 : : #endif
2618 : :
2619 : 0 : dev->dev_ops = &ice_eth_dev_ops;
2620 : 0 : dev->rx_queue_count = ice_rx_queue_count;
2621 : 0 : dev->rx_descriptor_status = ice_rx_descriptor_status;
2622 : 0 : dev->tx_descriptor_status = ice_tx_descriptor_status;
2623 : 0 : dev->rx_pkt_burst = ice_recv_pkts;
2624 : 0 : dev->tx_pkt_burst = ice_xmit_pkts;
2625 : 0 : dev->tx_pkt_prepare = ice_prep_pkts;
2626 : :
2627 : : /* for secondary processes, we don't initialise any further as primary
2628 : : * has already done this work.
2629 : : */
2630 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2631 : 0 : ice_set_rx_function(dev);
2632 : 0 : ice_set_tx_function(dev);
2633 : 0 : return 0;
2634 : : }
2635 : :
2636 : 0 : ice_set_default_ptype_table(dev);
2637 : 0 : pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2638 : 0 : intr_handle = pci_dev->intr_handle;
2639 : :
2640 : 0 : pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2641 : 0 : pf->dev_data = dev->data;
2642 : 0 : hw->back = pf->adapter;
2643 : 0 : hw->hw_addr = (uint8_t *)pci_dev->mem_resource[0].addr;
2644 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
2645 : 0 : hw->device_id = pci_dev->id.device_id;
2646 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2647 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2648 : 0 : hw->bus.device = pci_dev->addr.devid;
2649 : 0 : hw->bus.func = pci_dev->addr.function;
2650 : :
2651 : 0 : ret = ice_parse_devargs(dev);
2652 [ # # ]: 0 : if (ret) {
2653 : 0 : PMD_INIT_LOG(ERR, "Failed to parse devargs");
2654 : 0 : return -EINVAL;
2655 : : }
2656 : :
2657 : : ice_init_controlq_parameter(hw);
2658 : :
2659 : 0 : ret = ice_init_hw(hw);
2660 [ # # ]: 0 : if (ret) {
2661 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize HW");
2662 : 0 : return -EINVAL;
2663 : : }
2664 : :
2665 : : #ifndef RTE_EXEC_ENV_WINDOWS
2666 : : use_dsn = false;
2667 : : dsn = 0;
2668 : 0 : pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN);
2669 [ # # ]: 0 : if (pos) {
2670 [ # # # # ]: 0 : if (rte_pci_read_config(pci_dev, &dsn_low, 4, pos + 4) < 0 ||
2671 : 0 : rte_pci_read_config(pci_dev, &dsn_high, 4, pos + 8) < 0) {
2672 : 0 : PMD_INIT_LOG(WARNING, "Failed to read pci config space");
2673 : : } else {
2674 : : use_dsn = true;
2675 : 0 : dsn = (uint64_t)dsn_high << 32 | dsn_low;
2676 : : }
2677 : : } else {
2678 : 0 : PMD_INIT_LOG(INFO, "Failed to read device serial number");
2679 : : }
2680 : :
2681 : 0 : ret = ice_load_pkg(pf->adapter, use_dsn, dsn);
2682 [ # # ]: 0 : if (ret == 0) {
2683 : 0 : ret = ice_init_hw_tbls(hw);
2684 [ # # ]: 0 : if (ret) {
2685 : 0 : PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d", ret);
2686 : 0 : rte_free(hw->pkg_copy);
2687 : : }
2688 : : }
2689 : :
2690 [ # # ]: 0 : if (ret) {
2691 [ # # ]: 0 : if (ad->devargs.safe_mode_support == 0) {
2692 : 0 : PMD_INIT_LOG(ERR, "Failed to load the DDP package,"
2693 : : "Use safe-mode-support=1 to enter Safe Mode");
2694 : 0 : goto err_init_fw;
2695 : : }
2696 : :
2697 : 0 : PMD_INIT_LOG(WARNING, "Failed to load the DDP package,"
2698 : : "Entering Safe Mode");
2699 : 0 : ad->is_safe_mode = 1;
2700 : : }
2701 : : #endif
2702 : :
2703 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
2704 : : hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2705 : : hw->api_maj_ver, hw->api_min_ver);
2706 : :
2707 : 0 : ice_pf_sw_init(dev);
2708 : 0 : ret = ice_init_mac_address(dev);
2709 [ # # ]: 0 : if (ret) {
2710 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize mac address");
2711 : 0 : goto err_init_mac;
2712 : : }
2713 : :
2714 : 0 : ret = ice_res_pool_init(&pf->msix_pool, 1,
2715 : 0 : hw->func_caps.common_cap.num_msix_vectors - 1);
2716 [ # # ]: 0 : if (ret) {
2717 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
2718 : 0 : goto err_msix_pool_init;
2719 : : }
2720 : :
2721 : 0 : ret = ice_pf_setup(pf);
2722 [ # # ]: 0 : if (ret) {
2723 : 0 : PMD_INIT_LOG(ERR, "Failed to setup PF");
2724 : 0 : goto err_pf_setup;
2725 : : }
2726 : :
2727 : 0 : ret = ice_send_driver_ver(hw);
2728 [ # # ]: 0 : if (ret) {
2729 : 0 : PMD_INIT_LOG(ERR, "Failed to send driver version");
2730 : 0 : goto err_pf_setup;
2731 : : }
2732 : :
2733 : 0 : vsi = pf->main_vsi;
2734 : :
2735 : 0 : ret = ice_aq_stop_lldp(hw, true, false, NULL);
2736 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2737 : 0 : PMD_INIT_LOG(DEBUG, "lldp has already stopped");
2738 : 0 : ret = ice_init_dcb(hw, true);
2739 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2740 : 0 : PMD_INIT_LOG(DEBUG, "Failed to init DCB");
2741 : : /* Forward LLDP packets to default VSI */
2742 : 0 : ret = ice_lldp_fltr_add_remove(hw, vsi->vsi_id, true);
2743 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2744 : 0 : PMD_INIT_LOG(DEBUG, "Failed to cfg lldp");
2745 : : /* register callback func to eal lib */
2746 : 0 : rte_intr_callback_register(intr_handle,
2747 : : ice_interrupt_handler, dev);
2748 : :
2749 : 0 : ice_pf_enable_irq0(hw);
2750 : :
2751 : : /* enable uio intr after callback register */
2752 : 0 : rte_intr_enable(intr_handle);
2753 : :
2754 : : /* get base queue pairs index in the device */
2755 : 0 : ice_base_queue_get(pf);
2756 : :
2757 : : /* Initialize RSS context for gtpu_eh */
2758 : : ice_rss_ctx_init(pf);
2759 : :
2760 : : /* Initialize TM configuration */
2761 : 0 : ice_tm_conf_init(dev);
2762 : :
2763 : : /* Initialize PHY model */
2764 : 0 : ice_ptp_init_phy_model(hw);
2765 : :
2766 : : /* Initialize PTP info */
2767 : 0 : ice_ptp_init_info(dev);
2768 : :
2769 [ # # ]: 0 : if (hw->phy_model == ICE_PHY_E822) {
2770 : 0 : ret = ice_start_phy_timer_e822(hw, hw->pf_id, true);
2771 [ # # ]: 0 : if (ret)
2772 : 0 : PMD_INIT_LOG(ERR, "Failed to start phy timer");
2773 : : }
2774 : :
2775 [ # # ]: 0 : if (!ad->is_safe_mode) {
2776 : 0 : ret = ice_flow_init(ad);
2777 [ # # ]: 0 : if (ret) {
2778 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize flow");
2779 : 0 : goto err_flow_init;
2780 : : }
2781 : : }
2782 : :
2783 : 0 : ret = ice_reset_fxp_resource(hw);
2784 [ # # ]: 0 : if (ret) {
2785 : 0 : PMD_INIT_LOG(ERR, "Failed to reset fxp resource");
2786 : 0 : goto err_flow_init;
2787 : : }
2788 : :
2789 : 0 : pf->supported_rxdid = ice_get_supported_rxdid(hw);
2790 : :
2791 : : /* reset all stats of the device, including pf and main vsi */
2792 : 0 : ice_stats_reset(dev);
2793 : :
2794 : 0 : return 0;
2795 : :
2796 : 0 : err_flow_init:
2797 : 0 : ice_flow_uninit(ad);
2798 : 0 : rte_intr_disable(intr_handle);
2799 : : ice_pf_disable_irq0(hw);
2800 : 0 : rte_intr_callback_unregister(intr_handle,
2801 : : ice_interrupt_handler, dev);
2802 : 0 : err_pf_setup:
2803 : 0 : ice_res_pool_destroy(&pf->msix_pool);
2804 : 0 : err_msix_pool_init:
2805 : 0 : rte_free(dev->data->mac_addrs);
2806 : 0 : dev->data->mac_addrs = NULL;
2807 : 0 : err_init_mac:
2808 : 0 : rte_free(pf->proto_xtr);
2809 : : #ifndef RTE_EXEC_ENV_WINDOWS
2810 : 0 : err_init_fw:
2811 : : #endif
2812 : 0 : ice_deinit_hw(hw);
2813 : :
2814 : 0 : return ret;
2815 : : }
2816 : :
2817 : : int
2818 : 0 : ice_release_vsi(struct ice_vsi *vsi)
2819 : : {
2820 : : struct ice_hw *hw;
2821 : : struct ice_vsi_ctx vsi_ctx;
2822 : : int ret, error = 0;
2823 : :
2824 [ # # ]: 0 : if (!vsi)
2825 : : return error;
2826 : :
2827 : 0 : hw = ICE_VSI_TO_HW(vsi);
2828 : :
2829 : 0 : ice_remove_all_mac_vlan_filters(vsi);
2830 : :
2831 : : memset(&vsi_ctx, 0, sizeof(vsi_ctx));
2832 : :
2833 : 0 : vsi_ctx.vsi_num = vsi->vsi_id;
2834 : 0 : vsi_ctx.info = vsi->info;
2835 : 0 : ret = ice_free_vsi(hw, vsi->idx, &vsi_ctx, false, NULL);
2836 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
2837 : 0 : PMD_INIT_LOG(ERR, "Failed to free vsi by aq, %u", vsi->vsi_id);
2838 : : error = -1;
2839 : : }
2840 : :
2841 : 0 : rte_free(vsi->rss_lut);
2842 : 0 : rte_free(vsi->rss_key);
2843 : 0 : rte_free(vsi);
2844 : 0 : return error;
2845 : : }
2846 : :
2847 : : void
2848 : 0 : ice_vsi_disable_queues_intr(struct ice_vsi *vsi)
2849 : : {
2850 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
2851 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2852 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2853 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2854 : : uint16_t msix_intr, i;
2855 : :
2856 : : /* disable interrupt and also clear all the exist config */
2857 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2858 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
2859 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
2860 : : rte_wmb();
2861 : : }
2862 : :
2863 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
2864 : : /* vfio-pci */
2865 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2866 : 0 : msix_intr = vsi->msix_intr + i;
2867 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
2868 : : GLINT_DYN_CTL_WB_ON_ITR_M);
2869 : : }
2870 : : else
2871 : : /* igb_uio */
2872 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
2873 : 0 : }
2874 : :
2875 : : static int
2876 : 0 : ice_dev_stop(struct rte_eth_dev *dev)
2877 : : {
2878 : 0 : struct rte_eth_dev_data *data = dev->data;
2879 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2880 : : struct ice_adapter *ad =
2881 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2882 : 0 : struct ice_vsi *main_vsi = pf->main_vsi;
2883 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2884 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2885 : : uint16_t i;
2886 : :
2887 : : /* avoid stopping again */
2888 [ # # ]: 0 : if (pf->adapter_stopped)
2889 : : return 0;
2890 : :
2891 : : /* stop and clear all Rx queues */
2892 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++)
2893 : 0 : ice_rx_queue_stop(dev, i);
2894 : :
2895 : : /* stop and clear all Tx queues */
2896 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++)
2897 : 0 : ice_tx_queue_stop(dev, i);
2898 : :
2899 : : /* disable all queue interrupts */
2900 : 0 : ice_vsi_disable_queues_intr(main_vsi);
2901 : :
2902 [ # # ]: 0 : if (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
2903 : 0 : ad->txpp_ena = 0;
2904 : 0 : ice_timesync_disable(dev);
2905 : : }
2906 : :
2907 [ # # # # ]: 0 : if (pf->adapter->devargs.link_state_on_close == ICE_LINK_UP ||
2908 : 0 : (pf->adapter->devargs.link_state_on_close == ICE_LINK_INITIAL &&
2909 [ # # ]: 0 : pf->init_link_up))
2910 : : ice_dev_set_link_up(dev);
2911 : : else
2912 : : ice_dev_set_link_down(dev);
2913 : :
2914 : : /* Clean datapath event and queue/vec mapping */
2915 : 0 : rte_intr_efd_disable(intr_handle);
2916 : 0 : rte_intr_vec_list_free(intr_handle);
2917 : :
2918 : 0 : pf->adapter_stopped = true;
2919 : 0 : dev->data->dev_started = 0;
2920 : :
2921 : 0 : return 0;
2922 : : }
2923 : :
2924 : : static void
2925 : 0 : ice_deinit_dcb(struct rte_eth_dev *dev)
2926 : : {
2927 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2928 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2929 : 0 : struct ice_port_info *port_info = hw->port_info;
2930 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
2931 : 0 : struct ice_dcbx_cfg *local_dcb_conf = &qos_cfg->local_dcbx_cfg;
2932 : : int i, ret, cgd_idx;
2933 : : uint16_t max_frame_size;
2934 : 0 : u8 max_tcs = local_dcb_conf->etscfg.maxtcs;
2935 : : u8 tc;
2936 : :
2937 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG ||
2938 [ # # ]: 0 : dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_DCB))
2939 : : return;
2940 : :
2941 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
2942 : 0 : tc = ice_get_tc_by_priority(hw, i);
2943 : 0 : cgd_idx = ice_get_cgd_idx(hw, tc);
2944 [ # # ]: 0 : wr32(hw, GLRPB_TCHW(cgd_idx), CPU_TO_LE32(ICE_MAC_TC_MAX_WATERMARK));
2945 [ # # ]: 0 : wr32(hw, GLRPB_TCLW(cgd_idx), CPU_TO_LE32(ICE_MAC_TC_MAX_WATERMARK));
2946 : : }
2947 : :
2948 [ # # ]: 0 : max_frame_size = pf->dev_data->mtu ?
2949 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD : ICE_FRAME_SIZE_MAX;
2950 : : /* for each TC resets corresponding PFC quanta/threshold to its default values */
2951 : 0 : ret = ice_aq_set_mac_pfc_cfg(hw, max_frame_size, (1 << max_tcs) - 1,
2952 : : UINT16_MAX, INT16_MAX + 1, false, NULL);
2953 [ # # ]: 0 : if (ret)
2954 : 0 : PMD_DRV_LOG(ERR, "Failed to set mac config on DCB deinit");
2955 : :
2956 : : memset(local_dcb_conf, 0, sizeof(*local_dcb_conf));
2957 : 0 : local_dcb_conf->etscfg.maxtcs = max_tcs;
2958 : 0 : local_dcb_conf->etscfg.tcbwtable[0] = 100;
2959 : 0 : local_dcb_conf->etsrec.tcbwtable[0] = 100;
2960 : 0 : ret = ice_set_dcb_cfg(port_info);
2961 [ # # ]: 0 : if (ret)
2962 : 0 : PMD_DRV_LOG(ERR, "Failed to disable DCB");
2963 : : }
2964 : :
2965 : : static int
2966 : 0 : ice_dev_close(struct rte_eth_dev *dev)
2967 : : {
2968 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2969 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2970 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2971 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2972 : : struct ice_adapter *ad =
2973 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2974 : : int ret;
2975 : : uint32_t val;
2976 : 0 : uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
2977 : 0 : uint32_t pin_idx = ad->devargs.pin_idx;
2978 : :
2979 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2980 : : return 0;
2981 : :
2982 : : /* Since stop will make link down, then the link event will be
2983 : : * triggered, disable the irq firstly.
2984 : : */
2985 : : ice_pf_disable_irq0(hw);
2986 : :
2987 : : /* Unregister callback func from eal lib, use sync version to
2988 : : * make sure all active interrupt callbacks is done, then it's
2989 : : * safe to free all resources.
2990 : : */
2991 : 0 : rte_intr_callback_unregister_sync(intr_handle,
2992 : : ice_interrupt_handler, dev);
2993 : :
2994 : 0 : ret = ice_dev_stop(dev);
2995 : :
2996 [ # # ]: 0 : if (!ad->is_safe_mode)
2997 : 0 : ice_flow_uninit(ad);
2998 : :
2999 : 0 : ice_deinit_dcb(dev);
3000 : : /* release all queue resource */
3001 : 0 : ice_free_queues(dev);
3002 : :
3003 : 0 : ice_res_pool_destroy(&pf->msix_pool);
3004 : 0 : ice_release_vsi(pf->main_vsi);
3005 : 0 : ice_sched_cleanup_all(hw);
3006 : 0 : ice_free_hw_tbls(hw);
3007 : 0 : rte_free(hw->port_info);
3008 : 0 : hw->port_info = NULL;
3009 : 0 : free((void *)(uintptr_t)ad->devargs.ddp_filename);
3010 : 0 : ad->devargs.ddp_filename = NULL;
3011 : 0 : ice_shutdown_all_ctrlq(hw, true);
3012 : 0 : rte_free(pf->proto_xtr);
3013 : 0 : pf->proto_xtr = NULL;
3014 : :
3015 : : /* Uninit TM configuration */
3016 : 0 : ice_tm_conf_uninit(dev);
3017 : :
3018 [ # # ]: 0 : if (ad->devargs.pps_out_ena) {
3019 : 0 : ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(pin_idx, timer), 0);
3020 : 0 : ICE_WRITE_REG(hw, GLTSYN_CLKO(pin_idx, timer), 0);
3021 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_L(pin_idx, timer), 0);
3022 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_H(pin_idx, timer), 0);
3023 : :
3024 : : val = GLGEN_GPIO_CTL_PIN_DIR_M;
3025 : 0 : ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(pin_idx), val);
3026 : : }
3027 : :
3028 : : /* disable uio intr before callback unregister */
3029 : 0 : rte_intr_disable(intr_handle);
3030 : :
3031 : 0 : return ret;
3032 : : }
3033 : :
3034 : : static int
3035 : 0 : ice_dev_uninit(struct rte_eth_dev *dev)
3036 : : {
3037 : 0 : ice_dev_close(dev);
3038 : :
3039 : 0 : return 0;
3040 : : }
3041 : :
3042 : : static bool
3043 : : is_hash_cfg_valid(struct ice_rss_hash_cfg *cfg)
3044 : : {
3045 [ # # # # ]: 0 : return (cfg->hash_flds != 0 && cfg->addl_hdrs != 0) ? true : false;
3046 : : }
3047 : :
3048 : : static void
3049 : : hash_cfg_reset(struct ice_rss_hash_cfg *cfg)
3050 : : {
3051 : 0 : cfg->hash_flds = 0;
3052 : 0 : cfg->addl_hdrs = 0;
3053 : 0 : cfg->symm = 0;
3054 : 0 : cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
3055 : 0 : }
3056 : :
3057 : : static int
3058 : 0 : ice_hash_moveout(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3059 : : {
3060 : : int status;
3061 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3062 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
3063 : :
3064 [ # # ]: 0 : if (!is_hash_cfg_valid(cfg))
3065 : : return -ENOENT;
3066 : :
3067 : 0 : status = ice_rem_rss_cfg(hw, vsi->idx, cfg);
3068 [ # # ]: 0 : if (status && status != ICE_ERR_DOES_NOT_EXIST) {
3069 : 0 : PMD_DRV_LOG(ERR,
3070 : : "ice_rem_rss_cfg failed for VSI:%d, error:%d",
3071 : : vsi->idx, status);
3072 : 0 : return -EBUSY;
3073 : : }
3074 : :
3075 : : return 0;
3076 : : }
3077 : :
3078 : : static int
3079 : 0 : ice_hash_moveback(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3080 : : {
3081 : : int status;
3082 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3083 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
3084 : :
3085 [ # # ]: 0 : if (!is_hash_cfg_valid(cfg))
3086 : : return -ENOENT;
3087 : :
3088 : 0 : status = ice_add_rss_cfg(hw, vsi->idx, cfg);
3089 [ # # ]: 0 : if (status) {
3090 : 0 : PMD_DRV_LOG(ERR,
3091 : : "ice_add_rss_cfg failed for VSI:%d, error:%d",
3092 : : vsi->idx, status);
3093 : 0 : return -EBUSY;
3094 : : }
3095 : :
3096 : : return 0;
3097 : : }
3098 : :
3099 : : static int
3100 : : ice_hash_remove(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3101 : : {
3102 : : int ret;
3103 : :
3104 : 0 : ret = ice_hash_moveout(pf, cfg);
3105 [ # # # # : 0 : if (ret && (ret != -ENOENT))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
3106 : : return ret;
3107 : :
3108 : : hash_cfg_reset(cfg);
3109 : :
3110 : 0 : return 0;
3111 : : }
3112 : :
3113 : : static int
3114 : 0 : ice_add_rss_cfg_pre_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
3115 : : u8 ctx_idx)
3116 : : {
3117 : : int ret;
3118 : :
3119 [ # # # # : 0 : switch (ctx_idx) {
# # # # ]
3120 : 0 : case ICE_HASH_GTPU_CTX_EH_IP:
3121 : 0 : ret = ice_hash_remove(pf,
3122 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3123 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3124 : : return ret;
3125 : :
3126 : 0 : ret = ice_hash_remove(pf,
3127 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3128 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3129 : : return ret;
3130 : :
3131 : 0 : ret = ice_hash_remove(pf,
3132 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3133 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3134 : : return ret;
3135 : :
3136 : 0 : ret = ice_hash_remove(pf,
3137 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3138 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3139 : : return ret;
3140 : :
3141 : 0 : ret = ice_hash_remove(pf,
3142 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3143 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3144 : : return ret;
3145 : :
3146 : 0 : ret = ice_hash_remove(pf,
3147 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3148 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3149 : : return ret;
3150 : :
3151 : 0 : ret = ice_hash_remove(pf,
3152 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3153 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3154 : : return ret;
3155 : :
3156 : 0 : ret = ice_hash_remove(pf,
3157 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3158 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3159 : 0 : return ret;
3160 : :
3161 : : break;
3162 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_UDP:
3163 : 0 : ret = ice_hash_remove(pf,
3164 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3165 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3166 : : return ret;
3167 : :
3168 : 0 : ret = ice_hash_remove(pf,
3169 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3170 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3171 : : return ret;
3172 : :
3173 : 0 : ret = ice_hash_moveout(pf,
3174 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3175 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3176 : : return ret;
3177 : :
3178 : 0 : ret = ice_hash_moveout(pf,
3179 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3180 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3181 : : return ret;
3182 : :
3183 : 0 : ret = ice_hash_moveout(pf,
3184 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3185 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3186 : : return ret;
3187 : :
3188 : 0 : ret = ice_hash_moveout(pf,
3189 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3190 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3191 : 0 : return ret;
3192 : :
3193 : : break;
3194 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_TCP:
3195 : 0 : ret = ice_hash_remove(pf,
3196 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3197 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3198 : : return ret;
3199 : :
3200 : 0 : ret = ice_hash_remove(pf,
3201 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3202 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3203 : : return ret;
3204 : :
3205 : 0 : ret = ice_hash_moveout(pf,
3206 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3207 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3208 : : return ret;
3209 : :
3210 : 0 : ret = ice_hash_moveout(pf,
3211 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3212 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3213 : : return ret;
3214 : :
3215 : 0 : ret = ice_hash_moveout(pf,
3216 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3217 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3218 : : return ret;
3219 : :
3220 : 0 : ret = ice_hash_moveout(pf,
3221 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3222 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3223 : 0 : return ret;
3224 : :
3225 : : break;
3226 : 0 : case ICE_HASH_GTPU_CTX_UP_IP:
3227 : 0 : ret = ice_hash_remove(pf,
3228 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3229 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3230 : : return ret;
3231 : :
3232 : 0 : ret = ice_hash_remove(pf,
3233 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3234 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3235 : : return ret;
3236 : :
3237 : 0 : ret = ice_hash_moveout(pf,
3238 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3239 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3240 : : return ret;
3241 : :
3242 : 0 : ret = ice_hash_moveout(pf,
3243 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3244 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3245 : : return ret;
3246 : :
3247 : 0 : ret = ice_hash_moveout(pf,
3248 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3249 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3250 : 0 : return ret;
3251 : :
3252 : : break;
3253 : 0 : case ICE_HASH_GTPU_CTX_UP_IP_UDP:
3254 : : case ICE_HASH_GTPU_CTX_UP_IP_TCP:
3255 : 0 : ret = ice_hash_moveout(pf,
3256 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3257 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3258 : : return ret;
3259 : :
3260 : 0 : ret = ice_hash_moveout(pf,
3261 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3262 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3263 : : return ret;
3264 : :
3265 : 0 : ret = ice_hash_moveout(pf,
3266 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3267 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3268 : 0 : return ret;
3269 : :
3270 : : break;
3271 : 0 : case ICE_HASH_GTPU_CTX_DW_IP:
3272 : 0 : ret = ice_hash_remove(pf,
3273 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3274 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3275 : : return ret;
3276 : :
3277 : 0 : ret = ice_hash_remove(pf,
3278 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3279 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3280 : : return ret;
3281 : :
3282 : 0 : ret = ice_hash_moveout(pf,
3283 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3284 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3285 : : return ret;
3286 : :
3287 : 0 : ret = ice_hash_moveout(pf,
3288 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3289 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3290 : : return ret;
3291 : :
3292 : 0 : ret = ice_hash_moveout(pf,
3293 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3294 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3295 : 0 : return ret;
3296 : :
3297 : : break;
3298 : 0 : case ICE_HASH_GTPU_CTX_DW_IP_UDP:
3299 : : case ICE_HASH_GTPU_CTX_DW_IP_TCP:
3300 : 0 : ret = ice_hash_moveout(pf,
3301 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3302 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3303 : : return ret;
3304 : :
3305 : 0 : ret = ice_hash_moveout(pf,
3306 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3307 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3308 : : return ret;
3309 : :
3310 : 0 : ret = ice_hash_moveout(pf,
3311 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3312 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3313 : 0 : return ret;
3314 : :
3315 : : break;
3316 : : default:
3317 : : break;
3318 : : }
3319 : :
3320 : : return 0;
3321 : : }
3322 : :
3323 : 0 : static u8 calc_gtpu_ctx_idx(uint32_t hdr)
3324 : : {
3325 : : u8 eh_idx, ip_idx;
3326 : :
3327 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_GTPU_EH)
3328 : : eh_idx = 0;
3329 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_GTPU_UP)
3330 : : eh_idx = 1;
3331 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_GTPU_DWN)
3332 : : eh_idx = 2;
3333 : : else
3334 : : return ICE_HASH_GTPU_CTX_MAX;
3335 : :
3336 : : ip_idx = 0;
3337 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_UDP)
3338 : : ip_idx = 1;
3339 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_TCP)
3340 : : ip_idx = 2;
3341 : :
3342 [ # # ]: 0 : if (hdr & (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6))
3343 : 0 : return eh_idx * 3 + ip_idx;
3344 : : else
3345 : : return ICE_HASH_GTPU_CTX_MAX;
3346 : : }
3347 : :
3348 : : static int
3349 : 0 : ice_add_rss_cfg_pre(struct ice_pf *pf, uint32_t hdr)
3350 : : {
3351 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
3352 : :
3353 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_IPV4)
3354 : 0 : return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu4,
3355 : : gtpu_ctx_idx);
3356 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
3357 : 0 : return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu6,
3358 : : gtpu_ctx_idx);
3359 : :
3360 : : return 0;
3361 : : }
3362 : :
3363 : : static int
3364 : 0 : ice_add_rss_cfg_post_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
3365 : : u8 ctx_idx, struct ice_rss_hash_cfg *cfg)
3366 : : {
3367 : : int ret;
3368 : :
3369 [ # # ]: 0 : if (ctx_idx < ICE_HASH_GTPU_CTX_MAX)
3370 : 0 : ctx->ctx[ctx_idx] = *cfg;
3371 : :
3372 [ # # # # ]: 0 : switch (ctx_idx) {
3373 : : case ICE_HASH_GTPU_CTX_EH_IP:
3374 : : break;
3375 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_UDP:
3376 : 0 : ret = ice_hash_moveback(pf,
3377 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3378 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3379 : : return ret;
3380 : :
3381 : 0 : ret = ice_hash_moveback(pf,
3382 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3383 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3384 : : return ret;
3385 : :
3386 : 0 : ret = ice_hash_moveback(pf,
3387 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3388 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3389 : : return ret;
3390 : :
3391 : 0 : ret = ice_hash_moveback(pf,
3392 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3393 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3394 : 0 : return ret;
3395 : :
3396 : : break;
3397 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_TCP:
3398 : 0 : ret = ice_hash_moveback(pf,
3399 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3400 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3401 : : return ret;
3402 : :
3403 : 0 : ret = ice_hash_moveback(pf,
3404 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3405 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3406 : : return ret;
3407 : :
3408 : 0 : ret = ice_hash_moveback(pf,
3409 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3410 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3411 : : return ret;
3412 : :
3413 : 0 : ret = ice_hash_moveback(pf,
3414 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3415 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3416 : 0 : return ret;
3417 : :
3418 : : break;
3419 : 0 : case ICE_HASH_GTPU_CTX_UP_IP:
3420 : : case ICE_HASH_GTPU_CTX_UP_IP_UDP:
3421 : : case ICE_HASH_GTPU_CTX_UP_IP_TCP:
3422 : : case ICE_HASH_GTPU_CTX_DW_IP:
3423 : : case ICE_HASH_GTPU_CTX_DW_IP_UDP:
3424 : : case ICE_HASH_GTPU_CTX_DW_IP_TCP:
3425 : 0 : ret = ice_hash_moveback(pf,
3426 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3427 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3428 : : return ret;
3429 : :
3430 : 0 : ret = ice_hash_moveback(pf,
3431 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3432 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3433 : : return ret;
3434 : :
3435 : 0 : ret = ice_hash_moveback(pf,
3436 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3437 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3438 : 0 : return ret;
3439 : :
3440 : : break;
3441 : : default:
3442 : : break;
3443 : : }
3444 : :
3445 : : return 0;
3446 : : }
3447 : :
3448 : : static int
3449 : 0 : ice_add_rss_cfg_post(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3450 : : {
3451 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(cfg->addl_hdrs);
3452 : :
3453 [ # # ]: 0 : if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV4)
3454 : 0 : return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu4,
3455 : : gtpu_ctx_idx, cfg);
3456 [ # # ]: 0 : else if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV6)
3457 : 0 : return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu6,
3458 : : gtpu_ctx_idx, cfg);
3459 : :
3460 : : return 0;
3461 : : }
3462 : :
3463 : : static void
3464 : 0 : ice_rem_rss_cfg_post(struct ice_pf *pf, uint32_t hdr)
3465 : : {
3466 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
3467 : :
3468 [ # # ]: 0 : if (gtpu_ctx_idx >= ICE_HASH_GTPU_CTX_MAX)
3469 : : return;
3470 : :
3471 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_IPV4)
3472 : 0 : hash_cfg_reset(&pf->hash_ctx.gtpu4.ctx[gtpu_ctx_idx]);
3473 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
3474 : 0 : hash_cfg_reset(&pf->hash_ctx.gtpu6.ctx[gtpu_ctx_idx]);
3475 : : }
3476 : :
3477 : : int
3478 : 0 : ice_rem_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
3479 : : struct ice_rss_hash_cfg *cfg)
3480 : : {
3481 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3482 : : int ret;
3483 : :
3484 : 0 : ret = ice_rem_rss_cfg(hw, vsi_id, cfg);
3485 [ # # ]: 0 : if (ret && ret != ICE_ERR_DOES_NOT_EXIST)
3486 : 0 : PMD_DRV_LOG(ERR, "remove rss cfg failed");
3487 : :
3488 : 0 : ice_rem_rss_cfg_post(pf, cfg->addl_hdrs);
3489 : :
3490 : 0 : return 0;
3491 : : }
3492 : :
3493 : : int
3494 : 0 : ice_add_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
3495 : : struct ice_rss_hash_cfg *cfg)
3496 : : {
3497 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3498 : : int ret;
3499 : :
3500 : 0 : ret = ice_add_rss_cfg_pre(pf, cfg->addl_hdrs);
3501 [ # # ]: 0 : if (ret)
3502 : 0 : PMD_DRV_LOG(ERR, "add rss cfg pre failed");
3503 : :
3504 : 0 : ret = ice_add_rss_cfg(hw, vsi_id, cfg);
3505 [ # # ]: 0 : if (ret)
3506 : 0 : PMD_DRV_LOG(ERR, "add rss cfg failed");
3507 : :
3508 : 0 : ret = ice_add_rss_cfg_post(pf, cfg);
3509 [ # # ]: 0 : if (ret)
3510 : 0 : PMD_DRV_LOG(ERR, "add rss cfg post failed");
3511 : :
3512 : 0 : return 0;
3513 : : }
3514 : :
3515 : : static void
3516 : 0 : ice_rss_hash_set(struct ice_pf *pf, uint64_t rss_hf)
3517 : : {
3518 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3519 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3520 : : struct ice_rss_hash_cfg cfg;
3521 : : int ret;
3522 : :
3523 : : #define ICE_RSS_HF_ALL ( \
3524 : : RTE_ETH_RSS_IPV4 | \
3525 : : RTE_ETH_RSS_IPV6 | \
3526 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
3527 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
3528 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
3529 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
3530 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
3531 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
3532 : :
3533 : 0 : ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
3534 [ # # ]: 0 : if (ret)
3535 : 0 : PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
3536 : : __func__, ret);
3537 : :
3538 : 0 : cfg.symm = 0;
3539 : 0 : cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
3540 : : /* Configure RSS for IPv4 with src/dst addr as input set */
3541 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4) {
3542 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3543 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3544 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3545 [ # # ]: 0 : if (ret)
3546 : 0 : PMD_DRV_LOG(ERR, "%s IPV4 rss flow fail %d",
3547 : : __func__, ret);
3548 : : }
3549 : :
3550 : : /* Configure RSS for IPv6 with src/dst addr as input set */
3551 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6) {
3552 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3553 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3554 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3555 [ # # ]: 0 : if (ret)
3556 : 0 : PMD_DRV_LOG(ERR, "%s IPV6 rss flow fail %d",
3557 : : __func__, ret);
3558 : : }
3559 : :
3560 : : /* Configure RSS for udp4 with src/dst addr and port as input set */
3561 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3562 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4 |
3563 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3564 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV4;
3565 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3566 [ # # ]: 0 : if (ret)
3567 : 0 : PMD_DRV_LOG(ERR, "%s UDP_IPV4 rss flow fail %d",
3568 : : __func__, ret);
3569 : : }
3570 : :
3571 : : /* Configure RSS for udp6 with src/dst addr and port as input set */
3572 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3573 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6 |
3574 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3575 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV6;
3576 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3577 [ # # ]: 0 : if (ret)
3578 : 0 : PMD_DRV_LOG(ERR, "%s UDP_IPV6 rss flow fail %d",
3579 : : __func__, ret);
3580 : : }
3581 : :
3582 : : /* Configure RSS for tcp4 with src/dst addr and port as input set */
3583 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3584 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4 |
3585 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3586 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV4;
3587 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3588 [ # # ]: 0 : if (ret)
3589 : 0 : PMD_DRV_LOG(ERR, "%s TCP_IPV4 rss flow fail %d",
3590 : : __func__, ret);
3591 : : }
3592 : :
3593 : : /* Configure RSS for tcp6 with src/dst addr and port as input set */
3594 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3595 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6 |
3596 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3597 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV6;
3598 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3599 [ # # ]: 0 : if (ret)
3600 : 0 : PMD_DRV_LOG(ERR, "%s TCP_IPV6 rss flow fail %d",
3601 : : __func__, ret);
3602 : : }
3603 : :
3604 : : /* Configure RSS for sctp4 with src/dst addr and port as input set */
3605 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) {
3606 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4 |
3607 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3608 : 0 : cfg.hash_flds = ICE_HASH_SCTP_IPV4;
3609 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3610 [ # # ]: 0 : if (ret)
3611 : 0 : PMD_DRV_LOG(ERR, "%s SCTP_IPV4 rss flow fail %d",
3612 : : __func__, ret);
3613 : : }
3614 : :
3615 : : /* Configure RSS for sctp6 with src/dst addr and port as input set */
3616 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) {
3617 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6 |
3618 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3619 : 0 : cfg.hash_flds = ICE_HASH_SCTP_IPV6;
3620 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3621 [ # # ]: 0 : if (ret)
3622 : 0 : PMD_DRV_LOG(ERR, "%s SCTP_IPV6 rss flow fail %d",
3623 : : __func__, ret);
3624 : : }
3625 : :
3626 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4) {
3627 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV4 |
3628 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3629 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3630 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3631 [ # # ]: 0 : if (ret)
3632 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4 rss flow fail %d",
3633 : : __func__, ret);
3634 : : }
3635 : :
3636 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6) {
3637 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV6 |
3638 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3639 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3640 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3641 [ # # ]: 0 : if (ret)
3642 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6 rss flow fail %d",
3643 : : __func__, ret);
3644 : : }
3645 : :
3646 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3647 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3648 : : ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3649 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV4;
3650 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3651 [ # # ]: 0 : if (ret)
3652 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_UDP rss flow fail %d",
3653 : : __func__, ret);
3654 : : }
3655 : :
3656 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3657 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3658 : : ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3659 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV6;
3660 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3661 [ # # ]: 0 : if (ret)
3662 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_UDP rss flow fail %d",
3663 : : __func__, ret);
3664 : : }
3665 : :
3666 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3667 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3668 : : ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3669 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV4;
3670 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3671 [ # # ]: 0 : if (ret)
3672 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_TCP rss flow fail %d",
3673 : : __func__, ret);
3674 : : }
3675 : :
3676 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3677 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3678 : : ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3679 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV6;
3680 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3681 [ # # ]: 0 : if (ret)
3682 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_TCP rss flow fail %d",
3683 : : __func__, ret);
3684 : : }
3685 : :
3686 : 0 : pf->rss_hf = rss_hf & ICE_RSS_HF_ALL;
3687 : 0 : }
3688 : :
3689 : : static void
3690 : 0 : ice_get_default_rss_key(uint8_t *rss_key, uint32_t rss_key_size)
3691 : : {
3692 : : static struct ice_aqc_get_set_rss_keys default_key;
3693 : : static bool default_key_done;
3694 : : uint8_t *key = (uint8_t *)&default_key;
3695 : : size_t i;
3696 : :
3697 [ # # ]: 0 : if (rss_key_size > sizeof(default_key)) {
3698 : 0 : PMD_DRV_LOG(WARNING,
3699 : : "requested size %u is larger than default %zu, "
3700 : : "only %zu bytes are gotten for key",
3701 : : rss_key_size, sizeof(default_key),
3702 : : sizeof(default_key));
3703 : : }
3704 : :
3705 [ # # ]: 0 : if (!default_key_done) {
3706 : : /* Calculate the default hash key */
3707 [ # # ]: 0 : for (i = 0; i < sizeof(default_key); i++)
3708 : 0 : key[i] = (uint8_t)rte_rand();
3709 : 0 : default_key_done = true;
3710 : : }
3711 : 0 : memcpy(rss_key, key, RTE_MIN(rss_key_size, sizeof(default_key)));
3712 : 0 : }
3713 : :
3714 : 0 : static int ice_init_rss(struct ice_pf *pf)
3715 : : {
3716 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3717 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3718 : 0 : struct rte_eth_dev_data *dev_data = pf->dev_data;
3719 : : struct ice_aq_get_set_rss_lut_params lut_params;
3720 : : struct rte_eth_rss_conf *rss_conf;
3721 : : struct ice_aqc_get_set_rss_keys key;
3722 : : uint16_t i, nb_q;
3723 : : int ret = 0;
3724 : 0 : bool is_safe_mode = pf->adapter->is_safe_mode;
3725 : : uint32_t reg;
3726 : :
3727 : : rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
3728 : 0 : nb_q = dev_data->nb_rx_queues;
3729 : 0 : vsi->rss_key_size = ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE +
3730 : : ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE;
3731 : 0 : vsi->rss_lut_size = pf->hash_lut_size;
3732 : :
3733 [ # # ]: 0 : if (nb_q == 0) {
3734 : 0 : PMD_DRV_LOG(WARNING,
3735 : : "RSS is not supported as rx queues number is zero");
3736 : 0 : return 0;
3737 : : }
3738 : :
3739 [ # # ]: 0 : if (is_safe_mode) {
3740 : 0 : PMD_DRV_LOG(WARNING, "RSS is not supported in safe mode");
3741 : 0 : return 0;
3742 : : }
3743 : :
3744 [ # # ]: 0 : if (!vsi->rss_key) {
3745 : 0 : vsi->rss_key = rte_zmalloc(NULL,
3746 : : vsi->rss_key_size, 0);
3747 [ # # ]: 0 : if (vsi->rss_key == NULL) {
3748 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3749 : 0 : return -ENOMEM;
3750 : : }
3751 : : }
3752 [ # # ]: 0 : if (!vsi->rss_lut) {
3753 : 0 : vsi->rss_lut = rte_zmalloc(NULL,
3754 : 0 : vsi->rss_lut_size, 0);
3755 [ # # ]: 0 : if (vsi->rss_lut == NULL) {
3756 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3757 : 0 : rte_free(vsi->rss_key);
3758 : 0 : vsi->rss_key = NULL;
3759 : 0 : return -ENOMEM;
3760 : : }
3761 : : }
3762 : : /* configure RSS key */
3763 [ # # ]: 0 : if (!rss_conf->rss_key)
3764 : 0 : ice_get_default_rss_key(vsi->rss_key, vsi->rss_key_size);
3765 : : else
3766 : 0 : memcpy(vsi->rss_key, rss_conf->rss_key,
3767 : 0 : RTE_MIN(rss_conf->rss_key_len,
3768 : : vsi->rss_key_size));
3769 : :
3770 : 0 : memcpy(key.standard_rss_key, vsi->rss_key,
3771 : : ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
3772 : : memcpy(key.extended_hash_key,
3773 : : &vsi->rss_key[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE],
3774 : : ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE);
3775 : 0 : ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
3776 [ # # ]: 0 : if (ret)
3777 : 0 : goto out;
3778 : :
3779 : : /* init RSS LUT table */
3780 [ # # ]: 0 : for (i = 0; i < vsi->rss_lut_size; i++)
3781 : 0 : vsi->rss_lut[i] = i % nb_q;
3782 : :
3783 [ # # # # ]: 0 : if (nb_q <= ICE_RSS_LUT_GLOBAL_QUEUE_NB && (hw)->mac_type == ICE_MAC_E830) {
3784 : : struct ice_vsi_ctx vsi_ctx;
3785 : : uint16_t global_lut;
3786 : :
3787 [ # # ]: 0 : if (!vsi->global_lut_allocated) {
3788 : 0 : ret = ice_alloc_rss_global_lut(hw, false, &global_lut);
3789 [ # # ]: 0 : if (ret)
3790 : 0 : goto out;
3791 : 0 : vsi->global_lut_allocated = true;
3792 : 0 : vsi->global_lut_id = global_lut;
3793 : : }
3794 : 0 : global_lut = vsi->global_lut_id;
3795 : :
3796 : 0 : vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
3797 : 0 : vsi_ctx.info = vsi->info;
3798 : 0 : vsi_ctx.info.q_opt_rss &= ICE_AQ_VSI_Q_OPT_RSS_LUT_M |
3799 : : ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M;
3800 : 0 : vsi_ctx.info.q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_LUT_GBL |
3801 : 0 : ((global_lut << ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_S) &
3802 : : ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
3803 : :
3804 : 0 : vsi_ctx.info.valid_sections =
3805 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
3806 : :
3807 : 0 : ret = ice_update_vsi(hw, vsi->idx, &vsi_ctx, NULL);
3808 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
3809 : 0 : PMD_INIT_LOG(ERR, "update vsi failed, err = %d", ret);
3810 : 0 : goto out;
3811 : : }
3812 : :
3813 : 0 : vsi->info = vsi_ctx.info;
3814 : 0 : lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL;
3815 : 0 : lut_params.global_lut_id = global_lut;
3816 : : } else {
3817 : 0 : lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
3818 : 0 : lut_params.global_lut_id = 0;
3819 : : }
3820 : :
3821 : 0 : lut_params.vsi_handle = vsi->idx;
3822 : 0 : lut_params.lut_size = vsi->rss_lut_size;
3823 : 0 : lut_params.lut = vsi->rss_lut;
3824 : 0 : ret = ice_aq_set_rss_lut(hw, &lut_params);
3825 [ # # ]: 0 : if (ret)
3826 : 0 : goto out;
3827 : :
3828 : : /* Enable registers for symmetric_toeplitz function. */
3829 : 0 : reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
3830 : 0 : reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
3831 : : (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
3832 : 0 : ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
3833 : :
3834 : : /* RSS hash configuration */
3835 : 0 : ice_rss_hash_set(pf, rss_conf->rss_hf);
3836 : :
3837 : 0 : return 0;
3838 : 0 : out:
3839 : 0 : rte_free(vsi->rss_key);
3840 : 0 : vsi->rss_key = NULL;
3841 : 0 : rte_free(vsi->rss_lut);
3842 : 0 : vsi->rss_lut = NULL;
3843 : 0 : return -EINVAL;
3844 : : }
3845 : :
3846 : : static int
3847 : 0 : check_dcb_conf(int is_8_ports, struct rte_eth_dcb_rx_conf *dcb_conf)
3848 : : {
3849 : : uint32_t tc_map = 0;
3850 : : int i;
3851 : :
3852 : 0 : enum rte_eth_nb_tcs nb_tcs = dcb_conf->nb_tcs;
3853 [ # # ]: 0 : if (nb_tcs != RTE_ETH_4_TCS && is_8_ports) {
3854 : 0 : PMD_DRV_LOG(ERR, "Invalid num TCs setting - only 4 TCs are supported");
3855 : 0 : return -1;
3856 [ # # ]: 0 : } else if (nb_tcs != RTE_ETH_4_TCS && nb_tcs != RTE_ETH_8_TCS) {
3857 : 0 : PMD_DRV_LOG(ERR, "Invalid num TCs setting - only 8 TCs or 4 TCs are supported");
3858 : 0 : return -1;
3859 : : }
3860 : :
3861 : : /* Check if associated TC are in continuous range */
3862 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++)
3863 : 0 : tc_map |= 1 << (dcb_conf->dcb_tc[i] & 0x7);
3864 : :
3865 [ # # ]: 0 : if (!rte_is_power_of_2(tc_map + 1)) {
3866 : 0 : PMD_DRV_LOG(ERR,
3867 : : "Bad VLAN User Priority to Traffic Class association in DCB config");
3868 : 0 : return -1;
3869 : : }
3870 : :
3871 : 0 : return rte_popcount32(tc_map);
3872 : : }
3873 : :
3874 : : static int
3875 : 0 : ice_dev_configure(struct rte_eth_dev *dev)
3876 : : {
3877 : 0 : struct ice_adapter *ad =
3878 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3879 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3880 : : int ret;
3881 : :
3882 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
3883 : : * bulk allocation or vector Rx preconditions we will reset it.
3884 : : */
3885 : 0 : ad->rx_bulk_alloc_allowed = true;
3886 : 0 : ad->tx_simple_allowed = true;
3887 : :
3888 : 0 : ad->rx_func_type = ICE_RX_DEFAULT;
3889 : 0 : ad->tx_func_type = ICE_TX_DEFAULT;
3890 : :
3891 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
3892 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
3893 : :
3894 [ # # ]: 0 : if (dev->data->nb_rx_queues) {
3895 : 0 : ret = ice_init_rss(pf);
3896 [ # # ]: 0 : if (ret) {
3897 : 0 : PMD_DRV_LOG(ERR, "Failed to enable rss for PF");
3898 : 0 : return ret;
3899 : : }
3900 : : }
3901 : :
3902 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
3903 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3904 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3905 : 0 : struct ice_port_info *port_info = hw->port_info;
3906 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
3907 : 0 : struct ice_dcbx_cfg *local_dcb_conf = &qos_cfg->local_dcbx_cfg;
3908 : : struct ice_vsi_ctx ctxt;
3909 : 0 : struct rte_eth_dcb_rx_conf *dcb_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3910 : : int i;
3911 : 0 : enum rte_eth_nb_tcs nb_tcs = dcb_conf->nb_tcs;
3912 : : int nb_tc_used, queues_per_tc;
3913 : : uint16_t total_q_nb;
3914 : :
3915 : 0 : nb_tc_used = check_dcb_conf(ice_get_port_max_cgd(hw) == ICE_4_CGD_PER_PORT,
3916 : : dcb_conf);
3917 [ # # ]: 0 : if (nb_tc_used < 0)
3918 : 0 : return -EINVAL;
3919 : :
3920 : 0 : ctxt.info = vsi->info;
3921 [ # # ]: 0 : if (rte_le_to_cpu_16(ctxt.info.mapping_flags) == ICE_AQ_VSI_Q_MAP_NONCONTIG) {
3922 : 0 : PMD_DRV_LOG(ERR, "VSI configured with non contiguous queues, DCB is not supported");
3923 : 0 : return -EINVAL;
3924 : : }
3925 : :
3926 : 0 : total_q_nb = dev->data->nb_rx_queues;
3927 : 0 : queues_per_tc = total_q_nb / nb_tc_used;
3928 [ # # ]: 0 : if (total_q_nb % nb_tc_used != 0) {
3929 : 0 : PMD_DRV_LOG(ERR, "For DCB, number of queues must be evenly divisible by number of used TCs");
3930 : 0 : return -EINVAL;
3931 [ # # ]: 0 : } else if (!rte_is_power_of_2(queues_per_tc)) {
3932 : 0 : PMD_DRV_LOG(ERR, "For DCB, number of queues per TC must be a power of 2");
3933 : 0 : return -EINVAL;
3934 : : }
3935 : :
3936 [ # # ]: 0 : for (i = 0; i < nb_tc_used; i++) {
3937 : 0 : ctxt.info.tc_mapping[i] =
3938 : 0 : rte_cpu_to_le_16(((i * queues_per_tc) << ICE_AQ_VSI_TC_Q_OFFSET_S) |
3939 : : (rte_log2_u32(queues_per_tc) << ICE_AQ_VSI_TC_Q_NUM_S));
3940 : : }
3941 : :
3942 : : memset(local_dcb_conf, 0, sizeof(*local_dcb_conf));
3943 : :
3944 : 0 : local_dcb_conf->etscfg.maxtcs = nb_tcs;
3945 : :
3946 : : /* Associate each VLAN UP with particular TC */
3947 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
3948 : 0 : local_dcb_conf->etscfg.prio_table[i] = dcb_conf->dcb_tc[i];
3949 : 0 : local_dcb_conf->etsrec.prio_table[i] = dcb_conf->dcb_tc[i];
3950 : : }
3951 : :
3952 : : /*
3953 : : * Since current API does not support setting ETS BW Share and Scheduler
3954 : : * configure all TC as ETS and evenly share load across all existing TC
3955 : : **/
3956 : 0 : const int bw_share_percent = 100 / nb_tc_used;
3957 : : const int bw_share_left = 100 - bw_share_percent * nb_tc_used;
3958 [ # # ]: 0 : for (i = 0; i < nb_tc_used; i++) {
3959 : : /* Per TC bandwidth table (all valued must add up to 100%), valid on ETS */
3960 : 0 : local_dcb_conf->etscfg.tcbwtable[i] = bw_share_percent;
3961 : 0 : local_dcb_conf->etsrec.tcbwtable[i] = bw_share_percent;
3962 : :
3963 : : /**< Transmission Selection Algorithm. 0 - Strict prio, 2 - ETS */
3964 : 0 : local_dcb_conf->etscfg.tsatable[i] = 2;
3965 : 0 : local_dcb_conf->etsrec.tsatable[i] = 2;
3966 : : }
3967 : :
3968 [ # # ]: 0 : for (i = 0; i < bw_share_left; i++) {
3969 : 0 : local_dcb_conf->etscfg.tcbwtable[i]++;
3970 : 0 : local_dcb_conf->etsrec.tcbwtable[i]++;
3971 : : }
3972 : :
3973 : 0 : local_dcb_conf->pfc.pfccap = nb_tcs;
3974 : : local_dcb_conf->pfc.pfcena = 0;
3975 : :
3976 : 0 : ret = ice_set_dcb_cfg(port_info);
3977 [ # # ]: 0 : if (ret) {
3978 : 0 : PMD_DRV_LOG(ERR, "Failed to configure DCB for PF");
3979 : 0 : return ret;
3980 : : }
3981 : :
3982 : : /* Update VSI queue allocatios per TC */
3983 : 0 : ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3984 : 0 : ctxt.info.mapping_flags = rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
3985 : :
3986 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3987 [ # # ]: 0 : if (ret) {
3988 : 0 : PMD_DRV_LOG(ERR, "Failed to configure queue mapping");
3989 : 0 : return ret;
3990 : : }
3991 : :
3992 : 0 : ctxt.info.valid_sections = 0;
3993 : 0 : vsi->info = ctxt.info;
3994 : :
3995 : 0 : hw->port_info->fc.current_mode = ICE_FC_PFC;
3996 : : }
3997 : :
3998 : : return 0;
3999 : : }
4000 : :
4001 : : static int
4002 : 0 : ice_get_dcb_info(struct rte_eth_dev *dev, struct rte_eth_dcb_info *dcb_info)
4003 : : {
4004 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4005 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
4006 : 0 : struct ice_port_info *port_info = hw->port_info;
4007 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
4008 : : struct ice_dcbx_cfg *dcb_conf = &qos_cfg->local_dcbx_cfg;
4009 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4010 : :
4011 [ # # ]: 0 : if (rte_le_to_cpu_16(vsi->info.mapping_flags) == ICE_AQ_VSI_Q_MAP_NONCONTIG) {
4012 : 0 : PMD_DRV_LOG(ERR, "VSI configured with non contiguous queues, DCB is not supported");
4013 : 0 : return -ENOTSUP;
4014 : : }
4015 : :
4016 : 0 : dcb_info->nb_tcs = dcb_conf->etscfg.maxtcs;
4017 [ # # ]: 0 : for (int i = 0; i < dcb_info->nb_tcs; i++) {
4018 : 0 : dcb_info->prio_tc[i] = dcb_conf->etscfg.prio_table[i];
4019 : 0 : dcb_info->tc_bws[i] = dcb_conf->etscfg.tcbwtable[i];
4020 : : /* Using VMDQ pool zero since DCB+VMDQ is not supported */
4021 : 0 : uint16_t tc_rx_q_map = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
4022 : 0 : dcb_info->tc_queue.tc_rxq[0][i].base = tc_rx_q_map & ICE_AQ_VSI_TC_Q_OFFSET_M;
4023 : 0 : dcb_info->tc_queue.tc_rxq[0][i].nb_queue =
4024 : 0 : 1 << ((tc_rx_q_map & ICE_AQ_VSI_TC_Q_NUM_M) >> ICE_AQ_VSI_TC_Q_NUM_S);
4025 : :
4026 : 0 : dcb_info->tc_queue.tc_txq[0][i].base = dcb_info->tc_queue.tc_rxq[0][i].base;
4027 : 0 : dcb_info->tc_queue.tc_txq[0][i].nb_queue = dcb_info->tc_queue.tc_rxq[0][i].nb_queue;
4028 : : }
4029 : :
4030 : : return 0;
4031 : : }
4032 : :
4033 : : static int
4034 : 0 : ice_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
4035 : : {
4036 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4037 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
4038 : 0 : struct ice_port_info *port_info = hw->port_info;
4039 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
4040 : : struct ice_dcbx_cfg *dcb_conf = &qos_cfg->local_dcbx_cfg;
4041 : : int ret;
4042 : :
4043 : 0 : dcb_conf->pfc_mode = ICE_QOS_MODE_VLAN;
4044 : 0 : dcb_conf->pfc.willing = 0;
4045 : : /** pfccap should already be set by DCB config, check if zero */
4046 [ # # ]: 0 : if (dcb_conf->pfc.pfccap == 0) {
4047 : 0 : PMD_DRV_LOG(ERR, "DCB is not configured on the port, can not set PFC");
4048 : 0 : return -EINVAL;
4049 : : }
4050 : :
4051 : 0 : ret = ice_aq_set_pfc_mode(hw, ICE_AQC_PFC_VLAN_BASED_PFC, NULL);
4052 [ # # ]: 0 : if (ret) {
4053 : 0 : PMD_DRV_LOG(ERR, "Failed to enable PFC in VLAN mode");
4054 : 0 : return ret;
4055 : : }
4056 : :
4057 : 0 : u8 tc = ice_get_tc_by_priority(hw, pfc_conf->priority);
4058 : :
4059 [ # # # # : 0 : switch (pfc_conf->fc.mode) {
# ]
4060 : 0 : case (RTE_ETH_FC_NONE):
4061 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4062 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4063 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4064 : 0 : break;
4065 : 0 : case (RTE_ETH_FC_RX_PAUSE):
4066 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4067 : 0 : dcb_conf->pfc.pfcena_asym_rx |= (1 << tc);
4068 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4069 : 0 : break;
4070 : 0 : case (RTE_ETH_FC_TX_PAUSE):
4071 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4072 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4073 : 0 : dcb_conf->pfc.pfcena_asym_tx |= (1 << tc);
4074 : 0 : break;
4075 : 0 : case (RTE_ETH_FC_FULL):
4076 : 0 : dcb_conf->pfc.pfcena |= (1 << tc);
4077 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4078 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4079 : 0 : break;
4080 : : }
4081 : :
4082 : 0 : ret = ice_set_dcb_cfg(port_info);
4083 [ # # ]: 0 : if (ret) {
4084 : 0 : PMD_DRV_LOG(ERR, "Failed to configure DCB for PF");
4085 : 0 : return ret;
4086 : : }
4087 : :
4088 : : /* Update high and low watermarks */
4089 : 0 : u32 high_watermark = pfc_conf->fc.high_water;
4090 [ # # ]: 0 : if (high_watermark > ICE_MAC_TC_MAX_WATERMARK)
4091 : : high_watermark = ICE_MAC_TC_MAX_WATERMARK;
4092 : :
4093 : 0 : u32 low_watermark = pfc_conf->fc.low_water;
4094 : : if (low_watermark > ICE_MAC_TC_MAX_WATERMARK)
4095 : : low_watermark = ICE_MAC_TC_MAX_WATERMARK;
4096 : :
4097 : 0 : int cgd_idx = ice_get_cgd_idx(hw, tc);
4098 : :
4099 [ # # ]: 0 : if (high_watermark)
4100 : 0 : wr32(hw, GLRPB_TCHW(cgd_idx), high_watermark);
4101 [ # # ]: 0 : if (low_watermark)
4102 : 0 : wr32(hw, GLRPB_TCLW(cgd_idx), low_watermark);
4103 : :
4104 : : /* Update pause quanta */
4105 [ # # ]: 0 : uint16_t max_frame_size = pf->dev_data->mtu ?
4106 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD :
4107 : : ICE_FRAME_SIZE_MAX;
4108 : 0 : ret = ice_aq_set_mac_pfc_cfg(hw, max_frame_size, 1 << tc, pfc_conf->fc.pause_time,
4109 : 0 : ((u32)pfc_conf->fc.pause_time + 1) / 2, false, NULL);
4110 [ # # ]: 0 : if (ret) {
4111 : 0 : PMD_DRV_LOG(ERR, "Can not update MAC configuration");
4112 : 0 : return ret;
4113 : : }
4114 : :
4115 : : /* Update forwarding of the non FC MAC control frames settings */
4116 [ # # ]: 0 : if ((hw)->mac_type == ICE_MAC_E830) {
4117 : : #define E830_MAC_COMMAND_CONFIG(pi) (((pi)->phy.link_info.link_speed == ICE_AQ_LINK_SPEED_200GB) ? \
4118 : : E830_PRTMAC_200G_COMMAND_CONFIG : E830_PRTMAC_COMMAND_CONFIG)
4119 : :
4120 [ # # ]: 0 : u32 mac_config = rd32(hw, E830_MAC_COMMAND_CONFIG(port_info));
4121 : :
4122 [ # # ]: 0 : if (pfc_conf->fc.mac_ctrl_frame_fwd)
4123 : 0 : mac_config |= E830_PRTMAC_COMMAND_CONFIG_CNTL_FRM_ENA_M;
4124 : : else
4125 : 0 : mac_config &= ~E830_PRTMAC_COMMAND_CONFIG_CNTL_FRM_ENA_M;
4126 : :
4127 [ # # ]: 0 : wr32(hw, E830_MAC_COMMAND_CONFIG(port_info), mac_config);
4128 : : }
4129 : :
4130 : : return 0;
4131 : : }
4132 : :
4133 : : static void
4134 : 0 : __vsi_queues_bind_intr(struct ice_vsi *vsi, uint16_t msix_vect,
4135 : : int base_queue, int nb_queue)
4136 : : {
4137 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4138 : : uint32_t val, val_tx;
4139 : : int rx_low_latency, i;
4140 : :
4141 : 0 : rx_low_latency = vsi->adapter->devargs.rx_low_latency;
4142 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
4143 : : /*do actual bind*/
4144 : 0 : val = (msix_vect & QINT_RQCTL_MSIX_INDX_M) |
4145 : : (0 << QINT_RQCTL_ITR_INDX_S) | QINT_RQCTL_CAUSE_ENA_M;
4146 : : val_tx = (msix_vect & QINT_TQCTL_MSIX_INDX_M) |
4147 : : (0 << QINT_TQCTL_ITR_INDX_S) | QINT_TQCTL_CAUSE_ENA_M;
4148 : :
4149 : 0 : PMD_DRV_LOG(INFO, "queue %d is binding to vect %d",
4150 : : base_queue + i, msix_vect);
4151 : :
4152 : : /* set ITR0 value */
4153 [ # # ]: 0 : if (rx_low_latency) {
4154 : : /**
4155 : : * Empirical configuration for optimal real time
4156 : : * latency reduced interrupt throttling to 2us
4157 : : */
4158 : 0 : ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x1);
4159 : 0 : ICE_WRITE_REG(hw, QRX_ITR(base_queue + i),
4160 : : QRX_ITR_NO_EXPR_M);
4161 : : } else {
4162 : 0 : ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x2);
4163 : 0 : ICE_WRITE_REG(hw, QRX_ITR(base_queue + i), 0);
4164 : : }
4165 : :
4166 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(base_queue + i), val);
4167 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(base_queue + i), val_tx);
4168 : : }
4169 : 0 : }
4170 : :
4171 : : void
4172 : 0 : ice_vsi_queues_bind_intr(struct ice_vsi *vsi)
4173 : : {
4174 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
4175 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4176 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4177 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4178 : 0 : uint16_t msix_vect = vsi->msix_intr;
4179 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
4180 : : rte_intr_nb_efd_get(intr_handle));
4181 : : uint16_t queue_idx = 0;
4182 : : int record = 0;
4183 : : int i;
4184 : :
4185 : : /* clear Rx/Tx queue interrupt */
4186 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4187 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
4188 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
4189 : : }
4190 : :
4191 : : /* PF bind interrupt */
4192 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
4193 : : queue_idx = 0;
4194 : : record = 1;
4195 : : }
4196 : :
4197 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4198 [ # # ]: 0 : if (nb_msix <= 1) {
4199 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
4200 : : msix_vect = ICE_MISC_VEC_ID;
4201 : :
4202 : : /* uio mapping all queue to one msix_vect */
4203 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
4204 : 0 : vsi->base_queue + i,
4205 : 0 : vsi->nb_used_qps - i);
4206 : :
4207 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
4208 : 0 : rte_intr_vec_list_index_set(intr_handle,
4209 : : queue_idx + i, msix_vect);
4210 : :
4211 : : break;
4212 : : }
4213 : :
4214 : : /* vfio 1:1 queue/msix_vect mapping */
4215 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
4216 : 0 : vsi->base_queue + i, 1);
4217 : :
4218 [ # # ]: 0 : if (!!record)
4219 : 0 : rte_intr_vec_list_index_set(intr_handle,
4220 : : queue_idx + i,
4221 : : msix_vect);
4222 : :
4223 : 0 : msix_vect++;
4224 : 0 : nb_msix--;
4225 : : }
4226 : 0 : }
4227 : :
4228 : : void
4229 : 0 : ice_vsi_enable_queues_intr(struct ice_vsi *vsi)
4230 : : {
4231 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
4232 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4233 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4234 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4235 : : uint16_t msix_intr, i;
4236 : :
4237 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
4238 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4239 : 0 : msix_intr = vsi->msix_intr + i;
4240 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
4241 : : GLINT_DYN_CTL_INTENA_M |
4242 : : GLINT_DYN_CTL_CLEARPBA_M |
4243 : : GLINT_DYN_CTL_ITR_INDX_M |
4244 : : GLINT_DYN_CTL_WB_ON_ITR_M);
4245 : : }
4246 : : else
4247 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
4248 : : GLINT_DYN_CTL_INTENA_M |
4249 : : GLINT_DYN_CTL_CLEARPBA_M |
4250 : : GLINT_DYN_CTL_ITR_INDX_M |
4251 : : GLINT_DYN_CTL_WB_ON_ITR_M);
4252 : 0 : }
4253 : :
4254 : : static int
4255 : 0 : ice_rxq_intr_setup(struct rte_eth_dev *dev)
4256 : : {
4257 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4258 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4259 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4260 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4261 : : uint32_t intr_vector = 0;
4262 : :
4263 : 0 : rte_intr_disable(intr_handle);
4264 : :
4265 : : /* check and configure queue intr-vector mapping */
4266 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
4267 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
4268 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
4269 : 0 : intr_vector = dev->data->nb_rx_queues;
4270 [ # # ]: 0 : if (intr_vector > ICE_MAX_INTR_QUEUE_NUM) {
4271 : 0 : PMD_DRV_LOG(ERR, "At most %d intr queues supported",
4272 : : ICE_MAX_INTR_QUEUE_NUM);
4273 : 0 : return -ENOTSUP;
4274 : : }
4275 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
4276 : : return -1;
4277 : : }
4278 : :
4279 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
4280 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, NULL,
4281 : 0 : dev->data->nb_rx_queues)) {
4282 : 0 : PMD_DRV_LOG(ERR,
4283 : : "Failed to allocate %d rx_queues intr_vec",
4284 : : dev->data->nb_rx_queues);
4285 : 0 : return -ENOMEM;
4286 : : }
4287 : : }
4288 : :
4289 : : /* Map queues with MSIX interrupt */
4290 : 0 : vsi->nb_used_qps = dev->data->nb_rx_queues;
4291 : 0 : ice_vsi_queues_bind_intr(vsi);
4292 : :
4293 : : /* Enable interrupts for all the queues */
4294 : 0 : ice_vsi_enable_queues_intr(vsi);
4295 : :
4296 : 0 : rte_intr_enable(intr_handle);
4297 : :
4298 : 0 : return 0;
4299 : : }
4300 : :
4301 : : static int
4302 : 0 : ice_get_link_info_safe(struct ice_pf *pf, bool ena_lse,
4303 : : struct ice_link_status *link)
4304 : : {
4305 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
4306 : : int ret;
4307 : :
4308 : 0 : rte_spinlock_lock(&pf->link_lock);
4309 : :
4310 : 0 : ret = ice_aq_get_link_info(hw->port_info, ena_lse, link, NULL);
4311 : :
4312 : : rte_spinlock_unlock(&pf->link_lock);
4313 : :
4314 : 0 : return ret;
4315 : : }
4316 : :
4317 : : static void
4318 : 0 : ice_get_init_link_status(struct rte_eth_dev *dev)
4319 : : {
4320 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4321 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
4322 : : struct ice_link_status link_status;
4323 : : int ret;
4324 : :
4325 : 0 : ret = ice_get_link_info_safe(pf, enable_lse, &link_status);
4326 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4327 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
4328 : 0 : pf->init_link_up = false;
4329 : 0 : return;
4330 : : }
4331 : :
4332 [ # # ]: 0 : if (link_status.link_info & ICE_AQ_LINK_UP)
4333 : 0 : pf->init_link_up = true;
4334 : : else
4335 : 0 : pf->init_link_up = false;
4336 : : }
4337 : :
4338 : : static int
4339 : 0 : ice_pps_out_cfg(struct ice_hw *hw, int idx, int timer)
4340 : : {
4341 : : uint64_t current_time, start_time;
4342 : : uint32_t hi, lo, lo2, func, val;
4343 : :
4344 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4345 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
4346 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4347 : :
4348 [ # # ]: 0 : if (lo2 < lo) {
4349 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4350 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
4351 : : }
4352 : :
4353 : 0 : current_time = ((uint64_t)hi << 32) | lo;
4354 : :
4355 : 0 : start_time = (current_time + NSEC_PER_SEC) /
4356 : : NSEC_PER_SEC * NSEC_PER_SEC;
4357 : 0 : start_time = start_time - PPS_OUT_DELAY_NS;
4358 : :
4359 : 0 : func = 8 + idx + timer * 4;
4360 : 0 : val = GLGEN_GPIO_CTL_PIN_DIR_M |
4361 : 0 : ((func << GLGEN_GPIO_CTL_PIN_FUNC_S) &
4362 : : GLGEN_GPIO_CTL_PIN_FUNC_M);
4363 : :
4364 : : /* Write clkout with half of period value */
4365 : 0 : ICE_WRITE_REG(hw, GLTSYN_CLKO(idx, timer), NSEC_PER_SEC / 2);
4366 : :
4367 : : /* Write TARGET time register */
4368 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_L(idx, timer), start_time & 0xffffffff);
4369 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_H(idx, timer), start_time >> 32);
4370 : :
4371 : : /* Write AUX_OUT register */
4372 : 0 : ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(idx, timer),
4373 : : GLTSYN_AUX_OUT_0_OUT_ENA_M | GLTSYN_AUX_OUT_0_OUTMOD_M);
4374 : :
4375 : : /* Write GPIO CTL register */
4376 : 0 : ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(idx), val);
4377 : :
4378 : 0 : return 0;
4379 : : }
4380 : :
4381 : : static int
4382 : 0 : ice_dev_start(struct rte_eth_dev *dev)
4383 : : {
4384 : 0 : struct rte_eth_dev_data *data = dev->data;
4385 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4386 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4387 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4388 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4389 : : struct ice_adapter *ad =
4390 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
4391 : : uint16_t nb_rxq = 0;
4392 : : uint16_t nb_txq, i;
4393 : : uint16_t max_frame_size;
4394 : : int mask, ret;
4395 : 0 : uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
4396 : 0 : uint32_t pin_idx = ad->devargs.pin_idx;
4397 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
4398 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
4399 : :
4400 : : /* choose vector Tx function before starting queues */
4401 : 0 : ice_set_tx_function(dev);
4402 : :
4403 : : /* program Tx queues' context in hardware */
4404 [ # # ]: 0 : for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
4405 : 0 : ret = ice_tx_queue_start(dev, nb_txq);
4406 [ # # ]: 0 : if (ret) {
4407 : 0 : PMD_DRV_LOG(ERR, "fail to start Tx queue %u", nb_txq);
4408 : 0 : goto tx_err;
4409 : : }
4410 : : }
4411 : :
4412 : : /* program Rx queues' context in hardware*/
4413 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < data->nb_rx_queues; nb_rxq++) {
4414 : 0 : ret = ice_rx_queue_start(dev, nb_rxq);
4415 [ # # ]: 0 : if (ret) {
4416 : 0 : PMD_DRV_LOG(ERR, "fail to start Rx queue %u", nb_rxq);
4417 : 0 : goto rx_err;
4418 : : }
4419 : : }
4420 : :
4421 : : /* we need to choose Rx fn after queue start, when we know if we need scattered Rx */
4422 : 0 : ice_set_rx_function(dev);
4423 : :
4424 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
4425 : : RTE_ETH_VLAN_EXTEND_MASK;
4426 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
4427 : : mask |= RTE_ETH_QINQ_STRIP_MASK;
4428 : :
4429 : 0 : ret = ice_vlan_offload_set(dev, mask);
4430 [ # # ]: 0 : if (ret) {
4431 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
4432 : 0 : goto rx_err;
4433 : : }
4434 : :
4435 : : /* enable Rx interrupt and mapping Rx queue to interrupt vector */
4436 [ # # ]: 0 : if (ice_rxq_intr_setup(dev))
4437 : : return -EIO;
4438 : :
4439 : 0 : rte_intr_enable(pci_dev->intr_handle);
4440 : :
4441 : : /* Enable receiving broadcast packets and transmitting packets */
4442 : : ice_set_bit(ICE_PROMISC_BCAST_RX, pmask);
4443 : : ice_set_bit(ICE_PROMISC_BCAST_TX, pmask);
4444 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
4445 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
4446 : :
4447 : 0 : ret = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4448 [ # # ]: 0 : if (ret != ICE_SUCCESS)
4449 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
4450 : :
4451 : 0 : ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
4452 : : ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
4453 : : ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
4454 : : ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS |
4455 : : ICE_AQ_LINK_EVENT_SIGNAL_DETECT |
4456 : : ICE_AQ_LINK_EVENT_AN_COMPLETED |
4457 : : ICE_AQ_LINK_EVENT_PORT_TX_SUSPENDED)),
4458 : : NULL);
4459 [ # # ]: 0 : if (ret != ICE_SUCCESS)
4460 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
4461 : :
4462 : 0 : ice_get_init_link_status(dev);
4463 : :
4464 : : ice_dev_set_link_up(dev);
4465 : :
4466 : : /* Call get_link_info aq command to enable/disable LSE */
4467 : 0 : ice_link_update(dev, 0);
4468 : :
4469 : 0 : pf->adapter_stopped = false;
4470 : :
4471 : : /* Set the max frame size to default value*/
4472 [ # # ]: 0 : max_frame_size = pf->dev_data->mtu ?
4473 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD :
4474 : : ICE_FRAME_SIZE_MAX;
4475 : :
4476 : : /* Set the max frame size to HW*/
4477 : 0 : ice_aq_set_mac_cfg(hw, max_frame_size, false, NULL);
4478 : :
4479 [ # # ]: 0 : if (ad->devargs.pps_out_ena) {
4480 : 0 : ret = ice_pps_out_cfg(hw, pin_idx, timer);
4481 [ # # ]: 0 : if (ret) {
4482 : 0 : PMD_DRV_LOG(ERR, "Fail to configure 1pps out");
4483 : 0 : goto rx_err;
4484 : : }
4485 : : }
4486 : :
4487 [ # # ]: 0 : if (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
4488 : 0 : ice_timesync_enable(dev);
4489 : 0 : ad->txpp_ena = 1;
4490 : : }
4491 : :
4492 : : return 0;
4493 : :
4494 : : /* stop the started queues if failed to start all queues */
4495 : 0 : rx_err:
4496 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
4497 : 0 : ice_rx_queue_stop(dev, i);
4498 : 0 : tx_err:
4499 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
4500 : 0 : ice_tx_queue_stop(dev, i);
4501 : :
4502 : : return -EIO;
4503 : : }
4504 : :
4505 : : static int
4506 : 0 : ice_dev_reset(struct rte_eth_dev *dev)
4507 : : {
4508 : : int ret;
4509 : :
4510 [ # # ]: 0 : if (dev->data->sriov.active)
4511 : : return -ENOTSUP;
4512 : :
4513 : : ret = ice_dev_uninit(dev);
4514 : : if (ret) {
4515 : : PMD_INIT_LOG(ERR, "failed to uninit device, status = %d", ret);
4516 : : return -ENXIO;
4517 : : }
4518 : :
4519 : 0 : ret = ice_dev_init(dev);
4520 [ # # ]: 0 : if (ret) {
4521 : 0 : PMD_INIT_LOG(ERR, "failed to init device, status = %d", ret);
4522 : 0 : return -ENXIO;
4523 : : }
4524 : :
4525 : : return 0;
4526 : : }
4527 : :
4528 : : static int
4529 : 0 : ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
4530 : : {
4531 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4532 : : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4533 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4534 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
4535 : 0 : bool is_safe_mode = pf->adapter->is_safe_mode;
4536 : : u64 phy_type_low;
4537 : : u64 phy_type_high;
4538 : :
4539 : 0 : dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
4540 : 0 : dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
4541 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
4542 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
4543 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
4544 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
4545 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - ICE_ETH_OVERHEAD;
4546 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
4547 : :
4548 : 0 : dev_info->rx_offload_capa =
4549 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
4550 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
4551 : : RTE_ETH_RX_OFFLOAD_SCATTER |
4552 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4553 : 0 : dev_info->tx_offload_capa =
4554 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
4555 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
4556 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
4557 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
4558 : 0 : dev_info->flow_type_rss_offloads = 0;
4559 : :
4560 [ # # ]: 0 : if (!is_safe_mode) {
4561 : 0 : dev_info->rx_offload_capa |=
4562 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
4563 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
4564 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
4565 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
4566 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
4567 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
4568 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
4569 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
4570 : : RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
4571 : 0 : dev_info->tx_offload_capa |=
4572 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
4573 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
4574 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
4575 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
4576 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
4577 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
4578 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
4579 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
4580 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
4581 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
4582 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
4583 : : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP;
4584 : 0 : dev_info->flow_type_rss_offloads |= ICE_RSS_OFFLOAD_ALL;
4585 : : }
4586 : :
4587 : 0 : dev_info->rx_queue_offload_capa = RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
4588 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
4589 : :
4590 : 0 : dev_info->reta_size = pf->hash_lut_size;
4591 : 0 : dev_info->hash_key_size = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
4592 : :
4593 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
4594 : : .rx_thresh = {
4595 : : .pthresh = ICE_DEFAULT_RX_PTHRESH,
4596 : : .hthresh = ICE_DEFAULT_RX_HTHRESH,
4597 : : .wthresh = ICE_DEFAULT_RX_WTHRESH,
4598 : : },
4599 : : .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
4600 : : .rx_drop_en = 0,
4601 : : .offloads = 0,
4602 : : };
4603 : :
4604 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
4605 : : .tx_thresh = {
4606 : : .pthresh = ICE_DEFAULT_TX_PTHRESH,
4607 : : .hthresh = ICE_DEFAULT_TX_HTHRESH,
4608 : : .wthresh = ICE_DEFAULT_TX_WTHRESH,
4609 : : },
4610 : : .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
4611 : : .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
4612 : : .offloads = 0,
4613 : : };
4614 : :
4615 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
4616 : : .nb_max = ICE_MAX_RING_DESC,
4617 : : .nb_min = ICE_MIN_RING_DESC,
4618 : : .nb_align = ICE_ALIGN_RING_DESC,
4619 : : };
4620 : :
4621 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
4622 : : .nb_max = ICE_MAX_RING_DESC,
4623 : : .nb_min = ICE_MIN_RING_DESC,
4624 : : .nb_align = ICE_ALIGN_RING_DESC,
4625 : : .nb_mtu_seg_max = ICE_TX_MTU_SEG_MAX,
4626 : : .nb_seg_max = ICE_MAX_RING_DESC,
4627 : : };
4628 : :
4629 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M |
4630 : : RTE_ETH_LINK_SPEED_100M |
4631 : : RTE_ETH_LINK_SPEED_1G |
4632 : : RTE_ETH_LINK_SPEED_2_5G |
4633 : : RTE_ETH_LINK_SPEED_5G |
4634 : : RTE_ETH_LINK_SPEED_10G |
4635 : : RTE_ETH_LINK_SPEED_20G |
4636 : : RTE_ETH_LINK_SPEED_25G;
4637 : :
4638 : 0 : phy_type_low = hw->port_info->phy.phy_type_low;
4639 : 0 : phy_type_high = hw->port_info->phy.phy_type_high;
4640 : :
4641 [ # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_50G(phy_type_low))
4642 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_50G;
4643 : :
4644 [ # # # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_100G_LOW(phy_type_low) ||
4645 [ # # ]: 0 : ICE_PHY_TYPE_SUPPORT_100G_HIGH(phy_type_high))
4646 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100G;
4647 : :
4648 [ # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_200G_HIGH(phy_type_high))
4649 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_200G;
4650 : :
4651 : 0 : dev_info->nb_rx_queues = dev->data->nb_rx_queues;
4652 : 0 : dev_info->nb_tx_queues = dev->data->nb_tx_queues;
4653 : :
4654 : 0 : dev_info->default_rxportconf.burst_size = ICE_RX_MAX_BURST;
4655 : 0 : dev_info->default_txportconf.burst_size = ICE_TX_MAX_BURST;
4656 : 0 : dev_info->default_rxportconf.nb_queues = 1;
4657 : 0 : dev_info->default_txportconf.nb_queues = 1;
4658 : 0 : dev_info->default_rxportconf.ring_size = ICE_BUF_SIZE_MIN;
4659 : 0 : dev_info->default_txportconf.ring_size = ICE_BUF_SIZE_MIN;
4660 : :
4661 : 0 : dev_info->rx_seg_capa.max_nseg = ICE_RX_MAX_NSEG;
4662 : 0 : dev_info->rx_seg_capa.multi_pools = 1;
4663 : 0 : dev_info->rx_seg_capa.offset_allowed = 0;
4664 : 0 : dev_info->rx_seg_capa.offset_align_log2 = 0;
4665 : :
4666 : 0 : return 0;
4667 : : }
4668 : :
4669 : : static inline int
4670 : 0 : ice_atomic_read_link_status(struct rte_eth_dev *dev,
4671 : : struct rte_eth_link *link)
4672 : : {
4673 : : struct rte_eth_link *dst = link;
4674 : 0 : struct rte_eth_link *src = &dev->data->dev_link;
4675 : :
4676 : : /* NOTE: review for potential ordering optimization */
4677 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit((uint64_t __rte_atomic *)dst,
4678 : : (uint64_t *)dst, *(uint64_t *)src,
4679 : : rte_memory_order_seq_cst, rte_memory_order_seq_cst))
4680 : 0 : return -1;
4681 : :
4682 : : return 0;
4683 : : }
4684 : :
4685 : : static inline int
4686 : 0 : ice_atomic_write_link_status(struct rte_eth_dev *dev,
4687 : : struct rte_eth_link *link)
4688 : : {
4689 : 0 : struct rte_eth_link *dst = &dev->data->dev_link;
4690 : : struct rte_eth_link *src = link;
4691 : :
4692 : : /* NOTE: review for potential ordering optimization */
4693 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit((uint64_t __rte_atomic *)dst,
4694 : : (uint64_t *)dst, *(uint64_t *)src,
4695 : : rte_memory_order_seq_cst, rte_memory_order_seq_cst))
4696 : 0 : return -1;
4697 : :
4698 : : return 0;
4699 : : }
4700 : :
4701 : : static int
4702 : 0 : ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
4703 : : {
4704 : : #define CHECK_INTERVAL 50 /* 50ms */
4705 : : #define MAX_REPEAT_TIME 40 /* 2s (40 * 50ms) in total */
4706 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4707 : : struct ice_link_status link_status;
4708 : : struct rte_eth_link link, old;
4709 : : int status;
4710 : : unsigned int rep_cnt = MAX_REPEAT_TIME;
4711 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
4712 : :
4713 : : memset(&link, 0, sizeof(link));
4714 : : memset(&old, 0, sizeof(old));
4715 : : memset(&link_status, 0, sizeof(link_status));
4716 : 0 : ice_atomic_read_link_status(dev, &old);
4717 : :
4718 : : do {
4719 : : /* Get link status information from hardware */
4720 : 0 : status = ice_get_link_info_safe(pf, enable_lse, &link_status);
4721 [ # # ]: 0 : if (status != ICE_SUCCESS) {
4722 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4723 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4724 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
4725 : 0 : goto out;
4726 : : }
4727 : :
4728 : 0 : link.link_status = link_status.link_info & ICE_AQ_LINK_UP;
4729 [ # # # # ]: 0 : if (!wait_to_complete || link.link_status)
4730 : : break;
4731 : :
4732 : : rte_delay_ms(CHECK_INTERVAL);
4733 [ # # ]: 0 : } while (--rep_cnt);
4734 : :
4735 [ # # ]: 0 : if (!link.link_status)
4736 : 0 : goto out;
4737 : :
4738 : : /* Full-duplex operation at all supported speeds */
4739 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4740 : :
4741 : : /* Parse the link status */
4742 [ # # # # : 0 : switch (link_status.link_speed) {
# # # # #
# # # #
# ]
4743 : 0 : case ICE_AQ_LINK_SPEED_10MB:
4744 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10M;
4745 : 0 : break;
4746 : 0 : case ICE_AQ_LINK_SPEED_100MB:
4747 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4748 : 0 : break;
4749 : 0 : case ICE_AQ_LINK_SPEED_1000MB:
4750 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_1G;
4751 : 0 : break;
4752 : 0 : case ICE_AQ_LINK_SPEED_2500MB:
4753 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_2_5G;
4754 : 0 : break;
4755 : 0 : case ICE_AQ_LINK_SPEED_5GB:
4756 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_5G;
4757 : 0 : break;
4758 : 0 : case ICE_AQ_LINK_SPEED_10GB:
4759 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
4760 : 0 : break;
4761 : 0 : case ICE_AQ_LINK_SPEED_20GB:
4762 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_20G;
4763 : 0 : break;
4764 : 0 : case ICE_AQ_LINK_SPEED_25GB:
4765 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_25G;
4766 : 0 : break;
4767 : 0 : case ICE_AQ_LINK_SPEED_40GB:
4768 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_40G;
4769 : 0 : break;
4770 : 0 : case ICE_AQ_LINK_SPEED_50GB:
4771 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_50G;
4772 : 0 : break;
4773 : 0 : case ICE_AQ_LINK_SPEED_100GB:
4774 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100G;
4775 : 0 : break;
4776 : 0 : case ICE_AQ_LINK_SPEED_200GB:
4777 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_200G;
4778 : 0 : break;
4779 : 0 : case ICE_AQ_LINK_SPEED_UNKNOWN:
4780 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed");
4781 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
4782 : 0 : break;
4783 : 0 : default:
4784 : 0 : PMD_DRV_LOG(ERR, "None link speed");
4785 : : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
4786 : 0 : break;
4787 : : }
4788 : :
4789 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
4790 : : RTE_ETH_LINK_SPEED_FIXED);
4791 : :
4792 : 0 : out:
4793 : 0 : ice_atomic_write_link_status(dev, &link);
4794 [ # # ]: 0 : if (link.link_status == old.link_status)
4795 : 0 : return -1;
4796 : :
4797 : : return 0;
4798 : : }
4799 : :
4800 : : static inline uint16_t
4801 : 0 : ice_parse_link_speeds(uint16_t link_speeds)
4802 : : {
4803 : : uint16_t link_speed = ICE_AQ_LINK_SPEED_UNKNOWN;
4804 : :
4805 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_200G)
4806 : : link_speed |= ICE_AQ_LINK_SPEED_200GB;
4807 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100G)
4808 : 0 : link_speed |= ICE_AQ_LINK_SPEED_100GB;
4809 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_50G)
4810 : 0 : link_speed |= ICE_AQ_LINK_SPEED_50GB;
4811 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
4812 : 0 : link_speed |= ICE_AQ_LINK_SPEED_40GB;
4813 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
4814 : 0 : link_speed |= ICE_AQ_LINK_SPEED_25GB;
4815 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
4816 : 0 : link_speed |= ICE_AQ_LINK_SPEED_20GB;
4817 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
4818 : 0 : link_speed |= ICE_AQ_LINK_SPEED_10GB;
4819 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_5G)
4820 : 0 : link_speed |= ICE_AQ_LINK_SPEED_5GB;
4821 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_2_5G)
4822 : 0 : link_speed |= ICE_AQ_LINK_SPEED_2500MB;
4823 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
4824 : 0 : link_speed |= ICE_AQ_LINK_SPEED_1000MB;
4825 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
4826 : 0 : link_speed |= ICE_AQ_LINK_SPEED_100MB;
4827 : :
4828 : 0 : return link_speed;
4829 : : }
4830 : :
4831 : : static int
4832 : 0 : ice_apply_link_speed(struct rte_eth_dev *dev)
4833 : : {
4834 : : uint16_t speed;
4835 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4836 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
4837 : :
4838 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
4839 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_200G |
4840 : : RTE_ETH_LINK_SPEED_100G |
4841 : : RTE_ETH_LINK_SPEED_50G |
4842 : : RTE_ETH_LINK_SPEED_40G |
4843 : : RTE_ETH_LINK_SPEED_25G |
4844 : : RTE_ETH_LINK_SPEED_20G |
4845 : : RTE_ETH_LINK_SPEED_10G |
4846 : : RTE_ETH_LINK_SPEED_5G |
4847 : : RTE_ETH_LINK_SPEED_2_5G |
4848 : : RTE_ETH_LINK_SPEED_1G |
4849 : : RTE_ETH_LINK_SPEED_100M;
4850 : : }
4851 : 0 : speed = ice_parse_link_speeds(conf->link_speeds);
4852 : :
4853 : 0 : return ice_phy_conf_link(hw, speed, true);
4854 : : }
4855 : :
4856 : : static int
4857 : 0 : ice_phy_conf_link(struct ice_hw *hw,
4858 : : u16 link_speeds_bitmap,
4859 : : bool link_up)
4860 : : {
4861 : 0 : struct ice_aqc_set_phy_cfg_data cfg = { 0 };
4862 : 0 : struct ice_port_info *pi = hw->port_info;
4863 : : struct ice_aqc_get_phy_caps_data *phy_caps;
4864 : : int err;
4865 : 0 : u64 phy_type_low = 0;
4866 : 0 : u64 phy_type_high = 0;
4867 : :
4868 : : phy_caps = (struct ice_aqc_get_phy_caps_data *)
4869 : 0 : ice_malloc(hw, sizeof(*phy_caps));
4870 [ # # ]: 0 : if (!phy_caps)
4871 : : return ICE_ERR_NO_MEMORY;
4872 : :
4873 [ # # ]: 0 : if (!pi)
4874 : : return -EIO;
4875 : :
4876 : :
4877 [ # # ]: 0 : if (ice_fw_supports_report_dflt_cfg(pi->hw))
4878 : 0 : err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
4879 : : phy_caps, NULL);
4880 : : else
4881 : 0 : err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
4882 : : phy_caps, NULL);
4883 [ # # ]: 0 : if (err)
4884 : 0 : goto done;
4885 : :
4886 : 0 : ice_update_phy_type(&phy_type_low, &phy_type_high, link_speeds_bitmap);
4887 : :
4888 [ # # ]: 0 : if (link_speeds_bitmap == ICE_LINK_SPEED_UNKNOWN) {
4889 : 0 : cfg.phy_type_low = phy_caps->phy_type_low;
4890 : 0 : cfg.phy_type_high = phy_caps->phy_type_high;
4891 [ # # ]: 0 : } else if (phy_type_low & phy_caps->phy_type_low ||
4892 [ # # ]: 0 : phy_type_high & phy_caps->phy_type_high) {
4893 : 0 : cfg.phy_type_low = phy_type_low & phy_caps->phy_type_low;
4894 : 0 : cfg.phy_type_high = phy_type_high & phy_caps->phy_type_high;
4895 : : } else {
4896 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!");
4897 : 0 : cfg.phy_type_low = phy_caps->phy_type_low;
4898 : 0 : cfg.phy_type_high = phy_caps->phy_type_high;
4899 : : }
4900 : :
4901 : 0 : cfg.caps = phy_caps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
4902 : 0 : cfg.low_power_ctrl_an = phy_caps->low_power_ctrl_an;
4903 : 0 : cfg.eee_cap = phy_caps->eee_cap;
4904 : 0 : cfg.eeer_value = phy_caps->eeer_value;
4905 : 0 : cfg.link_fec_opt = phy_caps->link_fec_options;
4906 [ # # ]: 0 : if (link_up)
4907 : 0 : cfg.caps |= ICE_AQ_PHY_ENA_LINK;
4908 : : else
4909 : 0 : cfg.caps &= ~ICE_AQ_PHY_ENA_LINK;
4910 : :
4911 : 0 : err = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
4912 : :
4913 : 0 : done:
4914 : 0 : ice_free(hw, phy_caps);
4915 : 0 : return err;
4916 : : }
4917 : :
4918 : : static int
4919 : 0 : ice_dev_set_link_up(struct rte_eth_dev *dev)
4920 : : {
4921 : 0 : return ice_apply_link_speed(dev);
4922 : : }
4923 : :
4924 : : static int
4925 : 0 : ice_dev_set_link_down(struct rte_eth_dev *dev)
4926 : : {
4927 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4928 : : uint8_t speed = ICE_LINK_SPEED_UNKNOWN;
4929 : :
4930 : 0 : return ice_phy_conf_link(hw, speed, false);
4931 : : }
4932 : :
4933 : : static int
4934 : 0 : ice_dev_led_on(struct rte_eth_dev *dev)
4935 : : {
4936 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4937 : 0 : int status = ice_aq_set_port_id_led(hw->port_info, false, NULL);
4938 : :
4939 [ # # ]: 0 : return status == ICE_SUCCESS ? 0 : -ENOTSUP;
4940 : : }
4941 : :
4942 : : static int
4943 : 0 : ice_dev_led_off(struct rte_eth_dev *dev)
4944 : : {
4945 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4946 : 0 : int status = ice_aq_set_port_id_led(hw->port_info, true, NULL);
4947 : :
4948 [ # # ]: 0 : return status == ICE_SUCCESS ? 0 : -ENOTSUP;
4949 : : }
4950 : :
4951 : : static int
4952 : 0 : ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
4953 : : {
4954 : : /* mtu setting is forbidden if port is start */
4955 [ # # ]: 0 : if (dev->data->dev_started != 0) {
4956 : 0 : PMD_DRV_LOG(ERR,
4957 : : "port %d must be stopped before configuration",
4958 : : dev->data->port_id);
4959 : 0 : return -EBUSY;
4960 : : }
4961 : :
4962 : : return 0;
4963 : : }
4964 : :
4965 : 0 : static int ice_macaddr_set(struct rte_eth_dev *dev,
4966 : : struct rte_ether_addr *mac_addr)
4967 : : {
4968 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4969 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4970 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
4971 : : struct ice_mac_filter *f;
4972 : : uint8_t flags = 0;
4973 : : int ret;
4974 : :
4975 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
4976 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
4977 : 0 : return -EINVAL;
4978 : : }
4979 : :
4980 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
4981 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
4982 : : break;
4983 : : }
4984 : :
4985 [ # # ]: 0 : if (!f) {
4986 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
4987 : 0 : return -EIO;
4988 : : }
4989 : :
4990 : 0 : ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr);
4991 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4992 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
4993 : 0 : return -EIO;
4994 : : }
4995 : 0 : ret = ice_add_mac_filter(vsi, mac_addr);
4996 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4997 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
4998 : 0 : return -EIO;
4999 : : }
5000 : : rte_ether_addr_copy(mac_addr, &pf->dev_addr);
5001 : :
5002 : : flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
5003 : 0 : ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL);
5004 [ # # ]: 0 : if (ret != ICE_SUCCESS)
5005 : 0 : PMD_DRV_LOG(ERR, "Failed to set manage mac");
5006 : :
5007 : : return 0;
5008 : : }
5009 : :
5010 : : /* Add a MAC address, and update filters */
5011 : : static int
5012 : 0 : ice_macaddr_add(struct rte_eth_dev *dev,
5013 : : struct rte_ether_addr *mac_addr,
5014 : : __rte_unused uint32_t index,
5015 : : __rte_unused uint32_t pool)
5016 : : {
5017 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5018 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5019 : : int ret;
5020 : :
5021 : 0 : ret = ice_add_mac_filter(vsi, mac_addr);
5022 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
5023 : 0 : PMD_DRV_LOG(ERR, "Failed to add MAC filter");
5024 : 0 : return -EINVAL;
5025 : : }
5026 : :
5027 : : return ICE_SUCCESS;
5028 : : }
5029 : :
5030 : : /* Remove a MAC address, and update filters */
5031 : : static void
5032 : 0 : ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
5033 : : {
5034 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5035 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5036 : : struct rte_eth_dev_data *data = dev->data;
5037 : : struct rte_ether_addr *macaddr;
5038 : : int ret;
5039 : :
5040 : 0 : macaddr = &data->mac_addrs[index];
5041 : 0 : ret = ice_remove_mac_filter(vsi, macaddr);
5042 [ # # ]: 0 : if (ret) {
5043 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
5044 : 0 : return;
5045 : : }
5046 : : }
5047 : :
5048 : : static int
5049 : 0 : ice_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
5050 : : {
5051 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5052 : : /* Use the configured outer_ethertype instead of hardcoded 0x8100 */
5053 : 0 : struct ice_vlan vlan = ICE_VLAN(pf->outer_ethertype, vlan_id);
5054 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5055 : : int ret;
5056 : :
5057 : 0 : PMD_INIT_FUNC_TRACE();
5058 : :
5059 : : /**
5060 : : * Vlan 0 is the generic filter for untagged packets
5061 : : * and can't be removed or added by user.
5062 : : */
5063 [ # # ]: 0 : if (vlan_id == 0)
5064 : : return 0;
5065 : :
5066 [ # # ]: 0 : if (on) {
5067 : 0 : ret = ice_add_vlan_filter(vsi, &vlan);
5068 [ # # ]: 0 : if (ret < 0) {
5069 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
5070 : 0 : return -EINVAL;
5071 : : }
5072 : : } else {
5073 : 0 : ret = ice_remove_vlan_filter(vsi, &vlan);
5074 [ # # ]: 0 : if (ret < 0) {
5075 : 0 : PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
5076 : 0 : return -EINVAL;
5077 : : }
5078 : : }
5079 : :
5080 : : return 0;
5081 : : }
5082 : :
5083 : : /* In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are
5084 : : * based on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8)
5085 : : * doesn't matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
5086 : : * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
5087 : : *
5088 : : * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
5089 : : * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
5090 : : * traffic in SVM, since the VLAN TPID isn't part of filtering.
5091 : : *
5092 : : * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
5093 : : * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
5094 : : * part of filtering.
5095 : : */
5096 : : static int
5097 : 0 : ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
5098 : : {
5099 : : struct ice_vlan vlan;
5100 : : int err;
5101 : :
5102 : 0 : vlan = ICE_VLAN(0, 0);
5103 : 0 : err = ice_add_vlan_filter(vsi, &vlan);
5104 [ # # ]: 0 : if (err) {
5105 : 0 : PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0");
5106 : 0 : return err;
5107 : : }
5108 : :
5109 : : /* in SVM both VLAN 0 filters are identical */
5110 [ # # ]: 0 : if (!ice_is_dvm_ena(&vsi->adapter->hw))
5111 : : return 0;
5112 : :
5113 : 0 : vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
5114 : 0 : err = ice_add_vlan_filter(vsi, &vlan);
5115 [ # # ]: 0 : if (err) {
5116 : 0 : PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0 in double VLAN mode");
5117 : 0 : return err;
5118 : : }
5119 : :
5120 : : return 0;
5121 : : }
5122 : :
5123 : : /*
5124 : : * Delete the VLAN 0 filters in the same manner that they were added in
5125 : : * ice_vsi_add_vlan_zero.
5126 : : */
5127 : : static int
5128 : 0 : ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
5129 : : {
5130 : : struct ice_vlan vlan;
5131 : : int err;
5132 : :
5133 : 0 : vlan = ICE_VLAN(0, 0);
5134 : 0 : err = ice_remove_vlan_filter(vsi, &vlan);
5135 [ # # ]: 0 : if (err) {
5136 : 0 : PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0");
5137 : 0 : return err;
5138 : : }
5139 : :
5140 : : /* in SVM both VLAN 0 filters are identical */
5141 [ # # ]: 0 : if (!ice_is_dvm_ena(&vsi->adapter->hw))
5142 : : return 0;
5143 : :
5144 : 0 : vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
5145 : 0 : err = ice_remove_vlan_filter(vsi, &vlan);
5146 [ # # ]: 0 : if (err) {
5147 : 0 : PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0 in double VLAN mode");
5148 : 0 : return err;
5149 : : }
5150 : :
5151 : : return 0;
5152 : : }
5153 : :
5154 : : /* Configure vlan filter on or off */
5155 : : static int
5156 : 0 : ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
5157 : : {
5158 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5159 : : struct ice_vsi_ctx ctxt;
5160 : : uint8_t sw_flags2;
5161 : : int ret = 0;
5162 : :
5163 : : sw_flags2 = ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
5164 : :
5165 [ # # ]: 0 : if (on)
5166 : 0 : vsi->info.sw_flags2 |= sw_flags2;
5167 : : else
5168 : 0 : vsi->info.sw_flags2 &= ~sw_flags2;
5169 : :
5170 : 0 : vsi->info.sw_id = hw->port_info->sw_id;
5171 : 0 : (void)memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5172 : 0 : ctxt.info.valid_sections =
5173 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
5174 : : ICE_AQ_VSI_PROP_SECURITY_VALID);
5175 : 0 : ctxt.vsi_num = vsi->vsi_id;
5176 : :
5177 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5178 [ # # ]: 0 : if (ret) {
5179 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
5180 : : on ? "enable" : "disable");
5181 : 0 : return -EINVAL;
5182 : : } else {
5183 : 0 : vsi->info.valid_sections |=
5184 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
5185 : : ICE_AQ_VSI_PROP_SECURITY_VALID);
5186 : : }
5187 : :
5188 : : /* consist with other drivers, allow untagged packet when vlan filter on */
5189 [ # # ]: 0 : if (on)
5190 : 0 : ret = ice_vsi_add_vlan_zero(vsi);
5191 : : else
5192 : 0 : ret = ice_vsi_del_vlan_zero(vsi);
5193 : :
5194 : : return 0;
5195 : : }
5196 : :
5197 : : /* Manage VLAN stripping for the VSI for Rx */
5198 : : static int
5199 : 0 : ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
5200 : : {
5201 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5202 : : struct ice_vsi_ctx ctxt;
5203 : : int status, err = 0;
5204 : :
5205 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
5206 : : * on this VSI
5207 : : */
5208 [ # # ]: 0 : if (vsi->info.port_based_inner_vlan)
5209 : : return 0;
5210 : :
5211 : : memset(&ctxt, 0, sizeof(ctxt));
5212 : :
5213 [ # # ]: 0 : if (ena)
5214 : : /* Strip VLAN tag from Rx packet and put it in the desc */
5215 : : ctxt.info.inner_vlan_flags =
5216 : : ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
5217 : : else
5218 : : /* Disable stripping. Leave tag in packet */
5219 : 0 : ctxt.info.inner_vlan_flags =
5220 : : ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
5221 : :
5222 : : /* Allow all packets untagged/tagged */
5223 : 0 : ctxt.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
5224 : :
5225 : 0 : ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5226 : :
5227 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5228 [ # # ]: 0 : if (status) {
5229 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan stripping",
5230 : : ena ? "enable" : "disable");
5231 : : err = -EIO;
5232 : : } else {
5233 : 0 : vsi->info.inner_vlan_flags = ctxt.info.inner_vlan_flags;
5234 : : }
5235 : :
5236 : : return err;
5237 : : }
5238 : :
5239 : : static int
5240 : : ice_vsi_ena_inner_stripping(struct ice_vsi *vsi)
5241 : : {
5242 : 0 : return ice_vsi_manage_vlan_stripping(vsi, true);
5243 : : }
5244 : :
5245 : : static int
5246 : : ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
5247 : : {
5248 : 0 : return ice_vsi_manage_vlan_stripping(vsi, false);
5249 : : }
5250 : :
5251 : : /**
5252 : : * tpid_to_vsi_outer_vlan_type - convert from TPID to VSI context based tag_type
5253 : : * @tpid: tpid used to translate into VSI context based tag_type
5254 : : * @tag_type: output variable to hold the VSI context based tag type
5255 : : */
5256 : : static int tpid_to_vsi_outer_vlan_type(u16 tpid, u8 *tag_type)
5257 : : {
5258 [ # # # # : 0 : switch (tpid) {
# # # # ]
5259 : : case RTE_ETHER_TYPE_VLAN:
5260 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_8100;
5261 : : break;
5262 : : case RTE_ETHER_TYPE_QINQ:
5263 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_STAG;
5264 : : break;
5265 : : case RTE_ETHER_TYPE_QINQ1:
5266 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_9100;
5267 : : break;
5268 : : default:
5269 : : *tag_type = 0;
5270 : : return -EINVAL;
5271 : : }
5272 : :
5273 : : return 0;
5274 : : }
5275 : :
5276 : : /**
5277 : : * ice_is_supported_port_vlan_proto - make sure the vlan_proto is supported
5278 : : * @hw: hardware structure used to check the VLAN mode
5279 : : * @vlan_proto: VLAN TPID being checked
5280 : : *
5281 : : * If the device is configured in Double VLAN Mode (DVM), it supports three
5282 : : * types: RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ1 and RTE_ETHER_TYPE_QINQ. If the device is
5283 : : * configured in Single VLAN Mode (SVM), then only RTE_ETHER_TYPE_VLAN is supported.
5284 : : */
5285 : : static bool
5286 : 0 : ice_is_supported_port_vlan_proto(struct ice_hw *hw, u16 vlan_proto)
5287 : : {
5288 : : bool is_supported = false;
5289 : :
5290 [ # # # # ]: 0 : switch (vlan_proto) {
5291 : 0 : case RTE_ETHER_TYPE_VLAN:
5292 : : is_supported = true;
5293 : 0 : break;
5294 : 0 : case RTE_ETHER_TYPE_QINQ:
5295 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
5296 : : is_supported = true;
5297 : : break;
5298 : 0 : case RTE_ETHER_TYPE_QINQ1:
5299 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
5300 : : is_supported = true;
5301 : : break;
5302 : : }
5303 : :
5304 : 0 : return is_supported;
5305 : : }
5306 : :
5307 : : /**
5308 : : * ice_vsi_ena_outer_stripping - enable outer VLAN stripping
5309 : : * @vsi: VSI to configure
5310 : : * @tpid: TPID to enable outer VLAN stripping for
5311 : : *
5312 : : * Enable outer VLAN stripping via VSI context. This function should only be
5313 : : * used if DVM is supported.
5314 : : *
5315 : : * Since the VSI context only supports a single TPID for insertion and
5316 : : * stripping, setting the TPID for stripping will affect the TPID for insertion.
5317 : : * Callers need to be aware of this limitation.
5318 : : *
5319 : : * Only modify outer VLAN stripping settings and the VLAN TPID. Outer VLAN
5320 : : * insertion settings are unmodified.
5321 : : *
5322 : : * This enables hardware to strip a VLAN tag with the specified TPID to be
5323 : : * stripped from the packet and placed in the receive descriptor.
5324 : : */
5325 : 0 : static int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi, u16 tpid)
5326 : : {
5327 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5328 : : struct ice_vsi_ctx ctxt;
5329 : : int status, err = 0;
5330 : : u8 tag_type;
5331 : :
5332 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
5333 : : * on this VSI
5334 : : */
5335 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
5336 : : return 0;
5337 : :
5338 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
5339 : : return -EINVAL;
5340 : :
5341 : : memset(&ctxt, 0, sizeof(ctxt));
5342 : :
5343 : 0 : ctxt.info.valid_sections =
5344 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
5345 : : /* clear current outer VLAN strip settings */
5346 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
5347 : : ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
5348 : 0 : ctxt.info.outer_vlan_flags |=
5349 : : (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
5350 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
5351 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
5352 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
5353 : :
5354 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5355 [ # # ]: 0 : if (status) {
5356 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
5357 : : err = -EIO;
5358 : : } else {
5359 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
5360 : : }
5361 : :
5362 : : return err;
5363 : : }
5364 : :
5365 : : static int
5366 : 0 : ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
5367 : : {
5368 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5369 : : struct ice_vsi_ctx ctxt;
5370 : : int status, err = 0;
5371 : :
5372 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
5373 : : return 0;
5374 : :
5375 : : memset(&ctxt, 0, sizeof(ctxt));
5376 : :
5377 : 0 : ctxt.info.valid_sections =
5378 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
5379 : : /* clear current outer VLAN strip settings */
5380 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
5381 : : ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
5382 : 0 : ctxt.info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
5383 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
5384 : :
5385 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5386 [ # # ]: 0 : if (status) {
5387 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to disable outer VLAN stripping");
5388 : : err = -EIO;
5389 : : } else {
5390 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
5391 : : }
5392 : :
5393 : : return err;
5394 : : }
5395 : :
5396 : : static int
5397 : 0 : ice_vsi_config_vlan_stripping(struct ice_vsi *vsi, bool ena)
5398 : : {
5399 : : int ret;
5400 : :
5401 [ # # ]: 0 : if (ena)
5402 : : ret = ice_vsi_ena_inner_stripping(vsi);
5403 : : else
5404 : : ret = ice_vsi_dis_inner_stripping(vsi);
5405 : :
5406 : 0 : return ret;
5407 : : }
5408 : :
5409 : : /* Configure outer vlan stripping on or off in QinQ mode */
5410 : : static int
5411 : 0 : ice_vsi_config_outer_vlan_stripping(struct ice_vsi *vsi, bool on)
5412 : : {
5413 : 0 : uint16_t outer_ethertype = vsi->adapter->pf.outer_ethertype;
5414 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5415 : :
5416 [ # # ]: 0 : if (vsi->vsi_id >= ICE_MAX_NUM_VSIS) {
5417 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
5418 : 0 : return -EINVAL;
5419 : : }
5420 : :
5421 [ # # ]: 0 : if (!ice_is_dvm_ena(hw)) {
5422 : 0 : PMD_DRV_LOG(ERR, "Single VLAN mode (SVM) does not support qinq");
5423 : 0 : return -EOPNOTSUPP;
5424 : : }
5425 : :
5426 : : return on ?
5427 [ # # ]: 0 : ice_vsi_ena_outer_stripping(vsi, outer_ethertype) :
5428 : 0 : ice_vsi_dis_outer_stripping(vsi);
5429 : : }
5430 : :
5431 : : static int
5432 : 0 : ice_vlan_offload_set(struct rte_eth_dev *dev, int mask)
5433 : : {
5434 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5435 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5436 : : struct rte_eth_rxmode *rxmode;
5437 : :
5438 : : rxmode = &dev->data->dev_conf.rxmode;
5439 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
5440 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
5441 : 0 : ice_vsi_config_vlan_filter(vsi, true);
5442 : : else
5443 : 0 : ice_vsi_config_vlan_filter(vsi, false);
5444 : : }
5445 : :
5446 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5447 [ # # ]: 0 : if (!ice_is_dvm_ena(hw)) {
5448 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
5449 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5450 : 0 : ice_vsi_config_vlan_stripping(vsi, true);
5451 : : else
5452 : 0 : ice_vsi_config_vlan_stripping(vsi, false);
5453 : : }
5454 : :
5455 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
5456 : 0 : PMD_DRV_LOG(ERR, "Single VLAN mode (SVM) does not support qinq");
5457 : 0 : return -ENOTSUP;
5458 : : }
5459 : : } else {
5460 [ # # ]: 0 : if ((mask & RTE_ETH_VLAN_STRIP_MASK) |
5461 : : (mask & RTE_ETH_QINQ_STRIP_MASK)) {
5462 [ # # ]: 0 : if (rxmode->offloads & (RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
5463 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP))
5464 : 0 : ice_vsi_config_outer_vlan_stripping(vsi, true);
5465 : : else
5466 : 0 : ice_vsi_config_outer_vlan_stripping(vsi, false);
5467 : : }
5468 : :
5469 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
5470 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
5471 : 0 : ice_vsi_config_vlan_stripping(vsi, true);
5472 : : else
5473 : 0 : ice_vsi_config_vlan_stripping(vsi, false);
5474 : : }
5475 : : }
5476 : :
5477 : : return 0;
5478 : : }
5479 : :
5480 : : static int
5481 : 0 : ice_get_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
5482 : : {
5483 : : struct ice_aq_get_set_rss_lut_params lut_params;
5484 : 0 : struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
5485 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5486 : : int ret;
5487 : :
5488 [ # # ]: 0 : if (!lut)
5489 : : return -EINVAL;
5490 : :
5491 [ # # ]: 0 : if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
5492 : 0 : lut_params.vsi_handle = vsi->idx;
5493 : 0 : lut_params.lut_size = lut_size;
5494 [ # # ]: 0 : lut_params.lut_type = (vsi->global_lut_allocated) ?
5495 : : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
5496 : 0 : lut_params.lut = lut;
5497 [ # # ]: 0 : lut_params.global_lut_id = (vsi->global_lut_allocated) ? vsi->global_lut_id : 0;
5498 : 0 : ret = ice_aq_get_rss_lut(hw, &lut_params);
5499 [ # # ]: 0 : if (ret) {
5500 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
5501 : 0 : return -EINVAL;
5502 : : }
5503 : : } else {
5504 : : uint64_t *lut_dw = (uint64_t *)lut;
5505 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
5506 : :
5507 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
5508 : 0 : lut_dw[i] = ICE_READ_REG(hw, PFQF_HLUT(i));
5509 : : }
5510 : :
5511 : : return 0;
5512 : : }
5513 : :
5514 : : static int
5515 : 0 : ice_set_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
5516 : : {
5517 : : struct ice_aq_get_set_rss_lut_params lut_params;
5518 : : struct ice_pf *pf;
5519 : : struct ice_hw *hw;
5520 : : int ret;
5521 : :
5522 [ # # ]: 0 : if (!vsi || !lut)
5523 : : return -EINVAL;
5524 : :
5525 : 0 : pf = ICE_VSI_TO_PF(vsi);
5526 : 0 : hw = ICE_VSI_TO_HW(vsi);
5527 : :
5528 [ # # ]: 0 : if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
5529 : 0 : lut_params.vsi_handle = vsi->idx;
5530 : 0 : lut_params.lut_size = lut_size;
5531 [ # # ]: 0 : lut_params.lut_type = (vsi->global_lut_allocated) ?
5532 : : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
5533 : 0 : lut_params.lut = lut;
5534 [ # # ]: 0 : lut_params.global_lut_id = (vsi->global_lut_allocated) ? vsi->global_lut_id : 0;
5535 : 0 : ret = ice_aq_set_rss_lut(hw, &lut_params);
5536 [ # # ]: 0 : if (ret) {
5537 : 0 : PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
5538 : 0 : return -EINVAL;
5539 : : }
5540 : : } else {
5541 : : uint64_t *lut_dw = (uint64_t *)lut;
5542 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
5543 : :
5544 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
5545 : 0 : ICE_WRITE_REG(hw, PFQF_HLUT(i), lut_dw[i]);
5546 : :
5547 : 0 : ice_flush(hw);
5548 : : }
5549 : :
5550 : : return 0;
5551 : : }
5552 : :
5553 : : static int
5554 : 0 : ice_rss_reta_update(struct rte_eth_dev *dev,
5555 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5556 : : uint16_t reta_size)
5557 : : {
5558 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5559 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
5560 : : uint16_t idx, shift;
5561 : 0 : uint8_t lut[ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K] = {0};
5562 : : int ret;
5563 : :
5564 : 0 : if (reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128 &&
5565 [ # # # # ]: 0 : reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512 &&
5566 : : reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) {
5567 : 0 : PMD_DRV_LOG(ERR,
5568 : : "The size of hash lookup table configured (%d)"
5569 : : "doesn't match the number hardware can "
5570 : : "supported (128, 512, 2048)",
5571 : : reta_size);
5572 : 0 : return -EINVAL;
5573 : : }
5574 : :
5575 : : /* It MUST use the current LUT size to get the RSS lookup table,
5576 : : * otherwise if will fail with -100 error code.
5577 : : */
5578 : 0 : ret = ice_get_rss_lut(pf->main_vsi, lut, lut_size);
5579 [ # # ]: 0 : if (ret)
5580 : : return ret;
5581 : :
5582 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
5583 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5584 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5585 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
5586 : 0 : lut[i] = reta_conf[idx].reta[shift];
5587 : : }
5588 : 0 : ret = ice_set_rss_lut(pf->main_vsi, lut, reta_size);
5589 [ # # ]: 0 : if (ret == 0 && lut_size != reta_size) {
5590 : 0 : PMD_DRV_LOG(INFO,
5591 : : "The size of hash lookup table is changed from (%d) to (%d)",
5592 : : lut_size, reta_size);
5593 : 0 : pf->hash_lut_size = reta_size;
5594 : : }
5595 : :
5596 : : return 0;
5597 : : }
5598 : :
5599 : : static int
5600 : 0 : ice_rss_reta_query(struct rte_eth_dev *dev,
5601 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5602 : : uint16_t reta_size)
5603 : : {
5604 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5605 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
5606 : : uint16_t idx, shift;
5607 : 0 : uint8_t lut[ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K] = {0};
5608 : : int ret;
5609 : :
5610 [ # # ]: 0 : if (reta_size != lut_size) {
5611 : 0 : PMD_DRV_LOG(ERR,
5612 : : "The size of hash lookup table configured (%d)"
5613 : : "doesn't match the number hardware can "
5614 : : "supported (%d)",
5615 : : reta_size, lut_size);
5616 : 0 : return -EINVAL;
5617 : : }
5618 : :
5619 : 0 : ret = ice_get_rss_lut(pf->main_vsi, lut, reta_size);
5620 [ # # ]: 0 : if (ret)
5621 : : return ret;
5622 : :
5623 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
5624 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5625 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5626 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
5627 : 0 : reta_conf[idx].reta[shift] = lut[i];
5628 : : }
5629 : :
5630 : : return 0;
5631 : : }
5632 : :
5633 : : static int
5634 : 0 : ice_set_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t key_len)
5635 : : {
5636 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5637 : : int ret = 0;
5638 : :
5639 [ # # ]: 0 : if (!key || key_len == 0) {
5640 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
5641 : 0 : return 0;
5642 [ # # ]: 0 : } else if (key_len != (VSIQF_HKEY_MAX_INDEX + 1) *
5643 : : sizeof(uint32_t)) {
5644 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
5645 : 0 : return -EINVAL;
5646 : : }
5647 : :
5648 : : struct ice_aqc_get_set_rss_keys *key_dw =
5649 : : (struct ice_aqc_get_set_rss_keys *)key;
5650 : :
5651 : 0 : ret = ice_aq_set_rss_key(hw, vsi->idx, key_dw);
5652 [ # # ]: 0 : if (ret) {
5653 : 0 : PMD_DRV_LOG(ERR, "Failed to configure RSS key via AQ");
5654 : : ret = -EINVAL;
5655 : : }
5656 : :
5657 : : return ret;
5658 : : }
5659 : :
5660 : : static int
5661 : 0 : ice_get_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t *key_len)
5662 : : {
5663 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5664 : : int ret;
5665 : :
5666 [ # # ]: 0 : if (!key || !key_len)
5667 : : return -EINVAL;
5668 : :
5669 : 0 : ret = ice_aq_get_rss_key
5670 : 0 : (hw, vsi->idx,
5671 : : (struct ice_aqc_get_set_rss_keys *)key);
5672 [ # # ]: 0 : if (ret) {
5673 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS key via AQ");
5674 : 0 : return -EINVAL;
5675 : : }
5676 : 0 : *key_len = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
5677 : :
5678 : 0 : return 0;
5679 : : }
5680 : :
5681 : : static int
5682 : 0 : ice_rss_hash_update(struct rte_eth_dev *dev,
5683 : : struct rte_eth_rss_conf *rss_conf)
5684 : : {
5685 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5686 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5687 : : int status;
5688 : :
5689 : : /* set hash key */
5690 : 0 : status = ice_set_rss_key(vsi, rss_conf->rss_key, rss_conf->rss_key_len);
5691 [ # # ]: 0 : if (status)
5692 : : return status;
5693 : :
5694 [ # # ]: 0 : if (rss_conf->rss_hf == 0)
5695 : 0 : pf->rss_hf = 0;
5696 : :
5697 : : /* RSS hash configuration */
5698 : 0 : ice_rss_hash_set(pf, rss_conf->rss_hf);
5699 : :
5700 : 0 : return 0;
5701 : : }
5702 : :
5703 : : static int
5704 : 0 : ice_rss_hash_conf_get(struct rte_eth_dev *dev,
5705 : : struct rte_eth_rss_conf *rss_conf)
5706 : : {
5707 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5708 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5709 : :
5710 : 0 : ice_get_rss_key(vsi, rss_conf->rss_key,
5711 : : &rss_conf->rss_key_len);
5712 : :
5713 : 0 : rss_conf->rss_hf = pf->rss_hf;
5714 : 0 : return 0;
5715 : : }
5716 : :
5717 : : static int
5718 : 0 : ice_promisc_enable(struct rte_eth_dev *dev)
5719 : : {
5720 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5721 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5722 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5723 : : int status, ret = 0;
5724 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5725 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5726 : :
5727 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5728 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5729 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5730 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5731 : :
5732 : 0 : status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
5733 [ # # # ]: 0 : switch (status) {
5734 : 0 : case ICE_ERR_ALREADY_EXISTS:
5735 : 0 : PMD_DRV_LOG(DEBUG, "Promisc mode has already been enabled");
5736 : : case ICE_SUCCESS:
5737 : : break;
5738 : 0 : default:
5739 : 0 : PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
5740 : : ret = -EAGAIN;
5741 : : }
5742 : :
5743 : 0 : return ret;
5744 : : }
5745 : :
5746 : : static int
5747 : 0 : ice_promisc_disable(struct rte_eth_dev *dev)
5748 : : {
5749 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5750 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5751 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5752 : : int status, ret = 0;
5753 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5754 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5755 : :
5756 [ # # ]: 0 : if (dev->data->all_multicast == 1) {
5757 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5758 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5759 : : } else {
5760 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5761 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5762 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5763 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5764 : : }
5765 : :
5766 : 0 : status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
5767 [ # # ]: 0 : if (status != ICE_SUCCESS) {
5768 : 0 : PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
5769 : : ret = -EAGAIN;
5770 : : }
5771 : :
5772 : 0 : return ret;
5773 : : }
5774 : :
5775 : : static int
5776 : 0 : ice_allmulti_enable(struct rte_eth_dev *dev)
5777 : : {
5778 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5779 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5780 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5781 : : int status, ret = 0;
5782 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5783 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5784 : :
5785 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5786 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5787 : :
5788 : 0 : status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
5789 : :
5790 [ # # # ]: 0 : switch (status) {
5791 : 0 : case ICE_ERR_ALREADY_EXISTS:
5792 : 0 : PMD_DRV_LOG(DEBUG, "Allmulti has already been enabled");
5793 : : case ICE_SUCCESS:
5794 : : break;
5795 : 0 : default:
5796 : 0 : PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
5797 : : ret = -EAGAIN;
5798 : : }
5799 : :
5800 : 0 : return ret;
5801 : : }
5802 : :
5803 : : static int
5804 : 0 : ice_allmulti_disable(struct rte_eth_dev *dev)
5805 : : {
5806 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5807 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5808 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5809 : : int status, ret = 0;
5810 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5811 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5812 : :
5813 [ # # ]: 0 : if (dev->data->promiscuous == 1)
5814 : : return 0; /* must remain in all_multicast mode */
5815 : :
5816 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5817 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5818 : :
5819 : 0 : status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
5820 [ # # ]: 0 : if (status != ICE_SUCCESS) {
5821 : 0 : PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
5822 : : ret = -EAGAIN;
5823 : : }
5824 : :
5825 : : return ret;
5826 : : }
5827 : :
5828 : 0 : static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
5829 : : uint16_t queue_id)
5830 : : {
5831 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
5832 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5833 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5834 : : uint32_t val;
5835 : : uint16_t msix_intr;
5836 : :
5837 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
5838 : :
5839 : : val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
5840 : : GLINT_DYN_CTL_ITR_INDX_M;
5841 : : val &= ~GLINT_DYN_CTL_WB_ON_ITR_M;
5842 : :
5843 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), val);
5844 : 0 : rte_intr_ack(pci_dev->intr_handle);
5845 : :
5846 : 0 : return 0;
5847 : : }
5848 : :
5849 : 0 : static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
5850 : : uint16_t queue_id)
5851 : : {
5852 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
5853 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5854 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5855 : : uint16_t msix_intr;
5856 : :
5857 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
5858 : :
5859 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), GLINT_DYN_CTL_WB_ON_ITR_M);
5860 : :
5861 : 0 : return 0;
5862 : : }
5863 : :
5864 : : static int
5865 : 0 : ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
5866 : : {
5867 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5868 : : u8 ver, patch;
5869 : : u16 build;
5870 : : int ret;
5871 : :
5872 : 0 : ver = hw->flash.orom.major;
5873 : 0 : patch = hw->flash.orom.patch;
5874 : 0 : build = hw->flash.orom.build;
5875 : :
5876 : 0 : ret = snprintf(fw_version, fw_size,
5877 : : "%x.%02x 0x%08x %d.%d.%d",
5878 : 0 : hw->flash.nvm.major,
5879 [ # # ]: 0 : hw->flash.nvm.minor,
5880 : : hw->flash.nvm.eetrack,
5881 : : ver, build, patch);
5882 [ # # ]: 0 : if (ret < 0)
5883 : : return -EINVAL;
5884 : :
5885 : : /* add the size of '\0' */
5886 : 0 : ret += 1;
5887 [ # # ]: 0 : if (fw_size < (size_t)ret)
5888 : : return ret;
5889 : : else
5890 : 0 : return 0;
5891 : : }
5892 : :
5893 : : static int
5894 : 0 : ice_vsi_vlan_pvid_set(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
5895 : : {
5896 : : struct ice_hw *hw;
5897 : : struct ice_vsi_ctx ctxt;
5898 : : uint8_t vlan_flags = 0;
5899 : : int ret;
5900 : :
5901 [ # # ]: 0 : if (!vsi || !info) {
5902 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5903 : 0 : return -EINVAL;
5904 : : }
5905 : :
5906 [ # # ]: 0 : if (info->on) {
5907 : 0 : vsi->info.port_based_inner_vlan = info->config.pvid;
5908 : : /**
5909 : : * If insert pvid is enabled, only tagged pkts are
5910 : : * allowed to be sent out.
5911 : : */
5912 : : vlan_flags = ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
5913 : : ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
5914 : : } else {
5915 : 0 : vsi->info.port_based_inner_vlan = 0;
5916 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5917 : : vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTTAGGED;
5918 : :
5919 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5920 : 0 : vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
5921 : : }
5922 : 0 : vsi->info.inner_vlan_flags &= ~(ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
5923 : : ICE_AQ_VSI_INNER_VLAN_EMODE_M);
5924 : 0 : vsi->info.inner_vlan_flags |= vlan_flags;
5925 : : memset(&ctxt, 0, sizeof(ctxt));
5926 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5927 : 0 : ctxt.info.valid_sections =
5928 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5929 : 0 : ctxt.vsi_num = vsi->vsi_id;
5930 : :
5931 : 0 : hw = ICE_VSI_TO_HW(vsi);
5932 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5933 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
5934 : 0 : PMD_DRV_LOG(ERR,
5935 : : "update VSI for VLAN insert failed, err %d",
5936 : : ret);
5937 : 0 : return -EINVAL;
5938 : : }
5939 : :
5940 : 0 : vsi->info.valid_sections |=
5941 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5942 : :
5943 : 0 : return ret;
5944 : : }
5945 : :
5946 : : /**
5947 : : * ice_vsi_set_outer_port_vlan - set the outer port VLAN and related settings
5948 : : * @vsi: VSI to configure
5949 : : * @vlan_info: packed u16 that contains the VLAN prio and ID
5950 : : * @tpid: TPID of the port VLAN
5951 : : *
5952 : : * Set the port VLAN prio, ID, and TPID.
5953 : : *
5954 : : * Enable VLAN pruning so the VSI doesn't receive any traffic that doesn't match
5955 : : * a VLAN prune rule. The caller should take care to add a VLAN prune rule that
5956 : : * matches the port VLAN ID and TPID.
5957 : : *
5958 : : * Tell hardware to strip outer VLAN tagged packets on receive and don't put
5959 : : * them in the receive descriptor. VSI(s) in port VLANs should not be aware of
5960 : : * the port VLAN ID or TPID they are assigned to.
5961 : : *
5962 : : * Tell hardware to prevent outer VLAN tag insertion on transmit and only allow
5963 : : * untagged outer packets from the transmit descriptor.
5964 : : *
5965 : : * Also, tell the hardware to insert the port VLAN on transmit.
5966 : : */
5967 : : static int
5968 : 0 : ice_vsi_set_outer_port_vlan(struct ice_vsi *vsi, u16 vlan_info, u16 tpid)
5969 : : {
5970 [ # # # # ]: 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5971 : : struct ice_vsi_ctx ctxt;
5972 : : int status, err = 0;
5973 : : u8 tag_type;
5974 : :
5975 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
5976 : : return -EINVAL;
5977 : :
5978 : : memset(&ctxt, 0, sizeof(ctxt));
5979 : :
5980 : 0 : ctxt.info = vsi->info;
5981 : :
5982 : 0 : ctxt.info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
5983 : :
5984 : 0 : ctxt.info.port_based_outer_vlan = rte_cpu_to_le_16(vlan_info);
5985 : 0 : ctxt.info.outer_vlan_flags =
5986 : : (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW <<
5987 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
5988 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
5989 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M) |
5990 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
5991 : : (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTUNTAGGED <<
5992 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) |
5993 : : ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT;
5994 : 0 : ctxt.info.valid_sections =
5995 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID |
5996 : : ICE_AQ_VSI_PROP_SW_VALID);
5997 : :
5998 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5999 [ # # ]: 0 : if (status != ICE_SUCCESS) {
6000 : 0 : PMD_DRV_LOG(ERR,
6001 : : "update VSI for setting outer port based VLAN failed, err %d",
6002 : : status);
6003 : : err = -EINVAL;
6004 : : } else {
6005 : 0 : vsi->info.port_based_outer_vlan = ctxt.info.port_based_outer_vlan;
6006 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
6007 : 0 : vsi->info.sw_flags2 = ctxt.info.sw_flags2;
6008 : : }
6009 : :
6010 : : return err;
6011 : : }
6012 : :
6013 : : /**
6014 : : * ice_vsi_dis_outer_insertion - disable outer VLAN insertion
6015 : : * @vsi: VSI to configure
6016 : : * @info: vlan pvid info
6017 : : *
6018 : : * Disable outer VLAN insertion via VSI context. This function should only be
6019 : : * used if DVM is supported.
6020 : : *
6021 : : * Only modify the outer VLAN insertion settings. The VLAN TPID and outer VLAN
6022 : : * settings are unmodified.
6023 : : *
6024 : : * This tells the hardware to not allow VLAN tagged packets in the transmit
6025 : : * descriptor. This enables software offloaded VLAN insertion and disables
6026 : : * hardware offloaded VLAN insertion.
6027 : : */
6028 : 0 : static int ice_vsi_dis_outer_insertion(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
6029 : : {
6030 [ # # ]: 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6031 : : struct ice_vsi_ctx ctxt;
6032 : : uint8_t vlan_flags = 0;
6033 : : int status, err = 0;
6034 : :
6035 : : memset(&ctxt, 0, sizeof(ctxt));
6036 : :
6037 : 0 : ctxt.info.valid_sections =
6038 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
6039 : : ctxt.info.port_based_inner_vlan = 0;
6040 : : /* clear current outer VLAN insertion settings */
6041 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
6042 : : ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
6043 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
6044 [ # # ]: 0 : if (info->config.reject.tagged == 0)
6045 : : vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTTAGGED;
6046 [ # # ]: 0 : if (info->config.reject.untagged == 0)
6047 : 0 : vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTUNTAGGED;
6048 : 0 : ctxt.info.outer_vlan_flags |=
6049 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
6050 : 0 : ((vlan_flags <<
6051 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
6052 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
6053 : :
6054 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
6055 [ # # ]: 0 : if (!status) {
6056 : 0 : PMD_DRV_LOG(ERR,
6057 : : "update VSI for disabling outer VLAN insertion failed, err %d",
6058 : : status);
6059 : : err = -EINVAL;
6060 : : } else {
6061 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
6062 : 0 : vsi->info.port_based_inner_vlan = ctxt.info.port_based_inner_vlan;
6063 : : }
6064 : :
6065 : 0 : return err;
6066 : : }
6067 : :
6068 : : static int
6069 : 0 : ice_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
6070 : : {
6071 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6072 : 0 : struct ice_vsi *vsi = pf->main_vsi;
6073 [ # # ]: 0 : struct rte_eth_dev_data *data = pf->dev_data;
6074 : : struct ice_vsi_vlan_pvid_info info;
6075 : : int ret;
6076 : :
6077 : : memset(&info, 0, sizeof(info));
6078 : 0 : info.on = on;
6079 [ # # ]: 0 : if (info.on) {
6080 : 0 : info.config.pvid = pvid;
6081 : : } else {
6082 : 0 : info.config.reject.tagged =
6083 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
6084 : 0 : info.config.reject.untagged =
6085 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
6086 : : }
6087 : :
6088 [ # # ]: 0 : if (ice_is_dvm_ena(&vsi->adapter->hw)) {
6089 [ # # ]: 0 : if (on)
6090 : 0 : return ice_vsi_set_outer_port_vlan(vsi, pvid, pf->outer_ethertype);
6091 : : else
6092 : 0 : return ice_vsi_dis_outer_insertion(vsi, &info);
6093 : : }
6094 : :
6095 : 0 : ret = ice_vsi_vlan_pvid_set(vsi, &info);
6096 [ # # ]: 0 : if (ret < 0) {
6097 : 0 : PMD_DRV_LOG(ERR, "Failed to set pvid.");
6098 : 0 : return -EINVAL;
6099 : : }
6100 : :
6101 : : return 0;
6102 : : }
6103 : :
6104 : 0 : static int ice_vsi_ena_outer_insertion(struct ice_vsi *vsi, uint16_t tpid)
6105 : : {
6106 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6107 : : struct ice_vsi_ctx ctxt;
6108 : : int status, err = 0;
6109 : : u8 tag_type;
6110 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
6111 : : * on this VSI
6112 : : */
6113 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
6114 : : return 0;
6115 : :
6116 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
6117 : : return -EINVAL;
6118 : :
6119 : : memset(&ctxt, 0, sizeof(ctxt));
6120 : 0 : ctxt.info.valid_sections =
6121 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
6122 : : /* clear current outer VLAN insertion settings */
6123 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
6124 : : ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
6125 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
6126 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M |
6127 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
6128 : 0 : ctxt.info.outer_vlan_flags |=
6129 : : ((ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
6130 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
6131 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M) |
6132 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
6133 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
6134 : :
6135 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
6136 [ # # ]: 0 : if (status) {
6137 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
6138 : : err = -EIO;
6139 : : } else {
6140 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
6141 : : }
6142 : :
6143 : : return err;
6144 : : }
6145 : :
6146 : : static int
6147 : 0 : ice_vlan_tpid_set(struct rte_eth_dev *dev,
6148 : : enum rte_vlan_type vlan_type,
6149 : : uint16_t tpid)
6150 : : {
6151 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6152 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6153 : 0 : struct ice_vsi *vsi = pf->main_vsi;
6154 : 0 : uint64_t qinq = dev->data->dev_conf.rxmode.offloads &
6155 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
6156 : : int err = 0;
6157 : :
6158 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
6159 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
6160 [ # # # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER) ||
6161 : 0 : !ice_is_supported_port_vlan_proto(hw, tpid)) {
6162 : 0 : PMD_DRV_LOG(ERR,
6163 : : "Unsupported vlan type.");
6164 : 0 : return -EINVAL;
6165 : : }
6166 : :
6167 : 0 : err = ice_vsi_ena_outer_insertion(vsi, tpid);
6168 [ # # ]: 0 : if (!err)
6169 : 0 : pf->outer_ethertype = tpid;
6170 : :
6171 : : return err;
6172 : : }
6173 : :
6174 : : static int
6175 : 0 : ice_get_eeprom_length(struct rte_eth_dev *dev)
6176 : : {
6177 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6178 : :
6179 : 0 : return hw->flash.flash_size;
6180 : : }
6181 : :
6182 : : static int
6183 : 0 : ice_get_eeprom(struct rte_eth_dev *dev,
6184 : : struct rte_dev_eeprom_info *eeprom)
6185 : : {
6186 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6187 : 0 : uint8_t *data = eeprom->data;
6188 : : int status;
6189 : :
6190 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6191 : :
6192 : 0 : status = ice_acquire_nvm(hw, ICE_RES_READ);
6193 [ # # ]: 0 : if (status) {
6194 : 0 : PMD_DRV_LOG(ERR, "acquire nvm failed.");
6195 : 0 : return -EIO;
6196 : : }
6197 : :
6198 : 0 : status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->length,
6199 : : data, false);
6200 : :
6201 : 0 : ice_release_nvm(hw);
6202 : :
6203 [ # # ]: 0 : if (status) {
6204 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
6205 : 0 : return -EIO;
6206 : : }
6207 : :
6208 : : return 0;
6209 : : }
6210 : :
6211 : : static int
6212 : 0 : ice_get_module_info(struct rte_eth_dev *dev,
6213 : : struct rte_eth_dev_module_info *modinfo)
6214 : : {
6215 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6216 : 0 : u8 sff8472_comp = 0;
6217 : 0 : u8 sff8472_swap = 0;
6218 : 0 : u8 sff8636_rev = 0;
6219 : 0 : u8 value = 0;
6220 : : int status;
6221 : :
6222 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
6223 : : 0, &value, 1, 0, NULL);
6224 [ # # ]: 0 : if (status)
6225 : : return -EIO;
6226 : :
6227 [ # # # ]: 0 : switch (value) {
6228 : 0 : case ICE_MODULE_TYPE_SFP:
6229 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6230 : : ICE_MODULE_SFF_8472_COMP, 0x00, 0,
6231 : : &sff8472_comp, 1, 0, NULL);
6232 [ # # ]: 0 : if (status)
6233 : : return -EIO;
6234 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6235 : : ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
6236 : : &sff8472_swap, 1, 0, NULL);
6237 [ # # ]: 0 : if (status)
6238 : : return -EIO;
6239 : :
6240 [ # # ]: 0 : if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
6241 : 0 : modinfo->type = ICE_MODULE_SFF_8079;
6242 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8079_LEN;
6243 [ # # # # ]: 0 : } else if (sff8472_comp &&
6244 : : (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
6245 : 0 : modinfo->type = ICE_MODULE_SFF_8472;
6246 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8472_LEN;
6247 : : } else {
6248 : 0 : modinfo->type = ICE_MODULE_SFF_8079;
6249 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8079_LEN;
6250 : : }
6251 : : break;
6252 : 0 : case ICE_MODULE_TYPE_QSFP_PLUS:
6253 : : case ICE_MODULE_TYPE_QSFP28:
6254 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6255 : : ICE_MODULE_REVISION_ADDR, 0x00, 0,
6256 : : &sff8636_rev, 1, 0, NULL);
6257 [ # # ]: 0 : if (status)
6258 : : return -EIO;
6259 : : /* Check revision compliance */
6260 [ # # ]: 0 : if (sff8636_rev > 0x02) {
6261 : : /* Module is SFF-8636 compliant */
6262 : 0 : modinfo->type = ICE_MODULE_SFF_8636;
6263 : 0 : modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
6264 : : } else {
6265 : 0 : modinfo->type = ICE_MODULE_SFF_8436;
6266 : 0 : modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
6267 : : }
6268 : : break;
6269 : 0 : default:
6270 : 0 : PMD_DRV_LOG(WARNING, "SFF Module Type not recognized.");
6271 : 0 : return -EINVAL;
6272 : : }
6273 : : return 0;
6274 : : }
6275 : :
6276 : : static int
6277 : 0 : ice_get_module_eeprom(struct rte_eth_dev *dev,
6278 : : struct rte_dev_eeprom_info *info)
6279 : : {
6280 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6281 : : #define SFF_READ_BLOCK_SIZE 8
6282 : : #define I2C_BUSY_TRY_TIMES 4
6283 : : #define I2C_USLEEP_MIN_TIME 1500
6284 : : #define I2C_USLEEP_MAX_TIME 2500
6285 : 0 : uint8_t value[SFF_READ_BLOCK_SIZE] = {0};
6286 : : uint8_t addr = ICE_I2C_EEPROM_DEV_ADDR;
6287 : : uint8_t *data = NULL;
6288 : : bool is_sfp = false;
6289 : : uint32_t i, j;
6290 : : uint32_t offset = 0;
6291 : : uint8_t page = 0;
6292 : : int status;
6293 : :
6294 [ # # # # : 0 : if (!info || !info->length || !info->data)
# # ]
6295 : : return -EINVAL;
6296 : :
6297 : 0 : status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
6298 : : NULL);
6299 [ # # ]: 0 : if (status)
6300 : : return -EIO;
6301 : :
6302 [ # # ]: 0 : if (value[0] == ICE_MODULE_TYPE_SFP)
6303 : : is_sfp = true;
6304 : :
6305 : 0 : data = info->data;
6306 : 0 : memset(data, 0, info->length);
6307 [ # # ]: 0 : for (i = 0; i < info->length; i += SFF_READ_BLOCK_SIZE) {
6308 : 0 : offset = i + info->offset;
6309 : : page = 0;
6310 : :
6311 : : /* Check if we need to access the other memory page */
6312 [ # # ]: 0 : if (is_sfp) {
6313 [ # # ]: 0 : if (offset >= ICE_MODULE_SFF_8079_LEN) {
6314 : 0 : offset -= ICE_MODULE_SFF_8079_LEN;
6315 : : addr = ICE_I2C_EEPROM_DEV_ADDR2;
6316 : : }
6317 : : } else {
6318 [ # # ]: 0 : while (offset >= ICE_MODULE_SFF_8436_LEN) {
6319 : : /* Compute memory page number and offset. */
6320 : 0 : offset -= ICE_MODULE_SFF_8436_LEN / 2;
6321 : 0 : page++;
6322 : : }
6323 : : }
6324 : :
6325 : : /* Bit 2 of eeprom address 0x02 declares upper
6326 : : * pages are disabled on QSFP modules.
6327 : : * SFP modules only ever use page 0.
6328 : : */
6329 [ # # # # ]: 0 : if (page == 0 || !(data[0x2] & 0x4)) {
6330 : : /* If i2c bus is busy due to slow page change or
6331 : : * link management access, call can fail.
6332 : : * This is normal. So we retry this a few times.
6333 : : */
6334 [ # # ]: 0 : for (j = 0; j < I2C_BUSY_TRY_TIMES; j++) {
6335 : 0 : status = ice_aq_sff_eeprom(hw, 0, addr, offset,
6336 : 0 : page, !is_sfp, value,
6337 : : SFF_READ_BLOCK_SIZE,
6338 : : 0, NULL);
6339 : 0 : PMD_DRV_LOG(DEBUG, "SFF %02X %02X %02X %X = "
6340 : : "%02X%02X%02X%02X."
6341 : : "%02X%02X%02X%02X (%X)",
6342 : : addr, offset, page, is_sfp,
6343 : : value[0], value[1],
6344 : : value[2], value[3],
6345 : : value[4], value[5],
6346 : : value[6], value[7],
6347 : : status);
6348 [ # # ]: 0 : if (status) {
6349 : 0 : usleep_range(I2C_USLEEP_MIN_TIME,
6350 : : I2C_USLEEP_MAX_TIME);
6351 : : memset(value, 0, SFF_READ_BLOCK_SIZE);
6352 : : continue;
6353 : : }
6354 : : break;
6355 : : }
6356 : :
6357 : : /* Make sure we have enough room for the new block */
6358 [ # # ]: 0 : if ((i + SFF_READ_BLOCK_SIZE) <= info->length)
6359 : 0 : memcpy(data + i, value, SFF_READ_BLOCK_SIZE);
6360 : : }
6361 : : }
6362 : :
6363 : : return 0;
6364 : : }
6365 : :
6366 : : static void
6367 : : ice_stat_update_32(struct ice_hw *hw,
6368 : : uint32_t reg,
6369 : : bool offset_loaded,
6370 : : uint64_t *offset,
6371 : : uint64_t *stat)
6372 : : {
6373 : : uint64_t new_data;
6374 : :
6375 : 0 : new_data = (uint64_t)ICE_READ_REG(hw, reg);
6376 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
6377 : 0 : *offset = new_data;
6378 : :
6379 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
6380 : 0 : *stat = (uint64_t)(new_data - *offset);
6381 : : else
6382 : 0 : *stat = (uint64_t)((new_data +
6383 : : ((uint64_t)1 << ICE_32_BIT_WIDTH))
6384 : : - *offset);
6385 : : }
6386 : :
6387 : : static void
6388 : 0 : ice_stat_update_40(struct ice_hw *hw,
6389 : : uint32_t hireg,
6390 : : uint32_t loreg,
6391 : : bool offset_loaded,
6392 : : uint64_t *offset,
6393 : : uint64_t *stat)
6394 : : {
6395 : : uint64_t new_data;
6396 : : uint32_t lo_old, hi, lo;
6397 : :
6398 : : do {
6399 : 0 : lo_old = ICE_READ_REG(hw, loreg);
6400 : 0 : hi = ICE_READ_REG(hw, hireg);
6401 : 0 : lo = ICE_READ_REG(hw, loreg);
6402 [ # # ]: 0 : } while (lo_old > lo);
6403 : :
6404 : 0 : new_data = (uint64_t)lo;
6405 : 0 : new_data |= (uint64_t)(hi & ICE_8_BIT_MASK) << ICE_32_BIT_WIDTH;
6406 : :
6407 [ # # ]: 0 : if (!offset_loaded)
6408 : 0 : *offset = new_data;
6409 : :
6410 [ # # ]: 0 : if (new_data >= *offset)
6411 : 0 : *stat = new_data - *offset;
6412 : : else
6413 : 0 : *stat = (uint64_t)((new_data +
6414 : : ((uint64_t)1 << ICE_40_BIT_WIDTH)) -
6415 : : *offset);
6416 : :
6417 : 0 : *stat &= ICE_40_BIT_MASK;
6418 : 0 : }
6419 : :
6420 : : /**
6421 : : * There are various counters that are bubbled up in uint64 values but do not make use of all
6422 : : * 64 bits, most commonly using only 32 or 40 bits. This function handles the "overflow" when
6423 : : * these counters hit their 32 or 40 bit limit to enlarge that limitation to 64 bits.
6424 : :
6425 : : * @offset_loaded: refers to whether this function has been called before and old_value is known to
6426 : : * have a value, i.e. its possible that value has overflowed past its original limitation
6427 : : * @value_bit_limitation: refers to the number of bits the given value uses before overflowing
6428 : : * @value: is the current value with its original limitation (i.e. 32 or 40 bits)
6429 : : * @old_value: is expected to be the previous value of the given value with the overflow accounted
6430 : : * for (i.e. the full 64 bit previous value)
6431 : : *
6432 : : * This function will appropriately update both value and old_value, accounting for overflow
6433 : : */
6434 : : static void
6435 : : ice_handle_overflow(bool offset_loaded,
6436 : : uint8_t value_bit_limitation,
6437 : : uint64_t *value,
6438 : : uint64_t *old_value)
6439 : : {
6440 : : uint64_t low_bit_mask = RTE_LEN2MASK(value_bit_limitation, uint64_t);
6441 : : uint64_t high_bit_mask = ~low_bit_mask;
6442 : :
6443 : 0 : if (offset_loaded) {
6444 [ # # # # : 0 : if ((*old_value & low_bit_mask) > *value)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
6445 : 0 : *value += (uint64_t)1 << value_bit_limitation;
6446 : 0 : *value += *old_value & high_bit_mask;
6447 : : }
6448 [ # # # # : 0 : *old_value = *value;
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
6449 : : }
6450 : :
6451 : : /* Get all the statistics of a VSI */
6452 : : static void
6453 : 0 : ice_update_vsi_stats(struct ice_vsi *vsi)
6454 : : {
6455 : : struct ice_eth_stats *oes = &vsi->eth_stats_offset;
6456 : : struct ice_eth_stats *nes = &vsi->eth_stats;
6457 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6458 : 0 : int idx = rte_le_to_cpu_16(vsi->vsi_id);
6459 : :
6460 : 0 : ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
6461 : 0 : vsi->offset_loaded, &oes->rx_bytes,
6462 : 0 : &nes->rx_bytes);
6463 : 0 : ice_stat_update_40(hw, GLV_UPRCH(idx), GLV_UPRCL(idx),
6464 : 0 : vsi->offset_loaded, &oes->rx_unicast,
6465 : 0 : &nes->rx_unicast);
6466 : 0 : ice_stat_update_40(hw, GLV_MPRCH(idx), GLV_MPRCL(idx),
6467 : 0 : vsi->offset_loaded, &oes->rx_multicast,
6468 : 0 : &nes->rx_multicast);
6469 : 0 : ice_stat_update_40(hw, GLV_BPRCH(idx), GLV_BPRCL(idx),
6470 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
6471 : 0 : &nes->rx_broadcast);
6472 : :
6473 [ # # ]: 0 : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6474 : : &nes->rx_unicast, &vsi->old_get_stats_fields.rx_unicast);
6475 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6476 : : &nes->rx_multicast, &vsi->old_get_stats_fields.rx_multicast);
6477 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6478 : : &nes->rx_broadcast, &vsi->old_get_stats_fields.rx_broadcast);
6479 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6480 : : &nes->rx_bytes, &vsi->old_get_stats_fields.rx_bytes);
6481 : :
6482 : : /* exclude CRC bytes */
6483 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
6484 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
6485 : :
6486 : 0 : ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
6487 : : &oes->rx_discards, &nes->rx_discards);
6488 : : /* GLV_REPC not supported */
6489 : : /* GLV_RMPC not supported */
6490 : 0 : ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
6491 : : &oes->rx_unknown_protocol,
6492 : : &nes->rx_unknown_protocol);
6493 : 0 : ice_stat_update_40(hw, GLV_GOTCH(idx), GLV_GOTCL(idx),
6494 : 0 : vsi->offset_loaded, &oes->tx_bytes,
6495 : 0 : &nes->tx_bytes);
6496 : 0 : ice_stat_update_40(hw, GLV_UPTCH(idx), GLV_UPTCL(idx),
6497 : 0 : vsi->offset_loaded, &oes->tx_unicast,
6498 : 0 : &nes->tx_unicast);
6499 : 0 : ice_stat_update_40(hw, GLV_MPTCH(idx), GLV_MPTCL(idx),
6500 : 0 : vsi->offset_loaded, &oes->tx_multicast,
6501 : 0 : &nes->tx_multicast);
6502 : 0 : ice_stat_update_40(hw, GLV_BPTCH(idx), GLV_BPTCL(idx),
6503 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
6504 : 0 : &nes->tx_broadcast);
6505 : : /* GLV_TDPC not supported */
6506 : 0 : ice_stat_update_32(hw, GLV_TEPC(idx), vsi->offset_loaded,
6507 : : &oes->tx_errors, &nes->tx_errors);
6508 : :
6509 [ # # ]: 0 : ice_handle_overflow(vsi->offset_loaded, ICE_32_BIT_WIDTH,
6510 : : &nes->rx_discards, &vsi->old_get_stats_fields.rx_discards);
6511 : : ice_handle_overflow(vsi->offset_loaded, ICE_32_BIT_WIDTH,
6512 : : &nes->tx_errors, &vsi->old_get_stats_fields.tx_errors);
6513 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6514 : : &nes->tx_bytes, &vsi->old_get_stats_fields.tx_bytes);
6515 : :
6516 : 0 : vsi->offset_loaded = true;
6517 : :
6518 : 0 : PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats start **************",
6519 : : vsi->vsi_id);
6520 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
6521 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
6522 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
6523 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
6524 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
6525 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
6526 : : nes->rx_unknown_protocol);
6527 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
6528 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
6529 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
6530 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
6531 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
6532 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
6533 : 0 : PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats end ****************",
6534 : : vsi->vsi_id);
6535 : 0 : }
6536 : :
6537 : : static void
6538 : 0 : ice_read_stats_registers(struct ice_pf *pf, struct ice_hw *hw)
6539 : : {
6540 : : struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
6541 : : struct ice_hw_port_stats *os = &pf->stats_offset; /* old stats */
6542 : :
6543 : : /* Get statistics of struct ice_eth_stats */
6544 : 0 : ice_stat_update_40(hw, GLPRT_GORCH(hw->port_info->lport),
6545 : 0 : GLPRT_GORCL(hw->port_info->lport),
6546 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
6547 : 0 : &ns->eth.rx_bytes);
6548 : 0 : ice_stat_update_40(hw, GLPRT_UPRCH(hw->port_info->lport),
6549 : 0 : GLPRT_UPRCL(hw->port_info->lport),
6550 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
6551 : 0 : &ns->eth.rx_unicast);
6552 : 0 : ice_stat_update_40(hw, GLPRT_MPRCH(hw->port_info->lport),
6553 : 0 : GLPRT_MPRCL(hw->port_info->lport),
6554 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
6555 : 0 : &ns->eth.rx_multicast);
6556 : 0 : ice_stat_update_40(hw, GLPRT_BPRCH(hw->port_info->lport),
6557 : 0 : GLPRT_BPRCL(hw->port_info->lport),
6558 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
6559 : 0 : &ns->eth.rx_broadcast);
6560 : : ice_stat_update_32(hw, PRTRPB_RDPC,
6561 : 0 : pf->offset_loaded, &os->eth.rx_discards,
6562 : : &ns->eth.rx_discards);
6563 : :
6564 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6565 : : &ns->eth.rx_bytes, &pf->old_get_stats_fields.rx_bytes);
6566 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6567 : : &ns->eth.rx_discards, &pf->old_get_stats_fields.rx_discards);
6568 : :
6569 : : /* Workaround: CRC size should not be included in byte statistics,
6570 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
6571 : : * packet.
6572 : : */
6573 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
6574 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
6575 : :
6576 : : /* GLPRT_REPC not supported */
6577 : : /* GLPRT_RMPC not supported */
6578 : 0 : ice_stat_update_32(hw, GLSWID_RUPP(hw->port_info->lport),
6579 : : pf->offset_loaded,
6580 : : &os->eth.rx_unknown_protocol,
6581 : : &ns->eth.rx_unknown_protocol);
6582 : 0 : ice_stat_update_40(hw, GLPRT_GOTCH(hw->port_info->lport),
6583 : 0 : GLPRT_GOTCL(hw->port_info->lport),
6584 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
6585 : 0 : &ns->eth.tx_bytes);
6586 : 0 : ice_stat_update_40(hw, GLPRT_UPTCH(hw->port_info->lport),
6587 : 0 : GLPRT_UPTCL(hw->port_info->lport),
6588 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
6589 : 0 : &ns->eth.tx_unicast);
6590 : 0 : ice_stat_update_40(hw, GLPRT_MPTCH(hw->port_info->lport),
6591 : 0 : GLPRT_MPTCL(hw->port_info->lport),
6592 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
6593 : 0 : &ns->eth.tx_multicast);
6594 : 0 : ice_stat_update_40(hw, GLPRT_BPTCH(hw->port_info->lport),
6595 : 0 : GLPRT_BPTCL(hw->port_info->lport),
6596 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
6597 : 0 : &ns->eth.tx_broadcast);
6598 : :
6599 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6600 : : &ns->eth.tx_bytes, &pf->old_get_stats_fields.tx_bytes);
6601 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6602 : : &ns->eth.tx_unicast, &pf->old_get_stats_fields.tx_unicast);
6603 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6604 : : &ns->eth.tx_multicast, &pf->old_get_stats_fields.tx_multicast);
6605 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6606 : : &ns->eth.tx_broadcast, &pf->old_get_stats_fields.tx_broadcast);
6607 : :
6608 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
6609 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
6610 : :
6611 : : /* GLPRT_TEPC not supported */
6612 : :
6613 : : /* additional port specific stats */
6614 : 0 : ice_stat_update_32(hw, GLPRT_TDOLD(hw->port_info->lport),
6615 : : pf->offset_loaded, &os->tx_dropped_link_down,
6616 : : &ns->tx_dropped_link_down);
6617 : 0 : ice_stat_update_32(hw, GLPRT_CRCERRS(hw->port_info->lport),
6618 : 0 : pf->offset_loaded, &os->crc_errors,
6619 : : &ns->crc_errors);
6620 : 0 : ice_stat_update_32(hw, GLPRT_ILLERRC(hw->port_info->lport),
6621 : 0 : pf->offset_loaded, &os->illegal_bytes,
6622 : : &ns->illegal_bytes);
6623 : : /* GLPRT_ERRBC not supported */
6624 : 0 : ice_stat_update_32(hw, GLPRT_MLFC(hw->port_info->lport),
6625 : 0 : pf->offset_loaded, &os->mac_local_faults,
6626 : : &ns->mac_local_faults);
6627 : 0 : ice_stat_update_32(hw, GLPRT_MRFC(hw->port_info->lport),
6628 : 0 : pf->offset_loaded, &os->mac_remote_faults,
6629 : : &ns->mac_remote_faults);
6630 : :
6631 : 0 : ice_stat_update_32(hw, GLPRT_RLEC(hw->port_info->lport),
6632 : 0 : pf->offset_loaded, &os->rx_len_errors,
6633 : : &ns->rx_len_errors);
6634 : :
6635 : 0 : ice_stat_update_32(hw, GLPRT_LXONRXC(hw->port_info->lport),
6636 : 0 : pf->offset_loaded, &os->link_xon_rx,
6637 : : &ns->link_xon_rx);
6638 : 0 : ice_stat_update_32(hw, GLPRT_LXOFFRXC(hw->port_info->lport),
6639 : 0 : pf->offset_loaded, &os->link_xoff_rx,
6640 : : &ns->link_xoff_rx);
6641 : 0 : ice_stat_update_32(hw, GLPRT_LXONTXC(hw->port_info->lport),
6642 : 0 : pf->offset_loaded, &os->link_xon_tx,
6643 : : &ns->link_xon_tx);
6644 : 0 : ice_stat_update_32(hw, GLPRT_LXOFFTXC(hw->port_info->lport),
6645 : 0 : pf->offset_loaded, &os->link_xoff_tx,
6646 : : &ns->link_xoff_tx);
6647 : 0 : ice_stat_update_40(hw, GLPRT_PRC64H(hw->port_info->lport),
6648 : 0 : GLPRT_PRC64L(hw->port_info->lport),
6649 : 0 : pf->offset_loaded, &os->rx_size_64,
6650 : 0 : &ns->rx_size_64);
6651 : 0 : ice_stat_update_40(hw, GLPRT_PRC127H(hw->port_info->lport),
6652 : 0 : GLPRT_PRC127L(hw->port_info->lport),
6653 : 0 : pf->offset_loaded, &os->rx_size_127,
6654 : 0 : &ns->rx_size_127);
6655 : 0 : ice_stat_update_40(hw, GLPRT_PRC255H(hw->port_info->lport),
6656 : 0 : GLPRT_PRC255L(hw->port_info->lport),
6657 : 0 : pf->offset_loaded, &os->rx_size_255,
6658 : 0 : &ns->rx_size_255);
6659 : 0 : ice_stat_update_40(hw, GLPRT_PRC511H(hw->port_info->lport),
6660 : 0 : GLPRT_PRC511L(hw->port_info->lport),
6661 : 0 : pf->offset_loaded, &os->rx_size_511,
6662 : 0 : &ns->rx_size_511);
6663 : 0 : ice_stat_update_40(hw, GLPRT_PRC1023H(hw->port_info->lport),
6664 : 0 : GLPRT_PRC1023L(hw->port_info->lport),
6665 : 0 : pf->offset_loaded, &os->rx_size_1023,
6666 : 0 : &ns->rx_size_1023);
6667 : 0 : ice_stat_update_40(hw, GLPRT_PRC1522H(hw->port_info->lport),
6668 : 0 : GLPRT_PRC1522L(hw->port_info->lport),
6669 : 0 : pf->offset_loaded, &os->rx_size_1522,
6670 : 0 : &ns->rx_size_1522);
6671 : 0 : ice_stat_update_40(hw, GLPRT_PRC9522H(hw->port_info->lport),
6672 : 0 : GLPRT_PRC9522L(hw->port_info->lport),
6673 : 0 : pf->offset_loaded, &os->rx_size_big,
6674 : 0 : &ns->rx_size_big);
6675 : 0 : ice_stat_update_32(hw, GLPRT_RUC(hw->port_info->lport),
6676 : 0 : pf->offset_loaded, &os->rx_undersize,
6677 : : &ns->rx_undersize);
6678 : 0 : ice_stat_update_32(hw, GLPRT_RFC(hw->port_info->lport),
6679 : 0 : pf->offset_loaded, &os->rx_fragments,
6680 : : &ns->rx_fragments);
6681 : 0 : ice_stat_update_32(hw, GLPRT_ROC(hw->port_info->lport),
6682 : 0 : pf->offset_loaded, &os->rx_oversize,
6683 : : &ns->rx_oversize);
6684 : 0 : ice_stat_update_32(hw, GLPRT_RJC(hw->port_info->lport),
6685 : 0 : pf->offset_loaded, &os->rx_jabber,
6686 : : &ns->rx_jabber);
6687 : 0 : ice_stat_update_40(hw, GLPRT_PTC64H(hw->port_info->lport),
6688 : 0 : GLPRT_PTC64L(hw->port_info->lport),
6689 : 0 : pf->offset_loaded, &os->tx_size_64,
6690 : 0 : &ns->tx_size_64);
6691 : 0 : ice_stat_update_40(hw, GLPRT_PTC127H(hw->port_info->lport),
6692 : 0 : GLPRT_PTC127L(hw->port_info->lport),
6693 : 0 : pf->offset_loaded, &os->tx_size_127,
6694 : 0 : &ns->tx_size_127);
6695 : 0 : ice_stat_update_40(hw, GLPRT_PTC255H(hw->port_info->lport),
6696 : 0 : GLPRT_PTC255L(hw->port_info->lport),
6697 : 0 : pf->offset_loaded, &os->tx_size_255,
6698 : 0 : &ns->tx_size_255);
6699 : 0 : ice_stat_update_40(hw, GLPRT_PTC511H(hw->port_info->lport),
6700 : 0 : GLPRT_PTC511L(hw->port_info->lport),
6701 : 0 : pf->offset_loaded, &os->tx_size_511,
6702 : 0 : &ns->tx_size_511);
6703 : 0 : ice_stat_update_40(hw, GLPRT_PTC1023H(hw->port_info->lport),
6704 : 0 : GLPRT_PTC1023L(hw->port_info->lport),
6705 : 0 : pf->offset_loaded, &os->tx_size_1023,
6706 : 0 : &ns->tx_size_1023);
6707 : 0 : ice_stat_update_40(hw, GLPRT_PTC1522H(hw->port_info->lport),
6708 : 0 : GLPRT_PTC1522L(hw->port_info->lport),
6709 : 0 : pf->offset_loaded, &os->tx_size_1522,
6710 : 0 : &ns->tx_size_1522);
6711 : 0 : ice_stat_update_40(hw, GLPRT_PTC9522H(hw->port_info->lport),
6712 : 0 : GLPRT_PTC9522L(hw->port_info->lport),
6713 : 0 : pf->offset_loaded, &os->tx_size_big,
6714 : 0 : &ns->tx_size_big);
6715 : :
6716 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6717 : : &ns->crc_errors, &pf->old_get_stats_fields.crc_errors);
6718 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6719 : : &ns->rx_undersize, &pf->old_get_stats_fields.rx_undersize);
6720 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6721 : : &ns->rx_fragments, &pf->old_get_stats_fields.rx_fragments);
6722 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6723 : : &ns->rx_oversize, &pf->old_get_stats_fields.rx_oversize);
6724 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6725 : : &ns->rx_jabber, &pf->old_get_stats_fields.rx_jabber);
6726 : :
6727 : : /* GLPRT_MSPDC not supported */
6728 : : /* GLPRT_XEC not supported */
6729 : :
6730 [ # # ]: 0 : for (int i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
6731 : 0 : ice_stat_update_40(hw, GLPRT_PXONRXC_H(hw->port_info->lport, i),
6732 : 0 : GLPRT_PXONRXC(hw->port_info->lport, i),
6733 : 0 : pf->offset_loaded, &os->priority_xon_rx[i],
6734 : 0 : &ns->priority_xon_rx[i]);
6735 : 0 : ice_stat_update_40(hw, GLPRT_PXONTXC_H(hw->port_info->lport, i),
6736 : 0 : GLPRT_PXONTXC(hw->port_info->lport, i),
6737 : 0 : pf->offset_loaded, &os->priority_xon_tx[i],
6738 : 0 : &ns->priority_xon_tx[i]);
6739 : 0 : ice_stat_update_40(hw, GLPRT_PXOFFRXC_H(hw->port_info->lport, i),
6740 : 0 : GLPRT_PXOFFRXC(hw->port_info->lport, i),
6741 : 0 : pf->offset_loaded, &os->priority_xoff_rx[i],
6742 : 0 : &ns->priority_xoff_rx[i]);
6743 : 0 : ice_stat_update_40(hw, GLPRT_PXOFFTXC_H(hw->port_info->lport, i),
6744 : 0 : GLPRT_PXOFFTXC(hw->port_info->lport, i),
6745 : 0 : pf->offset_loaded, &os->priority_xoff_tx[i],
6746 : 0 : &ns->priority_xoff_tx[i]);
6747 : 0 : ice_stat_update_40(hw, GLPRT_RXON2OFFCNT_H(hw->port_info->lport, i),
6748 : 0 : GLPRT_RXON2OFFCNT(hw->port_info->lport, i),
6749 : 0 : pf->offset_loaded, &os->priority_xon_2_xoff[i],
6750 : 0 : &ns->priority_xon_2_xoff[i]);
6751 : : }
6752 : :
6753 : 0 : pf->offset_loaded = true;
6754 : :
6755 [ # # ]: 0 : if (pf->main_vsi)
6756 : 0 : ice_update_vsi_stats(pf->main_vsi);
6757 : 0 : }
6758 : :
6759 : : /* Get all statistics of a port */
6760 : : static int
6761 : 0 : ice_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
6762 : : struct eth_queue_stats *qstats __rte_unused)
6763 : : {
6764 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6765 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6766 : : struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
6767 : :
6768 : : /* call read registers - updates values, now write them to struct */
6769 : 0 : ice_read_stats_registers(pf, hw);
6770 : :
6771 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
6772 : 0 : pf->main_vsi->eth_stats.rx_multicast +
6773 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
6774 : 0 : pf->main_vsi->eth_stats.rx_discards;
6775 : 0 : stats->opackets = ns->eth.tx_unicast +
6776 : 0 : ns->eth.tx_multicast +
6777 : 0 : ns->eth.tx_broadcast;
6778 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
6779 : 0 : stats->obytes = ns->eth.tx_bytes;
6780 : 0 : stats->oerrors = ns->eth.tx_errors +
6781 : 0 : pf->main_vsi->eth_stats.tx_errors;
6782 : :
6783 : : /* Rx Errors */
6784 : 0 : stats->imissed = ns->eth.rx_discards +
6785 : : pf->main_vsi->eth_stats.rx_discards;
6786 : 0 : stats->ierrors = ns->crc_errors +
6787 : 0 : ns->rx_undersize +
6788 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
6789 : :
6790 : 0 : PMD_DRV_LOG(DEBUG, "*************** PF stats start *****************");
6791 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
6792 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
6793 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast:%"PRIu64"", ns->eth.rx_multicast);
6794 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast:%"PRIu64"", ns->eth.rx_broadcast);
6795 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards:%"PRIu64"", ns->eth.rx_discards);
6796 : 0 : PMD_DRV_LOG(DEBUG, "vsi rx_discards:%"PRIu64"",
6797 : : pf->main_vsi->eth_stats.rx_discards);
6798 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
6799 : : ns->eth.rx_unknown_protocol);
6800 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
6801 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
6802 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast:%"PRIu64"", ns->eth.tx_multicast);
6803 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast:%"PRIu64"", ns->eth.tx_broadcast);
6804 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards:%"PRIu64"", ns->eth.tx_discards);
6805 : 0 : PMD_DRV_LOG(DEBUG, "vsi tx_discards:%"PRIu64"",
6806 : : pf->main_vsi->eth_stats.tx_discards);
6807 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
6808 : :
6809 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
6810 : : ns->tx_dropped_link_down);
6811 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
6812 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
6813 : : ns->illegal_bytes);
6814 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
6815 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
6816 : : ns->mac_local_faults);
6817 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
6818 : : ns->mac_remote_faults);
6819 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
6820 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
6821 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
6822 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
6823 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
6824 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
6825 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
6826 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
6827 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
6828 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
6829 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
6830 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
6831 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
6832 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
6833 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
6834 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
6835 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
6836 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
6837 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
6838 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
6839 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
6840 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
6841 : 0 : PMD_DRV_LOG(DEBUG, "rx_len_errors: %"PRIu64"", ns->rx_len_errors);
6842 : 0 : PMD_DRV_LOG(DEBUG, "************* PF stats end ****************");
6843 : 0 : return 0;
6844 : : }
6845 : :
6846 : : /* Reset the statistics */
6847 : : static int
6848 : 0 : ice_stats_reset(struct rte_eth_dev *dev)
6849 : : {
6850 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6851 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6852 : :
6853 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
6854 : 0 : pf->offset_loaded = false;
6855 [ # # ]: 0 : if (pf->main_vsi)
6856 : 0 : pf->main_vsi->offset_loaded = false;
6857 : :
6858 : : /* read the stats, reading current register values into offset */
6859 : 0 : ice_read_stats_registers(pf, hw);
6860 : :
6861 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct ice_mbuf_stats));
6862 : :
6863 : 0 : return 0;
6864 : : }
6865 : :
6866 : : static uint32_t
6867 : : ice_xstats_calc_num(void)
6868 : : {
6869 : : uint32_t num;
6870 : :
6871 : : num = ICE_NB_ETH_XSTATS + ICE_NB_MBUF_XSTATS + ICE_NB_HW_PORT_XSTATS;
6872 : :
6873 : : return num;
6874 : : }
6875 : :
6876 : : static void
6877 : : ice_update_mbuf_stats(struct rte_eth_dev *ethdev,
6878 : : struct ice_mbuf_stats *mbuf_stats)
6879 : : {
6880 : : uint16_t idx;
6881 : : struct ci_tx_queue *txq;
6882 : :
6883 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
6884 : 0 : txq = ethdev->data->tx_queues[idx];
6885 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
6886 : : }
6887 : : }
6888 : :
6889 : : static int
6890 : 0 : ice_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
6891 : : unsigned int n)
6892 : : {
6893 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6894 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6895 : : struct ice_adapter *adapter =
6896 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
6897 : : struct ice_mbuf_stats mbuf_stats = {0};
6898 : : unsigned int i;
6899 : : unsigned int count;
6900 : 0 : struct ice_hw_port_stats *hw_stats = &pf->stats;
6901 : :
6902 : : count = ice_xstats_calc_num();
6903 [ # # ]: 0 : if (n < count)
6904 : : return count;
6905 : :
6906 : 0 : ice_read_stats_registers(pf, hw);
6907 : :
6908 [ # # ]: 0 : if (!xstats)
6909 : : return 0;
6910 : :
6911 : : count = 0;
6912 : :
6913 [ # # ]: 0 : if (adapter->devargs.mbuf_check)
6914 : : ice_update_mbuf_stats(dev, &mbuf_stats);
6915 : :
6916 : : /* Get stats from ice_eth_stats struct */
6917 [ # # ]: 0 : for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
6918 : 0 : xstats[count].value =
6919 : 0 : *(uint64_t *)((char *)&hw_stats->eth +
6920 : 0 : ice_stats_strings[i].offset);
6921 : 0 : xstats[count].id = count;
6922 : 0 : count++;
6923 : : }
6924 : :
6925 : : /* Get stats from ice_mbuf_stats struct */
6926 [ # # ]: 0 : for (i = 0; i < ICE_NB_MBUF_XSTATS; i++) {
6927 : 0 : xstats[count].value =
6928 : : *(uint64_t *)((char *)&mbuf_stats + ice_mbuf_strings[i].offset);
6929 : 0 : xstats[count].id = count;
6930 : 0 : count++;
6931 : : }
6932 : :
6933 : : /* Get individual stats from ice_hw_port struct */
6934 [ # # ]: 0 : for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
6935 : 0 : xstats[count].value =
6936 : 0 : *(uint64_t *)((char *)hw_stats +
6937 : 0 : ice_hw_port_strings[i].offset);
6938 : 0 : xstats[count].id = count;
6939 : 0 : count++;
6940 : : }
6941 : :
6942 : 0 : return count;
6943 : : }
6944 : :
6945 : 0 : static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
6946 : : struct rte_eth_xstat_name *xstats_names,
6947 : : __rte_unused unsigned int limit)
6948 : : {
6949 : : unsigned int count = 0;
6950 : : unsigned int i;
6951 : :
6952 [ # # ]: 0 : if (!xstats_names)
6953 : : return ice_xstats_calc_num();
6954 : :
6955 : : /* Note: limit checked in rte_eth_xstats_names() */
6956 : :
6957 : : /* Get stats from ice_eth_stats struct */
6958 [ # # ]: 0 : for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
6959 : 0 : strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
6960 : : sizeof(xstats_names[count].name));
6961 : 0 : count++;
6962 : : }
6963 : :
6964 : : /* Get stats from ice_mbuf_stats struct */
6965 [ # # ]: 0 : for (i = 0; i < ICE_NB_MBUF_XSTATS; i++) {
6966 : 0 : strlcpy(xstats_names[count].name, ice_mbuf_strings[i].name,
6967 : : sizeof(xstats_names[count].name));
6968 : 0 : count++;
6969 : : }
6970 : :
6971 : : /* Get individual stats from ice_hw_port struct */
6972 [ # # ]: 0 : for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
6973 : 0 : strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
6974 : : sizeof(xstats_names[count].name));
6975 : 0 : count++;
6976 : : }
6977 : :
6978 : 0 : return count;
6979 : : }
6980 : :
6981 : : static int
6982 : 0 : ice_dev_flow_ops_get(struct rte_eth_dev *dev,
6983 : : const struct rte_flow_ops **ops)
6984 : : {
6985 [ # # ]: 0 : if (!dev)
6986 : : return -EINVAL;
6987 : :
6988 : 0 : *ops = &ice_flow_ops;
6989 : 0 : return 0;
6990 : : }
6991 : :
6992 : : /* Add UDP tunneling port */
6993 : : static int
6994 : 0 : ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
6995 : : struct rte_eth_udp_tunnel *udp_tunnel)
6996 : : {
6997 : : int ret = 0;
6998 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6999 : : struct ice_adapter *ad =
7000 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7001 : :
7002 [ # # ]: 0 : if (udp_tunnel == NULL)
7003 : : return -EINVAL;
7004 : :
7005 [ # # ]: 0 : switch (udp_tunnel->prot_type) {
7006 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
7007 : 0 : ret = ice_create_tunnel(hw, TNL_VXLAN, udp_tunnel->udp_port);
7008 [ # # # # ]: 0 : if (!ret && ad->psr != NULL)
7009 : 0 : ice_parser_vxlan_tunnel_set(ad->psr,
7010 : 0 : udp_tunnel->udp_port, true);
7011 : : break;
7012 : 0 : default:
7013 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7014 : : ret = -EINVAL;
7015 : 0 : break;
7016 : : }
7017 : :
7018 : : return ret;
7019 : : }
7020 : :
7021 : : /* Delete UDP tunneling port */
7022 : : static int
7023 : 0 : ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
7024 : : struct rte_eth_udp_tunnel *udp_tunnel)
7025 : : {
7026 : : int ret = 0;
7027 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7028 : : struct ice_adapter *ad =
7029 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7030 : :
7031 [ # # ]: 0 : if (udp_tunnel == NULL)
7032 : : return -EINVAL;
7033 : :
7034 [ # # ]: 0 : switch (udp_tunnel->prot_type) {
7035 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
7036 : 0 : ret = ice_destroy_tunnel(hw, udp_tunnel->udp_port, 0);
7037 [ # # # # ]: 0 : if (!ret && ad->psr != NULL)
7038 : 0 : ice_parser_vxlan_tunnel_set(ad->psr,
7039 : 0 : udp_tunnel->udp_port, false);
7040 : : break;
7041 : 0 : default:
7042 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7043 : : ret = -EINVAL;
7044 : 0 : break;
7045 : : }
7046 : :
7047 : : return ret;
7048 : : }
7049 : :
7050 : : /**
7051 : : * ice_ptp_write_init - Set PHC time to provided value
7052 : : * @hw: Hardware private structure
7053 : : *
7054 : : * Set the PHC time to CLOCK_REALTIME
7055 : : */
7056 : 0 : static int ice_ptp_write_init(struct ice_hw *hw)
7057 : : {
7058 : : uint64_t ns;
7059 : : struct timespec sys_time;
7060 : 0 : clock_gettime(CLOCK_REALTIME, &sys_time);
7061 : : ns = rte_timespec_to_ns(&sys_time);
7062 : :
7063 : 0 : return ice_ptp_init_time(hw, ns, true);
7064 : : }
7065 : :
7066 : : static int
7067 : 0 : ice_timesync_enable(struct rte_eth_dev *dev)
7068 : : {
7069 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7070 : : struct ice_adapter *ad =
7071 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7072 : : int ret;
7073 : :
7074 [ # # ]: 0 : if (ad->txpp_ena)
7075 : : return 0;
7076 : :
7077 [ # # # # ]: 0 : if (dev->data->dev_started && !(dev->data->dev_conf.rxmode.offloads &
7078 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
7079 : 0 : PMD_DRV_LOG(ERR, "Rx timestamp offload not configured");
7080 : 0 : return -1;
7081 : : }
7082 : :
7083 [ # # ]: 0 : if (hw->func_caps.ts_func_info.src_tmr_owned) {
7084 : 0 : ret = ice_ptp_init_phc(hw);
7085 [ # # ]: 0 : if (ret) {
7086 : 0 : PMD_DRV_LOG(ERR, "Failed to initialize PHC");
7087 : 0 : return -1;
7088 : : }
7089 : :
7090 : 0 : ret = ice_ptp_write_incval(hw, ICE_PTP_NOMINAL_INCVAL_E810, true);
7091 [ # # ]: 0 : if (ret) {
7092 : 0 : PMD_DRV_LOG(ERR,
7093 : : "Failed to write PHC increment time value");
7094 : 0 : return -1;
7095 : : }
7096 : : }
7097 : :
7098 [ # # ]: 0 : if (!ice_ptp_lock(hw)) {
7099 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PTP, "Failed to acquire PTP semaphore");
7100 : 0 : return ICE_ERR_NOT_READY;
7101 : : }
7102 : :
7103 : 0 : ret = ice_ptp_write_init(hw);
7104 : 0 : ice_ptp_unlock(hw);
7105 [ # # ]: 0 : if (ret)
7106 : 0 : PMD_INIT_LOG(ERR, "Failed to set current system time to PHC timer");
7107 : :
7108 : 0 : ad->ptp_ena = 1;
7109 : :
7110 : 0 : return 0;
7111 : : }
7112 : :
7113 : : static int
7114 : 0 : ice_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
7115 : : struct timespec *timestamp, uint32_t flags)
7116 : : {
7117 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7118 : : struct ice_adapter *ad =
7119 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7120 : : struct ci_rx_queue *rxq;
7121 : : uint32_t ts_high;
7122 : : uint64_t ts_ns;
7123 : :
7124 : 0 : rxq = dev->data->rx_queues[flags];
7125 : :
7126 : 0 : ts_high = rxq->time_high;
7127 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, ts_high);
7128 : 0 : *timestamp = rte_ns_to_timespec(ts_ns);
7129 : :
7130 : 0 : return 0;
7131 : : }
7132 : :
7133 : : static int
7134 : 0 : ice_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
7135 : : struct timespec *timestamp)
7136 : : {
7137 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7138 : : struct ice_adapter *ad =
7139 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7140 : 0 : uint64_t ts_ns, tstamp, tstamp_ready = 0;
7141 : : uint64_t end_time;
7142 : : const uint64_t mask = 0xFFFFFFFF;
7143 : : int ret;
7144 : :
7145 : : /* Set the end time with a delay of 10 microseconds */
7146 : 0 : end_time = rte_get_timer_cycles() + (rte_get_timer_hz() / 100000);
7147 : :
7148 : : do {
7149 : 0 : ret = ice_get_phy_tx_tstamp_ready(hw, ad->ptp_tx_block, &tstamp_ready);
7150 [ # # ]: 0 : if (ret) {
7151 : 0 : PMD_DRV_LOG(ERR, "Failed to get phy ready for timestamp");
7152 : 0 : return -1;
7153 : : }
7154 : :
7155 [ # # # # ]: 0 : if ((tstamp_ready & BIT_ULL(0)) == 0 && rte_get_timer_cycles() > end_time) {
7156 : 0 : PMD_DRV_LOG(ERR, "Timeout to get phy ready for timestamp");
7157 : 0 : return -1;
7158 : : }
7159 [ # # ]: 0 : } while ((tstamp_ready & BIT_ULL(0)) == 0);
7160 : :
7161 : 0 : ret = ice_read_phy_tstamp(hw, ad->ptp_tx_block, ad->ptp_tx_index, &tstamp);
7162 [ # # # # ]: 0 : if (ret || tstamp == 0) {
7163 : 0 : PMD_DRV_LOG(ERR, "Failed to read phy timestamp");
7164 : 0 : return -1;
7165 : : }
7166 : :
7167 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, (tstamp >> 8) & mask);
7168 : 0 : *timestamp = rte_ns_to_timespec(ts_ns);
7169 : :
7170 : 0 : return 0;
7171 : : }
7172 : :
7173 : : static int
7174 : 0 : ice_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
7175 : : {
7176 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7177 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7178 : : uint32_t lo, lo2, hi;
7179 : : uint64_t time, ns;
7180 : : int ret;
7181 : :
7182 [ # # ]: 0 : if (delta > INT32_MAX || delta < INT32_MIN) {
7183 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7184 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7185 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7186 : :
7187 [ # # ]: 0 : if (lo2 < lo) {
7188 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7189 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7190 : : }
7191 : :
7192 : 0 : time = ((uint64_t)hi << 32) | lo;
7193 : 0 : ns = time + delta;
7194 : :
7195 : 0 : wr32(hw, GLTSYN_SHTIME_L(tmr_idx), ICE_LO_DWORD(ns));
7196 : 0 : wr32(hw, GLTSYN_SHTIME_H(tmr_idx), ICE_HI_DWORD(ns));
7197 : 0 : wr32(hw, GLTSYN_SHTIME_0(tmr_idx), 0);
7198 : :
7199 : 0 : ret = ice_ptp_init_time(hw, ns, true);
7200 [ # # ]: 0 : if (ret) {
7201 : 0 : PMD_DRV_LOG(ERR, "PTP init time failed, err %d", ret);
7202 : 0 : return -1;
7203 : : }
7204 : : return 0;
7205 : : }
7206 : :
7207 : 0 : ret = ice_ptp_adj_clock(hw, delta, true);
7208 [ # # ]: 0 : if (ret) {
7209 : 0 : PMD_DRV_LOG(ERR, "PTP adj clock failed, err %d", ret);
7210 : 0 : return -1;
7211 : : }
7212 : :
7213 : : return 0;
7214 : : }
7215 : :
7216 : : static int
7217 : 0 : ice_timesync_adjust_freq(struct rte_eth_dev *dev, int64_t ppm)
7218 : : {
7219 [ # # # # ]: 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7220 : : int64_t incval, diff = 0;
7221 : : bool negative = false;
7222 : : uint64_t div, rem;
7223 : : uint64_t divisor = 1000000ULL << 16;
7224 : : int shift;
7225 : : int ret;
7226 : :
7227 : 0 : incval = ice_get_base_incval(hw, ICE_SRC_TMR_MODE_NANOSECONDS);
7228 : :
7229 [ # # ]: 0 : if (ppm < 0) {
7230 : : negative = true;
7231 : 0 : ppm = -ppm;
7232 : : }
7233 : :
7234 : : /* can incval * ppm overflow ? */
7235 [ # # ]: 0 : if (log2(incval) + log2(ppm) > 62) {
7236 : 0 : rem = ppm % divisor;
7237 : 0 : div = ppm / divisor;
7238 : 0 : diff = div * incval;
7239 : 0 : ppm = rem;
7240 : :
7241 : 0 : shift = log2(incval) + log2(ppm) - 62;
7242 [ # # ]: 0 : if (shift > 0) {
7243 : : /* drop precision */
7244 : 0 : ppm >>= shift;
7245 : 0 : divisor >>= shift;
7246 : : }
7247 : : }
7248 : :
7249 [ # # ]: 0 : if (divisor)
7250 : 0 : diff = diff + incval * ppm / divisor;
7251 : :
7252 [ # # ]: 0 : if (negative)
7253 : 0 : incval -= diff;
7254 : : else
7255 : 0 : incval += diff;
7256 : :
7257 : 0 : ret = ice_ptp_write_incval_locked(hw, incval, true);
7258 [ # # ]: 0 : if (ret) {
7259 : 0 : PMD_DRV_LOG(ERR, "PTP failed to set incval, err %d", ret);
7260 : 0 : return -1;
7261 : : }
7262 : : return 0;
7263 : : }
7264 : :
7265 : : static int
7266 : 0 : ice_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
7267 : : {
7268 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7269 : : uint64_t ns;
7270 : : int ret;
7271 : :
7272 : : ns = rte_timespec_to_ns(ts);
7273 : 0 : ret = ice_ptp_init_time(hw, ns, true);
7274 [ # # ]: 0 : if (ret) {
7275 : 0 : PMD_DRV_LOG(ERR, "PTP init time failed, err %d", ret);
7276 : 0 : return -1;
7277 : : }
7278 : :
7279 : : return 0;
7280 : : }
7281 : :
7282 : : static int
7283 : 0 : ice_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
7284 : : {
7285 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7286 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7287 : : uint32_t hi, lo, lo2;
7288 : : uint64_t time;
7289 : :
7290 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7291 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7292 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7293 : :
7294 [ # # ]: 0 : if (lo2 < lo) {
7295 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7296 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7297 : : }
7298 : :
7299 [ # # ]: 0 : time = ((uint64_t)hi << 32) | lo;
7300 : 0 : *ts = rte_ns_to_timespec(time);
7301 : :
7302 : 0 : return 0;
7303 : : }
7304 : :
7305 : : static int
7306 : 0 : ice_timesync_disable(struct rte_eth_dev *dev)
7307 : : {
7308 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7309 : : struct ice_adapter *ad =
7310 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7311 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7312 : : uint64_t val;
7313 : : uint8_t lport;
7314 : :
7315 [ # # ]: 0 : if (ad->txpp_ena)
7316 : : return 0;
7317 : :
7318 : 0 : lport = hw->port_info->lport;
7319 : :
7320 : 0 : ice_clear_phy_tstamp(hw, lport, 0);
7321 : :
7322 : 0 : val = ICE_READ_REG(hw, GLTSYN_ENA(tmr_idx));
7323 : 0 : val &= ~GLTSYN_ENA_TSYN_ENA_M;
7324 : 0 : ICE_WRITE_REG(hw, GLTSYN_ENA(tmr_idx), val);
7325 : :
7326 : 0 : ICE_WRITE_REG(hw, GLTSYN_INCVAL_L(tmr_idx), 0);
7327 : 0 : ICE_WRITE_REG(hw, GLTSYN_INCVAL_H(tmr_idx), 0);
7328 : :
7329 : 0 : ad->ptp_ena = 0;
7330 : :
7331 : 0 : return 0;
7332 : : }
7333 : :
7334 : : static int
7335 : 0 : ice_read_clock(__rte_unused struct rte_eth_dev *dev, uint64_t *clock)
7336 : : {
7337 : : struct timespec system_time;
7338 : :
7339 : : #ifdef RTE_EXEC_ENV_LINUX
7340 : 0 : clock_gettime(CLOCK_MONOTONIC_RAW, &system_time);
7341 : : #else
7342 : : clock_gettime(CLOCK_MONOTONIC, &system_time);
7343 : : #endif
7344 : 0 : *clock = system_time.tv_sec * NSEC_PER_SEC + system_time.tv_nsec;
7345 : :
7346 : 0 : return 0;
7347 : : }
7348 : :
7349 : : static const uint32_t *
7350 : 0 : ice_buffer_split_supported_hdr_ptypes_get(struct rte_eth_dev *dev __rte_unused,
7351 : : size_t *no_of_elements)
7352 : : {
7353 : : /* Buffer split protocol header capability. */
7354 : : static const uint32_t ptypes[] = {
7355 : : /* Non tunneled */
7356 : : RTE_PTYPE_L2_ETHER,
7357 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
7358 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP,
7359 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP,
7360 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP,
7361 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
7362 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP,
7363 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP,
7364 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP,
7365 : :
7366 : : /* Tunneled */
7367 : : RTE_PTYPE_TUNNEL_GRENAT,
7368 : :
7369 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
7370 : :
7371 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7372 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
7373 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7374 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
7375 : :
7376 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7377 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP,
7378 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7379 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP,
7380 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7381 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP,
7382 : :
7383 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7384 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP,
7385 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7386 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP,
7387 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7388 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP,
7389 : :
7390 : : };
7391 : :
7392 : 0 : *no_of_elements = RTE_DIM(ptypes);
7393 : 0 : return ptypes;
7394 : : }
7395 : :
7396 : : static unsigned int
7397 : 0 : ice_fec_get_capa_num(struct ice_aqc_get_phy_caps_data *pcaps,
7398 : : struct rte_eth_fec_capa *speed_fec_capa)
7399 : : {
7400 : : unsigned int num = 0;
7401 : 0 : int auto_fec = (pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC) ?
7402 : 0 : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) : 0;
7403 : 0 : int link_nofec = (pcaps->link_fec_options & ICE_AQC_PHY_FEC_DIS) ?
7404 : 0 : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) : 0;
7405 : :
7406 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_100BASE_TX) {
7407 [ # # ]: 0 : if (speed_fec_capa) {
7408 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_100M;
7409 : 0 : speed_fec_capa[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7410 : : }
7411 : : num++;
7412 : : }
7413 : :
7414 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_1000BASE_T |
7415 : : ICE_AQC_PHY_EEE_EN_1000BASE_KX)) {
7416 [ # # ]: 0 : if (speed_fec_capa) {
7417 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_1G;
7418 : 0 : speed_fec_capa[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7419 : : }
7420 : 0 : num++;
7421 : : }
7422 : :
7423 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_10GBASE_T |
7424 : : ICE_AQC_PHY_EEE_EN_10GBASE_KR)) {
7425 [ # # ]: 0 : if (speed_fec_capa) {
7426 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_10G;
7427 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7428 : :
7429 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN)
7430 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7431 : : }
7432 : 0 : num++;
7433 : : }
7434 : :
7435 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_25GBASE_KR) {
7436 [ # # ]: 0 : if (speed_fec_capa) {
7437 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_25G;
7438 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7439 : :
7440 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7441 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7442 : :
7443 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7444 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7445 : : }
7446 : 0 : num++;
7447 : : }
7448 : :
7449 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_40GBASE_KR4) {
7450 [ # # ]: 0 : if (speed_fec_capa) {
7451 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_40G;
7452 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7453 : :
7454 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN)
7455 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7456 : : }
7457 : 0 : num++;
7458 : : }
7459 : :
7460 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_50GBASE_KR2 |
7461 : : ICE_AQC_PHY_EEE_EN_50GBASE_KR_PAM4)) {
7462 [ # # ]: 0 : if (speed_fec_capa) {
7463 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_50G;
7464 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7465 : :
7466 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7467 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7468 : :
7469 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7470 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7471 : : }
7472 : 0 : num++;
7473 : : }
7474 : :
7475 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_100GBASE_KR4 |
7476 : : ICE_AQC_PHY_EEE_EN_100GBASE_KR2_PAM4)) {
7477 [ # # ]: 0 : if (speed_fec_capa) {
7478 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_100G;
7479 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7480 : :
7481 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7482 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7483 : :
7484 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7485 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7486 : : }
7487 : 0 : num++;
7488 : : }
7489 : :
7490 : 0 : return num;
7491 : : }
7492 : :
7493 : : static int
7494 : 0 : ice_fec_get_capability(struct rte_eth_dev *dev, struct rte_eth_fec_capa *speed_fec_capa,
7495 : : unsigned int num)
7496 : : {
7497 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7498 : 0 : struct ice_aqc_get_phy_caps_data pcaps = {0};
7499 : : unsigned int capa_num;
7500 : : int ret;
7501 : :
7502 : 0 : ret = ice_aq_get_phy_caps(hw->port_info, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
7503 : : &pcaps, NULL);
7504 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7505 : 0 : PMD_DRV_LOG(ERR, "Failed to get capability information: %d",
7506 : : ret);
7507 : 0 : return -ENOTSUP;
7508 : : }
7509 : :
7510 : : /* first time to get capa_num */
7511 : 0 : capa_num = ice_fec_get_capa_num(&pcaps, NULL);
7512 [ # # ]: 0 : if (!speed_fec_capa || num < capa_num)
7513 : 0 : return capa_num;
7514 : :
7515 : 0 : return ice_fec_get_capa_num(&pcaps, speed_fec_capa);
7516 : : }
7517 : :
7518 : : static int
7519 : 0 : ice_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
7520 : : {
7521 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7522 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7523 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
7524 : : bool link_up;
7525 : : u32 temp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7526 : 0 : struct ice_link_status link_status = {0};
7527 : 0 : struct ice_aqc_get_phy_caps_data pcaps = {0};
7528 : 0 : struct ice_port_info *pi = hw->port_info;
7529 : : u8 fec_config;
7530 : : int ret;
7531 : :
7532 [ # # ]: 0 : if (!pi)
7533 : : return -ENOTSUP;
7534 : :
7535 : 0 : ret = ice_get_link_info_safe(pf, enable_lse, &link_status);
7536 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7537 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
7538 : : ret);
7539 : 0 : return -ENOTSUP;
7540 : : }
7541 : :
7542 : 0 : link_up = link_status.link_info & ICE_AQ_LINK_UP;
7543 : :
7544 : 0 : ret = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
7545 : : &pcaps, NULL);
7546 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7547 : 0 : PMD_DRV_LOG(ERR, "Failed to get capability information: %d",
7548 : : ret);
7549 : 0 : return -ENOTSUP;
7550 : : }
7551 : :
7552 : : /* Get current FEC mode from port info */
7553 [ # # ]: 0 : if (link_up) {
7554 [ # # # ]: 0 : switch (link_status.fec_info) {
7555 : 0 : case ICE_AQ_LINK_25G_KR_FEC_EN:
7556 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7557 : 0 : break;
7558 : 0 : case ICE_AQ_LINK_25G_RS_528_FEC_EN:
7559 : : /* fall-through */
7560 : : case ICE_AQ_LINK_25G_RS_544_FEC_EN:
7561 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7562 : 0 : break;
7563 : 0 : default:
7564 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7565 : 0 : break;
7566 : : }
7567 : 0 : return 0;
7568 : : }
7569 : :
7570 [ # # ]: 0 : if (pcaps.caps & ICE_AQC_PHY_EN_AUTO_FEC) {
7571 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO);
7572 : 0 : return 0;
7573 : : }
7574 : :
7575 : 0 : fec_config = pcaps.link_fec_options & ICE_AQC_PHY_FEC_MASK;
7576 : :
7577 [ # # ]: 0 : if (fec_config & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7578 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7579 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7580 : : ICE_AQC_PHY_FEC_25G_KR_REQ))
7581 : : temp_fec_capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7582 : :
7583 [ # # ]: 0 : if (fec_config & (ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7584 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7585 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ))
7586 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7587 : :
7588 : 0 : *fec_capa = temp_fec_capa;
7589 : 0 : return 0;
7590 : : }
7591 : :
7592 : : static int
7593 : 0 : ice_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
7594 : : {
7595 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7596 : 0 : struct ice_port_info *pi = hw->port_info;
7597 : : struct ice_aqc_set_phy_cfg_data cfg = { 0 };
7598 : : bool fec_auto = false, fec_kr = false, fec_rs = false;
7599 : :
7600 [ # # ]: 0 : if (!pi)
7601 : : return -ENOTSUP;
7602 : :
7603 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
7604 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
7605 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
7606 : : return -EINVAL;
7607 : : /* Copy the current user PHY configuration. The current user PHY
7608 : : * configuration is initialized during probe from PHY capabilities
7609 : : * software mode, and updated on set PHY configuration.
7610 : : */
7611 [ # # ]: 0 : memcpy(&cfg, &pi->phy.curr_user_phy_cfg, sizeof(cfg));
7612 : :
7613 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
7614 : : fec_auto = true;
7615 : :
7616 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
7617 : : fec_kr = true;
7618 : :
7619 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
7620 : : fec_rs = true;
7621 : :
7622 [ # # ]: 0 : if (fec_auto) {
7623 [ # # ]: 0 : if (fec_kr || fec_rs) {
7624 [ # # ]: 0 : if (fec_rs) {
7625 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7626 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7627 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ;
7628 : : }
7629 [ # # ]: 0 : if (fec_kr) {
7630 : 0 : cfg.link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7631 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7632 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7633 : : ICE_AQC_PHY_FEC_25G_KR_REQ;
7634 : : }
7635 : : } else {
7636 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7637 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7638 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ |
7639 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7640 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7641 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7642 : : ICE_AQC_PHY_FEC_25G_KR_REQ;
7643 : : }
7644 : : } else {
7645 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
7646 [ # # ]: 0 : if (fec_rs) {
7647 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7648 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7649 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ;
7650 : : } else {
7651 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7652 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7653 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7654 : : ICE_AQC_PHY_FEC_25G_KR_REQ;
7655 : : }
7656 : : } else {
7657 : : return -EINVAL;
7658 : : }
7659 : : }
7660 : :
7661 : : /* Recovery of accidentally rewritten bit */
7662 [ # # ]: 0 : if (pi->phy.curr_user_phy_cfg.link_fec_opt &
7663 : : ICE_AQC_PHY_FEC_DIS)
7664 : 0 : cfg.link_fec_opt |= ICE_AQC_PHY_FEC_DIS;
7665 : :
7666 : : /* Proceed only if requesting different FEC mode */
7667 [ # # ]: 0 : if (pi->phy.curr_user_phy_cfg.link_fec_opt == cfg.link_fec_opt)
7668 : : return 0;
7669 : :
7670 : 0 : cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
7671 : :
7672 [ # # ]: 0 : if (ice_aq_set_phy_cfg(pi->hw, pi, &cfg, NULL))
7673 : 0 : return -EAGAIN;
7674 : :
7675 : : return 0;
7676 : : }
7677 : :
7678 : : static int
7679 : 0 : ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
7680 : : struct rte_pci_device *pci_dev)
7681 : : {
7682 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
7683 : : sizeof(struct ice_adapter),
7684 : : ice_dev_init);
7685 : : }
7686 : :
7687 : : static int
7688 : 0 : ice_pci_remove(struct rte_pci_device *pci_dev)
7689 : : {
7690 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, ice_dev_uninit);
7691 : : }
7692 : :
7693 : : static struct rte_pci_driver rte_ice_pmd = {
7694 : : .id_table = pci_id_ice_map,
7695 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
7696 : : .probe = ice_pci_probe,
7697 : : .remove = ice_pci_remove,
7698 : : };
7699 : :
7700 : : /**
7701 : : * Driver initialization routine.
7702 : : * Invoked once at EAL init time.
7703 : : * Register itself as the [Poll Mode] Driver of PCI devices.
7704 : : */
7705 : 301 : RTE_PMD_REGISTER_PCI(net_ice, rte_ice_pmd);
7706 : : RTE_PMD_REGISTER_PCI_TABLE(net_ice, pci_id_ice_map);
7707 : : RTE_PMD_REGISTER_KMOD_DEP(net_ice, "* igb_uio | uio_pci_generic | vfio-pci");
7708 : : RTE_PMD_REGISTER_PARAM_STRING(net_ice,
7709 : : ICE_HW_DEBUG_MASK_ARG "=0xXXX"
7710 : : ICE_PROTO_XTR_ARG "=[queue:]<vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset>"
7711 : : ICE_SAFE_MODE_SUPPORT_ARG "=<0|1>"
7712 : : ICE_DEFAULT_MAC_DISABLE "=<0|1>"
7713 : : ICE_DDP_FILENAME_ARG "=</path/to/file>"
7714 : : ICE_DDP_LOAD_SCHED_ARG "=<0|1>"
7715 : : ICE_TM_LEVELS_ARG "=<N>"
7716 : : ICE_SOURCE_PRUNE_ARG "=<0|1>"
7717 : : ICE_RX_LOW_LATENCY_ARG "=<0|1>"
7718 : : ICE_LINK_STATE_ON_CLOSE "=<down|up|initial>");
7719 : :
7720 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(ice_logtype_init, init, NOTICE);
7721 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(ice_logtype_driver, driver, NOTICE);
7722 : : #ifdef RTE_ETHDEV_DEBUG_RX
7723 : : RTE_LOG_REGISTER_SUFFIX(ice_logtype_rx, rx, DEBUG);
7724 : : #endif
7725 : : #ifdef RTE_ETHDEV_DEBUG_TX
7726 : : RTE_LOG_REGISTER_SUFFIX(ice_logtype_tx, tx, DEBUG);
7727 : : #endif
7728 : :
7729 : 0 : bool is_ice_supported(struct rte_eth_dev *dev)
7730 : : {
7731 : 0 : return !strcmp(dev->device->driver->name, rte_ice_pmd.driver.name);
7732 : : }
|