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"
22 #include "rte_pmd_ice.h"
23 #include "ice_ethdev.h"
25 #include "ice_generic_flow.h"
28 #define ICE_SAFE_MODE_SUPPORT_ARG "safe-mode-support"
29 #define ICE_PIPELINE_MODE_SUPPORT_ARG "pipeline-mode-support"
30 #define ICE_PROTO_XTR_ARG "proto_xtr"
31 #define ICE_HW_DEBUG_MASK_ARG "hw_debug_mask"
33 static const char * const ice_valid_args[] = {
34 ICE_SAFE_MODE_SUPPORT_ARG,
35 ICE_PIPELINE_MODE_SUPPORT_ARG,
37 ICE_HW_DEBUG_MASK_ARG,
41 static const struct rte_mbuf_dynfield ice_proto_xtr_metadata_param = {
42 .name = "intel_pmd_dynfield_proto_xtr_metadata",
43 .size = sizeof(uint32_t),
44 .align = __alignof__(uint32_t),
48 struct proto_xtr_ol_flag {
49 const struct rte_mbuf_dynflag param;
54 static bool ice_proto_xtr_hw_support[PROTO_XTR_MAX];
56 static struct proto_xtr_ol_flag ice_proto_xtr_ol_flag_params[] = {
58 .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
59 .ol_flag = &rte_net_ice_dynflag_proto_xtr_vlan_mask },
61 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
62 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv4_mask },
64 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
65 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_mask },
66 [PROTO_XTR_IPV6_FLOW] = {
67 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
68 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask },
70 .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
71 .ol_flag = &rte_net_ice_dynflag_proto_xtr_tcp_mask },
72 [PROTO_XTR_IP_OFFSET] = {
73 .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
74 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ip_offset_mask },
77 #define ICE_OS_DEFAULT_PKG_NAME "ICE OS Default Package"
78 #define ICE_COMMS_PKG_NAME "ICE COMMS Package"
79 #define ICE_MAX_RES_DESC_NUM 1024
81 static int ice_dev_configure(struct rte_eth_dev *dev);
82 static int ice_dev_start(struct rte_eth_dev *dev);
83 static int ice_dev_stop(struct rte_eth_dev *dev);
84 static int ice_dev_close(struct rte_eth_dev *dev);
85 static int ice_dev_reset(struct rte_eth_dev *dev);
86 static int ice_dev_info_get(struct rte_eth_dev *dev,
87 struct rte_eth_dev_info *dev_info);
88 static int ice_link_update(struct rte_eth_dev *dev,
89 int wait_to_complete);
90 static int ice_dev_set_link_up(struct rte_eth_dev *dev);
91 static int ice_dev_set_link_down(struct rte_eth_dev *dev);
93 static int ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
94 static int ice_vlan_offload_set(struct rte_eth_dev *dev, int mask);
95 static int ice_rss_reta_update(struct rte_eth_dev *dev,
96 struct rte_eth_rss_reta_entry64 *reta_conf,
98 static int ice_rss_reta_query(struct rte_eth_dev *dev,
99 struct rte_eth_rss_reta_entry64 *reta_conf,
101 static int ice_rss_hash_update(struct rte_eth_dev *dev,
102 struct rte_eth_rss_conf *rss_conf);
103 static int ice_rss_hash_conf_get(struct rte_eth_dev *dev,
104 struct rte_eth_rss_conf *rss_conf);
105 static int ice_promisc_enable(struct rte_eth_dev *dev);
106 static int ice_promisc_disable(struct rte_eth_dev *dev);
107 static int ice_allmulti_enable(struct rte_eth_dev *dev);
108 static int ice_allmulti_disable(struct rte_eth_dev *dev);
109 static int ice_vlan_filter_set(struct rte_eth_dev *dev,
112 static int ice_macaddr_set(struct rte_eth_dev *dev,
113 struct rte_ether_addr *mac_addr);
114 static int ice_macaddr_add(struct rte_eth_dev *dev,
115 struct rte_ether_addr *mac_addr,
116 __rte_unused uint32_t index,
118 static void ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
119 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
121 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
123 static int ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
125 static int ice_vlan_pvid_set(struct rte_eth_dev *dev,
126 uint16_t pvid, int on);
127 static int ice_get_eeprom_length(struct rte_eth_dev *dev);
128 static int ice_get_eeprom(struct rte_eth_dev *dev,
129 struct rte_dev_eeprom_info *eeprom);
130 static int ice_stats_get(struct rte_eth_dev *dev,
131 struct rte_eth_stats *stats);
132 static int ice_stats_reset(struct rte_eth_dev *dev);
133 static int ice_xstats_get(struct rte_eth_dev *dev,
134 struct rte_eth_xstat *xstats, unsigned int n);
135 static int ice_xstats_get_names(struct rte_eth_dev *dev,
136 struct rte_eth_xstat_name *xstats_names,
138 static int ice_dev_flow_ops_get(struct rte_eth_dev *dev,
139 const struct rte_flow_ops **ops);
140 static int ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
141 struct rte_eth_udp_tunnel *udp_tunnel);
142 static int ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
143 struct rte_eth_udp_tunnel *udp_tunnel);
145 static const struct rte_pci_id pci_id_ice_map[] = {
146 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_BACKPLANE) },
147 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_SFP) },
148 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_10G_BASE_T) },
149 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_1GBE) },
150 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_QSFP) },
151 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) },
152 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_QSFP) },
153 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_SFP) },
154 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_BACKPLANE) },
155 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_QSFP) },
156 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_SFP) },
157 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_BACKPLANE) },
158 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_QSFP) },
159 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SFP) },
160 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_10G_BASE_T) },
161 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SGMII) },
162 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_BACKPLANE) },
163 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_QSFP) },
164 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SFP) },
165 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_10G_BASE_T) },
166 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SGMII) },
167 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_BACKPLANE) },
168 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SFP) },
169 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_10G_BASE_T) },
170 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SGMII) },
171 { .vendor_id = 0, /* sentinel */ },
174 static const struct eth_dev_ops ice_eth_dev_ops = {
175 .dev_configure = ice_dev_configure,
176 .dev_start = ice_dev_start,
177 .dev_stop = ice_dev_stop,
178 .dev_close = ice_dev_close,
179 .dev_reset = ice_dev_reset,
180 .dev_set_link_up = ice_dev_set_link_up,
181 .dev_set_link_down = ice_dev_set_link_down,
182 .rx_queue_start = ice_rx_queue_start,
183 .rx_queue_stop = ice_rx_queue_stop,
184 .tx_queue_start = ice_tx_queue_start,
185 .tx_queue_stop = ice_tx_queue_stop,
186 .rx_queue_setup = ice_rx_queue_setup,
187 .rx_queue_release = ice_rx_queue_release,
188 .tx_queue_setup = ice_tx_queue_setup,
189 .tx_queue_release = ice_tx_queue_release,
190 .dev_infos_get = ice_dev_info_get,
191 .dev_supported_ptypes_get = ice_dev_supported_ptypes_get,
192 .link_update = ice_link_update,
193 .mtu_set = ice_mtu_set,
194 .mac_addr_set = ice_macaddr_set,
195 .mac_addr_add = ice_macaddr_add,
196 .mac_addr_remove = ice_macaddr_remove,
197 .vlan_filter_set = ice_vlan_filter_set,
198 .vlan_offload_set = ice_vlan_offload_set,
199 .reta_update = ice_rss_reta_update,
200 .reta_query = ice_rss_reta_query,
201 .rss_hash_update = ice_rss_hash_update,
202 .rss_hash_conf_get = ice_rss_hash_conf_get,
203 .promiscuous_enable = ice_promisc_enable,
204 .promiscuous_disable = ice_promisc_disable,
205 .allmulticast_enable = ice_allmulti_enable,
206 .allmulticast_disable = ice_allmulti_disable,
207 .rx_queue_intr_enable = ice_rx_queue_intr_enable,
208 .rx_queue_intr_disable = ice_rx_queue_intr_disable,
209 .fw_version_get = ice_fw_version_get,
210 .vlan_pvid_set = ice_vlan_pvid_set,
211 .rxq_info_get = ice_rxq_info_get,
212 .txq_info_get = ice_txq_info_get,
213 .rx_burst_mode_get = ice_rx_burst_mode_get,
214 .tx_burst_mode_get = ice_tx_burst_mode_get,
215 .get_eeprom_length = ice_get_eeprom_length,
216 .get_eeprom = ice_get_eeprom,
217 .stats_get = ice_stats_get,
218 .stats_reset = ice_stats_reset,
219 .xstats_get = ice_xstats_get,
220 .xstats_get_names = ice_xstats_get_names,
221 .xstats_reset = ice_stats_reset,
222 .flow_ops_get = ice_dev_flow_ops_get,
223 .udp_tunnel_port_add = ice_dev_udp_tunnel_port_add,
224 .udp_tunnel_port_del = ice_dev_udp_tunnel_port_del,
225 .tx_done_cleanup = ice_tx_done_cleanup,
226 .get_monitor_addr = ice_get_monitor_addr,
229 /* store statistics names and its offset in stats structure */
230 struct ice_xstats_name_off {
231 char name[RTE_ETH_XSTATS_NAME_SIZE];
235 static const struct ice_xstats_name_off ice_stats_strings[] = {
236 {"rx_unicast_packets", offsetof(struct ice_eth_stats, rx_unicast)},
237 {"rx_multicast_packets", offsetof(struct ice_eth_stats, rx_multicast)},
238 {"rx_broadcast_packets", offsetof(struct ice_eth_stats, rx_broadcast)},
239 {"rx_dropped_packets", offsetof(struct ice_eth_stats, rx_discards)},
240 {"rx_unknown_protocol_packets", offsetof(struct ice_eth_stats,
241 rx_unknown_protocol)},
242 {"tx_unicast_packets", offsetof(struct ice_eth_stats, tx_unicast)},
243 {"tx_multicast_packets", offsetof(struct ice_eth_stats, tx_multicast)},
244 {"tx_broadcast_packets", offsetof(struct ice_eth_stats, tx_broadcast)},
245 {"tx_dropped_packets", offsetof(struct ice_eth_stats, tx_discards)},
248 #define ICE_NB_ETH_XSTATS (sizeof(ice_stats_strings) / \
249 sizeof(ice_stats_strings[0]))
251 static const struct ice_xstats_name_off ice_hw_port_strings[] = {
252 {"tx_link_down_dropped", offsetof(struct ice_hw_port_stats,
253 tx_dropped_link_down)},
254 {"rx_crc_errors", offsetof(struct ice_hw_port_stats, crc_errors)},
255 {"rx_illegal_byte_errors", offsetof(struct ice_hw_port_stats,
257 {"rx_error_bytes", offsetof(struct ice_hw_port_stats, error_bytes)},
258 {"mac_local_errors", offsetof(struct ice_hw_port_stats,
260 {"mac_remote_errors", offsetof(struct ice_hw_port_stats,
262 {"rx_len_errors", offsetof(struct ice_hw_port_stats,
264 {"tx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_tx)},
265 {"rx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_rx)},
266 {"tx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_tx)},
267 {"rx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_rx)},
268 {"rx_size_64_packets", offsetof(struct ice_hw_port_stats, rx_size_64)},
269 {"rx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
271 {"rx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
273 {"rx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
275 {"rx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
277 {"rx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
279 {"rx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
281 {"rx_undersized_errors", offsetof(struct ice_hw_port_stats,
283 {"rx_oversize_errors", offsetof(struct ice_hw_port_stats,
285 {"rx_mac_short_pkt_dropped", offsetof(struct ice_hw_port_stats,
286 mac_short_pkt_dropped)},
287 {"rx_fragmented_errors", offsetof(struct ice_hw_port_stats,
289 {"rx_jabber_errors", offsetof(struct ice_hw_port_stats, rx_jabber)},
290 {"tx_size_64_packets", offsetof(struct ice_hw_port_stats, tx_size_64)},
291 {"tx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
293 {"tx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
295 {"tx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
297 {"tx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
299 {"tx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
301 {"tx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
305 #define ICE_NB_HW_PORT_XSTATS (sizeof(ice_hw_port_strings) / \
306 sizeof(ice_hw_port_strings[0]))
309 ice_init_controlq_parameter(struct ice_hw *hw)
311 /* fields for adminq */
312 hw->adminq.num_rq_entries = ICE_ADMINQ_LEN;
313 hw->adminq.num_sq_entries = ICE_ADMINQ_LEN;
314 hw->adminq.rq_buf_size = ICE_ADMINQ_BUF_SZ;
315 hw->adminq.sq_buf_size = ICE_ADMINQ_BUF_SZ;
317 /* fields for mailboxq, DPDK used as PF host */
318 hw->mailboxq.num_rq_entries = ICE_MAILBOXQ_LEN;
319 hw->mailboxq.num_sq_entries = ICE_MAILBOXQ_LEN;
320 hw->mailboxq.rq_buf_size = ICE_MAILBOXQ_BUF_SZ;
321 hw->mailboxq.sq_buf_size = ICE_MAILBOXQ_BUF_SZ;
325 lookup_proto_xtr_type(const char *xtr_name)
329 enum proto_xtr_type type;
331 { "vlan", PROTO_XTR_VLAN },
332 { "ipv4", PROTO_XTR_IPV4 },
333 { "ipv6", PROTO_XTR_IPV6 },
334 { "ipv6_flow", PROTO_XTR_IPV6_FLOW },
335 { "tcp", PROTO_XTR_TCP },
336 { "ip_offset", PROTO_XTR_IP_OFFSET },
340 for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
341 if (strcmp(xtr_name, xtr_type_map[i].name) == 0)
342 return xtr_type_map[i].type;
349 * Parse elem, the elem could be single number/range or '(' ')' group
350 * 1) A single number elem, it's just a simple digit. e.g. 9
351 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
352 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
353 * Within group elem, '-' used for a range separator;
354 * ',' used for a single number.
357 parse_queue_set(const char *input, int xtr_type, struct ice_devargs *devargs)
359 const char *str = input;
364 while (isblank(*str))
367 if (!isdigit(*str) && *str != '(')
370 /* process single number or single range of number */
373 idx = strtoul(str, &end, 10);
374 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
377 while (isblank(*end))
383 /* process single <number>-<number> */
386 while (isblank(*end))
392 idx = strtoul(end, &end, 10);
393 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
397 while (isblank(*end))
404 for (idx = RTE_MIN(min, max);
405 idx <= RTE_MAX(min, max); idx++)
406 devargs->proto_xtr[idx] = xtr_type;
411 /* process set within bracket */
413 while (isblank(*str))
418 min = ICE_MAX_QUEUE_NUM;
420 /* go ahead to the first digit */
421 while (isblank(*str))
426 /* get the digit value */
428 idx = strtoul(str, &end, 10);
429 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
432 /* go ahead to separator '-',',' and ')' */
433 while (isblank(*end))
436 if (min == ICE_MAX_QUEUE_NUM)
438 else /* avoid continuous '-' */
440 } else if (*end == ',' || *end == ')') {
442 if (min == ICE_MAX_QUEUE_NUM)
445 for (idx = RTE_MIN(min, max);
446 idx <= RTE_MAX(min, max); idx++)
447 devargs->proto_xtr[idx] = xtr_type;
449 min = ICE_MAX_QUEUE_NUM;
455 } while (*end != ')' && *end != '\0');
461 parse_queue_proto_xtr(const char *queues, struct ice_devargs *devargs)
463 const char *queue_start;
468 while (isblank(*queues))
471 if (*queues != '[') {
472 xtr_type = lookup_proto_xtr_type(queues);
476 devargs->proto_xtr_dflt = xtr_type;
483 while (isblank(*queues))
488 queue_start = queues;
490 /* go across a complete bracket */
491 if (*queue_start == '(') {
492 queues += strcspn(queues, ")");
497 /* scan the separator ':' */
498 queues += strcspn(queues, ":");
499 if (*queues++ != ':')
501 while (isblank(*queues))
504 for (idx = 0; ; idx++) {
505 if (isblank(queues[idx]) ||
506 queues[idx] == ',' ||
507 queues[idx] == ']' ||
511 if (idx > sizeof(xtr_name) - 2)
514 xtr_name[idx] = queues[idx];
516 xtr_name[idx] = '\0';
517 xtr_type = lookup_proto_xtr_type(xtr_name);
523 while (isblank(*queues) || *queues == ',' || *queues == ']')
526 if (parse_queue_set(queue_start, xtr_type, devargs) < 0)
528 } while (*queues != '\0');
534 handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
537 struct ice_devargs *devargs = extra_args;
539 if (value == NULL || extra_args == NULL)
542 if (parse_queue_proto_xtr(value, devargs) < 0) {
544 "The protocol extraction parameter is wrong : '%s'",
553 ice_check_proto_xtr_support(struct ice_hw *hw)
555 #define FLX_REG(val, fld, idx) \
556 (((val) & GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_M) >> \
557 GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_S)
564 [PROTO_XTR_VLAN] = { ICE_RXDID_COMMS_AUX_VLAN,
566 ICE_PROT_EVLAN_O, ICE_PROT_VLAN_O},
567 [PROTO_XTR_IPV4] = { ICE_RXDID_COMMS_AUX_IPV4,
569 ICE_PROT_IPV4_OF_OR_S,
570 ICE_PROT_IPV4_OF_OR_S },
571 [PROTO_XTR_IPV6] = { ICE_RXDID_COMMS_AUX_IPV6,
573 ICE_PROT_IPV6_OF_OR_S,
574 ICE_PROT_IPV6_OF_OR_S },
575 [PROTO_XTR_IPV6_FLOW] = { ICE_RXDID_COMMS_AUX_IPV6_FLOW,
577 ICE_PROT_IPV6_OF_OR_S,
578 ICE_PROT_IPV6_OF_OR_S },
579 [PROTO_XTR_TCP] = { ICE_RXDID_COMMS_AUX_TCP,
581 ICE_PROT_TCP_IL, ICE_PROT_ID_INVAL },
582 [PROTO_XTR_IP_OFFSET] = { ICE_RXDID_COMMS_AUX_IP_OFFSET,
584 ICE_PROT_IPV4_OF_OR_S,
585 ICE_PROT_IPV6_OF_OR_S },
589 for (i = 0; i < RTE_DIM(xtr_sets); i++) {
590 uint32_t rxdid = xtr_sets[i].rxdid;
593 if (xtr_sets[i].protid_0 != ICE_PROT_ID_INVAL) {
594 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_4(rxdid));
596 if (FLX_REG(v, PROT_MDID, 4) == xtr_sets[i].protid_0 &&
597 FLX_REG(v, RXDID_OPCODE, 4) == xtr_sets[i].opcode)
598 ice_proto_xtr_hw_support[i] = true;
601 if (xtr_sets[i].protid_1 != ICE_PROT_ID_INVAL) {
602 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_5(rxdid));
604 if (FLX_REG(v, PROT_MDID, 5) == xtr_sets[i].protid_1 &&
605 FLX_REG(v, RXDID_OPCODE, 5) == xtr_sets[i].opcode)
606 ice_proto_xtr_hw_support[i] = true;
612 ice_res_pool_init(struct ice_res_pool_info *pool, uint32_t base,
615 struct pool_entry *entry;
620 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
623 "Failed to allocate memory for resource pool");
627 /* queue heap initialize */
628 pool->num_free = num;
631 LIST_INIT(&pool->alloc_list);
632 LIST_INIT(&pool->free_list);
634 /* Initialize element */
638 LIST_INSERT_HEAD(&pool->free_list, entry, next);
643 ice_res_pool_alloc(struct ice_res_pool_info *pool,
646 struct pool_entry *entry, *valid_entry;
649 PMD_INIT_LOG(ERR, "Invalid parameter");
653 if (pool->num_free < num) {
654 PMD_INIT_LOG(ERR, "No resource. ask:%u, available:%u",
655 num, pool->num_free);
660 /* Lookup in free list and find most fit one */
661 LIST_FOREACH(entry, &pool->free_list, next) {
662 if (entry->len >= num) {
664 if (entry->len == num) {
669 valid_entry->len > entry->len)
674 /* Not find one to satisfy the request, return */
676 PMD_INIT_LOG(ERR, "No valid entry found");
680 * The entry have equal queue number as requested,
681 * remove it from alloc_list.
683 if (valid_entry->len == num) {
684 LIST_REMOVE(valid_entry, next);
687 * The entry have more numbers than requested,
688 * create a new entry for alloc_list and minus its
689 * queue base and number in free_list.
691 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
694 "Failed to allocate memory for "
698 entry->base = valid_entry->base;
700 valid_entry->base += num;
701 valid_entry->len -= num;
705 /* Insert it into alloc list, not sorted */
706 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
708 pool->num_free -= valid_entry->len;
709 pool->num_alloc += valid_entry->len;
711 return valid_entry->base + pool->base;
715 ice_res_pool_destroy(struct ice_res_pool_info *pool)
717 struct pool_entry *entry, *next_entry;
722 for (entry = LIST_FIRST(&pool->alloc_list);
723 entry && (next_entry = LIST_NEXT(entry, next), 1);
724 entry = next_entry) {
725 LIST_REMOVE(entry, next);
729 for (entry = LIST_FIRST(&pool->free_list);
730 entry && (next_entry = LIST_NEXT(entry, next), 1);
731 entry = next_entry) {
732 LIST_REMOVE(entry, next);
739 LIST_INIT(&pool->alloc_list);
740 LIST_INIT(&pool->free_list);
744 ice_vsi_config_default_rss(struct ice_aqc_vsi_props *info)
746 /* Set VSI LUT selection */
747 info->q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI &
748 ICE_AQ_VSI_Q_OPT_RSS_LUT_M;
749 /* Set Hash scheme */
750 info->q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_TPLZ &
751 ICE_AQ_VSI_Q_OPT_RSS_HASH_M;
753 info->q_opt_tc = ICE_AQ_VSI_Q_OPT_TC_OVR_M;
756 static enum ice_status
757 ice_vsi_config_tc_queue_mapping(struct ice_vsi *vsi,
758 struct ice_aqc_vsi_props *info,
759 uint8_t enabled_tcmap)
761 uint16_t bsf, qp_idx;
763 /* default tc 0 now. Multi-TC supporting need to be done later.
764 * Configure TC and queue mapping parameters, for enabled TC,
765 * allocate qpnum_per_tc queues to this traffic.
767 if (enabled_tcmap != 0x01) {
768 PMD_INIT_LOG(ERR, "only TC0 is supported");
772 vsi->nb_qps = RTE_MIN(vsi->nb_qps, ICE_MAX_Q_PER_TC);
773 bsf = rte_bsf32(vsi->nb_qps);
774 /* Adjust the queue number to actual queues that can be applied */
775 vsi->nb_qps = 0x1 << bsf;
778 /* Set tc and queue mapping with VSI */
779 info->tc_mapping[0] = rte_cpu_to_le_16((qp_idx <<
780 ICE_AQ_VSI_TC_Q_OFFSET_S) |
781 (bsf << ICE_AQ_VSI_TC_Q_NUM_S));
783 /* Associate queue number with VSI */
784 info->mapping_flags |= rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
785 info->q_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
786 info->q_mapping[1] = rte_cpu_to_le_16(vsi->nb_qps);
787 info->valid_sections |=
788 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
789 /* Set the info.ingress_table and info.egress_table
790 * for UP translate table. Now just set it to 1:1 map by default
791 * -- 0b 111 110 101 100 011 010 001 000 == 0xFAC688
793 #define ICE_TC_QUEUE_TABLE_DFLT 0x00FAC688
794 info->ingress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
795 info->egress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
796 info->outer_up_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
801 ice_init_mac_address(struct rte_eth_dev *dev)
803 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
805 if (!rte_is_unicast_ether_addr
806 ((struct rte_ether_addr *)hw->port_info[0].mac.lan_addr)) {
807 PMD_INIT_LOG(ERR, "Invalid MAC address");
812 (struct rte_ether_addr *)hw->port_info[0].mac.lan_addr,
813 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr);
815 dev->data->mac_addrs =
816 rte_zmalloc(NULL, sizeof(struct rte_ether_addr) * ICE_NUM_MACADDR_MAX, 0);
817 if (!dev->data->mac_addrs) {
819 "Failed to allocate memory to store mac address");
822 /* store it to dev data */
824 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr,
825 &dev->data->mac_addrs[0]);
829 /* Find out specific MAC filter */
830 static struct ice_mac_filter *
831 ice_find_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *macaddr)
833 struct ice_mac_filter *f;
835 TAILQ_FOREACH(f, &vsi->mac_list, next) {
836 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
844 ice_add_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
846 struct ice_fltr_list_entry *m_list_itr = NULL;
847 struct ice_mac_filter *f;
848 struct LIST_HEAD_TYPE list_head;
849 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
852 /* If it's added and configured, return */
853 f = ice_find_mac_filter(vsi, mac_addr);
855 PMD_DRV_LOG(INFO, "This MAC filter already exists.");
859 INIT_LIST_HEAD(&list_head);
861 m_list_itr = (struct ice_fltr_list_entry *)
862 ice_malloc(hw, sizeof(*m_list_itr));
867 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
868 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
869 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
870 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
871 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
872 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
873 m_list_itr->fltr_info.vsi_handle = vsi->idx;
875 LIST_ADD(&m_list_itr->list_entry, &list_head);
878 ret = ice_add_mac(hw, &list_head);
879 if (ret != ICE_SUCCESS) {
880 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
884 /* Add the mac addr into mac list */
885 f = rte_zmalloc(NULL, sizeof(*f), 0);
887 PMD_DRV_LOG(ERR, "failed to allocate memory");
891 rte_ether_addr_copy(mac_addr, &f->mac_info.mac_addr);
892 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
898 rte_free(m_list_itr);
903 ice_remove_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
905 struct ice_fltr_list_entry *m_list_itr = NULL;
906 struct ice_mac_filter *f;
907 struct LIST_HEAD_TYPE list_head;
908 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
911 /* Can't find it, return an error */
912 f = ice_find_mac_filter(vsi, mac_addr);
916 INIT_LIST_HEAD(&list_head);
918 m_list_itr = (struct ice_fltr_list_entry *)
919 ice_malloc(hw, sizeof(*m_list_itr));
924 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
925 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
926 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
927 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
928 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
929 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
930 m_list_itr->fltr_info.vsi_handle = vsi->idx;
932 LIST_ADD(&m_list_itr->list_entry, &list_head);
934 /* remove the mac filter */
935 ret = ice_remove_mac(hw, &list_head);
936 if (ret != ICE_SUCCESS) {
937 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
942 /* Remove the mac addr from mac list */
943 TAILQ_REMOVE(&vsi->mac_list, f, next);
949 rte_free(m_list_itr);
953 /* Find out specific VLAN filter */
954 static struct ice_vlan_filter *
955 ice_find_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
957 struct ice_vlan_filter *f;
959 TAILQ_FOREACH(f, &vsi->vlan_list, next) {
960 if (vlan->tpid == f->vlan_info.vlan.tpid &&
961 vlan->vid == f->vlan_info.vlan.vid)
969 ice_add_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
971 struct ice_fltr_list_entry *v_list_itr = NULL;
972 struct ice_vlan_filter *f;
973 struct LIST_HEAD_TYPE list_head;
977 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
980 hw = ICE_VSI_TO_HW(vsi);
982 /* If it's added and configured, return. */
983 f = ice_find_vlan_filter(vsi, vlan);
985 PMD_DRV_LOG(INFO, "This VLAN filter already exists.");
989 if (!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on)
992 INIT_LIST_HEAD(&list_head);
994 v_list_itr = (struct ice_fltr_list_entry *)
995 ice_malloc(hw, sizeof(*v_list_itr));
1000 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1001 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1002 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1003 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1004 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1005 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1006 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1007 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1009 LIST_ADD(&v_list_itr->list_entry, &list_head);
1012 ret = ice_add_vlan(hw, &list_head);
1013 if (ret != ICE_SUCCESS) {
1014 PMD_DRV_LOG(ERR, "Failed to add VLAN filter");
1019 /* Add vlan into vlan list */
1020 f = rte_zmalloc(NULL, sizeof(*f), 0);
1022 PMD_DRV_LOG(ERR, "failed to allocate memory");
1026 f->vlan_info.vlan.tpid = vlan->tpid;
1027 f->vlan_info.vlan.vid = vlan->vid;
1028 TAILQ_INSERT_TAIL(&vsi->vlan_list, f, next);
1034 rte_free(v_list_itr);
1039 ice_remove_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1041 struct ice_fltr_list_entry *v_list_itr = NULL;
1042 struct ice_vlan_filter *f;
1043 struct LIST_HEAD_TYPE list_head;
1047 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1050 hw = ICE_VSI_TO_HW(vsi);
1052 /* Can't find it, return an error */
1053 f = ice_find_vlan_filter(vsi, vlan);
1057 INIT_LIST_HEAD(&list_head);
1059 v_list_itr = (struct ice_fltr_list_entry *)
1060 ice_malloc(hw, sizeof(*v_list_itr));
1066 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1067 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1068 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1069 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1070 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1071 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1072 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1073 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1075 LIST_ADD(&v_list_itr->list_entry, &list_head);
1077 /* remove the vlan filter */
1078 ret = ice_remove_vlan(hw, &list_head);
1079 if (ret != ICE_SUCCESS) {
1080 PMD_DRV_LOG(ERR, "Failed to remove VLAN filter");
1085 /* Remove the vlan id from vlan list */
1086 TAILQ_REMOVE(&vsi->vlan_list, f, next);
1092 rte_free(v_list_itr);
1097 ice_remove_all_mac_vlan_filters(struct ice_vsi *vsi)
1099 struct ice_mac_filter *m_f;
1100 struct ice_vlan_filter *v_f;
1104 if (!vsi || !vsi->mac_num)
1107 TAILQ_FOREACH_SAFE(m_f, &vsi->mac_list, next, temp) {
1108 ret = ice_remove_mac_filter(vsi, &m_f->mac_info.mac_addr);
1109 if (ret != ICE_SUCCESS) {
1115 if (vsi->vlan_num == 0)
1118 TAILQ_FOREACH_SAFE(v_f, &vsi->vlan_list, next, temp) {
1119 ret = ice_remove_vlan_filter(vsi, &v_f->vlan_info.vlan);
1120 if (ret != ICE_SUCCESS) {
1132 ice_pf_enable_irq0(struct ice_hw *hw)
1134 /* reset the registers */
1135 ICE_WRITE_REG(hw, PFINT_OICR_ENA, 0);
1136 ICE_READ_REG(hw, PFINT_OICR);
1139 ICE_WRITE_REG(hw, PFINT_OICR_ENA,
1140 (uint32_t)(PFINT_OICR_ENA_INT_ENA_M &
1141 (~PFINT_OICR_LINK_STAT_CHANGE_M)));
1143 ICE_WRITE_REG(hw, PFINT_OICR_CTL,
1144 (0 & PFINT_OICR_CTL_MSIX_INDX_M) |
1145 ((0 << PFINT_OICR_CTL_ITR_INDX_S) &
1146 PFINT_OICR_CTL_ITR_INDX_M) |
1147 PFINT_OICR_CTL_CAUSE_ENA_M);
1149 ICE_WRITE_REG(hw, PFINT_FW_CTL,
1150 (0 & PFINT_FW_CTL_MSIX_INDX_M) |
1151 ((0 << PFINT_FW_CTL_ITR_INDX_S) &
1152 PFINT_FW_CTL_ITR_INDX_M) |
1153 PFINT_FW_CTL_CAUSE_ENA_M);
1155 ICE_WRITE_REG(hw, PFINT_OICR_ENA, PFINT_OICR_ENA_INT_ENA_M);
1158 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
1159 GLINT_DYN_CTL_INTENA_M |
1160 GLINT_DYN_CTL_CLEARPBA_M |
1161 GLINT_DYN_CTL_ITR_INDX_M);
1168 ice_pf_disable_irq0(struct ice_hw *hw)
1170 /* Disable all interrupt types */
1171 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
1177 ice_handle_aq_msg(struct rte_eth_dev *dev)
1179 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1180 struct ice_ctl_q_info *cq = &hw->adminq;
1181 struct ice_rq_event_info event;
1182 uint16_t pending, opcode;
1185 event.buf_len = ICE_AQ_MAX_BUF_LEN;
1186 event.msg_buf = rte_zmalloc(NULL, event.buf_len, 0);
1187 if (!event.msg_buf) {
1188 PMD_DRV_LOG(ERR, "Failed to allocate mem");
1194 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1196 if (ret != ICE_SUCCESS) {
1198 "Failed to read msg from AdminQ, "
1200 hw->adminq.sq_last_status);
1203 opcode = rte_le_to_cpu_16(event.desc.opcode);
1206 case ice_aqc_opc_get_link_status:
1207 ret = ice_link_update(dev, 0);
1209 rte_eth_dev_callback_process
1210 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1213 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
1218 rte_free(event.msg_buf);
1223 * Interrupt handler triggered by NIC for handling
1224 * specific interrupt.
1227 * Pointer to interrupt handle.
1229 * The address of parameter (struct rte_eth_dev *) regsitered before.
1235 ice_interrupt_handler(void *param)
1237 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1238 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1246 uint32_t int_fw_ctl;
1249 /* Disable interrupt */
1250 ice_pf_disable_irq0(hw);
1252 /* read out interrupt causes */
1253 oicr = ICE_READ_REG(hw, PFINT_OICR);
1255 int_fw_ctl = ICE_READ_REG(hw, PFINT_FW_CTL);
1258 /* No interrupt event indicated */
1259 if (!(oicr & PFINT_OICR_INTEVENT_M)) {
1260 PMD_DRV_LOG(INFO, "No interrupt event");
1265 if (int_fw_ctl & PFINT_FW_CTL_INTEVENT_M) {
1266 PMD_DRV_LOG(INFO, "FW_CTL: link state change event");
1267 ice_handle_aq_msg(dev);
1270 if (oicr & PFINT_OICR_LINK_STAT_CHANGE_M) {
1271 PMD_DRV_LOG(INFO, "OICR: link state change event");
1272 ret = ice_link_update(dev, 0);
1274 rte_eth_dev_callback_process
1275 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1279 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1280 PMD_DRV_LOG(WARNING, "OICR: MDD event");
1281 reg = ICE_READ_REG(hw, GL_MDET_TX_PQM);
1282 if (reg & GL_MDET_TX_PQM_VALID_M) {
1283 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1284 GL_MDET_TX_PQM_PF_NUM_S;
1285 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1286 GL_MDET_TX_PQM_MAL_TYPE_S;
1287 queue = (reg & GL_MDET_TX_PQM_QNUM_M) >>
1288 GL_MDET_TX_PQM_QNUM_S;
1290 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1291 "%d by PQM on TX queue %d PF# %d",
1292 event, queue, pf_num);
1295 reg = ICE_READ_REG(hw, GL_MDET_TX_TCLAN);
1296 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1297 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1298 GL_MDET_TX_TCLAN_PF_NUM_S;
1299 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1300 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1301 queue = (reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1302 GL_MDET_TX_TCLAN_QNUM_S;
1304 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1305 "%d by TCLAN on TX queue %d PF# %d",
1306 event, queue, pf_num);
1310 /* Enable interrupt */
1311 ice_pf_enable_irq0(hw);
1312 rte_intr_ack(dev->intr_handle);
1316 ice_init_proto_xtr(struct rte_eth_dev *dev)
1318 struct ice_adapter *ad =
1319 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1320 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1321 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1322 const struct proto_xtr_ol_flag *ol_flag;
1323 bool proto_xtr_enable = false;
1327 pf->proto_xtr = rte_zmalloc(NULL, pf->lan_nb_qps, 0);
1328 if (unlikely(pf->proto_xtr == NULL)) {
1329 PMD_DRV_LOG(ERR, "No memory for setting up protocol extraction table");
1333 for (i = 0; i < pf->lan_nb_qps; i++) {
1334 pf->proto_xtr[i] = ad->devargs.proto_xtr[i] != PROTO_XTR_NONE ?
1335 ad->devargs.proto_xtr[i] :
1336 ad->devargs.proto_xtr_dflt;
1338 if (pf->proto_xtr[i] != PROTO_XTR_NONE) {
1339 uint8_t type = pf->proto_xtr[i];
1341 ice_proto_xtr_ol_flag_params[type].required = true;
1342 proto_xtr_enable = true;
1346 if (likely(!proto_xtr_enable))
1349 ice_check_proto_xtr_support(hw);
1351 offset = rte_mbuf_dynfield_register(&ice_proto_xtr_metadata_param);
1352 if (unlikely(offset == -1)) {
1354 "Protocol extraction metadata is disabled in mbuf with error %d",
1360 "Protocol extraction metadata offset in mbuf is : %d",
1362 rte_net_ice_dynfield_proto_xtr_metadata_offs = offset;
1364 for (i = 0; i < RTE_DIM(ice_proto_xtr_ol_flag_params); i++) {
1365 ol_flag = &ice_proto_xtr_ol_flag_params[i];
1367 if (!ol_flag->required)
1370 if (!ice_proto_xtr_hw_support[i]) {
1372 "Protocol extraction type %u is not supported in hardware",
1374 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1378 offset = rte_mbuf_dynflag_register(&ol_flag->param);
1379 if (unlikely(offset == -1)) {
1381 "Protocol extraction offload '%s' failed to register with error %d",
1382 ol_flag->param.name, -rte_errno);
1384 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1389 "Protocol extraction offload '%s' offset in mbuf is : %d",
1390 ol_flag->param.name, offset);
1391 *ol_flag->ol_flag = 1ULL << offset;
1395 /* Initialize SW parameters of PF */
1397 ice_pf_sw_init(struct rte_eth_dev *dev)
1399 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1400 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1403 (uint16_t)RTE_MIN(hw->func_caps.common_cap.num_txq,
1404 hw->func_caps.common_cap.num_rxq);
1406 pf->lan_nb_qps = pf->lan_nb_qp_max;
1408 ice_init_proto_xtr(dev);
1410 if (hw->func_caps.fd_fltr_guar > 0 ||
1411 hw->func_caps.fd_fltr_best_effort > 0) {
1412 pf->flags |= ICE_FLAG_FDIR;
1413 pf->fdir_nb_qps = ICE_DEFAULT_QP_NUM_FDIR;
1414 pf->lan_nb_qps = pf->lan_nb_qp_max - pf->fdir_nb_qps;
1416 pf->fdir_nb_qps = 0;
1418 pf->fdir_qp_offset = 0;
1424 ice_setup_vsi(struct ice_pf *pf, enum ice_vsi_type type)
1426 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1427 struct ice_vsi *vsi = NULL;
1428 struct ice_vsi_ctx vsi_ctx;
1430 struct rte_ether_addr broadcast = {
1431 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
1432 struct rte_ether_addr mac_addr;
1433 uint16_t max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1434 uint8_t tc_bitmap = 0x1;
1437 /* hw->num_lports = 1 in NIC mode */
1438 vsi = rte_zmalloc(NULL, sizeof(struct ice_vsi), 0);
1442 vsi->idx = pf->next_vsi_idx;
1445 vsi->adapter = ICE_PF_TO_ADAPTER(pf);
1446 vsi->max_macaddrs = ICE_NUM_MACADDR_MAX;
1447 vsi->vlan_anti_spoof_on = 0;
1448 vsi->vlan_filter_on = 1;
1449 TAILQ_INIT(&vsi->mac_list);
1450 TAILQ_INIT(&vsi->vlan_list);
1452 /* Be sync with ETH_RSS_RETA_SIZE_x maximum value definition */
1453 pf->hash_lut_size = hw->func_caps.common_cap.rss_table_size >
1454 ETH_RSS_RETA_SIZE_512 ? ETH_RSS_RETA_SIZE_512 :
1455 hw->func_caps.common_cap.rss_table_size;
1456 pf->flags |= ICE_FLAG_RSS_AQ_CAPABLE;
1458 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
1461 vsi->nb_qps = pf->lan_nb_qps;
1462 vsi->base_queue = 1;
1463 ice_vsi_config_default_rss(&vsi_ctx.info);
1464 vsi_ctx.alloc_from_pool = true;
1465 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1466 /* switch_id is queried by get_switch_config aq, which is done
1469 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1470 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1471 /* Allow all untagged or tagged packets */
1472 vsi_ctx.info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
1473 vsi_ctx.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
1474 vsi_ctx.info.q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF |
1475 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
1476 if (ice_is_dvm_ena(hw)) {
1477 vsi_ctx.info.outer_vlan_flags =
1478 (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
1479 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
1480 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M;
1481 vsi_ctx.info.outer_vlan_flags |=
1482 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
1483 ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
1484 ICE_AQ_VSI_OUTER_TAG_TYPE_M;
1488 cfg = ICE_AQ_VSI_PROP_SECURITY_VALID |
1489 ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1490 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1491 cfg = ICE_AQ_VSI_FD_ENABLE;
1492 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1493 vsi_ctx.info.max_fd_fltr_dedicated =
1494 rte_cpu_to_le_16(hw->func_caps.fd_fltr_guar);
1495 vsi_ctx.info.max_fd_fltr_shared =
1496 rte_cpu_to_le_16(hw->func_caps.fd_fltr_best_effort);
1498 /* Enable VLAN/UP trip */
1499 ret = ice_vsi_config_tc_queue_mapping(vsi,
1504 "tc queue mapping with vsi failed, "
1512 vsi->nb_qps = pf->fdir_nb_qps;
1513 vsi->base_queue = ICE_FDIR_QUEUE_ID;
1514 vsi_ctx.alloc_from_pool = true;
1515 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1517 cfg = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1518 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1519 cfg = ICE_AQ_VSI_FD_PROG_ENABLE;
1520 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1521 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1522 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1523 ret = ice_vsi_config_tc_queue_mapping(vsi,
1528 "tc queue mapping with vsi failed, "
1535 /* for other types of VSI */
1536 PMD_INIT_LOG(ERR, "other types of VSI not supported");
1540 /* VF has MSIX interrupt in VF range, don't allocate here */
1541 if (type == ICE_VSI_PF) {
1542 ret = ice_res_pool_alloc(&pf->msix_pool,
1543 RTE_MIN(vsi->nb_qps,
1544 RTE_MAX_RXTX_INTR_VEC_ID));
1546 PMD_INIT_LOG(ERR, "VSI MAIN %d get heap failed %d",
1549 vsi->msix_intr = ret;
1550 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
1551 } else if (type == ICE_VSI_CTRL) {
1552 ret = ice_res_pool_alloc(&pf->msix_pool, 1);
1554 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d",
1557 vsi->msix_intr = ret;
1563 ret = ice_add_vsi(hw, vsi->idx, &vsi_ctx, NULL);
1564 if (ret != ICE_SUCCESS) {
1565 PMD_INIT_LOG(ERR, "add vsi failed, err = %d", ret);
1568 /* store vsi information is SW structure */
1569 vsi->vsi_id = vsi_ctx.vsi_num;
1570 vsi->info = vsi_ctx.info;
1571 pf->vsis_allocated = vsi_ctx.vsis_allocd;
1572 pf->vsis_unallocated = vsi_ctx.vsis_unallocated;
1574 if (type == ICE_VSI_PF) {
1575 /* MAC configuration */
1576 rte_ether_addr_copy((struct rte_ether_addr *)
1577 hw->port_info->mac.perm_addr,
1580 rte_ether_addr_copy(&pf->dev_addr, &mac_addr);
1581 ret = ice_add_mac_filter(vsi, &mac_addr);
1582 if (ret != ICE_SUCCESS)
1583 PMD_INIT_LOG(ERR, "Failed to add dflt MAC filter");
1585 rte_ether_addr_copy(&broadcast, &mac_addr);
1586 ret = ice_add_mac_filter(vsi, &mac_addr);
1587 if (ret != ICE_SUCCESS)
1588 PMD_INIT_LOG(ERR, "Failed to add MAC filter");
1591 /* At the beginning, only TC0. */
1592 /* What we need here is the maximam number of the TX queues.
1593 * Currently vsi->nb_qps means it.
1594 * Correct it if any change.
1596 max_txqs[0] = vsi->nb_qps;
1597 ret = ice_cfg_vsi_lan(hw->port_info, vsi->idx,
1598 tc_bitmap, max_txqs);
1599 if (ret != ICE_SUCCESS)
1600 PMD_INIT_LOG(ERR, "Failed to config vsi sched");
1610 ice_send_driver_ver(struct ice_hw *hw)
1612 struct ice_driver_ver dv;
1614 /* we don't have driver version use 0 for dummy */
1618 dv.subbuild_ver = 0;
1619 strncpy((char *)dv.driver_string, "dpdk", sizeof(dv.driver_string));
1621 return ice_aq_send_driver_ver(hw, &dv, NULL);
1625 ice_pf_setup(struct ice_pf *pf)
1627 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1628 struct ice_vsi *vsi;
1631 /* Clear all stats counters */
1632 pf->offset_loaded = false;
1633 memset(&pf->stats, 0, sizeof(struct ice_hw_port_stats));
1634 memset(&pf->stats_offset, 0, sizeof(struct ice_hw_port_stats));
1635 memset(&pf->internal_stats, 0, sizeof(struct ice_eth_stats));
1636 memset(&pf->internal_stats_offset, 0, sizeof(struct ice_eth_stats));
1638 /* force guaranteed filter pool for PF */
1639 ice_alloc_fd_guar_item(hw, &unused,
1640 hw->func_caps.fd_fltr_guar);
1641 /* force shared filter pool for PF */
1642 ice_alloc_fd_shrd_item(hw, &unused,
1643 hw->func_caps.fd_fltr_best_effort);
1645 vsi = ice_setup_vsi(pf, ICE_VSI_PF);
1647 PMD_INIT_LOG(ERR, "Failed to add vsi for PF");
1656 static enum ice_pkg_type
1657 ice_load_pkg_type(struct ice_hw *hw)
1659 enum ice_pkg_type package_type;
1661 /* store the activated package type (OS default or Comms) */
1662 if (!strncmp((char *)hw->active_pkg_name, ICE_OS_DEFAULT_PKG_NAME,
1664 package_type = ICE_PKG_TYPE_OS_DEFAULT;
1665 else if (!strncmp((char *)hw->active_pkg_name, ICE_COMMS_PKG_NAME,
1667 package_type = ICE_PKG_TYPE_COMMS;
1669 package_type = ICE_PKG_TYPE_UNKNOWN;
1671 PMD_INIT_LOG(NOTICE, "Active package is: %d.%d.%d.%d, %s (%s VLAN mode)",
1672 hw->active_pkg_ver.major, hw->active_pkg_ver.minor,
1673 hw->active_pkg_ver.update, hw->active_pkg_ver.draft,
1674 hw->active_pkg_name,
1675 ice_is_dvm_ena(hw) ? "double" : "single");
1677 return package_type;
1680 int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)
1682 struct ice_hw *hw = &adapter->hw;
1683 char pkg_file[ICE_MAX_PKG_FILENAME_SIZE];
1684 char opt_ddp_filename[ICE_MAX_PKG_FILENAME_SIZE];
1692 memset(opt_ddp_filename, 0, ICE_MAX_PKG_FILENAME_SIZE);
1693 snprintf(opt_ddp_filename, ICE_MAX_PKG_FILENAME_SIZE,
1694 "ice-%016" PRIx64 ".pkg", dsn);
1695 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_UPDATES,
1696 ICE_MAX_PKG_FILENAME_SIZE);
1697 strcat(pkg_file, opt_ddp_filename);
1698 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1701 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_DEFAULT,
1702 ICE_MAX_PKG_FILENAME_SIZE);
1703 strcat(pkg_file, opt_ddp_filename);
1704 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1708 strncpy(pkg_file, ICE_PKG_FILE_UPDATES, ICE_MAX_PKG_FILENAME_SIZE);
1709 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1712 strncpy(pkg_file, ICE_PKG_FILE_DEFAULT, ICE_MAX_PKG_FILENAME_SIZE);
1713 if (rte_firmware_read(pkg_file, &buf, &bufsz) < 0) {
1714 PMD_INIT_LOG(ERR, "failed to search file path\n");
1719 PMD_INIT_LOG(DEBUG, "DDP package name: %s", pkg_file);
1721 err = ice_copy_and_init_pkg(hw, buf, bufsz);
1723 PMD_INIT_LOG(ERR, "ice_copy_and_init_hw failed: %d\n", err);
1727 /* store the loaded pkg type info */
1728 adapter->active_pkg_type = ice_load_pkg_type(hw);
1736 ice_base_queue_get(struct ice_pf *pf)
1739 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1741 reg = ICE_READ_REG(hw, PFLAN_RX_QALLOC);
1742 if (reg & PFLAN_RX_QALLOC_VALID_M) {
1743 pf->base_queue = reg & PFLAN_RX_QALLOC_FIRSTQ_M;
1745 PMD_INIT_LOG(WARNING, "Failed to get Rx base queue"
1751 parse_bool(const char *key, const char *value, void *args)
1753 int *i = (int *)args;
1757 num = strtoul(value, &end, 10);
1759 if (num != 0 && num != 1) {
1760 PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", "
1761 "value must be 0 or 1",
1771 parse_u64(const char *key, const char *value, void *args)
1773 u64 *num = (u64 *)args;
1777 tmp = strtoull(value, NULL, 16);
1779 PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64",
1789 static int ice_parse_devargs(struct rte_eth_dev *dev)
1791 struct ice_adapter *ad =
1792 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1793 struct rte_devargs *devargs = dev->device->devargs;
1794 struct rte_kvargs *kvlist;
1797 if (devargs == NULL)
1800 kvlist = rte_kvargs_parse(devargs->args, ice_valid_args);
1801 if (kvlist == NULL) {
1802 PMD_INIT_LOG(ERR, "Invalid kvargs key\n");
1806 ad->devargs.proto_xtr_dflt = PROTO_XTR_NONE;
1807 memset(ad->devargs.proto_xtr, PROTO_XTR_NONE,
1808 sizeof(ad->devargs.proto_xtr));
1810 ret = rte_kvargs_process(kvlist, ICE_PROTO_XTR_ARG,
1811 &handle_proto_xtr_arg, &ad->devargs);
1815 ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG,
1816 &parse_bool, &ad->devargs.safe_mode_support);
1820 ret = rte_kvargs_process(kvlist, ICE_PIPELINE_MODE_SUPPORT_ARG,
1821 &parse_bool, &ad->devargs.pipe_mode_support);
1825 ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG,
1826 &parse_u64, &ad->hw.debug_mask);
1831 rte_kvargs_free(kvlist);
1835 /* Forward LLDP packets to default VSI by set switch rules */
1837 ice_vsi_config_sw_lldp(struct ice_vsi *vsi, bool on)
1839 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
1840 struct ice_fltr_list_entry *s_list_itr = NULL;
1841 struct LIST_HEAD_TYPE list_head;
1844 INIT_LIST_HEAD(&list_head);
1846 s_list_itr = (struct ice_fltr_list_entry *)
1847 ice_malloc(hw, sizeof(*s_list_itr));
1850 s_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
1851 s_list_itr->fltr_info.vsi_handle = vsi->idx;
1852 s_list_itr->fltr_info.l_data.ethertype_mac.ethertype =
1853 RTE_ETHER_TYPE_LLDP;
1854 s_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1855 s_list_itr->fltr_info.flag = ICE_FLTR_RX;
1856 s_list_itr->fltr_info.src_id = ICE_SRC_ID_LPORT;
1857 LIST_ADD(&s_list_itr->list_entry, &list_head);
1859 ret = ice_add_eth_mac(hw, &list_head);
1861 ret = ice_remove_eth_mac(hw, &list_head);
1863 rte_free(s_list_itr);
1867 static enum ice_status
1868 ice_get_hw_res(struct ice_hw *hw, uint16_t res_type,
1869 uint16_t num, uint16_t desc_id,
1870 uint16_t *prof_buf, uint16_t *num_prof)
1872 struct ice_aqc_res_elem *resp_buf;
1875 bool res_shared = 1;
1876 struct ice_aq_desc aq_desc;
1877 struct ice_sq_cd *cd = NULL;
1878 struct ice_aqc_get_allocd_res_desc *cmd =
1879 &aq_desc.params.get_res_desc;
1881 buf_len = sizeof(*resp_buf) * num;
1882 resp_buf = ice_malloc(hw, buf_len);
1886 ice_fill_dflt_direct_cmd_desc(&aq_desc,
1887 ice_aqc_opc_get_allocd_res_desc);
1889 cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
1890 ICE_AQC_RES_TYPE_M) | (res_shared ?
1891 ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
1892 cmd->ops.cmd.first_desc = CPU_TO_LE16(desc_id);
1894 ret = ice_aq_send_cmd(hw, &aq_desc, resp_buf, buf_len, cd);
1896 *num_prof = LE16_TO_CPU(cmd->ops.resp.num_desc);
1900 ice_memcpy(prof_buf, resp_buf, sizeof(*resp_buf) *
1901 (*num_prof), ICE_NONDMA_TO_NONDMA);
1908 ice_cleanup_resource(struct ice_hw *hw, uint16_t res_type)
1912 uint16_t prof_buf[ICE_MAX_RES_DESC_NUM];
1913 uint16_t first_desc = 1;
1914 uint16_t num_prof = 0;
1916 ret = ice_get_hw_res(hw, res_type, ICE_MAX_RES_DESC_NUM,
1917 first_desc, prof_buf, &num_prof);
1919 PMD_INIT_LOG(ERR, "Failed to get fxp resource");
1923 for (prof_id = 0; prof_id < num_prof; prof_id++) {
1924 ret = ice_free_hw_res(hw, res_type, 1, &prof_buf[prof_id]);
1926 PMD_INIT_LOG(ERR, "Failed to free fxp resource");
1934 ice_reset_fxp_resource(struct ice_hw *hw)
1938 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID);
1940 PMD_INIT_LOG(ERR, "Failed to clearup fdir resource");
1944 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID);
1946 PMD_INIT_LOG(ERR, "Failed to clearup rss resource");
1954 ice_rss_ctx_init(struct ice_pf *pf)
1956 memset(&pf->hash_ctx, 0, sizeof(pf->hash_ctx));
1960 ice_get_supported_rxdid(struct ice_hw *hw)
1962 uint64_t supported_rxdid = 0; /* bitmap for supported RXDID */
1966 supported_rxdid |= BIT(ICE_RXDID_LEGACY_1);
1968 for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
1969 regval = ICE_READ_REG(hw, GLFLXP_RXDID_FLAGS(i, 0));
1970 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
1971 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
1972 supported_rxdid |= BIT(i);
1974 return supported_rxdid;
1978 ice_dev_init(struct rte_eth_dev *dev)
1980 struct rte_pci_device *pci_dev;
1981 struct rte_intr_handle *intr_handle;
1982 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1983 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1984 struct ice_adapter *ad =
1985 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1986 struct ice_vsi *vsi;
1988 #ifndef RTE_EXEC_ENV_WINDOWS
1990 uint32_t dsn_low, dsn_high;
1995 dev->dev_ops = &ice_eth_dev_ops;
1996 dev->rx_queue_count = ice_rx_queue_count;
1997 dev->rx_descriptor_status = ice_rx_descriptor_status;
1998 dev->tx_descriptor_status = ice_tx_descriptor_status;
1999 dev->rx_pkt_burst = ice_recv_pkts;
2000 dev->tx_pkt_burst = ice_xmit_pkts;
2001 dev->tx_pkt_prepare = ice_prep_pkts;
2003 /* for secondary processes, we don't initialise any further as primary
2004 * has already done this work.
2006 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2007 ice_set_rx_function(dev);
2008 ice_set_tx_function(dev);
2012 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2014 ice_set_default_ptype_table(dev);
2015 pci_dev = RTE_DEV_TO_PCI(dev->device);
2016 intr_handle = &pci_dev->intr_handle;
2018 pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2019 pf->dev_data = dev->data;
2020 hw->back = pf->adapter;
2021 hw->hw_addr = (uint8_t *)pci_dev->mem_resource[0].addr;
2022 hw->vendor_id = pci_dev->id.vendor_id;
2023 hw->device_id = pci_dev->id.device_id;
2024 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2025 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2026 hw->bus.device = pci_dev->addr.devid;
2027 hw->bus.func = pci_dev->addr.function;
2029 ret = ice_parse_devargs(dev);
2031 PMD_INIT_LOG(ERR, "Failed to parse devargs");
2035 ice_init_controlq_parameter(hw);
2037 ret = ice_init_hw(hw);
2039 PMD_INIT_LOG(ERR, "Failed to initialize HW");
2043 #ifndef RTE_EXEC_ENV_WINDOWS
2046 pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN);
2048 if (rte_pci_read_config(pci_dev, &dsn_low, 4, pos + 4) < 0 ||
2049 rte_pci_read_config(pci_dev, &dsn_high, 4, pos + 8) < 0) {
2050 PMD_INIT_LOG(ERR, "Failed to read pci config space\n");
2053 dsn = (uint64_t)dsn_high << 32 | dsn_low;
2056 PMD_INIT_LOG(ERR, "Failed to read device serial number\n");
2059 ret = ice_load_pkg(pf->adapter, use_dsn, dsn);
2061 ret = ice_init_hw_tbls(hw);
2063 PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d\n", ret);
2064 rte_free(hw->pkg_copy);
2069 if (ad->devargs.safe_mode_support == 0) {
2070 PMD_INIT_LOG(ERR, "Failed to load the DDP package,"
2071 "Use safe-mode-support=1 to enter Safe Mode");
2075 PMD_INIT_LOG(WARNING, "Failed to load the DDP package,"
2076 "Entering Safe Mode");
2077 ad->is_safe_mode = 1;
2081 PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
2082 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2083 hw->api_maj_ver, hw->api_min_ver);
2085 ice_pf_sw_init(dev);
2086 ret = ice_init_mac_address(dev);
2088 PMD_INIT_LOG(ERR, "Failed to initialize mac address");
2092 ret = ice_res_pool_init(&pf->msix_pool, 1,
2093 hw->func_caps.common_cap.num_msix_vectors - 1);
2095 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
2096 goto err_msix_pool_init;
2099 ret = ice_pf_setup(pf);
2101 PMD_INIT_LOG(ERR, "Failed to setup PF");
2105 ret = ice_send_driver_ver(hw);
2107 PMD_INIT_LOG(ERR, "Failed to send driver version");
2113 ret = ice_aq_stop_lldp(hw, true, false, NULL);
2114 if (ret != ICE_SUCCESS)
2115 PMD_INIT_LOG(DEBUG, "lldp has already stopped\n");
2116 ret = ice_init_dcb(hw, true);
2117 if (ret != ICE_SUCCESS)
2118 PMD_INIT_LOG(DEBUG, "Failed to init DCB\n");
2119 /* Forward LLDP packets to default VSI */
2120 ret = ice_vsi_config_sw_lldp(vsi, true);
2121 if (ret != ICE_SUCCESS)
2122 PMD_INIT_LOG(DEBUG, "Failed to cfg lldp\n");
2123 /* register callback func to eal lib */
2124 rte_intr_callback_register(intr_handle,
2125 ice_interrupt_handler, dev);
2127 ice_pf_enable_irq0(hw);
2129 /* enable uio intr after callback register */
2130 rte_intr_enable(intr_handle);
2132 /* get base queue pairs index in the device */
2133 ice_base_queue_get(pf);
2135 /* Initialize RSS context for gtpu_eh */
2136 ice_rss_ctx_init(pf);
2138 if (!ad->is_safe_mode) {
2139 ret = ice_flow_init(ad);
2141 PMD_INIT_LOG(ERR, "Failed to initialize flow");
2146 ret = ice_reset_fxp_resource(hw);
2148 PMD_INIT_LOG(ERR, "Failed to reset fxp resource");
2152 pf->supported_rxdid = ice_get_supported_rxdid(hw);
2157 ice_flow_uninit(ad);
2158 rte_intr_disable(intr_handle);
2159 ice_pf_disable_irq0(hw);
2160 rte_intr_callback_unregister(intr_handle,
2161 ice_interrupt_handler, dev);
2163 ice_res_pool_destroy(&pf->msix_pool);
2165 rte_free(dev->data->mac_addrs);
2166 dev->data->mac_addrs = NULL;
2168 rte_free(pf->proto_xtr);
2169 #ifndef RTE_EXEC_ENV_WINDOWS
2178 ice_release_vsi(struct ice_vsi *vsi)
2181 struct ice_vsi_ctx vsi_ctx;
2182 enum ice_status ret;
2188 hw = ICE_VSI_TO_HW(vsi);
2190 ice_remove_all_mac_vlan_filters(vsi);
2192 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
2194 vsi_ctx.vsi_num = vsi->vsi_id;
2195 vsi_ctx.info = vsi->info;
2196 ret = ice_free_vsi(hw, vsi->idx, &vsi_ctx, false, NULL);
2197 if (ret != ICE_SUCCESS) {
2198 PMD_INIT_LOG(ERR, "Failed to free vsi by aq, %u", vsi->vsi_id);
2202 rte_free(vsi->rss_lut);
2203 rte_free(vsi->rss_key);
2209 ice_vsi_disable_queues_intr(struct ice_vsi *vsi)
2211 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
2212 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2213 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2214 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2215 uint16_t msix_intr, i;
2217 /* disable interrupt and also clear all the exist config */
2218 for (i = 0; i < vsi->nb_qps; i++) {
2219 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
2220 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
2224 if (rte_intr_allow_others(intr_handle))
2226 for (i = 0; i < vsi->nb_msix; i++) {
2227 msix_intr = vsi->msix_intr + i;
2228 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
2229 GLINT_DYN_CTL_WB_ON_ITR_M);
2233 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
2237 ice_dev_stop(struct rte_eth_dev *dev)
2239 struct rte_eth_dev_data *data = dev->data;
2240 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2241 struct ice_vsi *main_vsi = pf->main_vsi;
2242 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2243 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2246 /* avoid stopping again */
2247 if (pf->adapter_stopped)
2250 /* stop and clear all Rx queues */
2251 for (i = 0; i < data->nb_rx_queues; i++)
2252 ice_rx_queue_stop(dev, i);
2254 /* stop and clear all Tx queues */
2255 for (i = 0; i < data->nb_tx_queues; i++)
2256 ice_tx_queue_stop(dev, i);
2258 /* disable all queue interrupts */
2259 ice_vsi_disable_queues_intr(main_vsi);
2261 if (pf->init_link_up)
2262 ice_dev_set_link_up(dev);
2264 ice_dev_set_link_down(dev);
2266 /* Clean datapath event and queue/vec mapping */
2267 rte_intr_efd_disable(intr_handle);
2268 if (intr_handle->intr_vec) {
2269 rte_free(intr_handle->intr_vec);
2270 intr_handle->intr_vec = NULL;
2273 pf->adapter_stopped = true;
2274 dev->data->dev_started = 0;
2280 ice_dev_close(struct rte_eth_dev *dev)
2282 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2283 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2284 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2285 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2286 struct ice_adapter *ad =
2287 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2290 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2293 /* Since stop will make link down, then the link event will be
2294 * triggered, disable the irq firstly to avoid the port_infoe etc
2295 * resources deallocation causing the interrupt service thread
2298 ice_pf_disable_irq0(hw);
2300 ret = ice_dev_stop(dev);
2302 if (!ad->is_safe_mode)
2303 ice_flow_uninit(ad);
2305 /* release all queue resource */
2306 ice_free_queues(dev);
2308 ice_res_pool_destroy(&pf->msix_pool);
2309 ice_release_vsi(pf->main_vsi);
2310 ice_sched_cleanup_all(hw);
2311 ice_free_hw_tbls(hw);
2312 rte_free(hw->port_info);
2313 hw->port_info = NULL;
2314 ice_shutdown_all_ctrlq(hw);
2315 rte_free(pf->proto_xtr);
2316 pf->proto_xtr = NULL;
2318 /* disable uio intr before callback unregister */
2319 rte_intr_disable(intr_handle);
2321 /* unregister callback func from eal lib */
2322 rte_intr_callback_unregister(intr_handle,
2323 ice_interrupt_handler, dev);
2329 ice_dev_uninit(struct rte_eth_dev *dev)
2337 is_hash_cfg_valid(struct ice_rss_hash_cfg *cfg)
2339 return (cfg->hash_flds != 0 && cfg->addl_hdrs != 0) ? true : false;
2343 hash_cfg_reset(struct ice_rss_hash_cfg *cfg)
2348 cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
2352 ice_hash_moveout(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2354 enum ice_status status = ICE_SUCCESS;
2355 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2356 struct ice_vsi *vsi = pf->main_vsi;
2358 if (!is_hash_cfg_valid(cfg))
2361 status = ice_rem_rss_cfg(hw, vsi->idx, cfg);
2362 if (status && status != ICE_ERR_DOES_NOT_EXIST) {
2364 "ice_rem_rss_cfg failed for VSI:%d, error:%d\n",
2373 ice_hash_moveback(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2375 enum ice_status status = ICE_SUCCESS;
2376 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2377 struct ice_vsi *vsi = pf->main_vsi;
2379 if (!is_hash_cfg_valid(cfg))
2382 status = ice_add_rss_cfg(hw, vsi->idx, cfg);
2385 "ice_add_rss_cfg failed for VSI:%d, error:%d\n",
2394 ice_hash_remove(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2398 ret = ice_hash_moveout(pf, cfg);
2399 if (ret && (ret != -ENOENT))
2402 hash_cfg_reset(cfg);
2408 ice_add_rss_cfg_pre_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2414 case ICE_HASH_GTPU_CTX_EH_IP:
2415 ret = ice_hash_remove(pf,
2416 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2417 if (ret && (ret != -ENOENT))
2420 ret = ice_hash_remove(pf,
2421 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2422 if (ret && (ret != -ENOENT))
2425 ret = ice_hash_remove(pf,
2426 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2427 if (ret && (ret != -ENOENT))
2430 ret = ice_hash_remove(pf,
2431 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2432 if (ret && (ret != -ENOENT))
2435 ret = ice_hash_remove(pf,
2436 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2437 if (ret && (ret != -ENOENT))
2440 ret = ice_hash_remove(pf,
2441 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2442 if (ret && (ret != -ENOENT))
2445 ret = ice_hash_remove(pf,
2446 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2447 if (ret && (ret != -ENOENT))
2450 ret = ice_hash_remove(pf,
2451 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2452 if (ret && (ret != -ENOENT))
2456 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2457 ret = ice_hash_remove(pf,
2458 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2459 if (ret && (ret != -ENOENT))
2462 ret = ice_hash_remove(pf,
2463 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2464 if (ret && (ret != -ENOENT))
2467 ret = ice_hash_moveout(pf,
2468 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2469 if (ret && (ret != -ENOENT))
2472 ret = ice_hash_moveout(pf,
2473 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2474 if (ret && (ret != -ENOENT))
2477 ret = ice_hash_moveout(pf,
2478 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2479 if (ret && (ret != -ENOENT))
2482 ret = ice_hash_moveout(pf,
2483 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2484 if (ret && (ret != -ENOENT))
2488 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2489 ret = ice_hash_remove(pf,
2490 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2491 if (ret && (ret != -ENOENT))
2494 ret = ice_hash_remove(pf,
2495 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2496 if (ret && (ret != -ENOENT))
2499 ret = ice_hash_moveout(pf,
2500 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2501 if (ret && (ret != -ENOENT))
2504 ret = ice_hash_moveout(pf,
2505 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2506 if (ret && (ret != -ENOENT))
2509 ret = ice_hash_moveout(pf,
2510 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2511 if (ret && (ret != -ENOENT))
2514 ret = ice_hash_moveout(pf,
2515 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2516 if (ret && (ret != -ENOENT))
2520 case ICE_HASH_GTPU_CTX_UP_IP:
2521 ret = ice_hash_remove(pf,
2522 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2523 if (ret && (ret != -ENOENT))
2526 ret = ice_hash_remove(pf,
2527 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2528 if (ret && (ret != -ENOENT))
2531 ret = ice_hash_moveout(pf,
2532 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2533 if (ret && (ret != -ENOENT))
2536 ret = ice_hash_moveout(pf,
2537 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2538 if (ret && (ret != -ENOENT))
2541 ret = ice_hash_moveout(pf,
2542 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2543 if (ret && (ret != -ENOENT))
2547 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2548 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2549 ret = ice_hash_moveout(pf,
2550 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2551 if (ret && (ret != -ENOENT))
2554 ret = ice_hash_moveout(pf,
2555 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2556 if (ret && (ret != -ENOENT))
2559 ret = ice_hash_moveout(pf,
2560 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2561 if (ret && (ret != -ENOENT))
2565 case ICE_HASH_GTPU_CTX_DW_IP:
2566 ret = ice_hash_remove(pf,
2567 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2568 if (ret && (ret != -ENOENT))
2571 ret = ice_hash_remove(pf,
2572 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2573 if (ret && (ret != -ENOENT))
2576 ret = ice_hash_moveout(pf,
2577 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2578 if (ret && (ret != -ENOENT))
2581 ret = ice_hash_moveout(pf,
2582 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2583 if (ret && (ret != -ENOENT))
2586 ret = ice_hash_moveout(pf,
2587 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2588 if (ret && (ret != -ENOENT))
2592 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2593 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2594 ret = ice_hash_moveout(pf,
2595 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2596 if (ret && (ret != -ENOENT))
2599 ret = ice_hash_moveout(pf,
2600 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2601 if (ret && (ret != -ENOENT))
2604 ret = ice_hash_moveout(pf,
2605 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2606 if (ret && (ret != -ENOENT))
2617 static u8 calc_gtpu_ctx_idx(uint32_t hdr)
2621 if (hdr & ICE_FLOW_SEG_HDR_GTPU_EH)
2623 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_UP)
2625 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_DWN)
2628 return ICE_HASH_GTPU_CTX_MAX;
2631 if (hdr & ICE_FLOW_SEG_HDR_UDP)
2633 else if (hdr & ICE_FLOW_SEG_HDR_TCP)
2636 if (hdr & (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6))
2637 return eh_idx * 3 + ip_idx;
2639 return ICE_HASH_GTPU_CTX_MAX;
2643 ice_add_rss_cfg_pre(struct ice_pf *pf, uint32_t hdr)
2645 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2647 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2648 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu4,
2650 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2651 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu6,
2658 ice_add_rss_cfg_post_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2659 u8 ctx_idx, struct ice_rss_hash_cfg *cfg)
2663 if (ctx_idx < ICE_HASH_GTPU_CTX_MAX)
2664 ctx->ctx[ctx_idx] = *cfg;
2667 case ICE_HASH_GTPU_CTX_EH_IP:
2669 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2670 ret = ice_hash_moveback(pf,
2671 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2672 if (ret && (ret != -ENOENT))
2675 ret = ice_hash_moveback(pf,
2676 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2677 if (ret && (ret != -ENOENT))
2680 ret = ice_hash_moveback(pf,
2681 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2682 if (ret && (ret != -ENOENT))
2685 ret = ice_hash_moveback(pf,
2686 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2687 if (ret && (ret != -ENOENT))
2691 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2692 ret = ice_hash_moveback(pf,
2693 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2694 if (ret && (ret != -ENOENT))
2697 ret = ice_hash_moveback(pf,
2698 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2699 if (ret && (ret != -ENOENT))
2702 ret = ice_hash_moveback(pf,
2703 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2704 if (ret && (ret != -ENOENT))
2707 ret = ice_hash_moveback(pf,
2708 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2709 if (ret && (ret != -ENOENT))
2713 case ICE_HASH_GTPU_CTX_UP_IP:
2714 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2715 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2716 case ICE_HASH_GTPU_CTX_DW_IP:
2717 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2718 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2719 ret = ice_hash_moveback(pf,
2720 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2721 if (ret && (ret != -ENOENT))
2724 ret = ice_hash_moveback(pf,
2725 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2726 if (ret && (ret != -ENOENT))
2729 ret = ice_hash_moveback(pf,
2730 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2731 if (ret && (ret != -ENOENT))
2743 ice_add_rss_cfg_post(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2745 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(cfg->addl_hdrs);
2747 if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV4)
2748 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu4,
2750 else if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV6)
2751 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu6,
2758 ice_rem_rss_cfg_post(struct ice_pf *pf, uint32_t hdr)
2760 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2762 if (gtpu_ctx_idx >= ICE_HASH_GTPU_CTX_MAX)
2765 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2766 hash_cfg_reset(&pf->hash_ctx.gtpu4.ctx[gtpu_ctx_idx]);
2767 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2768 hash_cfg_reset(&pf->hash_ctx.gtpu6.ctx[gtpu_ctx_idx]);
2772 ice_rem_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2773 struct ice_rss_hash_cfg *cfg)
2775 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2778 ret = ice_rem_rss_cfg(hw, vsi_id, cfg);
2779 if (ret && ret != ICE_ERR_DOES_NOT_EXIST)
2780 PMD_DRV_LOG(ERR, "remove rss cfg failed\n");
2782 ice_rem_rss_cfg_post(pf, cfg->addl_hdrs);
2788 ice_add_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2789 struct ice_rss_hash_cfg *cfg)
2791 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2794 ret = ice_add_rss_cfg_pre(pf, cfg->addl_hdrs);
2796 PMD_DRV_LOG(ERR, "add rss cfg pre failed\n");
2798 ret = ice_add_rss_cfg(hw, vsi_id, cfg);
2800 PMD_DRV_LOG(ERR, "add rss cfg failed\n");
2802 ret = ice_add_rss_cfg_post(pf, cfg);
2804 PMD_DRV_LOG(ERR, "add rss cfg post failed\n");
2810 ice_rss_hash_set(struct ice_pf *pf, uint64_t rss_hf)
2812 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2813 struct ice_vsi *vsi = pf->main_vsi;
2814 struct ice_rss_hash_cfg cfg;
2817 #define ICE_RSS_HF_ALL ( \
2820 ETH_RSS_NONFRAG_IPV4_UDP | \
2821 ETH_RSS_NONFRAG_IPV6_UDP | \
2822 ETH_RSS_NONFRAG_IPV4_TCP | \
2823 ETH_RSS_NONFRAG_IPV6_TCP | \
2824 ETH_RSS_NONFRAG_IPV4_SCTP | \
2825 ETH_RSS_NONFRAG_IPV6_SCTP | \
2826 ETH_RSS_FRAG_IPV4 | \
2829 ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
2831 PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
2835 cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
2836 /* Configure RSS for IPv4 with src/dst addr as input set */
2837 if (rss_hf & ETH_RSS_IPV4) {
2838 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2839 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
2840 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2842 PMD_DRV_LOG(ERR, "%s IPV4 rss flow fail %d",
2846 /* Configure RSS for IPv6 with src/dst addr as input set */
2847 if (rss_hf & ETH_RSS_IPV6) {
2848 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2849 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
2850 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2852 PMD_DRV_LOG(ERR, "%s IPV6 rss flow fail %d",
2856 /* Configure RSS for udp4 with src/dst addr and port as input set */
2857 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
2858 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4 |
2859 ICE_FLOW_SEG_HDR_IPV_OTHER;
2860 cfg.hash_flds = ICE_HASH_UDP_IPV4;
2861 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2863 PMD_DRV_LOG(ERR, "%s UDP_IPV4 rss flow fail %d",
2867 /* Configure RSS for udp6 with src/dst addr and port as input set */
2868 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) {
2869 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6 |
2870 ICE_FLOW_SEG_HDR_IPV_OTHER;
2871 cfg.hash_flds = ICE_HASH_UDP_IPV6;
2872 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2874 PMD_DRV_LOG(ERR, "%s UDP_IPV6 rss flow fail %d",
2878 /* Configure RSS for tcp4 with src/dst addr and port as input set */
2879 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
2880 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4 |
2881 ICE_FLOW_SEG_HDR_IPV_OTHER;
2882 cfg.hash_flds = ICE_HASH_TCP_IPV4;
2883 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2885 PMD_DRV_LOG(ERR, "%s TCP_IPV4 rss flow fail %d",
2889 /* Configure RSS for tcp6 with src/dst addr and port as input set */
2890 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
2891 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6 |
2892 ICE_FLOW_SEG_HDR_IPV_OTHER;
2893 cfg.hash_flds = ICE_HASH_TCP_IPV6;
2894 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2896 PMD_DRV_LOG(ERR, "%s TCP_IPV6 rss flow fail %d",
2900 /* Configure RSS for sctp4 with src/dst addr and port as input set */
2901 if (rss_hf & ETH_RSS_NONFRAG_IPV4_SCTP) {
2902 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4 |
2903 ICE_FLOW_SEG_HDR_IPV_OTHER;
2904 cfg.hash_flds = ICE_HASH_SCTP_IPV4;
2905 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2907 PMD_DRV_LOG(ERR, "%s SCTP_IPV4 rss flow fail %d",
2911 /* Configure RSS for sctp6 with src/dst addr and port as input set */
2912 if (rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) {
2913 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6 |
2914 ICE_FLOW_SEG_HDR_IPV_OTHER;
2915 cfg.hash_flds = ICE_HASH_SCTP_IPV6;
2916 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2918 PMD_DRV_LOG(ERR, "%s SCTP_IPV6 rss flow fail %d",
2922 if (rss_hf & ETH_RSS_IPV4) {
2923 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV4 |
2924 ICE_FLOW_SEG_HDR_IPV_OTHER;
2925 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
2926 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2928 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4 rss flow fail %d",
2932 if (rss_hf & ETH_RSS_IPV6) {
2933 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV6 |
2934 ICE_FLOW_SEG_HDR_IPV_OTHER;
2935 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
2936 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2938 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6 rss flow fail %d",
2942 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
2943 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
2944 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2945 cfg.hash_flds = ICE_HASH_UDP_IPV4;
2946 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2948 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_UDP rss flow fail %d",
2952 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) {
2953 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
2954 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2955 cfg.hash_flds = ICE_HASH_UDP_IPV6;
2956 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2958 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_UDP rss flow fail %d",
2962 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
2963 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
2964 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2965 cfg.hash_flds = ICE_HASH_TCP_IPV4;
2966 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2968 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_TCP rss flow fail %d",
2972 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
2973 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
2974 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2975 cfg.hash_flds = ICE_HASH_TCP_IPV6;
2976 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2978 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_TCP rss flow fail %d",
2982 if (rss_hf & ETH_RSS_FRAG_IPV4) {
2983 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_FRAG;
2984 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
2985 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2987 PMD_DRV_LOG(ERR, "%s IPV4_FRAG rss flow fail %d",
2991 if (rss_hf & ETH_RSS_FRAG_IPV6) {
2992 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_FRAG;
2993 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
2994 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2996 PMD_DRV_LOG(ERR, "%s IPV6_FRAG rss flow fail %d",
3000 pf->rss_hf = rss_hf & ICE_RSS_HF_ALL;
3004 ice_get_default_rss_key(uint8_t *rss_key, uint32_t rss_key_size)
3006 static struct ice_aqc_get_set_rss_keys default_key;
3007 static bool default_key_done;
3008 uint8_t *key = (uint8_t *)&default_key;
3011 if (rss_key_size > sizeof(default_key)) {
3012 PMD_DRV_LOG(WARNING,
3013 "requested size %u is larger than default %zu, "
3014 "only %zu bytes are gotten for key\n",
3015 rss_key_size, sizeof(default_key),
3016 sizeof(default_key));
3019 if (!default_key_done) {
3020 /* Calculate the default hash key */
3021 for (i = 0; i < sizeof(default_key); i++)
3022 key[i] = (uint8_t)rte_rand();
3023 default_key_done = true;
3025 rte_memcpy(rss_key, key, RTE_MIN(rss_key_size, sizeof(default_key)));
3028 static int ice_init_rss(struct ice_pf *pf)
3030 struct ice_hw *hw = ICE_PF_TO_HW(pf);
3031 struct ice_vsi *vsi = pf->main_vsi;
3032 struct rte_eth_dev_data *dev_data = pf->dev_data;
3033 struct ice_aq_get_set_rss_lut_params lut_params;
3034 struct rte_eth_rss_conf *rss_conf;
3035 struct ice_aqc_get_set_rss_keys key;
3038 bool is_safe_mode = pf->adapter->is_safe_mode;
3041 rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
3042 nb_q = dev_data->nb_rx_queues;
3043 vsi->rss_key_size = ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE;
3044 vsi->rss_lut_size = pf->hash_lut_size;
3047 PMD_DRV_LOG(WARNING,
3048 "RSS is not supported as rx queues number is zero\n");
3053 PMD_DRV_LOG(WARNING, "RSS is not supported in safe mode\n");
3057 if (!vsi->rss_key) {
3058 vsi->rss_key = rte_zmalloc(NULL,
3059 vsi->rss_key_size, 0);
3060 if (vsi->rss_key == NULL) {
3061 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3065 if (!vsi->rss_lut) {
3066 vsi->rss_lut = rte_zmalloc(NULL,
3067 vsi->rss_lut_size, 0);
3068 if (vsi->rss_lut == NULL) {
3069 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3070 rte_free(vsi->rss_key);
3071 vsi->rss_key = NULL;
3075 /* configure RSS key */
3076 if (!rss_conf->rss_key)
3077 ice_get_default_rss_key(vsi->rss_key, vsi->rss_key_size);
3079 rte_memcpy(vsi->rss_key, rss_conf->rss_key,
3080 RTE_MIN(rss_conf->rss_key_len,
3081 vsi->rss_key_size));
3083 rte_memcpy(key.standard_rss_key, vsi->rss_key, vsi->rss_key_size);
3084 ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
3088 /* init RSS LUT table */
3089 for (i = 0; i < vsi->rss_lut_size; i++)
3090 vsi->rss_lut[i] = i % nb_q;
3092 lut_params.vsi_handle = vsi->idx;
3093 lut_params.lut_size = vsi->rss_lut_size;
3094 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
3095 lut_params.lut = vsi->rss_lut;
3096 lut_params.global_lut_id = 0;
3097 ret = ice_aq_set_rss_lut(hw, &lut_params);
3101 /* Enable registers for symmetric_toeplitz function. */
3102 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
3103 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
3104 (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
3105 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
3107 /* RSS hash configuration */
3108 ice_rss_hash_set(pf, rss_conf->rss_hf);
3112 rte_free(vsi->rss_key);
3113 vsi->rss_key = NULL;
3114 rte_free(vsi->rss_lut);
3115 vsi->rss_lut = NULL;
3120 ice_dev_configure(struct rte_eth_dev *dev)
3122 struct ice_adapter *ad =
3123 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3124 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3127 /* Initialize to TRUE. If any of Rx queues doesn't meet the
3128 * bulk allocation or vector Rx preconditions we will reset it.
3130 ad->rx_bulk_alloc_allowed = true;
3131 ad->tx_simple_allowed = true;
3133 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
3134 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
3136 if (dev->data->nb_rx_queues) {
3137 ret = ice_init_rss(pf);
3139 PMD_DRV_LOG(ERR, "Failed to enable rss for PF");
3148 __vsi_queues_bind_intr(struct ice_vsi *vsi, uint16_t msix_vect,
3149 int base_queue, int nb_queue)
3151 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3152 uint32_t val, val_tx;
3155 for (i = 0; i < nb_queue; i++) {
3157 val = (msix_vect & QINT_RQCTL_MSIX_INDX_M) |
3158 (0 << QINT_RQCTL_ITR_INDX_S) | QINT_RQCTL_CAUSE_ENA_M;
3159 val_tx = (msix_vect & QINT_TQCTL_MSIX_INDX_M) |
3160 (0 << QINT_TQCTL_ITR_INDX_S) | QINT_TQCTL_CAUSE_ENA_M;
3162 PMD_DRV_LOG(INFO, "queue %d is binding to vect %d",
3163 base_queue + i, msix_vect);
3164 /* set ITR0 value */
3165 ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x2);
3166 ICE_WRITE_REG(hw, QINT_RQCTL(base_queue + i), val);
3167 ICE_WRITE_REG(hw, QINT_TQCTL(base_queue + i), val_tx);
3172 ice_vsi_queues_bind_intr(struct ice_vsi *vsi)
3174 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3175 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3176 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3177 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3178 uint16_t msix_vect = vsi->msix_intr;
3179 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
3180 uint16_t queue_idx = 0;
3184 /* clear Rx/Tx queue interrupt */
3185 for (i = 0; i < vsi->nb_used_qps; i++) {
3186 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
3187 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
3190 /* PF bind interrupt */
3191 if (rte_intr_dp_is_en(intr_handle)) {
3196 for (i = 0; i < vsi->nb_used_qps; i++) {
3198 if (!rte_intr_allow_others(intr_handle))
3199 msix_vect = ICE_MISC_VEC_ID;
3201 /* uio mapping all queue to one msix_vect */
3202 __vsi_queues_bind_intr(vsi, msix_vect,
3203 vsi->base_queue + i,
3204 vsi->nb_used_qps - i);
3206 for (; !!record && i < vsi->nb_used_qps; i++)
3207 intr_handle->intr_vec[queue_idx + i] =
3212 /* vfio 1:1 queue/msix_vect mapping */
3213 __vsi_queues_bind_intr(vsi, msix_vect,
3214 vsi->base_queue + i, 1);
3217 intr_handle->intr_vec[queue_idx + i] = msix_vect;
3225 ice_vsi_enable_queues_intr(struct ice_vsi *vsi)
3227 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3228 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3229 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3230 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3231 uint16_t msix_intr, i;
3233 if (rte_intr_allow_others(intr_handle))
3234 for (i = 0; i < vsi->nb_used_qps; i++) {
3235 msix_intr = vsi->msix_intr + i;
3236 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
3237 GLINT_DYN_CTL_INTENA_M |
3238 GLINT_DYN_CTL_CLEARPBA_M |
3239 GLINT_DYN_CTL_ITR_INDX_M |
3240 GLINT_DYN_CTL_WB_ON_ITR_M);
3243 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
3244 GLINT_DYN_CTL_INTENA_M |
3245 GLINT_DYN_CTL_CLEARPBA_M |
3246 GLINT_DYN_CTL_ITR_INDX_M |
3247 GLINT_DYN_CTL_WB_ON_ITR_M);
3251 ice_rxq_intr_setup(struct rte_eth_dev *dev)
3253 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3254 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3255 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3256 struct ice_vsi *vsi = pf->main_vsi;
3257 uint32_t intr_vector = 0;
3259 rte_intr_disable(intr_handle);
3261 /* check and configure queue intr-vector mapping */
3262 if ((rte_intr_cap_multiple(intr_handle) ||
3263 !RTE_ETH_DEV_SRIOV(dev).active) &&
3264 dev->data->dev_conf.intr_conf.rxq != 0) {
3265 intr_vector = dev->data->nb_rx_queues;
3266 if (intr_vector > ICE_MAX_INTR_QUEUE_NUM) {
3267 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
3268 ICE_MAX_INTR_QUEUE_NUM);
3271 if (rte_intr_efd_enable(intr_handle, intr_vector))
3275 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3276 intr_handle->intr_vec =
3277 rte_zmalloc(NULL, dev->data->nb_rx_queues * sizeof(int),
3279 if (!intr_handle->intr_vec) {
3281 "Failed to allocate %d rx_queues intr_vec",
3282 dev->data->nb_rx_queues);
3287 /* Map queues with MSIX interrupt */
3288 vsi->nb_used_qps = dev->data->nb_rx_queues;
3289 ice_vsi_queues_bind_intr(vsi);
3291 /* Enable interrupts for all the queues */
3292 ice_vsi_enable_queues_intr(vsi);
3294 rte_intr_enable(intr_handle);
3300 ice_get_init_link_status(struct rte_eth_dev *dev)
3302 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3303 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3304 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3305 struct ice_link_status link_status;
3308 ret = ice_aq_get_link_info(hw->port_info, enable_lse,
3309 &link_status, NULL);
3310 if (ret != ICE_SUCCESS) {
3311 PMD_DRV_LOG(ERR, "Failed to get link info");
3312 pf->init_link_up = false;
3316 if (link_status.link_info & ICE_AQ_LINK_UP)
3317 pf->init_link_up = true;
3321 ice_dev_start(struct rte_eth_dev *dev)
3323 struct rte_eth_dev_data *data = dev->data;
3324 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3325 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3326 struct ice_vsi *vsi = pf->main_vsi;
3327 uint16_t nb_rxq = 0;
3329 uint16_t max_frame_size;
3332 /* program Tx queues' context in hardware */
3333 for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
3334 ret = ice_tx_queue_start(dev, nb_txq);
3336 PMD_DRV_LOG(ERR, "fail to start Tx queue %u", nb_txq);
3341 /* program Rx queues' context in hardware*/
3342 for (nb_rxq = 0; nb_rxq < data->nb_rx_queues; nb_rxq++) {
3343 ret = ice_rx_queue_start(dev, nb_rxq);
3345 PMD_DRV_LOG(ERR, "fail to start Rx queue %u", nb_rxq);
3350 ice_set_rx_function(dev);
3351 ice_set_tx_function(dev);
3353 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
3354 ETH_VLAN_EXTEND_MASK;
3355 ret = ice_vlan_offload_set(dev, mask);
3357 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
3361 /* enable Rx interrput and mapping Rx queue to interrupt vector */
3362 if (ice_rxq_intr_setup(dev))
3365 /* Enable receiving broadcast packets and transmitting packets */
3366 ret = ice_set_vsi_promisc(hw, vsi->idx,
3367 ICE_PROMISC_BCAST_RX | ICE_PROMISC_BCAST_TX |
3368 ICE_PROMISC_UCAST_TX | ICE_PROMISC_MCAST_TX,
3370 if (ret != ICE_SUCCESS)
3371 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
3373 ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
3374 ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
3375 ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
3376 ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS |
3377 ICE_AQ_LINK_EVENT_SIGNAL_DETECT |
3378 ICE_AQ_LINK_EVENT_AN_COMPLETED |
3379 ICE_AQ_LINK_EVENT_PORT_TX_SUSPENDED)),
3381 if (ret != ICE_SUCCESS)
3382 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
3384 ice_get_init_link_status(dev);
3386 ice_dev_set_link_up(dev);
3388 /* Call get_link_info aq commond to enable/disable LSE */
3389 ice_link_update(dev, 0);
3391 pf->adapter_stopped = false;
3393 /* Set the max frame size to default value*/
3394 max_frame_size = pf->dev_data->dev_conf.rxmode.max_rx_pkt_len ?
3395 pf->dev_data->dev_conf.rxmode.max_rx_pkt_len :
3398 /* Set the max frame size to HW*/
3399 ice_aq_set_mac_cfg(hw, max_frame_size, NULL);
3403 /* stop the started queues if failed to start all queues */
3405 for (i = 0; i < nb_rxq; i++)
3406 ice_rx_queue_stop(dev, i);
3408 for (i = 0; i < nb_txq; i++)
3409 ice_tx_queue_stop(dev, i);
3415 ice_dev_reset(struct rte_eth_dev *dev)
3419 if (dev->data->sriov.active)
3422 ret = ice_dev_uninit(dev);
3424 PMD_INIT_LOG(ERR, "failed to uninit device, status = %d", ret);
3428 ret = ice_dev_init(dev);
3430 PMD_INIT_LOG(ERR, "failed to init device, status = %d", ret);
3438 ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3440 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3441 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3442 struct ice_vsi *vsi = pf->main_vsi;
3443 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3444 bool is_safe_mode = pf->adapter->is_safe_mode;
3448 dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
3449 dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
3450 dev_info->max_rx_queues = vsi->nb_qps;
3451 dev_info->max_tx_queues = vsi->nb_qps;
3452 dev_info->max_mac_addrs = vsi->max_macaddrs;
3453 dev_info->max_vfs = pci_dev->max_vfs;
3454 dev_info->max_mtu = dev_info->max_rx_pktlen - ICE_ETH_OVERHEAD;
3455 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3457 dev_info->rx_offload_capa =
3458 DEV_RX_OFFLOAD_VLAN_STRIP |
3459 DEV_RX_OFFLOAD_JUMBO_FRAME |
3460 DEV_RX_OFFLOAD_KEEP_CRC |
3461 DEV_RX_OFFLOAD_SCATTER |
3462 DEV_RX_OFFLOAD_VLAN_FILTER;
3463 dev_info->tx_offload_capa =
3464 DEV_TX_OFFLOAD_VLAN_INSERT |
3465 DEV_TX_OFFLOAD_TCP_TSO |
3466 DEV_TX_OFFLOAD_MULTI_SEGS |
3467 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3468 dev_info->flow_type_rss_offloads = 0;
3470 if (!is_safe_mode) {
3471 dev_info->rx_offload_capa |=
3472 DEV_RX_OFFLOAD_IPV4_CKSUM |
3473 DEV_RX_OFFLOAD_UDP_CKSUM |
3474 DEV_RX_OFFLOAD_TCP_CKSUM |
3475 DEV_RX_OFFLOAD_QINQ_STRIP |
3476 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3477 DEV_RX_OFFLOAD_VLAN_EXTEND |
3478 DEV_RX_OFFLOAD_RSS_HASH;
3479 dev_info->tx_offload_capa |=
3480 DEV_TX_OFFLOAD_QINQ_INSERT |
3481 DEV_TX_OFFLOAD_IPV4_CKSUM |
3482 DEV_TX_OFFLOAD_UDP_CKSUM |
3483 DEV_TX_OFFLOAD_TCP_CKSUM |
3484 DEV_TX_OFFLOAD_SCTP_CKSUM |
3485 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3486 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
3487 dev_info->flow_type_rss_offloads |= ICE_RSS_OFFLOAD_ALL;
3490 dev_info->rx_queue_offload_capa = 0;
3491 dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3493 dev_info->reta_size = pf->hash_lut_size;
3494 dev_info->hash_key_size = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
3496 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3498 .pthresh = ICE_DEFAULT_RX_PTHRESH,
3499 .hthresh = ICE_DEFAULT_RX_HTHRESH,
3500 .wthresh = ICE_DEFAULT_RX_WTHRESH,
3502 .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
3507 dev_info->default_txconf = (struct rte_eth_txconf) {
3509 .pthresh = ICE_DEFAULT_TX_PTHRESH,
3510 .hthresh = ICE_DEFAULT_TX_HTHRESH,
3511 .wthresh = ICE_DEFAULT_TX_WTHRESH,
3513 .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
3514 .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
3518 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3519 .nb_max = ICE_MAX_RING_DESC,
3520 .nb_min = ICE_MIN_RING_DESC,
3521 .nb_align = ICE_ALIGN_RING_DESC,
3524 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3525 .nb_max = ICE_MAX_RING_DESC,
3526 .nb_min = ICE_MIN_RING_DESC,
3527 .nb_align = ICE_ALIGN_RING_DESC,
3530 dev_info->speed_capa = ETH_LINK_SPEED_10M |
3531 ETH_LINK_SPEED_100M |
3533 ETH_LINK_SPEED_2_5G |
3535 ETH_LINK_SPEED_10G |
3536 ETH_LINK_SPEED_20G |
3539 phy_type_low = hw->port_info->phy.phy_type_low;
3540 phy_type_high = hw->port_info->phy.phy_type_high;
3542 if (ICE_PHY_TYPE_SUPPORT_50G(phy_type_low))
3543 dev_info->speed_capa |= ETH_LINK_SPEED_50G;
3545 if (ICE_PHY_TYPE_SUPPORT_100G_LOW(phy_type_low) ||
3546 ICE_PHY_TYPE_SUPPORT_100G_HIGH(phy_type_high))
3547 dev_info->speed_capa |= ETH_LINK_SPEED_100G;
3549 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
3550 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
3552 dev_info->default_rxportconf.burst_size = ICE_RX_MAX_BURST;
3553 dev_info->default_txportconf.burst_size = ICE_TX_MAX_BURST;
3554 dev_info->default_rxportconf.nb_queues = 1;
3555 dev_info->default_txportconf.nb_queues = 1;
3556 dev_info->default_rxportconf.ring_size = ICE_BUF_SIZE_MIN;
3557 dev_info->default_txportconf.ring_size = ICE_BUF_SIZE_MIN;
3563 ice_atomic_read_link_status(struct rte_eth_dev *dev,
3564 struct rte_eth_link *link)
3566 struct rte_eth_link *dst = link;
3567 struct rte_eth_link *src = &dev->data->dev_link;
3569 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3570 *(uint64_t *)src) == 0)
3577 ice_atomic_write_link_status(struct rte_eth_dev *dev,
3578 struct rte_eth_link *link)
3580 struct rte_eth_link *dst = &dev->data->dev_link;
3581 struct rte_eth_link *src = link;
3583 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3584 *(uint64_t *)src) == 0)
3591 ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3593 #define CHECK_INTERVAL 100 /* 100ms */
3594 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3595 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3596 struct ice_link_status link_status;
3597 struct rte_eth_link link, old;
3599 unsigned int rep_cnt = MAX_REPEAT_TIME;
3600 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3602 memset(&link, 0, sizeof(link));
3603 memset(&old, 0, sizeof(old));
3604 memset(&link_status, 0, sizeof(link_status));
3605 ice_atomic_read_link_status(dev, &old);
3608 /* Get link status information from hardware */
3609 status = ice_aq_get_link_info(hw->port_info, enable_lse,
3610 &link_status, NULL);
3611 if (status != ICE_SUCCESS) {
3612 link.link_speed = ETH_SPEED_NUM_100M;
3613 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3614 PMD_DRV_LOG(ERR, "Failed to get link info");
3618 link.link_status = link_status.link_info & ICE_AQ_LINK_UP;
3619 if (!wait_to_complete || link.link_status)
3622 rte_delay_ms(CHECK_INTERVAL);
3623 } while (--rep_cnt);
3625 if (!link.link_status)
3628 /* Full-duplex operation at all supported speeds */
3629 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3631 /* Parse the link status */
3632 switch (link_status.link_speed) {
3633 case ICE_AQ_LINK_SPEED_10MB:
3634 link.link_speed = ETH_SPEED_NUM_10M;
3636 case ICE_AQ_LINK_SPEED_100MB:
3637 link.link_speed = ETH_SPEED_NUM_100M;
3639 case ICE_AQ_LINK_SPEED_1000MB:
3640 link.link_speed = ETH_SPEED_NUM_1G;
3642 case ICE_AQ_LINK_SPEED_2500MB:
3643 link.link_speed = ETH_SPEED_NUM_2_5G;
3645 case ICE_AQ_LINK_SPEED_5GB:
3646 link.link_speed = ETH_SPEED_NUM_5G;
3648 case ICE_AQ_LINK_SPEED_10GB:
3649 link.link_speed = ETH_SPEED_NUM_10G;
3651 case ICE_AQ_LINK_SPEED_20GB:
3652 link.link_speed = ETH_SPEED_NUM_20G;
3654 case ICE_AQ_LINK_SPEED_25GB:
3655 link.link_speed = ETH_SPEED_NUM_25G;
3657 case ICE_AQ_LINK_SPEED_40GB:
3658 link.link_speed = ETH_SPEED_NUM_40G;
3660 case ICE_AQ_LINK_SPEED_50GB:
3661 link.link_speed = ETH_SPEED_NUM_50G;
3663 case ICE_AQ_LINK_SPEED_100GB:
3664 link.link_speed = ETH_SPEED_NUM_100G;
3666 case ICE_AQ_LINK_SPEED_UNKNOWN:
3667 PMD_DRV_LOG(ERR, "Unknown link speed");
3668 link.link_speed = ETH_SPEED_NUM_UNKNOWN;
3671 PMD_DRV_LOG(ERR, "None link speed");
3672 link.link_speed = ETH_SPEED_NUM_NONE;
3676 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3677 ETH_LINK_SPEED_FIXED);
3680 ice_atomic_write_link_status(dev, &link);
3681 if (link.link_status == old.link_status)
3687 /* Force the physical link state by getting the current PHY capabilities from
3688 * hardware and setting the PHY config based on the determined capabilities. If
3689 * link changes, link event will be triggered because both the Enable Automatic
3690 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
3692 static enum ice_status
3693 ice_force_phys_link_state(struct ice_hw *hw, bool link_up)
3695 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
3696 struct ice_aqc_get_phy_caps_data *pcaps;
3697 struct ice_port_info *pi;
3698 enum ice_status status;
3700 if (!hw || !hw->port_info)
3701 return ICE_ERR_PARAM;
3705 pcaps = (struct ice_aqc_get_phy_caps_data *)
3706 ice_malloc(hw, sizeof(*pcaps));
3708 return ICE_ERR_NO_MEMORY;
3710 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
3715 /* No change in link */
3716 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
3717 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
3720 cfg.phy_type_low = pcaps->phy_type_low;
3721 cfg.phy_type_high = pcaps->phy_type_high;
3722 cfg.caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3723 cfg.low_power_ctrl_an = pcaps->low_power_ctrl_an;
3724 cfg.eee_cap = pcaps->eee_cap;
3725 cfg.eeer_value = pcaps->eeer_value;
3726 cfg.link_fec_opt = pcaps->link_fec_options;
3728 cfg.caps |= ICE_AQ_PHY_ENA_LINK;
3730 cfg.caps &= ~ICE_AQ_PHY_ENA_LINK;
3732 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
3735 ice_free(hw, pcaps);
3740 ice_dev_set_link_up(struct rte_eth_dev *dev)
3742 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3744 return ice_force_phys_link_state(hw, true);
3748 ice_dev_set_link_down(struct rte_eth_dev *dev)
3750 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3752 return ice_force_phys_link_state(hw, false);
3756 ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3758 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3759 struct rte_eth_dev_data *dev_data = pf->dev_data;
3760 uint32_t frame_size = mtu + ICE_ETH_OVERHEAD;
3762 /* check if mtu is within the allowed range */
3763 if (mtu < RTE_ETHER_MIN_MTU || frame_size > ICE_FRAME_SIZE_MAX)
3766 /* mtu setting is forbidden if port is start */
3767 if (dev_data->dev_started) {
3769 "port %d must be stopped before configuration",
3774 if (frame_size > ICE_ETH_MAX_LEN)
3775 dev_data->dev_conf.rxmode.offloads |=
3776 DEV_RX_OFFLOAD_JUMBO_FRAME;
3778 dev_data->dev_conf.rxmode.offloads &=
3779 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
3781 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3786 static int ice_macaddr_set(struct rte_eth_dev *dev,
3787 struct rte_ether_addr *mac_addr)
3789 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3790 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3791 struct ice_vsi *vsi = pf->main_vsi;
3792 struct ice_mac_filter *f;
3796 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
3797 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
3801 TAILQ_FOREACH(f, &vsi->mac_list, next) {
3802 if (rte_is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
3807 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
3811 ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr);
3812 if (ret != ICE_SUCCESS) {
3813 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
3816 ret = ice_add_mac_filter(vsi, mac_addr);
3817 if (ret != ICE_SUCCESS) {
3818 PMD_DRV_LOG(ERR, "Failed to add mac filter");
3821 rte_ether_addr_copy(mac_addr, &pf->dev_addr);
3823 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3824 ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL);
3825 if (ret != ICE_SUCCESS)
3826 PMD_DRV_LOG(ERR, "Failed to set manage mac");
3831 /* Add a MAC address, and update filters */
3833 ice_macaddr_add(struct rte_eth_dev *dev,
3834 struct rte_ether_addr *mac_addr,
3835 __rte_unused uint32_t index,
3836 __rte_unused uint32_t pool)
3838 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3839 struct ice_vsi *vsi = pf->main_vsi;
3842 ret = ice_add_mac_filter(vsi, mac_addr);
3843 if (ret != ICE_SUCCESS) {
3844 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
3851 /* Remove a MAC address, and update filters */
3853 ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
3855 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3856 struct ice_vsi *vsi = pf->main_vsi;
3857 struct rte_eth_dev_data *data = dev->data;
3858 struct rte_ether_addr *macaddr;
3861 macaddr = &data->mac_addrs[index];
3862 ret = ice_remove_mac_filter(vsi, macaddr);
3864 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
3870 ice_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3872 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3873 struct ice_vlan vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, vlan_id);
3874 struct ice_vsi *vsi = pf->main_vsi;
3877 PMD_INIT_FUNC_TRACE();
3880 * Vlan 0 is the generic filter for untagged packets
3881 * and can't be removed or added by user.
3887 ret = ice_add_vlan_filter(vsi, &vlan);
3889 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
3893 ret = ice_remove_vlan_filter(vsi, &vlan);
3895 PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
3903 /* In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are
3904 * based on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8)
3905 * doesn't matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
3906 * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
3908 * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
3909 * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
3910 * traffic in SVM, since the VLAN TPID isn't part of filtering.
3912 * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
3913 * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
3914 * part of filtering.
3917 ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
3919 struct ice_vlan vlan;
3922 vlan = ICE_VLAN(0, 0);
3923 err = ice_add_vlan_filter(vsi, &vlan);
3925 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0");
3929 /* in SVM both VLAN 0 filters are identical */
3930 if (!ice_is_dvm_ena(&vsi->adapter->hw))
3933 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
3934 err = ice_add_vlan_filter(vsi, &vlan);
3936 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0 in double VLAN mode");
3944 * Delete the VLAN 0 filters in the same manner that they were added in
3945 * ice_vsi_add_vlan_zero.
3948 ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
3950 struct ice_vlan vlan;
3953 vlan = ICE_VLAN(0, 0);
3954 err = ice_remove_vlan_filter(vsi, &vlan);
3956 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0");
3960 /* in SVM both VLAN 0 filters are identical */
3961 if (!ice_is_dvm_ena(&vsi->adapter->hw))
3964 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
3965 err = ice_remove_vlan_filter(vsi, &vlan);
3967 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0 in double VLAN mode");
3974 /* Configure vlan filter on or off */
3976 ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
3978 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3979 struct ice_vsi_ctx ctxt;
3983 sw_flags2 = ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
3986 vsi->info.sw_flags2 |= sw_flags2;
3988 vsi->info.sw_flags2 &= ~sw_flags2;
3990 vsi->info.sw_id = hw->port_info->sw_id;
3991 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
3992 ctxt.info.valid_sections =
3993 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
3994 ICE_AQ_VSI_PROP_SECURITY_VALID);
3995 ctxt.vsi_num = vsi->vsi_id;
3997 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3999 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
4000 on ? "enable" : "disable");
4003 vsi->info.valid_sections |=
4004 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
4005 ICE_AQ_VSI_PROP_SECURITY_VALID);
4008 /* consist with other drivers, allow untagged packet when vlan filter on */
4010 ret = ice_vsi_add_vlan_zero(vsi);
4012 ret = ice_vsi_del_vlan_zero(vsi);
4017 /* Manage VLAN stripping for the VSI for Rx */
4019 ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
4021 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4022 struct ice_vsi_ctx ctxt;
4023 enum ice_status status;
4026 /* do not allow modifying VLAN stripping when a port VLAN is configured
4029 if (vsi->info.port_based_inner_vlan)
4032 memset(&ctxt, 0, sizeof(ctxt));
4035 /* Strip VLAN tag from Rx packet and put it in the desc */
4036 ctxt.info.inner_vlan_flags =
4037 ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
4039 /* Disable stripping. Leave tag in packet */
4040 ctxt.info.inner_vlan_flags =
4041 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4043 /* Allow all packets untagged/tagged */
4044 ctxt.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
4046 ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4048 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4050 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan stripping",
4051 ena ? "enable" : "disable");
4054 vsi->info.inner_vlan_flags = ctxt.info.inner_vlan_flags;
4061 ice_vsi_ena_inner_stripping(struct ice_vsi *vsi)
4063 return ice_vsi_manage_vlan_stripping(vsi, true);
4067 ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
4069 return ice_vsi_manage_vlan_stripping(vsi, false);
4072 static int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi)
4074 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4075 struct ice_vsi_ctx ctxt;
4076 enum ice_status status;
4079 /* do not allow modifying VLAN stripping when a port VLAN is configured
4082 if (vsi->info.port_based_outer_vlan)
4085 memset(&ctxt, 0, sizeof(ctxt));
4087 ctxt.info.valid_sections =
4088 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4089 /* clear current outer VLAN strip settings */
4090 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4091 ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
4092 ctxt.info.outer_vlan_flags |=
4093 (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
4094 ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
4095 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
4096 ICE_AQ_VSI_OUTER_TAG_TYPE_S);
4098 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4100 PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
4103 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4110 ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
4112 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4113 struct ice_vsi_ctx ctxt;
4114 enum ice_status status;
4117 if (vsi->info.port_based_outer_vlan)
4120 memset(&ctxt, 0, sizeof(ctxt));
4122 ctxt.info.valid_sections =
4123 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4124 /* clear current outer VLAN strip settings */
4125 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4126 ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
4127 ctxt.info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
4128 ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
4130 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4132 PMD_DRV_LOG(ERR, "Update VSI failed to disable outer VLAN stripping");
4135 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4142 ice_vsi_config_vlan_stripping(struct ice_vsi *vsi, bool ena)
4144 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4147 if (ice_is_dvm_ena(hw)) {
4149 ret = ice_vsi_ena_outer_stripping(vsi);
4151 ret = ice_vsi_dis_outer_stripping(vsi);
4154 ret = ice_vsi_ena_inner_stripping(vsi);
4156 ret = ice_vsi_dis_inner_stripping(vsi);
4163 ice_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4165 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4166 struct ice_vsi *vsi = pf->main_vsi;
4167 struct rte_eth_rxmode *rxmode;
4169 rxmode = &dev->data->dev_conf.rxmode;
4170 if (mask & ETH_VLAN_FILTER_MASK) {
4171 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
4172 ice_vsi_config_vlan_filter(vsi, true);
4174 ice_vsi_config_vlan_filter(vsi, false);
4177 if (mask & ETH_VLAN_STRIP_MASK) {
4178 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4179 ice_vsi_config_vlan_stripping(vsi, true);
4181 ice_vsi_config_vlan_stripping(vsi, false);
4188 ice_get_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4190 struct ice_aq_get_set_rss_lut_params lut_params;
4191 struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
4192 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4198 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4199 lut_params.vsi_handle = vsi->idx;
4200 lut_params.lut_size = lut_size;
4201 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4202 lut_params.lut = lut;
4203 lut_params.global_lut_id = 0;
4204 ret = ice_aq_get_rss_lut(hw, &lut_params);
4206 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4210 uint64_t *lut_dw = (uint64_t *)lut;
4211 uint16_t i, lut_size_dw = lut_size / 4;
4213 for (i = 0; i < lut_size_dw; i++)
4214 lut_dw[i] = ICE_READ_REG(hw, PFQF_HLUT(i));
4221 ice_set_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4223 struct ice_aq_get_set_rss_lut_params lut_params;
4231 pf = ICE_VSI_TO_PF(vsi);
4232 hw = ICE_VSI_TO_HW(vsi);
4234 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4235 lut_params.vsi_handle = vsi->idx;
4236 lut_params.lut_size = lut_size;
4237 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4238 lut_params.lut = lut;
4239 lut_params.global_lut_id = 0;
4240 ret = ice_aq_set_rss_lut(hw, &lut_params);
4242 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
4246 uint64_t *lut_dw = (uint64_t *)lut;
4247 uint16_t i, lut_size_dw = lut_size / 4;
4249 for (i = 0; i < lut_size_dw; i++)
4250 ICE_WRITE_REG(hw, PFQF_HLUT(i), lut_dw[i]);
4259 ice_rss_reta_update(struct rte_eth_dev *dev,
4260 struct rte_eth_rss_reta_entry64 *reta_conf,
4263 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4264 uint16_t i, lut_size = pf->hash_lut_size;
4265 uint16_t idx, shift;
4269 if (reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128 &&
4270 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512 &&
4271 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) {
4273 "The size of hash lookup table configured (%d)"
4274 "doesn't match the number hardware can "
4275 "supported (128, 512, 2048)",
4280 /* It MUST use the current LUT size to get the RSS lookup table,
4281 * otherwise if will fail with -100 error code.
4283 lut = rte_zmalloc(NULL, RTE_MAX(reta_size, lut_size), 0);
4285 PMD_DRV_LOG(ERR, "No memory can be allocated");
4288 ret = ice_get_rss_lut(pf->main_vsi, lut, lut_size);
4292 for (i = 0; i < reta_size; i++) {
4293 idx = i / RTE_RETA_GROUP_SIZE;
4294 shift = i % RTE_RETA_GROUP_SIZE;
4295 if (reta_conf[idx].mask & (1ULL << shift))
4296 lut[i] = reta_conf[idx].reta[shift];
4298 ret = ice_set_rss_lut(pf->main_vsi, lut, reta_size);
4299 if (ret == 0 && lut_size != reta_size) {
4301 "The size of hash lookup table is changed from (%d) to (%d)",
4302 lut_size, reta_size);
4303 pf->hash_lut_size = reta_size;
4313 ice_rss_reta_query(struct rte_eth_dev *dev,
4314 struct rte_eth_rss_reta_entry64 *reta_conf,
4317 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4318 uint16_t i, lut_size = pf->hash_lut_size;
4319 uint16_t idx, shift;
4323 if (reta_size != lut_size) {
4325 "The size of hash lookup table configured (%d)"
4326 "doesn't match the number hardware can "
4328 reta_size, lut_size);
4332 lut = rte_zmalloc(NULL, reta_size, 0);
4334 PMD_DRV_LOG(ERR, "No memory can be allocated");
4338 ret = ice_get_rss_lut(pf->main_vsi, lut, reta_size);
4342 for (i = 0; i < reta_size; i++) {
4343 idx = i / RTE_RETA_GROUP_SIZE;
4344 shift = i % RTE_RETA_GROUP_SIZE;
4345 if (reta_conf[idx].mask & (1ULL << shift))
4346 reta_conf[idx].reta[shift] = lut[i];
4356 ice_set_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t key_len)
4358 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4361 if (!key || key_len == 0) {
4362 PMD_DRV_LOG(DEBUG, "No key to be configured");
4364 } else if (key_len != (VSIQF_HKEY_MAX_INDEX + 1) *
4366 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
4370 struct ice_aqc_get_set_rss_keys *key_dw =
4371 (struct ice_aqc_get_set_rss_keys *)key;
4373 ret = ice_aq_set_rss_key(hw, vsi->idx, key_dw);
4375 PMD_DRV_LOG(ERR, "Failed to configure RSS key via AQ");
4383 ice_get_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t *key_len)
4385 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4388 if (!key || !key_len)
4391 ret = ice_aq_get_rss_key
4393 (struct ice_aqc_get_set_rss_keys *)key);
4395 PMD_DRV_LOG(ERR, "Failed to get RSS key via AQ");
4398 *key_len = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
4404 ice_rss_hash_update(struct rte_eth_dev *dev,
4405 struct rte_eth_rss_conf *rss_conf)
4407 enum ice_status status = ICE_SUCCESS;
4408 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4409 struct ice_vsi *vsi = pf->main_vsi;
4412 status = ice_set_rss_key(vsi, rss_conf->rss_key, rss_conf->rss_key_len);
4416 if (rss_conf->rss_hf == 0) {
4421 /* RSS hash configuration */
4422 ice_rss_hash_set(pf, rss_conf->rss_hf);
4428 ice_rss_hash_conf_get(struct rte_eth_dev *dev,
4429 struct rte_eth_rss_conf *rss_conf)
4431 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4432 struct ice_vsi *vsi = pf->main_vsi;
4434 ice_get_rss_key(vsi, rss_conf->rss_key,
4435 &rss_conf->rss_key_len);
4437 rss_conf->rss_hf = pf->rss_hf;
4442 ice_promisc_enable(struct rte_eth_dev *dev)
4444 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4445 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4446 struct ice_vsi *vsi = pf->main_vsi;
4447 enum ice_status status;
4451 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4452 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4454 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4456 case ICE_ERR_ALREADY_EXISTS:
4457 PMD_DRV_LOG(DEBUG, "Promisc mode has already been enabled");
4461 PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
4469 ice_promisc_disable(struct rte_eth_dev *dev)
4471 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4472 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4473 struct ice_vsi *vsi = pf->main_vsi;
4474 enum ice_status status;
4478 if (dev->data->all_multicast == 1)
4479 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX;
4481 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4482 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4484 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4485 if (status != ICE_SUCCESS) {
4486 PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
4494 ice_allmulti_enable(struct rte_eth_dev *dev)
4496 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4497 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4498 struct ice_vsi *vsi = pf->main_vsi;
4499 enum ice_status status;
4503 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4505 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4508 case ICE_ERR_ALREADY_EXISTS:
4509 PMD_DRV_LOG(DEBUG, "Allmulti has already been enabled");
4513 PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
4521 ice_allmulti_disable(struct rte_eth_dev *dev)
4523 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4524 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4525 struct ice_vsi *vsi = pf->main_vsi;
4526 enum ice_status status;
4530 if (dev->data->promiscuous == 1)
4531 return 0; /* must remain in all_multicast mode */
4533 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4535 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4536 if (status != ICE_SUCCESS) {
4537 PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
4544 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
4547 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4548 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4549 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4553 msix_intr = intr_handle->intr_vec[queue_id];
4555 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
4556 GLINT_DYN_CTL_ITR_INDX_M;
4557 val &= ~GLINT_DYN_CTL_WB_ON_ITR_M;
4559 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), val);
4560 rte_intr_ack(&pci_dev->intr_handle);
4565 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
4568 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4569 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4570 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4573 msix_intr = intr_handle->intr_vec[queue_id];
4575 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), GLINT_DYN_CTL_WB_ON_ITR_M);
4581 ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
4583 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4588 ver = hw->flash.orom.major;
4589 patch = hw->flash.orom.patch;
4590 build = hw->flash.orom.build;
4592 ret = snprintf(fw_version, fw_size,
4593 "%x.%02x 0x%08x %d.%d.%d",
4594 hw->flash.nvm.major,
4595 hw->flash.nvm.minor,
4596 hw->flash.nvm.eetrack,
4601 /* add the size of '\0' */
4603 if (fw_size < (size_t)ret)
4610 ice_vsi_vlan_pvid_set(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
4613 struct ice_vsi_ctx ctxt;
4614 uint8_t vlan_flags = 0;
4617 if (!vsi || !info) {
4618 PMD_DRV_LOG(ERR, "invalid parameters");
4623 vsi->info.port_based_inner_vlan = info->config.pvid;
4625 * If insert pvid is enabled, only tagged pkts are
4626 * allowed to be sent out.
4628 vlan_flags = ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4629 ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4631 vsi->info.port_based_inner_vlan = 0;
4632 if (info->config.reject.tagged == 0)
4633 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTTAGGED;
4635 if (info->config.reject.untagged == 0)
4636 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4638 vsi->info.inner_vlan_flags &= ~(ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4639 ICE_AQ_VSI_INNER_VLAN_EMODE_M);
4640 vsi->info.inner_vlan_flags |= vlan_flags;
4641 memset(&ctxt, 0, sizeof(ctxt));
4642 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4643 ctxt.info.valid_sections =
4644 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4645 ctxt.vsi_num = vsi->vsi_id;
4647 hw = ICE_VSI_TO_HW(vsi);
4648 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4649 if (ret != ICE_SUCCESS) {
4651 "update VSI for VLAN insert failed, err %d",
4656 vsi->info.valid_sections |=
4657 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4663 ice_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4665 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4666 struct ice_vsi *vsi = pf->main_vsi;
4667 struct rte_eth_dev_data *data = pf->dev_data;
4668 struct ice_vsi_vlan_pvid_info info;
4671 memset(&info, 0, sizeof(info));
4674 info.config.pvid = pvid;
4676 info.config.reject.tagged =
4677 data->dev_conf.txmode.hw_vlan_reject_tagged;
4678 info.config.reject.untagged =
4679 data->dev_conf.txmode.hw_vlan_reject_untagged;
4682 ret = ice_vsi_vlan_pvid_set(vsi, &info);
4684 PMD_DRV_LOG(ERR, "Failed to set pvid.");
4692 ice_get_eeprom_length(struct rte_eth_dev *dev)
4694 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4696 return hw->flash.flash_size;
4700 ice_get_eeprom(struct rte_eth_dev *dev,
4701 struct rte_dev_eeprom_info *eeprom)
4703 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4704 enum ice_status status = ICE_SUCCESS;
4705 uint8_t *data = eeprom->data;
4707 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
4709 status = ice_acquire_nvm(hw, ICE_RES_READ);
4711 PMD_DRV_LOG(ERR, "acquire nvm failed.");
4715 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->length,
4718 ice_release_nvm(hw);
4721 PMD_DRV_LOG(ERR, "EEPROM read failed.");
4729 ice_stat_update_32(struct ice_hw *hw,
4737 new_data = (uint64_t)ICE_READ_REG(hw, reg);
4741 if (new_data >= *offset)
4742 *stat = (uint64_t)(new_data - *offset);
4744 *stat = (uint64_t)((new_data +
4745 ((uint64_t)1 << ICE_32_BIT_WIDTH))
4750 ice_stat_update_40(struct ice_hw *hw,
4759 new_data = (uint64_t)ICE_READ_REG(hw, loreg);
4760 new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
4766 if (new_data >= *offset)
4767 *stat = new_data - *offset;
4769 *stat = (uint64_t)((new_data +
4770 ((uint64_t)1 << ICE_40_BIT_WIDTH)) -
4773 *stat &= ICE_40_BIT_MASK;
4776 /* Get all the statistics of a VSI */
4778 ice_update_vsi_stats(struct ice_vsi *vsi)
4780 struct ice_eth_stats *oes = &vsi->eth_stats_offset;
4781 struct ice_eth_stats *nes = &vsi->eth_stats;
4782 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4783 int idx = rte_le_to_cpu_16(vsi->vsi_id);
4785 ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
4786 vsi->offset_loaded, &oes->rx_bytes,
4788 ice_stat_update_40(hw, GLV_UPRCH(idx), GLV_UPRCL(idx),
4789 vsi->offset_loaded, &oes->rx_unicast,
4791 ice_stat_update_40(hw, GLV_MPRCH(idx), GLV_MPRCL(idx),
4792 vsi->offset_loaded, &oes->rx_multicast,
4793 &nes->rx_multicast);
4794 ice_stat_update_40(hw, GLV_BPRCH(idx), GLV_BPRCL(idx),
4795 vsi->offset_loaded, &oes->rx_broadcast,
4796 &nes->rx_broadcast);
4797 /* enlarge the limitation when rx_bytes overflowed */
4798 if (vsi->offset_loaded) {
4799 if (ICE_RXTX_BYTES_LOW(vsi->old_rx_bytes) > nes->rx_bytes)
4800 nes->rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
4801 nes->rx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_rx_bytes);
4803 vsi->old_rx_bytes = nes->rx_bytes;
4804 /* exclude CRC bytes */
4805 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
4806 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
4808 ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
4809 &oes->rx_discards, &nes->rx_discards);
4810 /* GLV_REPC not supported */
4811 /* GLV_RMPC not supported */
4812 ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
4813 &oes->rx_unknown_protocol,
4814 &nes->rx_unknown_protocol);
4815 ice_stat_update_40(hw, GLV_GOTCH(idx), GLV_GOTCL(idx),
4816 vsi->offset_loaded, &oes->tx_bytes,
4818 ice_stat_update_40(hw, GLV_UPTCH(idx), GLV_UPTCL(idx),
4819 vsi->offset_loaded, &oes->tx_unicast,
4821 ice_stat_update_40(hw, GLV_MPTCH(idx), GLV_MPTCL(idx),
4822 vsi->offset_loaded, &oes->tx_multicast,
4823 &nes->tx_multicast);
4824 ice_stat_update_40(hw, GLV_BPTCH(idx), GLV_BPTCL(idx),
4825 vsi->offset_loaded, &oes->tx_broadcast,
4826 &nes->tx_broadcast);
4827 /* GLV_TDPC not supported */
4828 ice_stat_update_32(hw, GLV_TEPC(idx), vsi->offset_loaded,
4829 &oes->tx_errors, &nes->tx_errors);
4830 /* enlarge the limitation when tx_bytes overflowed */
4831 if (vsi->offset_loaded) {
4832 if (ICE_RXTX_BYTES_LOW(vsi->old_tx_bytes) > nes->tx_bytes)
4833 nes->tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
4834 nes->tx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_tx_bytes);
4836 vsi->old_tx_bytes = nes->tx_bytes;
4837 vsi->offset_loaded = true;
4839 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats start **************",
4841 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
4842 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
4843 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
4844 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
4845 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
4846 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
4847 nes->rx_unknown_protocol);
4848 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
4849 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
4850 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
4851 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
4852 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
4853 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
4854 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats end ****************",
4859 ice_read_stats_registers(struct ice_pf *pf, struct ice_hw *hw)
4861 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
4862 struct ice_hw_port_stats *os = &pf->stats_offset; /* old stats */
4864 /* Get statistics of struct ice_eth_stats */
4865 ice_stat_update_40(hw, GLPRT_GORCH(hw->port_info->lport),
4866 GLPRT_GORCL(hw->port_info->lport),
4867 pf->offset_loaded, &os->eth.rx_bytes,
4869 ice_stat_update_40(hw, GLPRT_UPRCH(hw->port_info->lport),
4870 GLPRT_UPRCL(hw->port_info->lport),
4871 pf->offset_loaded, &os->eth.rx_unicast,
4872 &ns->eth.rx_unicast);
4873 ice_stat_update_40(hw, GLPRT_MPRCH(hw->port_info->lport),
4874 GLPRT_MPRCL(hw->port_info->lport),
4875 pf->offset_loaded, &os->eth.rx_multicast,
4876 &ns->eth.rx_multicast);
4877 ice_stat_update_40(hw, GLPRT_BPRCH(hw->port_info->lport),
4878 GLPRT_BPRCL(hw->port_info->lport),
4879 pf->offset_loaded, &os->eth.rx_broadcast,
4880 &ns->eth.rx_broadcast);
4881 ice_stat_update_32(hw, PRTRPB_RDPC,
4882 pf->offset_loaded, &os->eth.rx_discards,
4883 &ns->eth.rx_discards);
4884 /* enlarge the limitation when rx_bytes overflowed */
4885 if (pf->offset_loaded) {
4886 if (ICE_RXTX_BYTES_LOW(pf->old_rx_bytes) > ns->eth.rx_bytes)
4887 ns->eth.rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
4888 ns->eth.rx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_rx_bytes);
4890 pf->old_rx_bytes = ns->eth.rx_bytes;
4892 /* Workaround: CRC size should not be included in byte statistics,
4893 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
4896 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
4897 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
4899 /* GLPRT_REPC not supported */
4900 /* GLPRT_RMPC not supported */
4901 ice_stat_update_32(hw, GLSWID_RUPP(hw->port_info->lport),
4903 &os->eth.rx_unknown_protocol,
4904 &ns->eth.rx_unknown_protocol);
4905 ice_stat_update_40(hw, GLPRT_GOTCH(hw->port_info->lport),
4906 GLPRT_GOTCL(hw->port_info->lport),
4907 pf->offset_loaded, &os->eth.tx_bytes,
4909 ice_stat_update_40(hw, GLPRT_UPTCH(hw->port_info->lport),
4910 GLPRT_UPTCL(hw->port_info->lport),
4911 pf->offset_loaded, &os->eth.tx_unicast,
4912 &ns->eth.tx_unicast);
4913 ice_stat_update_40(hw, GLPRT_MPTCH(hw->port_info->lport),
4914 GLPRT_MPTCL(hw->port_info->lport),
4915 pf->offset_loaded, &os->eth.tx_multicast,
4916 &ns->eth.tx_multicast);
4917 ice_stat_update_40(hw, GLPRT_BPTCH(hw->port_info->lport),
4918 GLPRT_BPTCL(hw->port_info->lport),
4919 pf->offset_loaded, &os->eth.tx_broadcast,
4920 &ns->eth.tx_broadcast);
4921 /* enlarge the limitation when tx_bytes overflowed */
4922 if (pf->offset_loaded) {
4923 if (ICE_RXTX_BYTES_LOW(pf->old_tx_bytes) > ns->eth.tx_bytes)
4924 ns->eth.tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
4925 ns->eth.tx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_tx_bytes);
4927 pf->old_tx_bytes = ns->eth.tx_bytes;
4928 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
4929 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
4931 /* GLPRT_TEPC not supported */
4933 /* additional port specific stats */
4934 ice_stat_update_32(hw, GLPRT_TDOLD(hw->port_info->lport),
4935 pf->offset_loaded, &os->tx_dropped_link_down,
4936 &ns->tx_dropped_link_down);
4937 ice_stat_update_32(hw, GLPRT_CRCERRS(hw->port_info->lport),
4938 pf->offset_loaded, &os->crc_errors,
4940 ice_stat_update_32(hw, GLPRT_ILLERRC(hw->port_info->lport),
4941 pf->offset_loaded, &os->illegal_bytes,
4942 &ns->illegal_bytes);
4943 /* GLPRT_ERRBC not supported */
4944 ice_stat_update_32(hw, GLPRT_MLFC(hw->port_info->lport),
4945 pf->offset_loaded, &os->mac_local_faults,
4946 &ns->mac_local_faults);
4947 ice_stat_update_32(hw, GLPRT_MRFC(hw->port_info->lport),
4948 pf->offset_loaded, &os->mac_remote_faults,
4949 &ns->mac_remote_faults);
4951 ice_stat_update_32(hw, GLPRT_RLEC(hw->port_info->lport),
4952 pf->offset_loaded, &os->rx_len_errors,
4953 &ns->rx_len_errors);
4955 ice_stat_update_32(hw, GLPRT_LXONRXC(hw->port_info->lport),
4956 pf->offset_loaded, &os->link_xon_rx,
4958 ice_stat_update_32(hw, GLPRT_LXOFFRXC(hw->port_info->lport),
4959 pf->offset_loaded, &os->link_xoff_rx,
4961 ice_stat_update_32(hw, GLPRT_LXONTXC(hw->port_info->lport),
4962 pf->offset_loaded, &os->link_xon_tx,
4964 ice_stat_update_32(hw, GLPRT_LXOFFTXC(hw->port_info->lport),
4965 pf->offset_loaded, &os->link_xoff_tx,
4967 ice_stat_update_40(hw, GLPRT_PRC64H(hw->port_info->lport),
4968 GLPRT_PRC64L(hw->port_info->lport),
4969 pf->offset_loaded, &os->rx_size_64,
4971 ice_stat_update_40(hw, GLPRT_PRC127H(hw->port_info->lport),
4972 GLPRT_PRC127L(hw->port_info->lport),
4973 pf->offset_loaded, &os->rx_size_127,
4975 ice_stat_update_40(hw, GLPRT_PRC255H(hw->port_info->lport),
4976 GLPRT_PRC255L(hw->port_info->lport),
4977 pf->offset_loaded, &os->rx_size_255,
4979 ice_stat_update_40(hw, GLPRT_PRC511H(hw->port_info->lport),
4980 GLPRT_PRC511L(hw->port_info->lport),
4981 pf->offset_loaded, &os->rx_size_511,
4983 ice_stat_update_40(hw, GLPRT_PRC1023H(hw->port_info->lport),
4984 GLPRT_PRC1023L(hw->port_info->lport),
4985 pf->offset_loaded, &os->rx_size_1023,
4987 ice_stat_update_40(hw, GLPRT_PRC1522H(hw->port_info->lport),
4988 GLPRT_PRC1522L(hw->port_info->lport),
4989 pf->offset_loaded, &os->rx_size_1522,
4991 ice_stat_update_40(hw, GLPRT_PRC9522H(hw->port_info->lport),
4992 GLPRT_PRC9522L(hw->port_info->lport),
4993 pf->offset_loaded, &os->rx_size_big,
4995 ice_stat_update_32(hw, GLPRT_RUC(hw->port_info->lport),
4996 pf->offset_loaded, &os->rx_undersize,
4998 ice_stat_update_32(hw, GLPRT_RFC(hw->port_info->lport),
4999 pf->offset_loaded, &os->rx_fragments,
5001 ice_stat_update_32(hw, GLPRT_ROC(hw->port_info->lport),
5002 pf->offset_loaded, &os->rx_oversize,
5004 ice_stat_update_32(hw, GLPRT_RJC(hw->port_info->lport),
5005 pf->offset_loaded, &os->rx_jabber,
5007 ice_stat_update_40(hw, GLPRT_PTC64H(hw->port_info->lport),
5008 GLPRT_PTC64L(hw->port_info->lport),
5009 pf->offset_loaded, &os->tx_size_64,
5011 ice_stat_update_40(hw, GLPRT_PTC127H(hw->port_info->lport),
5012 GLPRT_PTC127L(hw->port_info->lport),
5013 pf->offset_loaded, &os->tx_size_127,
5015 ice_stat_update_40(hw, GLPRT_PTC255H(hw->port_info->lport),
5016 GLPRT_PTC255L(hw->port_info->lport),
5017 pf->offset_loaded, &os->tx_size_255,
5019 ice_stat_update_40(hw, GLPRT_PTC511H(hw->port_info->lport),
5020 GLPRT_PTC511L(hw->port_info->lport),
5021 pf->offset_loaded, &os->tx_size_511,
5023 ice_stat_update_40(hw, GLPRT_PTC1023H(hw->port_info->lport),
5024 GLPRT_PTC1023L(hw->port_info->lport),
5025 pf->offset_loaded, &os->tx_size_1023,
5027 ice_stat_update_40(hw, GLPRT_PTC1522H(hw->port_info->lport),
5028 GLPRT_PTC1522L(hw->port_info->lport),
5029 pf->offset_loaded, &os->tx_size_1522,
5031 ice_stat_update_40(hw, GLPRT_PTC9522H(hw->port_info->lport),
5032 GLPRT_PTC9522L(hw->port_info->lport),
5033 pf->offset_loaded, &os->tx_size_big,
5036 /* GLPRT_MSPDC not supported */
5037 /* GLPRT_XEC not supported */
5039 pf->offset_loaded = true;
5042 ice_update_vsi_stats(pf->main_vsi);
5045 /* Get all statistics of a port */
5047 ice_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
5049 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5050 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5051 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
5053 /* call read registers - updates values, now write them to struct */
5054 ice_read_stats_registers(pf, hw);
5056 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
5057 pf->main_vsi->eth_stats.rx_multicast +
5058 pf->main_vsi->eth_stats.rx_broadcast -
5059 pf->main_vsi->eth_stats.rx_discards;
5060 stats->opackets = ns->eth.tx_unicast +
5061 ns->eth.tx_multicast +
5062 ns->eth.tx_broadcast;
5063 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
5064 stats->obytes = ns->eth.tx_bytes;
5065 stats->oerrors = ns->eth.tx_errors +
5066 pf->main_vsi->eth_stats.tx_errors;
5069 stats->imissed = ns->eth.rx_discards +
5070 pf->main_vsi->eth_stats.rx_discards;
5071 stats->ierrors = ns->crc_errors +
5073 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
5075 PMD_DRV_LOG(DEBUG, "*************** PF stats start *****************");
5076 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
5077 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
5078 PMD_DRV_LOG(DEBUG, "rx_multicast:%"PRIu64"", ns->eth.rx_multicast);
5079 PMD_DRV_LOG(DEBUG, "rx_broadcast:%"PRIu64"", ns->eth.rx_broadcast);
5080 PMD_DRV_LOG(DEBUG, "rx_discards:%"PRIu64"", ns->eth.rx_discards);
5081 PMD_DRV_LOG(DEBUG, "vsi rx_discards:%"PRIu64"",
5082 pf->main_vsi->eth_stats.rx_discards);
5083 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
5084 ns->eth.rx_unknown_protocol);
5085 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
5086 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
5087 PMD_DRV_LOG(DEBUG, "tx_multicast:%"PRIu64"", ns->eth.tx_multicast);
5088 PMD_DRV_LOG(DEBUG, "tx_broadcast:%"PRIu64"", ns->eth.tx_broadcast);
5089 PMD_DRV_LOG(DEBUG, "tx_discards:%"PRIu64"", ns->eth.tx_discards);
5090 PMD_DRV_LOG(DEBUG, "vsi tx_discards:%"PRIu64"",
5091 pf->main_vsi->eth_stats.tx_discards);
5092 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
5094 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
5095 ns->tx_dropped_link_down);
5096 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
5097 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
5099 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
5100 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
5101 ns->mac_local_faults);
5102 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
5103 ns->mac_remote_faults);
5104 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
5105 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
5106 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
5107 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
5108 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
5109 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
5110 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
5111 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
5112 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
5113 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
5114 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
5115 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
5116 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
5117 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
5118 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
5119 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
5120 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
5121 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
5122 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
5123 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
5124 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
5125 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
5126 PMD_DRV_LOG(DEBUG, "rx_len_errors: %"PRIu64"", ns->rx_len_errors);
5127 PMD_DRV_LOG(DEBUG, "************* PF stats end ****************");
5131 /* Reset the statistics */
5133 ice_stats_reset(struct rte_eth_dev *dev)
5135 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5136 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5138 /* Mark PF and VSI stats to update the offset, aka "reset" */
5139 pf->offset_loaded = false;
5141 pf->main_vsi->offset_loaded = false;
5143 /* read the stats, reading current register values into offset */
5144 ice_read_stats_registers(pf, hw);
5150 ice_xstats_calc_num(void)
5154 num = ICE_NB_ETH_XSTATS + ICE_NB_HW_PORT_XSTATS;
5160 ice_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
5163 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5164 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5167 struct ice_hw_port_stats *hw_stats = &pf->stats;
5169 count = ice_xstats_calc_num();
5173 ice_read_stats_registers(pf, hw);
5180 /* Get stats from ice_eth_stats struct */
5181 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5182 xstats[count].value =
5183 *(uint64_t *)((char *)&hw_stats->eth +
5184 ice_stats_strings[i].offset);
5185 xstats[count].id = count;
5189 /* Get individiual stats from ice_hw_port struct */
5190 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5191 xstats[count].value =
5192 *(uint64_t *)((char *)hw_stats +
5193 ice_hw_port_strings[i].offset);
5194 xstats[count].id = count;
5201 static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
5202 struct rte_eth_xstat_name *xstats_names,
5203 __rte_unused unsigned int limit)
5205 unsigned int count = 0;
5209 return ice_xstats_calc_num();
5211 /* Note: limit checked in rte_eth_xstats_names() */
5213 /* Get stats from ice_eth_stats struct */
5214 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5215 strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
5216 sizeof(xstats_names[count].name));
5220 /* Get individiual stats from ice_hw_port struct */
5221 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5222 strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
5223 sizeof(xstats_names[count].name));
5231 ice_dev_flow_ops_get(struct rte_eth_dev *dev,
5232 const struct rte_flow_ops **ops)
5237 *ops = &ice_flow_ops;
5241 /* Add UDP tunneling port */
5243 ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
5244 struct rte_eth_udp_tunnel *udp_tunnel)
5247 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5249 if (udp_tunnel == NULL)
5252 switch (udp_tunnel->prot_type) {
5253 case RTE_TUNNEL_TYPE_VXLAN:
5254 ret = ice_create_tunnel(hw, TNL_VXLAN, udp_tunnel->udp_port);
5257 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5265 /* Delete UDP tunneling port */
5267 ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
5268 struct rte_eth_udp_tunnel *udp_tunnel)
5271 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5273 if (udp_tunnel == NULL)
5276 switch (udp_tunnel->prot_type) {
5277 case RTE_TUNNEL_TYPE_VXLAN:
5278 ret = ice_destroy_tunnel(hw, udp_tunnel->udp_port, 0);
5281 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5290 ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
5291 struct rte_pci_device *pci_dev)
5293 return rte_eth_dev_pci_generic_probe(pci_dev,
5294 sizeof(struct ice_adapter),
5299 ice_pci_remove(struct rte_pci_device *pci_dev)
5301 return rte_eth_dev_pci_generic_remove(pci_dev, ice_dev_uninit);
5304 static struct rte_pci_driver rte_ice_pmd = {
5305 .id_table = pci_id_ice_map,
5306 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
5307 .probe = ice_pci_probe,
5308 .remove = ice_pci_remove,
5312 * Driver initialization routine.
5313 * Invoked once at EAL init time.
5314 * Register itself as the [Poll Mode] Driver of PCI devices.
5316 RTE_PMD_REGISTER_PCI(net_ice, rte_ice_pmd);
5317 RTE_PMD_REGISTER_PCI_TABLE(net_ice, pci_id_ice_map);
5318 RTE_PMD_REGISTER_KMOD_DEP(net_ice, "* igb_uio | uio_pci_generic | vfio-pci");
5319 RTE_PMD_REGISTER_PARAM_STRING(net_ice,
5320 ICE_HW_DEBUG_MASK_ARG "=0xXXX"
5321 ICE_PROTO_XTR_ARG "=[queue:]<vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset>"
5322 ICE_SAFE_MODE_SUPPORT_ARG "=<0|1>"
5323 ICE_PIPELINE_MODE_SUPPORT_ARG "=<0|1>");
5325 RTE_LOG_REGISTER_SUFFIX(ice_logtype_init, init, NOTICE);
5326 RTE_LOG_REGISTER_SUFFIX(ice_logtype_driver, driver, NOTICE);
5327 #ifdef RTE_ETHDEV_DEBUG_RX
5328 RTE_LOG_REGISTER_SUFFIX(ice_logtype_rx, rx, DEBUG);
5330 #ifdef RTE_ETHDEV_DEBUG_TX
5331 RTE_LOG_REGISTER_SUFFIX(ice_logtype_tx, tx, DEBUG);