4 * Copyright (C) Cavium networks Ltd. 2016.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <netinet/in.h>
43 #include <sys/queue.h>
45 #include <rte_alarm.h>
46 #include <rte_atomic.h>
47 #include <rte_branch_prediction.h>
48 #include <rte_byteorder.h>
49 #include <rte_common.h>
50 #include <rte_cycles.h>
51 #include <rte_debug.h>
54 #include <rte_ether.h>
55 #include <rte_ethdev.h>
56 #include <rte_interrupts.h>
58 #include <rte_memory.h>
59 #include <rte_memzone.h>
60 #include <rte_malloc.h>
61 #include <rte_random.h>
63 #include <rte_tailq.h>
65 #include "base/nicvf_plat.h"
67 #include "nicvf_ethdev.h"
68 #include "nicvf_rxtx.h"
69 #include "nicvf_svf.h"
70 #include "nicvf_logs.h"
72 static void nicvf_dev_stop(struct rte_eth_dev *dev);
73 static void nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup);
74 static void nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic,
78 nicvf_atomic_write_link_status(struct rte_eth_dev *dev,
79 struct rte_eth_link *link)
81 struct rte_eth_link *dst = &dev->data->dev_link;
82 struct rte_eth_link *src = link;
84 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
85 *(uint64_t *)src) == 0)
92 nicvf_set_eth_link_status(struct nicvf *nic, struct rte_eth_link *link)
94 link->link_status = nic->link_up;
95 link->link_duplex = ETH_LINK_AUTONEG;
96 if (nic->duplex == NICVF_HALF_DUPLEX)
97 link->link_duplex = ETH_LINK_HALF_DUPLEX;
98 else if (nic->duplex == NICVF_FULL_DUPLEX)
99 link->link_duplex = ETH_LINK_FULL_DUPLEX;
100 link->link_speed = nic->speed;
101 link->link_autoneg = ETH_LINK_AUTONEG;
105 nicvf_interrupt(void *arg)
107 struct rte_eth_dev *dev = arg;
108 struct nicvf *nic = nicvf_pmd_priv(dev);
110 if (nicvf_reg_poll_interrupts(nic) == NIC_MBOX_MSG_BGX_LINK_CHANGE) {
111 if (dev->data->dev_conf.intr_conf.lsc)
112 nicvf_set_eth_link_status(nic, &dev->data->dev_link);
113 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
116 rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
117 nicvf_interrupt, dev);
121 nicvf_vf_interrupt(void *arg)
123 struct nicvf *nic = arg;
125 nicvf_reg_poll_interrupts(nic);
127 rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
128 nicvf_vf_interrupt, nic);
132 nicvf_periodic_alarm_start(void (fn)(void *), void *arg)
134 return rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000, fn, arg);
138 nicvf_periodic_alarm_stop(void (fn)(void *), void *arg)
140 return rte_eal_alarm_cancel(fn, arg);
144 * Return 0 means link status changed, -1 means not changed
147 nicvf_dev_link_update(struct rte_eth_dev *dev,
148 int wait_to_complete __rte_unused)
150 struct rte_eth_link link;
151 struct nicvf *nic = nicvf_pmd_priv(dev);
153 PMD_INIT_FUNC_TRACE();
155 memset(&link, 0, sizeof(link));
156 nicvf_set_eth_link_status(nic, &link);
157 return nicvf_atomic_write_link_status(dev, &link);
161 nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
163 struct nicvf *nic = nicvf_pmd_priv(dev);
164 uint32_t buffsz, frame_size = mtu + NIC_HW_L2_OVERHEAD;
167 PMD_INIT_FUNC_TRACE();
169 if (frame_size > NIC_HW_MAX_FRS)
172 if (frame_size < NIC_HW_MIN_FRS)
175 buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
178 * Refuse mtu that requires the support of scattered packets
179 * when this feature has not been enabled before.
181 if (dev->data->dev_started && !dev->data->scattered_rx &&
182 (frame_size + 2 * VLAN_TAG_SIZE > buffsz))
185 /* check <seg size> * <max_seg> >= max_frame */
186 if (dev->data->scattered_rx &&
187 (frame_size + 2 * VLAN_TAG_SIZE > buffsz * NIC_HW_MAX_SEGS))
190 if (frame_size > ETHER_MAX_LEN)
191 dev->data->dev_conf.rxmode.jumbo_frame = 1;
193 dev->data->dev_conf.rxmode.jumbo_frame = 0;
195 if (nicvf_mbox_update_hw_max_frs(nic, mtu))
198 /* Update max_rx_pkt_len */
199 dev->data->dev_conf.rxmode.max_rx_pkt_len = mtu + ETHER_HDR_LEN;
202 for (i = 0; i < nic->sqs_count; i++)
203 nic->snicvf[i]->mtu = mtu;
209 nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
211 uint64_t *data = regs->data;
212 struct nicvf *nic = nicvf_pmd_priv(dev);
215 regs->length = nicvf_reg_get_count();
216 regs->width = THUNDERX_REG_BYTES;
220 /* Support only full register dump */
221 if ((regs->length == 0) ||
222 (regs->length == (uint32_t)nicvf_reg_get_count())) {
223 regs->version = nic->vendor_id << 16 | nic->device_id;
224 nicvf_reg_dump(nic, data);
231 nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
234 struct nicvf_hw_rx_qstats rx_qstats;
235 struct nicvf_hw_tx_qstats tx_qstats;
236 struct nicvf_hw_stats port_stats;
237 struct nicvf *nic = nicvf_pmd_priv(dev);
238 uint16_t rx_start, rx_end;
239 uint16_t tx_start, tx_end;
242 /* RX queue indices for the first VF */
243 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
245 /* Reading per RX ring stats */
246 for (qidx = rx_start; qidx <= rx_end; qidx++) {
247 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
250 nicvf_hw_get_rx_qstats(nic, &rx_qstats, qidx);
251 stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
252 stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
255 /* TX queue indices for the first VF */
256 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
258 /* Reading per TX ring stats */
259 for (qidx = tx_start; qidx <= tx_end; qidx++) {
260 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
263 nicvf_hw_get_tx_qstats(nic, &tx_qstats, qidx);
264 stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
265 stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
268 for (i = 0; i < nic->sqs_count; i++) {
269 struct nicvf *snic = nic->snicvf[i];
274 /* RX queue indices for a secondary VF */
275 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
277 /* Reading per RX ring stats */
278 for (qidx = rx_start; qidx <= rx_end; qidx++) {
279 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
282 nicvf_hw_get_rx_qstats(snic, &rx_qstats,
283 qidx % MAX_RCV_QUEUES_PER_QS);
284 stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
285 stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
288 /* TX queue indices for a secondary VF */
289 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
290 /* Reading per TX ring stats */
291 for (qidx = tx_start; qidx <= tx_end; qidx++) {
292 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
295 nicvf_hw_get_tx_qstats(snic, &tx_qstats,
296 qidx % MAX_SND_QUEUES_PER_QS);
297 stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
298 stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
302 nicvf_hw_get_stats(nic, &port_stats);
303 stats->ibytes = port_stats.rx_bytes;
304 stats->ipackets = port_stats.rx_ucast_frames;
305 stats->ipackets += port_stats.rx_bcast_frames;
306 stats->ipackets += port_stats.rx_mcast_frames;
307 stats->ierrors = port_stats.rx_l2_errors;
308 stats->imissed = port_stats.rx_drop_red;
309 stats->imissed += port_stats.rx_drop_overrun;
310 stats->imissed += port_stats.rx_drop_bcast;
311 stats->imissed += port_stats.rx_drop_mcast;
312 stats->imissed += port_stats.rx_drop_l3_bcast;
313 stats->imissed += port_stats.rx_drop_l3_mcast;
315 stats->obytes = port_stats.tx_bytes_ok;
316 stats->opackets = port_stats.tx_ucast_frames_ok;
317 stats->opackets += port_stats.tx_bcast_frames_ok;
318 stats->opackets += port_stats.tx_mcast_frames_ok;
319 stats->oerrors = port_stats.tx_drops;
322 static const uint32_t *
323 nicvf_dev_supported_ptypes_get(struct rte_eth_dev *dev)
326 static uint32_t ptypes[32];
327 struct nicvf *nic = nicvf_pmd_priv(dev);
328 static const uint32_t ptypes_common[] = {
330 RTE_PTYPE_L3_IPV4_EXT,
332 RTE_PTYPE_L3_IPV6_EXT,
337 static const uint32_t ptypes_tunnel[] = {
338 RTE_PTYPE_TUNNEL_GRE,
339 RTE_PTYPE_TUNNEL_GENEVE,
340 RTE_PTYPE_TUNNEL_VXLAN,
341 RTE_PTYPE_TUNNEL_NVGRE,
343 static const uint32_t ptypes_end = RTE_PTYPE_UNKNOWN;
345 copied = sizeof(ptypes_common);
346 memcpy(ptypes, ptypes_common, copied);
347 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
348 memcpy((char *)ptypes + copied, ptypes_tunnel,
349 sizeof(ptypes_tunnel));
350 copied += sizeof(ptypes_tunnel);
353 memcpy((char *)ptypes + copied, &ptypes_end, sizeof(ptypes_end));
354 if (dev->rx_pkt_burst == nicvf_recv_pkts ||
355 dev->rx_pkt_burst == nicvf_recv_pkts_multiseg)
362 nicvf_dev_stats_reset(struct rte_eth_dev *dev)
365 uint16_t rxqs = 0, txqs = 0;
366 struct nicvf *nic = nicvf_pmd_priv(dev);
367 uint16_t rx_start, rx_end;
368 uint16_t tx_start, tx_end;
370 /* Reset all primary nic counters */
371 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
372 for (i = rx_start; i <= rx_end; i++)
373 rxqs |= (0x3 << (i * 2));
375 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
376 for (i = tx_start; i <= tx_end; i++)
377 txqs |= (0x3 << (i * 2));
379 nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, rxqs, txqs);
381 /* Reset secondary nic queue counters */
382 for (i = 0; i < nic->sqs_count; i++) {
383 struct nicvf *snic = nic->snicvf[i];
387 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
388 for (i = rx_start; i <= rx_end; i++)
389 rxqs |= (0x3 << ((i % MAX_CMP_QUEUES_PER_QS) * 2));
391 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
392 for (i = tx_start; i <= tx_end; i++)
393 txqs |= (0x3 << ((i % MAX_SND_QUEUES_PER_QS) * 2));
395 nicvf_mbox_reset_stat_counters(snic, 0, 0, rxqs, txqs);
399 /* Promiscuous mode enabled by default in LMAC to VF 1:1 map configuration */
401 nicvf_dev_promisc_enable(struct rte_eth_dev *dev __rte_unused)
405 static inline uint64_t
406 nicvf_rss_ethdev_to_nic(struct nicvf *nic, uint64_t ethdev_rss)
408 uint64_t nic_rss = 0;
410 if (ethdev_rss & ETH_RSS_IPV4)
411 nic_rss |= RSS_IP_ENA;
413 if (ethdev_rss & ETH_RSS_IPV6)
414 nic_rss |= RSS_IP_ENA;
416 if (ethdev_rss & ETH_RSS_NONFRAG_IPV4_UDP)
417 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
419 if (ethdev_rss & ETH_RSS_NONFRAG_IPV4_TCP)
420 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
422 if (ethdev_rss & ETH_RSS_NONFRAG_IPV6_UDP)
423 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
425 if (ethdev_rss & ETH_RSS_NONFRAG_IPV6_TCP)
426 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
428 if (ethdev_rss & ETH_RSS_PORT)
429 nic_rss |= RSS_L2_EXTENDED_HASH_ENA;
431 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
432 if (ethdev_rss & ETH_RSS_VXLAN)
433 nic_rss |= RSS_TUN_VXLAN_ENA;
435 if (ethdev_rss & ETH_RSS_GENEVE)
436 nic_rss |= RSS_TUN_GENEVE_ENA;
438 if (ethdev_rss & ETH_RSS_NVGRE)
439 nic_rss |= RSS_TUN_NVGRE_ENA;
445 static inline uint64_t
446 nicvf_rss_nic_to_ethdev(struct nicvf *nic, uint64_t nic_rss)
448 uint64_t ethdev_rss = 0;
450 if (nic_rss & RSS_IP_ENA)
451 ethdev_rss |= (ETH_RSS_IPV4 | ETH_RSS_IPV6);
453 if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_TCP_ENA))
454 ethdev_rss |= (ETH_RSS_NONFRAG_IPV4_TCP |
455 ETH_RSS_NONFRAG_IPV6_TCP);
457 if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_UDP_ENA))
458 ethdev_rss |= (ETH_RSS_NONFRAG_IPV4_UDP |
459 ETH_RSS_NONFRAG_IPV6_UDP);
461 if (nic_rss & RSS_L2_EXTENDED_HASH_ENA)
462 ethdev_rss |= ETH_RSS_PORT;
464 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
465 if (nic_rss & RSS_TUN_VXLAN_ENA)
466 ethdev_rss |= ETH_RSS_VXLAN;
468 if (nic_rss & RSS_TUN_GENEVE_ENA)
469 ethdev_rss |= ETH_RSS_GENEVE;
471 if (nic_rss & RSS_TUN_NVGRE_ENA)
472 ethdev_rss |= ETH_RSS_NVGRE;
478 nicvf_dev_reta_query(struct rte_eth_dev *dev,
479 struct rte_eth_rss_reta_entry64 *reta_conf,
482 struct nicvf *nic = nicvf_pmd_priv(dev);
483 uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
486 if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
487 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
488 "(%d) doesn't match the number hardware can supported "
489 "(%d)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
493 ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
497 /* Copy RETA table */
498 for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_RETA_GROUP_SIZE); i++) {
499 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
500 if ((reta_conf[i].mask >> j) & 0x01)
501 reta_conf[i].reta[j] = tbl[j];
508 nicvf_dev_reta_update(struct rte_eth_dev *dev,
509 struct rte_eth_rss_reta_entry64 *reta_conf,
512 struct nicvf *nic = nicvf_pmd_priv(dev);
513 uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
516 if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
517 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
518 "(%d) doesn't match the number hardware can supported "
519 "(%d)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
523 ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
527 /* Copy RETA table */
528 for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_RETA_GROUP_SIZE); i++) {
529 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
530 if ((reta_conf[i].mask >> j) & 0x01)
531 tbl[j] = reta_conf[i].reta[j];
534 return nicvf_rss_reta_update(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
538 nicvf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
539 struct rte_eth_rss_conf *rss_conf)
541 struct nicvf *nic = nicvf_pmd_priv(dev);
543 if (rss_conf->rss_key)
544 nicvf_rss_get_key(nic, rss_conf->rss_key);
546 rss_conf->rss_key_len = RSS_HASH_KEY_BYTE_SIZE;
547 rss_conf->rss_hf = nicvf_rss_nic_to_ethdev(nic, nicvf_rss_get_cfg(nic));
552 nicvf_dev_rss_hash_update(struct rte_eth_dev *dev,
553 struct rte_eth_rss_conf *rss_conf)
555 struct nicvf *nic = nicvf_pmd_priv(dev);
558 if (rss_conf->rss_key &&
559 rss_conf->rss_key_len != RSS_HASH_KEY_BYTE_SIZE) {
560 RTE_LOG(ERR, PMD, "Hash key size mismatch %d",
561 rss_conf->rss_key_len);
565 if (rss_conf->rss_key)
566 nicvf_rss_set_key(nic, rss_conf->rss_key);
568 nic_rss = nicvf_rss_ethdev_to_nic(nic, rss_conf->rss_hf);
569 nicvf_rss_set_cfg(nic, nic_rss);
574 nicvf_qset_cq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
575 struct nicvf_rxq *rxq, uint16_t qidx, uint32_t desc_cnt)
577 const struct rte_memzone *rz;
578 uint32_t ring_size = CMP_QUEUE_SZ_MAX * sizeof(union cq_entry_t);
580 rz = rte_eth_dma_zone_reserve(dev, "cq_ring",
581 nicvf_netdev_qidx(nic, qidx), ring_size,
582 NICVF_CQ_BASE_ALIGN_BYTES, nic->node);
584 PMD_INIT_LOG(ERR, "Failed to allocate mem for cq hw ring");
588 memset(rz->addr, 0, ring_size);
590 rxq->phys = rz->phys_addr;
591 rxq->desc = rz->addr;
592 rxq->qlen_mask = desc_cnt - 1;
598 nicvf_qset_sq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
599 struct nicvf_txq *sq, uint16_t qidx, uint32_t desc_cnt)
601 const struct rte_memzone *rz;
602 uint32_t ring_size = SND_QUEUE_SZ_MAX * sizeof(union sq_entry_t);
604 rz = rte_eth_dma_zone_reserve(dev, "sq",
605 nicvf_netdev_qidx(nic, qidx), ring_size,
606 NICVF_SQ_BASE_ALIGN_BYTES, nic->node);
608 PMD_INIT_LOG(ERR, "Failed allocate mem for sq hw ring");
612 memset(rz->addr, 0, ring_size);
614 sq->phys = rz->phys_addr;
616 sq->qlen_mask = desc_cnt - 1;
622 nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
623 uint32_t desc_cnt, uint32_t buffsz)
625 struct nicvf_rbdr *rbdr;
626 const struct rte_memzone *rz;
629 assert(nic->rbdr == NULL);
630 rbdr = rte_zmalloc_socket("rbdr", sizeof(struct nicvf_rbdr),
631 RTE_CACHE_LINE_SIZE, nic->node);
633 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr");
637 ring_size = sizeof(struct rbdr_entry_t) * RBDR_QUEUE_SZ_MAX;
638 rz = rte_eth_dma_zone_reserve(dev, "rbdr",
639 nicvf_netdev_qidx(nic, 0), ring_size,
640 NICVF_RBDR_BASE_ALIGN_BYTES, nic->node);
642 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr desc ring");
646 memset(rz->addr, 0, ring_size);
648 rbdr->phys = rz->phys_addr;
651 rbdr->desc = rz->addr;
652 rbdr->buffsz = buffsz;
653 rbdr->qlen_mask = desc_cnt - 1;
655 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_STATUS0;
657 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_DOOR;
664 nicvf_rbdr_release_mbuf(struct rte_eth_dev *dev, struct nicvf *nic,
665 nicvf_phys_addr_t phy)
669 struct nicvf_rxq *rxq;
670 uint16_t rx_start, rx_end;
672 /* Get queue ranges for this VF */
673 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
675 for (qidx = rx_start; qidx <= rx_end; qidx++) {
676 rxq = dev->data->rx_queues[qidx];
677 if (rxq->precharge_cnt) {
678 obj = (void *)nicvf_mbuff_phy2virt(phy,
680 rte_mempool_put(rxq->pool, obj);
681 rxq->precharge_cnt--;
688 nicvf_rbdr_release_mbufs(struct rte_eth_dev *dev, struct nicvf *nic)
690 uint32_t qlen_mask, head;
691 struct rbdr_entry_t *entry;
692 struct nicvf_rbdr *rbdr = nic->rbdr;
694 qlen_mask = rbdr->qlen_mask;
696 while (head != rbdr->tail) {
697 entry = rbdr->desc + head;
698 nicvf_rbdr_release_mbuf(dev, nic, entry->full_addr);
700 head = head & qlen_mask;
705 nicvf_tx_queue_release_mbufs(struct nicvf_txq *txq)
710 while (head != txq->tail) {
711 if (txq->txbuffs[head]) {
712 rte_pktmbuf_free_seg(txq->txbuffs[head]);
713 txq->txbuffs[head] = NULL;
716 head = head & txq->qlen_mask;
721 nicvf_tx_queue_reset(struct nicvf_txq *txq)
723 uint32_t txq_desc_cnt = txq->qlen_mask + 1;
725 memset(txq->desc, 0, sizeof(union sq_entry_t) * txq_desc_cnt);
726 memset(txq->txbuffs, 0, sizeof(struct rte_mbuf *) * txq_desc_cnt);
733 nicvf_vf_start_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
736 struct nicvf_txq *txq;
739 assert(qidx < MAX_SND_QUEUES_PER_QS);
741 if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
742 RTE_ETH_QUEUE_STATE_STARTED)
745 txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
747 ret = nicvf_qset_sq_config(nic, qidx, txq);
749 PMD_INIT_LOG(ERR, "Failed to configure sq VF%d %d %d",
750 nic->vf_id, qidx, ret);
751 goto config_sq_error;
754 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
755 RTE_ETH_QUEUE_STATE_STARTED;
759 nicvf_qset_sq_reclaim(nic, qidx);
764 nicvf_vf_stop_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
767 struct nicvf_txq *txq;
770 assert(qidx < MAX_SND_QUEUES_PER_QS);
772 if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
773 RTE_ETH_QUEUE_STATE_STOPPED)
776 ret = nicvf_qset_sq_reclaim(nic, qidx);
778 PMD_INIT_LOG(ERR, "Failed to reclaim sq VF%d %d %d",
779 nic->vf_id, qidx, ret);
781 txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
782 nicvf_tx_queue_release_mbufs(txq);
783 nicvf_tx_queue_reset(txq);
785 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
786 RTE_ETH_QUEUE_STATE_STOPPED;
791 nicvf_configure_cpi(struct rte_eth_dev *dev)
793 struct nicvf *nic = nicvf_pmd_priv(dev);
797 /* Count started rx queues */
798 for (qidx = qcnt = 0; qidx < dev->data->nb_rx_queues; qidx++)
799 if (dev->data->rx_queue_state[qidx] ==
800 RTE_ETH_QUEUE_STATE_STARTED)
803 nic->cpi_alg = CPI_ALG_NONE;
804 ret = nicvf_mbox_config_cpi(nic, qcnt);
806 PMD_INIT_LOG(ERR, "Failed to configure CPI %d", ret);
812 nicvf_configure_rss(struct rte_eth_dev *dev)
814 struct nicvf *nic = nicvf_pmd_priv(dev);
818 rsshf = nicvf_rss_ethdev_to_nic(nic,
819 dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
820 PMD_DRV_LOG(INFO, "mode=%d rx_queues=%d loopback=%d rsshf=0x%" PRIx64,
821 dev->data->dev_conf.rxmode.mq_mode,
822 dev->data->nb_rx_queues,
823 dev->data->dev_conf.lpbk_mode, rsshf);
825 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_NONE)
826 ret = nicvf_rss_term(nic);
827 else if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS)
828 ret = nicvf_rss_config(nic, dev->data->nb_rx_queues, rsshf);
830 PMD_INIT_LOG(ERR, "Failed to configure RSS %d", ret);
836 nicvf_configure_rss_reta(struct rte_eth_dev *dev)
838 struct nicvf *nic = nicvf_pmd_priv(dev);
839 unsigned int idx, qmap_size;
840 uint8_t qmap[RTE_MAX_QUEUES_PER_PORT];
841 uint8_t default_reta[NIC_MAX_RSS_IDR_TBL_SIZE];
843 if (nic->cpi_alg != CPI_ALG_NONE)
846 /* Prepare queue map */
847 for (idx = 0, qmap_size = 0; idx < dev->data->nb_rx_queues; idx++) {
848 if (dev->data->rx_queue_state[idx] ==
849 RTE_ETH_QUEUE_STATE_STARTED)
850 qmap[qmap_size++] = idx;
853 /* Update default RSS RETA */
854 for (idx = 0; idx < NIC_MAX_RSS_IDR_TBL_SIZE; idx++)
855 default_reta[idx] = qmap[idx % qmap_size];
857 return nicvf_rss_reta_update(nic, default_reta,
858 NIC_MAX_RSS_IDR_TBL_SIZE);
862 nicvf_dev_tx_queue_release(void *sq)
864 struct nicvf_txq *txq;
866 PMD_INIT_FUNC_TRACE();
868 txq = (struct nicvf_txq *)sq;
870 if (txq->txbuffs != NULL) {
871 nicvf_tx_queue_release_mbufs(txq);
872 rte_free(txq->txbuffs);
880 nicvf_set_tx_function(struct rte_eth_dev *dev)
882 struct nicvf_txq *txq = NULL;
884 bool multiseg = false;
886 for (i = 0; i < dev->data->nb_tx_queues; i++) {
887 txq = dev->data->tx_queues[i];
888 if ((txq->txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS) == 0) {
894 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
896 PMD_DRV_LOG(DEBUG, "Using multi-segment tx callback");
897 dev->tx_pkt_burst = nicvf_xmit_pkts_multiseg;
899 PMD_DRV_LOG(DEBUG, "Using single-segment tx callback");
900 dev->tx_pkt_burst = nicvf_xmit_pkts;
906 if (txq->pool_free == nicvf_single_pool_free_xmited_buffers)
907 PMD_DRV_LOG(DEBUG, "Using single-mempool tx free method");
909 PMD_DRV_LOG(DEBUG, "Using multi-mempool tx free method");
913 nicvf_set_rx_function(struct rte_eth_dev *dev)
915 if (dev->data->scattered_rx) {
916 PMD_DRV_LOG(DEBUG, "Using multi-segment rx callback");
917 dev->rx_pkt_burst = nicvf_recv_pkts_multiseg;
919 PMD_DRV_LOG(DEBUG, "Using single-segment rx callback");
920 dev->rx_pkt_burst = nicvf_recv_pkts;
925 nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
926 uint16_t nb_desc, unsigned int socket_id,
927 const struct rte_eth_txconf *tx_conf)
929 uint16_t tx_free_thresh;
930 uint8_t is_single_pool;
931 struct nicvf_txq *txq;
932 struct nicvf *nic = nicvf_pmd_priv(dev);
934 PMD_INIT_FUNC_TRACE();
936 if (qidx >= MAX_SND_QUEUES_PER_QS)
937 nic = nic->snicvf[qidx / MAX_SND_QUEUES_PER_QS - 1];
939 qidx = qidx % MAX_SND_QUEUES_PER_QS;
941 /* Socket id check */
942 if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
943 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
944 socket_id, nic->node);
946 /* Tx deferred start is not supported */
947 if (tx_conf->tx_deferred_start) {
948 PMD_INIT_LOG(ERR, "Tx deferred start not supported");
952 /* Roundup nb_desc to available qsize and validate max number of desc */
953 nb_desc = nicvf_qsize_sq_roundup(nb_desc);
955 PMD_INIT_LOG(ERR, "Value of nb_desc beyond available sq qsize");
959 /* Validate tx_free_thresh */
960 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
961 tx_conf->tx_free_thresh :
962 NICVF_DEFAULT_TX_FREE_THRESH);
964 if (tx_free_thresh > (nb_desc) ||
965 tx_free_thresh > NICVF_MAX_TX_FREE_THRESH) {
967 "tx_free_thresh must be less than the number of TX "
968 "descriptors. (tx_free_thresh=%u port=%d "
969 "queue=%d)", (unsigned int)tx_free_thresh,
970 (int)dev->data->port_id, (int)qidx);
974 /* Free memory prior to re-allocation if needed. */
975 if (dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
976 PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
977 nicvf_netdev_qidx(nic, qidx));
978 nicvf_dev_tx_queue_release(
979 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)]);
980 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
983 /* Allocating tx queue data structure */
984 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nicvf_txq),
985 RTE_CACHE_LINE_SIZE, nic->node);
987 PMD_INIT_LOG(ERR, "Failed to allocate txq=%d",
988 nicvf_netdev_qidx(nic, qidx));
993 txq->queue_id = qidx;
994 txq->tx_free_thresh = tx_free_thresh;
995 txq->txq_flags = tx_conf->txq_flags;
996 txq->sq_head = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_HEAD;
997 txq->sq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_DOOR;
998 is_single_pool = (txq->txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT &&
999 txq->txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP);
1001 /* Choose optimum free threshold value for multipool case */
1002 if (!is_single_pool) {
1003 txq->tx_free_thresh = (uint16_t)
1004 (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ?
1005 NICVF_TX_FREE_MPOOL_THRESH :
1006 tx_conf->tx_free_thresh);
1007 txq->pool_free = nicvf_multi_pool_free_xmited_buffers;
1009 txq->pool_free = nicvf_single_pool_free_xmited_buffers;
1012 /* Allocate software ring */
1013 txq->txbuffs = rte_zmalloc_socket("txq->txbuffs",
1014 nb_desc * sizeof(struct rte_mbuf *),
1015 RTE_CACHE_LINE_SIZE, nic->node);
1017 if (txq->txbuffs == NULL) {
1018 nicvf_dev_tx_queue_release(txq);
1022 if (nicvf_qset_sq_alloc(dev, nic, txq, qidx, nb_desc)) {
1023 PMD_INIT_LOG(ERR, "Failed to allocate mem for sq %d", qidx);
1024 nicvf_dev_tx_queue_release(txq);
1028 nicvf_tx_queue_reset(txq);
1030 PMD_TX_LOG(DEBUG, "[%d] txq=%p nb_desc=%d desc=%p phys=0x%" PRIx64,
1031 nicvf_netdev_qidx(nic, qidx), txq, nb_desc, txq->desc,
1034 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = txq;
1035 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1036 RTE_ETH_QUEUE_STATE_STOPPED;
1041 nicvf_rx_queue_release_mbufs(struct rte_eth_dev *dev, struct nicvf_rxq *rxq)
1044 uint32_t nb_pkts, released_pkts = 0;
1045 uint32_t refill_cnt = 0;
1046 struct rte_mbuf *rx_pkts[NICVF_MAX_RX_FREE_THRESH];
1048 if (dev->rx_pkt_burst == NULL)
1051 while ((rxq_cnt = nicvf_dev_rx_queue_count(dev,
1052 nicvf_netdev_qidx(rxq->nic, rxq->queue_id)))) {
1053 nb_pkts = dev->rx_pkt_burst(rxq, rx_pkts,
1054 NICVF_MAX_RX_FREE_THRESH);
1055 PMD_DRV_LOG(INFO, "nb_pkts=%d rxq_cnt=%d", nb_pkts, rxq_cnt);
1057 rte_pktmbuf_free_seg(rx_pkts[--nb_pkts]);
1063 refill_cnt += nicvf_dev_rbdr_refill(dev,
1064 nicvf_netdev_qidx(rxq->nic, rxq->queue_id));
1066 PMD_DRV_LOG(INFO, "free_cnt=%d refill_cnt=%d",
1067 released_pkts, refill_cnt);
1071 nicvf_rx_queue_reset(struct nicvf_rxq *rxq)
1074 rxq->available_space = 0;
1075 rxq->recv_buffers = 0;
1079 nicvf_vf_start_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1082 struct nicvf_rxq *rxq;
1085 assert(qidx < MAX_RCV_QUEUES_PER_QS);
1087 if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1088 RTE_ETH_QUEUE_STATE_STARTED)
1091 /* Update rbdr pointer to all rxq */
1092 rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1093 rxq->shared_rbdr = nic->rbdr;
1095 ret = nicvf_qset_rq_config(nic, qidx, rxq);
1097 PMD_INIT_LOG(ERR, "Failed to configure rq VF%d %d %d",
1098 nic->vf_id, qidx, ret);
1099 goto config_rq_error;
1101 ret = nicvf_qset_cq_config(nic, qidx, rxq);
1103 PMD_INIT_LOG(ERR, "Failed to configure cq VF%d %d %d",
1104 nic->vf_id, qidx, ret);
1105 goto config_cq_error;
1108 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1109 RTE_ETH_QUEUE_STATE_STARTED;
1113 nicvf_qset_cq_reclaim(nic, qidx);
1115 nicvf_qset_rq_reclaim(nic, qidx);
1120 nicvf_vf_stop_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1123 struct nicvf_rxq *rxq;
1124 int ret, other_error;
1126 if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1127 RTE_ETH_QUEUE_STATE_STOPPED)
1130 ret = nicvf_qset_rq_reclaim(nic, qidx);
1132 PMD_INIT_LOG(ERR, "Failed to reclaim rq VF%d %d %d",
1133 nic->vf_id, qidx, ret);
1136 rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1137 nicvf_rx_queue_release_mbufs(dev, rxq);
1138 nicvf_rx_queue_reset(rxq);
1140 ret = nicvf_qset_cq_reclaim(nic, qidx);
1142 PMD_INIT_LOG(ERR, "Failed to reclaim cq VF%d %d %d",
1143 nic->vf_id, qidx, ret);
1146 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1147 RTE_ETH_QUEUE_STATE_STOPPED;
1152 nicvf_dev_rx_queue_release(void *rx_queue)
1154 PMD_INIT_FUNC_TRACE();
1160 nicvf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1162 struct nicvf *nic = nicvf_pmd_priv(dev);
1165 if (qidx >= MAX_RCV_QUEUES_PER_QS)
1166 nic = nic->snicvf[(qidx / MAX_RCV_QUEUES_PER_QS - 1)];
1168 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1170 ret = nicvf_vf_start_rx_queue(dev, nic, qidx);
1174 ret = nicvf_configure_cpi(dev);
1178 return nicvf_configure_rss_reta(dev);
1182 nicvf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1185 struct nicvf *nic = nicvf_pmd_priv(dev);
1187 if (qidx >= MAX_SND_QUEUES_PER_QS)
1188 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1190 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1192 ret = nicvf_vf_stop_rx_queue(dev, nic, qidx);
1193 ret |= nicvf_configure_cpi(dev);
1194 ret |= nicvf_configure_rss_reta(dev);
1199 nicvf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1201 struct nicvf *nic = nicvf_pmd_priv(dev);
1203 if (qidx >= MAX_SND_QUEUES_PER_QS)
1204 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1206 qidx = qidx % MAX_SND_QUEUES_PER_QS;
1208 return nicvf_vf_start_tx_queue(dev, nic, qidx);
1212 nicvf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1214 struct nicvf *nic = nicvf_pmd_priv(dev);
1216 if (qidx >= MAX_SND_QUEUES_PER_QS)
1217 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1219 qidx = qidx % MAX_SND_QUEUES_PER_QS;
1221 return nicvf_vf_stop_tx_queue(dev, nic, qidx);
1226 nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1227 uint16_t nb_desc, unsigned int socket_id,
1228 const struct rte_eth_rxconf *rx_conf,
1229 struct rte_mempool *mp)
1231 uint16_t rx_free_thresh;
1232 struct nicvf_rxq *rxq;
1233 struct nicvf *nic = nicvf_pmd_priv(dev);
1235 PMD_INIT_FUNC_TRACE();
1237 if (qidx >= MAX_RCV_QUEUES_PER_QS)
1238 nic = nic->snicvf[qidx / MAX_RCV_QUEUES_PER_QS - 1];
1240 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1242 /* Socket id check */
1243 if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
1244 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
1245 socket_id, nic->node);
1247 /* Mempool memory must be contiguous, so must be one memory segment*/
1248 if (mp->nb_mem_chunks != 1) {
1249 PMD_INIT_LOG(ERR, "Non-contiguous mempool, add more huge pages");
1253 /* Mempool memory must be physically contiguous */
1254 if (mp->flags & MEMPOOL_F_NO_PHYS_CONTIG) {
1255 PMD_INIT_LOG(ERR, "Mempool memory must be physically contiguous");
1259 /* Rx deferred start is not supported */
1260 if (rx_conf->rx_deferred_start) {
1261 PMD_INIT_LOG(ERR, "Rx deferred start not supported");
1265 /* Roundup nb_desc to available qsize and validate max number of desc */
1266 nb_desc = nicvf_qsize_cq_roundup(nb_desc);
1268 PMD_INIT_LOG(ERR, "Value nb_desc beyond available hw cq qsize");
1272 /* Check rx_free_thresh upper bound */
1273 rx_free_thresh = (uint16_t)((rx_conf->rx_free_thresh) ?
1274 rx_conf->rx_free_thresh :
1275 NICVF_DEFAULT_RX_FREE_THRESH);
1276 if (rx_free_thresh > NICVF_MAX_RX_FREE_THRESH ||
1277 rx_free_thresh >= nb_desc * .75) {
1278 PMD_INIT_LOG(ERR, "rx_free_thresh greater than expected %d",
1283 /* Free memory prior to re-allocation if needed */
1284 if (dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
1285 PMD_RX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
1286 nicvf_netdev_qidx(nic, qidx));
1287 nicvf_dev_rx_queue_release(
1288 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)]);
1289 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
1292 /* Allocate rxq memory */
1293 rxq = rte_zmalloc_socket("ethdev rx queue", sizeof(struct nicvf_rxq),
1294 RTE_CACHE_LINE_SIZE, nic->node);
1296 PMD_INIT_LOG(ERR, "Failed to allocate rxq=%d",
1297 nicvf_netdev_qidx(nic, qidx));
1303 rxq->queue_id = qidx;
1304 rxq->port_id = dev->data->port_id;
1305 rxq->rx_free_thresh = rx_free_thresh;
1306 rxq->rx_drop_en = rx_conf->rx_drop_en;
1307 rxq->cq_status = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_STATUS;
1308 rxq->cq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_DOOR;
1309 rxq->precharge_cnt = 0;
1311 if (nicvf_hw_cap(nic) & NICVF_CAP_CQE_RX2)
1312 rxq->rbptr_offset = NICVF_CQE_RX2_RBPTR_WORD;
1314 rxq->rbptr_offset = NICVF_CQE_RBPTR_WORD;
1317 /* Alloc completion queue */
1318 if (nicvf_qset_cq_alloc(dev, nic, rxq, rxq->queue_id, nb_desc)) {
1319 PMD_INIT_LOG(ERR, "failed to allocate cq %u", rxq->queue_id);
1320 nicvf_dev_rx_queue_release(rxq);
1324 nicvf_rx_queue_reset(rxq);
1326 PMD_RX_LOG(DEBUG, "[%d] rxq=%p pool=%s nb_desc=(%d/%d) phy=%" PRIx64,
1327 nicvf_netdev_qidx(nic, qidx), rxq, mp->name, nb_desc,
1328 rte_mempool_avail_count(mp), rxq->phys);
1330 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = rxq;
1331 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1332 RTE_ETH_QUEUE_STATE_STOPPED;
1337 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1339 struct nicvf *nic = nicvf_pmd_priv(dev);
1341 PMD_INIT_FUNC_TRACE();
1343 dev_info->min_rx_bufsize = ETHER_MIN_MTU;
1344 dev_info->max_rx_pktlen = NIC_HW_MAX_MTU + ETHER_HDR_LEN;
1345 dev_info->max_rx_queues =
1346 (uint16_t)MAX_RCV_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1347 dev_info->max_tx_queues =
1348 (uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1349 dev_info->max_mac_addrs = 1;
1350 dev_info->max_vfs = dev->pci_dev->max_vfs;
1352 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1353 dev_info->tx_offload_capa =
1354 DEV_TX_OFFLOAD_IPV4_CKSUM |
1355 DEV_TX_OFFLOAD_UDP_CKSUM |
1356 DEV_TX_OFFLOAD_TCP_CKSUM |
1357 DEV_TX_OFFLOAD_TCP_TSO |
1358 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
1360 dev_info->reta_size = nic->rss_info.rss_size;
1361 dev_info->hash_key_size = RSS_HASH_KEY_BYTE_SIZE;
1362 dev_info->flow_type_rss_offloads = NICVF_RSS_OFFLOAD_PASS1;
1363 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING)
1364 dev_info->flow_type_rss_offloads |= NICVF_RSS_OFFLOAD_TUNNEL;
1366 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1367 .rx_free_thresh = NICVF_DEFAULT_RX_FREE_THRESH,
1371 dev_info->default_txconf = (struct rte_eth_txconf) {
1372 .tx_free_thresh = NICVF_DEFAULT_TX_FREE_THRESH,
1374 ETH_TXQ_FLAGS_NOMULTSEGS |
1375 ETH_TXQ_FLAGS_NOREFCOUNT |
1376 ETH_TXQ_FLAGS_NOMULTMEMP |
1377 ETH_TXQ_FLAGS_NOVLANOFFL |
1378 ETH_TXQ_FLAGS_NOXSUMSCTP,
1382 static nicvf_phys_addr_t
1383 rbdr_rte_mempool_get(void *dev, void *opaque)
1387 struct nicvf_rxq *rxq;
1388 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)dev;
1389 struct nicvf *nic = (struct nicvf *)opaque;
1390 uint16_t rx_start, rx_end;
1392 /* Get queue ranges for this VF */
1393 nicvf_rx_range(eth_dev, nic, &rx_start, &rx_end);
1395 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1396 rxq = eth_dev->data->rx_queues[qidx];
1397 /* Maintain equal buffer count across all pools */
1398 if (rxq->precharge_cnt >= rxq->qlen_mask)
1400 rxq->precharge_cnt++;
1401 mbuf = (uintptr_t)rte_pktmbuf_alloc(rxq->pool);
1403 return nicvf_mbuff_virt2phy(mbuf, rxq->mbuf_phys_off);
1409 nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
1413 uint32_t total_rxq_desc, nb_rbdr_desc, exp_buffs;
1414 uint64_t mbuf_phys_off = 0;
1415 struct nicvf_rxq *rxq;
1416 struct rte_mbuf *mbuf;
1417 uint16_t rx_start, rx_end;
1418 uint16_t tx_start, tx_end;
1420 PMD_INIT_FUNC_TRACE();
1422 /* Userspace process exited without proper shutdown in last run */
1423 if (nicvf_qset_rbdr_active(nic, 0))
1424 nicvf_vf_stop(dev, nic, false);
1426 /* Get queue ranges for this VF */
1427 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1430 * Thunderx nicvf PMD can support more than one pool per port only when
1431 * 1) Data payload size is same across all the pools in given port
1433 * 2) All mbuffs in the pools are from the same hugepage
1435 * 3) Mbuff metadata size is same across all the pools in given port
1437 * This is to support existing application that uses multiple pool/port.
1438 * But, the purpose of using multipool for QoS will not be addressed.
1442 /* Validate mempool attributes */
1443 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1444 rxq = dev->data->rx_queues[qidx];
1445 rxq->mbuf_phys_off = nicvf_mempool_phy_offset(rxq->pool);
1446 mbuf = rte_pktmbuf_alloc(rxq->pool);
1448 PMD_INIT_LOG(ERR, "Failed allocate mbuf VF%d qid=%d "
1450 nic->vf_id, qidx, rxq->pool->name);
1453 rxq->mbuf_phys_off -= nicvf_mbuff_meta_length(mbuf);
1454 rxq->mbuf_phys_off -= RTE_PKTMBUF_HEADROOM;
1455 rte_pktmbuf_free(mbuf);
1457 if (mbuf_phys_off == 0)
1458 mbuf_phys_off = rxq->mbuf_phys_off;
1459 if (mbuf_phys_off != rxq->mbuf_phys_off) {
1460 PMD_INIT_LOG(ERR, "pool params not same,%s VF%d %"
1461 PRIx64, rxq->pool->name, nic->vf_id,
1467 /* Check the level of buffers in the pool */
1469 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1470 rxq = dev->data->rx_queues[qidx];
1471 /* Count total numbers of rxq descs */
1472 total_rxq_desc += rxq->qlen_mask + 1;
1473 exp_buffs = RTE_MEMPOOL_CACHE_MAX_SIZE + rxq->rx_free_thresh;
1474 exp_buffs *= dev->data->nb_rx_queues;
1475 if (rte_mempool_avail_count(rxq->pool) < exp_buffs) {
1476 PMD_INIT_LOG(ERR, "Buff shortage in pool=%s (%d/%d)",
1478 rte_mempool_avail_count(rxq->pool),
1484 /* Check RBDR desc overflow */
1485 ret = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1487 PMD_INIT_LOG(ERR, "Reached RBDR desc limit, reduce nr desc "
1488 "VF%d", nic->vf_id);
1493 ret = nicvf_qset_config(nic);
1495 PMD_INIT_LOG(ERR, "Failed to enable qset %d VF%d", ret,
1500 /* Allocate RBDR and RBDR ring desc */
1501 nb_rbdr_desc = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1502 ret = nicvf_qset_rbdr_alloc(dev, nic, nb_rbdr_desc, rbdrsz);
1504 PMD_INIT_LOG(ERR, "Failed to allocate memory for rbdr alloc "
1505 "VF%d", nic->vf_id);
1509 /* Enable and configure RBDR registers */
1510 ret = nicvf_qset_rbdr_config(nic, 0);
1512 PMD_INIT_LOG(ERR, "Failed to configure rbdr %d VF%d", ret,
1514 goto qset_rbdr_free;
1517 /* Fill rte_mempool buffers in RBDR pool and precharge it */
1518 ret = nicvf_qset_rbdr_precharge(dev, nic, 0, rbdr_rte_mempool_get,
1521 PMD_INIT_LOG(ERR, "Failed to fill rbdr %d VF%d", ret,
1523 goto qset_rbdr_reclaim;
1526 PMD_DRV_LOG(INFO, "Filled %d out of %d entries in RBDR VF%d",
1527 nic->rbdr->tail, nb_rbdr_desc, nic->vf_id);
1529 /* Configure VLAN Strip */
1530 nicvf_vlan_hw_strip(nic, dev->data->dev_conf.rxmode.hw_vlan_strip);
1532 /* Based on the packet type(IPv4 or IPv6), the nicvf HW aligns L3 data
1533 * to the 64bit memory address.
1534 * The alignment creates a hole in mbuf(between the end of headroom and
1535 * packet data start). The new revision of the HW provides an option to
1536 * disable the L3 alignment feature and make mbuf layout looks
1537 * more like other NICs. For better application compatibility, disabling
1538 * l3 alignment feature on the hardware revisions it supports
1540 nicvf_apad_config(nic, false);
1542 /* Get queue ranges for this VF */
1543 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1545 /* Configure TX queues */
1546 for (qidx = tx_start; qidx <= tx_end; qidx++) {
1547 ret = nicvf_vf_start_tx_queue(dev, nic,
1548 qidx % MAX_SND_QUEUES_PER_QS);
1550 goto start_txq_error;
1553 /* Configure RX queues */
1554 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1555 ret = nicvf_vf_start_rx_queue(dev, nic,
1556 qidx % MAX_RCV_QUEUES_PER_QS);
1558 goto start_rxq_error;
1561 if (!nic->sqs_mode) {
1562 /* Configure CPI algorithm */
1563 ret = nicvf_configure_cpi(dev);
1565 goto start_txq_error;
1567 ret = nicvf_mbox_get_rss_size(nic);
1569 PMD_INIT_LOG(ERR, "Failed to get rss table size");
1570 goto qset_rss_error;
1574 ret = nicvf_configure_rss(dev);
1576 goto qset_rss_error;
1579 /* Done; Let PF make the BGX's RX and TX switches to ON position */
1580 nicvf_mbox_cfg_done(nic);
1584 nicvf_rss_term(nic);
1586 for (qidx = rx_start; qidx <= rx_end; qidx++)
1587 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1589 for (qidx = tx_start; qidx <= tx_end; qidx++)
1590 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1592 nicvf_qset_rbdr_reclaim(nic, 0);
1593 nicvf_rbdr_release_mbufs(dev, nic);
1596 rte_free(nic->rbdr);
1600 nicvf_qset_reclaim(nic);
1605 nicvf_dev_start(struct rte_eth_dev *dev)
1610 struct nicvf *nic = nicvf_pmd_priv(dev);
1611 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
1613 uint32_t buffsz = 0, rbdrsz = 0;
1614 struct rte_pktmbuf_pool_private *mbp_priv;
1615 struct nicvf_rxq *rxq;
1617 PMD_INIT_FUNC_TRACE();
1619 /* This function must be called for a primary device */
1620 assert_primary(nic);
1622 /* Validate RBDR buff size */
1623 for (qidx = 0; qidx < dev->data->nb_rx_queues; qidx++) {
1624 rxq = dev->data->rx_queues[qidx];
1625 mbp_priv = rte_mempool_get_priv(rxq->pool);
1626 buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1628 PMD_INIT_LOG(ERR, "rxbuf size must be multiply of 128");
1633 if (rbdrsz != buffsz) {
1634 PMD_INIT_LOG(ERR, "buffsz not same, qidx=%d (%d/%d)",
1635 qidx, rbdrsz, buffsz);
1640 /* Configure loopback */
1641 ret = nicvf_loopback_config(nic, dev->data->dev_conf.lpbk_mode);
1643 PMD_INIT_LOG(ERR, "Failed to configure loopback %d", ret);
1647 /* Reset all statistics counters attached to this port */
1648 ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, 0xFFFF, 0xFFFF);
1650 PMD_INIT_LOG(ERR, "Failed to reset stat counters %d", ret);
1654 /* Setup scatter mode if needed by jumbo */
1655 if (dev->data->dev_conf.rxmode.max_rx_pkt_len +
1656 2 * VLAN_TAG_SIZE > buffsz)
1657 dev->data->scattered_rx = 1;
1658 if (rx_conf->enable_scatter)
1659 dev->data->scattered_rx = 1;
1661 /* Setup MTU based on max_rx_pkt_len or default */
1662 mtu = dev->data->dev_conf.rxmode.jumbo_frame ?
1663 dev->data->dev_conf.rxmode.max_rx_pkt_len
1664 - ETHER_HDR_LEN : ETHER_MTU;
1666 if (nicvf_dev_set_mtu(dev, mtu)) {
1667 PMD_INIT_LOG(ERR, "Failed to set default mtu size");
1671 ret = nicvf_vf_start(dev, nic, rbdrsz);
1675 for (i = 0; i < nic->sqs_count; i++) {
1676 assert(nic->snicvf[i]);
1678 ret = nicvf_vf_start(dev, nic->snicvf[i], rbdrsz);
1683 /* Configure callbacks based on scatter mode */
1684 nicvf_set_tx_function(dev);
1685 nicvf_set_rx_function(dev);
1691 nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup)
1695 struct nicvf *nic = nicvf_pmd_priv(dev);
1697 PMD_INIT_FUNC_TRACE();
1699 /* Teardown secondary vf first */
1700 for (i = 0; i < nic->sqs_count; i++) {
1701 if (!nic->snicvf[i])
1704 nicvf_vf_stop(dev, nic->snicvf[i], cleanup);
1707 /* Stop the primary VF now */
1708 nicvf_vf_stop(dev, nic, cleanup);
1710 /* Disable loopback */
1711 ret = nicvf_loopback_config(nic, 0);
1713 PMD_INIT_LOG(ERR, "Failed to disable loopback %d", ret);
1715 /* Reclaim CPI configuration */
1716 ret = nicvf_mbox_config_cpi(nic, 0);
1718 PMD_INIT_LOG(ERR, "Failed to reclaim CPI config %d", ret);
1722 nicvf_dev_stop(struct rte_eth_dev *dev)
1724 PMD_INIT_FUNC_TRACE();
1726 nicvf_dev_stop_cleanup(dev, false);
1730 nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic, bool cleanup)
1734 uint16_t tx_start, tx_end;
1735 uint16_t rx_start, rx_end;
1737 PMD_INIT_FUNC_TRACE();
1740 /* Let PF make the BGX's RX and TX switches to OFF position */
1741 nicvf_mbox_shutdown(nic);
1744 /* Disable VLAN Strip */
1745 nicvf_vlan_hw_strip(nic, 0);
1747 /* Get queue ranges for this VF */
1748 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1750 for (qidx = tx_start; qidx <= tx_end; qidx++)
1751 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1753 /* Get queue ranges for this VF */
1754 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1757 for (qidx = rx_start; qidx <= rx_end; qidx++)
1758 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1761 ret = nicvf_qset_rbdr_reclaim(nic, 0);
1763 PMD_INIT_LOG(ERR, "Failed to reclaim RBDR %d", ret);
1765 /* Move all charged buffers in RBDR back to pool */
1766 if (nic->rbdr != NULL)
1767 nicvf_rbdr_release_mbufs(dev, nic);
1770 ret = nicvf_qset_reclaim(nic);
1772 PMD_INIT_LOG(ERR, "Failed to disable qset %d", ret);
1774 /* Disable all interrupts */
1775 nicvf_disable_all_interrupts(nic);
1777 /* Free RBDR SW structure */
1779 rte_free(nic->rbdr);
1785 nicvf_dev_close(struct rte_eth_dev *dev)
1788 struct nicvf *nic = nicvf_pmd_priv(dev);
1790 PMD_INIT_FUNC_TRACE();
1792 nicvf_dev_stop_cleanup(dev, true);
1793 nicvf_periodic_alarm_stop(nicvf_interrupt, dev);
1795 for (i = 0; i < nic->sqs_count; i++) {
1796 if (!nic->snicvf[i])
1799 nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic->snicvf[i]);
1804 nicvf_request_sqs(struct nicvf *nic)
1808 assert_primary(nic);
1809 assert(nic->sqs_count > 0);
1810 assert(nic->sqs_count <= MAX_SQS_PER_VF);
1812 /* Set no of Rx/Tx queues in each of the SQsets */
1813 for (i = 0; i < nic->sqs_count; i++) {
1814 if (nicvf_svf_empty())
1815 rte_panic("Cannot assign sufficient number of "
1816 "secondary queues to primary VF%" PRIu8 "\n",
1819 nic->snicvf[i] = nicvf_svf_pop();
1820 nic->snicvf[i]->sqs_id = i;
1823 return nicvf_mbox_request_sqs(nic);
1827 nicvf_dev_configure(struct rte_eth_dev *dev)
1829 struct rte_eth_dev_data *data = dev->data;
1830 struct rte_eth_conf *conf = &data->dev_conf;
1831 struct rte_eth_rxmode *rxmode = &conf->rxmode;
1832 struct rte_eth_txmode *txmode = &conf->txmode;
1833 struct nicvf *nic = nicvf_pmd_priv(dev);
1836 PMD_INIT_FUNC_TRACE();
1838 if (!rte_eal_has_hugepages()) {
1839 PMD_INIT_LOG(INFO, "Huge page is not configured");
1843 if (txmode->mq_mode) {
1844 PMD_INIT_LOG(INFO, "Tx mq_mode DCB or VMDq not supported");
1848 if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
1849 rxmode->mq_mode != ETH_MQ_RX_RSS) {
1850 PMD_INIT_LOG(INFO, "Unsupported rx qmode %d", rxmode->mq_mode);
1854 if (!rxmode->hw_strip_crc) {
1855 PMD_INIT_LOG(NOTICE, "Can't disable hw crc strip");
1856 rxmode->hw_strip_crc = 1;
1859 if (rxmode->hw_ip_checksum) {
1860 PMD_INIT_LOG(NOTICE, "Rxcksum not supported");
1861 rxmode->hw_ip_checksum = 0;
1864 if (rxmode->split_hdr_size) {
1865 PMD_INIT_LOG(INFO, "Rxmode does not support split header");
1869 if (rxmode->hw_vlan_filter) {
1870 PMD_INIT_LOG(INFO, "VLAN filter not supported");
1874 if (rxmode->hw_vlan_extend) {
1875 PMD_INIT_LOG(INFO, "VLAN extended not supported");
1879 if (rxmode->enable_lro) {
1880 PMD_INIT_LOG(INFO, "LRO not supported");
1884 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
1885 PMD_INIT_LOG(INFO, "Setting link speed/duplex not supported");
1889 if (conf->dcb_capability_en) {
1890 PMD_INIT_LOG(INFO, "DCB enable not supported");
1894 if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1895 PMD_INIT_LOG(INFO, "Flow director not supported");
1899 assert_primary(nic);
1900 NICVF_STATIC_ASSERT(MAX_RCV_QUEUES_PER_QS == MAX_SND_QUEUES_PER_QS);
1901 cqcount = RTE_MAX(data->nb_tx_queues, data->nb_rx_queues);
1902 if (cqcount > MAX_RCV_QUEUES_PER_QS) {
1903 nic->sqs_count = RTE_ALIGN_CEIL(cqcount, MAX_RCV_QUEUES_PER_QS);
1904 nic->sqs_count = (nic->sqs_count / MAX_RCV_QUEUES_PER_QS) - 1;
1909 assert(nic->sqs_count <= MAX_SQS_PER_VF);
1911 if (nic->sqs_count > 0) {
1912 if (nicvf_request_sqs(nic)) {
1913 rte_panic("Cannot assign sufficient number of "
1914 "secondary queues to PORT%d VF%" PRIu8 "\n",
1915 dev->data->port_id, nic->vf_id);
1919 PMD_INIT_LOG(DEBUG, "Configured ethdev port%d hwcap=0x%" PRIx64,
1920 dev->data->port_id, nicvf_hw_cap(nic));
1925 /* Initialize and register driver with DPDK Application */
1926 static const struct eth_dev_ops nicvf_eth_dev_ops = {
1927 .dev_configure = nicvf_dev_configure,
1928 .dev_start = nicvf_dev_start,
1929 .dev_stop = nicvf_dev_stop,
1930 .link_update = nicvf_dev_link_update,
1931 .dev_close = nicvf_dev_close,
1932 .stats_get = nicvf_dev_stats_get,
1933 .stats_reset = nicvf_dev_stats_reset,
1934 .promiscuous_enable = nicvf_dev_promisc_enable,
1935 .dev_infos_get = nicvf_dev_info_get,
1936 .dev_supported_ptypes_get = nicvf_dev_supported_ptypes_get,
1937 .mtu_set = nicvf_dev_set_mtu,
1938 .reta_update = nicvf_dev_reta_update,
1939 .reta_query = nicvf_dev_reta_query,
1940 .rss_hash_update = nicvf_dev_rss_hash_update,
1941 .rss_hash_conf_get = nicvf_dev_rss_hash_conf_get,
1942 .rx_queue_start = nicvf_dev_rx_queue_start,
1943 .rx_queue_stop = nicvf_dev_rx_queue_stop,
1944 .tx_queue_start = nicvf_dev_tx_queue_start,
1945 .tx_queue_stop = nicvf_dev_tx_queue_stop,
1946 .rx_queue_setup = nicvf_dev_rx_queue_setup,
1947 .rx_queue_release = nicvf_dev_rx_queue_release,
1948 .rx_queue_count = nicvf_dev_rx_queue_count,
1949 .tx_queue_setup = nicvf_dev_tx_queue_setup,
1950 .tx_queue_release = nicvf_dev_tx_queue_release,
1951 .get_reg = nicvf_dev_get_regs,
1955 nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
1958 struct rte_pci_device *pci_dev;
1959 struct nicvf *nic = nicvf_pmd_priv(eth_dev);
1961 PMD_INIT_FUNC_TRACE();
1963 eth_dev->dev_ops = &nicvf_eth_dev_ops;
1965 /* For secondary processes, the primary has done all the work */
1966 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1968 /* Setup callbacks for secondary process */
1969 nicvf_set_tx_function(eth_dev);
1970 nicvf_set_rx_function(eth_dev);
1973 /* If nic == NULL than it is secondary function
1974 * so ethdev need to be released by caller */
1979 pci_dev = eth_dev->pci_dev;
1980 rte_eth_copy_pci_info(eth_dev, pci_dev);
1982 nic->device_id = pci_dev->id.device_id;
1983 nic->vendor_id = pci_dev->id.vendor_id;
1984 nic->subsystem_device_id = pci_dev->id.subsystem_device_id;
1985 nic->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1987 PMD_INIT_LOG(DEBUG, "nicvf: device (%x:%x) %u:%u:%u:%u",
1988 pci_dev->id.vendor_id, pci_dev->id.device_id,
1989 pci_dev->addr.domain, pci_dev->addr.bus,
1990 pci_dev->addr.devid, pci_dev->addr.function);
1992 nic->reg_base = (uintptr_t)pci_dev->mem_resource[0].addr;
1993 if (!nic->reg_base) {
1994 PMD_INIT_LOG(ERR, "Failed to map BAR0");
1999 nicvf_disable_all_interrupts(nic);
2001 ret = nicvf_periodic_alarm_start(nicvf_interrupt, eth_dev);
2003 PMD_INIT_LOG(ERR, "Failed to start period alarm");
2007 ret = nicvf_mbox_check_pf_ready(nic);
2009 PMD_INIT_LOG(ERR, "Failed to get ready message from PF");
2013 "node=%d vf=%d mode=%s sqs=%s loopback_supported=%s",
2014 nic->node, nic->vf_id,
2015 nic->tns_mode == NIC_TNS_MODE ? "tns" : "tns-bypass",
2016 nic->sqs_mode ? "true" : "false",
2017 nic->loopback_supported ? "true" : "false"
2021 ret = nicvf_base_init(nic);
2023 PMD_INIT_LOG(ERR, "Failed to execute nicvf_base_init");
2027 if (nic->sqs_mode) {
2028 /* Push nic to stack of secondary vfs */
2029 nicvf_svf_push(nic);
2031 /* Steal nic pointer from the device for further reuse */
2032 eth_dev->data->dev_private = NULL;
2034 nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2035 ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
2037 PMD_INIT_LOG(ERR, "Failed to start period alarm");
2041 /* Detach port by returning postive error number */
2045 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", ETHER_ADDR_LEN, 0);
2046 if (eth_dev->data->mac_addrs == NULL) {
2047 PMD_INIT_LOG(ERR, "Failed to allocate memory for mac addr");
2051 if (is_zero_ether_addr((struct ether_addr *)nic->mac_addr))
2052 eth_random_addr(&nic->mac_addr[0]);
2054 ether_addr_copy((struct ether_addr *)nic->mac_addr,
2055 ð_dev->data->mac_addrs[0]);
2057 ret = nicvf_mbox_set_mac_addr(nic, nic->mac_addr);
2059 PMD_INIT_LOG(ERR, "Failed to set mac addr");
2063 PMD_INIT_LOG(INFO, "Port %d (%x:%x) mac=%02x:%02x:%02x:%02x:%02x:%02x",
2064 eth_dev->data->port_id, nic->vendor_id, nic->device_id,
2065 nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
2066 nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);
2071 rte_free(eth_dev->data->mac_addrs);
2073 nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2078 static const struct rte_pci_id pci_id_nicvf_map[] = {
2080 .class_id = RTE_CLASS_ANY_ID,
2081 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2082 .device_id = PCI_DEVICE_ID_THUNDERX_CN88XX_PASS1_NICVF,
2083 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2084 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS1_NICVF,
2087 .class_id = RTE_CLASS_ANY_ID,
2088 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2089 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2090 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2091 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS2_NICVF,
2094 .class_id = RTE_CLASS_ANY_ID,
2095 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2096 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2097 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2098 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN81XX_NICVF,
2101 .class_id = RTE_CLASS_ANY_ID,
2102 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2103 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2104 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2105 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN83XX_NICVF,
2112 static struct eth_driver rte_nicvf_pmd = {
2114 .id_table = pci_id_nicvf_map,
2115 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2116 .probe = rte_eth_dev_pci_probe,
2117 .remove = rte_eth_dev_pci_remove,
2119 .eth_dev_init = nicvf_eth_dev_init,
2120 .dev_private_size = sizeof(struct nicvf),
2123 RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd.pci_drv);
2124 RTE_PMD_REGISTER_PCI_TABLE(net_thunderx, pci_id_nicvf_map);