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"
32 #define ICE_ONE_PPS_OUT_ARG "pps_out"
33 #define ICE_RX_LOW_LATENCY_ARG "rx_low_latency"
35 uint64_t ice_timestamp_dynflag;
36 int ice_timestamp_dynfield_offset = -1;
38 static const char * const ice_valid_args[] = {
39 ICE_SAFE_MODE_SUPPORT_ARG,
40 ICE_PIPELINE_MODE_SUPPORT_ARG,
42 ICE_HW_DEBUG_MASK_ARG,
44 ICE_RX_LOW_LATENCY_ARG,
48 #define NSEC_PER_SEC 1000000000
49 #define PPS_OUT_DELAY_NS 1
51 static const struct rte_mbuf_dynfield ice_proto_xtr_metadata_param = {
52 .name = "intel_pmd_dynfield_proto_xtr_metadata",
53 .size = sizeof(uint32_t),
54 .align = __alignof__(uint32_t),
58 struct proto_xtr_ol_flag {
59 const struct rte_mbuf_dynflag param;
64 static bool ice_proto_xtr_hw_support[PROTO_XTR_MAX];
66 static struct proto_xtr_ol_flag ice_proto_xtr_ol_flag_params[] = {
68 .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
69 .ol_flag = &rte_net_ice_dynflag_proto_xtr_vlan_mask },
71 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
72 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv4_mask },
74 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
75 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_mask },
76 [PROTO_XTR_IPV6_FLOW] = {
77 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
78 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask },
80 .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
81 .ol_flag = &rte_net_ice_dynflag_proto_xtr_tcp_mask },
82 [PROTO_XTR_IP_OFFSET] = {
83 .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
84 .ol_flag = &rte_net_ice_dynflag_proto_xtr_ip_offset_mask },
87 #define ICE_OS_DEFAULT_PKG_NAME "ICE OS Default Package"
88 #define ICE_COMMS_PKG_NAME "ICE COMMS Package"
89 #define ICE_MAX_RES_DESC_NUM 1024
91 static int ice_dev_configure(struct rte_eth_dev *dev);
92 static int ice_dev_start(struct rte_eth_dev *dev);
93 static int ice_dev_stop(struct rte_eth_dev *dev);
94 static int ice_dev_close(struct rte_eth_dev *dev);
95 static int ice_dev_reset(struct rte_eth_dev *dev);
96 static int ice_dev_info_get(struct rte_eth_dev *dev,
97 struct rte_eth_dev_info *dev_info);
98 static int ice_link_update(struct rte_eth_dev *dev,
99 int wait_to_complete);
100 static int ice_dev_set_link_up(struct rte_eth_dev *dev);
101 static int ice_dev_set_link_down(struct rte_eth_dev *dev);
103 static int ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
104 static int ice_vlan_offload_set(struct rte_eth_dev *dev, int mask);
105 static int ice_rss_reta_update(struct rte_eth_dev *dev,
106 struct rte_eth_rss_reta_entry64 *reta_conf,
108 static int ice_rss_reta_query(struct rte_eth_dev *dev,
109 struct rte_eth_rss_reta_entry64 *reta_conf,
111 static int ice_rss_hash_update(struct rte_eth_dev *dev,
112 struct rte_eth_rss_conf *rss_conf);
113 static int ice_rss_hash_conf_get(struct rte_eth_dev *dev,
114 struct rte_eth_rss_conf *rss_conf);
115 static int ice_promisc_enable(struct rte_eth_dev *dev);
116 static int ice_promisc_disable(struct rte_eth_dev *dev);
117 static int ice_allmulti_enable(struct rte_eth_dev *dev);
118 static int ice_allmulti_disable(struct rte_eth_dev *dev);
119 static int ice_vlan_filter_set(struct rte_eth_dev *dev,
122 static int ice_macaddr_set(struct rte_eth_dev *dev,
123 struct rte_ether_addr *mac_addr);
124 static int ice_macaddr_add(struct rte_eth_dev *dev,
125 struct rte_ether_addr *mac_addr,
126 __rte_unused uint32_t index,
128 static void ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
129 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
131 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
133 static int ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
135 static int ice_vlan_pvid_set(struct rte_eth_dev *dev,
136 uint16_t pvid, int on);
137 static int ice_get_eeprom_length(struct rte_eth_dev *dev);
138 static int ice_get_eeprom(struct rte_eth_dev *dev,
139 struct rte_dev_eeprom_info *eeprom);
140 static int ice_stats_get(struct rte_eth_dev *dev,
141 struct rte_eth_stats *stats);
142 static int ice_stats_reset(struct rte_eth_dev *dev);
143 static int ice_xstats_get(struct rte_eth_dev *dev,
144 struct rte_eth_xstat *xstats, unsigned int n);
145 static int ice_xstats_get_names(struct rte_eth_dev *dev,
146 struct rte_eth_xstat_name *xstats_names,
148 static int ice_dev_flow_ops_get(struct rte_eth_dev *dev,
149 const struct rte_flow_ops **ops);
150 static int ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
151 struct rte_eth_udp_tunnel *udp_tunnel);
152 static int ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
153 struct rte_eth_udp_tunnel *udp_tunnel);
155 static const struct rte_pci_id pci_id_ice_map[] = {
156 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_BACKPLANE) },
157 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_SFP) },
158 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_10G_BASE_T) },
159 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_1GBE) },
160 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823L_QSFP) },
161 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_BACKPLANE) },
162 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_QSFP) },
163 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810C_SFP) },
164 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_BACKPLANE) },
165 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_QSFP) },
166 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E810_XXV_SFP) },
167 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_BACKPLANE) },
168 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_QSFP) },
169 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SFP) },
170 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_10G_BASE_T) },
171 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E823C_SGMII) },
172 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_BACKPLANE) },
173 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_QSFP) },
174 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SFP) },
175 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_10G_BASE_T) },
176 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822C_SGMII) },
177 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_BACKPLANE) },
178 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SFP) },
179 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_10G_BASE_T) },
180 { RTE_PCI_DEVICE(ICE_INTEL_VENDOR_ID, ICE_DEV_ID_E822L_SGMII) },
181 { .vendor_id = 0, /* sentinel */ },
184 static const struct eth_dev_ops ice_eth_dev_ops = {
185 .dev_configure = ice_dev_configure,
186 .dev_start = ice_dev_start,
187 .dev_stop = ice_dev_stop,
188 .dev_close = ice_dev_close,
189 .dev_reset = ice_dev_reset,
190 .dev_set_link_up = ice_dev_set_link_up,
191 .dev_set_link_down = ice_dev_set_link_down,
192 .rx_queue_start = ice_rx_queue_start,
193 .rx_queue_stop = ice_rx_queue_stop,
194 .tx_queue_start = ice_tx_queue_start,
195 .tx_queue_stop = ice_tx_queue_stop,
196 .rx_queue_setup = ice_rx_queue_setup,
197 .rx_queue_release = ice_rx_queue_release,
198 .tx_queue_setup = ice_tx_queue_setup,
199 .tx_queue_release = ice_tx_queue_release,
200 .dev_infos_get = ice_dev_info_get,
201 .dev_supported_ptypes_get = ice_dev_supported_ptypes_get,
202 .link_update = ice_link_update,
203 .mtu_set = ice_mtu_set,
204 .mac_addr_set = ice_macaddr_set,
205 .mac_addr_add = ice_macaddr_add,
206 .mac_addr_remove = ice_macaddr_remove,
207 .vlan_filter_set = ice_vlan_filter_set,
208 .vlan_offload_set = ice_vlan_offload_set,
209 .reta_update = ice_rss_reta_update,
210 .reta_query = ice_rss_reta_query,
211 .rss_hash_update = ice_rss_hash_update,
212 .rss_hash_conf_get = ice_rss_hash_conf_get,
213 .promiscuous_enable = ice_promisc_enable,
214 .promiscuous_disable = ice_promisc_disable,
215 .allmulticast_enable = ice_allmulti_enable,
216 .allmulticast_disable = ice_allmulti_disable,
217 .rx_queue_intr_enable = ice_rx_queue_intr_enable,
218 .rx_queue_intr_disable = ice_rx_queue_intr_disable,
219 .fw_version_get = ice_fw_version_get,
220 .vlan_pvid_set = ice_vlan_pvid_set,
221 .rxq_info_get = ice_rxq_info_get,
222 .txq_info_get = ice_txq_info_get,
223 .rx_burst_mode_get = ice_rx_burst_mode_get,
224 .tx_burst_mode_get = ice_tx_burst_mode_get,
225 .get_eeprom_length = ice_get_eeprom_length,
226 .get_eeprom = ice_get_eeprom,
227 .stats_get = ice_stats_get,
228 .stats_reset = ice_stats_reset,
229 .xstats_get = ice_xstats_get,
230 .xstats_get_names = ice_xstats_get_names,
231 .xstats_reset = ice_stats_reset,
232 .flow_ops_get = ice_dev_flow_ops_get,
233 .udp_tunnel_port_add = ice_dev_udp_tunnel_port_add,
234 .udp_tunnel_port_del = ice_dev_udp_tunnel_port_del,
235 .tx_done_cleanup = ice_tx_done_cleanup,
236 .get_monitor_addr = ice_get_monitor_addr,
239 /* store statistics names and its offset in stats structure */
240 struct ice_xstats_name_off {
241 char name[RTE_ETH_XSTATS_NAME_SIZE];
245 static const struct ice_xstats_name_off ice_stats_strings[] = {
246 {"rx_unicast_packets", offsetof(struct ice_eth_stats, rx_unicast)},
247 {"rx_multicast_packets", offsetof(struct ice_eth_stats, rx_multicast)},
248 {"rx_broadcast_packets", offsetof(struct ice_eth_stats, rx_broadcast)},
249 {"rx_dropped_packets", offsetof(struct ice_eth_stats, rx_discards)},
250 {"rx_unknown_protocol_packets", offsetof(struct ice_eth_stats,
251 rx_unknown_protocol)},
252 {"tx_unicast_packets", offsetof(struct ice_eth_stats, tx_unicast)},
253 {"tx_multicast_packets", offsetof(struct ice_eth_stats, tx_multicast)},
254 {"tx_broadcast_packets", offsetof(struct ice_eth_stats, tx_broadcast)},
255 {"tx_dropped_packets", offsetof(struct ice_eth_stats, tx_discards)},
258 #define ICE_NB_ETH_XSTATS (sizeof(ice_stats_strings) / \
259 sizeof(ice_stats_strings[0]))
261 static const struct ice_xstats_name_off ice_hw_port_strings[] = {
262 {"tx_link_down_dropped", offsetof(struct ice_hw_port_stats,
263 tx_dropped_link_down)},
264 {"rx_crc_errors", offsetof(struct ice_hw_port_stats, crc_errors)},
265 {"rx_illegal_byte_errors", offsetof(struct ice_hw_port_stats,
267 {"rx_error_bytes", offsetof(struct ice_hw_port_stats, error_bytes)},
268 {"mac_local_errors", offsetof(struct ice_hw_port_stats,
270 {"mac_remote_errors", offsetof(struct ice_hw_port_stats,
272 {"rx_len_errors", offsetof(struct ice_hw_port_stats,
274 {"tx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_tx)},
275 {"rx_xon_packets", offsetof(struct ice_hw_port_stats, link_xon_rx)},
276 {"tx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_tx)},
277 {"rx_xoff_packets", offsetof(struct ice_hw_port_stats, link_xoff_rx)},
278 {"rx_size_64_packets", offsetof(struct ice_hw_port_stats, rx_size_64)},
279 {"rx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
281 {"rx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
283 {"rx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
285 {"rx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
287 {"rx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
289 {"rx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
291 {"rx_undersized_errors", offsetof(struct ice_hw_port_stats,
293 {"rx_oversize_errors", offsetof(struct ice_hw_port_stats,
295 {"rx_mac_short_pkt_dropped", offsetof(struct ice_hw_port_stats,
296 mac_short_pkt_dropped)},
297 {"rx_fragmented_errors", offsetof(struct ice_hw_port_stats,
299 {"rx_jabber_errors", offsetof(struct ice_hw_port_stats, rx_jabber)},
300 {"tx_size_64_packets", offsetof(struct ice_hw_port_stats, tx_size_64)},
301 {"tx_size_65_to_127_packets", offsetof(struct ice_hw_port_stats,
303 {"tx_size_128_to_255_packets", offsetof(struct ice_hw_port_stats,
305 {"tx_size_256_to_511_packets", offsetof(struct ice_hw_port_stats,
307 {"tx_size_512_to_1023_packets", offsetof(struct ice_hw_port_stats,
309 {"tx_size_1024_to_1522_packets", offsetof(struct ice_hw_port_stats,
311 {"tx_size_1523_to_max_packets", offsetof(struct ice_hw_port_stats,
315 #define ICE_NB_HW_PORT_XSTATS (sizeof(ice_hw_port_strings) / \
316 sizeof(ice_hw_port_strings[0]))
319 ice_init_controlq_parameter(struct ice_hw *hw)
321 /* fields for adminq */
322 hw->adminq.num_rq_entries = ICE_ADMINQ_LEN;
323 hw->adminq.num_sq_entries = ICE_ADMINQ_LEN;
324 hw->adminq.rq_buf_size = ICE_ADMINQ_BUF_SZ;
325 hw->adminq.sq_buf_size = ICE_ADMINQ_BUF_SZ;
327 /* fields for mailboxq, DPDK used as PF host */
328 hw->mailboxq.num_rq_entries = ICE_MAILBOXQ_LEN;
329 hw->mailboxq.num_sq_entries = ICE_MAILBOXQ_LEN;
330 hw->mailboxq.rq_buf_size = ICE_MAILBOXQ_BUF_SZ;
331 hw->mailboxq.sq_buf_size = ICE_MAILBOXQ_BUF_SZ;
335 lookup_proto_xtr_type(const char *xtr_name)
339 enum proto_xtr_type type;
341 { "vlan", PROTO_XTR_VLAN },
342 { "ipv4", PROTO_XTR_IPV4 },
343 { "ipv6", PROTO_XTR_IPV6 },
344 { "ipv6_flow", PROTO_XTR_IPV6_FLOW },
345 { "tcp", PROTO_XTR_TCP },
346 { "ip_offset", PROTO_XTR_IP_OFFSET },
350 for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
351 if (strcmp(xtr_name, xtr_type_map[i].name) == 0)
352 return xtr_type_map[i].type;
359 * Parse elem, the elem could be single number/range or '(' ')' group
360 * 1) A single number elem, it's just a simple digit. e.g. 9
361 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
362 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
363 * Within group elem, '-' used for a range separator;
364 * ',' used for a single number.
367 parse_queue_set(const char *input, int xtr_type, struct ice_devargs *devargs)
369 const char *str = input;
374 while (isblank(*str))
377 if (!isdigit(*str) && *str != '(')
380 /* process single number or single range of number */
383 idx = strtoul(str, &end, 10);
384 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
387 while (isblank(*end))
393 /* process single <number>-<number> */
396 while (isblank(*end))
402 idx = strtoul(end, &end, 10);
403 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
407 while (isblank(*end))
414 for (idx = RTE_MIN(min, max);
415 idx <= RTE_MAX(min, max); idx++)
416 devargs->proto_xtr[idx] = xtr_type;
421 /* process set within bracket */
423 while (isblank(*str))
428 min = ICE_MAX_QUEUE_NUM;
430 /* go ahead to the first digit */
431 while (isblank(*str))
436 /* get the digit value */
438 idx = strtoul(str, &end, 10);
439 if (errno || end == NULL || idx >= ICE_MAX_QUEUE_NUM)
442 /* go ahead to separator '-',',' and ')' */
443 while (isblank(*end))
446 if (min == ICE_MAX_QUEUE_NUM)
448 else /* avoid continuous '-' */
450 } else if (*end == ',' || *end == ')') {
452 if (min == ICE_MAX_QUEUE_NUM)
455 for (idx = RTE_MIN(min, max);
456 idx <= RTE_MAX(min, max); idx++)
457 devargs->proto_xtr[idx] = xtr_type;
459 min = ICE_MAX_QUEUE_NUM;
465 } while (*end != ')' && *end != '\0');
471 parse_queue_proto_xtr(const char *queues, struct ice_devargs *devargs)
473 const char *queue_start;
478 while (isblank(*queues))
481 if (*queues != '[') {
482 xtr_type = lookup_proto_xtr_type(queues);
486 devargs->proto_xtr_dflt = xtr_type;
493 while (isblank(*queues))
498 queue_start = queues;
500 /* go across a complete bracket */
501 if (*queue_start == '(') {
502 queues += strcspn(queues, ")");
507 /* scan the separator ':' */
508 queues += strcspn(queues, ":");
509 if (*queues++ != ':')
511 while (isblank(*queues))
514 for (idx = 0; ; idx++) {
515 if (isblank(queues[idx]) ||
516 queues[idx] == ',' ||
517 queues[idx] == ']' ||
521 if (idx > sizeof(xtr_name) - 2)
524 xtr_name[idx] = queues[idx];
526 xtr_name[idx] = '\0';
527 xtr_type = lookup_proto_xtr_type(xtr_name);
533 while (isblank(*queues) || *queues == ',' || *queues == ']')
536 if (parse_queue_set(queue_start, xtr_type, devargs) < 0)
538 } while (*queues != '\0');
544 handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
547 struct ice_devargs *devargs = extra_args;
549 if (value == NULL || extra_args == NULL)
552 if (parse_queue_proto_xtr(value, devargs) < 0) {
554 "The protocol extraction parameter is wrong : '%s'",
563 ice_check_proto_xtr_support(struct ice_hw *hw)
565 #define FLX_REG(val, fld, idx) \
566 (((val) & GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_M) >> \
567 GLFLXP_RXDID_FLX_WRD_##idx##_##fld##_S)
574 [PROTO_XTR_VLAN] = { ICE_RXDID_COMMS_AUX_VLAN,
576 ICE_PROT_EVLAN_O, ICE_PROT_VLAN_O},
577 [PROTO_XTR_IPV4] = { ICE_RXDID_COMMS_AUX_IPV4,
579 ICE_PROT_IPV4_OF_OR_S,
580 ICE_PROT_IPV4_OF_OR_S },
581 [PROTO_XTR_IPV6] = { ICE_RXDID_COMMS_AUX_IPV6,
583 ICE_PROT_IPV6_OF_OR_S,
584 ICE_PROT_IPV6_OF_OR_S },
585 [PROTO_XTR_IPV6_FLOW] = { ICE_RXDID_COMMS_AUX_IPV6_FLOW,
587 ICE_PROT_IPV6_OF_OR_S,
588 ICE_PROT_IPV6_OF_OR_S },
589 [PROTO_XTR_TCP] = { ICE_RXDID_COMMS_AUX_TCP,
591 ICE_PROT_TCP_IL, ICE_PROT_ID_INVAL },
592 [PROTO_XTR_IP_OFFSET] = { ICE_RXDID_COMMS_AUX_IP_OFFSET,
594 ICE_PROT_IPV4_OF_OR_S,
595 ICE_PROT_IPV6_OF_OR_S },
599 for (i = 0; i < RTE_DIM(xtr_sets); i++) {
600 uint32_t rxdid = xtr_sets[i].rxdid;
603 if (xtr_sets[i].protid_0 != ICE_PROT_ID_INVAL) {
604 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_4(rxdid));
606 if (FLX_REG(v, PROT_MDID, 4) == xtr_sets[i].protid_0 &&
607 FLX_REG(v, RXDID_OPCODE, 4) == xtr_sets[i].opcode)
608 ice_proto_xtr_hw_support[i] = true;
611 if (xtr_sets[i].protid_1 != ICE_PROT_ID_INVAL) {
612 v = ICE_READ_REG(hw, GLFLXP_RXDID_FLX_WRD_5(rxdid));
614 if (FLX_REG(v, PROT_MDID, 5) == xtr_sets[i].protid_1 &&
615 FLX_REG(v, RXDID_OPCODE, 5) == xtr_sets[i].opcode)
616 ice_proto_xtr_hw_support[i] = true;
622 ice_res_pool_init(struct ice_res_pool_info *pool, uint32_t base,
625 struct pool_entry *entry;
630 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
633 "Failed to allocate memory for resource pool");
637 /* queue heap initialize */
638 pool->num_free = num;
641 LIST_INIT(&pool->alloc_list);
642 LIST_INIT(&pool->free_list);
644 /* Initialize element */
648 LIST_INSERT_HEAD(&pool->free_list, entry, next);
653 ice_res_pool_alloc(struct ice_res_pool_info *pool,
656 struct pool_entry *entry, *valid_entry;
659 PMD_INIT_LOG(ERR, "Invalid parameter");
663 if (pool->num_free < num) {
664 PMD_INIT_LOG(ERR, "No resource. ask:%u, available:%u",
665 num, pool->num_free);
670 /* Lookup in free list and find most fit one */
671 LIST_FOREACH(entry, &pool->free_list, next) {
672 if (entry->len >= num) {
674 if (entry->len == num) {
679 valid_entry->len > entry->len)
684 /* Not find one to satisfy the request, return */
686 PMD_INIT_LOG(ERR, "No valid entry found");
690 * The entry have equal queue number as requested,
691 * remove it from alloc_list.
693 if (valid_entry->len == num) {
694 LIST_REMOVE(valid_entry, next);
697 * The entry have more numbers than requested,
698 * create a new entry for alloc_list and minus its
699 * queue base and number in free_list.
701 entry = rte_zmalloc(NULL, sizeof(*entry), 0);
704 "Failed to allocate memory for "
708 entry->base = valid_entry->base;
710 valid_entry->base += num;
711 valid_entry->len -= num;
715 /* Insert it into alloc list, not sorted */
716 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
718 pool->num_free -= valid_entry->len;
719 pool->num_alloc += valid_entry->len;
721 return valid_entry->base + pool->base;
725 ice_res_pool_destroy(struct ice_res_pool_info *pool)
727 struct pool_entry *entry, *next_entry;
732 for (entry = LIST_FIRST(&pool->alloc_list);
733 entry && (next_entry = LIST_NEXT(entry, next), 1);
734 entry = next_entry) {
735 LIST_REMOVE(entry, next);
739 for (entry = LIST_FIRST(&pool->free_list);
740 entry && (next_entry = LIST_NEXT(entry, next), 1);
741 entry = next_entry) {
742 LIST_REMOVE(entry, next);
749 LIST_INIT(&pool->alloc_list);
750 LIST_INIT(&pool->free_list);
754 ice_vsi_config_default_rss(struct ice_aqc_vsi_props *info)
756 /* Set VSI LUT selection */
757 info->q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI &
758 ICE_AQ_VSI_Q_OPT_RSS_LUT_M;
759 /* Set Hash scheme */
760 info->q_opt_rss |= ICE_AQ_VSI_Q_OPT_RSS_TPLZ &
761 ICE_AQ_VSI_Q_OPT_RSS_HASH_M;
763 info->q_opt_tc = ICE_AQ_VSI_Q_OPT_TC_OVR_M;
766 static enum ice_status
767 ice_vsi_config_tc_queue_mapping(struct ice_vsi *vsi,
768 struct ice_aqc_vsi_props *info,
769 uint8_t enabled_tcmap)
771 uint16_t bsf, qp_idx;
773 /* default tc 0 now. Multi-TC supporting need to be done later.
774 * Configure TC and queue mapping parameters, for enabled TC,
775 * allocate qpnum_per_tc queues to this traffic.
777 if (enabled_tcmap != 0x01) {
778 PMD_INIT_LOG(ERR, "only TC0 is supported");
782 vsi->nb_qps = RTE_MIN(vsi->nb_qps, ICE_MAX_Q_PER_TC);
783 bsf = rte_bsf32(vsi->nb_qps);
784 /* Adjust the queue number to actual queues that can be applied */
785 vsi->nb_qps = 0x1 << bsf;
788 /* Set tc and queue mapping with VSI */
789 info->tc_mapping[0] = rte_cpu_to_le_16((qp_idx <<
790 ICE_AQ_VSI_TC_Q_OFFSET_S) |
791 (bsf << ICE_AQ_VSI_TC_Q_NUM_S));
793 /* Associate queue number with VSI */
794 info->mapping_flags |= rte_cpu_to_le_16(ICE_AQ_VSI_Q_MAP_CONTIG);
795 info->q_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
796 info->q_mapping[1] = rte_cpu_to_le_16(vsi->nb_qps);
797 info->valid_sections |=
798 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
799 /* Set the info.ingress_table and info.egress_table
800 * for UP translate table. Now just set it to 1:1 map by default
801 * -- 0b 111 110 101 100 011 010 001 000 == 0xFAC688
803 #define ICE_TC_QUEUE_TABLE_DFLT 0x00FAC688
804 info->ingress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
805 info->egress_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
806 info->outer_up_table = rte_cpu_to_le_32(ICE_TC_QUEUE_TABLE_DFLT);
811 ice_init_mac_address(struct rte_eth_dev *dev)
813 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
815 if (!rte_is_unicast_ether_addr
816 ((struct rte_ether_addr *)hw->port_info[0].mac.lan_addr)) {
817 PMD_INIT_LOG(ERR, "Invalid MAC address");
822 (struct rte_ether_addr *)hw->port_info[0].mac.lan_addr,
823 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr);
825 dev->data->mac_addrs =
826 rte_zmalloc(NULL, sizeof(struct rte_ether_addr) * ICE_NUM_MACADDR_MAX, 0);
827 if (!dev->data->mac_addrs) {
829 "Failed to allocate memory to store mac address");
832 /* store it to dev data */
834 (struct rte_ether_addr *)hw->port_info[0].mac.perm_addr,
835 &dev->data->mac_addrs[0]);
839 /* Find out specific MAC filter */
840 static struct ice_mac_filter *
841 ice_find_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *macaddr)
843 struct ice_mac_filter *f;
845 TAILQ_FOREACH(f, &vsi->mac_list, next) {
846 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
854 ice_add_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
856 struct ice_fltr_list_entry *m_list_itr = NULL;
857 struct ice_mac_filter *f;
858 struct LIST_HEAD_TYPE list_head;
859 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
862 /* If it's added and configured, return */
863 f = ice_find_mac_filter(vsi, mac_addr);
865 PMD_DRV_LOG(INFO, "This MAC filter already exists.");
869 INIT_LIST_HEAD(&list_head);
871 m_list_itr = (struct ice_fltr_list_entry *)
872 ice_malloc(hw, sizeof(*m_list_itr));
877 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
878 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
879 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
880 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
881 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
882 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
883 m_list_itr->fltr_info.vsi_handle = vsi->idx;
885 LIST_ADD(&m_list_itr->list_entry, &list_head);
888 ret = ice_add_mac(hw, &list_head);
889 if (ret != ICE_SUCCESS) {
890 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
894 /* Add the mac addr into mac list */
895 f = rte_zmalloc(NULL, sizeof(*f), 0);
897 PMD_DRV_LOG(ERR, "failed to allocate memory");
901 rte_ether_addr_copy(mac_addr, &f->mac_info.mac_addr);
902 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
908 rte_free(m_list_itr);
913 ice_remove_mac_filter(struct ice_vsi *vsi, struct rte_ether_addr *mac_addr)
915 struct ice_fltr_list_entry *m_list_itr = NULL;
916 struct ice_mac_filter *f;
917 struct LIST_HEAD_TYPE list_head;
918 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
921 /* Can't find it, return an error */
922 f = ice_find_mac_filter(vsi, mac_addr);
926 INIT_LIST_HEAD(&list_head);
928 m_list_itr = (struct ice_fltr_list_entry *)
929 ice_malloc(hw, sizeof(*m_list_itr));
934 ice_memcpy(m_list_itr->fltr_info.l_data.mac.mac_addr,
935 mac_addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
936 m_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
937 m_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
938 m_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
939 m_list_itr->fltr_info.flag = ICE_FLTR_TX;
940 m_list_itr->fltr_info.vsi_handle = vsi->idx;
942 LIST_ADD(&m_list_itr->list_entry, &list_head);
944 /* remove the mac filter */
945 ret = ice_remove_mac(hw, &list_head);
946 if (ret != ICE_SUCCESS) {
947 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
952 /* Remove the mac addr from mac list */
953 TAILQ_REMOVE(&vsi->mac_list, f, next);
959 rte_free(m_list_itr);
963 /* Find out specific VLAN filter */
964 static struct ice_vlan_filter *
965 ice_find_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
967 struct ice_vlan_filter *f;
969 TAILQ_FOREACH(f, &vsi->vlan_list, next) {
970 if (vlan->tpid == f->vlan_info.vlan.tpid &&
971 vlan->vid == f->vlan_info.vlan.vid)
979 ice_add_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
981 struct ice_fltr_list_entry *v_list_itr = NULL;
982 struct ice_vlan_filter *f;
983 struct LIST_HEAD_TYPE list_head;
987 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
990 hw = ICE_VSI_TO_HW(vsi);
992 /* If it's added and configured, return. */
993 f = ice_find_vlan_filter(vsi, vlan);
995 PMD_DRV_LOG(INFO, "This VLAN filter already exists.");
999 if (!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on)
1002 INIT_LIST_HEAD(&list_head);
1004 v_list_itr = (struct ice_fltr_list_entry *)
1005 ice_malloc(hw, sizeof(*v_list_itr));
1010 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1011 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1012 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1013 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1014 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1015 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1016 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1017 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1019 LIST_ADD(&v_list_itr->list_entry, &list_head);
1022 ret = ice_add_vlan(hw, &list_head);
1023 if (ret != ICE_SUCCESS) {
1024 PMD_DRV_LOG(ERR, "Failed to add VLAN filter");
1029 /* Add vlan into vlan list */
1030 f = rte_zmalloc(NULL, sizeof(*f), 0);
1032 PMD_DRV_LOG(ERR, "failed to allocate memory");
1036 f->vlan_info.vlan.tpid = vlan->tpid;
1037 f->vlan_info.vlan.vid = vlan->vid;
1038 TAILQ_INSERT_TAIL(&vsi->vlan_list, f, next);
1044 rte_free(v_list_itr);
1049 ice_remove_vlan_filter(struct ice_vsi *vsi, struct ice_vlan *vlan)
1051 struct ice_fltr_list_entry *v_list_itr = NULL;
1052 struct ice_vlan_filter *f;
1053 struct LIST_HEAD_TYPE list_head;
1057 if (!vsi || vlan->vid > RTE_ETHER_MAX_VLAN_ID)
1060 hw = ICE_VSI_TO_HW(vsi);
1062 /* Can't find it, return an error */
1063 f = ice_find_vlan_filter(vsi, vlan);
1067 INIT_LIST_HEAD(&list_head);
1069 v_list_itr = (struct ice_fltr_list_entry *)
1070 ice_malloc(hw, sizeof(*v_list_itr));
1076 v_list_itr->fltr_info.l_data.vlan.vlan_id = vlan->vid;
1077 v_list_itr->fltr_info.l_data.vlan.tpid = vlan->tpid;
1078 v_list_itr->fltr_info.l_data.vlan.tpid_valid = true;
1079 v_list_itr->fltr_info.src_id = ICE_SRC_ID_VSI;
1080 v_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1081 v_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1082 v_list_itr->fltr_info.flag = ICE_FLTR_TX;
1083 v_list_itr->fltr_info.vsi_handle = vsi->idx;
1085 LIST_ADD(&v_list_itr->list_entry, &list_head);
1087 /* remove the vlan filter */
1088 ret = ice_remove_vlan(hw, &list_head);
1089 if (ret != ICE_SUCCESS) {
1090 PMD_DRV_LOG(ERR, "Failed to remove VLAN filter");
1095 /* Remove the vlan id from vlan list */
1096 TAILQ_REMOVE(&vsi->vlan_list, f, next);
1102 rte_free(v_list_itr);
1107 ice_remove_all_mac_vlan_filters(struct ice_vsi *vsi)
1109 struct ice_mac_filter *m_f;
1110 struct ice_vlan_filter *v_f;
1114 if (!vsi || !vsi->mac_num)
1117 RTE_TAILQ_FOREACH_SAFE(m_f, &vsi->mac_list, next, temp) {
1118 ret = ice_remove_mac_filter(vsi, &m_f->mac_info.mac_addr);
1119 if (ret != ICE_SUCCESS) {
1125 if (vsi->vlan_num == 0)
1128 RTE_TAILQ_FOREACH_SAFE(v_f, &vsi->vlan_list, next, temp) {
1129 ret = ice_remove_vlan_filter(vsi, &v_f->vlan_info.vlan);
1130 if (ret != ICE_SUCCESS) {
1142 ice_pf_enable_irq0(struct ice_hw *hw)
1144 /* reset the registers */
1145 ICE_WRITE_REG(hw, PFINT_OICR_ENA, 0);
1146 ICE_READ_REG(hw, PFINT_OICR);
1149 ICE_WRITE_REG(hw, PFINT_OICR_ENA,
1150 (uint32_t)(PFINT_OICR_ENA_INT_ENA_M &
1151 (~PFINT_OICR_LINK_STAT_CHANGE_M)));
1153 ICE_WRITE_REG(hw, PFINT_OICR_CTL,
1154 (0 & PFINT_OICR_CTL_MSIX_INDX_M) |
1155 ((0 << PFINT_OICR_CTL_ITR_INDX_S) &
1156 PFINT_OICR_CTL_ITR_INDX_M) |
1157 PFINT_OICR_CTL_CAUSE_ENA_M);
1159 ICE_WRITE_REG(hw, PFINT_FW_CTL,
1160 (0 & PFINT_FW_CTL_MSIX_INDX_M) |
1161 ((0 << PFINT_FW_CTL_ITR_INDX_S) &
1162 PFINT_FW_CTL_ITR_INDX_M) |
1163 PFINT_FW_CTL_CAUSE_ENA_M);
1165 ICE_WRITE_REG(hw, PFINT_OICR_ENA, PFINT_OICR_ENA_INT_ENA_M);
1168 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
1169 GLINT_DYN_CTL_INTENA_M |
1170 GLINT_DYN_CTL_CLEARPBA_M |
1171 GLINT_DYN_CTL_ITR_INDX_M);
1178 ice_pf_disable_irq0(struct ice_hw *hw)
1180 /* Disable all interrupt types */
1181 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
1187 ice_handle_aq_msg(struct rte_eth_dev *dev)
1189 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1190 struct ice_ctl_q_info *cq = &hw->adminq;
1191 struct ice_rq_event_info event;
1192 uint16_t pending, opcode;
1195 event.buf_len = ICE_AQ_MAX_BUF_LEN;
1196 event.msg_buf = rte_zmalloc(NULL, event.buf_len, 0);
1197 if (!event.msg_buf) {
1198 PMD_DRV_LOG(ERR, "Failed to allocate mem");
1204 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1206 if (ret != ICE_SUCCESS) {
1208 "Failed to read msg from AdminQ, "
1210 hw->adminq.sq_last_status);
1213 opcode = rte_le_to_cpu_16(event.desc.opcode);
1216 case ice_aqc_opc_get_link_status:
1217 ret = ice_link_update(dev, 0);
1219 rte_eth_dev_callback_process
1220 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1223 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
1228 rte_free(event.msg_buf);
1233 * Interrupt handler triggered by NIC for handling
1234 * specific interrupt.
1237 * Pointer to interrupt handle.
1239 * The address of parameter (struct rte_eth_dev *) regsitered before.
1245 ice_interrupt_handler(void *param)
1247 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1248 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1256 uint32_t int_fw_ctl;
1259 /* Disable interrupt */
1260 ice_pf_disable_irq0(hw);
1262 /* read out interrupt causes */
1263 oicr = ICE_READ_REG(hw, PFINT_OICR);
1265 int_fw_ctl = ICE_READ_REG(hw, PFINT_FW_CTL);
1268 /* No interrupt event indicated */
1269 if (!(oicr & PFINT_OICR_INTEVENT_M)) {
1270 PMD_DRV_LOG(INFO, "No interrupt event");
1275 if (int_fw_ctl & PFINT_FW_CTL_INTEVENT_M) {
1276 PMD_DRV_LOG(INFO, "FW_CTL: link state change event");
1277 ice_handle_aq_msg(dev);
1280 if (oicr & PFINT_OICR_LINK_STAT_CHANGE_M) {
1281 PMD_DRV_LOG(INFO, "OICR: link state change event");
1282 ret = ice_link_update(dev, 0);
1284 rte_eth_dev_callback_process
1285 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1289 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1290 PMD_DRV_LOG(WARNING, "OICR: MDD event");
1291 reg = ICE_READ_REG(hw, GL_MDET_TX_PQM);
1292 if (reg & GL_MDET_TX_PQM_VALID_M) {
1293 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1294 GL_MDET_TX_PQM_PF_NUM_S;
1295 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1296 GL_MDET_TX_PQM_MAL_TYPE_S;
1297 queue = (reg & GL_MDET_TX_PQM_QNUM_M) >>
1298 GL_MDET_TX_PQM_QNUM_S;
1300 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1301 "%d by PQM on TX queue %d PF# %d",
1302 event, queue, pf_num);
1305 reg = ICE_READ_REG(hw, GL_MDET_TX_TCLAN);
1306 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1307 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1308 GL_MDET_TX_TCLAN_PF_NUM_S;
1309 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1310 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1311 queue = (reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1312 GL_MDET_TX_TCLAN_QNUM_S;
1314 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event "
1315 "%d by TCLAN on TX queue %d PF# %d",
1316 event, queue, pf_num);
1320 /* Enable interrupt */
1321 ice_pf_enable_irq0(hw);
1322 rte_intr_ack(dev->intr_handle);
1326 ice_init_proto_xtr(struct rte_eth_dev *dev)
1328 struct ice_adapter *ad =
1329 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1330 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1331 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1332 const struct proto_xtr_ol_flag *ol_flag;
1333 bool proto_xtr_enable = false;
1337 pf->proto_xtr = rte_zmalloc(NULL, pf->lan_nb_qps, 0);
1338 if (unlikely(pf->proto_xtr == NULL)) {
1339 PMD_DRV_LOG(ERR, "No memory for setting up protocol extraction table");
1343 for (i = 0; i < pf->lan_nb_qps; i++) {
1344 pf->proto_xtr[i] = ad->devargs.proto_xtr[i] != PROTO_XTR_NONE ?
1345 ad->devargs.proto_xtr[i] :
1346 ad->devargs.proto_xtr_dflt;
1348 if (pf->proto_xtr[i] != PROTO_XTR_NONE) {
1349 uint8_t type = pf->proto_xtr[i];
1351 ice_proto_xtr_ol_flag_params[type].required = true;
1352 proto_xtr_enable = true;
1356 if (likely(!proto_xtr_enable))
1359 ice_check_proto_xtr_support(hw);
1361 offset = rte_mbuf_dynfield_register(&ice_proto_xtr_metadata_param);
1362 if (unlikely(offset == -1)) {
1364 "Protocol extraction metadata is disabled in mbuf with error %d",
1370 "Protocol extraction metadata offset in mbuf is : %d",
1372 rte_net_ice_dynfield_proto_xtr_metadata_offs = offset;
1374 for (i = 0; i < RTE_DIM(ice_proto_xtr_ol_flag_params); i++) {
1375 ol_flag = &ice_proto_xtr_ol_flag_params[i];
1377 if (!ol_flag->required)
1380 if (!ice_proto_xtr_hw_support[i]) {
1382 "Protocol extraction type %u is not supported in hardware",
1384 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1388 offset = rte_mbuf_dynflag_register(&ol_flag->param);
1389 if (unlikely(offset == -1)) {
1391 "Protocol extraction offload '%s' failed to register with error %d",
1392 ol_flag->param.name, -rte_errno);
1394 rte_net_ice_dynfield_proto_xtr_metadata_offs = -1;
1399 "Protocol extraction offload '%s' offset in mbuf is : %d",
1400 ol_flag->param.name, offset);
1401 *ol_flag->ol_flag = 1ULL << offset;
1405 /* Initialize SW parameters of PF */
1407 ice_pf_sw_init(struct rte_eth_dev *dev)
1409 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1410 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1413 (uint16_t)RTE_MIN(hw->func_caps.common_cap.num_txq,
1414 hw->func_caps.common_cap.num_rxq);
1416 pf->lan_nb_qps = pf->lan_nb_qp_max;
1418 ice_init_proto_xtr(dev);
1420 if (hw->func_caps.fd_fltr_guar > 0 ||
1421 hw->func_caps.fd_fltr_best_effort > 0) {
1422 pf->flags |= ICE_FLAG_FDIR;
1423 pf->fdir_nb_qps = ICE_DEFAULT_QP_NUM_FDIR;
1424 pf->lan_nb_qps = pf->lan_nb_qp_max - pf->fdir_nb_qps;
1426 pf->fdir_nb_qps = 0;
1428 pf->fdir_qp_offset = 0;
1434 ice_setup_vsi(struct ice_pf *pf, enum ice_vsi_type type)
1436 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1437 struct ice_vsi *vsi = NULL;
1438 struct ice_vsi_ctx vsi_ctx;
1440 struct rte_ether_addr broadcast = {
1441 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
1442 struct rte_ether_addr mac_addr;
1443 uint16_t max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1444 uint8_t tc_bitmap = 0x1;
1447 /* hw->num_lports = 1 in NIC mode */
1448 vsi = rte_zmalloc(NULL, sizeof(struct ice_vsi), 0);
1452 vsi->idx = pf->next_vsi_idx;
1455 vsi->adapter = ICE_PF_TO_ADAPTER(pf);
1456 vsi->max_macaddrs = ICE_NUM_MACADDR_MAX;
1457 vsi->vlan_anti_spoof_on = 0;
1458 vsi->vlan_filter_on = 1;
1459 TAILQ_INIT(&vsi->mac_list);
1460 TAILQ_INIT(&vsi->vlan_list);
1462 /* Be sync with ETH_RSS_RETA_SIZE_x maximum value definition */
1463 pf->hash_lut_size = hw->func_caps.common_cap.rss_table_size >
1464 ETH_RSS_RETA_SIZE_512 ? ETH_RSS_RETA_SIZE_512 :
1465 hw->func_caps.common_cap.rss_table_size;
1466 pf->flags |= ICE_FLAG_RSS_AQ_CAPABLE;
1468 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
1471 vsi->nb_qps = pf->lan_nb_qps;
1472 vsi->base_queue = 1;
1473 ice_vsi_config_default_rss(&vsi_ctx.info);
1474 vsi_ctx.alloc_from_pool = true;
1475 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1476 /* switch_id is queried by get_switch_config aq, which is done
1479 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1480 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1481 /* Allow all untagged or tagged packets */
1482 vsi_ctx.info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
1483 vsi_ctx.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
1484 vsi_ctx.info.q_opt_rss = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF |
1485 ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
1486 if (ice_is_dvm_ena(hw)) {
1487 vsi_ctx.info.outer_vlan_flags =
1488 (ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL <<
1489 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_S) &
1490 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M;
1491 vsi_ctx.info.outer_vlan_flags |=
1492 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
1493 ICE_AQ_VSI_OUTER_TAG_TYPE_S) &
1494 ICE_AQ_VSI_OUTER_TAG_TYPE_M;
1498 cfg = ICE_AQ_VSI_PROP_SECURITY_VALID |
1499 ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1500 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1501 cfg = ICE_AQ_VSI_FD_ENABLE;
1502 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1503 vsi_ctx.info.max_fd_fltr_dedicated =
1504 rte_cpu_to_le_16(hw->func_caps.fd_fltr_guar);
1505 vsi_ctx.info.max_fd_fltr_shared =
1506 rte_cpu_to_le_16(hw->func_caps.fd_fltr_best_effort);
1508 /* Enable VLAN/UP trip */
1509 ret = ice_vsi_config_tc_queue_mapping(vsi,
1514 "tc queue mapping with vsi failed, "
1522 vsi->nb_qps = pf->fdir_nb_qps;
1523 vsi->base_queue = ICE_FDIR_QUEUE_ID;
1524 vsi_ctx.alloc_from_pool = true;
1525 vsi_ctx.flags = ICE_AQ_VSI_TYPE_PF;
1527 cfg = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1528 vsi_ctx.info.valid_sections |= rte_cpu_to_le_16(cfg);
1529 cfg = ICE_AQ_VSI_FD_PROG_ENABLE;
1530 vsi_ctx.info.fd_options = rte_cpu_to_le_16(cfg);
1531 vsi_ctx.info.sw_id = hw->port_info->sw_id;
1532 vsi_ctx.info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1533 ret = ice_vsi_config_tc_queue_mapping(vsi,
1538 "tc queue mapping with vsi failed, "
1545 /* for other types of VSI */
1546 PMD_INIT_LOG(ERR, "other types of VSI not supported");
1550 /* VF has MSIX interrupt in VF range, don't allocate here */
1551 if (type == ICE_VSI_PF) {
1552 ret = ice_res_pool_alloc(&pf->msix_pool,
1553 RTE_MIN(vsi->nb_qps,
1554 RTE_MAX_RXTX_INTR_VEC_ID));
1556 PMD_INIT_LOG(ERR, "VSI MAIN %d get heap failed %d",
1559 vsi->msix_intr = ret;
1560 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
1561 } else if (type == ICE_VSI_CTRL) {
1562 ret = ice_res_pool_alloc(&pf->msix_pool, 1);
1564 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d",
1567 vsi->msix_intr = ret;
1573 ret = ice_add_vsi(hw, vsi->idx, &vsi_ctx, NULL);
1574 if (ret != ICE_SUCCESS) {
1575 PMD_INIT_LOG(ERR, "add vsi failed, err = %d", ret);
1578 /* store vsi information is SW structure */
1579 vsi->vsi_id = vsi_ctx.vsi_num;
1580 vsi->info = vsi_ctx.info;
1581 pf->vsis_allocated = vsi_ctx.vsis_allocd;
1582 pf->vsis_unallocated = vsi_ctx.vsis_unallocated;
1584 if (type == ICE_VSI_PF) {
1585 /* MAC configuration */
1586 rte_ether_addr_copy((struct rte_ether_addr *)
1587 hw->port_info->mac.perm_addr,
1590 rte_ether_addr_copy(&pf->dev_addr, &mac_addr);
1591 ret = ice_add_mac_filter(vsi, &mac_addr);
1592 if (ret != ICE_SUCCESS)
1593 PMD_INIT_LOG(ERR, "Failed to add dflt MAC filter");
1595 rte_ether_addr_copy(&broadcast, &mac_addr);
1596 ret = ice_add_mac_filter(vsi, &mac_addr);
1597 if (ret != ICE_SUCCESS)
1598 PMD_INIT_LOG(ERR, "Failed to add MAC filter");
1601 /* At the beginning, only TC0. */
1602 /* What we need here is the maximam number of the TX queues.
1603 * Currently vsi->nb_qps means it.
1604 * Correct it if any change.
1606 max_txqs[0] = vsi->nb_qps;
1607 ret = ice_cfg_vsi_lan(hw->port_info, vsi->idx,
1608 tc_bitmap, max_txqs);
1609 if (ret != ICE_SUCCESS)
1610 PMD_INIT_LOG(ERR, "Failed to config vsi sched");
1620 ice_send_driver_ver(struct ice_hw *hw)
1622 struct ice_driver_ver dv;
1624 /* we don't have driver version use 0 for dummy */
1628 dv.subbuild_ver = 0;
1629 strncpy((char *)dv.driver_string, "dpdk", sizeof(dv.driver_string));
1631 return ice_aq_send_driver_ver(hw, &dv, NULL);
1635 ice_pf_setup(struct ice_pf *pf)
1637 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1638 struct ice_vsi *vsi;
1641 /* Clear all stats counters */
1642 pf->offset_loaded = false;
1643 memset(&pf->stats, 0, sizeof(struct ice_hw_port_stats));
1644 memset(&pf->stats_offset, 0, sizeof(struct ice_hw_port_stats));
1645 memset(&pf->internal_stats, 0, sizeof(struct ice_eth_stats));
1646 memset(&pf->internal_stats_offset, 0, sizeof(struct ice_eth_stats));
1648 /* force guaranteed filter pool for PF */
1649 ice_alloc_fd_guar_item(hw, &unused,
1650 hw->func_caps.fd_fltr_guar);
1651 /* force shared filter pool for PF */
1652 ice_alloc_fd_shrd_item(hw, &unused,
1653 hw->func_caps.fd_fltr_best_effort);
1655 vsi = ice_setup_vsi(pf, ICE_VSI_PF);
1657 PMD_INIT_LOG(ERR, "Failed to add vsi for PF");
1666 static enum ice_pkg_type
1667 ice_load_pkg_type(struct ice_hw *hw)
1669 enum ice_pkg_type package_type;
1671 /* store the activated package type (OS default or Comms) */
1672 if (!strncmp((char *)hw->active_pkg_name, ICE_OS_DEFAULT_PKG_NAME,
1674 package_type = ICE_PKG_TYPE_OS_DEFAULT;
1675 else if (!strncmp((char *)hw->active_pkg_name, ICE_COMMS_PKG_NAME,
1677 package_type = ICE_PKG_TYPE_COMMS;
1679 package_type = ICE_PKG_TYPE_UNKNOWN;
1681 PMD_INIT_LOG(NOTICE, "Active package is: %d.%d.%d.%d, %s (%s VLAN mode)",
1682 hw->active_pkg_ver.major, hw->active_pkg_ver.minor,
1683 hw->active_pkg_ver.update, hw->active_pkg_ver.draft,
1684 hw->active_pkg_name,
1685 ice_is_dvm_ena(hw) ? "double" : "single");
1687 return package_type;
1690 int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)
1692 struct ice_hw *hw = &adapter->hw;
1693 char pkg_file[ICE_MAX_PKG_FILENAME_SIZE];
1694 char opt_ddp_filename[ICE_MAX_PKG_FILENAME_SIZE];
1702 memset(opt_ddp_filename, 0, ICE_MAX_PKG_FILENAME_SIZE);
1703 snprintf(opt_ddp_filename, ICE_MAX_PKG_FILENAME_SIZE,
1704 "ice-%016" PRIx64 ".pkg", dsn);
1705 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_UPDATES,
1706 ICE_MAX_PKG_FILENAME_SIZE);
1707 strcat(pkg_file, opt_ddp_filename);
1708 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1711 strncpy(pkg_file, ICE_PKG_FILE_SEARCH_PATH_DEFAULT,
1712 ICE_MAX_PKG_FILENAME_SIZE);
1713 strcat(pkg_file, opt_ddp_filename);
1714 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1718 strncpy(pkg_file, ICE_PKG_FILE_UPDATES, ICE_MAX_PKG_FILENAME_SIZE);
1719 if (rte_firmware_read(pkg_file, &buf, &bufsz) == 0)
1722 strncpy(pkg_file, ICE_PKG_FILE_DEFAULT, ICE_MAX_PKG_FILENAME_SIZE);
1723 if (rte_firmware_read(pkg_file, &buf, &bufsz) < 0) {
1724 PMD_INIT_LOG(ERR, "failed to search file path\n");
1729 PMD_INIT_LOG(DEBUG, "DDP package name: %s", pkg_file);
1731 err = ice_copy_and_init_pkg(hw, buf, bufsz);
1733 PMD_INIT_LOG(ERR, "ice_copy_and_init_hw failed: %d\n", err);
1737 /* store the loaded pkg type info */
1738 adapter->active_pkg_type = ice_load_pkg_type(hw);
1746 ice_base_queue_get(struct ice_pf *pf)
1749 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1751 reg = ICE_READ_REG(hw, PFLAN_RX_QALLOC);
1752 if (reg & PFLAN_RX_QALLOC_VALID_M) {
1753 pf->base_queue = reg & PFLAN_RX_QALLOC_FIRSTQ_M;
1755 PMD_INIT_LOG(WARNING, "Failed to get Rx base queue"
1761 parse_bool(const char *key, const char *value, void *args)
1763 int *i = (int *)args;
1767 num = strtoul(value, &end, 10);
1769 if (num != 0 && num != 1) {
1770 PMD_DRV_LOG(WARNING, "invalid value:\"%s\" for key:\"%s\", "
1771 "value must be 0 or 1",
1781 parse_u64(const char *key, const char *value, void *args)
1783 u64 *num = (u64 *)args;
1787 tmp = strtoull(value, NULL, 16);
1789 PMD_DRV_LOG(WARNING, "%s: \"%s\" is not a valid u64",
1800 lookup_pps_type(const char *pps_name)
1805 } pps_type_map[] = {
1811 for (i = 0; i < RTE_DIM(pps_type_map); i++) {
1812 if (strcmp(pps_name, pps_type_map[i].name) == 0)
1813 return pps_type_map[i].type;
1820 parse_pin_set(const char *input, int pps_type, struct ice_devargs *devargs)
1822 const char *str = input;
1826 while (isblank(*str))
1832 if (pps_type == PPS_PIN) {
1833 idx = strtoul(str, &end, 10);
1834 if (end == NULL || idx >= ICE_MAX_PIN_NUM)
1837 devargs->pin_idx = idx;
1838 devargs->pps_out_ena = 1;
1841 while (isblank(*end))
1851 parse_pps_out_parameter(const char *pins, struct ice_devargs *devargs)
1853 const char *pin_start;
1858 while (isblank(*pins))
1862 while (isblank(*pins))
1867 for (idx = 0; ; idx++) {
1868 if (isblank(pins[idx]) ||
1873 pps_name[idx] = pins[idx];
1875 pps_name[idx] = '\0';
1876 pps_type = lookup_pps_type(pps_name);
1882 pins += strcspn(pins, ":");
1885 while (isblank(*pins))
1890 while (isblank(*pins))
1893 if (parse_pin_set(pin_start, pps_type, devargs) < 0)
1900 handle_pps_out_arg(__rte_unused const char *key, const char *value,
1903 struct ice_devargs *devargs = extra_args;
1905 if (value == NULL || extra_args == NULL)
1908 if (parse_pps_out_parameter(value, devargs) < 0) {
1910 "The GPIO pin parameter is wrong : '%s'",
1918 static int ice_parse_devargs(struct rte_eth_dev *dev)
1920 struct ice_adapter *ad =
1921 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1922 struct rte_devargs *devargs = dev->device->devargs;
1923 struct rte_kvargs *kvlist;
1926 if (devargs == NULL)
1929 kvlist = rte_kvargs_parse(devargs->args, ice_valid_args);
1930 if (kvlist == NULL) {
1931 PMD_INIT_LOG(ERR, "Invalid kvargs key\n");
1935 ad->devargs.proto_xtr_dflt = PROTO_XTR_NONE;
1936 memset(ad->devargs.proto_xtr, PROTO_XTR_NONE,
1937 sizeof(ad->devargs.proto_xtr));
1939 ret = rte_kvargs_process(kvlist, ICE_PROTO_XTR_ARG,
1940 &handle_proto_xtr_arg, &ad->devargs);
1944 ret = rte_kvargs_process(kvlist, ICE_SAFE_MODE_SUPPORT_ARG,
1945 &parse_bool, &ad->devargs.safe_mode_support);
1949 ret = rte_kvargs_process(kvlist, ICE_PIPELINE_MODE_SUPPORT_ARG,
1950 &parse_bool, &ad->devargs.pipe_mode_support);
1954 ret = rte_kvargs_process(kvlist, ICE_HW_DEBUG_MASK_ARG,
1955 &parse_u64, &ad->hw.debug_mask);
1959 ret = rte_kvargs_process(kvlist, ICE_ONE_PPS_OUT_ARG,
1960 &handle_pps_out_arg, &ad->devargs);
1964 ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG,
1965 &parse_bool, &ad->devargs.rx_low_latency);
1968 rte_kvargs_free(kvlist);
1972 /* Forward LLDP packets to default VSI by set switch rules */
1974 ice_vsi_config_sw_lldp(struct ice_vsi *vsi, bool on)
1976 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
1977 struct ice_fltr_list_entry *s_list_itr = NULL;
1978 struct LIST_HEAD_TYPE list_head;
1981 INIT_LIST_HEAD(&list_head);
1983 s_list_itr = (struct ice_fltr_list_entry *)
1984 ice_malloc(hw, sizeof(*s_list_itr));
1987 s_list_itr->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
1988 s_list_itr->fltr_info.vsi_handle = vsi->idx;
1989 s_list_itr->fltr_info.l_data.ethertype_mac.ethertype =
1990 RTE_ETHER_TYPE_LLDP;
1991 s_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1992 s_list_itr->fltr_info.flag = ICE_FLTR_RX;
1993 s_list_itr->fltr_info.src_id = ICE_SRC_ID_LPORT;
1994 LIST_ADD(&s_list_itr->list_entry, &list_head);
1996 ret = ice_add_eth_mac(hw, &list_head);
1998 ret = ice_remove_eth_mac(hw, &list_head);
2000 rte_free(s_list_itr);
2004 static enum ice_status
2005 ice_get_hw_res(struct ice_hw *hw, uint16_t res_type,
2006 uint16_t num, uint16_t desc_id,
2007 uint16_t *prof_buf, uint16_t *num_prof)
2009 struct ice_aqc_res_elem *resp_buf;
2012 bool res_shared = 1;
2013 struct ice_aq_desc aq_desc;
2014 struct ice_sq_cd *cd = NULL;
2015 struct ice_aqc_get_allocd_res_desc *cmd =
2016 &aq_desc.params.get_res_desc;
2018 buf_len = sizeof(*resp_buf) * num;
2019 resp_buf = ice_malloc(hw, buf_len);
2023 ice_fill_dflt_direct_cmd_desc(&aq_desc,
2024 ice_aqc_opc_get_allocd_res_desc);
2026 cmd->ops.cmd.res = CPU_TO_LE16(((res_type << ICE_AQC_RES_TYPE_S) &
2027 ICE_AQC_RES_TYPE_M) | (res_shared ?
2028 ICE_AQC_RES_TYPE_FLAG_SHARED : 0));
2029 cmd->ops.cmd.first_desc = CPU_TO_LE16(desc_id);
2031 ret = ice_aq_send_cmd(hw, &aq_desc, resp_buf, buf_len, cd);
2033 *num_prof = LE16_TO_CPU(cmd->ops.resp.num_desc);
2037 ice_memcpy(prof_buf, resp_buf, sizeof(*resp_buf) *
2038 (*num_prof), ICE_NONDMA_TO_NONDMA);
2045 ice_cleanup_resource(struct ice_hw *hw, uint16_t res_type)
2049 uint16_t prof_buf[ICE_MAX_RES_DESC_NUM];
2050 uint16_t first_desc = 1;
2051 uint16_t num_prof = 0;
2053 ret = ice_get_hw_res(hw, res_type, ICE_MAX_RES_DESC_NUM,
2054 first_desc, prof_buf, &num_prof);
2056 PMD_INIT_LOG(ERR, "Failed to get fxp resource");
2060 for (prof_id = 0; prof_id < num_prof; prof_id++) {
2061 ret = ice_free_hw_res(hw, res_type, 1, &prof_buf[prof_id]);
2063 PMD_INIT_LOG(ERR, "Failed to free fxp resource");
2071 ice_reset_fxp_resource(struct ice_hw *hw)
2075 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_FD_PROF_BLDR_PROFID);
2077 PMD_INIT_LOG(ERR, "Failed to clearup fdir resource");
2081 ret = ice_cleanup_resource(hw, ICE_AQC_RES_TYPE_HASH_PROF_BLDR_PROFID);
2083 PMD_INIT_LOG(ERR, "Failed to clearup rss resource");
2091 ice_rss_ctx_init(struct ice_pf *pf)
2093 memset(&pf->hash_ctx, 0, sizeof(pf->hash_ctx));
2097 ice_get_supported_rxdid(struct ice_hw *hw)
2099 uint64_t supported_rxdid = 0; /* bitmap for supported RXDID */
2103 supported_rxdid |= BIT(ICE_RXDID_LEGACY_1);
2105 for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
2106 regval = ICE_READ_REG(hw, GLFLXP_RXDID_FLAGS(i, 0));
2107 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
2108 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
2109 supported_rxdid |= BIT(i);
2111 return supported_rxdid;
2115 ice_dev_init(struct rte_eth_dev *dev)
2117 struct rte_pci_device *pci_dev;
2118 struct rte_intr_handle *intr_handle;
2119 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2120 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2121 struct ice_adapter *ad =
2122 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2123 struct ice_vsi *vsi;
2125 #ifndef RTE_EXEC_ENV_WINDOWS
2127 uint32_t dsn_low, dsn_high;
2132 dev->dev_ops = &ice_eth_dev_ops;
2133 dev->rx_queue_count = ice_rx_queue_count;
2134 dev->rx_descriptor_status = ice_rx_descriptor_status;
2135 dev->tx_descriptor_status = ice_tx_descriptor_status;
2136 dev->rx_pkt_burst = ice_recv_pkts;
2137 dev->tx_pkt_burst = ice_xmit_pkts;
2138 dev->tx_pkt_prepare = ice_prep_pkts;
2140 /* for secondary processes, we don't initialise any further as primary
2141 * has already done this work.
2143 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2144 ice_set_rx_function(dev);
2145 ice_set_tx_function(dev);
2149 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2151 ice_set_default_ptype_table(dev);
2152 pci_dev = RTE_DEV_TO_PCI(dev->device);
2153 intr_handle = &pci_dev->intr_handle;
2155 pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2156 pf->dev_data = dev->data;
2157 hw->back = pf->adapter;
2158 hw->hw_addr = (uint8_t *)pci_dev->mem_resource[0].addr;
2159 hw->vendor_id = pci_dev->id.vendor_id;
2160 hw->device_id = pci_dev->id.device_id;
2161 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2162 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2163 hw->bus.device = pci_dev->addr.devid;
2164 hw->bus.func = pci_dev->addr.function;
2166 ret = ice_parse_devargs(dev);
2168 PMD_INIT_LOG(ERR, "Failed to parse devargs");
2172 ice_init_controlq_parameter(hw);
2174 ret = ice_init_hw(hw);
2176 PMD_INIT_LOG(ERR, "Failed to initialize HW");
2180 #ifndef RTE_EXEC_ENV_WINDOWS
2183 pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN);
2185 if (rte_pci_read_config(pci_dev, &dsn_low, 4, pos + 4) < 0 ||
2186 rte_pci_read_config(pci_dev, &dsn_high, 4, pos + 8) < 0) {
2187 PMD_INIT_LOG(ERR, "Failed to read pci config space\n");
2190 dsn = (uint64_t)dsn_high << 32 | dsn_low;
2193 PMD_INIT_LOG(ERR, "Failed to read device serial number\n");
2196 ret = ice_load_pkg(pf->adapter, use_dsn, dsn);
2198 ret = ice_init_hw_tbls(hw);
2200 PMD_INIT_LOG(ERR, "ice_init_hw_tbls failed: %d\n", ret);
2201 rte_free(hw->pkg_copy);
2206 if (ad->devargs.safe_mode_support == 0) {
2207 PMD_INIT_LOG(ERR, "Failed to load the DDP package,"
2208 "Use safe-mode-support=1 to enter Safe Mode");
2212 PMD_INIT_LOG(WARNING, "Failed to load the DDP package,"
2213 "Entering Safe Mode");
2214 ad->is_safe_mode = 1;
2218 PMD_INIT_LOG(INFO, "FW %d.%d.%05d API %d.%d",
2219 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2220 hw->api_maj_ver, hw->api_min_ver);
2222 ice_pf_sw_init(dev);
2223 ret = ice_init_mac_address(dev);
2225 PMD_INIT_LOG(ERR, "Failed to initialize mac address");
2229 ret = ice_res_pool_init(&pf->msix_pool, 1,
2230 hw->func_caps.common_cap.num_msix_vectors - 1);
2232 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
2233 goto err_msix_pool_init;
2236 ret = ice_pf_setup(pf);
2238 PMD_INIT_LOG(ERR, "Failed to setup PF");
2242 ret = ice_send_driver_ver(hw);
2244 PMD_INIT_LOG(ERR, "Failed to send driver version");
2250 ret = ice_aq_stop_lldp(hw, true, false, NULL);
2251 if (ret != ICE_SUCCESS)
2252 PMD_INIT_LOG(DEBUG, "lldp has already stopped\n");
2253 ret = ice_init_dcb(hw, true);
2254 if (ret != ICE_SUCCESS)
2255 PMD_INIT_LOG(DEBUG, "Failed to init DCB\n");
2256 /* Forward LLDP packets to default VSI */
2257 ret = ice_vsi_config_sw_lldp(vsi, true);
2258 if (ret != ICE_SUCCESS)
2259 PMD_INIT_LOG(DEBUG, "Failed to cfg lldp\n");
2260 /* register callback func to eal lib */
2261 rte_intr_callback_register(intr_handle,
2262 ice_interrupt_handler, dev);
2264 ice_pf_enable_irq0(hw);
2266 /* enable uio intr after callback register */
2267 rte_intr_enable(intr_handle);
2269 /* get base queue pairs index in the device */
2270 ice_base_queue_get(pf);
2272 /* Initialize RSS context for gtpu_eh */
2273 ice_rss_ctx_init(pf);
2275 if (!ad->is_safe_mode) {
2276 ret = ice_flow_init(ad);
2278 PMD_INIT_LOG(ERR, "Failed to initialize flow");
2283 ret = ice_reset_fxp_resource(hw);
2285 PMD_INIT_LOG(ERR, "Failed to reset fxp resource");
2289 pf->supported_rxdid = ice_get_supported_rxdid(hw);
2294 ice_flow_uninit(ad);
2295 rte_intr_disable(intr_handle);
2296 ice_pf_disable_irq0(hw);
2297 rte_intr_callback_unregister(intr_handle,
2298 ice_interrupt_handler, dev);
2300 ice_res_pool_destroy(&pf->msix_pool);
2302 rte_free(dev->data->mac_addrs);
2303 dev->data->mac_addrs = NULL;
2305 rte_free(pf->proto_xtr);
2306 #ifndef RTE_EXEC_ENV_WINDOWS
2315 ice_release_vsi(struct ice_vsi *vsi)
2318 struct ice_vsi_ctx vsi_ctx;
2319 enum ice_status ret;
2325 hw = ICE_VSI_TO_HW(vsi);
2327 ice_remove_all_mac_vlan_filters(vsi);
2329 memset(&vsi_ctx, 0, sizeof(vsi_ctx));
2331 vsi_ctx.vsi_num = vsi->vsi_id;
2332 vsi_ctx.info = vsi->info;
2333 ret = ice_free_vsi(hw, vsi->idx, &vsi_ctx, false, NULL);
2334 if (ret != ICE_SUCCESS) {
2335 PMD_INIT_LOG(ERR, "Failed to free vsi by aq, %u", vsi->vsi_id);
2339 rte_free(vsi->rss_lut);
2340 rte_free(vsi->rss_key);
2346 ice_vsi_disable_queues_intr(struct ice_vsi *vsi)
2348 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
2349 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2350 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2351 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
2352 uint16_t msix_intr, i;
2354 /* disable interrupt and also clear all the exist config */
2355 for (i = 0; i < vsi->nb_qps; i++) {
2356 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
2357 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
2361 if (rte_intr_allow_others(intr_handle))
2363 for (i = 0; i < vsi->nb_msix; i++) {
2364 msix_intr = vsi->msix_intr + i;
2365 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
2366 GLINT_DYN_CTL_WB_ON_ITR_M);
2370 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0), GLINT_DYN_CTL_WB_ON_ITR_M);
2374 ice_dev_stop(struct rte_eth_dev *dev)
2376 struct rte_eth_dev_data *data = dev->data;
2377 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2378 struct ice_vsi *main_vsi = pf->main_vsi;
2379 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
2380 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2383 /* avoid stopping again */
2384 if (pf->adapter_stopped)
2387 /* stop and clear all Rx queues */
2388 for (i = 0; i < data->nb_rx_queues; i++)
2389 ice_rx_queue_stop(dev, i);
2391 /* stop and clear all Tx queues */
2392 for (i = 0; i < data->nb_tx_queues; i++)
2393 ice_tx_queue_stop(dev, i);
2395 /* disable all queue interrupts */
2396 ice_vsi_disable_queues_intr(main_vsi);
2398 if (pf->init_link_up)
2399 ice_dev_set_link_up(dev);
2401 ice_dev_set_link_down(dev);
2403 /* Clean datapath event and queue/vec mapping */
2404 rte_intr_efd_disable(intr_handle);
2405 if (intr_handle->intr_vec) {
2406 rte_free(intr_handle->intr_vec);
2407 intr_handle->intr_vec = NULL;
2410 pf->adapter_stopped = true;
2411 dev->data->dev_started = 0;
2417 ice_dev_close(struct rte_eth_dev *dev)
2419 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2420 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2421 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2422 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2423 struct ice_adapter *ad =
2424 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2427 uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
2428 uint32_t pin_idx = ad->devargs.pin_idx;
2430 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2433 /* Since stop will make link down, then the link event will be
2434 * triggered, disable the irq firstly to avoid the port_infoe etc
2435 * resources deallocation causing the interrupt service thread
2438 ice_pf_disable_irq0(hw);
2440 ret = ice_dev_stop(dev);
2442 if (!ad->is_safe_mode)
2443 ice_flow_uninit(ad);
2445 /* release all queue resource */
2446 ice_free_queues(dev);
2448 ice_res_pool_destroy(&pf->msix_pool);
2449 ice_release_vsi(pf->main_vsi);
2450 ice_sched_cleanup_all(hw);
2451 ice_free_hw_tbls(hw);
2452 rte_free(hw->port_info);
2453 hw->port_info = NULL;
2454 ice_shutdown_all_ctrlq(hw);
2455 rte_free(pf->proto_xtr);
2456 pf->proto_xtr = NULL;
2458 if (ad->devargs.pps_out_ena) {
2459 ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(pin_idx, timer), 0);
2460 ICE_WRITE_REG(hw, GLTSYN_CLKO(pin_idx, timer), 0);
2461 ICE_WRITE_REG(hw, GLTSYN_TGT_L(pin_idx, timer), 0);
2462 ICE_WRITE_REG(hw, GLTSYN_TGT_H(pin_idx, timer), 0);
2464 val = GLGEN_GPIO_CTL_PIN_DIR_M;
2465 ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(pin_idx), val);
2468 /* disable uio intr before callback unregister */
2469 rte_intr_disable(intr_handle);
2471 /* unregister callback func from eal lib */
2472 rte_intr_callback_unregister(intr_handle,
2473 ice_interrupt_handler, dev);
2479 ice_dev_uninit(struct rte_eth_dev *dev)
2487 is_hash_cfg_valid(struct ice_rss_hash_cfg *cfg)
2489 return (cfg->hash_flds != 0 && cfg->addl_hdrs != 0) ? true : false;
2493 hash_cfg_reset(struct ice_rss_hash_cfg *cfg)
2498 cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
2502 ice_hash_moveout(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2504 enum ice_status status = ICE_SUCCESS;
2505 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2506 struct ice_vsi *vsi = pf->main_vsi;
2508 if (!is_hash_cfg_valid(cfg))
2511 status = ice_rem_rss_cfg(hw, vsi->idx, cfg);
2512 if (status && status != ICE_ERR_DOES_NOT_EXIST) {
2514 "ice_rem_rss_cfg failed for VSI:%d, error:%d\n",
2523 ice_hash_moveback(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2525 enum ice_status status = ICE_SUCCESS;
2526 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2527 struct ice_vsi *vsi = pf->main_vsi;
2529 if (!is_hash_cfg_valid(cfg))
2532 status = ice_add_rss_cfg(hw, vsi->idx, cfg);
2535 "ice_add_rss_cfg failed for VSI:%d, error:%d\n",
2544 ice_hash_remove(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2548 ret = ice_hash_moveout(pf, cfg);
2549 if (ret && (ret != -ENOENT))
2552 hash_cfg_reset(cfg);
2558 ice_add_rss_cfg_pre_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2564 case ICE_HASH_GTPU_CTX_EH_IP:
2565 ret = ice_hash_remove(pf,
2566 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2567 if (ret && (ret != -ENOENT))
2570 ret = ice_hash_remove(pf,
2571 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2572 if (ret && (ret != -ENOENT))
2575 ret = ice_hash_remove(pf,
2576 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2577 if (ret && (ret != -ENOENT))
2580 ret = ice_hash_remove(pf,
2581 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2582 if (ret && (ret != -ENOENT))
2585 ret = ice_hash_remove(pf,
2586 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2587 if (ret && (ret != -ENOENT))
2590 ret = ice_hash_remove(pf,
2591 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2592 if (ret && (ret != -ENOENT))
2595 ret = ice_hash_remove(pf,
2596 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2597 if (ret && (ret != -ENOENT))
2600 ret = ice_hash_remove(pf,
2601 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2602 if (ret && (ret != -ENOENT))
2606 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2607 ret = ice_hash_remove(pf,
2608 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2609 if (ret && (ret != -ENOENT))
2612 ret = ice_hash_remove(pf,
2613 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2614 if (ret && (ret != -ENOENT))
2617 ret = ice_hash_moveout(pf,
2618 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2619 if (ret && (ret != -ENOENT))
2622 ret = ice_hash_moveout(pf,
2623 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2624 if (ret && (ret != -ENOENT))
2627 ret = ice_hash_moveout(pf,
2628 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2629 if (ret && (ret != -ENOENT))
2632 ret = ice_hash_moveout(pf,
2633 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2634 if (ret && (ret != -ENOENT))
2638 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2639 ret = ice_hash_remove(pf,
2640 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2641 if (ret && (ret != -ENOENT))
2644 ret = ice_hash_remove(pf,
2645 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2646 if (ret && (ret != -ENOENT))
2649 ret = ice_hash_moveout(pf,
2650 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2651 if (ret && (ret != -ENOENT))
2654 ret = ice_hash_moveout(pf,
2655 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2656 if (ret && (ret != -ENOENT))
2659 ret = ice_hash_moveout(pf,
2660 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2661 if (ret && (ret != -ENOENT))
2664 ret = ice_hash_moveout(pf,
2665 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2666 if (ret && (ret != -ENOENT))
2670 case ICE_HASH_GTPU_CTX_UP_IP:
2671 ret = ice_hash_remove(pf,
2672 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2673 if (ret && (ret != -ENOENT))
2676 ret = ice_hash_remove(pf,
2677 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2678 if (ret && (ret != -ENOENT))
2681 ret = ice_hash_moveout(pf,
2682 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2683 if (ret && (ret != -ENOENT))
2686 ret = ice_hash_moveout(pf,
2687 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2688 if (ret && (ret != -ENOENT))
2691 ret = ice_hash_moveout(pf,
2692 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2693 if (ret && (ret != -ENOENT))
2697 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2698 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2699 ret = ice_hash_moveout(pf,
2700 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2701 if (ret && (ret != -ENOENT))
2704 ret = ice_hash_moveout(pf,
2705 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2706 if (ret && (ret != -ENOENT))
2709 ret = ice_hash_moveout(pf,
2710 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2711 if (ret && (ret != -ENOENT))
2715 case ICE_HASH_GTPU_CTX_DW_IP:
2716 ret = ice_hash_remove(pf,
2717 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2718 if (ret && (ret != -ENOENT))
2721 ret = ice_hash_remove(pf,
2722 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2723 if (ret && (ret != -ENOENT))
2726 ret = ice_hash_moveout(pf,
2727 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2728 if (ret && (ret != -ENOENT))
2731 ret = ice_hash_moveout(pf,
2732 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2733 if (ret && (ret != -ENOENT))
2736 ret = ice_hash_moveout(pf,
2737 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2738 if (ret && (ret != -ENOENT))
2742 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2743 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2744 ret = ice_hash_moveout(pf,
2745 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2746 if (ret && (ret != -ENOENT))
2749 ret = ice_hash_moveout(pf,
2750 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2751 if (ret && (ret != -ENOENT))
2754 ret = ice_hash_moveout(pf,
2755 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2756 if (ret && (ret != -ENOENT))
2767 static u8 calc_gtpu_ctx_idx(uint32_t hdr)
2771 if (hdr & ICE_FLOW_SEG_HDR_GTPU_EH)
2773 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_UP)
2775 else if (hdr & ICE_FLOW_SEG_HDR_GTPU_DWN)
2778 return ICE_HASH_GTPU_CTX_MAX;
2781 if (hdr & ICE_FLOW_SEG_HDR_UDP)
2783 else if (hdr & ICE_FLOW_SEG_HDR_TCP)
2786 if (hdr & (ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV6))
2787 return eh_idx * 3 + ip_idx;
2789 return ICE_HASH_GTPU_CTX_MAX;
2793 ice_add_rss_cfg_pre(struct ice_pf *pf, uint32_t hdr)
2795 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2797 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2798 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu4,
2800 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2801 return ice_add_rss_cfg_pre_gtpu(pf, &pf->hash_ctx.gtpu6,
2808 ice_add_rss_cfg_post_gtpu(struct ice_pf *pf, struct ice_hash_gtpu_ctx *ctx,
2809 u8 ctx_idx, struct ice_rss_hash_cfg *cfg)
2813 if (ctx_idx < ICE_HASH_GTPU_CTX_MAX)
2814 ctx->ctx[ctx_idx] = *cfg;
2817 case ICE_HASH_GTPU_CTX_EH_IP:
2819 case ICE_HASH_GTPU_CTX_EH_IP_UDP:
2820 ret = ice_hash_moveback(pf,
2821 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2822 if (ret && (ret != -ENOENT))
2825 ret = ice_hash_moveback(pf,
2826 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_TCP]);
2827 if (ret && (ret != -ENOENT))
2830 ret = ice_hash_moveback(pf,
2831 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2832 if (ret && (ret != -ENOENT))
2835 ret = ice_hash_moveback(pf,
2836 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_TCP]);
2837 if (ret && (ret != -ENOENT))
2841 case ICE_HASH_GTPU_CTX_EH_IP_TCP:
2842 ret = ice_hash_moveback(pf,
2843 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP]);
2844 if (ret && (ret != -ENOENT))
2847 ret = ice_hash_moveback(pf,
2848 &ctx->ctx[ICE_HASH_GTPU_CTX_UP_IP_UDP]);
2849 if (ret && (ret != -ENOENT))
2852 ret = ice_hash_moveback(pf,
2853 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP]);
2854 if (ret && (ret != -ENOENT))
2857 ret = ice_hash_moveback(pf,
2858 &ctx->ctx[ICE_HASH_GTPU_CTX_DW_IP_UDP]);
2859 if (ret && (ret != -ENOENT))
2863 case ICE_HASH_GTPU_CTX_UP_IP:
2864 case ICE_HASH_GTPU_CTX_UP_IP_UDP:
2865 case ICE_HASH_GTPU_CTX_UP_IP_TCP:
2866 case ICE_HASH_GTPU_CTX_DW_IP:
2867 case ICE_HASH_GTPU_CTX_DW_IP_UDP:
2868 case ICE_HASH_GTPU_CTX_DW_IP_TCP:
2869 ret = ice_hash_moveback(pf,
2870 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP]);
2871 if (ret && (ret != -ENOENT))
2874 ret = ice_hash_moveback(pf,
2875 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_UDP]);
2876 if (ret && (ret != -ENOENT))
2879 ret = ice_hash_moveback(pf,
2880 &ctx->ctx[ICE_HASH_GTPU_CTX_EH_IP_TCP]);
2881 if (ret && (ret != -ENOENT))
2893 ice_add_rss_cfg_post(struct ice_pf *pf, struct ice_rss_hash_cfg *cfg)
2895 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(cfg->addl_hdrs);
2897 if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV4)
2898 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu4,
2900 else if (cfg->addl_hdrs & ICE_FLOW_SEG_HDR_IPV6)
2901 return ice_add_rss_cfg_post_gtpu(pf, &pf->hash_ctx.gtpu6,
2908 ice_rem_rss_cfg_post(struct ice_pf *pf, uint32_t hdr)
2910 u8 gtpu_ctx_idx = calc_gtpu_ctx_idx(hdr);
2912 if (gtpu_ctx_idx >= ICE_HASH_GTPU_CTX_MAX)
2915 if (hdr & ICE_FLOW_SEG_HDR_IPV4)
2916 hash_cfg_reset(&pf->hash_ctx.gtpu4.ctx[gtpu_ctx_idx]);
2917 else if (hdr & ICE_FLOW_SEG_HDR_IPV6)
2918 hash_cfg_reset(&pf->hash_ctx.gtpu6.ctx[gtpu_ctx_idx]);
2922 ice_rem_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2923 struct ice_rss_hash_cfg *cfg)
2925 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2928 ret = ice_rem_rss_cfg(hw, vsi_id, cfg);
2929 if (ret && ret != ICE_ERR_DOES_NOT_EXIST)
2930 PMD_DRV_LOG(ERR, "remove rss cfg failed\n");
2932 ice_rem_rss_cfg_post(pf, cfg->addl_hdrs);
2938 ice_add_rss_cfg_wrap(struct ice_pf *pf, uint16_t vsi_id,
2939 struct ice_rss_hash_cfg *cfg)
2941 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2944 ret = ice_add_rss_cfg_pre(pf, cfg->addl_hdrs);
2946 PMD_DRV_LOG(ERR, "add rss cfg pre failed\n");
2948 ret = ice_add_rss_cfg(hw, vsi_id, cfg);
2950 PMD_DRV_LOG(ERR, "add rss cfg failed\n");
2952 ret = ice_add_rss_cfg_post(pf, cfg);
2954 PMD_DRV_LOG(ERR, "add rss cfg post failed\n");
2960 ice_rss_hash_set(struct ice_pf *pf, uint64_t rss_hf)
2962 struct ice_hw *hw = ICE_PF_TO_HW(pf);
2963 struct ice_vsi *vsi = pf->main_vsi;
2964 struct ice_rss_hash_cfg cfg;
2967 #define ICE_RSS_HF_ALL ( \
2970 ETH_RSS_NONFRAG_IPV4_UDP | \
2971 ETH_RSS_NONFRAG_IPV6_UDP | \
2972 ETH_RSS_NONFRAG_IPV4_TCP | \
2973 ETH_RSS_NONFRAG_IPV6_TCP | \
2974 ETH_RSS_NONFRAG_IPV4_SCTP | \
2975 ETH_RSS_NONFRAG_IPV6_SCTP)
2977 ret = ice_rem_vsi_rss_cfg(hw, vsi->idx);
2979 PMD_DRV_LOG(ERR, "%s Remove rss vsi fail %d",
2983 cfg.hdr_type = ICE_RSS_OUTER_HEADERS;
2984 /* Configure RSS for IPv4 with src/dst addr as input set */
2985 if (rss_hf & ETH_RSS_IPV4) {
2986 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2987 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
2988 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
2990 PMD_DRV_LOG(ERR, "%s IPV4 rss flow fail %d",
2994 /* Configure RSS for IPv6 with src/dst addr as input set */
2995 if (rss_hf & ETH_RSS_IPV6) {
2996 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
2997 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
2998 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3000 PMD_DRV_LOG(ERR, "%s IPV6 rss flow fail %d",
3004 /* Configure RSS for udp4 with src/dst addr and port as input set */
3005 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
3006 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4 |
3007 ICE_FLOW_SEG_HDR_IPV_OTHER;
3008 cfg.hash_flds = ICE_HASH_UDP_IPV4;
3009 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3011 PMD_DRV_LOG(ERR, "%s UDP_IPV4 rss flow fail %d",
3015 /* Configure RSS for udp6 with src/dst addr and port as input set */
3016 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) {
3017 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6 |
3018 ICE_FLOW_SEG_HDR_IPV_OTHER;
3019 cfg.hash_flds = ICE_HASH_UDP_IPV6;
3020 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3022 PMD_DRV_LOG(ERR, "%s UDP_IPV6 rss flow fail %d",
3026 /* Configure RSS for tcp4 with src/dst addr and port as input set */
3027 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
3028 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4 |
3029 ICE_FLOW_SEG_HDR_IPV_OTHER;
3030 cfg.hash_flds = ICE_HASH_TCP_IPV4;
3031 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3033 PMD_DRV_LOG(ERR, "%s TCP_IPV4 rss flow fail %d",
3037 /* Configure RSS for tcp6 with src/dst addr and port as input set */
3038 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
3039 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6 |
3040 ICE_FLOW_SEG_HDR_IPV_OTHER;
3041 cfg.hash_flds = ICE_HASH_TCP_IPV6;
3042 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3044 PMD_DRV_LOG(ERR, "%s TCP_IPV6 rss flow fail %d",
3048 /* Configure RSS for sctp4 with src/dst addr and port as input set */
3049 if (rss_hf & ETH_RSS_NONFRAG_IPV4_SCTP) {
3050 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4 |
3051 ICE_FLOW_SEG_HDR_IPV_OTHER;
3052 cfg.hash_flds = ICE_HASH_SCTP_IPV4;
3053 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3055 PMD_DRV_LOG(ERR, "%s SCTP_IPV4 rss flow fail %d",
3059 /* Configure RSS for sctp6 with src/dst addr and port as input set */
3060 if (rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) {
3061 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6 |
3062 ICE_FLOW_SEG_HDR_IPV_OTHER;
3063 cfg.hash_flds = ICE_HASH_SCTP_IPV6;
3064 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3066 PMD_DRV_LOG(ERR, "%s SCTP_IPV6 rss flow fail %d",
3070 if (rss_hf & ETH_RSS_IPV4) {
3071 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV4 |
3072 ICE_FLOW_SEG_HDR_IPV_OTHER;
3073 cfg.hash_flds = ICE_FLOW_HASH_IPV4;
3074 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3076 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4 rss flow fail %d",
3080 if (rss_hf & ETH_RSS_IPV6) {
3081 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_IPV6 |
3082 ICE_FLOW_SEG_HDR_IPV_OTHER;
3083 cfg.hash_flds = ICE_FLOW_HASH_IPV6;
3084 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3086 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6 rss flow fail %d",
3090 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) {
3091 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3092 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3093 cfg.hash_flds = ICE_HASH_UDP_IPV4;
3094 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3096 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_UDP rss flow fail %d",
3100 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) {
3101 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_UDP |
3102 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3103 cfg.hash_flds = ICE_HASH_UDP_IPV6;
3104 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3106 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_UDP rss flow fail %d",
3110 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) {
3111 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3112 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3113 cfg.hash_flds = ICE_HASH_TCP_IPV4;
3114 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3116 PMD_DRV_LOG(ERR, "%s PPPoE_IPV4_TCP rss flow fail %d",
3120 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) {
3121 cfg.addl_hdrs = ICE_FLOW_SEG_HDR_PPPOE | ICE_FLOW_SEG_HDR_TCP |
3122 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER;
3123 cfg.hash_flds = ICE_HASH_TCP_IPV6;
3124 ret = ice_add_rss_cfg_wrap(pf, vsi->idx, &cfg);
3126 PMD_DRV_LOG(ERR, "%s PPPoE_IPV6_TCP rss flow fail %d",
3130 pf->rss_hf = rss_hf & ICE_RSS_HF_ALL;
3134 ice_get_default_rss_key(uint8_t *rss_key, uint32_t rss_key_size)
3136 static struct ice_aqc_get_set_rss_keys default_key;
3137 static bool default_key_done;
3138 uint8_t *key = (uint8_t *)&default_key;
3141 if (rss_key_size > sizeof(default_key)) {
3142 PMD_DRV_LOG(WARNING,
3143 "requested size %u is larger than default %zu, "
3144 "only %zu bytes are gotten for key\n",
3145 rss_key_size, sizeof(default_key),
3146 sizeof(default_key));
3149 if (!default_key_done) {
3150 /* Calculate the default hash key */
3151 for (i = 0; i < sizeof(default_key); i++)
3152 key[i] = (uint8_t)rte_rand();
3153 default_key_done = true;
3155 rte_memcpy(rss_key, key, RTE_MIN(rss_key_size, sizeof(default_key)));
3158 static int ice_init_rss(struct ice_pf *pf)
3160 struct ice_hw *hw = ICE_PF_TO_HW(pf);
3161 struct ice_vsi *vsi = pf->main_vsi;
3162 struct rte_eth_dev_data *dev_data = pf->dev_data;
3163 struct ice_aq_get_set_rss_lut_params lut_params;
3164 struct rte_eth_rss_conf *rss_conf;
3165 struct ice_aqc_get_set_rss_keys key;
3168 bool is_safe_mode = pf->adapter->is_safe_mode;
3171 rss_conf = &dev_data->dev_conf.rx_adv_conf.rss_conf;
3172 nb_q = dev_data->nb_rx_queues;
3173 vsi->rss_key_size = ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE;
3174 vsi->rss_lut_size = pf->hash_lut_size;
3177 PMD_DRV_LOG(WARNING,
3178 "RSS is not supported as rx queues number is zero\n");
3183 PMD_DRV_LOG(WARNING, "RSS is not supported in safe mode\n");
3187 if (!vsi->rss_key) {
3188 vsi->rss_key = rte_zmalloc(NULL,
3189 vsi->rss_key_size, 0);
3190 if (vsi->rss_key == NULL) {
3191 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3195 if (!vsi->rss_lut) {
3196 vsi->rss_lut = rte_zmalloc(NULL,
3197 vsi->rss_lut_size, 0);
3198 if (vsi->rss_lut == NULL) {
3199 PMD_DRV_LOG(ERR, "Failed to allocate memory for rss_key");
3200 rte_free(vsi->rss_key);
3201 vsi->rss_key = NULL;
3205 /* configure RSS key */
3206 if (!rss_conf->rss_key)
3207 ice_get_default_rss_key(vsi->rss_key, vsi->rss_key_size);
3209 rte_memcpy(vsi->rss_key, rss_conf->rss_key,
3210 RTE_MIN(rss_conf->rss_key_len,
3211 vsi->rss_key_size));
3213 rte_memcpy(key.standard_rss_key, vsi->rss_key, vsi->rss_key_size);
3214 ret = ice_aq_set_rss_key(hw, vsi->idx, &key);
3218 /* init RSS LUT table */
3219 for (i = 0; i < vsi->rss_lut_size; i++)
3220 vsi->rss_lut[i] = i % nb_q;
3222 lut_params.vsi_handle = vsi->idx;
3223 lut_params.lut_size = vsi->rss_lut_size;
3224 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
3225 lut_params.lut = vsi->rss_lut;
3226 lut_params.global_lut_id = 0;
3227 ret = ice_aq_set_rss_lut(hw, &lut_params);
3231 /* Enable registers for symmetric_toeplitz function. */
3232 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
3233 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
3234 (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
3235 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
3237 /* RSS hash configuration */
3238 ice_rss_hash_set(pf, rss_conf->rss_hf);
3242 rte_free(vsi->rss_key);
3243 vsi->rss_key = NULL;
3244 rte_free(vsi->rss_lut);
3245 vsi->rss_lut = NULL;
3250 ice_dev_configure(struct rte_eth_dev *dev)
3252 struct ice_adapter *ad =
3253 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3254 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3257 /* Initialize to TRUE. If any of Rx queues doesn't meet the
3258 * bulk allocation or vector Rx preconditions we will reset it.
3260 ad->rx_bulk_alloc_allowed = true;
3261 ad->tx_simple_allowed = true;
3263 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
3264 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
3266 if (dev->data->nb_rx_queues) {
3267 ret = ice_init_rss(pf);
3269 PMD_DRV_LOG(ERR, "Failed to enable rss for PF");
3278 __vsi_queues_bind_intr(struct ice_vsi *vsi, uint16_t msix_vect,
3279 int base_queue, int nb_queue)
3281 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3282 uint32_t val, val_tx;
3283 int rx_low_latency, i;
3285 rx_low_latency = vsi->adapter->devargs.rx_low_latency;
3286 for (i = 0; i < nb_queue; i++) {
3288 val = (msix_vect & QINT_RQCTL_MSIX_INDX_M) |
3289 (0 << QINT_RQCTL_ITR_INDX_S) | QINT_RQCTL_CAUSE_ENA_M;
3290 val_tx = (msix_vect & QINT_TQCTL_MSIX_INDX_M) |
3291 (0 << QINT_TQCTL_ITR_INDX_S) | QINT_TQCTL_CAUSE_ENA_M;
3293 PMD_DRV_LOG(INFO, "queue %d is binding to vect %d",
3294 base_queue + i, msix_vect);
3296 /* set ITR0 value */
3297 if (rx_low_latency) {
3299 * Empirical configuration for optimal real time
3300 * latency reduced interrupt throttling to 2us
3302 ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x1);
3303 ICE_WRITE_REG(hw, QRX_ITR(base_queue + i),
3306 ICE_WRITE_REG(hw, GLINT_ITR(0, msix_vect), 0x2);
3307 ICE_WRITE_REG(hw, QRX_ITR(base_queue + i), 0);
3310 ICE_WRITE_REG(hw, QINT_RQCTL(base_queue + i), val);
3311 ICE_WRITE_REG(hw, QINT_TQCTL(base_queue + i), val_tx);
3316 ice_vsi_queues_bind_intr(struct ice_vsi *vsi)
3318 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3319 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3320 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3321 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3322 uint16_t msix_vect = vsi->msix_intr;
3323 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
3324 uint16_t queue_idx = 0;
3328 /* clear Rx/Tx queue interrupt */
3329 for (i = 0; i < vsi->nb_used_qps; i++) {
3330 ICE_WRITE_REG(hw, QINT_TQCTL(vsi->base_queue + i), 0);
3331 ICE_WRITE_REG(hw, QINT_RQCTL(vsi->base_queue + i), 0);
3334 /* PF bind interrupt */
3335 if (rte_intr_dp_is_en(intr_handle)) {
3340 for (i = 0; i < vsi->nb_used_qps; i++) {
3342 if (!rte_intr_allow_others(intr_handle))
3343 msix_vect = ICE_MISC_VEC_ID;
3345 /* uio mapping all queue to one msix_vect */
3346 __vsi_queues_bind_intr(vsi, msix_vect,
3347 vsi->base_queue + i,
3348 vsi->nb_used_qps - i);
3350 for (; !!record && i < vsi->nb_used_qps; i++)
3351 intr_handle->intr_vec[queue_idx + i] =
3356 /* vfio 1:1 queue/msix_vect mapping */
3357 __vsi_queues_bind_intr(vsi, msix_vect,
3358 vsi->base_queue + i, 1);
3361 intr_handle->intr_vec[queue_idx + i] = msix_vect;
3369 ice_vsi_enable_queues_intr(struct ice_vsi *vsi)
3371 struct rte_eth_dev *dev = &rte_eth_devices[vsi->adapter->pf.dev_data->port_id];
3372 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3373 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3374 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
3375 uint16_t msix_intr, i;
3377 if (rte_intr_allow_others(intr_handle))
3378 for (i = 0; i < vsi->nb_used_qps; i++) {
3379 msix_intr = vsi->msix_intr + i;
3380 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr),
3381 GLINT_DYN_CTL_INTENA_M |
3382 GLINT_DYN_CTL_CLEARPBA_M |
3383 GLINT_DYN_CTL_ITR_INDX_M |
3384 GLINT_DYN_CTL_WB_ON_ITR_M);
3387 ICE_WRITE_REG(hw, GLINT_DYN_CTL(0),
3388 GLINT_DYN_CTL_INTENA_M |
3389 GLINT_DYN_CTL_CLEARPBA_M |
3390 GLINT_DYN_CTL_ITR_INDX_M |
3391 GLINT_DYN_CTL_WB_ON_ITR_M);
3395 ice_rxq_intr_setup(struct rte_eth_dev *dev)
3397 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3398 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
3399 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3400 struct ice_vsi *vsi = pf->main_vsi;
3401 uint32_t intr_vector = 0;
3403 rte_intr_disable(intr_handle);
3405 /* check and configure queue intr-vector mapping */
3406 if ((rte_intr_cap_multiple(intr_handle) ||
3407 !RTE_ETH_DEV_SRIOV(dev).active) &&
3408 dev->data->dev_conf.intr_conf.rxq != 0) {
3409 intr_vector = dev->data->nb_rx_queues;
3410 if (intr_vector > ICE_MAX_INTR_QUEUE_NUM) {
3411 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
3412 ICE_MAX_INTR_QUEUE_NUM);
3415 if (rte_intr_efd_enable(intr_handle, intr_vector))
3419 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3420 intr_handle->intr_vec =
3421 rte_zmalloc(NULL, dev->data->nb_rx_queues * sizeof(int),
3423 if (!intr_handle->intr_vec) {
3425 "Failed to allocate %d rx_queues intr_vec",
3426 dev->data->nb_rx_queues);
3431 /* Map queues with MSIX interrupt */
3432 vsi->nb_used_qps = dev->data->nb_rx_queues;
3433 ice_vsi_queues_bind_intr(vsi);
3435 /* Enable interrupts for all the queues */
3436 ice_vsi_enable_queues_intr(vsi);
3438 rte_intr_enable(intr_handle);
3444 ice_get_init_link_status(struct rte_eth_dev *dev)
3446 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3447 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3448 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3449 struct ice_link_status link_status;
3452 ret = ice_aq_get_link_info(hw->port_info, enable_lse,
3453 &link_status, NULL);
3454 if (ret != ICE_SUCCESS) {
3455 PMD_DRV_LOG(ERR, "Failed to get link info");
3456 pf->init_link_up = false;
3460 if (link_status.link_info & ICE_AQ_LINK_UP)
3461 pf->init_link_up = true;
3465 ice_pps_out_cfg(struct ice_hw *hw, int idx, int timer)
3467 uint64_t current_time, start_time;
3468 uint32_t hi, lo, lo2, func, val;
3470 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3471 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
3472 lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3475 lo = ICE_READ_REG(hw, GLTSYN_TIME_L(timer));
3476 hi = ICE_READ_REG(hw, GLTSYN_TIME_H(timer));
3479 current_time = ((uint64_t)hi << 32) | lo;
3481 start_time = (current_time + NSEC_PER_SEC) /
3482 NSEC_PER_SEC * NSEC_PER_SEC;
3483 start_time = start_time - PPS_OUT_DELAY_NS;
3485 func = 8 + idx + timer * 4;
3486 val = GLGEN_GPIO_CTL_PIN_DIR_M |
3487 ((func << GLGEN_GPIO_CTL_PIN_FUNC_S) &
3488 GLGEN_GPIO_CTL_PIN_FUNC_M);
3490 /* Write clkout with half of period value */
3491 ICE_WRITE_REG(hw, GLTSYN_CLKO(idx, timer), NSEC_PER_SEC / 2);
3493 /* Write TARGET time register */
3494 ICE_WRITE_REG(hw, GLTSYN_TGT_L(idx, timer), start_time & 0xffffffff);
3495 ICE_WRITE_REG(hw, GLTSYN_TGT_H(idx, timer), start_time >> 32);
3497 /* Write AUX_OUT register */
3498 ICE_WRITE_REG(hw, GLTSYN_AUX_OUT(idx, timer),
3499 GLTSYN_AUX_OUT_0_OUT_ENA_M | GLTSYN_AUX_OUT_0_OUTMOD_M);
3501 /* Write GPIO CTL register */
3502 ICE_WRITE_REG(hw, GLGEN_GPIO_CTL(idx), val);
3508 ice_dev_start(struct rte_eth_dev *dev)
3510 struct rte_eth_dev_data *data = dev->data;
3511 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3512 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3513 struct ice_vsi *vsi = pf->main_vsi;
3514 struct ice_adapter *ad =
3515 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3516 uint16_t nb_rxq = 0;
3518 uint16_t max_frame_size;
3520 uint8_t timer = hw->func_caps.ts_func_info.tmr_index_owned;
3521 uint32_t pin_idx = ad->devargs.pin_idx;
3523 /* program Tx queues' context in hardware */
3524 for (nb_txq = 0; nb_txq < data->nb_tx_queues; nb_txq++) {
3525 ret = ice_tx_queue_start(dev, nb_txq);
3527 PMD_DRV_LOG(ERR, "fail to start Tx queue %u", nb_txq);
3532 /* program Rx queues' context in hardware*/
3533 for (nb_rxq = 0; nb_rxq < data->nb_rx_queues; nb_rxq++) {
3534 ret = ice_rx_queue_start(dev, nb_rxq);
3536 PMD_DRV_LOG(ERR, "fail to start Rx queue %u", nb_rxq);
3541 ice_set_rx_function(dev);
3542 ice_set_tx_function(dev);
3544 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
3545 ETH_VLAN_EXTEND_MASK;
3546 ret = ice_vlan_offload_set(dev, mask);
3548 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
3552 /* enable Rx interrput and mapping Rx queue to interrupt vector */
3553 if (ice_rxq_intr_setup(dev))
3556 /* Enable receiving broadcast packets and transmitting packets */
3557 ret = ice_set_vsi_promisc(hw, vsi->idx,
3558 ICE_PROMISC_BCAST_RX | ICE_PROMISC_BCAST_TX |
3559 ICE_PROMISC_UCAST_TX | ICE_PROMISC_MCAST_TX,
3561 if (ret != ICE_SUCCESS)
3562 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
3564 ret = ice_aq_set_event_mask(hw, hw->port_info->lport,
3565 ((u16)(ICE_AQ_LINK_EVENT_LINK_FAULT |
3566 ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM |
3567 ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS |
3568 ICE_AQ_LINK_EVENT_SIGNAL_DETECT |
3569 ICE_AQ_LINK_EVENT_AN_COMPLETED |
3570 ICE_AQ_LINK_EVENT_PORT_TX_SUSPENDED)),
3572 if (ret != ICE_SUCCESS)
3573 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
3575 ice_get_init_link_status(dev);
3577 ice_dev_set_link_up(dev);
3579 /* Call get_link_info aq commond to enable/disable LSE */
3580 ice_link_update(dev, 0);
3582 pf->adapter_stopped = false;
3584 /* Set the max frame size to default value*/
3585 max_frame_size = pf->dev_data->dev_conf.rxmode.max_rx_pkt_len ?
3586 pf->dev_data->dev_conf.rxmode.max_rx_pkt_len :
3589 /* Set the max frame size to HW*/
3590 ice_aq_set_mac_cfg(hw, max_frame_size, NULL);
3592 if (ad->devargs.pps_out_ena) {
3593 ret = ice_pps_out_cfg(hw, pin_idx, timer);
3595 PMD_DRV_LOG(ERR, "Fail to configure 1pps out");
3602 /* stop the started queues if failed to start all queues */
3604 for (i = 0; i < nb_rxq; i++)
3605 ice_rx_queue_stop(dev, i);
3607 for (i = 0; i < nb_txq; i++)
3608 ice_tx_queue_stop(dev, i);
3614 ice_dev_reset(struct rte_eth_dev *dev)
3618 if (dev->data->sriov.active)
3621 ret = ice_dev_uninit(dev);
3623 PMD_INIT_LOG(ERR, "failed to uninit device, status = %d", ret);
3627 ret = ice_dev_init(dev);
3629 PMD_INIT_LOG(ERR, "failed to init device, status = %d", ret);
3637 ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3639 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3640 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3641 struct ice_vsi *vsi = pf->main_vsi;
3642 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3643 bool is_safe_mode = pf->adapter->is_safe_mode;
3647 dev_info->min_rx_bufsize = ICE_BUF_SIZE_MIN;
3648 dev_info->max_rx_pktlen = ICE_FRAME_SIZE_MAX;
3649 dev_info->max_rx_queues = vsi->nb_qps;
3650 dev_info->max_tx_queues = vsi->nb_qps;
3651 dev_info->max_mac_addrs = vsi->max_macaddrs;
3652 dev_info->max_vfs = pci_dev->max_vfs;
3653 dev_info->max_mtu = dev_info->max_rx_pktlen - ICE_ETH_OVERHEAD;
3654 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3656 dev_info->rx_offload_capa =
3657 DEV_RX_OFFLOAD_VLAN_STRIP |
3658 DEV_RX_OFFLOAD_JUMBO_FRAME |
3659 DEV_RX_OFFLOAD_KEEP_CRC |
3660 DEV_RX_OFFLOAD_SCATTER |
3661 DEV_RX_OFFLOAD_VLAN_FILTER;
3662 dev_info->tx_offload_capa =
3663 DEV_TX_OFFLOAD_VLAN_INSERT |
3664 DEV_TX_OFFLOAD_TCP_TSO |
3665 DEV_TX_OFFLOAD_MULTI_SEGS |
3666 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3667 dev_info->flow_type_rss_offloads = 0;
3669 if (!is_safe_mode) {
3670 dev_info->rx_offload_capa |=
3671 DEV_RX_OFFLOAD_IPV4_CKSUM |
3672 DEV_RX_OFFLOAD_UDP_CKSUM |
3673 DEV_RX_OFFLOAD_TCP_CKSUM |
3674 DEV_RX_OFFLOAD_QINQ_STRIP |
3675 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3676 DEV_RX_OFFLOAD_VLAN_EXTEND |
3677 DEV_RX_OFFLOAD_RSS_HASH |
3678 DEV_RX_OFFLOAD_TIMESTAMP;
3679 dev_info->tx_offload_capa |=
3680 DEV_TX_OFFLOAD_QINQ_INSERT |
3681 DEV_TX_OFFLOAD_IPV4_CKSUM |
3682 DEV_TX_OFFLOAD_UDP_CKSUM |
3683 DEV_TX_OFFLOAD_TCP_CKSUM |
3684 DEV_TX_OFFLOAD_SCTP_CKSUM |
3685 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3686 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
3687 dev_info->flow_type_rss_offloads |= ICE_RSS_OFFLOAD_ALL;
3690 dev_info->rx_queue_offload_capa = 0;
3691 dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3693 dev_info->reta_size = pf->hash_lut_size;
3694 dev_info->hash_key_size = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
3696 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3698 .pthresh = ICE_DEFAULT_RX_PTHRESH,
3699 .hthresh = ICE_DEFAULT_RX_HTHRESH,
3700 .wthresh = ICE_DEFAULT_RX_WTHRESH,
3702 .rx_free_thresh = ICE_DEFAULT_RX_FREE_THRESH,
3707 dev_info->default_txconf = (struct rte_eth_txconf) {
3709 .pthresh = ICE_DEFAULT_TX_PTHRESH,
3710 .hthresh = ICE_DEFAULT_TX_HTHRESH,
3711 .wthresh = ICE_DEFAULT_TX_WTHRESH,
3713 .tx_free_thresh = ICE_DEFAULT_TX_FREE_THRESH,
3714 .tx_rs_thresh = ICE_DEFAULT_TX_RSBIT_THRESH,
3718 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3719 .nb_max = ICE_MAX_RING_DESC,
3720 .nb_min = ICE_MIN_RING_DESC,
3721 .nb_align = ICE_ALIGN_RING_DESC,
3724 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3725 .nb_max = ICE_MAX_RING_DESC,
3726 .nb_min = ICE_MIN_RING_DESC,
3727 .nb_align = ICE_ALIGN_RING_DESC,
3730 dev_info->speed_capa = ETH_LINK_SPEED_10M |
3731 ETH_LINK_SPEED_100M |
3733 ETH_LINK_SPEED_2_5G |
3735 ETH_LINK_SPEED_10G |
3736 ETH_LINK_SPEED_20G |
3739 phy_type_low = hw->port_info->phy.phy_type_low;
3740 phy_type_high = hw->port_info->phy.phy_type_high;
3742 if (ICE_PHY_TYPE_SUPPORT_50G(phy_type_low))
3743 dev_info->speed_capa |= ETH_LINK_SPEED_50G;
3745 if (ICE_PHY_TYPE_SUPPORT_100G_LOW(phy_type_low) ||
3746 ICE_PHY_TYPE_SUPPORT_100G_HIGH(phy_type_high))
3747 dev_info->speed_capa |= ETH_LINK_SPEED_100G;
3749 dev_info->nb_rx_queues = dev->data->nb_rx_queues;
3750 dev_info->nb_tx_queues = dev->data->nb_tx_queues;
3752 dev_info->default_rxportconf.burst_size = ICE_RX_MAX_BURST;
3753 dev_info->default_txportconf.burst_size = ICE_TX_MAX_BURST;
3754 dev_info->default_rxportconf.nb_queues = 1;
3755 dev_info->default_txportconf.nb_queues = 1;
3756 dev_info->default_rxportconf.ring_size = ICE_BUF_SIZE_MIN;
3757 dev_info->default_txportconf.ring_size = ICE_BUF_SIZE_MIN;
3763 ice_atomic_read_link_status(struct rte_eth_dev *dev,
3764 struct rte_eth_link *link)
3766 struct rte_eth_link *dst = link;
3767 struct rte_eth_link *src = &dev->data->dev_link;
3769 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3770 *(uint64_t *)src) == 0)
3777 ice_atomic_write_link_status(struct rte_eth_dev *dev,
3778 struct rte_eth_link *link)
3780 struct rte_eth_link *dst = &dev->data->dev_link;
3781 struct rte_eth_link *src = link;
3783 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
3784 *(uint64_t *)src) == 0)
3791 ice_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3793 #define CHECK_INTERVAL 100 /* 100ms */
3794 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3795 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3796 struct ice_link_status link_status;
3797 struct rte_eth_link link, old;
3799 unsigned int rep_cnt = MAX_REPEAT_TIME;
3800 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3802 memset(&link, 0, sizeof(link));
3803 memset(&old, 0, sizeof(old));
3804 memset(&link_status, 0, sizeof(link_status));
3805 ice_atomic_read_link_status(dev, &old);
3808 /* Get link status information from hardware */
3809 status = ice_aq_get_link_info(hw->port_info, enable_lse,
3810 &link_status, NULL);
3811 if (status != ICE_SUCCESS) {
3812 link.link_speed = ETH_SPEED_NUM_100M;
3813 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3814 PMD_DRV_LOG(ERR, "Failed to get link info");
3818 link.link_status = link_status.link_info & ICE_AQ_LINK_UP;
3819 if (!wait_to_complete || link.link_status)
3822 rte_delay_ms(CHECK_INTERVAL);
3823 } while (--rep_cnt);
3825 if (!link.link_status)
3828 /* Full-duplex operation at all supported speeds */
3829 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3831 /* Parse the link status */
3832 switch (link_status.link_speed) {
3833 case ICE_AQ_LINK_SPEED_10MB:
3834 link.link_speed = ETH_SPEED_NUM_10M;
3836 case ICE_AQ_LINK_SPEED_100MB:
3837 link.link_speed = ETH_SPEED_NUM_100M;
3839 case ICE_AQ_LINK_SPEED_1000MB:
3840 link.link_speed = ETH_SPEED_NUM_1G;
3842 case ICE_AQ_LINK_SPEED_2500MB:
3843 link.link_speed = ETH_SPEED_NUM_2_5G;
3845 case ICE_AQ_LINK_SPEED_5GB:
3846 link.link_speed = ETH_SPEED_NUM_5G;
3848 case ICE_AQ_LINK_SPEED_10GB:
3849 link.link_speed = ETH_SPEED_NUM_10G;
3851 case ICE_AQ_LINK_SPEED_20GB:
3852 link.link_speed = ETH_SPEED_NUM_20G;
3854 case ICE_AQ_LINK_SPEED_25GB:
3855 link.link_speed = ETH_SPEED_NUM_25G;
3857 case ICE_AQ_LINK_SPEED_40GB:
3858 link.link_speed = ETH_SPEED_NUM_40G;
3860 case ICE_AQ_LINK_SPEED_50GB:
3861 link.link_speed = ETH_SPEED_NUM_50G;
3863 case ICE_AQ_LINK_SPEED_100GB:
3864 link.link_speed = ETH_SPEED_NUM_100G;
3866 case ICE_AQ_LINK_SPEED_UNKNOWN:
3867 PMD_DRV_LOG(ERR, "Unknown link speed");
3868 link.link_speed = ETH_SPEED_NUM_UNKNOWN;
3871 PMD_DRV_LOG(ERR, "None link speed");
3872 link.link_speed = ETH_SPEED_NUM_NONE;
3876 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3877 ETH_LINK_SPEED_FIXED);
3880 ice_atomic_write_link_status(dev, &link);
3881 if (link.link_status == old.link_status)
3887 /* Force the physical link state by getting the current PHY capabilities from
3888 * hardware and setting the PHY config based on the determined capabilities. If
3889 * link changes, link event will be triggered because both the Enable Automatic
3890 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
3892 static enum ice_status
3893 ice_force_phys_link_state(struct ice_hw *hw, bool link_up)
3895 struct ice_aqc_set_phy_cfg_data cfg = { 0 };
3896 struct ice_aqc_get_phy_caps_data *pcaps;
3897 struct ice_port_info *pi;
3898 enum ice_status status;
3900 if (!hw || !hw->port_info)
3901 return ICE_ERR_PARAM;
3905 pcaps = (struct ice_aqc_get_phy_caps_data *)
3906 ice_malloc(hw, sizeof(*pcaps));
3908 return ICE_ERR_NO_MEMORY;
3910 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG,
3915 /* No change in link */
3916 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
3917 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
3920 cfg.phy_type_low = pcaps->phy_type_low;
3921 cfg.phy_type_high = pcaps->phy_type_high;
3922 cfg.caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3923 cfg.low_power_ctrl_an = pcaps->low_power_ctrl_an;
3924 cfg.eee_cap = pcaps->eee_cap;
3925 cfg.eeer_value = pcaps->eeer_value;
3926 cfg.link_fec_opt = pcaps->link_fec_options;
3928 cfg.caps |= ICE_AQ_PHY_ENA_LINK;
3930 cfg.caps &= ~ICE_AQ_PHY_ENA_LINK;
3932 status = ice_aq_set_phy_cfg(hw, pi, &cfg, NULL);
3935 ice_free(hw, pcaps);
3940 ice_dev_set_link_up(struct rte_eth_dev *dev)
3942 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3944 return ice_force_phys_link_state(hw, true);
3948 ice_dev_set_link_down(struct rte_eth_dev *dev)
3950 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3952 return ice_force_phys_link_state(hw, false);
3956 ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3958 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3959 struct rte_eth_dev_data *dev_data = pf->dev_data;
3960 uint32_t frame_size = mtu + ICE_ETH_OVERHEAD;
3962 /* check if mtu is within the allowed range */
3963 if (mtu < RTE_ETHER_MIN_MTU || frame_size > ICE_FRAME_SIZE_MAX)
3966 /* mtu setting is forbidden if port is start */
3967 if (dev_data->dev_started) {
3969 "port %d must be stopped before configuration",
3974 if (frame_size > ICE_ETH_MAX_LEN)
3975 dev_data->dev_conf.rxmode.offloads |=
3976 DEV_RX_OFFLOAD_JUMBO_FRAME;
3978 dev_data->dev_conf.rxmode.offloads &=
3979 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
3981 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3986 static int ice_macaddr_set(struct rte_eth_dev *dev,
3987 struct rte_ether_addr *mac_addr)
3989 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3990 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3991 struct ice_vsi *vsi = pf->main_vsi;
3992 struct ice_mac_filter *f;
3996 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
3997 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
4001 TAILQ_FOREACH(f, &vsi->mac_list, next) {
4002 if (rte_is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
4007 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
4011 ret = ice_remove_mac_filter(vsi, &f->mac_info.mac_addr);
4012 if (ret != ICE_SUCCESS) {
4013 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
4016 ret = ice_add_mac_filter(vsi, mac_addr);
4017 if (ret != ICE_SUCCESS) {
4018 PMD_DRV_LOG(ERR, "Failed to add mac filter");
4021 rte_ether_addr_copy(mac_addr, &pf->dev_addr);
4023 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
4024 ret = ice_aq_manage_mac_write(hw, mac_addr->addr_bytes, flags, NULL);
4025 if (ret != ICE_SUCCESS)
4026 PMD_DRV_LOG(ERR, "Failed to set manage mac");
4031 /* Add a MAC address, and update filters */
4033 ice_macaddr_add(struct rte_eth_dev *dev,
4034 struct rte_ether_addr *mac_addr,
4035 __rte_unused uint32_t index,
4036 __rte_unused uint32_t pool)
4038 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4039 struct ice_vsi *vsi = pf->main_vsi;
4042 ret = ice_add_mac_filter(vsi, mac_addr);
4043 if (ret != ICE_SUCCESS) {
4044 PMD_DRV_LOG(ERR, "Failed to add MAC filter");
4051 /* Remove a MAC address, and update filters */
4053 ice_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4055 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4056 struct ice_vsi *vsi = pf->main_vsi;
4057 struct rte_eth_dev_data *data = dev->data;
4058 struct rte_ether_addr *macaddr;
4061 macaddr = &data->mac_addrs[index];
4062 ret = ice_remove_mac_filter(vsi, macaddr);
4064 PMD_DRV_LOG(ERR, "Failed to remove MAC filter");
4070 ice_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4072 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4073 struct ice_vlan vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, vlan_id);
4074 struct ice_vsi *vsi = pf->main_vsi;
4077 PMD_INIT_FUNC_TRACE();
4080 * Vlan 0 is the generic filter for untagged packets
4081 * and can't be removed or added by user.
4087 ret = ice_add_vlan_filter(vsi, &vlan);
4089 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
4093 ret = ice_remove_vlan_filter(vsi, &vlan);
4095 PMD_DRV_LOG(ERR, "Failed to remove vlan filter");
4103 /* In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are
4104 * based on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8)
4105 * doesn't matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
4106 * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
4108 * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
4109 * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
4110 * traffic in SVM, since the VLAN TPID isn't part of filtering.
4112 * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
4113 * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
4114 * part of filtering.
4117 ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
4119 struct ice_vlan vlan;
4122 vlan = ICE_VLAN(0, 0);
4123 err = ice_add_vlan_filter(vsi, &vlan);
4125 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0");
4129 /* in SVM both VLAN 0 filters are identical */
4130 if (!ice_is_dvm_ena(&vsi->adapter->hw))
4133 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
4134 err = ice_add_vlan_filter(vsi, &vlan);
4136 PMD_DRV_LOG(DEBUG, "Failed to add VLAN ID 0 in double VLAN mode");
4144 * Delete the VLAN 0 filters in the same manner that they were added in
4145 * ice_vsi_add_vlan_zero.
4148 ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
4150 struct ice_vlan vlan;
4153 vlan = ICE_VLAN(0, 0);
4154 err = ice_remove_vlan_filter(vsi, &vlan);
4156 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0");
4160 /* in SVM both VLAN 0 filters are identical */
4161 if (!ice_is_dvm_ena(&vsi->adapter->hw))
4164 vlan = ICE_VLAN(RTE_ETHER_TYPE_VLAN, 0);
4165 err = ice_remove_vlan_filter(vsi, &vlan);
4167 PMD_DRV_LOG(DEBUG, "Failed to remove VLAN ID 0 in double VLAN mode");
4174 /* Configure vlan filter on or off */
4176 ice_vsi_config_vlan_filter(struct ice_vsi *vsi, bool on)
4178 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4179 struct ice_vsi_ctx ctxt;
4183 sw_flags2 = ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4186 vsi->info.sw_flags2 |= sw_flags2;
4188 vsi->info.sw_flags2 &= ~sw_flags2;
4190 vsi->info.sw_id = hw->port_info->sw_id;
4191 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4192 ctxt.info.valid_sections =
4193 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
4194 ICE_AQ_VSI_PROP_SECURITY_VALID);
4195 ctxt.vsi_num = vsi->vsi_id;
4197 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4199 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan rx pruning",
4200 on ? "enable" : "disable");
4203 vsi->info.valid_sections |=
4204 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_SW_VALID |
4205 ICE_AQ_VSI_PROP_SECURITY_VALID);
4208 /* consist with other drivers, allow untagged packet when vlan filter on */
4210 ret = ice_vsi_add_vlan_zero(vsi);
4212 ret = ice_vsi_del_vlan_zero(vsi);
4217 /* Manage VLAN stripping for the VSI for Rx */
4219 ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
4221 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4222 struct ice_vsi_ctx ctxt;
4223 enum ice_status status;
4226 /* do not allow modifying VLAN stripping when a port VLAN is configured
4229 if (vsi->info.port_based_inner_vlan)
4232 memset(&ctxt, 0, sizeof(ctxt));
4235 /* Strip VLAN tag from Rx packet and put it in the desc */
4236 ctxt.info.inner_vlan_flags =
4237 ICE_AQ_VSI_INNER_VLAN_EMODE_STR_BOTH;
4239 /* Disable stripping. Leave tag in packet */
4240 ctxt.info.inner_vlan_flags =
4241 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4243 /* Allow all packets untagged/tagged */
4244 ctxt.info.inner_vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL;
4246 ctxt.info.valid_sections = rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4248 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4250 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan stripping",
4251 ena ? "enable" : "disable");
4254 vsi->info.inner_vlan_flags = ctxt.info.inner_vlan_flags;
4261 ice_vsi_ena_inner_stripping(struct ice_vsi *vsi)
4263 return ice_vsi_manage_vlan_stripping(vsi, true);
4267 ice_vsi_dis_inner_stripping(struct ice_vsi *vsi)
4269 return ice_vsi_manage_vlan_stripping(vsi, false);
4272 static int ice_vsi_ena_outer_stripping(struct ice_vsi *vsi)
4274 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4275 struct ice_vsi_ctx ctxt;
4276 enum ice_status status;
4279 /* do not allow modifying VLAN stripping when a port VLAN is configured
4282 if (vsi->info.port_based_outer_vlan)
4285 memset(&ctxt, 0, sizeof(ctxt));
4287 ctxt.info.valid_sections =
4288 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4289 /* clear current outer VLAN strip settings */
4290 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4291 ~(ICE_AQ_VSI_OUTER_VLAN_EMODE_M | ICE_AQ_VSI_OUTER_TAG_TYPE_M);
4292 ctxt.info.outer_vlan_flags |=
4293 (ICE_AQ_VSI_OUTER_VLAN_EMODE_SHOW_BOTH <<
4294 ICE_AQ_VSI_OUTER_VLAN_EMODE_S) |
4295 (ICE_AQ_VSI_OUTER_TAG_VLAN_8100 <<
4296 ICE_AQ_VSI_OUTER_TAG_TYPE_S);
4298 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4300 PMD_DRV_LOG(ERR, "Update VSI failed to enable outer VLAN stripping");
4303 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4310 ice_vsi_dis_outer_stripping(struct ice_vsi *vsi)
4312 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4313 struct ice_vsi_ctx ctxt;
4314 enum ice_status status;
4317 if (vsi->info.port_based_outer_vlan)
4320 memset(&ctxt, 0, sizeof(ctxt));
4322 ctxt.info.valid_sections =
4323 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_OUTER_TAG_VALID);
4324 /* clear current outer VLAN strip settings */
4325 ctxt.info.outer_vlan_flags = vsi->info.outer_vlan_flags &
4326 ~ICE_AQ_VSI_OUTER_VLAN_EMODE_M;
4327 ctxt.info.outer_vlan_flags |= ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING <<
4328 ICE_AQ_VSI_OUTER_VLAN_EMODE_S;
4330 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4332 PMD_DRV_LOG(ERR, "Update VSI failed to disable outer VLAN stripping");
4335 vsi->info.outer_vlan_flags = ctxt.info.outer_vlan_flags;
4342 ice_vsi_config_vlan_stripping(struct ice_vsi *vsi, bool ena)
4344 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4347 if (ice_is_dvm_ena(hw)) {
4349 ret = ice_vsi_ena_outer_stripping(vsi);
4351 ret = ice_vsi_dis_outer_stripping(vsi);
4354 ret = ice_vsi_ena_inner_stripping(vsi);
4356 ret = ice_vsi_dis_inner_stripping(vsi);
4363 ice_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4365 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4366 struct ice_vsi *vsi = pf->main_vsi;
4367 struct rte_eth_rxmode *rxmode;
4369 rxmode = &dev->data->dev_conf.rxmode;
4370 if (mask & ETH_VLAN_FILTER_MASK) {
4371 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
4372 ice_vsi_config_vlan_filter(vsi, true);
4374 ice_vsi_config_vlan_filter(vsi, false);
4377 if (mask & ETH_VLAN_STRIP_MASK) {
4378 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
4379 ice_vsi_config_vlan_stripping(vsi, true);
4381 ice_vsi_config_vlan_stripping(vsi, false);
4388 ice_get_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4390 struct ice_aq_get_set_rss_lut_params lut_params;
4391 struct ice_pf *pf = ICE_VSI_TO_PF(vsi);
4392 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4398 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4399 lut_params.vsi_handle = vsi->idx;
4400 lut_params.lut_size = lut_size;
4401 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4402 lut_params.lut = lut;
4403 lut_params.global_lut_id = 0;
4404 ret = ice_aq_get_rss_lut(hw, &lut_params);
4406 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4410 uint64_t *lut_dw = (uint64_t *)lut;
4411 uint16_t i, lut_size_dw = lut_size / 4;
4413 for (i = 0; i < lut_size_dw; i++)
4414 lut_dw[i] = ICE_READ_REG(hw, PFQF_HLUT(i));
4421 ice_set_rss_lut(struct ice_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4423 struct ice_aq_get_set_rss_lut_params lut_params;
4431 pf = ICE_VSI_TO_PF(vsi);
4432 hw = ICE_VSI_TO_HW(vsi);
4434 if (pf->flags & ICE_FLAG_RSS_AQ_CAPABLE) {
4435 lut_params.vsi_handle = vsi->idx;
4436 lut_params.lut_size = lut_size;
4437 lut_params.lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
4438 lut_params.lut = lut;
4439 lut_params.global_lut_id = 0;
4440 ret = ice_aq_set_rss_lut(hw, &lut_params);
4442 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
4446 uint64_t *lut_dw = (uint64_t *)lut;
4447 uint16_t i, lut_size_dw = lut_size / 4;
4449 for (i = 0; i < lut_size_dw; i++)
4450 ICE_WRITE_REG(hw, PFQF_HLUT(i), lut_dw[i]);
4459 ice_rss_reta_update(struct rte_eth_dev *dev,
4460 struct rte_eth_rss_reta_entry64 *reta_conf,
4463 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4464 uint16_t i, lut_size = pf->hash_lut_size;
4465 uint16_t idx, shift;
4469 if (reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_128 &&
4470 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_512 &&
4471 reta_size != ICE_AQC_GSET_RSS_LUT_TABLE_SIZE_2K) {
4473 "The size of hash lookup table configured (%d)"
4474 "doesn't match the number hardware can "
4475 "supported (128, 512, 2048)",
4480 /* It MUST use the current LUT size to get the RSS lookup table,
4481 * otherwise if will fail with -100 error code.
4483 lut = rte_zmalloc(NULL, RTE_MAX(reta_size, lut_size), 0);
4485 PMD_DRV_LOG(ERR, "No memory can be allocated");
4488 ret = ice_get_rss_lut(pf->main_vsi, lut, lut_size);
4492 for (i = 0; i < reta_size; i++) {
4493 idx = i / RTE_RETA_GROUP_SIZE;
4494 shift = i % RTE_RETA_GROUP_SIZE;
4495 if (reta_conf[idx].mask & (1ULL << shift))
4496 lut[i] = reta_conf[idx].reta[shift];
4498 ret = ice_set_rss_lut(pf->main_vsi, lut, reta_size);
4499 if (ret == 0 && lut_size != reta_size) {
4501 "The size of hash lookup table is changed from (%d) to (%d)",
4502 lut_size, reta_size);
4503 pf->hash_lut_size = reta_size;
4513 ice_rss_reta_query(struct rte_eth_dev *dev,
4514 struct rte_eth_rss_reta_entry64 *reta_conf,
4517 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4518 uint16_t i, lut_size = pf->hash_lut_size;
4519 uint16_t idx, shift;
4523 if (reta_size != lut_size) {
4525 "The size of hash lookup table configured (%d)"
4526 "doesn't match the number hardware can "
4528 reta_size, lut_size);
4532 lut = rte_zmalloc(NULL, reta_size, 0);
4534 PMD_DRV_LOG(ERR, "No memory can be allocated");
4538 ret = ice_get_rss_lut(pf->main_vsi, lut, reta_size);
4542 for (i = 0; i < reta_size; i++) {
4543 idx = i / RTE_RETA_GROUP_SIZE;
4544 shift = i % RTE_RETA_GROUP_SIZE;
4545 if (reta_conf[idx].mask & (1ULL << shift))
4546 reta_conf[idx].reta[shift] = lut[i];
4556 ice_set_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t key_len)
4558 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4561 if (!key || key_len == 0) {
4562 PMD_DRV_LOG(DEBUG, "No key to be configured");
4564 } else if (key_len != (VSIQF_HKEY_MAX_INDEX + 1) *
4566 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
4570 struct ice_aqc_get_set_rss_keys *key_dw =
4571 (struct ice_aqc_get_set_rss_keys *)key;
4573 ret = ice_aq_set_rss_key(hw, vsi->idx, key_dw);
4575 PMD_DRV_LOG(ERR, "Failed to configure RSS key via AQ");
4583 ice_get_rss_key(struct ice_vsi *vsi, uint8_t *key, uint8_t *key_len)
4585 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4588 if (!key || !key_len)
4591 ret = ice_aq_get_rss_key
4593 (struct ice_aqc_get_set_rss_keys *)key);
4595 PMD_DRV_LOG(ERR, "Failed to get RSS key via AQ");
4598 *key_len = (VSIQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
4604 ice_rss_hash_update(struct rte_eth_dev *dev,
4605 struct rte_eth_rss_conf *rss_conf)
4607 enum ice_status status = ICE_SUCCESS;
4608 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4609 struct ice_vsi *vsi = pf->main_vsi;
4612 status = ice_set_rss_key(vsi, rss_conf->rss_key, rss_conf->rss_key_len);
4616 if (rss_conf->rss_hf == 0) {
4621 /* RSS hash configuration */
4622 ice_rss_hash_set(pf, rss_conf->rss_hf);
4628 ice_rss_hash_conf_get(struct rte_eth_dev *dev,
4629 struct rte_eth_rss_conf *rss_conf)
4631 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4632 struct ice_vsi *vsi = pf->main_vsi;
4634 ice_get_rss_key(vsi, rss_conf->rss_key,
4635 &rss_conf->rss_key_len);
4637 rss_conf->rss_hf = pf->rss_hf;
4642 ice_promisc_enable(struct rte_eth_dev *dev)
4644 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4645 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4646 struct ice_vsi *vsi = pf->main_vsi;
4647 enum ice_status status;
4651 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4652 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4654 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4656 case ICE_ERR_ALREADY_EXISTS:
4657 PMD_DRV_LOG(DEBUG, "Promisc mode has already been enabled");
4661 PMD_DRV_LOG(ERR, "Failed to enable promisc, err=%d", status);
4669 ice_promisc_disable(struct rte_eth_dev *dev)
4671 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4672 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4673 struct ice_vsi *vsi = pf->main_vsi;
4674 enum ice_status status;
4678 if (dev->data->all_multicast == 1)
4679 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX;
4681 pmask = ICE_PROMISC_UCAST_RX | ICE_PROMISC_UCAST_TX |
4682 ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4684 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4685 if (status != ICE_SUCCESS) {
4686 PMD_DRV_LOG(ERR, "Failed to clear promisc, err=%d", status);
4694 ice_allmulti_enable(struct rte_eth_dev *dev)
4696 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4697 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4698 struct ice_vsi *vsi = pf->main_vsi;
4699 enum ice_status status;
4703 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4705 status = ice_set_vsi_promisc(hw, vsi->idx, pmask, 0);
4708 case ICE_ERR_ALREADY_EXISTS:
4709 PMD_DRV_LOG(DEBUG, "Allmulti has already been enabled");
4713 PMD_DRV_LOG(ERR, "Failed to enable allmulti, err=%d", status);
4721 ice_allmulti_disable(struct rte_eth_dev *dev)
4723 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4724 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4725 struct ice_vsi *vsi = pf->main_vsi;
4726 enum ice_status status;
4730 if (dev->data->promiscuous == 1)
4731 return 0; /* must remain in all_multicast mode */
4733 pmask = ICE_PROMISC_MCAST_RX | ICE_PROMISC_MCAST_TX;
4735 status = ice_clear_vsi_promisc(hw, vsi->idx, pmask, 0);
4736 if (status != ICE_SUCCESS) {
4737 PMD_DRV_LOG(ERR, "Failed to clear allmulti, err=%d", status);
4744 static int ice_rx_queue_intr_enable(struct rte_eth_dev *dev,
4747 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4748 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4749 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4753 msix_intr = intr_handle->intr_vec[queue_id];
4755 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
4756 GLINT_DYN_CTL_ITR_INDX_M;
4757 val &= ~GLINT_DYN_CTL_WB_ON_ITR_M;
4759 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), val);
4760 rte_intr_ack(&pci_dev->intr_handle);
4765 static int ice_rx_queue_intr_disable(struct rte_eth_dev *dev,
4768 struct rte_pci_device *pci_dev = ICE_DEV_TO_PCI(dev);
4769 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4770 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4773 msix_intr = intr_handle->intr_vec[queue_id];
4775 ICE_WRITE_REG(hw, GLINT_DYN_CTL(msix_intr), GLINT_DYN_CTL_WB_ON_ITR_M);
4781 ice_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
4783 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4788 ver = hw->flash.orom.major;
4789 patch = hw->flash.orom.patch;
4790 build = hw->flash.orom.build;
4792 ret = snprintf(fw_version, fw_size,
4793 "%x.%02x 0x%08x %d.%d.%d",
4794 hw->flash.nvm.major,
4795 hw->flash.nvm.minor,
4796 hw->flash.nvm.eetrack,
4801 /* add the size of '\0' */
4803 if (fw_size < (size_t)ret)
4810 ice_vsi_vlan_pvid_set(struct ice_vsi *vsi, struct ice_vsi_vlan_pvid_info *info)
4813 struct ice_vsi_ctx ctxt;
4814 uint8_t vlan_flags = 0;
4817 if (!vsi || !info) {
4818 PMD_DRV_LOG(ERR, "invalid parameters");
4823 vsi->info.port_based_inner_vlan = info->config.pvid;
4825 * If insert pvid is enabled, only tagged pkts are
4826 * allowed to be sent out.
4828 vlan_flags = ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4829 ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4831 vsi->info.port_based_inner_vlan = 0;
4832 if (info->config.reject.tagged == 0)
4833 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTTAGGED;
4835 if (info->config.reject.untagged == 0)
4836 vlan_flags |= ICE_AQ_VSI_INNER_VLAN_TX_MODE_ACCEPTUNTAGGED;
4838 vsi->info.inner_vlan_flags &= ~(ICE_AQ_VSI_INNER_VLAN_INSERT_PVID |
4839 ICE_AQ_VSI_INNER_VLAN_EMODE_M);
4840 vsi->info.inner_vlan_flags |= vlan_flags;
4841 memset(&ctxt, 0, sizeof(ctxt));
4842 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4843 ctxt.info.valid_sections =
4844 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4845 ctxt.vsi_num = vsi->vsi_id;
4847 hw = ICE_VSI_TO_HW(vsi);
4848 ret = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
4849 if (ret != ICE_SUCCESS) {
4851 "update VSI for VLAN insert failed, err %d",
4856 vsi->info.valid_sections |=
4857 rte_cpu_to_le_16(ICE_AQ_VSI_PROP_VLAN_VALID);
4863 ice_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4865 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4866 struct ice_vsi *vsi = pf->main_vsi;
4867 struct rte_eth_dev_data *data = pf->dev_data;
4868 struct ice_vsi_vlan_pvid_info info;
4871 memset(&info, 0, sizeof(info));
4874 info.config.pvid = pvid;
4876 info.config.reject.tagged =
4877 data->dev_conf.txmode.hw_vlan_reject_tagged;
4878 info.config.reject.untagged =
4879 data->dev_conf.txmode.hw_vlan_reject_untagged;
4882 ret = ice_vsi_vlan_pvid_set(vsi, &info);
4884 PMD_DRV_LOG(ERR, "Failed to set pvid.");
4892 ice_get_eeprom_length(struct rte_eth_dev *dev)
4894 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4896 return hw->flash.flash_size;
4900 ice_get_eeprom(struct rte_eth_dev *dev,
4901 struct rte_dev_eeprom_info *eeprom)
4903 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4904 enum ice_status status = ICE_SUCCESS;
4905 uint8_t *data = eeprom->data;
4907 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
4909 status = ice_acquire_nvm(hw, ICE_RES_READ);
4911 PMD_DRV_LOG(ERR, "acquire nvm failed.");
4915 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->length,
4918 ice_release_nvm(hw);
4921 PMD_DRV_LOG(ERR, "EEPROM read failed.");
4929 ice_stat_update_32(struct ice_hw *hw,
4937 new_data = (uint64_t)ICE_READ_REG(hw, reg);
4941 if (new_data >= *offset)
4942 *stat = (uint64_t)(new_data - *offset);
4944 *stat = (uint64_t)((new_data +
4945 ((uint64_t)1 << ICE_32_BIT_WIDTH))
4950 ice_stat_update_40(struct ice_hw *hw,
4959 new_data = (uint64_t)ICE_READ_REG(hw, loreg);
4960 new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
4966 if (new_data >= *offset)
4967 *stat = new_data - *offset;
4969 *stat = (uint64_t)((new_data +
4970 ((uint64_t)1 << ICE_40_BIT_WIDTH)) -
4973 *stat &= ICE_40_BIT_MASK;
4976 /* Get all the statistics of a VSI */
4978 ice_update_vsi_stats(struct ice_vsi *vsi)
4980 struct ice_eth_stats *oes = &vsi->eth_stats_offset;
4981 struct ice_eth_stats *nes = &vsi->eth_stats;
4982 struct ice_hw *hw = ICE_VSI_TO_HW(vsi);
4983 int idx = rte_le_to_cpu_16(vsi->vsi_id);
4985 ice_stat_update_40(hw, GLV_GORCH(idx), GLV_GORCL(idx),
4986 vsi->offset_loaded, &oes->rx_bytes,
4988 ice_stat_update_40(hw, GLV_UPRCH(idx), GLV_UPRCL(idx),
4989 vsi->offset_loaded, &oes->rx_unicast,
4991 ice_stat_update_40(hw, GLV_MPRCH(idx), GLV_MPRCL(idx),
4992 vsi->offset_loaded, &oes->rx_multicast,
4993 &nes->rx_multicast);
4994 ice_stat_update_40(hw, GLV_BPRCH(idx), GLV_BPRCL(idx),
4995 vsi->offset_loaded, &oes->rx_broadcast,
4996 &nes->rx_broadcast);
4997 /* enlarge the limitation when rx_bytes overflowed */
4998 if (vsi->offset_loaded) {
4999 if (ICE_RXTX_BYTES_LOW(vsi->old_rx_bytes) > nes->rx_bytes)
5000 nes->rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5001 nes->rx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_rx_bytes);
5003 vsi->old_rx_bytes = nes->rx_bytes;
5004 /* exclude CRC bytes */
5005 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
5006 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
5008 ice_stat_update_32(hw, GLV_RDPC(idx), vsi->offset_loaded,
5009 &oes->rx_discards, &nes->rx_discards);
5010 /* GLV_REPC not supported */
5011 /* GLV_RMPC not supported */
5012 ice_stat_update_32(hw, GLSWID_RUPP(idx), vsi->offset_loaded,
5013 &oes->rx_unknown_protocol,
5014 &nes->rx_unknown_protocol);
5015 ice_stat_update_40(hw, GLV_GOTCH(idx), GLV_GOTCL(idx),
5016 vsi->offset_loaded, &oes->tx_bytes,
5018 ice_stat_update_40(hw, GLV_UPTCH(idx), GLV_UPTCL(idx),
5019 vsi->offset_loaded, &oes->tx_unicast,
5021 ice_stat_update_40(hw, GLV_MPTCH(idx), GLV_MPTCL(idx),
5022 vsi->offset_loaded, &oes->tx_multicast,
5023 &nes->tx_multicast);
5024 ice_stat_update_40(hw, GLV_BPTCH(idx), GLV_BPTCL(idx),
5025 vsi->offset_loaded, &oes->tx_broadcast,
5026 &nes->tx_broadcast);
5027 /* GLV_TDPC not supported */
5028 ice_stat_update_32(hw, GLV_TEPC(idx), vsi->offset_loaded,
5029 &oes->tx_errors, &nes->tx_errors);
5030 /* enlarge the limitation when tx_bytes overflowed */
5031 if (vsi->offset_loaded) {
5032 if (ICE_RXTX_BYTES_LOW(vsi->old_tx_bytes) > nes->tx_bytes)
5033 nes->tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5034 nes->tx_bytes += ICE_RXTX_BYTES_HIGH(vsi->old_tx_bytes);
5036 vsi->old_tx_bytes = nes->tx_bytes;
5037 vsi->offset_loaded = true;
5039 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats start **************",
5041 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
5042 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
5043 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
5044 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
5045 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
5046 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
5047 nes->rx_unknown_protocol);
5048 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
5049 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
5050 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
5051 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
5052 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
5053 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
5054 PMD_DRV_LOG(DEBUG, "************** VSI[%u] stats end ****************",
5059 ice_read_stats_registers(struct ice_pf *pf, struct ice_hw *hw)
5061 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
5062 struct ice_hw_port_stats *os = &pf->stats_offset; /* old stats */
5064 /* Get statistics of struct ice_eth_stats */
5065 ice_stat_update_40(hw, GLPRT_GORCH(hw->port_info->lport),
5066 GLPRT_GORCL(hw->port_info->lport),
5067 pf->offset_loaded, &os->eth.rx_bytes,
5069 ice_stat_update_40(hw, GLPRT_UPRCH(hw->port_info->lport),
5070 GLPRT_UPRCL(hw->port_info->lport),
5071 pf->offset_loaded, &os->eth.rx_unicast,
5072 &ns->eth.rx_unicast);
5073 ice_stat_update_40(hw, GLPRT_MPRCH(hw->port_info->lport),
5074 GLPRT_MPRCL(hw->port_info->lport),
5075 pf->offset_loaded, &os->eth.rx_multicast,
5076 &ns->eth.rx_multicast);
5077 ice_stat_update_40(hw, GLPRT_BPRCH(hw->port_info->lport),
5078 GLPRT_BPRCL(hw->port_info->lport),
5079 pf->offset_loaded, &os->eth.rx_broadcast,
5080 &ns->eth.rx_broadcast);
5081 ice_stat_update_32(hw, PRTRPB_RDPC,
5082 pf->offset_loaded, &os->eth.rx_discards,
5083 &ns->eth.rx_discards);
5084 /* enlarge the limitation when rx_bytes overflowed */
5085 if (pf->offset_loaded) {
5086 if (ICE_RXTX_BYTES_LOW(pf->old_rx_bytes) > ns->eth.rx_bytes)
5087 ns->eth.rx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5088 ns->eth.rx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_rx_bytes);
5090 pf->old_rx_bytes = ns->eth.rx_bytes;
5092 /* Workaround: CRC size should not be included in byte statistics,
5093 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
5096 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
5097 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
5099 /* GLPRT_REPC not supported */
5100 /* GLPRT_RMPC not supported */
5101 ice_stat_update_32(hw, GLSWID_RUPP(hw->port_info->lport),
5103 &os->eth.rx_unknown_protocol,
5104 &ns->eth.rx_unknown_protocol);
5105 ice_stat_update_40(hw, GLPRT_GOTCH(hw->port_info->lport),
5106 GLPRT_GOTCL(hw->port_info->lport),
5107 pf->offset_loaded, &os->eth.tx_bytes,
5109 ice_stat_update_40(hw, GLPRT_UPTCH(hw->port_info->lport),
5110 GLPRT_UPTCL(hw->port_info->lport),
5111 pf->offset_loaded, &os->eth.tx_unicast,
5112 &ns->eth.tx_unicast);
5113 ice_stat_update_40(hw, GLPRT_MPTCH(hw->port_info->lport),
5114 GLPRT_MPTCL(hw->port_info->lport),
5115 pf->offset_loaded, &os->eth.tx_multicast,
5116 &ns->eth.tx_multicast);
5117 ice_stat_update_40(hw, GLPRT_BPTCH(hw->port_info->lport),
5118 GLPRT_BPTCL(hw->port_info->lport),
5119 pf->offset_loaded, &os->eth.tx_broadcast,
5120 &ns->eth.tx_broadcast);
5121 /* enlarge the limitation when tx_bytes overflowed */
5122 if (pf->offset_loaded) {
5123 if (ICE_RXTX_BYTES_LOW(pf->old_tx_bytes) > ns->eth.tx_bytes)
5124 ns->eth.tx_bytes += (uint64_t)1 << ICE_40_BIT_WIDTH;
5125 ns->eth.tx_bytes += ICE_RXTX_BYTES_HIGH(pf->old_tx_bytes);
5127 pf->old_tx_bytes = ns->eth.tx_bytes;
5128 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
5129 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
5131 /* GLPRT_TEPC not supported */
5133 /* additional port specific stats */
5134 ice_stat_update_32(hw, GLPRT_TDOLD(hw->port_info->lport),
5135 pf->offset_loaded, &os->tx_dropped_link_down,
5136 &ns->tx_dropped_link_down);
5137 ice_stat_update_32(hw, GLPRT_CRCERRS(hw->port_info->lport),
5138 pf->offset_loaded, &os->crc_errors,
5140 ice_stat_update_32(hw, GLPRT_ILLERRC(hw->port_info->lport),
5141 pf->offset_loaded, &os->illegal_bytes,
5142 &ns->illegal_bytes);
5143 /* GLPRT_ERRBC not supported */
5144 ice_stat_update_32(hw, GLPRT_MLFC(hw->port_info->lport),
5145 pf->offset_loaded, &os->mac_local_faults,
5146 &ns->mac_local_faults);
5147 ice_stat_update_32(hw, GLPRT_MRFC(hw->port_info->lport),
5148 pf->offset_loaded, &os->mac_remote_faults,
5149 &ns->mac_remote_faults);
5151 ice_stat_update_32(hw, GLPRT_RLEC(hw->port_info->lport),
5152 pf->offset_loaded, &os->rx_len_errors,
5153 &ns->rx_len_errors);
5155 ice_stat_update_32(hw, GLPRT_LXONRXC(hw->port_info->lport),
5156 pf->offset_loaded, &os->link_xon_rx,
5158 ice_stat_update_32(hw, GLPRT_LXOFFRXC(hw->port_info->lport),
5159 pf->offset_loaded, &os->link_xoff_rx,
5161 ice_stat_update_32(hw, GLPRT_LXONTXC(hw->port_info->lport),
5162 pf->offset_loaded, &os->link_xon_tx,
5164 ice_stat_update_32(hw, GLPRT_LXOFFTXC(hw->port_info->lport),
5165 pf->offset_loaded, &os->link_xoff_tx,
5167 ice_stat_update_40(hw, GLPRT_PRC64H(hw->port_info->lport),
5168 GLPRT_PRC64L(hw->port_info->lport),
5169 pf->offset_loaded, &os->rx_size_64,
5171 ice_stat_update_40(hw, GLPRT_PRC127H(hw->port_info->lport),
5172 GLPRT_PRC127L(hw->port_info->lport),
5173 pf->offset_loaded, &os->rx_size_127,
5175 ice_stat_update_40(hw, GLPRT_PRC255H(hw->port_info->lport),
5176 GLPRT_PRC255L(hw->port_info->lport),
5177 pf->offset_loaded, &os->rx_size_255,
5179 ice_stat_update_40(hw, GLPRT_PRC511H(hw->port_info->lport),
5180 GLPRT_PRC511L(hw->port_info->lport),
5181 pf->offset_loaded, &os->rx_size_511,
5183 ice_stat_update_40(hw, GLPRT_PRC1023H(hw->port_info->lport),
5184 GLPRT_PRC1023L(hw->port_info->lport),
5185 pf->offset_loaded, &os->rx_size_1023,
5187 ice_stat_update_40(hw, GLPRT_PRC1522H(hw->port_info->lport),
5188 GLPRT_PRC1522L(hw->port_info->lport),
5189 pf->offset_loaded, &os->rx_size_1522,
5191 ice_stat_update_40(hw, GLPRT_PRC9522H(hw->port_info->lport),
5192 GLPRT_PRC9522L(hw->port_info->lport),
5193 pf->offset_loaded, &os->rx_size_big,
5195 ice_stat_update_32(hw, GLPRT_RUC(hw->port_info->lport),
5196 pf->offset_loaded, &os->rx_undersize,
5198 ice_stat_update_32(hw, GLPRT_RFC(hw->port_info->lport),
5199 pf->offset_loaded, &os->rx_fragments,
5201 ice_stat_update_32(hw, GLPRT_ROC(hw->port_info->lport),
5202 pf->offset_loaded, &os->rx_oversize,
5204 ice_stat_update_32(hw, GLPRT_RJC(hw->port_info->lport),
5205 pf->offset_loaded, &os->rx_jabber,
5207 ice_stat_update_40(hw, GLPRT_PTC64H(hw->port_info->lport),
5208 GLPRT_PTC64L(hw->port_info->lport),
5209 pf->offset_loaded, &os->tx_size_64,
5211 ice_stat_update_40(hw, GLPRT_PTC127H(hw->port_info->lport),
5212 GLPRT_PTC127L(hw->port_info->lport),
5213 pf->offset_loaded, &os->tx_size_127,
5215 ice_stat_update_40(hw, GLPRT_PTC255H(hw->port_info->lport),
5216 GLPRT_PTC255L(hw->port_info->lport),
5217 pf->offset_loaded, &os->tx_size_255,
5219 ice_stat_update_40(hw, GLPRT_PTC511H(hw->port_info->lport),
5220 GLPRT_PTC511L(hw->port_info->lport),
5221 pf->offset_loaded, &os->tx_size_511,
5223 ice_stat_update_40(hw, GLPRT_PTC1023H(hw->port_info->lport),
5224 GLPRT_PTC1023L(hw->port_info->lport),
5225 pf->offset_loaded, &os->tx_size_1023,
5227 ice_stat_update_40(hw, GLPRT_PTC1522H(hw->port_info->lport),
5228 GLPRT_PTC1522L(hw->port_info->lport),
5229 pf->offset_loaded, &os->tx_size_1522,
5231 ice_stat_update_40(hw, GLPRT_PTC9522H(hw->port_info->lport),
5232 GLPRT_PTC9522L(hw->port_info->lport),
5233 pf->offset_loaded, &os->tx_size_big,
5236 /* GLPRT_MSPDC not supported */
5237 /* GLPRT_XEC not supported */
5239 pf->offset_loaded = true;
5242 ice_update_vsi_stats(pf->main_vsi);
5245 /* Get all statistics of a port */
5247 ice_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
5249 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5250 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5251 struct ice_hw_port_stats *ns = &pf->stats; /* new stats */
5253 /* call read registers - updates values, now write them to struct */
5254 ice_read_stats_registers(pf, hw);
5256 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
5257 pf->main_vsi->eth_stats.rx_multicast +
5258 pf->main_vsi->eth_stats.rx_broadcast -
5259 pf->main_vsi->eth_stats.rx_discards;
5260 stats->opackets = ns->eth.tx_unicast +
5261 ns->eth.tx_multicast +
5262 ns->eth.tx_broadcast;
5263 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
5264 stats->obytes = ns->eth.tx_bytes;
5265 stats->oerrors = ns->eth.tx_errors +
5266 pf->main_vsi->eth_stats.tx_errors;
5269 stats->imissed = ns->eth.rx_discards +
5270 pf->main_vsi->eth_stats.rx_discards;
5271 stats->ierrors = ns->crc_errors +
5273 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
5275 PMD_DRV_LOG(DEBUG, "*************** PF stats start *****************");
5276 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
5277 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
5278 PMD_DRV_LOG(DEBUG, "rx_multicast:%"PRIu64"", ns->eth.rx_multicast);
5279 PMD_DRV_LOG(DEBUG, "rx_broadcast:%"PRIu64"", ns->eth.rx_broadcast);
5280 PMD_DRV_LOG(DEBUG, "rx_discards:%"PRIu64"", ns->eth.rx_discards);
5281 PMD_DRV_LOG(DEBUG, "vsi rx_discards:%"PRIu64"",
5282 pf->main_vsi->eth_stats.rx_discards);
5283 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
5284 ns->eth.rx_unknown_protocol);
5285 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
5286 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
5287 PMD_DRV_LOG(DEBUG, "tx_multicast:%"PRIu64"", ns->eth.tx_multicast);
5288 PMD_DRV_LOG(DEBUG, "tx_broadcast:%"PRIu64"", ns->eth.tx_broadcast);
5289 PMD_DRV_LOG(DEBUG, "tx_discards:%"PRIu64"", ns->eth.tx_discards);
5290 PMD_DRV_LOG(DEBUG, "vsi tx_discards:%"PRIu64"",
5291 pf->main_vsi->eth_stats.tx_discards);
5292 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
5294 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
5295 ns->tx_dropped_link_down);
5296 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
5297 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
5299 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
5300 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
5301 ns->mac_local_faults);
5302 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
5303 ns->mac_remote_faults);
5304 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
5305 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
5306 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
5307 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
5308 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
5309 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
5310 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
5311 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
5312 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
5313 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
5314 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
5315 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
5316 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
5317 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
5318 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
5319 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
5320 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
5321 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
5322 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
5323 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
5324 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
5325 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
5326 PMD_DRV_LOG(DEBUG, "rx_len_errors: %"PRIu64"", ns->rx_len_errors);
5327 PMD_DRV_LOG(DEBUG, "************* PF stats end ****************");
5331 /* Reset the statistics */
5333 ice_stats_reset(struct rte_eth_dev *dev)
5335 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5336 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5338 /* Mark PF and VSI stats to update the offset, aka "reset" */
5339 pf->offset_loaded = false;
5341 pf->main_vsi->offset_loaded = false;
5343 /* read the stats, reading current register values into offset */
5344 ice_read_stats_registers(pf, hw);
5350 ice_xstats_calc_num(void)
5354 num = ICE_NB_ETH_XSTATS + ICE_NB_HW_PORT_XSTATS;
5360 ice_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
5363 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5364 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5367 struct ice_hw_port_stats *hw_stats = &pf->stats;
5369 count = ice_xstats_calc_num();
5373 ice_read_stats_registers(pf, hw);
5380 /* Get stats from ice_eth_stats struct */
5381 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5382 xstats[count].value =
5383 *(uint64_t *)((char *)&hw_stats->eth +
5384 ice_stats_strings[i].offset);
5385 xstats[count].id = count;
5389 /* Get individiual stats from ice_hw_port struct */
5390 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5391 xstats[count].value =
5392 *(uint64_t *)((char *)hw_stats +
5393 ice_hw_port_strings[i].offset);
5394 xstats[count].id = count;
5401 static int ice_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
5402 struct rte_eth_xstat_name *xstats_names,
5403 __rte_unused unsigned int limit)
5405 unsigned int count = 0;
5409 return ice_xstats_calc_num();
5411 /* Note: limit checked in rte_eth_xstats_names() */
5413 /* Get stats from ice_eth_stats struct */
5414 for (i = 0; i < ICE_NB_ETH_XSTATS; i++) {
5415 strlcpy(xstats_names[count].name, ice_stats_strings[i].name,
5416 sizeof(xstats_names[count].name));
5420 /* Get individiual stats from ice_hw_port struct */
5421 for (i = 0; i < ICE_NB_HW_PORT_XSTATS; i++) {
5422 strlcpy(xstats_names[count].name, ice_hw_port_strings[i].name,
5423 sizeof(xstats_names[count].name));
5431 ice_dev_flow_ops_get(struct rte_eth_dev *dev,
5432 const struct rte_flow_ops **ops)
5437 *ops = &ice_flow_ops;
5441 /* Add UDP tunneling port */
5443 ice_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
5444 struct rte_eth_udp_tunnel *udp_tunnel)
5447 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5449 if (udp_tunnel == NULL)
5452 switch (udp_tunnel->prot_type) {
5453 case RTE_TUNNEL_TYPE_VXLAN:
5454 ret = ice_create_tunnel(hw, TNL_VXLAN, udp_tunnel->udp_port);
5457 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5465 /* Delete UDP tunneling port */
5467 ice_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
5468 struct rte_eth_udp_tunnel *udp_tunnel)
5471 struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5473 if (udp_tunnel == NULL)
5476 switch (udp_tunnel->prot_type) {
5477 case RTE_TUNNEL_TYPE_VXLAN:
5478 ret = ice_destroy_tunnel(hw, udp_tunnel->udp_port, 0);
5481 PMD_DRV_LOG(ERR, "Invalid tunnel type");
5490 ice_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
5491 struct rte_pci_device *pci_dev)
5493 return rte_eth_dev_pci_generic_probe(pci_dev,
5494 sizeof(struct ice_adapter),
5499 ice_pci_remove(struct rte_pci_device *pci_dev)
5501 return rte_eth_dev_pci_generic_remove(pci_dev, ice_dev_uninit);
5504 static struct rte_pci_driver rte_ice_pmd = {
5505 .id_table = pci_id_ice_map,
5506 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
5507 .probe = ice_pci_probe,
5508 .remove = ice_pci_remove,
5512 * Driver initialization routine.
5513 * Invoked once at EAL init time.
5514 * Register itself as the [Poll Mode] Driver of PCI devices.
5516 RTE_PMD_REGISTER_PCI(net_ice, rte_ice_pmd);
5517 RTE_PMD_REGISTER_PCI_TABLE(net_ice, pci_id_ice_map);
5518 RTE_PMD_REGISTER_KMOD_DEP(net_ice, "* igb_uio | uio_pci_generic | vfio-pci");
5519 RTE_PMD_REGISTER_PARAM_STRING(net_ice,
5520 ICE_HW_DEBUG_MASK_ARG "=0xXXX"
5521 ICE_PROTO_XTR_ARG "=[queue:]<vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset>"
5522 ICE_SAFE_MODE_SUPPORT_ARG "=<0|1>"
5523 ICE_PIPELINE_MODE_SUPPORT_ARG "=<0|1>"
5524 ICE_RX_LOW_LATENCY_ARG "=<0|1>");
5526 RTE_LOG_REGISTER_SUFFIX(ice_logtype_init, init, NOTICE);
5527 RTE_LOG_REGISTER_SUFFIX(ice_logtype_driver, driver, NOTICE);
5528 #ifdef RTE_ETHDEV_DEBUG_RX
5529 RTE_LOG_REGISTER_SUFFIX(ice_logtype_rx, rx, DEBUG);
5531 #ifdef RTE_ETHDEV_DEBUG_TX
5532 RTE_LOG_REGISTER_SUFFIX(ice_logtype_tx, tx, DEBUG);