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 : 0 : int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)
2007 : : {
2008 : 0 : struct ice_hw *hw = &adapter->hw;
2009 : : char pkg_file[ICE_MAX_PKG_FILENAME_SIZE];
2010 : : char customized_path[ICE_MAX_PKG_FILENAME_SIZE];
2011 : : char opt_ddp_filename[ICE_MAX_PKG_FILENAME_SIZE];
2012 : : void *buf;
2013 : : size_t bufsz;
2014 : : int err;
2015 : :
2016 : : /* first read any explicitly referenced DDP file*/
2017 [ # # ]: 0 : if (adapter->devargs.ddp_filename != NULL) {
2018 : : strlcpy(pkg_file, adapter->devargs.ddp_filename, sizeof(pkg_file));
2019 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0) {
2020 : 0 : goto load_fw;
2021 : : } else {
2022 : 0 : PMD_INIT_LOG(ERR, "Cannot load DDP file: %s", pkg_file);
2023 : 0 : return -1;
2024 : : }
2025 : : }
2026 : :
2027 : : memset(opt_ddp_filename, 0, ICE_MAX_PKG_FILENAME_SIZE);
2028 : : snprintf(opt_ddp_filename, ICE_MAX_PKG_FILENAME_SIZE,
2029 : : "ice-%016" PRIx64 ".pkg", dsn);
2030 : :
2031 [ # # ]: 0 : if (ice_read_customized_path(customized_path, ICE_MAX_PKG_FILENAME_SIZE) > 0) {
2032 [ # # ]: 0 : if (use_dsn) {
2033 : : snprintf(pkg_file, RTE_DIM(pkg_file), "%s/%s",
2034 : : customized_path, opt_ddp_filename);
2035 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
2036 : 0 : goto load_fw;
2037 : : }
2038 : : snprintf(pkg_file, RTE_DIM(pkg_file), "%s/%s", customized_path, "ice.pkg");
2039 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
2040 : 0 : goto load_fw;
2041 : : }
2042 : :
2043 [ # # ]: 0 : if (!use_dsn)
2044 : 0 : goto no_dsn;
2045 : :
2046 : : strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_UPDATES,
2047 : : ICE_MAX_PKG_FILENAME_SIZE);
2048 : : strcat(pkg_file, opt_ddp_filename);
2049 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
2050 : 0 : goto load_fw;
2051 : :
2052 : : strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_DEFAULT,
2053 : : ICE_MAX_PKG_FILENAME_SIZE);
2054 : : strcat(pkg_file, opt_ddp_filename);
2055 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
2056 : 0 : goto load_fw;
2057 : :
2058 : 0 : no_dsn:
2059 : : strncpy(pkg_file, ICE_PKG_FILE_UPDATES, ICE_MAX_PKG_FILENAME_SIZE);
2060 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
2061 : 0 : goto load_fw;
2062 : :
2063 : : strncpy(pkg_file, ICE_PKG_FILE_DEFAULT, ICE_MAX_PKG_FILENAME_SIZE);
2064 [ # # ]: 0 : if (rte_firmware_read(pkg_file, &buf, &bufsz) < 0) {
2065 : 0 : PMD_INIT_LOG(ERR, "failed to search file path");
2066 : 0 : return -1;
2067 : : }
2068 : :
2069 : 0 : load_fw:
2070 : 0 : PMD_INIT_LOG(DEBUG, "DDP package name: %s", pkg_file);
2071 : :
2072 : 0 : err = ice_copy_and_init_pkg(hw, buf, bufsz, adapter->devargs.ddp_load_sched);
2073 [ # # ]: 0 : if (!ice_is_init_pkg_successful(err)) {
2074 : 0 : PMD_INIT_LOG(ERR, "Failed to load DDP package: %d", err);
2075 : 0 : free(buf);
2076 : 0 : return -1;
2077 : : }
2078 : :
2079 : : /* store the loaded pkg type info */
2080 : 0 : adapter->active_pkg_type = ice_load_pkg_type(hw);
2081 : :
2082 : 0 : free(buf);
2083 : 0 : return 0;
2084 : : }
2085 : :
2086 : : static void
2087 : 0 : ice_base_queue_get(struct ice_pf *pf)
2088 : : {
2089 : : uint32_t reg;
2090 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
2091 : :
2092 : 0 : reg = ICE_READ_REG(hw, PFLAN_RX_QALLOC);
2093 [ # # ]: 0 : if (reg & PFLAN_RX_QALLOC_VALID_M) {
2094 : 0 : pf->base_queue = reg & PFLAN_RX_QALLOC_FIRSTQ_M;
2095 : : } else {
2096 : 0 : PMD_INIT_LOG(WARNING, "Failed to get Rx base queue"
2097 : : " index");
2098 : : }
2099 : 0 : }
2100 : :
2101 : : static int
2102 : 0 : parse_bool(const char *key, const char *value, void *args)
2103 : : {
2104 : : int *i = args;
2105 : :
2106 [ # # # # ]: 0 : if (value == NULL || value[0] == '\0') {
2107 : 0 : PMD_DRV_LOG(WARNING, "key:\"%s\", requires a value, which must be 0 or 1", key);
2108 : 0 : return -1;
2109 : : }
2110 [ # # # # ]: 0 : if (value[1] != '\0' || (value[0] != '0' && value[0] != '1')) {
2111 : 0 : PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", value must be 0 or 1",
2112 : : value, key);
2113 : 0 : return -1;
2114 : : }
2115 : :
2116 : 0 : *i = (value[0] == '1');
2117 : 0 : return 0;
2118 : : }
2119 : :
2120 : : static int
2121 : 0 : parse_u64(const char *key, const char *value, void *args)
2122 : : {
2123 : : u64 *num = (u64 *)args;
2124 : : u64 tmp;
2125 : :
2126 : 0 : errno = 0;
2127 : 0 : tmp = strtoull(value, NULL, 16);
2128 [ # # ]: 0 : if (errno) {
2129 : 0 : PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64",
2130 : : key, value);
2131 : 0 : return -1;
2132 : : }
2133 : :
2134 : 0 : *num = tmp;
2135 : :
2136 : 0 : return 0;
2137 : : }
2138 : :
2139 : : static int
2140 : 0 : parse_tx_sched_levels(const char *key, const char *value, void *args)
2141 : : {
2142 : : uint8_t *num = args;
2143 : : long tmp;
2144 : : char *endptr;
2145 : :
2146 : 0 : errno = 0;
2147 : 0 : tmp = strtol(value, &endptr, 0);
2148 : : /* the value needs two stage validation, since the actual number of available
2149 : : * levels is not known at this point. Initially just validate that it is in
2150 : : * the correct range, between 3 and 8. Later validation will check that the
2151 : : * available layers on a particular port is higher than the value specified here.
2152 : : */
2153 [ # # # # ]: 0 : if (errno || *endptr != '\0' ||
2154 [ # # ]: 0 : tmp < (ICE_VSI_LAYER_OFFSET - 1) || tmp >= ICE_TM_MAX_LAYERS) {
2155 : 0 : PMD_DRV_LOG(WARNING, "%s: Invalid value \"%s\", should be in range [%d, %d]",
2156 : : key, value, ICE_VSI_LAYER_OFFSET - 1, ICE_TM_MAX_LAYERS - 1);
2157 : 0 : return -1;
2158 : : }
2159 : :
2160 : 0 : *num = tmp;
2161 : :
2162 : 0 : return 0;
2163 : : }
2164 : :
2165 : : static int
2166 : 0 : parse_link_state_on_close(const char *key, const char *value, void *args)
2167 : : {
2168 : : int *state = args, ret = 0;
2169 : :
2170 [ # # ]: 0 : if (value == NULL || state == NULL)
2171 : : return -EINVAL;
2172 : :
2173 [ # # ]: 0 : if (strcmp(value, "down") == 0) {
2174 : 0 : *state = ICE_LINK_DOWN;
2175 [ # # ]: 0 : } else if (strcmp(value, "up") == 0) {
2176 : 0 : *state = ICE_LINK_UP;
2177 [ # # ]: 0 : } else if (strcmp(value, "initial") == 0) {
2178 : 0 : *state = ICE_LINK_INITIAL;
2179 : : } else {
2180 : : ret = -EINVAL;
2181 : 0 : PMD_DRV_LOG(WARNING, "%s: Invalid value \"%s\", "
2182 : : "should be \"down\" \"up\" or \"initial\"", key, value);
2183 : : }
2184 : :
2185 : : return ret;
2186 : : }
2187 : :
2188 : : static int
2189 : : lookup_pps_type(const char *pps_name)
2190 : : {
2191 : : static struct {
2192 : : const char *name;
2193 : : enum pps_type type;
2194 : : } pps_type_map[] = {
2195 : : { "pin", PPS_PIN },
2196 : : };
2197 : :
2198 : : uint32_t i;
2199 : :
2200 : : for (i = 0; i < RTE_DIM(pps_type_map); i++) {
2201 : 0 : if (strcmp(pps_name, pps_type_map[i].name) == 0)
2202 : 0 : return pps_type_map[i].type;
2203 : : }
2204 : :
2205 : : return -1;
2206 : : }
2207 : :
2208 : : static int
2209 : 0 : parse_pin_set(const char *input, int pps_type, struct ice_devargs *devargs)
2210 : : {
2211 : : const char *str = input;
2212 : 0 : char *end = NULL;
2213 : : uint32_t idx;
2214 : :
2215 [ # # ]: 0 : while (isblank(*str))
2216 : 0 : str++;
2217 : :
2218 [ # # ]: 0 : if (!isdigit(*str))
2219 : : return -1;
2220 : :
2221 [ # # ]: 0 : if (pps_type == PPS_PIN) {
2222 : 0 : idx = strtoul(str, &end, 10);
2223 [ # # # # ]: 0 : if (end == NULL || idx >= ICE_MAX_PIN_NUM)
2224 : : return -1;
2225 [ # # ]: 0 : while (isblank(*end))
2226 : 0 : end++;
2227 [ # # ]: 0 : if (*end != ']')
2228 : : return -1;
2229 : :
2230 : 0 : devargs->pin_idx = idx;
2231 : 0 : devargs->pps_out_ena = 1;
2232 : :
2233 : 0 : return 0;
2234 : : }
2235 : :
2236 : : return -1;
2237 : : }
2238 : :
2239 : : static int
2240 : 0 : parse_pps_out_parameter(const char *pins, struct ice_devargs *devargs)
2241 : : {
2242 : : const char *pin_start;
2243 : : uint32_t idx;
2244 : : int pps_type;
2245 : : char pps_name[32];
2246 : :
2247 [ # # ]: 0 : while (isblank(*pins))
2248 : 0 : pins++;
2249 : :
2250 : 0 : pins++;
2251 [ # # ]: 0 : while (isblank(*pins))
2252 : 0 : pins++;
2253 [ # # ]: 0 : if (*pins == '\0')
2254 : : return -1;
2255 : :
2256 : 0 : for (idx = 0; ; idx++) {
2257 [ # # # # ]: 0 : if (isblank(pins[idx]) ||
2258 [ # # ]: 0 : pins[idx] == ':' ||
2259 : : pins[idx] == '\0')
2260 : : break;
2261 : :
2262 : 0 : pps_name[idx] = pins[idx];
2263 : : }
2264 [ # # ]: 0 : pps_name[idx] = '\0';
2265 : : pps_type = lookup_pps_type(pps_name);
2266 [ # # ]: 0 : if (pps_type < 0)
2267 : : return -1;
2268 : :
2269 : : pins += idx;
2270 : :
2271 : 0 : pins += strcspn(pins, ":");
2272 [ # # ]: 0 : if (*pins++ != ':')
2273 : : return -1;
2274 [ # # ]: 0 : while (isblank(*pins))
2275 : 0 : pins++;
2276 : :
2277 : : pin_start = pins;
2278 : :
2279 : : while (isblank(*pins))
2280 : : pins++;
2281 : :
2282 [ # # ]: 0 : if (parse_pin_set(pin_start, pps_type, devargs) < 0)
2283 : 0 : return -1;
2284 : :
2285 : : return 0;
2286 : : }
2287 : :
2288 : : static int
2289 : 0 : handle_pps_out_arg(__rte_unused const char *key, const char *value,
2290 : : void *extra_args)
2291 : : {
2292 : : struct ice_devargs *devargs = extra_args;
2293 : :
2294 [ # # ]: 0 : if (value == NULL || extra_args == NULL)
2295 : : return -EINVAL;
2296 : :
2297 [ # # ]: 0 : if (parse_pps_out_parameter(value, devargs) < 0) {
2298 : 0 : PMD_DRV_LOG(ERR,
2299 : : "The GPIO pin parameter is wrong : '%s'",
2300 : : value);
2301 : 0 : return -1;
2302 : : }
2303 : :
2304 : : return 0;
2305 : : }
2306 : :
2307 : : static int
2308 : 0 : ice_parse_mbuf_check(__rte_unused const char *key, const char *value, void *args)
2309 : : {
2310 : : char *cur;
2311 : : char *tmp;
2312 : : int str_len;
2313 : : int valid_len;
2314 : :
2315 : : int ret = 0;
2316 : : uint64_t *mc_flags = args;
2317 : 0 : char *str2 = strdup(value);
2318 [ # # ]: 0 : if (str2 == NULL)
2319 : : return -1;
2320 : :
2321 : 0 : str_len = strlen(str2);
2322 [ # # ]: 0 : if (str_len == 0) {
2323 : : ret = -1;
2324 : 0 : goto err_end;
2325 : : }
2326 : :
2327 : : /* Try stripping the outer square brackets of the parameter string. */
2328 : : str_len = strlen(str2);
2329 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
2330 [ # # ]: 0 : if (str_len < 3) {
2331 : : ret = -1;
2332 : 0 : goto err_end;
2333 : : }
2334 : 0 : valid_len = str_len - 2;
2335 : 0 : memmove(str2, str2 + 1, valid_len);
2336 : 0 : memset(str2 + valid_len, '\0', 2);
2337 : : }
2338 : :
2339 : 0 : cur = strtok_r(str2, ",", &tmp);
2340 [ # # ]: 0 : while (cur != NULL) {
2341 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
2342 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_MBUF;
2343 [ # # ]: 0 : else if (!strcmp(cur, "size"))
2344 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_SIZE;
2345 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
2346 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_SEGMENT;
2347 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
2348 : 0 : *mc_flags |= ICE_MBUF_CHECK_F_TX_OFFLOAD;
2349 : : else
2350 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
2351 : 0 : cur = strtok_r(NULL, ",", &tmp);
2352 : : }
2353 : :
2354 : 0 : err_end:
2355 : 0 : free(str2);
2356 : 0 : return ret;
2357 : : }
2358 : :
2359 : 0 : static int ice_parse_devargs(struct rte_eth_dev *dev)
2360 : : {
2361 : 0 : struct ice_adapter *ad =
2362 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2363 : 0 : struct rte_devargs *devargs = dev->device->devargs;
2364 : : struct rte_kvargs *kvlist;
2365 : : int ret;
2366 : :
2367 [ # # ]: 0 : if (devargs == NULL)
2368 : : return 0;
2369 : :
2370 : 0 : kvlist = rte_kvargs_parse(devargs->args, ice_valid_args);
2371 [ # # ]: 0 : if (kvlist == NULL) {
2372 : 0 : PMD_INIT_LOG(ERR, "Invalid kvargs key");
2373 : 0 : return -EINVAL;
2374 : : }
2375 : :
2376 : 0 : ad->devargs.proto_xtr_dflt = PROTO_XTR_NONE;
2377 : 0 : memset(ad->devargs.proto_xtr, PROTO_XTR_NONE,
2378 : : sizeof(ad->devargs.proto_xtr));
2379 : :
2380 : 0 : ret = rte_kvargs_process(kvlist, ICE_PROTO_XTR_ARG,
2381 : 0 : &handle_proto_xtr_arg, &ad->devargs);
2382 [ # # ]: 0 : if (ret)
2383 : 0 : goto bail;
2384 : :
2385 : 0 : ret = rte_kvargs_process(kvlist, ICE_FIELD_OFFS_ARG,
2386 : 0 : &handle_field_offs_arg, &ad->devargs.xtr_field_offs);
2387 [ # # ]: 0 : if (ret)
2388 : 0 : goto bail;
2389 : :
2390 : 0 : ret = rte_kvargs_process(kvlist, ICE_FIELD_NAME_ARG,
2391 : 0 : &handle_field_name_arg, &ad->devargs.xtr_field_name);
2392 [ # # ]: 0 : if (ret)
2393 : 0 : goto bail;
2394 : :
2395 : 0 : ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG,
2396 : 0 : &parse_bool, &ad->devargs.safe_mode_support);
2397 [ # # ]: 0 : if (ret)
2398 : 0 : goto bail;
2399 : :
2400 : 0 : ret = rte_kvargs_process(kvlist, ICE_DEFAULT_MAC_DISABLE,
2401 : 0 : &parse_bool, &ad->devargs.default_mac_disable);
2402 [ # # ]: 0 : if (ret)
2403 : 0 : goto bail;
2404 : :
2405 : 0 : ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG,
2406 : 0 : &parse_u64, &ad->hw.debug_mask);
2407 [ # # ]: 0 : if (ret)
2408 : 0 : goto bail;
2409 : :
2410 : 0 : ret = rte_kvargs_process(kvlist, ICE_ONE_PPS_OUT_ARG,
2411 : : &handle_pps_out_arg, &ad->devargs);
2412 [ # # ]: 0 : if (ret)
2413 : 0 : goto bail;
2414 : :
2415 : 0 : ret = rte_kvargs_process(kvlist, ICE_MBUF_CHECK_ARG,
2416 : 0 : &ice_parse_mbuf_check, &ad->devargs.mbuf_check);
2417 [ # # ]: 0 : if (ret)
2418 : 0 : goto bail;
2419 : :
2420 : 0 : ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG,
2421 : 0 : &parse_bool, &ad->devargs.rx_low_latency);
2422 [ # # ]: 0 : if (ret)
2423 : 0 : goto bail;
2424 : :
2425 : 0 : ret = rte_kvargs_process(kvlist, ICE_DDP_FILENAME_ARG,
2426 : 0 : &handle_ddp_filename_arg, &ad->devargs.ddp_filename);
2427 [ # # ]: 0 : if (ret)
2428 : 0 : goto bail;
2429 : :
2430 : 0 : ret = rte_kvargs_process(kvlist, ICE_DDP_LOAD_SCHED_ARG,
2431 : 0 : &parse_bool, &ad->devargs.ddp_load_sched);
2432 [ # # ]: 0 : if (ret)
2433 : 0 : goto bail;
2434 : :
2435 : 0 : ret = rte_kvargs_process(kvlist, ICE_TM_LEVELS_ARG,
2436 : 0 : &parse_tx_sched_levels, &ad->devargs.tm_exposed_levels);
2437 [ # # ]: 0 : if (ret)
2438 : 0 : goto bail;
2439 : :
2440 : 0 : ret = rte_kvargs_process(kvlist, ICE_SOURCE_PRUNE_ARG,
2441 : 0 : &parse_bool, &ad->devargs.source_prune);
2442 [ # # ]: 0 : if (ret)
2443 : 0 : goto bail;
2444 : :
2445 : 0 : ret = rte_kvargs_process(kvlist, ICE_LINK_STATE_ON_CLOSE,
2446 : 0 : &parse_link_state_on_close, &ad->devargs.link_state_on_close);
2447 : :
2448 : 0 : bail:
2449 : 0 : rte_kvargs_free(kvlist);
2450 : 0 : return ret;
2451 : : }
2452 : :
2453 : : static int
2454 : 0 : ice_get_hw_res(struct ice_hw *hw, uint16_t res_type,
2455 : : uint16_t num, uint16_t desc_id,
2456 : : uint16_t *prof_buf, uint16_t *num_prof)
2457 : : {
2458 : : struct ice_aqc_res_elem *resp_buf;
2459 : : int ret;
2460 : : uint16_t buf_len;
2461 : : bool res_shared = 1;
2462 : : struct ice_aq_desc aq_desc;
2463 : : struct ice_sq_cd *cd = NULL;
2464 : : struct ice_aqc_get_allocd_res_desc *cmd =
2465 : : &aq_desc.params.get_res_desc;
2466 : :
2467 : 0 : buf_len = sizeof(*resp_buf) * num;
2468 : 0 : resp_buf = ice_malloc(hw, buf_len);
2469 [ # # ]: 0 : if (!resp_buf)
2470 : : return -ENOMEM;
2471 : :
2472 : 0 : ice_fill_dflt_direct_cmd_desc(&aq_desc,
2473 : : ice_aqc_opc_get_allocd_res_desc);
2474 : :
2475 : 0 : cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2476 : : ICE_AQC_RES_TYPE_M) | (res_shared ?
2477 : : ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2478 : 0 : cmd->ops.cmd.first_desc = CPU_TO_LE16(desc_id);
2479 : :
2480 : 0 : ret = ice_aq_send_cmd(hw, &aq_desc, resp_buf, buf_len, cd);
2481 [ # # ]: 0 : if (!ret)
2482 : 0 : *num_prof = LE16_TO_CPU(cmd->ops.resp.num_desc);
2483 : : else
2484 : 0 : goto exit;
2485 : :
2486 [ # # ]: 0 : ice_memcpy(prof_buf, resp_buf, sizeof(*resp_buf) *
2487 : : (*num_prof), ICE_NONDMA_TO_NONDMA);
2488 : :
2489 : 0 : exit:
2490 : 0 : rte_free(resp_buf);
2491 : 0 : return ret;
2492 : : }
2493 : : static int
2494 : 0 : ice_cleanup_resource(struct ice_hw *hw, uint16_t res_type)
2495 : : {
2496 : : int ret;
2497 : : uint16_t prof_id;
2498 : : uint16_t prof_buf[ICE_MAX_RES_DESC_NUM];
2499 : : uint16_t first_desc = 1;
2500 : 0 : uint16_t num_prof = 0;
2501 : :
2502 : 0 : ret = ice_get_hw_res(hw, res_type, ICE_MAX_RES_DESC_NUM,
2503 : : first_desc, prof_buf, &num_prof);
2504 [ # # ]: 0 : if (ret) {
2505 : 0 : PMD_INIT_LOG(ERR, "Failed to get fxp resource");
2506 : 0 : return ret;
2507 : : }
2508 : :
2509 [ # # ]: 0 : for (prof_id = 0; prof_id < num_prof; prof_id++) {
2510 : 0 : ret = ice_free_hw_res(hw, res_type, 1, &prof_buf[prof_id]);
2511 [ # # ]: 0 : if (ret) {
2512 : 0 : PMD_INIT_LOG(ERR, "Failed to free fxp resource");
2513 : 0 : return ret;
2514 : : }
2515 : : }
2516 : : return 0;
2517 : : }
2518 : :
2519 : : static int
2520 : 0 : ice_reset_fxp_resource(struct ice_hw *hw)
2521 : : {
2522 : : int ret;
2523 : :
2524 : 0 : ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID);
2525 [ # # ]: 0 : if (ret) {
2526 : 0 : PMD_INIT_LOG(ERR, "Failed to clearup fdir resource");
2527 : 0 : return ret;
2528 : : }
2529 : :
2530 : 0 : ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID);
2531 [ # # ]: 0 : if (ret) {
2532 : 0 : PMD_INIT_LOG(ERR, "Failed to clearup rss resource");
2533 : 0 : return ret;
2534 : : }
2535 : :
2536 : : return 0;
2537 : : }
2538 : :
2539 : : static void
2540 : : ice_rss_ctx_init(struct ice_pf *pf)
2541 : : {
2542 : 0 : memset(&pf->hash_ctx, 0, sizeof(pf->hash_ctx));
2543 : : }
2544 : :
2545 : : static uint64_t
2546 : : ice_get_supported_rxdid(struct ice_hw *hw)
2547 : : {
2548 : : uint64_t supported_rxdid = 0; /* bitmap for supported RXDID */
2549 : : uint32_t regval;
2550 : : int i;
2551 : :
2552 : : supported_rxdid |= RTE_BIT64(ICE_RXDID_LEGACY_1);
2553 : :
2554 [ # # ]: 0 : for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2555 : 0 : regval = ICE_READ_REG(hw, GLFLXP_RXDID_FLAGS(i, 0));
2556 : 0 : if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2557 [ # # ]: 0 : & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2558 : 0 : supported_rxdid |= RTE_BIT64(i);
2559 : : }
2560 : : return supported_rxdid;
2561 : : }
2562 : :
2563 : 0 : static void ice_ptp_init_info(struct rte_eth_dev *dev)
2564 : : {
2565 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2566 : : struct ice_adapter *ad =
2567 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2568 : :
2569 [ # # # # ]: 0 : switch (hw->phy_model) {
2570 : 0 : case ICE_PHY_ETH56G:
2571 : 0 : ad->ptp_tx_block = hw->pf_id;
2572 : 0 : ad->ptp_tx_index = 0;
2573 : 0 : break;
2574 : 0 : case ICE_PHY_E810:
2575 : : case ICE_PHY_E830:
2576 : 0 : ad->ptp_tx_block = hw->port_info->lport;
2577 : 0 : ad->ptp_tx_index = 0;
2578 : 0 : break;
2579 : 0 : case ICE_PHY_E822:
2580 : 0 : ad->ptp_tx_block = hw->pf_id / ICE_PORTS_PER_QUAD;
2581 : 0 : ad->ptp_tx_index = (hw->pf_id % ICE_PORTS_PER_QUAD) *
2582 : : ICE_PORTS_PER_PHY_E822 * ICE_QUADS_PER_PHY_E822;
2583 : 0 : break;
2584 : 0 : default:
2585 : 0 : PMD_DRV_LOG(WARNING, "Unsupported PHY model");
2586 : 0 : break;
2587 : : }
2588 : 0 : }
2589 : :
2590 : : static int
2591 : 0 : ice_dev_init(struct rte_eth_dev *dev)
2592 : : {
2593 : : struct rte_pci_device *pci_dev;
2594 : : struct rte_intr_handle *intr_handle;
2595 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2596 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2597 : : struct ice_adapter *ad =
2598 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2599 : : struct ice_vsi *vsi;
2600 : : int ret;
2601 : : #ifndef RTE_EXEC_ENV_WINDOWS
2602 : : off_t pos;
2603 : : uint32_t dsn_low, dsn_high;
2604 : : uint64_t dsn;
2605 : : bool use_dsn;
2606 : : #endif
2607 : :
2608 : 0 : dev->dev_ops = &ice_eth_dev_ops;
2609 : 0 : dev->rx_queue_count = ice_rx_queue_count;
2610 : 0 : dev->rx_descriptor_status = ice_rx_descriptor_status;
2611 : 0 : dev->tx_descriptor_status = ice_tx_descriptor_status;
2612 : 0 : dev->rx_pkt_burst = ice_recv_pkts;
2613 : 0 : dev->tx_pkt_burst = ice_xmit_pkts;
2614 : 0 : dev->tx_pkt_prepare = ice_prep_pkts;
2615 : :
2616 : : /* for secondary processes, we don't initialise any further as primary
2617 : : * has already done this work.
2618 : : */
2619 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2620 : 0 : ice_set_rx_function(dev);
2621 : 0 : ice_set_tx_function(dev);
2622 : 0 : return 0;
2623 : : }
2624 : :
2625 : 0 : ice_set_default_ptype_table(dev);
2626 : 0 : pci_dev = RTE_DEV_TO_PCI(dev->device);
2627 : 0 : intr_handle = pci_dev->intr_handle;
2628 : :
2629 : 0 : pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2630 : 0 : pf->dev_data = dev->data;
2631 : 0 : hw->back = pf->adapter;
2632 : 0 : hw->hw_addr = (uint8_t *)pci_dev->mem_resource[0].addr;
2633 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
2634 : 0 : hw->device_id = pci_dev->id.device_id;
2635 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2636 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2637 : 0 : hw->bus.device = pci_dev->addr.devid;
2638 : 0 : hw->bus.func = pci_dev->addr.function;
2639 : :
2640 : 0 : ret = ice_parse_devargs(dev);
2641 [ # # ]: 0 : if (ret) {
2642 : 0 : PMD_INIT_LOG(ERR, "Failed to parse devargs");
2643 : 0 : return -EINVAL;
2644 : : }
2645 : :
2646 : : ice_init_controlq_parameter(hw);
2647 : :
2648 : 0 : ret = ice_init_hw(hw);
2649 [ # # ]: 0 : if (ret) {
2650 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize HW");
2651 : 0 : return -EINVAL;
2652 : : }
2653 : :
2654 : : #ifndef RTE_EXEC_ENV_WINDOWS
2655 : : use_dsn = false;
2656 : : dsn = 0;
2657 : 0 : pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN);
2658 [ # # ]: 0 : if (pos) {
2659 [ # # # # ]: 0 : if (rte_pci_read_config(pci_dev, &dsn_low, 4, pos + 4) < 0 ||
2660 : 0 : rte_pci_read_config(pci_dev, &dsn_high, 4, pos + 8) < 0) {
2661 : 0 : PMD_INIT_LOG(ERR, "Failed to read pci config space");
2662 : : } else {
2663 : : use_dsn = true;
2664 : 0 : dsn = (uint64_t)dsn_high << 32 | dsn_low;
2665 : : }
2666 : : } else {
2667 : 0 : PMD_INIT_LOG(ERR, "Failed to read device serial number");
2668 : : }
2669 : :
2670 : 0 : ret = ice_load_pkg(pf->adapter, use_dsn, dsn);
2671 [ # # ]: 0 : if (ret == 0) {
2672 : 0 : ret = ice_init_hw_tbls(hw);
2673 [ # # ]: 0 : if (ret) {
2674 : 0 : PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d", ret);
2675 : 0 : rte_free(hw->pkg_copy);
2676 : : }
2677 : : }
2678 : :
2679 [ # # ]: 0 : if (ret) {
2680 [ # # ]: 0 : if (ad->devargs.safe_mode_support == 0) {
2681 : 0 : PMD_INIT_LOG(ERR, "Failed to load the DDP package,"
2682 : : "Use safe-mode-support=1 to enter Safe Mode");
2683 : 0 : goto err_init_fw;
2684 : : }
2685 : :
2686 : 0 : PMD_INIT_LOG(WARNING, "Failed to load the DDP package,"
2687 : : "Entering Safe Mode");
2688 : 0 : ad->is_safe_mode = 1;
2689 : : }
2690 : : #endif
2691 : :
2692 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
2693 : : hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2694 : : hw->api_maj_ver, hw->api_min_ver);
2695 : :
2696 : 0 : ice_pf_sw_init(dev);
2697 : 0 : ret = ice_init_mac_address(dev);
2698 [ # # ]: 0 : if (ret) {
2699 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize mac address");
2700 : 0 : goto err_init_mac;
2701 : : }
2702 : :
2703 : 0 : ret = ice_res_pool_init(&pf->msix_pool, 1,
2704 : 0 : hw->func_caps.common_cap.num_msix_vectors - 1);
2705 [ # # ]: 0 : if (ret) {
2706 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
2707 : 0 : goto err_msix_pool_init;
2708 : : }
2709 : :
2710 : 0 : ret = ice_pf_setup(pf);
2711 [ # # ]: 0 : if (ret) {
2712 : 0 : PMD_INIT_LOG(ERR, "Failed to setup PF");
2713 : 0 : goto err_pf_setup;
2714 : : }
2715 : :
2716 : 0 : ret = ice_send_driver_ver(hw);
2717 [ # # ]: 0 : if (ret) {
2718 : 0 : PMD_INIT_LOG(ERR, "Failed to send driver version");
2719 : 0 : goto err_pf_setup;
2720 : : }
2721 : :
2722 : 0 : vsi = pf->main_vsi;
2723 : :
2724 : 0 : ret = ice_aq_stop_lldp(hw, true, false, NULL);
2725 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2726 : 0 : PMD_INIT_LOG(DEBUG, "lldp has already stopped");
2727 : 0 : ret = ice_init_dcb(hw, true);
2728 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2729 : 0 : PMD_INIT_LOG(DEBUG, "Failed to init DCB");
2730 : : /* Forward LLDP packets to default VSI */
2731 : 0 : ret = ice_lldp_fltr_add_remove(hw, vsi->vsi_id, true);
2732 [ # # ]: 0 : if (ret != ICE_SUCCESS)
2733 : 0 : PMD_INIT_LOG(DEBUG, "Failed to cfg lldp");
2734 : : /* register callback func to eal lib */
2735 : 0 : rte_intr_callback_register(intr_handle,
2736 : : ice_interrupt_handler, dev);
2737 : :
2738 : 0 : ice_pf_enable_irq0(hw);
2739 : :
2740 : : /* enable uio intr after callback register */
2741 : 0 : rte_intr_enable(intr_handle);
2742 : :
2743 : : /* get base queue pairs index in the device */
2744 : 0 : ice_base_queue_get(pf);
2745 : :
2746 : : /* Initialize RSS context for gtpu_eh */
2747 : : ice_rss_ctx_init(pf);
2748 : :
2749 : : /* Initialize TM configuration */
2750 : 0 : ice_tm_conf_init(dev);
2751 : :
2752 : : /* Initialize PHY model */
2753 : 0 : ice_ptp_init_phy_model(hw);
2754 : :
2755 : : /* Initialize PTP info */
2756 : 0 : ice_ptp_init_info(dev);
2757 : :
2758 [ # # ]: 0 : if (hw->phy_model == ICE_PHY_E822) {
2759 : 0 : ret = ice_start_phy_timer_e822(hw, hw->pf_id, true);
2760 [ # # ]: 0 : if (ret)
2761 : 0 : PMD_INIT_LOG(ERR, "Failed to start phy timer");
2762 : : }
2763 : :
2764 [ # # ]: 0 : if (!ad->is_safe_mode) {
2765 : 0 : ret = ice_flow_init(ad);
2766 [ # # ]: 0 : if (ret) {
2767 : 0 : PMD_INIT_LOG(ERR, "Failed to initialize flow");
2768 : 0 : goto err_flow_init;
2769 : : }
2770 : : }
2771 : :
2772 : 0 : ret = ice_reset_fxp_resource(hw);
2773 [ # # ]: 0 : if (ret) {
2774 : 0 : PMD_INIT_LOG(ERR, "Failed to reset fxp resource");
2775 : 0 : goto err_flow_init;
2776 : : }
2777 : :
2778 : 0 : pf->supported_rxdid = ice_get_supported_rxdid(hw);
2779 : :
2780 : : /* reset all stats of the device, including pf and main vsi */
2781 : 0 : ice_stats_reset(dev);
2782 : :
2783 : 0 : return 0;
2784 : :
2785 : 0 : err_flow_init:
2786 : 0 : ice_flow_uninit(ad);
2787 : 0 : rte_intr_disable(intr_handle);
2788 : : ice_pf_disable_irq0(hw);
2789 : 0 : rte_intr_callback_unregister(intr_handle,
2790 : : ice_interrupt_handler, dev);
2791 : 0 : err_pf_setup:
2792 : 0 : ice_res_pool_destroy(&pf->msix_pool);
2793 : 0 : err_msix_pool_init:
2794 : 0 : rte_free(dev->data->mac_addrs);
2795 : 0 : dev->data->mac_addrs = NULL;
2796 : 0 : err_init_mac:
2797 : 0 : rte_free(pf->proto_xtr);
2798 : : #ifndef RTE_EXEC_ENV_WINDOWS
2799 : 0 : err_init_fw:
2800 : : #endif
2801 : 0 : ice_deinit_hw(hw);
2802 : :
2803 : 0 : return ret;
2804 : : }
2805 : :
2806 : : int
2807 : 0 : ice_release_vsi(struct ice_vsi *vsi)
2808 : : {
2809 : : struct ice_hw *hw;
2810 : : struct ice_vsi_ctx vsi_ctx;
2811 : : int ret, error = 0;
2812 : :
2813 [ # # ]: 0 : if (!vsi)
2814 : : return error;
2815 : :
2816 : 0 : hw = ICE_VSI_TO_HW(vsi);
2817 : :
2818 : 0 : ice_remove_all_mac_vlan_filters(vsi);
2819 : :
2820 : : memset(&vsi_ctx, 0, sizeof(vsi_ctx));
2821 : :
2822 : 0 : vsi_ctx.vsi_num = vsi->vsi_id;
2823 : 0 : vsi_ctx.info = vsi->info;
2824 : 0 : ret = ice_free_vsi(hw, vsi->idx, &vsi_ctx, false, NULL);
2825 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
2826 : 0 : PMD_INIT_LOG(ERR, "Failed to free vsi by aq, %u", vsi->vsi_id);
2827 : : error = -1;
2828 : : }
2829 : :
2830 : 0 : rte_free(vsi->rss_lut);
2831 : 0 : rte_free(vsi->rss_key);
2832 : 0 : rte_free(vsi);
2833 : 0 : return error;
2834 : : }
2835 : :
2836 : : void
2837 : 0 : ice_vsi_disable_queues_intr(struct ice_vsi *vsi)
2838 : : {
2839 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
2840 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2841 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2842 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2843 : : uint16_t msix_intr, i;
2844 : :
2845 : : /* disable interrupt and also clear all the exist config */
2846 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2847 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
2848 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
2849 : : rte_wmb();
2850 : : }
2851 : :
2852 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
2853 : : /* vfio-pci */
2854 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2855 : 0 : msix_intr = vsi->msix_intr + i;
2856 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
2857 : : GLINT_DYN_CTL_WB_ON_ITR_M);
2858 : : }
2859 : : else
2860 : : /* igb_uio */
2861 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
2862 : 0 : }
2863 : :
2864 : : static int
2865 : 0 : ice_dev_stop(struct rte_eth_dev *dev)
2866 : : {
2867 : 0 : struct rte_eth_dev_data *data = dev->data;
2868 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2869 : : struct ice_adapter *ad =
2870 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2871 : 0 : struct ice_vsi *main_vsi = pf->main_vsi;
2872 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2873 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2874 : : uint16_t i;
2875 : :
2876 : : /* avoid stopping again */
2877 [ # # ]: 0 : if (pf->adapter_stopped)
2878 : : return 0;
2879 : :
2880 : : /* stop and clear all Rx queues */
2881 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++)
2882 : 0 : ice_rx_queue_stop(dev, i);
2883 : :
2884 : : /* stop and clear all Tx queues */
2885 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++)
2886 : 0 : ice_tx_queue_stop(dev, i);
2887 : :
2888 : : /* disable all queue interrupts */
2889 : 0 : ice_vsi_disable_queues_intr(main_vsi);
2890 : :
2891 [ # # ]: 0 : if (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
2892 : 0 : ad->txpp_ena = 0;
2893 : 0 : ice_timesync_disable(dev);
2894 : : }
2895 : :
2896 [ # # # # ]: 0 : if (pf->adapter->devargs.link_state_on_close == ICE_LINK_UP ||
2897 : 0 : (pf->adapter->devargs.link_state_on_close == ICE_LINK_INITIAL &&
2898 [ # # ]: 0 : pf->init_link_up))
2899 : : ice_dev_set_link_up(dev);
2900 : : else
2901 : : ice_dev_set_link_down(dev);
2902 : :
2903 : : /* Clean datapath event and queue/vec mapping */
2904 : 0 : rte_intr_efd_disable(intr_handle);
2905 : 0 : rte_intr_vec_list_free(intr_handle);
2906 : :
2907 : 0 : pf->adapter_stopped = true;
2908 : 0 : dev->data->dev_started = 0;
2909 : :
2910 : 0 : return 0;
2911 : : }
2912 : :
2913 : : static void
2914 : 0 : ice_deinit_dcb(struct rte_eth_dev *dev)
2915 : : {
2916 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2917 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2918 : 0 : struct ice_port_info *port_info = hw->port_info;
2919 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
2920 : 0 : struct ice_dcbx_cfg *local_dcb_conf = &qos_cfg->local_dcbx_cfg;
2921 : : int i, ret, cgd_idx;
2922 : : uint16_t max_frame_size;
2923 : 0 : u8 max_tcs = local_dcb_conf->etscfg.maxtcs;
2924 : : u8 tc;
2925 : :
2926 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG ||
2927 [ # # ]: 0 : dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_DCB))
2928 : : return;
2929 : :
2930 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
2931 : 0 : tc = ice_get_tc_by_priority(hw, i);
2932 : 0 : cgd_idx = ice_get_cgd_idx(hw, tc);
2933 [ # # ]: 0 : wr32(hw, GLRPB_TCHW(cgd_idx), CPU_TO_LE32(ICE_MAC_TC_MAX_WATERMARK));
2934 [ # # ]: 0 : wr32(hw, GLRPB_TCLW(cgd_idx), CPU_TO_LE32(ICE_MAC_TC_MAX_WATERMARK));
2935 : : }
2936 : :
2937 [ # # ]: 0 : max_frame_size = pf->dev_data->mtu ?
2938 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD : ICE_FRAME_SIZE_MAX;
2939 : : /* for each TC resets corresponding PFC quanta/threshold to its default values */
2940 : 0 : ret = ice_aq_set_mac_pfc_cfg(hw, max_frame_size, (1 << max_tcs) - 1,
2941 : : UINT16_MAX, INT16_MAX + 1, false, NULL);
2942 [ # # ]: 0 : if (ret)
2943 : 0 : PMD_DRV_LOG(ERR, "Failed to set mac config on DCB deinit");
2944 : :
2945 : : memset(local_dcb_conf, 0, sizeof(*local_dcb_conf));
2946 : 0 : local_dcb_conf->etscfg.maxtcs = max_tcs;
2947 : 0 : local_dcb_conf->etscfg.tcbwtable[0] = 100;
2948 : 0 : local_dcb_conf->etsrec.tcbwtable[0] = 100;
2949 : 0 : ret = ice_set_dcb_cfg(port_info);
2950 [ # # ]: 0 : if (ret)
2951 : 0 : PMD_DRV_LOG(ERR, "Failed to disable DCB");
2952 : : }
2953 : :
2954 : : static int
2955 : 0 : ice_dev_close(struct rte_eth_dev *dev)
2956 : : {
2957 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2958 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2959 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2960 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2961 : : struct ice_adapter *ad =
2962 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2963 : : int ret;
2964 : : uint32_t val;
2965 : 0 : uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
2966 : 0 : uint32_t pin_idx = ad->devargs.pin_idx;
2967 : :
2968 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2969 : : return 0;
2970 : :
2971 : : /* Since stop will make link down, then the link event will be
2972 : : * triggered, disable the irq firstly.
2973 : : */
2974 : : ice_pf_disable_irq0(hw);
2975 : :
2976 : : /* Unregister callback func from eal lib, use sync version to
2977 : : * make sure all active interrupt callbacks is done, then it's
2978 : : * safe to free all resources.
2979 : : */
2980 : 0 : rte_intr_callback_unregister_sync(intr_handle,
2981 : : ice_interrupt_handler, dev);
2982 : :
2983 : 0 : ret = ice_dev_stop(dev);
2984 : :
2985 [ # # ]: 0 : if (!ad->is_safe_mode)
2986 : 0 : ice_flow_uninit(ad);
2987 : :
2988 : 0 : ice_deinit_dcb(dev);
2989 : : /* release all queue resource */
2990 : 0 : ice_free_queues(dev);
2991 : :
2992 : 0 : ice_res_pool_destroy(&pf->msix_pool);
2993 : 0 : ice_release_vsi(pf->main_vsi);
2994 : 0 : ice_sched_cleanup_all(hw);
2995 : 0 : ice_free_hw_tbls(hw);
2996 : 0 : rte_free(hw->port_info);
2997 : 0 : hw->port_info = NULL;
2998 : 0 : free((void *)(uintptr_t)ad->devargs.ddp_filename);
2999 : 0 : ad->devargs.ddp_filename = NULL;
3000 : 0 : ice_shutdown_all_ctrlq(hw, true);
3001 : 0 : rte_free(pf->proto_xtr);
3002 : 0 : pf->proto_xtr = NULL;
3003 : :
3004 : : /* Uninit TM configuration */
3005 : 0 : ice_tm_conf_uninit(dev);
3006 : :
3007 [ # # ]: 0 : if (ad->devargs.pps_out_ena) {
3008 : 0 : ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(pin_idx, timer), 0);
3009 : 0 : ICE_WRITE_REG(hw, GLTSYN_CLKO(pin_idx, timer), 0);
3010 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_L(pin_idx, timer), 0);
3011 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_H(pin_idx, timer), 0);
3012 : :
3013 : : val = GLGEN_GPIO_CTL_PIN_DIR_M;
3014 : 0 : ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(pin_idx), val);
3015 : : }
3016 : :
3017 : : /* disable uio intr before callback unregister */
3018 : 0 : rte_intr_disable(intr_handle);
3019 : :
3020 : 0 : return ret;
3021 : : }
3022 : :
3023 : : static int
3024 : 0 : ice_dev_uninit(struct rte_eth_dev *dev)
3025 : : {
3026 : 0 : ice_dev_close(dev);
3027 : :
3028 : 0 : return 0;
3029 : : }
3030 : :
3031 : : static bool
3032 : : is_hash_cfg_valid(struct ice_rss_hash_cfg *cfg)
3033 : : {
3034 [ # # # # ]: 0 : return (cfg->hash_flds != 0 && cfg->addl_hdrs != 0) ? true : false;
3035 : : }
3036 : :
3037 : : static void
3038 : : hash_cfg_reset(struct ice_rss_hash_cfg *cfg)
3039 : : {
3040 : 0 : cfg->hash_flds = 0;
3041 : 0 : cfg->addl_hdrs = 0;
3042 : 0 : cfg->symm = 0;
3043 : 0 : cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
3044 : 0 : }
3045 : :
3046 : : static int
3047 : 0 : ice_hash_moveout(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3048 : : {
3049 : : int status;
3050 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3051 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
3052 : :
3053 [ # # ]: 0 : if (!is_hash_cfg_valid(cfg))
3054 : : return -ENOENT;
3055 : :
3056 : 0 : status = ice_rem_rss_cfg(hw, vsi->idx, cfg);
3057 [ # # ]: 0 : if (status && status != ICE_ERR_DOES_NOT_EXIST) {
3058 : 0 : PMD_DRV_LOG(ERR,
3059 : : "ice_rem_rss_cfg failed for VSI:%d, error:%d",
3060 : : vsi->idx, status);
3061 : 0 : return -EBUSY;
3062 : : }
3063 : :
3064 : : return 0;
3065 : : }
3066 : :
3067 : : static int
3068 : 0 : ice_hash_moveback(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3069 : : {
3070 : : int status;
3071 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3072 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
3073 : :
3074 [ # # ]: 0 : if (!is_hash_cfg_valid(cfg))
3075 : : return -ENOENT;
3076 : :
3077 : 0 : status = ice_add_rss_cfg(hw, vsi->idx, cfg);
3078 [ # # ]: 0 : if (status) {
3079 : 0 : PMD_DRV_LOG(ERR,
3080 : : "ice_add_rss_cfg failed for VSI:%d, error:%d",
3081 : : vsi->idx, status);
3082 : 0 : return -EBUSY;
3083 : : }
3084 : :
3085 : : return 0;
3086 : : }
3087 : :
3088 : : static int
3089 : : ice_hash_remove(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3090 : : {
3091 : : int ret;
3092 : :
3093 : 0 : ret = ice_hash_moveout(pf, cfg);
3094 [ # # # # : 0 : if (ret && (ret != -ENOENT))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
3095 : : return ret;
3096 : :
3097 : : hash_cfg_reset(cfg);
3098 : :
3099 : 0 : return 0;
3100 : : }
3101 : :
3102 : : static int
3103 : 0 : ice_add_rss_cfg_pre_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
3104 : : u8 ctx_idx)
3105 : : {
3106 : : int ret;
3107 : :
3108 [ # # # # : 0 : switch (ctx_idx) {
# # # # ]
3109 : 0 : case ICE_HASH_GTPU_CTX_EH_IP:
3110 : 0 : ret = ice_hash_remove(pf,
3111 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3112 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3113 : : return ret;
3114 : :
3115 : 0 : ret = ice_hash_remove(pf,
3116 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3117 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3118 : : return ret;
3119 : :
3120 : 0 : ret = ice_hash_remove(pf,
3121 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3122 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3123 : : return ret;
3124 : :
3125 : 0 : ret = ice_hash_remove(pf,
3126 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3127 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3128 : : return ret;
3129 : :
3130 : 0 : ret = ice_hash_remove(pf,
3131 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3132 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3133 : : return ret;
3134 : :
3135 : 0 : ret = ice_hash_remove(pf,
3136 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3137 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3138 : : return ret;
3139 : :
3140 : 0 : ret = ice_hash_remove(pf,
3141 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3142 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3143 : : return ret;
3144 : :
3145 : 0 : ret = ice_hash_remove(pf,
3146 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3147 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3148 : 0 : return ret;
3149 : :
3150 : : break;
3151 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_UDP:
3152 : 0 : ret = ice_hash_remove(pf,
3153 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3154 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3155 : : return ret;
3156 : :
3157 : 0 : ret = ice_hash_remove(pf,
3158 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3159 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3160 : : return ret;
3161 : :
3162 : 0 : ret = ice_hash_moveout(pf,
3163 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3164 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3165 : : return ret;
3166 : :
3167 : 0 : ret = ice_hash_moveout(pf,
3168 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3169 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3170 : : return ret;
3171 : :
3172 : 0 : ret = ice_hash_moveout(pf,
3173 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3174 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3175 : : return ret;
3176 : :
3177 : 0 : ret = ice_hash_moveout(pf,
3178 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3179 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3180 : 0 : return ret;
3181 : :
3182 : : break;
3183 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_TCP:
3184 : 0 : ret = ice_hash_remove(pf,
3185 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3186 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3187 : : return ret;
3188 : :
3189 : 0 : ret = ice_hash_remove(pf,
3190 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3191 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3192 : : return ret;
3193 : :
3194 : 0 : ret = ice_hash_moveout(pf,
3195 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3196 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3197 : : return ret;
3198 : :
3199 : 0 : ret = ice_hash_moveout(pf,
3200 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3201 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3202 : : return ret;
3203 : :
3204 : 0 : ret = ice_hash_moveout(pf,
3205 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3206 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3207 : : return ret;
3208 : :
3209 : 0 : ret = ice_hash_moveout(pf,
3210 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3211 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3212 : 0 : return ret;
3213 : :
3214 : : break;
3215 : 0 : case ICE_HASH_GTPU_CTX_UP_IP:
3216 : 0 : ret = ice_hash_remove(pf,
3217 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3218 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3219 : : return ret;
3220 : :
3221 : 0 : ret = ice_hash_remove(pf,
3222 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3223 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3224 : : return ret;
3225 : :
3226 : 0 : ret = ice_hash_moveout(pf,
3227 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3228 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3229 : : return ret;
3230 : :
3231 : 0 : ret = ice_hash_moveout(pf,
3232 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3233 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3234 : : return ret;
3235 : :
3236 : 0 : ret = ice_hash_moveout(pf,
3237 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3238 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3239 : 0 : return ret;
3240 : :
3241 : : break;
3242 : 0 : case ICE_HASH_GTPU_CTX_UP_IP_UDP:
3243 : : case ICE_HASH_GTPU_CTX_UP_IP_TCP:
3244 : 0 : ret = ice_hash_moveout(pf,
3245 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3246 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3247 : : return ret;
3248 : :
3249 : 0 : ret = ice_hash_moveout(pf,
3250 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3251 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3252 : : return ret;
3253 : :
3254 : 0 : ret = ice_hash_moveout(pf,
3255 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3256 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3257 : 0 : return ret;
3258 : :
3259 : : break;
3260 : 0 : case ICE_HASH_GTPU_CTX_DW_IP:
3261 : 0 : ret = ice_hash_remove(pf,
3262 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3263 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3264 : : return ret;
3265 : :
3266 : 0 : ret = ice_hash_remove(pf,
3267 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3268 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3269 : : return ret;
3270 : :
3271 : 0 : ret = ice_hash_moveout(pf,
3272 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3273 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3274 : : return ret;
3275 : :
3276 : 0 : ret = ice_hash_moveout(pf,
3277 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3278 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3279 : : return ret;
3280 : :
3281 : 0 : ret = ice_hash_moveout(pf,
3282 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3283 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3284 : 0 : return ret;
3285 : :
3286 : : break;
3287 : 0 : case ICE_HASH_GTPU_CTX_DW_IP_UDP:
3288 : : case ICE_HASH_GTPU_CTX_DW_IP_TCP:
3289 : 0 : ret = ice_hash_moveout(pf,
3290 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3291 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3292 : : return ret;
3293 : :
3294 : 0 : ret = ice_hash_moveout(pf,
3295 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3296 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3297 : : return ret;
3298 : :
3299 : 0 : ret = ice_hash_moveout(pf,
3300 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3301 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3302 : 0 : return ret;
3303 : :
3304 : : break;
3305 : : default:
3306 : : break;
3307 : : }
3308 : :
3309 : : return 0;
3310 : : }
3311 : :
3312 : 0 : static u8 calc_gtpu_ctx_idx(uint32_t hdr)
3313 : : {
3314 : : u8 eh_idx, ip_idx;
3315 : :
3316 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_GTPU_EH)
3317 : : eh_idx = 0;
3318 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_GTPU_UP)
3319 : : eh_idx = 1;
3320 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_GTPU_DWN)
3321 : : eh_idx = 2;
3322 : : else
3323 : : return ICE_HASH_GTPU_CTX_MAX;
3324 : :
3325 : : ip_idx = 0;
3326 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_UDP)
3327 : : ip_idx = 1;
3328 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_TCP)
3329 : : ip_idx = 2;
3330 : :
3331 [ # # ]: 0 : if (hdr & (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6))
3332 : 0 : return eh_idx * 3 + ip_idx;
3333 : : else
3334 : : return ICE_HASH_GTPU_CTX_MAX;
3335 : : }
3336 : :
3337 : : static int
3338 : 0 : ice_add_rss_cfg_pre(struct ice_pf *pf, uint32_t hdr)
3339 : : {
3340 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
3341 : :
3342 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_IPV4)
3343 : 0 : return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu4,
3344 : : gtpu_ctx_idx);
3345 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
3346 : 0 : return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu6,
3347 : : gtpu_ctx_idx);
3348 : :
3349 : : return 0;
3350 : : }
3351 : :
3352 : : static int
3353 : 0 : ice_add_rss_cfg_post_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
3354 : : u8 ctx_idx, struct ice_rss_hash_cfg *cfg)
3355 : : {
3356 : : int ret;
3357 : :
3358 [ # # ]: 0 : if (ctx_idx < ICE_HASH_GTPU_CTX_MAX)
3359 : 0 : ctx->ctx[ctx_idx] = *cfg;
3360 : :
3361 [ # # # # ]: 0 : switch (ctx_idx) {
3362 : : case ICE_HASH_GTPU_CTX_EH_IP:
3363 : : break;
3364 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_UDP:
3365 : 0 : ret = ice_hash_moveback(pf,
3366 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3367 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3368 : : return ret;
3369 : :
3370 : 0 : ret = ice_hash_moveback(pf,
3371 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
3372 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3373 : : return ret;
3374 : :
3375 : 0 : ret = ice_hash_moveback(pf,
3376 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3377 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3378 : : return ret;
3379 : :
3380 : 0 : ret = ice_hash_moveback(pf,
3381 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
3382 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3383 : 0 : return ret;
3384 : :
3385 : : break;
3386 : 0 : case ICE_HASH_GTPU_CTX_EH_IP_TCP:
3387 : 0 : ret = ice_hash_moveback(pf,
3388 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
3389 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3390 : : return ret;
3391 : :
3392 : 0 : ret = ice_hash_moveback(pf,
3393 : : &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
3394 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3395 : : return ret;
3396 : :
3397 : 0 : ret = ice_hash_moveback(pf,
3398 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
3399 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3400 : : return ret;
3401 : :
3402 : 0 : ret = ice_hash_moveback(pf,
3403 : : &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
3404 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3405 : 0 : return ret;
3406 : :
3407 : : break;
3408 : 0 : case ICE_HASH_GTPU_CTX_UP_IP:
3409 : : case ICE_HASH_GTPU_CTX_UP_IP_UDP:
3410 : : case ICE_HASH_GTPU_CTX_UP_IP_TCP:
3411 : : case ICE_HASH_GTPU_CTX_DW_IP:
3412 : : case ICE_HASH_GTPU_CTX_DW_IP_UDP:
3413 : : case ICE_HASH_GTPU_CTX_DW_IP_TCP:
3414 : 0 : ret = ice_hash_moveback(pf,
3415 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
3416 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3417 : : return ret;
3418 : :
3419 : 0 : ret = ice_hash_moveback(pf,
3420 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
3421 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3422 : : return ret;
3423 : :
3424 : 0 : ret = ice_hash_moveback(pf,
3425 : : &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
3426 [ # # ]: 0 : if (ret && (ret != -ENOENT))
3427 : 0 : return ret;
3428 : :
3429 : : break;
3430 : : default:
3431 : : break;
3432 : : }
3433 : :
3434 : : return 0;
3435 : : }
3436 : :
3437 : : static int
3438 : 0 : ice_add_rss_cfg_post(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
3439 : : {
3440 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(cfg->addl_hdrs);
3441 : :
3442 [ # # ]: 0 : if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV4)
3443 : 0 : return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu4,
3444 : : gtpu_ctx_idx, cfg);
3445 [ # # ]: 0 : else if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV6)
3446 : 0 : return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu6,
3447 : : gtpu_ctx_idx, cfg);
3448 : :
3449 : : return 0;
3450 : : }
3451 : :
3452 : : static void
3453 : 0 : ice_rem_rss_cfg_post(struct ice_pf *pf, uint32_t hdr)
3454 : : {
3455 : 0 : u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
3456 : :
3457 [ # # ]: 0 : if (gtpu_ctx_idx >= ICE_HASH_GTPU_CTX_MAX)
3458 : : return;
3459 : :
3460 [ # # ]: 0 : if (hdr & ICE_FLOW_SEG_HDR_IPV4)
3461 : 0 : hash_cfg_reset(&pf->hash_ctx.gtpu4.ctx[gtpu_ctx_idx]);
3462 [ # # ]: 0 : else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
3463 : 0 : hash_cfg_reset(&pf->hash_ctx.gtpu6.ctx[gtpu_ctx_idx]);
3464 : : }
3465 : :
3466 : : int
3467 : 0 : ice_rem_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
3468 : : struct ice_rss_hash_cfg *cfg)
3469 : : {
3470 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3471 : : int ret;
3472 : :
3473 : 0 : ret = ice_rem_rss_cfg(hw, vsi_id, cfg);
3474 [ # # ]: 0 : if (ret && ret != ICE_ERR_DOES_NOT_EXIST)
3475 : 0 : PMD_DRV_LOG(ERR, "remove rss cfg failed");
3476 : :
3477 : 0 : ice_rem_rss_cfg_post(pf, cfg->addl_hdrs);
3478 : :
3479 : 0 : return 0;
3480 : : }
3481 : :
3482 : : int
3483 : 0 : ice_add_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
3484 : : struct ice_rss_hash_cfg *cfg)
3485 : : {
3486 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3487 : : int ret;
3488 : :
3489 : 0 : ret = ice_add_rss_cfg_pre(pf, cfg->addl_hdrs);
3490 [ # # ]: 0 : if (ret)
3491 : 0 : PMD_DRV_LOG(ERR, "add rss cfg pre failed");
3492 : :
3493 : 0 : ret = ice_add_rss_cfg(hw, vsi_id, cfg);
3494 [ # # ]: 0 : if (ret)
3495 : 0 : PMD_DRV_LOG(ERR, "add rss cfg failed");
3496 : :
3497 : 0 : ret = ice_add_rss_cfg_post(pf, cfg);
3498 [ # # ]: 0 : if (ret)
3499 : 0 : PMD_DRV_LOG(ERR, "add rss cfg post failed");
3500 : :
3501 : 0 : return 0;
3502 : : }
3503 : :
3504 : : static void
3505 : 0 : ice_rss_hash_set(struct ice_pf *pf, uint64_t rss_hf)
3506 : : {
3507 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3508 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3509 : : struct ice_rss_hash_cfg cfg;
3510 : : int ret;
3511 : :
3512 : : #define ICE_RSS_HF_ALL ( \
3513 : : RTE_ETH_RSS_IPV4 | \
3514 : : RTE_ETH_RSS_IPV6 | \
3515 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
3516 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
3517 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
3518 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
3519 : : RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
3520 : : RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
3521 : :
3522 : 0 : ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
3523 [ # # ]: 0 : if (ret)
3524 : 0 : PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
3525 : : __func__, ret);
3526 : :
3527 : 0 : cfg.symm = 0;
3528 : 0 : cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
3529 : : /* Configure RSS for IPv4 with src/dst addr as input set */
3530 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4) {
3531 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3532 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3533 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3534 [ # # ]: 0 : if (ret)
3535 : 0 : PMD_DRV_LOG(ERR, "%s IPV4 rss flow fail %d",
3536 : : __func__, ret);
3537 : : }
3538 : :
3539 : : /* Configure RSS for IPv6 with src/dst addr as input set */
3540 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6) {
3541 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3542 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3543 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3544 [ # # ]: 0 : if (ret)
3545 : 0 : PMD_DRV_LOG(ERR, "%s IPV6 rss flow fail %d",
3546 : : __func__, ret);
3547 : : }
3548 : :
3549 : : /* Configure RSS for udp4 with src/dst addr and port as input set */
3550 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3551 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4 |
3552 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3553 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV4;
3554 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3555 [ # # ]: 0 : if (ret)
3556 : 0 : PMD_DRV_LOG(ERR, "%s UDP_IPV4 rss flow fail %d",
3557 : : __func__, ret);
3558 : : }
3559 : :
3560 : : /* Configure RSS for udp6 with src/dst addr and port as input set */
3561 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3562 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6 |
3563 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3564 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV6;
3565 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3566 [ # # ]: 0 : if (ret)
3567 : 0 : PMD_DRV_LOG(ERR, "%s UDP_IPV6 rss flow fail %d",
3568 : : __func__, ret);
3569 : : }
3570 : :
3571 : : /* Configure RSS for tcp4 with src/dst addr and port as input set */
3572 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3573 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4 |
3574 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3575 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV4;
3576 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3577 [ # # ]: 0 : if (ret)
3578 : 0 : PMD_DRV_LOG(ERR, "%s TCP_IPV4 rss flow fail %d",
3579 : : __func__, ret);
3580 : : }
3581 : :
3582 : : /* Configure RSS for tcp6 with src/dst addr and port as input set */
3583 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3584 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6 |
3585 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3586 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV6;
3587 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3588 [ # # ]: 0 : if (ret)
3589 : 0 : PMD_DRV_LOG(ERR, "%s TCP_IPV6 rss flow fail %d",
3590 : : __func__, ret);
3591 : : }
3592 : :
3593 : : /* Configure RSS for sctp4 with src/dst addr and port as input set */
3594 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) {
3595 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4 |
3596 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3597 : 0 : cfg.hash_flds = ICE_HASH_SCTP_IPV4;
3598 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3599 [ # # ]: 0 : if (ret)
3600 : 0 : PMD_DRV_LOG(ERR, "%s SCTP_IPV4 rss flow fail %d",
3601 : : __func__, ret);
3602 : : }
3603 : :
3604 : : /* Configure RSS for sctp6 with src/dst addr and port as input set */
3605 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) {
3606 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6 |
3607 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3608 : 0 : cfg.hash_flds = ICE_HASH_SCTP_IPV6;
3609 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3610 [ # # ]: 0 : if (ret)
3611 : 0 : PMD_DRV_LOG(ERR, "%s SCTP_IPV6 rss flow fail %d",
3612 : : __func__, ret);
3613 : : }
3614 : :
3615 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV4) {
3616 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV4 |
3617 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3618 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3619 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3620 [ # # ]: 0 : if (ret)
3621 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4 rss flow fail %d",
3622 : : __func__, ret);
3623 : : }
3624 : :
3625 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_IPV6) {
3626 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV6 |
3627 : : ICE_FLOW_SEG_HDR_IPV_OTHER;
3628 : 0 : cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3629 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3630 [ # # ]: 0 : if (ret)
3631 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6 rss flow fail %d",
3632 : : __func__, ret);
3633 : : }
3634 : :
3635 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3636 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3637 : : ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3638 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV4;
3639 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3640 [ # # ]: 0 : if (ret)
3641 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_UDP rss flow fail %d",
3642 : : __func__, ret);
3643 : : }
3644 : :
3645 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3646 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3647 : : ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3648 : 0 : cfg.hash_flds = ICE_HASH_UDP_IPV6;
3649 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3650 [ # # ]: 0 : if (ret)
3651 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_UDP rss flow fail %d",
3652 : : __func__, ret);
3653 : : }
3654 : :
3655 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3656 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3657 : : ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3658 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV4;
3659 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3660 [ # # ]: 0 : if (ret)
3661 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_TCP rss flow fail %d",
3662 : : __func__, ret);
3663 : : }
3664 : :
3665 [ # # ]: 0 : if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3666 : 0 : cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3667 : : ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3668 : 0 : cfg.hash_flds = ICE_HASH_TCP_IPV6;
3669 : 0 : ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3670 [ # # ]: 0 : if (ret)
3671 : 0 : PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_TCP rss flow fail %d",
3672 : : __func__, ret);
3673 : : }
3674 : :
3675 : 0 : pf->rss_hf = rss_hf & ICE_RSS_HF_ALL;
3676 : 0 : }
3677 : :
3678 : : static void
3679 : 0 : ice_get_default_rss_key(uint8_t *rss_key, uint32_t rss_key_size)
3680 : : {
3681 : : static struct ice_aqc_get_set_rss_keys default_key;
3682 : : static bool default_key_done;
3683 : : uint8_t *key = (uint8_t *)&default_key;
3684 : : size_t i;
3685 : :
3686 [ # # ]: 0 : if (rss_key_size > sizeof(default_key)) {
3687 : 0 : PMD_DRV_LOG(WARNING,
3688 : : "requested size %u is larger than default %zu, "
3689 : : "only %zu bytes are gotten for key",
3690 : : rss_key_size, sizeof(default_key),
3691 : : sizeof(default_key));
3692 : : }
3693 : :
3694 [ # # ]: 0 : if (!default_key_done) {
3695 : : /* Calculate the default hash key */
3696 [ # # ]: 0 : for (i = 0; i < sizeof(default_key); i++)
3697 : 0 : key[i] = (uint8_t)rte_rand();
3698 : 0 : default_key_done = true;
3699 : : }
3700 [ # # ]: 0 : rte_memcpy(rss_key, key, RTE_MIN(rss_key_size, sizeof(default_key)));
3701 : 0 : }
3702 : :
3703 : 0 : static int ice_init_rss(struct ice_pf *pf)
3704 : : {
3705 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3706 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3707 : 0 : struct rte_eth_dev_data *dev_data = pf->dev_data;
3708 : : struct ice_aq_get_set_rss_lut_params lut_params;
3709 : : struct rte_eth_rss_conf *rss_conf;
3710 : : struct ice_aqc_get_set_rss_keys key;
3711 : : uint16_t i, nb_q;
3712 : : int ret = 0;
3713 : 0 : bool is_safe_mode = pf->adapter->is_safe_mode;
3714 : : uint32_t reg;
3715 : :
3716 : : rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
3717 : 0 : nb_q = dev_data->nb_rx_queues;
3718 : 0 : vsi->rss_key_size = ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE +
3719 : : ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE;
3720 : 0 : vsi->rss_lut_size = pf->hash_lut_size;
3721 : :
3722 [ # # ]: 0 : if (nb_q == 0) {
3723 : 0 : PMD_DRV_LOG(WARNING,
3724 : : "RSS is not supported as rx queues number is zero");
3725 : 0 : return 0;
3726 : : }
3727 : :
3728 [ # # ]: 0 : if (is_safe_mode) {
3729 : 0 : PMD_DRV_LOG(WARNING, "RSS is not supported in safe mode");
3730 : 0 : return 0;
3731 : : }
3732 : :
3733 [ # # ]: 0 : if (!vsi->rss_key) {
3734 : 0 : vsi->rss_key = rte_zmalloc(NULL,
3735 : : vsi->rss_key_size, 0);
3736 [ # # ]: 0 : if (vsi->rss_key == NULL) {
3737 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3738 : 0 : return -ENOMEM;
3739 : : }
3740 : : }
3741 [ # # ]: 0 : if (!vsi->rss_lut) {
3742 : 0 : vsi->rss_lut = rte_zmalloc(NULL,
3743 : 0 : vsi->rss_lut_size, 0);
3744 [ # # ]: 0 : if (vsi->rss_lut == NULL) {
3745 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3746 : 0 : rte_free(vsi->rss_key);
3747 : 0 : vsi->rss_key = NULL;
3748 : 0 : return -ENOMEM;
3749 : : }
3750 : : }
3751 : : /* configure RSS key */
3752 [ # # ]: 0 : if (!rss_conf->rss_key)
3753 : 0 : ice_get_default_rss_key(vsi->rss_key, vsi->rss_key_size);
3754 : : else
3755 : 0 : rte_memcpy(vsi->rss_key, rss_conf->rss_key,
3756 [ # # ]: 0 : RTE_MIN(rss_conf->rss_key_len,
3757 : : vsi->rss_key_size));
3758 : :
3759 [ # # ]: 0 : rte_memcpy(key.standard_rss_key, vsi->rss_key,
3760 : : ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
3761 : : rte_memcpy(key.extended_hash_key,
3762 [ # # ]: 0 : &vsi->rss_key[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE],
3763 : : ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE);
3764 : 0 : ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
3765 [ # # ]: 0 : if (ret)
3766 : 0 : goto out;
3767 : :
3768 : : /* init RSS LUT table */
3769 [ # # ]: 0 : for (i = 0; i < vsi->rss_lut_size; i++)
3770 : 0 : vsi->rss_lut[i] = i % nb_q;
3771 : :
3772 [ # # # # ]: 0 : if (nb_q <= ICE_RSS_LUT_GLOBAL_QUEUE_NB && (hw)->mac_type == ICE_MAC_E830) {
3773 : : struct ice_vsi_ctx vsi_ctx;
3774 : : uint16_t global_lut;
3775 : :
3776 [ # # ]: 0 : if (!vsi->global_lut_allocated) {
3777 : 0 : ret = ice_alloc_rss_global_lut(hw, false, &global_lut);
3778 [ # # ]: 0 : if (ret)
3779 : 0 : goto out;
3780 : 0 : vsi->global_lut_allocated = true;
3781 : 0 : vsi->global_lut_id = global_lut;
3782 : : }
3783 : 0 : global_lut = vsi->global_lut_id;
3784 : :
3785 : 0 : vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
3786 : 0 : vsi_ctx.info = vsi->info;
3787 : 0 : vsi_ctx.info.q_opt_rss &= ICE_AQ_VSI_Q_OPT_RSS_LUT_M |
3788 : : ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M;
3789 : 0 : vsi_ctx.info.q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_LUT_GBL |
3790 : 0 : ((global_lut << ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_S) &
3791 : : ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
3792 : :
3793 : 0 : vsi_ctx.info.valid_sections =
3794 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
3795 : :
3796 : 0 : ret = ice_update_vsi(hw, vsi->idx, &vsi_ctx, NULL);
3797 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
3798 : 0 : PMD_INIT_LOG(ERR, "update vsi failed, err = %d", ret);
3799 : 0 : goto out;
3800 : : }
3801 : :
3802 : 0 : vsi->info = vsi_ctx.info;
3803 : 0 : lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL;
3804 : 0 : lut_params.global_lut_id = global_lut;
3805 : : } else {
3806 : 0 : lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
3807 : 0 : lut_params.global_lut_id = 0;
3808 : : }
3809 : :
3810 : 0 : lut_params.vsi_handle = vsi->idx;
3811 : 0 : lut_params.lut_size = vsi->rss_lut_size;
3812 : 0 : lut_params.lut = vsi->rss_lut;
3813 : 0 : ret = ice_aq_set_rss_lut(hw, &lut_params);
3814 [ # # ]: 0 : if (ret)
3815 : 0 : goto out;
3816 : :
3817 : : /* Enable registers for symmetric_toeplitz function. */
3818 : 0 : reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
3819 : 0 : reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
3820 : : (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
3821 : 0 : ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
3822 : :
3823 : : /* RSS hash configuration */
3824 : 0 : ice_rss_hash_set(pf, rss_conf->rss_hf);
3825 : :
3826 : 0 : return 0;
3827 : 0 : out:
3828 : 0 : rte_free(vsi->rss_key);
3829 : 0 : vsi->rss_key = NULL;
3830 : 0 : rte_free(vsi->rss_lut);
3831 : 0 : vsi->rss_lut = NULL;
3832 : 0 : return -EINVAL;
3833 : : }
3834 : :
3835 : : static int
3836 : 0 : check_dcb_conf(int is_8_ports, struct rte_eth_dcb_rx_conf *dcb_conf)
3837 : : {
3838 : : uint32_t tc_map = 0;
3839 : : int i;
3840 : :
3841 : 0 : enum rte_eth_nb_tcs nb_tcs = dcb_conf->nb_tcs;
3842 [ # # ]: 0 : if (nb_tcs != RTE_ETH_4_TCS && is_8_ports) {
3843 : 0 : PMD_DRV_LOG(ERR, "Invalid num TCs setting - only 4 TCs are supported");
3844 : 0 : return -1;
3845 [ # # ]: 0 : } else if (nb_tcs != RTE_ETH_4_TCS && nb_tcs != RTE_ETH_8_TCS) {
3846 : 0 : PMD_DRV_LOG(ERR, "Invalid num TCs setting - only 8 TCs or 4 TCs are supported");
3847 : 0 : return -1;
3848 : : }
3849 : :
3850 : : /* Check if associated TC are in continuous range */
3851 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++)
3852 : 0 : tc_map |= 1 << (dcb_conf->dcb_tc[i] & 0x7);
3853 : :
3854 [ # # ]: 0 : if (!rte_is_power_of_2(tc_map + 1)) {
3855 : 0 : PMD_DRV_LOG(ERR,
3856 : : "Bad VLAN User Priority to Traffic Class association in DCB config");
3857 : 0 : return -1;
3858 : : }
3859 : :
3860 : 0 : return rte_popcount32(tc_map);
3861 : : }
3862 : :
3863 : : static int
3864 : 0 : ice_dev_configure(struct rte_eth_dev *dev)
3865 : : {
3866 : 0 : struct ice_adapter *ad =
3867 : 0 : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3868 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3869 : : int ret;
3870 : :
3871 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
3872 : : * bulk allocation or vector Rx preconditions we will reset it.
3873 : : */
3874 : 0 : ad->rx_bulk_alloc_allowed = true;
3875 : 0 : ad->tx_simple_allowed = true;
3876 : :
3877 : 0 : ad->rx_func_type = ICE_RX_DEFAULT;
3878 : 0 : ad->tx_func_type = ICE_TX_DEFAULT;
3879 : :
3880 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
3881 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
3882 : :
3883 [ # # ]: 0 : if (dev->data->nb_rx_queues) {
3884 : 0 : ret = ice_init_rss(pf);
3885 [ # # ]: 0 : if (ret) {
3886 : 0 : PMD_DRV_LOG(ERR, "Failed to enable rss for PF");
3887 : 0 : return ret;
3888 : : }
3889 : : }
3890 : :
3891 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
3892 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3893 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3894 : 0 : struct ice_port_info *port_info = hw->port_info;
3895 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
3896 : 0 : struct ice_dcbx_cfg *local_dcb_conf = &qos_cfg->local_dcbx_cfg;
3897 : : struct ice_vsi_ctx ctxt;
3898 : 0 : struct rte_eth_dcb_rx_conf *dcb_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
3899 : : int i;
3900 : 0 : enum rte_eth_nb_tcs nb_tcs = dcb_conf->nb_tcs;
3901 : : int nb_tc_used, queues_per_tc;
3902 : : uint16_t total_q_nb;
3903 : :
3904 : 0 : nb_tc_used = check_dcb_conf(ice_get_port_max_cgd(hw) == ICE_4_CGD_PER_PORT,
3905 : : dcb_conf);
3906 [ # # ]: 0 : if (nb_tc_used < 0)
3907 : 0 : return -EINVAL;
3908 : :
3909 : 0 : ctxt.info = vsi->info;
3910 [ # # ]: 0 : if (rte_le_to_cpu_16(ctxt.info.mapping_flags) == ICE_AQ_VSI_Q_MAP_NONCONTIG) {
3911 : 0 : PMD_DRV_LOG(ERR, "VSI configured with non contiguous queues, DCB is not supported");
3912 : 0 : return -EINVAL;
3913 : : }
3914 : :
3915 : 0 : total_q_nb = dev->data->nb_rx_queues;
3916 : 0 : queues_per_tc = total_q_nb / nb_tc_used;
3917 [ # # ]: 0 : if (total_q_nb % nb_tc_used != 0) {
3918 : 0 : PMD_DRV_LOG(ERR, "For DCB, number of queues must be evenly divisible by number of used TCs");
3919 : 0 : return -EINVAL;
3920 [ # # ]: 0 : } else if (!rte_is_power_of_2(queues_per_tc)) {
3921 : 0 : PMD_DRV_LOG(ERR, "For DCB, number of queues per TC must be a power of 2");
3922 : 0 : return -EINVAL;
3923 : : }
3924 : :
3925 [ # # ]: 0 : for (i = 0; i < nb_tc_used; i++) {
3926 : 0 : ctxt.info.tc_mapping[i] =
3927 : 0 : rte_cpu_to_le_16(((i * queues_per_tc) << ICE_AQ_VSI_TC_Q_OFFSET_S) |
3928 : : (rte_log2_u32(queues_per_tc) << ICE_AQ_VSI_TC_Q_NUM_S));
3929 : : }
3930 : :
3931 : : memset(local_dcb_conf, 0, sizeof(*local_dcb_conf));
3932 : :
3933 : 0 : local_dcb_conf->etscfg.maxtcs = nb_tcs;
3934 : :
3935 : : /* Associate each VLAN UP with particular TC */
3936 [ # # ]: 0 : for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
3937 : 0 : local_dcb_conf->etscfg.prio_table[i] = dcb_conf->dcb_tc[i];
3938 : 0 : local_dcb_conf->etsrec.prio_table[i] = dcb_conf->dcb_tc[i];
3939 : : }
3940 : :
3941 : : /*
3942 : : * Since current API does not support setting ETS BW Share and Scheduler
3943 : : * configure all TC as ETS and evenly share load across all existing TC
3944 : : **/
3945 : 0 : const int bw_share_percent = 100 / nb_tc_used;
3946 : : const int bw_share_left = 100 - bw_share_percent * nb_tc_used;
3947 [ # # ]: 0 : for (i = 0; i < nb_tc_used; i++) {
3948 : : /* Per TC bandwidth table (all valued must add up to 100%), valid on ETS */
3949 : 0 : local_dcb_conf->etscfg.tcbwtable[i] = bw_share_percent;
3950 : 0 : local_dcb_conf->etsrec.tcbwtable[i] = bw_share_percent;
3951 : :
3952 : : /**< Transmission Selection Algorithm. 0 - Strict prio, 2 - ETS */
3953 : 0 : local_dcb_conf->etscfg.tsatable[i] = 2;
3954 : 0 : local_dcb_conf->etsrec.tsatable[i] = 2;
3955 : : }
3956 : :
3957 [ # # ]: 0 : for (i = 0; i < bw_share_left; i++) {
3958 : 0 : local_dcb_conf->etscfg.tcbwtable[i]++;
3959 : 0 : local_dcb_conf->etsrec.tcbwtable[i]++;
3960 : : }
3961 : :
3962 : 0 : local_dcb_conf->pfc.pfccap = nb_tcs;
3963 : : local_dcb_conf->pfc.pfcena = 0;
3964 : :
3965 : 0 : ret = ice_set_dcb_cfg(port_info);
3966 [ # # ]: 0 : if (ret) {
3967 : 0 : PMD_DRV_LOG(ERR, "Failed to configure DCB for PF");
3968 : 0 : return ret;
3969 : : }
3970 : :
3971 : : /* Update VSI queue allocatios per TC */
3972 : 0 : ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3973 : 0 : ctxt.info.mapping_flags = rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
3974 : :
3975 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3976 [ # # ]: 0 : if (ret) {
3977 : 0 : PMD_DRV_LOG(ERR, "Failed to configure queue mapping");
3978 : 0 : return ret;
3979 : : }
3980 : :
3981 : 0 : ctxt.info.valid_sections = 0;
3982 : 0 : vsi->info = ctxt.info;
3983 : :
3984 : 0 : hw->port_info->fc.current_mode = ICE_FC_PFC;
3985 : : }
3986 : :
3987 : : return 0;
3988 : : }
3989 : :
3990 : : static int
3991 : 0 : ice_get_dcb_info(struct rte_eth_dev *dev, struct rte_eth_dcb_info *dcb_info)
3992 : : {
3993 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3994 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
3995 : 0 : struct ice_port_info *port_info = hw->port_info;
3996 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
3997 : : struct ice_dcbx_cfg *dcb_conf = &qos_cfg->local_dcbx_cfg;
3998 : 0 : struct ice_vsi *vsi = pf->main_vsi;
3999 : :
4000 [ # # ]: 0 : if (rte_le_to_cpu_16(vsi->info.mapping_flags) == ICE_AQ_VSI_Q_MAP_NONCONTIG) {
4001 : 0 : PMD_DRV_LOG(ERR, "VSI configured with non contiguous queues, DCB is not supported");
4002 : 0 : return -ENOTSUP;
4003 : : }
4004 : :
4005 : 0 : dcb_info->nb_tcs = dcb_conf->etscfg.maxtcs;
4006 [ # # ]: 0 : for (int i = 0; i < dcb_info->nb_tcs; i++) {
4007 : 0 : dcb_info->prio_tc[i] = dcb_conf->etscfg.prio_table[i];
4008 : 0 : dcb_info->tc_bws[i] = dcb_conf->etscfg.tcbwtable[i];
4009 : : /* Using VMDQ pool zero since DCB+VMDQ is not supported */
4010 : 0 : uint16_t tc_rx_q_map = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
4011 : 0 : dcb_info->tc_queue.tc_rxq[0][i].base = tc_rx_q_map & ICE_AQ_VSI_TC_Q_OFFSET_M;
4012 : 0 : dcb_info->tc_queue.tc_rxq[0][i].nb_queue =
4013 : 0 : 1 << ((tc_rx_q_map & ICE_AQ_VSI_TC_Q_NUM_M) >> ICE_AQ_VSI_TC_Q_NUM_S);
4014 : :
4015 : 0 : dcb_info->tc_queue.tc_txq[0][i].base = dcb_info->tc_queue.tc_rxq[0][i].base;
4016 : 0 : dcb_info->tc_queue.tc_txq[0][i].nb_queue = dcb_info->tc_queue.tc_rxq[0][i].nb_queue;
4017 : : }
4018 : :
4019 : : return 0;
4020 : : }
4021 : :
4022 : : static int
4023 : 0 : ice_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
4024 : : {
4025 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4026 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
4027 : 0 : struct ice_port_info *port_info = hw->port_info;
4028 : : struct ice_qos_cfg *qos_cfg = &port_info->qos_cfg;
4029 : : struct ice_dcbx_cfg *dcb_conf = &qos_cfg->local_dcbx_cfg;
4030 : : int ret;
4031 : :
4032 : 0 : dcb_conf->pfc_mode = ICE_QOS_MODE_VLAN;
4033 : 0 : dcb_conf->pfc.willing = 0;
4034 : : /** pfccap should already be set by DCB config, check if zero */
4035 [ # # ]: 0 : if (dcb_conf->pfc.pfccap == 0) {
4036 : 0 : PMD_DRV_LOG(ERR, "DCB is not configured on the port, can not set PFC");
4037 : 0 : return -EINVAL;
4038 : : }
4039 : :
4040 : 0 : ret = ice_aq_set_pfc_mode(hw, ICE_AQC_PFC_VLAN_BASED_PFC, NULL);
4041 [ # # ]: 0 : if (ret) {
4042 : 0 : PMD_DRV_LOG(ERR, "Failed to enable PFC in VLAN mode");
4043 : 0 : return ret;
4044 : : }
4045 : :
4046 : 0 : u8 tc = ice_get_tc_by_priority(hw, pfc_conf->priority);
4047 : :
4048 [ # # # # : 0 : switch (pfc_conf->fc.mode) {
# ]
4049 : 0 : case (RTE_ETH_FC_NONE):
4050 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4051 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4052 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4053 : 0 : break;
4054 : 0 : case (RTE_ETH_FC_RX_PAUSE):
4055 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4056 : 0 : dcb_conf->pfc.pfcena_asym_rx |= (1 << tc);
4057 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4058 : 0 : break;
4059 : 0 : case (RTE_ETH_FC_TX_PAUSE):
4060 : 0 : dcb_conf->pfc.pfcena &= ~(1 << tc);
4061 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4062 : 0 : dcb_conf->pfc.pfcena_asym_tx |= (1 << tc);
4063 : 0 : break;
4064 : 0 : case (RTE_ETH_FC_FULL):
4065 : 0 : dcb_conf->pfc.pfcena |= (1 << tc);
4066 : 0 : dcb_conf->pfc.pfcena_asym_rx &= ~(1 << tc);
4067 : 0 : dcb_conf->pfc.pfcena_asym_tx &= ~(1 << tc);
4068 : 0 : break;
4069 : : }
4070 : :
4071 : 0 : ret = ice_set_dcb_cfg(port_info);
4072 [ # # ]: 0 : if (ret) {
4073 : 0 : PMD_DRV_LOG(ERR, "Failed to configure DCB for PF");
4074 : 0 : return ret;
4075 : : }
4076 : :
4077 : : /* Update high and low watermarks */
4078 : 0 : u32 high_watermark = pfc_conf->fc.high_water;
4079 [ # # ]: 0 : if (high_watermark > ICE_MAC_TC_MAX_WATERMARK)
4080 : : high_watermark = ICE_MAC_TC_MAX_WATERMARK;
4081 : :
4082 : 0 : u32 low_watermark = pfc_conf->fc.low_water;
4083 : : if (low_watermark > ICE_MAC_TC_MAX_WATERMARK)
4084 : : low_watermark = ICE_MAC_TC_MAX_WATERMARK;
4085 : :
4086 : 0 : int cgd_idx = ice_get_cgd_idx(hw, tc);
4087 : :
4088 [ # # ]: 0 : if (high_watermark)
4089 : 0 : wr32(hw, GLRPB_TCHW(cgd_idx), high_watermark);
4090 [ # # ]: 0 : if (low_watermark)
4091 : 0 : wr32(hw, GLRPB_TCLW(cgd_idx), low_watermark);
4092 : :
4093 : : /* Update pause quanta */
4094 [ # # ]: 0 : uint16_t max_frame_size = pf->dev_data->mtu ?
4095 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD :
4096 : : ICE_FRAME_SIZE_MAX;
4097 : 0 : ret = ice_aq_set_mac_pfc_cfg(hw, max_frame_size, 1 << tc, pfc_conf->fc.pause_time,
4098 : 0 : ((u32)pfc_conf->fc.pause_time + 1) / 2, false, NULL);
4099 [ # # ]: 0 : if (ret) {
4100 : 0 : PMD_DRV_LOG(ERR, "Can not update MAC configuration");
4101 : 0 : return ret;
4102 : : }
4103 : :
4104 : : /* Update forwarding of the non FC MAC control frames settings */
4105 [ # # ]: 0 : if ((hw)->mac_type == ICE_MAC_E830) {
4106 : : #define E830_MAC_COMMAND_CONFIG(pi) (((pi)->phy.link_info.link_speed == ICE_AQ_LINK_SPEED_200GB) ? \
4107 : : E830_PRTMAC_200G_COMMAND_CONFIG : E830_PRTMAC_COMMAND_CONFIG)
4108 : :
4109 [ # # ]: 0 : u32 mac_config = rd32(hw, E830_MAC_COMMAND_CONFIG(port_info));
4110 : :
4111 [ # # ]: 0 : if (pfc_conf->fc.mac_ctrl_frame_fwd)
4112 : 0 : mac_config |= E830_PRTMAC_COMMAND_CONFIG_CNTL_FRM_ENA_M;
4113 : : else
4114 : 0 : mac_config &= ~E830_PRTMAC_COMMAND_CONFIG_CNTL_FRM_ENA_M;
4115 : :
4116 [ # # ]: 0 : wr32(hw, E830_MAC_COMMAND_CONFIG(port_info), mac_config);
4117 : : }
4118 : :
4119 : : return 0;
4120 : : }
4121 : :
4122 : : static void
4123 : 0 : __vsi_queues_bind_intr(struct ice_vsi *vsi, uint16_t msix_vect,
4124 : : int base_queue, int nb_queue)
4125 : : {
4126 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4127 : : uint32_t val, val_tx;
4128 : : int rx_low_latency, i;
4129 : :
4130 : 0 : rx_low_latency = vsi->adapter->devargs.rx_low_latency;
4131 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
4132 : : /*do actual bind*/
4133 : 0 : val = (msix_vect & QINT_RQCTL_MSIX_INDX_M) |
4134 : : (0 << QINT_RQCTL_ITR_INDX_S) | QINT_RQCTL_CAUSE_ENA_M;
4135 : : val_tx = (msix_vect & QINT_TQCTL_MSIX_INDX_M) |
4136 : : (0 << QINT_TQCTL_ITR_INDX_S) | QINT_TQCTL_CAUSE_ENA_M;
4137 : :
4138 : 0 : PMD_DRV_LOG(INFO, "queue %d is binding to vect %d",
4139 : : base_queue + i, msix_vect);
4140 : :
4141 : : /* set ITR0 value */
4142 [ # # ]: 0 : if (rx_low_latency) {
4143 : : /**
4144 : : * Empirical configuration for optimal real time
4145 : : * latency reduced interrupt throttling to 2us
4146 : : */
4147 : 0 : ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x1);
4148 : 0 : ICE_WRITE_REG(hw, QRX_ITR(base_queue + i),
4149 : : QRX_ITR_NO_EXPR_M);
4150 : : } else {
4151 : 0 : ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x2);
4152 : 0 : ICE_WRITE_REG(hw, QRX_ITR(base_queue + i), 0);
4153 : : }
4154 : :
4155 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(base_queue + i), val);
4156 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(base_queue + i), val_tx);
4157 : : }
4158 : 0 : }
4159 : :
4160 : : void
4161 : 0 : ice_vsi_queues_bind_intr(struct ice_vsi *vsi)
4162 : : {
4163 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
4164 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4165 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4166 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4167 : 0 : uint16_t msix_vect = vsi->msix_intr;
4168 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
4169 : : rte_intr_nb_efd_get(intr_handle));
4170 : : uint16_t queue_idx = 0;
4171 : : int record = 0;
4172 : : int i;
4173 : :
4174 : : /* clear Rx/Tx queue interrupt */
4175 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4176 : 0 : ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
4177 : 0 : ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
4178 : : }
4179 : :
4180 : : /* PF bind interrupt */
4181 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
4182 : : queue_idx = 0;
4183 : : record = 1;
4184 : : }
4185 : :
4186 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4187 [ # # ]: 0 : if (nb_msix <= 1) {
4188 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
4189 : : msix_vect = ICE_MISC_VEC_ID;
4190 : :
4191 : : /* uio mapping all queue to one msix_vect */
4192 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
4193 : 0 : vsi->base_queue + i,
4194 : 0 : vsi->nb_used_qps - i);
4195 : :
4196 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
4197 : 0 : rte_intr_vec_list_index_set(intr_handle,
4198 : : queue_idx + i, msix_vect);
4199 : :
4200 : : break;
4201 : : }
4202 : :
4203 : : /* vfio 1:1 queue/msix_vect mapping */
4204 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
4205 : 0 : vsi->base_queue + i, 1);
4206 : :
4207 [ # # ]: 0 : if (!!record)
4208 : 0 : rte_intr_vec_list_index_set(intr_handle,
4209 : : queue_idx + i,
4210 : : msix_vect);
4211 : :
4212 : 0 : msix_vect++;
4213 : 0 : nb_msix--;
4214 : : }
4215 : 0 : }
4216 : :
4217 : : void
4218 : 0 : ice_vsi_enable_queues_intr(struct ice_vsi *vsi)
4219 : : {
4220 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
4221 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4222 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4223 : : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4224 : : uint16_t msix_intr, i;
4225 : :
4226 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
4227 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
4228 : 0 : msix_intr = vsi->msix_intr + i;
4229 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
4230 : : GLINT_DYN_CTL_INTENA_M |
4231 : : GLINT_DYN_CTL_CLEARPBA_M |
4232 : : GLINT_DYN_CTL_ITR_INDX_M |
4233 : : GLINT_DYN_CTL_WB_ON_ITR_M);
4234 : : }
4235 : : else
4236 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
4237 : : GLINT_DYN_CTL_INTENA_M |
4238 : : GLINT_DYN_CTL_CLEARPBA_M |
4239 : : GLINT_DYN_CTL_ITR_INDX_M |
4240 : : GLINT_DYN_CTL_WB_ON_ITR_M);
4241 : 0 : }
4242 : :
4243 : : static int
4244 : 0 : ice_rxq_intr_setup(struct rte_eth_dev *dev)
4245 : : {
4246 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4247 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4248 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4249 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4250 : : uint32_t intr_vector = 0;
4251 : :
4252 : 0 : rte_intr_disable(intr_handle);
4253 : :
4254 : : /* check and configure queue intr-vector mapping */
4255 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
4256 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
4257 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
4258 : 0 : intr_vector = dev->data->nb_rx_queues;
4259 [ # # ]: 0 : if (intr_vector > ICE_MAX_INTR_QUEUE_NUM) {
4260 : 0 : PMD_DRV_LOG(ERR, "At most %d intr queues supported",
4261 : : ICE_MAX_INTR_QUEUE_NUM);
4262 : 0 : return -ENOTSUP;
4263 : : }
4264 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
4265 : : return -1;
4266 : : }
4267 : :
4268 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
4269 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, NULL,
4270 : 0 : dev->data->nb_rx_queues)) {
4271 : 0 : PMD_DRV_LOG(ERR,
4272 : : "Failed to allocate %d rx_queues intr_vec",
4273 : : dev->data->nb_rx_queues);
4274 : 0 : return -ENOMEM;
4275 : : }
4276 : : }
4277 : :
4278 : : /* Map queues with MSIX interrupt */
4279 : 0 : vsi->nb_used_qps = dev->data->nb_rx_queues;
4280 : 0 : ice_vsi_queues_bind_intr(vsi);
4281 : :
4282 : : /* Enable interrupts for all the queues */
4283 : 0 : ice_vsi_enable_queues_intr(vsi);
4284 : :
4285 : 0 : rte_intr_enable(intr_handle);
4286 : :
4287 : 0 : return 0;
4288 : : }
4289 : :
4290 : : static int
4291 : 0 : ice_get_link_info_safe(struct ice_pf *pf, bool ena_lse,
4292 : : struct ice_link_status *link)
4293 : : {
4294 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
4295 : : int ret;
4296 : :
4297 : 0 : rte_spinlock_lock(&pf->link_lock);
4298 : :
4299 : 0 : ret = ice_aq_get_link_info(hw->port_info, ena_lse, link, NULL);
4300 : :
4301 : : rte_spinlock_unlock(&pf->link_lock);
4302 : :
4303 : 0 : return ret;
4304 : : }
4305 : :
4306 : : static void
4307 : 0 : ice_get_init_link_status(struct rte_eth_dev *dev)
4308 : : {
4309 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4310 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
4311 : : struct ice_link_status link_status;
4312 : : int ret;
4313 : :
4314 : 0 : ret = ice_get_link_info_safe(pf, enable_lse, &link_status);
4315 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4316 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
4317 : 0 : pf->init_link_up = false;
4318 : 0 : return;
4319 : : }
4320 : :
4321 [ # # ]: 0 : if (link_status.link_info & ICE_AQ_LINK_UP)
4322 : 0 : pf->init_link_up = true;
4323 : : else
4324 : 0 : pf->init_link_up = false;
4325 : : }
4326 : :
4327 : : static int
4328 : 0 : ice_pps_out_cfg(struct ice_hw *hw, int idx, int timer)
4329 : : {
4330 : : uint64_t current_time, start_time;
4331 : : uint32_t hi, lo, lo2, func, val;
4332 : :
4333 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4334 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
4335 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4336 : :
4337 [ # # ]: 0 : if (lo2 < lo) {
4338 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
4339 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
4340 : : }
4341 : :
4342 : 0 : current_time = ((uint64_t)hi << 32) | lo;
4343 : :
4344 : 0 : start_time = (current_time + NSEC_PER_SEC) /
4345 : : NSEC_PER_SEC * NSEC_PER_SEC;
4346 : 0 : start_time = start_time - PPS_OUT_DELAY_NS;
4347 : :
4348 : 0 : func = 8 + idx + timer * 4;
4349 : 0 : val = GLGEN_GPIO_CTL_PIN_DIR_M |
4350 : 0 : ((func << GLGEN_GPIO_CTL_PIN_FUNC_S) &
4351 : : GLGEN_GPIO_CTL_PIN_FUNC_M);
4352 : :
4353 : : /* Write clkout with half of period value */
4354 : 0 : ICE_WRITE_REG(hw, GLTSYN_CLKO(idx, timer), NSEC_PER_SEC / 2);
4355 : :
4356 : : /* Write TARGET time register */
4357 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_L(idx, timer), start_time & 0xffffffff);
4358 : 0 : ICE_WRITE_REG(hw, GLTSYN_TGT_H(idx, timer), start_time >> 32);
4359 : :
4360 : : /* Write AUX_OUT register */
4361 : 0 : ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(idx, timer),
4362 : : GLTSYN_AUX_OUT_0_OUT_ENA_M | GLTSYN_AUX_OUT_0_OUTMOD_M);
4363 : :
4364 : : /* Write GPIO CTL register */
4365 : 0 : ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(idx), val);
4366 : :
4367 : 0 : return 0;
4368 : : }
4369 : :
4370 : : static int
4371 : 0 : ice_dev_start(struct rte_eth_dev *dev)
4372 : : {
4373 : 0 : struct rte_eth_dev_data *data = dev->data;
4374 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4375 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4376 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4377 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4378 : : struct ice_adapter *ad =
4379 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
4380 : : uint16_t nb_rxq = 0;
4381 : : uint16_t nb_txq, i;
4382 : : uint16_t max_frame_size;
4383 : : int mask, ret;
4384 : 0 : uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
4385 : 0 : uint32_t pin_idx = ad->devargs.pin_idx;
4386 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
4387 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
4388 : :
4389 : : /* choose vector Tx function before starting queues */
4390 : 0 : ice_set_tx_function(dev);
4391 : :
4392 : : /* program Tx queues' context in hardware */
4393 [ # # ]: 0 : for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
4394 : 0 : ret = ice_tx_queue_start(dev, nb_txq);
4395 [ # # ]: 0 : if (ret) {
4396 : 0 : PMD_DRV_LOG(ERR, "fail to start Tx queue %u", nb_txq);
4397 : 0 : goto tx_err;
4398 : : }
4399 : : }
4400 : :
4401 : : /* program Rx queues' context in hardware*/
4402 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < data->nb_rx_queues; nb_rxq++) {
4403 : 0 : ret = ice_rx_queue_start(dev, nb_rxq);
4404 [ # # ]: 0 : if (ret) {
4405 : 0 : PMD_DRV_LOG(ERR, "fail to start Rx queue %u", nb_rxq);
4406 : 0 : goto rx_err;
4407 : : }
4408 : : }
4409 : :
4410 : : /* we need to choose Rx fn after queue start, when we know if we need scattered Rx */
4411 : 0 : ice_set_rx_function(dev);
4412 : :
4413 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
4414 : : RTE_ETH_VLAN_EXTEND_MASK;
4415 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
4416 : : mask |= RTE_ETH_QINQ_STRIP_MASK;
4417 : :
4418 : 0 : ret = ice_vlan_offload_set(dev, mask);
4419 [ # # ]: 0 : if (ret) {
4420 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
4421 : 0 : goto rx_err;
4422 : : }
4423 : :
4424 : : /* enable Rx interrupt and mapping Rx queue to interrupt vector */
4425 [ # # ]: 0 : if (ice_rxq_intr_setup(dev))
4426 : : return -EIO;
4427 : :
4428 : 0 : rte_intr_enable(pci_dev->intr_handle);
4429 : :
4430 : : /* Enable receiving broadcast packets and transmitting packets */
4431 : : ice_set_bit(ICE_PROMISC_BCAST_RX, pmask);
4432 : : ice_set_bit(ICE_PROMISC_BCAST_TX, pmask);
4433 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
4434 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
4435 : :
4436 : 0 : ret = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4437 [ # # ]: 0 : if (ret != ICE_SUCCESS)
4438 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
4439 : :
4440 : 0 : ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
4441 : : ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
4442 : : ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
4443 : : ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS |
4444 : : ICE_AQ_LINK_EVENT_SIGNAL_DETECT |
4445 : : ICE_AQ_LINK_EVENT_AN_COMPLETED |
4446 : : ICE_AQ_LINK_EVENT_PORT_TX_SUSPENDED)),
4447 : : NULL);
4448 [ # # ]: 0 : if (ret != ICE_SUCCESS)
4449 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
4450 : :
4451 : 0 : ice_get_init_link_status(dev);
4452 : :
4453 : : ice_dev_set_link_up(dev);
4454 : :
4455 : : /* Call get_link_info aq command to enable/disable LSE */
4456 : 0 : ice_link_update(dev, 1);
4457 : :
4458 : 0 : pf->adapter_stopped = false;
4459 : :
4460 : : /* Set the max frame size to default value*/
4461 [ # # ]: 0 : max_frame_size = pf->dev_data->mtu ?
4462 : : pf->dev_data->mtu + ICE_ETH_OVERHEAD :
4463 : : ICE_FRAME_SIZE_MAX;
4464 : :
4465 : : /* Set the max frame size to HW*/
4466 : 0 : ice_aq_set_mac_cfg(hw, max_frame_size, false, NULL);
4467 : :
4468 [ # # ]: 0 : if (ad->devargs.pps_out_ena) {
4469 : 0 : ret = ice_pps_out_cfg(hw, pin_idx, timer);
4470 [ # # ]: 0 : if (ret) {
4471 : 0 : PMD_DRV_LOG(ERR, "Fail to configure 1pps out");
4472 : 0 : goto rx_err;
4473 : : }
4474 : : }
4475 : :
4476 [ # # ]: 0 : if (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
4477 : 0 : ice_timesync_enable(dev);
4478 : 0 : ad->txpp_ena = 1;
4479 : : }
4480 : :
4481 : : return 0;
4482 : :
4483 : : /* stop the started queues if failed to start all queues */
4484 : 0 : rx_err:
4485 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
4486 : 0 : ice_rx_queue_stop(dev, i);
4487 : 0 : tx_err:
4488 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
4489 : 0 : ice_tx_queue_stop(dev, i);
4490 : :
4491 : : return -EIO;
4492 : : }
4493 : :
4494 : : static int
4495 : 0 : ice_dev_reset(struct rte_eth_dev *dev)
4496 : : {
4497 : : int ret;
4498 : :
4499 [ # # ]: 0 : if (dev->data->sriov.active)
4500 : : return -ENOTSUP;
4501 : :
4502 : : ret = ice_dev_uninit(dev);
4503 : : if (ret) {
4504 : : PMD_INIT_LOG(ERR, "failed to uninit device, status = %d", ret);
4505 : : return -ENXIO;
4506 : : }
4507 : :
4508 : 0 : ret = ice_dev_init(dev);
4509 [ # # ]: 0 : if (ret) {
4510 : 0 : PMD_INIT_LOG(ERR, "failed to init device, status = %d", ret);
4511 : 0 : return -ENXIO;
4512 : : }
4513 : :
4514 : : return 0;
4515 : : }
4516 : :
4517 : : static int
4518 : 0 : ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
4519 : : {
4520 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4521 : : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4522 : 0 : struct ice_vsi *vsi = pf->main_vsi;
4523 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
4524 : 0 : bool is_safe_mode = pf->adapter->is_safe_mode;
4525 : : u64 phy_type_low;
4526 : : u64 phy_type_high;
4527 : :
4528 : 0 : dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
4529 : 0 : dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
4530 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
4531 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
4532 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
4533 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
4534 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - ICE_ETH_OVERHEAD;
4535 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
4536 : :
4537 : 0 : dev_info->rx_offload_capa =
4538 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
4539 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
4540 : : RTE_ETH_RX_OFFLOAD_SCATTER |
4541 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4542 : 0 : dev_info->tx_offload_capa =
4543 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
4544 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
4545 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
4546 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
4547 : 0 : dev_info->flow_type_rss_offloads = 0;
4548 : :
4549 [ # # ]: 0 : if (!is_safe_mode) {
4550 : 0 : dev_info->rx_offload_capa |=
4551 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
4552 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
4553 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
4554 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
4555 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
4556 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
4557 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
4558 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
4559 : : RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
4560 : 0 : dev_info->tx_offload_capa |=
4561 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
4562 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
4563 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
4564 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
4565 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
4566 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
4567 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
4568 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
4569 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
4570 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
4571 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
4572 : : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP;
4573 : 0 : dev_info->flow_type_rss_offloads |= ICE_RSS_OFFLOAD_ALL;
4574 : : }
4575 : :
4576 : 0 : dev_info->rx_queue_offload_capa = RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
4577 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
4578 : :
4579 : 0 : dev_info->reta_size = pf->hash_lut_size;
4580 : 0 : dev_info->hash_key_size = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
4581 : :
4582 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
4583 : : .rx_thresh = {
4584 : : .pthresh = ICE_DEFAULT_RX_PTHRESH,
4585 : : .hthresh = ICE_DEFAULT_RX_HTHRESH,
4586 : : .wthresh = ICE_DEFAULT_RX_WTHRESH,
4587 : : },
4588 : : .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
4589 : : .rx_drop_en = 0,
4590 : : .offloads = 0,
4591 : : };
4592 : :
4593 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
4594 : : .tx_thresh = {
4595 : : .pthresh = ICE_DEFAULT_TX_PTHRESH,
4596 : : .hthresh = ICE_DEFAULT_TX_HTHRESH,
4597 : : .wthresh = ICE_DEFAULT_TX_WTHRESH,
4598 : : },
4599 : : .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
4600 : : .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
4601 : : .offloads = 0,
4602 : : };
4603 : :
4604 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
4605 : : .nb_max = ICE_MAX_RING_DESC,
4606 : : .nb_min = ICE_MIN_RING_DESC,
4607 : : .nb_align = ICE_ALIGN_RING_DESC,
4608 : : };
4609 : :
4610 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
4611 : : .nb_max = ICE_MAX_RING_DESC,
4612 : : .nb_min = ICE_MIN_RING_DESC,
4613 : : .nb_align = ICE_ALIGN_RING_DESC,
4614 : : .nb_mtu_seg_max = ICE_TX_MTU_SEG_MAX,
4615 : : .nb_seg_max = ICE_MAX_RING_DESC,
4616 : : };
4617 : :
4618 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M |
4619 : : RTE_ETH_LINK_SPEED_100M |
4620 : : RTE_ETH_LINK_SPEED_1G |
4621 : : RTE_ETH_LINK_SPEED_2_5G |
4622 : : RTE_ETH_LINK_SPEED_5G |
4623 : : RTE_ETH_LINK_SPEED_10G |
4624 : : RTE_ETH_LINK_SPEED_20G |
4625 : : RTE_ETH_LINK_SPEED_25G;
4626 : :
4627 : 0 : phy_type_low = hw->port_info->phy.phy_type_low;
4628 : 0 : phy_type_high = hw->port_info->phy.phy_type_high;
4629 : :
4630 [ # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_50G(phy_type_low))
4631 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_50G;
4632 : :
4633 [ # # # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_100G_LOW(phy_type_low) ||
4634 [ # # ]: 0 : ICE_PHY_TYPE_SUPPORT_100G_HIGH(phy_type_high))
4635 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100G;
4636 : :
4637 [ # # ]: 0 : if (ICE_PHY_TYPE_SUPPORT_200G_HIGH(phy_type_high))
4638 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_200G;
4639 : :
4640 : 0 : dev_info->nb_rx_queues = dev->data->nb_rx_queues;
4641 : 0 : dev_info->nb_tx_queues = dev->data->nb_tx_queues;
4642 : :
4643 : 0 : dev_info->default_rxportconf.burst_size = ICE_RX_MAX_BURST;
4644 : 0 : dev_info->default_txportconf.burst_size = ICE_TX_MAX_BURST;
4645 : 0 : dev_info->default_rxportconf.nb_queues = 1;
4646 : 0 : dev_info->default_txportconf.nb_queues = 1;
4647 : 0 : dev_info->default_rxportconf.ring_size = ICE_BUF_SIZE_MIN;
4648 : 0 : dev_info->default_txportconf.ring_size = ICE_BUF_SIZE_MIN;
4649 : :
4650 : 0 : dev_info->rx_seg_capa.max_nseg = ICE_RX_MAX_NSEG;
4651 : 0 : dev_info->rx_seg_capa.multi_pools = 1;
4652 : 0 : dev_info->rx_seg_capa.offset_allowed = 0;
4653 : 0 : dev_info->rx_seg_capa.offset_align_log2 = 0;
4654 : :
4655 : 0 : return 0;
4656 : : }
4657 : :
4658 : : static inline int
4659 : 0 : ice_atomic_read_link_status(struct rte_eth_dev *dev,
4660 : : struct rte_eth_link *link)
4661 : : {
4662 : : struct rte_eth_link *dst = link;
4663 : 0 : struct rte_eth_link *src = &dev->data->dev_link;
4664 : :
4665 : : /* NOTE: review for potential ordering optimization */
4666 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit((uint64_t __rte_atomic *)dst,
4667 : : (uint64_t *)dst, *(uint64_t *)src,
4668 : : rte_memory_order_seq_cst, rte_memory_order_seq_cst))
4669 : 0 : return -1;
4670 : :
4671 : : return 0;
4672 : : }
4673 : :
4674 : : static inline int
4675 : 0 : ice_atomic_write_link_status(struct rte_eth_dev *dev,
4676 : : struct rte_eth_link *link)
4677 : : {
4678 : 0 : struct rte_eth_link *dst = &dev->data->dev_link;
4679 : : struct rte_eth_link *src = link;
4680 : :
4681 : : /* NOTE: review for potential ordering optimization */
4682 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit((uint64_t __rte_atomic *)dst,
4683 : : (uint64_t *)dst, *(uint64_t *)src,
4684 : : rte_memory_order_seq_cst, rte_memory_order_seq_cst))
4685 : 0 : return -1;
4686 : :
4687 : : return 0;
4688 : : }
4689 : :
4690 : : static int
4691 : 0 : ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
4692 : : {
4693 : : #define CHECK_INTERVAL 50 /* 50ms */
4694 : : #define MAX_REPEAT_TIME 40 /* 2s (40 * 50ms) in total */
4695 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4696 : : struct ice_link_status link_status;
4697 : : struct rte_eth_link link, old;
4698 : : int status;
4699 : : unsigned int rep_cnt = MAX_REPEAT_TIME;
4700 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
4701 : :
4702 : : memset(&link, 0, sizeof(link));
4703 : : memset(&old, 0, sizeof(old));
4704 : : memset(&link_status, 0, sizeof(link_status));
4705 : 0 : ice_atomic_read_link_status(dev, &old);
4706 : :
4707 : : do {
4708 : : /* Get link status information from hardware */
4709 : 0 : status = ice_get_link_info_safe(pf, enable_lse, &link_status);
4710 [ # # ]: 0 : if (status != ICE_SUCCESS) {
4711 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4712 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4713 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
4714 : 0 : goto out;
4715 : : }
4716 : :
4717 : 0 : link.link_status = link_status.link_info & ICE_AQ_LINK_UP;
4718 [ # # # # ]: 0 : if (!wait_to_complete || link.link_status)
4719 : : break;
4720 : :
4721 : : rte_delay_ms(CHECK_INTERVAL);
4722 [ # # ]: 0 : } while (--rep_cnt);
4723 : :
4724 [ # # ]: 0 : if (!link.link_status)
4725 : 0 : goto out;
4726 : :
4727 : : /* Full-duplex operation at all supported speeds */
4728 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4729 : :
4730 : : /* Parse the link status */
4731 [ # # # # : 0 : switch (link_status.link_speed) {
# # # # #
# # # #
# ]
4732 : 0 : case ICE_AQ_LINK_SPEED_10MB:
4733 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10M;
4734 : 0 : break;
4735 : 0 : case ICE_AQ_LINK_SPEED_100MB:
4736 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4737 : 0 : break;
4738 : 0 : case ICE_AQ_LINK_SPEED_1000MB:
4739 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_1G;
4740 : 0 : break;
4741 : 0 : case ICE_AQ_LINK_SPEED_2500MB:
4742 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_2_5G;
4743 : 0 : break;
4744 : 0 : case ICE_AQ_LINK_SPEED_5GB:
4745 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_5G;
4746 : 0 : break;
4747 : 0 : case ICE_AQ_LINK_SPEED_10GB:
4748 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
4749 : 0 : break;
4750 : 0 : case ICE_AQ_LINK_SPEED_20GB:
4751 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_20G;
4752 : 0 : break;
4753 : 0 : case ICE_AQ_LINK_SPEED_25GB:
4754 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_25G;
4755 : 0 : break;
4756 : 0 : case ICE_AQ_LINK_SPEED_40GB:
4757 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_40G;
4758 : 0 : break;
4759 : 0 : case ICE_AQ_LINK_SPEED_50GB:
4760 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_50G;
4761 : 0 : break;
4762 : 0 : case ICE_AQ_LINK_SPEED_100GB:
4763 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100G;
4764 : 0 : break;
4765 : 0 : case ICE_AQ_LINK_SPEED_200GB:
4766 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_200G;
4767 : 0 : break;
4768 : 0 : case ICE_AQ_LINK_SPEED_UNKNOWN:
4769 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed");
4770 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
4771 : 0 : break;
4772 : 0 : default:
4773 : 0 : PMD_DRV_LOG(ERR, "None link speed");
4774 : : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
4775 : 0 : break;
4776 : : }
4777 : :
4778 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
4779 : : RTE_ETH_LINK_SPEED_FIXED);
4780 : :
4781 : 0 : out:
4782 : 0 : ice_atomic_write_link_status(dev, &link);
4783 [ # # ]: 0 : if (link.link_status == old.link_status)
4784 : 0 : return -1;
4785 : :
4786 : : return 0;
4787 : : }
4788 : :
4789 : : static inline uint16_t
4790 : 0 : ice_parse_link_speeds(uint16_t link_speeds)
4791 : : {
4792 : : uint16_t link_speed = ICE_AQ_LINK_SPEED_UNKNOWN;
4793 : :
4794 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_200G)
4795 : : link_speed |= ICE_AQ_LINK_SPEED_200GB;
4796 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100G)
4797 : 0 : link_speed |= ICE_AQ_LINK_SPEED_100GB;
4798 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_50G)
4799 : 0 : link_speed |= ICE_AQ_LINK_SPEED_50GB;
4800 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
4801 : 0 : link_speed |= ICE_AQ_LINK_SPEED_40GB;
4802 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
4803 : 0 : link_speed |= ICE_AQ_LINK_SPEED_25GB;
4804 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
4805 : 0 : link_speed |= ICE_AQ_LINK_SPEED_20GB;
4806 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
4807 : 0 : link_speed |= ICE_AQ_LINK_SPEED_10GB;
4808 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_5G)
4809 : 0 : link_speed |= ICE_AQ_LINK_SPEED_5GB;
4810 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_2_5G)
4811 : 0 : link_speed |= ICE_AQ_LINK_SPEED_2500MB;
4812 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
4813 : 0 : link_speed |= ICE_AQ_LINK_SPEED_1000MB;
4814 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
4815 : 0 : link_speed |= ICE_AQ_LINK_SPEED_100MB;
4816 : :
4817 : 0 : return link_speed;
4818 : : }
4819 : :
4820 : : static int
4821 : 0 : ice_apply_link_speed(struct rte_eth_dev *dev)
4822 : : {
4823 : : uint16_t speed;
4824 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4825 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
4826 : :
4827 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
4828 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_200G |
4829 : : RTE_ETH_LINK_SPEED_100G |
4830 : : RTE_ETH_LINK_SPEED_50G |
4831 : : RTE_ETH_LINK_SPEED_40G |
4832 : : RTE_ETH_LINK_SPEED_25G |
4833 : : RTE_ETH_LINK_SPEED_20G |
4834 : : RTE_ETH_LINK_SPEED_10G |
4835 : : RTE_ETH_LINK_SPEED_5G |
4836 : : RTE_ETH_LINK_SPEED_2_5G |
4837 : : RTE_ETH_LINK_SPEED_1G |
4838 : : RTE_ETH_LINK_SPEED_100M;
4839 : : }
4840 : 0 : speed = ice_parse_link_speeds(conf->link_speeds);
4841 : :
4842 : 0 : return ice_phy_conf_link(hw, speed, true);
4843 : : }
4844 : :
4845 : : static int
4846 : 0 : ice_phy_conf_link(struct ice_hw *hw,
4847 : : u16 link_speeds_bitmap,
4848 : : bool link_up)
4849 : : {
4850 : 0 : struct ice_aqc_set_phy_cfg_data cfg = { 0 };
4851 : 0 : struct ice_port_info *pi = hw->port_info;
4852 : : struct ice_aqc_get_phy_caps_data *phy_caps;
4853 : : int err;
4854 : 0 : u64 phy_type_low = 0;
4855 : 0 : u64 phy_type_high = 0;
4856 : :
4857 : : phy_caps = (struct ice_aqc_get_phy_caps_data *)
4858 : 0 : ice_malloc(hw, sizeof(*phy_caps));
4859 [ # # ]: 0 : if (!phy_caps)
4860 : : return ICE_ERR_NO_MEMORY;
4861 : :
4862 [ # # ]: 0 : if (!pi)
4863 : : return -EIO;
4864 : :
4865 : :
4866 [ # # ]: 0 : if (ice_fw_supports_report_dflt_cfg(pi->hw))
4867 : 0 : err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
4868 : : phy_caps, NULL);
4869 : : else
4870 : 0 : err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
4871 : : phy_caps, NULL);
4872 [ # # ]: 0 : if (err)
4873 : 0 : goto done;
4874 : :
4875 : 0 : ice_update_phy_type(&phy_type_low, &phy_type_high, link_speeds_bitmap);
4876 : :
4877 [ # # ]: 0 : if (link_speeds_bitmap == ICE_LINK_SPEED_UNKNOWN) {
4878 : 0 : cfg.phy_type_low = phy_caps->phy_type_low;
4879 : 0 : cfg.phy_type_high = phy_caps->phy_type_high;
4880 [ # # ]: 0 : } else if (phy_type_low & phy_caps->phy_type_low ||
4881 [ # # ]: 0 : phy_type_high & phy_caps->phy_type_high) {
4882 : 0 : cfg.phy_type_low = phy_type_low & phy_caps->phy_type_low;
4883 : 0 : cfg.phy_type_high = phy_type_high & phy_caps->phy_type_high;
4884 : : } else {
4885 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!");
4886 : 0 : cfg.phy_type_low = phy_caps->phy_type_low;
4887 : 0 : cfg.phy_type_high = phy_caps->phy_type_high;
4888 : : }
4889 : :
4890 : 0 : cfg.caps = phy_caps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
4891 : 0 : cfg.low_power_ctrl_an = phy_caps->low_power_ctrl_an;
4892 : 0 : cfg.eee_cap = phy_caps->eee_cap;
4893 : 0 : cfg.eeer_value = phy_caps->eeer_value;
4894 : 0 : cfg.link_fec_opt = phy_caps->link_fec_options;
4895 [ # # ]: 0 : if (link_up)
4896 : 0 : cfg.caps |= ICE_AQ_PHY_ENA_LINK;
4897 : : else
4898 : 0 : cfg.caps &= ~ICE_AQ_PHY_ENA_LINK;
4899 : :
4900 : 0 : err = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
4901 : :
4902 : 0 : done:
4903 : 0 : ice_free(hw, phy_caps);
4904 : 0 : return err;
4905 : : }
4906 : :
4907 : : static int
4908 : 0 : ice_dev_set_link_up(struct rte_eth_dev *dev)
4909 : : {
4910 : 0 : return ice_apply_link_speed(dev);
4911 : : }
4912 : :
4913 : : static int
4914 : 0 : ice_dev_set_link_down(struct rte_eth_dev *dev)
4915 : : {
4916 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4917 : : uint8_t speed = ICE_LINK_SPEED_UNKNOWN;
4918 : :
4919 : 0 : return ice_phy_conf_link(hw, speed, false);
4920 : : }
4921 : :
4922 : : static int
4923 : 0 : ice_dev_led_on(struct rte_eth_dev *dev)
4924 : : {
4925 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4926 : 0 : int status = ice_aq_set_port_id_led(hw->port_info, false, NULL);
4927 : :
4928 [ # # ]: 0 : return status == ICE_SUCCESS ? 0 : -ENOTSUP;
4929 : : }
4930 : :
4931 : : static int
4932 : 0 : ice_dev_led_off(struct rte_eth_dev *dev)
4933 : : {
4934 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4935 : 0 : int status = ice_aq_set_port_id_led(hw->port_info, true, NULL);
4936 : :
4937 [ # # ]: 0 : return status == ICE_SUCCESS ? 0 : -ENOTSUP;
4938 : : }
4939 : :
4940 : : static int
4941 : 0 : ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
4942 : : {
4943 : : /* mtu setting is forbidden if port is start */
4944 [ # # ]: 0 : if (dev->data->dev_started != 0) {
4945 : 0 : PMD_DRV_LOG(ERR,
4946 : : "port %d must be stopped before configuration",
4947 : : dev->data->port_id);
4948 : 0 : return -EBUSY;
4949 : : }
4950 : :
4951 : : return 0;
4952 : : }
4953 : :
4954 : 0 : static int ice_macaddr_set(struct rte_eth_dev *dev,
4955 : : struct rte_ether_addr *mac_addr)
4956 : : {
4957 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4958 : : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4959 [ # # ]: 0 : struct ice_vsi *vsi = pf->main_vsi;
4960 : : struct ice_mac_filter *f;
4961 : : uint8_t flags = 0;
4962 : : int ret;
4963 : :
4964 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
4965 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
4966 : 0 : return -EINVAL;
4967 : : }
4968 : :
4969 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
4970 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
4971 : : break;
4972 : : }
4973 : :
4974 [ # # ]: 0 : if (!f) {
4975 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
4976 : 0 : return -EIO;
4977 : : }
4978 : :
4979 : 0 : ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr);
4980 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4981 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
4982 : 0 : return -EIO;
4983 : : }
4984 : 0 : ret = ice_add_mac_filter(vsi, mac_addr);
4985 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
4986 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
4987 : 0 : return -EIO;
4988 : : }
4989 : : rte_ether_addr_copy(mac_addr, &pf->dev_addr);
4990 : :
4991 : : flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
4992 : 0 : ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL);
4993 [ # # ]: 0 : if (ret != ICE_SUCCESS)
4994 : 0 : PMD_DRV_LOG(ERR, "Failed to set manage mac");
4995 : :
4996 : : return 0;
4997 : : }
4998 : :
4999 : : /* Add a MAC address, and update filters */
5000 : : static int
5001 : 0 : ice_macaddr_add(struct rte_eth_dev *dev,
5002 : : struct rte_ether_addr *mac_addr,
5003 : : __rte_unused uint32_t index,
5004 : : __rte_unused uint32_t pool)
5005 : : {
5006 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5007 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5008 : : int ret;
5009 : :
5010 : 0 : ret = ice_add_mac_filter(vsi, mac_addr);
5011 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
5012 : 0 : PMD_DRV_LOG(ERR, "Failed to add MAC filter");
5013 : 0 : return -EINVAL;
5014 : : }
5015 : :
5016 : : return ICE_SUCCESS;
5017 : : }
5018 : :
5019 : : /* Remove a MAC address, and update filters */
5020 : : static void
5021 : 0 : ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
5022 : : {
5023 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5024 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5025 : : struct rte_eth_dev_data *data = dev->data;
5026 : : struct rte_ether_addr *macaddr;
5027 : : int ret;
5028 : :
5029 : 0 : macaddr = &data->mac_addrs[index];
5030 : 0 : ret = ice_remove_mac_filter(vsi, macaddr);
5031 [ # # ]: 0 : if (ret) {
5032 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
5033 : 0 : return;
5034 : : }
5035 : : }
5036 : :
5037 : : static int
5038 : 0 : ice_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
5039 : : {
5040 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5041 : 0 : struct ice_vlan vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, vlan_id);
5042 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5043 : : int ret;
5044 : :
5045 : 0 : PMD_INIT_FUNC_TRACE();
5046 : :
5047 : : /**
5048 : : * Vlan 0 is the generic filter for untagged packets
5049 : : * and can't be removed or added by user.
5050 : : */
5051 [ # # ]: 0 : if (vlan_id == 0)
5052 : : return 0;
5053 : :
5054 [ # # ]: 0 : if (on) {
5055 : 0 : ret = ice_add_vlan_filter(vsi, &vlan);
5056 [ # # ]: 0 : if (ret < 0) {
5057 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
5058 : 0 : return -EINVAL;
5059 : : }
5060 : : } else {
5061 : 0 : ret = ice_remove_vlan_filter(vsi, &vlan);
5062 [ # # ]: 0 : if (ret < 0) {
5063 : 0 : PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
5064 : 0 : return -EINVAL;
5065 : : }
5066 : : }
5067 : :
5068 : : return 0;
5069 : : }
5070 : :
5071 : : /* In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are
5072 : : * based on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8)
5073 : : * doesn't matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
5074 : : * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
5075 : : *
5076 : : * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
5077 : : * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
5078 : : * traffic in SVM, since the VLAN TPID isn't part of filtering.
5079 : : *
5080 : : * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
5081 : : * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
5082 : : * part of filtering.
5083 : : */
5084 : : static int
5085 : 0 : ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
5086 : : {
5087 : : struct ice_vlan vlan;
5088 : : int err;
5089 : :
5090 : 0 : vlan = ICE_VLAN(0, 0);
5091 : 0 : err = ice_add_vlan_filter(vsi, &vlan);
5092 [ # # ]: 0 : if (err) {
5093 : 0 : PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0");
5094 : 0 : return err;
5095 : : }
5096 : :
5097 : : /* in SVM both VLAN 0 filters are identical */
5098 [ # # ]: 0 : if (!ice_is_dvm_ena(&vsi->adapter->hw))
5099 : : return 0;
5100 : :
5101 : 0 : vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
5102 : 0 : err = ice_add_vlan_filter(vsi, &vlan);
5103 [ # # ]: 0 : if (err) {
5104 : 0 : PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0 in double VLAN mode");
5105 : 0 : return err;
5106 : : }
5107 : :
5108 : : return 0;
5109 : : }
5110 : :
5111 : : /*
5112 : : * Delete the VLAN 0 filters in the same manner that they were added in
5113 : : * ice_vsi_add_vlan_zero.
5114 : : */
5115 : : static int
5116 : 0 : ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
5117 : : {
5118 : : struct ice_vlan vlan;
5119 : : int err;
5120 : :
5121 : 0 : vlan = ICE_VLAN(0, 0);
5122 : 0 : err = ice_remove_vlan_filter(vsi, &vlan);
5123 [ # # ]: 0 : if (err) {
5124 : 0 : PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0");
5125 : 0 : return err;
5126 : : }
5127 : :
5128 : : /* in SVM both VLAN 0 filters are identical */
5129 [ # # ]: 0 : if (!ice_is_dvm_ena(&vsi->adapter->hw))
5130 : : return 0;
5131 : :
5132 : 0 : vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
5133 : 0 : err = ice_remove_vlan_filter(vsi, &vlan);
5134 [ # # ]: 0 : if (err) {
5135 : 0 : PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0 in double VLAN mode");
5136 : 0 : return err;
5137 : : }
5138 : :
5139 : : return 0;
5140 : : }
5141 : :
5142 : : /* Configure vlan filter on or off */
5143 : : static int
5144 : 0 : ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
5145 : : {
5146 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5147 : : struct ice_vsi_ctx ctxt;
5148 : : uint8_t sw_flags2;
5149 : : int ret = 0;
5150 : :
5151 : : sw_flags2 = ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
5152 : :
5153 [ # # ]: 0 : if (on)
5154 : 0 : vsi->info.sw_flags2 |= sw_flags2;
5155 : : else
5156 : 0 : vsi->info.sw_flags2 &= ~sw_flags2;
5157 : :
5158 : 0 : vsi->info.sw_id = hw->port_info->sw_id;
5159 [ # # ]: 0 : (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5160 : 0 : ctxt.info.valid_sections =
5161 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
5162 : : ICE_AQ_VSI_PROP_SECURITY_VALID);
5163 : 0 : ctxt.vsi_num = vsi->vsi_id;
5164 : :
5165 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5166 [ # # ]: 0 : if (ret) {
5167 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
5168 : : on ? "enable" : "disable");
5169 : 0 : return -EINVAL;
5170 : : } else {
5171 : 0 : vsi->info.valid_sections |=
5172 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
5173 : : ICE_AQ_VSI_PROP_SECURITY_VALID);
5174 : : }
5175 : :
5176 : : /* consist with other drivers, allow untagged packet when vlan filter on */
5177 [ # # ]: 0 : if (on)
5178 : 0 : ret = ice_vsi_add_vlan_zero(vsi);
5179 : : else
5180 : 0 : ret = ice_vsi_del_vlan_zero(vsi);
5181 : :
5182 : : return 0;
5183 : : }
5184 : :
5185 : : /* Manage VLAN stripping for the VSI for Rx */
5186 : : static int
5187 : 0 : ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
5188 : : {
5189 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5190 : : struct ice_vsi_ctx ctxt;
5191 : : int status, err = 0;
5192 : :
5193 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
5194 : : * on this VSI
5195 : : */
5196 [ # # ]: 0 : if (vsi->info.port_based_inner_vlan)
5197 : : return 0;
5198 : :
5199 : : memset(&ctxt, 0, sizeof(ctxt));
5200 : :
5201 [ # # ]: 0 : if (ena)
5202 : : /* Strip VLAN tag from Rx packet and put it in the desc */
5203 : : ctxt.info.inner_vlan_flags =
5204 : : ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
5205 : : else
5206 : : /* Disable stripping. Leave tag in packet */
5207 : 0 : ctxt.info.inner_vlan_flags =
5208 : : ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
5209 : :
5210 : : /* Allow all packets untagged/tagged */
5211 : 0 : ctxt.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
5212 : :
5213 : 0 : ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5214 : :
5215 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5216 [ # # ]: 0 : if (status) {
5217 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan stripping",
5218 : : ena ? "enable" : "disable");
5219 : : err = -EIO;
5220 : : } else {
5221 : 0 : vsi->info.inner_vlan_flags = ctxt.info.inner_vlan_flags;
5222 : : }
5223 : :
5224 : : return err;
5225 : : }
5226 : :
5227 : : static int
5228 : : ice_vsi_ena_inner_stripping(struct ice_vsi *vsi)
5229 : : {
5230 : 0 : return ice_vsi_manage_vlan_stripping(vsi, true);
5231 : : }
5232 : :
5233 : : static int
5234 : : ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
5235 : : {
5236 : 0 : return ice_vsi_manage_vlan_stripping(vsi, false);
5237 : : }
5238 : :
5239 : : /**
5240 : : * tpid_to_vsi_outer_vlan_type - convert from TPID to VSI context based tag_type
5241 : : * @tpid: tpid used to translate into VSI context based tag_type
5242 : : * @tag_type: output variable to hold the VSI context based tag type
5243 : : */
5244 : : static int tpid_to_vsi_outer_vlan_type(u16 tpid, u8 *tag_type)
5245 : : {
5246 [ # # # # : 0 : switch (tpid) {
# # # # ]
5247 : : case RTE_ETHER_TYPE_VLAN:
5248 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_8100;
5249 : : break;
5250 : : case RTE_ETHER_TYPE_QINQ:
5251 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_STAG;
5252 : : break;
5253 : : case RTE_ETHER_TYPE_QINQ1:
5254 : : *tag_type = ICE_AQ_VSI_OUTER_TAG_VLAN_9100;
5255 : : break;
5256 : : default:
5257 : : *tag_type = 0;
5258 : : return -EINVAL;
5259 : : }
5260 : :
5261 : : return 0;
5262 : : }
5263 : :
5264 : : /**
5265 : : * ice_is_supported_port_vlan_proto - make sure the vlan_proto is supported
5266 : : * @hw: hardware structure used to check the VLAN mode
5267 : : * @vlan_proto: VLAN TPID being checked
5268 : : *
5269 : : * If the device is configured in Double VLAN Mode (DVM), it supports three
5270 : : * types: RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ1 and RTE_ETHER_TYPE_QINQ. If the device is
5271 : : * configured in Single VLAN Mode (SVM), then only RTE_ETHER_TYPE_VLAN is supported.
5272 : : */
5273 : : static bool
5274 : 0 : ice_is_supported_port_vlan_proto(struct ice_hw *hw, u16 vlan_proto)
5275 : : {
5276 : : bool is_supported = false;
5277 : :
5278 [ # # # # ]: 0 : switch (vlan_proto) {
5279 : 0 : case RTE_ETHER_TYPE_VLAN:
5280 : : is_supported = true;
5281 : 0 : break;
5282 : 0 : case RTE_ETHER_TYPE_QINQ:
5283 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
5284 : : is_supported = true;
5285 : : break;
5286 : 0 : case RTE_ETHER_TYPE_QINQ1:
5287 [ # # ]: 0 : if (ice_is_dvm_ena(hw))
5288 : : is_supported = true;
5289 : : break;
5290 : : }
5291 : :
5292 : 0 : return is_supported;
5293 : : }
5294 : :
5295 : : /**
5296 : : * ice_vsi_ena_outer_stripping - enable outer VLAN stripping
5297 : : * @vsi: VSI to configure
5298 : : * @tpid: TPID to enable outer VLAN stripping for
5299 : : *
5300 : : * Enable outer VLAN stripping via VSI context. This function should only be
5301 : : * used if DVM is supported.
5302 : : *
5303 : : * Since the VSI context only supports a single TPID for insertion and
5304 : : * stripping, setting the TPID for stripping will affect the TPID for insertion.
5305 : : * Callers need to be aware of this limitation.
5306 : : *
5307 : : * Only modify outer VLAN stripping settings and the VLAN TPID. Outer VLAN
5308 : : * insertion settings are unmodified.
5309 : : *
5310 : : * This enables hardware to strip a VLAN tag with the specified TPID to be
5311 : : * stripped from the packet and placed in the receive descriptor.
5312 : : */
5313 : 0 : static int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi, u16 tpid)
5314 : : {
5315 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5316 : : struct ice_vsi_ctx ctxt;
5317 : : int status, err = 0;
5318 : : u8 tag_type;
5319 : :
5320 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
5321 : : * on this VSI
5322 : : */
5323 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
5324 : : return 0;
5325 : :
5326 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
5327 : : return -EINVAL;
5328 : :
5329 : : memset(&ctxt, 0, sizeof(ctxt));
5330 : :
5331 : 0 : ctxt.info.valid_sections =
5332 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
5333 : : /* clear current outer VLAN strip settings */
5334 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
5335 : : ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
5336 : 0 : ctxt.info.outer_vlan_flags |=
5337 : : (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
5338 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
5339 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
5340 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
5341 : :
5342 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5343 [ # # ]: 0 : if (status) {
5344 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
5345 : : err = -EIO;
5346 : : } else {
5347 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
5348 : : }
5349 : :
5350 : : return err;
5351 : : }
5352 : :
5353 : : static int
5354 : 0 : ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
5355 : : {
5356 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5357 : : struct ice_vsi_ctx ctxt;
5358 : : int status, err = 0;
5359 : :
5360 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
5361 : : return 0;
5362 : :
5363 : : memset(&ctxt, 0, sizeof(ctxt));
5364 : :
5365 : 0 : ctxt.info.valid_sections =
5366 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
5367 : : /* clear current outer VLAN strip settings */
5368 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
5369 : : ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
5370 : 0 : ctxt.info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
5371 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
5372 : :
5373 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5374 [ # # ]: 0 : if (status) {
5375 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to disable outer VLAN stripping");
5376 : : err = -EIO;
5377 : : } else {
5378 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
5379 : : }
5380 : :
5381 : : return err;
5382 : : }
5383 : :
5384 : : static int
5385 : 0 : ice_vsi_config_vlan_stripping(struct ice_vsi *vsi, bool ena)
5386 : : {
5387 : : int ret;
5388 : :
5389 [ # # ]: 0 : if (ena)
5390 : : ret = ice_vsi_ena_inner_stripping(vsi);
5391 : : else
5392 : : ret = ice_vsi_dis_inner_stripping(vsi);
5393 : :
5394 : 0 : return ret;
5395 : : }
5396 : :
5397 : : /* Configure outer vlan stripping on or off in QinQ mode */
5398 : : static int
5399 : 0 : ice_vsi_config_outer_vlan_stripping(struct ice_vsi *vsi, bool on)
5400 : : {
5401 : 0 : uint16_t outer_ethertype = vsi->adapter->pf.outer_ethertype;
5402 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5403 : :
5404 [ # # ]: 0 : if (vsi->vsi_id >= ICE_MAX_NUM_VSIS) {
5405 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
5406 : 0 : return -EINVAL;
5407 : : }
5408 : :
5409 [ # # ]: 0 : if (!ice_is_dvm_ena(hw)) {
5410 : 0 : PMD_DRV_LOG(ERR, "Single VLAN mode (SVM) does not support qinq");
5411 : 0 : return -EOPNOTSUPP;
5412 : : }
5413 : :
5414 : : return on ?
5415 [ # # ]: 0 : ice_vsi_ena_outer_stripping(vsi, outer_ethertype) :
5416 : 0 : ice_vsi_dis_outer_stripping(vsi);
5417 : : }
5418 : :
5419 : : static int
5420 : 0 : ice_vlan_offload_set(struct rte_eth_dev *dev, int mask)
5421 : : {
5422 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5423 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5424 : : struct rte_eth_rxmode *rxmode;
5425 : :
5426 : : rxmode = &dev->data->dev_conf.rxmode;
5427 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
5428 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
5429 : 0 : ice_vsi_config_vlan_filter(vsi, true);
5430 : : else
5431 : 0 : ice_vsi_config_vlan_filter(vsi, false);
5432 : : }
5433 : :
5434 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5435 [ # # ]: 0 : if (!ice_is_dvm_ena(hw)) {
5436 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
5437 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
5438 : 0 : ice_vsi_config_vlan_stripping(vsi, true);
5439 : : else
5440 : 0 : ice_vsi_config_vlan_stripping(vsi, false);
5441 : : }
5442 : :
5443 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
5444 : 0 : PMD_DRV_LOG(ERR, "Single VLAN mode (SVM) does not support qinq");
5445 : 0 : return -ENOTSUP;
5446 : : }
5447 : : } else {
5448 [ # # ]: 0 : if ((mask & RTE_ETH_VLAN_STRIP_MASK) |
5449 : : (mask & RTE_ETH_QINQ_STRIP_MASK)) {
5450 [ # # ]: 0 : if (rxmode->offloads & (RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
5451 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP))
5452 : 0 : ice_vsi_config_outer_vlan_stripping(vsi, true);
5453 : : else
5454 : 0 : ice_vsi_config_outer_vlan_stripping(vsi, false);
5455 : : }
5456 : :
5457 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
5458 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
5459 : 0 : ice_vsi_config_vlan_stripping(vsi, true);
5460 : : else
5461 : 0 : ice_vsi_config_vlan_stripping(vsi, false);
5462 : : }
5463 : : }
5464 : :
5465 : : return 0;
5466 : : }
5467 : :
5468 : : static int
5469 : 0 : ice_get_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
5470 : : {
5471 : : struct ice_aq_get_set_rss_lut_params lut_params;
5472 : 0 : struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
5473 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5474 : : int ret;
5475 : :
5476 [ # # ]: 0 : if (!lut)
5477 : : return -EINVAL;
5478 : :
5479 [ # # ]: 0 : if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
5480 : 0 : lut_params.vsi_handle = vsi->idx;
5481 : 0 : lut_params.lut_size = lut_size;
5482 [ # # ]: 0 : lut_params.lut_type = (vsi->global_lut_allocated) ?
5483 : : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
5484 : 0 : lut_params.lut = lut;
5485 [ # # ]: 0 : lut_params.global_lut_id = (vsi->global_lut_allocated) ? vsi->global_lut_id : 0;
5486 : 0 : ret = ice_aq_get_rss_lut(hw, &lut_params);
5487 [ # # ]: 0 : if (ret) {
5488 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
5489 : 0 : return -EINVAL;
5490 : : }
5491 : : } else {
5492 : : uint64_t *lut_dw = (uint64_t *)lut;
5493 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
5494 : :
5495 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
5496 : 0 : lut_dw[i] = ICE_READ_REG(hw, PFQF_HLUT(i));
5497 : : }
5498 : :
5499 : : return 0;
5500 : : }
5501 : :
5502 : : static int
5503 : 0 : ice_set_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
5504 : : {
5505 : : struct ice_aq_get_set_rss_lut_params lut_params;
5506 : : struct ice_pf *pf;
5507 : : struct ice_hw *hw;
5508 : : int ret;
5509 : :
5510 [ # # ]: 0 : if (!vsi || !lut)
5511 : : return -EINVAL;
5512 : :
5513 : 0 : pf = ICE_VSI_TO_PF(vsi);
5514 : 0 : hw = ICE_VSI_TO_HW(vsi);
5515 : :
5516 [ # # ]: 0 : if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
5517 : 0 : lut_params.vsi_handle = vsi->idx;
5518 : 0 : lut_params.lut_size = lut_size;
5519 [ # # ]: 0 : lut_params.lut_type = (vsi->global_lut_allocated) ?
5520 : : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_GLOBAL : ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
5521 : 0 : lut_params.lut = lut;
5522 [ # # ]: 0 : lut_params.global_lut_id = (vsi->global_lut_allocated) ? vsi->global_lut_id : 0;
5523 : 0 : ret = ice_aq_set_rss_lut(hw, &lut_params);
5524 [ # # ]: 0 : if (ret) {
5525 : 0 : PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
5526 : 0 : return -EINVAL;
5527 : : }
5528 : : } else {
5529 : : uint64_t *lut_dw = (uint64_t *)lut;
5530 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
5531 : :
5532 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
5533 : 0 : ICE_WRITE_REG(hw, PFQF_HLUT(i), lut_dw[i]);
5534 : :
5535 : 0 : ice_flush(hw);
5536 : : }
5537 : :
5538 : : return 0;
5539 : : }
5540 : :
5541 : : static int
5542 : 0 : ice_rss_reta_update(struct rte_eth_dev *dev,
5543 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5544 : : uint16_t reta_size)
5545 : : {
5546 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5547 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
5548 : : uint16_t idx, shift;
5549 : 0 : uint8_t lut[ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K] = {0};
5550 : : int ret;
5551 : :
5552 : 0 : if (reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128 &&
5553 [ # # # # ]: 0 : reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512 &&
5554 : : reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) {
5555 : 0 : PMD_DRV_LOG(ERR,
5556 : : "The size of hash lookup table configured (%d)"
5557 : : "doesn't match the number hardware can "
5558 : : "supported (128, 512, 2048)",
5559 : : reta_size);
5560 : 0 : return -EINVAL;
5561 : : }
5562 : :
5563 : : /* It MUST use the current LUT size to get the RSS lookup table,
5564 : : * otherwise if will fail with -100 error code.
5565 : : */
5566 : 0 : ret = ice_get_rss_lut(pf->main_vsi, lut, lut_size);
5567 [ # # ]: 0 : if (ret)
5568 : : return ret;
5569 : :
5570 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
5571 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5572 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5573 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
5574 : 0 : lut[i] = reta_conf[idx].reta[shift];
5575 : : }
5576 : 0 : ret = ice_set_rss_lut(pf->main_vsi, lut, reta_size);
5577 [ # # ]: 0 : if (ret == 0 && lut_size != reta_size) {
5578 : 0 : PMD_DRV_LOG(INFO,
5579 : : "The size of hash lookup table is changed from (%d) to (%d)",
5580 : : lut_size, reta_size);
5581 : 0 : pf->hash_lut_size = reta_size;
5582 : : }
5583 : :
5584 : : return 0;
5585 : : }
5586 : :
5587 : : static int
5588 : 0 : ice_rss_reta_query(struct rte_eth_dev *dev,
5589 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5590 : : uint16_t reta_size)
5591 : : {
5592 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5593 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
5594 : : uint16_t idx, shift;
5595 : 0 : uint8_t lut[ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K] = {0};
5596 : : int ret;
5597 : :
5598 [ # # ]: 0 : if (reta_size != lut_size) {
5599 : 0 : PMD_DRV_LOG(ERR,
5600 : : "The size of hash lookup table configured (%d)"
5601 : : "doesn't match the number hardware can "
5602 : : "supported (%d)",
5603 : : reta_size, lut_size);
5604 : 0 : return -EINVAL;
5605 : : }
5606 : :
5607 : 0 : ret = ice_get_rss_lut(pf->main_vsi, lut, reta_size);
5608 [ # # ]: 0 : if (ret)
5609 : : return ret;
5610 : :
5611 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
5612 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5613 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5614 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
5615 : 0 : reta_conf[idx].reta[shift] = lut[i];
5616 : : }
5617 : :
5618 : : return 0;
5619 : : }
5620 : :
5621 : : static int
5622 : 0 : ice_set_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t key_len)
5623 : : {
5624 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5625 : : int ret = 0;
5626 : :
5627 [ # # ]: 0 : if (!key || key_len == 0) {
5628 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
5629 : 0 : return 0;
5630 [ # # ]: 0 : } else if (key_len != (VSIQF_HKEY_MAX_INDEX + 1) *
5631 : : sizeof(uint32_t)) {
5632 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
5633 : 0 : return -EINVAL;
5634 : : }
5635 : :
5636 : : struct ice_aqc_get_set_rss_keys *key_dw =
5637 : : (struct ice_aqc_get_set_rss_keys *)key;
5638 : :
5639 : 0 : ret = ice_aq_set_rss_key(hw, vsi->idx, key_dw);
5640 [ # # ]: 0 : if (ret) {
5641 : 0 : PMD_DRV_LOG(ERR, "Failed to configure RSS key via AQ");
5642 : : ret = -EINVAL;
5643 : : }
5644 : :
5645 : : return ret;
5646 : : }
5647 : :
5648 : : static int
5649 : 0 : ice_get_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t *key_len)
5650 : : {
5651 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5652 : : int ret;
5653 : :
5654 [ # # ]: 0 : if (!key || !key_len)
5655 : : return -EINVAL;
5656 : :
5657 : 0 : ret = ice_aq_get_rss_key
5658 : 0 : (hw, vsi->idx,
5659 : : (struct ice_aqc_get_set_rss_keys *)key);
5660 [ # # ]: 0 : if (ret) {
5661 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS key via AQ");
5662 : 0 : return -EINVAL;
5663 : : }
5664 : 0 : *key_len = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
5665 : :
5666 : 0 : return 0;
5667 : : }
5668 : :
5669 : : static int
5670 : 0 : ice_rss_hash_update(struct rte_eth_dev *dev,
5671 : : struct rte_eth_rss_conf *rss_conf)
5672 : : {
5673 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5674 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5675 : : int status;
5676 : :
5677 : : /* set hash key */
5678 : 0 : status = ice_set_rss_key(vsi, rss_conf->rss_key, rss_conf->rss_key_len);
5679 [ # # ]: 0 : if (status)
5680 : : return status;
5681 : :
5682 [ # # ]: 0 : if (rss_conf->rss_hf == 0)
5683 : 0 : pf->rss_hf = 0;
5684 : :
5685 : : /* RSS hash configuration */
5686 : 0 : ice_rss_hash_set(pf, rss_conf->rss_hf);
5687 : :
5688 : 0 : return 0;
5689 : : }
5690 : :
5691 : : static int
5692 : 0 : ice_rss_hash_conf_get(struct rte_eth_dev *dev,
5693 : : struct rte_eth_rss_conf *rss_conf)
5694 : : {
5695 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5696 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5697 : :
5698 : 0 : ice_get_rss_key(vsi, rss_conf->rss_key,
5699 : : &rss_conf->rss_key_len);
5700 : :
5701 : 0 : rss_conf->rss_hf = pf->rss_hf;
5702 : 0 : return 0;
5703 : : }
5704 : :
5705 : : static int
5706 : 0 : ice_promisc_enable(struct rte_eth_dev *dev)
5707 : : {
5708 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5709 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5710 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5711 : : int status, ret = 0;
5712 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5713 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5714 : :
5715 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5716 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5717 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5718 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5719 : :
5720 : 0 : status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
5721 [ # # # ]: 0 : switch (status) {
5722 : 0 : case ICE_ERR_ALREADY_EXISTS:
5723 : 0 : PMD_DRV_LOG(DEBUG, "Promisc mode has already been enabled");
5724 : : case ICE_SUCCESS:
5725 : : break;
5726 : 0 : default:
5727 : 0 : PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
5728 : : ret = -EAGAIN;
5729 : : }
5730 : :
5731 : 0 : return ret;
5732 : : }
5733 : :
5734 : : static int
5735 : 0 : ice_promisc_disable(struct rte_eth_dev *dev)
5736 : : {
5737 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5738 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5739 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5740 : : int status, ret = 0;
5741 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5742 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5743 : :
5744 [ # # ]: 0 : if (dev->data->all_multicast == 1) {
5745 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5746 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5747 : : } else {
5748 : : ice_set_bit(ICE_PROMISC_UCAST_RX, pmask);
5749 : : ice_set_bit(ICE_PROMISC_UCAST_TX, pmask);
5750 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5751 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5752 : : }
5753 : :
5754 : 0 : status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
5755 [ # # ]: 0 : if (status != ICE_SUCCESS) {
5756 : 0 : PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
5757 : : ret = -EAGAIN;
5758 : : }
5759 : :
5760 : 0 : return ret;
5761 : : }
5762 : :
5763 : : static int
5764 : 0 : ice_allmulti_enable(struct rte_eth_dev *dev)
5765 : : {
5766 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5767 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5768 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5769 : : int status, ret = 0;
5770 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5771 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5772 : :
5773 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5774 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5775 : :
5776 : 0 : status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
5777 : :
5778 [ # # # ]: 0 : switch (status) {
5779 : 0 : case ICE_ERR_ALREADY_EXISTS:
5780 : 0 : PMD_DRV_LOG(DEBUG, "Allmulti has already been enabled");
5781 : : case ICE_SUCCESS:
5782 : : break;
5783 : 0 : default:
5784 : 0 : PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
5785 : : ret = -EAGAIN;
5786 : : }
5787 : :
5788 : 0 : return ret;
5789 : : }
5790 : :
5791 : : static int
5792 : 0 : ice_allmulti_disable(struct rte_eth_dev *dev)
5793 : : {
5794 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5795 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5796 : 0 : struct ice_vsi *vsi = pf->main_vsi;
5797 : : int status, ret = 0;
5798 : : ice_declare_bitmap(pmask, ICE_PROMISC_MAX);
5799 : : ice_zero_bitmap(pmask, ICE_PROMISC_MAX);
5800 : :
5801 [ # # ]: 0 : if (dev->data->promiscuous == 1)
5802 : : return 0; /* must remain in all_multicast mode */
5803 : :
5804 : : ice_set_bit(ICE_PROMISC_MCAST_RX, pmask);
5805 : : ice_set_bit(ICE_PROMISC_MCAST_TX, pmask);
5806 : :
5807 : 0 : status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
5808 [ # # ]: 0 : if (status != ICE_SUCCESS) {
5809 : 0 : PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
5810 : : ret = -EAGAIN;
5811 : : }
5812 : :
5813 : : return ret;
5814 : : }
5815 : :
5816 : 0 : static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
5817 : : uint16_t queue_id)
5818 : : {
5819 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
5820 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5821 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5822 : : uint32_t val;
5823 : : uint16_t msix_intr;
5824 : :
5825 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
5826 : :
5827 : : val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
5828 : : GLINT_DYN_CTL_ITR_INDX_M;
5829 : : val &= ~GLINT_DYN_CTL_WB_ON_ITR_M;
5830 : :
5831 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), val);
5832 : 0 : rte_intr_ack(pci_dev->intr_handle);
5833 : :
5834 : 0 : return 0;
5835 : : }
5836 : :
5837 : 0 : static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
5838 : : uint16_t queue_id)
5839 : : {
5840 : 0 : struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
5841 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5842 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5843 : : uint16_t msix_intr;
5844 : :
5845 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
5846 : :
5847 : 0 : ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), GLINT_DYN_CTL_WB_ON_ITR_M);
5848 : :
5849 : 0 : return 0;
5850 : : }
5851 : :
5852 : : static int
5853 : 0 : ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
5854 : : {
5855 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5856 : : u8 ver, patch;
5857 : : u16 build;
5858 : : int ret;
5859 : :
5860 : 0 : ver = hw->flash.orom.major;
5861 : 0 : patch = hw->flash.orom.patch;
5862 : 0 : build = hw->flash.orom.build;
5863 : :
5864 : 0 : ret = snprintf(fw_version, fw_size,
5865 : : "%x.%02x 0x%08x %d.%d.%d",
5866 : 0 : hw->flash.nvm.major,
5867 [ # # ]: 0 : hw->flash.nvm.minor,
5868 : : hw->flash.nvm.eetrack,
5869 : : ver, build, patch);
5870 [ # # ]: 0 : if (ret < 0)
5871 : : return -EINVAL;
5872 : :
5873 : : /* add the size of '\0' */
5874 : 0 : ret += 1;
5875 [ # # ]: 0 : if (fw_size < (size_t)ret)
5876 : : return ret;
5877 : : else
5878 : 0 : return 0;
5879 : : }
5880 : :
5881 : : static int
5882 : 0 : ice_vsi_vlan_pvid_set(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
5883 : : {
5884 : : struct ice_hw *hw;
5885 : : struct ice_vsi_ctx ctxt;
5886 : : uint8_t vlan_flags = 0;
5887 : : int ret;
5888 : :
5889 [ # # ]: 0 : if (!vsi || !info) {
5890 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5891 : 0 : return -EINVAL;
5892 : : }
5893 : :
5894 [ # # ]: 0 : if (info->on) {
5895 : 0 : vsi->info.port_based_inner_vlan = info->config.pvid;
5896 : : /**
5897 : : * If insert pvid is enabled, only tagged pkts are
5898 : : * allowed to be sent out.
5899 : : */
5900 : : vlan_flags = ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
5901 : : ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
5902 : : } else {
5903 : 0 : vsi->info.port_based_inner_vlan = 0;
5904 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5905 : : vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTTAGGED;
5906 : :
5907 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5908 : 0 : vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
5909 : : }
5910 : 0 : vsi->info.inner_vlan_flags &= ~(ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
5911 : : ICE_AQ_VSI_INNER_VLAN_EMODE_M);
5912 [ # # ]: 0 : vsi->info.inner_vlan_flags |= vlan_flags;
5913 : : memset(&ctxt, 0, sizeof(ctxt));
5914 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5915 : 0 : ctxt.info.valid_sections =
5916 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5917 : 0 : ctxt.vsi_num = vsi->vsi_id;
5918 : :
5919 : 0 : hw = ICE_VSI_TO_HW(vsi);
5920 : 0 : ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5921 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
5922 : 0 : PMD_DRV_LOG(ERR,
5923 : : "update VSI for VLAN insert failed, err %d",
5924 : : ret);
5925 : 0 : return -EINVAL;
5926 : : }
5927 : :
5928 : 0 : vsi->info.valid_sections |=
5929 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
5930 : :
5931 : 0 : return ret;
5932 : : }
5933 : :
5934 : : /**
5935 : : * ice_vsi_set_outer_port_vlan - set the outer port VLAN and related settings
5936 : : * @vsi: VSI to configure
5937 : : * @vlan_info: packed u16 that contains the VLAN prio and ID
5938 : : * @tpid: TPID of the port VLAN
5939 : : *
5940 : : * Set the port VLAN prio, ID, and TPID.
5941 : : *
5942 : : * Enable VLAN pruning so the VSI doesn't receive any traffic that doesn't match
5943 : : * a VLAN prune rule. The caller should take care to add a VLAN prune rule that
5944 : : * matches the port VLAN ID and TPID.
5945 : : *
5946 : : * Tell hardware to strip outer VLAN tagged packets on receive and don't put
5947 : : * them in the receive descriptor. VSI(s) in port VLANs should not be aware of
5948 : : * the port VLAN ID or TPID they are assigned to.
5949 : : *
5950 : : * Tell hardware to prevent outer VLAN tag insertion on transmit and only allow
5951 : : * untagged outer packets from the transmit descriptor.
5952 : : *
5953 : : * Also, tell the hardware to insert the port VLAN on transmit.
5954 : : */
5955 : : static int
5956 : 0 : ice_vsi_set_outer_port_vlan(struct ice_vsi *vsi, u16 vlan_info, u16 tpid)
5957 : : {
5958 [ # # # # ]: 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
5959 : : struct ice_vsi_ctx ctxt;
5960 : : int status, err = 0;
5961 : : u8 tag_type;
5962 : :
5963 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
5964 : : return -EINVAL;
5965 : :
5966 : : memset(&ctxt, 0, sizeof(ctxt));
5967 : :
5968 : 0 : ctxt.info = vsi->info;
5969 : :
5970 : 0 : ctxt.info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
5971 : :
5972 : 0 : ctxt.info.port_based_outer_vlan = rte_cpu_to_le_16(vlan_info);
5973 : 0 : ctxt.info.outer_vlan_flags =
5974 : : (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW <<
5975 : : ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
5976 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
5977 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M) |
5978 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
5979 : : (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTUNTAGGED <<
5980 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) |
5981 : : ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT;
5982 : 0 : ctxt.info.valid_sections =
5983 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID |
5984 : : ICE_AQ_VSI_PROP_SW_VALID);
5985 : :
5986 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
5987 [ # # ]: 0 : if (status != ICE_SUCCESS) {
5988 : 0 : PMD_DRV_LOG(ERR,
5989 : : "update VSI for setting outer port based VLAN failed, err %d",
5990 : : status);
5991 : : err = -EINVAL;
5992 : : } else {
5993 : 0 : vsi->info.port_based_outer_vlan = ctxt.info.port_based_outer_vlan;
5994 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
5995 : 0 : vsi->info.sw_flags2 = ctxt.info.sw_flags2;
5996 : : }
5997 : :
5998 : : return err;
5999 : : }
6000 : :
6001 : : /**
6002 : : * ice_vsi_dis_outer_insertion - disable outer VLAN insertion
6003 : : * @vsi: VSI to configure
6004 : : * @info: vlan pvid info
6005 : : *
6006 : : * Disable outer VLAN insertion via VSI context. This function should only be
6007 : : * used if DVM is supported.
6008 : : *
6009 : : * Only modify the outer VLAN insertion settings. The VLAN TPID and outer VLAN
6010 : : * settings are unmodified.
6011 : : *
6012 : : * This tells the hardware to not allow VLAN tagged packets in the transmit
6013 : : * descriptor. This enables software offloaded VLAN insertion and disables
6014 : : * hardware offloaded VLAN insertion.
6015 : : */
6016 : 0 : static int ice_vsi_dis_outer_insertion(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
6017 : : {
6018 [ # # ]: 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6019 : : struct ice_vsi_ctx ctxt;
6020 : : uint8_t vlan_flags = 0;
6021 : : int status, err = 0;
6022 : :
6023 : : memset(&ctxt, 0, sizeof(ctxt));
6024 : :
6025 : 0 : ctxt.info.valid_sections =
6026 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
6027 : : ctxt.info.port_based_inner_vlan = 0;
6028 : : /* clear current outer VLAN insertion settings */
6029 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
6030 : : ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
6031 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
6032 [ # # ]: 0 : if (info->config.reject.tagged == 0)
6033 : : vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTTAGGED;
6034 [ # # ]: 0 : if (info->config.reject.untagged == 0)
6035 : 0 : vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ACCEPTUNTAGGED;
6036 : 0 : ctxt.info.outer_vlan_flags |=
6037 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
6038 : 0 : ((vlan_flags <<
6039 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
6040 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M);
6041 : :
6042 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
6043 [ # # ]: 0 : if (!status) {
6044 : 0 : PMD_DRV_LOG(ERR,
6045 : : "update VSI for disabling outer VLAN insertion failed, err %d",
6046 : : status);
6047 : : err = -EINVAL;
6048 : : } else {
6049 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
6050 : 0 : vsi->info.port_based_inner_vlan = ctxt.info.port_based_inner_vlan;
6051 : : }
6052 : :
6053 : 0 : return err;
6054 : : }
6055 : :
6056 : : static int
6057 : 0 : ice_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
6058 : : {
6059 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6060 : 0 : struct ice_vsi *vsi = pf->main_vsi;
6061 [ # # ]: 0 : struct rte_eth_dev_data *data = pf->dev_data;
6062 : : struct ice_vsi_vlan_pvid_info info;
6063 : : int ret;
6064 : :
6065 : : memset(&info, 0, sizeof(info));
6066 : 0 : info.on = on;
6067 [ # # ]: 0 : if (info.on) {
6068 : 0 : info.config.pvid = pvid;
6069 : : } else {
6070 : 0 : info.config.reject.tagged =
6071 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
6072 : 0 : info.config.reject.untagged =
6073 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
6074 : : }
6075 : :
6076 [ # # ]: 0 : if (ice_is_dvm_ena(&vsi->adapter->hw)) {
6077 [ # # ]: 0 : if (on)
6078 : 0 : return ice_vsi_set_outer_port_vlan(vsi, pvid, pf->outer_ethertype);
6079 : : else
6080 : 0 : return ice_vsi_dis_outer_insertion(vsi, &info);
6081 : : }
6082 : :
6083 : 0 : ret = ice_vsi_vlan_pvid_set(vsi, &info);
6084 [ # # ]: 0 : if (ret < 0) {
6085 : 0 : PMD_DRV_LOG(ERR, "Failed to set pvid.");
6086 : 0 : return -EINVAL;
6087 : : }
6088 : :
6089 : : return 0;
6090 : : }
6091 : :
6092 : 0 : static int ice_vsi_ena_outer_insertion(struct ice_vsi *vsi, uint16_t tpid)
6093 : : {
6094 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6095 : : struct ice_vsi_ctx ctxt;
6096 : : int status, err = 0;
6097 : : u8 tag_type;
6098 : : /* do not allow modifying VLAN stripping when a port VLAN is configured
6099 : : * on this VSI
6100 : : */
6101 [ # # ]: 0 : if (vsi->info.port_based_outer_vlan)
6102 : : return 0;
6103 : :
6104 : : if (tpid_to_vsi_outer_vlan_type(tpid, &tag_type))
6105 : : return -EINVAL;
6106 : :
6107 : : memset(&ctxt, 0, sizeof(ctxt));
6108 : 0 : ctxt.info.valid_sections =
6109 : : rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
6110 : : /* clear current outer VLAN insertion settings */
6111 : 0 : ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
6112 : : ~(ICE_AQ_VSI_OUTER_VLAN_PORT_BASED_INSERT |
6113 : : ICE_AQ_VSI_OUTER_VLAN_BLOCK_TX_DESC |
6114 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M |
6115 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
6116 : 0 : ctxt.info.outer_vlan_flags |=
6117 : : ((ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
6118 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
6119 : : ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M) |
6120 : 0 : ((tag_type << ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
6121 : : ICE_AQ_VSI_OUTER_TAG_TYPE_M);
6122 : :
6123 : 0 : status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
6124 [ # # ]: 0 : if (status) {
6125 : 0 : PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
6126 : : err = -EIO;
6127 : : } else {
6128 : 0 : vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
6129 : : }
6130 : :
6131 : : return err;
6132 : : }
6133 : :
6134 : : static int
6135 : 0 : ice_vlan_tpid_set(struct rte_eth_dev *dev,
6136 : : enum rte_vlan_type vlan_type,
6137 : : uint16_t tpid)
6138 : : {
6139 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6140 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6141 : 0 : struct ice_vsi *vsi = pf->main_vsi;
6142 : 0 : uint64_t qinq = dev->data->dev_conf.rxmode.offloads &
6143 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
6144 : : int err = 0;
6145 : :
6146 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
6147 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
6148 [ # # # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER) ||
6149 : 0 : !ice_is_supported_port_vlan_proto(hw, tpid)) {
6150 : 0 : PMD_DRV_LOG(ERR,
6151 : : "Unsupported vlan type.");
6152 : 0 : return -EINVAL;
6153 : : }
6154 : :
6155 : 0 : err = ice_vsi_ena_outer_insertion(vsi, tpid);
6156 [ # # ]: 0 : if (!err)
6157 : 0 : pf->outer_ethertype = tpid;
6158 : :
6159 : : return err;
6160 : : }
6161 : :
6162 : : static int
6163 : 0 : ice_get_eeprom_length(struct rte_eth_dev *dev)
6164 : : {
6165 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6166 : :
6167 : 0 : return hw->flash.flash_size;
6168 : : }
6169 : :
6170 : : static int
6171 : 0 : ice_get_eeprom(struct rte_eth_dev *dev,
6172 : : struct rte_dev_eeprom_info *eeprom)
6173 : : {
6174 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6175 : 0 : uint8_t *data = eeprom->data;
6176 : : int status;
6177 : :
6178 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6179 : :
6180 : 0 : status = ice_acquire_nvm(hw, ICE_RES_READ);
6181 [ # # ]: 0 : if (status) {
6182 : 0 : PMD_DRV_LOG(ERR, "acquire nvm failed.");
6183 : 0 : return -EIO;
6184 : : }
6185 : :
6186 : 0 : status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->length,
6187 : : data, false);
6188 : :
6189 : 0 : ice_release_nvm(hw);
6190 : :
6191 [ # # ]: 0 : if (status) {
6192 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
6193 : 0 : return -EIO;
6194 : : }
6195 : :
6196 : : return 0;
6197 : : }
6198 : :
6199 : : static int
6200 : 0 : ice_get_module_info(struct rte_eth_dev *dev,
6201 : : struct rte_eth_dev_module_info *modinfo)
6202 : : {
6203 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6204 : 0 : u8 sff8472_comp = 0;
6205 : 0 : u8 sff8472_swap = 0;
6206 : 0 : u8 sff8636_rev = 0;
6207 : 0 : u8 value = 0;
6208 : : int status;
6209 : :
6210 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
6211 : : 0, &value, 1, 0, NULL);
6212 [ # # ]: 0 : if (status)
6213 : : return -EIO;
6214 : :
6215 [ # # # ]: 0 : switch (value) {
6216 : 0 : case ICE_MODULE_TYPE_SFP:
6217 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6218 : : ICE_MODULE_SFF_8472_COMP, 0x00, 0,
6219 : : &sff8472_comp, 1, 0, NULL);
6220 [ # # ]: 0 : if (status)
6221 : : return -EIO;
6222 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6223 : : ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
6224 : : &sff8472_swap, 1, 0, NULL);
6225 [ # # ]: 0 : if (status)
6226 : : return -EIO;
6227 : :
6228 [ # # ]: 0 : if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
6229 : 0 : modinfo->type = ICE_MODULE_SFF_8079;
6230 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8079_LEN;
6231 [ # # # # ]: 0 : } else if (sff8472_comp &&
6232 : : (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
6233 : 0 : modinfo->type = ICE_MODULE_SFF_8472;
6234 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8472_LEN;
6235 : : } else {
6236 : 0 : modinfo->type = ICE_MODULE_SFF_8079;
6237 : 0 : modinfo->eeprom_len = ICE_MODULE_SFF_8079_LEN;
6238 : : }
6239 : : break;
6240 : 0 : case ICE_MODULE_TYPE_QSFP_PLUS:
6241 : : case ICE_MODULE_TYPE_QSFP28:
6242 : 0 : status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
6243 : : ICE_MODULE_REVISION_ADDR, 0x00, 0,
6244 : : &sff8636_rev, 1, 0, NULL);
6245 [ # # ]: 0 : if (status)
6246 : : return -EIO;
6247 : : /* Check revision compliance */
6248 [ # # ]: 0 : if (sff8636_rev > 0x02) {
6249 : : /* Module is SFF-8636 compliant */
6250 : 0 : modinfo->type = ICE_MODULE_SFF_8636;
6251 : 0 : modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
6252 : : } else {
6253 : 0 : modinfo->type = ICE_MODULE_SFF_8436;
6254 : 0 : modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
6255 : : }
6256 : : break;
6257 : 0 : default:
6258 : 0 : PMD_DRV_LOG(WARNING, "SFF Module Type not recognized.");
6259 : 0 : return -EINVAL;
6260 : : }
6261 : : return 0;
6262 : : }
6263 : :
6264 : : static int
6265 : 0 : ice_get_module_eeprom(struct rte_eth_dev *dev,
6266 : : struct rte_dev_eeprom_info *info)
6267 : : {
6268 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6269 : : #define SFF_READ_BLOCK_SIZE 8
6270 : : #define I2C_BUSY_TRY_TIMES 4
6271 : : #define I2C_USLEEP_MIN_TIME 1500
6272 : : #define I2C_USLEEP_MAX_TIME 2500
6273 : 0 : uint8_t value[SFF_READ_BLOCK_SIZE] = {0};
6274 : : uint8_t addr = ICE_I2C_EEPROM_DEV_ADDR;
6275 : : uint8_t *data = NULL;
6276 : : bool is_sfp = false;
6277 : : uint32_t i, j;
6278 : : uint32_t offset = 0;
6279 : : uint8_t page = 0;
6280 : : int status;
6281 : :
6282 [ # # # # : 0 : if (!info || !info->length || !info->data)
# # ]
6283 : : return -EINVAL;
6284 : :
6285 : 0 : status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
6286 : : NULL);
6287 [ # # ]: 0 : if (status)
6288 : : return -EIO;
6289 : :
6290 [ # # ]: 0 : if (value[0] == ICE_MODULE_TYPE_SFP)
6291 : : is_sfp = true;
6292 : :
6293 : 0 : data = info->data;
6294 : 0 : memset(data, 0, info->length);
6295 [ # # ]: 0 : for (i = 0; i < info->length; i += SFF_READ_BLOCK_SIZE) {
6296 : 0 : offset = i + info->offset;
6297 : : page = 0;
6298 : :
6299 : : /* Check if we need to access the other memory page */
6300 [ # # ]: 0 : if (is_sfp) {
6301 [ # # ]: 0 : if (offset >= ICE_MODULE_SFF_8079_LEN) {
6302 : 0 : offset -= ICE_MODULE_SFF_8079_LEN;
6303 : : addr = ICE_I2C_EEPROM_DEV_ADDR2;
6304 : : }
6305 : : } else {
6306 [ # # ]: 0 : while (offset >= ICE_MODULE_SFF_8436_LEN) {
6307 : : /* Compute memory page number and offset. */
6308 : 0 : offset -= ICE_MODULE_SFF_8436_LEN / 2;
6309 : 0 : page++;
6310 : : }
6311 : : }
6312 : :
6313 : : /* Bit 2 of eeprom address 0x02 declares upper
6314 : : * pages are disabled on QSFP modules.
6315 : : * SFP modules only ever use page 0.
6316 : : */
6317 [ # # # # ]: 0 : if (page == 0 || !(data[0x2] & 0x4)) {
6318 : : /* If i2c bus is busy due to slow page change or
6319 : : * link management access, call can fail.
6320 : : * This is normal. So we retry this a few times.
6321 : : */
6322 [ # # ]: 0 : for (j = 0; j < I2C_BUSY_TRY_TIMES; j++) {
6323 : 0 : status = ice_aq_sff_eeprom(hw, 0, addr, offset,
6324 : 0 : page, !is_sfp, value,
6325 : : SFF_READ_BLOCK_SIZE,
6326 : : 0, NULL);
6327 : 0 : PMD_DRV_LOG(DEBUG, "SFF %02X %02X %02X %X = "
6328 : : "%02X%02X%02X%02X."
6329 : : "%02X%02X%02X%02X (%X)",
6330 : : addr, offset, page, is_sfp,
6331 : : value[0], value[1],
6332 : : value[2], value[3],
6333 : : value[4], value[5],
6334 : : value[6], value[7],
6335 : : status);
6336 [ # # ]: 0 : if (status) {
6337 : 0 : usleep_range(I2C_USLEEP_MIN_TIME,
6338 : : I2C_USLEEP_MAX_TIME);
6339 : : memset(value, 0, SFF_READ_BLOCK_SIZE);
6340 : : continue;
6341 : : }
6342 : : break;
6343 : : }
6344 : :
6345 : : /* Make sure we have enough room for the new block */
6346 [ # # ]: 0 : if ((i + SFF_READ_BLOCK_SIZE) <= info->length)
6347 : 0 : memcpy(data + i, value, SFF_READ_BLOCK_SIZE);
6348 : : }
6349 : : }
6350 : :
6351 : : return 0;
6352 : : }
6353 : :
6354 : : static void
6355 : : ice_stat_update_32(struct ice_hw *hw,
6356 : : uint32_t reg,
6357 : : bool offset_loaded,
6358 : : uint64_t *offset,
6359 : : uint64_t *stat)
6360 : : {
6361 : : uint64_t new_data;
6362 : :
6363 : 0 : new_data = (uint64_t)ICE_READ_REG(hw, reg);
6364 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
6365 : 0 : *offset = new_data;
6366 : :
6367 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
6368 : 0 : *stat = (uint64_t)(new_data - *offset);
6369 : : else
6370 : 0 : *stat = (uint64_t)((new_data +
6371 : : ((uint64_t)1 << ICE_32_BIT_WIDTH))
6372 : : - *offset);
6373 : : }
6374 : :
6375 : : static void
6376 : 0 : ice_stat_update_40(struct ice_hw *hw,
6377 : : uint32_t hireg,
6378 : : uint32_t loreg,
6379 : : bool offset_loaded,
6380 : : uint64_t *offset,
6381 : : uint64_t *stat)
6382 : : {
6383 : : uint64_t new_data;
6384 : : uint32_t lo_old, hi, lo;
6385 : :
6386 : : do {
6387 : 0 : lo_old = ICE_READ_REG(hw, loreg);
6388 : 0 : hi = ICE_READ_REG(hw, hireg);
6389 : 0 : lo = ICE_READ_REG(hw, loreg);
6390 [ # # ]: 0 : } while (lo_old > lo);
6391 : :
6392 : 0 : new_data = (uint64_t)lo;
6393 : 0 : new_data |= (uint64_t)(hi & ICE_8_BIT_MASK) << ICE_32_BIT_WIDTH;
6394 : :
6395 [ # # ]: 0 : if (!offset_loaded)
6396 : 0 : *offset = new_data;
6397 : :
6398 [ # # ]: 0 : if (new_data >= *offset)
6399 : 0 : *stat = new_data - *offset;
6400 : : else
6401 : 0 : *stat = (uint64_t)((new_data +
6402 : : ((uint64_t)1 << ICE_40_BIT_WIDTH)) -
6403 : : *offset);
6404 : :
6405 : 0 : *stat &= ICE_40_BIT_MASK;
6406 : 0 : }
6407 : :
6408 : : /**
6409 : : * There are various counters that are bubbled up in uint64 values but do not make use of all
6410 : : * 64 bits, most commonly using only 32 or 40 bits. This function handles the "overflow" when
6411 : : * these counters hit their 32 or 40 bit limit to enlarge that limitation to 64 bits.
6412 : :
6413 : : * @offset_loaded: refers to whether this function has been called before and old_value is known to
6414 : : * have a value, i.e. its possible that value has overflowed past its original limitation
6415 : : * @value_bit_limitation: refers to the number of bits the given value uses before overflowing
6416 : : * @value: is the current value with its original limitation (i.e. 32 or 40 bits)
6417 : : * @old_value: is expected to be the previous value of the given value with the overflow accounted
6418 : : * for (i.e. the full 64 bit previous value)
6419 : : *
6420 : : * This function will appropriately update both value and old_value, accounting for overflow
6421 : : */
6422 : : static void
6423 : : ice_handle_overflow(bool offset_loaded,
6424 : : uint8_t value_bit_limitation,
6425 : : uint64_t *value,
6426 : : uint64_t *old_value)
6427 : : {
6428 : : uint64_t low_bit_mask = RTE_LEN2MASK(value_bit_limitation, uint64_t);
6429 : : uint64_t high_bit_mask = ~low_bit_mask;
6430 : :
6431 : 0 : if (offset_loaded) {
6432 [ # # # # : 0 : if ((*old_value & low_bit_mask) > *value)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
6433 : 0 : *value += (uint64_t)1 << value_bit_limitation;
6434 : 0 : *value += *old_value & high_bit_mask;
6435 : : }
6436 [ # # # # : 0 : *old_value = *value;
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
6437 : : }
6438 : :
6439 : : /* Get all the statistics of a VSI */
6440 : : static void
6441 : 0 : ice_update_vsi_stats(struct ice_vsi *vsi)
6442 : : {
6443 : : struct ice_eth_stats *oes = &vsi->eth_stats_offset;
6444 : : struct ice_eth_stats *nes = &vsi->eth_stats;
6445 : 0 : struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
6446 : 0 : int idx = rte_le_to_cpu_16(vsi->vsi_id);
6447 : :
6448 : 0 : ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
6449 : 0 : vsi->offset_loaded, &oes->rx_bytes,
6450 : 0 : &nes->rx_bytes);
6451 : 0 : ice_stat_update_40(hw, GLV_UPRCH(idx), GLV_UPRCL(idx),
6452 : 0 : vsi->offset_loaded, &oes->rx_unicast,
6453 : 0 : &nes->rx_unicast);
6454 : 0 : ice_stat_update_40(hw, GLV_MPRCH(idx), GLV_MPRCL(idx),
6455 : 0 : vsi->offset_loaded, &oes->rx_multicast,
6456 : 0 : &nes->rx_multicast);
6457 : 0 : ice_stat_update_40(hw, GLV_BPRCH(idx), GLV_BPRCL(idx),
6458 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
6459 : 0 : &nes->rx_broadcast);
6460 : :
6461 [ # # ]: 0 : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6462 : : &nes->rx_unicast, &vsi->old_get_stats_fields.rx_unicast);
6463 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6464 : : &nes->rx_multicast, &vsi->old_get_stats_fields.rx_multicast);
6465 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6466 : : &nes->rx_broadcast, &vsi->old_get_stats_fields.rx_broadcast);
6467 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6468 : : &nes->rx_bytes, &vsi->old_get_stats_fields.rx_bytes);
6469 : :
6470 : : /* exclude CRC bytes */
6471 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
6472 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
6473 : :
6474 : 0 : ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
6475 : : &oes->rx_discards, &nes->rx_discards);
6476 : : /* GLV_REPC not supported */
6477 : : /* GLV_RMPC not supported */
6478 : 0 : ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
6479 : : &oes->rx_unknown_protocol,
6480 : : &nes->rx_unknown_protocol);
6481 : 0 : ice_stat_update_40(hw, GLV_GOTCH(idx), GLV_GOTCL(idx),
6482 : 0 : vsi->offset_loaded, &oes->tx_bytes,
6483 : 0 : &nes->tx_bytes);
6484 : 0 : ice_stat_update_40(hw, GLV_UPTCH(idx), GLV_UPTCL(idx),
6485 : 0 : vsi->offset_loaded, &oes->tx_unicast,
6486 : 0 : &nes->tx_unicast);
6487 : 0 : ice_stat_update_40(hw, GLV_MPTCH(idx), GLV_MPTCL(idx),
6488 : 0 : vsi->offset_loaded, &oes->tx_multicast,
6489 : 0 : &nes->tx_multicast);
6490 : 0 : ice_stat_update_40(hw, GLV_BPTCH(idx), GLV_BPTCL(idx),
6491 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
6492 : 0 : &nes->tx_broadcast);
6493 : : /* GLV_TDPC not supported */
6494 : 0 : ice_stat_update_32(hw, GLV_TEPC(idx), vsi->offset_loaded,
6495 : : &oes->tx_errors, &nes->tx_errors);
6496 : :
6497 [ # # ]: 0 : ice_handle_overflow(vsi->offset_loaded, ICE_32_BIT_WIDTH,
6498 : : &nes->rx_discards, &vsi->old_get_stats_fields.rx_discards);
6499 : : ice_handle_overflow(vsi->offset_loaded, ICE_32_BIT_WIDTH,
6500 : : &nes->tx_errors, &vsi->old_get_stats_fields.tx_errors);
6501 : : ice_handle_overflow(vsi->offset_loaded, ICE_40_BIT_WIDTH,
6502 : : &nes->tx_bytes, &vsi->old_get_stats_fields.tx_bytes);
6503 : :
6504 : 0 : vsi->offset_loaded = true;
6505 : :
6506 : 0 : PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats start **************",
6507 : : vsi->vsi_id);
6508 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
6509 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
6510 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
6511 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
6512 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
6513 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
6514 : : nes->rx_unknown_protocol);
6515 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
6516 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
6517 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
6518 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
6519 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
6520 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
6521 : 0 : PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats end ****************",
6522 : : vsi->vsi_id);
6523 : 0 : }
6524 : :
6525 : : static void
6526 : 0 : ice_read_stats_registers(struct ice_pf *pf, struct ice_hw *hw)
6527 : : {
6528 : : struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
6529 : : struct ice_hw_port_stats *os = &pf->stats_offset; /* old stats */
6530 : :
6531 : : /* Get statistics of struct ice_eth_stats */
6532 : 0 : ice_stat_update_40(hw, GLPRT_GORCH(hw->port_info->lport),
6533 : 0 : GLPRT_GORCL(hw->port_info->lport),
6534 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
6535 : 0 : &ns->eth.rx_bytes);
6536 : 0 : ice_stat_update_40(hw, GLPRT_UPRCH(hw->port_info->lport),
6537 : 0 : GLPRT_UPRCL(hw->port_info->lport),
6538 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
6539 : 0 : &ns->eth.rx_unicast);
6540 : 0 : ice_stat_update_40(hw, GLPRT_MPRCH(hw->port_info->lport),
6541 : 0 : GLPRT_MPRCL(hw->port_info->lport),
6542 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
6543 : 0 : &ns->eth.rx_multicast);
6544 : 0 : ice_stat_update_40(hw, GLPRT_BPRCH(hw->port_info->lport),
6545 : 0 : GLPRT_BPRCL(hw->port_info->lport),
6546 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
6547 : 0 : &ns->eth.rx_broadcast);
6548 : : ice_stat_update_32(hw, PRTRPB_RDPC,
6549 : 0 : pf->offset_loaded, &os->eth.rx_discards,
6550 : : &ns->eth.rx_discards);
6551 : :
6552 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6553 : : &ns->eth.rx_bytes, &pf->old_get_stats_fields.rx_bytes);
6554 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6555 : : &ns->eth.rx_discards, &pf->old_get_stats_fields.rx_discards);
6556 : :
6557 : : /* Workaround: CRC size should not be included in byte statistics,
6558 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
6559 : : * packet.
6560 : : */
6561 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
6562 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
6563 : :
6564 : : /* GLPRT_REPC not supported */
6565 : : /* GLPRT_RMPC not supported */
6566 : 0 : ice_stat_update_32(hw, GLSWID_RUPP(hw->port_info->lport),
6567 : : pf->offset_loaded,
6568 : : &os->eth.rx_unknown_protocol,
6569 : : &ns->eth.rx_unknown_protocol);
6570 : 0 : ice_stat_update_40(hw, GLPRT_GOTCH(hw->port_info->lport),
6571 : 0 : GLPRT_GOTCL(hw->port_info->lport),
6572 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
6573 : 0 : &ns->eth.tx_bytes);
6574 : 0 : ice_stat_update_40(hw, GLPRT_UPTCH(hw->port_info->lport),
6575 : 0 : GLPRT_UPTCL(hw->port_info->lport),
6576 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
6577 : 0 : &ns->eth.tx_unicast);
6578 : 0 : ice_stat_update_40(hw, GLPRT_MPTCH(hw->port_info->lport),
6579 : 0 : GLPRT_MPTCL(hw->port_info->lport),
6580 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
6581 : 0 : &ns->eth.tx_multicast);
6582 : 0 : ice_stat_update_40(hw, GLPRT_BPTCH(hw->port_info->lport),
6583 : 0 : GLPRT_BPTCL(hw->port_info->lport),
6584 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
6585 : 0 : &ns->eth.tx_broadcast);
6586 : :
6587 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6588 : : &ns->eth.tx_bytes, &pf->old_get_stats_fields.tx_bytes);
6589 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6590 : : &ns->eth.tx_unicast, &pf->old_get_stats_fields.tx_unicast);
6591 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6592 : : &ns->eth.tx_multicast, &pf->old_get_stats_fields.tx_multicast);
6593 : : ice_handle_overflow(pf->offset_loaded, ICE_40_BIT_WIDTH,
6594 : : &ns->eth.tx_broadcast, &pf->old_get_stats_fields.tx_broadcast);
6595 : :
6596 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
6597 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
6598 : :
6599 : : /* GLPRT_TEPC not supported */
6600 : :
6601 : : /* additional port specific stats */
6602 : 0 : ice_stat_update_32(hw, GLPRT_TDOLD(hw->port_info->lport),
6603 : : pf->offset_loaded, &os->tx_dropped_link_down,
6604 : : &ns->tx_dropped_link_down);
6605 : 0 : ice_stat_update_32(hw, GLPRT_CRCERRS(hw->port_info->lport),
6606 : 0 : pf->offset_loaded, &os->crc_errors,
6607 : : &ns->crc_errors);
6608 : 0 : ice_stat_update_32(hw, GLPRT_ILLERRC(hw->port_info->lport),
6609 : 0 : pf->offset_loaded, &os->illegal_bytes,
6610 : : &ns->illegal_bytes);
6611 : : /* GLPRT_ERRBC not supported */
6612 : 0 : ice_stat_update_32(hw, GLPRT_MLFC(hw->port_info->lport),
6613 : 0 : pf->offset_loaded, &os->mac_local_faults,
6614 : : &ns->mac_local_faults);
6615 : 0 : ice_stat_update_32(hw, GLPRT_MRFC(hw->port_info->lport),
6616 : 0 : pf->offset_loaded, &os->mac_remote_faults,
6617 : : &ns->mac_remote_faults);
6618 : :
6619 : 0 : ice_stat_update_32(hw, GLPRT_RLEC(hw->port_info->lport),
6620 : 0 : pf->offset_loaded, &os->rx_len_errors,
6621 : : &ns->rx_len_errors);
6622 : :
6623 : 0 : ice_stat_update_32(hw, GLPRT_LXONRXC(hw->port_info->lport),
6624 : 0 : pf->offset_loaded, &os->link_xon_rx,
6625 : : &ns->link_xon_rx);
6626 : 0 : ice_stat_update_32(hw, GLPRT_LXOFFRXC(hw->port_info->lport),
6627 : 0 : pf->offset_loaded, &os->link_xoff_rx,
6628 : : &ns->link_xoff_rx);
6629 : 0 : ice_stat_update_32(hw, GLPRT_LXONTXC(hw->port_info->lport),
6630 : 0 : pf->offset_loaded, &os->link_xon_tx,
6631 : : &ns->link_xon_tx);
6632 : 0 : ice_stat_update_32(hw, GLPRT_LXOFFTXC(hw->port_info->lport),
6633 : 0 : pf->offset_loaded, &os->link_xoff_tx,
6634 : : &ns->link_xoff_tx);
6635 : 0 : ice_stat_update_40(hw, GLPRT_PRC64H(hw->port_info->lport),
6636 : 0 : GLPRT_PRC64L(hw->port_info->lport),
6637 : 0 : pf->offset_loaded, &os->rx_size_64,
6638 : 0 : &ns->rx_size_64);
6639 : 0 : ice_stat_update_40(hw, GLPRT_PRC127H(hw->port_info->lport),
6640 : 0 : GLPRT_PRC127L(hw->port_info->lport),
6641 : 0 : pf->offset_loaded, &os->rx_size_127,
6642 : 0 : &ns->rx_size_127);
6643 : 0 : ice_stat_update_40(hw, GLPRT_PRC255H(hw->port_info->lport),
6644 : 0 : GLPRT_PRC255L(hw->port_info->lport),
6645 : 0 : pf->offset_loaded, &os->rx_size_255,
6646 : 0 : &ns->rx_size_255);
6647 : 0 : ice_stat_update_40(hw, GLPRT_PRC511H(hw->port_info->lport),
6648 : 0 : GLPRT_PRC511L(hw->port_info->lport),
6649 : 0 : pf->offset_loaded, &os->rx_size_511,
6650 : 0 : &ns->rx_size_511);
6651 : 0 : ice_stat_update_40(hw, GLPRT_PRC1023H(hw->port_info->lport),
6652 : 0 : GLPRT_PRC1023L(hw->port_info->lport),
6653 : 0 : pf->offset_loaded, &os->rx_size_1023,
6654 : 0 : &ns->rx_size_1023);
6655 : 0 : ice_stat_update_40(hw, GLPRT_PRC1522H(hw->port_info->lport),
6656 : 0 : GLPRT_PRC1522L(hw->port_info->lport),
6657 : 0 : pf->offset_loaded, &os->rx_size_1522,
6658 : 0 : &ns->rx_size_1522);
6659 : 0 : ice_stat_update_40(hw, GLPRT_PRC9522H(hw->port_info->lport),
6660 : 0 : GLPRT_PRC9522L(hw->port_info->lport),
6661 : 0 : pf->offset_loaded, &os->rx_size_big,
6662 : 0 : &ns->rx_size_big);
6663 : 0 : ice_stat_update_32(hw, GLPRT_RUC(hw->port_info->lport),
6664 : 0 : pf->offset_loaded, &os->rx_undersize,
6665 : : &ns->rx_undersize);
6666 : 0 : ice_stat_update_32(hw, GLPRT_RFC(hw->port_info->lport),
6667 : 0 : pf->offset_loaded, &os->rx_fragments,
6668 : : &ns->rx_fragments);
6669 : 0 : ice_stat_update_32(hw, GLPRT_ROC(hw->port_info->lport),
6670 : 0 : pf->offset_loaded, &os->rx_oversize,
6671 : : &ns->rx_oversize);
6672 : 0 : ice_stat_update_32(hw, GLPRT_RJC(hw->port_info->lport),
6673 : 0 : pf->offset_loaded, &os->rx_jabber,
6674 : : &ns->rx_jabber);
6675 : 0 : ice_stat_update_40(hw, GLPRT_PTC64H(hw->port_info->lport),
6676 : 0 : GLPRT_PTC64L(hw->port_info->lport),
6677 : 0 : pf->offset_loaded, &os->tx_size_64,
6678 : 0 : &ns->tx_size_64);
6679 : 0 : ice_stat_update_40(hw, GLPRT_PTC127H(hw->port_info->lport),
6680 : 0 : GLPRT_PTC127L(hw->port_info->lport),
6681 : 0 : pf->offset_loaded, &os->tx_size_127,
6682 : 0 : &ns->tx_size_127);
6683 : 0 : ice_stat_update_40(hw, GLPRT_PTC255H(hw->port_info->lport),
6684 : 0 : GLPRT_PTC255L(hw->port_info->lport),
6685 : 0 : pf->offset_loaded, &os->tx_size_255,
6686 : 0 : &ns->tx_size_255);
6687 : 0 : ice_stat_update_40(hw, GLPRT_PTC511H(hw->port_info->lport),
6688 : 0 : GLPRT_PTC511L(hw->port_info->lport),
6689 : 0 : pf->offset_loaded, &os->tx_size_511,
6690 : 0 : &ns->tx_size_511);
6691 : 0 : ice_stat_update_40(hw, GLPRT_PTC1023H(hw->port_info->lport),
6692 : 0 : GLPRT_PTC1023L(hw->port_info->lport),
6693 : 0 : pf->offset_loaded, &os->tx_size_1023,
6694 : 0 : &ns->tx_size_1023);
6695 : 0 : ice_stat_update_40(hw, GLPRT_PTC1522H(hw->port_info->lport),
6696 : 0 : GLPRT_PTC1522L(hw->port_info->lport),
6697 : 0 : pf->offset_loaded, &os->tx_size_1522,
6698 : 0 : &ns->tx_size_1522);
6699 : 0 : ice_stat_update_40(hw, GLPRT_PTC9522H(hw->port_info->lport),
6700 : 0 : GLPRT_PTC9522L(hw->port_info->lport),
6701 : 0 : pf->offset_loaded, &os->tx_size_big,
6702 : 0 : &ns->tx_size_big);
6703 : :
6704 [ # # ]: 0 : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6705 : : &ns->crc_errors, &pf->old_get_stats_fields.crc_errors);
6706 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6707 : : &ns->rx_undersize, &pf->old_get_stats_fields.rx_undersize);
6708 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6709 : : &ns->rx_fragments, &pf->old_get_stats_fields.rx_fragments);
6710 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6711 : : &ns->rx_oversize, &pf->old_get_stats_fields.rx_oversize);
6712 : : ice_handle_overflow(pf->offset_loaded, ICE_32_BIT_WIDTH,
6713 : : &ns->rx_jabber, &pf->old_get_stats_fields.rx_jabber);
6714 : :
6715 : : /* GLPRT_MSPDC not supported */
6716 : : /* GLPRT_XEC not supported */
6717 : :
6718 [ # # ]: 0 : for (int i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
6719 : 0 : ice_stat_update_40(hw, GLPRT_PXONRXC_H(hw->port_info->lport, i),
6720 : 0 : GLPRT_PXONRXC(hw->port_info->lport, i),
6721 : 0 : pf->offset_loaded, &os->priority_xon_rx[i],
6722 : 0 : &ns->priority_xon_rx[i]);
6723 : 0 : ice_stat_update_40(hw, GLPRT_PXONTXC_H(hw->port_info->lport, i),
6724 : 0 : GLPRT_PXONTXC(hw->port_info->lport, i),
6725 : 0 : pf->offset_loaded, &os->priority_xon_tx[i],
6726 : 0 : &ns->priority_xon_tx[i]);
6727 : 0 : ice_stat_update_40(hw, GLPRT_PXOFFRXC_H(hw->port_info->lport, i),
6728 : 0 : GLPRT_PXOFFRXC(hw->port_info->lport, i),
6729 : 0 : pf->offset_loaded, &os->priority_xoff_rx[i],
6730 : 0 : &ns->priority_xoff_rx[i]);
6731 : 0 : ice_stat_update_40(hw, GLPRT_PXOFFTXC_H(hw->port_info->lport, i),
6732 : 0 : GLPRT_PXOFFTXC(hw->port_info->lport, i),
6733 : 0 : pf->offset_loaded, &os->priority_xoff_tx[i],
6734 : 0 : &ns->priority_xoff_tx[i]);
6735 : 0 : ice_stat_update_40(hw, GLPRT_RXON2OFFCNT_H(hw->port_info->lport, i),
6736 : 0 : GLPRT_RXON2OFFCNT(hw->port_info->lport, i),
6737 : 0 : pf->offset_loaded, &os->priority_xon_2_xoff[i],
6738 : 0 : &ns->priority_xon_2_xoff[i]);
6739 : : }
6740 : :
6741 : 0 : pf->offset_loaded = true;
6742 : :
6743 [ # # ]: 0 : if (pf->main_vsi)
6744 : 0 : ice_update_vsi_stats(pf->main_vsi);
6745 : 0 : }
6746 : :
6747 : : /* Get all statistics of a port */
6748 : : static int
6749 : 0 : ice_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
6750 : : struct eth_queue_stats *qstats __rte_unused)
6751 : : {
6752 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6753 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6754 : : struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
6755 : :
6756 : : /* call read registers - updates values, now write them to struct */
6757 : 0 : ice_read_stats_registers(pf, hw);
6758 : :
6759 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
6760 : 0 : pf->main_vsi->eth_stats.rx_multicast +
6761 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
6762 : 0 : pf->main_vsi->eth_stats.rx_discards;
6763 : 0 : stats->opackets = ns->eth.tx_unicast +
6764 : 0 : ns->eth.tx_multicast +
6765 : 0 : ns->eth.tx_broadcast;
6766 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
6767 : 0 : stats->obytes = ns->eth.tx_bytes;
6768 : 0 : stats->oerrors = ns->eth.tx_errors +
6769 : 0 : pf->main_vsi->eth_stats.tx_errors;
6770 : :
6771 : : /* Rx Errors */
6772 : 0 : stats->imissed = ns->eth.rx_discards +
6773 : : pf->main_vsi->eth_stats.rx_discards;
6774 : 0 : stats->ierrors = ns->crc_errors +
6775 : 0 : ns->rx_undersize +
6776 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
6777 : :
6778 : 0 : PMD_DRV_LOG(DEBUG, "*************** PF stats start *****************");
6779 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
6780 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
6781 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast:%"PRIu64"", ns->eth.rx_multicast);
6782 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast:%"PRIu64"", ns->eth.rx_broadcast);
6783 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards:%"PRIu64"", ns->eth.rx_discards);
6784 : 0 : PMD_DRV_LOG(DEBUG, "vsi rx_discards:%"PRIu64"",
6785 : : pf->main_vsi->eth_stats.rx_discards);
6786 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
6787 : : ns->eth.rx_unknown_protocol);
6788 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
6789 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
6790 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast:%"PRIu64"", ns->eth.tx_multicast);
6791 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast:%"PRIu64"", ns->eth.tx_broadcast);
6792 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards:%"PRIu64"", ns->eth.tx_discards);
6793 : 0 : PMD_DRV_LOG(DEBUG, "vsi tx_discards:%"PRIu64"",
6794 : : pf->main_vsi->eth_stats.tx_discards);
6795 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
6796 : :
6797 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
6798 : : ns->tx_dropped_link_down);
6799 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
6800 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
6801 : : ns->illegal_bytes);
6802 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
6803 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
6804 : : ns->mac_local_faults);
6805 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
6806 : : ns->mac_remote_faults);
6807 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
6808 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
6809 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
6810 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
6811 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
6812 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
6813 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
6814 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
6815 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
6816 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
6817 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
6818 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
6819 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
6820 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
6821 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
6822 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
6823 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
6824 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
6825 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
6826 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
6827 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
6828 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
6829 : 0 : PMD_DRV_LOG(DEBUG, "rx_len_errors: %"PRIu64"", ns->rx_len_errors);
6830 : 0 : PMD_DRV_LOG(DEBUG, "************* PF stats end ****************");
6831 : 0 : return 0;
6832 : : }
6833 : :
6834 : : /* Reset the statistics */
6835 : : static int
6836 : 0 : ice_stats_reset(struct rte_eth_dev *dev)
6837 : : {
6838 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6839 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6840 : :
6841 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
6842 : 0 : pf->offset_loaded = false;
6843 [ # # ]: 0 : if (pf->main_vsi)
6844 : 0 : pf->main_vsi->offset_loaded = false;
6845 : :
6846 : : /* read the stats, reading current register values into offset */
6847 : 0 : ice_read_stats_registers(pf, hw);
6848 : :
6849 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct ice_mbuf_stats));
6850 : :
6851 : 0 : return 0;
6852 : : }
6853 : :
6854 : : static uint32_t
6855 : : ice_xstats_calc_num(void)
6856 : : {
6857 : : uint32_t num;
6858 : :
6859 : : num = ICE_NB_ETH_XSTATS + ICE_NB_MBUF_XSTATS + ICE_NB_HW_PORT_XSTATS;
6860 : :
6861 : : return num;
6862 : : }
6863 : :
6864 : : static void
6865 : : ice_update_mbuf_stats(struct rte_eth_dev *ethdev,
6866 : : struct ice_mbuf_stats *mbuf_stats)
6867 : : {
6868 : : uint16_t idx;
6869 : : struct ci_tx_queue *txq;
6870 : :
6871 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
6872 : 0 : txq = ethdev->data->tx_queues[idx];
6873 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
6874 : : }
6875 : : }
6876 : :
6877 : : static int
6878 : 0 : ice_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
6879 : : unsigned int n)
6880 : : {
6881 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6882 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6883 : : struct ice_adapter *adapter =
6884 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
6885 : : struct ice_mbuf_stats mbuf_stats = {0};
6886 : : unsigned int i;
6887 : : unsigned int count;
6888 : 0 : struct ice_hw_port_stats *hw_stats = &pf->stats;
6889 : :
6890 : : count = ice_xstats_calc_num();
6891 [ # # ]: 0 : if (n < count)
6892 : : return count;
6893 : :
6894 : 0 : ice_read_stats_registers(pf, hw);
6895 : :
6896 [ # # ]: 0 : if (!xstats)
6897 : : return 0;
6898 : :
6899 : : count = 0;
6900 : :
6901 [ # # ]: 0 : if (adapter->devargs.mbuf_check)
6902 : : ice_update_mbuf_stats(dev, &mbuf_stats);
6903 : :
6904 : : /* Get stats from ice_eth_stats struct */
6905 [ # # ]: 0 : for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
6906 : 0 : xstats[count].value =
6907 : 0 : *(uint64_t *)((char *)&hw_stats->eth +
6908 : 0 : ice_stats_strings[i].offset);
6909 : 0 : xstats[count].id = count;
6910 : 0 : count++;
6911 : : }
6912 : :
6913 : : /* Get stats from ice_mbuf_stats struct */
6914 [ # # ]: 0 : for (i = 0; i < ICE_NB_MBUF_XSTATS; i++) {
6915 : 0 : xstats[count].value =
6916 : : *(uint64_t *)((char *)&mbuf_stats + ice_mbuf_strings[i].offset);
6917 : 0 : xstats[count].id = count;
6918 : 0 : count++;
6919 : : }
6920 : :
6921 : : /* Get individual stats from ice_hw_port struct */
6922 [ # # ]: 0 : for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
6923 : 0 : xstats[count].value =
6924 : 0 : *(uint64_t *)((char *)hw_stats +
6925 : 0 : ice_hw_port_strings[i].offset);
6926 : 0 : xstats[count].id = count;
6927 : 0 : count++;
6928 : : }
6929 : :
6930 : 0 : return count;
6931 : : }
6932 : :
6933 : 0 : static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
6934 : : struct rte_eth_xstat_name *xstats_names,
6935 : : __rte_unused unsigned int limit)
6936 : : {
6937 : : unsigned int count = 0;
6938 : : unsigned int i;
6939 : :
6940 [ # # ]: 0 : if (!xstats_names)
6941 : : return ice_xstats_calc_num();
6942 : :
6943 : : /* Note: limit checked in rte_eth_xstats_names() */
6944 : :
6945 : : /* Get stats from ice_eth_stats struct */
6946 [ # # ]: 0 : for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
6947 : 0 : strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
6948 : : sizeof(xstats_names[count].name));
6949 : 0 : count++;
6950 : : }
6951 : :
6952 : : /* Get stats from ice_mbuf_stats struct */
6953 [ # # ]: 0 : for (i = 0; i < ICE_NB_MBUF_XSTATS; i++) {
6954 : 0 : strlcpy(xstats_names[count].name, ice_mbuf_strings[i].name,
6955 : : sizeof(xstats_names[count].name));
6956 : 0 : count++;
6957 : : }
6958 : :
6959 : : /* Get individual stats from ice_hw_port struct */
6960 [ # # ]: 0 : for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
6961 : 0 : strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
6962 : : sizeof(xstats_names[count].name));
6963 : 0 : count++;
6964 : : }
6965 : :
6966 : 0 : return count;
6967 : : }
6968 : :
6969 : : static int
6970 : 0 : ice_dev_flow_ops_get(struct rte_eth_dev *dev,
6971 : : const struct rte_flow_ops **ops)
6972 : : {
6973 [ # # ]: 0 : if (!dev)
6974 : : return -EINVAL;
6975 : :
6976 : 0 : *ops = &ice_flow_ops;
6977 : 0 : return 0;
6978 : : }
6979 : :
6980 : : /* Add UDP tunneling port */
6981 : : static int
6982 : 0 : ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
6983 : : struct rte_eth_udp_tunnel *udp_tunnel)
6984 : : {
6985 : : int ret = 0;
6986 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6987 : : struct ice_adapter *ad =
6988 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
6989 : :
6990 [ # # ]: 0 : if (udp_tunnel == NULL)
6991 : : return -EINVAL;
6992 : :
6993 [ # # ]: 0 : switch (udp_tunnel->prot_type) {
6994 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
6995 : 0 : ret = ice_create_tunnel(hw, TNL_VXLAN, udp_tunnel->udp_port);
6996 [ # # # # ]: 0 : if (!ret && ad->psr != NULL)
6997 : 0 : ice_parser_vxlan_tunnel_set(ad->psr,
6998 : 0 : udp_tunnel->udp_port, true);
6999 : : break;
7000 : 0 : default:
7001 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7002 : : ret = -EINVAL;
7003 : 0 : break;
7004 : : }
7005 : :
7006 : : return ret;
7007 : : }
7008 : :
7009 : : /* Delete UDP tunneling port */
7010 : : static int
7011 : 0 : ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
7012 : : struct rte_eth_udp_tunnel *udp_tunnel)
7013 : : {
7014 : : int ret = 0;
7015 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7016 : : struct ice_adapter *ad =
7017 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7018 : :
7019 [ # # ]: 0 : if (udp_tunnel == NULL)
7020 : : return -EINVAL;
7021 : :
7022 [ # # ]: 0 : switch (udp_tunnel->prot_type) {
7023 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
7024 : 0 : ret = ice_destroy_tunnel(hw, udp_tunnel->udp_port, 0);
7025 [ # # # # ]: 0 : if (!ret && ad->psr != NULL)
7026 : 0 : ice_parser_vxlan_tunnel_set(ad->psr,
7027 : 0 : udp_tunnel->udp_port, false);
7028 : : break;
7029 : 0 : default:
7030 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7031 : : ret = -EINVAL;
7032 : 0 : break;
7033 : : }
7034 : :
7035 : : return ret;
7036 : : }
7037 : :
7038 : : /**
7039 : : * ice_ptp_write_init - Set PHC time to provided value
7040 : : * @hw: Hardware private structure
7041 : : *
7042 : : * Set the PHC time to CLOCK_REALTIME
7043 : : */
7044 : 0 : static int ice_ptp_write_init(struct ice_hw *hw)
7045 : : {
7046 : : uint64_t ns;
7047 : : struct timespec sys_time;
7048 : 0 : clock_gettime(CLOCK_REALTIME, &sys_time);
7049 : : ns = rte_timespec_to_ns(&sys_time);
7050 : :
7051 : 0 : return ice_ptp_init_time(hw, ns, true);
7052 : : }
7053 : :
7054 : : static int
7055 : 0 : ice_timesync_enable(struct rte_eth_dev *dev)
7056 : : {
7057 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7058 : : struct ice_adapter *ad =
7059 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7060 : : int ret;
7061 : :
7062 [ # # ]: 0 : if (ad->txpp_ena)
7063 : : return 0;
7064 : :
7065 [ # # # # ]: 0 : if (dev->data->dev_started && !(dev->data->dev_conf.rxmode.offloads &
7066 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
7067 : 0 : PMD_DRV_LOG(ERR, "Rx timestamp offload not configured");
7068 : 0 : return -1;
7069 : : }
7070 : :
7071 [ # # ]: 0 : if (hw->func_caps.ts_func_info.src_tmr_owned) {
7072 : 0 : ret = ice_ptp_init_phc(hw);
7073 [ # # ]: 0 : if (ret) {
7074 : 0 : PMD_DRV_LOG(ERR, "Failed to initialize PHC");
7075 : 0 : return -1;
7076 : : }
7077 : :
7078 : 0 : ret = ice_ptp_write_incval(hw, ICE_PTP_NOMINAL_INCVAL_E810, true);
7079 [ # # ]: 0 : if (ret) {
7080 : 0 : PMD_DRV_LOG(ERR,
7081 : : "Failed to write PHC increment time value");
7082 : 0 : return -1;
7083 : : }
7084 : : }
7085 : :
7086 [ # # ]: 0 : if (!ice_ptp_lock(hw)) {
7087 [ # # ]: 0 : ice_debug(hw, ICE_DBG_PTP, "Failed to acquire PTP semaphore");
7088 : 0 : return ICE_ERR_NOT_READY;
7089 : : }
7090 : :
7091 : 0 : ret = ice_ptp_write_init(hw);
7092 : 0 : ice_ptp_unlock(hw);
7093 [ # # ]: 0 : if (ret)
7094 : 0 : PMD_INIT_LOG(ERR, "Failed to set current system time to PHC timer");
7095 : :
7096 : 0 : ad->ptp_ena = 1;
7097 : :
7098 : 0 : return 0;
7099 : : }
7100 : :
7101 : : static int
7102 : 0 : ice_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
7103 : : struct timespec *timestamp, uint32_t flags)
7104 : : {
7105 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7106 : : struct ice_adapter *ad =
7107 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7108 : : struct ci_rx_queue *rxq;
7109 : : uint32_t ts_high;
7110 : : uint64_t ts_ns;
7111 : :
7112 : 0 : rxq = dev->data->rx_queues[flags];
7113 : :
7114 : 0 : ts_high = rxq->time_high;
7115 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, ts_high);
7116 : 0 : *timestamp = rte_ns_to_timespec(ts_ns);
7117 : :
7118 : 0 : return 0;
7119 : : }
7120 : :
7121 : : static int
7122 : 0 : ice_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
7123 : : struct timespec *timestamp)
7124 : : {
7125 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7126 : : struct ice_adapter *ad =
7127 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7128 : 0 : uint64_t ts_ns, tstamp, tstamp_ready = 0;
7129 : : uint64_t end_time;
7130 : : const uint64_t mask = 0xFFFFFFFF;
7131 : : int ret;
7132 : :
7133 : : /* Set the end time with a delay of 10 microseconds */
7134 : 0 : end_time = rte_get_timer_cycles() + (rte_get_timer_hz() / 100000);
7135 : :
7136 : : do {
7137 : 0 : ret = ice_get_phy_tx_tstamp_ready(hw, ad->ptp_tx_block, &tstamp_ready);
7138 [ # # ]: 0 : if (ret) {
7139 : 0 : PMD_DRV_LOG(ERR, "Failed to get phy ready for timestamp");
7140 : 0 : return -1;
7141 : : }
7142 : :
7143 [ # # # # ]: 0 : if ((tstamp_ready & BIT_ULL(0)) == 0 && rte_get_timer_cycles() > end_time) {
7144 : 0 : PMD_DRV_LOG(ERR, "Timeout to get phy ready for timestamp");
7145 : 0 : return -1;
7146 : : }
7147 [ # # ]: 0 : } while ((tstamp_ready & BIT_ULL(0)) == 0);
7148 : :
7149 : 0 : ret = ice_read_phy_tstamp(hw, ad->ptp_tx_block, ad->ptp_tx_index, &tstamp);
7150 [ # # # # ]: 0 : if (ret || tstamp == 0) {
7151 : 0 : PMD_DRV_LOG(ERR, "Failed to read phy timestamp");
7152 : 0 : return -1;
7153 : : }
7154 : :
7155 : 0 : ts_ns = ice_tstamp_convert_32b_64b(hw, ad, 1, (tstamp >> 8) & mask);
7156 : 0 : *timestamp = rte_ns_to_timespec(ts_ns);
7157 : :
7158 : 0 : return 0;
7159 : : }
7160 : :
7161 : : static int
7162 : 0 : ice_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
7163 : : {
7164 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7165 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7166 : : uint32_t lo, lo2, hi;
7167 : : uint64_t time, ns;
7168 : : int ret;
7169 : :
7170 [ # # ]: 0 : if (delta > INT32_MAX || delta < INT32_MIN) {
7171 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7172 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7173 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7174 : :
7175 [ # # ]: 0 : if (lo2 < lo) {
7176 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7177 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7178 : : }
7179 : :
7180 : 0 : time = ((uint64_t)hi << 32) | lo;
7181 : 0 : ns = time + delta;
7182 : :
7183 : 0 : wr32(hw, GLTSYN_SHTIME_L(tmr_idx), ICE_LO_DWORD(ns));
7184 : 0 : wr32(hw, GLTSYN_SHTIME_H(tmr_idx), ICE_HI_DWORD(ns));
7185 : 0 : wr32(hw, GLTSYN_SHTIME_0(tmr_idx), 0);
7186 : :
7187 : 0 : ret = ice_ptp_init_time(hw, ns, true);
7188 [ # # ]: 0 : if (ret) {
7189 : 0 : PMD_DRV_LOG(ERR, "PTP init time failed, err %d", ret);
7190 : 0 : return -1;
7191 : : }
7192 : : return 0;
7193 : : }
7194 : :
7195 : 0 : ret = ice_ptp_adj_clock(hw, delta, true);
7196 [ # # ]: 0 : if (ret) {
7197 : 0 : PMD_DRV_LOG(ERR, "PTP adj clock failed, err %d", ret);
7198 : 0 : return -1;
7199 : : }
7200 : :
7201 : : return 0;
7202 : : }
7203 : :
7204 : : static int
7205 : 0 : ice_timesync_adjust_freq(struct rte_eth_dev *dev, int64_t ppm)
7206 : : {
7207 [ # # # # ]: 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7208 : : int64_t incval, diff = 0;
7209 : : bool negative = false;
7210 : : uint64_t div, rem;
7211 : : uint64_t divisor = 1000000ULL << 16;
7212 : : int shift;
7213 : : int ret;
7214 : :
7215 : 0 : incval = ice_get_base_incval(hw, ICE_SRC_TMR_MODE_NANOSECONDS);
7216 : :
7217 [ # # ]: 0 : if (ppm < 0) {
7218 : : negative = true;
7219 : 0 : ppm = -ppm;
7220 : : }
7221 : :
7222 : : /* can incval * ppm overflow ? */
7223 [ # # ]: 0 : if (log2(incval) + log2(ppm) > 62) {
7224 : 0 : rem = ppm % divisor;
7225 : 0 : div = ppm / divisor;
7226 : 0 : diff = div * incval;
7227 : 0 : ppm = rem;
7228 : :
7229 : 0 : shift = log2(incval) + log2(ppm) - 62;
7230 [ # # ]: 0 : if (shift > 0) {
7231 : : /* drop precision */
7232 : 0 : ppm >>= shift;
7233 : 0 : divisor >>= shift;
7234 : : }
7235 : : }
7236 : :
7237 [ # # ]: 0 : if (divisor)
7238 : 0 : diff = diff + incval * ppm / divisor;
7239 : :
7240 [ # # ]: 0 : if (negative)
7241 : 0 : incval -= diff;
7242 : : else
7243 : 0 : incval += diff;
7244 : :
7245 : 0 : ret = ice_ptp_write_incval_locked(hw, incval, true);
7246 [ # # ]: 0 : if (ret) {
7247 : 0 : PMD_DRV_LOG(ERR, "PTP failed to set incval, err %d", ret);
7248 : 0 : return -1;
7249 : : }
7250 : : return 0;
7251 : : }
7252 : :
7253 : : static int
7254 : 0 : ice_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
7255 : : {
7256 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7257 : : uint64_t ns;
7258 : : int ret;
7259 : :
7260 : : ns = rte_timespec_to_ns(ts);
7261 : 0 : ret = ice_ptp_init_time(hw, ns, true);
7262 [ # # ]: 0 : if (ret) {
7263 : 0 : PMD_DRV_LOG(ERR, "PTP init time failed, err %d", ret);
7264 : 0 : return -1;
7265 : : }
7266 : :
7267 : : return 0;
7268 : : }
7269 : :
7270 : : static int
7271 : 0 : ice_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
7272 : : {
7273 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7274 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7275 : : uint32_t hi, lo, lo2;
7276 : : uint64_t time;
7277 : :
7278 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7279 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7280 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7281 : :
7282 [ # # ]: 0 : if (lo2 < lo) {
7283 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
7284 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
7285 : : }
7286 : :
7287 [ # # ]: 0 : time = ((uint64_t)hi << 32) | lo;
7288 : 0 : *ts = rte_ns_to_timespec(time);
7289 : :
7290 : 0 : return 0;
7291 : : }
7292 : :
7293 : : static int
7294 : 0 : ice_timesync_disable(struct rte_eth_dev *dev)
7295 : : {
7296 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7297 : : struct ice_adapter *ad =
7298 : : ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
7299 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
7300 : : uint64_t val;
7301 : : uint8_t lport;
7302 : :
7303 [ # # ]: 0 : if (ad->txpp_ena)
7304 : : return 0;
7305 : :
7306 : 0 : lport = hw->port_info->lport;
7307 : :
7308 : 0 : ice_clear_phy_tstamp(hw, lport, 0);
7309 : :
7310 : 0 : val = ICE_READ_REG(hw, GLTSYN_ENA(tmr_idx));
7311 : 0 : val &= ~GLTSYN_ENA_TSYN_ENA_M;
7312 : 0 : ICE_WRITE_REG(hw, GLTSYN_ENA(tmr_idx), val);
7313 : :
7314 : 0 : ICE_WRITE_REG(hw, GLTSYN_INCVAL_L(tmr_idx), 0);
7315 : 0 : ICE_WRITE_REG(hw, GLTSYN_INCVAL_H(tmr_idx), 0);
7316 : :
7317 : 0 : ad->ptp_ena = 0;
7318 : :
7319 : 0 : return 0;
7320 : : }
7321 : :
7322 : : static int
7323 : 0 : ice_read_clock(__rte_unused struct rte_eth_dev *dev, uint64_t *clock)
7324 : : {
7325 : : struct timespec system_time;
7326 : :
7327 : : #ifdef RTE_EXEC_ENV_LINUX
7328 : 0 : clock_gettime(CLOCK_MONOTONIC_RAW, &system_time);
7329 : : #else
7330 : : clock_gettime(CLOCK_MONOTONIC, &system_time);
7331 : : #endif
7332 : 0 : *clock = system_time.tv_sec * NSEC_PER_SEC + system_time.tv_nsec;
7333 : :
7334 : 0 : return 0;
7335 : : }
7336 : :
7337 : : static const uint32_t *
7338 : 0 : ice_buffer_split_supported_hdr_ptypes_get(struct rte_eth_dev *dev __rte_unused,
7339 : : size_t *no_of_elements)
7340 : : {
7341 : : /* Buffer split protocol header capability. */
7342 : : static const uint32_t ptypes[] = {
7343 : : /* Non tunneled */
7344 : : RTE_PTYPE_L2_ETHER,
7345 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
7346 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_UDP,
7347 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP,
7348 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP,
7349 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
7350 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_UDP,
7351 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_TCP,
7352 : : RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_L4_SCTP,
7353 : :
7354 : : /* Tunneled */
7355 : : RTE_PTYPE_TUNNEL_GRENAT,
7356 : :
7357 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER,
7358 : :
7359 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7360 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
7361 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7362 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
7363 : :
7364 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7365 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP,
7366 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7367 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP,
7368 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7369 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP,
7370 : :
7371 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7372 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_UDP,
7373 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7374 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP,
7375 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
7376 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_SCTP,
7377 : :
7378 : : };
7379 : :
7380 : 0 : *no_of_elements = RTE_DIM(ptypes);
7381 : 0 : return ptypes;
7382 : : }
7383 : :
7384 : : static unsigned int
7385 : 0 : ice_fec_get_capa_num(struct ice_aqc_get_phy_caps_data *pcaps,
7386 : : struct rte_eth_fec_capa *speed_fec_capa)
7387 : : {
7388 : : unsigned int num = 0;
7389 : 0 : int auto_fec = (pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC) ?
7390 : 0 : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) : 0;
7391 : 0 : int link_nofec = (pcaps->link_fec_options & ICE_AQC_PHY_FEC_DIS) ?
7392 : 0 : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) : 0;
7393 : :
7394 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_100BASE_TX) {
7395 [ # # ]: 0 : if (speed_fec_capa) {
7396 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_100M;
7397 : 0 : speed_fec_capa[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7398 : : }
7399 : : num++;
7400 : : }
7401 : :
7402 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_1000BASE_T |
7403 : : ICE_AQC_PHY_EEE_EN_1000BASE_KX)) {
7404 [ # # ]: 0 : if (speed_fec_capa) {
7405 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_1G;
7406 : 0 : speed_fec_capa[num].capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7407 : : }
7408 : 0 : num++;
7409 : : }
7410 : :
7411 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_10GBASE_T |
7412 : : ICE_AQC_PHY_EEE_EN_10GBASE_KR)) {
7413 [ # # ]: 0 : if (speed_fec_capa) {
7414 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_10G;
7415 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7416 : :
7417 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN)
7418 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7419 : : }
7420 : 0 : num++;
7421 : : }
7422 : :
7423 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_25GBASE_KR) {
7424 [ # # ]: 0 : if (speed_fec_capa) {
7425 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_25G;
7426 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7427 : :
7428 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7429 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7430 : :
7431 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7432 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7433 : : }
7434 : 0 : num++;
7435 : : }
7436 : :
7437 [ # # ]: 0 : if (pcaps->eee_cap & ICE_AQC_PHY_EEE_EN_40GBASE_KR4) {
7438 [ # # ]: 0 : if (speed_fec_capa) {
7439 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_40G;
7440 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7441 : :
7442 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN)
7443 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7444 : : }
7445 : 0 : num++;
7446 : : }
7447 : :
7448 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_50GBASE_KR2 |
7449 : : ICE_AQC_PHY_EEE_EN_50GBASE_KR_PAM4)) {
7450 [ # # ]: 0 : if (speed_fec_capa) {
7451 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_50G;
7452 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7453 : :
7454 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7455 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7456 : :
7457 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7458 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7459 : : }
7460 : 0 : num++;
7461 : : }
7462 : :
7463 [ # # ]: 0 : if (pcaps->eee_cap & (ICE_AQC_PHY_EEE_EN_100GBASE_KR4 |
7464 : : ICE_AQC_PHY_EEE_EN_100GBASE_KR2_PAM4)) {
7465 [ # # ]: 0 : if (speed_fec_capa) {
7466 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_100G;
7467 : 0 : speed_fec_capa[num].capa = auto_fec | link_nofec;
7468 : :
7469 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
7470 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7471 : :
7472 [ # # ]: 0 : if (pcaps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
7473 : 0 : speed_fec_capa[num].capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7474 : : }
7475 : 0 : num++;
7476 : : }
7477 : :
7478 : 0 : return num;
7479 : : }
7480 : :
7481 : : static int
7482 : 0 : ice_fec_get_capability(struct rte_eth_dev *dev, struct rte_eth_fec_capa *speed_fec_capa,
7483 : : unsigned int num)
7484 : : {
7485 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7486 : 0 : struct ice_aqc_get_phy_caps_data pcaps = {0};
7487 : : unsigned int capa_num;
7488 : : int ret;
7489 : :
7490 : 0 : ret = ice_aq_get_phy_caps(hw->port_info, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
7491 : : &pcaps, NULL);
7492 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7493 : 0 : PMD_DRV_LOG(ERR, "Failed to get capability information: %d",
7494 : : ret);
7495 : 0 : return -ENOTSUP;
7496 : : }
7497 : :
7498 : : /* first time to get capa_num */
7499 : 0 : capa_num = ice_fec_get_capa_num(&pcaps, NULL);
7500 [ # # ]: 0 : if (!speed_fec_capa || num < capa_num)
7501 : 0 : return capa_num;
7502 : :
7503 : 0 : return ice_fec_get_capa_num(&pcaps, speed_fec_capa);
7504 : : }
7505 : :
7506 : : static int
7507 : 0 : ice_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
7508 : : {
7509 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7510 : 0 : struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7511 : 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
7512 : : bool link_up;
7513 : : u32 temp_fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7514 : 0 : struct ice_link_status link_status = {0};
7515 : 0 : struct ice_aqc_get_phy_caps_data pcaps = {0};
7516 : 0 : struct ice_port_info *pi = hw->port_info;
7517 : : u8 fec_config;
7518 : : int ret;
7519 : :
7520 [ # # ]: 0 : if (!pi)
7521 : : return -ENOTSUP;
7522 : :
7523 : 0 : ret = ice_get_link_info_safe(pf, enable_lse, &link_status);
7524 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7525 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
7526 : : ret);
7527 : 0 : return -ENOTSUP;
7528 : : }
7529 : :
7530 : 0 : link_up = link_status.link_info & ICE_AQ_LINK_UP;
7531 : :
7532 : 0 : ret = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
7533 : : &pcaps, NULL);
7534 [ # # ]: 0 : if (ret != ICE_SUCCESS) {
7535 : 0 : PMD_DRV_LOG(ERR, "Failed to get capability information: %d",
7536 : : ret);
7537 : 0 : return -ENOTSUP;
7538 : : }
7539 : :
7540 : : /* Get current FEC mode from port info */
7541 [ # # ]: 0 : if (link_up) {
7542 [ # # # ]: 0 : switch (link_status.fec_info) {
7543 : 0 : case ICE_AQ_LINK_25G_KR_FEC_EN:
7544 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7545 : 0 : break;
7546 : 0 : case ICE_AQ_LINK_25G_RS_528_FEC_EN:
7547 : : /* fall-through */
7548 : : case ICE_AQ_LINK_25G_RS_544_FEC_EN:
7549 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7550 : 0 : break;
7551 : 0 : default:
7552 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
7553 : 0 : break;
7554 : : }
7555 : 0 : return 0;
7556 : : }
7557 : :
7558 [ # # ]: 0 : if (pcaps.caps & ICE_AQC_PHY_EN_AUTO_FEC) {
7559 : 0 : *fec_capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO);
7560 : 0 : return 0;
7561 : : }
7562 : :
7563 : 0 : fec_config = pcaps.link_fec_options & ICE_AQC_PHY_FEC_MASK;
7564 : :
7565 [ # # ]: 0 : if (fec_config & (ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7566 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7567 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7568 : : ICE_AQC_PHY_FEC_25G_KR_REQ))
7569 : : temp_fec_capa |= RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
7570 : :
7571 [ # # ]: 0 : if (fec_config & (ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7572 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7573 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ))
7574 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_CAPA_MASK(RS);
7575 : :
7576 : 0 : *fec_capa = temp_fec_capa;
7577 : 0 : return 0;
7578 : : }
7579 : :
7580 : : static int
7581 : 0 : ice_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
7582 : : {
7583 : 0 : struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7584 : 0 : struct ice_port_info *pi = hw->port_info;
7585 : : struct ice_aqc_set_phy_cfg_data cfg = { 0 };
7586 : : bool fec_auto = false, fec_kr = false, fec_rs = false;
7587 : :
7588 [ # # ]: 0 : if (!pi)
7589 : : return -ENOTSUP;
7590 : :
7591 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
7592 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
7593 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
7594 : : return -EINVAL;
7595 : : /* Copy the current user PHY configuration. The current user PHY
7596 : : * configuration is initialized during probe from PHY capabilities
7597 : : * software mode, and updated on set PHY configuration.
7598 : : */
7599 [ # # ]: 0 : memcpy(&cfg, &pi->phy.curr_user_phy_cfg, sizeof(cfg));
7600 : :
7601 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
7602 : : fec_auto = true;
7603 : :
7604 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
7605 : : fec_kr = true;
7606 : :
7607 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
7608 : : fec_rs = true;
7609 : :
7610 [ # # ]: 0 : if (fec_auto) {
7611 [ # # ]: 0 : if (fec_kr || fec_rs) {
7612 [ # # ]: 0 : if (fec_rs) {
7613 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7614 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7615 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ;
7616 : : }
7617 [ # # ]: 0 : if (fec_kr) {
7618 : 0 : cfg.link_fec_opt |= ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7619 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7620 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7621 : : ICE_AQC_PHY_FEC_25G_KR_REQ;
7622 : : }
7623 : : } else {
7624 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7625 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7626 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ |
7627 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN |
7628 : : ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN |
7629 : : ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ |
7630 : : ICE_AQC_PHY_FEC_25G_KR_REQ;
7631 : : }
7632 : : } else {
7633 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
7634 [ # # ]: 0 : if (fec_rs) {
7635 : 0 : cfg.link_fec_opt = ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN |
7636 : : ICE_AQC_PHY_FEC_25G_RS_528_REQ |
7637 : : ICE_AQC_PHY_FEC_25G_RS_544_REQ;
7638 : : } else {
7639 : 0 : cfg.link_fec_opt = 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 : : return -EINVAL;
7646 : : }
7647 : : }
7648 : :
7649 : : /* Recovery of accidentally rewritten bit */
7650 [ # # ]: 0 : if (pi->phy.curr_user_phy_cfg.link_fec_opt &
7651 : : ICE_AQC_PHY_FEC_DIS)
7652 : 0 : cfg.link_fec_opt |= ICE_AQC_PHY_FEC_DIS;
7653 : :
7654 : : /* Proceed only if requesting different FEC mode */
7655 [ # # ]: 0 : if (pi->phy.curr_user_phy_cfg.link_fec_opt == cfg.link_fec_opt)
7656 : : return 0;
7657 : :
7658 : 0 : cfg.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
7659 : :
7660 [ # # ]: 0 : if (ice_aq_set_phy_cfg(pi->hw, pi, &cfg, NULL))
7661 : 0 : return -EAGAIN;
7662 : :
7663 : : return 0;
7664 : : }
7665 : :
7666 : : static int
7667 : 0 : ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
7668 : : struct rte_pci_device *pci_dev)
7669 : : {
7670 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
7671 : : sizeof(struct ice_adapter),
7672 : : ice_dev_init);
7673 : : }
7674 : :
7675 : : static int
7676 : 0 : ice_pci_remove(struct rte_pci_device *pci_dev)
7677 : : {
7678 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, ice_dev_uninit);
7679 : : }
7680 : :
7681 : : static struct rte_pci_driver rte_ice_pmd = {
7682 : : .id_table = pci_id_ice_map,
7683 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
7684 : : .probe = ice_pci_probe,
7685 : : .remove = ice_pci_remove,
7686 : : };
7687 : :
7688 : : /**
7689 : : * Driver initialization routine.
7690 : : * Invoked once at EAL init time.
7691 : : * Register itself as the [Poll Mode] Driver of PCI devices.
7692 : : */
7693 : 276 : RTE_PMD_REGISTER_PCI(net_ice, rte_ice_pmd);
7694 : : RTE_PMD_REGISTER_PCI_TABLE(net_ice, pci_id_ice_map);
7695 : : RTE_PMD_REGISTER_KMOD_DEP(net_ice, "* igb_uio | uio_pci_generic | vfio-pci");
7696 : : RTE_PMD_REGISTER_PARAM_STRING(net_ice,
7697 : : ICE_HW_DEBUG_MASK_ARG "=0xXXX"
7698 : : ICE_PROTO_XTR_ARG "=[queue:]<vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset>"
7699 : : ICE_SAFE_MODE_SUPPORT_ARG "=<0|1>"
7700 : : ICE_DEFAULT_MAC_DISABLE "=<0|1>"
7701 : : ICE_DDP_FILENAME_ARG "=</path/to/file>"
7702 : : ICE_DDP_LOAD_SCHED_ARG "=<0|1>"
7703 : : ICE_TM_LEVELS_ARG "=<N>"
7704 : : ICE_SOURCE_PRUNE_ARG "=<0|1>"
7705 : : ICE_RX_LOW_LATENCY_ARG "=<0|1>"
7706 : : ICE_LINK_STATE_ON_CLOSE "=<down|up|initial>");
7707 : :
7708 [ - + ]: 276 : RTE_LOG_REGISTER_SUFFIX(ice_logtype_init, init, NOTICE);
7709 [ - + ]: 276 : RTE_LOG_REGISTER_SUFFIX(ice_logtype_driver, driver, NOTICE);
7710 : : #ifdef RTE_ETHDEV_DEBUG_RX
7711 : : RTE_LOG_REGISTER_SUFFIX(ice_logtype_rx, rx, DEBUG);
7712 : : #endif
7713 : : #ifdef RTE_ETHDEV_DEBUG_TX
7714 : : RTE_LOG_REGISTER_SUFFIX(ice_logtype_tx, tx, DEBUG);
7715 : : #endif
7716 : :
7717 : 0 : bool is_ice_supported(struct rte_eth_dev *dev)
7718 : : {
7719 : 0 : return !strcmp(dev->device->driver->name, rte_ice_pmd.driver.name);
7720 : : }
|