1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #include <rte_string_fns.h>
6 #include <ethdev_pci.h>
13 #include <rte_tailq.h>
15 #include "eal_firmware.h"
17 #include "base/ice_sched.h"
18 #include "base/ice_flow.h"
19 #include "base/ice_dcb.h"
20 #include "base/ice_common.h"
21 #include "base/ice_ptp_hw.h"
23 #include "rte_pmd_ice.h"
24 #include "ice_ethdev.h"
26 #include "ice_generic_flow.h"
29 #define ICE_SAFE_MODE_SUPPORT_ARG "safe-mode-support"
30 #define ICE_PIPELINE_MODE_SUPPORT_ARG "pipeline-mode-support"
31 #define ICE_PROTO_XTR_ARG "proto_xtr"
32 #define ICE_HW_DEBUG_MASK_ARG "hw_debug_mask"
33 #define ICE_ONE_PPS_OUT_ARG "pps_out"
34 #define ICE_RX_LOW_LATENCY_ARG "rx_low_latency"
36 #define ICE_CYCLECOUNTER_MASK 0xffffffffffffffffULL
38 uint64_t ice_timestamp_dynflag;
39 int ice_timestamp_dynfield_offset = -1;
41 static const char * const ice_valid_args[] = {
42 ICE_SAFE_MODE_SUPPORT_ARG,
43 ICE_PIPELINE_MODE_SUPPORT_ARG,
45 ICE_HW_DEBUG_MASK_ARG,
47 ICE_RX_LOW_LATENCY_ARG,
51 #define PPS_OUT_DELAY_NS 1
53 static const struct rte_mbuf_dynfield ice_proto_xtr_metadata_param = {
54 .name = "intel_pmd_dynfield_proto_xtr_metadata",
55 .size = sizeof(uint32_t),
56 .align = __alignof__(uint32_t),
60 struct proto_xtr_ol_flag {
61 const struct rte_mbuf_dynflag param;
66 static bool ice_proto_xtr_hw_support[PROTO_XTR_MAX];
68 static struct proto_xtr_ol_flag ice_proto_xtr_ol_flag_params[] = {
70 .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
71 .ol_flag = &rte_net_ice_dynflag_proto_xtr_vlan_mask },
73 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
74 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv4_mask },
76 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
77 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_mask },
78 [PROTO_XTR_IPV6_FLOW] = {
79 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
80 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask },
82 .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
83 .ol_flag = &rte_net_ice_dynflag_proto_xtr_tcp_mask },
84 [PROTO_XTR_IP_OFFSET] = {
85 .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
86 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ip_offset_mask },
89 #define ICE_OS_DEFAULT_PKG_NAME "ICE OS Default Package"
90 #define ICE_COMMS_PKG_NAME "ICE COMMS Package"
91 #define ICE_MAX_RES_DESC_NUM 1024
93 static int ice_dev_configure(struct rte_eth_dev *dev);
94 static int ice_dev_start(struct rte_eth_dev *dev);
95 static int ice_dev_stop(struct rte_eth_dev *dev);
96 static int ice_dev_close(struct rte_eth_dev *dev);
97 static int ice_dev_reset(struct rte_eth_dev *dev);
98 static int ice_dev_info_get(struct rte_eth_dev *dev,
99 struct rte_eth_dev_info *dev_info);
100 static int ice_link_update(struct rte_eth_dev *dev,
101 int wait_to_complete);
102 static int ice_dev_set_link_up(struct rte_eth_dev *dev);
103 static int ice_dev_set_link_down(struct rte_eth_dev *dev);
105 static int ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
106 static int ice_vlan_offload_set(struct rte_eth_dev *dev, int mask);
107 static int ice_rss_reta_update(struct rte_eth_dev *dev,
108 struct rte_eth_rss_reta_entry64 *reta_conf,
110 static int ice_rss_reta_query(struct rte_eth_dev *dev,
111 struct rte_eth_rss_reta_entry64 *reta_conf,
113 static int ice_rss_hash_update(struct rte_eth_dev *dev,
114 struct rte_eth_rss_conf *rss_conf);
115 static int ice_rss_hash_conf_get(struct rte_eth_dev *dev,
116 struct rte_eth_rss_conf *rss_conf);
117 static int ice_promisc_enable(struct rte_eth_dev *dev);
118 static int ice_promisc_disable(struct rte_eth_dev *dev);
119 static int ice_allmulti_enable(struct rte_eth_dev *dev);
120 static int ice_allmulti_disable(struct rte_eth_dev *dev);
121 static int ice_vlan_filter_set(struct rte_eth_dev *dev,
124 static int ice_macaddr_set(struct rte_eth_dev *dev,
125 struct rte_ether_addr *mac_addr);
126 static int ice_macaddr_add(struct rte_eth_dev *dev,
127 struct rte_ether_addr *mac_addr,
128 __rte_unused uint32_t index,
130 static void ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
131 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
133 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
135 static int ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
137 static int ice_vlan_pvid_set(struct rte_eth_dev *dev,
138 uint16_t pvid, int on);
139 static int ice_get_eeprom_length(struct rte_eth_dev *dev);
140 static int ice_get_eeprom(struct rte_eth_dev *dev,
141 struct rte_dev_eeprom_info *eeprom);
142 static int ice_stats_get(struct rte_eth_dev *dev,
143 struct rte_eth_stats *stats);
144 static int ice_stats_reset(struct rte_eth_dev *dev);
145 static int ice_xstats_get(struct rte_eth_dev *dev,
146 struct rte_eth_xstat *xstats, unsigned int n);
147 static int ice_xstats_get_names(struct rte_eth_dev *dev,
148 struct rte_eth_xstat_name *xstats_names,
150 static int ice_dev_flow_ops_get(struct rte_eth_dev *dev,
151 const struct rte_flow_ops **ops);
152 static int ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
153 struct rte_eth_udp_tunnel *udp_tunnel);
154 static int ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
155 struct rte_eth_udp_tunnel *udp_tunnel);
156 static int ice_timesync_enable(struct rte_eth_dev *dev);
157 static int ice_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
158 struct timespec *timestamp,
160 static int ice_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
161 struct timespec *timestamp);
162 static int ice_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
163 static int ice_timesync_read_time(struct rte_eth_dev *dev,
164 struct timespec *timestamp);
165 static int ice_timesync_write_time(struct rte_eth_dev *dev,
166 const struct timespec *timestamp);
167 static int ice_timesync_disable(struct rte_eth_dev *dev);
169 static const struct rte_pci_id pci_id_ice_map[] = {
170 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_BACKPLANE) },
171 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_SFP) },
172 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_10G_BASE_T) },
173 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_1GBE) },
174 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_QSFP) },
175 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) },
176 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_QSFP) },
177 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_SFP) },
178 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_BACKPLANE) },
179 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_QSFP) },
180 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_SFP) },
181 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_BACKPLANE) },
182 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_QSFP) },
183 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SFP) },
184 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_10G_BASE_T) },
185 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SGMII) },
186 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_BACKPLANE) },
187 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_QSFP) },
188 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SFP) },
189 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_10G_BASE_T) },
190 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SGMII) },
191 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_BACKPLANE) },
192 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SFP) },
193 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_10G_BASE_T) },
194 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SGMII) },
195 { .vendor_id = 0, /* sentinel */ },
198 static const struct eth_dev_ops ice_eth_dev_ops = {
199 .dev_configure = ice_dev_configure,
200 .dev_start = ice_dev_start,
201 .dev_stop = ice_dev_stop,
202 .dev_close = ice_dev_close,
203 .dev_reset = ice_dev_reset,
204 .dev_set_link_up = ice_dev_set_link_up,
205 .dev_set_link_down = ice_dev_set_link_down,
206 .rx_queue_start = ice_rx_queue_start,
207 .rx_queue_stop = ice_rx_queue_stop,
208 .tx_queue_start = ice_tx_queue_start,
209 .tx_queue_stop = ice_tx_queue_stop,
210 .rx_queue_setup = ice_rx_queue_setup,
211 .rx_queue_release = ice_dev_rx_queue_release,
212 .tx_queue_setup = ice_tx_queue_setup,
213 .tx_queue_release = ice_dev_tx_queue_release,
214 .dev_infos_get = ice_dev_info_get,
215 .dev_supported_ptypes_get = ice_dev_supported_ptypes_get,
216 .link_update = ice_link_update,
217 .mtu_set = ice_mtu_set,
218 .mac_addr_set = ice_macaddr_set,
219 .mac_addr_add = ice_macaddr_add,
220 .mac_addr_remove = ice_macaddr_remove,
221 .vlan_filter_set = ice_vlan_filter_set,
222 .vlan_offload_set = ice_vlan_offload_set,
223 .reta_update = ice_rss_reta_update,
224 .reta_query = ice_rss_reta_query,
225 .rss_hash_update = ice_rss_hash_update,
226 .rss_hash_conf_get = ice_rss_hash_conf_get,
227 .promiscuous_enable = ice_promisc_enable,
228 .promiscuous_disable = ice_promisc_disable,
229 .allmulticast_enable = ice_allmulti_enable,
230 .allmulticast_disable = ice_allmulti_disable,
231 .rx_queue_intr_enable = ice_rx_queue_intr_enable,
232 .rx_queue_intr_disable = ice_rx_queue_intr_disable,
233 .fw_version_get = ice_fw_version_get,
234 .vlan_pvid_set = ice_vlan_pvid_set,
235 .rxq_info_get = ice_rxq_info_get,
236 .txq_info_get = ice_txq_info_get,
237 .rx_burst_mode_get = ice_rx_burst_mode_get,
238 .tx_burst_mode_get = ice_tx_burst_mode_get,
239 .get_eeprom_length = ice_get_eeprom_length,
240 .get_eeprom = ice_get_eeprom,
241 .stats_get = ice_stats_get,
242 .stats_reset = ice_stats_reset,
243 .xstats_get = ice_xstats_get,
244 .xstats_get_names = ice_xstats_get_names,
245 .xstats_reset = ice_stats_reset,
246 .flow_ops_get = ice_dev_flow_ops_get,
247 .udp_tunnel_port_add = ice_dev_udp_tunnel_port_add,
248 .udp_tunnel_port_del = ice_dev_udp_tunnel_port_del,
249 .tx_done_cleanup = ice_tx_done_cleanup,
250 .get_monitor_addr = ice_get_monitor_addr,
251 .timesync_enable = ice_timesync_enable,
252 .timesync_read_rx_timestamp = ice_timesync_read_rx_timestamp,
253 .timesync_read_tx_timestamp = ice_timesync_read_tx_timestamp,
254 .timesync_adjust_time = ice_timesync_adjust_time,
255 .timesync_read_time = ice_timesync_read_time,
256 .timesync_write_time = ice_timesync_write_time,
257 .timesync_disable = ice_timesync_disable,
260 /* store statistics names and its offset in stats structure */
261 struct ice_xstats_name_off {
262 char name[RTE_ETH_XSTATS_NAME_SIZE];
266 static const struct ice_xstats_name_off ice_stats_strings[] = {
267 {"rx_unicast_packets", offsetof(struct ice_eth_stats, rx_unicast)},
268 {"rx_multicast_packets", offsetof(struct ice_eth_stats, rx_multicast)},
269 {"rx_broadcast_packets", offsetof(struct ice_eth_stats, rx_broadcast)},
270 {"rx_dropped_packets", offsetof(struct ice_eth_stats, rx_discards)},
271 {"rx_unknown_protocol_packets", offsetof(struct ice_eth_stats,
272 rx_unknown_protocol)},
273 {"tx_unicast_packets", offsetof(struct ice_eth_stats, tx_unicast)},
274 {"tx_multicast_packets", offsetof(struct ice_eth_stats, tx_multicast)},
275 {"tx_broadcast_packets", offsetof(struct ice_eth_stats, tx_broadcast)},
276 {"tx_dropped_packets", offsetof(struct ice_eth_stats, tx_discards)},
279 #define ICE_NB_ETH_XSTATS (sizeof(ice_stats_strings) / \
280 sizeof(ice_stats_strings[0]))
282 static const struct ice_xstats_name_off ice_hw_port_strings[] = {
283 {"tx_link_down_dropped", offsetof(struct ice_hw_port_stats,
284 tx_dropped_link_down)},
285 {"rx_crc_errors", offsetof(struct ice_hw_port_stats, crc_errors)},
286 {"rx_illegal_byte_errors", offsetof(struct ice_hw_port_stats,
288 {"rx_error_bytes", offsetof(struct ice_hw_port_stats, error_bytes)},
289 {"mac_local_errors", offsetof(struct ice_hw_port_stats,
291 {"mac_remote_errors", offsetof(struct ice_hw_port_stats,
293 {"rx_len_errors", offsetof(struct ice_hw_port_stats,
295 {"tx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_tx)},
296 {"rx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_rx)},
297 {"tx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_tx)},
298 {"rx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_rx)},
299 {"rx_size_64_packets", offsetof(struct ice_hw_port_stats, rx_size_64)},
300 {"rx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
302 {"rx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
304 {"rx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
306 {"rx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
308 {"rx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
310 {"rx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
312 {"rx_undersized_errors", offsetof(struct ice_hw_port_stats,
314 {"rx_oversize_errors", offsetof(struct ice_hw_port_stats,
316 {"rx_mac_short_pkt_dropped", offsetof(struct ice_hw_port_stats,
317 mac_short_pkt_dropped)},
318 {"rx_fragmented_errors", offsetof(struct ice_hw_port_stats,
320 {"rx_jabber_errors", offsetof(struct ice_hw_port_stats, rx_jabber)},
321 {"tx_size_64_packets", offsetof(struct ice_hw_port_stats, tx_size_64)},
322 {"tx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
324 {"tx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
326 {"tx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
328 {"tx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
330 {"tx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
332 {"tx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
336 #define ICE_NB_HW_PORT_XSTATS (sizeof(ice_hw_port_strings) / \
337 sizeof(ice_hw_port_strings[0]))
340 ice_init_controlq_parameter(struct ice_hw *hw)
342 /* fields for adminq */
343 hw->adminq.num_rq_entries = ICE_ADMINQ_LEN;
344 hw->adminq.num_sq_entries = ICE_ADMINQ_LEN;
345 hw->adminq.rq_buf_size = ICE_ADMINQ_BUF_SZ;
346 hw->adminq.sq_buf_size = ICE_ADMINQ_BUF_SZ;
348 /* fields for mailboxq, DPDK used as PF host */
349 hw->mailboxq.num_rq_entries = ICE_MAILBOXQ_LEN;
350 hw->mailboxq.num_sq_entries = ICE_MAILBOXQ_LEN;
351 hw->mailboxq.rq_buf_size = ICE_MAILBOXQ_BUF_SZ;
352 hw->mailboxq.sq_buf_size = ICE_MAILBOXQ_BUF_SZ;
354 /* fields for sideband queue */
355 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
356 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
357 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
358 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
363 lookup_proto_xtr_type(const char *xtr_name)
367 enum proto_xtr_type type;
369 { "vlan", PROTO_XTR_VLAN },
370 { "ipv4", PROTO_XTR_IPV4 },
371 { "ipv6", PROTO_XTR_IPV6 },
372 { "ipv6_flow", PROTO_XTR_IPV6_FLOW },
373 { "tcp", PROTO_XTR_TCP },
374 { "ip_offset", PROTO_XTR_IP_OFFSET },
378 for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
379 if (strcmp(xtr_name, xtr_type_map[i].name) == 0)
380 return xtr_type_map[i].type;
387 * Parse elem, the elem could be single number/range or '(' ')' group
388 * 1) A single number elem, it's just a simple digit. e.g. 9
389 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
390 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
391 * Within group elem, '-' used for a range separator;
392 * ',' used for a single number.
395 parse_queue_set(const char *input, int xtr_type, struct ice_devargs *devargs)
397 const char *str = input;
402 while (isblank(*str))
405 if (!isdigit(*str) && *str != '(')
408 /* process single number or single range of number */
411 idx = strtoul(str, &end, 10);
412 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
415 while (isblank(*end))
421 /* process single <number>-<number> */
424 while (isblank(*end))
430 idx = strtoul(end, &end, 10);
431 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
435 while (isblank(*end))
442 for (idx = RTE_MIN(min, max);
443 idx <= RTE_MAX(min, max); idx++)
444 devargs->proto_xtr[idx] = xtr_type;
449 /* process set within bracket */
451 while (isblank(*str))
456 min = ICE_MAX_QUEUE_NUM;
458 /* go ahead to the first digit */
459 while (isblank(*str))
464 /* get the digit value */
466 idx = strtoul(str, &end, 10);
467 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
470 /* go ahead to separator '-',',' and ')' */
471 while (isblank(*end))
474 if (min == ICE_MAX_QUEUE_NUM)
476 else /* avoid continuous '-' */
478 } else if (*end == ',' || *end == ')') {
480 if (min == ICE_MAX_QUEUE_NUM)
483 for (idx = RTE_MIN(min, max);
484 idx <= RTE_MAX(min, max); idx++)
485 devargs->proto_xtr[idx] = xtr_type;
487 min = ICE_MAX_QUEUE_NUM;
493 } while (*end != ')' && *end != '\0');
499 parse_queue_proto_xtr(const char *queues, struct ice_devargs *devargs)
501 const char *queue_start;
506 while (isblank(*queues))
509 if (*queues != '[') {
510 xtr_type = lookup_proto_xtr_type(queues);
514 devargs->proto_xtr_dflt = xtr_type;
521 while (isblank(*queues))
526 queue_start = queues;
528 /* go across a complete bracket */
529 if (*queue_start == '(') {
530 queues += strcspn(queues, ")");
535 /* scan the separator ':' */
536 queues += strcspn(queues, ":");
537 if (*queues++ != ':')
539 while (isblank(*queues))
542 for (idx = 0; ; idx++) {
543 if (isblank(queues[idx]) ||
544 queues[idx] == ',' ||
545 queues[idx] == ']' ||
549 if (idx > sizeof(xtr_name) - 2)
552 xtr_name[idx] = queues[idx];
554 xtr_name[idx] = '\0';
555 xtr_type = lookup_proto_xtr_type(xtr_name);
561 while (isblank(*queues) || *queues == ',' || *queues == ']')
564 if (parse_queue_set(queue_start, xtr_type, devargs) < 0)
566 } while (*queues != '\0');
572 handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
575 struct ice_devargs *devargs = extra_args;
577 if (value == NULL || extra_args == NULL)
580 if (parse_queue_proto_xtr(value, devargs) < 0) {
582 "The protocol extraction parameter is wrong : '%s'",
591 ice_check_proto_xtr_support(struct ice_hw *hw)
593 #define FLX_REG(val, fld, idx) \
594 (((val) & GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_M) >> \
595 GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_S)
602 [PROTO_XTR_VLAN] = { ICE_RXDID_COMMS_AUX_VLAN,
604 ICE_PROT_EVLAN_O, ICE_PROT_VLAN_O},
605 [PROTO_XTR_IPV4] = { ICE_RXDID_COMMS_AUX_IPV4,
607 ICE_PROT_IPV4_OF_OR_S,
608 ICE_PROT_IPV4_OF_OR_S },
609 [PROTO_XTR_IPV6] = { ICE_RXDID_COMMS_AUX_IPV6,
611 ICE_PROT_IPV6_OF_OR_S,
612 ICE_PROT_IPV6_OF_OR_S },
613 [PROTO_XTR_IPV6_FLOW] = { ICE_RXDID_COMMS_AUX_IPV6_FLOW,
615 ICE_PROT_IPV6_OF_OR_S,
616 ICE_PROT_IPV6_OF_OR_S },
617 [PROTO_XTR_TCP] = { ICE_RXDID_COMMS_AUX_TCP,
619 ICE_PROT_TCP_IL, ICE_PROT_ID_INVAL },
620 [PROTO_XTR_IP_OFFSET] = { ICE_RXDID_COMMS_AUX_IP_OFFSET,
622 ICE_PROT_IPV4_OF_OR_S,
623 ICE_PROT_IPV6_OF_OR_S },
627 for (i = 0; i < RTE_DIM(xtr_sets); i++) {
628 uint32_t rxdid = xtr_sets[i].rxdid;
631 if (xtr_sets[i].protid_0 != ICE_PROT_ID_INVAL) {
632 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_4(rxdid));
634 if (FLX_REG(v, PROT_MDID, 4) == xtr_sets[i].protid_0 &&
635 FLX_REG(v, RXDID_OPCODE, 4) == xtr_sets[i].opcode)
636 ice_proto_xtr_hw_support[i] = true;
639 if (xtr_sets[i].protid_1 != ICE_PROT_ID_INVAL) {
640 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_5(rxdid));
642 if (FLX_REG(v, PROT_MDID, 5) == xtr_sets[i].protid_1 &&
643 FLX_REG(v, RXDID_OPCODE, 5) == xtr_sets[i].opcode)
644 ice_proto_xtr_hw_support[i] = true;
650 ice_res_pool_init(struct ice_res_pool_info *pool, uint32_t base,
653 struct pool_entry *entry;
658 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
661 "Failed to allocate memory for resource pool");
665 /* queue heap initialize */
666 pool->num_free = num;
669 LIST_INIT(&pool->alloc_list);
670 LIST_INIT(&pool->free_list);
672 /* Initialize element */
676 LIST_INSERT_HEAD(&pool->free_list, entry, next);
681 ice_res_pool_alloc(struct ice_res_pool_info *pool,
684 struct pool_entry *entry, *valid_entry;
687 PMD_INIT_LOG(ERR, "Invalid parameter");
691 if (pool->num_free < num) {
692 PMD_INIT_LOG(ERR, "No resource. ask:%u, available:%u",
693 num, pool->num_free);
698 /* Lookup in free list and find most fit one */
699 LIST_FOREACH(entry, &pool->free_list, next) {
700 if (entry->len >= num) {
702 if (entry->len == num) {
707 valid_entry->len > entry->len)
712 /* Not find one to satisfy the request, return */
714 PMD_INIT_LOG(ERR, "No valid entry found");
718 * The entry have equal queue number as requested,
719 * remove it from alloc_list.
721 if (valid_entry->len == num) {
722 LIST_REMOVE(valid_entry, next);
725 * The entry have more numbers than requested,
726 * create a new entry for alloc_list and minus its
727 * queue base and number in free_list.
729 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
732 "Failed to allocate memory for "
736 entry->base = valid_entry->base;
738 valid_entry->base += num;
739 valid_entry->len -= num;
743 /* Insert it into alloc list, not sorted */
744 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
746 pool->num_free -= valid_entry->len;
747 pool->num_alloc += valid_entry->len;
749 return valid_entry->base + pool->base;
753 ice_res_pool_destroy(struct ice_res_pool_info *pool)
755 struct pool_entry *entry, *next_entry;
760 for (entry = LIST_FIRST(&pool->alloc_list);
761 entry && (next_entry = LIST_NEXT(entry, next), 1);
762 entry = next_entry) {
763 LIST_REMOVE(entry, next);
767 for (entry = LIST_FIRST(&pool->free_list);
768 entry && (next_entry = LIST_NEXT(entry, next), 1);
769 entry = next_entry) {
770 LIST_REMOVE(entry, next);
777 LIST_INIT(&pool->alloc_list);
778 LIST_INIT(&pool->free_list);
782 ice_vsi_config_default_rss(struct ice_aqc_vsi_props *info)
784 /* Set VSI LUT selection */
785 info->q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI &
786 ICE_AQ_VSI_Q_OPT_RSS_LUT_M;
787 /* Set Hash scheme */
788 info->q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_TPLZ &
789 ICE_AQ_VSI_Q_OPT_RSS_HASH_M;
791 info->q_opt_tc = ICE_AQ_VSI_Q_OPT_TC_OVR_M;
794 static enum ice_status
795 ice_vsi_config_tc_queue_mapping(struct ice_vsi *vsi,
796 struct ice_aqc_vsi_props *info,
797 uint8_t enabled_tcmap)
799 uint16_t bsf, qp_idx;
801 /* default tc 0 now. Multi-TC supporting need to be done later.
802 * Configure TC and queue mapping parameters, for enabled TC,
803 * allocate qpnum_per_tc queues to this traffic.
805 if (enabled_tcmap != 0x01) {
806 PMD_INIT_LOG(ERR, "only TC0 is supported");
810 vsi->nb_qps = RTE_MIN(vsi->nb_qps, ICE_MAX_Q_PER_TC);
811 bsf = rte_bsf32(vsi->nb_qps);
812 /* Adjust the queue number to actual queues that can be applied */
813 vsi->nb_qps = 0x1 << bsf;
816 /* Set tc and queue mapping with VSI */
817 info->tc_mapping[0] = rte_cpu_to_le_16((qp_idx <<
818 ICE_AQ_VSI_TC_Q_OFFSET_S) |
819 (bsf << ICE_AQ_VSI_TC_Q_NUM_S));
821 /* Associate queue number with VSI */
822 info->mapping_flags |= rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
823 info->q_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
824 info->q_mapping[1] = rte_cpu_to_le_16(vsi->nb_qps);
825 info->valid_sections |=
826 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
827 /* Set the info.ingress_table and info.egress_table
828 * for UP translate table. Now just set it to 1:1 map by default
829 * -- 0b 111 110 101 100 011 010 001 000 == 0xFAC688
831 #define ICE_TC_QUEUE_TABLE_DFLT 0x00FAC688
832 info->ingress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
833 info->egress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
834 info->outer_up_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
839 ice_init_mac_address(struct rte_eth_dev *dev)
841 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
843 if (!rte_is_unicast_ether_addr
844 ((struct rte_ether_addr *)hw->port_info[0].mac.lan_addr)) {
845 PMD_INIT_LOG(ERR, "Invalid MAC address");
850 (struct rte_ether_addr *)hw->port_info[0].mac.lan_addr,
851 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr);
853 dev->data->mac_addrs =
854 rte_zmalloc(NULL, sizeof(struct rte_ether_addr) * ICE_NUM_MACADDR_MAX, 0);
855 if (!dev->data->mac_addrs) {
857 "Failed to allocate memory to store mac address");
860 /* store it to dev data */
862 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr,
863 &dev->data->mac_addrs[0]);
867 /* Find out specific MAC filter */
868 static struct ice_mac_filter *
869 ice_find_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *macaddr)
871 struct ice_mac_filter *f;
873 TAILQ_FOREACH(f, &vsi->mac_list, next) {
874 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
882 ice_add_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
884 struct ice_fltr_list_entry *m_list_itr = NULL;
885 struct ice_mac_filter *f;
886 struct LIST_HEAD_TYPE list_head;
887 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
890 /* If it's added and configured, return */
891 f = ice_find_mac_filter(vsi, mac_addr);
893 PMD_DRV_LOG(INFO, "This MAC filter already exists.");
897 INIT_LIST_HEAD(&list_head);
899 m_list_itr = (struct ice_fltr_list_entry *)
900 ice_malloc(hw, sizeof(*m_list_itr));
905 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
906 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
907 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
908 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
909 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
910 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
911 m_list_itr->fltr_info.vsi_handle = vsi->idx;
913 LIST_ADD(&m_list_itr->list_entry, &list_head);
916 ret = ice_add_mac(hw, &list_head);
917 if (ret != ICE_SUCCESS) {
918 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
922 /* Add the mac addr into mac list */
923 f = rte_zmalloc(NULL, sizeof(*f), 0);
925 PMD_DRV_LOG(ERR, "failed to allocate memory");
929 rte_ether_addr_copy(mac_addr, &f->mac_info.mac_addr);
930 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
936 rte_free(m_list_itr);
941 ice_remove_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
943 struct ice_fltr_list_entry *m_list_itr = NULL;
944 struct ice_mac_filter *f;
945 struct LIST_HEAD_TYPE list_head;
946 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
949 /* Can't find it, return an error */
950 f = ice_find_mac_filter(vsi, mac_addr);
954 INIT_LIST_HEAD(&list_head);
956 m_list_itr = (struct ice_fltr_list_entry *)
957 ice_malloc(hw, sizeof(*m_list_itr));
962 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
963 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
964 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
965 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
966 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
967 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
968 m_list_itr->fltr_info.vsi_handle = vsi->idx;
970 LIST_ADD(&m_list_itr->list_entry, &list_head);
972 /* remove the mac filter */
973 ret = ice_remove_mac(hw, &list_head);
974 if (ret != ICE_SUCCESS) {
975 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
980 /* Remove the mac addr from mac list */
981 TAILQ_REMOVE(&vsi->mac_list, f, next);
987 rte_free(m_list_itr);
991 /* Find out specific VLAN filter */
992 static struct ice_vlan_filter *
993 ice_find_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
995 struct ice_vlan_filter *f;
997 TAILQ_FOREACH(f, &vsi->vlan_list, next) {
998 if (vlan->tpid == f->vlan_info.vlan.tpid &&
999 vlan->vid == f->vlan_info.vlan.vid)
1007 ice_add_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1009 struct ice_fltr_list_entry *v_list_itr = NULL;
1010 struct ice_vlan_filter *f;
1011 struct LIST_HEAD_TYPE list_head;
1015 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1018 hw = ICE_VSI_TO_HW(vsi);
1020 /* If it's added and configured, return. */
1021 f = ice_find_vlan_filter(vsi, vlan);
1023 PMD_DRV_LOG(INFO, "This VLAN filter already exists.");
1027 if (!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on)
1030 INIT_LIST_HEAD(&list_head);
1032 v_list_itr = (struct ice_fltr_list_entry *)
1033 ice_malloc(hw, sizeof(*v_list_itr));
1038 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1039 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1040 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1041 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1042 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1043 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1044 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1045 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1047 LIST_ADD(&v_list_itr->list_entry, &list_head);
1050 ret = ice_add_vlan(hw, &list_head);
1051 if (ret != ICE_SUCCESS) {
1052 PMD_DRV_LOG(ERR, "Failed to add VLAN filter");
1057 /* Add vlan into vlan list */
1058 f = rte_zmalloc(NULL, sizeof(*f), 0);
1060 PMD_DRV_LOG(ERR, "failed to allocate memory");
1064 f->vlan_info.vlan.tpid = vlan->tpid;
1065 f->vlan_info.vlan.vid = vlan->vid;
1066 TAILQ_INSERT_TAIL(&vsi->vlan_list, f, next);
1072 rte_free(v_list_itr);
1077 ice_remove_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1079 struct ice_fltr_list_entry *v_list_itr = NULL;
1080 struct ice_vlan_filter *f;
1081 struct LIST_HEAD_TYPE list_head;
1085 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1088 hw = ICE_VSI_TO_HW(vsi);
1090 /* Can't find it, return an error */
1091 f = ice_find_vlan_filter(vsi, vlan);
1095 INIT_LIST_HEAD(&list_head);
1097 v_list_itr = (struct ice_fltr_list_entry *)
1098 ice_malloc(hw, sizeof(*v_list_itr));
1104 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1105 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1106 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1107 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1108 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1109 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1110 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1111 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1113 LIST_ADD(&v_list_itr->list_entry, &list_head);
1115 /* remove the vlan filter */
1116 ret = ice_remove_vlan(hw, &list_head);
1117 if (ret != ICE_SUCCESS) {
1118 PMD_DRV_LOG(ERR, "Failed to remove VLAN filter");
1123 /* Remove the vlan id from vlan list */
1124 TAILQ_REMOVE(&vsi->vlan_list, f, next);
1130 rte_free(v_list_itr);
1135 ice_remove_all_mac_vlan_filters(struct ice_vsi *vsi)
1137 struct ice_mac_filter *m_f;
1138 struct ice_vlan_filter *v_f;
1142 if (!vsi || !vsi->mac_num)
1145 RTE_TAILQ_FOREACH_SAFE(m_f, &vsi->mac_list, next, temp) {
1146 ret = ice_remove_mac_filter(vsi, &m_f->mac_info.mac_addr);
1147 if (ret != ICE_SUCCESS) {
1153 if (vsi->vlan_num == 0)
1156 RTE_TAILQ_FOREACH_SAFE(v_f, &vsi->vlan_list, next, temp) {
1157 ret = ice_remove_vlan_filter(vsi, &v_f->vlan_info.vlan);
1158 if (ret != ICE_SUCCESS) {
1170 ice_pf_enable_irq0(struct ice_hw *hw)
1172 /* reset the registers */
1173 ICE_WRITE_REG(hw, PFINT_OICR_ENA, 0);
1174 ICE_READ_REG(hw, PFINT_OICR);
1177 ICE_WRITE_REG(hw, PFINT_OICR_ENA,
1178 (uint32_t)(PFINT_OICR_ENA_INT_ENA_M &
1179 (~PFINT_OICR_LINK_STAT_CHANGE_M)));
1181 ICE_WRITE_REG(hw, PFINT_OICR_CTL,
1182 (0 & PFINT_OICR_CTL_MSIX_INDX_M) |
1183 ((0 << PFINT_OICR_CTL_ITR_INDX_S) &
1184 PFINT_OICR_CTL_ITR_INDX_M) |
1185 PFINT_OICR_CTL_CAUSE_ENA_M);
1187 ICE_WRITE_REG(hw, PFINT_FW_CTL,
1188 (0 & PFINT_FW_CTL_MSIX_INDX_M) |
1189 ((0 << PFINT_FW_CTL_ITR_INDX_S) &
1190 PFINT_FW_CTL_ITR_INDX_M) |
1191 PFINT_FW_CTL_CAUSE_ENA_M);
1193 ICE_WRITE_REG(hw, PFINT_OICR_ENA, PFINT_OICR_ENA_INT_ENA_M);
1196 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
1197 GLINT_DYN_CTL_INTENA_M |
1198 GLINT_DYN_CTL_CLEARPBA_M |
1199 GLINT_DYN_CTL_ITR_INDX_M);
1206 ice_pf_disable_irq0(struct ice_hw *hw)
1208 /* Disable all interrupt types */
1209 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
1215 ice_handle_aq_msg(struct rte_eth_dev *dev)
1217 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1218 struct ice_ctl_q_info *cq = &hw->adminq;
1219 struct ice_rq_event_info event;
1220 uint16_t pending, opcode;
1223 event.buf_len = ICE_AQ_MAX_BUF_LEN;
1224 event.msg_buf = rte_zmalloc(NULL, event.buf_len, 0);
1225 if (!event.msg_buf) {
1226 PMD_DRV_LOG(ERR, "Failed to allocate mem");
1232 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1234 if (ret != ICE_SUCCESS) {
1236 "Failed to read msg from AdminQ, "
1238 hw->adminq.sq_last_status);
1241 opcode = rte_le_to_cpu_16(event.desc.opcode);
1244 case ice_aqc_opc_get_link_status:
1245 ret = ice_link_update(dev, 0);
1247 rte_eth_dev_callback_process
1248 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1251 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
1256 rte_free(event.msg_buf);
1261 * Interrupt handler triggered by NIC for handling
1262 * specific interrupt.
1265 * Pointer to interrupt handle.
1267 * The address of parameter (struct rte_eth_dev *) regsitered before.
1273 ice_interrupt_handler(void *param)
1275 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1276 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1284 uint32_t int_fw_ctl;
1287 /* Disable interrupt */
1288 ice_pf_disable_irq0(hw);
1290 /* read out interrupt causes */
1291 oicr = ICE_READ_REG(hw, PFINT_OICR);
1293 int_fw_ctl = ICE_READ_REG(hw, PFINT_FW_CTL);
1296 /* No interrupt event indicated */
1297 if (!(oicr & PFINT_OICR_INTEVENT_M)) {
1298 PMD_DRV_LOG(INFO, "No interrupt event");
1303 if (int_fw_ctl & PFINT_FW_CTL_INTEVENT_M) {
1304 PMD_DRV_LOG(INFO, "FW_CTL: link state change event");
1305 ice_handle_aq_msg(dev);
1308 if (oicr & PFINT_OICR_LINK_STAT_CHANGE_M) {
1309 PMD_DRV_LOG(INFO, "OICR: link state change event");
1310 ret = ice_link_update(dev, 0);
1312 rte_eth_dev_callback_process
1313 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1317 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1318 PMD_DRV_LOG(WARNING, "OICR: MDD event");
1319 reg = ICE_READ_REG(hw, GL_MDET_TX_PQM);
1320 if (reg & GL_MDET_TX_PQM_VALID_M) {
1321 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1322 GL_MDET_TX_PQM_PF_NUM_S;
1323 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1324 GL_MDET_TX_PQM_MAL_TYPE_S;
1325 queue = (reg & GL_MDET_TX_PQM_QNUM_M) >>
1326 GL_MDET_TX_PQM_QNUM_S;
1328 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1329 "%d by PQM on TX queue %d PF# %d",
1330 event, queue, pf_num);
1333 reg = ICE_READ_REG(hw, GL_MDET_TX_TCLAN);
1334 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1335 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1336 GL_MDET_TX_TCLAN_PF_NUM_S;
1337 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1338 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1339 queue = (reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1340 GL_MDET_TX_TCLAN_QNUM_S;
1342 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1343 "%d by TCLAN on TX queue %d PF# %d",
1344 event, queue, pf_num);
1348 /* Enable interrupt */
1349 ice_pf_enable_irq0(hw);
1350 rte_intr_ack(dev->intr_handle);
1354 ice_init_proto_xtr(struct rte_eth_dev *dev)
1356 struct ice_adapter *ad =
1357 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1358 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1359 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1360 const struct proto_xtr_ol_flag *ol_flag;
1361 bool proto_xtr_enable = false;
1365 pf->proto_xtr = rte_zmalloc(NULL, pf->lan_nb_qps, 0);
1366 if (unlikely(pf->proto_xtr == NULL)) {
1367 PMD_DRV_LOG(ERR, "No memory for setting up protocol extraction table");
1371 for (i = 0; i < pf->lan_nb_qps; i++) {
1372 pf->proto_xtr[i] = ad->devargs.proto_xtr[i] != PROTO_XTR_NONE ?
1373 ad->devargs.proto_xtr[i] :
1374 ad->devargs.proto_xtr_dflt;
1376 if (pf->proto_xtr[i] != PROTO_XTR_NONE) {
1377 uint8_t type = pf->proto_xtr[i];
1379 ice_proto_xtr_ol_flag_params[type].required = true;
1380 proto_xtr_enable = true;
1384 if (likely(!proto_xtr_enable))
1387 ice_check_proto_xtr_support(hw);
1389 offset = rte_mbuf_dynfield_register(&ice_proto_xtr_metadata_param);
1390 if (unlikely(offset == -1)) {
1392 "Protocol extraction metadata is disabled in mbuf with error %d",
1398 "Protocol extraction metadata offset in mbuf is : %d",
1400 rte_net_ice_dynfield_proto_xtr_metadata_offs = offset;
1402 for (i = 0; i < RTE_DIM(ice_proto_xtr_ol_flag_params); i++) {
1403 ol_flag = &ice_proto_xtr_ol_flag_params[i];
1405 if (!ol_flag->required)
1408 if (!ice_proto_xtr_hw_support[i]) {
1410 "Protocol extraction type %u is not supported in hardware",
1412 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1416 offset = rte_mbuf_dynflag_register(&ol_flag->param);
1417 if (unlikely(offset == -1)) {
1419 "Protocol extraction offload '%s' failed to register with error %d",
1420 ol_flag->param.name, -rte_errno);
1422 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1427 "Protocol extraction offload '%s' offset in mbuf is : %d",
1428 ol_flag->param.name, offset);
1429 *ol_flag->ol_flag = 1ULL << offset;
1433 /* Initialize SW parameters of PF */
1435 ice_pf_sw_init(struct rte_eth_dev *dev)
1437 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1438 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1441 (uint16_t)RTE_MIN(hw->func_caps.common_cap.num_txq,
1442 hw->func_caps.common_cap.num_rxq);
1444 pf->lan_nb_qps = pf->lan_nb_qp_max;
1446 ice_init_proto_xtr(dev);
1448 if (hw->func_caps.fd_fltr_guar > 0 ||
1449 hw->func_caps.fd_fltr_best_effort > 0) {
1450 pf->flags |= ICE_FLAG_FDIR;
1451 pf->fdir_nb_qps = ICE_DEFAULT_QP_NUM_FDIR;
1452 pf->lan_nb_qps = pf->lan_nb_qp_max - pf->fdir_nb_qps;
1454 pf->fdir_nb_qps = 0;
1456 pf->fdir_qp_offset = 0;
1462 ice_setup_vsi(struct ice_pf *pf, enum ice_vsi_type type)
1464 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1465 struct ice_vsi *vsi = NULL;
1466 struct ice_vsi_ctx vsi_ctx;
1468 struct rte_ether_addr broadcast = {
1469 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
1470 struct rte_ether_addr mac_addr;
1471 uint16_t max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1472 uint8_t tc_bitmap = 0x1;
1475 /* hw->num_lports = 1 in NIC mode */
1476 vsi = rte_zmalloc(NULL, sizeof(struct ice_vsi), 0);
1480 vsi->idx = pf->next_vsi_idx;
1483 vsi->adapter = ICE_PF_TO_ADAPTER(pf);
1484 vsi->max_macaddrs = ICE_NUM_MACADDR_MAX;
1485 vsi->vlan_anti_spoof_on = 0;
1486 vsi->vlan_filter_on = 1;
1487 TAILQ_INIT(&vsi->mac_list);
1488 TAILQ_INIT(&vsi->vlan_list);
1490 /* Be sync with RTE_ETH_RSS_RETA_SIZE_x maximum value definition */
1491 pf->hash_lut_size = hw->func_caps.common_cap.rss_table_size >
1492 RTE_ETH_RSS_RETA_SIZE_512 ? RTE_ETH_RSS_RETA_SIZE_512 :
1493 hw->func_caps.common_cap.rss_table_size;
1494 pf->flags |= ICE_FLAG_RSS_AQ_CAPABLE;
1496 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
1499 vsi->nb_qps = pf->lan_nb_qps;
1500 vsi->base_queue = 1;
1501 ice_vsi_config_default_rss(&vsi_ctx.info);
1502 vsi_ctx.alloc_from_pool = true;
1503 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1504 /* switch_id is queried by get_switch_config aq, which is done
1507 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1508 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1509 /* Allow all untagged or tagged packets */
1510 vsi_ctx.info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
1511 vsi_ctx.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
1512 vsi_ctx.info.q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF |
1513 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
1514 if (ice_is_dvm_ena(hw)) {
1515 vsi_ctx.info.outer_vlan_flags =
1516 (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
1517 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
1518 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M;
1519 vsi_ctx.info.outer_vlan_flags |=
1520 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
1521 ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
1522 ICE_AQ_VSI_OUTER_TAG_TYPE_M;
1526 cfg = ICE_AQ_VSI_PROP_SECURITY_VALID |
1527 ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1528 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1529 cfg = ICE_AQ_VSI_FD_ENABLE;
1530 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1531 vsi_ctx.info.max_fd_fltr_dedicated =
1532 rte_cpu_to_le_16(hw->func_caps.fd_fltr_guar);
1533 vsi_ctx.info.max_fd_fltr_shared =
1534 rte_cpu_to_le_16(hw->func_caps.fd_fltr_best_effort);
1536 /* Enable VLAN/UP trip */
1537 ret = ice_vsi_config_tc_queue_mapping(vsi,
1542 "tc queue mapping with vsi failed, "
1550 vsi->nb_qps = pf->fdir_nb_qps;
1551 vsi->base_queue = ICE_FDIR_QUEUE_ID;
1552 vsi_ctx.alloc_from_pool = true;
1553 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1555 cfg = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1556 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1557 cfg = ICE_AQ_VSI_FD_PROG_ENABLE;
1558 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1559 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1560 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1561 ret = ice_vsi_config_tc_queue_mapping(vsi,
1566 "tc queue mapping with vsi failed, "
1573 /* for other types of VSI */
1574 PMD_INIT_LOG(ERR, "other types of VSI not supported");
1578 /* VF has MSIX interrupt in VF range, don't allocate here */
1579 if (type == ICE_VSI_PF) {
1580 ret = ice_res_pool_alloc(&pf->msix_pool,
1581 RTE_MIN(vsi->nb_qps,
1582 RTE_MAX_RXTX_INTR_VEC_ID));
1584 PMD_INIT_LOG(ERR, "VSI MAIN %d get heap failed %d",
1587 vsi->msix_intr = ret;
1588 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
1589 } else if (type == ICE_VSI_CTRL) {
1590 ret = ice_res_pool_alloc(&pf->msix_pool, 1);
1592 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d",
1595 vsi->msix_intr = ret;
1601 ret = ice_add_vsi(hw, vsi->idx, &vsi_ctx, NULL);
1602 if (ret != ICE_SUCCESS) {
1603 PMD_INIT_LOG(ERR, "add vsi failed, err = %d", ret);
1606 /* store vsi information is SW structure */
1607 vsi->vsi_id = vsi_ctx.vsi_num;
1608 vsi->info = vsi_ctx.info;
1609 pf->vsis_allocated = vsi_ctx.vsis_allocd;
1610 pf->vsis_unallocated = vsi_ctx.vsis_unallocated;
1612 if (type == ICE_VSI_PF) {
1613 /* MAC configuration */
1614 rte_ether_addr_copy((struct rte_ether_addr *)
1615 hw->port_info->mac.perm_addr,
1618 rte_ether_addr_copy(&pf->dev_addr, &mac_addr);
1619 ret = ice_add_mac_filter(vsi, &mac_addr);
1620 if (ret != ICE_SUCCESS)
1621 PMD_INIT_LOG(ERR, "Failed to add dflt MAC filter");
1623 rte_ether_addr_copy(&broadcast, &mac_addr);
1624 ret = ice_add_mac_filter(vsi, &mac_addr);
1625 if (ret != ICE_SUCCESS)
1626 PMD_INIT_LOG(ERR, "Failed to add MAC filter");
1629 /* At the beginning, only TC0. */
1630 /* What we need here is the maximam number of the TX queues.
1631 * Currently vsi->nb_qps means it.
1632 * Correct it if any change.
1634 max_txqs[0] = vsi->nb_qps;
1635 ret = ice_cfg_vsi_lan(hw->port_info, vsi->idx,
1636 tc_bitmap, max_txqs);
1637 if (ret != ICE_SUCCESS)
1638 PMD_INIT_LOG(ERR, "Failed to config vsi sched");
1648 ice_send_driver_ver(struct ice_hw *hw)
1650 struct ice_driver_ver dv;
1652 /* we don't have driver version use 0 for dummy */
1656 dv.subbuild_ver = 0;
1657 strncpy((char *)dv.driver_string, "dpdk", sizeof(dv.driver_string));
1659 return ice_aq_send_driver_ver(hw, &dv, NULL);
1663 ice_pf_setup(struct ice_pf *pf)
1665 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1666 struct ice_vsi *vsi;
1669 /* Clear all stats counters */
1670 pf->offset_loaded = false;
1671 memset(&pf->stats, 0, sizeof(struct ice_hw_port_stats));
1672 memset(&pf->stats_offset, 0, sizeof(struct ice_hw_port_stats));
1673 memset(&pf->internal_stats, 0, sizeof(struct ice_eth_stats));
1674 memset(&pf->internal_stats_offset, 0, sizeof(struct ice_eth_stats));
1676 /* force guaranteed filter pool for PF */
1677 ice_alloc_fd_guar_item(hw, &unused,
1678 hw->func_caps.fd_fltr_guar);
1679 /* force shared filter pool for PF */
1680 ice_alloc_fd_shrd_item(hw, &unused,
1681 hw->func_caps.fd_fltr_best_effort);
1683 vsi = ice_setup_vsi(pf, ICE_VSI_PF);
1685 PMD_INIT_LOG(ERR, "Failed to add vsi for PF");
1694 static enum ice_pkg_type
1695 ice_load_pkg_type(struct ice_hw *hw)
1697 enum ice_pkg_type package_type;
1699 /* store the activated package type (OS default or Comms) */
1700 if (!strncmp((char *)hw->active_pkg_name, ICE_OS_DEFAULT_PKG_NAME,
1702 package_type = ICE_PKG_TYPE_OS_DEFAULT;
1703 else if (!strncmp((char *)hw->active_pkg_name, ICE_COMMS_PKG_NAME,
1705 package_type = ICE_PKG_TYPE_COMMS;
1707 package_type = ICE_PKG_TYPE_UNKNOWN;
1709 PMD_INIT_LOG(NOTICE, "Active package is: %d.%d.%d.%d, %s (%s VLAN mode)",
1710 hw->active_pkg_ver.major, hw->active_pkg_ver.minor,
1711 hw->active_pkg_ver.update, hw->active_pkg_ver.draft,
1712 hw->active_pkg_name,
1713 ice_is_dvm_ena(hw) ? "double" : "single");
1715 return package_type;
1718 int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)
1720 struct ice_hw *hw = &adapter->hw;
1721 char pkg_file[ICE_MAX_PKG_FILENAME_SIZE];
1722 char opt_ddp_filename[ICE_MAX_PKG_FILENAME_SIZE];
1730 memset(opt_ddp_filename, 0, ICE_MAX_PKG_FILENAME_SIZE);
1731 snprintf(opt_ddp_filename, ICE_MAX_PKG_FILENAME_SIZE,
1732 "ice-%016" PRIx64 ".pkg", dsn);
1733 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_UPDATES,
1734 ICE_MAX_PKG_FILENAME_SIZE);
1735 strcat(pkg_file, opt_ddp_filename);
1736 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1739 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_DEFAULT,
1740 ICE_MAX_PKG_FILENAME_SIZE);
1741 strcat(pkg_file, opt_ddp_filename);
1742 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1746 strncpy(pkg_file, ICE_PKG_FILE_UPDATES, ICE_MAX_PKG_FILENAME_SIZE);
1747 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1750 strncpy(pkg_file, ICE_PKG_FILE_DEFAULT, ICE_MAX_PKG_FILENAME_SIZE);
1751 if (rte_firmware_read(pkg_file, &buf, &bufsz) < 0) {
1752 PMD_INIT_LOG(ERR, "failed to search file path\n");
1757 PMD_INIT_LOG(DEBUG, "DDP package name: %s", pkg_file);
1759 err = ice_copy_and_init_pkg(hw, buf, bufsz);
1761 PMD_INIT_LOG(ERR, "ice_copy_and_init_hw failed: %d\n", err);
1765 /* store the loaded pkg type info */
1766 adapter->active_pkg_type = ice_load_pkg_type(hw);
1774 ice_base_queue_get(struct ice_pf *pf)
1777 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1779 reg = ICE_READ_REG(hw, PFLAN_RX_QALLOC);
1780 if (reg & PFLAN_RX_QALLOC_VALID_M) {
1781 pf->base_queue = reg & PFLAN_RX_QALLOC_FIRSTQ_M;
1783 PMD_INIT_LOG(WARNING, "Failed to get Rx base queue"
1789 parse_bool(const char *key, const char *value, void *args)
1791 int *i = (int *)args;
1795 num = strtoul(value, &end, 10);
1797 if (num != 0 && num != 1) {
1798 PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", "
1799 "value must be 0 or 1",
1809 parse_u64(const char *key, const char *value, void *args)
1811 u64 *num = (u64 *)args;
1815 tmp = strtoull(value, NULL, 16);
1817 PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64",
1828 lookup_pps_type(const char *pps_name)
1833 } pps_type_map[] = {
1839 for (i = 0; i < RTE_DIM(pps_type_map); i++) {
1840 if (strcmp(pps_name, pps_type_map[i].name) == 0)
1841 return pps_type_map[i].type;
1848 parse_pin_set(const char *input, int pps_type, struct ice_devargs *devargs)
1850 const char *str = input;
1854 while (isblank(*str))
1860 if (pps_type == PPS_PIN) {
1861 idx = strtoul(str, &end, 10);
1862 if (end == NULL || idx >= ICE_MAX_PIN_NUM)
1864 while (isblank(*end))
1869 devargs->pin_idx = idx;
1870 devargs->pps_out_ena = 1;
1879 parse_pps_out_parameter(const char *pins, struct ice_devargs *devargs)
1881 const char *pin_start;
1886 while (isblank(*pins))
1890 while (isblank(*pins))
1895 for (idx = 0; ; idx++) {
1896 if (isblank(pins[idx]) ||
1901 pps_name[idx] = pins[idx];
1903 pps_name[idx] = '\0';
1904 pps_type = lookup_pps_type(pps_name);
1910 pins += strcspn(pins, ":");
1913 while (isblank(*pins))
1918 while (isblank(*pins))
1921 if (parse_pin_set(pin_start, pps_type, devargs) < 0)
1928 handle_pps_out_arg(__rte_unused const char *key, const char *value,
1931 struct ice_devargs *devargs = extra_args;
1933 if (value == NULL || extra_args == NULL)
1936 if (parse_pps_out_parameter(value, devargs) < 0) {
1938 "The GPIO pin parameter is wrong : '%s'",
1946 static int ice_parse_devargs(struct rte_eth_dev *dev)
1948 struct ice_adapter *ad =
1949 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1950 struct rte_devargs *devargs = dev->device->devargs;
1951 struct rte_kvargs *kvlist;
1954 if (devargs == NULL)
1957 kvlist = rte_kvargs_parse(devargs->args, ice_valid_args);
1958 if (kvlist == NULL) {
1959 PMD_INIT_LOG(ERR, "Invalid kvargs key\n");
1963 ad->devargs.proto_xtr_dflt = PROTO_XTR_NONE;
1964 memset(ad->devargs.proto_xtr, PROTO_XTR_NONE,
1965 sizeof(ad->devargs.proto_xtr));
1967 ret = rte_kvargs_process(kvlist, ICE_PROTO_XTR_ARG,
1968 &handle_proto_xtr_arg, &ad->devargs);
1972 ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG,
1973 &parse_bool, &ad->devargs.safe_mode_support);
1977 ret = rte_kvargs_process(kvlist, ICE_PIPELINE_MODE_SUPPORT_ARG,
1978 &parse_bool, &ad->devargs.pipe_mode_support);
1982 ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG,
1983 &parse_u64, &ad->hw.debug_mask);
1987 ret = rte_kvargs_process(kvlist, ICE_ONE_PPS_OUT_ARG,
1988 &handle_pps_out_arg, &ad->devargs);
1992 ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG,
1993 &parse_bool, &ad->devargs.rx_low_latency);
1996 rte_kvargs_free(kvlist);
2000 /* Forward LLDP packets to default VSI by set switch rules */
2002 ice_vsi_config_sw_lldp(struct ice_vsi *vsi, bool on)
2004 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2005 struct ice_fltr_list_entry *s_list_itr = NULL;
2006 struct LIST_HEAD_TYPE list_head;
2009 INIT_LIST_HEAD(&list_head);
2011 s_list_itr = (struct ice_fltr_list_entry *)
2012 ice_malloc(hw, sizeof(*s_list_itr));
2015 s_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
2016 s_list_itr->fltr_info.vsi_handle = vsi->idx;
2017 s_list_itr->fltr_info.l_data.ethertype_mac.ethertype =
2018 RTE_ETHER_TYPE_LLDP;
2019 s_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2020 s_list_itr->fltr_info.flag = ICE_FLTR_RX;
2021 s_list_itr->fltr_info.src_id = ICE_SRC_ID_LPORT;
2022 LIST_ADD(&s_list_itr->list_entry, &list_head);
2024 ret = ice_add_eth_mac(hw, &list_head);
2026 ret = ice_remove_eth_mac(hw, &list_head);
2028 rte_free(s_list_itr);
2032 static enum ice_status
2033 ice_get_hw_res(struct ice_hw *hw, uint16_t res_type,
2034 uint16_t num, uint16_t desc_id,
2035 uint16_t *prof_buf, uint16_t *num_prof)
2037 struct ice_aqc_res_elem *resp_buf;
2040 bool res_shared = 1;
2041 struct ice_aq_desc aq_desc;
2042 struct ice_sq_cd *cd = NULL;
2043 struct ice_aqc_get_allocd_res_desc *cmd =
2044 &aq_desc.params.get_res_desc;
2046 buf_len = sizeof(*resp_buf) * num;
2047 resp_buf = ice_malloc(hw, buf_len);
2051 ice_fill_dflt_direct_cmd_desc(&aq_desc,
2052 ice_aqc_opc_get_allocd_res_desc);
2054 cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2055 ICE_AQC_RES_TYPE_M) | (res_shared ?
2056 ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2057 cmd->ops.cmd.first_desc = CPU_TO_LE16(desc_id);
2059 ret = ice_aq_send_cmd(hw, &aq_desc, resp_buf, buf_len, cd);
2061 *num_prof = LE16_TO_CPU(cmd->ops.resp.num_desc);
2065 ice_memcpy(prof_buf, resp_buf, sizeof(*resp_buf) *
2066 (*num_prof), ICE_NONDMA_TO_NONDMA);
2073 ice_cleanup_resource(struct ice_hw *hw, uint16_t res_type)
2077 uint16_t prof_buf[ICE_MAX_RES_DESC_NUM];
2078 uint16_t first_desc = 1;
2079 uint16_t num_prof = 0;
2081 ret = ice_get_hw_res(hw, res_type, ICE_MAX_RES_DESC_NUM,
2082 first_desc, prof_buf, &num_prof);
2084 PMD_INIT_LOG(ERR, "Failed to get fxp resource");
2088 for (prof_id = 0; prof_id < num_prof; prof_id++) {
2089 ret = ice_free_hw_res(hw, res_type, 1, &prof_buf[prof_id]);
2091 PMD_INIT_LOG(ERR, "Failed to free fxp resource");
2099 ice_reset_fxp_resource(struct ice_hw *hw)
2103 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID);
2105 PMD_INIT_LOG(ERR, "Failed to clearup fdir resource");
2109 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID);
2111 PMD_INIT_LOG(ERR, "Failed to clearup rss resource");
2119 ice_rss_ctx_init(struct ice_pf *pf)
2121 memset(&pf->hash_ctx, 0, sizeof(pf->hash_ctx));
2125 ice_get_supported_rxdid(struct ice_hw *hw)
2127 uint64_t supported_rxdid = 0; /* bitmap for supported RXDID */
2131 supported_rxdid |= BIT(ICE_RXDID_LEGACY_1);
2133 for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2134 regval = ICE_READ_REG(hw, GLFLXP_RXDID_FLAGS(i, 0));
2135 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2136 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2137 supported_rxdid |= BIT(i);
2139 return supported_rxdid;
2143 ice_dev_init(struct rte_eth_dev *dev)
2145 struct rte_pci_device *pci_dev;
2146 struct rte_intr_handle *intr_handle;
2147 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2148 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2149 struct ice_adapter *ad =
2150 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2151 struct ice_vsi *vsi;
2153 #ifndef RTE_EXEC_ENV_WINDOWS
2155 uint32_t dsn_low, dsn_high;
2160 dev->dev_ops = &ice_eth_dev_ops;
2161 dev->rx_queue_count = ice_rx_queue_count;
2162 dev->rx_descriptor_status = ice_rx_descriptor_status;
2163 dev->tx_descriptor_status = ice_tx_descriptor_status;
2164 dev->rx_pkt_burst = ice_recv_pkts;
2165 dev->tx_pkt_burst = ice_xmit_pkts;
2166 dev->tx_pkt_prepare = ice_prep_pkts;
2168 /* for secondary processes, we don't initialise any further as primary
2169 * has already done this work.
2171 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2172 ice_set_rx_function(dev);
2173 ice_set_tx_function(dev);
2177 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2179 ice_set_default_ptype_table(dev);
2180 pci_dev = RTE_DEV_TO_PCI(dev->device);
2181 intr_handle = pci_dev->intr_handle;
2183 pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2184 pf->dev_data = dev->data;
2185 hw->back = pf->adapter;
2186 hw->hw_addr = (uint8_t *)pci_dev->mem_resource[0].addr;
2187 hw->vendor_id = pci_dev->id.vendor_id;
2188 hw->device_id = pci_dev->id.device_id;
2189 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2190 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2191 hw->bus.device = pci_dev->addr.devid;
2192 hw->bus.func = pci_dev->addr.function;
2194 ret = ice_parse_devargs(dev);
2196 PMD_INIT_LOG(ERR, "Failed to parse devargs");
2200 ice_init_controlq_parameter(hw);
2202 ret = ice_init_hw(hw);
2204 PMD_INIT_LOG(ERR, "Failed to initialize HW");
2208 #ifndef RTE_EXEC_ENV_WINDOWS
2211 pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN);
2213 if (rte_pci_read_config(pci_dev, &dsn_low, 4, pos + 4) < 0 ||
2214 rte_pci_read_config(pci_dev, &dsn_high, 4, pos + 8) < 0) {
2215 PMD_INIT_LOG(ERR, "Failed to read pci config space\n");
2218 dsn = (uint64_t)dsn_high << 32 | dsn_low;
2221 PMD_INIT_LOG(ERR, "Failed to read device serial number\n");
2224 ret = ice_load_pkg(pf->adapter, use_dsn, dsn);
2226 ret = ice_init_hw_tbls(hw);
2228 PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d\n", ret);
2229 rte_free(hw->pkg_copy);
2234 if (ad->devargs.safe_mode_support == 0) {
2235 PMD_INIT_LOG(ERR, "Failed to load the DDP package,"
2236 "Use safe-mode-support=1 to enter Safe Mode");
2240 PMD_INIT_LOG(WARNING, "Failed to load the DDP package,"
2241 "Entering Safe Mode");
2242 ad->is_safe_mode = 1;
2246 PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
2247 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2248 hw->api_maj_ver, hw->api_min_ver);
2250 ice_pf_sw_init(dev);
2251 ret = ice_init_mac_address(dev);
2253 PMD_INIT_LOG(ERR, "Failed to initialize mac address");
2257 ret = ice_res_pool_init(&pf->msix_pool, 1,
2258 hw->func_caps.common_cap.num_msix_vectors - 1);
2260 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
2261 goto err_msix_pool_init;
2264 ret = ice_pf_setup(pf);
2266 PMD_INIT_LOG(ERR, "Failed to setup PF");
2270 ret = ice_send_driver_ver(hw);
2272 PMD_INIT_LOG(ERR, "Failed to send driver version");
2278 ret = ice_aq_stop_lldp(hw, true, false, NULL);
2279 if (ret != ICE_SUCCESS)
2280 PMD_INIT_LOG(DEBUG, "lldp has already stopped\n");
2281 ret = ice_init_dcb(hw, true);
2282 if (ret != ICE_SUCCESS)
2283 PMD_INIT_LOG(DEBUG, "Failed to init DCB\n");
2284 /* Forward LLDP packets to default VSI */
2285 ret = ice_vsi_config_sw_lldp(vsi, true);
2286 if (ret != ICE_SUCCESS)
2287 PMD_INIT_LOG(DEBUG, "Failed to cfg lldp\n");
2288 /* register callback func to eal lib */
2289 rte_intr_callback_register(intr_handle,
2290 ice_interrupt_handler, dev);
2292 ice_pf_enable_irq0(hw);
2294 /* enable uio intr after callback register */
2295 rte_intr_enable(intr_handle);
2297 /* get base queue pairs index in the device */
2298 ice_base_queue_get(pf);
2300 /* Initialize RSS context for gtpu_eh */
2301 ice_rss_ctx_init(pf);
2303 if (!ad->is_safe_mode) {
2304 ret = ice_flow_init(ad);
2306 PMD_INIT_LOG(ERR, "Failed to initialize flow");
2311 ret = ice_reset_fxp_resource(hw);
2313 PMD_INIT_LOG(ERR, "Failed to reset fxp resource");
2317 pf->supported_rxdid = ice_get_supported_rxdid(hw);
2322 ice_flow_uninit(ad);
2323 rte_intr_disable(intr_handle);
2324 ice_pf_disable_irq0(hw);
2325 rte_intr_callback_unregister(intr_handle,
2326 ice_interrupt_handler, dev);
2328 ice_res_pool_destroy(&pf->msix_pool);
2330 rte_free(dev->data->mac_addrs);
2331 dev->data->mac_addrs = NULL;
2333 rte_free(pf->proto_xtr);
2334 #ifndef RTE_EXEC_ENV_WINDOWS
2343 ice_release_vsi(struct ice_vsi *vsi)
2346 struct ice_vsi_ctx vsi_ctx;
2347 enum ice_status ret;
2353 hw = ICE_VSI_TO_HW(vsi);
2355 ice_remove_all_mac_vlan_filters(vsi);
2357 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
2359 vsi_ctx.vsi_num = vsi->vsi_id;
2360 vsi_ctx.info = vsi->info;
2361 ret = ice_free_vsi(hw, vsi->idx, &vsi_ctx, false, NULL);
2362 if (ret != ICE_SUCCESS) {
2363 PMD_INIT_LOG(ERR, "Failed to free vsi by aq, %u", vsi->vsi_id);
2367 rte_free(vsi->rss_lut);
2368 rte_free(vsi->rss_key);
2374 ice_vsi_disable_queues_intr(struct ice_vsi *vsi)
2376 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
2377 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2378 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2379 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2380 uint16_t msix_intr, i;
2382 /* disable interrupt and also clear all the exist config */
2383 for (i = 0; i < vsi->nb_qps; i++) {
2384 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
2385 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
2389 if (rte_intr_allow_others(intr_handle))
2391 for (i = 0; i < vsi->nb_msix; i++) {
2392 msix_intr = vsi->msix_intr + i;
2393 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
2394 GLINT_DYN_CTL_WB_ON_ITR_M);
2398 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
2402 ice_dev_stop(struct rte_eth_dev *dev)
2404 struct rte_eth_dev_data *data = dev->data;
2405 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2406 struct ice_vsi *main_vsi = pf->main_vsi;
2407 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2408 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2411 /* avoid stopping again */
2412 if (pf->adapter_stopped)
2415 /* stop and clear all Rx queues */
2416 for (i = 0; i < data->nb_rx_queues; i++)
2417 ice_rx_queue_stop(dev, i);
2419 /* stop and clear all Tx queues */
2420 for (i = 0; i < data->nb_tx_queues; i++)
2421 ice_tx_queue_stop(dev, i);
2423 /* disable all queue interrupts */
2424 ice_vsi_disable_queues_intr(main_vsi);
2426 if (pf->init_link_up)
2427 ice_dev_set_link_up(dev);
2429 ice_dev_set_link_down(dev);
2431 /* Clean datapath event and queue/vec mapping */
2432 rte_intr_efd_disable(intr_handle);
2433 rte_intr_vec_list_free(intr_handle);
2435 pf->adapter_stopped = true;
2436 dev->data->dev_started = 0;
2442 ice_dev_close(struct rte_eth_dev *dev)
2444 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2445 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2446 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2447 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2448 struct ice_adapter *ad =
2449 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2452 uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
2453 uint32_t pin_idx = ad->devargs.pin_idx;
2455 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2458 /* Since stop will make link down, then the link event will be
2459 * triggered, disable the irq firstly to avoid the port_infoe etc
2460 * resources deallocation causing the interrupt service thread
2463 ice_pf_disable_irq0(hw);
2465 ret = ice_dev_stop(dev);
2467 if (!ad->is_safe_mode)
2468 ice_flow_uninit(ad);
2470 /* release all queue resource */
2471 ice_free_queues(dev);
2473 ice_res_pool_destroy(&pf->msix_pool);
2474 ice_release_vsi(pf->main_vsi);
2475 ice_sched_cleanup_all(hw);
2476 ice_free_hw_tbls(hw);
2477 rte_free(hw->port_info);
2478 hw->port_info = NULL;
2479 ice_shutdown_all_ctrlq(hw);
2480 rte_free(pf->proto_xtr);
2481 pf->proto_xtr = NULL;
2483 if (ad->devargs.pps_out_ena) {
2484 ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(pin_idx, timer), 0);
2485 ICE_WRITE_REG(hw, GLTSYN_CLKO(pin_idx, timer), 0);
2486 ICE_WRITE_REG(hw, GLTSYN_TGT_L(pin_idx, timer), 0);
2487 ICE_WRITE_REG(hw, GLTSYN_TGT_H(pin_idx, timer), 0);
2489 val = GLGEN_GPIO_CTL_PIN_DIR_M;
2490 ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(pin_idx), val);
2493 /* disable uio intr before callback unregister */
2494 rte_intr_disable(intr_handle);
2496 /* unregister callback func from eal lib */
2497 rte_intr_callback_unregister(intr_handle,
2498 ice_interrupt_handler, dev);
2504 ice_dev_uninit(struct rte_eth_dev *dev)
2512 is_hash_cfg_valid(struct ice_rss_hash_cfg *cfg)
2514 return (cfg->hash_flds != 0 && cfg->addl_hdrs != 0) ? true : false;
2518 hash_cfg_reset(struct ice_rss_hash_cfg *cfg)
2523 cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
2527 ice_hash_moveout(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2529 enum ice_status status = ICE_SUCCESS;
2530 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2531 struct ice_vsi *vsi = pf->main_vsi;
2533 if (!is_hash_cfg_valid(cfg))
2536 status = ice_rem_rss_cfg(hw, vsi->idx, cfg);
2537 if (status && status != ICE_ERR_DOES_NOT_EXIST) {
2539 "ice_rem_rss_cfg failed for VSI:%d, error:%d\n",
2548 ice_hash_moveback(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2550 enum ice_status status = ICE_SUCCESS;
2551 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2552 struct ice_vsi *vsi = pf->main_vsi;
2554 if (!is_hash_cfg_valid(cfg))
2557 status = ice_add_rss_cfg(hw, vsi->idx, cfg);
2560 "ice_add_rss_cfg failed for VSI:%d, error:%d\n",
2569 ice_hash_remove(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2573 ret = ice_hash_moveout(pf, cfg);
2574 if (ret && (ret != -ENOENT))
2577 hash_cfg_reset(cfg);
2583 ice_add_rss_cfg_pre_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2589 case ICE_HASH_GTPU_CTX_EH_IP:
2590 ret = ice_hash_remove(pf,
2591 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2592 if (ret && (ret != -ENOENT))
2595 ret = ice_hash_remove(pf,
2596 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2597 if (ret && (ret != -ENOENT))
2600 ret = ice_hash_remove(pf,
2601 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2602 if (ret && (ret != -ENOENT))
2605 ret = ice_hash_remove(pf,
2606 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2607 if (ret && (ret != -ENOENT))
2610 ret = ice_hash_remove(pf,
2611 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2612 if (ret && (ret != -ENOENT))
2615 ret = ice_hash_remove(pf,
2616 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2617 if (ret && (ret != -ENOENT))
2620 ret = ice_hash_remove(pf,
2621 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2622 if (ret && (ret != -ENOENT))
2625 ret = ice_hash_remove(pf,
2626 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2627 if (ret && (ret != -ENOENT))
2631 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2632 ret = ice_hash_remove(pf,
2633 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2634 if (ret && (ret != -ENOENT))
2637 ret = ice_hash_remove(pf,
2638 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2639 if (ret && (ret != -ENOENT))
2642 ret = ice_hash_moveout(pf,
2643 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2644 if (ret && (ret != -ENOENT))
2647 ret = ice_hash_moveout(pf,
2648 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2649 if (ret && (ret != -ENOENT))
2652 ret = ice_hash_moveout(pf,
2653 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2654 if (ret && (ret != -ENOENT))
2657 ret = ice_hash_moveout(pf,
2658 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2659 if (ret && (ret != -ENOENT))
2663 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2664 ret = ice_hash_remove(pf,
2665 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2666 if (ret && (ret != -ENOENT))
2669 ret = ice_hash_remove(pf,
2670 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2671 if (ret && (ret != -ENOENT))
2674 ret = ice_hash_moveout(pf,
2675 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2676 if (ret && (ret != -ENOENT))
2679 ret = ice_hash_moveout(pf,
2680 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2681 if (ret && (ret != -ENOENT))
2684 ret = ice_hash_moveout(pf,
2685 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2686 if (ret && (ret != -ENOENT))
2689 ret = ice_hash_moveout(pf,
2690 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2691 if (ret && (ret != -ENOENT))
2695 case ICE_HASH_GTPU_CTX_UP_IP:
2696 ret = ice_hash_remove(pf,
2697 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2698 if (ret && (ret != -ENOENT))
2701 ret = ice_hash_remove(pf,
2702 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2703 if (ret && (ret != -ENOENT))
2706 ret = ice_hash_moveout(pf,
2707 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2708 if (ret && (ret != -ENOENT))
2711 ret = ice_hash_moveout(pf,
2712 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2713 if (ret && (ret != -ENOENT))
2716 ret = ice_hash_moveout(pf,
2717 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2718 if (ret && (ret != -ENOENT))
2722 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2723 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2724 ret = ice_hash_moveout(pf,
2725 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2726 if (ret && (ret != -ENOENT))
2729 ret = ice_hash_moveout(pf,
2730 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2731 if (ret && (ret != -ENOENT))
2734 ret = ice_hash_moveout(pf,
2735 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2736 if (ret && (ret != -ENOENT))
2740 case ICE_HASH_GTPU_CTX_DW_IP:
2741 ret = ice_hash_remove(pf,
2742 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2743 if (ret && (ret != -ENOENT))
2746 ret = ice_hash_remove(pf,
2747 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2748 if (ret && (ret != -ENOENT))
2751 ret = ice_hash_moveout(pf,
2752 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2753 if (ret && (ret != -ENOENT))
2756 ret = ice_hash_moveout(pf,
2757 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2758 if (ret && (ret != -ENOENT))
2761 ret = ice_hash_moveout(pf,
2762 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2763 if (ret && (ret != -ENOENT))
2767 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2768 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2769 ret = ice_hash_moveout(pf,
2770 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2771 if (ret && (ret != -ENOENT))
2774 ret = ice_hash_moveout(pf,
2775 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2776 if (ret && (ret != -ENOENT))
2779 ret = ice_hash_moveout(pf,
2780 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2781 if (ret && (ret != -ENOENT))
2792 static u8 calc_gtpu_ctx_idx(uint32_t hdr)
2796 if (hdr & ICE_FLOW_SEG_HDR_GTPU_EH)
2798 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_UP)
2800 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_DWN)
2803 return ICE_HASH_GTPU_CTX_MAX;
2806 if (hdr & ICE_FLOW_SEG_HDR_UDP)
2808 else if (hdr & ICE_FLOW_SEG_HDR_TCP)
2811 if (hdr & (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6))
2812 return eh_idx * 3 + ip_idx;
2814 return ICE_HASH_GTPU_CTX_MAX;
2818 ice_add_rss_cfg_pre(struct ice_pf *pf, uint32_t hdr)
2820 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2822 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2823 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu4,
2825 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2826 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu6,
2833 ice_add_rss_cfg_post_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2834 u8 ctx_idx, struct ice_rss_hash_cfg *cfg)
2838 if (ctx_idx < ICE_HASH_GTPU_CTX_MAX)
2839 ctx->ctx[ctx_idx] = *cfg;
2842 case ICE_HASH_GTPU_CTX_EH_IP:
2844 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2845 ret = ice_hash_moveback(pf,
2846 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2847 if (ret && (ret != -ENOENT))
2850 ret = ice_hash_moveback(pf,
2851 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2852 if (ret && (ret != -ENOENT))
2855 ret = ice_hash_moveback(pf,
2856 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2857 if (ret && (ret != -ENOENT))
2860 ret = ice_hash_moveback(pf,
2861 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2862 if (ret && (ret != -ENOENT))
2866 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2867 ret = ice_hash_moveback(pf,
2868 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2869 if (ret && (ret != -ENOENT))
2872 ret = ice_hash_moveback(pf,
2873 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2874 if (ret && (ret != -ENOENT))
2877 ret = ice_hash_moveback(pf,
2878 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2879 if (ret && (ret != -ENOENT))
2882 ret = ice_hash_moveback(pf,
2883 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2884 if (ret && (ret != -ENOENT))
2888 case ICE_HASH_GTPU_CTX_UP_IP:
2889 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2890 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2891 case ICE_HASH_GTPU_CTX_DW_IP:
2892 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2893 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2894 ret = ice_hash_moveback(pf,
2895 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2896 if (ret && (ret != -ENOENT))
2899 ret = ice_hash_moveback(pf,
2900 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2901 if (ret && (ret != -ENOENT))
2904 ret = ice_hash_moveback(pf,
2905 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2906 if (ret && (ret != -ENOENT))
2918 ice_add_rss_cfg_post(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2920 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(cfg->addl_hdrs);
2922 if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV4)
2923 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu4,
2925 else if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV6)
2926 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu6,
2933 ice_rem_rss_cfg_post(struct ice_pf *pf, uint32_t hdr)
2935 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2937 if (gtpu_ctx_idx >= ICE_HASH_GTPU_CTX_MAX)
2940 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2941 hash_cfg_reset(&pf->hash_ctx.gtpu4.ctx[gtpu_ctx_idx]);
2942 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2943 hash_cfg_reset(&pf->hash_ctx.gtpu6.ctx[gtpu_ctx_idx]);
2947 ice_rem_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2948 struct ice_rss_hash_cfg *cfg)
2950 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2953 ret = ice_rem_rss_cfg(hw, vsi_id, cfg);
2954 if (ret && ret != ICE_ERR_DOES_NOT_EXIST)
2955 PMD_DRV_LOG(ERR, "remove rss cfg failed\n");
2957 ice_rem_rss_cfg_post(pf, cfg->addl_hdrs);
2963 ice_add_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2964 struct ice_rss_hash_cfg *cfg)
2966 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2969 ret = ice_add_rss_cfg_pre(pf, cfg->addl_hdrs);
2971 PMD_DRV_LOG(ERR, "add rss cfg pre failed\n");
2973 ret = ice_add_rss_cfg(hw, vsi_id, cfg);
2975 PMD_DRV_LOG(ERR, "add rss cfg failed\n");
2977 ret = ice_add_rss_cfg_post(pf, cfg);
2979 PMD_DRV_LOG(ERR, "add rss cfg post failed\n");
2985 ice_rss_hash_set(struct ice_pf *pf, uint64_t rss_hf)
2987 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2988 struct ice_vsi *vsi = pf->main_vsi;
2989 struct ice_rss_hash_cfg cfg;
2992 #define ICE_RSS_HF_ALL ( \
2993 RTE_ETH_RSS_IPV4 | \
2994 RTE_ETH_RSS_IPV6 | \
2995 RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
2996 RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
2997 RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
2998 RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
2999 RTE_ETH_RSS_NONFRAG_IPV4_SCTP | \
3000 RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
3002 ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
3004 PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
3008 cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
3009 /* Configure RSS for IPv4 with src/dst addr as input set */
3010 if (rss_hf & RTE_ETH_RSS_IPV4) {
3011 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3012 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3013 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3015 PMD_DRV_LOG(ERR, "%s IPV4 rss flow fail %d",
3019 /* Configure RSS for IPv6 with src/dst addr as input set */
3020 if (rss_hf & RTE_ETH_RSS_IPV6) {
3021 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3022 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3023 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3025 PMD_DRV_LOG(ERR, "%s IPV6 rss flow fail %d",
3029 /* Configure RSS for udp4 with src/dst addr and port as input set */
3030 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3031 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4 |
3032 ICE_FLOW_SEG_HDR_IPV_OTHER;
3033 cfg.hash_flds = ICE_HASH_UDP_IPV4;
3034 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3036 PMD_DRV_LOG(ERR, "%s UDP_IPV4 rss flow fail %d",
3040 /* Configure RSS for udp6 with src/dst addr and port as input set */
3041 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3042 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6 |
3043 ICE_FLOW_SEG_HDR_IPV_OTHER;
3044 cfg.hash_flds = ICE_HASH_UDP_IPV6;
3045 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3047 PMD_DRV_LOG(ERR, "%s UDP_IPV6 rss flow fail %d",
3051 /* Configure RSS for tcp4 with src/dst addr and port as input set */
3052 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3053 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4 |
3054 ICE_FLOW_SEG_HDR_IPV_OTHER;
3055 cfg.hash_flds = ICE_HASH_TCP_IPV4;
3056 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3058 PMD_DRV_LOG(ERR, "%s TCP_IPV4 rss flow fail %d",
3062 /* Configure RSS for tcp6 with src/dst addr and port as input set */
3063 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3064 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6 |
3065 ICE_FLOW_SEG_HDR_IPV_OTHER;
3066 cfg.hash_flds = ICE_HASH_TCP_IPV6;
3067 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3069 PMD_DRV_LOG(ERR, "%s TCP_IPV6 rss flow fail %d",
3073 /* Configure RSS for sctp4 with src/dst addr and port as input set */
3074 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_SCTP) {
3075 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4 |
3076 ICE_FLOW_SEG_HDR_IPV_OTHER;
3077 cfg.hash_flds = ICE_HASH_SCTP_IPV4;
3078 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3080 PMD_DRV_LOG(ERR, "%s SCTP_IPV4 rss flow fail %d",
3084 /* Configure RSS for sctp6 with src/dst addr and port as input set */
3085 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_SCTP) {
3086 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6 |
3087 ICE_FLOW_SEG_HDR_IPV_OTHER;
3088 cfg.hash_flds = ICE_HASH_SCTP_IPV6;
3089 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3091 PMD_DRV_LOG(ERR, "%s SCTP_IPV6 rss flow fail %d",
3095 if (rss_hf & RTE_ETH_RSS_IPV4) {
3096 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV4 |
3097 ICE_FLOW_SEG_HDR_IPV_OTHER;
3098 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3099 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3101 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4 rss flow fail %d",
3105 if (rss_hf & RTE_ETH_RSS_IPV6) {
3106 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV6 |
3107 ICE_FLOW_SEG_HDR_IPV_OTHER;
3108 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3109 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3111 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6 rss flow fail %d",
3115 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) {
3116 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3117 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3118 cfg.hash_flds = ICE_HASH_UDP_IPV4;
3119 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3121 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_UDP rss flow fail %d",
3125 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) {
3126 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3127 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3128 cfg.hash_flds = ICE_HASH_UDP_IPV6;
3129 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3131 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_UDP rss flow fail %d",
3135 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) {
3136 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3137 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3138 cfg.hash_flds = ICE_HASH_TCP_IPV4;
3139 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3141 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_TCP rss flow fail %d",
3145 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) {
3146 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3147 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3148 cfg.hash_flds = ICE_HASH_TCP_IPV6;
3149 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3151 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_TCP rss flow fail %d",
3155 pf->rss_hf = rss_hf & ICE_RSS_HF_ALL;
3159 ice_get_default_rss_key(uint8_t *rss_key, uint32_t rss_key_size)
3161 static struct ice_aqc_get_set_rss_keys default_key;
3162 static bool default_key_done;
3163 uint8_t *key = (uint8_t *)&default_key;
3166 if (rss_key_size > sizeof(default_key)) {
3167 PMD_DRV_LOG(WARNING,
3168 "requested size %u is larger than default %zu, "
3169 "only %zu bytes are gotten for key\n",
3170 rss_key_size, sizeof(default_key),
3171 sizeof(default_key));
3174 if (!default_key_done) {
3175 /* Calculate the default hash key */
3176 for (i = 0; i < sizeof(default_key); i++)
3177 key[i] = (uint8_t)rte_rand();
3178 default_key_done = true;
3180 rte_memcpy(rss_key, key, RTE_MIN(rss_key_size, sizeof(default_key)));
3183 static int ice_init_rss(struct ice_pf *pf)
3185 struct ice_hw *hw = ICE_PF_TO_HW(pf);
3186 struct ice_vsi *vsi = pf->main_vsi;
3187 struct rte_eth_dev_data *dev_data = pf->dev_data;
3188 struct ice_aq_get_set_rss_lut_params lut_params;
3189 struct rte_eth_rss_conf *rss_conf;
3190 struct ice_aqc_get_set_rss_keys key;
3193 bool is_safe_mode = pf->adapter->is_safe_mode;
3196 rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
3197 nb_q = dev_data->nb_rx_queues;
3198 vsi->rss_key_size = ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE;
3199 vsi->rss_lut_size = pf->hash_lut_size;
3202 PMD_DRV_LOG(WARNING,
3203 "RSS is not supported as rx queues number is zero\n");
3208 PMD_DRV_LOG(WARNING, "RSS is not supported in safe mode\n");
3212 if (!vsi->rss_key) {
3213 vsi->rss_key = rte_zmalloc(NULL,
3214 vsi->rss_key_size, 0);
3215 if (vsi->rss_key == NULL) {
3216 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3220 if (!vsi->rss_lut) {
3221 vsi->rss_lut = rte_zmalloc(NULL,
3222 vsi->rss_lut_size, 0);
3223 if (vsi->rss_lut == NULL) {
3224 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3225 rte_free(vsi->rss_key);
3226 vsi->rss_key = NULL;
3230 /* configure RSS key */
3231 if (!rss_conf->rss_key)
3232 ice_get_default_rss_key(vsi->rss_key, vsi->rss_key_size);
3234 rte_memcpy(vsi->rss_key, rss_conf->rss_key,
3235 RTE_MIN(rss_conf->rss_key_len,
3236 vsi->rss_key_size));
3238 rte_memcpy(key.standard_rss_key, vsi->rss_key, vsi->rss_key_size);
3239 ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
3243 /* init RSS LUT table */
3244 for (i = 0; i < vsi->rss_lut_size; i++)
3245 vsi->rss_lut[i] = i % nb_q;
3247 lut_params.vsi_handle = vsi->idx;
3248 lut_params.lut_size = vsi->rss_lut_size;
3249 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
3250 lut_params.lut = vsi->rss_lut;
3251 lut_params.global_lut_id = 0;
3252 ret = ice_aq_set_rss_lut(hw, &lut_params);
3256 /* Enable registers for symmetric_toeplitz function. */
3257 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
3258 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
3259 (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
3260 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
3262 /* RSS hash configuration */
3263 ice_rss_hash_set(pf, rss_conf->rss_hf);
3267 rte_free(vsi->rss_key);
3268 vsi->rss_key = NULL;
3269 rte_free(vsi->rss_lut);
3270 vsi->rss_lut = NULL;
3275 ice_dev_configure(struct rte_eth_dev *dev)
3277 struct ice_adapter *ad =
3278 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3279 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3282 /* Initialize to TRUE. If any of Rx queues doesn't meet the
3283 * bulk allocation or vector Rx preconditions we will reset it.
3285 ad->rx_bulk_alloc_allowed = true;
3286 ad->tx_simple_allowed = true;
3288 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
3289 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
3291 if (dev->data->nb_rx_queues) {
3292 ret = ice_init_rss(pf);
3294 PMD_DRV_LOG(ERR, "Failed to enable rss for PF");
3303 __vsi_queues_bind_intr(struct ice_vsi *vsi, uint16_t msix_vect,
3304 int base_queue, int nb_queue)
3306 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3307 uint32_t val, val_tx;
3308 int rx_low_latency, i;
3310 rx_low_latency = vsi->adapter->devargs.rx_low_latency;
3311 for (i = 0; i < nb_queue; i++) {
3313 val = (msix_vect & QINT_RQCTL_MSIX_INDX_M) |
3314 (0 << QINT_RQCTL_ITR_INDX_S) | QINT_RQCTL_CAUSE_ENA_M;
3315 val_tx = (msix_vect & QINT_TQCTL_MSIX_INDX_M) |
3316 (0 << QINT_TQCTL_ITR_INDX_S) | QINT_TQCTL_CAUSE_ENA_M;
3318 PMD_DRV_LOG(INFO, "queue %d is binding to vect %d",
3319 base_queue + i, msix_vect);
3321 /* set ITR0 value */
3322 if (rx_low_latency) {
3324 * Empirical configuration for optimal real time
3325 * latency reduced interrupt throttling to 2us
3327 ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x1);
3328 ICE_WRITE_REG(hw, QRX_ITR(base_queue + i),
3331 ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x2);
3332 ICE_WRITE_REG(hw, QRX_ITR(base_queue + i), 0);
3335 ICE_WRITE_REG(hw, QINT_RQCTL(base_queue + i), val);
3336 ICE_WRITE_REG(hw, QINT_TQCTL(base_queue + i), val_tx);
3341 ice_vsi_queues_bind_intr(struct ice_vsi *vsi)
3343 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3344 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3345 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3346 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3347 uint16_t msix_vect = vsi->msix_intr;
3348 uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
3349 rte_intr_nb_efd_get(intr_handle));
3350 uint16_t queue_idx = 0;
3354 /* clear Rx/Tx queue interrupt */
3355 for (i = 0; i < vsi->nb_used_qps; i++) {
3356 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
3357 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
3360 /* PF bind interrupt */
3361 if (rte_intr_dp_is_en(intr_handle)) {
3366 for (i = 0; i < vsi->nb_used_qps; i++) {
3368 if (!rte_intr_allow_others(intr_handle))
3369 msix_vect = ICE_MISC_VEC_ID;
3371 /* uio mapping all queue to one msix_vect */
3372 __vsi_queues_bind_intr(vsi, msix_vect,
3373 vsi->base_queue + i,
3374 vsi->nb_used_qps - i);
3376 for (; !!record && i < vsi->nb_used_qps; i++)
3377 rte_intr_vec_list_index_set(intr_handle,
3378 queue_idx + i, msix_vect);
3383 /* vfio 1:1 queue/msix_vect mapping */
3384 __vsi_queues_bind_intr(vsi, msix_vect,
3385 vsi->base_queue + i, 1);
3388 rte_intr_vec_list_index_set(intr_handle,
3398 ice_vsi_enable_queues_intr(struct ice_vsi *vsi)
3400 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3401 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3402 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3403 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3404 uint16_t msix_intr, i;
3406 if (rte_intr_allow_others(intr_handle))
3407 for (i = 0; i < vsi->nb_used_qps; i++) {
3408 msix_intr = vsi->msix_intr + i;
3409 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
3410 GLINT_DYN_CTL_INTENA_M |
3411 GLINT_DYN_CTL_CLEARPBA_M |
3412 GLINT_DYN_CTL_ITR_INDX_M |
3413 GLINT_DYN_CTL_WB_ON_ITR_M);
3416 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
3417 GLINT_DYN_CTL_INTENA_M |
3418 GLINT_DYN_CTL_CLEARPBA_M |
3419 GLINT_DYN_CTL_ITR_INDX_M |
3420 GLINT_DYN_CTL_WB_ON_ITR_M);
3424 ice_rxq_intr_setup(struct rte_eth_dev *dev)
3426 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3427 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3428 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3429 struct ice_vsi *vsi = pf->main_vsi;
3430 uint32_t intr_vector = 0;
3432 rte_intr_disable(intr_handle);
3434 /* check and configure queue intr-vector mapping */
3435 if ((rte_intr_cap_multiple(intr_handle) ||
3436 !RTE_ETH_DEV_SRIOV(dev).active) &&
3437 dev->data->dev_conf.intr_conf.rxq != 0) {
3438 intr_vector = dev->data->nb_rx_queues;
3439 if (intr_vector > ICE_MAX_INTR_QUEUE_NUM) {
3440 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
3441 ICE_MAX_INTR_QUEUE_NUM);
3444 if (rte_intr_efd_enable(intr_handle, intr_vector))
3448 if (rte_intr_dp_is_en(intr_handle)) {
3449 if (rte_intr_vec_list_alloc(intr_handle, NULL,
3450 dev->data->nb_rx_queues)) {
3452 "Failed to allocate %d rx_queues intr_vec",
3453 dev->data->nb_rx_queues);
3458 /* Map queues with MSIX interrupt */
3459 vsi->nb_used_qps = dev->data->nb_rx_queues;
3460 ice_vsi_queues_bind_intr(vsi);
3462 /* Enable interrupts for all the queues */
3463 ice_vsi_enable_queues_intr(vsi);
3465 rte_intr_enable(intr_handle);
3471 ice_get_init_link_status(struct rte_eth_dev *dev)
3473 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3474 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3475 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3476 struct ice_link_status link_status;
3479 ret = ice_aq_get_link_info(hw->port_info, enable_lse,
3480 &link_status, NULL);
3481 if (ret != ICE_SUCCESS) {
3482 PMD_DRV_LOG(ERR, "Failed to get link info");
3483 pf->init_link_up = false;
3487 if (link_status.link_info & ICE_AQ_LINK_UP)
3488 pf->init_link_up = true;
3492 ice_pps_out_cfg(struct ice_hw *hw, int idx, int timer)
3494 uint64_t current_time, start_time;
3495 uint32_t hi, lo, lo2, func, val;
3497 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3498 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
3499 lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3502 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3503 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
3506 current_time = ((uint64_t)hi << 32) | lo;
3508 start_time = (current_time + NSEC_PER_SEC) /
3509 NSEC_PER_SEC * NSEC_PER_SEC;
3510 start_time = start_time - PPS_OUT_DELAY_NS;
3512 func = 8 + idx + timer * 4;
3513 val = GLGEN_GPIO_CTL_PIN_DIR_M |
3514 ((func << GLGEN_GPIO_CTL_PIN_FUNC_S) &
3515 GLGEN_GPIO_CTL_PIN_FUNC_M);
3517 /* Write clkout with half of period value */
3518 ICE_WRITE_REG(hw, GLTSYN_CLKO(idx, timer), NSEC_PER_SEC / 2);
3520 /* Write TARGET time register */
3521 ICE_WRITE_REG(hw, GLTSYN_TGT_L(idx, timer), start_time & 0xffffffff);
3522 ICE_WRITE_REG(hw, GLTSYN_TGT_H(idx, timer), start_time >> 32);
3524 /* Write AUX_OUT register */
3525 ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(idx, timer),
3526 GLTSYN_AUX_OUT_0_OUT_ENA_M | GLTSYN_AUX_OUT_0_OUTMOD_M);
3528 /* Write GPIO CTL register */
3529 ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(idx), val);
3535 ice_dev_start(struct rte_eth_dev *dev)
3537 struct rte_eth_dev_data *data = dev->data;
3538 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3539 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3540 struct ice_vsi *vsi = pf->main_vsi;
3541 struct ice_adapter *ad =
3542 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3543 uint16_t nb_rxq = 0;
3545 uint16_t max_frame_size;
3547 uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
3548 uint32_t pin_idx = ad->devargs.pin_idx;
3550 /* program Tx queues' context in hardware */
3551 for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
3552 ret = ice_tx_queue_start(dev, nb_txq);
3554 PMD_DRV_LOG(ERR, "fail to start Tx queue %u", nb_txq);
3559 /* program Rx queues' context in hardware*/
3560 for (nb_rxq = 0; nb_rxq < data->nb_rx_queues; nb_rxq++) {
3561 ret = ice_rx_queue_start(dev, nb_rxq);
3563 PMD_DRV_LOG(ERR, "fail to start Rx queue %u", nb_rxq);
3568 ice_set_rx_function(dev);
3569 ice_set_tx_function(dev);
3571 mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
3572 RTE_ETH_VLAN_EXTEND_MASK;
3573 ret = ice_vlan_offload_set(dev, mask);
3575 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
3579 /* enable Rx interrput and mapping Rx queue to interrupt vector */
3580 if (ice_rxq_intr_setup(dev))
3583 /* Enable receiving broadcast packets and transmitting packets */
3584 ret = ice_set_vsi_promisc(hw, vsi->idx,
3585 ICE_PROMISC_BCAST_RX | ICE_PROMISC_BCAST_TX |
3586 ICE_PROMISC_UCAST_TX | ICE_PROMISC_MCAST_TX,
3588 if (ret != ICE_SUCCESS)
3589 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
3591 ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
3592 ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
3593 ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
3594 ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS |
3595 ICE_AQ_LINK_EVENT_SIGNAL_DETECT |
3596 ICE_AQ_LINK_EVENT_AN_COMPLETED |
3597 ICE_AQ_LINK_EVENT_PORT_TX_SUSPENDED)),
3599 if (ret != ICE_SUCCESS)
3600 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
3602 ice_get_init_link_status(dev);
3604 ice_dev_set_link_up(dev);
3606 /* Call get_link_info aq commond to enable/disable LSE */
3607 ice_link_update(dev, 0);
3609 pf->adapter_stopped = false;
3611 /* Set the max frame size to default value*/
3612 max_frame_size = pf->dev_data->mtu ?
3613 pf->dev_data->mtu + ICE_ETH_OVERHEAD :
3616 /* Set the max frame size to HW*/
3617 ice_aq_set_mac_cfg(hw, max_frame_size, NULL);
3619 if (ad->devargs.pps_out_ena) {
3620 ret = ice_pps_out_cfg(hw, pin_idx, timer);
3622 PMD_DRV_LOG(ERR, "Fail to configure 1pps out");
3629 /* stop the started queues if failed to start all queues */
3631 for (i = 0; i < nb_rxq; i++)
3632 ice_rx_queue_stop(dev, i);
3634 for (i = 0; i < nb_txq; i++)
3635 ice_tx_queue_stop(dev, i);
3641 ice_dev_reset(struct rte_eth_dev *dev)
3645 if (dev->data->sriov.active)
3648 ret = ice_dev_uninit(dev);
3650 PMD_INIT_LOG(ERR, "failed to uninit device, status = %d", ret);
3654 ret = ice_dev_init(dev);
3656 PMD_INIT_LOG(ERR, "failed to init device, status = %d", ret);
3664 ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3666 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3667 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3668 struct ice_vsi *vsi = pf->main_vsi;
3669 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3670 bool is_safe_mode = pf->adapter->is_safe_mode;
3674 dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
3675 dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
3676 dev_info->max_rx_queues = vsi->nb_qps;
3677 dev_info->max_tx_queues = vsi->nb_qps;
3678 dev_info->max_mac_addrs = vsi->max_macaddrs;
3679 dev_info->max_vfs = pci_dev->max_vfs;
3680 dev_info->max_mtu = dev_info->max_rx_pktlen - ICE_ETH_OVERHEAD;
3681 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3683 dev_info->rx_offload_capa =
3684 RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3685 RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3686 RTE_ETH_RX_OFFLOAD_SCATTER |
3687 RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
3688 dev_info->tx_offload_capa =
3689 RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3690 RTE_ETH_TX_OFFLOAD_TCP_TSO |
3691 RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3692 RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3693 dev_info->flow_type_rss_offloads = 0;
3695 if (!is_safe_mode) {
3696 dev_info->rx_offload_capa |=
3697 RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3698 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3699 RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3700 RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3701 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3702 RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3703 RTE_ETH_RX_OFFLOAD_RSS_HASH |
3704 RTE_ETH_RX_OFFLOAD_TIMESTAMP;
3705 dev_info->tx_offload_capa |=
3706 RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3707 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3708 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3709 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3710 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3711 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3712 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
3713 dev_info->flow_type_rss_offloads |= ICE_RSS_OFFLOAD_ALL;
3716 dev_info->rx_queue_offload_capa = 0;
3717 dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3719 dev_info->reta_size = pf->hash_lut_size;
3720 dev_info->hash_key_size = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
3722 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3724 .pthresh = ICE_DEFAULT_RX_PTHRESH,
3725 .hthresh = ICE_DEFAULT_RX_HTHRESH,
3726 .wthresh = ICE_DEFAULT_RX_WTHRESH,
3728 .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
3733 dev_info->default_txconf = (struct rte_eth_txconf) {
3735 .pthresh = ICE_DEFAULT_TX_PTHRESH,
3736 .hthresh = ICE_DEFAULT_TX_HTHRESH,
3737 .wthresh = ICE_DEFAULT_TX_WTHRESH,
3739 .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
3740 .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
3744 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3745 .nb_max = ICE_MAX_RING_DESC,
3746 .nb_min = ICE_MIN_RING_DESC,
3747 .nb_align = ICE_ALIGN_RING_DESC,
3750 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3751 .nb_max = ICE_MAX_RING_DESC,
3752 .nb_min = ICE_MIN_RING_DESC,
3753 .nb_align = ICE_ALIGN_RING_DESC,
3756 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M |
3757 RTE_ETH_LINK_SPEED_100M |
3758 RTE_ETH_LINK_SPEED_1G |
3759 RTE_ETH_LINK_SPEED_2_5G |
3760 RTE_ETH_LINK_SPEED_5G |
3761 RTE_ETH_LINK_SPEED_10G |
3762 RTE_ETH_LINK_SPEED_20G |
3763 RTE_ETH_LINK_SPEED_25G;
3765 phy_type_low = hw->port_info->phy.phy_type_low;
3766 phy_type_high = hw->port_info->phy.phy_type_high;
3768 if (ICE_PHY_TYPE_SUPPORT_50G(phy_type_low))
3769 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_50G;
3771 if (ICE_PHY_TYPE_SUPPORT_100G_LOW(phy_type_low) ||
3772 ICE_PHY_TYPE_SUPPORT_100G_HIGH(phy_type_high))
3773 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100G;
3775 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
3776 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
3778 dev_info->default_rxportconf.burst_size = ICE_RX_MAX_BURST;
3779 dev_info->default_txportconf.burst_size = ICE_TX_MAX_BURST;
3780 dev_info->default_rxportconf.nb_queues = 1;
3781 dev_info->default_txportconf.nb_queues = 1;
3782 dev_info->default_rxportconf.ring_size = ICE_BUF_SIZE_MIN;
3783 dev_info->default_txportconf.ring_size = ICE_BUF_SIZE_MIN;
3789 ice_atomic_read_link_status(struct rte_eth_dev *dev,
3790 struct rte_eth_link *link)
3792 struct rte_eth_link *dst = link;
3793 struct rte_eth_link *src = &dev->data->dev_link;
3795 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3796 *(uint64_t *)src) == 0)
3803 ice_atomic_write_link_status(struct rte_eth_dev *dev,
3804 struct rte_eth_link *link)
3806 struct rte_eth_link *dst = &dev->data->dev_link;
3807 struct rte_eth_link *src = link;
3809 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3810 *(uint64_t *)src) == 0)
3817 ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3819 #define CHECK_INTERVAL 100 /* 100ms */
3820 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3821 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3822 struct ice_link_status link_status;
3823 struct rte_eth_link link, old;
3825 unsigned int rep_cnt = MAX_REPEAT_TIME;
3826 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3828 memset(&link, 0, sizeof(link));
3829 memset(&old, 0, sizeof(old));
3830 memset(&link_status, 0, sizeof(link_status));
3831 ice_atomic_read_link_status(dev, &old);
3834 /* Get link status information from hardware */
3835 status = ice_aq_get_link_info(hw->port_info, enable_lse,
3836 &link_status, NULL);
3837 if (status != ICE_SUCCESS) {
3838 link.link_speed = RTE_ETH_SPEED_NUM_100M;
3839 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3840 PMD_DRV_LOG(ERR, "Failed to get link info");
3844 link.link_status = link_status.link_info & ICE_AQ_LINK_UP;
3845 if (!wait_to_complete || link.link_status)
3848 rte_delay_ms(CHECK_INTERVAL);
3849 } while (--rep_cnt);
3851 if (!link.link_status)
3854 /* Full-duplex operation at all supported speeds */
3855 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3857 /* Parse the link status */
3858 switch (link_status.link_speed) {
3859 case ICE_AQ_LINK_SPEED_10MB:
3860 link.link_speed = RTE_ETH_SPEED_NUM_10M;
3862 case ICE_AQ_LINK_SPEED_100MB:
3863 link.link_speed = RTE_ETH_SPEED_NUM_100M;
3865 case ICE_AQ_LINK_SPEED_1000MB:
3866 link.link_speed = RTE_ETH_SPEED_NUM_1G;
3868 case ICE_AQ_LINK_SPEED_2500MB:
3869 link.link_speed = RTE_ETH_SPEED_NUM_2_5G;
3871 case ICE_AQ_LINK_SPEED_5GB:
3872 link.link_speed = RTE_ETH_SPEED_NUM_5G;
3874 case ICE_AQ_LINK_SPEED_10GB:
3875 link.link_speed = RTE_ETH_SPEED_NUM_10G;
3877 case ICE_AQ_LINK_SPEED_20GB:
3878 link.link_speed = RTE_ETH_SPEED_NUM_20G;
3880 case ICE_AQ_LINK_SPEED_25GB:
3881 link.link_speed = RTE_ETH_SPEED_NUM_25G;
3883 case ICE_AQ_LINK_SPEED_40GB:
3884 link.link_speed = RTE_ETH_SPEED_NUM_40G;
3886 case ICE_AQ_LINK_SPEED_50GB:
3887 link.link_speed = RTE_ETH_SPEED_NUM_50G;
3889 case ICE_AQ_LINK_SPEED_100GB:
3890 link.link_speed = RTE_ETH_SPEED_NUM_100G;
3892 case ICE_AQ_LINK_SPEED_UNKNOWN:
3893 PMD_DRV_LOG(ERR, "Unknown link speed");
3894 link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3897 PMD_DRV_LOG(ERR, "None link speed");
3898 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
3902 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3903 RTE_ETH_LINK_SPEED_FIXED);
3906 ice_atomic_write_link_status(dev, &link);
3907 if (link.link_status == old.link_status)
3913 /* Force the physical link state by getting the current PHY capabilities from
3914 * hardware and setting the PHY config based on the determined capabilities. If
3915 * link changes, link event will be triggered because both the Enable Automatic
3916 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
3918 static enum ice_status
3919 ice_force_phys_link_state(struct ice_hw *hw, bool link_up)
3921 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
3922 struct ice_aqc_get_phy_caps_data *pcaps;
3923 struct ice_port_info *pi;
3924 enum ice_status status;
3926 if (!hw || !hw->port_info)
3927 return ICE_ERR_PARAM;
3931 pcaps = (struct ice_aqc_get_phy_caps_data *)
3932 ice_malloc(hw, sizeof(*pcaps));
3934 return ICE_ERR_NO_MEMORY;
3936 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
3941 /* No change in link */
3942 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
3943 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
3946 cfg.phy_type_low = pcaps->phy_type_low;
3947 cfg.phy_type_high = pcaps->phy_type_high;
3948 cfg.caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3949 cfg.low_power_ctrl_an = pcaps->low_power_ctrl_an;
3950 cfg.eee_cap = pcaps->eee_cap;
3951 cfg.eeer_value = pcaps->eeer_value;
3952 cfg.link_fec_opt = pcaps->link_fec_options;
3954 cfg.caps |= ICE_AQ_PHY_ENA_LINK;
3956 cfg.caps &= ~ICE_AQ_PHY_ENA_LINK;
3958 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
3961 ice_free(hw, pcaps);
3966 ice_dev_set_link_up(struct rte_eth_dev *dev)
3968 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3970 return ice_force_phys_link_state(hw, true);
3974 ice_dev_set_link_down(struct rte_eth_dev *dev)
3976 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3978 return ice_force_phys_link_state(hw, false);
3982 ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
3984 /* mtu setting is forbidden if port is start */
3985 if (dev->data->dev_started != 0) {
3987 "port %d must be stopped before configuration",
3988 dev->data->port_id);
3995 static int ice_macaddr_set(struct rte_eth_dev *dev,
3996 struct rte_ether_addr *mac_addr)
3998 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3999 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4000 struct ice_vsi *vsi = pf->main_vsi;
4001 struct ice_mac_filter *f;
4005 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
4006 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
4010 TAILQ_FOREACH(f, &vsi->mac_list, next) {
4011 if (rte_is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
4016 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
4020 ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr);
4021 if (ret != ICE_SUCCESS) {
4022 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
4025 ret = ice_add_mac_filter(vsi, mac_addr);
4026 if (ret != ICE_SUCCESS) {
4027 PMD_DRV_LOG(ERR, "Failed to add mac filter");
4030 rte_ether_addr_copy(mac_addr, &pf->dev_addr);
4032 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
4033 ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL);
4034 if (ret != ICE_SUCCESS)
4035 PMD_DRV_LOG(ERR, "Failed to set manage mac");
4040 /* Add a MAC address, and update filters */
4042 ice_macaddr_add(struct rte_eth_dev *dev,
4043 struct rte_ether_addr *mac_addr,
4044 __rte_unused uint32_t index,
4045 __rte_unused uint32_t pool)
4047 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4048 struct ice_vsi *vsi = pf->main_vsi;
4051 ret = ice_add_mac_filter(vsi, mac_addr);
4052 if (ret != ICE_SUCCESS) {
4053 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
4060 /* Remove a MAC address, and update filters */
4062 ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4064 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4065 struct ice_vsi *vsi = pf->main_vsi;
4066 struct rte_eth_dev_data *data = dev->data;
4067 struct rte_ether_addr *macaddr;
4070 macaddr = &data->mac_addrs[index];
4071 ret = ice_remove_mac_filter(vsi, macaddr);
4073 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
4079 ice_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4081 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4082 struct ice_vlan vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, vlan_id);
4083 struct ice_vsi *vsi = pf->main_vsi;
4086 PMD_INIT_FUNC_TRACE();
4089 * Vlan 0 is the generic filter for untagged packets
4090 * and can't be removed or added by user.
4096 ret = ice_add_vlan_filter(vsi, &vlan);
4098 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
4102 ret = ice_remove_vlan_filter(vsi, &vlan);
4104 PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
4112 /* In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are
4113 * based on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8)
4114 * doesn't matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
4115 * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
4117 * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
4118 * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
4119 * traffic in SVM, since the VLAN TPID isn't part of filtering.
4121 * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
4122 * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
4123 * part of filtering.
4126 ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
4128 struct ice_vlan vlan;
4131 vlan = ICE_VLAN(0, 0);
4132 err = ice_add_vlan_filter(vsi, &vlan);
4134 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0");
4138 /* in SVM both VLAN 0 filters are identical */
4139 if (!ice_is_dvm_ena(&vsi->adapter->hw))
4142 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
4143 err = ice_add_vlan_filter(vsi, &vlan);
4145 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0 in double VLAN mode");
4153 * Delete the VLAN 0 filters in the same manner that they were added in
4154 * ice_vsi_add_vlan_zero.
4157 ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
4159 struct ice_vlan vlan;
4162 vlan = ICE_VLAN(0, 0);
4163 err = ice_remove_vlan_filter(vsi, &vlan);
4165 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0");
4169 /* in SVM both VLAN 0 filters are identical */
4170 if (!ice_is_dvm_ena(&vsi->adapter->hw))
4173 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
4174 err = ice_remove_vlan_filter(vsi, &vlan);
4176 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0 in double VLAN mode");
4183 /* Configure vlan filter on or off */
4185 ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
4187 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4188 struct ice_vsi_ctx ctxt;
4192 sw_flags2 = ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4195 vsi->info.sw_flags2 |= sw_flags2;
4197 vsi->info.sw_flags2 &= ~sw_flags2;
4199 vsi->info.sw_id = hw->port_info->sw_id;
4200 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4201 ctxt.info.valid_sections =
4202 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
4203 ICE_AQ_VSI_PROP_SECURITY_VALID);
4204 ctxt.vsi_num = vsi->vsi_id;
4206 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4208 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
4209 on ? "enable" : "disable");
4212 vsi->info.valid_sections |=
4213 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
4214 ICE_AQ_VSI_PROP_SECURITY_VALID);
4217 /* consist with other drivers, allow untagged packet when vlan filter on */
4219 ret = ice_vsi_add_vlan_zero(vsi);
4221 ret = ice_vsi_del_vlan_zero(vsi);
4226 /* Manage VLAN stripping for the VSI for Rx */
4228 ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
4230 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4231 struct ice_vsi_ctx ctxt;
4232 enum ice_status status;
4235 /* do not allow modifying VLAN stripping when a port VLAN is configured
4238 if (vsi->info.port_based_inner_vlan)
4241 memset(&ctxt, 0, sizeof(ctxt));
4244 /* Strip VLAN tag from Rx packet and put it in the desc */
4245 ctxt.info.inner_vlan_flags =
4246 ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
4248 /* Disable stripping. Leave tag in packet */
4249 ctxt.info.inner_vlan_flags =
4250 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4252 /* Allow all packets untagged/tagged */
4253 ctxt.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
4255 ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4257 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4259 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan stripping",
4260 ena ? "enable" : "disable");
4263 vsi->info.inner_vlan_flags = ctxt.info.inner_vlan_flags;
4270 ice_vsi_ena_inner_stripping(struct ice_vsi *vsi)
4272 return ice_vsi_manage_vlan_stripping(vsi, true);
4276 ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
4278 return ice_vsi_manage_vlan_stripping(vsi, false);
4281 static int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi)
4283 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4284 struct ice_vsi_ctx ctxt;
4285 enum ice_status status;
4288 /* do not allow modifying VLAN stripping when a port VLAN is configured
4291 if (vsi->info.port_based_outer_vlan)
4294 memset(&ctxt, 0, sizeof(ctxt));
4296 ctxt.info.valid_sections =
4297 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4298 /* clear current outer VLAN strip settings */
4299 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4300 ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
4301 ctxt.info.outer_vlan_flags |=
4302 (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
4303 ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
4304 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
4305 ICE_AQ_VSI_OUTER_TAG_TYPE_S);
4307 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4309 PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
4312 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4319 ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
4321 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4322 struct ice_vsi_ctx ctxt;
4323 enum ice_status status;
4326 if (vsi->info.port_based_outer_vlan)
4329 memset(&ctxt, 0, sizeof(ctxt));
4331 ctxt.info.valid_sections =
4332 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4333 /* clear current outer VLAN strip settings */
4334 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4335 ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
4336 ctxt.info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
4337 ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
4339 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4341 PMD_DRV_LOG(ERR, "Update VSI failed to disable outer VLAN stripping");
4344 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4351 ice_vsi_config_vlan_stripping(struct ice_vsi *vsi, bool ena)
4353 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4356 if (ice_is_dvm_ena(hw)) {
4358 ret = ice_vsi_ena_outer_stripping(vsi);
4360 ret = ice_vsi_dis_outer_stripping(vsi);
4363 ret = ice_vsi_ena_inner_stripping(vsi);
4365 ret = ice_vsi_dis_inner_stripping(vsi);
4372 ice_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4374 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4375 struct ice_vsi *vsi = pf->main_vsi;
4376 struct rte_eth_rxmode *rxmode;
4378 rxmode = &dev->data->dev_conf.rxmode;
4379 if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4380 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4381 ice_vsi_config_vlan_filter(vsi, true);
4383 ice_vsi_config_vlan_filter(vsi, false);
4386 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4387 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4388 ice_vsi_config_vlan_stripping(vsi, true);
4390 ice_vsi_config_vlan_stripping(vsi, false);
4397 ice_get_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4399 struct ice_aq_get_set_rss_lut_params lut_params;
4400 struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
4401 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4407 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4408 lut_params.vsi_handle = vsi->idx;
4409 lut_params.lut_size = lut_size;
4410 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4411 lut_params.lut = lut;
4412 lut_params.global_lut_id = 0;
4413 ret = ice_aq_get_rss_lut(hw, &lut_params);
4415 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4419 uint64_t *lut_dw = (uint64_t *)lut;
4420 uint16_t i, lut_size_dw = lut_size / 4;
4422 for (i = 0; i < lut_size_dw; i++)
4423 lut_dw[i] = ICE_READ_REG(hw, PFQF_HLUT(i));
4430 ice_set_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4432 struct ice_aq_get_set_rss_lut_params lut_params;
4440 pf = ICE_VSI_TO_PF(vsi);
4441 hw = ICE_VSI_TO_HW(vsi);
4443 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4444 lut_params.vsi_handle = vsi->idx;
4445 lut_params.lut_size = lut_size;
4446 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4447 lut_params.lut = lut;
4448 lut_params.global_lut_id = 0;
4449 ret = ice_aq_set_rss_lut(hw, &lut_params);
4451 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
4455 uint64_t *lut_dw = (uint64_t *)lut;
4456 uint16_t i, lut_size_dw = lut_size / 4;
4458 for (i = 0; i < lut_size_dw; i++)
4459 ICE_WRITE_REG(hw, PFQF_HLUT(i), lut_dw[i]);
4468 ice_rss_reta_update(struct rte_eth_dev *dev,
4469 struct rte_eth_rss_reta_entry64 *reta_conf,
4472 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4473 uint16_t i, lut_size = pf->hash_lut_size;
4474 uint16_t idx, shift;
4478 if (reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128 &&
4479 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512 &&
4480 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) {
4482 "The size of hash lookup table configured (%d)"
4483 "doesn't match the number hardware can "
4484 "supported (128, 512, 2048)",
4489 /* It MUST use the current LUT size to get the RSS lookup table,
4490 * otherwise if will fail with -100 error code.
4492 lut = rte_zmalloc(NULL, RTE_MAX(reta_size, lut_size), 0);
4494 PMD_DRV_LOG(ERR, "No memory can be allocated");
4497 ret = ice_get_rss_lut(pf->main_vsi, lut, lut_size);
4501 for (i = 0; i < reta_size; i++) {
4502 idx = i / RTE_ETH_RETA_GROUP_SIZE;
4503 shift = i % RTE_ETH_RETA_GROUP_SIZE;
4504 if (reta_conf[idx].mask & (1ULL << shift))
4505 lut[i] = reta_conf[idx].reta[shift];
4507 ret = ice_set_rss_lut(pf->main_vsi, lut, reta_size);
4508 if (ret == 0 && lut_size != reta_size) {
4510 "The size of hash lookup table is changed from (%d) to (%d)",
4511 lut_size, reta_size);
4512 pf->hash_lut_size = reta_size;
4522 ice_rss_reta_query(struct rte_eth_dev *dev,
4523 struct rte_eth_rss_reta_entry64 *reta_conf,
4526 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4527 uint16_t i, lut_size = pf->hash_lut_size;
4528 uint16_t idx, shift;
4532 if (reta_size != lut_size) {
4534 "The size of hash lookup table configured (%d)"
4535 "doesn't match the number hardware can "
4537 reta_size, lut_size);
4541 lut = rte_zmalloc(NULL, reta_size, 0);
4543 PMD_DRV_LOG(ERR, "No memory can be allocated");
4547 ret = ice_get_rss_lut(pf->main_vsi, lut, reta_size);
4551 for (i = 0; i < reta_size; i++) {
4552 idx = i / RTE_ETH_RETA_GROUP_SIZE;
4553 shift = i % RTE_ETH_RETA_GROUP_SIZE;
4554 if (reta_conf[idx].mask & (1ULL << shift))
4555 reta_conf[idx].reta[shift] = lut[i];
4565 ice_set_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t key_len)
4567 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4570 if (!key || key_len == 0) {
4571 PMD_DRV_LOG(DEBUG, "No key to be configured");
4573 } else if (key_len != (VSIQF_HKEY_MAX_INDEX + 1) *
4575 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
4579 struct ice_aqc_get_set_rss_keys *key_dw =
4580 (struct ice_aqc_get_set_rss_keys *)key;
4582 ret = ice_aq_set_rss_key(hw, vsi->idx, key_dw);
4584 PMD_DRV_LOG(ERR, "Failed to configure RSS key via AQ");
4592 ice_get_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t *key_len)
4594 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4597 if (!key || !key_len)
4600 ret = ice_aq_get_rss_key
4602 (struct ice_aqc_get_set_rss_keys *)key);
4604 PMD_DRV_LOG(ERR, "Failed to get RSS key via AQ");
4607 *key_len = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
4613 ice_rss_hash_update(struct rte_eth_dev *dev,
4614 struct rte_eth_rss_conf *rss_conf)
4616 enum ice_status status = ICE_SUCCESS;
4617 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4618 struct ice_vsi *vsi = pf->main_vsi;
4621 status = ice_set_rss_key(vsi, rss_conf->rss_key, rss_conf->rss_key_len);
4625 if (rss_conf->rss_hf == 0) {
4630 /* RSS hash configuration */
4631 ice_rss_hash_set(pf, rss_conf->rss_hf);
4637 ice_rss_hash_conf_get(struct rte_eth_dev *dev,
4638 struct rte_eth_rss_conf *rss_conf)
4640 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4641 struct ice_vsi *vsi = pf->main_vsi;
4643 ice_get_rss_key(vsi, rss_conf->rss_key,
4644 &rss_conf->rss_key_len);
4646 rss_conf->rss_hf = pf->rss_hf;
4651 ice_promisc_enable(struct rte_eth_dev *dev)
4653 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4654 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4655 struct ice_vsi *vsi = pf->main_vsi;
4656 enum ice_status status;
4660 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4661 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4663 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4665 case ICE_ERR_ALREADY_EXISTS:
4666 PMD_DRV_LOG(DEBUG, "Promisc mode has already been enabled");
4670 PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
4678 ice_promisc_disable(struct rte_eth_dev *dev)
4680 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4681 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4682 struct ice_vsi *vsi = pf->main_vsi;
4683 enum ice_status status;
4687 if (dev->data->all_multicast == 1)
4688 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX;
4690 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4691 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4693 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4694 if (status != ICE_SUCCESS) {
4695 PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
4703 ice_allmulti_enable(struct rte_eth_dev *dev)
4705 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4706 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4707 struct ice_vsi *vsi = pf->main_vsi;
4708 enum ice_status status;
4712 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4714 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4717 case ICE_ERR_ALREADY_EXISTS:
4718 PMD_DRV_LOG(DEBUG, "Allmulti has already been enabled");
4722 PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
4730 ice_allmulti_disable(struct rte_eth_dev *dev)
4732 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4733 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4734 struct ice_vsi *vsi = pf->main_vsi;
4735 enum ice_status status;
4739 if (dev->data->promiscuous == 1)
4740 return 0; /* must remain in all_multicast mode */
4742 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4744 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4745 if (status != ICE_SUCCESS) {
4746 PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
4753 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
4756 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4757 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4758 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4762 msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
4764 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
4765 GLINT_DYN_CTL_ITR_INDX_M;
4766 val &= ~GLINT_DYN_CTL_WB_ON_ITR_M;
4768 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), val);
4769 rte_intr_ack(pci_dev->intr_handle);
4774 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
4777 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4778 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4779 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4782 msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
4784 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), GLINT_DYN_CTL_WB_ON_ITR_M);
4790 ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
4792 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4797 ver = hw->flash.orom.major;
4798 patch = hw->flash.orom.patch;
4799 build = hw->flash.orom.build;
4801 ret = snprintf(fw_version, fw_size,
4802 "%x.%02x 0x%08x %d.%d.%d",
4803 hw->flash.nvm.major,
4804 hw->flash.nvm.minor,
4805 hw->flash.nvm.eetrack,
4810 /* add the size of '\0' */
4812 if (fw_size < (size_t)ret)
4819 ice_vsi_vlan_pvid_set(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
4822 struct ice_vsi_ctx ctxt;
4823 uint8_t vlan_flags = 0;
4826 if (!vsi || !info) {
4827 PMD_DRV_LOG(ERR, "invalid parameters");
4832 vsi->info.port_based_inner_vlan = info->config.pvid;
4834 * If insert pvid is enabled, only tagged pkts are
4835 * allowed to be sent out.
4837 vlan_flags = ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4838 ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4840 vsi->info.port_based_inner_vlan = 0;
4841 if (info->config.reject.tagged == 0)
4842 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTTAGGED;
4844 if (info->config.reject.untagged == 0)
4845 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4847 vsi->info.inner_vlan_flags &= ~(ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4848 ICE_AQ_VSI_INNER_VLAN_EMODE_M);
4849 vsi->info.inner_vlan_flags |= vlan_flags;
4850 memset(&ctxt, 0, sizeof(ctxt));
4851 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4852 ctxt.info.valid_sections =
4853 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4854 ctxt.vsi_num = vsi->vsi_id;
4856 hw = ICE_VSI_TO_HW(vsi);
4857 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4858 if (ret != ICE_SUCCESS) {
4860 "update VSI for VLAN insert failed, err %d",
4865 vsi->info.valid_sections |=
4866 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4872 ice_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4874 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4875 struct ice_vsi *vsi = pf->main_vsi;
4876 struct rte_eth_dev_data *data = pf->dev_data;
4877 struct ice_vsi_vlan_pvid_info info;
4880 memset(&info, 0, sizeof(info));
4883 info.config.pvid = pvid;
4885 info.config.reject.tagged =
4886 data->dev_conf.txmode.hw_vlan_reject_tagged;
4887 info.config.reject.untagged =
4888 data->dev_conf.txmode.hw_vlan_reject_untagged;
4891 ret = ice_vsi_vlan_pvid_set(vsi, &info);
4893 PMD_DRV_LOG(ERR, "Failed to set pvid.");
4901 ice_get_eeprom_length(struct rte_eth_dev *dev)
4903 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4905 return hw->flash.flash_size;
4909 ice_get_eeprom(struct rte_eth_dev *dev,
4910 struct rte_dev_eeprom_info *eeprom)
4912 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4913 enum ice_status status = ICE_SUCCESS;
4914 uint8_t *data = eeprom->data;
4916 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
4918 status = ice_acquire_nvm(hw, ICE_RES_READ);
4920 PMD_DRV_LOG(ERR, "acquire nvm failed.");
4924 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->length,
4927 ice_release_nvm(hw);
4930 PMD_DRV_LOG(ERR, "EEPROM read failed.");
4938 ice_stat_update_32(struct ice_hw *hw,
4946 new_data = (uint64_t)ICE_READ_REG(hw, reg);
4950 if (new_data >= *offset)
4951 *stat = (uint64_t)(new_data - *offset);
4953 *stat = (uint64_t)((new_data +
4954 ((uint64_t)1 << ICE_32_BIT_WIDTH))
4959 ice_stat_update_40(struct ice_hw *hw,
4968 new_data = (uint64_t)ICE_READ_REG(hw, loreg);
4969 new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
4975 if (new_data >= *offset)
4976 *stat = new_data - *offset;
4978 *stat = (uint64_t)((new_data +
4979 ((uint64_t)1 << ICE_40_BIT_WIDTH)) -
4982 *stat &= ICE_40_BIT_MASK;
4985 /* Get all the statistics of a VSI */
4987 ice_update_vsi_stats(struct ice_vsi *vsi)
4989 struct ice_eth_stats *oes = &vsi->eth_stats_offset;
4990 struct ice_eth_stats *nes = &vsi->eth_stats;
4991 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4992 int idx = rte_le_to_cpu_16(vsi->vsi_id);
4994 ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
4995 vsi->offset_loaded, &oes->rx_bytes,
4997 ice_stat_update_40(hw, GLV_UPRCH(idx), GLV_UPRCL(idx),
4998 vsi->offset_loaded, &oes->rx_unicast,
5000 ice_stat_update_40(hw, GLV_MPRCH(idx), GLV_MPRCL(idx),
5001 vsi->offset_loaded, &oes->rx_multicast,
5002 &nes->rx_multicast);
5003 ice_stat_update_40(hw, GLV_BPRCH(idx), GLV_BPRCL(idx),
5004 vsi->offset_loaded, &oes->rx_broadcast,
5005 &nes->rx_broadcast);
5006 /* enlarge the limitation when rx_bytes overflowed */
5007 if (vsi->offset_loaded) {
5008 if (ICE_RXTX_BYTES_LOW(vsi->old_rx_bytes) > nes->rx_bytes)
5009 nes->rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5010 nes->rx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_rx_bytes);
5012 vsi->old_rx_bytes = nes->rx_bytes;
5013 /* exclude CRC bytes */
5014 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
5015 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
5017 ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
5018 &oes->rx_discards, &nes->rx_discards);
5019 /* GLV_REPC not supported */
5020 /* GLV_RMPC not supported */
5021 ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
5022 &oes->rx_unknown_protocol,
5023 &nes->rx_unknown_protocol);
5024 ice_stat_update_40(hw, GLV_GOTCH(idx), GLV_GOTCL(idx),
5025 vsi->offset_loaded, &oes->tx_bytes,
5027 ice_stat_update_40(hw, GLV_UPTCH(idx), GLV_UPTCL(idx),
5028 vsi->offset_loaded, &oes->tx_unicast,
5030 ice_stat_update_40(hw, GLV_MPTCH(idx), GLV_MPTCL(idx),
5031 vsi->offset_loaded, &oes->tx_multicast,
5032 &nes->tx_multicast);
5033 ice_stat_update_40(hw, GLV_BPTCH(idx), GLV_BPTCL(idx),
5034 vsi->offset_loaded, &oes->tx_broadcast,
5035 &nes->tx_broadcast);
5036 /* GLV_TDPC not supported */
5037 ice_stat_update_32(hw, GLV_TEPC(idx), vsi->offset_loaded,
5038 &oes->tx_errors, &nes->tx_errors);
5039 /* enlarge the limitation when tx_bytes overflowed */
5040 if (vsi->offset_loaded) {
5041 if (ICE_RXTX_BYTES_LOW(vsi->old_tx_bytes) > nes->tx_bytes)
5042 nes->tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5043 nes->tx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_tx_bytes);
5045 vsi->old_tx_bytes = nes->tx_bytes;
5046 vsi->offset_loaded = true;
5048 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats start **************",
5050 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
5051 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
5052 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
5053 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
5054 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
5055 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
5056 nes->rx_unknown_protocol);
5057 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
5058 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
5059 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
5060 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
5061 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
5062 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
5063 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats end ****************",
5068 ice_read_stats_registers(struct ice_pf *pf, struct ice_hw *hw)
5070 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
5071 struct ice_hw_port_stats *os = &pf->stats_offset; /* old stats */
5073 /* Get statistics of struct ice_eth_stats */
5074 ice_stat_update_40(hw, GLPRT_GORCH(hw->port_info->lport),
5075 GLPRT_GORCL(hw->port_info->lport),
5076 pf->offset_loaded, &os->eth.rx_bytes,
5078 ice_stat_update_40(hw, GLPRT_UPRCH(hw->port_info->lport),
5079 GLPRT_UPRCL(hw->port_info->lport),
5080 pf->offset_loaded, &os->eth.rx_unicast,
5081 &ns->eth.rx_unicast);
5082 ice_stat_update_40(hw, GLPRT_MPRCH(hw->port_info->lport),
5083 GLPRT_MPRCL(hw->port_info->lport),
5084 pf->offset_loaded, &os->eth.rx_multicast,
5085 &ns->eth.rx_multicast);
5086 ice_stat_update_40(hw, GLPRT_BPRCH(hw->port_info->lport),
5087 GLPRT_BPRCL(hw->port_info->lport),
5088 pf->offset_loaded, &os->eth.rx_broadcast,
5089 &ns->eth.rx_broadcast);
5090 ice_stat_update_32(hw, PRTRPB_RDPC,
5091 pf->offset_loaded, &os->eth.rx_discards,
5092 &ns->eth.rx_discards);
5093 /* enlarge the limitation when rx_bytes overflowed */
5094 if (pf->offset_loaded) {
5095 if (ICE_RXTX_BYTES_LOW(pf->old_rx_bytes) > ns->eth.rx_bytes)
5096 ns->eth.rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5097 ns->eth.rx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_rx_bytes);
5099 pf->old_rx_bytes = ns->eth.rx_bytes;
5101 /* Workaround: CRC size should not be included in byte statistics,
5102 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
5105 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
5106 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
5108 /* GLPRT_REPC not supported */
5109 /* GLPRT_RMPC not supported */
5110 ice_stat_update_32(hw, GLSWID_RUPP(hw->port_info->lport),
5112 &os->eth.rx_unknown_protocol,
5113 &ns->eth.rx_unknown_protocol);
5114 ice_stat_update_40(hw, GLPRT_GOTCH(hw->port_info->lport),
5115 GLPRT_GOTCL(hw->port_info->lport),
5116 pf->offset_loaded, &os->eth.tx_bytes,
5118 ice_stat_update_40(hw, GLPRT_UPTCH(hw->port_info->lport),
5119 GLPRT_UPTCL(hw->port_info->lport),
5120 pf->offset_loaded, &os->eth.tx_unicast,
5121 &ns->eth.tx_unicast);
5122 ice_stat_update_40(hw, GLPRT_MPTCH(hw->port_info->lport),
5123 GLPRT_MPTCL(hw->port_info->lport),
5124 pf->offset_loaded, &os->eth.tx_multicast,
5125 &ns->eth.tx_multicast);
5126 ice_stat_update_40(hw, GLPRT_BPTCH(hw->port_info->lport),
5127 GLPRT_BPTCL(hw->port_info->lport),
5128 pf->offset_loaded, &os->eth.tx_broadcast,
5129 &ns->eth.tx_broadcast);
5130 /* enlarge the limitation when tx_bytes overflowed */
5131 if (pf->offset_loaded) {
5132 if (ICE_RXTX_BYTES_LOW(pf->old_tx_bytes) > ns->eth.tx_bytes)
5133 ns->eth.tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5134 ns->eth.tx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_tx_bytes);
5136 pf->old_tx_bytes = ns->eth.tx_bytes;
5137 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
5138 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
5140 /* GLPRT_TEPC not supported */
5142 /* additional port specific stats */
5143 ice_stat_update_32(hw, GLPRT_TDOLD(hw->port_info->lport),
5144 pf->offset_loaded, &os->tx_dropped_link_down,
5145 &ns->tx_dropped_link_down);
5146 ice_stat_update_32(hw, GLPRT_CRCERRS(hw->port_info->lport),
5147 pf->offset_loaded, &os->crc_errors,
5149 ice_stat_update_32(hw, GLPRT_ILLERRC(hw->port_info->lport),
5150 pf->offset_loaded, &os->illegal_bytes,
5151 &ns->illegal_bytes);
5152 /* GLPRT_ERRBC not supported */
5153 ice_stat_update_32(hw, GLPRT_MLFC(hw->port_info->lport),
5154 pf->offset_loaded, &os->mac_local_faults,
5155 &ns->mac_local_faults);
5156 ice_stat_update_32(hw, GLPRT_MRFC(hw->port_info->lport),
5157 pf->offset_loaded, &os->mac_remote_faults,
5158 &ns->mac_remote_faults);
5160 ice_stat_update_32(hw, GLPRT_RLEC(hw->port_info->lport),
5161 pf->offset_loaded, &os->rx_len_errors,
5162 &ns->rx_len_errors);
5164 ice_stat_update_32(hw, GLPRT_LXONRXC(hw->port_info->lport),
5165 pf->offset_loaded, &os->link_xon_rx,
5167 ice_stat_update_32(hw, GLPRT_LXOFFRXC(hw->port_info->lport),
5168 pf->offset_loaded, &os->link_xoff_rx,
5170 ice_stat_update_32(hw, GLPRT_LXONTXC(hw->port_info->lport),
5171 pf->offset_loaded, &os->link_xon_tx,
5173 ice_stat_update_32(hw, GLPRT_LXOFFTXC(hw->port_info->lport),
5174 pf->offset_loaded, &os->link_xoff_tx,
5176 ice_stat_update_40(hw, GLPRT_PRC64H(hw->port_info->lport),
5177 GLPRT_PRC64L(hw->port_info->lport),
5178 pf->offset_loaded, &os->rx_size_64,
5180 ice_stat_update_40(hw, GLPRT_PRC127H(hw->port_info->lport),
5181 GLPRT_PRC127L(hw->port_info->lport),
5182 pf->offset_loaded, &os->rx_size_127,
5184 ice_stat_update_40(hw, GLPRT_PRC255H(hw->port_info->lport),
5185 GLPRT_PRC255L(hw->port_info->lport),
5186 pf->offset_loaded, &os->rx_size_255,
5188 ice_stat_update_40(hw, GLPRT_PRC511H(hw->port_info->lport),
5189 GLPRT_PRC511L(hw->port_info->lport),
5190 pf->offset_loaded, &os->rx_size_511,
5192 ice_stat_update_40(hw, GLPRT_PRC1023H(hw->port_info->lport),
5193 GLPRT_PRC1023L(hw->port_info->lport),
5194 pf->offset_loaded, &os->rx_size_1023,
5196 ice_stat_update_40(hw, GLPRT_PRC1522H(hw->port_info->lport),
5197 GLPRT_PRC1522L(hw->port_info->lport),
5198 pf->offset_loaded, &os->rx_size_1522,
5200 ice_stat_update_40(hw, GLPRT_PRC9522H(hw->port_info->lport),
5201 GLPRT_PRC9522L(hw->port_info->lport),
5202 pf->offset_loaded, &os->rx_size_big,
5204 ice_stat_update_32(hw, GLPRT_RUC(hw->port_info->lport),
5205 pf->offset_loaded, &os->rx_undersize,
5207 ice_stat_update_32(hw, GLPRT_RFC(hw->port_info->lport),
5208 pf->offset_loaded, &os->rx_fragments,
5210 ice_stat_update_32(hw, GLPRT_ROC(hw->port_info->lport),
5211 pf->offset_loaded, &os->rx_oversize,
5213 ice_stat_update_32(hw, GLPRT_RJC(hw->port_info->lport),
5214 pf->offset_loaded, &os->rx_jabber,
5216 ice_stat_update_40(hw, GLPRT_PTC64H(hw->port_info->lport),
5217 GLPRT_PTC64L(hw->port_info->lport),
5218 pf->offset_loaded, &os->tx_size_64,
5220 ice_stat_update_40(hw, GLPRT_PTC127H(hw->port_info->lport),
5221 GLPRT_PTC127L(hw->port_info->lport),
5222 pf->offset_loaded, &os->tx_size_127,
5224 ice_stat_update_40(hw, GLPRT_PTC255H(hw->port_info->lport),
5225 GLPRT_PTC255L(hw->port_info->lport),
5226 pf->offset_loaded, &os->tx_size_255,
5228 ice_stat_update_40(hw, GLPRT_PTC511H(hw->port_info->lport),
5229 GLPRT_PTC511L(hw->port_info->lport),
5230 pf->offset_loaded, &os->tx_size_511,
5232 ice_stat_update_40(hw, GLPRT_PTC1023H(hw->port_info->lport),
5233 GLPRT_PTC1023L(hw->port_info->lport),
5234 pf->offset_loaded, &os->tx_size_1023,
5236 ice_stat_update_40(hw, GLPRT_PTC1522H(hw->port_info->lport),
5237 GLPRT_PTC1522L(hw->port_info->lport),
5238 pf->offset_loaded, &os->tx_size_1522,
5240 ice_stat_update_40(hw, GLPRT_PTC9522H(hw->port_info->lport),
5241 GLPRT_PTC9522L(hw->port_info->lport),
5242 pf->offset_loaded, &os->tx_size_big,
5245 /* GLPRT_MSPDC not supported */
5246 /* GLPRT_XEC not supported */
5248 pf->offset_loaded = true;
5251 ice_update_vsi_stats(pf->main_vsi);
5254 /* Get all statistics of a port */
5256 ice_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
5258 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5259 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5260 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
5262 /* call read registers - updates values, now write them to struct */
5263 ice_read_stats_registers(pf, hw);
5265 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
5266 pf->main_vsi->eth_stats.rx_multicast +
5267 pf->main_vsi->eth_stats.rx_broadcast -
5268 pf->main_vsi->eth_stats.rx_discards;
5269 stats->opackets = ns->eth.tx_unicast +
5270 ns->eth.tx_multicast +
5271 ns->eth.tx_broadcast;
5272 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
5273 stats->obytes = ns->eth.tx_bytes;
5274 stats->oerrors = ns->eth.tx_errors +
5275 pf->main_vsi->eth_stats.tx_errors;
5278 stats->imissed = ns->eth.rx_discards +
5279 pf->main_vsi->eth_stats.rx_discards;
5280 stats->ierrors = ns->crc_errors +
5282 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
5284 PMD_DRV_LOG(DEBUG, "*************** PF stats start *****************");
5285 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
5286 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
5287 PMD_DRV_LOG(DEBUG, "rx_multicast:%"PRIu64"", ns->eth.rx_multicast);
5288 PMD_DRV_LOG(DEBUG, "rx_broadcast:%"PRIu64"", ns->eth.rx_broadcast);
5289 PMD_DRV_LOG(DEBUG, "rx_discards:%"PRIu64"", ns->eth.rx_discards);
5290 PMD_DRV_LOG(DEBUG, "vsi rx_discards:%"PRIu64"",
5291 pf->main_vsi->eth_stats.rx_discards);
5292 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
5293 ns->eth.rx_unknown_protocol);
5294 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
5295 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
5296 PMD_DRV_LOG(DEBUG, "tx_multicast:%"PRIu64"", ns->eth.tx_multicast);
5297 PMD_DRV_LOG(DEBUG, "tx_broadcast:%"PRIu64"", ns->eth.tx_broadcast);
5298 PMD_DRV_LOG(DEBUG, "tx_discards:%"PRIu64"", ns->eth.tx_discards);
5299 PMD_DRV_LOG(DEBUG, "vsi tx_discards:%"PRIu64"",
5300 pf->main_vsi->eth_stats.tx_discards);
5301 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
5303 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
5304 ns->tx_dropped_link_down);
5305 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
5306 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
5308 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
5309 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
5310 ns->mac_local_faults);
5311 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
5312 ns->mac_remote_faults);
5313 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
5314 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
5315 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
5316 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
5317 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
5318 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
5319 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
5320 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
5321 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
5322 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
5323 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
5324 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
5325 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
5326 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
5327 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
5328 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
5329 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
5330 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
5331 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
5332 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
5333 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
5334 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
5335 PMD_DRV_LOG(DEBUG, "rx_len_errors: %"PRIu64"", ns->rx_len_errors);
5336 PMD_DRV_LOG(DEBUG, "************* PF stats end ****************");
5340 /* Reset the statistics */
5342 ice_stats_reset(struct rte_eth_dev *dev)
5344 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5345 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5347 /* Mark PF and VSI stats to update the offset, aka "reset" */
5348 pf->offset_loaded = false;
5350 pf->main_vsi->offset_loaded = false;
5352 /* read the stats, reading current register values into offset */
5353 ice_read_stats_registers(pf, hw);
5359 ice_xstats_calc_num(void)
5363 num = ICE_NB_ETH_XSTATS + ICE_NB_HW_PORT_XSTATS;
5369 ice_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
5372 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5373 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5376 struct ice_hw_port_stats *hw_stats = &pf->stats;
5378 count = ice_xstats_calc_num();
5382 ice_read_stats_registers(pf, hw);
5389 /* Get stats from ice_eth_stats struct */
5390 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5391 xstats[count].value =
5392 *(uint64_t *)((char *)&hw_stats->eth +
5393 ice_stats_strings[i].offset);
5394 xstats[count].id = count;
5398 /* Get individiual stats from ice_hw_port struct */
5399 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5400 xstats[count].value =
5401 *(uint64_t *)((char *)hw_stats +
5402 ice_hw_port_strings[i].offset);
5403 xstats[count].id = count;
5410 static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
5411 struct rte_eth_xstat_name *xstats_names,
5412 __rte_unused unsigned int limit)
5414 unsigned int count = 0;
5418 return ice_xstats_calc_num();
5420 /* Note: limit checked in rte_eth_xstats_names() */
5422 /* Get stats from ice_eth_stats struct */
5423 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5424 strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
5425 sizeof(xstats_names[count].name));
5429 /* Get individiual stats from ice_hw_port struct */
5430 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5431 strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
5432 sizeof(xstats_names[count].name));
5440 ice_dev_flow_ops_get(struct rte_eth_dev *dev,
5441 const struct rte_flow_ops **ops)
5446 *ops = &ice_flow_ops;
5450 /* Add UDP tunneling port */
5452 ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
5453 struct rte_eth_udp_tunnel *udp_tunnel)
5456 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5458 if (udp_tunnel == NULL)
5461 switch (udp_tunnel->prot_type) {
5462 case RTE_ETH_TUNNEL_TYPE_VXLAN:
5463 ret = ice_create_tunnel(hw, TNL_VXLAN, udp_tunnel->udp_port);
5466 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5474 /* Delete UDP tunneling port */
5476 ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
5477 struct rte_eth_udp_tunnel *udp_tunnel)
5480 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5482 if (udp_tunnel == NULL)
5485 switch (udp_tunnel->prot_type) {
5486 case RTE_ETH_TUNNEL_TYPE_VXLAN:
5487 ret = ice_destroy_tunnel(hw, udp_tunnel->udp_port, 0);
5490 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5499 ice_timesync_enable(struct rte_eth_dev *dev)
5501 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5502 struct ice_adapter *ad =
5503 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5506 if (dev->data->dev_started && !(dev->data->dev_conf.rxmode.offloads &
5507 RTE_ETH_RX_OFFLOAD_TIMESTAMP)) {
5508 PMD_DRV_LOG(ERR, "Rx timestamp offload not configured");
5512 if (hw->func_caps.ts_func_info.src_tmr_owned) {
5513 ret = ice_ptp_init_phc(hw);
5515 PMD_DRV_LOG(ERR, "Failed to initialize PHC");
5519 ret = ice_ptp_write_incval(hw, ICE_PTP_NOMINAL_INCVAL_E810);
5522 "Failed to write PHC increment time value");
5527 /* Initialize cycle counters for system time/RX/TX timestamp */
5528 memset(&ad->systime_tc, 0, sizeof(struct rte_timecounter));
5529 memset(&ad->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5530 memset(&ad->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5532 ad->systime_tc.cc_mask = ICE_CYCLECOUNTER_MASK;
5533 ad->systime_tc.cc_shift = 0;
5534 ad->systime_tc.nsec_mask = 0;
5536 ad->rx_tstamp_tc.cc_mask = ICE_CYCLECOUNTER_MASK;
5537 ad->rx_tstamp_tc.cc_shift = 0;
5538 ad->rx_tstamp_tc.nsec_mask = 0;
5540 ad->tx_tstamp_tc.cc_mask = ICE_CYCLECOUNTER_MASK;
5541 ad->tx_tstamp_tc.cc_shift = 0;
5542 ad->tx_tstamp_tc.nsec_mask = 0;
5550 ice_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5551 struct timespec *timestamp, uint32_t flags)
5553 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5554 struct ice_adapter *ad =
5555 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5556 struct ice_rx_queue *rxq;
5560 rxq = dev->data->rx_queues[flags];
5562 ts_high = rxq->time_high;
5563 ts_ns = ice_tstamp_convert_32b_64b(hw, ts_high);
5564 ns = rte_timecounter_update(&ad->rx_tstamp_tc, ts_ns);
5565 *timestamp = rte_ns_to_timespec(ns);
5571 ice_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5572 struct timespec *timestamp)
5574 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5575 struct ice_adapter *ad =
5576 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5578 uint64_t ts_ns, ns, tstamp;
5579 const uint64_t mask = 0xFFFFFFFF;
5582 lport = hw->port_info->lport;
5584 ret = ice_read_phy_tstamp(hw, lport, 0, &tstamp);
5586 PMD_DRV_LOG(ERR, "Failed to read phy timestamp");
5590 ts_ns = ice_tstamp_convert_32b_64b(hw, (tstamp >> 8) & mask);
5591 ns = rte_timecounter_update(&ad->tx_tstamp_tc, ts_ns);
5592 *timestamp = rte_ns_to_timespec(ns);
5598 ice_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
5600 struct ice_adapter *ad =
5601 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5603 ad->systime_tc.nsec += delta;
5604 ad->rx_tstamp_tc.nsec += delta;
5605 ad->tx_tstamp_tc.nsec += delta;
5611 ice_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
5613 struct ice_adapter *ad =
5614 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5617 ns = rte_timespec_to_ns(ts);
5619 ad->systime_tc.nsec = ns;
5620 ad->rx_tstamp_tc.nsec = ns;
5621 ad->tx_tstamp_tc.nsec = ns;
5627 ice_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5629 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5630 struct ice_adapter *ad =
5631 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5632 uint32_t hi, lo, lo2;
5635 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(0));
5636 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(0));
5637 lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(0));
5640 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(0));
5641 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(0));
5644 time = ((uint64_t)hi << 32) | lo;
5645 ns = rte_timecounter_update(&ad->systime_tc, time);
5646 *ts = rte_ns_to_timespec(ns);
5652 ice_timesync_disable(struct rte_eth_dev *dev)
5654 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5655 struct ice_adapter *ad =
5656 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
5660 lport = hw->port_info->lport;
5662 ice_clear_phy_tstamp(hw, lport, 0);
5664 val = ICE_READ_REG(hw, GLTSYN_ENA(0));
5665 val &= ~GLTSYN_ENA_TSYN_ENA_M;
5666 ICE_WRITE_REG(hw, GLTSYN_ENA(0), val);
5668 ICE_WRITE_REG(hw, GLTSYN_INCVAL_L(0), 0);
5669 ICE_WRITE_REG(hw, GLTSYN_INCVAL_H(0), 0);
5677 ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
5678 struct rte_pci_device *pci_dev)
5680 return rte_eth_dev_pci_generic_probe(pci_dev,
5681 sizeof(struct ice_adapter),
5686 ice_pci_remove(struct rte_pci_device *pci_dev)
5688 return rte_eth_dev_pci_generic_remove(pci_dev, ice_dev_uninit);
5691 static struct rte_pci_driver rte_ice_pmd = {
5692 .id_table = pci_id_ice_map,
5693 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
5694 .probe = ice_pci_probe,
5695 .remove = ice_pci_remove,
5699 * Driver initialization routine.
5700 * Invoked once at EAL init time.
5701 * Register itself as the [Poll Mode] Driver of PCI devices.
5703 RTE_PMD_REGISTER_PCI(net_ice, rte_ice_pmd);
5704 RTE_PMD_REGISTER_PCI_TABLE(net_ice, pci_id_ice_map);
5705 RTE_PMD_REGISTER_KMOD_DEP(net_ice, "* igb_uio | uio_pci_generic | vfio-pci");
5706 RTE_PMD_REGISTER_PARAM_STRING(net_ice,
5707 ICE_HW_DEBUG_MASK_ARG "=0xXXX"
5708 ICE_PROTO_XTR_ARG "=[queue:]<vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset>"
5709 ICE_SAFE_MODE_SUPPORT_ARG "=<0|1>"
5710 ICE_PIPELINE_MODE_SUPPORT_ARG "=<0|1>"
5711 ICE_RX_LOW_LATENCY_ARG "=<0|1>");
5713 RTE_LOG_REGISTER_SUFFIX(ice_logtype_init, init, NOTICE);
5714 RTE_LOG_REGISTER_SUFFIX(ice_logtype_driver, driver, NOTICE);
5715 #ifdef RTE_ETHDEV_DEBUG_RX
5716 RTE_LOG_REGISTER_SUFFIX(ice_logtype_rx, rx, DEBUG);
5718 #ifdef RTE_ETHDEV_DEBUG_TX
5719 RTE_LOG_REGISTER_SUFFIX(ice_logtype_tx, tx, DEBUG);