LCOV - code coverage report
Current view: top level - drivers/net/dpaa - dpaa_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 5 1068 0.5 %
Date: 2025-05-01 17:49:45 Functions: 3 58 5.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 575 0.9 %

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

Generated by: LCOV version 1.14