4 * Copyright(c) 2013-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_ethdev.h>
35 #include <rte_malloc.h>
36 #include <rte_memzone.h>
37 #include <rte_string_fns.h>
39 #include <rte_spinlock.h>
40 #include <rte_kvargs.h>
43 #include "base/fm10k_api.h"
45 /* Default delay to acquire mailbox lock */
46 #define FM10K_MBXLOCK_DELAY_US 20
47 #define UINT64_LOWER_32BITS_MASK 0x00000000ffffffffULL
49 #define MAIN_VSI_POOL_NUMBER 0
51 /* Max try times to acquire switch status */
52 #define MAX_QUERY_SWITCH_STATE_TIMES 10
53 /* Wait interval to get switch status */
54 #define WAIT_SWITCH_MSG_US 100000
55 /* A period of quiescence for switch */
56 #define FM10K_SWITCH_QUIESCE_US 100000
57 /* Number of chars per uint32 type */
58 #define CHARS_PER_UINT32 (sizeof(uint32_t))
59 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
61 /* default 1:1 map from queue ID to interrupt vector ID */
62 #define Q2V(dev, queue_id) (dev->pci_dev->intr_handle.intr_vec[queue_id])
64 /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
65 #define MAX_LPORT_NUM 128
66 #define GLORT_FD_Q_BASE 0x40
67 #define GLORT_PF_MASK 0xFFC0
68 #define GLORT_FD_MASK GLORT_PF_MASK
69 #define GLORT_FD_INDEX GLORT_FD_Q_BASE
71 static void fm10k_close_mbx_service(struct fm10k_hw *hw);
72 static void fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev);
73 static void fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev);
74 static void fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev);
75 static void fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev);
76 static inline int fm10k_glort_valid(struct fm10k_hw *hw);
78 fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
79 static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
80 const u8 *mac, bool add, uint32_t pool);
81 static void fm10k_tx_queue_release(void *queue);
82 static void fm10k_rx_queue_release(void *queue);
83 static void fm10k_set_rx_function(struct rte_eth_dev *dev);
84 static void fm10k_set_tx_function(struct rte_eth_dev *dev);
85 static int fm10k_check_ftag(struct rte_devargs *devargs);
86 static int fm10k_link_update(struct rte_eth_dev *dev, int wait_to_complete);
88 struct fm10k_xstats_name_off {
89 char name[RTE_ETH_XSTATS_NAME_SIZE];
93 struct fm10k_xstats_name_off fm10k_hw_stats_strings[] = {
94 {"completion_timeout_count", offsetof(struct fm10k_hw_stats, timeout)},
95 {"unsupported_requests_count", offsetof(struct fm10k_hw_stats, ur)},
96 {"completer_abort_count", offsetof(struct fm10k_hw_stats, ca)},
97 {"unsupported_message_count", offsetof(struct fm10k_hw_stats, um)},
98 {"checksum_error_count", offsetof(struct fm10k_hw_stats, xec)},
99 {"vlan_dropped", offsetof(struct fm10k_hw_stats, vlan_drop)},
100 {"loopback_dropped", offsetof(struct fm10k_hw_stats, loopback_drop)},
101 {"rx_mbuf_allocation_errors", offsetof(struct fm10k_hw_stats,
105 #define FM10K_NB_HW_XSTATS (sizeof(fm10k_hw_stats_strings) / \
106 sizeof(fm10k_hw_stats_strings[0]))
108 struct fm10k_xstats_name_off fm10k_hw_stats_rx_q_strings[] = {
109 {"packets", offsetof(struct fm10k_hw_stats_q, rx_packets)},
110 {"bytes", offsetof(struct fm10k_hw_stats_q, rx_bytes)},
111 {"dropped", offsetof(struct fm10k_hw_stats_q, rx_drops)},
114 #define FM10K_NB_RX_Q_XSTATS (sizeof(fm10k_hw_stats_rx_q_strings) / \
115 sizeof(fm10k_hw_stats_rx_q_strings[0]))
117 struct fm10k_xstats_name_off fm10k_hw_stats_tx_q_strings[] = {
118 {"packets", offsetof(struct fm10k_hw_stats_q, tx_packets)},
119 {"bytes", offsetof(struct fm10k_hw_stats_q, tx_bytes)},
122 #define FM10K_NB_TX_Q_XSTATS (sizeof(fm10k_hw_stats_tx_q_strings) / \
123 sizeof(fm10k_hw_stats_tx_q_strings[0]))
125 #define FM10K_NB_XSTATS (FM10K_NB_HW_XSTATS + FM10K_MAX_QUEUES_PF * \
126 (FM10K_NB_RX_Q_XSTATS + FM10K_NB_TX_Q_XSTATS))
128 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
131 fm10k_mbx_initlock(struct fm10k_hw *hw)
133 rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
137 fm10k_mbx_lock(struct fm10k_hw *hw)
139 while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
140 rte_delay_us(FM10K_MBXLOCK_DELAY_US);
144 fm10k_mbx_unlock(struct fm10k_hw *hw)
146 rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
149 /* Stubs needed for linkage when vPMD is disabled */
150 int __attribute__((weak))
151 fm10k_rx_vec_condition_check(__rte_unused struct rte_eth_dev *dev)
156 uint16_t __attribute__((weak))
158 __rte_unused void *rx_queue,
159 __rte_unused struct rte_mbuf **rx_pkts,
160 __rte_unused uint16_t nb_pkts)
165 uint16_t __attribute__((weak))
166 fm10k_recv_scattered_pkts_vec(
167 __rte_unused void *rx_queue,
168 __rte_unused struct rte_mbuf **rx_pkts,
169 __rte_unused uint16_t nb_pkts)
174 int __attribute__((weak))
175 fm10k_rxq_vec_setup(__rte_unused struct fm10k_rx_queue *rxq)
181 void __attribute__((weak))
182 fm10k_rx_queue_release_mbufs_vec(
183 __rte_unused struct fm10k_rx_queue *rxq)
188 void __attribute__((weak))
189 fm10k_txq_vec_setup(__rte_unused struct fm10k_tx_queue *txq)
194 int __attribute__((weak))
195 fm10k_tx_vec_condition_check(__rte_unused struct fm10k_tx_queue *txq)
200 uint16_t __attribute__((weak))
201 fm10k_xmit_pkts_vec(__rte_unused void *tx_queue,
202 __rte_unused struct rte_mbuf **tx_pkts,
203 __rte_unused uint16_t nb_pkts)
209 * reset queue to initial state, allocate software buffers used when starting
211 * return 0 on success
212 * return -ENOMEM if buffers cannot be allocated
213 * return -EINVAL if buffers do not satisfy alignment condition
216 rx_queue_reset(struct fm10k_rx_queue *q)
218 static const union fm10k_rx_desc zero = {{0} };
221 PMD_INIT_FUNC_TRACE();
223 diag = rte_mempool_get_bulk(q->mp, (void **)q->sw_ring, q->nb_desc);
227 for (i = 0; i < q->nb_desc; ++i) {
228 fm10k_pktmbuf_reset(q->sw_ring[i], q->port_id);
229 if (!fm10k_addr_alignment_valid(q->sw_ring[i])) {
230 rte_mempool_put_bulk(q->mp, (void **)q->sw_ring,
234 dma_addr = MBUF_DMA_ADDR_DEFAULT(q->sw_ring[i]);
235 q->hw_ring[i].q.pkt_addr = dma_addr;
236 q->hw_ring[i].q.hdr_addr = dma_addr;
239 /* initialize extra software ring entries. Space for these extra
240 * entries is always allocated.
242 memset(&q->fake_mbuf, 0x0, sizeof(q->fake_mbuf));
243 for (i = 0; i < q->nb_fake_desc; ++i) {
244 q->sw_ring[q->nb_desc + i] = &q->fake_mbuf;
245 q->hw_ring[q->nb_desc + i] = zero;
250 q->next_trigger = q->alloc_thresh - 1;
251 FM10K_PCI_REG_WRITE(q->tail_ptr, q->nb_desc - 1);
252 q->rxrearm_start = 0;
259 * clean queue, descriptor rings, free software buffers used when stopping
263 rx_queue_clean(struct fm10k_rx_queue *q)
265 union fm10k_rx_desc zero = {.q = {0, 0, 0, 0} };
267 PMD_INIT_FUNC_TRACE();
269 /* zero descriptor rings */
270 for (i = 0; i < q->nb_desc; ++i)
271 q->hw_ring[i] = zero;
273 /* zero faked descriptors */
274 for (i = 0; i < q->nb_fake_desc; ++i)
275 q->hw_ring[q->nb_desc + i] = zero;
277 /* vPMD driver has a different way of releasing mbufs. */
278 if (q->rx_using_sse) {
279 fm10k_rx_queue_release_mbufs_vec(q);
283 /* free software buffers */
284 for (i = 0; i < q->nb_desc; ++i) {
286 rte_pktmbuf_free_seg(q->sw_ring[i]);
287 q->sw_ring[i] = NULL;
293 * free all queue memory used when releasing the queue (i.e. configure)
296 rx_queue_free(struct fm10k_rx_queue *q)
298 PMD_INIT_FUNC_TRACE();
300 PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
303 rte_free(q->sw_ring);
312 * disable RX queue, wait unitl HW finished necessary flush operation
315 rx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
319 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
320 FM10K_WRITE_REG(hw, FM10K_RXQCTL(qnum),
321 reg & ~FM10K_RXQCTL_ENABLE);
323 /* Wait 100us at most */
324 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
326 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
327 if (!(reg & FM10K_RXQCTL_ENABLE))
331 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
338 * reset queue to initial state, allocate software buffers used when starting
342 tx_queue_reset(struct fm10k_tx_queue *q)
344 PMD_INIT_FUNC_TRACE();
348 q->nb_free = q->nb_desc - 1;
349 fifo_reset(&q->rs_tracker, (q->nb_desc + 1) / q->rs_thresh);
350 FM10K_PCI_REG_WRITE(q->tail_ptr, 0);
354 * clean queue, descriptor rings, free software buffers used when stopping
358 tx_queue_clean(struct fm10k_tx_queue *q)
360 struct fm10k_tx_desc zero = {0, 0, 0, 0, 0, 0};
362 PMD_INIT_FUNC_TRACE();
364 /* zero descriptor rings */
365 for (i = 0; i < q->nb_desc; ++i)
366 q->hw_ring[i] = zero;
368 /* free software buffers */
369 for (i = 0; i < q->nb_desc; ++i) {
371 rte_pktmbuf_free_seg(q->sw_ring[i]);
372 q->sw_ring[i] = NULL;
378 * free all queue memory used when releasing the queue (i.e. configure)
381 tx_queue_free(struct fm10k_tx_queue *q)
383 PMD_INIT_FUNC_TRACE();
385 PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
387 if (q->rs_tracker.list) {
388 rte_free(q->rs_tracker.list);
389 q->rs_tracker.list = NULL;
392 rte_free(q->sw_ring);
401 * disable TX queue, wait unitl HW finished necessary flush operation
404 tx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
408 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
409 FM10K_WRITE_REG(hw, FM10K_TXDCTL(qnum),
410 reg & ~FM10K_TXDCTL_ENABLE);
412 /* Wait 100us at most */
413 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
415 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
416 if (!(reg & FM10K_TXDCTL_ENABLE))
420 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
427 fm10k_check_mq_mode(struct rte_eth_dev *dev)
429 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
430 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
431 struct rte_eth_vmdq_rx_conf *vmdq_conf;
432 uint16_t nb_rx_q = dev->data->nb_rx_queues;
434 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
436 if (rx_mq_mode & ETH_MQ_RX_DCB_FLAG) {
437 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
441 if (!(rx_mq_mode & ETH_MQ_RX_VMDQ_FLAG))
444 if (hw->mac.type == fm10k_mac_vf) {
445 PMD_INIT_LOG(ERR, "VMDQ mode is not supported in VF.");
449 /* Check VMDQ queue pool number */
450 if (vmdq_conf->nb_queue_pools >
451 sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT ||
452 vmdq_conf->nb_queue_pools > nb_rx_q) {
453 PMD_INIT_LOG(ERR, "Too many of queue pools: %d",
454 vmdq_conf->nb_queue_pools);
461 static const struct fm10k_txq_ops def_txq_ops = {
462 .reset = tx_queue_reset,
466 fm10k_dev_configure(struct rte_eth_dev *dev)
470 PMD_INIT_FUNC_TRACE();
472 if (dev->data->dev_conf.rxmode.hw_strip_crc == 0)
473 PMD_INIT_LOG(WARNING, "fm10k always strip CRC");
474 /* multipe queue mode checking */
475 ret = fm10k_check_mq_mode(dev);
477 PMD_DRV_LOG(ERR, "fm10k_check_mq_mode fails with %d.",
486 fm10k_dev_vmdq_rx_configure(struct rte_eth_dev *dev)
488 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
489 struct rte_eth_vmdq_rx_conf *vmdq_conf;
492 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
494 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
495 if (!vmdq_conf->pool_map[i].pools)
498 fm10k_update_vlan(hw, vmdq_conf->pool_map[i].vlan_id, 0, true);
499 fm10k_mbx_unlock(hw);
504 fm10k_dev_pf_main_vsi_reset(struct rte_eth_dev *dev)
506 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
508 /* Add default mac address */
509 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
510 MAIN_VSI_POOL_NUMBER);
514 fm10k_dev_rss_configure(struct rte_eth_dev *dev)
516 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
517 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
518 uint32_t mrqc, *key, i, reta, j;
521 #define RSS_KEY_SIZE 40
522 static uint8_t rss_intel_key[RSS_KEY_SIZE] = {
523 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
524 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
525 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
526 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
527 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
530 if (dev->data->nb_rx_queues == 1 ||
531 dev_conf->rxmode.mq_mode != ETH_MQ_RX_RSS ||
532 dev_conf->rx_adv_conf.rss_conf.rss_hf == 0) {
533 FM10K_WRITE_REG(hw, FM10K_MRQC(0), 0);
537 /* random key is rss_intel_key (default) or user provided (rss_key) */
538 if (dev_conf->rx_adv_conf.rss_conf.rss_key == NULL)
539 key = (uint32_t *)rss_intel_key;
541 key = (uint32_t *)dev_conf->rx_adv_conf.rss_conf.rss_key;
543 /* Now fill our hash function seeds, 4 bytes at a time */
544 for (i = 0; i < RSS_KEY_SIZE / sizeof(*key); ++i)
545 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
548 * Fill in redirection table
549 * The byte-swap is needed because NIC registers are in
550 * little-endian order.
553 for (i = 0, j = 0; i < FM10K_MAX_RSS_INDICES; i++, j++) {
554 if (j == dev->data->nb_rx_queues)
556 reta = (reta << CHAR_BIT) | j;
558 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2),
563 * Generate RSS hash based on packet types, TCP/UDP
564 * port numbers and/or IPv4/v6 src and dst addresses
566 hf = dev_conf->rx_adv_conf.rss_conf.rss_hf;
568 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
569 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
570 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
571 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
572 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
573 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
574 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
575 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
576 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
579 PMD_INIT_LOG(ERR, "Specified RSS mode 0x%"PRIx64"is not"
584 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
588 fm10k_dev_logic_port_update(struct rte_eth_dev *dev, uint16_t nb_lport_new)
590 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
593 for (i = 0; i < nb_lport_new; i++) {
594 /* Set unicast mode by default. App can change
595 * to other mode in other API func.
598 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map + i,
599 FM10K_XCAST_MODE_NONE);
600 fm10k_mbx_unlock(hw);
605 fm10k_dev_mq_rx_configure(struct rte_eth_dev *dev)
607 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
608 struct rte_eth_vmdq_rx_conf *vmdq_conf;
609 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
610 struct fm10k_macvlan_filter_info *macvlan;
611 uint16_t nb_queue_pools = 0; /* pool number in configuration */
612 uint16_t nb_lport_new;
614 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
615 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
617 fm10k_dev_rss_configure(dev);
619 /* only PF supports VMDQ */
620 if (hw->mac.type != fm10k_mac_pf)
623 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
624 nb_queue_pools = vmdq_conf->nb_queue_pools;
626 /* no pool number change, no need to update logic port and VLAN/MAC */
627 if (macvlan->nb_queue_pools == nb_queue_pools)
630 nb_lport_new = nb_queue_pools ? nb_queue_pools : 1;
631 fm10k_dev_logic_port_update(dev, nb_lport_new);
633 /* reset MAC/VLAN as it's based on VMDQ or PF main VSI */
634 memset(dev->data->mac_addrs, 0,
635 ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM);
636 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
637 &dev->data->mac_addrs[0]);
638 memset(macvlan, 0, sizeof(*macvlan));
639 macvlan->nb_queue_pools = nb_queue_pools;
642 fm10k_dev_vmdq_rx_configure(dev);
644 fm10k_dev_pf_main_vsi_reset(dev);
648 fm10k_dev_tx_init(struct rte_eth_dev *dev)
650 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
652 struct fm10k_tx_queue *txq;
656 /* Disable TXINT to avoid possible interrupt */
657 for (i = 0; i < hw->mac.max_queues; i++)
658 FM10K_WRITE_REG(hw, FM10K_TXINT(i),
659 3 << FM10K_TXINT_TIMER_SHIFT);
662 for (i = 0; i < dev->data->nb_tx_queues; ++i) {
663 txq = dev->data->tx_queues[i];
664 base_addr = txq->hw_ring_phys_addr;
665 size = txq->nb_desc * sizeof(struct fm10k_tx_desc);
667 /* disable queue to avoid issues while updating state */
668 ret = tx_queue_disable(hw, i);
670 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
673 /* Enable use of FTAG bit in TX descriptor, PFVTCTL
674 * register is read-only for VF.
676 if (fm10k_check_ftag(dev->pci_dev->device.devargs)) {
677 if (hw->mac.type == fm10k_mac_pf) {
678 FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
679 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
680 PMD_INIT_LOG(DEBUG, "FTAG mode is enabled");
682 PMD_INIT_LOG(ERR, "VF FTAG is not supported.");
687 /* set location and size for descriptor ring */
688 FM10K_WRITE_REG(hw, FM10K_TDBAL(i),
689 base_addr & UINT64_LOWER_32BITS_MASK);
690 FM10K_WRITE_REG(hw, FM10K_TDBAH(i),
691 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
692 FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
694 /* assign default SGLORT for each TX queue by PF */
695 if (hw->mac.type == fm10k_mac_pf)
696 FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
699 /* set up vector or scalar TX function as appropriate */
700 fm10k_set_tx_function(dev);
706 fm10k_dev_rx_init(struct rte_eth_dev *dev)
708 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
709 struct fm10k_macvlan_filter_info *macvlan;
710 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
712 struct fm10k_rx_queue *rxq;
715 uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
716 uint32_t logic_port = hw->mac.dglort_map;
718 uint16_t queue_stride = 0;
720 /* enable RXINT for interrupt mode */
722 if (rte_intr_dp_is_en(intr_handle)) {
723 for (; i < dev->data->nb_rx_queues; i++) {
724 FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(dev, i));
725 if (hw->mac.type == fm10k_mac_pf)
726 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
728 FM10K_ITR_MASK_CLEAR);
730 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
732 FM10K_ITR_MASK_CLEAR);
735 /* Disable other RXINT to avoid possible interrupt */
736 for (; i < hw->mac.max_queues; i++)
737 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
738 3 << FM10K_RXINT_TIMER_SHIFT);
740 /* Setup RX queues */
741 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
742 rxq = dev->data->rx_queues[i];
743 base_addr = rxq->hw_ring_phys_addr;
744 size = rxq->nb_desc * sizeof(union fm10k_rx_desc);
746 /* disable queue to avoid issues while updating state */
747 ret = rx_queue_disable(hw, i);
749 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
753 /* Setup the Base and Length of the Rx Descriptor Ring */
754 FM10K_WRITE_REG(hw, FM10K_RDBAL(i),
755 base_addr & UINT64_LOWER_32BITS_MASK);
756 FM10K_WRITE_REG(hw, FM10K_RDBAH(i),
757 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
758 FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
760 /* Configure the Rx buffer size for one buff without split */
761 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
762 RTE_PKTMBUF_HEADROOM);
763 /* As RX buffer is aligned to 512B within mbuf, some bytes are
764 * reserved for this purpose, and the worst case could be 511B.
765 * But SRR reg assumes all buffers have the same size. In order
766 * to fill the gap, we'll have to consider the worst case and
767 * assume 512B is reserved. If we don't do so, it's possible
768 * for HW to overwrite data to next mbuf.
770 buf_size -= FM10K_RX_DATABUF_ALIGN;
772 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
773 (buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT) |
774 FM10K_SRRCTL_LOOPBACK_SUPPRESS);
776 /* It adds dual VLAN length for supporting dual VLAN */
777 if ((dev->data->dev_conf.rxmode.max_rx_pkt_len +
778 2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
779 dev->data->dev_conf.rxmode.enable_scatter) {
781 dev->data->scattered_rx = 1;
782 reg = FM10K_READ_REG(hw, FM10K_SRRCTL(i));
783 reg |= FM10K_SRRCTL_BUFFER_CHAINING_EN;
784 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), reg);
787 /* Enable drop on empty, it's RO for VF */
788 if (hw->mac.type == fm10k_mac_pf && rxq->drop_en)
789 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
791 FM10K_WRITE_REG(hw, FM10K_RXDCTL(i), rxdctl);
792 FM10K_WRITE_FLUSH(hw);
795 /* Configure VMDQ/RSS if applicable */
796 fm10k_dev_mq_rx_configure(dev);
798 /* Decide the best RX function */
799 fm10k_set_rx_function(dev);
801 /* update RX_SGLORT for loopback suppress*/
802 if (hw->mac.type != fm10k_mac_pf)
804 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
805 if (macvlan->nb_queue_pools)
806 queue_stride = dev->data->nb_rx_queues / macvlan->nb_queue_pools;
807 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
808 if (i && queue_stride && !(i % queue_stride))
810 FM10K_WRITE_REG(hw, FM10K_RX_SGLORT(i), logic_port);
817 fm10k_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
819 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
822 struct fm10k_rx_queue *rxq;
824 PMD_INIT_FUNC_TRACE();
826 if (rx_queue_id < dev->data->nb_rx_queues) {
827 rxq = dev->data->rx_queues[rx_queue_id];
828 err = rx_queue_reset(rxq);
829 if (err == -ENOMEM) {
830 PMD_INIT_LOG(ERR, "Failed to alloc memory : %d", err);
832 } else if (err == -EINVAL) {
833 PMD_INIT_LOG(ERR, "Invalid buffer address alignment :"
838 /* Setup the HW Rx Head and Tail Descriptor Pointers
839 * Note: this must be done AFTER the queue is enabled on real
840 * hardware, but BEFORE the queue is enabled when using the
841 * emulation platform. Do it in both places for now and remove
842 * this comment and the following two register writes when the
843 * emulation platform is no longer being used.
845 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
846 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
848 /* Set PF ownership flag for PF devices */
849 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(rx_queue_id));
850 if (hw->mac.type == fm10k_mac_pf)
851 reg |= FM10K_RXQCTL_PF;
852 reg |= FM10K_RXQCTL_ENABLE;
853 /* enable RX queue */
854 FM10K_WRITE_REG(hw, FM10K_RXQCTL(rx_queue_id), reg);
855 FM10K_WRITE_FLUSH(hw);
857 /* Setup the HW Rx Head and Tail Descriptor Pointers
858 * Note: this must be done AFTER the queue is enabled
860 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
861 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
862 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
869 fm10k_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
871 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
873 PMD_INIT_FUNC_TRACE();
875 if (rx_queue_id < dev->data->nb_rx_queues) {
876 /* Disable RX queue */
877 rx_queue_disable(hw, rx_queue_id);
879 /* Free mbuf and clean HW ring */
880 rx_queue_clean(dev->data->rx_queues[rx_queue_id]);
881 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
888 fm10k_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
890 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
891 /** @todo - this should be defined in the shared code */
892 #define FM10K_TXDCTL_WRITE_BACK_MIN_DELAY 0x00010000
893 uint32_t txdctl = FM10K_TXDCTL_WRITE_BACK_MIN_DELAY;
896 PMD_INIT_FUNC_TRACE();
898 if (tx_queue_id < dev->data->nb_tx_queues) {
899 struct fm10k_tx_queue *q = dev->data->tx_queues[tx_queue_id];
903 /* reset head and tail pointers */
904 FM10K_WRITE_REG(hw, FM10K_TDH(tx_queue_id), 0);
905 FM10K_WRITE_REG(hw, FM10K_TDT(tx_queue_id), 0);
907 /* enable TX queue */
908 FM10K_WRITE_REG(hw, FM10K_TXDCTL(tx_queue_id),
909 FM10K_TXDCTL_ENABLE | txdctl);
910 FM10K_WRITE_FLUSH(hw);
911 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
919 fm10k_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
921 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
923 PMD_INIT_FUNC_TRACE();
925 if (tx_queue_id < dev->data->nb_tx_queues) {
926 tx_queue_disable(hw, tx_queue_id);
927 tx_queue_clean(dev->data->tx_queues[tx_queue_id]);
928 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
934 static inline int fm10k_glort_valid(struct fm10k_hw *hw)
936 return ((hw->mac.dglort_map & FM10K_DGLORTMAP_NONE)
937 != FM10K_DGLORTMAP_NONE);
941 fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev)
943 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
946 PMD_INIT_FUNC_TRACE();
948 /* Return if it didn't acquire valid glort range */
949 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
953 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
954 FM10K_XCAST_MODE_PROMISC);
955 fm10k_mbx_unlock(hw);
957 if (status != FM10K_SUCCESS)
958 PMD_INIT_LOG(ERR, "Failed to enable promiscuous mode");
962 fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev)
964 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
968 PMD_INIT_FUNC_TRACE();
970 /* Return if it didn't acquire valid glort range */
971 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
974 if (dev->data->all_multicast == 1)
975 mode = FM10K_XCAST_MODE_ALLMULTI;
977 mode = FM10K_XCAST_MODE_NONE;
980 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
982 fm10k_mbx_unlock(hw);
984 if (status != FM10K_SUCCESS)
985 PMD_INIT_LOG(ERR, "Failed to disable promiscuous mode");
989 fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev)
991 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
994 PMD_INIT_FUNC_TRACE();
996 /* Return if it didn't acquire valid glort range */
997 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
1000 /* If promiscuous mode is enabled, it doesn't make sense to enable
1001 * allmulticast and disable promiscuous since fm10k only can select
1004 if (dev->data->promiscuous) {
1005 PMD_INIT_LOG(INFO, "Promiscuous mode is enabled, "\
1006 "needn't enable allmulticast");
1011 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
1012 FM10K_XCAST_MODE_ALLMULTI);
1013 fm10k_mbx_unlock(hw);
1015 if (status != FM10K_SUCCESS)
1016 PMD_INIT_LOG(ERR, "Failed to enable allmulticast mode");
1020 fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev)
1022 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1025 PMD_INIT_FUNC_TRACE();
1027 /* Return if it didn't acquire valid glort range */
1028 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
1031 if (dev->data->promiscuous) {
1032 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode "\
1033 "since promisc mode is enabled");
1038 /* Change mode to unicast mode */
1039 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
1040 FM10K_XCAST_MODE_NONE);
1041 fm10k_mbx_unlock(hw);
1043 if (status != FM10K_SUCCESS)
1044 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode");
1048 fm10k_dev_dglort_map_configure(struct rte_eth_dev *dev)
1050 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1051 uint32_t dglortdec, pool_len, rss_len, i, dglortmask;
1052 uint16_t nb_queue_pools;
1053 struct fm10k_macvlan_filter_info *macvlan;
1055 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1056 nb_queue_pools = macvlan->nb_queue_pools;
1057 pool_len = nb_queue_pools ? rte_fls_u32(nb_queue_pools - 1) : 0;
1058 rss_len = rte_fls_u32(dev->data->nb_rx_queues - 1) - pool_len;
1060 /* GLORT 0x0-0x3F are used by PF and VMDQ, 0x40-0x7F used by FD */
1061 dglortdec = (rss_len << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) | pool_len;
1062 dglortmask = (GLORT_PF_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1064 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(0), dglortmask);
1065 /* Configure VMDQ/RSS DGlort Decoder */
1066 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(0), dglortdec);
1068 /* Flow Director configurations, only queue number is valid. */
1069 dglortdec = rte_fls_u32(dev->data->nb_rx_queues - 1);
1070 dglortmask = (GLORT_FD_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1071 (hw->mac.dglort_map + GLORT_FD_Q_BASE);
1072 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(1), dglortmask);
1073 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(1), dglortdec);
1075 /* Invalidate all other GLORT entries */
1076 for (i = 2; i < FM10K_DGLORT_COUNT; i++)
1077 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i),
1078 FM10K_DGLORTMAP_NONE);
1081 #define BSIZEPKT_ROUNDUP ((1 << FM10K_SRRCTL_BSIZEPKT_SHIFT) - 1)
1083 fm10k_dev_start(struct rte_eth_dev *dev)
1085 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1088 PMD_INIT_FUNC_TRACE();
1090 /* stop, init, then start the hw */
1091 diag = fm10k_stop_hw(hw);
1092 if (diag != FM10K_SUCCESS) {
1093 PMD_INIT_LOG(ERR, "Hardware stop failed: %d", diag);
1097 diag = fm10k_init_hw(hw);
1098 if (diag != FM10K_SUCCESS) {
1099 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
1103 diag = fm10k_start_hw(hw);
1104 if (diag != FM10K_SUCCESS) {
1105 PMD_INIT_LOG(ERR, "Hardware start failed: %d", diag);
1109 diag = fm10k_dev_tx_init(dev);
1111 PMD_INIT_LOG(ERR, "TX init failed: %d", diag);
1115 if (fm10k_dev_rxq_interrupt_setup(dev))
1118 diag = fm10k_dev_rx_init(dev);
1120 PMD_INIT_LOG(ERR, "RX init failed: %d", diag);
1124 if (hw->mac.type == fm10k_mac_pf)
1125 fm10k_dev_dglort_map_configure(dev);
1127 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1128 struct fm10k_rx_queue *rxq;
1129 rxq = dev->data->rx_queues[i];
1131 if (rxq->rx_deferred_start)
1133 diag = fm10k_dev_rx_queue_start(dev, i);
1136 for (j = 0; j < i; ++j)
1137 rx_queue_clean(dev->data->rx_queues[j]);
1142 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1143 struct fm10k_tx_queue *txq;
1144 txq = dev->data->tx_queues[i];
1146 if (txq->tx_deferred_start)
1148 diag = fm10k_dev_tx_queue_start(dev, i);
1151 for (j = 0; j < i; ++j)
1152 tx_queue_clean(dev->data->tx_queues[j]);
1153 for (j = 0; j < dev->data->nb_rx_queues; ++j)
1154 rx_queue_clean(dev->data->rx_queues[j]);
1159 /* Update default vlan when not in VMDQ mode */
1160 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG))
1161 fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
1163 fm10k_link_update(dev, 0);
1169 fm10k_dev_stop(struct rte_eth_dev *dev)
1171 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1172 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1175 PMD_INIT_FUNC_TRACE();
1177 if (dev->data->tx_queues)
1178 for (i = 0; i < dev->data->nb_tx_queues; i++)
1179 fm10k_dev_tx_queue_stop(dev, i);
1181 if (dev->data->rx_queues)
1182 for (i = 0; i < dev->data->nb_rx_queues; i++)
1183 fm10k_dev_rx_queue_stop(dev, i);
1185 /* Disable datapath event */
1186 if (rte_intr_dp_is_en(intr_handle)) {
1187 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1188 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
1189 3 << FM10K_RXINT_TIMER_SHIFT);
1190 if (hw->mac.type == fm10k_mac_pf)
1191 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, i)),
1192 FM10K_ITR_MASK_SET);
1194 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, i)),
1195 FM10K_ITR_MASK_SET);
1198 /* Clean datapath event and queue/vec mapping */
1199 rte_intr_efd_disable(intr_handle);
1200 rte_free(intr_handle->intr_vec);
1201 intr_handle->intr_vec = NULL;
1205 fm10k_dev_queue_release(struct rte_eth_dev *dev)
1209 PMD_INIT_FUNC_TRACE();
1211 if (dev->data->tx_queues) {
1212 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1213 struct fm10k_tx_queue *txq = dev->data->tx_queues[i];
1219 if (dev->data->rx_queues) {
1220 for (i = 0; i < dev->data->nb_rx_queues; i++)
1221 fm10k_rx_queue_release(dev->data->rx_queues[i]);
1226 fm10k_dev_close(struct rte_eth_dev *dev)
1228 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1230 PMD_INIT_FUNC_TRACE();
1233 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
1234 MAX_LPORT_NUM, false);
1235 fm10k_mbx_unlock(hw);
1237 /* allow 100ms for device to quiesce */
1238 rte_delay_us(FM10K_SWITCH_QUIESCE_US);
1240 /* Stop mailbox service first */
1241 fm10k_close_mbx_service(hw);
1242 fm10k_dev_stop(dev);
1243 fm10k_dev_queue_release(dev);
1248 fm10k_link_update(struct rte_eth_dev *dev,
1249 __rte_unused int wait_to_complete)
1251 PMD_INIT_FUNC_TRACE();
1253 /* The host-interface link is always up. The speed is ~50Gbps per Gen3
1254 * x8 PCIe interface. For now, we leave the speed undefined since there
1255 * is no 50Gbps Ethernet. */
1256 dev->data->dev_link.link_speed = 0;
1257 dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
1258 dev->data->dev_link.link_status = ETH_LINK_UP;
1263 static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1264 struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
1269 if (xstats_names != NULL) {
1270 /* Note: limit checked in rte_eth_xstats_names() */
1273 for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1274 snprintf(xstats_names[count].name,
1275 sizeof(xstats_names[count].name),
1276 "%s", fm10k_hw_stats_strings[count].name);
1280 /* PF queue stats */
1281 for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1282 for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1283 snprintf(xstats_names[count].name,
1284 sizeof(xstats_names[count].name),
1286 fm10k_hw_stats_rx_q_strings[i].name);
1289 for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1290 snprintf(xstats_names[count].name,
1291 sizeof(xstats_names[count].name),
1293 fm10k_hw_stats_tx_q_strings[i].name);
1298 return FM10K_NB_XSTATS;
1302 fm10k_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1305 struct fm10k_hw_stats *hw_stats =
1306 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1307 unsigned i, q, count = 0;
1309 if (n < FM10K_NB_XSTATS)
1310 return FM10K_NB_XSTATS;
1313 for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1314 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
1315 fm10k_hw_stats_strings[count].offset);
1316 xstats[count].id = count;
1320 /* PF queue stats */
1321 for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1322 for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1323 xstats[count].value =
1324 *(uint64_t *)(((char *)&hw_stats->q[q]) +
1325 fm10k_hw_stats_rx_q_strings[i].offset);
1326 xstats[count].id = count;
1329 for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1330 xstats[count].value =
1331 *(uint64_t *)(((char *)&hw_stats->q[q]) +
1332 fm10k_hw_stats_tx_q_strings[i].offset);
1333 xstats[count].id = count;
1338 return FM10K_NB_XSTATS;
1342 fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1344 uint64_t ipackets, opackets, ibytes, obytes;
1345 struct fm10k_hw *hw =
1346 FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1347 struct fm10k_hw_stats *hw_stats =
1348 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1351 PMD_INIT_FUNC_TRACE();
1353 fm10k_update_hw_stats(hw, hw_stats);
1355 ipackets = opackets = ibytes = obytes = 0;
1356 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1357 (i < hw->mac.max_queues); ++i) {
1358 stats->q_ipackets[i] = hw_stats->q[i].rx_packets.count;
1359 stats->q_opackets[i] = hw_stats->q[i].tx_packets.count;
1360 stats->q_ibytes[i] = hw_stats->q[i].rx_bytes.count;
1361 stats->q_obytes[i] = hw_stats->q[i].tx_bytes.count;
1362 ipackets += stats->q_ipackets[i];
1363 opackets += stats->q_opackets[i];
1364 ibytes += stats->q_ibytes[i];
1365 obytes += stats->q_obytes[i];
1367 stats->ipackets = ipackets;
1368 stats->opackets = opackets;
1369 stats->ibytes = ibytes;
1370 stats->obytes = obytes;
1374 fm10k_stats_reset(struct rte_eth_dev *dev)
1376 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1377 struct fm10k_hw_stats *hw_stats =
1378 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1380 PMD_INIT_FUNC_TRACE();
1382 memset(hw_stats, 0, sizeof(*hw_stats));
1383 fm10k_rebind_hw_stats(hw, hw_stats);
1387 fm10k_dev_infos_get(struct rte_eth_dev *dev,
1388 struct rte_eth_dev_info *dev_info)
1390 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1392 PMD_INIT_FUNC_TRACE();
1394 dev_info->min_rx_bufsize = FM10K_MIN_RX_BUF_SIZE;
1395 dev_info->max_rx_pktlen = FM10K_MAX_PKT_SIZE;
1396 dev_info->max_rx_queues = hw->mac.max_queues;
1397 dev_info->max_tx_queues = hw->mac.max_queues;
1398 dev_info->max_mac_addrs = FM10K_MAX_MACADDR_NUM;
1399 dev_info->max_hash_mac_addrs = 0;
1400 dev_info->max_vfs = dev->pci_dev->max_vfs;
1401 dev_info->vmdq_pool_base = 0;
1402 dev_info->vmdq_queue_base = 0;
1403 dev_info->max_vmdq_pools = ETH_32_POOLS;
1404 dev_info->vmdq_queue_num = FM10K_MAX_QUEUES_PF;
1405 dev_info->rx_offload_capa =
1406 DEV_RX_OFFLOAD_VLAN_STRIP |
1407 DEV_RX_OFFLOAD_IPV4_CKSUM |
1408 DEV_RX_OFFLOAD_UDP_CKSUM |
1409 DEV_RX_OFFLOAD_TCP_CKSUM;
1410 dev_info->tx_offload_capa =
1411 DEV_TX_OFFLOAD_VLAN_INSERT |
1412 DEV_TX_OFFLOAD_IPV4_CKSUM |
1413 DEV_TX_OFFLOAD_UDP_CKSUM |
1414 DEV_TX_OFFLOAD_TCP_CKSUM |
1415 DEV_TX_OFFLOAD_TCP_TSO;
1417 dev_info->hash_key_size = FM10K_RSSRK_SIZE * sizeof(uint32_t);
1418 dev_info->reta_size = FM10K_MAX_RSS_INDICES;
1420 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1422 .pthresh = FM10K_DEFAULT_RX_PTHRESH,
1423 .hthresh = FM10K_DEFAULT_RX_HTHRESH,
1424 .wthresh = FM10K_DEFAULT_RX_WTHRESH,
1426 .rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(0),
1430 dev_info->default_txconf = (struct rte_eth_txconf) {
1432 .pthresh = FM10K_DEFAULT_TX_PTHRESH,
1433 .hthresh = FM10K_DEFAULT_TX_HTHRESH,
1434 .wthresh = FM10K_DEFAULT_TX_WTHRESH,
1436 .tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(0),
1437 .tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(0),
1438 .txq_flags = FM10K_SIMPLE_TX_FLAG,
1441 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1442 .nb_max = FM10K_MAX_RX_DESC,
1443 .nb_min = FM10K_MIN_RX_DESC,
1444 .nb_align = FM10K_MULT_RX_DESC,
1447 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1448 .nb_max = FM10K_MAX_TX_DESC,
1449 .nb_min = FM10K_MIN_TX_DESC,
1450 .nb_align = FM10K_MULT_TX_DESC,
1453 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G |
1454 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_25G |
1455 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_100G;
1458 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
1459 static const uint32_t *
1460 fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1462 if (dev->rx_pkt_burst == fm10k_recv_pkts ||
1463 dev->rx_pkt_burst == fm10k_recv_scattered_pkts) {
1464 static uint32_t ptypes[] = {
1465 /* refers to rx_desc_to_ol_flags() */
1468 RTE_PTYPE_L3_IPV4_EXT,
1470 RTE_PTYPE_L3_IPV6_EXT,
1477 } else if (dev->rx_pkt_burst == fm10k_recv_pkts_vec ||
1478 dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec) {
1479 static uint32_t ptypes_vec[] = {
1480 /* refers to fm10k_desc_to_pktype_v() */
1482 RTE_PTYPE_L3_IPV4_EXT,
1484 RTE_PTYPE_L3_IPV6_EXT,
1487 RTE_PTYPE_TUNNEL_GENEVE,
1488 RTE_PTYPE_TUNNEL_NVGRE,
1489 RTE_PTYPE_TUNNEL_VXLAN,
1490 RTE_PTYPE_TUNNEL_GRE,
1500 static const uint32_t *
1501 fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1508 fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1511 uint16_t mac_num = 0;
1512 uint32_t vid_idx, vid_bit, mac_index;
1513 struct fm10k_hw *hw;
1514 struct fm10k_macvlan_filter_info *macvlan;
1515 struct rte_eth_dev_data *data = dev->data;
1517 hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1518 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1520 if (macvlan->nb_queue_pools > 0) { /* VMDQ mode */
1521 PMD_INIT_LOG(ERR, "Cannot change VLAN filter in VMDQ mode");
1525 if (vlan_id > ETH_VLAN_ID_MAX) {
1526 PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");
1530 vid_idx = FM10K_VFTA_IDX(vlan_id);
1531 vid_bit = FM10K_VFTA_BIT(vlan_id);
1532 /* this VLAN ID is already in the VLAN filter table, return SUCCESS */
1533 if (on && (macvlan->vfta[vid_idx] & vid_bit))
1535 /* this VLAN ID is NOT in the VLAN filter table, cannot remove */
1536 if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {
1537 PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "
1538 "in the VLAN filter table");
1543 result = fm10k_update_vlan(hw, vlan_id, 0, on);
1544 fm10k_mbx_unlock(hw);
1545 if (result != FM10K_SUCCESS) {
1546 PMD_INIT_LOG(ERR, "VLAN update failed: %d", result);
1550 for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) &&
1551 (result == FM10K_SUCCESS); mac_index++) {
1552 if (is_zero_ether_addr(&data->mac_addrs[mac_index]))
1554 if (mac_num > macvlan->mac_num - 1) {
1555 PMD_INIT_LOG(ERR, "MAC address number "
1560 result = fm10k_update_uc_addr(hw, hw->mac.dglort_map,
1561 data->mac_addrs[mac_index].addr_bytes,
1563 fm10k_mbx_unlock(hw);
1566 if (result != FM10K_SUCCESS) {
1567 PMD_INIT_LOG(ERR, "MAC address update failed: %d", result);
1572 macvlan->vlan_num++;
1573 macvlan->vfta[vid_idx] |= vid_bit;
1575 macvlan->vlan_num--;
1576 macvlan->vfta[vid_idx] &= ~vid_bit;
1582 fm10k_vlan_offload_set(__rte_unused struct rte_eth_dev *dev, int mask)
1584 if (mask & ETH_VLAN_STRIP_MASK) {
1585 if (!dev->data->dev_conf.rxmode.hw_vlan_strip)
1586 PMD_INIT_LOG(ERR, "VLAN stripping is "
1587 "always on in fm10k");
1590 if (mask & ETH_VLAN_EXTEND_MASK) {
1591 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1592 PMD_INIT_LOG(ERR, "VLAN QinQ is not "
1593 "supported in fm10k");
1596 if (mask & ETH_VLAN_FILTER_MASK) {
1597 if (!dev->data->dev_conf.rxmode.hw_vlan_filter)
1598 PMD_INIT_LOG(ERR, "VLAN filter is always on in fm10k");
1602 /* Add/Remove a MAC address, and update filters to main VSI */
1603 static void fm10k_MAC_filter_set_main_vsi(struct rte_eth_dev *dev,
1604 const u8 *mac, bool add, uint32_t pool)
1606 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1607 struct fm10k_macvlan_filter_info *macvlan;
1610 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1612 if (pool != MAIN_VSI_POOL_NUMBER) {
1613 PMD_DRV_LOG(ERR, "VMDQ not enabled, can't set "
1614 "mac to pool %u", pool);
1617 for (i = 0, j = 0; j < FM10K_VFTA_SIZE; j++) {
1618 if (!macvlan->vfta[j])
1620 for (k = 0; k < FM10K_UINT32_BIT_SIZE; k++) {
1621 if (!(macvlan->vfta[j] & (1 << k)))
1623 if (i + 1 > macvlan->vlan_num) {
1624 PMD_INIT_LOG(ERR, "vlan number not match");
1628 fm10k_update_uc_addr(hw, hw->mac.dglort_map, mac,
1629 j * FM10K_UINT32_BIT_SIZE + k, add, 0);
1630 fm10k_mbx_unlock(hw);
1636 /* Add/Remove a MAC address, and update filters to VMDQ */
1637 static void fm10k_MAC_filter_set_vmdq(struct rte_eth_dev *dev,
1638 const u8 *mac, bool add, uint32_t pool)
1640 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1641 struct fm10k_macvlan_filter_info *macvlan;
1642 struct rte_eth_vmdq_rx_conf *vmdq_conf;
1645 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1646 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
1648 if (pool > macvlan->nb_queue_pools) {
1649 PMD_DRV_LOG(ERR, "Pool number %u invalid."
1651 pool, macvlan->nb_queue_pools);
1654 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
1655 if (!(vmdq_conf->pool_map[i].pools & (1UL << pool)))
1658 fm10k_update_uc_addr(hw, hw->mac.dglort_map + pool, mac,
1659 vmdq_conf->pool_map[i].vlan_id, add, 0);
1660 fm10k_mbx_unlock(hw);
1664 /* Add/Remove a MAC address, and update filters */
1665 static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
1666 const u8 *mac, bool add, uint32_t pool)
1668 struct fm10k_macvlan_filter_info *macvlan;
1670 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1672 if (macvlan->nb_queue_pools > 0) /* VMDQ mode */
1673 fm10k_MAC_filter_set_vmdq(dev, mac, add, pool);
1675 fm10k_MAC_filter_set_main_vsi(dev, mac, add, pool);
1683 /* Add a MAC address, and update filters */
1685 fm10k_macaddr_add(struct rte_eth_dev *dev,
1686 struct ether_addr *mac_addr,
1690 struct fm10k_macvlan_filter_info *macvlan;
1692 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1693 fm10k_MAC_filter_set(dev, mac_addr->addr_bytes, TRUE, pool);
1694 macvlan->mac_vmdq_id[index] = pool;
1697 /* Remove a MAC address, and update filters */
1699 fm10k_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
1701 struct rte_eth_dev_data *data = dev->data;
1702 struct fm10k_macvlan_filter_info *macvlan;
1704 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1705 fm10k_MAC_filter_set(dev, data->mac_addrs[index].addr_bytes,
1706 FALSE, macvlan->mac_vmdq_id[index]);
1707 macvlan->mac_vmdq_id[index] = 0;
1711 check_nb_desc(uint16_t min, uint16_t max, uint16_t mult, uint16_t request)
1713 if ((request < min) || (request > max) || ((request % mult) != 0))
1721 check_thresh(uint16_t min, uint16_t max, uint16_t div, uint16_t request)
1723 if ((request < min) || (request > max) || ((div % request) != 0))
1730 handle_rxconf(struct fm10k_rx_queue *q, const struct rte_eth_rxconf *conf)
1732 uint16_t rx_free_thresh;
1734 if (conf->rx_free_thresh == 0)
1735 rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(q);
1737 rx_free_thresh = conf->rx_free_thresh;
1739 /* make sure the requested threshold satisfies the constraints */
1740 if (check_thresh(FM10K_RX_FREE_THRESH_MIN(q),
1741 FM10K_RX_FREE_THRESH_MAX(q),
1742 FM10K_RX_FREE_THRESH_DIV(q),
1744 PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be "
1745 "less than or equal to %u, "
1746 "greater than or equal to %u, "
1747 "and a divisor of %u",
1748 rx_free_thresh, FM10K_RX_FREE_THRESH_MAX(q),
1749 FM10K_RX_FREE_THRESH_MIN(q),
1750 FM10K_RX_FREE_THRESH_DIV(q));
1754 q->alloc_thresh = rx_free_thresh;
1755 q->drop_en = conf->rx_drop_en;
1756 q->rx_deferred_start = conf->rx_deferred_start;
1762 * Hardware requires specific alignment for Rx packet buffers. At
1763 * least one of the following two conditions must be satisfied.
1764 * 1. Address is 512B aligned
1765 * 2. Address is 8B aligned and buffer does not cross 4K boundary.
1767 * As such, the driver may need to adjust the DMA address within the
1768 * buffer by up to 512B.
1770 * return 1 if the element size is valid, otherwise return 0.
1773 mempool_element_size_valid(struct rte_mempool *mp)
1777 /* elt_size includes mbuf header and headroom */
1778 min_size = mp->elt_size - sizeof(struct rte_mbuf) -
1779 RTE_PKTMBUF_HEADROOM;
1781 /* account for up to 512B of alignment */
1782 min_size -= FM10K_RX_DATABUF_ALIGN;
1784 /* sanity check for overflow */
1785 if (min_size > mp->elt_size)
1793 fm10k_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1794 uint16_t nb_desc, unsigned int socket_id,
1795 const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
1797 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1798 struct fm10k_dev_info *dev_info =
1799 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
1800 struct fm10k_rx_queue *q;
1801 const struct rte_memzone *mz;
1803 PMD_INIT_FUNC_TRACE();
1805 /* make sure the mempool element size can account for alignment. */
1806 if (!mempool_element_size_valid(mp)) {
1807 PMD_INIT_LOG(ERR, "Error : Mempool element size is too small");
1811 /* make sure a valid number of descriptors have been requested */
1812 if (check_nb_desc(FM10K_MIN_RX_DESC, FM10K_MAX_RX_DESC,
1813 FM10K_MULT_RX_DESC, nb_desc)) {
1814 PMD_INIT_LOG(ERR, "Number of Rx descriptors (%u) must be "
1815 "less than or equal to %"PRIu32", "
1816 "greater than or equal to %u, "
1817 "and a multiple of %u",
1818 nb_desc, (uint32_t)FM10K_MAX_RX_DESC, FM10K_MIN_RX_DESC,
1819 FM10K_MULT_RX_DESC);
1824 * if this queue existed already, free the associated memory. The
1825 * queue cannot be reused in case we need to allocate memory on
1826 * different socket than was previously used.
1828 if (dev->data->rx_queues[queue_id] != NULL) {
1829 rx_queue_free(dev->data->rx_queues[queue_id]);
1830 dev->data->rx_queues[queue_id] = NULL;
1833 /* allocate memory for the queue structure */
1834 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1837 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
1843 q->nb_desc = nb_desc;
1844 q->nb_fake_desc = FM10K_MULT_RX_DESC;
1845 q->port_id = dev->data->port_id;
1846 q->queue_id = queue_id;
1847 q->tail_ptr = (volatile uint32_t *)
1848 &((uint32_t *)hw->hw_addr)[FM10K_RDT(queue_id)];
1849 if (handle_rxconf(q, conf))
1852 /* allocate memory for the software ring */
1853 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
1854 (nb_desc + q->nb_fake_desc) * sizeof(struct rte_mbuf *),
1855 RTE_CACHE_LINE_SIZE, socket_id);
1856 if (q->sw_ring == NULL) {
1857 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
1863 * allocate memory for the hardware descriptor ring. A memzone large
1864 * enough to hold the maximum ring size is requested to allow for
1865 * resizing in later calls to the queue setup function.
1867 mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
1868 FM10K_MAX_RX_RING_SZ, FM10K_ALIGN_RX_DESC,
1871 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
1872 rte_free(q->sw_ring);
1876 q->hw_ring = mz->addr;
1877 q->hw_ring_phys_addr = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
1879 /* Check if number of descs satisfied Vector requirement */
1880 if (!rte_is_power_of_2(nb_desc)) {
1881 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
1882 "preconditions - canceling the feature for "
1883 "the whole port[%d]",
1884 q->queue_id, q->port_id);
1885 dev_info->rx_vec_allowed = false;
1887 fm10k_rxq_vec_setup(q);
1889 dev->data->rx_queues[queue_id] = q;
1894 fm10k_rx_queue_release(void *queue)
1896 PMD_INIT_FUNC_TRACE();
1898 rx_queue_free(queue);
1902 handle_txconf(struct fm10k_tx_queue *q, const struct rte_eth_txconf *conf)
1904 uint16_t tx_free_thresh;
1905 uint16_t tx_rs_thresh;
1907 /* constraint MACROs require that tx_free_thresh is configured
1908 * before tx_rs_thresh */
1909 if (conf->tx_free_thresh == 0)
1910 tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(q);
1912 tx_free_thresh = conf->tx_free_thresh;
1914 /* make sure the requested threshold satisfies the constraints */
1915 if (check_thresh(FM10K_TX_FREE_THRESH_MIN(q),
1916 FM10K_TX_FREE_THRESH_MAX(q),
1917 FM10K_TX_FREE_THRESH_DIV(q),
1919 PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be "
1920 "less than or equal to %u, "
1921 "greater than or equal to %u, "
1922 "and a divisor of %u",
1923 tx_free_thresh, FM10K_TX_FREE_THRESH_MAX(q),
1924 FM10K_TX_FREE_THRESH_MIN(q),
1925 FM10K_TX_FREE_THRESH_DIV(q));
1929 q->free_thresh = tx_free_thresh;
1931 if (conf->tx_rs_thresh == 0)
1932 tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(q);
1934 tx_rs_thresh = conf->tx_rs_thresh;
1936 q->tx_deferred_start = conf->tx_deferred_start;
1938 /* make sure the requested threshold satisfies the constraints */
1939 if (check_thresh(FM10K_TX_RS_THRESH_MIN(q),
1940 FM10K_TX_RS_THRESH_MAX(q),
1941 FM10K_TX_RS_THRESH_DIV(q),
1943 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be "
1944 "less than or equal to %u, "
1945 "greater than or equal to %u, "
1946 "and a divisor of %u",
1947 tx_rs_thresh, FM10K_TX_RS_THRESH_MAX(q),
1948 FM10K_TX_RS_THRESH_MIN(q),
1949 FM10K_TX_RS_THRESH_DIV(q));
1953 q->rs_thresh = tx_rs_thresh;
1959 fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1960 uint16_t nb_desc, unsigned int socket_id,
1961 const struct rte_eth_txconf *conf)
1963 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1964 struct fm10k_tx_queue *q;
1965 const struct rte_memzone *mz;
1967 PMD_INIT_FUNC_TRACE();
1969 /* make sure a valid number of descriptors have been requested */
1970 if (check_nb_desc(FM10K_MIN_TX_DESC, FM10K_MAX_TX_DESC,
1971 FM10K_MULT_TX_DESC, nb_desc)) {
1972 PMD_INIT_LOG(ERR, "Number of Tx descriptors (%u) must be "
1973 "less than or equal to %"PRIu32", "
1974 "greater than or equal to %u, "
1975 "and a multiple of %u",
1976 nb_desc, (uint32_t)FM10K_MAX_TX_DESC, FM10K_MIN_TX_DESC,
1977 FM10K_MULT_TX_DESC);
1982 * if this queue existed already, free the associated memory. The
1983 * queue cannot be reused in case we need to allocate memory on
1984 * different socket than was previously used.
1986 if (dev->data->tx_queues[queue_id] != NULL) {
1987 struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id];
1990 dev->data->tx_queues[queue_id] = NULL;
1993 /* allocate memory for the queue structure */
1994 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1997 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
2002 q->nb_desc = nb_desc;
2003 q->port_id = dev->data->port_id;
2004 q->queue_id = queue_id;
2005 q->txq_flags = conf->txq_flags;
2006 q->ops = &def_txq_ops;
2007 q->tail_ptr = (volatile uint32_t *)
2008 &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
2009 if (handle_txconf(q, conf))
2012 /* allocate memory for the software ring */
2013 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
2014 nb_desc * sizeof(struct rte_mbuf *),
2015 RTE_CACHE_LINE_SIZE, socket_id);
2016 if (q->sw_ring == NULL) {
2017 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
2023 * allocate memory for the hardware descriptor ring. A memzone large
2024 * enough to hold the maximum ring size is requested to allow for
2025 * resizing in later calls to the queue setup function.
2027 mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_id,
2028 FM10K_MAX_TX_RING_SZ, FM10K_ALIGN_TX_DESC,
2031 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
2032 rte_free(q->sw_ring);
2036 q->hw_ring = mz->addr;
2037 q->hw_ring_phys_addr = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
2040 * allocate memory for the RS bit tracker. Enough slots to hold the
2041 * descriptor index for each RS bit needing to be set are required.
2043 q->rs_tracker.list = rte_zmalloc_socket("fm10k rs tracker",
2044 ((nb_desc + 1) / q->rs_thresh) *
2046 RTE_CACHE_LINE_SIZE, socket_id);
2047 if (q->rs_tracker.list == NULL) {
2048 PMD_INIT_LOG(ERR, "Cannot allocate RS bit tracker");
2049 rte_free(q->sw_ring);
2054 dev->data->tx_queues[queue_id] = q;
2059 fm10k_tx_queue_release(void *queue)
2061 struct fm10k_tx_queue *q = queue;
2062 PMD_INIT_FUNC_TRACE();
2068 fm10k_reta_update(struct rte_eth_dev *dev,
2069 struct rte_eth_rss_reta_entry64 *reta_conf,
2072 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2073 uint16_t i, j, idx, shift;
2077 PMD_INIT_FUNC_TRACE();
2079 if (reta_size > FM10K_MAX_RSS_INDICES) {
2080 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2081 "(%d) doesn't match the number hardware can supported "
2082 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2087 * Update Redirection Table RETA[n], n=0..31. The redirection table has
2088 * 128-entries in 32 registers
2090 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2091 idx = i / RTE_RETA_GROUP_SIZE;
2092 shift = i % RTE_RETA_GROUP_SIZE;
2093 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2094 BIT_MASK_PER_UINT32);
2099 if (mask != BIT_MASK_PER_UINT32)
2100 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2102 for (j = 0; j < CHARS_PER_UINT32; j++) {
2103 if (mask & (0x1 << j)) {
2105 reta &= ~(UINT8_MAX << CHAR_BIT * j);
2106 reta |= reta_conf[idx].reta[shift + j] <<
2110 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2), reta);
2117 fm10k_reta_query(struct rte_eth_dev *dev,
2118 struct rte_eth_rss_reta_entry64 *reta_conf,
2121 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2122 uint16_t i, j, idx, shift;
2126 PMD_INIT_FUNC_TRACE();
2128 if (reta_size < FM10K_MAX_RSS_INDICES) {
2129 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2130 "(%d) doesn't match the number hardware can supported "
2131 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2136 * Read Redirection Table RETA[n], n=0..31. The redirection table has
2137 * 128-entries in 32 registers
2139 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2140 idx = i / RTE_RETA_GROUP_SIZE;
2141 shift = i % RTE_RETA_GROUP_SIZE;
2142 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2143 BIT_MASK_PER_UINT32);
2147 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2148 for (j = 0; j < CHARS_PER_UINT32; j++) {
2149 if (mask & (0x1 << j))
2150 reta_conf[idx].reta[shift + j] = ((reta >>
2151 CHAR_BIT * j) & UINT8_MAX);
2159 fm10k_rss_hash_update(struct rte_eth_dev *dev,
2160 struct rte_eth_rss_conf *rss_conf)
2162 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2163 uint32_t *key = (uint32_t *)rss_conf->rss_key;
2165 uint64_t hf = rss_conf->rss_hf;
2168 PMD_INIT_FUNC_TRACE();
2170 if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2171 FM10K_RSSRK_ENTRIES_PER_REG))
2178 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
2179 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
2180 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
2181 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
2182 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
2183 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
2184 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
2185 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
2186 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
2188 /* If the mapping doesn't fit any supported, return */
2193 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2194 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
2196 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
2202 fm10k_rss_hash_conf_get(struct rte_eth_dev *dev,
2203 struct rte_eth_rss_conf *rss_conf)
2205 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2206 uint32_t *key = (uint32_t *)rss_conf->rss_key;
2211 PMD_INIT_FUNC_TRACE();
2213 if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2214 FM10K_RSSRK_ENTRIES_PER_REG))
2218 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2219 key[i] = FM10K_READ_REG(hw, FM10K_RSSRK(0, i));
2221 mrqc = FM10K_READ_REG(hw, FM10K_MRQC(0));
2223 hf |= (mrqc & FM10K_MRQC_IPV4) ? ETH_RSS_IPV4 : 0;
2224 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6 : 0;
2225 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6_EX : 0;
2226 hf |= (mrqc & FM10K_MRQC_TCP_IPV4) ? ETH_RSS_NONFRAG_IPV4_TCP : 0;
2227 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_NONFRAG_IPV6_TCP : 0;
2228 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_IPV6_TCP_EX : 0;
2229 hf |= (mrqc & FM10K_MRQC_UDP_IPV4) ? ETH_RSS_NONFRAG_IPV4_UDP : 0;
2230 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_NONFRAG_IPV6_UDP : 0;
2231 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_IPV6_UDP_EX : 0;
2233 rss_conf->rss_hf = hf;
2239 fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)
2241 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2242 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2244 /* Bind all local non-queue interrupt to vector 0 */
2245 int_map |= FM10K_MISC_VEC_ID;
2247 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2248 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2249 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2250 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2251 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2252 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2254 /* Enable misc causes */
2255 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
2256 FM10K_EIMR_ENABLE(THI_FAULT) |
2257 FM10K_EIMR_ENABLE(FUM_FAULT) |
2258 FM10K_EIMR_ENABLE(MAILBOX) |
2259 FM10K_EIMR_ENABLE(SWITCHREADY) |
2260 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
2261 FM10K_EIMR_ENABLE(SRAMERROR) |
2262 FM10K_EIMR_ENABLE(VFLR));
2265 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2266 FM10K_ITR_MASK_CLEAR);
2267 FM10K_WRITE_FLUSH(hw);
2271 fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev)
2273 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2274 uint32_t int_map = FM10K_INT_MAP_DISABLE;
2276 int_map |= FM10K_MISC_VEC_ID;
2278 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2279 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2280 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2281 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2282 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2283 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2285 /* Disable misc causes */
2286 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
2287 FM10K_EIMR_DISABLE(THI_FAULT) |
2288 FM10K_EIMR_DISABLE(FUM_FAULT) |
2289 FM10K_EIMR_DISABLE(MAILBOX) |
2290 FM10K_EIMR_DISABLE(SWITCHREADY) |
2291 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
2292 FM10K_EIMR_DISABLE(SRAMERROR) |
2293 FM10K_EIMR_DISABLE(VFLR));
2296 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
2297 FM10K_WRITE_FLUSH(hw);
2301 fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
2303 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2304 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2306 /* Bind all local non-queue interrupt to vector 0 */
2307 int_map |= FM10K_MISC_VEC_ID;
2309 /* Only INT 0 available, other 15 are reserved. */
2310 FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2313 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2314 FM10K_ITR_MASK_CLEAR);
2315 FM10K_WRITE_FLUSH(hw);
2319 fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev)
2321 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2322 uint32_t int_map = FM10K_INT_MAP_DISABLE;
2324 int_map |= FM10K_MISC_VEC_ID;
2326 /* Only INT 0 available, other 15 are reserved. */
2327 FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2330 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
2331 FM10K_WRITE_FLUSH(hw);
2335 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2337 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2340 if (hw->mac.type == fm10k_mac_pf)
2341 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
2342 FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2344 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
2345 FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2346 rte_intr_enable(&dev->pci_dev->intr_handle);
2351 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2353 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2356 if (hw->mac.type == fm10k_mac_pf)
2357 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(dev, queue_id)),
2358 FM10K_ITR_MASK_SET);
2360 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(dev, queue_id)),
2361 FM10K_ITR_MASK_SET);
2366 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2368 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2369 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
2370 uint32_t intr_vector, vec;
2374 /* fm10k needs one separate interrupt for mailbox,
2375 * so only drivers which support multiple interrupt vectors
2376 * e.g. vfio-pci can work for fm10k interrupt mode
2378 if (!rte_intr_cap_multiple(intr_handle) ||
2379 dev->data->dev_conf.intr_conf.rxq == 0)
2382 intr_vector = dev->data->nb_rx_queues;
2384 /* disable interrupt first */
2385 rte_intr_disable(&dev->pci_dev->intr_handle);
2386 if (hw->mac.type == fm10k_mac_pf)
2387 fm10k_dev_disable_intr_pf(dev);
2389 fm10k_dev_disable_intr_vf(dev);
2391 if (rte_intr_efd_enable(intr_handle, intr_vector)) {
2392 PMD_INIT_LOG(ERR, "Failed to init event fd");
2396 if (rte_intr_dp_is_en(intr_handle) && !result) {
2397 intr_handle->intr_vec = rte_zmalloc("intr_vec",
2398 dev->data->nb_rx_queues * sizeof(int), 0);
2399 if (intr_handle->intr_vec) {
2400 for (queue_id = 0, vec = FM10K_RX_VEC_START;
2401 queue_id < dev->data->nb_rx_queues;
2403 intr_handle->intr_vec[queue_id] = vec;
2404 if (vec < intr_handle->nb_efd - 1
2405 + FM10K_RX_VEC_START)
2409 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2410 " intr_vec", dev->data->nb_rx_queues);
2411 rte_intr_efd_disable(intr_handle);
2416 if (hw->mac.type == fm10k_mac_pf)
2417 fm10k_dev_enable_intr_pf(dev);
2419 fm10k_dev_enable_intr_vf(dev);
2420 rte_intr_enable(&dev->pci_dev->intr_handle);
2421 hw->mac.ops.update_int_moderator(hw);
2426 fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
2428 struct fm10k_fault fault;
2430 const char *estr = "Unknown error";
2432 /* Process PCA fault */
2433 if (eicr & FM10K_EICR_PCA_FAULT) {
2434 err = fm10k_get_fault(hw, FM10K_PCA_FAULT, &fault);
2437 switch (fault.type) {
2439 estr = "PCA_NO_FAULT"; break;
2440 case PCA_UNMAPPED_ADDR:
2441 estr = "PCA_UNMAPPED_ADDR"; break;
2442 case PCA_BAD_QACCESS_PF:
2443 estr = "PCA_BAD_QACCESS_PF"; break;
2444 case PCA_BAD_QACCESS_VF:
2445 estr = "PCA_BAD_QACCESS_VF"; break;
2446 case PCA_MALICIOUS_REQ:
2447 estr = "PCA_MALICIOUS_REQ"; break;
2448 case PCA_POISONED_TLP:
2449 estr = "PCA_POISONED_TLP"; break;
2451 estr = "PCA_TLP_ABORT"; break;
2455 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2456 estr, fault.func ? "VF" : "PF", fault.func,
2457 fault.address, fault.specinfo);
2460 /* Process THI fault */
2461 if (eicr & FM10K_EICR_THI_FAULT) {
2462 err = fm10k_get_fault(hw, FM10K_THI_FAULT, &fault);
2465 switch (fault.type) {
2467 estr = "THI_NO_FAULT"; break;
2468 case THI_MAL_DIS_Q_FAULT:
2469 estr = "THI_MAL_DIS_Q_FAULT"; break;
2473 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2474 estr, fault.func ? "VF" : "PF", fault.func,
2475 fault.address, fault.specinfo);
2478 /* Process FUM fault */
2479 if (eicr & FM10K_EICR_FUM_FAULT) {
2480 err = fm10k_get_fault(hw, FM10K_FUM_FAULT, &fault);
2483 switch (fault.type) {
2485 estr = "FUM_NO_FAULT"; break;
2486 case FUM_UNMAPPED_ADDR:
2487 estr = "FUM_UNMAPPED_ADDR"; break;
2488 case FUM_POISONED_TLP:
2489 estr = "FUM_POISONED_TLP"; break;
2490 case FUM_BAD_VF_QACCESS:
2491 estr = "FUM_BAD_VF_QACCESS"; break;
2492 case FUM_ADD_DECODE_ERR:
2493 estr = "FUM_ADD_DECODE_ERR"; break;
2495 estr = "FUM_RO_ERROR"; break;
2496 case FUM_QPRC_CRC_ERROR:
2497 estr = "FUM_QPRC_CRC_ERROR"; break;
2498 case FUM_CSR_TIMEOUT:
2499 estr = "FUM_CSR_TIMEOUT"; break;
2500 case FUM_INVALID_TYPE:
2501 estr = "FUM_INVALID_TYPE"; break;
2502 case FUM_INVALID_LENGTH:
2503 estr = "FUM_INVALID_LENGTH"; break;
2504 case FUM_INVALID_BE:
2505 estr = "FUM_INVALID_BE"; break;
2506 case FUM_INVALID_ALIGN:
2507 estr = "FUM_INVALID_ALIGN"; break;
2511 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2512 estr, fault.func ? "VF" : "PF", fault.func,
2513 fault.address, fault.specinfo);
2518 PMD_INIT_LOG(ERR, "Failed to handle fault event.");
2523 * PF interrupt handler triggered by NIC for handling specific interrupt.
2526 * Pointer to interrupt handle.
2528 * The address of parameter (struct rte_eth_dev *) regsitered before.
2534 fm10k_dev_interrupt_handler_pf(
2535 __rte_unused struct rte_intr_handle *handle,
2538 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2539 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2540 uint32_t cause, status;
2542 if (hw->mac.type != fm10k_mac_pf)
2545 cause = FM10K_READ_REG(hw, FM10K_EICR);
2547 /* Handle PCI fault cases */
2548 if (cause & FM10K_EICR_FAULT_MASK) {
2549 PMD_INIT_LOG(ERR, "INT: find fault!");
2550 fm10k_dev_handle_fault(hw, cause);
2553 /* Handle switch up/down */
2554 if (cause & FM10K_EICR_SWITCHNOTREADY)
2555 PMD_INIT_LOG(ERR, "INT: Switch is not ready");
2557 if (cause & FM10K_EICR_SWITCHREADY)
2558 PMD_INIT_LOG(INFO, "INT: Switch is ready");
2560 /* Handle mailbox message */
2562 hw->mbx.ops.process(hw, &hw->mbx);
2563 fm10k_mbx_unlock(hw);
2565 /* Handle SRAM error */
2566 if (cause & FM10K_EICR_SRAMERROR) {
2567 PMD_INIT_LOG(ERR, "INT: SRAM error on PEP");
2569 status = FM10K_READ_REG(hw, FM10K_SRAM_IP);
2570 /* Write to clear pending bits */
2571 FM10K_WRITE_REG(hw, FM10K_SRAM_IP, status);
2573 /* Todo: print out error message after shared code updates */
2576 /* Clear these 3 events if having any */
2577 cause &= FM10K_EICR_SWITCHNOTREADY | FM10K_EICR_MAILBOX |
2578 FM10K_EICR_SWITCHREADY;
2580 FM10K_WRITE_REG(hw, FM10K_EICR, cause);
2582 /* Re-enable interrupt from device side */
2583 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2584 FM10K_ITR_MASK_CLEAR);
2585 /* Re-enable interrupt from host side */
2586 rte_intr_enable(&(dev->pci_dev->intr_handle));
2590 * VF interrupt handler triggered by NIC for handling specific interrupt.
2593 * Pointer to interrupt handle.
2595 * The address of parameter (struct rte_eth_dev *) regsitered before.
2601 fm10k_dev_interrupt_handler_vf(
2602 __rte_unused struct rte_intr_handle *handle,
2605 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2606 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2608 if (hw->mac.type != fm10k_mac_vf)
2611 /* Handle mailbox message if lock is acquired */
2613 hw->mbx.ops.process(hw, &hw->mbx);
2614 fm10k_mbx_unlock(hw);
2616 /* Re-enable interrupt from device side */
2617 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2618 FM10K_ITR_MASK_CLEAR);
2619 /* Re-enable interrupt from host side */
2620 rte_intr_enable(&(dev->pci_dev->intr_handle));
2623 /* Mailbox message handler in VF */
2624 static const struct fm10k_msg_data fm10k_msgdata_vf[] = {
2625 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
2626 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
2627 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
2628 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
2632 fm10k_setup_mbx_service(struct fm10k_hw *hw)
2636 /* Initialize mailbox lock */
2637 fm10k_mbx_initlock(hw);
2639 /* Replace default message handler with new ones */
2640 if (hw->mac.type == fm10k_mac_vf)
2641 err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_vf);
2644 PMD_INIT_LOG(ERR, "Failed to register mailbox handler.err:%d",
2648 /* Connect to SM for PF device or PF for VF device */
2649 return hw->mbx.ops.connect(hw, &hw->mbx);
2653 fm10k_close_mbx_service(struct fm10k_hw *hw)
2655 /* Disconnect from SM for PF device or PF for VF device */
2656 hw->mbx.ops.disconnect(hw, &hw->mbx);
2659 static const struct eth_dev_ops fm10k_eth_dev_ops = {
2660 .dev_configure = fm10k_dev_configure,
2661 .dev_start = fm10k_dev_start,
2662 .dev_stop = fm10k_dev_stop,
2663 .dev_close = fm10k_dev_close,
2664 .promiscuous_enable = fm10k_dev_promiscuous_enable,
2665 .promiscuous_disable = fm10k_dev_promiscuous_disable,
2666 .allmulticast_enable = fm10k_dev_allmulticast_enable,
2667 .allmulticast_disable = fm10k_dev_allmulticast_disable,
2668 .stats_get = fm10k_stats_get,
2669 .xstats_get = fm10k_xstats_get,
2670 .xstats_get_names = fm10k_xstats_get_names,
2671 .stats_reset = fm10k_stats_reset,
2672 .xstats_reset = fm10k_stats_reset,
2673 .link_update = fm10k_link_update,
2674 .dev_infos_get = fm10k_dev_infos_get,
2675 .dev_supported_ptypes_get = fm10k_dev_supported_ptypes_get,
2676 .vlan_filter_set = fm10k_vlan_filter_set,
2677 .vlan_offload_set = fm10k_vlan_offload_set,
2678 .mac_addr_add = fm10k_macaddr_add,
2679 .mac_addr_remove = fm10k_macaddr_remove,
2680 .rx_queue_start = fm10k_dev_rx_queue_start,
2681 .rx_queue_stop = fm10k_dev_rx_queue_stop,
2682 .tx_queue_start = fm10k_dev_tx_queue_start,
2683 .tx_queue_stop = fm10k_dev_tx_queue_stop,
2684 .rx_queue_setup = fm10k_rx_queue_setup,
2685 .rx_queue_release = fm10k_rx_queue_release,
2686 .tx_queue_setup = fm10k_tx_queue_setup,
2687 .tx_queue_release = fm10k_tx_queue_release,
2688 .rx_descriptor_done = fm10k_dev_rx_descriptor_done,
2689 .rx_queue_intr_enable = fm10k_dev_rx_queue_intr_enable,
2690 .rx_queue_intr_disable = fm10k_dev_rx_queue_intr_disable,
2691 .reta_update = fm10k_reta_update,
2692 .reta_query = fm10k_reta_query,
2693 .rss_hash_update = fm10k_rss_hash_update,
2694 .rss_hash_conf_get = fm10k_rss_hash_conf_get,
2697 static int ftag_check_handler(__rte_unused const char *key,
2698 const char *value, __rte_unused void *opaque)
2700 if (strcmp(value, "1"))
2707 fm10k_check_ftag(struct rte_devargs *devargs)
2709 struct rte_kvargs *kvlist;
2710 const char *ftag_key = "enable_ftag";
2712 if (devargs == NULL)
2715 kvlist = rte_kvargs_parse(devargs->args, NULL);
2719 if (!rte_kvargs_count(kvlist, ftag_key)) {
2720 rte_kvargs_free(kvlist);
2723 /* FTAG is enabled when there's key-value pair: enable_ftag=1 */
2724 if (rte_kvargs_process(kvlist, ftag_key,
2725 ftag_check_handler, NULL) < 0) {
2726 rte_kvargs_free(kvlist);
2729 rte_kvargs_free(kvlist);
2734 static void __attribute__((cold))
2735 fm10k_set_tx_function(struct rte_eth_dev *dev)
2737 struct fm10k_tx_queue *txq;
2740 uint16_t tx_ftag_en = 0;
2742 if (fm10k_check_ftag(dev->pci_dev->device.devargs))
2745 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2746 txq = dev->data->tx_queues[i];
2747 txq->tx_ftag_en = tx_ftag_en;
2748 /* Check if Vector Tx is satisfied */
2749 if (fm10k_tx_vec_condition_check(txq))
2754 PMD_INIT_LOG(DEBUG, "Use vector Tx func");
2755 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2756 txq = dev->data->tx_queues[i];
2757 fm10k_txq_vec_setup(txq);
2759 dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
2761 dev->tx_pkt_burst = fm10k_xmit_pkts;
2762 PMD_INIT_LOG(DEBUG, "Use regular Tx func");
2766 static void __attribute__((cold))
2767 fm10k_set_rx_function(struct rte_eth_dev *dev)
2769 struct fm10k_dev_info *dev_info =
2770 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2771 uint16_t i, rx_using_sse;
2772 uint16_t rx_ftag_en = 0;
2774 if (fm10k_check_ftag(dev->pci_dev->device.devargs))
2777 /* In order to allow Vector Rx there are a few configuration
2778 * conditions to be met.
2780 if (!fm10k_rx_vec_condition_check(dev) &&
2781 dev_info->rx_vec_allowed && !rx_ftag_en) {
2782 if (dev->data->scattered_rx)
2783 dev->rx_pkt_burst = fm10k_recv_scattered_pkts_vec;
2785 dev->rx_pkt_burst = fm10k_recv_pkts_vec;
2786 } else if (dev->data->scattered_rx)
2787 dev->rx_pkt_burst = fm10k_recv_scattered_pkts;
2789 dev->rx_pkt_burst = fm10k_recv_pkts;
2792 (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec ||
2793 dev->rx_pkt_burst == fm10k_recv_pkts_vec);
2796 PMD_INIT_LOG(DEBUG, "Use vector Rx func");
2798 PMD_INIT_LOG(DEBUG, "Use regular Rx func");
2800 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2801 struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];
2803 rxq->rx_using_sse = rx_using_sse;
2804 rxq->rx_ftag_en = rx_ftag_en;
2809 fm10k_params_init(struct rte_eth_dev *dev)
2811 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2812 struct fm10k_dev_info *info =
2813 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2815 /* Inialize bus info. Normally we would call fm10k_get_bus_info(), but
2816 * there is no way to get link status without reading BAR4. Until this
2817 * works, assume we have maximum bandwidth.
2818 * @todo - fix bus info
2820 hw->bus_caps.speed = fm10k_bus_speed_8000;
2821 hw->bus_caps.width = fm10k_bus_width_pcie_x8;
2822 hw->bus_caps.payload = fm10k_bus_payload_512;
2823 hw->bus.speed = fm10k_bus_speed_8000;
2824 hw->bus.width = fm10k_bus_width_pcie_x8;
2825 hw->bus.payload = fm10k_bus_payload_256;
2827 info->rx_vec_allowed = true;
2831 eth_fm10k_dev_init(struct rte_eth_dev *dev)
2833 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2835 struct fm10k_macvlan_filter_info *macvlan;
2837 PMD_INIT_FUNC_TRACE();
2839 dev->dev_ops = &fm10k_eth_dev_ops;
2840 dev->rx_pkt_burst = &fm10k_recv_pkts;
2841 dev->tx_pkt_burst = &fm10k_xmit_pkts;
2843 /* only initialize in the primary process */
2844 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2847 rte_eth_copy_pci_info(dev, dev->pci_dev);
2849 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
2850 memset(macvlan, 0, sizeof(*macvlan));
2851 /* Vendor and Device ID need to be set before init of shared code */
2852 memset(hw, 0, sizeof(*hw));
2853 hw->device_id = dev->pci_dev->id.device_id;
2854 hw->vendor_id = dev->pci_dev->id.vendor_id;
2855 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
2856 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
2857 hw->revision_id = 0;
2858 hw->hw_addr = (void *)dev->pci_dev->mem_resource[0].addr;
2859 if (hw->hw_addr == NULL) {
2860 PMD_INIT_LOG(ERR, "Bad mem resource."
2861 " Try to blacklist unused devices.");
2865 /* Store fm10k_adapter pointer */
2866 hw->back = dev->data->dev_private;
2868 /* Initialize the shared code */
2869 diag = fm10k_init_shared_code(hw);
2870 if (diag != FM10K_SUCCESS) {
2871 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
2875 /* Initialize parameters */
2876 fm10k_params_init(dev);
2878 /* Initialize the hw */
2879 diag = fm10k_init_hw(hw);
2880 if (diag != FM10K_SUCCESS) {
2881 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
2885 /* Initialize MAC address(es) */
2886 dev->data->mac_addrs = rte_zmalloc("fm10k",
2887 ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM, 0);
2888 if (dev->data->mac_addrs == NULL) {
2889 PMD_INIT_LOG(ERR, "Cannot allocate memory for MAC addresses");
2893 diag = fm10k_read_mac_addr(hw);
2895 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
2896 &dev->data->mac_addrs[0]);
2898 if (diag != FM10K_SUCCESS ||
2899 !is_valid_assigned_ether_addr(dev->data->mac_addrs)) {
2901 /* Generate a random addr */
2902 eth_random_addr(hw->mac.addr);
2903 memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
2904 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
2905 &dev->data->mac_addrs[0]);
2908 /* Reset the hw statistics */
2909 fm10k_stats_reset(dev);
2912 diag = fm10k_reset_hw(hw);
2913 if (diag != FM10K_SUCCESS) {
2914 PMD_INIT_LOG(ERR, "Hardware reset failed: %d", diag);
2918 /* Setup mailbox service */
2919 diag = fm10k_setup_mbx_service(hw);
2920 if (diag != FM10K_SUCCESS) {
2921 PMD_INIT_LOG(ERR, "Failed to setup mailbox: %d", diag);
2925 /*PF/VF has different interrupt handling mechanism */
2926 if (hw->mac.type == fm10k_mac_pf) {
2927 /* register callback func to eal lib */
2928 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
2929 fm10k_dev_interrupt_handler_pf, (void *)dev);
2931 /* enable MISC interrupt */
2932 fm10k_dev_enable_intr_pf(dev);
2934 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
2935 fm10k_dev_interrupt_handler_vf, (void *)dev);
2937 fm10k_dev_enable_intr_vf(dev);
2940 /* Enable intr after callback registered */
2941 rte_intr_enable(&(dev->pci_dev->intr_handle));
2943 hw->mac.ops.update_int_moderator(hw);
2945 /* Make sure Switch Manager is ready before going forward. */
2946 if (hw->mac.type == fm10k_mac_pf) {
2947 int switch_ready = 0;
2949 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
2951 hw->mac.ops.get_host_state(hw, &switch_ready);
2952 fm10k_mbx_unlock(hw);
2955 /* Delay some time to acquire async LPORT_MAP info. */
2956 rte_delay_us(WAIT_SWITCH_MSG_US);
2959 if (switch_ready == 0) {
2960 PMD_INIT_LOG(ERR, "switch is not ready");
2966 * Below function will trigger operations on mailbox, acquire lock to
2967 * avoid race condition from interrupt handler. Operations on mailbox
2968 * FIFO will trigger interrupt to PF/SM, in which interrupt handler
2969 * will handle and generate an interrupt to our side. Then, FIFO in
2970 * mailbox will be touched.
2973 /* Enable port first */
2974 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
2977 /* Set unicast mode by default. App can change to other mode in other
2980 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
2981 FM10K_XCAST_MODE_NONE);
2983 fm10k_mbx_unlock(hw);
2985 /* Make sure default VID is ready before going forward. */
2986 if (hw->mac.type == fm10k_mac_pf) {
2987 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
2988 if (hw->mac.default_vid)
2990 /* Delay some time to acquire async port VLAN info. */
2991 rte_delay_us(WAIT_SWITCH_MSG_US);
2994 if (!hw->mac.default_vid) {
2995 PMD_INIT_LOG(ERR, "default VID is not ready");
3000 /* Add default mac address */
3001 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
3002 MAIN_VSI_POOL_NUMBER);
3008 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
3010 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3012 PMD_INIT_FUNC_TRACE();
3014 /* only uninitialize in the primary process */
3015 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3018 /* safe to close dev here */
3019 fm10k_dev_close(dev);
3021 dev->dev_ops = NULL;
3022 dev->rx_pkt_burst = NULL;
3023 dev->tx_pkt_burst = NULL;
3025 /* disable uio/vfio intr */
3026 rte_intr_disable(&(dev->pci_dev->intr_handle));
3028 /*PF/VF has different interrupt handling mechanism */
3029 if (hw->mac.type == fm10k_mac_pf) {
3030 /* disable interrupt */
3031 fm10k_dev_disable_intr_pf(dev);
3033 /* unregister callback func to eal lib */
3034 rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
3035 fm10k_dev_interrupt_handler_pf, (void *)dev);
3037 /* disable interrupt */
3038 fm10k_dev_disable_intr_vf(dev);
3040 rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
3041 fm10k_dev_interrupt_handler_vf, (void *)dev);
3044 /* free mac memory */
3045 if (dev->data->mac_addrs) {
3046 rte_free(dev->data->mac_addrs);
3047 dev->data->mac_addrs = NULL;
3050 memset(hw, 0, sizeof(*hw));
3056 * The set of PCI devices this driver supports. This driver will enable both PF
3057 * and SRIOV-VF devices.
3059 static const struct rte_pci_id pci_id_fm10k_map[] = {
3060 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_PF) },
3061 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_SDI_FM10420_QDA2) },
3062 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_VF) },
3063 { .vendor_id = 0, /* sentinel */ },
3066 static struct eth_driver rte_pmd_fm10k = {
3068 .id_table = pci_id_fm10k_map,
3069 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
3070 RTE_PCI_DRV_DETACHABLE,
3071 .probe = rte_eth_dev_pci_probe,
3072 .remove = rte_eth_dev_pci_remove,
3074 .eth_dev_init = eth_fm10k_dev_init,
3075 .eth_dev_uninit = eth_fm10k_dev_uninit,
3076 .dev_private_size = sizeof(struct fm10k_adapter),
3079 RTE_PMD_REGISTER_PCI(net_fm10k, rte_pmd_fm10k.pci_drv);
3080 RTE_PMD_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);