1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
13 #include <rte_byteorder.h>
14 #include <rte_common.h>
16 #include <rte_interrupts.h>
17 #include <rte_debug.h>
19 #include <rte_atomic.h>
21 #include <rte_ether.h>
22 #include <ethdev_driver.h>
23 #include <ethdev_pci.h>
24 #include <rte_malloc.h>
25 #include <rte_memzone.h>
29 #include "iavf_rxtx.h"
30 #include "iavf_generic_flow.h"
31 #include "rte_pmd_iavf.h"
34 #define IAVF_PROTO_XTR_ARG "proto_xtr"
36 static const char * const iavf_valid_args[] = {
41 static const struct rte_mbuf_dynfield iavf_proto_xtr_metadata_param = {
42 .name = "intel_pmd_dynfield_proto_xtr_metadata",
43 .size = sizeof(uint32_t),
44 .align = __alignof__(uint32_t),
48 struct iavf_proto_xtr_ol {
49 const struct rte_mbuf_dynflag param;
54 static struct iavf_proto_xtr_ol iavf_proto_xtr_params[] = {
55 [IAVF_PROTO_XTR_VLAN] = {
56 .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
57 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_vlan_mask },
58 [IAVF_PROTO_XTR_IPV4] = {
59 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
60 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask },
61 [IAVF_PROTO_XTR_IPV6] = {
62 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
63 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask },
64 [IAVF_PROTO_XTR_IPV6_FLOW] = {
65 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
66 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask },
67 [IAVF_PROTO_XTR_TCP] = {
68 .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
69 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_tcp_mask },
70 [IAVF_PROTO_XTR_IP_OFFSET] = {
71 .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
72 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask },
75 static int iavf_dev_configure(struct rte_eth_dev *dev);
76 static int iavf_dev_start(struct rte_eth_dev *dev);
77 static int iavf_dev_stop(struct rte_eth_dev *dev);
78 static int iavf_dev_close(struct rte_eth_dev *dev);
79 static int iavf_dev_reset(struct rte_eth_dev *dev);
80 static int iavf_dev_info_get(struct rte_eth_dev *dev,
81 struct rte_eth_dev_info *dev_info);
82 static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev);
83 static int iavf_dev_stats_get(struct rte_eth_dev *dev,
84 struct rte_eth_stats *stats);
85 static int iavf_dev_stats_reset(struct rte_eth_dev *dev);
86 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
87 struct rte_eth_xstat *xstats, unsigned int n);
88 static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev,
89 struct rte_eth_xstat_name *xstats_names,
91 static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
92 static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
93 static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
94 static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
95 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
96 struct rte_ether_addr *addr,
99 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
100 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
101 uint16_t vlan_id, int on);
102 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
103 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
104 struct rte_eth_rss_reta_entry64 *reta_conf,
106 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
107 struct rte_eth_rss_reta_entry64 *reta_conf,
109 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
110 struct rte_eth_rss_conf *rss_conf);
111 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
112 struct rte_eth_rss_conf *rss_conf);
113 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
114 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
115 struct rte_ether_addr *mac_addr);
116 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
118 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
120 static int iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
121 const struct rte_flow_ops **ops);
122 static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
123 struct rte_ether_addr *mc_addrs,
124 uint32_t mc_addrs_num);
126 static const struct rte_pci_id pci_id_iavf_map[] = {
127 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
128 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF) },
129 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF_HV) },
130 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_VF) },
131 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_A0_VF) },
132 { .vendor_id = 0, /* sentinel */ },
135 struct rte_iavf_xstats_name_off {
136 char name[RTE_ETH_XSTATS_NAME_SIZE];
140 static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = {
141 {"rx_bytes", offsetof(struct iavf_eth_stats, rx_bytes)},
142 {"rx_unicast_packets", offsetof(struct iavf_eth_stats, rx_unicast)},
143 {"rx_multicast_packets", offsetof(struct iavf_eth_stats, rx_multicast)},
144 {"rx_broadcast_packets", offsetof(struct iavf_eth_stats, rx_broadcast)},
145 {"rx_dropped_packets", offsetof(struct iavf_eth_stats, rx_discards)},
146 {"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats,
147 rx_unknown_protocol)},
148 {"tx_bytes", offsetof(struct iavf_eth_stats, tx_bytes)},
149 {"tx_unicast_packets", offsetof(struct iavf_eth_stats, tx_unicast)},
150 {"tx_multicast_packets", offsetof(struct iavf_eth_stats, tx_multicast)},
151 {"tx_broadcast_packets", offsetof(struct iavf_eth_stats, tx_broadcast)},
152 {"tx_dropped_packets", offsetof(struct iavf_eth_stats, tx_discards)},
153 {"tx_error_packets", offsetof(struct iavf_eth_stats, tx_errors)},
156 #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
157 sizeof(rte_iavf_stats_strings[0]))
159 static const struct eth_dev_ops iavf_eth_dev_ops = {
160 .dev_configure = iavf_dev_configure,
161 .dev_start = iavf_dev_start,
162 .dev_stop = iavf_dev_stop,
163 .dev_close = iavf_dev_close,
164 .dev_reset = iavf_dev_reset,
165 .dev_infos_get = iavf_dev_info_get,
166 .dev_supported_ptypes_get = iavf_dev_supported_ptypes_get,
167 .link_update = iavf_dev_link_update,
168 .stats_get = iavf_dev_stats_get,
169 .stats_reset = iavf_dev_stats_reset,
170 .xstats_get = iavf_dev_xstats_get,
171 .xstats_get_names = iavf_dev_xstats_get_names,
172 .xstats_reset = iavf_dev_stats_reset,
173 .promiscuous_enable = iavf_dev_promiscuous_enable,
174 .promiscuous_disable = iavf_dev_promiscuous_disable,
175 .allmulticast_enable = iavf_dev_allmulticast_enable,
176 .allmulticast_disable = iavf_dev_allmulticast_disable,
177 .mac_addr_add = iavf_dev_add_mac_addr,
178 .mac_addr_remove = iavf_dev_del_mac_addr,
179 .set_mc_addr_list = iavf_set_mc_addr_list,
180 .vlan_filter_set = iavf_dev_vlan_filter_set,
181 .vlan_offload_set = iavf_dev_vlan_offload_set,
182 .rx_queue_start = iavf_dev_rx_queue_start,
183 .rx_queue_stop = iavf_dev_rx_queue_stop,
184 .tx_queue_start = iavf_dev_tx_queue_start,
185 .tx_queue_stop = iavf_dev_tx_queue_stop,
186 .rx_queue_setup = iavf_dev_rx_queue_setup,
187 .rx_queue_release = iavf_dev_rx_queue_release,
188 .tx_queue_setup = iavf_dev_tx_queue_setup,
189 .tx_queue_release = iavf_dev_tx_queue_release,
190 .mac_addr_set = iavf_dev_set_default_mac_addr,
191 .reta_update = iavf_dev_rss_reta_update,
192 .reta_query = iavf_dev_rss_reta_query,
193 .rss_hash_update = iavf_dev_rss_hash_update,
194 .rss_hash_conf_get = iavf_dev_rss_hash_conf_get,
195 .rxq_info_get = iavf_dev_rxq_info_get,
196 .txq_info_get = iavf_dev_txq_info_get,
197 .mtu_set = iavf_dev_mtu_set,
198 .rx_queue_intr_enable = iavf_dev_rx_queue_intr_enable,
199 .rx_queue_intr_disable = iavf_dev_rx_queue_intr_disable,
200 .flow_ops_get = iavf_dev_flow_ops_get,
201 .tx_done_cleanup = iavf_dev_tx_done_cleanup,
202 .get_monitor_addr = iavf_get_monitor_addr,
206 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
207 struct rte_ether_addr *mc_addrs,
208 uint32_t mc_addrs_num)
210 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
211 struct iavf_adapter *adapter =
212 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
215 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
217 "can't add more than a limited number (%u) of addresses.",
218 (uint32_t)IAVF_NUM_MACADDR_MAX);
222 /* flush previous addresses */
223 err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
229 err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
232 /* if adding mac address list fails, should add the previous
235 ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
236 vf->mc_addrs_num, true);
240 vf->mc_addrs_num = mc_addrs_num;
242 mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
249 iavf_config_rss_hf(struct iavf_adapter *adapter, uint64_t rss_hf)
251 static const uint64_t map_hena_rss[] = {
253 [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
254 ETH_RSS_NONFRAG_IPV4_UDP,
255 [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
256 ETH_RSS_NONFRAG_IPV4_UDP,
257 [IAVF_FILTER_PCTYPE_NONF_IPV4_UDP] =
258 ETH_RSS_NONFRAG_IPV4_UDP,
259 [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
260 ETH_RSS_NONFRAG_IPV4_TCP,
261 [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP] =
262 ETH_RSS_NONFRAG_IPV4_TCP,
263 [IAVF_FILTER_PCTYPE_NONF_IPV4_SCTP] =
264 ETH_RSS_NONFRAG_IPV4_SCTP,
265 [IAVF_FILTER_PCTYPE_NONF_IPV4_OTHER] =
266 ETH_RSS_NONFRAG_IPV4_OTHER,
267 [IAVF_FILTER_PCTYPE_FRAG_IPV4] = ETH_RSS_FRAG_IPV4,
270 [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
271 ETH_RSS_NONFRAG_IPV6_UDP,
272 [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
273 ETH_RSS_NONFRAG_IPV6_UDP,
274 [IAVF_FILTER_PCTYPE_NONF_IPV6_UDP] =
275 ETH_RSS_NONFRAG_IPV6_UDP,
276 [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
277 ETH_RSS_NONFRAG_IPV6_TCP,
278 [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP] =
279 ETH_RSS_NONFRAG_IPV6_TCP,
280 [IAVF_FILTER_PCTYPE_NONF_IPV6_SCTP] =
281 ETH_RSS_NONFRAG_IPV6_SCTP,
282 [IAVF_FILTER_PCTYPE_NONF_IPV6_OTHER] =
283 ETH_RSS_NONFRAG_IPV6_OTHER,
284 [IAVF_FILTER_PCTYPE_FRAG_IPV6] = ETH_RSS_FRAG_IPV6,
287 [IAVF_FILTER_PCTYPE_L2_PAYLOAD] = ETH_RSS_L2_PAYLOAD
290 const uint64_t ipv4_rss = ETH_RSS_NONFRAG_IPV4_UDP |
291 ETH_RSS_NONFRAG_IPV4_TCP |
292 ETH_RSS_NONFRAG_IPV4_SCTP |
293 ETH_RSS_NONFRAG_IPV4_OTHER |
296 const uint64_t ipv6_rss = ETH_RSS_NONFRAG_IPV6_UDP |
297 ETH_RSS_NONFRAG_IPV6_TCP |
298 ETH_RSS_NONFRAG_IPV6_SCTP |
299 ETH_RSS_NONFRAG_IPV6_OTHER |
302 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
303 uint64_t caps = 0, hena = 0, valid_rss_hf = 0;
307 ret = iavf_get_hena_caps(adapter, &caps);
311 * ETH_RSS_IPV4 and ETH_RSS_IPV6 can be considered as 2
312 * generalizations of all other IPv4 and IPv6 RSS types.
314 if (rss_hf & ETH_RSS_IPV4)
317 if (rss_hf & ETH_RSS_IPV6)
320 RTE_BUILD_BUG_ON(RTE_DIM(map_hena_rss) > sizeof(uint64_t) * CHAR_BIT);
322 for (i = 0; i < RTE_DIM(map_hena_rss); i++) {
323 uint64_t bit = BIT_ULL(i);
325 if ((caps & bit) && (map_hena_rss[i] & rss_hf)) {
326 valid_rss_hf |= map_hena_rss[i];
331 ret = iavf_set_hena(adapter, hena);
335 if (valid_rss_hf & ipv4_rss)
336 valid_rss_hf |= rss_hf & ETH_RSS_IPV4;
338 if (valid_rss_hf & ipv6_rss)
339 valid_rss_hf |= rss_hf & ETH_RSS_IPV6;
341 if (rss_hf & ~valid_rss_hf)
342 PMD_DRV_LOG(WARNING, "Unsupported rss_hf 0x%" PRIx64,
343 rss_hf & ~valid_rss_hf);
345 vf->rss_hf = valid_rss_hf;
350 iavf_init_rss(struct iavf_adapter *adapter)
352 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
353 struct rte_eth_rss_conf *rss_conf;
357 rss_conf = &adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
358 nb_q = RTE_MIN(adapter->eth_dev->data->nb_rx_queues,
359 vf->max_rss_qregion);
361 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
362 PMD_DRV_LOG(DEBUG, "RSS is not supported");
366 /* configure RSS key */
367 if (!rss_conf->rss_key) {
368 /* Calculate the default hash key */
369 for (i = 0; i <= vf->vf_res->rss_key_size; i++)
370 vf->rss_key[i] = (uint8_t)rte_rand();
372 rte_memcpy(vf->rss_key, rss_conf->rss_key,
373 RTE_MIN(rss_conf->rss_key_len,
374 vf->vf_res->rss_key_size));
376 /* init RSS LUT table */
377 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
382 /* send virtchnnl ops to configure rss*/
383 ret = iavf_configure_rss_lut(adapter);
386 ret = iavf_configure_rss_key(adapter);
390 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
391 /* Set RSS hash configuration based on rss_conf->rss_hf. */
392 ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
394 PMD_DRV_LOG(ERR, "fail to set default RSS");
398 ret = iavf_config_rss_hf(adapter, rss_conf->rss_hf);
407 iavf_queues_req_reset(struct rte_eth_dev *dev, uint16_t num)
409 struct iavf_adapter *ad =
410 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
411 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
414 ret = iavf_request_queues(ad, num);
416 PMD_DRV_LOG(ERR, "request queues from PF failed");
419 PMD_DRV_LOG(INFO, "change queue pairs from %u to %u",
420 vf->vsi_res->num_queue_pairs, num);
422 ret = iavf_dev_reset(dev);
424 PMD_DRV_LOG(ERR, "vf reset failed");
432 iavf_dev_vlan_insert_set(struct rte_eth_dev *dev)
434 struct iavf_adapter *adapter =
435 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
436 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
439 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2))
442 enable = !!(dev->data->dev_conf.txmode.offloads &
443 DEV_TX_OFFLOAD_VLAN_INSERT);
444 iavf_config_vlan_insert_v2(adapter, enable);
450 iavf_dev_init_vlan(struct rte_eth_dev *dev)
454 err = iavf_dev_vlan_offload_set(dev,
455 ETH_VLAN_STRIP_MASK |
456 ETH_QINQ_STRIP_MASK |
457 ETH_VLAN_FILTER_MASK |
458 ETH_VLAN_EXTEND_MASK);
460 PMD_DRV_LOG(ERR, "Failed to update vlan offload");
464 err = iavf_dev_vlan_insert_set(dev);
466 PMD_DRV_LOG(ERR, "Failed to update vlan insertion");
472 iavf_dev_configure(struct rte_eth_dev *dev)
474 struct iavf_adapter *ad =
475 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
476 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
477 uint16_t num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
478 dev->data->nb_tx_queues);
481 ad->rx_bulk_alloc_allowed = true;
482 /* Initialize to TRUE. If any of Rx queues doesn't meet the
483 * vector Rx/Tx preconditions, it will be reset.
485 ad->rx_vec_allowed = true;
486 ad->tx_vec_allowed = true;
488 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
489 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
491 /* Large VF setting */
492 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT) {
493 if (!(vf->vf_res->vf_cap_flags &
494 VIRTCHNL_VF_LARGE_NUM_QPAIRS)) {
495 PMD_DRV_LOG(ERR, "large VF is not supported");
499 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_LV) {
500 PMD_DRV_LOG(ERR, "queue pairs number cannot be larger than %u",
501 IAVF_MAX_NUM_QUEUES_LV);
505 ret = iavf_queues_req_reset(dev, num_queue_pairs);
509 ret = iavf_get_max_rss_queue_region(ad);
511 PMD_INIT_LOG(ERR, "get max rss queue region failed");
515 vf->lv_enabled = true;
517 /* Check if large VF is already enabled. If so, disable and
518 * release redundant queue resource.
519 * Or check if enough queue pairs. If not, request them from PF.
521 if (vf->lv_enabled ||
522 num_queue_pairs > vf->vsi_res->num_queue_pairs) {
523 ret = iavf_queues_req_reset(dev, num_queue_pairs);
527 vf->lv_enabled = false;
529 /* if large VF is not required, use default rss queue region */
530 vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
533 ret = iavf_dev_init_vlan(dev);
535 PMD_DRV_LOG(ERR, "configure VLAN failed: %d", ret);
537 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
538 if (iavf_init_rss(ad) != 0) {
539 PMD_DRV_LOG(ERR, "configure rss failed");
547 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
549 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
550 struct rte_eth_dev_data *dev_data = dev->data;
551 uint16_t buf_size, max_pkt_len, len;
553 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
555 /* Calculate the maximum packet length allowed */
556 len = rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS;
557 max_pkt_len = RTE_MIN(len, dev->data->dev_conf.rxmode.max_rx_pkt_len);
559 /* Check if the jumbo frame and maximum packet length are set
562 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
563 if (max_pkt_len <= IAVF_ETH_MAX_LEN ||
564 max_pkt_len > IAVF_FRAME_SIZE_MAX) {
565 PMD_DRV_LOG(ERR, "maximum packet length must be "
566 "larger than %u and smaller than %u, "
567 "as jumbo frame is enabled",
568 (uint32_t)IAVF_ETH_MAX_LEN,
569 (uint32_t)IAVF_FRAME_SIZE_MAX);
573 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
574 max_pkt_len > IAVF_ETH_MAX_LEN) {
575 PMD_DRV_LOG(ERR, "maximum packet length must be "
576 "larger than %u and smaller than %u, "
577 "as jumbo frame is disabled",
578 (uint32_t)RTE_ETHER_MIN_LEN,
579 (uint32_t)IAVF_ETH_MAX_LEN);
584 rxq->max_pkt_len = max_pkt_len;
585 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
586 rxq->max_pkt_len > buf_size) {
587 dev_data->scattered_rx = 1;
589 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
590 IAVF_WRITE_FLUSH(hw);
596 iavf_init_queues(struct rte_eth_dev *dev)
598 struct iavf_rx_queue **rxq =
599 (struct iavf_rx_queue **)dev->data->rx_queues;
600 int i, ret = IAVF_SUCCESS;
602 for (i = 0; i < dev->data->nb_rx_queues; i++) {
603 if (!rxq[i] || !rxq[i]->q_set)
605 ret = iavf_init_rxq(dev, rxq[i]);
606 if (ret != IAVF_SUCCESS)
609 /* set rx/tx function to vector/scatter/single-segment
610 * according to parameters
612 iavf_set_rx_function(dev);
613 iavf_set_tx_function(dev);
618 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
619 struct rte_intr_handle *intr_handle)
621 struct iavf_adapter *adapter =
622 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
623 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
624 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
625 struct iavf_qv_map *qv_map;
626 uint16_t interval, i;
629 if (rte_intr_cap_multiple(intr_handle) &&
630 dev->data->dev_conf.intr_conf.rxq) {
631 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
635 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
636 intr_handle->intr_vec =
637 rte_zmalloc("intr_vec",
638 dev->data->nb_rx_queues * sizeof(int), 0);
639 if (!intr_handle->intr_vec) {
640 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
641 dev->data->nb_rx_queues);
646 qv_map = rte_zmalloc("qv_map",
647 dev->data->nb_rx_queues * sizeof(struct iavf_qv_map), 0);
649 PMD_DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
650 dev->data->nb_rx_queues);
654 if (!dev->data->dev_conf.intr_conf.rxq ||
655 !rte_intr_dp_is_en(intr_handle)) {
656 /* Rx interrupt disabled, Map interrupt only for writeback */
658 if (vf->vf_res->vf_cap_flags &
659 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
660 /* If WB_ON_ITR supports, enable it */
661 vf->msix_base = IAVF_RX_VEC_START;
662 /* Set the ITR for index zero, to 2us to make sure that
663 * we leave time for aggregation to occur, but don't
664 * increase latency dramatically.
667 IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
668 (0 << IAVF_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) |
669 IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK |
670 (2UL << IAVF_VFINT_DYN_CTLN1_INTERVAL_SHIFT));
671 /* debug - check for success! the return value
672 * should be 2, offset is 0x2800
674 /* IAVF_READ_REG(hw, IAVF_VFINT_ITRN1(0, 0)); */
676 /* If no WB_ON_ITR offload flags, need to set
677 * interrupt for descriptor write back.
679 vf->msix_base = IAVF_MISC_VEC_ID;
682 interval = iavf_calc_itr_interval(
683 IAVF_QUEUE_ITR_INTERVAL_MAX);
684 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
685 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
686 (IAVF_ITR_INDEX_DEFAULT <<
687 IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
689 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
691 IAVF_WRITE_FLUSH(hw);
692 /* map all queues to the same interrupt */
693 for (i = 0; i < dev->data->nb_rx_queues; i++) {
694 qv_map[i].queue_id = i;
695 qv_map[i].vector_id = vf->msix_base;
699 if (!rte_intr_allow_others(intr_handle)) {
701 vf->msix_base = IAVF_MISC_VEC_ID;
702 for (i = 0; i < dev->data->nb_rx_queues; i++) {
703 qv_map[i].queue_id = i;
704 qv_map[i].vector_id = vf->msix_base;
705 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
709 "vector %u are mapping to all Rx queues",
712 /* If Rx interrupt is reuquired, and we can use
713 * multi interrupts, then the vec is from 1
715 vf->nb_msix = RTE_MIN(intr_handle->nb_efd,
716 (uint16_t)(vf->vf_res->max_vectors - 1));
717 vf->msix_base = IAVF_RX_VEC_START;
718 vec = IAVF_RX_VEC_START;
719 for (i = 0; i < dev->data->nb_rx_queues; i++) {
720 qv_map[i].queue_id = i;
721 qv_map[i].vector_id = vec;
722 intr_handle->intr_vec[i] = vec++;
723 if (vec >= vf->nb_msix + IAVF_RX_VEC_START)
724 vec = IAVF_RX_VEC_START;
728 "%u vectors are mapping to %u Rx queues",
729 vf->nb_msix, dev->data->nb_rx_queues);
733 if (!vf->lv_enabled) {
734 if (iavf_config_irq_map(adapter)) {
735 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
739 uint16_t num_qv_maps = dev->data->nb_rx_queues;
742 while (num_qv_maps > IAVF_IRQ_MAP_NUM_PER_BUF) {
743 if (iavf_config_irq_map_lv(adapter,
744 IAVF_IRQ_MAP_NUM_PER_BUF, index)) {
745 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
748 num_qv_maps -= IAVF_IRQ_MAP_NUM_PER_BUF;
749 index += IAVF_IRQ_MAP_NUM_PER_BUF;
752 if (iavf_config_irq_map_lv(adapter, num_qv_maps, index)) {
753 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
761 iavf_start_queues(struct rte_eth_dev *dev)
763 struct iavf_rx_queue *rxq;
764 struct iavf_tx_queue *txq;
767 for (i = 0; i < dev->data->nb_tx_queues; i++) {
768 txq = dev->data->tx_queues[i];
769 if (txq->tx_deferred_start)
771 if (iavf_dev_tx_queue_start(dev, i) != 0) {
772 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
777 for (i = 0; i < dev->data->nb_rx_queues; i++) {
778 rxq = dev->data->rx_queues[i];
779 if (rxq->rx_deferred_start)
781 if (iavf_dev_rx_queue_start(dev, i) != 0) {
782 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
791 iavf_dev_start(struct rte_eth_dev *dev)
793 struct iavf_adapter *adapter =
794 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
795 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
796 struct rte_intr_handle *intr_handle = dev->intr_handle;
797 uint16_t num_queue_pairs;
800 PMD_INIT_FUNC_TRACE();
802 adapter->stopped = 0;
804 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
805 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
806 dev->data->nb_tx_queues);
807 num_queue_pairs = vf->num_queue_pairs;
809 if (iavf_init_queues(dev) != 0) {
810 PMD_DRV_LOG(ERR, "failed to do Queue init");
814 /* If needed, send configure queues msg multiple times to make the
815 * adminq buffer length smaller than the 4K limitation.
817 while (num_queue_pairs > IAVF_CFG_Q_NUM_PER_BUF) {
818 if (iavf_configure_queues(adapter,
819 IAVF_CFG_Q_NUM_PER_BUF, index) != 0) {
820 PMD_DRV_LOG(ERR, "configure queues failed");
823 num_queue_pairs -= IAVF_CFG_Q_NUM_PER_BUF;
824 index += IAVF_CFG_Q_NUM_PER_BUF;
827 if (iavf_configure_queues(adapter, num_queue_pairs, index) != 0) {
828 PMD_DRV_LOG(ERR, "configure queues failed");
832 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
833 PMD_DRV_LOG(ERR, "configure irq failed");
836 /* re-enable intr again, because efd assign may change */
837 if (dev->data->dev_conf.intr_conf.rxq != 0) {
838 rte_intr_disable(intr_handle);
839 rte_intr_enable(intr_handle);
842 /* Set all mac addrs */
843 iavf_add_del_all_mac_addr(adapter, true);
845 /* Set all multicast addresses */
846 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
849 if (iavf_start_queues(dev) != 0) {
850 PMD_DRV_LOG(ERR, "enable queues failed");
857 iavf_add_del_all_mac_addr(adapter, false);
863 iavf_dev_stop(struct rte_eth_dev *dev)
865 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
866 struct iavf_adapter *adapter =
867 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
868 struct rte_intr_handle *intr_handle = dev->intr_handle;
870 PMD_INIT_FUNC_TRACE();
872 if (adapter->stopped == 1)
875 iavf_stop_queues(dev);
877 /* Disable the interrupt for Rx */
878 rte_intr_efd_disable(intr_handle);
879 /* Rx interrupt vector mapping free */
880 if (intr_handle->intr_vec) {
881 rte_free(intr_handle->intr_vec);
882 intr_handle->intr_vec = NULL;
885 /* remove all mac addrs */
886 iavf_add_del_all_mac_addr(adapter, false);
888 /* remove all multicast addresses */
889 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
892 adapter->stopped = 1;
893 dev->data->dev_started = 0;
899 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
901 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
903 dev_info->max_rx_queues = IAVF_MAX_NUM_QUEUES_LV;
904 dev_info->max_tx_queues = IAVF_MAX_NUM_QUEUES_LV;
905 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
906 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
907 dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
908 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
909 dev_info->hash_key_size = vf->vf_res->rss_key_size;
910 dev_info->reta_size = vf->vf_res->rss_lut_size;
911 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
912 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
913 dev_info->rx_offload_capa =
914 DEV_RX_OFFLOAD_VLAN_STRIP |
915 DEV_RX_OFFLOAD_QINQ_STRIP |
916 DEV_RX_OFFLOAD_IPV4_CKSUM |
917 DEV_RX_OFFLOAD_UDP_CKSUM |
918 DEV_RX_OFFLOAD_TCP_CKSUM |
919 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
920 DEV_RX_OFFLOAD_SCATTER |
921 DEV_RX_OFFLOAD_JUMBO_FRAME |
922 DEV_RX_OFFLOAD_VLAN_FILTER |
923 DEV_RX_OFFLOAD_RSS_HASH;
925 dev_info->tx_offload_capa =
926 DEV_TX_OFFLOAD_VLAN_INSERT |
927 DEV_TX_OFFLOAD_QINQ_INSERT |
928 DEV_TX_OFFLOAD_IPV4_CKSUM |
929 DEV_TX_OFFLOAD_UDP_CKSUM |
930 DEV_TX_OFFLOAD_TCP_CKSUM |
931 DEV_TX_OFFLOAD_SCTP_CKSUM |
932 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
933 DEV_TX_OFFLOAD_TCP_TSO |
934 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
935 DEV_TX_OFFLOAD_GRE_TNL_TSO |
936 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
937 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
938 DEV_TX_OFFLOAD_MULTI_SEGS |
939 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
941 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
942 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_KEEP_CRC;
944 dev_info->default_rxconf = (struct rte_eth_rxconf) {
945 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
950 dev_info->default_txconf = (struct rte_eth_txconf) {
951 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
952 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
956 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
957 .nb_max = IAVF_MAX_RING_DESC,
958 .nb_min = IAVF_MIN_RING_DESC,
959 .nb_align = IAVF_ALIGN_RING_DESC,
962 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
963 .nb_max = IAVF_MAX_RING_DESC,
964 .nb_min = IAVF_MIN_RING_DESC,
965 .nb_align = IAVF_ALIGN_RING_DESC,
971 static const uint32_t *
972 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
974 static const uint32_t ptypes[] = {
976 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
979 RTE_PTYPE_L4_NONFRAG,
989 iavf_dev_link_update(struct rte_eth_dev *dev,
990 __rte_unused int wait_to_complete)
992 struct rte_eth_link new_link;
993 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
995 memset(&new_link, 0, sizeof(new_link));
997 /* Only read status info stored in VF, and the info is updated
998 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
1000 switch (vf->link_speed) {
1002 new_link.link_speed = ETH_SPEED_NUM_10M;
1005 new_link.link_speed = ETH_SPEED_NUM_100M;
1008 new_link.link_speed = ETH_SPEED_NUM_1G;
1011 new_link.link_speed = ETH_SPEED_NUM_10G;
1014 new_link.link_speed = ETH_SPEED_NUM_20G;
1017 new_link.link_speed = ETH_SPEED_NUM_25G;
1020 new_link.link_speed = ETH_SPEED_NUM_40G;
1023 new_link.link_speed = ETH_SPEED_NUM_50G;
1026 new_link.link_speed = ETH_SPEED_NUM_100G;
1029 new_link.link_speed = ETH_SPEED_NUM_NONE;
1033 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
1034 new_link.link_status = vf->link_up ? ETH_LINK_UP :
1036 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1037 ETH_LINK_SPEED_FIXED);
1039 return rte_eth_linkstatus_set(dev, &new_link);
1043 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1045 struct iavf_adapter *adapter =
1046 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1047 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1049 return iavf_config_promisc(adapter,
1050 true, vf->promisc_multicast_enabled);
1054 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1056 struct iavf_adapter *adapter =
1057 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1058 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1060 return iavf_config_promisc(adapter,
1061 false, vf->promisc_multicast_enabled);
1065 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1067 struct iavf_adapter *adapter =
1068 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1069 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1071 return iavf_config_promisc(adapter,
1072 vf->promisc_unicast_enabled, true);
1076 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1078 struct iavf_adapter *adapter =
1079 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1080 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1082 return iavf_config_promisc(adapter,
1083 vf->promisc_unicast_enabled, false);
1087 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
1088 __rte_unused uint32_t index,
1089 __rte_unused uint32_t pool)
1091 struct iavf_adapter *adapter =
1092 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1093 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1096 if (rte_is_zero_ether_addr(addr)) {
1097 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
1101 err = iavf_add_del_eth_addr(adapter, addr, true, VIRTCHNL_ETHER_ADDR_EXTRA);
1103 PMD_DRV_LOG(ERR, "fail to add MAC address");
1113 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1115 struct iavf_adapter *adapter =
1116 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1117 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1118 struct rte_ether_addr *addr;
1121 addr = &dev->data->mac_addrs[index];
1123 err = iavf_add_del_eth_addr(adapter, addr, false, VIRTCHNL_ETHER_ADDR_EXTRA);
1125 PMD_DRV_LOG(ERR, "fail to delete MAC address");
1131 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1133 struct iavf_adapter *adapter =
1134 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1135 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1138 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
1139 err = iavf_add_del_vlan_v2(adapter, vlan_id, on);
1145 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1148 err = iavf_add_del_vlan(adapter, vlan_id, on);
1155 iavf_iterate_vlan_filters_v2(struct rte_eth_dev *dev, bool enable)
1157 struct rte_vlan_filter_conf *vfc = &dev->data->vlan_filter_conf;
1158 struct iavf_adapter *adapter =
1159 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1163 for (i = 0; i < RTE_DIM(vfc->ids); i++) {
1164 if (vfc->ids[i] == 0)
1168 for (j = 0; ids != 0 && j < 64; j++, ids >>= 1) {
1170 iavf_add_del_vlan_v2(adapter,
1171 64 * i + j, enable);
1177 iavf_dev_vlan_offload_set_v2(struct rte_eth_dev *dev, int mask)
1179 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1180 struct iavf_adapter *adapter =
1181 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1185 if (mask & ETH_VLAN_FILTER_MASK) {
1186 enable = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
1188 iavf_iterate_vlan_filters_v2(dev, enable);
1191 if (mask & ETH_VLAN_STRIP_MASK) {
1192 enable = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
1194 err = iavf_config_vlan_strip_v2(adapter, enable);
1195 /* If not support, the stripping is already disabled by PF */
1196 if (err == -ENOTSUP && !enable)
1206 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1208 struct iavf_adapter *adapter =
1209 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1210 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1211 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1214 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
1215 return iavf_dev_vlan_offload_set_v2(dev, mask);
1217 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1220 /* Vlan stripping setting */
1221 if (mask & ETH_VLAN_STRIP_MASK) {
1222 /* Enable or disable VLAN stripping */
1223 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1224 err = iavf_enable_vlan_strip(adapter);
1226 err = iavf_disable_vlan_strip(adapter);
1235 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
1236 struct rte_eth_rss_reta_entry64 *reta_conf,
1239 struct iavf_adapter *adapter =
1240 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1241 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1243 uint16_t i, idx, shift;
1246 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1249 if (reta_size != vf->vf_res->rss_lut_size) {
1250 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1251 "(%d) doesn't match the number of hardware can "
1252 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1256 lut = rte_zmalloc("rss_lut", reta_size, 0);
1258 PMD_DRV_LOG(ERR, "No memory can be allocated");
1261 /* store the old lut table temporarily */
1262 rte_memcpy(lut, vf->rss_lut, reta_size);
1264 for (i = 0; i < reta_size; i++) {
1265 idx = i / RTE_RETA_GROUP_SIZE;
1266 shift = i % RTE_RETA_GROUP_SIZE;
1267 if (reta_conf[idx].mask & (1ULL << shift))
1268 lut[i] = reta_conf[idx].reta[shift];
1271 rte_memcpy(vf->rss_lut, lut, reta_size);
1272 /* send virtchnnl ops to configure rss*/
1273 ret = iavf_configure_rss_lut(adapter);
1274 if (ret) /* revert back */
1275 rte_memcpy(vf->rss_lut, lut, reta_size);
1282 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
1283 struct rte_eth_rss_reta_entry64 *reta_conf,
1286 struct iavf_adapter *adapter =
1287 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1288 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1289 uint16_t i, idx, shift;
1291 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1294 if (reta_size != vf->vf_res->rss_lut_size) {
1295 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1296 "(%d) doesn't match the number of hardware can "
1297 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1301 for (i = 0; i < reta_size; i++) {
1302 idx = i / RTE_RETA_GROUP_SIZE;
1303 shift = i % RTE_RETA_GROUP_SIZE;
1304 if (reta_conf[idx].mask & (1ULL << shift))
1305 reta_conf[idx].reta[shift] = vf->rss_lut[i];
1312 iavf_set_rss_key(struct iavf_adapter *adapter, uint8_t *key, uint8_t key_len)
1314 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1316 /* HENA setting, it is enabled by default, no change */
1317 if (!key || key_len == 0) {
1318 PMD_DRV_LOG(DEBUG, "No key to be configured");
1320 } else if (key_len != vf->vf_res->rss_key_size) {
1321 PMD_DRV_LOG(ERR, "The size of hash key configured "
1322 "(%d) doesn't match the size of hardware can "
1323 "support (%d)", key_len,
1324 vf->vf_res->rss_key_size);
1328 rte_memcpy(vf->rss_key, key, key_len);
1330 return iavf_configure_rss_key(adapter);
1334 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
1335 struct rte_eth_rss_conf *rss_conf)
1337 struct iavf_adapter *adapter =
1338 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1339 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1342 adapter->eth_dev->data->dev_conf.rx_adv_conf.rss_conf = *rss_conf;
1344 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1348 ret = iavf_set_rss_key(adapter, rss_conf->rss_key,
1349 rss_conf->rss_key_len);
1353 if (rss_conf->rss_hf == 0) {
1355 ret = iavf_set_hena(adapter, 0);
1357 /* It is a workaround, temporarily allow error to be returned
1358 * due to possible lack of PF handling for hena = 0.
1361 PMD_DRV_LOG(WARNING, "fail to clean existing RSS, lack PF support");
1365 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
1366 /* Clear existing RSS. */
1367 ret = iavf_set_hena(adapter, 0);
1369 /* It is a workaround, temporarily allow error to be returned
1370 * due to possible lack of PF handling for hena = 0.
1373 PMD_DRV_LOG(WARNING, "fail to clean existing RSS,"
1376 /* Set new RSS configuration. */
1377 ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
1379 PMD_DRV_LOG(ERR, "fail to set new RSS");
1383 ret = iavf_config_rss_hf(adapter, rss_conf->rss_hf);
1384 if (ret != -ENOTSUP)
1392 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1393 struct rte_eth_rss_conf *rss_conf)
1395 struct iavf_adapter *adapter =
1396 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1397 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1399 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1402 rss_conf->rss_hf = vf->rss_hf;
1404 if (!rss_conf->rss_key)
1407 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
1408 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
1414 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1416 uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
1419 if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
1422 /* mtu setting is forbidden if port is start */
1423 if (dev->data->dev_started) {
1424 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
1428 if (frame_size > IAVF_ETH_MAX_LEN)
1429 dev->data->dev_conf.rxmode.offloads |=
1430 DEV_RX_OFFLOAD_JUMBO_FRAME;
1432 dev->data->dev_conf.rxmode.offloads &=
1433 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1435 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1441 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1442 struct rte_ether_addr *mac_addr)
1444 struct iavf_adapter *adapter =
1445 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1446 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1447 struct rte_ether_addr *old_addr;
1450 old_addr = (struct rte_ether_addr *)hw->mac.addr;
1452 if (rte_is_same_ether_addr(old_addr, mac_addr))
1455 ret = iavf_add_del_eth_addr(adapter, old_addr, false, VIRTCHNL_ETHER_ADDR_PRIMARY);
1457 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1458 " %02X:%02X:%02X:%02X:%02X:%02X",
1459 old_addr->addr_bytes[0],
1460 old_addr->addr_bytes[1],
1461 old_addr->addr_bytes[2],
1462 old_addr->addr_bytes[3],
1463 old_addr->addr_bytes[4],
1464 old_addr->addr_bytes[5]);
1466 ret = iavf_add_del_eth_addr(adapter, mac_addr, true, VIRTCHNL_ETHER_ADDR_PRIMARY);
1468 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1469 " %02X:%02X:%02X:%02X:%02X:%02X",
1470 mac_addr->addr_bytes[0],
1471 mac_addr->addr_bytes[1],
1472 mac_addr->addr_bytes[2],
1473 mac_addr->addr_bytes[3],
1474 mac_addr->addr_bytes[4],
1475 mac_addr->addr_bytes[5]);
1480 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1485 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1487 if (*stat >= *offset)
1488 *stat = *stat - *offset;
1490 *stat = (uint64_t)((*stat +
1491 ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1493 *stat &= IAVF_48_BIT_MASK;
1497 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1499 if (*stat >= *offset)
1500 *stat = (uint64_t)(*stat - *offset);
1502 *stat = (uint64_t)((*stat +
1503 ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1507 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1509 struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1511 iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1512 iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1513 iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1514 iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1515 iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1516 iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1517 iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1518 iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1519 iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1520 iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1521 iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1525 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1527 struct iavf_adapter *adapter =
1528 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1529 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1530 struct iavf_vsi *vsi = &vf->vsi;
1531 struct virtchnl_eth_stats *pstats = NULL;
1534 ret = iavf_query_stats(adapter, &pstats);
1536 uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads &
1537 DEV_RX_OFFLOAD_KEEP_CRC) ? 0 :
1539 iavf_update_stats(vsi, pstats);
1540 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1541 pstats->rx_broadcast - pstats->rx_discards;
1542 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1544 stats->imissed = pstats->rx_discards;
1545 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1546 stats->ibytes = pstats->rx_bytes;
1547 stats->ibytes -= stats->ipackets * crc_stats_len;
1548 stats->obytes = pstats->tx_bytes;
1550 PMD_DRV_LOG(ERR, "Get statistics failed");
1556 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1559 struct iavf_adapter *adapter =
1560 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1561 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1562 struct iavf_vsi *vsi = &vf->vsi;
1563 struct virtchnl_eth_stats *pstats = NULL;
1565 /* read stat values to clear hardware registers */
1566 ret = iavf_query_stats(adapter, &pstats);
1570 /* set stats offset base on current values */
1571 vsi->eth_stats_offset = *pstats;
1576 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1577 struct rte_eth_xstat_name *xstats_names,
1578 __rte_unused unsigned int limit)
1582 if (xstats_names != NULL)
1583 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1584 snprintf(xstats_names[i].name,
1585 sizeof(xstats_names[i].name),
1586 "%s", rte_iavf_stats_strings[i].name);
1588 return IAVF_NB_XSTATS;
1591 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1592 struct rte_eth_xstat *xstats, unsigned int n)
1596 struct iavf_adapter *adapter =
1597 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1598 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1599 struct iavf_vsi *vsi = &vf->vsi;
1600 struct virtchnl_eth_stats *pstats = NULL;
1602 if (n < IAVF_NB_XSTATS)
1603 return IAVF_NB_XSTATS;
1605 ret = iavf_query_stats(adapter, &pstats);
1612 iavf_update_stats(vsi, pstats);
1614 /* loop over xstats array and values from pstats */
1615 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1617 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1618 rte_iavf_stats_strings[i].offset);
1621 return IAVF_NB_XSTATS;
1626 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1628 struct iavf_adapter *adapter =
1629 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1630 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1631 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1634 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1635 if (msix_intr == IAVF_MISC_VEC_ID) {
1636 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1637 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1638 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1639 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1640 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1643 IAVF_VFINT_DYN_CTLN1
1644 (msix_intr - IAVF_RX_VEC_START),
1645 IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1646 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1647 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1650 IAVF_WRITE_FLUSH(hw);
1652 rte_intr_ack(&pci_dev->intr_handle);
1658 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1660 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1661 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1664 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1665 if (msix_intr == IAVF_MISC_VEC_ID) {
1666 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1671 IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1674 IAVF_WRITE_FLUSH(hw);
1679 iavf_check_vf_reset_done(struct iavf_hw *hw)
1683 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1684 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1685 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1686 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1687 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1688 reset == VIRTCHNL_VFR_COMPLETED)
1693 if (i >= IAVF_RESET_WAIT_CNT)
1700 iavf_lookup_proto_xtr_type(const char *flex_name)
1704 enum iavf_proto_xtr_type type;
1705 } xtr_type_map[] = {
1706 { "vlan", IAVF_PROTO_XTR_VLAN },
1707 { "ipv4", IAVF_PROTO_XTR_IPV4 },
1708 { "ipv6", IAVF_PROTO_XTR_IPV6 },
1709 { "ipv6_flow", IAVF_PROTO_XTR_IPV6_FLOW },
1710 { "tcp", IAVF_PROTO_XTR_TCP },
1711 { "ip_offset", IAVF_PROTO_XTR_IP_OFFSET },
1715 for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
1716 if (strcmp(flex_name, xtr_type_map[i].name) == 0)
1717 return xtr_type_map[i].type;
1720 PMD_DRV_LOG(ERR, "wrong proto_xtr type, "
1721 "it should be: vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset");
1727 * Parse elem, the elem could be single number/range or '(' ')' group
1728 * 1) A single number elem, it's just a simple digit. e.g. 9
1729 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
1730 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
1731 * Within group elem, '-' used for a range separator;
1732 * ',' used for a single number.
1735 iavf_parse_queue_set(const char *input, int xtr_type,
1736 struct iavf_devargs *devargs)
1738 const char *str = input;
1743 while (isblank(*str))
1746 if (!isdigit(*str) && *str != '(')
1749 /* process single number or single range of number */
1752 idx = strtoul(str, &end, 10);
1753 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1756 while (isblank(*end))
1762 /* process single <number>-<number> */
1765 while (isblank(*end))
1771 idx = strtoul(end, &end, 10);
1772 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1776 while (isblank(*end))
1783 for (idx = RTE_MIN(min, max);
1784 idx <= RTE_MAX(min, max); idx++)
1785 devargs->proto_xtr[idx] = xtr_type;
1790 /* process set within bracket */
1792 while (isblank(*str))
1797 min = IAVF_MAX_QUEUE_NUM;
1799 /* go ahead to the first digit */
1800 while (isblank(*str))
1805 /* get the digit value */
1807 idx = strtoul(str, &end, 10);
1808 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1811 /* go ahead to separator '-',',' and ')' */
1812 while (isblank(*end))
1815 if (min == IAVF_MAX_QUEUE_NUM)
1817 else /* avoid continuous '-' */
1819 } else if (*end == ',' || *end == ')') {
1821 if (min == IAVF_MAX_QUEUE_NUM)
1824 for (idx = RTE_MIN(min, max);
1825 idx <= RTE_MAX(min, max); idx++)
1826 devargs->proto_xtr[idx] = xtr_type;
1828 min = IAVF_MAX_QUEUE_NUM;
1834 } while (*end != ')' && *end != '\0');
1840 iavf_parse_queue_proto_xtr(const char *queues, struct iavf_devargs *devargs)
1842 const char *queue_start;
1847 while (isblank(*queues))
1850 if (*queues != '[') {
1851 xtr_type = iavf_lookup_proto_xtr_type(queues);
1855 devargs->proto_xtr_dflt = xtr_type;
1862 while (isblank(*queues))
1864 if (*queues == '\0')
1867 queue_start = queues;
1869 /* go across a complete bracket */
1870 if (*queue_start == '(') {
1871 queues += strcspn(queues, ")");
1876 /* scan the separator ':' */
1877 queues += strcspn(queues, ":");
1878 if (*queues++ != ':')
1880 while (isblank(*queues))
1883 for (idx = 0; ; idx++) {
1884 if (isblank(queues[idx]) ||
1885 queues[idx] == ',' ||
1886 queues[idx] == ']' ||
1887 queues[idx] == '\0')
1890 if (idx > sizeof(flex_name) - 2)
1893 flex_name[idx] = queues[idx];
1895 flex_name[idx] = '\0';
1896 xtr_type = iavf_lookup_proto_xtr_type(flex_name);
1902 while (isblank(*queues) || *queues == ',' || *queues == ']')
1905 if (iavf_parse_queue_set(queue_start, xtr_type, devargs) < 0)
1907 } while (*queues != '\0');
1913 iavf_handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
1916 struct iavf_devargs *devargs = extra_args;
1918 if (!value || !extra_args)
1921 if (iavf_parse_queue_proto_xtr(value, devargs) < 0) {
1922 PMD_DRV_LOG(ERR, "the proto_xtr's parameter is wrong : '%s'",
1930 static int iavf_parse_devargs(struct rte_eth_dev *dev)
1932 struct iavf_adapter *ad =
1933 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1934 struct rte_devargs *devargs = dev->device->devargs;
1935 struct rte_kvargs *kvlist;
1941 kvlist = rte_kvargs_parse(devargs->args, iavf_valid_args);
1943 PMD_INIT_LOG(ERR, "invalid kvargs key\n");
1947 ad->devargs.proto_xtr_dflt = IAVF_PROTO_XTR_NONE;
1948 memset(ad->devargs.proto_xtr, IAVF_PROTO_XTR_NONE,
1949 sizeof(ad->devargs.proto_xtr));
1951 ret = rte_kvargs_process(kvlist, IAVF_PROTO_XTR_ARG,
1952 &iavf_handle_proto_xtr_arg, &ad->devargs);
1957 rte_kvargs_free(kvlist);
1962 iavf_init_proto_xtr(struct rte_eth_dev *dev)
1964 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1965 struct iavf_adapter *ad =
1966 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1967 const struct iavf_proto_xtr_ol *xtr_ol;
1968 bool proto_xtr_enable = false;
1972 vf->proto_xtr = rte_zmalloc("vf proto xtr",
1973 vf->vsi_res->num_queue_pairs, 0);
1974 if (unlikely(!(vf->proto_xtr))) {
1975 PMD_DRV_LOG(ERR, "no memory for setting up proto_xtr's table");
1979 for (i = 0; i < vf->vsi_res->num_queue_pairs; i++) {
1980 vf->proto_xtr[i] = ad->devargs.proto_xtr[i] !=
1981 IAVF_PROTO_XTR_NONE ?
1982 ad->devargs.proto_xtr[i] :
1983 ad->devargs.proto_xtr_dflt;
1985 if (vf->proto_xtr[i] != IAVF_PROTO_XTR_NONE) {
1986 uint8_t type = vf->proto_xtr[i];
1988 iavf_proto_xtr_params[type].required = true;
1989 proto_xtr_enable = true;
1993 if (likely(!proto_xtr_enable))
1996 offset = rte_mbuf_dynfield_register(&iavf_proto_xtr_metadata_param);
1997 if (unlikely(offset == -1)) {
1999 "failed to extract protocol metadata, error %d",
2005 "proto_xtr metadata offset in mbuf is : %d",
2007 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = offset;
2009 for (i = 0; i < RTE_DIM(iavf_proto_xtr_params); i++) {
2010 xtr_ol = &iavf_proto_xtr_params[i];
2012 uint8_t rxdid = iavf_proto_xtr_type_to_rxdid((uint8_t)i);
2014 if (!xtr_ol->required)
2017 if (!(vf->supported_rxdid & BIT(rxdid))) {
2019 "rxdid[%u] is not supported in hardware",
2021 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2025 offset = rte_mbuf_dynflag_register(&xtr_ol->param);
2026 if (unlikely(offset == -1)) {
2028 "failed to register proto_xtr offload '%s', error %d",
2029 xtr_ol->param.name, -rte_errno);
2031 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2036 "proto_xtr offload '%s' offset in mbuf is : %d",
2037 xtr_ol->param.name, offset);
2038 *xtr_ol->ol_flag = 1ULL << offset;
2043 iavf_init_vf(struct rte_eth_dev *dev)
2046 struct iavf_adapter *adapter =
2047 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2048 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2049 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2051 err = iavf_parse_devargs(dev);
2053 PMD_INIT_LOG(ERR, "Failed to parse devargs");
2057 err = iavf_set_mac_type(hw);
2059 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
2063 err = iavf_check_vf_reset_done(hw);
2065 PMD_INIT_LOG(ERR, "VF is still resetting");
2069 iavf_init_adminq_parameter(hw);
2070 err = iavf_init_adminq(hw);
2072 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
2076 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
2078 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
2081 if (iavf_check_api_version(adapter) != 0) {
2082 PMD_INIT_LOG(ERR, "check_api version failed");
2086 bufsz = sizeof(struct virtchnl_vf_resource) +
2087 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
2088 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
2090 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
2093 if (iavf_get_vf_resource(adapter) != 0) {
2094 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
2097 /* Allocate memort for RSS info */
2098 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2099 vf->rss_key = rte_zmalloc("rss_key",
2100 vf->vf_res->rss_key_size, 0);
2102 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
2105 vf->rss_lut = rte_zmalloc("rss_lut",
2106 vf->vf_res->rss_lut_size, 0);
2108 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
2113 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
2114 if (iavf_get_supported_rxdid(adapter) != 0) {
2115 PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
2120 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
2121 if (iavf_get_vlan_offload_caps_v2(adapter) != 0) {
2122 PMD_INIT_LOG(ERR, "failed to do get VLAN offload v2 capabilities");
2127 iavf_init_proto_xtr(dev);
2131 rte_free(vf->rss_key);
2132 rte_free(vf->rss_lut);
2134 rte_free(vf->vf_res);
2137 rte_free(vf->aq_resp);
2139 iavf_shutdown_adminq(hw);
2144 /* Enable default admin queue interrupt setting */
2146 iavf_enable_irq0(struct iavf_hw *hw)
2148 /* Enable admin queue interrupt trigger */
2149 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
2150 IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
2152 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2153 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2154 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2155 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2157 IAVF_WRITE_FLUSH(hw);
2161 iavf_disable_irq0(struct iavf_hw *hw)
2163 /* Disable all interrupt types */
2164 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
2165 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2166 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2167 IAVF_WRITE_FLUSH(hw);
2171 iavf_dev_interrupt_handler(void *param)
2173 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2174 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2176 iavf_disable_irq0(hw);
2178 iavf_handle_virtchnl_msg(dev);
2180 iavf_enable_irq0(hw);
2184 iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
2185 const struct rte_flow_ops **ops)
2190 *ops = &iavf_flow_ops;
2195 iavf_default_rss_disable(struct iavf_adapter *adapter)
2197 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2200 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2201 /* Set hena = 0 to ask PF to cleanup all existing RSS. */
2202 ret = iavf_set_hena(adapter, 0);
2204 /* It is a workaround, temporarily allow error to be
2205 * returned due to possible lack of PF handling for
2208 PMD_INIT_LOG(WARNING, "fail to disable default RSS,"
2214 iavf_dev_init(struct rte_eth_dev *eth_dev)
2216 struct iavf_adapter *adapter =
2217 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
2218 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
2219 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2222 PMD_INIT_FUNC_TRACE();
2224 /* assign ops func pointer */
2225 eth_dev->dev_ops = &iavf_eth_dev_ops;
2226 eth_dev->rx_queue_count = iavf_dev_rxq_count;
2227 eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
2228 eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
2229 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
2230 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
2231 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
2233 /* For secondary processes, we don't initialise any further as primary
2234 * has already done this work. Only check if we need a different RX
2237 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2238 iavf_set_rx_function(eth_dev);
2239 iavf_set_tx_function(eth_dev);
2242 rte_eth_copy_pci_info(eth_dev, pci_dev);
2243 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2245 hw->vendor_id = pci_dev->id.vendor_id;
2246 hw->device_id = pci_dev->id.device_id;
2247 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2248 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2249 hw->bus.bus_id = pci_dev->addr.bus;
2250 hw->bus.device = pci_dev->addr.devid;
2251 hw->bus.func = pci_dev->addr.function;
2252 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
2253 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
2254 adapter->eth_dev = eth_dev;
2255 adapter->stopped = 1;
2257 if (iavf_init_vf(eth_dev) != 0) {
2258 PMD_INIT_LOG(ERR, "Init vf failed");
2262 /* set default ptype table */
2263 adapter->ptype_tbl = iavf_get_default_ptype_table();
2266 eth_dev->data->mac_addrs = rte_zmalloc(
2267 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
2268 if (!eth_dev->data->mac_addrs) {
2269 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
2270 " store MAC addresses",
2271 RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
2274 /* If the MAC address is not configured by host,
2275 * generate a random one.
2277 if (!rte_is_valid_assigned_ether_addr(
2278 (struct rte_ether_addr *)hw->mac.addr))
2279 rte_eth_random_addr(hw->mac.addr);
2280 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
2281 ð_dev->data->mac_addrs[0]);
2283 /* register callback func to eal lib */
2284 rte_intr_callback_register(&pci_dev->intr_handle,
2285 iavf_dev_interrupt_handler,
2288 /* enable uio intr after callback register */
2289 rte_intr_enable(&pci_dev->intr_handle);
2291 /* configure and enable device interrupt */
2292 iavf_enable_irq0(hw);
2294 ret = iavf_flow_init(adapter);
2296 PMD_INIT_LOG(ERR, "Failed to initialize flow");
2300 iavf_default_rss_disable(adapter);
2306 iavf_dev_close(struct rte_eth_dev *dev)
2308 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2309 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2310 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2311 struct iavf_adapter *adapter =
2312 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2313 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2316 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2319 ret = iavf_dev_stop(dev);
2321 iavf_flow_flush(dev, NULL);
2322 iavf_flow_uninit(adapter);
2325 * disable promiscuous mode before reset vf
2326 * it is a workaround solution when work with kernel driver
2327 * and it is not the normal way
2329 if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
2330 iavf_config_promisc(adapter, false, false);
2332 iavf_shutdown_adminq(hw);
2333 /* disable uio intr before callback unregister */
2334 rte_intr_disable(intr_handle);
2336 /* unregister callback func from eal lib */
2337 rte_intr_callback_unregister(intr_handle,
2338 iavf_dev_interrupt_handler, dev);
2339 iavf_disable_irq0(hw);
2341 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2343 rte_free(vf->rss_lut);
2347 rte_free(vf->rss_key);
2352 rte_free(vf->vf_res);
2356 rte_free(vf->aq_resp);
2359 vf->vf_reset = false;
2365 iavf_dev_uninit(struct rte_eth_dev *dev)
2367 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2370 iavf_dev_close(dev);
2376 * Reset VF device only to re-initialize resources in PMD layer
2379 iavf_dev_reset(struct rte_eth_dev *dev)
2383 ret = iavf_dev_uninit(dev);
2387 return iavf_dev_init(dev);
2391 iavf_dcf_cap_check_handler(__rte_unused const char *key,
2392 const char *value, __rte_unused void *opaque)
2394 if (strcmp(value, "dcf"))
2401 iavf_dcf_cap_selected(struct rte_devargs *devargs)
2403 struct rte_kvargs *kvlist;
2404 const char *key = "cap";
2407 if (devargs == NULL)
2410 kvlist = rte_kvargs_parse(devargs->args, NULL);
2414 if (!rte_kvargs_count(kvlist, key))
2417 /* dcf capability selected when there's a key-value pair: cap=dcf */
2418 if (rte_kvargs_process(kvlist, key,
2419 iavf_dcf_cap_check_handler, NULL) < 0)
2425 rte_kvargs_free(kvlist);
2430 iavf_drv_i40evf_check_handler(__rte_unused const char *key,
2431 const char *value, __rte_unused void *opaque)
2433 if (strcmp(value, "i40evf"))
2440 iavf_drv_i40evf_selected(struct rte_devargs *devargs, uint16_t device_id)
2442 struct rte_kvargs *kvlist;
2443 const char *key = "driver";
2446 if (device_id != IAVF_DEV_ID_VF &&
2447 device_id != IAVF_DEV_ID_VF_HV &&
2448 device_id != IAVF_DEV_ID_X722_VF &&
2449 device_id != IAVF_DEV_ID_X722_A0_VF)
2452 if (devargs == NULL)
2455 kvlist = rte_kvargs_parse(devargs->args, NULL);
2459 if (!rte_kvargs_count(kvlist, key))
2462 /* i40evf driver selected when there's a key-value pair:
2465 if (rte_kvargs_process(kvlist, key,
2466 iavf_drv_i40evf_check_handler, NULL) < 0)
2472 rte_kvargs_free(kvlist);
2476 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2477 struct rte_pci_device *pci_dev)
2479 if (iavf_dcf_cap_selected(pci_dev->device.devargs) ||
2480 iavf_drv_i40evf_selected(pci_dev->device.devargs,
2481 pci_dev->id.device_id))
2484 return rte_eth_dev_pci_generic_probe(pci_dev,
2485 sizeof(struct iavf_adapter), iavf_dev_init);
2488 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
2490 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
2493 /* Adaptive virtual function driver struct */
2494 static struct rte_pci_driver rte_iavf_pmd = {
2495 .id_table = pci_id_iavf_map,
2496 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2497 .probe = eth_iavf_pci_probe,
2498 .remove = eth_iavf_pci_remove,
2501 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
2502 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
2503 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
2504 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf driver=i40evf");
2505 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_init, init, NOTICE);
2506 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_driver, driver, NOTICE);
2507 #ifdef RTE_ETHDEV_DEBUG_RX
2508 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_rx, rx, DEBUG);
2510 #ifdef RTE_ETHDEV_DEBUG_TX
2511 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_tx, tx, DEBUG);