4 * Copyright (C) Cavium, Inc. 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, Inc 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_ethdev_pci.h>
57 #include <rte_interrupts.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_random.h>
64 #include <rte_bus_pci.h>
65 #include <rte_tailq.h>
67 #include "base/nicvf_plat.h"
69 #include "nicvf_ethdev.h"
70 #include "nicvf_rxtx.h"
71 #include "nicvf_svf.h"
72 #include "nicvf_logs.h"
74 static void nicvf_dev_stop(struct rte_eth_dev *dev);
75 static void nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup);
76 static void nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic,
80 nicvf_atomic_write_link_status(struct rte_eth_dev *dev,
81 struct rte_eth_link *link)
83 struct rte_eth_link *dst = &dev->data->dev_link;
84 struct rte_eth_link *src = link;
86 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
87 *(uint64_t *)src) == 0)
94 nicvf_set_eth_link_status(struct nicvf *nic, struct rte_eth_link *link)
96 link->link_status = nic->link_up;
97 link->link_duplex = ETH_LINK_AUTONEG;
98 if (nic->duplex == NICVF_HALF_DUPLEX)
99 link->link_duplex = ETH_LINK_HALF_DUPLEX;
100 else if (nic->duplex == NICVF_FULL_DUPLEX)
101 link->link_duplex = ETH_LINK_FULL_DUPLEX;
102 link->link_speed = nic->speed;
103 link->link_autoneg = ETH_LINK_SPEED_AUTONEG;
107 nicvf_interrupt(void *arg)
109 struct rte_eth_dev *dev = arg;
110 struct nicvf *nic = nicvf_pmd_priv(dev);
112 if (nicvf_reg_poll_interrupts(nic) == NIC_MBOX_MSG_BGX_LINK_CHANGE) {
113 if (dev->data->dev_conf.intr_conf.lsc)
114 nicvf_set_eth_link_status(nic, &dev->data->dev_link);
115 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
119 rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
120 nicvf_interrupt, dev);
124 nicvf_vf_interrupt(void *arg)
126 struct nicvf *nic = arg;
128 nicvf_reg_poll_interrupts(nic);
130 rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000,
131 nicvf_vf_interrupt, nic);
135 nicvf_periodic_alarm_start(void (fn)(void *), void *arg)
137 return rte_eal_alarm_set(NICVF_INTR_POLL_INTERVAL_MS * 1000, fn, arg);
141 nicvf_periodic_alarm_stop(void (fn)(void *), void *arg)
143 return rte_eal_alarm_cancel(fn, arg);
147 * Return 0 means link status changed, -1 means not changed
150 nicvf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
152 #define CHECK_INTERVAL 100 /* 100ms */
153 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
154 struct rte_eth_link link;
155 struct nicvf *nic = nicvf_pmd_priv(dev);
158 PMD_INIT_FUNC_TRACE();
160 if (wait_to_complete) {
161 /* rte_eth_link_get() might need to wait up to 9 seconds */
162 for (i = 0; i < MAX_CHECK_TIME; i++) {
163 memset(&link, 0, sizeof(link));
164 nicvf_set_eth_link_status(nic, &link);
165 if (link.link_status)
167 rte_delay_ms(CHECK_INTERVAL);
170 memset(&link, 0, sizeof(link));
171 nicvf_set_eth_link_status(nic, &link);
173 return nicvf_atomic_write_link_status(dev, &link);
177 nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
179 struct nicvf *nic = nicvf_pmd_priv(dev);
180 uint32_t buffsz, frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
183 PMD_INIT_FUNC_TRACE();
185 if (frame_size > NIC_HW_MAX_FRS)
188 if (frame_size < NIC_HW_MIN_FRS)
191 buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
194 * Refuse mtu that requires the support of scattered packets
195 * when this feature has not been enabled before.
197 if (!dev->data->scattered_rx &&
198 (frame_size + 2 * VLAN_TAG_SIZE > buffsz))
201 /* check <seg size> * <max_seg> >= max_frame */
202 if (dev->data->scattered_rx &&
203 (frame_size + 2 * VLAN_TAG_SIZE > buffsz * NIC_HW_MAX_SEGS))
206 if (frame_size > ETHER_MAX_LEN)
207 dev->data->dev_conf.rxmode.jumbo_frame = 1;
209 dev->data->dev_conf.rxmode.jumbo_frame = 0;
211 if (nicvf_mbox_update_hw_max_frs(nic, frame_size))
214 /* Update max frame size */
215 dev->data->dev_conf.rxmode.max_rx_pkt_len = (uint32_t)frame_size;
218 for (i = 0; i < nic->sqs_count; i++)
219 nic->snicvf[i]->mtu = mtu;
225 nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
227 uint64_t *data = regs->data;
228 struct nicvf *nic = nicvf_pmd_priv(dev);
231 regs->length = nicvf_reg_get_count();
232 regs->width = THUNDERX_REG_BYTES;
236 /* Support only full register dump */
237 if ((regs->length == 0) ||
238 (regs->length == (uint32_t)nicvf_reg_get_count())) {
239 regs->version = nic->vendor_id << 16 | nic->device_id;
240 nicvf_reg_dump(nic, data);
247 nicvf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
250 struct nicvf_hw_rx_qstats rx_qstats;
251 struct nicvf_hw_tx_qstats tx_qstats;
252 struct nicvf_hw_stats port_stats;
253 struct nicvf *nic = nicvf_pmd_priv(dev);
254 uint16_t rx_start, rx_end;
255 uint16_t tx_start, tx_end;
258 /* RX queue indices for the first VF */
259 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
261 /* Reading per RX ring stats */
262 for (qidx = rx_start; qidx <= rx_end; qidx++) {
263 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
266 nicvf_hw_get_rx_qstats(nic, &rx_qstats, qidx);
267 stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
268 stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
271 /* TX queue indices for the first VF */
272 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
274 /* Reading per TX ring stats */
275 for (qidx = tx_start; qidx <= tx_end; qidx++) {
276 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
279 nicvf_hw_get_tx_qstats(nic, &tx_qstats, qidx);
280 stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
281 stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
284 for (i = 0; i < nic->sqs_count; i++) {
285 struct nicvf *snic = nic->snicvf[i];
290 /* RX queue indices for a secondary VF */
291 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
293 /* Reading per RX ring stats */
294 for (qidx = rx_start; qidx <= rx_end; qidx++) {
295 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
298 nicvf_hw_get_rx_qstats(snic, &rx_qstats,
299 qidx % MAX_RCV_QUEUES_PER_QS);
300 stats->q_ibytes[qidx] = rx_qstats.q_rx_bytes;
301 stats->q_ipackets[qidx] = rx_qstats.q_rx_packets;
304 /* TX queue indices for a secondary VF */
305 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
306 /* Reading per TX ring stats */
307 for (qidx = tx_start; qidx <= tx_end; qidx++) {
308 if (qidx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
311 nicvf_hw_get_tx_qstats(snic, &tx_qstats,
312 qidx % MAX_SND_QUEUES_PER_QS);
313 stats->q_obytes[qidx] = tx_qstats.q_tx_bytes;
314 stats->q_opackets[qidx] = tx_qstats.q_tx_packets;
318 nicvf_hw_get_stats(nic, &port_stats);
319 stats->ibytes = port_stats.rx_bytes;
320 stats->ipackets = port_stats.rx_ucast_frames;
321 stats->ipackets += port_stats.rx_bcast_frames;
322 stats->ipackets += port_stats.rx_mcast_frames;
323 stats->ierrors = port_stats.rx_l2_errors;
324 stats->imissed = port_stats.rx_drop_red;
325 stats->imissed += port_stats.rx_drop_overrun;
326 stats->imissed += port_stats.rx_drop_bcast;
327 stats->imissed += port_stats.rx_drop_mcast;
328 stats->imissed += port_stats.rx_drop_l3_bcast;
329 stats->imissed += port_stats.rx_drop_l3_mcast;
331 stats->obytes = port_stats.tx_bytes_ok;
332 stats->opackets = port_stats.tx_ucast_frames_ok;
333 stats->opackets += port_stats.tx_bcast_frames_ok;
334 stats->opackets += port_stats.tx_mcast_frames_ok;
335 stats->oerrors = port_stats.tx_drops;
340 static const uint32_t *
341 nicvf_dev_supported_ptypes_get(struct rte_eth_dev *dev)
344 static uint32_t ptypes[32];
345 struct nicvf *nic = nicvf_pmd_priv(dev);
346 static const uint32_t ptypes_common[] = {
348 RTE_PTYPE_L3_IPV4_EXT,
350 RTE_PTYPE_L3_IPV6_EXT,
355 static const uint32_t ptypes_tunnel[] = {
356 RTE_PTYPE_TUNNEL_GRE,
357 RTE_PTYPE_TUNNEL_GENEVE,
358 RTE_PTYPE_TUNNEL_VXLAN,
359 RTE_PTYPE_TUNNEL_NVGRE,
361 static const uint32_t ptypes_end = RTE_PTYPE_UNKNOWN;
363 copied = sizeof(ptypes_common);
364 memcpy(ptypes, ptypes_common, copied);
365 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
366 memcpy((char *)ptypes + copied, ptypes_tunnel,
367 sizeof(ptypes_tunnel));
368 copied += sizeof(ptypes_tunnel);
371 memcpy((char *)ptypes + copied, &ptypes_end, sizeof(ptypes_end));
372 if (dev->rx_pkt_burst == nicvf_recv_pkts ||
373 dev->rx_pkt_burst == nicvf_recv_pkts_multiseg)
380 nicvf_dev_stats_reset(struct rte_eth_dev *dev)
383 uint16_t rxqs = 0, txqs = 0;
384 struct nicvf *nic = nicvf_pmd_priv(dev);
385 uint16_t rx_start, rx_end;
386 uint16_t tx_start, tx_end;
388 /* Reset all primary nic counters */
389 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
390 for (i = rx_start; i <= rx_end; i++)
391 rxqs |= (0x3 << (i * 2));
393 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
394 for (i = tx_start; i <= tx_end; i++)
395 txqs |= (0x3 << (i * 2));
397 nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, rxqs, txqs);
399 /* Reset secondary nic queue counters */
400 for (i = 0; i < nic->sqs_count; i++) {
401 struct nicvf *snic = nic->snicvf[i];
405 nicvf_rx_range(dev, snic, &rx_start, &rx_end);
406 for (i = rx_start; i <= rx_end; i++)
407 rxqs |= (0x3 << ((i % MAX_CMP_QUEUES_PER_QS) * 2));
409 nicvf_tx_range(dev, snic, &tx_start, &tx_end);
410 for (i = tx_start; i <= tx_end; i++)
411 txqs |= (0x3 << ((i % MAX_SND_QUEUES_PER_QS) * 2));
413 nicvf_mbox_reset_stat_counters(snic, 0, 0, rxqs, txqs);
417 /* Promiscuous mode enabled by default in LMAC to VF 1:1 map configuration */
419 nicvf_dev_promisc_enable(struct rte_eth_dev *dev __rte_unused)
423 static inline uint64_t
424 nicvf_rss_ethdev_to_nic(struct nicvf *nic, uint64_t ethdev_rss)
426 uint64_t nic_rss = 0;
428 if (ethdev_rss & ETH_RSS_IPV4)
429 nic_rss |= RSS_IP_ENA;
431 if (ethdev_rss & ETH_RSS_IPV6)
432 nic_rss |= RSS_IP_ENA;
434 if (ethdev_rss & ETH_RSS_NONFRAG_IPV4_UDP)
435 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
437 if (ethdev_rss & ETH_RSS_NONFRAG_IPV4_TCP)
438 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
440 if (ethdev_rss & ETH_RSS_NONFRAG_IPV6_UDP)
441 nic_rss |= (RSS_IP_ENA | RSS_UDP_ENA);
443 if (ethdev_rss & ETH_RSS_NONFRAG_IPV6_TCP)
444 nic_rss |= (RSS_IP_ENA | RSS_TCP_ENA);
446 if (ethdev_rss & ETH_RSS_PORT)
447 nic_rss |= RSS_L2_EXTENDED_HASH_ENA;
449 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
450 if (ethdev_rss & ETH_RSS_VXLAN)
451 nic_rss |= RSS_TUN_VXLAN_ENA;
453 if (ethdev_rss & ETH_RSS_GENEVE)
454 nic_rss |= RSS_TUN_GENEVE_ENA;
456 if (ethdev_rss & ETH_RSS_NVGRE)
457 nic_rss |= RSS_TUN_NVGRE_ENA;
463 static inline uint64_t
464 nicvf_rss_nic_to_ethdev(struct nicvf *nic, uint64_t nic_rss)
466 uint64_t ethdev_rss = 0;
468 if (nic_rss & RSS_IP_ENA)
469 ethdev_rss |= (ETH_RSS_IPV4 | ETH_RSS_IPV6);
471 if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_TCP_ENA))
472 ethdev_rss |= (ETH_RSS_NONFRAG_IPV4_TCP |
473 ETH_RSS_NONFRAG_IPV6_TCP);
475 if ((nic_rss & RSS_IP_ENA) && (nic_rss & RSS_UDP_ENA))
476 ethdev_rss |= (ETH_RSS_NONFRAG_IPV4_UDP |
477 ETH_RSS_NONFRAG_IPV6_UDP);
479 if (nic_rss & RSS_L2_EXTENDED_HASH_ENA)
480 ethdev_rss |= ETH_RSS_PORT;
482 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING) {
483 if (nic_rss & RSS_TUN_VXLAN_ENA)
484 ethdev_rss |= ETH_RSS_VXLAN;
486 if (nic_rss & RSS_TUN_GENEVE_ENA)
487 ethdev_rss |= ETH_RSS_GENEVE;
489 if (nic_rss & RSS_TUN_NVGRE_ENA)
490 ethdev_rss |= ETH_RSS_NVGRE;
496 nicvf_dev_reta_query(struct rte_eth_dev *dev,
497 struct rte_eth_rss_reta_entry64 *reta_conf,
500 struct nicvf *nic = nicvf_pmd_priv(dev);
501 uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
504 if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
505 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
506 "(%d) doesn't match the number hardware can supported "
507 "(%d)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
511 ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
515 /* Copy RETA table */
516 for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_RETA_GROUP_SIZE); i++) {
517 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
518 if ((reta_conf[i].mask >> j) & 0x01)
519 reta_conf[i].reta[j] = tbl[j];
526 nicvf_dev_reta_update(struct rte_eth_dev *dev,
527 struct rte_eth_rss_reta_entry64 *reta_conf,
530 struct nicvf *nic = nicvf_pmd_priv(dev);
531 uint8_t tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
534 if (reta_size != NIC_MAX_RSS_IDR_TBL_SIZE) {
535 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
536 "(%d) doesn't match the number hardware can supported "
537 "(%d)", reta_size, NIC_MAX_RSS_IDR_TBL_SIZE);
541 ret = nicvf_rss_reta_query(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
545 /* Copy RETA table */
546 for (i = 0; i < (NIC_MAX_RSS_IDR_TBL_SIZE / RTE_RETA_GROUP_SIZE); i++) {
547 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++)
548 if ((reta_conf[i].mask >> j) & 0x01)
549 tbl[j] = reta_conf[i].reta[j];
552 return nicvf_rss_reta_update(nic, tbl, NIC_MAX_RSS_IDR_TBL_SIZE);
556 nicvf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
557 struct rte_eth_rss_conf *rss_conf)
559 struct nicvf *nic = nicvf_pmd_priv(dev);
561 if (rss_conf->rss_key)
562 nicvf_rss_get_key(nic, rss_conf->rss_key);
564 rss_conf->rss_key_len = RSS_HASH_KEY_BYTE_SIZE;
565 rss_conf->rss_hf = nicvf_rss_nic_to_ethdev(nic, nicvf_rss_get_cfg(nic));
570 nicvf_dev_rss_hash_update(struct rte_eth_dev *dev,
571 struct rte_eth_rss_conf *rss_conf)
573 struct nicvf *nic = nicvf_pmd_priv(dev);
576 if (rss_conf->rss_key &&
577 rss_conf->rss_key_len != RSS_HASH_KEY_BYTE_SIZE) {
578 RTE_LOG(ERR, PMD, "Hash key size mismatch %d",
579 rss_conf->rss_key_len);
583 if (rss_conf->rss_key)
584 nicvf_rss_set_key(nic, rss_conf->rss_key);
586 nic_rss = nicvf_rss_ethdev_to_nic(nic, rss_conf->rss_hf);
587 nicvf_rss_set_cfg(nic, nic_rss);
592 nicvf_qset_cq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
593 struct nicvf_rxq *rxq, uint16_t qidx, uint32_t desc_cnt)
595 const struct rte_memzone *rz;
596 uint32_t ring_size = CMP_QUEUE_SZ_MAX * sizeof(union cq_entry_t);
598 rz = rte_eth_dma_zone_reserve(dev, "cq_ring",
599 nicvf_netdev_qidx(nic, qidx), ring_size,
600 NICVF_CQ_BASE_ALIGN_BYTES, nic->node);
602 PMD_INIT_LOG(ERR, "Failed to allocate mem for cq hw ring");
606 memset(rz->addr, 0, ring_size);
608 rxq->phys = rz->phys_addr;
609 rxq->desc = rz->addr;
610 rxq->qlen_mask = desc_cnt - 1;
616 nicvf_qset_sq_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
617 struct nicvf_txq *sq, uint16_t qidx, uint32_t desc_cnt)
619 const struct rte_memzone *rz;
620 uint32_t ring_size = SND_QUEUE_SZ_MAX * sizeof(union sq_entry_t);
622 rz = rte_eth_dma_zone_reserve(dev, "sq",
623 nicvf_netdev_qidx(nic, qidx), ring_size,
624 NICVF_SQ_BASE_ALIGN_BYTES, nic->node);
626 PMD_INIT_LOG(ERR, "Failed allocate mem for sq hw ring");
630 memset(rz->addr, 0, ring_size);
632 sq->phys = rz->phys_addr;
634 sq->qlen_mask = desc_cnt - 1;
640 nicvf_qset_rbdr_alloc(struct rte_eth_dev *dev, struct nicvf *nic,
641 uint32_t desc_cnt, uint32_t buffsz)
643 struct nicvf_rbdr *rbdr;
644 const struct rte_memzone *rz;
647 assert(nic->rbdr == NULL);
648 rbdr = rte_zmalloc_socket("rbdr", sizeof(struct nicvf_rbdr),
649 RTE_CACHE_LINE_SIZE, nic->node);
651 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr");
655 ring_size = sizeof(struct rbdr_entry_t) * RBDR_QUEUE_SZ_MAX;
656 rz = rte_eth_dma_zone_reserve(dev, "rbdr",
657 nicvf_netdev_qidx(nic, 0), ring_size,
658 NICVF_RBDR_BASE_ALIGN_BYTES, nic->node);
660 PMD_INIT_LOG(ERR, "Failed to allocate mem for rbdr desc ring");
664 memset(rz->addr, 0, ring_size);
666 rbdr->phys = rz->phys_addr;
669 rbdr->desc = rz->addr;
670 rbdr->buffsz = buffsz;
671 rbdr->qlen_mask = desc_cnt - 1;
673 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_STATUS0;
675 nicvf_qset_base(nic, 0) + NIC_QSET_RBDR_0_1_DOOR;
682 nicvf_rbdr_release_mbuf(struct rte_eth_dev *dev, struct nicvf *nic,
683 nicvf_phys_addr_t phy)
687 struct nicvf_rxq *rxq;
688 uint16_t rx_start, rx_end;
690 /* Get queue ranges for this VF */
691 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
693 for (qidx = rx_start; qidx <= rx_end; qidx++) {
694 rxq = dev->data->rx_queues[qidx];
695 if (rxq->precharge_cnt) {
696 obj = (void *)nicvf_mbuff_phy2virt(phy,
698 rte_mempool_put(rxq->pool, obj);
699 rxq->precharge_cnt--;
706 nicvf_rbdr_release_mbufs(struct rte_eth_dev *dev, struct nicvf *nic)
708 uint32_t qlen_mask, head;
709 struct rbdr_entry_t *entry;
710 struct nicvf_rbdr *rbdr = nic->rbdr;
712 qlen_mask = rbdr->qlen_mask;
714 while (head != rbdr->tail) {
715 entry = rbdr->desc + head;
716 nicvf_rbdr_release_mbuf(dev, nic, entry->full_addr);
718 head = head & qlen_mask;
723 nicvf_tx_queue_release_mbufs(struct nicvf_txq *txq)
728 while (head != txq->tail) {
729 if (txq->txbuffs[head]) {
730 rte_pktmbuf_free_seg(txq->txbuffs[head]);
731 txq->txbuffs[head] = NULL;
734 head = head & txq->qlen_mask;
739 nicvf_tx_queue_reset(struct nicvf_txq *txq)
741 uint32_t txq_desc_cnt = txq->qlen_mask + 1;
743 memset(txq->desc, 0, sizeof(union sq_entry_t) * txq_desc_cnt);
744 memset(txq->txbuffs, 0, sizeof(struct rte_mbuf *) * txq_desc_cnt);
751 nicvf_vf_start_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
754 struct nicvf_txq *txq;
757 assert(qidx < MAX_SND_QUEUES_PER_QS);
759 if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
760 RTE_ETH_QUEUE_STATE_STARTED)
763 txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
765 ret = nicvf_qset_sq_config(nic, qidx, txq);
767 PMD_INIT_LOG(ERR, "Failed to configure sq VF%d %d %d",
768 nic->vf_id, qidx, ret);
769 goto config_sq_error;
772 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
773 RTE_ETH_QUEUE_STATE_STARTED;
777 nicvf_qset_sq_reclaim(nic, qidx);
782 nicvf_vf_stop_tx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
785 struct nicvf_txq *txq;
788 assert(qidx < MAX_SND_QUEUES_PER_QS);
790 if (dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
791 RTE_ETH_QUEUE_STATE_STOPPED)
794 ret = nicvf_qset_sq_reclaim(nic, qidx);
796 PMD_INIT_LOG(ERR, "Failed to reclaim sq VF%d %d %d",
797 nic->vf_id, qidx, ret);
799 txq = dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)];
800 nicvf_tx_queue_release_mbufs(txq);
801 nicvf_tx_queue_reset(txq);
803 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
804 RTE_ETH_QUEUE_STATE_STOPPED;
809 nicvf_configure_cpi(struct rte_eth_dev *dev)
811 struct nicvf *nic = nicvf_pmd_priv(dev);
815 /* Count started rx queues */
816 for (qidx = qcnt = 0; qidx < dev->data->nb_rx_queues; qidx++)
817 if (dev->data->rx_queue_state[qidx] ==
818 RTE_ETH_QUEUE_STATE_STARTED)
821 nic->cpi_alg = CPI_ALG_NONE;
822 ret = nicvf_mbox_config_cpi(nic, qcnt);
824 PMD_INIT_LOG(ERR, "Failed to configure CPI %d", ret);
830 nicvf_configure_rss(struct rte_eth_dev *dev)
832 struct nicvf *nic = nicvf_pmd_priv(dev);
836 rsshf = nicvf_rss_ethdev_to_nic(nic,
837 dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
838 PMD_DRV_LOG(INFO, "mode=%d rx_queues=%d loopback=%d rsshf=0x%" PRIx64,
839 dev->data->dev_conf.rxmode.mq_mode,
840 dev->data->nb_rx_queues,
841 dev->data->dev_conf.lpbk_mode, rsshf);
843 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_NONE)
844 ret = nicvf_rss_term(nic);
845 else if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS)
846 ret = nicvf_rss_config(nic, dev->data->nb_rx_queues, rsshf);
848 PMD_INIT_LOG(ERR, "Failed to configure RSS %d", ret);
854 nicvf_configure_rss_reta(struct rte_eth_dev *dev)
856 struct nicvf *nic = nicvf_pmd_priv(dev);
857 unsigned int idx, qmap_size;
858 uint8_t qmap[RTE_MAX_QUEUES_PER_PORT];
859 uint8_t default_reta[NIC_MAX_RSS_IDR_TBL_SIZE];
861 if (nic->cpi_alg != CPI_ALG_NONE)
864 /* Prepare queue map */
865 for (idx = 0, qmap_size = 0; idx < dev->data->nb_rx_queues; idx++) {
866 if (dev->data->rx_queue_state[idx] ==
867 RTE_ETH_QUEUE_STATE_STARTED)
868 qmap[qmap_size++] = idx;
871 /* Update default RSS RETA */
872 for (idx = 0; idx < NIC_MAX_RSS_IDR_TBL_SIZE; idx++)
873 default_reta[idx] = qmap[idx % qmap_size];
875 return nicvf_rss_reta_update(nic, default_reta,
876 NIC_MAX_RSS_IDR_TBL_SIZE);
880 nicvf_dev_tx_queue_release(void *sq)
882 struct nicvf_txq *txq;
884 PMD_INIT_FUNC_TRACE();
886 txq = (struct nicvf_txq *)sq;
888 if (txq->txbuffs != NULL) {
889 nicvf_tx_queue_release_mbufs(txq);
890 rte_free(txq->txbuffs);
898 nicvf_set_tx_function(struct rte_eth_dev *dev)
900 struct nicvf_txq *txq;
902 bool multiseg = false;
904 for (i = 0; i < dev->data->nb_tx_queues; i++) {
905 txq = dev->data->tx_queues[i];
906 if ((txq->txq_flags & ETH_TXQ_FLAGS_NOMULTSEGS) == 0) {
912 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
914 PMD_DRV_LOG(DEBUG, "Using multi-segment tx callback");
915 dev->tx_pkt_burst = nicvf_xmit_pkts_multiseg;
917 PMD_DRV_LOG(DEBUG, "Using single-segment tx callback");
918 dev->tx_pkt_burst = nicvf_xmit_pkts;
921 if (txq->pool_free == nicvf_single_pool_free_xmited_buffers)
922 PMD_DRV_LOG(DEBUG, "Using single-mempool tx free method");
924 PMD_DRV_LOG(DEBUG, "Using multi-mempool tx free method");
928 nicvf_set_rx_function(struct rte_eth_dev *dev)
930 if (dev->data->scattered_rx) {
931 PMD_DRV_LOG(DEBUG, "Using multi-segment rx callback");
932 dev->rx_pkt_burst = nicvf_recv_pkts_multiseg;
934 PMD_DRV_LOG(DEBUG, "Using single-segment rx callback");
935 dev->rx_pkt_burst = nicvf_recv_pkts;
940 nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
941 uint16_t nb_desc, unsigned int socket_id,
942 const struct rte_eth_txconf *tx_conf)
944 uint16_t tx_free_thresh;
945 uint8_t is_single_pool;
946 struct nicvf_txq *txq;
947 struct nicvf *nic = nicvf_pmd_priv(dev);
949 PMD_INIT_FUNC_TRACE();
951 if (qidx >= MAX_SND_QUEUES_PER_QS)
952 nic = nic->snicvf[qidx / MAX_SND_QUEUES_PER_QS - 1];
954 qidx = qidx % MAX_SND_QUEUES_PER_QS;
956 /* Socket id check */
957 if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
958 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
959 socket_id, nic->node);
961 /* Tx deferred start is not supported */
962 if (tx_conf->tx_deferred_start) {
963 PMD_INIT_LOG(ERR, "Tx deferred start not supported");
967 /* Roundup nb_desc to available qsize and validate max number of desc */
968 nb_desc = nicvf_qsize_sq_roundup(nb_desc);
970 PMD_INIT_LOG(ERR, "Value of nb_desc beyond available sq qsize");
974 /* Validate tx_free_thresh */
975 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
976 tx_conf->tx_free_thresh :
977 NICVF_DEFAULT_TX_FREE_THRESH);
979 if (tx_free_thresh > (nb_desc) ||
980 tx_free_thresh > NICVF_MAX_TX_FREE_THRESH) {
982 "tx_free_thresh must be less than the number of TX "
983 "descriptors. (tx_free_thresh=%u port=%d "
984 "queue=%d)", (unsigned int)tx_free_thresh,
985 (int)dev->data->port_id, (int)qidx);
989 /* Free memory prior to re-allocation if needed. */
990 if (dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
991 PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
992 nicvf_netdev_qidx(nic, qidx));
993 nicvf_dev_tx_queue_release(
994 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)]);
995 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
998 /* Allocating tx queue data structure */
999 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nicvf_txq),
1000 RTE_CACHE_LINE_SIZE, nic->node);
1002 PMD_INIT_LOG(ERR, "Failed to allocate txq=%d",
1003 nicvf_netdev_qidx(nic, qidx));
1008 txq->queue_id = qidx;
1009 txq->tx_free_thresh = tx_free_thresh;
1010 txq->txq_flags = tx_conf->txq_flags;
1011 txq->sq_head = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_HEAD;
1012 txq->sq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_DOOR;
1013 is_single_pool = (txq->txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT &&
1014 txq->txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP);
1016 /* Choose optimum free threshold value for multipool case */
1017 if (!is_single_pool) {
1018 txq->tx_free_thresh = (uint16_t)
1019 (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ?
1020 NICVF_TX_FREE_MPOOL_THRESH :
1021 tx_conf->tx_free_thresh);
1022 txq->pool_free = nicvf_multi_pool_free_xmited_buffers;
1024 txq->pool_free = nicvf_single_pool_free_xmited_buffers;
1027 /* Allocate software ring */
1028 txq->txbuffs = rte_zmalloc_socket("txq->txbuffs",
1029 nb_desc * sizeof(struct rte_mbuf *),
1030 RTE_CACHE_LINE_SIZE, nic->node);
1032 if (txq->txbuffs == NULL) {
1033 nicvf_dev_tx_queue_release(txq);
1037 if (nicvf_qset_sq_alloc(dev, nic, txq, qidx, nb_desc)) {
1038 PMD_INIT_LOG(ERR, "Failed to allocate mem for sq %d", qidx);
1039 nicvf_dev_tx_queue_release(txq);
1043 nicvf_tx_queue_reset(txq);
1045 PMD_TX_LOG(DEBUG, "[%d] txq=%p nb_desc=%d desc=%p phys=0x%" PRIx64,
1046 nicvf_netdev_qidx(nic, qidx), txq, nb_desc, txq->desc,
1049 dev->data->tx_queues[nicvf_netdev_qidx(nic, qidx)] = txq;
1050 dev->data->tx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1051 RTE_ETH_QUEUE_STATE_STOPPED;
1056 nicvf_rx_queue_release_mbufs(struct rte_eth_dev *dev, struct nicvf_rxq *rxq)
1059 uint32_t nb_pkts, released_pkts = 0;
1060 uint32_t refill_cnt = 0;
1061 struct rte_mbuf *rx_pkts[NICVF_MAX_RX_FREE_THRESH];
1063 if (dev->rx_pkt_burst == NULL)
1066 while ((rxq_cnt = nicvf_dev_rx_queue_count(dev,
1067 nicvf_netdev_qidx(rxq->nic, rxq->queue_id)))) {
1068 nb_pkts = dev->rx_pkt_burst(rxq, rx_pkts,
1069 NICVF_MAX_RX_FREE_THRESH);
1070 PMD_DRV_LOG(INFO, "nb_pkts=%d rxq_cnt=%d", nb_pkts, rxq_cnt);
1072 rte_pktmbuf_free_seg(rx_pkts[--nb_pkts]);
1078 refill_cnt += nicvf_dev_rbdr_refill(dev,
1079 nicvf_netdev_qidx(rxq->nic, rxq->queue_id));
1081 PMD_DRV_LOG(INFO, "free_cnt=%d refill_cnt=%d",
1082 released_pkts, refill_cnt);
1086 nicvf_rx_queue_reset(struct nicvf_rxq *rxq)
1089 rxq->available_space = 0;
1090 rxq->recv_buffers = 0;
1094 nicvf_vf_start_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1097 struct nicvf_rxq *rxq;
1100 assert(qidx < MAX_RCV_QUEUES_PER_QS);
1102 if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1103 RTE_ETH_QUEUE_STATE_STARTED)
1106 /* Update rbdr pointer to all rxq */
1107 rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1108 rxq->shared_rbdr = nic->rbdr;
1110 ret = nicvf_qset_rq_config(nic, qidx, rxq);
1112 PMD_INIT_LOG(ERR, "Failed to configure rq VF%d %d %d",
1113 nic->vf_id, qidx, ret);
1114 goto config_rq_error;
1116 ret = nicvf_qset_cq_config(nic, qidx, rxq);
1118 PMD_INIT_LOG(ERR, "Failed to configure cq VF%d %d %d",
1119 nic->vf_id, qidx, ret);
1120 goto config_cq_error;
1123 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1124 RTE_ETH_QUEUE_STATE_STARTED;
1128 nicvf_qset_cq_reclaim(nic, qidx);
1130 nicvf_qset_rq_reclaim(nic, qidx);
1135 nicvf_vf_stop_rx_queue(struct rte_eth_dev *dev, struct nicvf *nic,
1138 struct nicvf_rxq *rxq;
1139 int ret, other_error;
1141 if (dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] ==
1142 RTE_ETH_QUEUE_STATE_STOPPED)
1145 ret = nicvf_qset_rq_reclaim(nic, qidx);
1147 PMD_INIT_LOG(ERR, "Failed to reclaim rq VF%d %d %d",
1148 nic->vf_id, qidx, ret);
1151 rxq = dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)];
1152 nicvf_rx_queue_release_mbufs(dev, rxq);
1153 nicvf_rx_queue_reset(rxq);
1155 ret = nicvf_qset_cq_reclaim(nic, qidx);
1157 PMD_INIT_LOG(ERR, "Failed to reclaim cq VF%d %d %d",
1158 nic->vf_id, qidx, ret);
1161 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1162 RTE_ETH_QUEUE_STATE_STOPPED;
1167 nicvf_dev_rx_queue_release(void *rx_queue)
1169 PMD_INIT_FUNC_TRACE();
1175 nicvf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1177 struct nicvf *nic = nicvf_pmd_priv(dev);
1180 if (qidx >= MAX_RCV_QUEUES_PER_QS)
1181 nic = nic->snicvf[(qidx / MAX_RCV_QUEUES_PER_QS - 1)];
1183 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1185 ret = nicvf_vf_start_rx_queue(dev, nic, qidx);
1189 ret = nicvf_configure_cpi(dev);
1193 return nicvf_configure_rss_reta(dev);
1197 nicvf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1200 struct nicvf *nic = nicvf_pmd_priv(dev);
1202 if (qidx >= MAX_SND_QUEUES_PER_QS)
1203 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1205 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1207 ret = nicvf_vf_stop_rx_queue(dev, nic, qidx);
1208 ret |= nicvf_configure_cpi(dev);
1209 ret |= nicvf_configure_rss_reta(dev);
1214 nicvf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
1216 struct nicvf *nic = nicvf_pmd_priv(dev);
1218 if (qidx >= MAX_SND_QUEUES_PER_QS)
1219 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1221 qidx = qidx % MAX_SND_QUEUES_PER_QS;
1223 return nicvf_vf_start_tx_queue(dev, nic, qidx);
1227 nicvf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
1229 struct nicvf *nic = nicvf_pmd_priv(dev);
1231 if (qidx >= MAX_SND_QUEUES_PER_QS)
1232 nic = nic->snicvf[(qidx / MAX_SND_QUEUES_PER_QS - 1)];
1234 qidx = qidx % MAX_SND_QUEUES_PER_QS;
1236 return nicvf_vf_stop_tx_queue(dev, nic, qidx);
1240 nicvf_rxq_mbuf_setup(struct nicvf_rxq *rxq)
1243 struct rte_mbuf mb_def;
1245 RTE_BUILD_BUG_ON(sizeof(union mbuf_initializer) != 8);
1246 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
1247 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
1248 offsetof(struct rte_mbuf, data_off) != 2);
1249 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
1250 offsetof(struct rte_mbuf, data_off) != 4);
1251 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
1252 offsetof(struct rte_mbuf, data_off) != 6);
1254 mb_def.data_off = RTE_PKTMBUF_HEADROOM;
1255 mb_def.port = rxq->port_id;
1256 rte_mbuf_refcnt_set(&mb_def, 1);
1258 /* Prevent compiler reordering: rearm_data covers previous fields */
1259 rte_compiler_barrier();
1260 p = (uintptr_t)&mb_def.rearm_data;
1261 rxq->mbuf_initializer.value = *(uint64_t *)p;
1265 nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
1266 uint16_t nb_desc, unsigned int socket_id,
1267 const struct rte_eth_rxconf *rx_conf,
1268 struct rte_mempool *mp)
1270 uint16_t rx_free_thresh;
1271 struct nicvf_rxq *rxq;
1272 struct nicvf *nic = nicvf_pmd_priv(dev);
1274 PMD_INIT_FUNC_TRACE();
1276 if (qidx >= MAX_RCV_QUEUES_PER_QS)
1277 nic = nic->snicvf[qidx / MAX_RCV_QUEUES_PER_QS - 1];
1279 qidx = qidx % MAX_RCV_QUEUES_PER_QS;
1281 /* Socket id check */
1282 if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node)
1283 PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d",
1284 socket_id, nic->node);
1286 /* Mempool memory must be contiguous, so must be one memory segment*/
1287 if (mp->nb_mem_chunks != 1) {
1288 PMD_INIT_LOG(ERR, "Non-contiguous mempool, add more huge pages");
1292 /* Mempool memory must be physically contiguous */
1293 if (mp->flags & MEMPOOL_F_NO_PHYS_CONTIG) {
1294 PMD_INIT_LOG(ERR, "Mempool memory must be physically contiguous");
1298 /* Rx deferred start is not supported */
1299 if (rx_conf->rx_deferred_start) {
1300 PMD_INIT_LOG(ERR, "Rx deferred start not supported");
1304 /* Roundup nb_desc to available qsize and validate max number of desc */
1305 nb_desc = nicvf_qsize_cq_roundup(nb_desc);
1307 PMD_INIT_LOG(ERR, "Value nb_desc beyond available hw cq qsize");
1311 /* Check rx_free_thresh upper bound */
1312 rx_free_thresh = (uint16_t)((rx_conf->rx_free_thresh) ?
1313 rx_conf->rx_free_thresh :
1314 NICVF_DEFAULT_RX_FREE_THRESH);
1315 if (rx_free_thresh > NICVF_MAX_RX_FREE_THRESH ||
1316 rx_free_thresh >= nb_desc * .75) {
1317 PMD_INIT_LOG(ERR, "rx_free_thresh greater than expected %d",
1322 /* Free memory prior to re-allocation if needed */
1323 if (dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] != NULL) {
1324 PMD_RX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
1325 nicvf_netdev_qidx(nic, qidx));
1326 nicvf_dev_rx_queue_release(
1327 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)]);
1328 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = NULL;
1331 /* Allocate rxq memory */
1332 rxq = rte_zmalloc_socket("ethdev rx queue", sizeof(struct nicvf_rxq),
1333 RTE_CACHE_LINE_SIZE, nic->node);
1335 PMD_INIT_LOG(ERR, "Failed to allocate rxq=%d",
1336 nicvf_netdev_qidx(nic, qidx));
1342 rxq->queue_id = qidx;
1343 rxq->port_id = dev->data->port_id;
1344 rxq->rx_free_thresh = rx_free_thresh;
1345 rxq->rx_drop_en = rx_conf->rx_drop_en;
1346 rxq->cq_status = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_STATUS;
1347 rxq->cq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_CQ_0_7_DOOR;
1348 rxq->precharge_cnt = 0;
1350 if (nicvf_hw_cap(nic) & NICVF_CAP_CQE_RX2)
1351 rxq->rbptr_offset = NICVF_CQE_RX2_RBPTR_WORD;
1353 rxq->rbptr_offset = NICVF_CQE_RBPTR_WORD;
1355 nicvf_rxq_mbuf_setup(rxq);
1357 /* Alloc completion queue */
1358 if (nicvf_qset_cq_alloc(dev, nic, rxq, rxq->queue_id, nb_desc)) {
1359 PMD_INIT_LOG(ERR, "failed to allocate cq %u", rxq->queue_id);
1360 nicvf_dev_rx_queue_release(rxq);
1364 nicvf_rx_queue_reset(rxq);
1366 PMD_RX_LOG(DEBUG, "[%d] rxq=%p pool=%s nb_desc=(%d/%d) phy=%" PRIx64,
1367 nicvf_netdev_qidx(nic, qidx), rxq, mp->name, nb_desc,
1368 rte_mempool_avail_count(mp), rxq->phys);
1370 dev->data->rx_queues[nicvf_netdev_qidx(nic, qidx)] = rxq;
1371 dev->data->rx_queue_state[nicvf_netdev_qidx(nic, qidx)] =
1372 RTE_ETH_QUEUE_STATE_STOPPED;
1377 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1379 struct nicvf *nic = nicvf_pmd_priv(dev);
1380 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1382 PMD_INIT_FUNC_TRACE();
1384 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1386 /* Autonegotiation may be disabled */
1387 dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
1388 dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
1389 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
1390 if (nicvf_hw_version(nic) != PCI_SUB_DEVICE_ID_CN81XX_NICVF)
1391 dev_info->speed_capa |= ETH_LINK_SPEED_40G;
1393 dev_info->min_rx_bufsize = ETHER_MIN_MTU;
1394 dev_info->max_rx_pktlen = NIC_HW_MAX_FRS;
1395 dev_info->max_rx_queues =
1396 (uint16_t)MAX_RCV_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1397 dev_info->max_tx_queues =
1398 (uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
1399 dev_info->max_mac_addrs = 1;
1400 dev_info->max_vfs = pci_dev->max_vfs;
1402 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1403 dev_info->tx_offload_capa =
1404 DEV_TX_OFFLOAD_IPV4_CKSUM |
1405 DEV_TX_OFFLOAD_UDP_CKSUM |
1406 DEV_TX_OFFLOAD_TCP_CKSUM |
1407 DEV_TX_OFFLOAD_TCP_TSO |
1408 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
1410 dev_info->reta_size = nic->rss_info.rss_size;
1411 dev_info->hash_key_size = RSS_HASH_KEY_BYTE_SIZE;
1412 dev_info->flow_type_rss_offloads = NICVF_RSS_OFFLOAD_PASS1;
1413 if (nicvf_hw_cap(nic) & NICVF_CAP_TUNNEL_PARSING)
1414 dev_info->flow_type_rss_offloads |= NICVF_RSS_OFFLOAD_TUNNEL;
1416 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1417 .rx_free_thresh = NICVF_DEFAULT_RX_FREE_THRESH,
1421 dev_info->default_txconf = (struct rte_eth_txconf) {
1422 .tx_free_thresh = NICVF_DEFAULT_TX_FREE_THRESH,
1424 ETH_TXQ_FLAGS_NOMULTSEGS |
1425 ETH_TXQ_FLAGS_NOREFCOUNT |
1426 ETH_TXQ_FLAGS_NOMULTMEMP |
1427 ETH_TXQ_FLAGS_NOVLANOFFL |
1428 ETH_TXQ_FLAGS_NOXSUMSCTP,
1432 static nicvf_phys_addr_t
1433 rbdr_rte_mempool_get(void *dev, void *opaque)
1437 struct nicvf_rxq *rxq;
1438 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)dev;
1439 struct nicvf *nic = (struct nicvf *)opaque;
1440 uint16_t rx_start, rx_end;
1442 /* Get queue ranges for this VF */
1443 nicvf_rx_range(eth_dev, nic, &rx_start, &rx_end);
1445 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1446 rxq = eth_dev->data->rx_queues[qidx];
1447 /* Maintain equal buffer count across all pools */
1448 if (rxq->precharge_cnt >= rxq->qlen_mask)
1450 rxq->precharge_cnt++;
1451 mbuf = (uintptr_t)rte_pktmbuf_alloc(rxq->pool);
1453 return nicvf_mbuff_virt2phy(mbuf, rxq->mbuf_phys_off);
1459 nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
1462 uint16_t qidx, data_off;
1463 uint32_t total_rxq_desc, nb_rbdr_desc, exp_buffs;
1464 uint64_t mbuf_phys_off = 0;
1465 struct nicvf_rxq *rxq;
1466 struct rte_mbuf *mbuf;
1467 uint16_t rx_start, rx_end;
1468 uint16_t tx_start, tx_end;
1470 PMD_INIT_FUNC_TRACE();
1472 /* Userspace process exited without proper shutdown in last run */
1473 if (nicvf_qset_rbdr_active(nic, 0))
1474 nicvf_vf_stop(dev, nic, false);
1476 /* Get queue ranges for this VF */
1477 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1480 * Thunderx nicvf PMD can support more than one pool per port only when
1481 * 1) Data payload size is same across all the pools in given port
1483 * 2) All mbuffs in the pools are from the same hugepage
1485 * 3) Mbuff metadata size is same across all the pools in given port
1487 * This is to support existing application that uses multiple pool/port.
1488 * But, the purpose of using multipool for QoS will not be addressed.
1492 /* Validate mempool attributes */
1493 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1494 rxq = dev->data->rx_queues[qidx];
1495 rxq->mbuf_phys_off = nicvf_mempool_phy_offset(rxq->pool);
1496 mbuf = rte_pktmbuf_alloc(rxq->pool);
1498 PMD_INIT_LOG(ERR, "Failed allocate mbuf VF%d qid=%d "
1500 nic->vf_id, qidx, rxq->pool->name);
1503 data_off = nicvf_mbuff_meta_length(mbuf);
1504 data_off += RTE_PKTMBUF_HEADROOM;
1505 rte_pktmbuf_free(mbuf);
1507 if (data_off % RTE_CACHE_LINE_SIZE) {
1508 PMD_INIT_LOG(ERR, "%s: unaligned data_off=%d delta=%d",
1509 rxq->pool->name, data_off,
1510 data_off % RTE_CACHE_LINE_SIZE);
1513 rxq->mbuf_phys_off -= data_off;
1515 if (mbuf_phys_off == 0)
1516 mbuf_phys_off = rxq->mbuf_phys_off;
1517 if (mbuf_phys_off != rxq->mbuf_phys_off) {
1518 PMD_INIT_LOG(ERR, "pool params not same,%s VF%d %"
1519 PRIx64, rxq->pool->name, nic->vf_id,
1525 /* Check the level of buffers in the pool */
1527 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1528 rxq = dev->data->rx_queues[qidx];
1529 /* Count total numbers of rxq descs */
1530 total_rxq_desc += rxq->qlen_mask + 1;
1531 exp_buffs = RTE_MEMPOOL_CACHE_MAX_SIZE + rxq->rx_free_thresh;
1532 exp_buffs *= dev->data->nb_rx_queues;
1533 if (rte_mempool_avail_count(rxq->pool) < exp_buffs) {
1534 PMD_INIT_LOG(ERR, "Buff shortage in pool=%s (%d/%d)",
1536 rte_mempool_avail_count(rxq->pool),
1542 /* Check RBDR desc overflow */
1543 ret = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1545 PMD_INIT_LOG(ERR, "Reached RBDR desc limit, reduce nr desc "
1546 "VF%d", nic->vf_id);
1551 ret = nicvf_qset_config(nic);
1553 PMD_INIT_LOG(ERR, "Failed to enable qset %d VF%d", ret,
1558 /* Allocate RBDR and RBDR ring desc */
1559 nb_rbdr_desc = nicvf_qsize_rbdr_roundup(total_rxq_desc);
1560 ret = nicvf_qset_rbdr_alloc(dev, nic, nb_rbdr_desc, rbdrsz);
1562 PMD_INIT_LOG(ERR, "Failed to allocate memory for rbdr alloc "
1563 "VF%d", nic->vf_id);
1567 /* Enable and configure RBDR registers */
1568 ret = nicvf_qset_rbdr_config(nic, 0);
1570 PMD_INIT_LOG(ERR, "Failed to configure rbdr %d VF%d", ret,
1572 goto qset_rbdr_free;
1575 /* Fill rte_mempool buffers in RBDR pool and precharge it */
1576 ret = nicvf_qset_rbdr_precharge(dev, nic, 0, rbdr_rte_mempool_get,
1579 PMD_INIT_LOG(ERR, "Failed to fill rbdr %d VF%d", ret,
1581 goto qset_rbdr_reclaim;
1584 PMD_DRV_LOG(INFO, "Filled %d out of %d entries in RBDR VF%d",
1585 nic->rbdr->tail, nb_rbdr_desc, nic->vf_id);
1587 /* Configure VLAN Strip */
1588 nicvf_vlan_hw_strip(nic, dev->data->dev_conf.rxmode.hw_vlan_strip);
1590 /* Based on the packet type(IPv4 or IPv6), the nicvf HW aligns L3 data
1591 * to the 64bit memory address.
1592 * The alignment creates a hole in mbuf(between the end of headroom and
1593 * packet data start). The new revision of the HW provides an option to
1594 * disable the L3 alignment feature and make mbuf layout looks
1595 * more like other NICs. For better application compatibility, disabling
1596 * l3 alignment feature on the hardware revisions it supports
1598 nicvf_apad_config(nic, false);
1600 /* Get queue ranges for this VF */
1601 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1603 /* Configure TX queues */
1604 for (qidx = tx_start; qidx <= tx_end; qidx++) {
1605 ret = nicvf_vf_start_tx_queue(dev, nic,
1606 qidx % MAX_SND_QUEUES_PER_QS);
1608 goto start_txq_error;
1611 /* Configure RX queues */
1612 for (qidx = rx_start; qidx <= rx_end; qidx++) {
1613 ret = nicvf_vf_start_rx_queue(dev, nic,
1614 qidx % MAX_RCV_QUEUES_PER_QS);
1616 goto start_rxq_error;
1619 if (!nic->sqs_mode) {
1620 /* Configure CPI algorithm */
1621 ret = nicvf_configure_cpi(dev);
1623 goto start_txq_error;
1625 ret = nicvf_mbox_get_rss_size(nic);
1627 PMD_INIT_LOG(ERR, "Failed to get rss table size");
1628 goto qset_rss_error;
1632 ret = nicvf_configure_rss(dev);
1634 goto qset_rss_error;
1637 /* Done; Let PF make the BGX's RX and TX switches to ON position */
1638 nicvf_mbox_cfg_done(nic);
1642 nicvf_rss_term(nic);
1644 for (qidx = rx_start; qidx <= rx_end; qidx++)
1645 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1647 for (qidx = tx_start; qidx <= tx_end; qidx++)
1648 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1650 nicvf_qset_rbdr_reclaim(nic, 0);
1651 nicvf_rbdr_release_mbufs(dev, nic);
1654 rte_free(nic->rbdr);
1658 nicvf_qset_reclaim(nic);
1663 nicvf_dev_start(struct rte_eth_dev *dev)
1668 struct nicvf *nic = nicvf_pmd_priv(dev);
1669 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
1671 uint32_t buffsz = 0, rbdrsz = 0;
1672 struct rte_pktmbuf_pool_private *mbp_priv;
1673 struct nicvf_rxq *rxq;
1675 PMD_INIT_FUNC_TRACE();
1677 /* This function must be called for a primary device */
1678 assert_primary(nic);
1680 /* Validate RBDR buff size */
1681 for (qidx = 0; qidx < dev->data->nb_rx_queues; qidx++) {
1682 rxq = dev->data->rx_queues[qidx];
1683 mbp_priv = rte_mempool_get_priv(rxq->pool);
1684 buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
1686 PMD_INIT_LOG(ERR, "rxbuf size must be multiply of 128");
1691 if (rbdrsz != buffsz) {
1692 PMD_INIT_LOG(ERR, "buffsz not same, qidx=%d (%d/%d)",
1693 qidx, rbdrsz, buffsz);
1698 /* Configure loopback */
1699 ret = nicvf_loopback_config(nic, dev->data->dev_conf.lpbk_mode);
1701 PMD_INIT_LOG(ERR, "Failed to configure loopback %d", ret);
1705 /* Reset all statistics counters attached to this port */
1706 ret = nicvf_mbox_reset_stat_counters(nic, 0x3FFF, 0x1F, 0xFFFF, 0xFFFF);
1708 PMD_INIT_LOG(ERR, "Failed to reset stat counters %d", ret);
1712 /* Setup scatter mode if needed by jumbo */
1713 if (dev->data->dev_conf.rxmode.max_rx_pkt_len +
1714 2 * VLAN_TAG_SIZE > buffsz)
1715 dev->data->scattered_rx = 1;
1716 if (rx_conf->enable_scatter)
1717 dev->data->scattered_rx = 1;
1719 /* Setup MTU based on max_rx_pkt_len or default */
1720 mtu = dev->data->dev_conf.rxmode.jumbo_frame ?
1721 dev->data->dev_conf.rxmode.max_rx_pkt_len
1722 - ETHER_HDR_LEN - ETHER_CRC_LEN
1725 if (nicvf_dev_set_mtu(dev, mtu)) {
1726 PMD_INIT_LOG(ERR, "Failed to set default mtu size");
1730 ret = nicvf_vf_start(dev, nic, rbdrsz);
1734 for (i = 0; i < nic->sqs_count; i++) {
1735 assert(nic->snicvf[i]);
1737 ret = nicvf_vf_start(dev, nic->snicvf[i], rbdrsz);
1742 /* Configure callbacks based on scatter mode */
1743 nicvf_set_tx_function(dev);
1744 nicvf_set_rx_function(dev);
1750 nicvf_dev_stop_cleanup(struct rte_eth_dev *dev, bool cleanup)
1754 struct nicvf *nic = nicvf_pmd_priv(dev);
1756 PMD_INIT_FUNC_TRACE();
1758 /* Teardown secondary vf first */
1759 for (i = 0; i < nic->sqs_count; i++) {
1760 if (!nic->snicvf[i])
1763 nicvf_vf_stop(dev, nic->snicvf[i], cleanup);
1766 /* Stop the primary VF now */
1767 nicvf_vf_stop(dev, nic, cleanup);
1769 /* Disable loopback */
1770 ret = nicvf_loopback_config(nic, 0);
1772 PMD_INIT_LOG(ERR, "Failed to disable loopback %d", ret);
1774 /* Reclaim CPI configuration */
1775 ret = nicvf_mbox_config_cpi(nic, 0);
1777 PMD_INIT_LOG(ERR, "Failed to reclaim CPI config %d", ret);
1781 nicvf_dev_stop(struct rte_eth_dev *dev)
1783 PMD_INIT_FUNC_TRACE();
1785 nicvf_dev_stop_cleanup(dev, false);
1789 nicvf_vf_stop(struct rte_eth_dev *dev, struct nicvf *nic, bool cleanup)
1793 uint16_t tx_start, tx_end;
1794 uint16_t rx_start, rx_end;
1796 PMD_INIT_FUNC_TRACE();
1799 /* Let PF make the BGX's RX and TX switches to OFF position */
1800 nicvf_mbox_shutdown(nic);
1803 /* Disable VLAN Strip */
1804 nicvf_vlan_hw_strip(nic, 0);
1806 /* Get queue ranges for this VF */
1807 nicvf_tx_range(dev, nic, &tx_start, &tx_end);
1809 for (qidx = tx_start; qidx <= tx_end; qidx++)
1810 nicvf_vf_stop_tx_queue(dev, nic, qidx % MAX_SND_QUEUES_PER_QS);
1812 /* Get queue ranges for this VF */
1813 nicvf_rx_range(dev, nic, &rx_start, &rx_end);
1816 for (qidx = rx_start; qidx <= rx_end; qidx++)
1817 nicvf_vf_stop_rx_queue(dev, nic, qidx % MAX_RCV_QUEUES_PER_QS);
1820 ret = nicvf_qset_rbdr_reclaim(nic, 0);
1822 PMD_INIT_LOG(ERR, "Failed to reclaim RBDR %d", ret);
1824 /* Move all charged buffers in RBDR back to pool */
1825 if (nic->rbdr != NULL)
1826 nicvf_rbdr_release_mbufs(dev, nic);
1829 ret = nicvf_qset_reclaim(nic);
1831 PMD_INIT_LOG(ERR, "Failed to disable qset %d", ret);
1833 /* Disable all interrupts */
1834 nicvf_disable_all_interrupts(nic);
1836 /* Free RBDR SW structure */
1838 rte_free(nic->rbdr);
1844 nicvf_dev_close(struct rte_eth_dev *dev)
1847 struct nicvf *nic = nicvf_pmd_priv(dev);
1849 PMD_INIT_FUNC_TRACE();
1851 nicvf_dev_stop_cleanup(dev, true);
1852 nicvf_periodic_alarm_stop(nicvf_interrupt, dev);
1854 for (i = 0; i < nic->sqs_count; i++) {
1855 if (!nic->snicvf[i])
1858 nicvf_periodic_alarm_stop(nicvf_vf_interrupt, nic->snicvf[i]);
1863 nicvf_request_sqs(struct nicvf *nic)
1867 assert_primary(nic);
1868 assert(nic->sqs_count > 0);
1869 assert(nic->sqs_count <= MAX_SQS_PER_VF);
1871 /* Set no of Rx/Tx queues in each of the SQsets */
1872 for (i = 0; i < nic->sqs_count; i++) {
1873 if (nicvf_svf_empty())
1874 rte_panic("Cannot assign sufficient number of "
1875 "secondary queues to primary VF%" PRIu8 "\n",
1878 nic->snicvf[i] = nicvf_svf_pop();
1879 nic->snicvf[i]->sqs_id = i;
1882 return nicvf_mbox_request_sqs(nic);
1886 nicvf_dev_configure(struct rte_eth_dev *dev)
1888 struct rte_eth_dev_data *data = dev->data;
1889 struct rte_eth_conf *conf = &data->dev_conf;
1890 struct rte_eth_rxmode *rxmode = &conf->rxmode;
1891 struct rte_eth_txmode *txmode = &conf->txmode;
1892 struct nicvf *nic = nicvf_pmd_priv(dev);
1895 PMD_INIT_FUNC_TRACE();
1897 if (!rte_eal_has_hugepages()) {
1898 PMD_INIT_LOG(INFO, "Huge page is not configured");
1902 if (txmode->mq_mode) {
1903 PMD_INIT_LOG(INFO, "Tx mq_mode DCB or VMDq not supported");
1907 if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
1908 rxmode->mq_mode != ETH_MQ_RX_RSS) {
1909 PMD_INIT_LOG(INFO, "Unsupported rx qmode %d", rxmode->mq_mode);
1913 if (!rxmode->hw_strip_crc) {
1914 PMD_INIT_LOG(NOTICE, "Can't disable hw crc strip");
1915 rxmode->hw_strip_crc = 1;
1918 if (rxmode->hw_ip_checksum) {
1919 PMD_INIT_LOG(NOTICE, "Rxcksum not supported");
1920 rxmode->hw_ip_checksum = 0;
1923 if (rxmode->split_hdr_size) {
1924 PMD_INIT_LOG(INFO, "Rxmode does not support split header");
1928 if (rxmode->hw_vlan_filter) {
1929 PMD_INIT_LOG(INFO, "VLAN filter not supported");
1933 if (rxmode->hw_vlan_extend) {
1934 PMD_INIT_LOG(INFO, "VLAN extended not supported");
1938 if (rxmode->enable_lro) {
1939 PMD_INIT_LOG(INFO, "LRO not supported");
1943 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
1944 PMD_INIT_LOG(INFO, "Setting link speed/duplex not supported");
1948 if (conf->dcb_capability_en) {
1949 PMD_INIT_LOG(INFO, "DCB enable not supported");
1953 if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1954 PMD_INIT_LOG(INFO, "Flow director not supported");
1958 assert_primary(nic);
1959 NICVF_STATIC_ASSERT(MAX_RCV_QUEUES_PER_QS == MAX_SND_QUEUES_PER_QS);
1960 cqcount = RTE_MAX(data->nb_tx_queues, data->nb_rx_queues);
1961 if (cqcount > MAX_RCV_QUEUES_PER_QS) {
1962 nic->sqs_count = RTE_ALIGN_CEIL(cqcount, MAX_RCV_QUEUES_PER_QS);
1963 nic->sqs_count = (nic->sqs_count / MAX_RCV_QUEUES_PER_QS) - 1;
1968 assert(nic->sqs_count <= MAX_SQS_PER_VF);
1970 if (nic->sqs_count > 0) {
1971 if (nicvf_request_sqs(nic)) {
1972 rte_panic("Cannot assign sufficient number of "
1973 "secondary queues to PORT%d VF%" PRIu8 "\n",
1974 dev->data->port_id, nic->vf_id);
1978 PMD_INIT_LOG(DEBUG, "Configured ethdev port%d hwcap=0x%" PRIx64,
1979 dev->data->port_id, nicvf_hw_cap(nic));
1984 /* Initialize and register driver with DPDK Application */
1985 static const struct eth_dev_ops nicvf_eth_dev_ops = {
1986 .dev_configure = nicvf_dev_configure,
1987 .dev_start = nicvf_dev_start,
1988 .dev_stop = nicvf_dev_stop,
1989 .link_update = nicvf_dev_link_update,
1990 .dev_close = nicvf_dev_close,
1991 .stats_get = nicvf_dev_stats_get,
1992 .stats_reset = nicvf_dev_stats_reset,
1993 .promiscuous_enable = nicvf_dev_promisc_enable,
1994 .dev_infos_get = nicvf_dev_info_get,
1995 .dev_supported_ptypes_get = nicvf_dev_supported_ptypes_get,
1996 .mtu_set = nicvf_dev_set_mtu,
1997 .reta_update = nicvf_dev_reta_update,
1998 .reta_query = nicvf_dev_reta_query,
1999 .rss_hash_update = nicvf_dev_rss_hash_update,
2000 .rss_hash_conf_get = nicvf_dev_rss_hash_conf_get,
2001 .rx_queue_start = nicvf_dev_rx_queue_start,
2002 .rx_queue_stop = nicvf_dev_rx_queue_stop,
2003 .tx_queue_start = nicvf_dev_tx_queue_start,
2004 .tx_queue_stop = nicvf_dev_tx_queue_stop,
2005 .rx_queue_setup = nicvf_dev_rx_queue_setup,
2006 .rx_queue_release = nicvf_dev_rx_queue_release,
2007 .rx_queue_count = nicvf_dev_rx_queue_count,
2008 .tx_queue_setup = nicvf_dev_tx_queue_setup,
2009 .tx_queue_release = nicvf_dev_tx_queue_release,
2010 .get_reg = nicvf_dev_get_regs,
2014 nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
2017 struct rte_pci_device *pci_dev;
2018 struct nicvf *nic = nicvf_pmd_priv(eth_dev);
2020 PMD_INIT_FUNC_TRACE();
2022 eth_dev->dev_ops = &nicvf_eth_dev_ops;
2024 /* For secondary processes, the primary has done all the work */
2025 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2027 /* Setup callbacks for secondary process */
2028 nicvf_set_tx_function(eth_dev);
2029 nicvf_set_rx_function(eth_dev);
2032 /* If nic == NULL than it is secondary function
2033 * so ethdev need to be released by caller */
2038 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2039 rte_eth_copy_pci_info(eth_dev, pci_dev);
2041 nic->device_id = pci_dev->id.device_id;
2042 nic->vendor_id = pci_dev->id.vendor_id;
2043 nic->subsystem_device_id = pci_dev->id.subsystem_device_id;
2044 nic->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2046 PMD_INIT_LOG(DEBUG, "nicvf: device (%x:%x) %u:%u:%u:%u",
2047 pci_dev->id.vendor_id, pci_dev->id.device_id,
2048 pci_dev->addr.domain, pci_dev->addr.bus,
2049 pci_dev->addr.devid, pci_dev->addr.function);
2051 nic->reg_base = (uintptr_t)pci_dev->mem_resource[0].addr;
2052 if (!nic->reg_base) {
2053 PMD_INIT_LOG(ERR, "Failed to map BAR0");
2058 nicvf_disable_all_interrupts(nic);
2060 ret = nicvf_periodic_alarm_start(nicvf_interrupt, eth_dev);
2062 PMD_INIT_LOG(ERR, "Failed to start period alarm");
2066 ret = nicvf_mbox_check_pf_ready(nic);
2068 PMD_INIT_LOG(ERR, "Failed to get ready message from PF");
2072 "node=%d vf=%d mode=%s sqs=%s loopback_supported=%s",
2073 nic->node, nic->vf_id,
2074 nic->tns_mode == NIC_TNS_MODE ? "tns" : "tns-bypass",
2075 nic->sqs_mode ? "true" : "false",
2076 nic->loopback_supported ? "true" : "false"
2080 ret = nicvf_base_init(nic);
2082 PMD_INIT_LOG(ERR, "Failed to execute nicvf_base_init");
2086 if (nic->sqs_mode) {
2087 /* Push nic to stack of secondary vfs */
2088 nicvf_svf_push(nic);
2090 /* Steal nic pointer from the device for further reuse */
2091 eth_dev->data->dev_private = NULL;
2093 nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2094 ret = nicvf_periodic_alarm_start(nicvf_vf_interrupt, nic);
2096 PMD_INIT_LOG(ERR, "Failed to start period alarm");
2100 /* Detach port by returning positive error number */
2104 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", ETHER_ADDR_LEN, 0);
2105 if (eth_dev->data->mac_addrs == NULL) {
2106 PMD_INIT_LOG(ERR, "Failed to allocate memory for mac addr");
2110 if (is_zero_ether_addr((struct ether_addr *)nic->mac_addr))
2111 eth_random_addr(&nic->mac_addr[0]);
2113 ether_addr_copy((struct ether_addr *)nic->mac_addr,
2114 ð_dev->data->mac_addrs[0]);
2116 ret = nicvf_mbox_set_mac_addr(nic, nic->mac_addr);
2118 PMD_INIT_LOG(ERR, "Failed to set mac addr");
2122 PMD_INIT_LOG(INFO, "Port %d (%x:%x) mac=%02x:%02x:%02x:%02x:%02x:%02x",
2123 eth_dev->data->port_id, nic->vendor_id, nic->device_id,
2124 nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
2125 nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);
2130 rte_free(eth_dev->data->mac_addrs);
2132 nicvf_periodic_alarm_stop(nicvf_interrupt, eth_dev);
2137 static const struct rte_pci_id pci_id_nicvf_map[] = {
2139 .class_id = RTE_CLASS_ANY_ID,
2140 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2141 .device_id = PCI_DEVICE_ID_THUNDERX_CN88XX_PASS1_NICVF,
2142 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2143 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS1_NICVF,
2146 .class_id = RTE_CLASS_ANY_ID,
2147 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2148 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2149 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2150 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN88XX_PASS2_NICVF,
2153 .class_id = RTE_CLASS_ANY_ID,
2154 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2155 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2156 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2157 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN81XX_NICVF,
2160 .class_id = RTE_CLASS_ANY_ID,
2161 .vendor_id = PCI_VENDOR_ID_CAVIUM,
2162 .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
2163 .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
2164 .subsystem_device_id = PCI_SUB_DEVICE_ID_CN83XX_NICVF,
2171 static int nicvf_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2172 struct rte_pci_device *pci_dev)
2174 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct nicvf),
2175 nicvf_eth_dev_init);
2178 static int nicvf_eth_pci_remove(struct rte_pci_device *pci_dev)
2180 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
2183 static struct rte_pci_driver rte_nicvf_pmd = {
2184 .id_table = pci_id_nicvf_map,
2185 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_KEEP_MAPPED_RES |
2186 RTE_PCI_DRV_INTR_LSC,
2187 .probe = nicvf_eth_pci_probe,
2188 .remove = nicvf_eth_pci_remove,
2191 RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd);
2192 RTE_PMD_REGISTER_PCI_TABLE(net_thunderx, pci_id_nicvf_map);
2193 RTE_PMD_REGISTER_KMOD_DEP(net_thunderx, "* igb_uio | uio_pci_generic | vfio-pci");