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