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