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