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