LCOV - code coverage report
Current view: top level - drivers/net/dpaa - dpaa_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 6 1115 0.5 %
Date: 2025-11-01 17:50:34 Functions: 3 58 5.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 607 0.7 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  *   Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
       4                 :            :  *   Copyright 2017-2020,2022-2025 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : /* System headers */
       8                 :            : #include <stdio.h>
       9                 :            : #include <inttypes.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <limits.h>
      12                 :            : #include <sched.h>
      13                 :            : #include <signal.h>
      14                 :            : #include <pthread.h>
      15                 :            : #include <sys/types.h>
      16                 :            : #include <sys/syscall.h>
      17                 :            : #include <sys/ioctl.h>
      18                 :            : 
      19                 :            : #include <eal_export.h>
      20                 :            : #include <rte_string_fns.h>
      21                 :            : #include <rte_byteorder.h>
      22                 :            : #include <rte_common.h>
      23                 :            : #include <rte_interrupts.h>
      24                 :            : #include <rte_log.h>
      25                 :            : #include <rte_debug.h>
      26                 :            : #include <rte_pci.h>
      27                 :            : #include <rte_atomic.h>
      28                 :            : #include <rte_branch_prediction.h>
      29                 :            : #include <rte_memory.h>
      30                 :            : #include <rte_tailq.h>
      31                 :            : #include <rte_eal.h>
      32                 :            : #include <rte_alarm.h>
      33                 :            : #include <rte_ether.h>
      34                 :            : #include <rte_kvargs.h>
      35                 :            : #include <ethdev_driver.h>
      36                 :            : #include <rte_malloc.h>
      37                 :            : #include <rte_ring.h>
      38                 :            : 
      39                 :            : #include <bus_dpaa_driver.h>
      40                 :            : #include <rte_dpaa_logs.h>
      41                 :            : #include <dpaa_mempool.h>
      42                 :            : 
      43                 :            : #include <dpaa_ethdev.h>
      44                 :            : #include <dpaa_rxtx.h>
      45                 :            : #include <dpaa_flow.h>
      46                 :            : #include <rte_pmd_dpaa.h>
      47                 :            : 
      48                 :            : #include <fsl_usd.h>
      49                 :            : #include <fsl_qman.h>
      50                 :            : #include <fsl_bman.h>
      51                 :            : #include <fsl_fman.h>
      52                 :            : #include <process.h>
      53                 :            : #include <fmlib/fm_ext.h>
      54                 :            : 
      55                 :            : #define DRIVER_IEEE1588         "drv_ieee1588"
      56                 :            : #define CHECK_INTERVAL          100  /* 100ms */
      57                 :            : #define MAX_REPEAT_TIME         90   /* 9s (90 * 100ms) in total */
      58                 :            : #define DRIVER_RECV_ERR_PKTS      "recv_err_pkts"
      59                 :            : #define RTE_PRIORITY_103 103
      60                 :            : 
      61                 :            : /* Supported Rx offloads */
      62                 :            : static uint64_t dev_rx_offloads_sup =
      63                 :            :                 RTE_ETH_RX_OFFLOAD_SCATTER;
      64                 :            : 
      65                 :            : /* Rx offloads which cannot be disabled */
      66                 :            : static uint64_t dev_rx_offloads_nodis =
      67                 :            :                 RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
      68                 :            :                 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
      69                 :            :                 RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
      70                 :            :                 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
      71                 :            :                 RTE_ETH_RX_OFFLOAD_RSS_HASH;
      72                 :            : 
      73                 :            : /* Supported Tx offloads */
      74                 :            : static uint64_t dev_tx_offloads_sup =
      75                 :            :                 RTE_ETH_TX_OFFLOAD_MT_LOCKFREE |
      76                 :            :                 RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
      77                 :            : 
      78                 :            : /* Tx offloads which cannot be disabled */
      79                 :            : static uint64_t dev_tx_offloads_nodis =
      80                 :            :                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
      81                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
      82                 :            :                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
      83                 :            :                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
      84                 :            :                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
      85                 :            :                 RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
      86                 :            : 
      87                 :            : /* Keep track of whether QMAN and BMAN have been globally initialized */
      88                 :            : static int is_global_init;
      89                 :            : static int fmc_q = 1;   /* Indicates the use of static fmc for distribution */
      90                 :            : static int default_q;   /* use default queue - FMC is not executed*/
      91                 :            : int dpaa_ieee_1588;     /* use to indicate if IEEE 1588 is enabled for the driver */
      92                 :            : bool dpaa_enable_recv_err_pkts; /* Enable main queue to receive error packets */
      93                 :            : 
      94                 :            : /* At present we only allow up to 4 push mode queues as default - as each of
      95                 :            :  * this queue need dedicated portal and we are short of portals.
      96                 :            :  */
      97                 :            : #define DPAA_MAX_PUSH_MODE_QUEUE       8
      98                 :            : #define DPAA_DEFAULT_PUSH_MODE_QUEUE   4
      99                 :            : 
     100                 :            : static int dpaa_push_mode_max_queue = DPAA_DEFAULT_PUSH_MODE_QUEUE;
     101                 :            : static int dpaa_push_queue_idx; /* Queue index which are in push mode*/
     102                 :            : 
     103                 :            : 
     104                 :            : /* Per RX FQ Taildrop in frame count */
     105                 :            : static unsigned int td_threshold = CGR_RX_PERFQ_THRESH;
     106                 :            : 
     107                 :            : /* Per TX FQ Taildrop in frame count, disabled by default */
     108                 :            : static unsigned int td_tx_threshold;
     109                 :            : 
     110                 :            : struct rte_dpaa_xstats_name_off {
     111                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
     112                 :            :         uint32_t offset;
     113                 :            : };
     114                 :            : 
     115                 :            : static const struct rte_dpaa_xstats_name_off dpaa_xstats_strings[] = {
     116                 :            :         {"rx_align_err",
     117                 :            :                 offsetof(struct dpaa_if_stats, raln)},
     118                 :            :         {"rx_valid_pause",
     119                 :            :                 offsetof(struct dpaa_if_stats, rxpf)},
     120                 :            :         {"rx_fcs_err",
     121                 :            :                 offsetof(struct dpaa_if_stats, rfcs)},
     122                 :            :         {"rx_vlan_frame",
     123                 :            :                 offsetof(struct dpaa_if_stats, rvlan)},
     124                 :            :         {"rx_frame_err",
     125                 :            :                 offsetof(struct dpaa_if_stats, rerr)},
     126                 :            :         {"rx_drop_err",
     127                 :            :                 offsetof(struct dpaa_if_stats, rdrp)},
     128                 :            :         {"rx_undersized",
     129                 :            :                 offsetof(struct dpaa_if_stats, rund)},
     130                 :            :         {"rx_oversize_err",
     131                 :            :                 offsetof(struct dpaa_if_stats, rovr)},
     132                 :            :         {"rx_fragment_pkt",
     133                 :            :                 offsetof(struct dpaa_if_stats, rfrg)},
     134                 :            :         {"tx_valid_pause",
     135                 :            :                 offsetof(struct dpaa_if_stats, txpf)},
     136                 :            :         {"tx_fcs_err",
     137                 :            :                 offsetof(struct dpaa_if_stats, terr)},
     138                 :            :         {"tx_vlan_frame",
     139                 :            :                 offsetof(struct dpaa_if_stats, tvlan)},
     140                 :            :         {"rx_undersized",
     141                 :            :                 offsetof(struct dpaa_if_stats, tund)},
     142                 :            :         {"rx_frame_counter",
     143                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfrc)},
     144                 :            :         {"rx_bad_frames_count",
     145                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfbc)},
     146                 :            :         {"rx_large_frames_count",
     147                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rlfc)},
     148                 :            :         {"rx_filter_frames_count",
     149                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rffc)},
     150                 :            :         {"rx_frame_discrad_count",
     151                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfdc)},
     152                 :            :         {"rx_frame_list_dma_err_count",
     153                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rfldec)},
     154                 :            :         {"rx_out_of_buffer_discard ",
     155                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rodc)},
     156                 :            :         {"rx_buf_diallocate",
     157                 :            :                 offsetof(struct dpaa_if_rx_bmi_stats, fmbm_rbdc)},
     158                 :            : };
     159                 :            : 
     160                 :            : static struct rte_dpaa_driver rte_dpaa_pmd;
     161                 :            : int dpaa_valid_dev;
     162                 :            : struct rte_mempool *dpaa_tx_sg_pool;
     163                 :            : 
     164                 :            : static int
     165                 :            : dpaa_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info);
     166                 :            : 
     167                 :            : static int dpaa_eth_link_update(struct rte_eth_dev *dev,
     168                 :            :                                 int wait_to_complete __rte_unused);
     169                 :            : 
     170                 :            : static void dpaa_interrupt_handler(void *param);
     171                 :            : 
     172                 :            : static inline void
     173                 :          0 : dpaa_poll_queue_default_config(struct qm_mcc_initfq *opts)
     174                 :            : {
     175                 :            :         memset(opts, 0, sizeof(struct qm_mcc_initfq));
     176                 :          0 :         opts->we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
     177                 :          0 :         opts->fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
     178                 :            :                            QM_FQCTRL_PREFERINCACHE;
     179                 :            :         opts->fqd.context_a.stashing.exclusive = 0;
     180         [ #  # ]:          0 :         if (dpaa_soc_ver() != SVR_LS1046A_FAMILY)
     181                 :          0 :                 opts->fqd.context_a.stashing.annotation_cl =
     182                 :            :                                                 DPAA_IF_RX_ANNOTATION_STASH;
     183                 :          0 :         opts->fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
     184                 :          0 :         opts->fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
     185                 :          0 : }
     186                 :            : 
     187                 :            : static int
     188                 :          0 : dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
     189                 :            : {
     190                 :          0 :         uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
     191                 :          0 :                                 + VLAN_TAG_SIZE;
     192                 :          0 :         uint32_t buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
     193                 :          0 :         struct fman_if *fif = dev->process_private;
     194                 :            : 
     195                 :          0 :         PMD_INIT_FUNC_TRACE();
     196                 :            : 
     197         [ #  # ]:          0 :         if (fif->is_shared_mac) {
     198                 :          0 :                 DPAA_PMD_ERR("Cannot configure mtu from DPDK in VSP mode.");
     199                 :          0 :                 return -ENOTSUP;
     200                 :            :         }
     201                 :            : 
     202                 :            :         /*
     203                 :            :          * Refuse mtu that requires the support of scattered packets
     204                 :            :          * when this feature has not been enabled before.
     205                 :            :          */
     206         [ #  # ]:          0 :         if (dev->data->min_rx_buf_size &&
     207   [ #  #  #  # ]:          0 :                 !dev->data->scattered_rx && frame_size > buffsz) {
     208                 :          0 :                 DPAA_PMD_ERR("SG not enabled, will not fit in one buffer");
     209                 :          0 :                 return -EINVAL;
     210                 :            :         }
     211                 :            : 
     212                 :            :         /* check <seg size> * <max_seg>  >= max_frame */
     213   [ #  #  #  # ]:          0 :         if (dev->data->min_rx_buf_size && dev->data->scattered_rx &&
     214         [ #  # ]:          0 :                 (frame_size > buffsz * DPAA_SGT_MAX_ENTRIES)) {
     215                 :          0 :                 DPAA_PMD_ERR("Too big to fit for Max SG list %d",
     216                 :            :                                 buffsz * DPAA_SGT_MAX_ENTRIES);
     217                 :          0 :                 return -EINVAL;
     218                 :            :         }
     219                 :            : 
     220                 :          0 :         fman_if_set_maxfrm(dev->process_private, frame_size);
     221                 :            : 
     222                 :          0 :         return 0;
     223                 :            : }
     224                 :            : 
     225                 :            : static int
     226                 :          0 : dpaa_eth_dev_configure(struct rte_eth_dev *dev)
     227                 :            : {
     228                 :          0 :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     229                 :          0 :         uint64_t rx_offloads = eth_conf->rxmode.offloads;
     230                 :          0 :         uint64_t tx_offloads = eth_conf->txmode.offloads;
     231                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     232                 :          0 :         struct rte_device *rdev = dev->device;
     233                 :            :         struct rte_eth_link *link = &dev->data->dev_link;
     234                 :            :         struct rte_dpaa_device *dpaa_dev;
     235                 :          0 :         struct fman_if *fif = dev->process_private;
     236                 :            :         struct __fman_if *__fif;
     237                 :            :         struct rte_intr_handle *intr_handle;
     238                 :            :         uint32_t max_rx_pktlen;
     239                 :            :         int speed, duplex;
     240                 :            :         int ret, rx_status, socket_fd;
     241                 :            :         struct ifreq ifr;
     242                 :            : 
     243                 :          0 :         PMD_INIT_FUNC_TRACE();
     244                 :            : 
     245                 :          0 :         dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
     246                 :          0 :         intr_handle = dpaa_dev->intr_handle;
     247                 :            :         __fif = container_of(fif, struct __fman_if, __if);
     248                 :            : 
     249                 :            :         /* Check if interface is enabled in case of shared MAC */
     250         [ #  # ]:          0 :         if (fif->is_shared_mac) {
     251                 :          0 :                 rx_status = fman_if_get_rx_status(fif);
     252         [ #  # ]:          0 :                 if (!rx_status) {
     253                 :          0 :                         DPAA_PMD_ERR("%s Interface not enabled in kernel!",
     254                 :            :                                      dpaa_intf->name);
     255                 :          0 :                         return -EHOSTDOWN;
     256                 :            :                 }
     257                 :            : 
     258                 :          0 :                 socket_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
     259         [ #  # ]:          0 :                 if (socket_fd == -1) {
     260                 :          0 :                         DPAA_PMD_ERR("Cannot open IF socket");
     261                 :          0 :                         return -errno;
     262                 :            :                 }
     263                 :          0 :                 strncpy(ifr.ifr_name, dpaa_intf->name, IFNAMSIZ - 1);
     264                 :            : 
     265         [ #  # ]:          0 :                 if (ioctl(socket_fd, SIOCGIFMTU, &ifr) < 0) {
     266                 :          0 :                         DPAA_PMD_ERR("Cannot get interface mtu");
     267                 :          0 :                         close(socket_fd);
     268                 :          0 :                         return -errno;
     269                 :            :                 }
     270                 :            : 
     271                 :          0 :                 close(socket_fd);
     272                 :          0 :                 DPAA_PMD_INFO("Using kernel configured mtu size(%u)",
     273                 :            :                              ifr.ifr_mtu);
     274                 :            : 
     275                 :          0 :                 eth_conf->rxmode.mtu = ifr.ifr_mtu;
     276                 :            :         }
     277                 :            : 
     278                 :            :         /* Rx offloads which are enabled by default */
     279         [ #  # ]:          0 :         if (dev_rx_offloads_nodis & ~rx_offloads) {
     280                 :          0 :                 DPAA_PMD_INFO(
     281                 :            :                 "Some of rx offloads enabled by default - requested 0x%" PRIx64
     282                 :            :                 " fixed are 0x%" PRIx64,
     283                 :            :                 rx_offloads, dev_rx_offloads_nodis);
     284                 :            :         }
     285                 :            : 
     286                 :            :         /* Tx offloads which are enabled by default */
     287         [ #  # ]:          0 :         if (dev_tx_offloads_nodis & ~tx_offloads) {
     288                 :          0 :                 DPAA_PMD_INFO(
     289                 :            :                 "Some of tx offloads enabled by default - requested 0x%" PRIx64
     290                 :            :                 " fixed are 0x%" PRIx64,
     291                 :            :                 tx_offloads, dev_tx_offloads_nodis);
     292                 :            :         }
     293                 :            : 
     294                 :          0 :         max_rx_pktlen = eth_conf->rxmode.mtu + RTE_ETHER_HDR_LEN +
     295                 :            :                         RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
     296         [ #  # ]:          0 :         if (max_rx_pktlen > DPAA_MAX_RX_PKT_LEN) {
     297                 :          0 :                 DPAA_PMD_INFO("enabling jumbo override conf max len=%d "
     298                 :            :                         "supported is %d",
     299                 :            :                         max_rx_pktlen, DPAA_MAX_RX_PKT_LEN);
     300                 :            :                 max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
     301                 :            :         }
     302                 :            : 
     303   [ #  #  #  #  :          0 :         if (!fif->is_shared_mac && fif->mac_type != fman_offline_internal &&
                   #  # ]
     304                 :            :             fif->mac_type != fman_onic)
     305                 :          0 :                 fman_if_set_maxfrm(dev->process_private, max_rx_pktlen);
     306                 :            : 
     307         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
     308                 :          0 :                 DPAA_PMD_DEBUG("enabling scatter mode");
     309                 :          0 :                 fman_if_set_sg(dev->process_private, 1);
     310                 :          0 :                 dev->data->scattered_rx = 1;
     311                 :            :         }
     312                 :            : 
     313   [ #  #  #  # ]:          0 :         if (!(default_q || fmc_q)) {
     314                 :          0 :                 ret = dpaa_fm_config(dev,
     315                 :            :                         eth_conf->rx_adv_conf.rss_conf.rss_hf);
     316         [ #  # ]:          0 :                 if (ret) {
     317                 :          0 :                         dpaa_write_fm_config_to_file();
     318                 :          0 :                         DPAA_PMD_ERR("FM port configuration: Failed(%d)", ret);
     319                 :          0 :                         return ret;
     320                 :            :                 }
     321                 :          0 :                 dpaa_write_fm_config_to_file();
     322                 :            :         }
     323                 :            : 
     324                 :            :         /* Disable interrupt support on offline port*/
     325         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal ||
     326                 :            :             fif->mac_type == fman_onic)
     327                 :            :                 return 0;
     328                 :            : 
     329                 :            :         /* if the interrupts were configured on this devices*/
     330   [ #  #  #  # ]:          0 :         if (intr_handle && rte_intr_fd_get(intr_handle)) {
     331         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc != 0)
     332                 :          0 :                         rte_intr_callback_register(intr_handle,
     333                 :            :                                            dpaa_interrupt_handler,
     334                 :            :                                            (void *)dev);
     335                 :            : 
     336                 :          0 :                 ret = dpaa_intr_enable(__fif->node_name,
     337                 :            :                                        rte_intr_fd_get(intr_handle));
     338         [ #  # ]:          0 :                 if (ret) {
     339         [ #  # ]:          0 :                         if (dev->data->dev_conf.intr_conf.lsc != 0) {
     340                 :          0 :                                 rte_intr_callback_unregister(intr_handle,
     341                 :            :                                         dpaa_interrupt_handler,
     342                 :            :                                         (void *)dev);
     343         [ #  # ]:          0 :                                 if (ret == EINVAL)
     344                 :          0 :                                         DPAA_PMD_ERR("Failed to enable interrupt: Not Supported");
     345                 :            :                                 else
     346                 :          0 :                                         DPAA_PMD_ERR("Failed to enable interrupt");
     347                 :            :                         }
     348                 :          0 :                         dev->data->dev_conf.intr_conf.lsc = 0;
     349                 :          0 :                         dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
     350                 :            :                 }
     351                 :            :         }
     352                 :            : 
     353                 :            :         /* Wait for link status to get updated */
     354         [ #  # ]:          0 :         if (!link->link_status)
     355                 :          0 :                 sleep(1);
     356                 :            : 
     357                 :            :         /* Configure link only if link is UP*/
     358         [ #  # ]:          0 :         if (link->link_status) {
     359         [ #  # ]:          0 :                 if (eth_conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
     360                 :            :                         /* Start autoneg only if link is not in autoneg mode */
     361         [ #  # ]:          0 :                         if (!link->link_autoneg)
     362                 :          0 :                                 dpaa_restart_link_autoneg(__fif->node_name);
     363         [ #  # ]:          0 :                 } else if (eth_conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) {
     364                 :            :                         switch (eth_conf->link_speeds &  RTE_ETH_LINK_SPEED_FIXED) {
     365                 :            :                         case RTE_ETH_LINK_SPEED_10M_HD:
     366                 :            :                                 speed = RTE_ETH_SPEED_NUM_10M;
     367                 :            :                                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
     368                 :            :                                 break;
     369                 :            :                         case RTE_ETH_LINK_SPEED_10M:
     370                 :            :                                 speed = RTE_ETH_SPEED_NUM_10M;
     371                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     372                 :            :                                 break;
     373                 :            :                         case RTE_ETH_LINK_SPEED_100M_HD:
     374                 :            :                                 speed = RTE_ETH_SPEED_NUM_100M;
     375                 :            :                                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
     376                 :            :                                 break;
     377                 :            :                         case RTE_ETH_LINK_SPEED_100M:
     378                 :            :                                 speed = RTE_ETH_SPEED_NUM_100M;
     379                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     380                 :            :                                 break;
     381                 :            :                         case RTE_ETH_LINK_SPEED_1G:
     382                 :            :                                 speed = RTE_ETH_SPEED_NUM_1G;
     383                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     384                 :            :                                 break;
     385                 :            :                         case RTE_ETH_LINK_SPEED_2_5G:
     386                 :            :                                 speed = RTE_ETH_SPEED_NUM_2_5G;
     387                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     388                 :            :                                 break;
     389                 :            :                         case RTE_ETH_LINK_SPEED_10G:
     390                 :            :                                 speed = RTE_ETH_SPEED_NUM_10G;
     391                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     392                 :            :                                 break;
     393                 :            :                         default:
     394                 :            :                                 speed = RTE_ETH_SPEED_NUM_NONE;
     395                 :            :                                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
     396                 :            :                                 break;
     397                 :            :                         }
     398                 :            :                         /* Set link speed */
     399                 :          0 :                         dpaa_update_link_speed(__fif->node_name, speed, duplex);
     400                 :            :                 } else {
     401                 :            :                         /* Manual autoneg - custom advertisement speed. */
     402                 :          0 :                         DPAA_PMD_ERR("Custom Advertisement speeds not supported");
     403                 :            :                 }
     404                 :            :         }
     405                 :            : 
     406                 :            :         return 0;
     407                 :            : }
     408                 :            : 
     409                 :            : static const uint32_t *
     410                 :          0 : dpaa_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
     411                 :            : {
     412                 :            :         static const uint32_t ptypes[] = {
     413                 :            :                 RTE_PTYPE_L2_ETHER,
     414                 :            :                 RTE_PTYPE_L2_ETHER_VLAN,
     415                 :            :                 RTE_PTYPE_L2_ETHER_ARP,
     416                 :            :                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
     417                 :            :                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
     418                 :            :                 RTE_PTYPE_L4_ICMP,
     419                 :            :                 RTE_PTYPE_L4_TCP,
     420                 :            :                 RTE_PTYPE_L4_UDP,
     421                 :            :                 RTE_PTYPE_L4_FRAG,
     422                 :            :                 RTE_PTYPE_L4_TCP,
     423                 :            :                 RTE_PTYPE_L4_UDP,
     424                 :            :                 RTE_PTYPE_L4_SCTP,
     425                 :            :                 RTE_PTYPE_TUNNEL_ESP,
     426                 :            :                 RTE_PTYPE_TUNNEL_GRE,
     427                 :            :         };
     428                 :            : 
     429                 :          0 :         PMD_INIT_FUNC_TRACE();
     430                 :            : 
     431         [ #  # ]:          0 :         if (dev->rx_pkt_burst == dpaa_eth_queue_rx) {
     432                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
     433                 :          0 :                 return ptypes;
     434                 :            :         }
     435                 :            :         return NULL;
     436                 :            : }
     437                 :            : 
     438                 :          0 : static void dpaa_interrupt_handler(void *param)
     439                 :            : {
     440                 :            :         struct rte_eth_dev *dev = param;
     441                 :          0 :         struct rte_device *rdev = dev->device;
     442                 :            :         struct rte_dpaa_device *dpaa_dev;
     443                 :            :         struct rte_intr_handle *intr_handle;
     444                 :            :         uint64_t buf;
     445                 :            :         int bytes_read;
     446                 :            : 
     447                 :          0 :         dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
     448                 :          0 :         intr_handle = dpaa_dev->intr_handle;
     449                 :            : 
     450         [ #  # ]:          0 :         if (rte_intr_fd_get(intr_handle) < 0)
     451                 :          0 :                 return;
     452                 :            : 
     453                 :          0 :         bytes_read = read(rte_intr_fd_get(intr_handle), &buf,
     454                 :            :                           sizeof(uint64_t));
     455         [ #  # ]:          0 :         if (bytes_read < 0)
     456                 :          0 :                 DPAA_PMD_ERR("Error reading eventfd");
     457                 :          0 :         dpaa_eth_link_update(dev, 0);
     458                 :          0 :         rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
     459                 :            : }
     460                 :            : 
     461                 :          0 : static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
     462                 :            : {
     463                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     464                 :          0 :         struct fman_if *fif = dev->process_private;
     465                 :            :         uint16_t i;
     466                 :            : 
     467                 :          0 :         PMD_INIT_FUNC_TRACE();
     468                 :            : 
     469   [ #  #  #  # ]:          0 :         if (!(default_q || fmc_q))
     470                 :          0 :                 dpaa_write_fm_config_to_file();
     471                 :            : 
     472                 :            :         /* Change tx callback to the real one */
     473         [ #  # ]:          0 :         if (dpaa_intf->cgr_tx)
     474                 :          0 :                 dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
     475                 :            :         else
     476                 :          0 :                 dev->tx_pkt_burst = dpaa_eth_queue_tx;
     477                 :            : 
     478         [ #  # ]:          0 :         if (fif->mac_type != fman_onic) {
     479                 :          0 :                 fman_if_bmi_stats_enable(fif);
     480                 :          0 :                 fman_if_bmi_stats_reset(fif);
     481                 :          0 :                 fman_if_enable_rx(fif);
     482                 :            :         }
     483         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     484                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
     485         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
     486                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
     487                 :            : 
     488                 :          0 :         return 0;
     489                 :            : }
     490                 :            : 
     491                 :          0 : static int dpaa_eth_dev_stop(struct rte_eth_dev *dev)
     492                 :            : {
     493                 :          0 :         struct fman_if *fif = dev->process_private;
     494                 :            :         uint16_t i;
     495                 :            : 
     496                 :          0 :         PMD_INIT_FUNC_TRACE();
     497                 :          0 :         dev->data->dev_started = 0;
     498                 :            : 
     499         [ #  # ]:          0 :         if (!fif->is_shared_mac) {
     500                 :          0 :                 fman_if_bmi_stats_disable(fif);
     501                 :          0 :                 fman_if_disable_rx(fif);
     502                 :            :         }
     503                 :          0 :         dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
     504                 :            : 
     505         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
     506                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
     507         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
     508                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
     509                 :            : 
     510                 :          0 :         return 0;
     511                 :            : }
     512                 :            : 
     513                 :          0 : static int dpaa_eth_dev_close(struct rte_eth_dev *dev)
     514                 :            : {
     515                 :          0 :         struct fman_if *fif = dev->process_private;
     516                 :            :         struct __fman_if *__fif;
     517                 :          0 :         struct rte_device *rdev = dev->device;
     518                 :            :         struct rte_dpaa_device *dpaa_dev;
     519                 :            :         struct rte_intr_handle *intr_handle;
     520                 :          0 :         struct rte_eth_link *link = &dev->data->dev_link;
     521                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     522                 :            :         struct qman_fq *fq;
     523                 :            :         int loop;
     524                 :            :         int ret;
     525                 :            : 
     526                 :          0 :         PMD_INIT_FUNC_TRACE();
     527                 :            : 
     528         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     529                 :            :                 return 0;
     530                 :            : 
     531         [ #  # ]:          0 :         if (!dpaa_intf) {
     532                 :          0 :                 DPAA_PMD_DEBUG("Already closed or not started");
     533                 :          0 :                 return -ENOENT;
     534                 :            :         }
     535                 :            : 
     536                 :            :         /* DPAA FM deconfig */
     537   [ #  #  #  # ]:          0 :         if (!(default_q || fmc_q)) {
     538                 :          0 :                 ret = dpaa_fm_deconfig(dpaa_intf, dev->process_private);
     539         [ #  # ]:          0 :                 if (ret) {
     540                 :          0 :                         DPAA_PMD_WARN("%s: FM deconfig failed(%d)",
     541                 :            :                                 dev->data->name, ret);
     542                 :            :                 }
     543                 :            :         }
     544                 :            : 
     545                 :          0 :         dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
     546                 :          0 :         intr_handle = dpaa_dev->intr_handle;
     547                 :            :         __fif = container_of(fif, struct __fman_if, __if);
     548                 :            : 
     549                 :          0 :         ret = dpaa_eth_dev_stop(dev);
     550         [ #  # ]:          0 :         if (ret) {
     551                 :          0 :                 DPAA_PMD_WARN("%s: stop device failed(%d)",
     552                 :            :                         dev->data->name, ret);
     553                 :            :         }
     554                 :            : 
     555         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal ||
     556                 :            :             fif->mac_type == fman_onic)
     557                 :            :                 return 0;
     558                 :            : 
     559                 :            :         /* Reset link to autoneg */
     560         [ #  # ]:          0 :         if (link->link_status && !link->link_autoneg) {
     561                 :          0 :                 ret = dpaa_restart_link_autoneg(__fif->node_name);
     562         [ #  # ]:          0 :                 if (ret) {
     563                 :          0 :                         DPAA_PMD_WARN("%s: restart link failed(%d)",
     564                 :            :                                 dev->data->name, ret);
     565                 :            :                 }
     566                 :            :         }
     567                 :            : 
     568   [ #  #  #  # ]:          0 :         if (intr_handle && rte_intr_fd_get(intr_handle) &&
     569         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.lsc != 0) {
     570                 :          0 :                 ret = dpaa_intr_disable(__fif->node_name);
     571         [ #  # ]:          0 :                 if (ret) {
     572                 :          0 :                         DPAA_PMD_WARN("%s: disable interrupt failed(%d)",
     573                 :            :                                 dev->data->name, ret);
     574                 :            :                 }
     575                 :          0 :                 ret = rte_intr_callback_unregister(intr_handle,
     576                 :            :                         dpaa_interrupt_handler, (void *)dev);
     577         [ #  # ]:          0 :                 if (ret) {
     578                 :          0 :                         DPAA_PMD_WARN("%s: unregister interrupt failed(%d)",
     579                 :            :                                 dev->data->name, ret);
     580                 :            :                 }
     581                 :            :         }
     582                 :            : 
     583                 :            :         /* release configuration memory */
     584                 :          0 :         rte_free(dpaa_intf->fc_conf);
     585                 :            : 
     586                 :            :         /* Release RX congestion Groups */
     587         [ #  # ]:          0 :         if (dpaa_intf->cgr_rx) {
     588         [ #  # ]:          0 :                 for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
     589                 :          0 :                         ret = qman_delete_cgr(&dpaa_intf->cgr_rx[loop]);
     590         [ #  # ]:          0 :                         if (ret) {
     591                 :          0 :                                 DPAA_PMD_WARN("%s: delete rxq%d's cgr err(%d)",
     592                 :            :                                         dev->data->name, loop, ret);
     593                 :            :                         }
     594                 :            :                 }
     595                 :          0 :                 rte_free(dpaa_intf->cgr_rx);
     596                 :          0 :                 dpaa_intf->cgr_rx = NULL;
     597                 :            :         }
     598                 :            : 
     599                 :            :         /* Release TX congestion Groups */
     600         [ #  # ]:          0 :         if (dpaa_intf->cgr_tx) {
     601         [ #  # ]:          0 :                 for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
     602                 :          0 :                         ret = qman_delete_cgr(&dpaa_intf->cgr_tx[loop]);
     603         [ #  # ]:          0 :                         if (ret) {
     604                 :          0 :                                 DPAA_PMD_WARN("%s: delete txq%d's cgr err(%d)",
     605                 :            :                                         dev->data->name, loop, ret);
     606                 :            :                         }
     607                 :            :                 }
     608                 :          0 :                 rte_free(dpaa_intf->cgr_tx);
     609                 :          0 :                 dpaa_intf->cgr_tx = NULL;
     610                 :            :         }
     611                 :            : 
     612                 :            :         /* Freeing queue specific portals */
     613         [ #  # ]:          0 :         for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
     614         [ #  # ]:          0 :                 if (!dpaa_intf->rx_queues)
     615                 :            :                         break;
     616                 :            : 
     617                 :          0 :                 fq = &dpaa_intf->rx_queues[loop];
     618         [ #  # ]:          0 :                 if (fq->qp_initialized) {
     619                 :          0 :                         rte_dpaa_portal_fq_close(fq);
     620                 :          0 :                         fq->qp_initialized = 0;
     621                 :            :                 }
     622                 :            :         }
     623                 :            : 
     624                 :          0 :         rte_free(dpaa_intf->rx_queues);
     625                 :          0 :         dpaa_intf->rx_queues = NULL;
     626                 :            : 
     627                 :          0 :         rte_free(dpaa_intf->tx_queues);
     628                 :          0 :         dpaa_intf->tx_queues = NULL;
     629         [ #  # ]:          0 :         if (dpaa_intf->port_handle) {
     630                 :          0 :                 ret = dpaa_fm_deconfig(dpaa_intf, fif);
     631         [ #  # ]:          0 :                 if (ret) {
     632                 :          0 :                         DPAA_PMD_WARN("%s: FM deconfig failed(%d)",
     633                 :            :                                 dev->data->name, ret);
     634                 :            :                 }
     635                 :            :         }
     636         [ #  # ]:          0 :         if (fif->num_profiles) {
     637                 :          0 :                 ret = dpaa_port_vsp_cleanup(dpaa_intf, fif);
     638         [ #  # ]:          0 :                 if (ret) {
     639                 :          0 :                         DPAA_PMD_WARN("%s: cleanup VSP failed(%d)",
     640                 :            :                                 dev->data->name, ret);
     641                 :            :                 }
     642                 :            :         }
     643                 :            : 
     644                 :            :         return ret;
     645                 :            : }
     646                 :            : 
     647                 :            : static int
     648                 :          0 : dpaa_fw_version_get(struct rte_eth_dev *dev,
     649                 :            :         char *fw_version, size_t fw_size)
     650                 :            : {
     651                 :          0 :         struct fman_if *fif = dev->process_private;
     652                 :            :         int ret;
     653                 :            : 
     654                 :          0 :         PMD_INIT_FUNC_TRACE();
     655                 :            : 
     656                 :          0 :         ret = snprintf(fw_version, fw_size, "SVR:%x-fman-v%x",
     657                 :          0 :                         dpaa_soc_ver(), fif->fman->ip_rev);
     658         [ #  # ]:          0 :         if (ret < 0)
     659                 :            :                 return -EINVAL;
     660                 :            : 
     661                 :          0 :         ret += 1; /* add the size of '\0' */
     662         [ #  # ]:          0 :         if (fw_size < (size_t)ret)
     663                 :            :                 return ret;
     664                 :            :         else
     665                 :          0 :                 return 0;
     666                 :            : }
     667                 :            : 
     668                 :          0 : static int dpaa_eth_dev_info(struct rte_eth_dev *dev,
     669                 :            :                              struct rte_eth_dev_info *dev_info)
     670                 :            : {
     671                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     672                 :          0 :         struct fman_if *fif = dev->process_private;
     673                 :            : 
     674                 :          0 :         DPAA_PMD_DEBUG(": %s", dpaa_intf->name);
     675                 :            : 
     676                 :          0 :         dev_info->max_rx_queues = dpaa_intf->nb_rx_queues;
     677                 :          0 :         dev_info->max_tx_queues = dpaa_intf->nb_tx_queues;
     678                 :          0 :         dev_info->max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
     679                 :          0 :         dev_info->max_mac_addrs = DPAA_MAX_MAC_FILTER;
     680                 :          0 :         dev_info->max_hash_mac_addrs = 0;
     681                 :          0 :         dev_info->max_vfs = 0;
     682                 :          0 :         dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
     683                 :          0 :         dev_info->flow_type_rss_offloads = DPAA_RSS_OFFLOAD_ALL;
     684                 :            : 
     685         [ #  # ]:          0 :         if (fif->mac_type == fman_mac_1g) {
     686                 :          0 :                 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
     687                 :            :                                         | RTE_ETH_LINK_SPEED_10M
     688                 :            :                                         | RTE_ETH_LINK_SPEED_100M_HD
     689                 :            :                                         | RTE_ETH_LINK_SPEED_100M
     690                 :            :                                         | RTE_ETH_LINK_SPEED_1G;
     691         [ #  # ]:          0 :         } else if (fif->mac_type == fman_mac_2_5g) {
     692                 :          0 :                 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
     693                 :            :                                         | RTE_ETH_LINK_SPEED_10M
     694                 :            :                                         | RTE_ETH_LINK_SPEED_100M_HD
     695                 :            :                                         | RTE_ETH_LINK_SPEED_100M
     696                 :            :                                         | RTE_ETH_LINK_SPEED_1G
     697                 :            :                                         | RTE_ETH_LINK_SPEED_2_5G;
     698         [ #  # ]:          0 :         } else if (fif->mac_type == fman_mac_10g) {
     699                 :          0 :                 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
     700                 :            :                                         | RTE_ETH_LINK_SPEED_10M
     701                 :            :                                         | RTE_ETH_LINK_SPEED_100M_HD
     702                 :            :                                         | RTE_ETH_LINK_SPEED_100M
     703                 :            :                                         | RTE_ETH_LINK_SPEED_1G
     704                 :            :                                         | RTE_ETH_LINK_SPEED_2_5G
     705                 :            :                                         | RTE_ETH_LINK_SPEED_10G;
     706         [ #  # ]:          0 :         } else if (fif->mac_type == fman_offline_internal ||
     707                 :            :                    fif->mac_type == fman_onic) {
     708                 :          0 :                 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD
     709                 :            :                                         | RTE_ETH_LINK_SPEED_10M
     710                 :            :                                         | RTE_ETH_LINK_SPEED_100M_HD
     711                 :            :                                         | RTE_ETH_LINK_SPEED_100M
     712                 :            :                                         | RTE_ETH_LINK_SPEED_1G
     713                 :            :                                         | RTE_ETH_LINK_SPEED_2_5G;
     714                 :            :         } else {
     715                 :          0 :                 DPAA_PMD_ERR("invalid link_speed: %s, %d",
     716                 :            :                              dpaa_intf->name, fif->mac_type);
     717                 :          0 :                 return -EINVAL;
     718                 :            :         }
     719                 :            : 
     720                 :          0 :         dev_info->rx_offload_capa = dev_rx_offloads_sup |
     721                 :            :                                         dev_rx_offloads_nodis;
     722                 :          0 :         dev_info->tx_offload_capa = dev_tx_offloads_sup |
     723                 :            :                                         dev_tx_offloads_nodis;
     724                 :          0 :         dev_info->default_rxportconf.burst_size = DPAA_DEF_RX_BURST_SIZE;
     725                 :          0 :         dev_info->default_txportconf.burst_size = DPAA_DEF_TX_BURST_SIZE;
     726                 :          0 :         dev_info->default_rxportconf.nb_queues = 1;
     727                 :          0 :         dev_info->default_txportconf.nb_queues = 1;
     728                 :          0 :         dev_info->default_txportconf.ring_size = CGR_TX_CGR_THRESH;
     729                 :          0 :         dev_info->default_rxportconf.ring_size = CGR_RX_PERFQ_THRESH;
     730                 :            : 
     731                 :          0 :         return 0;
     732                 :            : }
     733                 :            : 
     734                 :            : static int
     735                 :          0 : dpaa_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
     736                 :            :                         __rte_unused uint16_t queue_id,
     737                 :            :                         struct rte_eth_burst_mode *mode)
     738                 :            : {
     739                 :          0 :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     740                 :            :         int ret = -EINVAL;
     741                 :            :         unsigned int i;
     742                 :            :         const struct burst_info {
     743                 :            :                 uint64_t flags;
     744                 :            :                 const char *output;
     745                 :          0 :         } rx_offload_map[] = {
     746                 :            :                         {RTE_ETH_RX_OFFLOAD_SCATTER, " Scattered,"},
     747                 :            :                         {RTE_ETH_RX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
     748                 :            :                         {RTE_ETH_RX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
     749                 :            :                         {RTE_ETH_RX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
     750                 :            :                         {RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
     751                 :            :                         {RTE_ETH_RX_OFFLOAD_RSS_HASH, " RSS,"}
     752                 :            :         };
     753                 :            : 
     754                 :            :         /* Update Rx offload info */
     755         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
     756         [ #  # ]:          0 :                 if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
     757                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
     758                 :          0 :                                 rx_offload_map[i].output);
     759                 :            :                         ret = 0;
     760                 :          0 :                         break;
     761                 :            :                 }
     762                 :            :         }
     763                 :          0 :         return ret;
     764                 :            : }
     765                 :            : 
     766                 :            : static int
     767                 :          0 : dpaa_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
     768                 :            :                         __rte_unused uint16_t queue_id,
     769                 :            :                         struct rte_eth_burst_mode *mode)
     770                 :            : {
     771                 :          0 :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     772                 :            :         int ret = -EINVAL;
     773                 :            :         unsigned int i;
     774                 :            :         const struct burst_info {
     775                 :            :                 uint64_t flags;
     776                 :            :                 const char *output;
     777                 :          0 :         } tx_offload_map[] = {
     778                 :            :                         {RTE_ETH_TX_OFFLOAD_MT_LOCKFREE, " MT lockfree,"},
     779                 :            :                         {RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, " MBUF free disable,"},
     780                 :            :                         {RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
     781                 :            :                         {RTE_ETH_TX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
     782                 :            :                         {RTE_ETH_TX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
     783                 :            :                         {RTE_ETH_TX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
     784                 :            :                         {RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
     785                 :            :                         {RTE_ETH_TX_OFFLOAD_MULTI_SEGS, " Scattered,"}
     786                 :            :         };
     787                 :            : 
     788                 :            :         /* Update Tx offload info */
     789         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
     790         [ #  # ]:          0 :                 if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
     791                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
     792                 :          0 :                                 tx_offload_map[i].output);
     793                 :            :                         ret = 0;
     794                 :          0 :                         break;
     795                 :            :                 }
     796                 :            :         }
     797                 :          0 :         return ret;
     798                 :            : }
     799                 :            : 
     800                 :          0 : static int dpaa_eth_link_update(struct rte_eth_dev *dev,
     801                 :            :                                 int wait_to_complete)
     802                 :            : {
     803                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     804                 :          0 :         struct rte_eth_link *link = &dev->data->dev_link;
     805                 :          0 :         struct fman_if *fif = dev->process_private;
     806                 :            :         struct __fman_if *__fif = container_of(fif, struct __fman_if, __if);
     807                 :            :         int ret, ioctl_version;
     808                 :            :         uint8_t count;
     809                 :            : 
     810                 :          0 :         PMD_INIT_FUNC_TRACE();
     811                 :            : 
     812                 :          0 :         ioctl_version = dpaa_get_ioctl_version_number();
     813                 :            : 
     814         [ #  # ]:          0 :         if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
     815   [ #  #  #  # ]:          0 :             fif->mac_type != fman_offline_internal &&
     816                 :            :             fif->mac_type != fman_onic) {
     817         [ #  # ]:          0 :                 for (count = 0; count <= MAX_REPEAT_TIME; count++) {
     818                 :          0 :                         ret = dpaa_get_link_status(__fif->node_name, link);
     819         [ #  # ]:          0 :                         if (ret)
     820                 :          0 :                                 return ret;
     821   [ #  #  #  # ]:          0 :                         if (link->link_status == RTE_ETH_LINK_DOWN &&
     822                 :            :                             wait_to_complete)
     823                 :            :                                 rte_delay_ms(CHECK_INTERVAL);
     824                 :            :                         else
     825                 :            :                                 break;
     826                 :            :                 }
     827                 :            :         } else {
     828                 :          0 :                 link->link_status = dpaa_intf->valid;
     829         [ #  # ]:          0 :                 if (fif->mac_type == fman_offline_internal ||
     830                 :            :                     fif->mac_type == fman_onic) {
     831                 :            :                         /*Max supported rate for O/H port is 3.75Mpps*/
     832                 :          0 :                         link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
     833                 :          0 :                         link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     834                 :            :                 }
     835                 :            :         }
     836                 :            : 
     837         [ #  # ]:          0 :         if (ioctl_version < 2) {
     838                 :          0 :                 link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
     839                 :          0 :                 link->link_autoneg = RTE_ETH_LINK_AUTONEG;
     840                 :            : 
     841         [ #  # ]:          0 :                 if (fif->mac_type == fman_mac_1g)
     842                 :          0 :                         link->link_speed = RTE_ETH_SPEED_NUM_1G;
     843         [ #  # ]:          0 :                 else if (fif->mac_type == fman_mac_2_5g)
     844                 :          0 :                         link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
     845         [ #  # ]:          0 :                 else if (fif->mac_type == fman_mac_10g)
     846                 :          0 :                         link->link_speed = RTE_ETH_SPEED_NUM_10G;
     847                 :            :                 else
     848                 :          0 :                         DPAA_PMD_ERR("invalid link_speed: %s, %d",
     849                 :            :                                      dpaa_intf->name, fif->mac_type);
     850                 :            :         }
     851                 :            : 
     852         [ #  # ]:          0 :         DPAA_PMD_INFO("Port %d Link is %s", dev->data->port_id,
     853                 :            :                       link->link_status ? "Up" : "Down");
     854                 :          0 :         return 0;
     855                 :            : }
     856                 :            : 
     857                 :          0 : static int dpaa_eth_stats_get(struct rte_eth_dev *dev,
     858                 :            :                                struct rte_eth_stats *stats,
     859                 :            :                                struct eth_queue_stats *qstats __rte_unused)
     860                 :            : {
     861                 :          0 :         PMD_INIT_FUNC_TRACE();
     862                 :            : 
     863                 :          0 :         fman_if_stats_get(dev->process_private, stats);
     864                 :          0 :         return 0;
     865                 :            : }
     866                 :            : 
     867                 :          0 : static int dpaa_eth_stats_reset(struct rte_eth_dev *dev)
     868                 :            : {
     869                 :          0 :         PMD_INIT_FUNC_TRACE();
     870                 :            : 
     871                 :          0 :         fman_if_stats_reset(dev->process_private);
     872                 :          0 :         fman_if_bmi_stats_reset(dev->process_private);
     873                 :            : 
     874                 :          0 :         return 0;
     875                 :            : }
     876                 :            : 
     877                 :            : static int
     878                 :          0 : dpaa_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
     879                 :            :                     unsigned int n)
     880                 :            : {
     881                 :            :         unsigned int i = 0, j, num = RTE_DIM(dpaa_xstats_strings);
     882                 :            :         uint64_t values[sizeof(struct dpaa_if_stats) / 8];
     883                 :            :         unsigned int bmi_count = sizeof(struct dpaa_if_rx_bmi_stats) / 4;
     884                 :            : 
     885         [ #  # ]:          0 :         if (n < num)
     886                 :            :                 return num;
     887                 :            : 
     888         [ #  # ]:          0 :         if (xstats == NULL)
     889                 :            :                 return 0;
     890                 :            : 
     891                 :          0 :         fman_if_stats_get_all(dev->process_private, values,
     892                 :            :                               sizeof(struct dpaa_if_stats) / 8);
     893                 :            : 
     894         [ #  # ]:          0 :         for (i = 0; i < num - (bmi_count - 1); i++) {
     895                 :          0 :                 xstats[i].id = i;
     896                 :          0 :                 xstats[i].value = values[dpaa_xstats_strings[i].offset / 8];
     897                 :            :         }
     898                 :          0 :         fman_if_bmi_stats_get_all(dev->process_private, values);
     899         [ #  # ]:          0 :         for (j = 0; i < num; i++, j++) {
     900                 :          0 :                 xstats[i].id = i;
     901                 :          0 :                 xstats[i].value = values[j];
     902                 :            :         }
     903                 :            : 
     904                 :            :         return i;
     905                 :            : }
     906                 :            : 
     907                 :            : static int
     908                 :          0 : dpaa_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
     909                 :            :                       struct rte_eth_xstat_name *xstats_names,
     910                 :            :                       unsigned int limit)
     911                 :            : {
     912                 :            :         unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
     913                 :            : 
     914         [ #  # ]:          0 :         if (limit < stat_cnt)
     915                 :            :                 return stat_cnt;
     916                 :            : 
     917         [ #  # ]:          0 :         if (xstats_names != NULL)
     918         [ #  # ]:          0 :                 for (i = 0; i < stat_cnt; i++)
     919                 :          0 :                         strlcpy(xstats_names[i].name,
     920                 :            :                                 dpaa_xstats_strings[i].name,
     921                 :            :                                 sizeof(xstats_names[i].name));
     922                 :            : 
     923                 :            :         return stat_cnt;
     924                 :            : }
     925                 :            : 
     926                 :            : static int
     927                 :          0 : dpaa_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
     928                 :            :                       uint64_t *values, unsigned int n)
     929                 :            : {
     930                 :            :         unsigned int i, j, stat_cnt = RTE_DIM(dpaa_xstats_strings);
     931                 :            :         uint64_t values_copy[sizeof(struct dpaa_if_stats) / 8];
     932                 :            :         unsigned int bmi_count = sizeof(struct dpaa_if_rx_bmi_stats) / 4;
     933                 :            : 
     934         [ #  # ]:          0 :         if (!ids) {
     935         [ #  # ]:          0 :                 if (n < stat_cnt)
     936                 :            :                         return stat_cnt;
     937                 :            : 
     938         [ #  # ]:          0 :                 if (!values)
     939                 :            :                         return 0;
     940                 :            : 
     941                 :          0 :                 fman_if_stats_get_all(dev->process_private, values_copy,
     942                 :            :                                       sizeof(struct dpaa_if_stats) / 8);
     943                 :            : 
     944         [ #  # ]:          0 :                 for (i = 0; i < stat_cnt - (bmi_count - 1); i++)
     945                 :          0 :                         values[i] =
     946                 :          0 :                                 values_copy[dpaa_xstats_strings[i].offset / 8];
     947                 :            : 
     948                 :          0 :                 fman_if_bmi_stats_get_all(dev->process_private, values);
     949         [ #  # ]:          0 :                 for (j = 0; i < stat_cnt; i++, j++)
     950                 :          0 :                         values[i] = values_copy[j];
     951                 :            : 
     952                 :            :                 return stat_cnt;
     953                 :            :         }
     954                 :            : 
     955                 :          0 :         dpaa_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
     956                 :            : 
     957         [ #  # ]:          0 :         for (i = 0; i < n; i++) {
     958         [ #  # ]:          0 :                 if (ids[i] >= stat_cnt) {
     959                 :          0 :                         DPAA_PMD_ERR("id value isn't valid");
     960                 :          0 :                         return -1;
     961                 :            :                 }
     962                 :          0 :                 values[i] = values_copy[ids[i]];
     963                 :            :         }
     964                 :          0 :         return n;
     965                 :            : }
     966                 :            : 
     967                 :            : static int
     968                 :          0 : dpaa_xstats_get_names_by_id(
     969                 :            :         struct rte_eth_dev *dev,
     970                 :            :         const uint64_t *ids,
     971                 :            :         struct rte_eth_xstat_name *xstats_names,
     972                 :            :         unsigned int limit)
     973                 :          0 : {
     974                 :            :         unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
     975                 :          0 :         struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
     976                 :            : 
     977         [ #  # ]:          0 :         if (!ids)
     978                 :          0 :                 return dpaa_xstats_get_names(dev, xstats_names, limit);
     979                 :            : 
     980                 :          0 :         dpaa_xstats_get_names(dev, xstats_names_copy, limit);
     981                 :            : 
     982         [ #  # ]:          0 :         for (i = 0; i < limit; i++) {
     983         [ #  # ]:          0 :                 if (ids[i] >= stat_cnt) {
     984                 :          0 :                         DPAA_PMD_ERR("id value isn't valid");
     985                 :          0 :                         return -1;
     986                 :            :                 }
     987                 :          0 :                 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
     988                 :            :         }
     989                 :          0 :         return limit;
     990                 :            : }
     991                 :            : 
     992                 :          0 : static int dpaa_eth_promiscuous_enable(struct rte_eth_dev *dev)
     993                 :            : {
     994                 :          0 :         struct fman_if *fif = dev->process_private;
     995                 :            : 
     996                 :          0 :         PMD_INIT_FUNC_TRACE();
     997                 :            : 
     998         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
     999                 :          0 :                 DPAA_PMD_INFO("Enable promiscuous mode not supported on ONIC "
    1000                 :            :                               "port");
    1001                 :          0 :                 return 0;
    1002                 :            :         }
    1003                 :            : 
    1004                 :          0 :         fman_if_promiscuous_enable(dev->process_private);
    1005                 :            : 
    1006                 :          0 :         return 0;
    1007                 :            : }
    1008                 :            : 
    1009                 :          0 : static int dpaa_eth_promiscuous_disable(struct rte_eth_dev *dev)
    1010                 :            : {
    1011                 :          0 :         struct fman_if *fif = dev->process_private;
    1012                 :            : 
    1013                 :          0 :         PMD_INIT_FUNC_TRACE();
    1014                 :            : 
    1015         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1016                 :          0 :                 DPAA_PMD_INFO("Disable promiscuous mode not supported on ONIC "
    1017                 :            :                               "port");
    1018                 :          0 :                 return 0;
    1019                 :            :         }
    1020                 :            : 
    1021                 :          0 :         fman_if_promiscuous_disable(dev->process_private);
    1022                 :            : 
    1023                 :          0 :         return 0;
    1024                 :            : }
    1025                 :            : 
    1026                 :          0 : static int dpaa_eth_multicast_enable(struct rte_eth_dev *dev)
    1027                 :            : {
    1028                 :          0 :         struct fman_if *fif = dev->process_private;
    1029                 :            : 
    1030                 :          0 :         PMD_INIT_FUNC_TRACE();
    1031                 :            : 
    1032         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1033                 :          0 :                 DPAA_PMD_INFO("Enable Multicast not supported on ONIC port");
    1034                 :          0 :                 return 0;
    1035                 :            :         }
    1036                 :            : 
    1037                 :          0 :         fman_if_set_mcast_filter_table(dev->process_private);
    1038                 :            : 
    1039                 :          0 :         return 0;
    1040                 :            : }
    1041                 :            : 
    1042                 :          0 : static int dpaa_eth_multicast_disable(struct rte_eth_dev *dev)
    1043                 :            : {
    1044                 :          0 :         struct fman_if *fif = dev->process_private;
    1045                 :            : 
    1046                 :          0 :         PMD_INIT_FUNC_TRACE();
    1047                 :            : 
    1048         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1049                 :          0 :                 DPAA_PMD_INFO("Disable Multicast not supported on ONIC port");
    1050                 :          0 :                 return 0;
    1051                 :            :         }
    1052                 :            : 
    1053                 :          0 :         fman_if_reset_mcast_filter_table(dev->process_private);
    1054                 :            : 
    1055                 :          0 :         return 0;
    1056                 :            : }
    1057                 :            : 
    1058                 :          0 : static void dpaa_fman_if_pool_setup(struct rte_eth_dev *dev)
    1059                 :            : {
    1060                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1061                 :            :         struct fman_if_ic_params icp;
    1062                 :            :         uint32_t fd_offset;
    1063                 :            :         uint32_t bp_size;
    1064                 :            : 
    1065                 :            :         memset(&icp, 0, sizeof(icp));
    1066                 :            :         /* set ICEOF for to the default value , which is 0*/
    1067                 :          0 :         icp.iciof = DEFAULT_ICIOF;
    1068                 :          0 :         icp.iceof = DEFAULT_RX_ICEOF;
    1069                 :          0 :         icp.icsz = DEFAULT_ICSZ;
    1070                 :          0 :         fman_if_set_ic_params(dev->process_private, &icp);
    1071                 :            : 
    1072                 :            :         fd_offset = RTE_PKTMBUF_HEADROOM + DPAA_HW_BUF_RESERVE;
    1073                 :          0 :         fman_if_set_fdoff(dev->process_private, fd_offset);
    1074                 :            : 
    1075                 :            :         /* Buffer pool size should be equal to Dataroom Size*/
    1076         [ #  # ]:          0 :         bp_size = rte_pktmbuf_data_room_size(dpaa_intf->bp_info->mp);
    1077                 :            : 
    1078                 :          0 :         fman_if_set_bp(dev->process_private,
    1079                 :            :                        dpaa_intf->bp_info->mp->size,
    1080                 :          0 :                        dpaa_intf->bp_info->bpid, bp_size);
    1081                 :          0 : }
    1082                 :            : 
    1083                 :          0 : static inline int dpaa_eth_rx_queue_bp_check(struct rte_eth_dev *dev,
    1084                 :            :                                              int8_t vsp_id, uint32_t bpid)
    1085                 :            : {
    1086                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1087                 :          0 :         struct fman_if *fif = dev->process_private;
    1088                 :            : 
    1089         [ #  # ]:          0 :         if (fif->num_profiles) {
    1090         [ #  # ]:          0 :                 if (vsp_id < 0)
    1091                 :          0 :                         vsp_id = fif->base_profile_id;
    1092                 :            :         } else {
    1093                 :            :                 if (vsp_id < 0)
    1094                 :            :                         vsp_id = 0;
    1095                 :            :         }
    1096                 :            : 
    1097   [ #  #  #  # ]:          0 :         if (dpaa_intf->vsp_bpid[vsp_id] &&
    1098                 :            :                 bpid != dpaa_intf->vsp_bpid[vsp_id]) {
    1099                 :          0 :                 DPAA_PMD_ERR("Various MPs are assigned to RXQs with same VSP");
    1100                 :            : 
    1101                 :          0 :                 return -1;
    1102                 :            :         }
    1103                 :            : 
    1104                 :            :         return 0;
    1105                 :            : }
    1106                 :            : 
    1107                 :            : static
    1108                 :          0 : int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
    1109                 :            :                             uint16_t nb_desc,
    1110                 :            :                             unsigned int socket_id __rte_unused,
    1111                 :            :                             const struct rte_eth_rxconf *rx_conf,
    1112                 :            :                             struct rte_mempool *mp)
    1113                 :            : {
    1114                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1115                 :          0 :         struct fman_if *fif = dev->process_private;
    1116                 :          0 :         struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_idx];
    1117         [ #  # ]:          0 :         struct qm_mcc_initfq opts = {0};
    1118                 :            :         u32 ch_id, flags = 0;
    1119                 :            :         int ret;
    1120                 :          0 :         u32 buffsz = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
    1121                 :            :         uint32_t max_rx_pktlen;
    1122                 :            : 
    1123                 :          0 :         PMD_INIT_FUNC_TRACE();
    1124                 :            : 
    1125         [ #  # ]:          0 :         if (queue_idx >= dev->data->nb_rx_queues) {
    1126                 :          0 :                 rte_errno = EOVERFLOW;
    1127                 :          0 :                 DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
    1128                 :            :                       (void *)dev, queue_idx, dev->data->nb_rx_queues);
    1129                 :          0 :                 return -rte_errno;
    1130                 :            :         }
    1131                 :            : 
    1132                 :          0 :         rxq->nb_desc = UINT16_MAX;
    1133                 :          0 :         rxq->offloads = rx_conf->offloads;
    1134                 :            : 
    1135                 :          0 :         DPAA_PMD_INFO("Rx queue setup for queue index: %d fq_id (0x%x)",
    1136                 :            :                         queue_idx, rxq->fqid);
    1137                 :            : 
    1138         [ #  # ]:          0 :         if (!fif->num_profiles) {
    1139   [ #  #  #  # ]:          0 :                 if (dpaa_intf->bp_info && dpaa_intf->bp_info->bp &&
    1140         [ #  # ]:          0 :                         dpaa_intf->bp_info->mp != mp) {
    1141                 :          0 :                         DPAA_PMD_WARN("Multiple pools on same interface not"
    1142                 :            :                                       " supported");
    1143                 :          0 :                         return -EINVAL;
    1144                 :            :                 }
    1145                 :            :         } else {
    1146         [ #  # ]:          0 :                 if (dpaa_eth_rx_queue_bp_check(dev, rxq->vsp_id,
    1147                 :          0 :                         DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid)) {
    1148                 :            :                         return -EINVAL;
    1149                 :            :                 }
    1150                 :            :         }
    1151                 :            : 
    1152   [ #  #  #  # ]:          0 :         if (dpaa_intf->bp_info && dpaa_intf->bp_info->bp &&
    1153         [ #  # ]:          0 :             dpaa_intf->bp_info->mp != mp) {
    1154                 :          0 :                 DPAA_PMD_WARN("Multiple pools on same interface not supported");
    1155                 :          0 :                 return -EINVAL;
    1156                 :            :         }
    1157                 :            : 
    1158                 :          0 :         max_rx_pktlen = dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
    1159                 :            :                 VLAN_TAG_SIZE;
    1160                 :            :         /* Max packet can fit in single buffer */
    1161         [ #  # ]:          0 :         if (max_rx_pktlen <= buffsz) {
    1162                 :            :                 ;
    1163         [ #  # ]:          0 :         } else if (dev->data->dev_conf.rxmode.offloads &
    1164                 :            :                         RTE_ETH_RX_OFFLOAD_SCATTER) {
    1165         [ #  # ]:          0 :                 if (max_rx_pktlen > buffsz * DPAA_SGT_MAX_ENTRIES) {
    1166                 :          0 :                         DPAA_PMD_ERR("Maximum Rx packet size %d too big to fit "
    1167                 :            :                                 "MaxSGlist %d",
    1168                 :            :                                 max_rx_pktlen, buffsz * DPAA_SGT_MAX_ENTRIES);
    1169                 :          0 :                         rte_errno = EOVERFLOW;
    1170                 :          0 :                         return -rte_errno;
    1171                 :            :                 }
    1172                 :            :         } else {
    1173                 :          0 :                 DPAA_PMD_WARN("The requested maximum Rx packet size (%u) is"
    1174                 :            :                      " larger than a single mbuf (%u) and scattered"
    1175                 :            :                      " mode has not been requested", max_rx_pktlen, buffsz);
    1176                 :            :         }
    1177                 :            : 
    1178                 :          0 :         dpaa_intf->bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
    1179                 :            : 
    1180                 :            :         /* For shared interface, it's done in kernel, skip.*/
    1181   [ #  #  #  #  :          0 :         if (!fif->is_shared_mac && fif->mac_type != fman_offline_internal &&
                   #  # ]
    1182                 :            :             fif->mac_type != fman_onic)
    1183                 :          0 :                 dpaa_fman_if_pool_setup(dev);
    1184                 :            : 
    1185         [ #  # ]:          0 :         if (fif->num_profiles) {
    1186                 :          0 :                 int8_t vsp_id = rxq->vsp_id;
    1187                 :            : 
    1188         [ #  # ]:          0 :                 if (vsp_id >= 0) {
    1189                 :          0 :                         ret = dpaa_port_vsp_update(dpaa_intf, fmc_q, vsp_id,
    1190                 :          0 :                                         DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid,
    1191                 :            :                                         fif, buffsz + RTE_PKTMBUF_HEADROOM);
    1192         [ #  # ]:          0 :                         if (ret) {
    1193                 :          0 :                                 DPAA_PMD_ERR("dpaa_port_vsp_update failed");
    1194                 :          0 :                                 return ret;
    1195                 :            :                         }
    1196                 :            :                 } else {
    1197                 :          0 :                         DPAA_PMD_INFO("Base profile is associated to"
    1198                 :            :                                 " RXQ fqid:%d", rxq->fqid);
    1199         [ #  # ]:          0 :                         if (fif->is_shared_mac) {
    1200                 :          0 :                                 DPAA_PMD_ERR("Fatal: Base profile is associated"
    1201                 :            :                                              " to shared interface on DPDK.");
    1202                 :          0 :                                 return -EINVAL;
    1203                 :            :                         }
    1204                 :          0 :                         dpaa_intf->vsp_bpid[fif->base_profile_id] =
    1205                 :          0 :                                 DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid;
    1206                 :            :                 }
    1207                 :            :         } else {
    1208                 :          0 :                 dpaa_intf->vsp_bpid[0] =
    1209                 :          0 :                         DPAA_MEMPOOL_TO_POOL_INFO(mp)->bpid;
    1210                 :            :         }
    1211                 :            : 
    1212                 :          0 :         dpaa_intf->valid = 1;
    1213         [ #  # ]:          0 :         if (fif->mac_type != fman_onic)
    1214                 :          0 :                 DPAA_PMD_DEBUG("if:%s sg_on = %d, max_frm =%d", dpaa_intf->name,
    1215                 :            :                                fman_if_get_sg_enable(fif), max_rx_pktlen);
    1216                 :            :         /* checking if push mode only, no error check for now */
    1217         [ #  # ]:          0 :         if (!rxq->is_static &&
    1218         [ #  # ]:          0 :             dpaa_push_mode_max_queue > dpaa_push_queue_idx) {
    1219                 :            :                 struct qman_portal *qp;
    1220                 :            :                 int q_fd;
    1221                 :            : 
    1222                 :          0 :                 dpaa_push_queue_idx++;
    1223                 :          0 :                 opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
    1224                 :          0 :                 opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK |
    1225                 :            :                                    QM_FQCTRL_CTXASTASHING |
    1226                 :            :                                    QM_FQCTRL_PREFERINCACHE;
    1227                 :          0 :                 opts.fqd.context_a.stashing.exclusive = 0;
    1228                 :            :                 /* In multicore scenario stashing becomes a bottleneck on LS1046.
    1229                 :            :                  * So do not enable stashing in this case
    1230                 :            :                  */
    1231         [ #  # ]:          0 :                 if (dpaa_soc_ver() != SVR_LS1046A_FAMILY)
    1232                 :          0 :                         opts.fqd.context_a.stashing.annotation_cl =
    1233                 :            :                                                 DPAA_IF_RX_ANNOTATION_STASH;
    1234                 :          0 :                 opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
    1235                 :          0 :                 opts.fqd.context_a.stashing.context_cl =
    1236                 :            :                                                 DPAA_IF_RX_CONTEXT_STASH;
    1237                 :            : 
    1238                 :            :                 /*Create a channel and associate given queue with the channel*/
    1239                 :          0 :                 qman_alloc_pool_range(&ch_id, 1, 1, 0);
    1240                 :          0 :                 rxq->ch_id = (u16)ch_id;
    1241                 :            : 
    1242                 :          0 :                 opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
    1243                 :          0 :                 opts.fqd.dest.channel = rxq->ch_id;
    1244                 :          0 :                 opts.fqd.dest.wq = DPAA_IF_RX_PRIORITY;
    1245                 :            :                 flags = QMAN_INITFQ_FLAG_SCHED;
    1246                 :            : 
    1247                 :            :                 /* Configure tail drop */
    1248         [ #  # ]:          0 :                 if (dpaa_intf->cgr_rx) {
    1249                 :          0 :                         opts.we_mask |= QM_INITFQ_WE_CGID;
    1250                 :          0 :                         opts.fqd.cgid = dpaa_intf->cgr_rx[queue_idx].cgrid;
    1251                 :          0 :                         opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
    1252                 :            :                 }
    1253                 :          0 :                 ret = qman_init_fq(rxq, flags, &opts);
    1254         [ #  # ]:          0 :                 if (ret) {
    1255                 :          0 :                         DPAA_PMD_ERR("Channel/Q association failed. fqid 0x%x "
    1256                 :            :                                 "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
    1257                 :          0 :                         return ret;
    1258                 :            :                 }
    1259         [ #  # ]:          0 :                 if (dpaa_soc_ver() == SVR_LS1043A_FAMILY) {
    1260                 :          0 :                         rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb_no_prefetch;
    1261                 :            :                 } else {
    1262                 :          0 :                         rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb;
    1263                 :          0 :                         rxq->cb.dqrr_prepare = dpaa_rx_cb_prepare;
    1264                 :            :                 }
    1265                 :            : 
    1266                 :          0 :                 rxq->is_static = true;
    1267                 :            : 
    1268                 :            :                 /* Allocate qman specific portals */
    1269                 :          0 :                 qp = fsl_qman_fq_portal_create(&q_fd);
    1270         [ #  # ]:          0 :                 if (!qp) {
    1271                 :          0 :                         DPAA_PMD_ERR("Unable to alloc fq portal");
    1272                 :          0 :                         return -1;
    1273                 :            :                 }
    1274                 :          0 :                 rxq->qp = qp;
    1275                 :            : 
    1276                 :            :                 /* Set up the device interrupt handler */
    1277         [ #  # ]:          0 :                 if (dev->intr_handle == NULL) {
    1278                 :            :                         struct rte_dpaa_device *dpaa_dev;
    1279                 :          0 :                         struct rte_device *rdev = dev->device;
    1280                 :            : 
    1281                 :          0 :                         dpaa_dev = container_of(rdev, struct rte_dpaa_device,
    1282                 :            :                                                 device);
    1283                 :          0 :                         dev->intr_handle = dpaa_dev->intr_handle;
    1284         [ #  # ]:          0 :                         if (rte_intr_vec_list_alloc(dev->intr_handle,
    1285                 :            :                                         NULL, dpaa_push_mode_max_queue)) {
    1286                 :          0 :                                 DPAA_PMD_ERR("intr_vec alloc failed");
    1287                 :          0 :                                 return -ENOMEM;
    1288                 :            :                         }
    1289         [ #  # ]:          0 :                         if (rte_intr_nb_efd_set(dev->intr_handle,
    1290                 :            :                                         dpaa_push_mode_max_queue))
    1291                 :          0 :                                 return -rte_errno;
    1292                 :            : 
    1293         [ #  # ]:          0 :                         if (rte_intr_max_intr_set(dev->intr_handle,
    1294                 :            :                                         dpaa_push_mode_max_queue))
    1295                 :          0 :                                 return -rte_errno;
    1296                 :            :                 }
    1297                 :            : 
    1298         [ #  # ]:          0 :                 if (rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_EXT))
    1299                 :          0 :                         return -rte_errno;
    1300                 :            : 
    1301         [ #  # ]:          0 :                 if (rte_intr_vec_list_index_set(dev->intr_handle,
    1302                 :            :                                                 queue_idx, queue_idx + 1))
    1303                 :          0 :                         return -rte_errno;
    1304                 :            : 
    1305         [ #  # ]:          0 :                 if (rte_intr_efds_index_set(dev->intr_handle, queue_idx,
    1306                 :            :                                                    q_fd))
    1307                 :          0 :                         return -rte_errno;
    1308                 :            : 
    1309                 :          0 :                 rxq->q_fd = q_fd;
    1310                 :            :         }
    1311                 :          0 :         rxq->bp_array = rte_dpaa_bpid_info;
    1312                 :          0 :         dev->data->rx_queues[queue_idx] = rxq;
    1313                 :            : 
    1314                 :            :         /* configure the CGR size as per the desc size */
    1315         [ #  # ]:          0 :         if (dpaa_intf->cgr_rx) {
    1316                 :          0 :                 struct qm_mcc_initcgr cgr_opts = {0};
    1317                 :            : 
    1318                 :          0 :                 rxq->nb_desc = nb_desc;
    1319                 :            :                 /* Enable tail drop with cgr on this queue */
    1320                 :          0 :                 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, nb_desc, 0);
    1321                 :          0 :                 ret = qman_modify_cgr(dpaa_intf->cgr_rx, 0, &cgr_opts);
    1322         [ #  # ]:          0 :                 if (ret) {
    1323                 :          0 :                         DPAA_PMD_WARN(
    1324                 :            :                                 "rx taildrop modify fail on fqid %d (ret=%d)",
    1325                 :            :                                 rxq->fqid, ret);
    1326                 :            :                 }
    1327                 :            :         }
    1328                 :            : 
    1329                 :            :         /* Enable main queue to receive error packets */
    1330         [ #  # ]:          0 :         if (fif->mac_type != fman_offline_internal &&
    1331         [ #  # ]:          0 :                         fif->mac_type != fman_onic &&
    1332         [ #  # ]:          0 :                         dpaa_enable_recv_err_pkts && !fif->is_shared_mac) {
    1333                 :          0 :                 fman_if_set_err_fqid(fif, rxq->fqid);
    1334                 :            :         }
    1335                 :            : 
    1336                 :            :         return 0;
    1337                 :            : }
    1338                 :            : 
    1339                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_eth_eventq_attach)
    1340                 :            : int
    1341                 :          0 : dpaa_eth_eventq_attach(const struct rte_eth_dev *dev,
    1342                 :            :                 int eth_rx_queue_id,
    1343                 :            :                 u16 ch_id,
    1344                 :            :                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
    1345                 :            : {
    1346                 :            :         int ret;
    1347                 :            :         u32 flags = 0;
    1348                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1349                 :          0 :         struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
    1350                 :          0 :         struct qm_mcc_initfq opts = {0};
    1351                 :            : 
    1352         [ #  # ]:          0 :         if (dpaa_push_mode_max_queue) {
    1353                 :          0 :                 DPAA_PMD_WARN("PUSH mode q and EVENTDEV are not compatible");
    1354                 :          0 :                 DPAA_PMD_WARN("PUSH mode already enabled for first %d queues.",
    1355                 :            :                               dpaa_push_mode_max_queue);
    1356                 :          0 :                 DPAA_PMD_WARN("To disable set DPAA_PUSH_QUEUES_NUMBER to 0");
    1357                 :            :         }
    1358                 :            : 
    1359                 :          0 :         dpaa_poll_queue_default_config(&opts);
    1360                 :            : 
    1361      [ #  #  # ]:          0 :         switch (queue_conf->ev.sched_type) {
    1362                 :          0 :         case RTE_SCHED_TYPE_ATOMIC:
    1363                 :          0 :                 opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
    1364                 :            :                 /* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
    1365                 :            :                  * configuration with HOLD_ACTIVE setting
    1366                 :            :                  */
    1367                 :          0 :                 opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
    1368                 :          0 :                 rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_atomic;
    1369                 :          0 :                 break;
    1370                 :          0 :         case RTE_SCHED_TYPE_ORDERED:
    1371                 :          0 :                 DPAA_PMD_ERR("Ordered queue schedule type is not supported");
    1372                 :          0 :                 return -1;
    1373                 :          0 :         default:
    1374                 :          0 :                 opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
    1375                 :          0 :                 rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_parallel;
    1376                 :          0 :                 break;
    1377                 :            :         }
    1378                 :            : 
    1379                 :          0 :         opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
    1380                 :          0 :         opts.fqd.dest.channel = ch_id;
    1381                 :          0 :         opts.fqd.dest.wq = queue_conf->ev.priority;
    1382                 :            : 
    1383         [ #  # ]:          0 :         if (dpaa_intf->cgr_rx) {
    1384                 :          0 :                 opts.we_mask |= QM_INITFQ_WE_CGID;
    1385                 :          0 :                 opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
    1386                 :          0 :                 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
    1387                 :            :         }
    1388                 :            : 
    1389                 :            :         flags = QMAN_INITFQ_FLAG_SCHED;
    1390                 :            : 
    1391                 :          0 :         ret = qman_init_fq(rxq, flags, &opts);
    1392         [ #  # ]:          0 :         if (ret) {
    1393                 :          0 :                 DPAA_PMD_ERR("Ev-Channel/Q association failed. fqid 0x%x "
    1394                 :            :                                 "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
    1395                 :          0 :                 return ret;
    1396                 :            :         }
    1397                 :            : 
    1398                 :            :         /* copy configuration which needs to be filled during dequeue */
    1399                 :          0 :         memcpy(&rxq->ev, &queue_conf->ev, sizeof(struct rte_event));
    1400                 :          0 :         dev->data->rx_queues[eth_rx_queue_id] = rxq;
    1401                 :            : 
    1402                 :          0 :         return ret;
    1403                 :            : }
    1404                 :            : 
    1405                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpaa_eth_eventq_detach)
    1406                 :            : int
    1407                 :          0 : dpaa_eth_eventq_detach(const struct rte_eth_dev *dev,
    1408                 :            :                 int eth_rx_queue_id)
    1409                 :            : {
    1410                 :          0 :         struct qm_mcc_initfq opts = {0};
    1411                 :            :         int ret;
    1412                 :            :         u32 flags = 0;
    1413                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1414                 :          0 :         struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
    1415                 :            : 
    1416                 :          0 :         qman_retire_fq(rxq, NULL);
    1417                 :          0 :         qman_oos_fq(rxq);
    1418                 :          0 :         ret = qman_init_fq(rxq, flags, &opts);
    1419         [ #  # ]:          0 :         if (ret) {
    1420                 :          0 :                 DPAA_PMD_ERR("detach rx fqid %d failed with ret: %d",
    1421                 :            :                              rxq->fqid, ret);
    1422                 :            :         }
    1423                 :            : 
    1424                 :          0 :         rxq->cb.dqrr_dpdk_cb = NULL;
    1425                 :          0 :         dev->data->rx_queues[eth_rx_queue_id] = NULL;
    1426                 :            : 
    1427                 :          0 :         return 0;
    1428                 :            : }
    1429                 :            : 
    1430                 :            : static
    1431                 :          0 : int dpaa_eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
    1432                 :            :                             uint16_t nb_desc __rte_unused,
    1433                 :            :                 unsigned int socket_id __rte_unused,
    1434                 :            :                 const struct rte_eth_txconf *tx_conf)
    1435                 :            : {
    1436                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1437                 :          0 :         struct qman_fq *txq = &dpaa_intf->tx_queues[queue_idx];
    1438                 :            : 
    1439                 :          0 :         PMD_INIT_FUNC_TRACE();
    1440                 :            : 
    1441                 :          0 :         txq->nb_desc = UINT16_MAX;
    1442                 :          0 :         txq->offloads = tx_conf->offloads;
    1443                 :            : 
    1444         [ #  # ]:          0 :         if (queue_idx >= dev->data->nb_tx_queues) {
    1445                 :          0 :                 rte_errno = EOVERFLOW;
    1446                 :          0 :                 DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
    1447                 :            :                       (void *)dev, queue_idx, dev->data->nb_tx_queues);
    1448                 :          0 :                 return -rte_errno;
    1449                 :            :         }
    1450                 :            : 
    1451                 :          0 :         DPAA_PMD_INFO("Tx queue setup for queue index: %d fq_id (0x%x)",
    1452                 :            :                         queue_idx, txq->fqid);
    1453                 :          0 :         dev->data->tx_queues[queue_idx] = txq;
    1454                 :            : 
    1455                 :          0 :         return 0;
    1456                 :            : }
    1457                 :            : 
    1458                 :            : static int
    1459                 :          0 : dpaa_dev_rx_queue_count(void *rx_queue)
    1460                 :            : {
    1461                 :            :         struct qman_fq *rxq = rx_queue;
    1462                 :          0 :         u32 frm_cnt = 0;
    1463                 :            : 
    1464                 :          0 :         PMD_INIT_FUNC_TRACE();
    1465                 :            : 
    1466         [ #  # ]:          0 :         if (qman_query_fq_frm_cnt(rxq, &frm_cnt) == 0) {
    1467                 :          0 :                 DPAA_PMD_DEBUG("RX frame count for q(%p) is %u",
    1468                 :            :                                rx_queue, frm_cnt);
    1469                 :            :         }
    1470                 :          0 :         return frm_cnt;
    1471                 :            : }
    1472                 :            : 
    1473                 :          0 : static int dpaa_link_down(struct rte_eth_dev *dev)
    1474                 :            : {
    1475                 :          0 :         struct fman_if *fif = dev->process_private;
    1476                 :            :         struct __fman_if *__fif;
    1477                 :            : 
    1478                 :          0 :         PMD_INIT_FUNC_TRACE();
    1479                 :            : 
    1480                 :            :         __fif = container_of(fif, struct __fman_if, __if);
    1481                 :            : 
    1482         [ #  # ]:          0 :         if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
    1483   [ #  #  #  # ]:          0 :             fif->mac_type != fman_offline_internal &&
    1484                 :            :             fif->mac_type != fman_onic)
    1485                 :          0 :                 dpaa_update_link_status(__fif->node_name, RTE_ETH_LINK_DOWN);
    1486                 :            :         else
    1487                 :          0 :                 return dpaa_eth_dev_stop(dev);
    1488                 :          0 :         return 0;
    1489                 :            : }
    1490                 :            : 
    1491                 :          0 : static int dpaa_link_up(struct rte_eth_dev *dev)
    1492                 :            : {
    1493                 :          0 :         struct fman_if *fif = dev->process_private;
    1494                 :            :         struct __fman_if *__fif;
    1495                 :            : 
    1496                 :          0 :         PMD_INIT_FUNC_TRACE();
    1497                 :            : 
    1498                 :            :         __fif = container_of(fif, struct __fman_if, __if);
    1499                 :            : 
    1500         [ #  # ]:          0 :         if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC &&
    1501   [ #  #  #  # ]:          0 :             fif->mac_type != fman_offline_internal &&
    1502                 :            :             fif->mac_type != fman_onic)
    1503                 :          0 :                 dpaa_update_link_status(__fif->node_name, RTE_ETH_LINK_UP);
    1504                 :            :         else
    1505                 :          0 :                 dpaa_eth_dev_start(dev);
    1506                 :          0 :         return 0;
    1507                 :            : }
    1508                 :            : 
    1509                 :            : static int
    1510                 :          0 : dpaa_flow_ctrl_set(struct rte_eth_dev *dev,
    1511                 :            :                    struct rte_eth_fc_conf *fc_conf)
    1512                 :            : {
    1513                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1514                 :            :         struct rte_eth_fc_conf *net_fc;
    1515                 :          0 :         struct fman_if *fm_if = dev->process_private;
    1516                 :            :         int ret;
    1517                 :            : 
    1518                 :          0 :         PMD_INIT_FUNC_TRACE();
    1519                 :            : 
    1520         [ #  # ]:          0 :         if (!(dpaa_intf->fc_conf)) {
    1521                 :          0 :                 dpaa_intf->fc_conf = rte_zmalloc(NULL,
    1522                 :            :                         sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
    1523         [ #  # ]:          0 :                 if (!dpaa_intf->fc_conf) {
    1524                 :          0 :                         DPAA_PMD_ERR("unable to save flow control info");
    1525                 :          0 :                         return -ENOMEM;
    1526                 :            :                 }
    1527                 :            :         }
    1528                 :          0 :         net_fc = dpaa_intf->fc_conf;
    1529                 :            : 
    1530         [ #  # ]:          0 :         if (fc_conf->high_water < fc_conf->low_water) {
    1531                 :          0 :                 DPAA_PMD_ERR("Incorrect Flow Control Configuration");
    1532                 :          0 :                 return -EINVAL;
    1533                 :            :         }
    1534                 :            : 
    1535         [ #  # ]:          0 :         if (fc_conf->mode == RTE_ETH_FC_NONE)
    1536                 :            :                 return 0;
    1537                 :            : 
    1538         [ #  # ]:          0 :         if (fc_conf->mode != RTE_ETH_FC_TX_PAUSE &&
    1539                 :            :                 fc_conf->mode != RTE_ETH_FC_FULL)
    1540                 :          0 :                 goto save_fc;
    1541                 :            : 
    1542                 :          0 :         ret = fman_if_set_fc_threshold(fm_if,
    1543                 :            :                                          fc_conf->high_water,
    1544                 :            :                                          fc_conf->low_water,
    1545                 :          0 :                                          dpaa_intf->bp_info->bpid);
    1546         [ #  # ]:          0 :         if (ret) {
    1547                 :          0 :                 DPAA_PMD_ERR("Set %s's fc on bpid(%d) err(%d)",
    1548                 :            :                                 dev->data->name, dpaa_intf->bp_info->bpid,
    1549                 :            :                                 ret);
    1550                 :            :         }
    1551         [ #  # ]:          0 :         if (fc_conf->pause_time) {
    1552                 :          0 :                 ret = fman_if_set_fc_quanta(fm_if, fc_conf->pause_time);
    1553         [ #  # ]:          0 :                 if (ret) {
    1554                 :          0 :                         DPAA_PMD_ERR("Set %s's fc pause time err(%d)",
    1555                 :            :                                 dev->data->name, ret);
    1556                 :            :                 }
    1557                 :            :         }
    1558                 :            : 
    1559                 :          0 : save_fc:
    1560                 :            :         /* Save the information in dpaa device */
    1561                 :          0 :         net_fc->pause_time = fc_conf->pause_time;
    1562                 :          0 :         net_fc->high_water = fc_conf->high_water;
    1563                 :          0 :         net_fc->low_water = fc_conf->low_water;
    1564                 :          0 :         net_fc->send_xon = fc_conf->send_xon;
    1565                 :          0 :         net_fc->mac_ctrl_frame_fwd = fc_conf->mac_ctrl_frame_fwd;
    1566                 :          0 :         net_fc->mode = fc_conf->mode;
    1567                 :          0 :         net_fc->autoneg = fc_conf->autoneg;
    1568                 :            : 
    1569                 :          0 :         return 0;
    1570                 :            : }
    1571                 :            : 
    1572                 :            : static int
    1573                 :          0 : dpaa_flow_ctrl_get(struct rte_eth_dev *dev,
    1574                 :            :                    struct rte_eth_fc_conf *fc_conf)
    1575                 :            : {
    1576                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1577                 :          0 :         struct rte_eth_fc_conf *net_fc = dpaa_intf->fc_conf;
    1578                 :            :         int ret;
    1579                 :            : 
    1580                 :          0 :         PMD_INIT_FUNC_TRACE();
    1581                 :            : 
    1582         [ #  # ]:          0 :         if (net_fc) {
    1583                 :          0 :                 fc_conf->pause_time = net_fc->pause_time;
    1584                 :          0 :                 fc_conf->high_water = net_fc->high_water;
    1585                 :          0 :                 fc_conf->low_water = net_fc->low_water;
    1586                 :          0 :                 fc_conf->send_xon = net_fc->send_xon;
    1587                 :          0 :                 fc_conf->mac_ctrl_frame_fwd = net_fc->mac_ctrl_frame_fwd;
    1588                 :          0 :                 fc_conf->mode = net_fc->mode;
    1589                 :          0 :                 fc_conf->autoneg = net_fc->autoneg;
    1590                 :          0 :                 return 0;
    1591                 :            :         }
    1592                 :          0 :         ret = fman_if_get_fc_threshold(dev->process_private);
    1593         [ #  # ]:          0 :         if (ret) {
    1594                 :          0 :                 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    1595                 :          0 :                 fc_conf->pause_time =
    1596                 :          0 :                         fman_if_get_fc_quanta(dev->process_private);
    1597                 :            :         } else {
    1598                 :          0 :                 fc_conf->mode = RTE_ETH_FC_NONE;
    1599                 :            :         }
    1600                 :            : 
    1601                 :            :         return 0;
    1602                 :            : }
    1603                 :            : 
    1604                 :            : static int
    1605                 :          0 : dpaa_dev_add_mac_addr(struct rte_eth_dev *dev,
    1606                 :            :                              struct rte_ether_addr *addr,
    1607                 :            :                              uint32_t index,
    1608                 :            :                              __rte_unused uint32_t pool)
    1609                 :            : {
    1610                 :            :         int ret;
    1611                 :          0 :         struct fman_if *fif = dev->process_private;
    1612                 :            : 
    1613                 :          0 :         PMD_INIT_FUNC_TRACE();
    1614                 :            : 
    1615         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal) {
    1616                 :          0 :                 DPAA_PMD_DEBUG("Add MAC Address not supported on O/H port");
    1617                 :          0 :                 return 0;
    1618                 :            :         }
    1619                 :            : 
    1620         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1621                 :          0 :                 DPAA_PMD_INFO("Add MAC Address not supported on ONIC port");
    1622                 :          0 :                 return 0;
    1623                 :            :         }
    1624                 :            : 
    1625                 :          0 :         ret = fman_if_add_mac_addr(dev->process_private,
    1626                 :          0 :                                    addr->addr_bytes, index);
    1627                 :            : 
    1628         [ #  # ]:          0 :         if (ret)
    1629                 :          0 :                 DPAA_PMD_ERR("Adding the MAC ADDR failed: err = %d", ret);
    1630                 :            :         return 0;
    1631                 :            : }
    1632                 :            : 
    1633                 :            : static void
    1634                 :          0 : dpaa_dev_remove_mac_addr(struct rte_eth_dev *dev,
    1635                 :            :                           uint32_t index)
    1636                 :            : {
    1637                 :          0 :         struct fman_if *fif = dev->process_private;
    1638                 :            : 
    1639                 :          0 :         PMD_INIT_FUNC_TRACE();
    1640                 :            : 
    1641         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal) {
    1642                 :          0 :                 DPAA_PMD_DEBUG("Remove MAC Address not supported on O/H port");
    1643                 :          0 :                 return;
    1644                 :            :         }
    1645                 :            : 
    1646         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1647                 :          0 :                 DPAA_PMD_INFO("Remove MAC Address not supported on ONIC port");
    1648                 :          0 :                 return;
    1649                 :            :         }
    1650                 :            : 
    1651                 :          0 :         fman_if_clear_mac_addr(dev->process_private, index);
    1652                 :            : }
    1653                 :            : 
    1654                 :            : static int
    1655                 :          0 : dpaa_dev_set_mac_addr(struct rte_eth_dev *dev,
    1656                 :            :                        struct rte_ether_addr *addr)
    1657                 :            : {
    1658                 :            :         int ret;
    1659                 :          0 :         struct fman_if *fif = dev->process_private;
    1660                 :            : 
    1661                 :          0 :         PMD_INIT_FUNC_TRACE();
    1662                 :            : 
    1663         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal) {
    1664                 :          0 :                 DPAA_PMD_DEBUG("Set MAC Address not supported on O/H port");
    1665                 :          0 :                 return 0;
    1666                 :            :         }
    1667                 :            : 
    1668         [ #  # ]:          0 :         if (fif->mac_type == fman_onic) {
    1669                 :          0 :                 DPAA_PMD_INFO("Set MAC Address not supported on ONIC port");
    1670                 :          0 :                 return 0;
    1671                 :            :         }
    1672                 :            : 
    1673                 :          0 :         ret = fman_if_add_mac_addr(dev->process_private, addr->addr_bytes, 0);
    1674         [ #  # ]:          0 :         if (ret)
    1675                 :          0 :                 DPAA_PMD_ERR("Setting the MAC ADDR failed %d", ret);
    1676                 :            : 
    1677                 :            :         return ret;
    1678                 :            : }
    1679                 :            : 
    1680                 :            : static int
    1681                 :          0 : dpaa_dev_rss_hash_update(struct rte_eth_dev *dev,
    1682                 :            :                          struct rte_eth_rss_conf *rss_conf)
    1683                 :            : {
    1684                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1685                 :            :         struct rte_eth_conf *eth_conf = &data->dev_conf;
    1686                 :            :         int ret;
    1687                 :            : 
    1688                 :          0 :         PMD_INIT_FUNC_TRACE();
    1689                 :            : 
    1690   [ #  #  #  # ]:          0 :         if (!(default_q || fmc_q)) {
    1691                 :          0 :                 ret = dpaa_fm_config(dev, rss_conf->rss_hf);
    1692         [ #  # ]:          0 :                 if (ret) {
    1693                 :          0 :                         DPAA_PMD_ERR("FM port configuration: Failed(%d)", ret);
    1694                 :          0 :                         return ret;
    1695                 :            :                 }
    1696                 :          0 :                 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
    1697                 :            :         } else {
    1698                 :          0 :                 DPAA_PMD_ERR("Function not supported");
    1699                 :          0 :                 return -ENOTSUP;
    1700                 :            :         }
    1701                 :          0 :         return 0;
    1702                 :            : }
    1703                 :            : 
    1704                 :            : static int
    1705                 :          0 : dpaa_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
    1706                 :            :                            struct rte_eth_rss_conf *rss_conf)
    1707                 :            : {
    1708                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1709                 :            :         struct rte_eth_conf *eth_conf = &data->dev_conf;
    1710                 :            : 
    1711                 :            :         /* dpaa does not support rss_key, so length should be 0*/
    1712                 :          0 :         rss_conf->rss_key_len = 0;
    1713                 :          0 :         rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
    1714                 :          0 :         return 0;
    1715                 :            : }
    1716                 :            : 
    1717                 :          0 : static int dpaa_dev_queue_intr_enable(struct rte_eth_dev *dev,
    1718                 :            :                                       uint16_t queue_id)
    1719                 :            : {
    1720                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1721                 :          0 :         struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
    1722                 :            : 
    1723         [ #  # ]:          0 :         if (!rxq->is_static)
    1724                 :            :                 return -EINVAL;
    1725                 :            : 
    1726                 :          0 :         return qman_fq_portal_irqsource_add(rxq->qp, QM_PIRQ_DQRI);
    1727                 :            : }
    1728                 :            : 
    1729                 :          0 : static int dpaa_dev_queue_intr_disable(struct rte_eth_dev *dev,
    1730                 :            :                                        uint16_t queue_id)
    1731                 :            : {
    1732                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1733                 :          0 :         struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
    1734                 :            :         uint32_t temp;
    1735                 :            :         ssize_t temp1;
    1736                 :            : 
    1737         [ #  # ]:          0 :         if (!rxq->is_static)
    1738                 :            :                 return -EINVAL;
    1739                 :            : 
    1740                 :          0 :         qman_fq_portal_irqsource_remove(rxq->qp, ~0);
    1741                 :            : 
    1742                 :          0 :         temp1 = read(rxq->q_fd, &temp, sizeof(temp));
    1743         [ #  # ]:          0 :         if (temp1 != sizeof(temp))
    1744                 :          0 :                 DPAA_PMD_DEBUG("read did not return anything");
    1745                 :            : 
    1746                 :          0 :         qman_fq_portal_thread_irq(rxq->qp);
    1747                 :            : 
    1748                 :          0 :         return 0;
    1749                 :            : }
    1750                 :            : 
    1751                 :            : static void
    1752                 :          0 : dpaa_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    1753                 :            :         struct rte_eth_rxq_info *qinfo)
    1754                 :            : {
    1755                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
    1756                 :            :         struct qman_fq *rxq;
    1757                 :            :         int ret;
    1758                 :            : 
    1759                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    1760                 :            : 
    1761                 :          0 :         qinfo->mp = dpaa_intf->bp_info->mp;
    1762                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    1763                 :          0 :         qinfo->nb_desc = rxq->nb_desc;
    1764                 :            : 
    1765                 :            :         /* Report the HW Rx buffer length to user */
    1766                 :          0 :         ret = fman_if_get_maxfrm(dev->process_private);
    1767         [ #  # ]:          0 :         if (ret > 0)
    1768                 :          0 :                 qinfo->rx_buf_size = ret;
    1769                 :            : 
    1770                 :          0 :         qinfo->conf.rx_free_thresh = 1;
    1771                 :          0 :         qinfo->conf.rx_drop_en = 1;
    1772                 :          0 :         qinfo->conf.rx_deferred_start = 0;
    1773                 :          0 :         qinfo->conf.offloads = rxq->offloads;
    1774                 :          0 : }
    1775                 :            : 
    1776                 :            : static void
    1777                 :          0 : dpaa_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    1778                 :            :         struct rte_eth_txq_info *qinfo)
    1779                 :            : {
    1780                 :            :         struct qman_fq *txq;
    1781                 :            : 
    1782                 :          0 :         txq = dev->data->tx_queues[queue_id];
    1783                 :            : 
    1784                 :          0 :         qinfo->nb_desc = txq->nb_desc;
    1785                 :          0 :         qinfo->conf.tx_thresh.pthresh = 0;
    1786                 :          0 :         qinfo->conf.tx_thresh.hthresh = 0;
    1787                 :          0 :         qinfo->conf.tx_thresh.wthresh = 0;
    1788                 :            : 
    1789                 :          0 :         qinfo->conf.tx_free_thresh = 0;
    1790                 :          0 :         qinfo->conf.tx_rs_thresh = 0;
    1791                 :          0 :         qinfo->conf.offloads = txq->offloads;
    1792                 :          0 :         qinfo->conf.tx_deferred_start = 0;
    1793                 :          0 : }
    1794                 :            : 
    1795                 :            : static struct eth_dev_ops dpaa_devops = {
    1796                 :            :         .dev_configure            = dpaa_eth_dev_configure,
    1797                 :            :         .dev_start                = dpaa_eth_dev_start,
    1798                 :            :         .dev_stop                 = dpaa_eth_dev_stop,
    1799                 :            :         .dev_close                = dpaa_eth_dev_close,
    1800                 :            :         .dev_infos_get            = dpaa_eth_dev_info,
    1801                 :            :         .dev_supported_ptypes_get = dpaa_supported_ptypes_get,
    1802                 :            : 
    1803                 :            :         .rx_queue_setup           = dpaa_eth_rx_queue_setup,
    1804                 :            :         .tx_queue_setup           = dpaa_eth_tx_queue_setup,
    1805                 :            :         .rx_burst_mode_get        = dpaa_dev_rx_burst_mode_get,
    1806                 :            :         .tx_burst_mode_get        = dpaa_dev_tx_burst_mode_get,
    1807                 :            :         .rxq_info_get             = dpaa_rxq_info_get,
    1808                 :            :         .txq_info_get             = dpaa_txq_info_get,
    1809                 :            : 
    1810                 :            :         .flow_ctrl_get            = dpaa_flow_ctrl_get,
    1811                 :            :         .flow_ctrl_set            = dpaa_flow_ctrl_set,
    1812                 :            : 
    1813                 :            :         .link_update              = dpaa_eth_link_update,
    1814                 :            :         .stats_get                = dpaa_eth_stats_get,
    1815                 :            :         .xstats_get               = dpaa_dev_xstats_get,
    1816                 :            :         .xstats_get_by_id         = dpaa_xstats_get_by_id,
    1817                 :            :         .xstats_get_names_by_id   = dpaa_xstats_get_names_by_id,
    1818                 :            :         .xstats_get_names         = dpaa_xstats_get_names,
    1819                 :            :         .xstats_reset             = dpaa_eth_stats_reset,
    1820                 :            :         .stats_reset              = dpaa_eth_stats_reset,
    1821                 :            :         .promiscuous_enable       = dpaa_eth_promiscuous_enable,
    1822                 :            :         .promiscuous_disable      = dpaa_eth_promiscuous_disable,
    1823                 :            :         .allmulticast_enable      = dpaa_eth_multicast_enable,
    1824                 :            :         .allmulticast_disable     = dpaa_eth_multicast_disable,
    1825                 :            :         .mtu_set                  = dpaa_mtu_set,
    1826                 :            :         .dev_set_link_down        = dpaa_link_down,
    1827                 :            :         .dev_set_link_up          = dpaa_link_up,
    1828                 :            :         .mac_addr_add             = dpaa_dev_add_mac_addr,
    1829                 :            :         .mac_addr_remove          = dpaa_dev_remove_mac_addr,
    1830                 :            :         .mac_addr_set             = dpaa_dev_set_mac_addr,
    1831                 :            : 
    1832                 :            :         .fw_version_get           = dpaa_fw_version_get,
    1833                 :            : 
    1834                 :            :         .rx_queue_intr_enable     = dpaa_dev_queue_intr_enable,
    1835                 :            :         .rx_queue_intr_disable    = dpaa_dev_queue_intr_disable,
    1836                 :            :         .rss_hash_update          = dpaa_dev_rss_hash_update,
    1837                 :            :         .rss_hash_conf_get        = dpaa_dev_rss_hash_conf_get,
    1838                 :            :         .timesync_enable          = dpaa_timesync_enable,
    1839                 :            :         .timesync_disable         = dpaa_timesync_disable,
    1840                 :            :         .timesync_read_time       = dpaa_timesync_read_time,
    1841                 :            :         .timesync_write_time      = dpaa_timesync_write_time,
    1842                 :            :         .timesync_adjust_time     = dpaa_timesync_adjust_time,
    1843                 :            :         .timesync_read_rx_timestamp = dpaa_timesync_read_rx_timestamp,
    1844                 :            :         .timesync_read_tx_timestamp = dpaa_timesync_read_tx_timestamp,
    1845                 :            : };
    1846                 :            : 
    1847                 :            : static bool
    1848                 :            : is_device_supported(struct rte_eth_dev *dev, struct rte_dpaa_driver *drv)
    1849                 :            : {
    1850         [ #  # ]:          0 :         if (strcmp(dev->device->driver->name,
    1851                 :            :                    drv->driver.name))
    1852                 :            :                 return false;
    1853                 :            : 
    1854                 :            :         return true;
    1855                 :            : }
    1856                 :            : 
    1857                 :            : static bool
    1858                 :            : is_dpaa_supported(struct rte_eth_dev *dev)
    1859                 :            : {
    1860                 :            :         return is_device_supported(dev, &rte_dpaa_pmd);
    1861                 :            : }
    1862                 :            : 
    1863                 :            : RTE_EXPORT_SYMBOL(rte_pmd_dpaa_set_tx_loopback)
    1864                 :            : int
    1865                 :          0 : rte_pmd_dpaa_set_tx_loopback(uint16_t port, uint8_t on)
    1866                 :            : {
    1867                 :            :         struct rte_eth_dev *dev;
    1868                 :            : 
    1869         [ #  # ]:          0 :         RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
    1870                 :            : 
    1871                 :            :         dev = &rte_eth_devices[port];
    1872                 :            : 
    1873                 :            :         if (!is_dpaa_supported(dev))
    1874                 :            :                 return -ENOTSUP;
    1875                 :            : 
    1876         [ #  # ]:          0 :         if (on)
    1877                 :          0 :                 fman_if_loopback_enable(dev->process_private);
    1878                 :            :         else
    1879                 :          0 :                 fman_if_loopback_disable(dev->process_private);
    1880                 :            : 
    1881                 :            :         return 0;
    1882                 :            : }
    1883                 :            : 
    1884                 :          0 : static int dpaa_fc_set_default(struct dpaa_if *dpaa_intf,
    1885                 :            :                                struct fman_if *fman_intf)
    1886                 :            : {
    1887                 :            :         struct rte_eth_fc_conf *fc_conf;
    1888                 :            :         int ret;
    1889                 :            : 
    1890                 :          0 :         PMD_INIT_FUNC_TRACE();
    1891                 :            : 
    1892         [ #  # ]:          0 :         if (!(dpaa_intf->fc_conf)) {
    1893                 :          0 :                 dpaa_intf->fc_conf = rte_zmalloc(NULL,
    1894                 :            :                         sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
    1895         [ #  # ]:          0 :                 if (!dpaa_intf->fc_conf) {
    1896                 :          0 :                         DPAA_PMD_ERR("unable to save flow control info");
    1897                 :          0 :                         return -ENOMEM;
    1898                 :            :                 }
    1899                 :            :         }
    1900                 :          0 :         fc_conf = dpaa_intf->fc_conf;
    1901                 :          0 :         ret = fman_if_get_fc_threshold(fman_intf);
    1902         [ #  # ]:          0 :         if (ret) {
    1903                 :          0 :                 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    1904                 :          0 :                 fc_conf->pause_time = fman_if_get_fc_quanta(fman_intf);
    1905                 :            :         } else {
    1906                 :          0 :                 fc_conf->mode = RTE_ETH_FC_NONE;
    1907                 :            :         }
    1908                 :            : 
    1909                 :            :         return 0;
    1910                 :            : }
    1911                 :            : 
    1912                 :            : /* Initialise an Rx FQ */
    1913                 :          0 : static int dpaa_rx_queue_init(struct qman_fq *fq, struct qman_cgr *cgr_rx,
    1914                 :            :                               uint32_t fqid)
    1915                 :            : {
    1916                 :          0 :         struct qm_mcc_initfq opts = {0};
    1917                 :            :         int ret;
    1918                 :            :         u32 flags = QMAN_FQ_FLAG_NO_ENQUEUE;
    1919                 :          0 :         struct qm_mcc_initcgr cgr_opts = {
    1920                 :            :                 .we_mask = QM_CGR_WE_CS_THRES |
    1921                 :            :                                 QM_CGR_WE_CSTD_EN |
    1922                 :            :                                 QM_CGR_WE_MODE,
    1923                 :            :                 .cgr = {
    1924                 :            :                         .cstd_en = QM_CGR_EN,
    1925                 :            :                         .mode = QMAN_CGR_MODE_FRAME
    1926                 :            :                 }
    1927                 :            :         };
    1928                 :            : 
    1929   [ #  #  #  # ]:          0 :         if (fmc_q || default_q) {
    1930                 :            :                 ret = qman_reserve_fqid(fqid);
    1931         [ #  # ]:          0 :                 if (ret) {
    1932                 :          0 :                         DPAA_PMD_ERR("reserve rx fqid 0x%x failed, ret: %d",
    1933                 :            :                                      fqid, ret);
    1934                 :          0 :                         return -EINVAL;
    1935                 :            :                 }
    1936                 :            :         }
    1937                 :            : 
    1938                 :          0 :         DPAA_PMD_DEBUG("creating rx fq %p, fqid 0x%x", fq, fqid);
    1939                 :          0 :         ret = qman_create_fq(fqid, flags, fq);
    1940         [ #  # ]:          0 :         if (ret) {
    1941                 :          0 :                 DPAA_PMD_ERR("create rx fqid 0x%x failed with ret: %d",
    1942                 :            :                         fqid, ret);
    1943                 :          0 :                 return ret;
    1944                 :            :         }
    1945                 :          0 :         fq->is_static = false;
    1946                 :            : 
    1947                 :          0 :         dpaa_poll_queue_default_config(&opts);
    1948                 :            : 
    1949         [ #  # ]:          0 :         if (cgr_rx) {
    1950                 :            :                 /* Enable tail drop with cgr on this queue */
    1951                 :          0 :                 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, td_threshold, 0);
    1952                 :          0 :                 cgr_rx->cb = NULL;
    1953                 :          0 :                 ret = qman_create_cgr(cgr_rx, QMAN_CGR_FLAG_USE_INIT,
    1954                 :            :                                       &cgr_opts);
    1955         [ #  # ]:          0 :                 if (ret) {
    1956                 :          0 :                         DPAA_PMD_WARN(
    1957                 :            :                                 "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
    1958                 :            :                                 fq->fqid, ret);
    1959                 :          0 :                         goto without_cgr;
    1960                 :            :                 }
    1961                 :          0 :                 opts.we_mask |= QM_INITFQ_WE_CGID;
    1962                 :          0 :                 opts.fqd.cgid = cgr_rx->cgrid;
    1963                 :          0 :                 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
    1964                 :            :         }
    1965                 :          0 : without_cgr:
    1966                 :          0 :         ret = qman_init_fq(fq, 0, &opts);
    1967         [ #  # ]:          0 :         if (ret)
    1968                 :          0 :                 DPAA_PMD_ERR("init rx fqid 0x%x failed with ret:%d", fqid, ret);
    1969                 :            :         return ret;
    1970                 :            : }
    1971                 :            : 
    1972                 :          0 : uint8_t fm_default_vsp_id(struct fman_if *fif)
    1973                 :            : {
    1974                 :            :         /* Avoid being same as base profile which could be used
    1975                 :            :          * for kernel interface of shared mac.
    1976                 :            :          */
    1977         [ #  # ]:          0 :         if (fif->base_profile_id)
    1978                 :            :                 return 0;
    1979                 :            :         else
    1980                 :          0 :                 return DPAA_DEFAULT_RXQ_VSP_ID;
    1981                 :            : }
    1982                 :            : 
    1983                 :            : /* Initialise a Tx FQ */
    1984                 :          0 : static int dpaa_tx_queue_init(struct qman_fq *fq,
    1985                 :            :                               struct fman_if *fman_intf,
    1986                 :            :                               struct qman_cgr *cgr_tx)
    1987                 :            : {
    1988                 :          0 :         struct qm_mcc_initfq opts = {0};
    1989                 :          0 :         struct qm_mcc_initcgr cgr_opts = {
    1990                 :            :                 .we_mask = QM_CGR_WE_CS_THRES |
    1991                 :            :                                 QM_CGR_WE_CSTD_EN |
    1992                 :            :                                 QM_CGR_WE_MODE,
    1993                 :            :                 .cgr = {
    1994                 :            :                         .cstd_en = QM_CGR_EN,
    1995                 :            :                         .mode = QMAN_CGR_MODE_FRAME
    1996                 :            :                 }
    1997                 :            :         };
    1998                 :            :         int ret;
    1999                 :            : 
    2000                 :          0 :         ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
    2001                 :            :                              QMAN_FQ_FLAG_TO_DCPORTAL, fq);
    2002         [ #  # ]:          0 :         if (ret) {
    2003                 :          0 :                 DPAA_PMD_ERR("create tx fq failed with ret: %d", ret);
    2004                 :          0 :                 return ret;
    2005                 :            :         }
    2006                 :          0 :         opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
    2007                 :            :                        QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA;
    2008                 :          0 :         opts.fqd.dest.channel = fman_intf->tx_channel_id;
    2009                 :          0 :         opts.fqd.dest.wq = DPAA_IF_TX_PRIORITY;
    2010                 :          0 :         opts.fqd.fq_ctrl = QM_FQCTRL_PREFERINCACHE;
    2011                 :          0 :         opts.fqd.context_b = 0;
    2012         [ #  # ]:          0 :         if (dpaa_ieee_1588) {
    2013                 :          0 :                 opts.fqd.context_a.lo = 0;
    2014                 :          0 :                 opts.fqd.context_a.hi =
    2015                 :          0 :                         fman_intf->fman->dealloc_bufs_mask_hi;
    2016                 :            :         } else {
    2017                 :            :                 /* no tx-confirmation */
    2018                 :          0 :                 opts.fqd.context_a.lo =
    2019                 :          0 :                         fman_intf->fman->dealloc_bufs_mask_lo;
    2020                 :          0 :                 opts.fqd.context_a.hi =
    2021                 :          0 :                         DPAA_FQD_CTX_A_OVERRIDE_FQ |
    2022                 :          0 :                         fman_intf->fman->dealloc_bufs_mask_hi;
    2023                 :            :         }
    2024                 :            : 
    2025         [ #  # ]:          0 :         if (fman_intf->fman->ip_rev >= FMAN_V3)
    2026                 :            :                 /* Set B0V bit in contextA to set ASPID to 0 */
    2027                 :          0 :                 opts.fqd.context_a.hi |= DPAA_FQD_CTX_A_B0_FIELD_VALID;
    2028                 :            : 
    2029         [ #  # ]:          0 :         if (fman_intf->mac_type == fman_offline_internal ||
    2030                 :            :             fman_intf->mac_type == fman_onic) {
    2031                 :          0 :                 opts.fqd.context_a.lo |= DPAA_FQD_CTX_A2_VSPE_BIT;
    2032                 :          0 :                 opts.fqd.context_b = fm_default_vsp_id(fman_intf) <<
    2033                 :            :                                      DPAA_FQD_CTX_B_SHIFT_BITS;
    2034                 :            :         }
    2035                 :            : 
    2036                 :          0 :         DPAA_PMD_DEBUG("init tx fq %p, fqid 0x%x", fq, fq->fqid);
    2037                 :            : 
    2038         [ #  # ]:          0 :         if (cgr_tx) {
    2039                 :            :                 /* Enable tail drop with cgr on this queue */
    2040                 :          0 :                 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres,
    2041                 :            :                                       td_tx_threshold, 0);
    2042                 :          0 :                 cgr_tx->cb = NULL;
    2043                 :          0 :                 ret = qman_create_cgr(cgr_tx, QMAN_CGR_FLAG_USE_INIT,
    2044                 :            :                                       &cgr_opts);
    2045         [ #  # ]:          0 :                 if (ret) {
    2046                 :          0 :                         DPAA_PMD_WARN(
    2047                 :            :                                 "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
    2048                 :            :                                 fq->fqid, ret);
    2049                 :          0 :                         goto without_cgr;
    2050                 :            :                 }
    2051                 :          0 :                 opts.we_mask |= QM_INITFQ_WE_CGID;
    2052                 :          0 :                 opts.fqd.cgid = cgr_tx->cgrid;
    2053                 :          0 :                 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
    2054                 :          0 :                 DPAA_PMD_DEBUG("Tx FQ tail drop enabled, threshold = %d",
    2055                 :            :                                 td_tx_threshold);
    2056                 :            :         }
    2057                 :          0 : without_cgr:
    2058                 :          0 :         ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
    2059         [ #  # ]:          0 :         if (ret)
    2060                 :          0 :                 DPAA_PMD_ERR("init tx fqid 0x%x failed %d", fq->fqid, ret);
    2061                 :            :         return ret;
    2062                 :            : }
    2063                 :            : 
    2064                 :            : static int
    2065                 :          0 : dpaa_tx_conf_queue_init(struct qman_fq *fq)
    2066                 :            : {
    2067                 :          0 :         struct qm_mcc_initfq opts = {0};
    2068                 :            :         int ret;
    2069                 :            : 
    2070                 :          0 :         PMD_INIT_FUNC_TRACE();
    2071                 :            : 
    2072                 :          0 :         ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID, fq);
    2073         [ #  # ]:          0 :         if (ret) {
    2074                 :          0 :                 DPAA_PMD_ERR("create Tx_conf failed with ret: %d", ret);
    2075                 :          0 :                 return ret;
    2076                 :            :         }
    2077                 :            : 
    2078                 :          0 :         opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL;
    2079                 :          0 :         opts.fqd.dest.wq = DPAA_IF_DEBUG_PRIORITY;
    2080                 :          0 :         ret = qman_init_fq(fq, 0, &opts);
    2081         [ #  # ]:          0 :         if (ret)
    2082                 :          0 :                 DPAA_PMD_ERR("init Tx_conf fqid %d failed with ret: %d",
    2083                 :            :                         fq->fqid, ret);
    2084                 :            :         return ret;
    2085                 :            : }
    2086                 :            : 
    2087                 :            : #if defined(RTE_LIBRTE_DPAA_DEBUG_DRIVER)
    2088                 :            : /* Initialise a DEBUG FQ ([rt]x_error, rx_default) */
    2089                 :            : static int dpaa_def_queue_init(struct qman_fq *fq, uint32_t fqid)
    2090                 :            : {
    2091                 :            :         struct qm_mcc_initfq opts = {0};
    2092                 :            :         int ret;
    2093                 :            : 
    2094                 :            :         PMD_INIT_FUNC_TRACE();
    2095                 :            : 
    2096                 :            :         ret = qman_reserve_fqid(fqid);
    2097                 :            :         if (ret) {
    2098                 :            :                 DPAA_PMD_ERR("Reserve fqid %d failed with ret: %d",
    2099                 :            :                         fqid, ret);
    2100                 :            :                 return -EINVAL;
    2101                 :            :         }
    2102                 :            :         /* "map" this Rx FQ to one of the interfaces Tx FQID */
    2103                 :            :         DPAA_PMD_DEBUG("Creating fq %p, fqid %d", fq, fqid);
    2104                 :            :         ret = qman_create_fq(fqid, QMAN_FQ_FLAG_NO_ENQUEUE, fq);
    2105                 :            :         if (ret) {
    2106                 :            :                 DPAA_PMD_ERR("create fqid %d failed with ret: %d",
    2107                 :            :                         fqid, ret);
    2108                 :            :                 return ret;
    2109                 :            :         }
    2110                 :            :         opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL;
    2111                 :            :         opts.fqd.dest.wq = DPAA_IF_DEBUG_PRIORITY;
    2112                 :            :         ret = qman_init_fq(fq, 0, &opts);
    2113                 :            :         if (ret)
    2114                 :            :                 DPAA_PMD_ERR("init fqid %d failed with ret: %d",
    2115                 :            :                             fqid, ret);
    2116                 :            :         return ret;
    2117                 :            : }
    2118                 :            : #endif
    2119                 :            : 
    2120                 :            : /* Initialise a network interface */
    2121                 :            : static int
    2122                 :          0 : dpaa_dev_init_secondary(struct rte_eth_dev *eth_dev)
    2123                 :            : {
    2124                 :            :         struct rte_dpaa_device *dpaa_device;
    2125                 :            :         struct fm_eth_port_cfg *cfg;
    2126                 :            :         struct dpaa_if *dpaa_intf;
    2127                 :            :         struct fman_if *fman_intf;
    2128                 :            :         int dev_id;
    2129                 :            : 
    2130                 :          0 :         PMD_INIT_FUNC_TRACE();
    2131                 :            : 
    2132                 :          0 :         dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
    2133                 :          0 :         dev_id = dpaa_device->id.dev_id;
    2134                 :          0 :         cfg = dpaa_get_eth_port_cfg(dev_id);
    2135                 :          0 :         fman_intf = cfg->fman_if;
    2136                 :          0 :         eth_dev->process_private = fman_intf;
    2137                 :            : 
    2138                 :            :         /* Plugging of UCODE burst API not supported in Secondary */
    2139                 :          0 :         dpaa_intf = eth_dev->data->dev_private;
    2140                 :          0 :         eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
    2141         [ #  # ]:          0 :         if (dpaa_intf->cgr_tx)
    2142                 :          0 :                 eth_dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
    2143                 :            :         else
    2144                 :          0 :                 eth_dev->tx_pkt_burst = dpaa_eth_queue_tx;
    2145                 :            : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
    2146                 :          0 :         qman_set_fq_lookup_table(
    2147                 :          0 :                 dpaa_intf->rx_queues->qman_fq_lookup_table);
    2148                 :            : #endif
    2149                 :            : 
    2150                 :          0 :         return 0;
    2151                 :            : }
    2152                 :            : 
    2153                 :            : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
    2154                 :            : static int
    2155                 :            : dpaa_error_queue_init(struct dpaa_if *dpaa_intf,
    2156                 :            :         struct fman_if *fman_intf)
    2157                 :            : {
    2158                 :            :         int i, ret;
    2159                 :            :         struct qman_fq *err_queues = dpaa_intf->debug_queues;
    2160                 :            :         uint32_t err_fqid = 0;
    2161                 :            : 
    2162                 :            :         if (fman_intf->is_shared_mac) {
    2163                 :            :                 DPAA_PMD_DEBUG("Shared MAC's err queues are handled in kernel");
    2164                 :            :                 return 0;
    2165                 :            :         }
    2166                 :            : 
    2167                 :            :         for (i = 0; i < DPAA_DEBUG_FQ_MAX_NUM; i++) {
    2168                 :            :                 if (i == DPAA_DEBUG_FQ_RX_ERROR)
    2169                 :            :                         err_fqid = fman_intf->fqid_rx_err;
    2170                 :            :                 else if (i == DPAA_DEBUG_FQ_TX_ERROR)
    2171                 :            :                         err_fqid = fman_intf->fqid_tx_err;
    2172                 :            :                 else
    2173                 :            :                         continue;
    2174                 :            :                 ret = dpaa_def_queue_init(&err_queues[i], err_fqid);
    2175                 :            :                 if (ret) {
    2176                 :            :                         DPAA_PMD_ERR("DPAA %s ERROR queue init failed!",
    2177                 :            :                                 i == DPAA_DEBUG_FQ_RX_ERROR ?
    2178                 :            :                                 "RX" : "TX");
    2179                 :            :                         return ret;
    2180                 :            :                 }
    2181                 :            :                 err_queues[i].dpaa_intf = dpaa_intf;
    2182                 :            :         }
    2183                 :            : 
    2184                 :            :         return 0;
    2185                 :            : }
    2186                 :            : #endif
    2187                 :            : 
    2188                 :            : static int
    2189                 :          0 : check_devargs_handler(__rte_unused const char *key, const char *value,
    2190                 :            :                       __rte_unused void *opaque)
    2191                 :            : {
    2192         [ #  # ]:          0 :         if (strcmp(value, "1"))
    2193                 :          0 :                 return -1;
    2194                 :            : 
    2195                 :            :         return 0;
    2196                 :            : }
    2197                 :            : 
    2198                 :            : static int
    2199                 :          0 : dpaa_get_devargs(struct rte_devargs *devargs, const char *key)
    2200                 :            : {
    2201                 :            :         struct rte_kvargs *kvlist;
    2202                 :            : 
    2203         [ #  # ]:          0 :         if (!devargs)
    2204                 :            :                 return 0;
    2205                 :            : 
    2206                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
    2207         [ #  # ]:          0 :         if (!kvlist)
    2208                 :            :                 return 0;
    2209                 :            : 
    2210         [ #  # ]:          0 :         if (!rte_kvargs_count(kvlist, key)) {
    2211                 :          0 :                 rte_kvargs_free(kvlist);
    2212                 :          0 :                 return 0;
    2213                 :            :         }
    2214                 :            : 
    2215         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist, key,
    2216                 :            :                                check_devargs_handler, NULL) < 0) {
    2217                 :          0 :                 rte_kvargs_free(kvlist);
    2218                 :          0 :                 return 0;
    2219                 :            :         }
    2220                 :          0 :         rte_kvargs_free(kvlist);
    2221                 :            : 
    2222                 :          0 :         return 1;
    2223                 :            : }
    2224                 :            : 
    2225                 :            : /* Initialise a network interface */
    2226                 :            : static int
    2227                 :          0 : dpaa_dev_init(struct rte_eth_dev *eth_dev)
    2228                 :            : {
    2229                 :            :         int num_rx_fqs, fqid;
    2230                 :            :         int loop, ret = 0;
    2231                 :            :         int dev_id;
    2232                 :            :         struct rte_dpaa_device *dpaa_device;
    2233                 :            :         struct dpaa_if *dpaa_intf;
    2234                 :            :         struct fm_eth_port_cfg *cfg;
    2235                 :            :         struct fman_if *fman_intf;
    2236                 :            :         struct fman_if_bpool *bp, *tmp_bp;
    2237                 :            :         uint32_t cgrid[DPAA_MAX_NUM_PCD_QUEUES];
    2238                 :            :         uint32_t cgrid_tx[MAX_DPAA_CORES];
    2239                 :            :         uint32_t dev_rx_fqids[DPAA_MAX_NUM_PCD_QUEUES];
    2240                 :            :         int8_t dev_vspids[DPAA_MAX_NUM_PCD_QUEUES];
    2241                 :            :         int8_t vsp_id = -1;
    2242                 :          0 :         struct rte_device *dev = eth_dev->device;
    2243                 :            : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
    2244                 :            :         char *penv;
    2245                 :            : #endif
    2246                 :            : 
    2247                 :          0 :         PMD_INIT_FUNC_TRACE();
    2248                 :            : 
    2249                 :          0 :         dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
    2250                 :          0 :         dev_id = dpaa_device->id.dev_id;
    2251                 :          0 :         dpaa_intf = eth_dev->data->dev_private;
    2252                 :          0 :         cfg = dpaa_get_eth_port_cfg(dev_id);
    2253                 :          0 :         fman_intf = cfg->fman_if;
    2254                 :            : 
    2255                 :          0 :         dpaa_intf->name = dpaa_device->name;
    2256                 :            : 
    2257                 :            :         /* save fman_if & cfg in the interface structure */
    2258                 :          0 :         eth_dev->process_private = fman_intf;
    2259                 :          0 :         dpaa_intf->ifid = dev_id;
    2260                 :          0 :         dpaa_intf->cfg = cfg;
    2261                 :            : 
    2262         [ #  # ]:          0 :         if (dpaa_get_devargs(dev->devargs, DRIVER_IEEE1588))
    2263                 :          0 :                 dpaa_ieee_1588 = 1;
    2264                 :            : 
    2265         [ #  # ]:          0 :         if (dpaa_get_devargs(dev->devargs, DRIVER_RECV_ERR_PKTS))
    2266                 :          0 :                 dpaa_enable_recv_err_pkts = 1;
    2267                 :            : 
    2268                 :            :         memset((char *)dev_rx_fqids, 0,
    2269                 :            :                 sizeof(uint32_t) * DPAA_MAX_NUM_PCD_QUEUES);
    2270                 :            : 
    2271                 :            :         memset(dev_vspids, -1, DPAA_MAX_NUM_PCD_QUEUES);
    2272                 :            : 
    2273                 :            :         /* Initialize Rx FQ's */
    2274         [ #  # ]:          0 :         if (default_q) {
    2275                 :            :                 num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
    2276         [ #  # ]:          0 :         } else if (fmc_q) {
    2277                 :          0 :                 num_rx_fqs = dpaa_port_fmc_init(fman_intf, dev_rx_fqids,
    2278                 :            :                                                 dev_vspids,
    2279                 :            :                                                 DPAA_MAX_NUM_PCD_QUEUES);
    2280         [ #  # ]:          0 :                 if (num_rx_fqs < 0) {
    2281                 :          0 :                         DPAA_PMD_ERR("%s FMC initializes failed!",
    2282                 :            :                                 dpaa_intf->name);
    2283                 :          0 :                         goto free_rx;
    2284                 :            :                 }
    2285         [ #  # ]:          0 :                 if (!num_rx_fqs) {
    2286         [ #  # ]:          0 :                         if (fman_intf->mac_type == fman_offline_internal ||
    2287                 :            :                             fman_intf->mac_type == fman_onic) {
    2288                 :            :                                 ret = -ENODEV;
    2289                 :          0 :                                 goto free_rx;
    2290                 :            :                         }
    2291                 :          0 :                         DPAA_PMD_WARN("%s is not configured by FMC.",
    2292                 :            :                                 dpaa_intf->name);
    2293                 :            :                 }
    2294                 :            :         } else {
    2295                 :            :                 /* FMCLESS mode, load balance to multiple cores.*/
    2296                 :          0 :                 num_rx_fqs = rte_lcore_count();
    2297                 :            :         }
    2298                 :            : 
    2299                 :            :         /* Each device can not have more than DPAA_MAX_NUM_PCD_QUEUES RX
    2300                 :            :          * queues.
    2301                 :            :          */
    2302         [ #  # ]:          0 :         if (num_rx_fqs > DPAA_MAX_NUM_PCD_QUEUES) {
    2303                 :          0 :                 DPAA_PMD_ERR("Invalid number of RX queues(%d)", num_rx_fqs);
    2304                 :          0 :                 return -EINVAL;
    2305                 :            :         }
    2306                 :            : 
    2307         [ #  # ]:          0 :         if (num_rx_fqs > 0) {
    2308                 :          0 :                 dpaa_intf->rx_queues = rte_zmalloc(NULL,
    2309                 :            :                         sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
    2310         [ #  # ]:          0 :                 if (!dpaa_intf->rx_queues) {
    2311                 :          0 :                         DPAA_PMD_ERR("Failed to alloc mem for RX queues");
    2312                 :          0 :                         return -ENOMEM;
    2313                 :            :                 }
    2314                 :            :         } else {
    2315                 :          0 :                 dpaa_intf->rx_queues = NULL;
    2316                 :            :         }
    2317                 :            : 
    2318                 :            :         memset(cgrid, 0, sizeof(cgrid));
    2319                 :            :         memset(cgrid_tx, 0, sizeof(cgrid_tx));
    2320                 :            : 
    2321                 :            :         /* if DPAA_TX_TAILDROP_THRESHOLD is set, use that value; if 0, it means
    2322                 :            :          * Tx tail drop is disabled.
    2323                 :            :          */
    2324         [ #  # ]:          0 :         if (getenv("DPAA_TX_TAILDROP_THRESHOLD")) {
    2325                 :          0 :                 td_tx_threshold = atoi(getenv("DPAA_TX_TAILDROP_THRESHOLD"));
    2326                 :          0 :                 DPAA_PMD_DEBUG("Tail drop threshold env configured: %u",
    2327                 :            :                                td_tx_threshold);
    2328                 :            :                 /* if a very large value is being configured */
    2329         [ #  # ]:          0 :                 if (td_tx_threshold > UINT16_MAX)
    2330                 :          0 :                         td_tx_threshold = CGR_RX_PERFQ_THRESH;
    2331                 :            :         }
    2332                 :            : 
    2333                 :            : #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
    2334                 :            :         penv = getenv("DPAA_DISPLAY_FRAME_AND_PARSER_RESULT");
    2335                 :            :         if (penv)
    2336                 :            :                 dpaa_force_display_frame_set(atoi(penv));
    2337                 :            : #endif
    2338                 :            : 
    2339                 :            :         /* If congestion control is enabled globally*/
    2340   [ #  #  #  # ]:          0 :         if (num_rx_fqs > 0 && td_threshold) {
    2341                 :          0 :                 dpaa_intf->cgr_rx = rte_zmalloc(NULL,
    2342                 :            :                         sizeof(struct qman_cgr) * num_rx_fqs, MAX_CACHELINE);
    2343         [ #  # ]:          0 :                 if (!dpaa_intf->cgr_rx) {
    2344                 :          0 :                         DPAA_PMD_ERR("Failed to alloc mem for cgr_rx");
    2345                 :            :                         ret = -ENOMEM;
    2346                 :          0 :                         goto free_rx;
    2347                 :            :                 }
    2348                 :            : 
    2349                 :          0 :                 ret = qman_alloc_cgrid_range(&cgrid[0], num_rx_fqs, 1, 0);
    2350         [ #  # ]:          0 :                 if (ret != num_rx_fqs) {
    2351                 :          0 :                         DPAA_PMD_WARN("insufficient CGRIDs available");
    2352                 :            :                         ret = -EINVAL;
    2353                 :          0 :                         goto free_rx;
    2354                 :            :                 }
    2355                 :            :         } else {
    2356                 :          0 :                 dpaa_intf->cgr_rx = NULL;
    2357                 :            :         }
    2358                 :            : 
    2359   [ #  #  #  # ]:          0 :         if (!fmc_q && !default_q) {
    2360                 :          0 :                 ret = qman_alloc_fqid_range(dev_rx_fqids, num_rx_fqs,
    2361                 :            :                                             num_rx_fqs, 0);
    2362         [ #  # ]:          0 :                 if (ret < 0) {
    2363                 :          0 :                         DPAA_PMD_ERR("Failed to alloc rx fqid's");
    2364                 :          0 :                         goto free_rx;
    2365                 :            :                 }
    2366                 :            :         }
    2367                 :            : 
    2368         [ #  # ]:          0 :         for (loop = 0; loop < num_rx_fqs; loop++) {
    2369         [ #  # ]:          0 :                 if (default_q)
    2370                 :          0 :                         fqid = cfg->rx_def;
    2371                 :            :                 else
    2372                 :          0 :                         fqid = dev_rx_fqids[loop];
    2373                 :            : 
    2374                 :          0 :                 vsp_id = dev_vspids[loop];
    2375                 :            : 
    2376         [ #  # ]:          0 :                 if (dpaa_intf->cgr_rx)
    2377                 :          0 :                         dpaa_intf->cgr_rx[loop].cgrid = cgrid[loop];
    2378                 :            : 
    2379         [ #  # ]:          0 :                 ret = dpaa_rx_queue_init(&dpaa_intf->rx_queues[loop],
    2380                 :          0 :                         dpaa_intf->cgr_rx ? &dpaa_intf->cgr_rx[loop] : NULL,
    2381                 :            :                         fqid);
    2382         [ #  # ]:          0 :                 if (ret)
    2383                 :          0 :                         goto free_rx;
    2384                 :          0 :                 dpaa_intf->rx_queues[loop].vsp_id = vsp_id;
    2385                 :          0 :                 dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
    2386                 :            :         }
    2387                 :          0 :         dpaa_intf->nb_rx_queues = num_rx_fqs;
    2388                 :            : 
    2389                 :            :         /* Initialise Tx FQs.free_rx Have as many Tx FQ's as number of cores */
    2390                 :          0 :         dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
    2391                 :            :                 MAX_DPAA_CORES, MAX_CACHELINE);
    2392         [ #  # ]:          0 :         if (!dpaa_intf->tx_queues) {
    2393                 :          0 :                 DPAA_PMD_ERR("Failed to alloc mem for TX queues");
    2394                 :            :                 ret = -ENOMEM;
    2395                 :          0 :                 goto free_rx;
    2396                 :            :         }
    2397                 :            : 
    2398                 :          0 :         dpaa_intf->tx_conf_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
    2399                 :            :                 MAX_DPAA_CORES, MAX_CACHELINE);
    2400         [ #  # ]:          0 :         if (!dpaa_intf->tx_conf_queues) {
    2401                 :          0 :                 DPAA_PMD_ERR("Failed to alloc mem for TX conf queues");
    2402                 :            :                 ret = -ENOMEM;
    2403                 :          0 :                 goto free_rx;
    2404                 :            :         }
    2405                 :            : 
    2406                 :            :         /* If congestion control is enabled globally*/
    2407         [ #  # ]:          0 :         if (td_tx_threshold) {
    2408                 :          0 :                 dpaa_intf->cgr_tx = rte_zmalloc(NULL,
    2409                 :            :                         sizeof(struct qman_cgr) * MAX_DPAA_CORES,
    2410                 :            :                         MAX_CACHELINE);
    2411         [ #  # ]:          0 :                 if (!dpaa_intf->cgr_tx) {
    2412                 :          0 :                         DPAA_PMD_ERR("Failed to alloc mem for cgr_tx");
    2413                 :            :                         ret = -ENOMEM;
    2414                 :          0 :                         goto free_rx;
    2415                 :            :                 }
    2416                 :            : 
    2417                 :          0 :                 ret = qman_alloc_cgrid_range(&cgrid_tx[0], MAX_DPAA_CORES,
    2418                 :            :                                              1, 0);
    2419         [ #  # ]:          0 :                 if (ret != MAX_DPAA_CORES) {
    2420                 :          0 :                         DPAA_PMD_WARN("insufficient CGRIDs available");
    2421                 :            :                         ret = -EINVAL;
    2422                 :          0 :                         goto free_rx;
    2423                 :            :                 }
    2424                 :            :         } else {
    2425                 :          0 :                 dpaa_intf->cgr_tx = NULL;
    2426                 :            :         }
    2427                 :            : 
    2428                 :            : 
    2429         [ #  # ]:          0 :         for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
    2430         [ #  # ]:          0 :                 if (dpaa_intf->cgr_tx)
    2431                 :          0 :                         dpaa_intf->cgr_tx[loop].cgrid = cgrid_tx[loop];
    2432                 :            : 
    2433         [ #  # ]:          0 :                 ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
    2434                 :            :                         fman_intf,
    2435                 :          0 :                         dpaa_intf->cgr_tx ? &dpaa_intf->cgr_tx[loop] : NULL);
    2436         [ #  # ]:          0 :                 if (ret)
    2437                 :          0 :                         goto free_tx;
    2438                 :          0 :                 dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
    2439                 :            : 
    2440         [ #  # ]:          0 :                 if (dpaa_ieee_1588) {
    2441                 :          0 :                         ret = dpaa_tx_conf_queue_init(&dpaa_intf->tx_conf_queues[loop]);
    2442         [ #  # ]:          0 :                         if (ret)
    2443                 :          0 :                                 goto free_tx;
    2444                 :            : 
    2445                 :          0 :                         dpaa_intf->tx_conf_queues[loop].dpaa_intf = dpaa_intf;
    2446                 :          0 :                         dpaa_intf->tx_queues[loop].tx_conf_queue = &dpaa_intf->tx_conf_queues[loop];
    2447                 :            :                 }
    2448                 :            :         }
    2449                 :          0 :         dpaa_intf->nb_tx_queues = MAX_DPAA_CORES;
    2450                 :            : #if defined(RTE_LIBRTE_DPAA_DEBUG_DRIVER)
    2451                 :            :         ret = dpaa_error_queue_init(dpaa_intf, fman_intf);
    2452                 :            :         if (ret)
    2453                 :            :                 goto free_tx;
    2454                 :            : #endif
    2455                 :          0 :         DPAA_PMD_DEBUG("All frame queues created");
    2456                 :            : 
    2457                 :            :         /* Get the initial configuration for flow control */
    2458         [ #  # ]:          0 :         if (fman_intf->mac_type != fman_offline_internal &&
    2459                 :            :             fman_intf->mac_type != fman_onic)
    2460                 :          0 :                 dpaa_fc_set_default(dpaa_intf, fman_intf);
    2461                 :            : 
    2462                 :            :         /* reset bpool list, initialize bpool dynamically */
    2463         [ #  # ]:          0 :         list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
    2464                 :          0 :                 list_del(&bp->node);
    2465                 :          0 :                 rte_free(bp);
    2466                 :            :         }
    2467                 :            : 
    2468                 :            :         /* Populate ethdev structure */
    2469                 :          0 :         eth_dev->dev_ops = &dpaa_devops;
    2470                 :          0 :         eth_dev->rx_queue_count = dpaa_dev_rx_queue_count;
    2471                 :          0 :         eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
    2472                 :          0 :         eth_dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
    2473                 :            : 
    2474                 :            :         /* Allocate memory for storing MAC addresses */
    2475                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
    2476                 :            :                 RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER, 0);
    2477         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    2478                 :          0 :                 DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
    2479                 :            :                                                 "store MAC addresses",
    2480                 :            :                                 RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
    2481                 :            :                 ret = -ENOMEM;
    2482                 :          0 :                 goto free_tx;
    2483                 :            :         }
    2484                 :            : 
    2485                 :            :         /* copy the primary mac address */
    2486                 :            :         rte_ether_addr_copy(&fman_intf->mac_addr, &eth_dev->data->mac_addrs[0]);
    2487                 :            : 
    2488                 :          0 :         DPAA_PMD_INFO("net: dpaa: %s: " RTE_ETHER_ADDR_PRT_FMT,
    2489                 :            :                       dpaa_device->name, RTE_ETHER_ADDR_BYTES(&fman_intf->mac_addr));
    2490                 :            : 
    2491         [ #  # ]:          0 :         if (!fman_intf->is_shared_mac &&
    2492   [ #  #  #  # ]:          0 :             fman_intf->mac_type != fman_offline_internal &&
    2493                 :            :             fman_intf->mac_type != fman_onic) {
    2494                 :            :                 /* Configure error packet handling */
    2495                 :            : #ifndef RTE_LIBRTE_DPAA_DEBUG_DRIVER
    2496         [ #  # ]:          0 :                         if (dpaa_enable_recv_err_pkts)
    2497                 :            : #endif
    2498                 :          0 :                                 fman_if_receive_rx_errors(fman_intf,
    2499                 :            :                                                 FM_FD_RX_STATUS_ERR_MASK);
    2500                 :            : 
    2501                 :            :                 /* Disable RX mode */
    2502                 :          0 :                 fman_if_disable_rx(fman_intf);
    2503                 :            :                 /* Disable promiscuous mode */
    2504                 :          0 :                 fman_if_promiscuous_disable(fman_intf);
    2505                 :            :                 /* Disable multicast */
    2506                 :          0 :                 fman_if_reset_mcast_filter_table(fman_intf);
    2507                 :            :                 /* Reset interface statistics */
    2508                 :          0 :                 fman_if_stats_reset(fman_intf);
    2509                 :            :                 /* Disable SG by default */
    2510                 :          0 :                 fman_if_set_sg(fman_intf, 0);
    2511                 :          0 :                 fman_if_set_maxfrm(fman_intf,
    2512                 :            :                                    RTE_ETHER_MAX_LEN + VLAN_TAG_SIZE);
    2513                 :            :         }
    2514                 :            : 
    2515                 :            :         return 0;
    2516                 :            : 
    2517                 :          0 : free_tx:
    2518                 :          0 :         rte_free(dpaa_intf->tx_queues);
    2519                 :          0 :         dpaa_intf->tx_queues = NULL;
    2520                 :          0 :         dpaa_intf->nb_tx_queues = 0;
    2521                 :            : 
    2522                 :          0 : free_rx:
    2523                 :          0 :         rte_free(dpaa_intf->cgr_rx);
    2524                 :          0 :         rte_free(dpaa_intf->cgr_tx);
    2525                 :          0 :         rte_free(dpaa_intf->rx_queues);
    2526                 :          0 :         dpaa_intf->rx_queues = NULL;
    2527                 :          0 :         dpaa_intf->nb_rx_queues = 0;
    2528                 :          0 :         return ret;
    2529                 :            : }
    2530                 :            : 
    2531                 :            : static int
    2532                 :          0 : rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
    2533                 :            :                struct rte_dpaa_device *dpaa_dev)
    2534                 :            : {
    2535                 :            :         int diag;
    2536                 :            :         int ret;
    2537                 :            :         struct rte_eth_dev *eth_dev;
    2538                 :            : 
    2539                 :          0 :         PMD_INIT_FUNC_TRACE();
    2540                 :            : 
    2541                 :            :         if ((DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE) >
    2542                 :            :                 RTE_PKTMBUF_HEADROOM) {
    2543                 :            :                 DPAA_PMD_ERR(
    2544                 :            :                 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA Annotation req(%d)",
    2545                 :            :                 RTE_PKTMBUF_HEADROOM,
    2546                 :            :                 DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE);
    2547                 :            : 
    2548                 :            :                 return -1;
    2549                 :            :         }
    2550                 :            : 
    2551                 :            :         /* In case of secondary process, the device is already configured
    2552                 :            :          * and no further action is required, except portal initialization
    2553                 :            :          * and verifying secondary attachment to port name.
    2554                 :            :          */
    2555         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    2556                 :          0 :                 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
    2557         [ #  # ]:          0 :                 if (!eth_dev)
    2558                 :            :                         return -ENOMEM;
    2559                 :          0 :                 eth_dev->device = &dpaa_dev->device;
    2560                 :          0 :                 eth_dev->dev_ops = &dpaa_devops;
    2561                 :            : 
    2562                 :          0 :                 ret = dpaa_dev_init_secondary(eth_dev);
    2563         [ #  # ]:          0 :                 if (ret) {
    2564                 :          0 :                         DPAA_PMD_ERR("secondary dev init failed(%d)", ret);
    2565                 :          0 :                         return ret;
    2566                 :            :                 }
    2567                 :            : 
    2568                 :          0 :                 rte_eth_dev_probing_finish(eth_dev);
    2569                 :          0 :                 return 0;
    2570                 :            :         }
    2571                 :            : 
    2572   [ #  #  #  # ]:          0 :         if (!is_global_init && (rte_eal_process_type() == RTE_PROC_PRIMARY)) {
    2573         [ #  # ]:          0 :                 if (access("/tmp/fmc.bin", F_OK) == -1) {
    2574                 :          0 :                         DPAA_PMD_INFO("* FMC not configured.Enabling default mode");
    2575                 :          0 :                         default_q = 1;
    2576                 :            :                 }
    2577                 :            : 
    2578   [ #  #  #  # ]:          0 :                 if (!(default_q || fmc_q)) {
    2579                 :          0 :                         ret = dpaa_fm_init();
    2580         [ #  # ]:          0 :                         if (ret) {
    2581                 :          0 :                                 DPAA_PMD_ERR("FM init failed(%d)", ret);
    2582                 :          0 :                                 return ret;
    2583                 :            :                         }
    2584                 :            :                 }
    2585                 :            : 
    2586                 :            :                 /* disabling the default push mode for LS1043 */
    2587         [ #  # ]:          0 :                 if (dpaa_soc_ver() == SVR_LS1043A_FAMILY)
    2588                 :          0 :                         dpaa_push_mode_max_queue = 0;
    2589                 :            : 
    2590                 :            :                 /* if push mode queues to be enabled. Currently we are allowing
    2591                 :            :                  * only one queue per thread.
    2592                 :            :                  */
    2593         [ #  # ]:          0 :                 if (getenv("DPAA_PUSH_QUEUES_NUMBER")) {
    2594                 :          0 :                         dpaa_push_mode_max_queue =
    2595                 :          0 :                                         atoi(getenv("DPAA_PUSH_QUEUES_NUMBER"));
    2596         [ #  # ]:          0 :                         if (dpaa_push_mode_max_queue > DPAA_MAX_PUSH_MODE_QUEUE)
    2597                 :          0 :                             dpaa_push_mode_max_queue = DPAA_MAX_PUSH_MODE_QUEUE;
    2598                 :            :                 }
    2599                 :            : 
    2600                 :          0 :                 is_global_init = 1;
    2601                 :            :         }
    2602                 :            : 
    2603         [ #  # ]:          0 :         if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
    2604                 :          0 :                 ret = rte_dpaa_portal_init((void *)1);
    2605         [ #  # ]:          0 :                 if (ret) {
    2606                 :          0 :                         DPAA_PMD_ERR("Unable to initialize portal");
    2607                 :          0 :                         return ret;
    2608                 :            :                 }
    2609                 :            :         }
    2610                 :            : 
    2611                 :          0 :         eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
    2612         [ #  # ]:          0 :         if (!eth_dev)
    2613                 :            :                 return -ENOMEM;
    2614                 :            : 
    2615                 :          0 :         eth_dev->data->dev_private =
    2616                 :          0 :                         rte_zmalloc("ethdev private structure",
    2617                 :            :                                         sizeof(struct dpaa_if),
    2618                 :            :                                         RTE_CACHE_LINE_SIZE);
    2619         [ #  # ]:          0 :         if (!eth_dev->data->dev_private) {
    2620                 :          0 :                 DPAA_PMD_ERR("Cannot allocate memzone for port data");
    2621                 :          0 :                 rte_eth_dev_release_port(eth_dev);
    2622                 :          0 :                 return -ENOMEM;
    2623                 :            :         }
    2624                 :            : 
    2625                 :          0 :         eth_dev->device = &dpaa_dev->device;
    2626                 :          0 :         dpaa_dev->eth_dev = eth_dev;
    2627                 :            : 
    2628                 :          0 :         qman_ern_register_cb(dpaa_free_mbuf);
    2629                 :            : 
    2630         [ #  # ]:          0 :         if (dpaa_drv->drv_flags & RTE_DPAA_DRV_INTR_LSC)
    2631                 :          0 :                 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
    2632                 :            : 
    2633                 :            :         /* Invoke PMD device initialization function */
    2634                 :          0 :         diag = dpaa_dev_init(eth_dev);
    2635         [ #  # ]:          0 :         if (diag == 0) {
    2636         [ #  # ]:          0 :                 if (!dpaa_tx_sg_pool) {
    2637                 :          0 :                         dpaa_tx_sg_pool =
    2638                 :          0 :                                 rte_pktmbuf_pool_create("dpaa_mbuf_tx_sg_pool",
    2639                 :            :                                 DPAA_POOL_SIZE,
    2640                 :            :                                 DPAA_POOL_CACHE_SIZE, 0,
    2641                 :            :                                 DPAA_MAX_SGS * sizeof(struct qm_sg_entry),
    2642                 :          0 :                                 rte_socket_id());
    2643         [ #  # ]:          0 :                         if (dpaa_tx_sg_pool == NULL) {
    2644                 :          0 :                                 DPAA_PMD_ERR("SG pool creation failed");
    2645                 :          0 :                                 return -ENOMEM;
    2646                 :            :                         }
    2647                 :            :                 }
    2648                 :          0 :                 rte_eth_dev_probing_finish(eth_dev);
    2649                 :          0 :                 dpaa_valid_dev++;
    2650                 :          0 :                 return 0;
    2651                 :            :         }
    2652                 :            : 
    2653                 :          0 :         rte_eth_dev_release_port(eth_dev);
    2654                 :          0 :         return diag;
    2655                 :            : }
    2656                 :            : 
    2657                 :            : /* Adding destructor for double check in case non-gracefully
    2658                 :            :  * exit.
    2659                 :            :  */
    2660                 :        253 : RTE_FINI_PRIO(dpaa_finish, 103)
    2661                 :            : {
    2662                 :            :         struct dpaa_if *dpaa_intf;
    2663                 :            :         int loop;
    2664                 :            :         struct qman_fq *fq;
    2665                 :            :         uint16_t portid;
    2666                 :            :         struct rte_eth_dev *dev;
    2667                 :            : 
    2668                 :        253 :         PMD_INIT_FUNC_TRACE();
    2669                 :            :         /* For secondary, primary will do all the cleanup */
    2670         [ +  + ]:        253 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    2671                 :            :                 return;
    2672                 :            : 
    2673         [ -  + ]:        225 :         if (!is_global_init)
    2674                 :            :                 return;
    2675                 :            : 
    2676   [ #  #  #  # ]:          0 :         if (!(default_q || fmc_q)) {
    2677         [ #  # ]:          0 :                         if (dpaa_fm_term())
    2678                 :          0 :                                 DPAA_PMD_WARN("DPAA FM term failed");
    2679                 :            : 
    2680                 :          0 :                 DPAA_PMD_INFO("DPAA fman cleaned up");
    2681                 :            :         }
    2682                 :            : 
    2683         [ #  # ]:          0 :         RTE_ETH_FOREACH_DEV(portid) {
    2684                 :          0 :                 dev = &rte_eth_devices[portid];
    2685         [ #  # ]:          0 :                 if (strcmp(dev->device->driver->name,
    2686                 :            :                         rte_dpaa_pmd.driver.name))
    2687                 :          0 :                         continue;
    2688                 :          0 :                 dpaa_intf = dev->data->dev_private;
    2689                 :            :                 /* Freeing queue specific portals */
    2690         [ #  # ]:          0 :                 for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) {
    2691         [ #  # ]:          0 :                         if (!dpaa_intf->rx_queues)
    2692                 :            :                                 break;
    2693                 :            : 
    2694                 :          0 :                         fq = &dpaa_intf->rx_queues[loop];
    2695         [ #  # ]:          0 :                         if (fq->qp_initialized) {
    2696                 :          0 :                                 rte_dpaa_portal_fq_close(fq);
    2697                 :          0 :                                 fq->qp_initialized = 0;
    2698                 :            :                         }
    2699                 :            :                 }
    2700                 :            :         }
    2701                 :          0 :         is_global_init = 0;
    2702                 :            : }
    2703                 :            : 
    2704                 :            : static int
    2705                 :          0 : rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
    2706                 :            : {
    2707                 :            :         struct rte_eth_dev *eth_dev;
    2708                 :            :         int ret;
    2709                 :            : 
    2710                 :          0 :         PMD_INIT_FUNC_TRACE();
    2711                 :            : 
    2712                 :          0 :         eth_dev = dpaa_dev->eth_dev;
    2713                 :          0 :         dpaa_eth_dev_close(eth_dev);
    2714                 :          0 :         ret = rte_eth_dev_release_port(eth_dev);
    2715                 :          0 :         dpaa_valid_dev--;
    2716         [ #  # ]:          0 :         if (!dpaa_valid_dev) {
    2717                 :          0 :                 rte_mempool_free(dpaa_tx_sg_pool);
    2718                 :          0 :                 dpaa_finish();
    2719                 :            :         }
    2720                 :          0 :         return ret;
    2721                 :            : }
    2722                 :            : 
    2723                 :            : static struct rte_dpaa_driver rte_dpaa_pmd = {
    2724                 :            :         .drv_flags = RTE_DPAA_DRV_INTR_LSC,
    2725                 :            :         .drv_type = FSL_DPAA_ETH,
    2726                 :            :         .probe = rte_dpaa_probe,
    2727                 :            :         .remove = rte_dpaa_remove,
    2728                 :            : };
    2729                 :            : 
    2730                 :        253 : RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);
    2731                 :            : RTE_PMD_REGISTER_PARAM_STRING(net_dpaa,
    2732                 :            :                 DRIVER_IEEE1588 "=<int>"
    2733                 :            :                 DRIVER_RECV_ERR_PKTS "=<int>");
    2734         [ -  + ]:        253 : RTE_LOG_REGISTER_DEFAULT(dpaa_logtype_pmd, NOTICE);

Generated by: LCOV version 1.14