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_alarm.h>
20 #include <rte_atomic.h>
22 #include <rte_ether.h>
23 #include <ethdev_driver.h>
24 #include <ethdev_pci.h>
25 #include <rte_malloc.h>
26 #include <rte_memzone.h>
30 #include "iavf_rxtx.h"
31 #include "iavf_generic_flow.h"
32 #include "rte_pmd_iavf.h"
35 #define IAVF_PROTO_XTR_ARG "proto_xtr"
37 static const char * const iavf_valid_args[] = {
42 static const struct rte_mbuf_dynfield iavf_proto_xtr_metadata_param = {
43 .name = "intel_pmd_dynfield_proto_xtr_metadata",
44 .size = sizeof(uint32_t),
45 .align = __alignof__(uint32_t),
49 struct iavf_proto_xtr_ol {
50 const struct rte_mbuf_dynflag param;
55 static struct iavf_proto_xtr_ol iavf_proto_xtr_params[] = {
56 [IAVF_PROTO_XTR_VLAN] = {
57 .param = { .name = "intel_pmd_dynflag_proto_xtr_vlan" },
58 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_vlan_mask },
59 [IAVF_PROTO_XTR_IPV4] = {
60 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv4" },
61 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask },
62 [IAVF_PROTO_XTR_IPV6] = {
63 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6" },
64 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask },
65 [IAVF_PROTO_XTR_IPV6_FLOW] = {
66 .param = { .name = "intel_pmd_dynflag_proto_xtr_ipv6_flow" },
67 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask },
68 [IAVF_PROTO_XTR_TCP] = {
69 .param = { .name = "intel_pmd_dynflag_proto_xtr_tcp" },
70 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_tcp_mask },
71 [IAVF_PROTO_XTR_IP_OFFSET] = {
72 .param = { .name = "intel_pmd_dynflag_proto_xtr_ip_offset" },
73 .ol_flag = &rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask },
76 static int iavf_dev_configure(struct rte_eth_dev *dev);
77 static int iavf_dev_start(struct rte_eth_dev *dev);
78 static int iavf_dev_stop(struct rte_eth_dev *dev);
79 static int iavf_dev_close(struct rte_eth_dev *dev);
80 static int iavf_dev_reset(struct rte_eth_dev *dev);
81 static int iavf_dev_info_get(struct rte_eth_dev *dev,
82 struct rte_eth_dev_info *dev_info);
83 static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev);
84 static int iavf_dev_stats_get(struct rte_eth_dev *dev,
85 struct rte_eth_stats *stats);
86 static int iavf_dev_stats_reset(struct rte_eth_dev *dev);
87 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
88 struct rte_eth_xstat *xstats, unsigned int n);
89 static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev,
90 struct rte_eth_xstat_name *xstats_names,
92 static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev);
93 static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev);
94 static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev);
95 static int iavf_dev_allmulticast_disable(struct rte_eth_dev *dev);
96 static int iavf_dev_add_mac_addr(struct rte_eth_dev *dev,
97 struct rte_ether_addr *addr,
100 static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
101 static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
102 uint16_t vlan_id, int on);
103 static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
104 static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
105 struct rte_eth_rss_reta_entry64 *reta_conf,
107 static int iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
108 struct rte_eth_rss_reta_entry64 *reta_conf,
110 static int iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
111 struct rte_eth_rss_conf *rss_conf);
112 static int iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
113 struct rte_eth_rss_conf *rss_conf);
114 static int iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
115 static int iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
116 struct rte_ether_addr *mac_addr);
117 static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
119 static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
121 static int iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
122 const struct rte_flow_ops **ops);
123 static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
124 struct rte_ether_addr *mc_addrs,
125 uint32_t mc_addrs_num);
126 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
128 static const struct rte_pci_id pci_id_iavf_map[] = {
129 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
130 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF) },
131 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_VF_HV) },
132 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_VF) },
133 { RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_X722_A0_VF) },
134 { .vendor_id = 0, /* sentinel */ },
137 struct rte_iavf_xstats_name_off {
138 char name[RTE_ETH_XSTATS_NAME_SIZE];
142 static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = {
143 {"rx_bytes", offsetof(struct iavf_eth_stats, rx_bytes)},
144 {"rx_unicast_packets", offsetof(struct iavf_eth_stats, rx_unicast)},
145 {"rx_multicast_packets", offsetof(struct iavf_eth_stats, rx_multicast)},
146 {"rx_broadcast_packets", offsetof(struct iavf_eth_stats, rx_broadcast)},
147 {"rx_dropped_packets", offsetof(struct iavf_eth_stats, rx_discards)},
148 {"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats,
149 rx_unknown_protocol)},
150 {"tx_bytes", offsetof(struct iavf_eth_stats, tx_bytes)},
151 {"tx_unicast_packets", offsetof(struct iavf_eth_stats, tx_unicast)},
152 {"tx_multicast_packets", offsetof(struct iavf_eth_stats, tx_multicast)},
153 {"tx_broadcast_packets", offsetof(struct iavf_eth_stats, tx_broadcast)},
154 {"tx_dropped_packets", offsetof(struct iavf_eth_stats, tx_discards)},
155 {"tx_error_packets", offsetof(struct iavf_eth_stats, tx_errors)},
158 #define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \
159 sizeof(rte_iavf_stats_strings[0]))
161 static const struct eth_dev_ops iavf_eth_dev_ops = {
162 .dev_configure = iavf_dev_configure,
163 .dev_start = iavf_dev_start,
164 .dev_stop = iavf_dev_stop,
165 .dev_close = iavf_dev_close,
166 .dev_reset = iavf_dev_reset,
167 .dev_infos_get = iavf_dev_info_get,
168 .dev_supported_ptypes_get = iavf_dev_supported_ptypes_get,
169 .link_update = iavf_dev_link_update,
170 .stats_get = iavf_dev_stats_get,
171 .stats_reset = iavf_dev_stats_reset,
172 .xstats_get = iavf_dev_xstats_get,
173 .xstats_get_names = iavf_dev_xstats_get_names,
174 .xstats_reset = iavf_dev_stats_reset,
175 .promiscuous_enable = iavf_dev_promiscuous_enable,
176 .promiscuous_disable = iavf_dev_promiscuous_disable,
177 .allmulticast_enable = iavf_dev_allmulticast_enable,
178 .allmulticast_disable = iavf_dev_allmulticast_disable,
179 .mac_addr_add = iavf_dev_add_mac_addr,
180 .mac_addr_remove = iavf_dev_del_mac_addr,
181 .set_mc_addr_list = iavf_set_mc_addr_list,
182 .vlan_filter_set = iavf_dev_vlan_filter_set,
183 .vlan_offload_set = iavf_dev_vlan_offload_set,
184 .rx_queue_start = iavf_dev_rx_queue_start,
185 .rx_queue_stop = iavf_dev_rx_queue_stop,
186 .tx_queue_start = iavf_dev_tx_queue_start,
187 .tx_queue_stop = iavf_dev_tx_queue_stop,
188 .rx_queue_setup = iavf_dev_rx_queue_setup,
189 .rx_queue_release = iavf_dev_rx_queue_release,
190 .tx_queue_setup = iavf_dev_tx_queue_setup,
191 .tx_queue_release = iavf_dev_tx_queue_release,
192 .mac_addr_set = iavf_dev_set_default_mac_addr,
193 .reta_update = iavf_dev_rss_reta_update,
194 .reta_query = iavf_dev_rss_reta_query,
195 .rss_hash_update = iavf_dev_rss_hash_update,
196 .rss_hash_conf_get = iavf_dev_rss_hash_conf_get,
197 .rxq_info_get = iavf_dev_rxq_info_get,
198 .txq_info_get = iavf_dev_txq_info_get,
199 .mtu_set = iavf_dev_mtu_set,
200 .rx_queue_intr_enable = iavf_dev_rx_queue_intr_enable,
201 .rx_queue_intr_disable = iavf_dev_rx_queue_intr_disable,
202 .flow_ops_get = iavf_dev_flow_ops_get,
203 .tx_done_cleanup = iavf_dev_tx_done_cleanup,
204 .get_monitor_addr = iavf_get_monitor_addr,
205 .tm_ops_get = iavf_tm_ops_get,
209 iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused,
215 *(const void **)arg = &iavf_tm_ops;
221 iavf_set_mc_addr_list(struct rte_eth_dev *dev,
222 struct rte_ether_addr *mc_addrs,
223 uint32_t mc_addrs_num)
225 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
226 struct iavf_adapter *adapter =
227 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
230 if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
232 "can't add more than a limited number (%u) of addresses.",
233 (uint32_t)IAVF_NUM_MACADDR_MAX);
237 /* flush previous addresses */
238 err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
244 err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
247 /* if adding mac address list fails, should add the previous
250 ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
251 vf->mc_addrs_num, true);
255 vf->mc_addrs_num = mc_addrs_num;
257 mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
264 iavf_config_rss_hf(struct iavf_adapter *adapter, uint64_t rss_hf)
266 static const uint64_t map_hena_rss[] = {
268 [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
269 ETH_RSS_NONFRAG_IPV4_UDP,
270 [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
271 ETH_RSS_NONFRAG_IPV4_UDP,
272 [IAVF_FILTER_PCTYPE_NONF_IPV4_UDP] =
273 ETH_RSS_NONFRAG_IPV4_UDP,
274 [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
275 ETH_RSS_NONFRAG_IPV4_TCP,
276 [IAVF_FILTER_PCTYPE_NONF_IPV4_TCP] =
277 ETH_RSS_NONFRAG_IPV4_TCP,
278 [IAVF_FILTER_PCTYPE_NONF_IPV4_SCTP] =
279 ETH_RSS_NONFRAG_IPV4_SCTP,
280 [IAVF_FILTER_PCTYPE_NONF_IPV4_OTHER] =
281 ETH_RSS_NONFRAG_IPV4_OTHER,
282 [IAVF_FILTER_PCTYPE_FRAG_IPV4] = ETH_RSS_FRAG_IPV4,
285 [IAVF_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
286 ETH_RSS_NONFRAG_IPV6_UDP,
287 [IAVF_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
288 ETH_RSS_NONFRAG_IPV6_UDP,
289 [IAVF_FILTER_PCTYPE_NONF_IPV6_UDP] =
290 ETH_RSS_NONFRAG_IPV6_UDP,
291 [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
292 ETH_RSS_NONFRAG_IPV6_TCP,
293 [IAVF_FILTER_PCTYPE_NONF_IPV6_TCP] =
294 ETH_RSS_NONFRAG_IPV6_TCP,
295 [IAVF_FILTER_PCTYPE_NONF_IPV6_SCTP] =
296 ETH_RSS_NONFRAG_IPV6_SCTP,
297 [IAVF_FILTER_PCTYPE_NONF_IPV6_OTHER] =
298 ETH_RSS_NONFRAG_IPV6_OTHER,
299 [IAVF_FILTER_PCTYPE_FRAG_IPV6] = ETH_RSS_FRAG_IPV6,
302 [IAVF_FILTER_PCTYPE_L2_PAYLOAD] = ETH_RSS_L2_PAYLOAD
305 const uint64_t ipv4_rss = ETH_RSS_NONFRAG_IPV4_UDP |
306 ETH_RSS_NONFRAG_IPV4_TCP |
307 ETH_RSS_NONFRAG_IPV4_SCTP |
308 ETH_RSS_NONFRAG_IPV4_OTHER |
311 const uint64_t ipv6_rss = ETH_RSS_NONFRAG_IPV6_UDP |
312 ETH_RSS_NONFRAG_IPV6_TCP |
313 ETH_RSS_NONFRAG_IPV6_SCTP |
314 ETH_RSS_NONFRAG_IPV6_OTHER |
317 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
318 uint64_t caps = 0, hena = 0, valid_rss_hf = 0;
322 ret = iavf_get_hena_caps(adapter, &caps);
325 * RSS offload type configuration is not a necessary feature
326 * for VF, so here just print a warning and return.
329 "fail to get RSS offload type caps, ret: %d", ret);
334 * ETH_RSS_IPV4 and ETH_RSS_IPV6 can be considered as 2
335 * generalizations of all other IPv4 and IPv6 RSS types.
337 if (rss_hf & ETH_RSS_IPV4)
340 if (rss_hf & ETH_RSS_IPV6)
343 RTE_BUILD_BUG_ON(RTE_DIM(map_hena_rss) > sizeof(uint64_t) * CHAR_BIT);
345 for (i = 0; i < RTE_DIM(map_hena_rss); i++) {
346 uint64_t bit = BIT_ULL(i);
348 if ((caps & bit) && (map_hena_rss[i] & rss_hf)) {
349 valid_rss_hf |= map_hena_rss[i];
354 ret = iavf_set_hena(adapter, hena);
357 * RSS offload type configuration is not a necessary feature
358 * for VF, so here just print a warning and return.
361 "fail to set RSS offload types, ret: %d", ret);
365 if (valid_rss_hf & ipv4_rss)
366 valid_rss_hf |= rss_hf & ETH_RSS_IPV4;
368 if (valid_rss_hf & ipv6_rss)
369 valid_rss_hf |= rss_hf & ETH_RSS_IPV6;
371 if (rss_hf & ~valid_rss_hf)
372 PMD_DRV_LOG(WARNING, "Unsupported rss_hf 0x%" PRIx64,
373 rss_hf & ~valid_rss_hf);
375 vf->rss_hf = valid_rss_hf;
379 iavf_init_rss(struct iavf_adapter *adapter)
381 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
382 struct rte_eth_rss_conf *rss_conf;
386 rss_conf = &adapter->dev_data->dev_conf.rx_adv_conf.rss_conf;
387 nb_q = RTE_MIN(adapter->dev_data->nb_rx_queues,
388 vf->max_rss_qregion);
390 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF)) {
391 PMD_DRV_LOG(DEBUG, "RSS is not supported");
395 /* configure RSS key */
396 if (!rss_conf->rss_key) {
397 /* Calculate the default hash key */
398 for (i = 0; i < vf->vf_res->rss_key_size; i++)
399 vf->rss_key[i] = (uint8_t)rte_rand();
401 rte_memcpy(vf->rss_key, rss_conf->rss_key,
402 RTE_MIN(rss_conf->rss_key_len,
403 vf->vf_res->rss_key_size));
405 /* init RSS LUT table */
406 for (i = 0, j = 0; i < vf->vf_res->rss_lut_size; i++, j++) {
411 /* send virtchnnl ops to configure rss*/
412 ret = iavf_configure_rss_lut(adapter);
415 ret = iavf_configure_rss_key(adapter);
419 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
420 /* Set RSS hash configuration based on rss_conf->rss_hf. */
421 ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
423 PMD_DRV_LOG(ERR, "fail to set default RSS");
427 iavf_config_rss_hf(adapter, rss_conf->rss_hf);
434 iavf_queues_req_reset(struct rte_eth_dev *dev, uint16_t num)
436 struct iavf_adapter *ad =
437 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
438 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
441 ret = iavf_request_queues(dev, num);
443 PMD_DRV_LOG(ERR, "request queues from PF failed");
446 PMD_DRV_LOG(INFO, "change queue pairs from %u to %u",
447 vf->vsi_res->num_queue_pairs, num);
449 ret = iavf_dev_reset(dev);
451 PMD_DRV_LOG(ERR, "vf reset failed");
459 iavf_dev_vlan_insert_set(struct rte_eth_dev *dev)
461 struct iavf_adapter *adapter =
462 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
463 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
466 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2))
469 enable = !!(dev->data->dev_conf.txmode.offloads &
470 DEV_TX_OFFLOAD_VLAN_INSERT);
471 iavf_config_vlan_insert_v2(adapter, enable);
477 iavf_dev_init_vlan(struct rte_eth_dev *dev)
481 err = iavf_dev_vlan_offload_set(dev,
482 ETH_VLAN_STRIP_MASK |
483 ETH_QINQ_STRIP_MASK |
484 ETH_VLAN_FILTER_MASK |
485 ETH_VLAN_EXTEND_MASK);
487 PMD_DRV_LOG(ERR, "Failed to update vlan offload");
491 err = iavf_dev_vlan_insert_set(dev);
493 PMD_DRV_LOG(ERR, "Failed to update vlan insertion");
499 iavf_dev_configure(struct rte_eth_dev *dev)
501 struct iavf_adapter *ad =
502 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
503 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(ad);
504 uint16_t num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
505 dev->data->nb_tx_queues);
508 ad->rx_bulk_alloc_allowed = true;
509 /* Initialize to TRUE. If any of Rx queues doesn't meet the
510 * vector Rx/Tx preconditions, it will be reset.
512 ad->rx_vec_allowed = true;
513 ad->tx_vec_allowed = true;
515 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
516 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
518 /* Large VF setting */
519 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_DFLT) {
520 if (!(vf->vf_res->vf_cap_flags &
521 VIRTCHNL_VF_LARGE_NUM_QPAIRS)) {
522 PMD_DRV_LOG(ERR, "large VF is not supported");
526 if (num_queue_pairs > IAVF_MAX_NUM_QUEUES_LV) {
527 PMD_DRV_LOG(ERR, "queue pairs number cannot be larger than %u",
528 IAVF_MAX_NUM_QUEUES_LV);
532 ret = iavf_queues_req_reset(dev, num_queue_pairs);
536 ret = iavf_get_max_rss_queue_region(ad);
538 PMD_INIT_LOG(ERR, "get max rss queue region failed");
542 vf->lv_enabled = true;
544 /* Check if large VF is already enabled. If so, disable and
545 * release redundant queue resource.
546 * Or check if enough queue pairs. If not, request them from PF.
548 if (vf->lv_enabled ||
549 num_queue_pairs > vf->vsi_res->num_queue_pairs) {
550 ret = iavf_queues_req_reset(dev, num_queue_pairs);
554 vf->lv_enabled = false;
556 /* if large VF is not required, use default rss queue region */
557 vf->max_rss_qregion = IAVF_MAX_NUM_QUEUES_DFLT;
560 ret = iavf_dev_init_vlan(dev);
562 PMD_DRV_LOG(ERR, "configure VLAN failed: %d", ret);
564 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
565 if (iavf_init_rss(ad) != 0) {
566 PMD_DRV_LOG(ERR, "configure rss failed");
574 iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
576 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
577 struct rte_eth_dev_data *dev_data = dev->data;
578 uint16_t buf_size, max_pkt_len;
579 uint32_t frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
581 buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
583 /* Calculate the maximum packet length allowed */
584 max_pkt_len = RTE_MIN((uint32_t)
585 rxq->rx_buf_len * IAVF_MAX_CHAINED_RX_BUFFERS,
588 /* Check if the jumbo frame and maximum packet length are set
591 if (dev->data->mtu & RTE_ETHER_MTU) {
592 if (max_pkt_len <= IAVF_ETH_MAX_LEN ||
593 max_pkt_len > IAVF_FRAME_SIZE_MAX) {
594 PMD_DRV_LOG(ERR, "maximum packet length must be "
595 "larger than %u and smaller than %u, "
596 "as jumbo frame is enabled",
597 (uint32_t)IAVF_ETH_MAX_LEN,
598 (uint32_t)IAVF_FRAME_SIZE_MAX);
602 if (max_pkt_len < RTE_ETHER_MIN_LEN ||
603 max_pkt_len > IAVF_ETH_MAX_LEN) {
604 PMD_DRV_LOG(ERR, "maximum packet length must be "
605 "larger than %u and smaller than %u, "
606 "as jumbo frame is disabled",
607 (uint32_t)RTE_ETHER_MIN_LEN,
608 (uint32_t)IAVF_ETH_MAX_LEN);
613 rxq->max_pkt_len = max_pkt_len;
614 if ((dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) ||
615 rxq->max_pkt_len > buf_size) {
616 dev_data->scattered_rx = 1;
618 IAVF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
619 IAVF_WRITE_FLUSH(hw);
625 iavf_init_queues(struct rte_eth_dev *dev)
627 struct iavf_rx_queue **rxq =
628 (struct iavf_rx_queue **)dev->data->rx_queues;
629 int i, ret = IAVF_SUCCESS;
631 for (i = 0; i < dev->data->nb_rx_queues; i++) {
632 if (!rxq[i] || !rxq[i]->q_set)
634 ret = iavf_init_rxq(dev, rxq[i]);
635 if (ret != IAVF_SUCCESS)
638 /* set rx/tx function to vector/scatter/single-segment
639 * according to parameters
641 iavf_set_rx_function(dev);
642 iavf_set_tx_function(dev);
647 static int iavf_config_rx_queues_irqs(struct rte_eth_dev *dev,
648 struct rte_intr_handle *intr_handle)
650 struct iavf_adapter *adapter =
651 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
652 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
653 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
654 struct iavf_qv_map *qv_map;
655 uint16_t interval, i;
658 if (rte_intr_cap_multiple(intr_handle) &&
659 dev->data->dev_conf.intr_conf.rxq) {
660 if (rte_intr_efd_enable(intr_handle, dev->data->nb_rx_queues))
664 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
665 intr_handle->intr_vec =
666 rte_zmalloc("intr_vec",
667 dev->data->nb_rx_queues * sizeof(int), 0);
668 if (!intr_handle->intr_vec) {
669 PMD_DRV_LOG(ERR, "Failed to allocate %d rx intr_vec",
670 dev->data->nb_rx_queues);
675 qv_map = rte_zmalloc("qv_map",
676 dev->data->nb_rx_queues * sizeof(struct iavf_qv_map), 0);
678 PMD_DRV_LOG(ERR, "Failed to allocate %d queue-vector map",
679 dev->data->nb_rx_queues);
680 goto qv_map_alloc_err;
683 if (!dev->data->dev_conf.intr_conf.rxq ||
684 !rte_intr_dp_is_en(intr_handle)) {
685 /* Rx interrupt disabled, Map interrupt only for writeback */
687 if (vf->vf_res->vf_cap_flags &
688 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
689 /* If WB_ON_ITR supports, enable it */
690 vf->msix_base = IAVF_RX_VEC_START;
691 /* Set the ITR for index zero, to 2us to make sure that
692 * we leave time for aggregation to occur, but don't
693 * increase latency dramatically.
696 IAVF_VFINT_DYN_CTLN1(vf->msix_base - 1),
697 (0 << IAVF_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) |
698 IAVF_VFINT_DYN_CTLN1_WB_ON_ITR_MASK |
699 (2UL << IAVF_VFINT_DYN_CTLN1_INTERVAL_SHIFT));
700 /* debug - check for success! the return value
701 * should be 2, offset is 0x2800
703 /* IAVF_READ_REG(hw, IAVF_VFINT_ITRN1(0, 0)); */
705 /* If no WB_ON_ITR offload flags, need to set
706 * interrupt for descriptor write back.
708 vf->msix_base = IAVF_MISC_VEC_ID;
710 /* set ITR to default */
711 interval = iavf_calc_itr_interval(
712 IAVF_QUEUE_ITR_INTERVAL_DEFAULT);
713 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
714 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
715 (IAVF_ITR_INDEX_DEFAULT <<
716 IAVF_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
718 IAVF_VFINT_DYN_CTL01_INTERVAL_SHIFT));
720 IAVF_WRITE_FLUSH(hw);
721 /* map all queues to the same interrupt */
722 for (i = 0; i < dev->data->nb_rx_queues; i++) {
723 qv_map[i].queue_id = i;
724 qv_map[i].vector_id = vf->msix_base;
728 if (!rte_intr_allow_others(intr_handle)) {
730 vf->msix_base = IAVF_MISC_VEC_ID;
731 for (i = 0; i < dev->data->nb_rx_queues; i++) {
732 qv_map[i].queue_id = i;
733 qv_map[i].vector_id = vf->msix_base;
734 intr_handle->intr_vec[i] = IAVF_MISC_VEC_ID;
738 "vector %u are mapping to all Rx queues",
741 /* If Rx interrupt is reuquired, and we can use
742 * multi interrupts, then the vec is from 1
744 vf->nb_msix = RTE_MIN(intr_handle->nb_efd,
745 (uint16_t)(vf->vf_res->max_vectors - 1));
746 vf->msix_base = IAVF_RX_VEC_START;
747 vec = IAVF_RX_VEC_START;
748 for (i = 0; i < dev->data->nb_rx_queues; i++) {
749 qv_map[i].queue_id = i;
750 qv_map[i].vector_id = vec;
751 intr_handle->intr_vec[i] = vec++;
752 if (vec >= vf->nb_msix + IAVF_RX_VEC_START)
753 vec = IAVF_RX_VEC_START;
757 "%u vectors are mapping to %u Rx queues",
758 vf->nb_msix, dev->data->nb_rx_queues);
762 if (!vf->lv_enabled) {
763 if (iavf_config_irq_map(adapter)) {
764 PMD_DRV_LOG(ERR, "config interrupt mapping failed");
765 goto config_irq_map_err;
768 uint16_t num_qv_maps = dev->data->nb_rx_queues;
771 while (num_qv_maps > IAVF_IRQ_MAP_NUM_PER_BUF) {
772 if (iavf_config_irq_map_lv(adapter,
773 IAVF_IRQ_MAP_NUM_PER_BUF, index)) {
774 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
775 goto config_irq_map_err;
777 num_qv_maps -= IAVF_IRQ_MAP_NUM_PER_BUF;
778 index += IAVF_IRQ_MAP_NUM_PER_BUF;
781 if (iavf_config_irq_map_lv(adapter, num_qv_maps, index)) {
782 PMD_DRV_LOG(ERR, "config interrupt mapping for large VF failed");
783 goto config_irq_map_err;
789 rte_free(vf->qv_map);
793 rte_free(intr_handle->intr_vec);
794 intr_handle->intr_vec = NULL;
800 iavf_start_queues(struct rte_eth_dev *dev)
802 struct iavf_rx_queue *rxq;
803 struct iavf_tx_queue *txq;
806 for (i = 0; i < dev->data->nb_tx_queues; i++) {
807 txq = dev->data->tx_queues[i];
808 if (txq->tx_deferred_start)
810 if (iavf_dev_tx_queue_start(dev, i) != 0) {
811 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
816 for (i = 0; i < dev->data->nb_rx_queues; i++) {
817 rxq = dev->data->rx_queues[i];
818 if (rxq->rx_deferred_start)
820 if (iavf_dev_rx_queue_start(dev, i) != 0) {
821 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
830 iavf_dev_start(struct rte_eth_dev *dev)
832 struct iavf_adapter *adapter =
833 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
834 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
835 struct rte_intr_handle *intr_handle = dev->intr_handle;
836 uint16_t num_queue_pairs;
839 PMD_INIT_FUNC_TRACE();
841 adapter->stopped = 0;
843 vf->max_pkt_len = dev->data->mtu + IAVF_ETH_OVERHEAD;
844 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
845 dev->data->nb_tx_queues);
846 num_queue_pairs = vf->num_queue_pairs;
848 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)
849 if (iavf_get_qos_cap(adapter)) {
850 PMD_INIT_LOG(ERR, "Failed to get qos capability");
854 if (iavf_init_queues(dev) != 0) {
855 PMD_DRV_LOG(ERR, "failed to do Queue init");
859 /* If needed, send configure queues msg multiple times to make the
860 * adminq buffer length smaller than the 4K limitation.
862 while (num_queue_pairs > IAVF_CFG_Q_NUM_PER_BUF) {
863 if (iavf_configure_queues(adapter,
864 IAVF_CFG_Q_NUM_PER_BUF, index) != 0) {
865 PMD_DRV_LOG(ERR, "configure queues failed");
868 num_queue_pairs -= IAVF_CFG_Q_NUM_PER_BUF;
869 index += IAVF_CFG_Q_NUM_PER_BUF;
872 if (iavf_configure_queues(adapter, num_queue_pairs, index) != 0) {
873 PMD_DRV_LOG(ERR, "configure queues failed");
877 if (iavf_config_rx_queues_irqs(dev, intr_handle) != 0) {
878 PMD_DRV_LOG(ERR, "configure irq failed");
881 /* re-enable intr again, because efd assign may change */
882 if (dev->data->dev_conf.intr_conf.rxq != 0) {
883 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
884 rte_intr_disable(intr_handle);
885 rte_intr_enable(intr_handle);
888 /* Set all mac addrs */
889 iavf_add_del_all_mac_addr(adapter, true);
891 /* Set all multicast addresses */
892 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
895 if (iavf_start_queues(dev) != 0) {
896 PMD_DRV_LOG(ERR, "enable queues failed");
903 iavf_add_del_all_mac_addr(adapter, false);
909 iavf_dev_stop(struct rte_eth_dev *dev)
911 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
912 struct iavf_adapter *adapter =
913 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
914 struct rte_intr_handle *intr_handle = dev->intr_handle;
916 PMD_INIT_FUNC_TRACE();
918 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) &&
919 dev->data->dev_conf.intr_conf.rxq != 0)
920 rte_intr_disable(intr_handle);
922 if (adapter->stopped == 1)
925 iavf_stop_queues(dev);
927 /* Disable the interrupt for Rx */
928 rte_intr_efd_disable(intr_handle);
929 /* Rx interrupt vector mapping free */
930 if (intr_handle->intr_vec) {
931 rte_free(intr_handle->intr_vec);
932 intr_handle->intr_vec = NULL;
935 /* remove all mac addrs */
936 iavf_add_del_all_mac_addr(adapter, false);
938 /* remove all multicast addresses */
939 iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
942 adapter->stopped = 1;
943 dev->data->dev_started = 0;
949 iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
951 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
953 dev_info->max_rx_queues = IAVF_MAX_NUM_QUEUES_LV;
954 dev_info->max_tx_queues = IAVF_MAX_NUM_QUEUES_LV;
955 dev_info->min_rx_bufsize = IAVF_BUF_SIZE_MIN;
956 dev_info->max_rx_pktlen = IAVF_FRAME_SIZE_MAX;
957 dev_info->max_mtu = dev_info->max_rx_pktlen - IAVF_ETH_OVERHEAD;
958 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
959 dev_info->hash_key_size = vf->vf_res->rss_key_size;
960 dev_info->reta_size = vf->vf_res->rss_lut_size;
961 dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
962 dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
963 dev_info->rx_offload_capa =
964 DEV_RX_OFFLOAD_VLAN_STRIP |
965 DEV_RX_OFFLOAD_QINQ_STRIP |
966 DEV_RX_OFFLOAD_IPV4_CKSUM |
967 DEV_RX_OFFLOAD_UDP_CKSUM |
968 DEV_RX_OFFLOAD_TCP_CKSUM |
969 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
970 DEV_RX_OFFLOAD_SCATTER |
971 DEV_RX_OFFLOAD_VLAN_FILTER |
972 DEV_RX_OFFLOAD_RSS_HASH;
974 dev_info->tx_offload_capa =
975 DEV_TX_OFFLOAD_VLAN_INSERT |
976 DEV_TX_OFFLOAD_QINQ_INSERT |
977 DEV_TX_OFFLOAD_IPV4_CKSUM |
978 DEV_TX_OFFLOAD_UDP_CKSUM |
979 DEV_TX_OFFLOAD_TCP_CKSUM |
980 DEV_TX_OFFLOAD_SCTP_CKSUM |
981 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
982 DEV_TX_OFFLOAD_TCP_TSO |
983 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
984 DEV_TX_OFFLOAD_GRE_TNL_TSO |
985 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
986 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
987 DEV_TX_OFFLOAD_MULTI_SEGS |
988 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
990 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
991 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_KEEP_CRC;
993 dev_info->default_rxconf = (struct rte_eth_rxconf) {
994 .rx_free_thresh = IAVF_DEFAULT_RX_FREE_THRESH,
999 dev_info->default_txconf = (struct rte_eth_txconf) {
1000 .tx_free_thresh = IAVF_DEFAULT_TX_FREE_THRESH,
1001 .tx_rs_thresh = IAVF_DEFAULT_TX_RS_THRESH,
1005 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1006 .nb_max = IAVF_MAX_RING_DESC,
1007 .nb_min = IAVF_MIN_RING_DESC,
1008 .nb_align = IAVF_ALIGN_RING_DESC,
1011 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1012 .nb_max = IAVF_MAX_RING_DESC,
1013 .nb_min = IAVF_MIN_RING_DESC,
1014 .nb_align = IAVF_ALIGN_RING_DESC,
1020 static const uint32_t *
1021 iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1023 static const uint32_t ptypes[] = {
1025 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1028 RTE_PTYPE_L4_NONFRAG,
1038 iavf_dev_link_update(struct rte_eth_dev *dev,
1039 __rte_unused int wait_to_complete)
1041 struct rte_eth_link new_link;
1042 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1044 memset(&new_link, 0, sizeof(new_link));
1046 /* Only read status info stored in VF, and the info is updated
1047 * when receive LINK_CHANGE evnet from PF by Virtchnnl.
1049 switch (vf->link_speed) {
1051 new_link.link_speed = ETH_SPEED_NUM_10M;
1054 new_link.link_speed = ETH_SPEED_NUM_100M;
1057 new_link.link_speed = ETH_SPEED_NUM_1G;
1060 new_link.link_speed = ETH_SPEED_NUM_10G;
1063 new_link.link_speed = ETH_SPEED_NUM_20G;
1066 new_link.link_speed = ETH_SPEED_NUM_25G;
1069 new_link.link_speed = ETH_SPEED_NUM_40G;
1072 new_link.link_speed = ETH_SPEED_NUM_50G;
1075 new_link.link_speed = ETH_SPEED_NUM_100G;
1078 new_link.link_speed = ETH_SPEED_NUM_NONE;
1082 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
1083 new_link.link_status = vf->link_up ? ETH_LINK_UP :
1085 new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1086 ETH_LINK_SPEED_FIXED);
1088 return rte_eth_linkstatus_set(dev, &new_link);
1092 iavf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1094 struct iavf_adapter *adapter =
1095 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1096 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1098 return iavf_config_promisc(adapter,
1099 true, vf->promisc_multicast_enabled);
1103 iavf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1105 struct iavf_adapter *adapter =
1106 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1107 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1109 return iavf_config_promisc(adapter,
1110 false, vf->promisc_multicast_enabled);
1114 iavf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1116 struct iavf_adapter *adapter =
1117 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1118 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1120 return iavf_config_promisc(adapter,
1121 vf->promisc_unicast_enabled, true);
1125 iavf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1127 struct iavf_adapter *adapter =
1128 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1129 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1131 return iavf_config_promisc(adapter,
1132 vf->promisc_unicast_enabled, false);
1136 iavf_dev_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr,
1137 __rte_unused uint32_t index,
1138 __rte_unused uint32_t pool)
1140 struct iavf_adapter *adapter =
1141 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1142 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1145 if (rte_is_zero_ether_addr(addr)) {
1146 PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
1150 err = iavf_add_del_eth_addr(adapter, addr, true, VIRTCHNL_ETHER_ADDR_EXTRA);
1152 PMD_DRV_LOG(ERR, "fail to add MAC address");
1162 iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1164 struct iavf_adapter *adapter =
1165 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1166 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1167 struct rte_ether_addr *addr;
1170 addr = &dev->data->mac_addrs[index];
1172 err = iavf_add_del_eth_addr(adapter, addr, false, VIRTCHNL_ETHER_ADDR_EXTRA);
1174 PMD_DRV_LOG(ERR, "fail to delete MAC address");
1180 iavf_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1182 struct iavf_adapter *adapter =
1183 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1184 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1187 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
1188 err = iavf_add_del_vlan_v2(adapter, vlan_id, on);
1194 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1197 err = iavf_add_del_vlan(adapter, vlan_id, on);
1204 iavf_iterate_vlan_filters_v2(struct rte_eth_dev *dev, bool enable)
1206 struct rte_vlan_filter_conf *vfc = &dev->data->vlan_filter_conf;
1207 struct iavf_adapter *adapter =
1208 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1212 for (i = 0; i < RTE_DIM(vfc->ids); i++) {
1213 if (vfc->ids[i] == 0)
1217 for (j = 0; ids != 0 && j < 64; j++, ids >>= 1) {
1219 iavf_add_del_vlan_v2(adapter,
1220 64 * i + j, enable);
1226 iavf_dev_vlan_offload_set_v2(struct rte_eth_dev *dev, int mask)
1228 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1229 struct iavf_adapter *adapter =
1230 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1234 if (mask & ETH_VLAN_FILTER_MASK) {
1235 enable = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER);
1237 iavf_iterate_vlan_filters_v2(dev, enable);
1240 if (mask & ETH_VLAN_STRIP_MASK) {
1241 enable = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
1243 err = iavf_config_vlan_strip_v2(adapter, enable);
1244 /* If not support, the stripping is already disabled by PF */
1245 if (err == -ENOTSUP && !enable)
1255 iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1257 struct iavf_adapter *adapter =
1258 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1259 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1260 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1263 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
1264 return iavf_dev_vlan_offload_set_v2(dev, mask);
1266 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
1269 /* Vlan stripping setting */
1270 if (mask & ETH_VLAN_STRIP_MASK) {
1271 /* Enable or disable VLAN stripping */
1272 if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1273 err = iavf_enable_vlan_strip(adapter);
1275 err = iavf_disable_vlan_strip(adapter);
1284 iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
1285 struct rte_eth_rss_reta_entry64 *reta_conf,
1288 struct iavf_adapter *adapter =
1289 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1290 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1292 uint16_t i, idx, shift;
1295 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1298 if (reta_size != vf->vf_res->rss_lut_size) {
1299 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1300 "(%d) doesn't match the number of hardware can "
1301 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1305 lut = rte_zmalloc("rss_lut", reta_size, 0);
1307 PMD_DRV_LOG(ERR, "No memory can be allocated");
1310 /* store the old lut table temporarily */
1311 rte_memcpy(lut, vf->rss_lut, reta_size);
1313 for (i = 0; i < reta_size; i++) {
1314 idx = i / RTE_RETA_GROUP_SIZE;
1315 shift = i % RTE_RETA_GROUP_SIZE;
1316 if (reta_conf[idx].mask & (1ULL << shift))
1317 lut[i] = reta_conf[idx].reta[shift];
1320 rte_memcpy(vf->rss_lut, lut, reta_size);
1321 /* send virtchnnl ops to configure rss*/
1322 ret = iavf_configure_rss_lut(adapter);
1323 if (ret) /* revert back */
1324 rte_memcpy(vf->rss_lut, lut, reta_size);
1331 iavf_dev_rss_reta_query(struct rte_eth_dev *dev,
1332 struct rte_eth_rss_reta_entry64 *reta_conf,
1335 struct iavf_adapter *adapter =
1336 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1337 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1338 uint16_t i, idx, shift;
1340 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1343 if (reta_size != vf->vf_res->rss_lut_size) {
1344 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1345 "(%d) doesn't match the number of hardware can "
1346 "support (%d)", reta_size, vf->vf_res->rss_lut_size);
1350 for (i = 0; i < reta_size; i++) {
1351 idx = i / RTE_RETA_GROUP_SIZE;
1352 shift = i % RTE_RETA_GROUP_SIZE;
1353 if (reta_conf[idx].mask & (1ULL << shift))
1354 reta_conf[idx].reta[shift] = vf->rss_lut[i];
1361 iavf_set_rss_key(struct iavf_adapter *adapter, uint8_t *key, uint8_t key_len)
1363 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1365 /* HENA setting, it is enabled by default, no change */
1366 if (!key || key_len == 0) {
1367 PMD_DRV_LOG(DEBUG, "No key to be configured");
1369 } else if (key_len != vf->vf_res->rss_key_size) {
1370 PMD_DRV_LOG(ERR, "The size of hash key configured "
1371 "(%d) doesn't match the size of hardware can "
1372 "support (%d)", key_len,
1373 vf->vf_res->rss_key_size);
1377 rte_memcpy(vf->rss_key, key, key_len);
1379 return iavf_configure_rss_key(adapter);
1383 iavf_dev_rss_hash_update(struct rte_eth_dev *dev,
1384 struct rte_eth_rss_conf *rss_conf)
1386 struct iavf_adapter *adapter =
1387 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1388 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1391 adapter->dev_data->dev_conf.rx_adv_conf.rss_conf = *rss_conf;
1393 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1397 ret = iavf_set_rss_key(adapter, rss_conf->rss_key,
1398 rss_conf->rss_key_len);
1402 if (rss_conf->rss_hf == 0) {
1404 ret = iavf_set_hena(adapter, 0);
1406 /* It is a workaround, temporarily allow error to be returned
1407 * due to possible lack of PF handling for hena = 0.
1410 PMD_DRV_LOG(WARNING, "fail to clean existing RSS, lack PF support");
1414 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF) {
1415 /* Clear existing RSS. */
1416 ret = iavf_set_hena(adapter, 0);
1418 /* It is a workaround, temporarily allow error to be returned
1419 * due to possible lack of PF handling for hena = 0.
1422 PMD_DRV_LOG(WARNING, "fail to clean existing RSS,"
1425 /* Set new RSS configuration. */
1426 ret = iavf_rss_hash_set(adapter, rss_conf->rss_hf, true);
1428 PMD_DRV_LOG(ERR, "fail to set new RSS");
1432 iavf_config_rss_hf(adapter, rss_conf->rss_hf);
1439 iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1440 struct rte_eth_rss_conf *rss_conf)
1442 struct iavf_adapter *adapter =
1443 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1444 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1446 if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF))
1449 rss_conf->rss_hf = vf->rss_hf;
1451 if (!rss_conf->rss_key)
1454 rss_conf->rss_key_len = vf->vf_res->rss_key_size;
1455 rte_memcpy(rss_conf->rss_key, vf->rss_key, rss_conf->rss_key_len);
1461 iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
1463 /* mtu setting is forbidden if port is start */
1464 if (dev->data->dev_started) {
1465 PMD_DRV_LOG(ERR, "port must be stopped before configuration");
1473 iavf_dev_set_default_mac_addr(struct rte_eth_dev *dev,
1474 struct rte_ether_addr *mac_addr)
1476 struct iavf_adapter *adapter =
1477 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1478 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1479 struct rte_ether_addr *old_addr;
1482 old_addr = (struct rte_ether_addr *)hw->mac.addr;
1484 if (rte_is_same_ether_addr(old_addr, mac_addr))
1487 ret = iavf_add_del_eth_addr(adapter, old_addr, false, VIRTCHNL_ETHER_ADDR_PRIMARY);
1489 PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
1490 RTE_ETHER_ADDR_PRT_FMT,
1491 RTE_ETHER_ADDR_BYTES(old_addr));
1493 ret = iavf_add_del_eth_addr(adapter, mac_addr, true, VIRTCHNL_ETHER_ADDR_PRIMARY);
1495 PMD_DRV_LOG(ERR, "Fail to add new MAC:"
1496 RTE_ETHER_ADDR_PRT_FMT,
1497 RTE_ETHER_ADDR_BYTES(mac_addr));
1502 rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw->mac.addr);
1507 iavf_stat_update_48(uint64_t *offset, uint64_t *stat)
1509 if (*stat >= *offset)
1510 *stat = *stat - *offset;
1512 *stat = (uint64_t)((*stat +
1513 ((uint64_t)1 << IAVF_48_BIT_WIDTH)) - *offset);
1515 *stat &= IAVF_48_BIT_MASK;
1519 iavf_stat_update_32(uint64_t *offset, uint64_t *stat)
1521 if (*stat >= *offset)
1522 *stat = (uint64_t)(*stat - *offset);
1524 *stat = (uint64_t)((*stat +
1525 ((uint64_t)1 << IAVF_32_BIT_WIDTH)) - *offset);
1529 iavf_update_stats(struct iavf_vsi *vsi, struct virtchnl_eth_stats *nes)
1531 struct virtchnl_eth_stats *oes = &vsi->eth_stats_offset;
1533 iavf_stat_update_48(&oes->rx_bytes, &nes->rx_bytes);
1534 iavf_stat_update_48(&oes->rx_unicast, &nes->rx_unicast);
1535 iavf_stat_update_48(&oes->rx_multicast, &nes->rx_multicast);
1536 iavf_stat_update_48(&oes->rx_broadcast, &nes->rx_broadcast);
1537 iavf_stat_update_32(&oes->rx_discards, &nes->rx_discards);
1538 iavf_stat_update_48(&oes->tx_bytes, &nes->tx_bytes);
1539 iavf_stat_update_48(&oes->tx_unicast, &nes->tx_unicast);
1540 iavf_stat_update_48(&oes->tx_multicast, &nes->tx_multicast);
1541 iavf_stat_update_48(&oes->tx_broadcast, &nes->tx_broadcast);
1542 iavf_stat_update_32(&oes->tx_errors, &nes->tx_errors);
1543 iavf_stat_update_32(&oes->tx_discards, &nes->tx_discards);
1547 iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1549 struct iavf_adapter *adapter =
1550 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1551 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1552 struct iavf_vsi *vsi = &vf->vsi;
1553 struct virtchnl_eth_stats *pstats = NULL;
1556 ret = iavf_query_stats(adapter, &pstats);
1558 uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads &
1559 DEV_RX_OFFLOAD_KEEP_CRC) ? 0 :
1561 iavf_update_stats(vsi, pstats);
1562 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
1563 pstats->rx_broadcast - pstats->rx_discards;
1564 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1566 stats->imissed = pstats->rx_discards;
1567 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1568 stats->ibytes = pstats->rx_bytes;
1569 stats->ibytes -= stats->ipackets * crc_stats_len;
1570 stats->obytes = pstats->tx_bytes;
1572 PMD_DRV_LOG(ERR, "Get statistics failed");
1578 iavf_dev_stats_reset(struct rte_eth_dev *dev)
1581 struct iavf_adapter *adapter =
1582 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1583 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1584 struct iavf_vsi *vsi = &vf->vsi;
1585 struct virtchnl_eth_stats *pstats = NULL;
1587 /* read stat values to clear hardware registers */
1588 ret = iavf_query_stats(adapter, &pstats);
1592 /* set stats offset base on current values */
1593 vsi->eth_stats_offset = *pstats;
1598 static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1599 struct rte_eth_xstat_name *xstats_names,
1600 __rte_unused unsigned int limit)
1604 if (xstats_names != NULL)
1605 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1606 snprintf(xstats_names[i].name,
1607 sizeof(xstats_names[i].name),
1608 "%s", rte_iavf_stats_strings[i].name);
1610 return IAVF_NB_XSTATS;
1613 static int iavf_dev_xstats_get(struct rte_eth_dev *dev,
1614 struct rte_eth_xstat *xstats, unsigned int n)
1618 struct iavf_adapter *adapter =
1619 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1620 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1621 struct iavf_vsi *vsi = &vf->vsi;
1622 struct virtchnl_eth_stats *pstats = NULL;
1624 if (n < IAVF_NB_XSTATS)
1625 return IAVF_NB_XSTATS;
1627 ret = iavf_query_stats(adapter, &pstats);
1634 iavf_update_stats(vsi, pstats);
1636 /* loop over xstats array and values from pstats */
1637 for (i = 0; i < IAVF_NB_XSTATS; i++) {
1639 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1640 rte_iavf_stats_strings[i].offset);
1643 return IAVF_NB_XSTATS;
1648 iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1650 struct iavf_adapter *adapter =
1651 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1652 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1653 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
1654 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
1657 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1658 if (msix_intr == IAVF_MISC_VEC_ID) {
1659 PMD_DRV_LOG(INFO, "MISC is also enabled for control");
1660 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
1661 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
1662 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1663 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
1666 IAVF_VFINT_DYN_CTLN1
1667 (msix_intr - IAVF_RX_VEC_START),
1668 IAVF_VFINT_DYN_CTLN1_INTENA_MASK |
1669 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
1670 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK);
1673 IAVF_WRITE_FLUSH(hw);
1675 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1676 rte_intr_ack(&pci_dev->intr_handle);
1682 iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1684 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1685 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1688 msix_intr = pci_dev->intr_handle.intr_vec[queue_id];
1689 if (msix_intr == IAVF_MISC_VEC_ID) {
1690 PMD_DRV_LOG(ERR, "MISC is used for control, cannot disable it");
1695 IAVF_VFINT_DYN_CTLN1(msix_intr - IAVF_RX_VEC_START),
1698 IAVF_WRITE_FLUSH(hw);
1703 iavf_check_vf_reset_done(struct iavf_hw *hw)
1707 for (i = 0; i < IAVF_RESET_WAIT_CNT; i++) {
1708 reset = IAVF_READ_REG(hw, IAVF_VFGEN_RSTAT) &
1709 IAVF_VFGEN_RSTAT_VFR_STATE_MASK;
1710 reset = reset >> IAVF_VFGEN_RSTAT_VFR_STATE_SHIFT;
1711 if (reset == VIRTCHNL_VFR_VFACTIVE ||
1712 reset == VIRTCHNL_VFR_COMPLETED)
1717 if (i >= IAVF_RESET_WAIT_CNT)
1724 iavf_lookup_proto_xtr_type(const char *flex_name)
1728 enum iavf_proto_xtr_type type;
1729 } xtr_type_map[] = {
1730 { "vlan", IAVF_PROTO_XTR_VLAN },
1731 { "ipv4", IAVF_PROTO_XTR_IPV4 },
1732 { "ipv6", IAVF_PROTO_XTR_IPV6 },
1733 { "ipv6_flow", IAVF_PROTO_XTR_IPV6_FLOW },
1734 { "tcp", IAVF_PROTO_XTR_TCP },
1735 { "ip_offset", IAVF_PROTO_XTR_IP_OFFSET },
1739 for (i = 0; i < RTE_DIM(xtr_type_map); i++) {
1740 if (strcmp(flex_name, xtr_type_map[i].name) == 0)
1741 return xtr_type_map[i].type;
1744 PMD_DRV_LOG(ERR, "wrong proto_xtr type, "
1745 "it should be: vlan|ipv4|ipv6|ipv6_flow|tcp|ip_offset");
1751 * Parse elem, the elem could be single number/range or '(' ')' group
1752 * 1) A single number elem, it's just a simple digit. e.g. 9
1753 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
1754 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
1755 * Within group elem, '-' used for a range separator;
1756 * ',' used for a single number.
1759 iavf_parse_queue_set(const char *input, int xtr_type,
1760 struct iavf_devargs *devargs)
1762 const char *str = input;
1767 while (isblank(*str))
1770 if (!isdigit(*str) && *str != '(')
1773 /* process single number or single range of number */
1776 idx = strtoul(str, &end, 10);
1777 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1780 while (isblank(*end))
1786 /* process single <number>-<number> */
1789 while (isblank(*end))
1795 idx = strtoul(end, &end, 10);
1796 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1800 while (isblank(*end))
1807 for (idx = RTE_MIN(min, max);
1808 idx <= RTE_MAX(min, max); idx++)
1809 devargs->proto_xtr[idx] = xtr_type;
1814 /* process set within bracket */
1816 while (isblank(*str))
1821 min = IAVF_MAX_QUEUE_NUM;
1823 /* go ahead to the first digit */
1824 while (isblank(*str))
1829 /* get the digit value */
1831 idx = strtoul(str, &end, 10);
1832 if (errno || !end || idx >= IAVF_MAX_QUEUE_NUM)
1835 /* go ahead to separator '-',',' and ')' */
1836 while (isblank(*end))
1839 if (min == IAVF_MAX_QUEUE_NUM)
1841 else /* avoid continuous '-' */
1843 } else if (*end == ',' || *end == ')') {
1845 if (min == IAVF_MAX_QUEUE_NUM)
1848 for (idx = RTE_MIN(min, max);
1849 idx <= RTE_MAX(min, max); idx++)
1850 devargs->proto_xtr[idx] = xtr_type;
1852 min = IAVF_MAX_QUEUE_NUM;
1858 } while (*end != ')' && *end != '\0');
1864 iavf_parse_queue_proto_xtr(const char *queues, struct iavf_devargs *devargs)
1866 const char *queue_start;
1871 while (isblank(*queues))
1874 if (*queues != '[') {
1875 xtr_type = iavf_lookup_proto_xtr_type(queues);
1879 devargs->proto_xtr_dflt = xtr_type;
1886 while (isblank(*queues))
1888 if (*queues == '\0')
1891 queue_start = queues;
1893 /* go across a complete bracket */
1894 if (*queue_start == '(') {
1895 queues += strcspn(queues, ")");
1900 /* scan the separator ':' */
1901 queues += strcspn(queues, ":");
1902 if (*queues++ != ':')
1904 while (isblank(*queues))
1907 for (idx = 0; ; idx++) {
1908 if (isblank(queues[idx]) ||
1909 queues[idx] == ',' ||
1910 queues[idx] == ']' ||
1911 queues[idx] == '\0')
1914 if (idx > sizeof(flex_name) - 2)
1917 flex_name[idx] = queues[idx];
1919 flex_name[idx] = '\0';
1920 xtr_type = iavf_lookup_proto_xtr_type(flex_name);
1926 while (isblank(*queues) || *queues == ',' || *queues == ']')
1929 if (iavf_parse_queue_set(queue_start, xtr_type, devargs) < 0)
1931 } while (*queues != '\0');
1937 iavf_handle_proto_xtr_arg(__rte_unused const char *key, const char *value,
1940 struct iavf_devargs *devargs = extra_args;
1942 if (!value || !extra_args)
1945 if (iavf_parse_queue_proto_xtr(value, devargs) < 0) {
1946 PMD_DRV_LOG(ERR, "the proto_xtr's parameter is wrong : '%s'",
1954 static int iavf_parse_devargs(struct rte_eth_dev *dev)
1956 struct iavf_adapter *ad =
1957 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1958 struct rte_devargs *devargs = dev->device->devargs;
1959 struct rte_kvargs *kvlist;
1965 kvlist = rte_kvargs_parse(devargs->args, iavf_valid_args);
1967 PMD_INIT_LOG(ERR, "invalid kvargs key\n");
1971 ad->devargs.proto_xtr_dflt = IAVF_PROTO_XTR_NONE;
1972 memset(ad->devargs.proto_xtr, IAVF_PROTO_XTR_NONE,
1973 sizeof(ad->devargs.proto_xtr));
1975 ret = rte_kvargs_process(kvlist, IAVF_PROTO_XTR_ARG,
1976 &iavf_handle_proto_xtr_arg, &ad->devargs);
1981 rte_kvargs_free(kvlist);
1986 iavf_init_proto_xtr(struct rte_eth_dev *dev)
1988 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1989 struct iavf_adapter *ad =
1990 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1991 const struct iavf_proto_xtr_ol *xtr_ol;
1992 bool proto_xtr_enable = false;
1996 vf->proto_xtr = rte_zmalloc("vf proto xtr",
1997 vf->vsi_res->num_queue_pairs, 0);
1998 if (unlikely(!(vf->proto_xtr))) {
1999 PMD_DRV_LOG(ERR, "no memory for setting up proto_xtr's table");
2003 for (i = 0; i < vf->vsi_res->num_queue_pairs; i++) {
2004 vf->proto_xtr[i] = ad->devargs.proto_xtr[i] !=
2005 IAVF_PROTO_XTR_NONE ?
2006 ad->devargs.proto_xtr[i] :
2007 ad->devargs.proto_xtr_dflt;
2009 if (vf->proto_xtr[i] != IAVF_PROTO_XTR_NONE) {
2010 uint8_t type = vf->proto_xtr[i];
2012 iavf_proto_xtr_params[type].required = true;
2013 proto_xtr_enable = true;
2017 if (likely(!proto_xtr_enable))
2020 offset = rte_mbuf_dynfield_register(&iavf_proto_xtr_metadata_param);
2021 if (unlikely(offset == -1)) {
2023 "failed to extract protocol metadata, error %d",
2029 "proto_xtr metadata offset in mbuf is : %d",
2031 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = offset;
2033 for (i = 0; i < RTE_DIM(iavf_proto_xtr_params); i++) {
2034 xtr_ol = &iavf_proto_xtr_params[i];
2036 uint8_t rxdid = iavf_proto_xtr_type_to_rxdid((uint8_t)i);
2038 if (!xtr_ol->required)
2041 if (!(vf->supported_rxdid & BIT(rxdid))) {
2043 "rxdid[%u] is not supported in hardware",
2045 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2049 offset = rte_mbuf_dynflag_register(&xtr_ol->param);
2050 if (unlikely(offset == -1)) {
2052 "failed to register proto_xtr offload '%s', error %d",
2053 xtr_ol->param.name, -rte_errno);
2055 rte_pmd_ifd_dynfield_proto_xtr_metadata_offs = -1;
2060 "proto_xtr offload '%s' offset in mbuf is : %d",
2061 xtr_ol->param.name, offset);
2062 *xtr_ol->ol_flag = 1ULL << offset;
2067 iavf_init_vf(struct rte_eth_dev *dev)
2070 struct iavf_adapter *adapter =
2071 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2072 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2073 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2077 err = iavf_parse_devargs(dev);
2079 PMD_INIT_LOG(ERR, "Failed to parse devargs");
2083 err = iavf_set_mac_type(hw);
2085 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
2089 err = iavf_check_vf_reset_done(hw);
2091 PMD_INIT_LOG(ERR, "VF is still resetting");
2095 iavf_init_adminq_parameter(hw);
2096 err = iavf_init_adminq(hw);
2098 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
2102 vf->aq_resp = rte_zmalloc("vf_aq_resp", IAVF_AQ_BUF_SZ, 0);
2104 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
2107 if (iavf_check_api_version(adapter) != 0) {
2108 PMD_INIT_LOG(ERR, "check_api version failed");
2112 bufsz = sizeof(struct virtchnl_vf_resource) +
2113 (IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
2114 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
2116 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
2120 if (iavf_get_vf_resource(adapter) != 0) {
2121 PMD_INIT_LOG(ERR, "iavf_get_vf_config failed");
2124 /* Allocate memort for RSS info */
2125 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2126 vf->rss_key = rte_zmalloc("rss_key",
2127 vf->vf_res->rss_key_size, 0);
2129 PMD_INIT_LOG(ERR, "unable to allocate rss_key memory");
2132 vf->rss_lut = rte_zmalloc("rss_lut",
2133 vf->vf_res->rss_lut_size, 0);
2135 PMD_INIT_LOG(ERR, "unable to allocate rss_lut memory");
2140 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
2141 if (iavf_get_supported_rxdid(adapter) != 0) {
2142 PMD_INIT_LOG(ERR, "failed to do get supported rxdid");
2147 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
2148 if (iavf_get_vlan_offload_caps_v2(adapter) != 0) {
2149 PMD_INIT_LOG(ERR, "failed to do get VLAN offload v2 capabilities");
2154 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS) {
2155 bufsz = sizeof(struct virtchnl_qos_cap_list) +
2156 IAVF_MAX_TRAFFIC_CLASS *
2157 sizeof(struct virtchnl_qos_cap_elem);
2158 vf->qos_cap = rte_zmalloc("qos_cap", bufsz, 0);
2160 PMD_INIT_LOG(ERR, "unable to allocate qos_cap memory");
2163 iavf_tm_conf_init(dev);
2166 iavf_init_proto_xtr(dev);
2170 rte_free(vf->rss_key);
2171 rte_free(vf->rss_lut);
2173 rte_free(vf->qos_cap);
2174 rte_free(vf->vf_res);
2177 rte_free(vf->aq_resp);
2179 iavf_shutdown_adminq(hw);
2185 iavf_uninit_vf(struct rte_eth_dev *dev)
2187 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2188 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2190 iavf_shutdown_adminq(hw);
2192 rte_free(vf->vf_res);
2196 rte_free(vf->aq_resp);
2199 rte_free(vf->qos_cap);
2202 rte_free(vf->rss_lut);
2204 rte_free(vf->rss_key);
2208 /* Enable default admin queue interrupt setting */
2210 iavf_enable_irq0(struct iavf_hw *hw)
2212 /* Enable admin queue interrupt trigger */
2213 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1,
2214 IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK);
2216 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2217 IAVF_VFINT_DYN_CTL01_INTENA_MASK |
2218 IAVF_VFINT_DYN_CTL01_CLEARPBA_MASK |
2219 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2221 IAVF_WRITE_FLUSH(hw);
2225 iavf_disable_irq0(struct iavf_hw *hw)
2227 /* Disable all interrupt types */
2228 IAVF_WRITE_REG(hw, IAVF_VFINT_ICR0_ENA1, 0);
2229 IAVF_WRITE_REG(hw, IAVF_VFINT_DYN_CTL01,
2230 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK);
2231 IAVF_WRITE_FLUSH(hw);
2235 iavf_dev_interrupt_handler(void *param)
2237 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2238 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2240 iavf_disable_irq0(hw);
2242 iavf_handle_virtchnl_msg(dev);
2244 iavf_enable_irq0(hw);
2248 iavf_dev_alarm_handler(void *param)
2250 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2251 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2254 iavf_disable_irq0(hw);
2256 /* read out interrupt causes */
2257 icr0 = IAVF_READ_REG(hw, IAVF_VFINT_ICR01);
2259 if (icr0 & IAVF_VFINT_ICR01_ADMINQ_MASK) {
2260 PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported");
2261 iavf_handle_virtchnl_msg(dev);
2264 iavf_enable_irq0(hw);
2266 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
2267 iavf_dev_alarm_handler, dev);
2271 iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
2272 const struct rte_flow_ops **ops)
2277 *ops = &iavf_flow_ops;
2282 iavf_default_rss_disable(struct iavf_adapter *adapter)
2284 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2287 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2288 /* Set hena = 0 to ask PF to cleanup all existing RSS. */
2289 ret = iavf_set_hena(adapter, 0);
2291 /* It is a workaround, temporarily allow error to be
2292 * returned due to possible lack of PF handling for
2295 PMD_INIT_LOG(WARNING, "fail to disable default RSS,"
2301 iavf_dev_init(struct rte_eth_dev *eth_dev)
2303 struct iavf_adapter *adapter =
2304 IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
2305 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(adapter);
2306 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
2307 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2310 PMD_INIT_FUNC_TRACE();
2312 /* assign ops func pointer */
2313 eth_dev->dev_ops = &iavf_eth_dev_ops;
2314 eth_dev->rx_queue_count = iavf_dev_rxq_count;
2315 eth_dev->rx_descriptor_status = iavf_dev_rx_desc_status;
2316 eth_dev->tx_descriptor_status = iavf_dev_tx_desc_status;
2317 eth_dev->rx_pkt_burst = &iavf_recv_pkts;
2318 eth_dev->tx_pkt_burst = &iavf_xmit_pkts;
2319 eth_dev->tx_pkt_prepare = &iavf_prep_pkts;
2321 /* For secondary processes, we don't initialise any further as primary
2322 * has already done this work. Only check if we need a different RX
2325 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2326 iavf_set_rx_function(eth_dev);
2327 iavf_set_tx_function(eth_dev);
2330 rte_eth_copy_pci_info(eth_dev, pci_dev);
2332 hw->vendor_id = pci_dev->id.vendor_id;
2333 hw->device_id = pci_dev->id.device_id;
2334 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2335 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2336 hw->bus.bus_id = pci_dev->addr.bus;
2337 hw->bus.device = pci_dev->addr.devid;
2338 hw->bus.func = pci_dev->addr.function;
2339 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
2340 hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data->dev_private);
2341 adapter->dev_data = eth_dev->data;
2342 adapter->stopped = 1;
2344 if (iavf_init_vf(eth_dev) != 0) {
2345 PMD_INIT_LOG(ERR, "Init vf failed");
2349 /* set default ptype table */
2350 adapter->ptype_tbl = iavf_get_default_ptype_table();
2353 eth_dev->data->mac_addrs = rte_zmalloc(
2354 "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
2355 if (!eth_dev->data->mac_addrs) {
2356 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
2357 " store MAC addresses",
2358 RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
2362 /* If the MAC address is not configured by host,
2363 * generate a random one.
2365 if (!rte_is_valid_assigned_ether_addr(
2366 (struct rte_ether_addr *)hw->mac.addr))
2367 rte_eth_random_addr(hw->mac.addr);
2368 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
2369 ð_dev->data->mac_addrs[0]);
2371 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
2372 /* register callback func to eal lib */
2373 rte_intr_callback_register(&pci_dev->intr_handle,
2374 iavf_dev_interrupt_handler,
2377 /* enable uio intr after callback register */
2378 rte_intr_enable(&pci_dev->intr_handle);
2380 rte_eal_alarm_set(IAVF_ALARM_INTERVAL,
2381 iavf_dev_alarm_handler, eth_dev);
2384 /* configure and enable device interrupt */
2385 iavf_enable_irq0(hw);
2387 ret = iavf_flow_init(adapter);
2389 PMD_INIT_LOG(ERR, "Failed to initialize flow");
2393 iavf_default_rss_disable(adapter);
2398 rte_free(eth_dev->data->mac_addrs);
2399 eth_dev->data->mac_addrs = NULL;
2402 iavf_uninit_vf(eth_dev);
2408 iavf_dev_close(struct rte_eth_dev *dev)
2410 struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2411 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2412 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2413 struct iavf_adapter *adapter =
2414 IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2415 struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2418 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2421 ret = iavf_dev_stop(dev);
2423 iavf_flow_flush(dev, NULL);
2424 iavf_flow_uninit(adapter);
2427 * disable promiscuous mode before reset vf
2428 * it is a workaround solution when work with kernel driver
2429 * and it is not the normal way
2431 if (vf->promisc_unicast_enabled || vf->promisc_multicast_enabled)
2432 iavf_config_promisc(adapter, false, false);
2434 iavf_shutdown_adminq(hw);
2435 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
2436 /* disable uio intr before callback unregister */
2437 rte_intr_disable(intr_handle);
2439 /* unregister callback func from eal lib */
2440 rte_intr_callback_unregister(intr_handle,
2441 iavf_dev_interrupt_handler, dev);
2443 rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev);
2445 iavf_disable_irq0(hw);
2447 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS)
2448 iavf_tm_conf_uninit(dev);
2450 if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2452 rte_free(vf->rss_lut);
2456 rte_free(vf->rss_key);
2461 rte_free(vf->vf_res);
2465 rte_free(vf->aq_resp);
2469 * If the VF is reset via VFLR, the device will be knocked out of bus
2470 * master mode, and the driver will fail to recover from the reset. Fix
2471 * this by enabling bus mastering after every reset. In a non-VFLR case,
2472 * the bus master bit will not be disabled, and this call will have no
2475 if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
2476 vf->vf_reset = false;
2482 iavf_dev_uninit(struct rte_eth_dev *dev)
2484 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2487 iavf_dev_close(dev);
2493 * Reset VF device only to re-initialize resources in PMD layer
2496 iavf_dev_reset(struct rte_eth_dev *dev)
2500 ret = iavf_dev_uninit(dev);
2504 return iavf_dev_init(dev);
2508 iavf_dcf_cap_check_handler(__rte_unused const char *key,
2509 const char *value, __rte_unused void *opaque)
2511 if (strcmp(value, "dcf"))
2518 iavf_dcf_cap_selected(struct rte_devargs *devargs)
2520 struct rte_kvargs *kvlist;
2521 const char *key = "cap";
2524 if (devargs == NULL)
2527 kvlist = rte_kvargs_parse(devargs->args, NULL);
2531 if (!rte_kvargs_count(kvlist, key))
2534 /* dcf capability selected when there's a key-value pair: cap=dcf */
2535 if (rte_kvargs_process(kvlist, key,
2536 iavf_dcf_cap_check_handler, NULL) < 0)
2542 rte_kvargs_free(kvlist);
2546 static int eth_iavf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2547 struct rte_pci_device *pci_dev)
2549 if (iavf_dcf_cap_selected(pci_dev->device.devargs))
2552 return rte_eth_dev_pci_generic_probe(pci_dev,
2553 sizeof(struct iavf_adapter), iavf_dev_init);
2556 static int eth_iavf_pci_remove(struct rte_pci_device *pci_dev)
2558 return rte_eth_dev_pci_generic_remove(pci_dev, iavf_dev_uninit);
2561 /* Adaptive virtual function driver struct */
2562 static struct rte_pci_driver rte_iavf_pmd = {
2563 .id_table = pci_id_iavf_map,
2564 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2565 .probe = eth_iavf_pci_probe,
2566 .remove = eth_iavf_pci_remove,
2569 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
2570 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
2571 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
2572 RTE_PMD_REGISTER_PARAM_STRING(net_iavf, "cap=dcf");
2573 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_init, init, NOTICE);
2574 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_driver, driver, NOTICE);
2575 #ifdef RTE_ETHDEV_DEBUG_RX
2576 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_rx, rx, DEBUG);
2578 #ifdef RTE_ETHDEV_DEBUG_TX
2579 RTE_LOG_REGISTER_SUFFIX(iavf_logtype_tx, tx, DEBUG);