1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013-2016 Intel Corporation
5 #include <rte_ethdev_driver.h>
6 #include <rte_ethdev_pci.h>
7 #include <rte_malloc.h>
8 #include <rte_memzone.h>
9 #include <rte_string_fns.h>
11 #include <rte_spinlock.h>
12 #include <rte_kvargs.h>
15 #include "base/fm10k_api.h"
17 /* Default delay to acquire mailbox lock */
18 #define FM10K_MBXLOCK_DELAY_US 20
19 #define UINT64_LOWER_32BITS_MASK 0x00000000ffffffffULL
21 #define MAIN_VSI_POOL_NUMBER 0
23 /* Max try times to acquire switch status */
24 #define MAX_QUERY_SWITCH_STATE_TIMES 10
25 /* Wait interval to get switch status */
26 #define WAIT_SWITCH_MSG_US 100000
27 /* A period of quiescence for switch */
28 #define FM10K_SWITCH_QUIESCE_US 100000
29 /* Number of chars per uint32 type */
30 #define CHARS_PER_UINT32 (sizeof(uint32_t))
31 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
33 /* default 1:1 map from queue ID to interrupt vector ID */
34 #define Q2V(pci_dev, queue_id) ((pci_dev)->intr_handle.intr_vec[queue_id])
36 /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
37 #define MAX_LPORT_NUM 128
38 #define GLORT_FD_Q_BASE 0x40
39 #define GLORT_PF_MASK 0xFFC0
40 #define GLORT_FD_MASK GLORT_PF_MASK
41 #define GLORT_FD_INDEX GLORT_FD_Q_BASE
43 int fm10k_logtype_init;
44 int fm10k_logtype_driver;
46 static void fm10k_close_mbx_service(struct fm10k_hw *hw);
47 static void fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev);
48 static void fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev);
49 static void fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev);
50 static void fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev);
51 static inline int fm10k_glort_valid(struct fm10k_hw *hw);
53 fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
54 static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
55 const u8 *mac, bool add, uint32_t pool);
56 static void fm10k_tx_queue_release(void *queue);
57 static void fm10k_rx_queue_release(void *queue);
58 static void fm10k_set_rx_function(struct rte_eth_dev *dev);
59 static void fm10k_set_tx_function(struct rte_eth_dev *dev);
60 static int fm10k_check_ftag(struct rte_devargs *devargs);
61 static int fm10k_link_update(struct rte_eth_dev *dev, int wait_to_complete);
63 static void fm10k_dev_infos_get(struct rte_eth_dev *dev,
64 struct rte_eth_dev_info *dev_info);
65 static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev);
66 static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev);
67 static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev);
68 static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev);
70 struct fm10k_xstats_name_off {
71 char name[RTE_ETH_XSTATS_NAME_SIZE];
75 static const struct fm10k_xstats_name_off fm10k_hw_stats_strings[] = {
76 {"completion_timeout_count", offsetof(struct fm10k_hw_stats, timeout)},
77 {"unsupported_requests_count", offsetof(struct fm10k_hw_stats, ur)},
78 {"completer_abort_count", offsetof(struct fm10k_hw_stats, ca)},
79 {"unsupported_message_count", offsetof(struct fm10k_hw_stats, um)},
80 {"checksum_error_count", offsetof(struct fm10k_hw_stats, xec)},
81 {"vlan_dropped", offsetof(struct fm10k_hw_stats, vlan_drop)},
82 {"loopback_dropped", offsetof(struct fm10k_hw_stats, loopback_drop)},
83 {"rx_mbuf_allocation_errors", offsetof(struct fm10k_hw_stats,
87 #define FM10K_NB_HW_XSTATS (sizeof(fm10k_hw_stats_strings) / \
88 sizeof(fm10k_hw_stats_strings[0]))
90 static const struct fm10k_xstats_name_off fm10k_hw_stats_rx_q_strings[] = {
91 {"packets", offsetof(struct fm10k_hw_stats_q, rx_packets)},
92 {"bytes", offsetof(struct fm10k_hw_stats_q, rx_bytes)},
93 {"dropped", offsetof(struct fm10k_hw_stats_q, rx_drops)},
96 #define FM10K_NB_RX_Q_XSTATS (sizeof(fm10k_hw_stats_rx_q_strings) / \
97 sizeof(fm10k_hw_stats_rx_q_strings[0]))
99 static const struct fm10k_xstats_name_off fm10k_hw_stats_tx_q_strings[] = {
100 {"packets", offsetof(struct fm10k_hw_stats_q, tx_packets)},
101 {"bytes", offsetof(struct fm10k_hw_stats_q, tx_bytes)},
104 #define FM10K_NB_TX_Q_XSTATS (sizeof(fm10k_hw_stats_tx_q_strings) / \
105 sizeof(fm10k_hw_stats_tx_q_strings[0]))
107 #define FM10K_NB_XSTATS (FM10K_NB_HW_XSTATS + FM10K_MAX_QUEUES_PF * \
108 (FM10K_NB_RX_Q_XSTATS + FM10K_NB_TX_Q_XSTATS))
110 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
113 fm10k_mbx_initlock(struct fm10k_hw *hw)
115 rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
119 fm10k_mbx_lock(struct fm10k_hw *hw)
121 while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
122 rte_delay_us(FM10K_MBXLOCK_DELAY_US);
126 fm10k_mbx_unlock(struct fm10k_hw *hw)
128 rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
131 /* Stubs needed for linkage when vPMD is disabled */
133 fm10k_rx_vec_condition_check(__rte_unused struct rte_eth_dev *dev)
140 __rte_unused void *rx_queue,
141 __rte_unused struct rte_mbuf **rx_pkts,
142 __rte_unused uint16_t nb_pkts)
148 fm10k_recv_scattered_pkts_vec(
149 __rte_unused void *rx_queue,
150 __rte_unused struct rte_mbuf **rx_pkts,
151 __rte_unused uint16_t nb_pkts)
157 fm10k_rxq_vec_setup(__rte_unused struct fm10k_rx_queue *rxq)
164 fm10k_rx_queue_release_mbufs_vec(
165 __rte_unused struct fm10k_rx_queue *rxq)
171 fm10k_txq_vec_setup(__rte_unused struct fm10k_tx_queue *txq)
177 fm10k_tx_vec_condition_check(__rte_unused struct fm10k_tx_queue *txq)
183 fm10k_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
184 __rte_unused struct rte_mbuf **tx_pkts,
185 __rte_unused uint16_t nb_pkts)
191 * reset queue to initial state, allocate software buffers used when starting
193 * return 0 on success
194 * return -ENOMEM if buffers cannot be allocated
195 * return -EINVAL if buffers do not satisfy alignment condition
198 rx_queue_reset(struct fm10k_rx_queue *q)
200 static const union fm10k_rx_desc zero = {{0} };
203 PMD_INIT_FUNC_TRACE();
205 diag = rte_mempool_get_bulk(q->mp, (void **)q->sw_ring, q->nb_desc);
209 for (i = 0; i < q->nb_desc; ++i) {
210 fm10k_pktmbuf_reset(q->sw_ring[i], q->port_id);
211 if (!fm10k_addr_alignment_valid(q->sw_ring[i])) {
212 rte_mempool_put_bulk(q->mp, (void **)q->sw_ring,
216 dma_addr = MBUF_DMA_ADDR_DEFAULT(q->sw_ring[i]);
217 q->hw_ring[i].q.pkt_addr = dma_addr;
218 q->hw_ring[i].q.hdr_addr = dma_addr;
221 /* initialize extra software ring entries. Space for these extra
222 * entries is always allocated.
224 memset(&q->fake_mbuf, 0x0, sizeof(q->fake_mbuf));
225 for (i = 0; i < q->nb_fake_desc; ++i) {
226 q->sw_ring[q->nb_desc + i] = &q->fake_mbuf;
227 q->hw_ring[q->nb_desc + i] = zero;
232 q->next_trigger = q->alloc_thresh - 1;
233 FM10K_PCI_REG_WRITE(q->tail_ptr, q->nb_desc - 1);
234 q->rxrearm_start = 0;
241 * clean queue, descriptor rings, free software buffers used when stopping
245 rx_queue_clean(struct fm10k_rx_queue *q)
247 union fm10k_rx_desc zero = {.q = {0, 0, 0, 0} };
249 PMD_INIT_FUNC_TRACE();
251 /* zero descriptor rings */
252 for (i = 0; i < q->nb_desc; ++i)
253 q->hw_ring[i] = zero;
255 /* zero faked descriptors */
256 for (i = 0; i < q->nb_fake_desc; ++i)
257 q->hw_ring[q->nb_desc + i] = zero;
259 /* vPMD driver has a different way of releasing mbufs. */
260 if (q->rx_using_sse) {
261 fm10k_rx_queue_release_mbufs_vec(q);
265 /* free software buffers */
266 for (i = 0; i < q->nb_desc; ++i) {
268 rte_pktmbuf_free_seg(q->sw_ring[i]);
269 q->sw_ring[i] = NULL;
275 * free all queue memory used when releasing the queue (i.e. configure)
278 rx_queue_free(struct fm10k_rx_queue *q)
280 PMD_INIT_FUNC_TRACE();
282 PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
285 rte_free(q->sw_ring);
294 * disable RX queue, wait unitl HW finished necessary flush operation
297 rx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
301 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
302 FM10K_WRITE_REG(hw, FM10K_RXQCTL(qnum),
303 reg & ~FM10K_RXQCTL_ENABLE);
305 /* Wait 100us at most */
306 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
308 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
309 if (!(reg & FM10K_RXQCTL_ENABLE))
313 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
320 * reset queue to initial state, allocate software buffers used when starting
324 tx_queue_reset(struct fm10k_tx_queue *q)
326 PMD_INIT_FUNC_TRACE();
330 q->nb_free = q->nb_desc - 1;
331 fifo_reset(&q->rs_tracker, (q->nb_desc + 1) / q->rs_thresh);
332 FM10K_PCI_REG_WRITE(q->tail_ptr, 0);
336 * clean queue, descriptor rings, free software buffers used when stopping
340 tx_queue_clean(struct fm10k_tx_queue *q)
342 struct fm10k_tx_desc zero = {0, 0, 0, 0, 0, 0};
344 PMD_INIT_FUNC_TRACE();
346 /* zero descriptor rings */
347 for (i = 0; i < q->nb_desc; ++i)
348 q->hw_ring[i] = zero;
350 /* free software buffers */
351 for (i = 0; i < q->nb_desc; ++i) {
353 rte_pktmbuf_free_seg(q->sw_ring[i]);
354 q->sw_ring[i] = NULL;
360 * free all queue memory used when releasing the queue (i.e. configure)
363 tx_queue_free(struct fm10k_tx_queue *q)
365 PMD_INIT_FUNC_TRACE();
367 PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
369 if (q->rs_tracker.list) {
370 rte_free(q->rs_tracker.list);
371 q->rs_tracker.list = NULL;
374 rte_free(q->sw_ring);
383 * disable TX queue, wait unitl HW finished necessary flush operation
386 tx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
390 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
391 FM10K_WRITE_REG(hw, FM10K_TXDCTL(qnum),
392 reg & ~FM10K_TXDCTL_ENABLE);
394 /* Wait 100us at most */
395 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
397 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
398 if (!(reg & FM10K_TXDCTL_ENABLE))
402 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
409 fm10k_check_mq_mode(struct rte_eth_dev *dev)
411 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
412 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
413 struct rte_eth_vmdq_rx_conf *vmdq_conf;
414 uint16_t nb_rx_q = dev->data->nb_rx_queues;
416 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
418 if (rx_mq_mode & ETH_MQ_RX_DCB_FLAG) {
419 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
423 if (!(rx_mq_mode & ETH_MQ_RX_VMDQ_FLAG))
426 if (hw->mac.type == fm10k_mac_vf) {
427 PMD_INIT_LOG(ERR, "VMDQ mode is not supported in VF.");
431 /* Check VMDQ queue pool number */
432 if (vmdq_conf->nb_queue_pools >
433 sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT ||
434 vmdq_conf->nb_queue_pools > nb_rx_q) {
435 PMD_INIT_LOG(ERR, "Too many of queue pools: %d",
436 vmdq_conf->nb_queue_pools);
443 static const struct fm10k_txq_ops def_txq_ops = {
444 .reset = tx_queue_reset,
448 fm10k_dev_configure(struct rte_eth_dev *dev)
452 PMD_INIT_FUNC_TRACE();
454 /* multipe queue mode checking */
455 ret = fm10k_check_mq_mode(dev);
457 PMD_DRV_LOG(ERR, "fm10k_check_mq_mode fails with %d.",
462 dev->data->scattered_rx = 0;
468 fm10k_dev_vmdq_rx_configure(struct rte_eth_dev *dev)
470 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
471 struct rte_eth_vmdq_rx_conf *vmdq_conf;
474 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
476 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
477 if (!vmdq_conf->pool_map[i].pools)
480 fm10k_update_vlan(hw, vmdq_conf->pool_map[i].vlan_id, 0, true);
481 fm10k_mbx_unlock(hw);
486 fm10k_dev_pf_main_vsi_reset(struct rte_eth_dev *dev)
488 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
490 /* Add default mac address */
491 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
492 MAIN_VSI_POOL_NUMBER);
496 fm10k_dev_rss_configure(struct rte_eth_dev *dev)
498 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
499 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
500 uint32_t mrqc, *key, i, reta, j;
503 #define RSS_KEY_SIZE 40
504 static uint8_t rss_intel_key[RSS_KEY_SIZE] = {
505 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
506 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
507 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
508 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
509 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
512 if (dev_conf->rxmode.mq_mode != ETH_MQ_RX_RSS ||
513 dev_conf->rx_adv_conf.rss_conf.rss_hf == 0) {
514 FM10K_WRITE_REG(hw, FM10K_MRQC(0), 0);
518 /* random key is rss_intel_key (default) or user provided (rss_key) */
519 if (dev_conf->rx_adv_conf.rss_conf.rss_key == NULL)
520 key = (uint32_t *)rss_intel_key;
522 key = (uint32_t *)dev_conf->rx_adv_conf.rss_conf.rss_key;
524 /* Now fill our hash function seeds, 4 bytes at a time */
525 for (i = 0; i < RSS_KEY_SIZE / sizeof(*key); ++i)
526 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
529 * Fill in redirection table
530 * The byte-swap is needed because NIC registers are in
531 * little-endian order.
534 for (i = 0, j = 0; i < FM10K_MAX_RSS_INDICES; i++, j++) {
535 if (j == dev->data->nb_rx_queues)
537 reta = (reta << CHAR_BIT) | j;
539 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2),
544 * Generate RSS hash based on packet types, TCP/UDP
545 * port numbers and/or IPv4/v6 src and dst addresses
547 hf = dev_conf->rx_adv_conf.rss_conf.rss_hf;
549 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
550 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
551 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
552 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
553 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
554 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
555 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
556 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
557 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
560 PMD_INIT_LOG(ERR, "Specified RSS mode 0x%"PRIx64"is not"
565 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
569 fm10k_dev_logic_port_update(struct rte_eth_dev *dev, uint16_t nb_lport_new)
571 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
574 for (i = 0; i < nb_lport_new; i++) {
575 /* Set unicast mode by default. App can change
576 * to other mode in other API func.
579 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map + i,
580 FM10K_XCAST_MODE_NONE);
581 fm10k_mbx_unlock(hw);
586 fm10k_dev_mq_rx_configure(struct rte_eth_dev *dev)
588 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
589 struct rte_eth_vmdq_rx_conf *vmdq_conf;
590 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
591 struct fm10k_macvlan_filter_info *macvlan;
592 uint16_t nb_queue_pools = 0; /* pool number in configuration */
593 uint16_t nb_lport_new;
595 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
596 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
598 fm10k_dev_rss_configure(dev);
600 /* only PF supports VMDQ */
601 if (hw->mac.type != fm10k_mac_pf)
604 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
605 nb_queue_pools = vmdq_conf->nb_queue_pools;
607 /* no pool number change, no need to update logic port and VLAN/MAC */
608 if (macvlan->nb_queue_pools == nb_queue_pools)
611 nb_lport_new = nb_queue_pools ? nb_queue_pools : 1;
612 fm10k_dev_logic_port_update(dev, nb_lport_new);
614 /* reset MAC/VLAN as it's based on VMDQ or PF main VSI */
615 memset(dev->data->mac_addrs, 0,
616 ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM);
617 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
618 &dev->data->mac_addrs[0]);
619 memset(macvlan, 0, sizeof(*macvlan));
620 macvlan->nb_queue_pools = nb_queue_pools;
623 fm10k_dev_vmdq_rx_configure(dev);
625 fm10k_dev_pf_main_vsi_reset(dev);
629 fm10k_dev_tx_init(struct rte_eth_dev *dev)
631 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
633 struct fm10k_tx_queue *txq;
637 /* Disable TXINT to avoid possible interrupt */
638 for (i = 0; i < hw->mac.max_queues; i++)
639 FM10K_WRITE_REG(hw, FM10K_TXINT(i),
640 3 << FM10K_TXINT_TIMER_SHIFT);
643 for (i = 0; i < dev->data->nb_tx_queues; ++i) {
644 txq = dev->data->tx_queues[i];
645 base_addr = txq->hw_ring_phys_addr;
646 size = txq->nb_desc * sizeof(struct fm10k_tx_desc);
648 /* disable queue to avoid issues while updating state */
649 ret = tx_queue_disable(hw, i);
651 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
654 /* Enable use of FTAG bit in TX descriptor, PFVTCTL
655 * register is read-only for VF.
657 if (fm10k_check_ftag(dev->device->devargs)) {
658 if (hw->mac.type == fm10k_mac_pf) {
659 FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
660 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
661 PMD_INIT_LOG(DEBUG, "FTAG mode is enabled");
663 PMD_INIT_LOG(ERR, "VF FTAG is not supported.");
668 /* set location and size for descriptor ring */
669 FM10K_WRITE_REG(hw, FM10K_TDBAL(i),
670 base_addr & UINT64_LOWER_32BITS_MASK);
671 FM10K_WRITE_REG(hw, FM10K_TDBAH(i),
672 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
673 FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
675 /* assign default SGLORT for each TX queue by PF */
676 if (hw->mac.type == fm10k_mac_pf)
677 FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
680 /* set up vector or scalar TX function as appropriate */
681 fm10k_set_tx_function(dev);
687 fm10k_dev_rx_init(struct rte_eth_dev *dev)
689 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
690 struct fm10k_macvlan_filter_info *macvlan;
691 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
692 struct rte_intr_handle *intr_handle = &pdev->intr_handle;
694 struct fm10k_rx_queue *rxq;
697 uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
698 uint32_t logic_port = hw->mac.dglort_map;
700 uint16_t queue_stride = 0;
702 /* enable RXINT for interrupt mode */
704 if (rte_intr_dp_is_en(intr_handle)) {
705 for (; i < dev->data->nb_rx_queues; i++) {
706 FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
707 if (hw->mac.type == fm10k_mac_pf)
708 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
710 FM10K_ITR_MASK_CLEAR);
712 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
714 FM10K_ITR_MASK_CLEAR);
717 /* Disable other RXINT to avoid possible interrupt */
718 for (; i < hw->mac.max_queues; i++)
719 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
720 3 << FM10K_RXINT_TIMER_SHIFT);
722 /* Setup RX queues */
723 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
724 rxq = dev->data->rx_queues[i];
725 base_addr = rxq->hw_ring_phys_addr;
726 size = rxq->nb_desc * sizeof(union fm10k_rx_desc);
728 /* disable queue to avoid issues while updating state */
729 ret = rx_queue_disable(hw, i);
731 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
735 /* Setup the Base and Length of the Rx Descriptor Ring */
736 FM10K_WRITE_REG(hw, FM10K_RDBAL(i),
737 base_addr & UINT64_LOWER_32BITS_MASK);
738 FM10K_WRITE_REG(hw, FM10K_RDBAH(i),
739 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
740 FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
742 /* Configure the Rx buffer size for one buff without split */
743 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
744 RTE_PKTMBUF_HEADROOM);
745 /* As RX buffer is aligned to 512B within mbuf, some bytes are
746 * reserved for this purpose, and the worst case could be 511B.
747 * But SRR reg assumes all buffers have the same size. In order
748 * to fill the gap, we'll have to consider the worst case and
749 * assume 512B is reserved. If we don't do so, it's possible
750 * for HW to overwrite data to next mbuf.
752 buf_size -= FM10K_RX_DATABUF_ALIGN;
754 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
755 (buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT) |
756 FM10K_SRRCTL_LOOPBACK_SUPPRESS);
758 /* It adds dual VLAN length for supporting dual VLAN */
759 if ((dev->data->dev_conf.rxmode.max_rx_pkt_len +
760 2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
761 rxq->offloads & DEV_RX_OFFLOAD_SCATTER) {
763 dev->data->scattered_rx = 1;
764 reg = FM10K_READ_REG(hw, FM10K_SRRCTL(i));
765 reg |= FM10K_SRRCTL_BUFFER_CHAINING_EN;
766 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), reg);
769 /* Enable drop on empty, it's RO for VF */
770 if (hw->mac.type == fm10k_mac_pf && rxq->drop_en)
771 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
773 FM10K_WRITE_REG(hw, FM10K_RXDCTL(i), rxdctl);
774 FM10K_WRITE_FLUSH(hw);
777 /* Configure VMDQ/RSS if applicable */
778 fm10k_dev_mq_rx_configure(dev);
780 /* Decide the best RX function */
781 fm10k_set_rx_function(dev);
783 /* update RX_SGLORT for loopback suppress*/
784 if (hw->mac.type != fm10k_mac_pf)
786 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
787 if (macvlan->nb_queue_pools)
788 queue_stride = dev->data->nb_rx_queues / macvlan->nb_queue_pools;
789 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
790 if (i && queue_stride && !(i % queue_stride))
792 FM10K_WRITE_REG(hw, FM10K_RX_SGLORT(i), logic_port);
799 fm10k_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
801 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
804 struct fm10k_rx_queue *rxq;
806 PMD_INIT_FUNC_TRACE();
808 rxq = dev->data->rx_queues[rx_queue_id];
809 err = rx_queue_reset(rxq);
810 if (err == -ENOMEM) {
811 PMD_INIT_LOG(ERR, "Failed to alloc memory : %d", err);
813 } else if (err == -EINVAL) {
814 PMD_INIT_LOG(ERR, "Invalid buffer address alignment :"
819 /* Setup the HW Rx Head and Tail Descriptor Pointers
820 * Note: this must be done AFTER the queue is enabled on real
821 * hardware, but BEFORE the queue is enabled when using the
822 * emulation platform. Do it in both places for now and remove
823 * this comment and the following two register writes when the
824 * emulation platform is no longer being used.
826 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
827 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
829 /* Set PF ownership flag for PF devices */
830 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(rx_queue_id));
831 if (hw->mac.type == fm10k_mac_pf)
832 reg |= FM10K_RXQCTL_PF;
833 reg |= FM10K_RXQCTL_ENABLE;
834 /* enable RX queue */
835 FM10K_WRITE_REG(hw, FM10K_RXQCTL(rx_queue_id), reg);
836 FM10K_WRITE_FLUSH(hw);
838 /* Setup the HW Rx Head and Tail Descriptor Pointers
839 * Note: this must be done AFTER the queue is enabled
841 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
842 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
843 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
849 fm10k_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
851 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
853 PMD_INIT_FUNC_TRACE();
855 /* Disable RX queue */
856 rx_queue_disable(hw, rx_queue_id);
858 /* Free mbuf and clean HW ring */
859 rx_queue_clean(dev->data->rx_queues[rx_queue_id]);
860 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
866 fm10k_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
868 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
869 /** @todo - this should be defined in the shared code */
870 #define FM10K_TXDCTL_WRITE_BACK_MIN_DELAY 0x00010000
871 uint32_t txdctl = FM10K_TXDCTL_WRITE_BACK_MIN_DELAY;
872 struct fm10k_tx_queue *q = dev->data->tx_queues[tx_queue_id];
874 PMD_INIT_FUNC_TRACE();
878 /* reset head and tail pointers */
879 FM10K_WRITE_REG(hw, FM10K_TDH(tx_queue_id), 0);
880 FM10K_WRITE_REG(hw, FM10K_TDT(tx_queue_id), 0);
882 /* enable TX queue */
883 FM10K_WRITE_REG(hw, FM10K_TXDCTL(tx_queue_id),
884 FM10K_TXDCTL_ENABLE | txdctl);
885 FM10K_WRITE_FLUSH(hw);
886 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
892 fm10k_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
894 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
896 PMD_INIT_FUNC_TRACE();
898 tx_queue_disable(hw, tx_queue_id);
899 tx_queue_clean(dev->data->tx_queues[tx_queue_id]);
900 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
905 static inline int fm10k_glort_valid(struct fm10k_hw *hw)
907 return ((hw->mac.dglort_map & FM10K_DGLORTMAP_NONE)
908 != FM10K_DGLORTMAP_NONE);
912 fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev)
914 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
917 PMD_INIT_FUNC_TRACE();
919 /* Return if it didn't acquire valid glort range */
920 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
924 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
925 FM10K_XCAST_MODE_PROMISC);
926 fm10k_mbx_unlock(hw);
928 if (status != FM10K_SUCCESS)
929 PMD_INIT_LOG(ERR, "Failed to enable promiscuous mode");
933 fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev)
935 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
939 PMD_INIT_FUNC_TRACE();
941 /* Return if it didn't acquire valid glort range */
942 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
945 if (dev->data->all_multicast == 1)
946 mode = FM10K_XCAST_MODE_ALLMULTI;
948 mode = FM10K_XCAST_MODE_NONE;
951 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
953 fm10k_mbx_unlock(hw);
955 if (status != FM10K_SUCCESS)
956 PMD_INIT_LOG(ERR, "Failed to disable promiscuous mode");
960 fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev)
962 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
965 PMD_INIT_FUNC_TRACE();
967 /* Return if it didn't acquire valid glort range */
968 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
971 /* If promiscuous mode is enabled, it doesn't make sense to enable
972 * allmulticast and disable promiscuous since fm10k only can select
975 if (dev->data->promiscuous) {
976 PMD_INIT_LOG(INFO, "Promiscuous mode is enabled, "\
977 "needn't enable allmulticast");
982 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
983 FM10K_XCAST_MODE_ALLMULTI);
984 fm10k_mbx_unlock(hw);
986 if (status != FM10K_SUCCESS)
987 PMD_INIT_LOG(ERR, "Failed to enable allmulticast mode");
991 fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev)
993 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
996 PMD_INIT_FUNC_TRACE();
998 /* Return if it didn't acquire valid glort range */
999 if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
1002 if (dev->data->promiscuous) {
1003 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode "\
1004 "since promisc mode is enabled");
1009 /* Change mode to unicast mode */
1010 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
1011 FM10K_XCAST_MODE_NONE);
1012 fm10k_mbx_unlock(hw);
1014 if (status != FM10K_SUCCESS)
1015 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode");
1019 fm10k_dev_dglort_map_configure(struct rte_eth_dev *dev)
1021 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1022 uint32_t dglortdec, pool_len, rss_len, i, dglortmask;
1023 uint16_t nb_queue_pools;
1024 struct fm10k_macvlan_filter_info *macvlan;
1026 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1027 nb_queue_pools = macvlan->nb_queue_pools;
1028 pool_len = nb_queue_pools ? rte_fls_u32(nb_queue_pools - 1) : 0;
1029 rss_len = rte_fls_u32(dev->data->nb_rx_queues - 1) - pool_len;
1031 /* GLORT 0x0-0x3F are used by PF and VMDQ, 0x40-0x7F used by FD */
1032 dglortdec = (rss_len << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) | pool_len;
1033 dglortmask = (GLORT_PF_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1035 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(0), dglortmask);
1036 /* Configure VMDQ/RSS DGlort Decoder */
1037 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(0), dglortdec);
1039 /* Flow Director configurations, only queue number is valid. */
1040 dglortdec = rte_fls_u32(dev->data->nb_rx_queues - 1);
1041 dglortmask = (GLORT_FD_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1042 (hw->mac.dglort_map + GLORT_FD_Q_BASE);
1043 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(1), dglortmask);
1044 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(1), dglortdec);
1046 /* Invalidate all other GLORT entries */
1047 for (i = 2; i < FM10K_DGLORT_COUNT; i++)
1048 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i),
1049 FM10K_DGLORTMAP_NONE);
1052 #define BSIZEPKT_ROUNDUP ((1 << FM10K_SRRCTL_BSIZEPKT_SHIFT) - 1)
1054 fm10k_dev_start(struct rte_eth_dev *dev)
1056 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1059 PMD_INIT_FUNC_TRACE();
1061 /* stop, init, then start the hw */
1062 diag = fm10k_stop_hw(hw);
1063 if (diag != FM10K_SUCCESS) {
1064 PMD_INIT_LOG(ERR, "Hardware stop failed: %d", diag);
1068 diag = fm10k_init_hw(hw);
1069 if (diag != FM10K_SUCCESS) {
1070 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
1074 diag = fm10k_start_hw(hw);
1075 if (diag != FM10K_SUCCESS) {
1076 PMD_INIT_LOG(ERR, "Hardware start failed: %d", diag);
1080 diag = fm10k_dev_tx_init(dev);
1082 PMD_INIT_LOG(ERR, "TX init failed: %d", diag);
1086 if (fm10k_dev_rxq_interrupt_setup(dev))
1089 diag = fm10k_dev_rx_init(dev);
1091 PMD_INIT_LOG(ERR, "RX init failed: %d", diag);
1095 if (hw->mac.type == fm10k_mac_pf)
1096 fm10k_dev_dglort_map_configure(dev);
1098 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1099 struct fm10k_rx_queue *rxq;
1100 rxq = dev->data->rx_queues[i];
1102 if (rxq->rx_deferred_start)
1104 diag = fm10k_dev_rx_queue_start(dev, i);
1107 for (j = 0; j < i; ++j)
1108 rx_queue_clean(dev->data->rx_queues[j]);
1113 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1114 struct fm10k_tx_queue *txq;
1115 txq = dev->data->tx_queues[i];
1117 if (txq->tx_deferred_start)
1119 diag = fm10k_dev_tx_queue_start(dev, i);
1122 for (j = 0; j < i; ++j)
1123 tx_queue_clean(dev->data->tx_queues[j]);
1124 for (j = 0; j < dev->data->nb_rx_queues; ++j)
1125 rx_queue_clean(dev->data->rx_queues[j]);
1130 /* Update default vlan when not in VMDQ mode */
1131 if (!(dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG))
1132 fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
1134 fm10k_link_update(dev, 0);
1140 fm10k_dev_stop(struct rte_eth_dev *dev)
1142 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1143 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
1144 struct rte_intr_handle *intr_handle = &pdev->intr_handle;
1147 PMD_INIT_FUNC_TRACE();
1149 if (dev->data->tx_queues)
1150 for (i = 0; i < dev->data->nb_tx_queues; i++)
1151 fm10k_dev_tx_queue_stop(dev, i);
1153 if (dev->data->rx_queues)
1154 for (i = 0; i < dev->data->nb_rx_queues; i++)
1155 fm10k_dev_rx_queue_stop(dev, i);
1157 /* Disable datapath event */
1158 if (rte_intr_dp_is_en(intr_handle)) {
1159 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1160 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
1161 3 << FM10K_RXINT_TIMER_SHIFT);
1162 if (hw->mac.type == fm10k_mac_pf)
1163 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
1164 FM10K_ITR_MASK_SET);
1166 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
1167 FM10K_ITR_MASK_SET);
1170 /* Clean datapath event and queue/vec mapping */
1171 rte_intr_efd_disable(intr_handle);
1172 rte_free(intr_handle->intr_vec);
1173 intr_handle->intr_vec = NULL;
1177 fm10k_dev_queue_release(struct rte_eth_dev *dev)
1181 PMD_INIT_FUNC_TRACE();
1183 if (dev->data->tx_queues) {
1184 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1185 struct fm10k_tx_queue *txq = dev->data->tx_queues[i];
1191 if (dev->data->rx_queues) {
1192 for (i = 0; i < dev->data->nb_rx_queues; i++)
1193 fm10k_rx_queue_release(dev->data->rx_queues[i]);
1198 fm10k_dev_close(struct rte_eth_dev *dev)
1200 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1202 PMD_INIT_FUNC_TRACE();
1205 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
1206 MAX_LPORT_NUM, false);
1207 fm10k_mbx_unlock(hw);
1209 /* allow 100ms for device to quiesce */
1210 rte_delay_us(FM10K_SWITCH_QUIESCE_US);
1212 /* Stop mailbox service first */
1213 fm10k_close_mbx_service(hw);
1214 fm10k_dev_stop(dev);
1215 fm10k_dev_queue_release(dev);
1220 fm10k_link_update(struct rte_eth_dev *dev,
1221 __rte_unused int wait_to_complete)
1223 struct fm10k_dev_info *dev_info =
1224 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
1225 PMD_INIT_FUNC_TRACE();
1227 dev->data->dev_link.link_speed = ETH_SPEED_NUM_50G;
1228 dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
1229 dev->data->dev_link.link_status =
1230 dev_info->sm_down ? ETH_LINK_DOWN : ETH_LINK_UP;
1231 dev->data->dev_link.link_autoneg = ETH_LINK_FIXED;
1236 static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1237 struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
1242 if (xstats_names != NULL) {
1243 /* Note: limit checked in rte_eth_xstats_names() */
1246 for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1247 snprintf(xstats_names[count].name,
1248 sizeof(xstats_names[count].name),
1249 "%s", fm10k_hw_stats_strings[count].name);
1253 /* PF queue stats */
1254 for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1255 for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1256 snprintf(xstats_names[count].name,
1257 sizeof(xstats_names[count].name),
1259 fm10k_hw_stats_rx_q_strings[i].name);
1262 for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1263 snprintf(xstats_names[count].name,
1264 sizeof(xstats_names[count].name),
1266 fm10k_hw_stats_tx_q_strings[i].name);
1271 return FM10K_NB_XSTATS;
1275 fm10k_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1278 struct fm10k_hw_stats *hw_stats =
1279 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1280 unsigned i, q, count = 0;
1282 if (n < FM10K_NB_XSTATS)
1283 return FM10K_NB_XSTATS;
1286 for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1287 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
1288 fm10k_hw_stats_strings[count].offset);
1289 xstats[count].id = count;
1293 /* PF queue stats */
1294 for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1295 for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1296 xstats[count].value =
1297 *(uint64_t *)(((char *)&hw_stats->q[q]) +
1298 fm10k_hw_stats_rx_q_strings[i].offset);
1299 xstats[count].id = count;
1302 for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1303 xstats[count].value =
1304 *(uint64_t *)(((char *)&hw_stats->q[q]) +
1305 fm10k_hw_stats_tx_q_strings[i].offset);
1306 xstats[count].id = count;
1311 return FM10K_NB_XSTATS;
1315 fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1317 uint64_t ipackets, opackets, ibytes, obytes, imissed;
1318 struct fm10k_hw *hw =
1319 FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1320 struct fm10k_hw_stats *hw_stats =
1321 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1324 PMD_INIT_FUNC_TRACE();
1326 fm10k_update_hw_stats(hw, hw_stats);
1328 ipackets = opackets = ibytes = obytes = imissed = 0;
1329 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1330 (i < hw->mac.max_queues); ++i) {
1331 stats->q_ipackets[i] = hw_stats->q[i].rx_packets.count;
1332 stats->q_opackets[i] = hw_stats->q[i].tx_packets.count;
1333 stats->q_ibytes[i] = hw_stats->q[i].rx_bytes.count;
1334 stats->q_obytes[i] = hw_stats->q[i].tx_bytes.count;
1335 stats->q_errors[i] = hw_stats->q[i].rx_drops.count;
1336 ipackets += stats->q_ipackets[i];
1337 opackets += stats->q_opackets[i];
1338 ibytes += stats->q_ibytes[i];
1339 obytes += stats->q_obytes[i];
1340 imissed += stats->q_errors[i];
1342 stats->ipackets = ipackets;
1343 stats->opackets = opackets;
1344 stats->ibytes = ibytes;
1345 stats->obytes = obytes;
1346 stats->imissed = imissed;
1351 fm10k_stats_reset(struct rte_eth_dev *dev)
1353 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1354 struct fm10k_hw_stats *hw_stats =
1355 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1357 PMD_INIT_FUNC_TRACE();
1359 memset(hw_stats, 0, sizeof(*hw_stats));
1360 fm10k_rebind_hw_stats(hw, hw_stats);
1364 fm10k_dev_infos_get(struct rte_eth_dev *dev,
1365 struct rte_eth_dev_info *dev_info)
1367 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1368 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
1370 PMD_INIT_FUNC_TRACE();
1372 dev_info->min_rx_bufsize = FM10K_MIN_RX_BUF_SIZE;
1373 dev_info->max_rx_pktlen = FM10K_MAX_PKT_SIZE;
1374 dev_info->max_rx_queues = hw->mac.max_queues;
1375 dev_info->max_tx_queues = hw->mac.max_queues;
1376 dev_info->max_mac_addrs = FM10K_MAX_MACADDR_NUM;
1377 dev_info->max_hash_mac_addrs = 0;
1378 dev_info->max_vfs = pdev->max_vfs;
1379 dev_info->vmdq_pool_base = 0;
1380 dev_info->vmdq_queue_base = 0;
1381 dev_info->max_vmdq_pools = ETH_32_POOLS;
1382 dev_info->vmdq_queue_num = FM10K_MAX_QUEUES_PF;
1383 dev_info->rx_queue_offload_capa = fm10k_get_rx_queue_offloads_capa(dev);
1384 dev_info->rx_offload_capa = fm10k_get_rx_port_offloads_capa(dev) |
1385 dev_info->rx_queue_offload_capa;
1386 dev_info->tx_queue_offload_capa = fm10k_get_tx_queue_offloads_capa(dev);
1387 dev_info->tx_offload_capa = fm10k_get_tx_port_offloads_capa(dev) |
1388 dev_info->tx_queue_offload_capa;
1390 dev_info->hash_key_size = FM10K_RSSRK_SIZE * sizeof(uint32_t);
1391 dev_info->reta_size = FM10K_MAX_RSS_INDICES;
1393 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1395 .pthresh = FM10K_DEFAULT_RX_PTHRESH,
1396 .hthresh = FM10K_DEFAULT_RX_HTHRESH,
1397 .wthresh = FM10K_DEFAULT_RX_WTHRESH,
1399 .rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(0),
1404 dev_info->default_txconf = (struct rte_eth_txconf) {
1406 .pthresh = FM10K_DEFAULT_TX_PTHRESH,
1407 .hthresh = FM10K_DEFAULT_TX_HTHRESH,
1408 .wthresh = FM10K_DEFAULT_TX_WTHRESH,
1410 .tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(0),
1411 .tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(0),
1415 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1416 .nb_max = FM10K_MAX_RX_DESC,
1417 .nb_min = FM10K_MIN_RX_DESC,
1418 .nb_align = FM10K_MULT_RX_DESC,
1421 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1422 .nb_max = FM10K_MAX_TX_DESC,
1423 .nb_min = FM10K_MIN_TX_DESC,
1424 .nb_align = FM10K_MULT_TX_DESC,
1425 .nb_seg_max = FM10K_TX_MAX_SEG,
1426 .nb_mtu_seg_max = FM10K_TX_MAX_MTU_SEG,
1429 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_2_5G |
1430 ETH_LINK_SPEED_10G | ETH_LINK_SPEED_25G |
1431 ETH_LINK_SPEED_40G | ETH_LINK_SPEED_100G;
1434 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
1435 static const uint32_t *
1436 fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1438 if (dev->rx_pkt_burst == fm10k_recv_pkts ||
1439 dev->rx_pkt_burst == fm10k_recv_scattered_pkts) {
1440 static uint32_t ptypes[] = {
1441 /* refers to rx_desc_to_ol_flags() */
1444 RTE_PTYPE_L3_IPV4_EXT,
1446 RTE_PTYPE_L3_IPV6_EXT,
1453 } else if (dev->rx_pkt_burst == fm10k_recv_pkts_vec ||
1454 dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec) {
1455 static uint32_t ptypes_vec[] = {
1456 /* refers to fm10k_desc_to_pktype_v() */
1458 RTE_PTYPE_L3_IPV4_EXT,
1460 RTE_PTYPE_L3_IPV6_EXT,
1463 RTE_PTYPE_TUNNEL_GENEVE,
1464 RTE_PTYPE_TUNNEL_NVGRE,
1465 RTE_PTYPE_TUNNEL_VXLAN,
1466 RTE_PTYPE_TUNNEL_GRE,
1476 static const uint32_t *
1477 fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused)
1484 fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1487 uint16_t mac_num = 0;
1488 uint32_t vid_idx, vid_bit, mac_index;
1489 struct fm10k_hw *hw;
1490 struct fm10k_macvlan_filter_info *macvlan;
1491 struct rte_eth_dev_data *data = dev->data;
1493 hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1494 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1496 if (macvlan->nb_queue_pools > 0) { /* VMDQ mode */
1497 PMD_INIT_LOG(ERR, "Cannot change VLAN filter in VMDQ mode");
1501 if (vlan_id > ETH_VLAN_ID_MAX) {
1502 PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");
1506 vid_idx = FM10K_VFTA_IDX(vlan_id);
1507 vid_bit = FM10K_VFTA_BIT(vlan_id);
1508 /* this VLAN ID is already in the VLAN filter table, return SUCCESS */
1509 if (on && (macvlan->vfta[vid_idx] & vid_bit))
1511 /* this VLAN ID is NOT in the VLAN filter table, cannot remove */
1512 if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {
1513 PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "
1514 "in the VLAN filter table");
1519 result = fm10k_update_vlan(hw, vlan_id, 0, on);
1520 fm10k_mbx_unlock(hw);
1521 if (result != FM10K_SUCCESS) {
1522 PMD_INIT_LOG(ERR, "VLAN update failed: %d", result);
1526 for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) &&
1527 (result == FM10K_SUCCESS); mac_index++) {
1528 if (is_zero_ether_addr(&data->mac_addrs[mac_index]))
1530 if (mac_num > macvlan->mac_num - 1) {
1531 PMD_INIT_LOG(ERR, "MAC address number "
1536 result = fm10k_update_uc_addr(hw, hw->mac.dglort_map,
1537 data->mac_addrs[mac_index].addr_bytes,
1539 fm10k_mbx_unlock(hw);
1542 if (result != FM10K_SUCCESS) {
1543 PMD_INIT_LOG(ERR, "MAC address update failed: %d", result);
1548 macvlan->vlan_num++;
1549 macvlan->vfta[vid_idx] |= vid_bit;
1551 macvlan->vlan_num--;
1552 macvlan->vfta[vid_idx] &= ~vid_bit;
1558 fm10k_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1560 if (mask & ETH_VLAN_STRIP_MASK) {
1561 if (!(dev->data->dev_conf.rxmode.offloads &
1562 DEV_RX_OFFLOAD_VLAN_STRIP))
1563 PMD_INIT_LOG(ERR, "VLAN stripping is "
1564 "always on in fm10k");
1567 if (mask & ETH_VLAN_EXTEND_MASK) {
1568 if (dev->data->dev_conf.rxmode.offloads &
1569 DEV_RX_OFFLOAD_VLAN_EXTEND)
1570 PMD_INIT_LOG(ERR, "VLAN QinQ is not "
1571 "supported in fm10k");
1574 if (mask & ETH_VLAN_FILTER_MASK) {
1575 if (!(dev->data->dev_conf.rxmode.offloads &
1576 DEV_RX_OFFLOAD_VLAN_FILTER))
1577 PMD_INIT_LOG(ERR, "VLAN filter is always on in fm10k");
1583 /* Add/Remove a MAC address, and update filters to main VSI */
1584 static void fm10k_MAC_filter_set_main_vsi(struct rte_eth_dev *dev,
1585 const u8 *mac, bool add, uint32_t pool)
1587 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1588 struct fm10k_macvlan_filter_info *macvlan;
1591 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1593 if (pool != MAIN_VSI_POOL_NUMBER) {
1594 PMD_DRV_LOG(ERR, "VMDQ not enabled, can't set "
1595 "mac to pool %u", pool);
1598 for (i = 0, j = 0; j < FM10K_VFTA_SIZE; j++) {
1599 if (!macvlan->vfta[j])
1601 for (k = 0; k < FM10K_UINT32_BIT_SIZE; k++) {
1602 if (!(macvlan->vfta[j] & (1 << k)))
1604 if (i + 1 > macvlan->vlan_num) {
1605 PMD_INIT_LOG(ERR, "vlan number not match");
1609 fm10k_update_uc_addr(hw, hw->mac.dglort_map, mac,
1610 j * FM10K_UINT32_BIT_SIZE + k, add, 0);
1611 fm10k_mbx_unlock(hw);
1617 /* Add/Remove a MAC address, and update filters to VMDQ */
1618 static void fm10k_MAC_filter_set_vmdq(struct rte_eth_dev *dev,
1619 const u8 *mac, bool add, uint32_t pool)
1621 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1622 struct fm10k_macvlan_filter_info *macvlan;
1623 struct rte_eth_vmdq_rx_conf *vmdq_conf;
1626 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1627 vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
1629 if (pool > macvlan->nb_queue_pools) {
1630 PMD_DRV_LOG(ERR, "Pool number %u invalid."
1632 pool, macvlan->nb_queue_pools);
1635 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
1636 if (!(vmdq_conf->pool_map[i].pools & (1UL << pool)))
1639 fm10k_update_uc_addr(hw, hw->mac.dglort_map + pool, mac,
1640 vmdq_conf->pool_map[i].vlan_id, add, 0);
1641 fm10k_mbx_unlock(hw);
1645 /* Add/Remove a MAC address, and update filters */
1646 static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
1647 const u8 *mac, bool add, uint32_t pool)
1649 struct fm10k_macvlan_filter_info *macvlan;
1651 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1653 if (macvlan->nb_queue_pools > 0) /* VMDQ mode */
1654 fm10k_MAC_filter_set_vmdq(dev, mac, add, pool);
1656 fm10k_MAC_filter_set_main_vsi(dev, mac, add, pool);
1664 /* Add a MAC address, and update filters */
1666 fm10k_macaddr_add(struct rte_eth_dev *dev,
1667 struct ether_addr *mac_addr,
1671 struct fm10k_macvlan_filter_info *macvlan;
1673 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1674 fm10k_MAC_filter_set(dev, mac_addr->addr_bytes, TRUE, pool);
1675 macvlan->mac_vmdq_id[index] = pool;
1679 /* Remove a MAC address, and update filters */
1681 fm10k_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
1683 struct rte_eth_dev_data *data = dev->data;
1684 struct fm10k_macvlan_filter_info *macvlan;
1686 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1687 fm10k_MAC_filter_set(dev, data->mac_addrs[index].addr_bytes,
1688 FALSE, macvlan->mac_vmdq_id[index]);
1689 macvlan->mac_vmdq_id[index] = 0;
1693 check_nb_desc(uint16_t min, uint16_t max, uint16_t mult, uint16_t request)
1695 if ((request < min) || (request > max) || ((request % mult) != 0))
1703 check_thresh(uint16_t min, uint16_t max, uint16_t div, uint16_t request)
1705 if ((request < min) || (request > max) || ((div % request) != 0))
1712 handle_rxconf(struct fm10k_rx_queue *q, const struct rte_eth_rxconf *conf)
1714 uint16_t rx_free_thresh;
1716 if (conf->rx_free_thresh == 0)
1717 rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(q);
1719 rx_free_thresh = conf->rx_free_thresh;
1721 /* make sure the requested threshold satisfies the constraints */
1722 if (check_thresh(FM10K_RX_FREE_THRESH_MIN(q),
1723 FM10K_RX_FREE_THRESH_MAX(q),
1724 FM10K_RX_FREE_THRESH_DIV(q),
1726 PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be "
1727 "less than or equal to %u, "
1728 "greater than or equal to %u, "
1729 "and a divisor of %u",
1730 rx_free_thresh, FM10K_RX_FREE_THRESH_MAX(q),
1731 FM10K_RX_FREE_THRESH_MIN(q),
1732 FM10K_RX_FREE_THRESH_DIV(q));
1736 q->alloc_thresh = rx_free_thresh;
1737 q->drop_en = conf->rx_drop_en;
1738 q->rx_deferred_start = conf->rx_deferred_start;
1744 * Hardware requires specific alignment for Rx packet buffers. At
1745 * least one of the following two conditions must be satisfied.
1746 * 1. Address is 512B aligned
1747 * 2. Address is 8B aligned and buffer does not cross 4K boundary.
1749 * As such, the driver may need to adjust the DMA address within the
1750 * buffer by up to 512B.
1752 * return 1 if the element size is valid, otherwise return 0.
1755 mempool_element_size_valid(struct rte_mempool *mp)
1759 /* elt_size includes mbuf header and headroom */
1760 min_size = mp->elt_size - sizeof(struct rte_mbuf) -
1761 RTE_PKTMBUF_HEADROOM;
1763 /* account for up to 512B of alignment */
1764 min_size -= FM10K_RX_DATABUF_ALIGN;
1766 /* sanity check for overflow */
1767 if (min_size > mp->elt_size)
1774 static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
1778 return (uint64_t)(DEV_RX_OFFLOAD_SCATTER);
1781 static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
1785 return (uint64_t)(DEV_RX_OFFLOAD_VLAN_STRIP |
1786 DEV_RX_OFFLOAD_VLAN_FILTER |
1787 DEV_RX_OFFLOAD_IPV4_CKSUM |
1788 DEV_RX_OFFLOAD_UDP_CKSUM |
1789 DEV_RX_OFFLOAD_TCP_CKSUM |
1790 DEV_RX_OFFLOAD_JUMBO_FRAME |
1791 DEV_RX_OFFLOAD_HEADER_SPLIT);
1795 fm10k_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1796 uint16_t nb_desc, unsigned int socket_id,
1797 const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
1799 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1800 struct fm10k_dev_info *dev_info =
1801 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
1802 struct fm10k_rx_queue *q;
1803 const struct rte_memzone *mz;
1806 PMD_INIT_FUNC_TRACE();
1808 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1810 /* make sure the mempool element size can account for alignment. */
1811 if (!mempool_element_size_valid(mp)) {
1812 PMD_INIT_LOG(ERR, "Error : Mempool element size is too small");
1816 /* make sure a valid number of descriptors have been requested */
1817 if (check_nb_desc(FM10K_MIN_RX_DESC, FM10K_MAX_RX_DESC,
1818 FM10K_MULT_RX_DESC, nb_desc)) {
1819 PMD_INIT_LOG(ERR, "Number of Rx descriptors (%u) must be "
1820 "less than or equal to %"PRIu32", "
1821 "greater than or equal to %u, "
1822 "and a multiple of %u",
1823 nb_desc, (uint32_t)FM10K_MAX_RX_DESC, FM10K_MIN_RX_DESC,
1824 FM10K_MULT_RX_DESC);
1829 * if this queue existed already, free the associated memory. The
1830 * queue cannot be reused in case we need to allocate memory on
1831 * different socket than was previously used.
1833 if (dev->data->rx_queues[queue_id] != NULL) {
1834 rx_queue_free(dev->data->rx_queues[queue_id]);
1835 dev->data->rx_queues[queue_id] = NULL;
1838 /* allocate memory for the queue structure */
1839 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1842 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
1848 q->nb_desc = nb_desc;
1849 q->nb_fake_desc = FM10K_MULT_RX_DESC;
1850 q->port_id = dev->data->port_id;
1851 q->queue_id = queue_id;
1852 q->tail_ptr = (volatile uint32_t *)
1853 &((uint32_t *)hw->hw_addr)[FM10K_RDT(queue_id)];
1854 q->offloads = offloads;
1855 if (handle_rxconf(q, conf))
1858 /* allocate memory for the software ring */
1859 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
1860 (nb_desc + q->nb_fake_desc) * sizeof(struct rte_mbuf *),
1861 RTE_CACHE_LINE_SIZE, socket_id);
1862 if (q->sw_ring == NULL) {
1863 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
1869 * allocate memory for the hardware descriptor ring. A memzone large
1870 * enough to hold the maximum ring size is requested to allow for
1871 * resizing in later calls to the queue setup function.
1873 mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
1874 FM10K_MAX_RX_RING_SZ, FM10K_ALIGN_RX_DESC,
1877 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
1878 rte_free(q->sw_ring);
1882 q->hw_ring = mz->addr;
1883 q->hw_ring_phys_addr = mz->iova;
1885 /* Check if number of descs satisfied Vector requirement */
1886 if (!rte_is_power_of_2(nb_desc)) {
1887 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
1888 "preconditions - canceling the feature for "
1889 "the whole port[%d]",
1890 q->queue_id, q->port_id);
1891 dev_info->rx_vec_allowed = false;
1893 fm10k_rxq_vec_setup(q);
1895 dev->data->rx_queues[queue_id] = q;
1900 fm10k_rx_queue_release(void *queue)
1902 PMD_INIT_FUNC_TRACE();
1904 rx_queue_free(queue);
1908 handle_txconf(struct fm10k_tx_queue *q, const struct rte_eth_txconf *conf)
1910 uint16_t tx_free_thresh;
1911 uint16_t tx_rs_thresh;
1913 /* constraint MACROs require that tx_free_thresh is configured
1914 * before tx_rs_thresh */
1915 if (conf->tx_free_thresh == 0)
1916 tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(q);
1918 tx_free_thresh = conf->tx_free_thresh;
1920 /* make sure the requested threshold satisfies the constraints */
1921 if (check_thresh(FM10K_TX_FREE_THRESH_MIN(q),
1922 FM10K_TX_FREE_THRESH_MAX(q),
1923 FM10K_TX_FREE_THRESH_DIV(q),
1925 PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be "
1926 "less than or equal to %u, "
1927 "greater than or equal to %u, "
1928 "and a divisor of %u",
1929 tx_free_thresh, FM10K_TX_FREE_THRESH_MAX(q),
1930 FM10K_TX_FREE_THRESH_MIN(q),
1931 FM10K_TX_FREE_THRESH_DIV(q));
1935 q->free_thresh = tx_free_thresh;
1937 if (conf->tx_rs_thresh == 0)
1938 tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(q);
1940 tx_rs_thresh = conf->tx_rs_thresh;
1942 q->tx_deferred_start = conf->tx_deferred_start;
1944 /* make sure the requested threshold satisfies the constraints */
1945 if (check_thresh(FM10K_TX_RS_THRESH_MIN(q),
1946 FM10K_TX_RS_THRESH_MAX(q),
1947 FM10K_TX_RS_THRESH_DIV(q),
1949 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be "
1950 "less than or equal to %u, "
1951 "greater than or equal to %u, "
1952 "and a divisor of %u",
1953 tx_rs_thresh, FM10K_TX_RS_THRESH_MAX(q),
1954 FM10K_TX_RS_THRESH_MIN(q),
1955 FM10K_TX_RS_THRESH_DIV(q));
1959 q->rs_thresh = tx_rs_thresh;
1964 static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
1971 static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
1975 return (uint64_t)(DEV_TX_OFFLOAD_VLAN_INSERT |
1976 DEV_TX_OFFLOAD_MULTI_SEGS |
1977 DEV_TX_OFFLOAD_IPV4_CKSUM |
1978 DEV_TX_OFFLOAD_UDP_CKSUM |
1979 DEV_TX_OFFLOAD_TCP_CKSUM |
1980 DEV_TX_OFFLOAD_TCP_TSO);
1984 fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1985 uint16_t nb_desc, unsigned int socket_id,
1986 const struct rte_eth_txconf *conf)
1988 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1989 struct fm10k_tx_queue *q;
1990 const struct rte_memzone *mz;
1993 PMD_INIT_FUNC_TRACE();
1995 offloads = conf->offloads | dev->data->dev_conf.txmode.offloads;
1997 /* make sure a valid number of descriptors have been requested */
1998 if (check_nb_desc(FM10K_MIN_TX_DESC, FM10K_MAX_TX_DESC,
1999 FM10K_MULT_TX_DESC, nb_desc)) {
2000 PMD_INIT_LOG(ERR, "Number of Tx descriptors (%u) must be "
2001 "less than or equal to %"PRIu32", "
2002 "greater than or equal to %u, "
2003 "and a multiple of %u",
2004 nb_desc, (uint32_t)FM10K_MAX_TX_DESC, FM10K_MIN_TX_DESC,
2005 FM10K_MULT_TX_DESC);
2010 * if this queue existed already, free the associated memory. The
2011 * queue cannot be reused in case we need to allocate memory on
2012 * different socket than was previously used.
2014 if (dev->data->tx_queues[queue_id] != NULL) {
2015 struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id];
2018 dev->data->tx_queues[queue_id] = NULL;
2021 /* allocate memory for the queue structure */
2022 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
2025 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
2030 q->nb_desc = nb_desc;
2031 q->port_id = dev->data->port_id;
2032 q->queue_id = queue_id;
2033 q->offloads = offloads;
2034 q->ops = &def_txq_ops;
2035 q->tail_ptr = (volatile uint32_t *)
2036 &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
2037 if (handle_txconf(q, conf))
2040 /* allocate memory for the software ring */
2041 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
2042 nb_desc * sizeof(struct rte_mbuf *),
2043 RTE_CACHE_LINE_SIZE, socket_id);
2044 if (q->sw_ring == NULL) {
2045 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
2051 * allocate memory for the hardware descriptor ring. A memzone large
2052 * enough to hold the maximum ring size is requested to allow for
2053 * resizing in later calls to the queue setup function.
2055 mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_id,
2056 FM10K_MAX_TX_RING_SZ, FM10K_ALIGN_TX_DESC,
2059 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
2060 rte_free(q->sw_ring);
2064 q->hw_ring = mz->addr;
2065 q->hw_ring_phys_addr = mz->iova;
2068 * allocate memory for the RS bit tracker. Enough slots to hold the
2069 * descriptor index for each RS bit needing to be set are required.
2071 q->rs_tracker.list = rte_zmalloc_socket("fm10k rs tracker",
2072 ((nb_desc + 1) / q->rs_thresh) *
2074 RTE_CACHE_LINE_SIZE, socket_id);
2075 if (q->rs_tracker.list == NULL) {
2076 PMD_INIT_LOG(ERR, "Cannot allocate RS bit tracker");
2077 rte_free(q->sw_ring);
2082 dev->data->tx_queues[queue_id] = q;
2087 fm10k_tx_queue_release(void *queue)
2089 struct fm10k_tx_queue *q = queue;
2090 PMD_INIT_FUNC_TRACE();
2096 fm10k_reta_update(struct rte_eth_dev *dev,
2097 struct rte_eth_rss_reta_entry64 *reta_conf,
2100 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2101 uint16_t i, j, idx, shift;
2105 PMD_INIT_FUNC_TRACE();
2107 if (reta_size > FM10K_MAX_RSS_INDICES) {
2108 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2109 "(%d) doesn't match the number hardware can supported "
2110 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2115 * Update Redirection Table RETA[n], n=0..31. The redirection table has
2116 * 128-entries in 32 registers
2118 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2119 idx = i / RTE_RETA_GROUP_SIZE;
2120 shift = i % RTE_RETA_GROUP_SIZE;
2121 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2122 BIT_MASK_PER_UINT32);
2127 if (mask != BIT_MASK_PER_UINT32)
2128 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2130 for (j = 0; j < CHARS_PER_UINT32; j++) {
2131 if (mask & (0x1 << j)) {
2133 reta &= ~(UINT8_MAX << CHAR_BIT * j);
2134 reta |= reta_conf[idx].reta[shift + j] <<
2138 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2), reta);
2145 fm10k_reta_query(struct rte_eth_dev *dev,
2146 struct rte_eth_rss_reta_entry64 *reta_conf,
2149 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2150 uint16_t i, j, idx, shift;
2154 PMD_INIT_FUNC_TRACE();
2156 if (reta_size < FM10K_MAX_RSS_INDICES) {
2157 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2158 "(%d) doesn't match the number hardware can supported "
2159 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2164 * Read Redirection Table RETA[n], n=0..31. The redirection table has
2165 * 128-entries in 32 registers
2167 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2168 idx = i / RTE_RETA_GROUP_SIZE;
2169 shift = i % RTE_RETA_GROUP_SIZE;
2170 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2171 BIT_MASK_PER_UINT32);
2175 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2176 for (j = 0; j < CHARS_PER_UINT32; j++) {
2177 if (mask & (0x1 << j))
2178 reta_conf[idx].reta[shift + j] = ((reta >>
2179 CHAR_BIT * j) & UINT8_MAX);
2187 fm10k_rss_hash_update(struct rte_eth_dev *dev,
2188 struct rte_eth_rss_conf *rss_conf)
2190 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2191 uint32_t *key = (uint32_t *)rss_conf->rss_key;
2193 uint64_t hf = rss_conf->rss_hf;
2196 PMD_INIT_FUNC_TRACE();
2198 if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2199 FM10K_RSSRK_ENTRIES_PER_REG))
2206 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
2207 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
2208 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
2209 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
2210 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
2211 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
2212 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
2213 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
2214 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
2216 /* If the mapping doesn't fit any supported, return */
2221 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2222 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
2224 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
2230 fm10k_rss_hash_conf_get(struct rte_eth_dev *dev,
2231 struct rte_eth_rss_conf *rss_conf)
2233 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2234 uint32_t *key = (uint32_t *)rss_conf->rss_key;
2239 PMD_INIT_FUNC_TRACE();
2241 if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2242 FM10K_RSSRK_ENTRIES_PER_REG))
2246 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2247 key[i] = FM10K_READ_REG(hw, FM10K_RSSRK(0, i));
2249 mrqc = FM10K_READ_REG(hw, FM10K_MRQC(0));
2251 hf |= (mrqc & FM10K_MRQC_IPV4) ? ETH_RSS_IPV4 : 0;
2252 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6 : 0;
2253 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6_EX : 0;
2254 hf |= (mrqc & FM10K_MRQC_TCP_IPV4) ? ETH_RSS_NONFRAG_IPV4_TCP : 0;
2255 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_NONFRAG_IPV6_TCP : 0;
2256 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_IPV6_TCP_EX : 0;
2257 hf |= (mrqc & FM10K_MRQC_UDP_IPV4) ? ETH_RSS_NONFRAG_IPV4_UDP : 0;
2258 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_NONFRAG_IPV6_UDP : 0;
2259 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_IPV6_UDP_EX : 0;
2261 rss_conf->rss_hf = hf;
2267 fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)
2269 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2270 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2272 /* Bind all local non-queue interrupt to vector 0 */
2273 int_map |= FM10K_MISC_VEC_ID;
2275 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2276 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2277 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2278 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2279 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2280 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2282 /* Enable misc causes */
2283 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
2284 FM10K_EIMR_ENABLE(THI_FAULT) |
2285 FM10K_EIMR_ENABLE(FUM_FAULT) |
2286 FM10K_EIMR_ENABLE(MAILBOX) |
2287 FM10K_EIMR_ENABLE(SWITCHREADY) |
2288 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
2289 FM10K_EIMR_ENABLE(SRAMERROR) |
2290 FM10K_EIMR_ENABLE(VFLR));
2293 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2294 FM10K_ITR_MASK_CLEAR);
2295 FM10K_WRITE_FLUSH(hw);
2299 fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev)
2301 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2302 uint32_t int_map = FM10K_INT_MAP_DISABLE;
2304 int_map |= FM10K_MISC_VEC_ID;
2306 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2307 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2308 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2309 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2310 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2311 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2313 /* Disable misc causes */
2314 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
2315 FM10K_EIMR_DISABLE(THI_FAULT) |
2316 FM10K_EIMR_DISABLE(FUM_FAULT) |
2317 FM10K_EIMR_DISABLE(MAILBOX) |
2318 FM10K_EIMR_DISABLE(SWITCHREADY) |
2319 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
2320 FM10K_EIMR_DISABLE(SRAMERROR) |
2321 FM10K_EIMR_DISABLE(VFLR));
2324 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
2325 FM10K_WRITE_FLUSH(hw);
2329 fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
2331 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2332 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2334 /* Bind all local non-queue interrupt to vector 0 */
2335 int_map |= FM10K_MISC_VEC_ID;
2337 /* Only INT 0 available, other 15 are reserved. */
2338 FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2341 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2342 FM10K_ITR_MASK_CLEAR);
2343 FM10K_WRITE_FLUSH(hw);
2347 fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev)
2349 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2350 uint32_t int_map = FM10K_INT_MAP_DISABLE;
2352 int_map |= FM10K_MISC_VEC_ID;
2354 /* Only INT 0 available, other 15 are reserved. */
2355 FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2358 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
2359 FM10K_WRITE_FLUSH(hw);
2363 fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2365 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2366 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2369 if (hw->mac.type == fm10k_mac_pf)
2370 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
2371 FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2373 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
2374 FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2375 rte_intr_enable(&pdev->intr_handle);
2380 fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2382 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2383 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2386 if (hw->mac.type == fm10k_mac_pf)
2387 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
2388 FM10K_ITR_MASK_SET);
2390 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
2391 FM10K_ITR_MASK_SET);
2396 fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2398 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2399 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2400 struct rte_intr_handle *intr_handle = &pdev->intr_handle;
2401 uint32_t intr_vector, vec;
2405 /* fm10k needs one separate interrupt for mailbox,
2406 * so only drivers which support multiple interrupt vectors
2407 * e.g. vfio-pci can work for fm10k interrupt mode
2409 if (!rte_intr_cap_multiple(intr_handle) ||
2410 dev->data->dev_conf.intr_conf.rxq == 0)
2413 intr_vector = dev->data->nb_rx_queues;
2415 /* disable interrupt first */
2416 rte_intr_disable(intr_handle);
2417 if (hw->mac.type == fm10k_mac_pf)
2418 fm10k_dev_disable_intr_pf(dev);
2420 fm10k_dev_disable_intr_vf(dev);
2422 if (rte_intr_efd_enable(intr_handle, intr_vector)) {
2423 PMD_INIT_LOG(ERR, "Failed to init event fd");
2427 if (rte_intr_dp_is_en(intr_handle) && !result) {
2428 intr_handle->intr_vec = rte_zmalloc("intr_vec",
2429 dev->data->nb_rx_queues * sizeof(int), 0);
2430 if (intr_handle->intr_vec) {
2431 for (queue_id = 0, vec = FM10K_RX_VEC_START;
2432 queue_id < dev->data->nb_rx_queues;
2434 intr_handle->intr_vec[queue_id] = vec;
2435 if (vec < intr_handle->nb_efd - 1
2436 + FM10K_RX_VEC_START)
2440 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2441 " intr_vec", dev->data->nb_rx_queues);
2442 rte_intr_efd_disable(intr_handle);
2447 if (hw->mac.type == fm10k_mac_pf)
2448 fm10k_dev_enable_intr_pf(dev);
2450 fm10k_dev_enable_intr_vf(dev);
2451 rte_intr_enable(intr_handle);
2452 hw->mac.ops.update_int_moderator(hw);
2457 fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
2459 struct fm10k_fault fault;
2461 const char *estr = "Unknown error";
2463 /* Process PCA fault */
2464 if (eicr & FM10K_EICR_PCA_FAULT) {
2465 err = fm10k_get_fault(hw, FM10K_PCA_FAULT, &fault);
2468 switch (fault.type) {
2470 estr = "PCA_NO_FAULT"; break;
2471 case PCA_UNMAPPED_ADDR:
2472 estr = "PCA_UNMAPPED_ADDR"; break;
2473 case PCA_BAD_QACCESS_PF:
2474 estr = "PCA_BAD_QACCESS_PF"; break;
2475 case PCA_BAD_QACCESS_VF:
2476 estr = "PCA_BAD_QACCESS_VF"; break;
2477 case PCA_MALICIOUS_REQ:
2478 estr = "PCA_MALICIOUS_REQ"; break;
2479 case PCA_POISONED_TLP:
2480 estr = "PCA_POISONED_TLP"; break;
2482 estr = "PCA_TLP_ABORT"; break;
2486 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2487 estr, fault.func ? "VF" : "PF", fault.func,
2488 fault.address, fault.specinfo);
2491 /* Process THI fault */
2492 if (eicr & FM10K_EICR_THI_FAULT) {
2493 err = fm10k_get_fault(hw, FM10K_THI_FAULT, &fault);
2496 switch (fault.type) {
2498 estr = "THI_NO_FAULT"; break;
2499 case THI_MAL_DIS_Q_FAULT:
2500 estr = "THI_MAL_DIS_Q_FAULT"; break;
2504 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2505 estr, fault.func ? "VF" : "PF", fault.func,
2506 fault.address, fault.specinfo);
2509 /* Process FUM fault */
2510 if (eicr & FM10K_EICR_FUM_FAULT) {
2511 err = fm10k_get_fault(hw, FM10K_FUM_FAULT, &fault);
2514 switch (fault.type) {
2516 estr = "FUM_NO_FAULT"; break;
2517 case FUM_UNMAPPED_ADDR:
2518 estr = "FUM_UNMAPPED_ADDR"; break;
2519 case FUM_POISONED_TLP:
2520 estr = "FUM_POISONED_TLP"; break;
2521 case FUM_BAD_VF_QACCESS:
2522 estr = "FUM_BAD_VF_QACCESS"; break;
2523 case FUM_ADD_DECODE_ERR:
2524 estr = "FUM_ADD_DECODE_ERR"; break;
2526 estr = "FUM_RO_ERROR"; break;
2527 case FUM_QPRC_CRC_ERROR:
2528 estr = "FUM_QPRC_CRC_ERROR"; break;
2529 case FUM_CSR_TIMEOUT:
2530 estr = "FUM_CSR_TIMEOUT"; break;
2531 case FUM_INVALID_TYPE:
2532 estr = "FUM_INVALID_TYPE"; break;
2533 case FUM_INVALID_LENGTH:
2534 estr = "FUM_INVALID_LENGTH"; break;
2535 case FUM_INVALID_BE:
2536 estr = "FUM_INVALID_BE"; break;
2537 case FUM_INVALID_ALIGN:
2538 estr = "FUM_INVALID_ALIGN"; break;
2542 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2543 estr, fault.func ? "VF" : "PF", fault.func,
2544 fault.address, fault.specinfo);
2549 PMD_INIT_LOG(ERR, "Failed to handle fault event.");
2554 * PF interrupt handler triggered by NIC for handling specific interrupt.
2557 * Pointer to interrupt handle.
2559 * The address of parameter (struct rte_eth_dev *) regsitered before.
2565 fm10k_dev_interrupt_handler_pf(void *param)
2567 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2568 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2569 uint32_t cause, status;
2570 struct fm10k_dev_info *dev_info =
2571 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2575 if (hw->mac.type != fm10k_mac_pf)
2578 cause = FM10K_READ_REG(hw, FM10K_EICR);
2580 /* Handle PCI fault cases */
2581 if (cause & FM10K_EICR_FAULT_MASK) {
2582 PMD_INIT_LOG(ERR, "INT: find fault!");
2583 fm10k_dev_handle_fault(hw, cause);
2586 /* Handle switch up/down */
2587 if (cause & FM10K_EICR_SWITCHNOTREADY)
2588 PMD_INIT_LOG(ERR, "INT: Switch is not ready");
2590 if (cause & FM10K_EICR_SWITCHREADY) {
2591 PMD_INIT_LOG(INFO, "INT: Switch is ready");
2592 if (dev_info->sm_down == 1) {
2595 /* For recreating logical ports */
2596 status_mbx = hw->mac.ops.update_lport_state(hw,
2597 hw->mac.dglort_map, MAX_LPORT_NUM, 1);
2598 if (status_mbx == FM10K_SUCCESS)
2600 "INT: Recreated Logical port");
2603 "INT: Logical ports weren't recreated");
2605 status_mbx = hw->mac.ops.update_xcast_mode(hw,
2606 hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
2607 if (status_mbx != FM10K_SUCCESS)
2608 PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
2610 fm10k_mbx_unlock(hw);
2612 /* first clear the internal SW recording structure */
2613 if (!(dev->data->dev_conf.rxmode.mq_mode &
2614 ETH_MQ_RX_VMDQ_FLAG))
2615 fm10k_vlan_filter_set(dev, hw->mac.default_vid,
2618 fm10k_MAC_filter_set(dev, hw->mac.addr, false,
2619 MAIN_VSI_POOL_NUMBER);
2622 * Add default mac address and vlan for the logical
2623 * ports that have been created, leave to the
2624 * application to fully recover Rx filtering.
2626 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
2627 MAIN_VSI_POOL_NUMBER);
2629 if (!(dev->data->dev_conf.rxmode.mq_mode &
2630 ETH_MQ_RX_VMDQ_FLAG))
2631 fm10k_vlan_filter_set(dev, hw->mac.default_vid,
2634 dev_info->sm_down = 0;
2635 _rte_eth_dev_callback_process(dev,
2636 RTE_ETH_EVENT_INTR_LSC,
2641 /* Handle mailbox message */
2643 err = hw->mbx.ops.process(hw, &hw->mbx);
2644 fm10k_mbx_unlock(hw);
2646 if (err == FM10K_ERR_RESET_REQUESTED) {
2647 PMD_INIT_LOG(INFO, "INT: Switch is down");
2648 dev_info->sm_down = 1;
2649 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2653 /* Handle SRAM error */
2654 if (cause & FM10K_EICR_SRAMERROR) {
2655 PMD_INIT_LOG(ERR, "INT: SRAM error on PEP");
2657 status = FM10K_READ_REG(hw, FM10K_SRAM_IP);
2658 /* Write to clear pending bits */
2659 FM10K_WRITE_REG(hw, FM10K_SRAM_IP, status);
2661 /* Todo: print out error message after shared code updates */
2664 /* Clear these 3 events if having any */
2665 cause &= FM10K_EICR_SWITCHNOTREADY | FM10K_EICR_MAILBOX |
2666 FM10K_EICR_SWITCHREADY;
2668 FM10K_WRITE_REG(hw, FM10K_EICR, cause);
2670 /* Re-enable interrupt from device side */
2671 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2672 FM10K_ITR_MASK_CLEAR);
2673 /* Re-enable interrupt from host side */
2674 rte_intr_enable(dev->intr_handle);
2678 * VF interrupt handler triggered by NIC for handling specific interrupt.
2681 * Pointer to interrupt handle.
2683 * The address of parameter (struct rte_eth_dev *) regsitered before.
2689 fm10k_dev_interrupt_handler_vf(void *param)
2691 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2692 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2693 struct fm10k_mbx_info *mbx = &hw->mbx;
2694 struct fm10k_dev_info *dev_info =
2695 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2696 const enum fm10k_mbx_state state = mbx->state;
2699 if (hw->mac.type != fm10k_mac_vf)
2702 /* Handle mailbox message if lock is acquired */
2704 hw->mbx.ops.process(hw, &hw->mbx);
2705 fm10k_mbx_unlock(hw);
2707 if (state == FM10K_STATE_OPEN && mbx->state == FM10K_STATE_CONNECT) {
2708 PMD_INIT_LOG(INFO, "INT: Switch has gone down");
2711 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
2713 fm10k_mbx_unlock(hw);
2715 /* Setting reset flag */
2716 dev_info->sm_down = 1;
2717 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2721 if (dev_info->sm_down == 1 &&
2722 hw->mac.dglort_map == FM10K_DGLORTMAP_ZERO) {
2723 PMD_INIT_LOG(INFO, "INT: Switch has gone up");
2725 status_mbx = hw->mac.ops.update_xcast_mode(hw,
2726 hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
2727 if (status_mbx != FM10K_SUCCESS)
2728 PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
2729 fm10k_mbx_unlock(hw);
2731 /* first clear the internal SW recording structure */
2732 fm10k_vlan_filter_set(dev, hw->mac.default_vid, false);
2733 fm10k_MAC_filter_set(dev, hw->mac.addr, false,
2734 MAIN_VSI_POOL_NUMBER);
2737 * Add default mac address and vlan for the logical ports that
2738 * have been created, leave to the application to fully recover
2741 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
2742 MAIN_VSI_POOL_NUMBER);
2743 fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
2745 dev_info->sm_down = 0;
2746 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2750 /* Re-enable interrupt from device side */
2751 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2752 FM10K_ITR_MASK_CLEAR);
2753 /* Re-enable interrupt from host side */
2754 rte_intr_enable(dev->intr_handle);
2757 /* Mailbox message handler in VF */
2758 static const struct fm10k_msg_data fm10k_msgdata_vf[] = {
2759 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
2760 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
2761 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
2762 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
2766 fm10k_setup_mbx_service(struct fm10k_hw *hw)
2770 /* Initialize mailbox lock */
2771 fm10k_mbx_initlock(hw);
2773 /* Replace default message handler with new ones */
2774 if (hw->mac.type == fm10k_mac_vf)
2775 err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_vf);
2778 PMD_INIT_LOG(ERR, "Failed to register mailbox handler.err:%d",
2782 /* Connect to SM for PF device or PF for VF device */
2783 return hw->mbx.ops.connect(hw, &hw->mbx);
2787 fm10k_close_mbx_service(struct fm10k_hw *hw)
2789 /* Disconnect from SM for PF device or PF for VF device */
2790 hw->mbx.ops.disconnect(hw, &hw->mbx);
2793 static const struct eth_dev_ops fm10k_eth_dev_ops = {
2794 .dev_configure = fm10k_dev_configure,
2795 .dev_start = fm10k_dev_start,
2796 .dev_stop = fm10k_dev_stop,
2797 .dev_close = fm10k_dev_close,
2798 .promiscuous_enable = fm10k_dev_promiscuous_enable,
2799 .promiscuous_disable = fm10k_dev_promiscuous_disable,
2800 .allmulticast_enable = fm10k_dev_allmulticast_enable,
2801 .allmulticast_disable = fm10k_dev_allmulticast_disable,
2802 .stats_get = fm10k_stats_get,
2803 .xstats_get = fm10k_xstats_get,
2804 .xstats_get_names = fm10k_xstats_get_names,
2805 .stats_reset = fm10k_stats_reset,
2806 .xstats_reset = fm10k_stats_reset,
2807 .link_update = fm10k_link_update,
2808 .dev_infos_get = fm10k_dev_infos_get,
2809 .dev_supported_ptypes_get = fm10k_dev_supported_ptypes_get,
2810 .vlan_filter_set = fm10k_vlan_filter_set,
2811 .vlan_offload_set = fm10k_vlan_offload_set,
2812 .mac_addr_add = fm10k_macaddr_add,
2813 .mac_addr_remove = fm10k_macaddr_remove,
2814 .rx_queue_start = fm10k_dev_rx_queue_start,
2815 .rx_queue_stop = fm10k_dev_rx_queue_stop,
2816 .tx_queue_start = fm10k_dev_tx_queue_start,
2817 .tx_queue_stop = fm10k_dev_tx_queue_stop,
2818 .rx_queue_setup = fm10k_rx_queue_setup,
2819 .rx_queue_release = fm10k_rx_queue_release,
2820 .tx_queue_setup = fm10k_tx_queue_setup,
2821 .tx_queue_release = fm10k_tx_queue_release,
2822 .rx_queue_count = fm10k_dev_rx_queue_count,
2823 .rx_descriptor_done = fm10k_dev_rx_descriptor_done,
2824 .rx_descriptor_status = fm10k_dev_rx_descriptor_status,
2825 .tx_descriptor_status = fm10k_dev_tx_descriptor_status,
2826 .rx_queue_intr_enable = fm10k_dev_rx_queue_intr_enable,
2827 .rx_queue_intr_disable = fm10k_dev_rx_queue_intr_disable,
2828 .reta_update = fm10k_reta_update,
2829 .reta_query = fm10k_reta_query,
2830 .rss_hash_update = fm10k_rss_hash_update,
2831 .rss_hash_conf_get = fm10k_rss_hash_conf_get,
2834 static int ftag_check_handler(__rte_unused const char *key,
2835 const char *value, __rte_unused void *opaque)
2837 if (strcmp(value, "1"))
2844 fm10k_check_ftag(struct rte_devargs *devargs)
2846 struct rte_kvargs *kvlist;
2847 const char *ftag_key = "enable_ftag";
2849 if (devargs == NULL)
2852 kvlist = rte_kvargs_parse(devargs->args, NULL);
2856 if (!rte_kvargs_count(kvlist, ftag_key)) {
2857 rte_kvargs_free(kvlist);
2860 /* FTAG is enabled when there's key-value pair: enable_ftag=1 */
2861 if (rte_kvargs_process(kvlist, ftag_key,
2862 ftag_check_handler, NULL) < 0) {
2863 rte_kvargs_free(kvlist);
2866 rte_kvargs_free(kvlist);
2872 fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
2876 struct fm10k_tx_queue *txq = (struct fm10k_tx_queue *)tx_queue;
2881 num = (uint16_t)RTE_MIN(nb_pkts, txq->rs_thresh);
2882 ret = fm10k_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
2893 static void __attribute__((cold))
2894 fm10k_set_tx_function(struct rte_eth_dev *dev)
2896 struct fm10k_tx_queue *txq;
2899 uint16_t tx_ftag_en = 0;
2901 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2902 /* primary process has set the ftag flag and offloads */
2903 txq = dev->data->tx_queues[0];
2904 if (fm10k_tx_vec_condition_check(txq)) {
2905 dev->tx_pkt_burst = fm10k_xmit_pkts;
2906 dev->tx_pkt_prepare = fm10k_prep_pkts;
2907 PMD_INIT_LOG(DEBUG, "Use regular Tx func");
2909 PMD_INIT_LOG(DEBUG, "Use vector Tx func");
2910 dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
2911 dev->tx_pkt_prepare = NULL;
2916 if (fm10k_check_ftag(dev->device->devargs))
2919 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2920 txq = dev->data->tx_queues[i];
2921 txq->tx_ftag_en = tx_ftag_en;
2922 /* Check if Vector Tx is satisfied */
2923 if (fm10k_tx_vec_condition_check(txq))
2928 PMD_INIT_LOG(DEBUG, "Use vector Tx func");
2929 for (i = 0; i < dev->data->nb_tx_queues; i++) {
2930 txq = dev->data->tx_queues[i];
2931 fm10k_txq_vec_setup(txq);
2933 dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
2934 dev->tx_pkt_prepare = NULL;
2936 dev->tx_pkt_burst = fm10k_xmit_pkts;
2937 dev->tx_pkt_prepare = fm10k_prep_pkts;
2938 PMD_INIT_LOG(DEBUG, "Use regular Tx func");
2942 static void __attribute__((cold))
2943 fm10k_set_rx_function(struct rte_eth_dev *dev)
2945 struct fm10k_dev_info *dev_info =
2946 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2947 uint16_t i, rx_using_sse;
2948 uint16_t rx_ftag_en = 0;
2950 if (fm10k_check_ftag(dev->device->devargs))
2953 /* In order to allow Vector Rx there are a few configuration
2954 * conditions to be met.
2956 if (!fm10k_rx_vec_condition_check(dev) &&
2957 dev_info->rx_vec_allowed && !rx_ftag_en) {
2958 if (dev->data->scattered_rx)
2959 dev->rx_pkt_burst = fm10k_recv_scattered_pkts_vec;
2961 dev->rx_pkt_burst = fm10k_recv_pkts_vec;
2962 } else if (dev->data->scattered_rx)
2963 dev->rx_pkt_burst = fm10k_recv_scattered_pkts;
2965 dev->rx_pkt_burst = fm10k_recv_pkts;
2968 (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec ||
2969 dev->rx_pkt_burst == fm10k_recv_pkts_vec);
2972 PMD_INIT_LOG(DEBUG, "Use vector Rx func");
2974 PMD_INIT_LOG(DEBUG, "Use regular Rx func");
2976 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2979 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2980 struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];
2982 rxq->rx_using_sse = rx_using_sse;
2983 rxq->rx_ftag_en = rx_ftag_en;
2988 fm10k_params_init(struct rte_eth_dev *dev)
2990 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2991 struct fm10k_dev_info *info =
2992 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2994 /* Inialize bus info. Normally we would call fm10k_get_bus_info(), but
2995 * there is no way to get link status without reading BAR4. Until this
2996 * works, assume we have maximum bandwidth.
2997 * @todo - fix bus info
2999 hw->bus_caps.speed = fm10k_bus_speed_8000;
3000 hw->bus_caps.width = fm10k_bus_width_pcie_x8;
3001 hw->bus_caps.payload = fm10k_bus_payload_512;
3002 hw->bus.speed = fm10k_bus_speed_8000;
3003 hw->bus.width = fm10k_bus_width_pcie_x8;
3004 hw->bus.payload = fm10k_bus_payload_256;
3006 info->rx_vec_allowed = true;
3007 info->sm_down = false;
3011 eth_fm10k_dev_init(struct rte_eth_dev *dev)
3013 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3014 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
3015 struct rte_intr_handle *intr_handle = &pdev->intr_handle;
3017 struct fm10k_macvlan_filter_info *macvlan;
3019 PMD_INIT_FUNC_TRACE();
3021 dev->dev_ops = &fm10k_eth_dev_ops;
3022 dev->rx_pkt_burst = &fm10k_recv_pkts;
3023 dev->tx_pkt_burst = &fm10k_xmit_pkts;
3024 dev->tx_pkt_prepare = &fm10k_prep_pkts;
3027 * Primary process does the whole initialization, for secondary
3028 * processes, we just select the same Rx and Tx function as primary.
3030 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3031 fm10k_set_rx_function(dev);
3032 fm10k_set_tx_function(dev);
3036 rte_eth_copy_pci_info(dev, pdev);
3038 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
3039 memset(macvlan, 0, sizeof(*macvlan));
3040 /* Vendor and Device ID need to be set before init of shared code */
3041 memset(hw, 0, sizeof(*hw));
3042 hw->device_id = pdev->id.device_id;
3043 hw->vendor_id = pdev->id.vendor_id;
3044 hw->subsystem_device_id = pdev->id.subsystem_device_id;
3045 hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
3046 hw->revision_id = 0;
3047 hw->hw_addr = (void *)pdev->mem_resource[0].addr;
3048 if (hw->hw_addr == NULL) {
3049 PMD_INIT_LOG(ERR, "Bad mem resource."
3050 " Try to blacklist unused devices.");
3054 /* Store fm10k_adapter pointer */
3055 hw->back = dev->data->dev_private;
3057 /* Initialize the shared code */
3058 diag = fm10k_init_shared_code(hw);
3059 if (diag != FM10K_SUCCESS) {
3060 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
3064 /* Initialize parameters */
3065 fm10k_params_init(dev);
3067 /* Initialize the hw */
3068 diag = fm10k_init_hw(hw);
3069 if (diag != FM10K_SUCCESS) {
3070 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
3074 /* Initialize MAC address(es) */
3075 dev->data->mac_addrs = rte_zmalloc("fm10k",
3076 ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM, 0);
3077 if (dev->data->mac_addrs == NULL) {
3078 PMD_INIT_LOG(ERR, "Cannot allocate memory for MAC addresses");
3082 diag = fm10k_read_mac_addr(hw);
3084 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
3085 &dev->data->mac_addrs[0]);
3087 if (diag != FM10K_SUCCESS ||
3088 !is_valid_assigned_ether_addr(dev->data->mac_addrs)) {
3090 /* Generate a random addr */
3091 eth_random_addr(hw->mac.addr);
3092 memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
3093 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
3094 &dev->data->mac_addrs[0]);
3097 /* Reset the hw statistics */
3098 fm10k_stats_reset(dev);
3101 diag = fm10k_reset_hw(hw);
3102 if (diag != FM10K_SUCCESS) {
3103 PMD_INIT_LOG(ERR, "Hardware reset failed: %d", diag);
3107 /* Setup mailbox service */
3108 diag = fm10k_setup_mbx_service(hw);
3109 if (diag != FM10K_SUCCESS) {
3110 PMD_INIT_LOG(ERR, "Failed to setup mailbox: %d", diag);
3114 /*PF/VF has different interrupt handling mechanism */
3115 if (hw->mac.type == fm10k_mac_pf) {
3116 /* register callback func to eal lib */
3117 rte_intr_callback_register(intr_handle,
3118 fm10k_dev_interrupt_handler_pf, (void *)dev);
3120 /* enable MISC interrupt */
3121 fm10k_dev_enable_intr_pf(dev);
3123 rte_intr_callback_register(intr_handle,
3124 fm10k_dev_interrupt_handler_vf, (void *)dev);
3126 fm10k_dev_enable_intr_vf(dev);
3129 /* Enable intr after callback registered */
3130 rte_intr_enable(intr_handle);
3132 hw->mac.ops.update_int_moderator(hw);
3134 /* Make sure Switch Manager is ready before going forward. */
3135 if (hw->mac.type == fm10k_mac_pf) {
3136 int switch_ready = 0;
3138 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
3140 hw->mac.ops.get_host_state(hw, &switch_ready);
3141 fm10k_mbx_unlock(hw);
3144 /* Delay some time to acquire async LPORT_MAP info. */
3145 rte_delay_us(WAIT_SWITCH_MSG_US);
3148 if (switch_ready == 0) {
3149 PMD_INIT_LOG(ERR, "switch is not ready");
3155 * Below function will trigger operations on mailbox, acquire lock to
3156 * avoid race condition from interrupt handler. Operations on mailbox
3157 * FIFO will trigger interrupt to PF/SM, in which interrupt handler
3158 * will handle and generate an interrupt to our side. Then, FIFO in
3159 * mailbox will be touched.
3162 /* Enable port first */
3163 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
3166 /* Set unicast mode by default. App can change to other mode in other
3169 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
3170 FM10K_XCAST_MODE_NONE);
3172 fm10k_mbx_unlock(hw);
3174 /* Make sure default VID is ready before going forward. */
3175 if (hw->mac.type == fm10k_mac_pf) {
3176 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
3177 if (hw->mac.default_vid)
3179 /* Delay some time to acquire async port VLAN info. */
3180 rte_delay_us(WAIT_SWITCH_MSG_US);
3183 if (!hw->mac.default_vid) {
3184 PMD_INIT_LOG(ERR, "default VID is not ready");
3189 /* Add default mac address */
3190 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
3191 MAIN_VSI_POOL_NUMBER);
3197 eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
3199 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3200 struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
3201 struct rte_intr_handle *intr_handle = &pdev->intr_handle;
3202 PMD_INIT_FUNC_TRACE();
3204 /* only uninitialize in the primary process */
3205 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3208 /* safe to close dev here */
3209 fm10k_dev_close(dev);
3211 dev->dev_ops = NULL;
3212 dev->rx_pkt_burst = NULL;
3213 dev->tx_pkt_burst = NULL;
3215 /* disable uio/vfio intr */
3216 rte_intr_disable(intr_handle);
3218 /*PF/VF has different interrupt handling mechanism */
3219 if (hw->mac.type == fm10k_mac_pf) {
3220 /* disable interrupt */
3221 fm10k_dev_disable_intr_pf(dev);
3223 /* unregister callback func to eal lib */
3224 rte_intr_callback_unregister(intr_handle,
3225 fm10k_dev_interrupt_handler_pf, (void *)dev);
3227 /* disable interrupt */
3228 fm10k_dev_disable_intr_vf(dev);
3230 rte_intr_callback_unregister(intr_handle,
3231 fm10k_dev_interrupt_handler_vf, (void *)dev);
3237 static int eth_fm10k_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3238 struct rte_pci_device *pci_dev)
3240 return rte_eth_dev_pci_generic_probe(pci_dev,
3241 sizeof(struct fm10k_adapter), eth_fm10k_dev_init);
3244 static int eth_fm10k_pci_remove(struct rte_pci_device *pci_dev)
3246 return rte_eth_dev_pci_generic_remove(pci_dev, eth_fm10k_dev_uninit);
3250 * The set of PCI devices this driver supports. This driver will enable both PF
3251 * and SRIOV-VF devices.
3253 static const struct rte_pci_id pci_id_fm10k_map[] = {
3254 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_PF) },
3255 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_SDI_FM10420_QDA2) },
3256 { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_VF) },
3257 { .vendor_id = 0, /* sentinel */ },
3260 static struct rte_pci_driver rte_pmd_fm10k = {
3261 .id_table = pci_id_fm10k_map,
3262 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
3263 RTE_PCI_DRV_IOVA_AS_VA,
3264 .probe = eth_fm10k_pci_probe,
3265 .remove = eth_fm10k_pci_remove,
3268 RTE_PMD_REGISTER_PCI(net_fm10k, rte_pmd_fm10k);
3269 RTE_PMD_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);
3270 RTE_PMD_REGISTER_KMOD_DEP(net_fm10k, "* igb_uio | uio_pci_generic | vfio-pci");
3272 RTE_INIT(fm10k_init_log)
3274 fm10k_logtype_init = rte_log_register("pmd.net.fm10k.init");
3275 if (fm10k_logtype_init >= 0)
3276 rte_log_set_level(fm10k_logtype_init, RTE_LOG_NOTICE);
3277 fm10k_logtype_driver = rte_log_register("pmd.net.fm10k.driver");
3278 if (fm10k_logtype_driver >= 0)
3279 rte_log_set_level(fm10k_logtype_driver, RTE_LOG_NOTICE);