LCOV - code coverage report
Current view: top level - drivers/net/dpaa2 - dpaa2_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 1299 0.2 %
Date: 2025-05-01 17:49:45 Functions: 2 59 3.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 661 0.2 %

           Branch data     Line data    Source code
       1                 :            : /* * SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
       4                 :            :  *   Copyright 2016-2024 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : 
       8                 :            : #include <time.h>
       9                 :            : #include <net/if.h>
      10                 :            : 
      11                 :            : #include <eal_export.h>
      12                 :            : #include <rte_mbuf.h>
      13                 :            : #include <ethdev_driver.h>
      14                 :            : #include <rte_malloc.h>
      15                 :            : #include <rte_memcpy.h>
      16                 :            : #include <rte_string_fns.h>
      17                 :            : #include <rte_cycles.h>
      18                 :            : #include <rte_kvargs.h>
      19                 :            : #include <dev_driver.h>
      20                 :            : #include <bus_fslmc_driver.h>
      21                 :            : #include <rte_flow_driver.h>
      22                 :            : #include "rte_dpaa2_mempool.h"
      23                 :            : 
      24                 :            : #include "dpaa2_pmd_logs.h"
      25                 :            : #include <fslmc_vfio.h>
      26                 :            : #include <dpaa2_hw_pvt.h>
      27                 :            : #include <dpaa2_hw_mempool.h>
      28                 :            : #include <dpaa2_hw_dpio.h>
      29                 :            : #include <mc/fsl_dpmng.h>
      30                 :            : #include "dpaa2_ethdev.h"
      31                 :            : #include "dpaa2_sparser.h"
      32                 :            : #include <fsl_qbman_debug.h>
      33                 :            : 
      34                 :            : #define DRIVER_LOOPBACK_MODE "drv_loopback"
      35                 :            : #define DRIVER_NO_PREFETCH_MODE "drv_no_prefetch"
      36                 :            : #define DRIVER_TX_CONF "drv_tx_conf"
      37                 :            : #define DRIVER_ERROR_QUEUE  "drv_err_queue"
      38                 :            : #define CHECK_INTERVAL         100  /* 100ms */
      39                 :            : #define MAX_REPEAT_TIME        90   /* 9s (90 * 100ms) in total */
      40                 :            : 
      41                 :            : /* Supported Rx offloads */
      42                 :            : static uint64_t dev_rx_offloads_sup =
      43                 :            :                 RTE_ETH_RX_OFFLOAD_CHECKSUM |
      44                 :            :                 RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
      45                 :            :                 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
      46                 :            :                 RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM |
      47                 :            :                 RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
      48                 :            :                 RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
      49                 :            :                 RTE_ETH_RX_OFFLOAD_TIMESTAMP;
      50                 :            : 
      51                 :            : /* Rx offloads which cannot be disabled */
      52                 :            : static uint64_t dev_rx_offloads_nodis =
      53                 :            :                 RTE_ETH_RX_OFFLOAD_RSS_HASH |
      54                 :            :                 RTE_ETH_RX_OFFLOAD_SCATTER;
      55                 :            : 
      56                 :            : /* Supported Tx offloads */
      57                 :            : static uint64_t dev_tx_offloads_sup =
      58                 :            :                 RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
      59                 :            :                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
      60                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
      61                 :            :                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
      62                 :            :                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
      63                 :            :                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
      64                 :            :                 RTE_ETH_TX_OFFLOAD_MT_LOCKFREE |
      65                 :            :                 RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
      66                 :            : 
      67                 :            : /* Tx offloads which cannot be disabled */
      68                 :            : static uint64_t dev_tx_offloads_nodis =
      69                 :            :                 RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
      70                 :            : 
      71                 :            : /* enable timestamp in mbuf */
      72                 :            : bool dpaa2_enable_ts[RTE_MAX_ETHPORTS];
      73                 :            : uint64_t dpaa2_timestamp_rx_dynflag;
      74                 :            : int dpaa2_timestamp_dynfield_offset = -1;
      75                 :            : 
      76                 :            : /* Enable error queue */
      77                 :            : bool dpaa2_enable_err_queue;
      78                 :            : 
      79                 :            : bool dpaa2_print_parser_result;
      80                 :            : 
      81                 :            : #define MAX_NB_RX_DESC          11264
      82                 :            : int total_nb_rx_desc;
      83                 :            : 
      84                 :            : int dpaa2_valid_dev;
      85                 :            : struct rte_mempool *dpaa2_tx_sg_pool;
      86                 :            : 
      87                 :            : struct rte_dpaa2_xstats_name_off {
      88                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
      89                 :            :         uint8_t page_id; /* dpni statistics page id */
      90                 :            :         uint8_t stats_id; /* stats id in the given page */
      91                 :            : };
      92                 :            : 
      93                 :            : static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
      94                 :            :         {"ingress_multicast_frames", 0, 2},
      95                 :            :         {"ingress_multicast_bytes", 0, 3},
      96                 :            :         {"ingress_broadcast_frames", 0, 4},
      97                 :            :         {"ingress_broadcast_bytes", 0, 5},
      98                 :            :         {"egress_multicast_frames", 1, 2},
      99                 :            :         {"egress_multicast_bytes", 1, 3},
     100                 :            :         {"egress_broadcast_frames", 1, 4},
     101                 :            :         {"egress_broadcast_bytes", 1, 5},
     102                 :            :         {"ingress_filtered_frames", 2, 0},
     103                 :            :         {"ingress_discarded_frames", 2, 1},
     104                 :            :         {"ingress_nobuffer_discards", 2, 2},
     105                 :            :         {"egress_discarded_frames", 2, 3},
     106                 :            :         {"egress_confirmed_frames", 2, 4},
     107                 :            :         {"cgr_reject_frames", 4, 0},
     108                 :            :         {"cgr_reject_bytes", 4, 1},
     109                 :            : };
     110                 :            : 
     111                 :            : static struct rte_dpaa2_driver rte_dpaa2_pmd;
     112                 :            : static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
     113                 :            :                                  int wait_to_complete);
     114                 :            : static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
     115                 :            : static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
     116                 :            : static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
     117                 :            : 
     118                 :            : static int
     119                 :          0 : dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
     120                 :            : {
     121                 :            :         int ret;
     122                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     123                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     124                 :            : 
     125                 :          0 :         PMD_INIT_FUNC_TRACE();
     126                 :            : 
     127         [ #  # ]:          0 :         if (!dpni) {
     128                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
     129                 :          0 :                 return -EINVAL;
     130                 :            :         }
     131                 :            : 
     132         [ #  # ]:          0 :         if (on)
     133                 :          0 :                 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW, priv->token,
     134                 :            :                                        vlan_id, 0, 0, 0);
     135                 :            :         else
     136                 :          0 :                 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
     137                 :          0 :                                           priv->token, vlan_id);
     138                 :            : 
     139         [ #  # ]:          0 :         if (ret < 0)
     140                 :          0 :                 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
     141                 :            :                               ret, vlan_id, priv->hw_id);
     142                 :            : 
     143                 :            :         return ret;
     144                 :            : }
     145                 :            : 
     146                 :            : static int
     147                 :          0 : dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
     148                 :            : {
     149                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     150                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     151                 :            :         int ret = 0;
     152                 :            : 
     153                 :          0 :         PMD_INIT_FUNC_TRACE();
     154                 :            : 
     155         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_FILTER_MASK) {
     156                 :            :                 /* VLAN Filter not available */
     157         [ #  # ]:          0 :                 if (!priv->max_vlan_filters) {
     158                 :          0 :                         DPAA2_PMD_INFO("VLAN filter not available");
     159                 :          0 :                         return -ENOTSUP;
     160                 :            :                 }
     161                 :            : 
     162         [ #  # ]:          0 :                 if (dev->data->dev_conf.rxmode.offloads &
     163                 :            :                         RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
     164                 :          0 :                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
     165                 :          0 :                                                       priv->token, true);
     166                 :            :                 else
     167                 :          0 :                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
     168                 :          0 :                                                       priv->token, false);
     169         [ #  # ]:          0 :                 if (ret < 0)
     170                 :          0 :                         DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
     171                 :            :         }
     172                 :            : 
     173                 :            :         return ret;
     174                 :            : }
     175                 :            : 
     176                 :            : static int
     177                 :          0 : dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
     178                 :            :         enum rte_vlan_type vlan_type __rte_unused,
     179                 :            :         uint16_t tpid)
     180                 :            : {
     181                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     182                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     183                 :            :         int ret = -ENOTSUP;
     184                 :            : 
     185                 :          0 :         PMD_INIT_FUNC_TRACE();
     186                 :            : 
     187                 :            :         /* nothing to be done for standard vlan tpids */
     188         [ #  # ]:          0 :         if (tpid == 0x8100 || tpid == 0x88A8)
     189                 :            :                 return 0;
     190                 :            : 
     191                 :          0 :         ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
     192                 :          0 :                                    priv->token, tpid);
     193         [ #  # ]:          0 :         if (ret < 0)
     194                 :          0 :                 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
     195                 :            :         /* if already configured tpids, remove them first */
     196         [ #  # ]:          0 :         if (ret == -EBUSY) {
     197                 :          0 :                 struct dpni_custom_tpid_cfg tpid_list = {0};
     198                 :            : 
     199                 :          0 :                 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
     200                 :          0 :                                    priv->token, &tpid_list);
     201         [ #  # ]:          0 :                 if (ret < 0)
     202                 :          0 :                         goto fail;
     203                 :          0 :                 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
     204                 :          0 :                                    priv->token, tpid_list.tpid1);
     205         [ #  # ]:          0 :                 if (ret < 0)
     206                 :          0 :                         goto fail;
     207                 :          0 :                 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
     208                 :          0 :                                            priv->token, tpid);
     209                 :            :         }
     210                 :          0 : fail:
     211                 :            :         return ret;
     212                 :            : }
     213                 :            : 
     214                 :            : static int
     215                 :          0 : dpaa2_fw_version_get(struct rte_eth_dev *dev,
     216                 :            :         char *fw_version, size_t fw_size)
     217                 :            : {
     218                 :            :         int ret;
     219                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     220                 :          0 :         struct mc_soc_version mc_plat_info = {0};
     221                 :          0 :         struct mc_version mc_ver_info = {0};
     222                 :            : 
     223                 :          0 :         PMD_INIT_FUNC_TRACE();
     224                 :            : 
     225         [ #  # ]:          0 :         if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
     226                 :          0 :                 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
     227                 :            : 
     228         [ #  # ]:          0 :         if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
     229                 :          0 :                 DPAA2_PMD_WARN("\tmc_get_version failed");
     230                 :            : 
     231         [ #  # ]:          0 :         ret = snprintf(fw_version, fw_size,
     232                 :            :                        "%x-%d.%d.%d",
     233                 :            :                        mc_plat_info.svr,
     234                 :            :                        mc_ver_info.major,
     235                 :            :                        mc_ver_info.minor,
     236                 :            :                        mc_ver_info.revision);
     237         [ #  # ]:          0 :         if (ret < 0)
     238                 :            :                 return -EINVAL;
     239                 :            : 
     240                 :          0 :         ret += 1; /* add the size of '\0' */
     241         [ #  # ]:          0 :         if (fw_size < (size_t)ret)
     242                 :            :                 return ret;
     243                 :            :         else
     244                 :          0 :                 return 0;
     245                 :            : }
     246                 :            : 
     247                 :            : static int
     248                 :          0 : dpaa2_dev_info_get(struct rte_eth_dev *dev,
     249                 :            :         struct rte_eth_dev_info *dev_info)
     250                 :            : {
     251                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     252                 :            : 
     253                 :          0 :         PMD_INIT_FUNC_TRACE();
     254                 :            : 
     255                 :          0 :         dev_info->max_mac_addrs = priv->max_mac_filters;
     256                 :          0 :         dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
     257                 :          0 :         dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
     258                 :          0 :         dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
     259                 :          0 :         dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
     260                 :          0 :         dev_info->rx_offload_capa = dev_rx_offloads_sup |
     261                 :            :                                         dev_rx_offloads_nodis;
     262                 :          0 :         dev_info->tx_offload_capa = dev_tx_offloads_sup |
     263                 :            :                                         dev_tx_offloads_nodis;
     264                 :          0 :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G |
     265                 :            :                         RTE_ETH_LINK_SPEED_2_5G |
     266                 :            :                         RTE_ETH_LINK_SPEED_10G;
     267                 :          0 :         dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
     268                 :            : 
     269                 :          0 :         dev_info->max_hash_mac_addrs = 0;
     270                 :          0 :         dev_info->max_vfs = 0;
     271                 :          0 :         dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
     272                 :          0 :         dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
     273                 :            : 
     274                 :          0 :         dev_info->default_rxportconf.burst_size = dpaa2_dqrr_size;
     275                 :            :         /* same is rx size for best perf */
     276                 :          0 :         dev_info->default_txportconf.burst_size = dpaa2_dqrr_size;
     277                 :            : 
     278                 :          0 :         dev_info->default_rxportconf.nb_queues = 1;
     279                 :          0 :         dev_info->default_txportconf.nb_queues = 1;
     280                 :          0 :         dev_info->default_txportconf.ring_size = CONG_ENTER_TX_THRESHOLD;
     281                 :          0 :         dev_info->default_rxportconf.ring_size = DPAA2_RX_DEFAULT_NBDESC;
     282                 :            : 
     283         [ #  # ]:          0 :         if (dpaa2_svr_family == SVR_LX2160A) {
     284                 :          0 :                 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_25G |
     285                 :            :                                 RTE_ETH_LINK_SPEED_40G |
     286                 :            :                                 RTE_ETH_LINK_SPEED_50G |
     287                 :            :                                 RTE_ETH_LINK_SPEED_100G;
     288                 :            :         }
     289                 :            : 
     290                 :          0 :         return 0;
     291                 :            : }
     292                 :            : 
     293                 :            : static int
     294                 :          0 : dpaa2_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
     295                 :            :         __rte_unused uint16_t queue_id,
     296                 :            :         struct rte_eth_burst_mode *mode)
     297                 :            : {
     298                 :          0 :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     299                 :            :         int ret = -EINVAL;
     300                 :            :         unsigned int i;
     301                 :            :         const struct burst_info {
     302                 :            :                 uint64_t flags;
     303                 :            :                 const char *output;
     304                 :          0 :         } rx_offload_map[] = {
     305                 :            :                         {RTE_ETH_RX_OFFLOAD_CHECKSUM, " Checksum,"},
     306                 :            :                         {RTE_ETH_RX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
     307                 :            :                         {RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
     308                 :            :                         {RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM, " Outer UDP csum,"},
     309                 :            :                         {RTE_ETH_RX_OFFLOAD_VLAN_STRIP, " VLAN strip,"},
     310                 :            :                         {RTE_ETH_RX_OFFLOAD_VLAN_FILTER, " VLAN filter,"},
     311                 :            :                         {RTE_ETH_RX_OFFLOAD_TIMESTAMP, " Timestamp,"},
     312                 :            :                         {RTE_ETH_RX_OFFLOAD_RSS_HASH, " RSS,"},
     313                 :            :                         {RTE_ETH_RX_OFFLOAD_SCATTER, " Scattered,"}
     314                 :            :         };
     315                 :            : 
     316                 :            :         /* Update Rx offload info */
     317         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
     318         [ #  # ]:          0 :                 if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
     319                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
     320                 :          0 :                                 rx_offload_map[i].output);
     321                 :            :                         ret = 0;
     322                 :          0 :                         break;
     323                 :            :                 }
     324                 :            :         }
     325                 :          0 :         return ret;
     326                 :            : }
     327                 :            : 
     328                 :            : static int
     329                 :          0 : dpaa2_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
     330                 :            :                         __rte_unused uint16_t queue_id,
     331                 :            :                         struct rte_eth_burst_mode *mode)
     332                 :            : {
     333                 :          0 :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     334                 :            :         int ret = -EINVAL;
     335                 :            :         unsigned int i;
     336                 :            :         const struct burst_info {
     337                 :            :                 uint64_t flags;
     338                 :            :                 const char *output;
     339                 :          0 :         } tx_offload_map[] = {
     340                 :            :                         {RTE_ETH_TX_OFFLOAD_VLAN_INSERT, " VLAN Insert,"},
     341                 :            :                         {RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
     342                 :            :                         {RTE_ETH_TX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
     343                 :            :                         {RTE_ETH_TX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
     344                 :            :                         {RTE_ETH_TX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
     345                 :            :                         {RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
     346                 :            :                         {RTE_ETH_TX_OFFLOAD_MT_LOCKFREE, " MT lockfree,"},
     347                 :            :                         {RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, " MBUF free disable,"},
     348                 :            :                         {RTE_ETH_TX_OFFLOAD_MULTI_SEGS, " Scattered,"}
     349                 :            :         };
     350                 :            : 
     351                 :            :         /* Update Tx offload info */
     352         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
     353         [ #  # ]:          0 :                 if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
     354                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
     355                 :          0 :                                 tx_offload_map[i].output);
     356                 :            :                         ret = 0;
     357                 :          0 :                         break;
     358                 :            :                 }
     359                 :            :         }
     360                 :          0 :         return ret;
     361                 :            : }
     362                 :            : 
     363                 :            : static int
     364                 :          0 : dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
     365                 :            : {
     366                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     367                 :            :         uint16_t dist_idx;
     368                 :            :         uint32_t vq_id;
     369                 :            :         uint8_t num_rxqueue_per_tc;
     370                 :            :         struct dpaa2_queue *mc_q, *mcq;
     371                 :            :         uint32_t tot_queues;
     372                 :            :         int i, ret = 0;
     373                 :            :         struct dpaa2_queue *dpaa2_q;
     374                 :            : 
     375                 :          0 :         PMD_INIT_FUNC_TRACE();
     376                 :            : 
     377                 :          0 :         num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
     378         [ #  # ]:          0 :         if (priv->flags & DPAA2_TX_CONF_ENABLE)
     379                 :          0 :                 tot_queues = priv->nb_rx_queues + 2 * priv->nb_tx_queues;
     380                 :            :         else
     381                 :          0 :                 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
     382                 :          0 :         mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
     383                 :            :                           RTE_CACHE_LINE_SIZE);
     384         [ #  # ]:          0 :         if (!mc_q) {
     385                 :          0 :                 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
     386                 :          0 :                 return -ENOBUFS;
     387                 :            :         }
     388                 :            : 
     389         [ #  # ]:          0 :         for (i = 0; i < priv->nb_rx_queues; i++) {
     390                 :          0 :                 mc_q->eth_data = dev->data;
     391                 :          0 :                 priv->rx_vq[i] = mc_q++;
     392                 :            :                 dpaa2_q = priv->rx_vq[i];
     393   [ #  #  #  #  :          0 :                 ret = dpaa2_queue_storage_alloc(dpaa2_q,
                   #  # ]
     394                 :            :                         RTE_MAX_LCORE);
     395         [ #  # ]:          0 :                 if (ret)
     396                 :          0 :                         goto fail;
     397                 :            :         }
     398                 :            : 
     399         [ #  # ]:          0 :         if (dpaa2_enable_err_queue) {
     400                 :          0 :                 priv->rx_err_vq = rte_zmalloc("dpni_rx_err",
     401                 :            :                         sizeof(struct dpaa2_queue), 0);
     402         [ #  # ]:          0 :                 if (!priv->rx_err_vq) {
     403                 :            :                         ret = -ENOBUFS;
     404                 :          0 :                         goto fail;
     405                 :            :                 }
     406                 :            : 
     407                 :            :                 dpaa2_q = priv->rx_err_vq;
     408   [ #  #  #  #  :          0 :                 ret = dpaa2_queue_storage_alloc(dpaa2_q,
                   #  # ]
     409                 :            :                         RTE_MAX_LCORE);
     410         [ #  # ]:          0 :                 if (ret)
     411                 :          0 :                         goto fail;
     412                 :            :         }
     413                 :            : 
     414         [ #  # ]:          0 :         for (i = 0; i < priv->nb_tx_queues; i++) {
     415                 :          0 :                 mc_q->eth_data = dev->data;
     416                 :          0 :                 mc_q->flow_id = DPAA2_INVALID_FLOW_ID;
     417                 :          0 :                 priv->tx_vq[i] = mc_q++;
     418                 :            :                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
     419                 :          0 :                 dpaa2_q->cscn = rte_malloc(NULL,
     420                 :            :                                            sizeof(struct qbman_result), 16);
     421         [ #  # ]:          0 :                 if (!dpaa2_q->cscn) {
     422                 :            :                         ret = -ENOBUFS;
     423                 :          0 :                         goto fail_tx;
     424                 :            :                 }
     425                 :            :         }
     426                 :            : 
     427         [ #  # ]:          0 :         if (priv->flags & DPAA2_TX_CONF_ENABLE) {
     428                 :            :                 /*Setup tx confirmation queues*/
     429         [ #  # ]:          0 :                 for (i = 0; i < priv->nb_tx_queues; i++) {
     430                 :          0 :                         mc_q->eth_data = dev->data;
     431                 :          0 :                         mc_q->tc_index = i;
     432                 :          0 :                         mc_q->flow_id = 0;
     433                 :          0 :                         priv->tx_conf_vq[i] = mc_q++;
     434                 :            :                         dpaa2_q = priv->tx_conf_vq[i];
     435   [ #  #  #  #  :          0 :                         ret = dpaa2_queue_storage_alloc(dpaa2_q,
                   #  # ]
     436                 :            :                                         RTE_MAX_LCORE);
     437         [ #  # ]:          0 :                         if (ret)
     438                 :          0 :                                 goto fail_tx_conf;
     439                 :            :                 }
     440                 :            :         }
     441                 :            : 
     442                 :            :         vq_id = 0;
     443         [ #  # ]:          0 :         for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
     444                 :          0 :                 mcq = priv->rx_vq[vq_id];
     445                 :          0 :                 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
     446                 :          0 :                 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
     447                 :          0 :                 vq_id++;
     448                 :            :         }
     449                 :            : 
     450                 :            :         return 0;
     451                 :            : fail_tx_conf:
     452                 :          0 :         i -= 1;
     453         [ #  # ]:          0 :         while (i >= 0) {
     454                 :          0 :                 dpaa2_q = priv->tx_conf_vq[i];
     455   [ #  #  #  # ]:          0 :                 dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
     456                 :          0 :                 priv->tx_conf_vq[i--] = NULL;
     457                 :            :         }
     458                 :          0 :         i = priv->nb_tx_queues;
     459                 :          0 : fail_tx:
     460                 :          0 :         i -= 1;
     461         [ #  # ]:          0 :         while (i >= 0) {
     462                 :          0 :                 dpaa2_q = priv->tx_vq[i];
     463                 :          0 :                 rte_free(dpaa2_q->cscn);
     464                 :          0 :                 priv->tx_vq[i--] = NULL;
     465                 :            :         }
     466                 :          0 :         i = priv->nb_rx_queues;
     467                 :          0 : fail:
     468                 :          0 :         i -= 1;
     469                 :          0 :         mc_q = priv->rx_vq[0];
     470         [ #  # ]:          0 :         while (i >= 0) {
     471                 :          0 :                 dpaa2_q = priv->rx_vq[i];
     472   [ #  #  #  # ]:          0 :                 dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
     473                 :          0 :                 priv->rx_vq[i--] = NULL;
     474                 :            :         }
     475                 :            : 
     476         [ #  # ]:          0 :         if (dpaa2_enable_err_queue) {
     477                 :          0 :                 dpaa2_q = priv->rx_err_vq;
     478   [ #  #  #  # ]:          0 :                 dpaa2_queue_storage_free(dpaa2_q, RTE_MAX_LCORE);
     479                 :            :         }
     480                 :            : 
     481                 :          0 :         rte_free(mc_q);
     482                 :          0 :         return ret;
     483                 :            : }
     484                 :            : 
     485                 :            : static void
     486                 :          0 : dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
     487                 :            : {
     488                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     489                 :            :         struct dpaa2_queue *dpaa2_q;
     490                 :            :         int i;
     491                 :            : 
     492                 :          0 :         PMD_INIT_FUNC_TRACE();
     493                 :            : 
     494                 :            :         /* Queue allocation base */
     495         [ #  # ]:          0 :         if (priv->rx_vq[0]) {
     496                 :            :                 /* cleaning up queue storage */
     497         [ #  # ]:          0 :                 for (i = 0; i < priv->nb_rx_queues; i++) {
     498                 :          0 :                         dpaa2_q = priv->rx_vq[i];
     499   [ #  #  #  # ]:          0 :                         dpaa2_queue_storage_free(dpaa2_q,
     500                 :            :                                 RTE_MAX_LCORE);
     501                 :            :                 }
     502                 :            :                 /* cleanup tx queue cscn */
     503         [ #  # ]:          0 :                 for (i = 0; i < priv->nb_tx_queues; i++) {
     504                 :          0 :                         dpaa2_q = priv->tx_vq[i];
     505                 :          0 :                         rte_free(dpaa2_q->cscn);
     506                 :            :                 }
     507         [ #  # ]:          0 :                 if (priv->flags & DPAA2_TX_CONF_ENABLE) {
     508                 :            :                         /* cleanup tx conf queue storage */
     509         [ #  # ]:          0 :                         for (i = 0; i < priv->nb_tx_queues; i++) {
     510                 :          0 :                                 dpaa2_q = priv->tx_conf_vq[i];
     511   [ #  #  #  # ]:          0 :                                 dpaa2_queue_storage_free(dpaa2_q,
     512                 :            :                                         RTE_MAX_LCORE);
     513                 :            :                         }
     514                 :            :                 }
     515                 :            :                 /*free memory for all queues (RX+TX) */
     516                 :          0 :                 rte_free(priv->rx_vq[0]);
     517                 :          0 :                 priv->rx_vq[0] = NULL;
     518                 :            :         }
     519                 :          0 : }
     520                 :            : 
     521                 :            : static int
     522                 :          0 : dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
     523                 :            : {
     524                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     525                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     526                 :            :         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
     527                 :          0 :         uint64_t rx_offloads = eth_conf->rxmode.offloads;
     528                 :          0 :         uint64_t tx_offloads = eth_conf->txmode.offloads;
     529                 :            :         int rx_l3_csum_offload = false;
     530                 :            :         int rx_l4_csum_offload = false;
     531                 :            :         int tx_l3_csum_offload = false;
     532                 :            :         int tx_l4_csum_offload = false;
     533                 :            :         int ret, tc_index;
     534                 :            :         uint32_t max_rx_pktlen;
     535                 :            : #if defined(RTE_LIBRTE_IEEE1588)
     536                 :            :         uint16_t ptp_correction_offset;
     537                 :            : #endif
     538                 :            : 
     539                 :          0 :         PMD_INIT_FUNC_TRACE();
     540                 :            : 
     541                 :            :         /* Rx offloads which are enabled by default */
     542         [ #  # ]:          0 :         if (dev_rx_offloads_nodis & ~rx_offloads) {
     543                 :          0 :                 DPAA2_PMD_INFO(
     544                 :            :                 "Some of rx offloads enabled by default - requested 0x%" PRIx64
     545                 :            :                 " fixed are 0x%" PRIx64,
     546                 :            :                 rx_offloads, dev_rx_offloads_nodis);
     547                 :            :         }
     548                 :            : 
     549                 :            :         /* Tx offloads which are enabled by default */
     550         [ #  # ]:          0 :         if (dev_tx_offloads_nodis & ~tx_offloads) {
     551                 :          0 :                 DPAA2_PMD_INFO(
     552                 :            :                 "Some of tx offloads enabled by default - requested 0x%" PRIx64
     553                 :            :                 " fixed are 0x%" PRIx64,
     554                 :            :                 tx_offloads, dev_tx_offloads_nodis);
     555                 :            :         }
     556                 :            : 
     557                 :          0 :         max_rx_pktlen = eth_conf->rxmode.mtu + RTE_ETHER_HDR_LEN +
     558                 :            :                                 RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
     559         [ #  # ]:          0 :         if (max_rx_pktlen <= DPAA2_MAX_RX_PKT_LEN) {
     560                 :          0 :                 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
     561                 :          0 :                         priv->token, max_rx_pktlen - RTE_ETHER_CRC_LEN);
     562         [ #  # ]:          0 :                 if (ret != 0) {
     563                 :          0 :                         DPAA2_PMD_ERR("Unable to set mtu. check config");
     564                 :          0 :                         return ret;
     565                 :            :                 }
     566                 :          0 :                 DPAA2_PMD_DEBUG("MTU configured for the device: %d",
     567                 :            :                                 dev->data->mtu);
     568                 :            :         } else {
     569                 :          0 :                 DPAA2_PMD_ERR("Configured mtu %d and calculated max-pkt-len is %d which should be <= %d",
     570                 :            :                         eth_conf->rxmode.mtu, max_rx_pktlen, DPAA2_MAX_RX_PKT_LEN);
     571                 :          0 :                 return -1;
     572                 :            :         }
     573                 :            : 
     574         [ #  # ]:          0 :         if (eth_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
     575         [ #  # ]:          0 :                 for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
     576                 :          0 :                         ret = dpaa2_setup_flow_dist(dev,
     577                 :            :                                         eth_conf->rx_adv_conf.rss_conf.rss_hf,
     578                 :            :                                         tc_index);
     579         [ #  # ]:          0 :                         if (ret) {
     580                 :          0 :                                 DPAA2_PMD_ERR(
     581                 :            :                                         "Unable to set flow distribution on tc%d."
     582                 :            :                                         "Check queue config", tc_index);
     583                 :          0 :                                 return ret;
     584                 :            :                         }
     585                 :            :                 }
     586                 :            :         }
     587                 :            : 
     588         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
     589                 :            :                 rx_l3_csum_offload = true;
     590                 :            : 
     591                 :          0 :         if ((rx_offloads & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) ||
     592         [ #  # ]:          0 :                 (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) ||
     593                 :            :                 (rx_offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM))
     594                 :            :                 rx_l4_csum_offload = true;
     595                 :            : 
     596                 :          0 :         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
     597                 :            :                                DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
     598         [ #  # ]:          0 :         if (ret) {
     599                 :          0 :                 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
     600                 :          0 :                 return ret;
     601                 :            :         }
     602                 :            : 
     603                 :          0 :         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
     604                 :            :                                DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
     605         [ #  # ]:          0 :         if (ret) {
     606                 :          0 :                 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
     607                 :          0 :                 return ret;
     608                 :            :         }
     609                 :            : 
     610                 :            : #if !defined(RTE_LIBRTE_IEEE1588)
     611         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
     612                 :            : #endif
     613                 :            :         {
     614                 :          0 :                 ret = rte_mbuf_dyn_rx_timestamp_register(
     615                 :            :                                 &dpaa2_timestamp_dynfield_offset,
     616                 :            :                                 &dpaa2_timestamp_rx_dynflag);
     617         [ #  # ]:          0 :                 if (ret != 0) {
     618                 :          0 :                         DPAA2_PMD_ERR("Error to register timestamp field/flag");
     619                 :          0 :                         return -rte_errno;
     620                 :            :                 }
     621                 :          0 :                 dpaa2_enable_ts[dev->data->port_id] = true;
     622                 :            :         }
     623                 :            : 
     624                 :            : #if defined(RTE_LIBRTE_IEEE1588)
     625                 :            :         /* By default setting ptp correction offset for Ethernet SYNC packets */
     626                 :            :         ptp_correction_offset = RTE_ETHER_HDR_LEN + 8;
     627                 :            :         rte_pmd_dpaa2_set_one_step_ts(dev->data->port_id, ptp_correction_offset, 0);
     628                 :            : #endif
     629         [ #  # ]:          0 :         if (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
     630                 :            :                 tx_l3_csum_offload = true;
     631                 :            : 
     632                 :          0 :         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ||
     633         [ #  # ]:          0 :                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ||
     634                 :            :                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM))
     635                 :            :                 tx_l4_csum_offload = true;
     636                 :            : 
     637                 :          0 :         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
     638                 :            :                                DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
     639         [ #  # ]:          0 :         if (ret) {
     640                 :          0 :                 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
     641                 :          0 :                 return ret;
     642                 :            :         }
     643                 :            : 
     644                 :          0 :         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
     645                 :            :                                DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
     646         [ #  # ]:          0 :         if (ret) {
     647                 :          0 :                 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
     648                 :          0 :                 return ret;
     649                 :            :         }
     650                 :            : 
     651                 :            :         /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
     652                 :            :          * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
     653                 :            :          * to 0 for LS2 in the hardware thus disabling data/annotation
     654                 :            :          * stashing. For LX2 this is fixed in hardware and thus hash result and
     655                 :            :          * parse results can be received in FD using this option.
     656                 :            :          */
     657         [ #  # ]:          0 :         if (dpaa2_svr_family == SVR_LX2160A) {
     658                 :          0 :                 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
     659                 :            :                                        DPNI_FLCTYPE_HASH, true);
     660         [ #  # ]:          0 :                 if (ret) {
     661                 :          0 :                         DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
     662                 :          0 :                         return ret;
     663                 :            :                 }
     664                 :            :         }
     665                 :            : 
     666         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
     667                 :          0 :                 dpaa2_vlan_offload_set(dev, RTE_ETH_VLAN_FILTER_MASK);
     668                 :            : 
     669         [ #  # ]:          0 :         if (eth_conf->lpbk_mode) {
     670                 :          0 :                 ret = dpaa2_dev_recycle_config(dev);
     671         [ #  # ]:          0 :                 if (ret) {
     672                 :          0 :                         DPAA2_PMD_ERR("Error to configure %s to recycle port.",
     673                 :            :                                 dev->data->name);
     674                 :            : 
     675                 :          0 :                         return ret;
     676                 :            :                 }
     677                 :            :         } else {
     678                 :            :                 /** User may disable loopback mode by calling
     679                 :            :                  * "dev_configure" with lpbk_mode cleared.
     680                 :            :                  * No matter the port was configured recycle or not,
     681                 :            :                  * recycle de-configure is called here.
     682                 :            :                  * If port is not recycled, the de-configure will return directly.
     683                 :            :                  */
     684                 :          0 :                 ret = dpaa2_dev_recycle_deconfig(dev);
     685         [ #  # ]:          0 :                 if (ret) {
     686                 :          0 :                         DPAA2_PMD_ERR("Error to de-configure recycle port %s.",
     687                 :            :                                 dev->data->name);
     688                 :            : 
     689                 :          0 :                         return ret;
     690                 :            :                 }
     691                 :            :         }
     692                 :            : 
     693                 :          0 :         dpaa2_tm_init(dev);
     694                 :            : 
     695                 :          0 :         return 0;
     696                 :            : }
     697                 :            : 
     698                 :            : /* Function to setup RX flow information. It contains traffic class ID,
     699                 :            :  * flow ID, destination configuration etc.
     700                 :            :  */
     701                 :            : static int
     702                 :          0 : dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
     703                 :            :         uint16_t rx_queue_id,
     704                 :            :         uint16_t nb_rx_desc,
     705                 :            :         unsigned int socket_id __rte_unused,
     706                 :            :         const struct rte_eth_rxconf *rx_conf,
     707                 :            :         struct rte_mempool *mb_pool)
     708                 :            : {
     709                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     710                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     711                 :            :         struct dpaa2_queue *dpaa2_q;
     712                 :            :         struct dpni_queue cfg;
     713                 :            :         uint8_t options = 0;
     714                 :            :         uint8_t flow_id;
     715                 :            :         uint32_t bpid;
     716                 :            :         int i, ret;
     717                 :            : 
     718                 :          0 :         PMD_INIT_FUNC_TRACE();
     719                 :            : 
     720                 :          0 :         DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
     721                 :            :                         dev, rx_queue_id, mb_pool, rx_conf);
     722                 :            : 
     723                 :          0 :         total_nb_rx_desc += nb_rx_desc;
     724         [ #  # ]:          0 :         if (total_nb_rx_desc > MAX_NB_RX_DESC) {
     725                 :          0 :                 DPAA2_PMD_WARN("Total nb_rx_desc exceeds %d limit. Please use Normal buffers",
     726                 :            :                                MAX_NB_RX_DESC);
     727                 :          0 :                 DPAA2_PMD_WARN("To use Normal buffers, run 'export DPNI_NORMAL_BUF=1' before running dynamic_dpl.sh script");
     728                 :            :         }
     729                 :            : 
     730   [ #  #  #  # ]:          0 :         if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
     731         [ #  # ]:          0 :                 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
     732                 :          0 :                         ret = rte_dpaa2_bpid_info_init(mb_pool);
     733         [ #  # ]:          0 :                         if (ret)
     734                 :            :                                 return ret;
     735                 :            :                 }
     736                 :          0 :                 bpid = mempool_to_bpid(mb_pool);
     737                 :          0 :                 ret = dpaa2_attach_bp_list(priv, dpni,
     738                 :          0 :                                 rte_dpaa2_bpid_info[bpid].bp_list);
     739         [ #  # ]:          0 :                 if (ret)
     740                 :            :                         return ret;
     741                 :            :         }
     742                 :          0 :         dpaa2_q = priv->rx_vq[rx_queue_id];
     743                 :          0 :         dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
     744                 :          0 :         dpaa2_q->bp_array = rte_dpaa2_bpid_info;
     745                 :          0 :         dpaa2_q->nb_desc = UINT16_MAX;
     746                 :          0 :         dpaa2_q->offloads = rx_conf->offloads;
     747                 :            : 
     748                 :            :         /*Get the flow id from given VQ id*/
     749                 :          0 :         flow_id = dpaa2_q->flow_id;
     750                 :            :         memset(&cfg, 0, sizeof(struct dpni_queue));
     751                 :            : 
     752                 :            :         options = options | DPNI_QUEUE_OPT_USER_CTX;
     753                 :          0 :         cfg.user_context = (size_t)(dpaa2_q);
     754                 :            : 
     755                 :            :         /* check if a private cgr available. */
     756         [ #  # ]:          0 :         for (i = 0; i < priv->max_cgs; i++) {
     757         [ #  # ]:          0 :                 if (!priv->cgid_in_use[i]) {
     758                 :          0 :                         priv->cgid_in_use[i] = 1;
     759                 :          0 :                         break;
     760                 :            :                 }
     761                 :            :         }
     762                 :            : 
     763         [ #  # ]:          0 :         if (i < priv->max_cgs) {
     764                 :            :                 options |= DPNI_QUEUE_OPT_SET_CGID;
     765                 :          0 :                 cfg.cgid = i;
     766                 :          0 :                 dpaa2_q->cgid = cfg.cgid;
     767                 :            :         } else {
     768                 :          0 :                 dpaa2_q->cgid = DPAA2_INVALID_CGID;
     769                 :            :         }
     770                 :            : 
     771                 :            :         /*if ls2088 or rev2 device, enable the stashing */
     772                 :            : 
     773         [ #  # ]:          0 :         if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
     774                 :          0 :                 options |= DPNI_QUEUE_OPT_FLC;
     775                 :          0 :                 cfg.flc.stash_control = true;
     776                 :            :                 dpaa2_flc_stashing_clear_all(&cfg.flc.value);
     777         [ #  # ]:          0 :                 if (getenv("DPAA2_DATA_STASHING_OFF")) {
     778                 :            :                         dpaa2_flc_stashing_set(DPAA2_FLC_DATA_STASHING, 0,
     779                 :            :                                 &cfg.flc.value);
     780                 :          0 :                         dpaa2_q->data_stashing_off = 1;
     781                 :            :                 } else {
     782                 :            :                         dpaa2_flc_stashing_set(DPAA2_FLC_DATA_STASHING, 1,
     783                 :            :                                 &cfg.flc.value);
     784                 :          0 :                         dpaa2_q->data_stashing_off = 0;
     785                 :            :                 }
     786         [ #  # ]:          0 :                 if ((dpaa2_svr_family & 0xffff0000) != SVR_LX2160A) {
     787                 :            :                         dpaa2_flc_stashing_set(DPAA2_FLC_ANNO_STASHING, 1,
     788                 :            :                                 &cfg.flc.value);
     789                 :            :                 }
     790                 :            :         }
     791                 :          0 :         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
     792                 :          0 :                         dpaa2_q->tc_index, flow_id, options, &cfg);
     793         [ #  # ]:          0 :         if (ret) {
     794                 :          0 :                 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
     795                 :          0 :                 return ret;
     796                 :            :         }
     797                 :            : 
     798         [ #  # ]:          0 :         if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
     799                 :            :                 struct dpni_taildrop taildrop;
     800                 :            : 
     801                 :          0 :                 taildrop.enable = 1;
     802                 :          0 :                 dpaa2_q->nb_desc = nb_rx_desc;
     803                 :            :                 /* Private CGR will use tail drop length as nb_rx_desc.
     804                 :            :                  * for rest cases we can use standard byte based tail drop.
     805                 :            :                  * There is no HW restriction, but number of CGRs are limited,
     806                 :            :                  * hence this restriction is placed.
     807                 :            :                  */
     808         [ #  # ]:          0 :                 if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
     809                 :            :                         /*enabling per rx queue congestion control */
     810                 :          0 :                         taildrop.threshold = nb_rx_desc;
     811                 :          0 :                         taildrop.units = DPNI_CONGESTION_UNIT_FRAMES;
     812                 :          0 :                         taildrop.oal = 0;
     813                 :          0 :                         DPAA2_PMD_DEBUG("Enabling CG Tail Drop on queue = %d",
     814                 :            :                                         rx_queue_id);
     815                 :          0 :                         ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
     816                 :            :                                                 DPNI_CP_CONGESTION_GROUP,
     817                 :            :                                                 DPNI_QUEUE_RX,
     818                 :          0 :                                                 dpaa2_q->tc_index,
     819                 :          0 :                                                 dpaa2_q->cgid, &taildrop);
     820                 :            :                 } else {
     821                 :            :                         /*enabling per rx queue congestion control */
     822                 :          0 :                         taildrop.threshold = CONG_THRESHOLD_RX_BYTES_Q;
     823                 :          0 :                         taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
     824                 :          0 :                         taildrop.oal = CONG_RX_OAL;
     825                 :          0 :                         DPAA2_PMD_DEBUG("Enabling Byte based Drop on queue= %d",
     826                 :            :                                         rx_queue_id);
     827                 :          0 :                         ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
     828                 :            :                                                 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
     829                 :          0 :                                                 dpaa2_q->tc_index, flow_id,
     830                 :            :                                                 &taildrop);
     831                 :            :                 }
     832         [ #  # ]:          0 :                 if (ret) {
     833                 :          0 :                         DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
     834                 :            :                                 ret);
     835                 :          0 :                         return ret;
     836                 :            :                 }
     837                 :            :         } else { /* Disable tail Drop */
     838                 :          0 :                 struct dpni_taildrop taildrop = {0};
     839                 :          0 :                 DPAA2_PMD_INFO("Tail drop is disabled on queue");
     840                 :            : 
     841                 :          0 :                 taildrop.enable = 0;
     842         [ #  # ]:          0 :                 if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
     843                 :          0 :                         ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
     844                 :            :                                         DPNI_CP_CONGESTION_GROUP, DPNI_QUEUE_RX,
     845                 :          0 :                                         dpaa2_q->tc_index,
     846                 :            :                                         dpaa2_q->cgid, &taildrop);
     847                 :            :                 } else {
     848                 :          0 :                         ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
     849                 :            :                                         DPNI_CP_QUEUE, DPNI_QUEUE_RX,
     850                 :          0 :                                         dpaa2_q->tc_index, flow_id, &taildrop);
     851                 :            :                 }
     852         [ #  # ]:          0 :                 if (ret) {
     853                 :          0 :                         DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
     854                 :            :                                 ret);
     855                 :          0 :                         return ret;
     856                 :            :                 }
     857                 :            :         }
     858                 :            : 
     859                 :          0 :         dev->data->rx_queues[rx_queue_id] = dpaa2_q;
     860                 :          0 :         return 0;
     861                 :            : }
     862                 :            : 
     863                 :            : static int
     864                 :          0 : dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
     865                 :            :         uint16_t tx_queue_id,
     866                 :            :         uint16_t nb_tx_desc,
     867                 :            :         unsigned int socket_id __rte_unused,
     868                 :            :         const struct rte_eth_txconf *tx_conf)
     869                 :            : {
     870                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
     871                 :          0 :         struct dpaa2_queue *dpaa2_q = priv->tx_vq[tx_queue_id];
     872                 :          0 :         struct dpaa2_queue *dpaa2_tx_conf_q = priv->tx_conf_vq[tx_queue_id];
     873                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
     874                 :            :         struct dpni_queue tx_conf_cfg;
     875                 :            :         struct dpni_queue tx_flow_cfg;
     876                 :            :         uint8_t options = 0, flow_id;
     877                 :            :         uint8_t ceetm_ch_idx;
     878                 :            :         uint16_t channel_id;
     879                 :            :         struct dpni_queue_id qid;
     880                 :            :         uint32_t tc_id;
     881                 :            :         int ret;
     882                 :            :         uint64_t iova;
     883                 :            : 
     884                 :          0 :         PMD_INIT_FUNC_TRACE();
     885                 :            : 
     886                 :          0 :         dpaa2_q->nb_desc = UINT16_MAX;
     887                 :          0 :         dpaa2_q->offloads = tx_conf->offloads;
     888                 :            : 
     889                 :            :         /* Return if queue already configured */
     890         [ #  # ]:          0 :         if (dpaa2_q->flow_id != DPAA2_INVALID_FLOW_ID) {
     891                 :          0 :                 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
     892                 :          0 :                 return 0;
     893                 :            :         }
     894                 :            : 
     895                 :            :         memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
     896                 :            :         memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
     897                 :            : 
     898         [ #  # ]:          0 :         if (!tx_queue_id) {
     899                 :            :                 for (ceetm_ch_idx = 0;
     900         [ #  # ]:          0 :                         ceetm_ch_idx <= (priv->num_channels - 1);
     901                 :          0 :                         ceetm_ch_idx++) {
     902                 :            :                         /*Set tx-conf and error configuration*/
     903         [ #  # ]:          0 :                         if (priv->flags & DPAA2_TX_CONF_ENABLE) {
     904                 :          0 :                                 ret = dpni_set_tx_confirmation_mode(dpni,
     905                 :          0 :                                                 CMD_PRI_LOW, priv->token,
     906                 :            :                                                 ceetm_ch_idx,
     907                 :            :                                                 DPNI_CONF_AFFINE);
     908                 :            :                         } else {
     909                 :          0 :                                 ret = dpni_set_tx_confirmation_mode(dpni,
     910                 :          0 :                                                 CMD_PRI_LOW, priv->token,
     911                 :            :                                                 ceetm_ch_idx,
     912                 :            :                                                 DPNI_CONF_DISABLE);
     913                 :            :                         }
     914         [ #  # ]:          0 :                         if (ret) {
     915                 :          0 :                                 DPAA2_PMD_ERR("Error(%d) in tx conf setting",
     916                 :            :                                         ret);
     917                 :          0 :                                 return ret;
     918                 :            :                         }
     919                 :            :                 }
     920                 :            :         }
     921                 :            : 
     922                 :          0 :         tc_id = tx_queue_id % priv->num_tx_tc;
     923                 :          0 :         channel_id = (uint8_t)(tx_queue_id / priv->num_tx_tc) % priv->num_channels;
     924                 :            :         flow_id = 0;
     925                 :            : 
     926                 :          0 :         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
     927                 :          0 :                         ((channel_id << 8) | tc_id), flow_id, options, &tx_flow_cfg);
     928         [ #  # ]:          0 :         if (ret) {
     929                 :          0 :                 DPAA2_PMD_ERR("Error in setting the tx flow: "
     930                 :            :                         "tc_id=%d, flow=%d err=%d",
     931                 :            :                         tc_id, flow_id, ret);
     932                 :          0 :                         return ret;
     933                 :            :         }
     934                 :            : 
     935                 :          0 :         dpaa2_q->flow_id = flow_id;
     936                 :            : 
     937                 :          0 :         dpaa2_q->tc_index = tc_id;
     938                 :            : 
     939                 :          0 :         ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
     940                 :          0 :                         DPNI_QUEUE_TX, ((channel_id << 8) | dpaa2_q->tc_index),
     941                 :            :                         dpaa2_q->flow_id, &tx_flow_cfg, &qid);
     942         [ #  # ]:          0 :         if (ret) {
     943                 :          0 :                 DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
     944                 :          0 :                 return ret;
     945                 :            :         }
     946                 :          0 :         dpaa2_q->fqid = qid.fqid;
     947                 :            : 
     948         [ #  # ]:          0 :         if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
     949                 :          0 :                 struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
     950                 :            : 
     951                 :          0 :                 dpaa2_q->nb_desc = nb_tx_desc;
     952                 :            : 
     953                 :          0 :                 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
     954                 :          0 :                 cong_notif_cfg.threshold_entry = nb_tx_desc;
     955                 :            :                 /* Notify that the queue is not congested when the data in
     956                 :            :                  * the queue is below this threshold.(90% of value)
     957                 :            :                  */
     958                 :          0 :                 cong_notif_cfg.threshold_exit = (nb_tx_desc * 9) / 10;
     959                 :            :                 cong_notif_cfg.message_ctx = 0;
     960                 :            : 
     961                 :          0 :                 iova = DPAA2_VADDR_TO_IOVA_AND_CHECK(dpaa2_q->cscn,
     962                 :            :                         sizeof(struct qbman_result));
     963         [ #  # ]:          0 :                 if (iova == RTE_BAD_IOVA) {
     964                 :          0 :                         DPAA2_PMD_ERR("No IOMMU map for cscn(%p)(size=%x)",
     965                 :            :                                 dpaa2_q->cscn, (uint32_t)sizeof(struct qbman_result));
     966                 :            : 
     967                 :          0 :                         return -ENOBUFS;
     968                 :            :                 }
     969                 :            : 
     970                 :          0 :                 cong_notif_cfg.message_iova = iova;
     971                 :          0 :                 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
     972                 :          0 :                 cong_notif_cfg.notification_mode =
     973                 :            :                                          DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
     974                 :            :                                          DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
     975                 :            :                                          DPNI_CONG_OPT_COHERENT_WRITE;
     976                 :          0 :                 cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
     977                 :            : 
     978                 :          0 :                 ret = dpni_set_congestion_notification(dpni,
     979                 :          0 :                                 CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
     980                 :            :                                 ((channel_id << 8) | tc_id), &cong_notif_cfg);
     981         [ #  # ]:          0 :                 if (ret) {
     982                 :          0 :                         DPAA2_PMD_ERR("Set TX congestion notification err=%d",
     983                 :            :                            ret);
     984                 :          0 :                         return ret;
     985                 :            :                 }
     986                 :            :         }
     987                 :          0 :         dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
     988                 :          0 :         dev->data->tx_queues[tx_queue_id] = dpaa2_q;
     989                 :            : 
     990         [ #  # ]:          0 :         if (priv->flags & DPAA2_TX_CONF_ENABLE) {
     991                 :          0 :                 dpaa2_q->tx_conf_queue = dpaa2_tx_conf_q;
     992                 :            :                 options = options | DPNI_QUEUE_OPT_USER_CTX;
     993                 :          0 :                 tx_conf_cfg.user_context = (size_t)(dpaa2_q);
     994                 :          0 :                 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
     995                 :            :                                 DPNI_QUEUE_TX_CONFIRM,
     996                 :          0 :                                 ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
     997                 :          0 :                                 dpaa2_tx_conf_q->flow_id,
     998                 :            :                                 options, &tx_conf_cfg);
     999         [ #  # ]:          0 :                 if (ret) {
    1000                 :          0 :                         DPAA2_PMD_ERR("Set TC[%d].TX[%d] conf flow err=%d",
    1001                 :            :                                 dpaa2_tx_conf_q->tc_index,
    1002                 :            :                                 dpaa2_tx_conf_q->flow_id, ret);
    1003                 :          0 :                         return ret;
    1004                 :            :                 }
    1005                 :            : 
    1006                 :          0 :                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
    1007                 :            :                                 DPNI_QUEUE_TX_CONFIRM,
    1008                 :          0 :                                 ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
    1009                 :          0 :                                 dpaa2_tx_conf_q->flow_id, &tx_conf_cfg, &qid);
    1010         [ #  # ]:          0 :                 if (ret) {
    1011                 :          0 :                         DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
    1012                 :          0 :                         return ret;
    1013                 :            :                 }
    1014                 :          0 :                 dpaa2_tx_conf_q->fqid = qid.fqid;
    1015                 :            :         }
    1016                 :            :         return 0;
    1017                 :            : }
    1018                 :            : 
    1019                 :            : static void
    1020                 :          0 : dpaa2_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    1021                 :            : {
    1022                 :          0 :         struct dpaa2_queue *dpaa2_q = dev->data->rx_queues[rx_queue_id];
    1023                 :          0 :         struct dpaa2_dev_priv *priv = dpaa2_q->eth_data->dev_private;
    1024                 :          0 :         struct fsl_mc_io *dpni = priv->eth_dev->process_private;
    1025                 :            :         uint8_t options = 0;
    1026                 :            :         int ret;
    1027                 :            :         struct dpni_queue cfg;
    1028                 :            : 
    1029                 :            :         memset(&cfg, 0, sizeof(struct dpni_queue));
    1030                 :          0 :         PMD_INIT_FUNC_TRACE();
    1031                 :            : 
    1032                 :          0 :         total_nb_rx_desc -= dpaa2_q->nb_desc;
    1033                 :            : 
    1034         [ #  # ]:          0 :         if (dpaa2_q->cgid != DPAA2_INVALID_CGID) {
    1035                 :            :                 options = DPNI_QUEUE_OPT_CLEAR_CGID;
    1036                 :          0 :                 cfg.cgid = dpaa2_q->cgid;
    1037                 :            : 
    1038                 :          0 :                 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
    1039                 :            :                                      DPNI_QUEUE_RX,
    1040                 :          0 :                                      dpaa2_q->tc_index, dpaa2_q->flow_id,
    1041                 :            :                                      options, &cfg);
    1042         [ #  # ]:          0 :                 if (ret)
    1043                 :          0 :                         DPAA2_PMD_ERR("Unable to clear CGR from q=%u err=%d",
    1044                 :            :                                         dpaa2_q->fqid, ret);
    1045                 :          0 :                 priv->cgid_in_use[dpaa2_q->cgid] = 0;
    1046                 :          0 :                 dpaa2_q->cgid = DPAA2_INVALID_CGID;
    1047                 :            :         }
    1048                 :          0 : }
    1049                 :            : 
    1050                 :            : static uint32_t
    1051                 :          0 : dpaa2_dev_rx_queue_count(void *rx_queue)
    1052                 :            : {
    1053                 :            :         int32_t ret;
    1054                 :            :         struct dpaa2_queue *dpaa2_q;
    1055                 :            :         struct qbman_swp *swp;
    1056                 :            :         struct qbman_fq_query_np_rslt state;
    1057                 :            :         uint32_t frame_cnt = 0;
    1058                 :            : 
    1059         [ #  # ]:          0 :         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
    1060                 :          0 :                 ret = dpaa2_affine_qbman_swp();
    1061         [ #  # ]:          0 :                 if (ret) {
    1062                 :          0 :                         DPAA2_PMD_ERR(
    1063                 :            :                                 "Failed to allocate IO portal, tid: %d",
    1064                 :            :                                 rte_gettid());
    1065                 :          0 :                         return -EINVAL;
    1066                 :            :                 }
    1067                 :            :         }
    1068                 :          0 :         swp = DPAA2_PER_LCORE_PORTAL;
    1069                 :            : 
    1070                 :            :         dpaa2_q = rx_queue;
    1071                 :            : 
    1072         [ #  # ]:          0 :         if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
    1073                 :          0 :                 frame_cnt = qbman_fq_state_frame_count(&state);
    1074                 :            :                 DPAA2_PMD_DP_DEBUG("RX frame count for q(%p) is %u",
    1075                 :            :                                 rx_queue, frame_cnt);
    1076                 :            :         }
    1077                 :            :         return frame_cnt;
    1078                 :            : }
    1079                 :            : 
    1080                 :            : static const uint32_t *
    1081                 :          0 : dpaa2_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
    1082                 :            : {
    1083                 :            :         static const uint32_t ptypes[] = {
    1084                 :            :                 /*todo -= add more types */
    1085                 :            :                 RTE_PTYPE_L2_ETHER,
    1086                 :            :                 RTE_PTYPE_L3_IPV4,
    1087                 :            :                 RTE_PTYPE_L3_IPV4_EXT,
    1088                 :            :                 RTE_PTYPE_L3_IPV6,
    1089                 :            :                 RTE_PTYPE_L3_IPV6_EXT,
    1090                 :            :                 RTE_PTYPE_L4_TCP,
    1091                 :            :                 RTE_PTYPE_L4_UDP,
    1092                 :            :                 RTE_PTYPE_L4_SCTP,
    1093                 :            :                 RTE_PTYPE_L4_ICMP,
    1094                 :            :         };
    1095                 :            : 
    1096   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
    1097         [ #  # ]:          0 :                 dev->rx_pkt_burst == dpaa2_dev_rx ||
    1098                 :            :                 dev->rx_pkt_burst == dpaa2_dev_loopback_rx) {
    1099                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
    1100                 :          0 :                 return ptypes;
    1101                 :            :         }
    1102                 :            :         return NULL;
    1103                 :            : }
    1104                 :            : 
    1105                 :            : /**
    1106                 :            :  * Dpaa2 link Interrupt handler
    1107                 :            :  *
    1108                 :            :  * @param param
    1109                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    1110                 :            :  *
    1111                 :            :  * @return
    1112                 :            :  *  void
    1113                 :            :  */
    1114                 :            : static void
    1115                 :          0 : dpaa2_interrupt_handler(void *param)
    1116                 :            : {
    1117                 :            :         struct rte_eth_dev *dev = param;
    1118                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1119                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1120                 :            :         int ret;
    1121                 :            :         int irq_index = DPNI_IRQ_INDEX;
    1122                 :          0 :         unsigned int status = 0, clear = 0;
    1123                 :            : 
    1124                 :          0 :         PMD_INIT_FUNC_TRACE();
    1125                 :            : 
    1126         [ #  # ]:          0 :         if (dpni == NULL) {
    1127                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1128                 :          0 :                 return;
    1129                 :            :         }
    1130                 :            : 
    1131                 :          0 :         ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
    1132                 :            :                                   irq_index, &status);
    1133         [ #  # ]:          0 :         if (unlikely(ret)) {
    1134                 :          0 :                 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
    1135                 :            :                 clear = 0xffffffff;
    1136                 :          0 :                 goto out;
    1137                 :            :         }
    1138                 :            : 
    1139         [ #  # ]:          0 :         if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
    1140                 :            :                 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
    1141                 :          0 :                 dpaa2_dev_link_update(dev, 0);
    1142                 :            :                 /* calling all the apps registered for link status event */
    1143                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    1144                 :            :         }
    1145                 :          0 : out:
    1146                 :          0 :         ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
    1147                 :            :                                     irq_index, clear);
    1148         [ #  # ]:          0 :         if (unlikely(ret))
    1149                 :          0 :                 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
    1150                 :            : }
    1151                 :            : 
    1152                 :            : static int
    1153                 :          0 : dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
    1154                 :            : {
    1155                 :            :         int err = 0;
    1156                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1157                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1158                 :            :         int irq_index = DPNI_IRQ_INDEX;
    1159                 :            :         unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
    1160                 :            : 
    1161                 :          0 :         PMD_INIT_FUNC_TRACE();
    1162                 :            : 
    1163                 :          0 :         err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
    1164                 :            :                                 irq_index, mask);
    1165         [ #  # ]:          0 :         if (err < 0) {
    1166                 :          0 :                 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
    1167                 :            :                               strerror(-err));
    1168                 :          0 :                 return err;
    1169                 :            :         }
    1170                 :            : 
    1171                 :          0 :         err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
    1172                 :            :                                   irq_index, enable);
    1173         [ #  # ]:          0 :         if (err < 0)
    1174                 :          0 :                 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
    1175                 :            :                               strerror(-err));
    1176                 :            : 
    1177                 :            :         return err;
    1178                 :            : }
    1179                 :            : 
    1180                 :            : static int
    1181                 :          0 : dpaa2_dev_start(struct rte_eth_dev *dev)
    1182                 :            : {
    1183                 :          0 :         struct rte_device *rdev = dev->device;
    1184                 :            :         struct rte_dpaa2_device *dpaa2_dev;
    1185                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1186                 :          0 :         struct dpaa2_dev_priv *priv = data->dev_private;
    1187                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1188                 :            :         struct dpni_queue cfg;
    1189                 :            :         struct dpni_error_cfg   err_cfg;
    1190                 :            :         struct dpni_queue_id qid;
    1191                 :            :         struct dpaa2_queue *dpaa2_q;
    1192                 :            :         int ret, i;
    1193                 :            :         struct rte_intr_handle *intr_handle;
    1194                 :            : 
    1195                 :          0 :         dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
    1196                 :          0 :         intr_handle = dpaa2_dev->intr_handle;
    1197                 :            : 
    1198                 :          0 :         PMD_INIT_FUNC_TRACE();
    1199                 :          0 :         ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
    1200         [ #  # ]:          0 :         if (ret) {
    1201                 :          0 :                 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
    1202                 :            :                               priv->hw_id, ret);
    1203                 :          0 :                 return ret;
    1204                 :            :         }
    1205                 :            : 
    1206                 :            :         /* Power up the phy. Needed to make the link go UP */
    1207                 :          0 :         dpaa2_dev_set_link_up(dev);
    1208                 :            : 
    1209         [ #  # ]:          0 :         for (i = 0; i < data->nb_rx_queues; i++) {
    1210                 :          0 :                 dpaa2_q = data->rx_queues[i];
    1211                 :          0 :                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
    1212                 :          0 :                                 DPNI_QUEUE_RX, dpaa2_q->tc_index,
    1213                 :          0 :                                 dpaa2_q->flow_id, &cfg, &qid);
    1214         [ #  # ]:          0 :                 if (ret) {
    1215                 :          0 :                         DPAA2_PMD_ERR("Error in getting flow information: "
    1216                 :            :                                       "err=%d", ret);
    1217                 :          0 :                         return ret;
    1218                 :            :                 }
    1219                 :          0 :                 dpaa2_q->fqid = qid.fqid;
    1220                 :            :         }
    1221                 :            : 
    1222         [ #  # ]:          0 :         if (dpaa2_enable_err_queue) {
    1223                 :          0 :                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
    1224                 :            :                                      DPNI_QUEUE_RX_ERR, 0, 0, &cfg, &qid);
    1225         [ #  # ]:          0 :                 if (ret) {
    1226                 :          0 :                         DPAA2_PMD_ERR("Error getting rx err flow information: err=%d",
    1227                 :            :                                                 ret);
    1228                 :          0 :                         return ret;
    1229                 :            :                 }
    1230                 :          0 :                 dpaa2_q = priv->rx_err_vq;
    1231                 :          0 :                 dpaa2_q->fqid = qid.fqid;
    1232                 :          0 :                 dpaa2_q->eth_data = dev->data;
    1233                 :            : 
    1234                 :          0 :                 err_cfg.errors =  DPNI_ERROR_DISC;
    1235                 :          0 :                 err_cfg.error_action = DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE;
    1236                 :            :         } else {
    1237                 :            :                 /* checksum errors, send them to normal path
    1238                 :            :                  * and set it in annotation
    1239                 :            :                  */
    1240                 :            :                 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
    1241                 :            : 
    1242                 :            :                 /* if packet with parse error are not to be dropped */
    1243                 :          0 :                 err_cfg.errors |= DPNI_ERROR_PHE;
    1244                 :            : 
    1245                 :          0 :                 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
    1246                 :            :         }
    1247                 :          0 :         err_cfg.set_frame_annotation = true;
    1248                 :            : 
    1249                 :          0 :         ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
    1250                 :          0 :                                        priv->token, &err_cfg);
    1251         [ #  # ]:          0 :         if (ret) {
    1252                 :          0 :                 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
    1253                 :            :                               ret);
    1254                 :          0 :                 return ret;
    1255                 :            :         }
    1256                 :            : 
    1257                 :            :         /* if the interrupts were configured on this devices*/
    1258   [ #  #  #  # ]:          0 :         if (intr_handle && rte_intr_fd_get(intr_handle) &&
    1259         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.lsc != 0) {
    1260                 :            :                 /* Registering LSC interrupt handler */
    1261                 :          0 :                 rte_intr_callback_register(intr_handle,
    1262                 :            :                                            dpaa2_interrupt_handler,
    1263                 :            :                                            (void *)dev);
    1264                 :            : 
    1265                 :            :                 /* enable vfio intr/eventfd mapping
    1266                 :            :                  * Interrupt index 0 is required, so we can not use
    1267                 :            :                  * rte_intr_enable.
    1268                 :            :                  */
    1269                 :          0 :                 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
    1270                 :            : 
    1271                 :            :                 /* enable dpni_irqs */
    1272                 :          0 :                 dpaa2_eth_setup_irqs(dev, 1);
    1273                 :            :         }
    1274                 :            : 
    1275                 :            :         /* Change the tx burst function if ordered queues are used */
    1276         [ #  # ]:          0 :         if (priv->en_ordered)
    1277                 :          0 :                 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
    1278                 :            : 
    1279         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
    1280                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    1281         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
    1282                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    1283                 :            : 
    1284                 :            :         return 0;
    1285                 :            : }
    1286                 :            : 
    1287                 :            : /**
    1288                 :            :  *  This routine disables all traffic on the adapter by issuing a
    1289                 :            :  *  global reset on the MAC.
    1290                 :            :  */
    1291                 :            : static int
    1292                 :          0 : dpaa2_dev_stop(struct rte_eth_dev *dev)
    1293                 :            : {
    1294                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1295                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1296                 :            :         int ret;
    1297                 :            :         struct rte_eth_link link;
    1298                 :          0 :         struct rte_device *rdev = dev->device;
    1299                 :            :         struct rte_intr_handle *intr_handle;
    1300                 :            :         struct rte_dpaa2_device *dpaa2_dev;
    1301                 :            :         uint16_t i;
    1302                 :            : 
    1303                 :          0 :         dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
    1304                 :          0 :         intr_handle = dpaa2_dev->intr_handle;
    1305                 :            : 
    1306                 :          0 :         PMD_INIT_FUNC_TRACE();
    1307                 :            : 
    1308                 :            :         /* reset interrupt callback  */
    1309   [ #  #  #  # ]:          0 :         if (intr_handle && rte_intr_fd_get(intr_handle) &&
    1310         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.lsc != 0) {
    1311                 :            :                 /*disable dpni irqs */
    1312                 :          0 :                 dpaa2_eth_setup_irqs(dev, 0);
    1313                 :            : 
    1314                 :            :                 /* disable vfio intr before callback unregister */
    1315                 :          0 :                 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
    1316                 :            : 
    1317                 :            :                 /* Unregistering LSC interrupt handler */
    1318                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    1319                 :            :                                              dpaa2_interrupt_handler,
    1320                 :            :                                              (void *)dev);
    1321                 :            :         }
    1322                 :            : 
    1323                 :          0 :         dpaa2_dev_set_link_down(dev);
    1324                 :            : 
    1325                 :          0 :         ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
    1326         [ #  # ]:          0 :         if (ret) {
    1327                 :          0 :                 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
    1328                 :            :                               ret, priv->hw_id);
    1329                 :          0 :                 return ret;
    1330                 :            :         }
    1331                 :            : 
    1332                 :            :         /* clear the recorded link status */
    1333                 :            :         memset(&link, 0, sizeof(link));
    1334                 :          0 :         rte_eth_linkstatus_set(dev, &link);
    1335                 :            : 
    1336         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++)
    1337                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1338         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++)
    1339                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1340                 :            : 
    1341                 :            :         return 0;
    1342                 :            : }
    1343                 :            : 
    1344                 :            : static int
    1345                 :          0 : dpaa2_dev_close(struct rte_eth_dev *dev)
    1346                 :            : {
    1347                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1348                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1349                 :            :         int i, ret;
    1350                 :            :         struct rte_eth_link link;
    1351                 :            : 
    1352                 :          0 :         PMD_INIT_FUNC_TRACE();
    1353                 :            : 
    1354         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1355                 :            :                 return 0;
    1356                 :            : 
    1357         [ #  # ]:          0 :         if (!dpni) {
    1358                 :          0 :                 DPAA2_PMD_WARN("Already closed or not started");
    1359                 :          0 :                 return -EINVAL;
    1360                 :            :         }
    1361                 :            : 
    1362                 :          0 :         dpaa2_tm_deinit(dev);
    1363                 :          0 :         dpaa2_flow_clean(dev);
    1364                 :            :         /* Clean the device first */
    1365                 :          0 :         ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
    1366         [ #  # ]:          0 :         if (ret) {
    1367                 :          0 :                 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
    1368                 :          0 :                 return ret;
    1369                 :            :         }
    1370                 :            : 
    1371                 :            :         memset(&link, 0, sizeof(link));
    1372                 :          0 :         rte_eth_linkstatus_set(dev, &link);
    1373                 :            : 
    1374                 :            :         /* Free private queues memory */
    1375                 :          0 :         dpaa2_free_rx_tx_queues(dev);
    1376                 :            :         /* Close the device at underlying layer*/
    1377                 :          0 :         ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
    1378         [ #  # ]:          0 :         if (ret) {
    1379                 :          0 :                 DPAA2_PMD_ERR("Failure closing dpni device with err code %d",
    1380                 :            :                         ret);
    1381                 :            :         }
    1382                 :            : 
    1383                 :            :         /* Free the allocated memory for ethernet private data and dpni*/
    1384                 :          0 :         priv->hw = NULL;
    1385                 :          0 :         dev->process_private = NULL;
    1386                 :          0 :         rte_free(dpni);
    1387                 :            : 
    1388         [ #  # ]:          0 :         for (i = 0; i < MAX_TCS; i++)
    1389                 :          0 :                 rte_free(priv->extract.tc_extract_param[i]);
    1390                 :            : 
    1391                 :          0 :         rte_free(priv->extract.qos_extract_param);
    1392                 :            : 
    1393                 :          0 :         DPAA2_PMD_INFO("%s: netdev deleted", dev->data->name);
    1394                 :          0 :         return 0;
    1395                 :            : }
    1396                 :            : 
    1397                 :            : static int
    1398                 :          0 : dpaa2_dev_promiscuous_enable(struct rte_eth_dev *dev)
    1399                 :            : {
    1400                 :            :         int ret;
    1401                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1402                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1403                 :            : 
    1404                 :          0 :         PMD_INIT_FUNC_TRACE();
    1405                 :            : 
    1406         [ #  # ]:          0 :         if (dpni == NULL) {
    1407                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1408                 :          0 :                 return -ENODEV;
    1409                 :            :         }
    1410                 :            : 
    1411                 :          0 :         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
    1412         [ #  # ]:          0 :         if (ret < 0)
    1413                 :          0 :                 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
    1414                 :            : 
    1415                 :          0 :         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
    1416         [ #  # ]:          0 :         if (ret < 0)
    1417                 :          0 :                 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
    1418                 :            : 
    1419                 :            :         return ret;
    1420                 :            : }
    1421                 :            : 
    1422                 :            : static int
    1423                 :          0 : dpaa2_dev_promiscuous_disable(
    1424                 :            :                 struct rte_eth_dev *dev)
    1425                 :            : {
    1426                 :            :         int ret;
    1427                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1428                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1429                 :            : 
    1430                 :          0 :         PMD_INIT_FUNC_TRACE();
    1431                 :            : 
    1432         [ #  # ]:          0 :         if (dpni == NULL) {
    1433                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1434                 :          0 :                 return -ENODEV;
    1435                 :            :         }
    1436                 :            : 
    1437                 :          0 :         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
    1438         [ #  # ]:          0 :         if (ret < 0)
    1439                 :          0 :                 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
    1440                 :            : 
    1441         [ #  # ]:          0 :         if (dev->data->all_multicast == 0) {
    1442                 :          0 :                 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
    1443                 :          0 :                                                  priv->token, false);
    1444         [ #  # ]:          0 :                 if (ret < 0)
    1445                 :          0 :                         DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
    1446                 :            :                                       ret);
    1447                 :            :         }
    1448                 :            : 
    1449                 :            :         return ret;
    1450                 :            : }
    1451                 :            : 
    1452                 :            : static int
    1453                 :          0 : dpaa2_dev_allmulticast_enable(
    1454                 :            :                 struct rte_eth_dev *dev)
    1455                 :            : {
    1456                 :            :         int ret;
    1457                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1458                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1459                 :            : 
    1460                 :          0 :         PMD_INIT_FUNC_TRACE();
    1461                 :            : 
    1462         [ #  # ]:          0 :         if (dpni == NULL) {
    1463                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1464                 :          0 :                 return -ENODEV;
    1465                 :            :         }
    1466                 :            : 
    1467                 :          0 :         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
    1468         [ #  # ]:          0 :         if (ret < 0)
    1469                 :          0 :                 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
    1470                 :            : 
    1471                 :            :         return ret;
    1472                 :            : }
    1473                 :            : 
    1474                 :            : static int
    1475                 :          0 : dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
    1476                 :            : {
    1477                 :            :         int ret;
    1478                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1479                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1480                 :            : 
    1481                 :          0 :         PMD_INIT_FUNC_TRACE();
    1482                 :            : 
    1483         [ #  # ]:          0 :         if (dpni == NULL) {
    1484                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1485                 :          0 :                 return -ENODEV;
    1486                 :            :         }
    1487                 :            : 
    1488                 :            :         /* must remain on for all promiscuous */
    1489         [ #  # ]:          0 :         if (dev->data->promiscuous == 1)
    1490                 :            :                 return 0;
    1491                 :            : 
    1492                 :          0 :         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
    1493         [ #  # ]:          0 :         if (ret < 0)
    1494                 :          0 :                 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
    1495                 :            : 
    1496                 :            :         return ret;
    1497                 :            : }
    1498                 :            : 
    1499                 :            : static int
    1500                 :          0 : dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
    1501                 :            : {
    1502                 :            :         int ret;
    1503                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1504                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1505                 :            :         uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
    1506                 :          0 :                                 + VLAN_TAG_SIZE;
    1507                 :            : 
    1508                 :          0 :         PMD_INIT_FUNC_TRACE();
    1509                 :            : 
    1510         [ #  # ]:          0 :         if (!dpni) {
    1511                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1512                 :          0 :                 return -EINVAL;
    1513                 :            :         }
    1514                 :            : 
    1515                 :            :         /* Set the Max Rx frame length as 'mtu' +
    1516                 :            :          * Maximum Ethernet header length
    1517                 :            :          */
    1518                 :          0 :         ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
    1519                 :          0 :                                         frame_size - RTE_ETHER_CRC_LEN);
    1520         [ #  # ]:          0 :         if (ret) {
    1521                 :          0 :                 DPAA2_PMD_ERR("Setting the max frame length failed");
    1522                 :          0 :                 return ret;
    1523                 :            :         }
    1524                 :          0 :         dev->data->mtu = mtu;
    1525                 :          0 :         DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
    1526                 :          0 :         return 0;
    1527                 :            : }
    1528                 :            : 
    1529                 :            : static int
    1530                 :          0 : dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
    1531                 :            :         struct rte_ether_addr *addr,
    1532                 :            :         __rte_unused uint32_t index,
    1533                 :            :         __rte_unused uint32_t pool)
    1534                 :            : {
    1535                 :            :         int ret;
    1536                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1537                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1538                 :            : 
    1539                 :          0 :         PMD_INIT_FUNC_TRACE();
    1540                 :            : 
    1541         [ #  # ]:          0 :         if (dpni == NULL) {
    1542                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1543                 :          0 :                 return -EINVAL;
    1544                 :            :         }
    1545                 :            : 
    1546                 :          0 :         ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW, priv->token,
    1547                 :          0 :                                 addr->addr_bytes, 0, 0, 0);
    1548         [ #  # ]:          0 :         if (ret)
    1549                 :          0 :                 DPAA2_PMD_ERR("ERR(%d) Adding the MAC ADDR failed", ret);
    1550                 :            :         return ret;
    1551                 :            : }
    1552                 :            : 
    1553                 :            : static void
    1554                 :          0 : dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
    1555                 :            :         uint32_t index)
    1556                 :            : {
    1557                 :            :         int ret;
    1558                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1559                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1560                 :            :         struct rte_eth_dev_data *data = dev->data;
    1561                 :            :         struct rte_ether_addr *macaddr;
    1562                 :            : 
    1563                 :          0 :         PMD_INIT_FUNC_TRACE();
    1564                 :            : 
    1565                 :          0 :         macaddr = &data->mac_addrs[index];
    1566                 :            : 
    1567         [ #  # ]:          0 :         if (!dpni) {
    1568                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1569                 :          0 :                 return;
    1570                 :            :         }
    1571                 :            : 
    1572                 :          0 :         ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
    1573                 :          0 :                                    priv->token, macaddr->addr_bytes);
    1574         [ #  # ]:          0 :         if (ret)
    1575                 :          0 :                 DPAA2_PMD_ERR(
    1576                 :            :                         "error: Removing the MAC ADDR failed: err = %d", ret);
    1577                 :            : }
    1578                 :            : 
    1579                 :            : static int
    1580                 :          0 : dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
    1581                 :            :         struct rte_ether_addr *addr)
    1582                 :            : {
    1583                 :            :         int ret;
    1584                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1585                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1586                 :            : 
    1587                 :          0 :         PMD_INIT_FUNC_TRACE();
    1588                 :            : 
    1589         [ #  # ]:          0 :         if (!dpni) {
    1590                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1591                 :          0 :                 return -EINVAL;
    1592                 :            :         }
    1593                 :            : 
    1594                 :          0 :         ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
    1595                 :          0 :                                         priv->token, addr->addr_bytes);
    1596                 :            : 
    1597         [ #  # ]:          0 :         if (ret)
    1598                 :          0 :                 DPAA2_PMD_ERR("ERR(%d) Setting the MAC ADDR failed", ret);
    1599                 :            : 
    1600                 :            :         return ret;
    1601                 :            : }
    1602                 :            : 
    1603                 :            : static int
    1604                 :          0 : dpaa2_dev_stats_get(struct rte_eth_dev *dev,
    1605                 :            :         struct rte_eth_stats *stats)
    1606                 :            : {
    1607                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1608                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1609                 :            :         int32_t retcode;
    1610                 :            :         uint8_t page0 = 0, page1 = 1, page2 = 2;
    1611                 :            :         union dpni_statistics value;
    1612                 :            :         int i;
    1613                 :            :         struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
    1614                 :            : 
    1615                 :            :         memset(&value, 0, sizeof(union dpni_statistics));
    1616                 :            : 
    1617                 :          0 :         PMD_INIT_FUNC_TRACE();
    1618                 :            : 
    1619         [ #  # ]:          0 :         if (!dpni) {
    1620                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1621                 :          0 :                 return -EINVAL;
    1622                 :            :         }
    1623                 :            : 
    1624         [ #  # ]:          0 :         if (!stats) {
    1625                 :          0 :                 DPAA2_PMD_ERR("stats is NULL");
    1626                 :          0 :                 return -EINVAL;
    1627                 :            :         }
    1628                 :            : 
    1629                 :            :         /*Get Counters from page_0*/
    1630                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1631                 :            :                                       page0, 0, &value);
    1632         [ #  # ]:          0 :         if (retcode)
    1633                 :          0 :                 goto err;
    1634                 :            : 
    1635                 :          0 :         stats->ipackets = value.page_0.ingress_all_frames;
    1636                 :          0 :         stats->ibytes = value.page_0.ingress_all_bytes;
    1637                 :            : 
    1638                 :            :         /*Get Counters from page_1*/
    1639                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1640                 :            :                                       page1, 0, &value);
    1641         [ #  # ]:          0 :         if (retcode)
    1642                 :          0 :                 goto err;
    1643                 :            : 
    1644                 :          0 :         stats->opackets = value.page_1.egress_all_frames;
    1645                 :          0 :         stats->obytes = value.page_1.egress_all_bytes;
    1646                 :            : 
    1647                 :            :         /*Get Counters from page_2*/
    1648                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1649                 :            :                                       page2, 0, &value);
    1650         [ #  # ]:          0 :         if (retcode)
    1651                 :          0 :                 goto err;
    1652                 :            : 
    1653                 :            :         /* Ingress drop frame count due to configured rules */
    1654                 :          0 :         stats->ierrors = value.page_2.ingress_filtered_frames;
    1655                 :            :         /* Ingress drop frame count due to error */
    1656                 :          0 :         stats->ierrors += value.page_2.ingress_discarded_frames;
    1657                 :            : 
    1658                 :          0 :         stats->oerrors = value.page_2.egress_discarded_frames;
    1659                 :          0 :         stats->imissed = value.page_2.ingress_nobuffer_discards;
    1660                 :            : 
    1661                 :            :         /* Fill in per queue stats */
    1662         [ #  # ]:          0 :         for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
    1663   [ #  #  #  # ]:          0 :                 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
    1664                 :          0 :                 dpaa2_rxq = priv->rx_vq[i];
    1665                 :          0 :                 dpaa2_txq = priv->tx_vq[i];
    1666         [ #  # ]:          0 :                 if (dpaa2_rxq)
    1667                 :          0 :                         stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
    1668         [ #  # ]:          0 :                 if (dpaa2_txq)
    1669                 :          0 :                         stats->q_opackets[i] = dpaa2_txq->tx_pkts;
    1670                 :            : 
    1671                 :            :                 /* Byte counting is not implemented */
    1672                 :          0 :                 stats->q_ibytes[i]   = 0;
    1673                 :          0 :                 stats->q_obytes[i]   = 0;
    1674                 :            :         }
    1675                 :            : 
    1676                 :            :         return 0;
    1677                 :            : 
    1678                 :          0 : err:
    1679                 :          0 :         DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
    1680                 :          0 :         return retcode;
    1681                 :            : };
    1682                 :            : 
    1683                 :            : static int
    1684                 :          0 : dpaa2_dev_xstats_get(struct rte_eth_dev *dev,
    1685                 :            :         struct rte_eth_xstat *xstats, unsigned int n)
    1686                 :            : {
    1687                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1688                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    1689                 :            :         int32_t retcode;
    1690                 :          0 :         union dpni_statistics value[5] = {};
    1691                 :            :         unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
    1692                 :            :         uint8_t page_id, stats_id;
    1693                 :            : 
    1694         [ #  # ]:          0 :         if (n < num)
    1695                 :            :                 return num;
    1696                 :            : 
    1697         [ #  # ]:          0 :         if (!xstats)
    1698                 :            :                 return 0;
    1699                 :            : 
    1700                 :            :         /* Get Counters from page_0*/
    1701                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1702                 :            :                                       0, 0, &value[0]);
    1703         [ #  # ]:          0 :         if (retcode)
    1704                 :          0 :                 goto err;
    1705                 :            : 
    1706                 :            :         /* Get Counters from page_1*/
    1707                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1708                 :            :                                       1, 0, &value[1]);
    1709         [ #  # ]:          0 :         if (retcode)
    1710                 :          0 :                 goto err;
    1711                 :            : 
    1712                 :            :         /* Get Counters from page_2*/
    1713                 :          0 :         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1714                 :            :                                       2, 0, &value[2]);
    1715         [ #  # ]:          0 :         if (retcode)
    1716                 :          0 :                 goto err;
    1717                 :            : 
    1718         [ #  # ]:          0 :         for (i = 0; i < priv->max_cgs; i++) {
    1719         [ #  # ]:          0 :                 if (!priv->cgid_in_use[i]) {
    1720                 :            :                         /* Get Counters from page_4*/
    1721                 :          0 :                         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW,
    1722                 :          0 :                                                       priv->token,
    1723                 :            :                                                       4, 0, &value[4]);
    1724         [ #  # ]:          0 :                         if (retcode)
    1725                 :          0 :                                 goto err;
    1726                 :            :                         break;
    1727                 :            :                 }
    1728                 :            :         }
    1729                 :            : 
    1730         [ #  # ]:          0 :         for (i = 0; i < num; i++) {
    1731                 :          0 :                 xstats[i].id = i;
    1732                 :          0 :                 page_id = dpaa2_xstats_strings[i].page_id;
    1733                 :          0 :                 stats_id = dpaa2_xstats_strings[i].stats_id;
    1734                 :          0 :                 xstats[i].value = value[page_id].raw.counter[stats_id];
    1735                 :            :         }
    1736                 :            :         return i;
    1737                 :          0 : err:
    1738                 :          0 :         DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
    1739                 :          0 :         return retcode;
    1740                 :            : }
    1741                 :            : 
    1742                 :            : static int
    1743                 :          0 : dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
    1744                 :            :         struct rte_eth_xstat_name *xstats_names,
    1745                 :            :         unsigned int limit)
    1746                 :            : {
    1747                 :            :         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
    1748                 :            : 
    1749         [ #  # ]:          0 :         if (limit < stat_cnt)
    1750                 :            :                 return stat_cnt;
    1751                 :            : 
    1752         [ #  # ]:          0 :         if (xstats_names != NULL)
    1753         [ #  # ]:          0 :                 for (i = 0; i < stat_cnt; i++)
    1754                 :          0 :                         strlcpy(xstats_names[i].name,
    1755                 :            :                                 dpaa2_xstats_strings[i].name,
    1756                 :            :                                 sizeof(xstats_names[i].name));
    1757                 :            : 
    1758                 :            :         return stat_cnt;
    1759                 :            : }
    1760                 :            : 
    1761                 :            : static int
    1762                 :          0 : dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
    1763                 :            :         uint64_t *values, unsigned int n)
    1764                 :          0 : {
    1765                 :            :         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
    1766                 :          0 :         uint64_t values_copy[stat_cnt];
    1767                 :            :         uint8_t page_id, stats_id;
    1768                 :            : 
    1769         [ #  # ]:          0 :         if (!ids) {
    1770                 :          0 :                 struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1771                 :          0 :                 struct fsl_mc_io *dpni = dev->process_private;
    1772                 :            :                 int32_t retcode;
    1773                 :          0 :                 union dpni_statistics value[5] = {};
    1774                 :            : 
    1775         [ #  # ]:          0 :                 if (n < stat_cnt)
    1776                 :            :                         return stat_cnt;
    1777                 :            : 
    1778         [ #  # ]:          0 :                 if (!values)
    1779                 :            :                         return 0;
    1780                 :            : 
    1781                 :            :                 /* Get Counters from page_0*/
    1782                 :          0 :                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1783                 :            :                                               0, 0, &value[0]);
    1784         [ #  # ]:          0 :                 if (retcode)
    1785                 :            :                         return 0;
    1786                 :            : 
    1787                 :            :                 /* Get Counters from page_1*/
    1788                 :          0 :                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1789                 :            :                                               1, 0, &value[1]);
    1790         [ #  # ]:          0 :                 if (retcode)
    1791                 :            :                         return 0;
    1792                 :            : 
    1793                 :            :                 /* Get Counters from page_2*/
    1794                 :          0 :                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1795                 :            :                                               2, 0, &value[2]);
    1796         [ #  # ]:          0 :                 if (retcode)
    1797                 :            :                         return 0;
    1798                 :            : 
    1799                 :            :                 /* Get Counters from page_4*/
    1800                 :          0 :                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
    1801                 :            :                                               4, 0, &value[4]);
    1802         [ #  # ]:          0 :                 if (retcode)
    1803                 :            :                         return 0;
    1804                 :            : 
    1805         [ #  # ]:          0 :                 for (i = 0; i < stat_cnt; i++) {
    1806                 :          0 :                         page_id = dpaa2_xstats_strings[i].page_id;
    1807                 :          0 :                         stats_id = dpaa2_xstats_strings[i].stats_id;
    1808                 :          0 :                         values[i] = value[page_id].raw.counter[stats_id];
    1809                 :            :                 }
    1810                 :            :                 return stat_cnt;
    1811                 :            :         }
    1812                 :            : 
    1813                 :          0 :         dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
    1814                 :            : 
    1815         [ #  # ]:          0 :         for (i = 0; i < n; i++) {
    1816         [ #  # ]:          0 :                 if (ids[i] >= stat_cnt) {
    1817                 :          0 :                         DPAA2_PMD_ERR("xstats id value isn't valid");
    1818                 :          0 :                         return -EINVAL;
    1819                 :            :                 }
    1820                 :          0 :                 values[i] = values_copy[ids[i]];
    1821                 :            :         }
    1822                 :          0 :         return n;
    1823                 :            : }
    1824                 :            : 
    1825                 :            : static int
    1826                 :          0 : dpaa2_xstats_get_names_by_id(struct rte_eth_dev *dev,
    1827                 :            :         const uint64_t *ids,
    1828                 :            :         struct rte_eth_xstat_name *xstats_names,
    1829                 :            :         unsigned int limit)
    1830                 :          0 : {
    1831                 :            :         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
    1832                 :          0 :         struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
    1833                 :            : 
    1834         [ #  # ]:          0 :         if (!ids)
    1835                 :          0 :                 return dpaa2_xstats_get_names(dev, xstats_names, limit);
    1836                 :            : 
    1837                 :          0 :         dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
    1838                 :            : 
    1839         [ #  # ]:          0 :         for (i = 0; i < limit; i++) {
    1840         [ #  # ]:          0 :                 if (ids[i] >= stat_cnt) {
    1841                 :          0 :                         DPAA2_PMD_ERR("xstats id value isn't valid");
    1842                 :          0 :                         return -1;
    1843                 :            :                 }
    1844                 :          0 :                 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
    1845                 :            :         }
    1846                 :          0 :         return limit;
    1847                 :            : }
    1848                 :            : 
    1849                 :            : static int
    1850                 :          0 : dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
    1851                 :            : {
    1852                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1853                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1854                 :            :         int retcode;
    1855                 :            :         int i;
    1856                 :            :         struct dpaa2_queue *dpaa2_q;
    1857                 :            : 
    1858                 :          0 :         PMD_INIT_FUNC_TRACE();
    1859                 :            : 
    1860         [ #  # ]:          0 :         if (!dpni) {
    1861                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1862                 :          0 :                 return -EINVAL;
    1863                 :            :         }
    1864                 :            : 
    1865                 :          0 :         retcode =  dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
    1866         [ #  # ]:          0 :         if (retcode)
    1867                 :          0 :                 goto error;
    1868                 :            : 
    1869                 :            :         /* Reset the per queue stats in dpaa2_queue structure */
    1870         [ #  # ]:          0 :         for (i = 0; i < priv->nb_rx_queues; i++) {
    1871                 :          0 :                 dpaa2_q = priv->rx_vq[i];
    1872         [ #  # ]:          0 :                 if (dpaa2_q)
    1873                 :          0 :                         dpaa2_q->rx_pkts = 0;
    1874                 :            :         }
    1875                 :            : 
    1876         [ #  # ]:          0 :         for (i = 0; i < priv->nb_tx_queues; i++) {
    1877                 :          0 :                 dpaa2_q = priv->tx_vq[i];
    1878         [ #  # ]:          0 :                 if (dpaa2_q)
    1879                 :          0 :                         dpaa2_q->tx_pkts = 0;
    1880                 :            :         }
    1881                 :            : 
    1882                 :            :         return 0;
    1883                 :            : 
    1884                 :            : error:
    1885                 :          0 :         DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
    1886                 :          0 :         return retcode;
    1887                 :            : };
    1888                 :            : 
    1889                 :            : /* return 0 means link status changed, -1 means not changed */
    1890                 :            : static int
    1891                 :          0 : dpaa2_dev_link_update(struct rte_eth_dev *dev,
    1892                 :            :                       int wait_to_complete)
    1893                 :            : {
    1894                 :            :         int ret;
    1895                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    1896                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    1897                 :            :         struct rte_eth_link link;
    1898                 :          0 :         struct dpni_link_state state = {0};
    1899                 :            :         uint8_t count;
    1900                 :            : 
    1901         [ #  # ]:          0 :         if (!dpni) {
    1902                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1903                 :          0 :                 return 0;
    1904                 :            :         }
    1905                 :            : 
    1906         [ #  # ]:          0 :         for (count = 0; count <= MAX_REPEAT_TIME; count++) {
    1907                 :          0 :                 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token,
    1908                 :            :                                           &state);
    1909         [ #  # ]:          0 :                 if (ret < 0) {
    1910                 :          0 :                         DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
    1911                 :          0 :                         return ret;
    1912                 :            :                 }
    1913   [ #  #  #  # ]:          0 :                 if (state.up == RTE_ETH_LINK_DOWN &&
    1914                 :            :                     wait_to_complete)
    1915                 :            :                         rte_delay_ms(CHECK_INTERVAL);
    1916                 :            :                 else
    1917                 :            :                         break;
    1918                 :            :         }
    1919                 :            : 
    1920                 :            :         memset(&link, 0, sizeof(struct rte_eth_link));
    1921                 :          0 :         link.link_status = state.up;
    1922                 :          0 :         link.link_speed = state.rate;
    1923                 :            : 
    1924         [ #  # ]:          0 :         if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
    1925                 :            :                 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
    1926                 :            :         else
    1927                 :          0 :                 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    1928                 :            : 
    1929                 :            :         ret = rte_eth_linkstatus_set(dev, &link);
    1930                 :            :         if (ret < 0)
    1931                 :          0 :                 DPAA2_PMD_DEBUG("No change in status");
    1932                 :            :         else
    1933         [ #  # ]:          0 :                 DPAA2_PMD_INFO("Port %d Link is %s", dev->data->port_id,
    1934                 :            :                                link.link_status ? "Up" : "Down");
    1935                 :            : 
    1936                 :            :         return ret;
    1937                 :            : }
    1938                 :            : 
    1939                 :            : /**
    1940                 :            :  * Toggle the DPNI to enable, if not already enabled.
    1941                 :            :  * This is not strictly PHY up/down - it is more of logical toggling.
    1942                 :            :  */
    1943                 :            : static int
    1944                 :          0 : dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
    1945                 :            : {
    1946                 :            :         int ret = -EINVAL;
    1947                 :            :         struct dpaa2_dev_priv *priv;
    1948                 :            :         struct fsl_mc_io *dpni;
    1949                 :          0 :         int en = 0;
    1950                 :          0 :         struct dpni_link_state state = {0};
    1951                 :            : 
    1952                 :          0 :         priv = dev->data->dev_private;
    1953                 :          0 :         dpni = dev->process_private;
    1954                 :            : 
    1955         [ #  # ]:          0 :         if (!dpni) {
    1956                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    1957                 :          0 :                 return ret;
    1958                 :            :         }
    1959                 :            : 
    1960                 :            :         /* Check if DPNI is currently enabled */
    1961                 :          0 :         ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
    1962         [ #  # ]:          0 :         if (ret) {
    1963                 :            :                 /* Unable to obtain dpni status; Not continuing */
    1964                 :          0 :                 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
    1965                 :          0 :                 return ret;
    1966                 :            :         }
    1967                 :            : 
    1968                 :            :         /* Enable link if not already enabled */
    1969         [ #  # ]:          0 :         if (!en) {
    1970                 :          0 :                 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
    1971         [ #  # ]:          0 :                 if (ret) {
    1972                 :          0 :                         DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
    1973                 :          0 :                         return ret;
    1974                 :            :                 }
    1975                 :            :         }
    1976                 :          0 :         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
    1977         [ #  # ]:          0 :         if (ret < 0) {
    1978                 :          0 :                 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
    1979                 :          0 :                 return ret;
    1980                 :            :         }
    1981                 :            : 
    1982                 :            :         /* changing tx burst function to start enqueues */
    1983                 :          0 :         dev->tx_pkt_burst = dpaa2_dev_tx;
    1984                 :          0 :         dev->data->dev_link.link_status = state.up;
    1985                 :          0 :         dev->data->dev_link.link_speed = state.rate;
    1986                 :            : 
    1987         [ #  # ]:          0 :         if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
    1988                 :          0 :                 dev->data->dev_link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
    1989                 :            :         else
    1990                 :          0 :                 dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    1991                 :            : 
    1992         [ #  # ]:          0 :         if (state.up)
    1993                 :          0 :                 DPAA2_PMD_DEBUG("Port %d Link is Up", dev->data->port_id);
    1994                 :            :         else
    1995                 :          0 :                 DPAA2_PMD_DEBUG("Port %d Link is Down", dev->data->port_id);
    1996                 :            :         return ret;
    1997                 :            : }
    1998                 :            : 
    1999                 :            : /**
    2000                 :            :  * Toggle the DPNI to disable, if not already disabled.
    2001                 :            :  * This is not strictly PHY up/down - it is more of logical toggling.
    2002                 :            :  */
    2003                 :            : static int
    2004                 :          0 : dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
    2005                 :            : {
    2006                 :            :         int ret = -EINVAL;
    2007                 :            :         struct dpaa2_dev_priv *priv;
    2008                 :            :         struct fsl_mc_io *dpni;
    2009                 :          0 :         int dpni_enabled = 0;
    2010                 :            :         int retries = 10;
    2011                 :            : 
    2012                 :          0 :         PMD_INIT_FUNC_TRACE();
    2013                 :            : 
    2014                 :          0 :         priv = dev->data->dev_private;
    2015                 :          0 :         dpni = dev->process_private;
    2016                 :            : 
    2017         [ #  # ]:          0 :         if (!dpni) {
    2018                 :          0 :                 DPAA2_PMD_ERR("Device has not yet been configured");
    2019                 :          0 :                 return ret;
    2020                 :            :         }
    2021                 :            : 
    2022                 :            :         /*changing  tx burst function to avoid any more enqueues */
    2023                 :          0 :         dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
    2024                 :            : 
    2025                 :            :         /* Loop while dpni_disable() attempts to drain the egress FQs
    2026                 :            :          * and confirm them back to us.
    2027                 :            :          */
    2028                 :            :         do {
    2029                 :          0 :                 ret = dpni_disable(dpni, 0, priv->token);
    2030         [ #  # ]:          0 :                 if (ret) {
    2031                 :          0 :                         DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
    2032                 :          0 :                         return ret;
    2033                 :            :                 }
    2034                 :          0 :                 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
    2035         [ #  # ]:          0 :                 if (ret) {
    2036                 :          0 :                         DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
    2037                 :          0 :                         return ret;
    2038                 :            :                 }
    2039         [ #  # ]:          0 :                 if (dpni_enabled)
    2040                 :            :                         /* Allow the MC some slack */
    2041                 :          0 :                         rte_delay_us(100 * 1000);
    2042   [ #  #  #  # ]:          0 :         } while (dpni_enabled && --retries);
    2043                 :            : 
    2044         [ #  # ]:          0 :         if (!retries) {
    2045                 :          0 :                 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
    2046                 :            :                 /* todo- we may have to manually cleanup queues.
    2047                 :            :                  */
    2048                 :            :         } else {
    2049                 :          0 :                 DPAA2_PMD_INFO("Port %d Link DOWN successful",
    2050                 :            :                                dev->data->port_id);
    2051                 :            :         }
    2052                 :            : 
    2053                 :          0 :         dev->data->dev_link.link_status = 0;
    2054                 :            : 
    2055                 :          0 :         return ret;
    2056                 :            : }
    2057                 :            : 
    2058                 :            : static int
    2059                 :          0 : dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    2060                 :            : {
    2061                 :            :         int ret = -EINVAL;
    2062                 :            :         struct dpaa2_dev_priv *priv;
    2063                 :            :         struct fsl_mc_io *dpni;
    2064                 :          0 :         struct dpni_link_cfg cfg = {0};
    2065                 :            : 
    2066                 :          0 :         PMD_INIT_FUNC_TRACE();
    2067                 :            : 
    2068                 :          0 :         priv = dev->data->dev_private;
    2069                 :          0 :         dpni = dev->process_private;
    2070                 :            : 
    2071         [ #  # ]:          0 :         if (!dpni || !fc_conf) {
    2072                 :          0 :                 DPAA2_PMD_ERR("device not configured");
    2073                 :          0 :                 return ret;
    2074                 :            :         }
    2075                 :            : 
    2076                 :          0 :         ret = dpni_get_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
    2077         [ #  # ]:          0 :         if (ret) {
    2078                 :          0 :                 DPAA2_PMD_ERR("error: dpni_get_link_cfg %d", ret);
    2079                 :          0 :                 return ret;
    2080                 :            :         }
    2081                 :            : 
    2082                 :            :         memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
    2083         [ #  # ]:          0 :         if (cfg.options & DPNI_LINK_OPT_PAUSE) {
    2084                 :            :                 /* DPNI_LINK_OPT_PAUSE set
    2085                 :            :                  *  if ASYM_PAUSE not set,
    2086                 :            :                  *      RX Side flow control (handle received Pause frame)
    2087                 :            :                  *      TX side flow control (send Pause frame)
    2088                 :            :                  *  if ASYM_PAUSE set,
    2089                 :            :                  *      RX Side flow control (handle received Pause frame)
    2090                 :            :                  *      No TX side flow control (send Pause frame disabled)
    2091                 :            :                  */
    2092         [ #  # ]:          0 :                 if (!(cfg.options & DPNI_LINK_OPT_ASYM_PAUSE))
    2093                 :          0 :                         fc_conf->mode = RTE_ETH_FC_FULL;
    2094                 :            :                 else
    2095                 :          0 :                         fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
    2096                 :            :         } else {
    2097                 :            :                 /* DPNI_LINK_OPT_PAUSE not set
    2098                 :            :                  *  if ASYM_PAUSE set,
    2099                 :            :                  *      TX side flow control (send Pause frame)
    2100                 :            :                  *      No RX side flow control (No action on pause frame rx)
    2101                 :            :                  *  if ASYM_PAUSE not set,
    2102                 :            :                  *      Flow control disabled
    2103                 :            :                  */
    2104         [ #  # ]:          0 :                 if (cfg.options & DPNI_LINK_OPT_ASYM_PAUSE)
    2105                 :          0 :                         fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    2106                 :            :                 else
    2107                 :            :                         fc_conf->mode = RTE_ETH_FC_NONE;
    2108                 :            :         }
    2109                 :            : 
    2110                 :            :         return ret;
    2111                 :            : }
    2112                 :            : 
    2113                 :            : static int
    2114                 :          0 : dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    2115                 :            : {
    2116                 :            :         int ret = -EINVAL;
    2117                 :            :         struct dpaa2_dev_priv *priv;
    2118                 :            :         struct fsl_mc_io *dpni;
    2119                 :          0 :         struct dpni_link_cfg cfg = {0};
    2120                 :            : 
    2121                 :          0 :         PMD_INIT_FUNC_TRACE();
    2122                 :            : 
    2123                 :          0 :         priv = dev->data->dev_private;
    2124                 :          0 :         dpni = dev->process_private;
    2125                 :            : 
    2126         [ #  # ]:          0 :         if (!dpni) {
    2127                 :          0 :                 DPAA2_PMD_ERR("dpni is NULL");
    2128                 :          0 :                 return ret;
    2129                 :            :         }
    2130                 :            : 
    2131                 :            :         /* It is necessary to obtain the current cfg before setting fc_conf
    2132                 :            :          * as MC would return error in case rate, autoneg or duplex values are
    2133                 :            :          * different.
    2134                 :            :          */
    2135                 :          0 :         ret = dpni_get_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
    2136         [ #  # ]:          0 :         if (ret) {
    2137                 :          0 :                 DPAA2_PMD_ERR("Unable to get link cfg (err=%d)", ret);
    2138                 :          0 :                 return ret;
    2139                 :            :         }
    2140                 :            : 
    2141                 :            :         /* Disable link before setting configuration */
    2142                 :          0 :         dpaa2_dev_set_link_down(dev);
    2143                 :            : 
    2144                 :            :         /* update cfg with fc_conf */
    2145   [ #  #  #  #  :          0 :         switch (fc_conf->mode) {
                      # ]
    2146                 :          0 :         case RTE_ETH_FC_FULL:
    2147                 :            :                 /* Full flow control;
    2148                 :            :                  * OPT_PAUSE set, ASYM_PAUSE not set
    2149                 :            :                  */
    2150                 :          0 :                 cfg.options |= DPNI_LINK_OPT_PAUSE;
    2151                 :          0 :                 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
    2152                 :          0 :                 break;
    2153                 :          0 :         case RTE_ETH_FC_TX_PAUSE:
    2154                 :            :                 /* Enable RX flow control
    2155                 :            :                  * OPT_PAUSE not set;
    2156                 :            :                  * ASYM_PAUSE set;
    2157                 :            :                  */
    2158                 :          0 :                 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
    2159                 :          0 :                 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
    2160                 :          0 :                 break;
    2161                 :          0 :         case RTE_ETH_FC_RX_PAUSE:
    2162                 :            :                 /* Enable TX Flow control
    2163                 :            :                  * OPT_PAUSE set
    2164                 :            :                  * ASYM_PAUSE set
    2165                 :            :                  */
    2166                 :          0 :                 cfg.options |= DPNI_LINK_OPT_PAUSE;
    2167                 :          0 :                 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
    2168                 :          0 :                 break;
    2169                 :          0 :         case RTE_ETH_FC_NONE:
    2170                 :            :                 /* Disable Flow control
    2171                 :            :                  * OPT_PAUSE not set
    2172                 :            :                  * ASYM_PAUSE not set
    2173                 :            :                  */
    2174                 :          0 :                 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
    2175                 :          0 :                 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
    2176                 :          0 :                 break;
    2177                 :          0 :         default:
    2178                 :          0 :                 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
    2179                 :            :                               fc_conf->mode);
    2180                 :          0 :                 return -EINVAL;
    2181                 :            :         }
    2182                 :            : 
    2183                 :          0 :         ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
    2184         [ #  # ]:          0 :         if (ret)
    2185                 :          0 :                 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
    2186                 :            :                               ret);
    2187                 :            : 
    2188                 :            :         /* Enable link */
    2189                 :          0 :         dpaa2_dev_set_link_up(dev);
    2190                 :            : 
    2191                 :          0 :         return ret;
    2192                 :            : }
    2193                 :            : 
    2194                 :            : static int
    2195                 :          0 : dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
    2196                 :            :                           struct rte_eth_rss_conf *rss_conf)
    2197                 :            : {
    2198                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    2199                 :          0 :         struct dpaa2_dev_priv *priv = data->dev_private;
    2200                 :            :         struct rte_eth_conf *eth_conf = &data->dev_conf;
    2201                 :            :         int ret, tc_index;
    2202                 :            : 
    2203                 :          0 :         PMD_INIT_FUNC_TRACE();
    2204                 :            : 
    2205         [ #  # ]:          0 :         if (rss_conf->rss_hf) {
    2206         [ #  # ]:          0 :                 for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
    2207                 :          0 :                         ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf,
    2208                 :            :                                 tc_index);
    2209         [ #  # ]:          0 :                         if (ret) {
    2210                 :          0 :                                 DPAA2_PMD_ERR("Unable to set flow dist on tc%d",
    2211                 :            :                                         tc_index);
    2212                 :          0 :                                 return ret;
    2213                 :            :                         }
    2214                 :            :                 }
    2215                 :            :         } else {
    2216         [ #  # ]:          0 :                 for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
    2217                 :          0 :                         ret = dpaa2_remove_flow_dist(dev, tc_index);
    2218         [ #  # ]:          0 :                         if (ret) {
    2219                 :          0 :                                 DPAA2_PMD_ERR(
    2220                 :            :                                         "Unable to remove flow dist on tc%d",
    2221                 :            :                                         tc_index);
    2222                 :          0 :                                 return ret;
    2223                 :            :                         }
    2224                 :            :                 }
    2225                 :            :         }
    2226                 :          0 :         eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
    2227                 :          0 :         return 0;
    2228                 :            : }
    2229                 :            : 
    2230                 :            : static int
    2231                 :          0 : dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
    2232                 :            :                             struct rte_eth_rss_conf *rss_conf)
    2233                 :            : {
    2234                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    2235                 :            :         struct rte_eth_conf *eth_conf = &data->dev_conf;
    2236                 :            : 
    2237                 :            :         /* dpaa2 does not support rss_key, so length should be 0*/
    2238                 :          0 :         rss_conf->rss_key_len = 0;
    2239                 :          0 :         rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
    2240                 :          0 :         return 0;
    2241                 :            : }
    2242                 :            : 
    2243                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpaa2_eth_eventq_attach)
    2244                 :          0 : int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
    2245                 :            :                 int eth_rx_queue_id,
    2246                 :            :                 struct dpaa2_dpcon_dev *dpcon,
    2247                 :            :                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
    2248                 :            : {
    2249                 :          0 :         struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
    2250                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    2251                 :          0 :         struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
    2252                 :          0 :         uint8_t flow_id = dpaa2_ethq->flow_id;
    2253                 :            :         struct dpni_queue cfg;
    2254                 :            :         uint8_t options, priority;
    2255                 :            :         int ret;
    2256                 :            : 
    2257         [ #  # ]:          0 :         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
    2258                 :          0 :                 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
    2259         [ #  # ]:          0 :         else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
    2260                 :          0 :                 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
    2261         [ #  # ]:          0 :         else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
    2262                 :          0 :                 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
    2263                 :            :         else
    2264                 :            :                 return -EINVAL;
    2265                 :            : 
    2266                 :          0 :         priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / queue_conf->ev.priority) *
    2267         [ #  # ]:          0 :                    (dpcon->num_priorities - 1);
    2268                 :            : 
    2269                 :            :         memset(&cfg, 0, sizeof(struct dpni_queue));
    2270                 :            :         options = DPNI_QUEUE_OPT_DEST;
    2271                 :          0 :         cfg.destination.type = DPNI_DEST_DPCON;
    2272                 :          0 :         cfg.destination.id = dpcon->dpcon_id;
    2273                 :          0 :         cfg.destination.priority = priority;
    2274                 :            : 
    2275         [ #  # ]:          0 :         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
    2276                 :            :                 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
    2277                 :          0 :                 cfg.destination.hold_active = 1;
    2278                 :            :         }
    2279                 :            : 
    2280         [ #  # ]:          0 :         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
    2281         [ #  # ]:          0 :                         !eth_priv->en_ordered) {
    2282                 :            :                 struct opr_cfg ocfg;
    2283                 :            : 
    2284                 :            :                 /* Restoration window size = 256 frames */
    2285                 :          0 :                 ocfg.oprrws = 3;
    2286                 :            :                 /* Restoration window size = 512 frames for LX2 */
    2287         [ #  # ]:          0 :                 if (dpaa2_svr_family == SVR_LX2160A)
    2288                 :          0 :                         ocfg.oprrws = 4;
    2289                 :            :                 /* Auto advance NESN window enabled */
    2290                 :          0 :                 ocfg.oa = 1;
    2291                 :            :                 /* Late arrival window size disabled */
    2292                 :          0 :                 ocfg.olws = 0;
    2293                 :            :                 /* ORL resource exhaustion advance NESN disabled */
    2294                 :          0 :                 ocfg.oeane = 0;
    2295                 :            :                 /* Loose ordering enabled */
    2296                 :          0 :                 ocfg.oloe = 1;
    2297                 :          0 :                 eth_priv->en_loose_ordered = 1;
    2298                 :            :                 /* Strict ordering enabled if explicitly set */
    2299         [ #  # ]:          0 :                 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
    2300                 :          0 :                         ocfg.oloe = 0;
    2301                 :          0 :                         eth_priv->en_loose_ordered = 0;
    2302                 :            :                 }
    2303                 :            : 
    2304                 :          0 :                 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
    2305                 :          0 :                                    dpaa2_ethq->tc_index, flow_id,
    2306                 :            :                                    OPR_OPT_CREATE, &ocfg, 0);
    2307         [ #  # ]:          0 :                 if (ret) {
    2308                 :          0 :                         DPAA2_PMD_ERR("Error setting opr: ret: %d", ret);
    2309                 :          0 :                         return ret;
    2310                 :            :                 }
    2311                 :            : 
    2312                 :          0 :                 eth_priv->en_ordered = 1;
    2313                 :            :         }
    2314                 :            : 
    2315                 :          0 :         options |= DPNI_QUEUE_OPT_USER_CTX;
    2316                 :          0 :         cfg.user_context = (size_t)(dpaa2_ethq);
    2317                 :            : 
    2318                 :          0 :         ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
    2319                 :          0 :                              dpaa2_ethq->tc_index, flow_id, options, &cfg);
    2320         [ #  # ]:          0 :         if (ret) {
    2321                 :          0 :                 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
    2322                 :          0 :                 return ret;
    2323                 :            :         }
    2324                 :            : 
    2325                 :          0 :         memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
    2326                 :            : 
    2327                 :          0 :         return 0;
    2328                 :            : }
    2329                 :            : 
    2330                 :            : RTE_EXPORT_INTERNAL_SYMBOL(dpaa2_eth_eventq_detach)
    2331                 :          0 : int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
    2332                 :            :                 int eth_rx_queue_id)
    2333                 :            : {
    2334                 :          0 :         struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
    2335                 :          0 :         struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
    2336                 :          0 :         struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
    2337                 :          0 :         uint8_t flow_id = dpaa2_ethq->flow_id;
    2338                 :            :         struct dpni_queue cfg;
    2339                 :            :         uint8_t options;
    2340                 :            :         int ret;
    2341                 :            : 
    2342                 :            :         memset(&cfg, 0, sizeof(struct dpni_queue));
    2343                 :            :         options = DPNI_QUEUE_OPT_DEST;
    2344                 :            :         cfg.destination.type = DPNI_DEST_NONE;
    2345                 :            : 
    2346                 :          0 :         ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
    2347                 :          0 :                              dpaa2_ethq->tc_index, flow_id, options, &cfg);
    2348         [ #  # ]:          0 :         if (ret)
    2349                 :          0 :                 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
    2350                 :            : 
    2351                 :          0 :         return ret;
    2352                 :            : }
    2353                 :            : 
    2354                 :            : static int
    2355                 :          0 : dpaa2_dev_flow_ops_get(struct rte_eth_dev *dev,
    2356                 :            :                        const struct rte_flow_ops **ops)
    2357                 :            : {
    2358         [ #  # ]:          0 :         if (!dev)
    2359                 :            :                 return -ENODEV;
    2360                 :            : 
    2361                 :          0 :         *ops = &dpaa2_flow_ops;
    2362                 :          0 :         return 0;
    2363                 :            : }
    2364                 :            : 
    2365                 :            : static void
    2366                 :          0 : dpaa2_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    2367                 :            :         struct rte_eth_rxq_info *qinfo)
    2368                 :            : {
    2369                 :            :         struct dpaa2_queue *rxq;
    2370                 :          0 :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    2371                 :          0 :         struct fsl_mc_io *dpni = dev->process_private;
    2372                 :            :         uint16_t max_frame_length;
    2373                 :            : 
    2374                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    2375                 :            : 
    2376                 :          0 :         qinfo->mp = rxq->mb_pool;
    2377                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    2378                 :          0 :         qinfo->nb_desc = rxq->nb_desc;
    2379         [ #  # ]:          0 :         if (dpni_get_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
    2380                 :            :                                 &max_frame_length) == 0)
    2381                 :          0 :                 qinfo->rx_buf_size = max_frame_length;
    2382                 :            : 
    2383                 :          0 :         qinfo->conf.rx_free_thresh = 1;
    2384                 :          0 :         qinfo->conf.rx_drop_en = 1;
    2385                 :          0 :         qinfo->conf.rx_deferred_start = 0;
    2386                 :          0 :         qinfo->conf.offloads = rxq->offloads;
    2387                 :          0 : }
    2388                 :            : 
    2389                 :            : static void
    2390                 :          0 : dpaa2_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    2391                 :            :         struct rte_eth_txq_info *qinfo)
    2392                 :            : {
    2393                 :            :         struct dpaa2_queue *txq;
    2394                 :            : 
    2395                 :          0 :         txq = dev->data->tx_queues[queue_id];
    2396                 :            : 
    2397                 :          0 :         qinfo->nb_desc = txq->nb_desc;
    2398                 :          0 :         qinfo->conf.tx_thresh.pthresh = 0;
    2399                 :          0 :         qinfo->conf.tx_thresh.hthresh = 0;
    2400                 :          0 :         qinfo->conf.tx_thresh.wthresh = 0;
    2401                 :            : 
    2402                 :          0 :         qinfo->conf.tx_free_thresh = 0;
    2403                 :          0 :         qinfo->conf.tx_rs_thresh = 0;
    2404                 :          0 :         qinfo->conf.offloads = txq->offloads;
    2405                 :          0 :         qinfo->conf.tx_deferred_start = 0;
    2406                 :          0 : }
    2407                 :            : 
    2408                 :            : static int
    2409                 :          0 : dpaa2_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
    2410                 :            : {
    2411                 :          0 :         *(const void **)ops = &dpaa2_tm_ops;
    2412                 :            : 
    2413                 :          0 :         return 0;
    2414                 :            : }
    2415                 :            : 
    2416                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_dpaa2_thread_init, 21.08)
    2417                 :            : void
    2418                 :          0 : rte_pmd_dpaa2_thread_init(void)
    2419                 :            : {
    2420                 :            :         int ret;
    2421                 :            : 
    2422         [ #  # ]:          0 :         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
    2423                 :          0 :                 ret = dpaa2_affine_qbman_swp();
    2424         [ #  # ]:          0 :                 if (ret) {
    2425                 :          0 :                         DPAA2_PMD_ERR(
    2426                 :            :                                 "Failed to allocate IO portal, tid: %d",
    2427                 :            :                                 rte_gettid());
    2428                 :          0 :                         return;
    2429                 :            :                 }
    2430                 :            :         }
    2431                 :            : }
    2432                 :            : 
    2433                 :            : static struct eth_dev_ops dpaa2_ethdev_ops = {
    2434                 :            :         .dev_configure    = dpaa2_eth_dev_configure,
    2435                 :            :         .dev_start            = dpaa2_dev_start,
    2436                 :            :         .dev_stop             = dpaa2_dev_stop,
    2437                 :            :         .dev_close            = dpaa2_dev_close,
    2438                 :            :         .promiscuous_enable   = dpaa2_dev_promiscuous_enable,
    2439                 :            :         .promiscuous_disable  = dpaa2_dev_promiscuous_disable,
    2440                 :            :         .allmulticast_enable  = dpaa2_dev_allmulticast_enable,
    2441                 :            :         .allmulticast_disable = dpaa2_dev_allmulticast_disable,
    2442                 :            :         .dev_set_link_up      = dpaa2_dev_set_link_up,
    2443                 :            :         .dev_set_link_down    = dpaa2_dev_set_link_down,
    2444                 :            :         .link_update       = dpaa2_dev_link_update,
    2445                 :            :         .stats_get             = dpaa2_dev_stats_get,
    2446                 :            :         .xstats_get            = dpaa2_dev_xstats_get,
    2447                 :            :         .xstats_get_by_id     = dpaa2_xstats_get_by_id,
    2448                 :            :         .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
    2449                 :            :         .xstats_get_names      = dpaa2_xstats_get_names,
    2450                 :            :         .stats_reset       = dpaa2_dev_stats_reset,
    2451                 :            :         .xstats_reset         = dpaa2_dev_stats_reset,
    2452                 :            :         .fw_version_get    = dpaa2_fw_version_get,
    2453                 :            :         .dev_infos_get     = dpaa2_dev_info_get,
    2454                 :            :         .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
    2455                 :            :         .mtu_set           = dpaa2_dev_mtu_set,
    2456                 :            :         .vlan_filter_set      = dpaa2_vlan_filter_set,
    2457                 :            :         .vlan_offload_set     = dpaa2_vlan_offload_set,
    2458                 :            :         .vlan_tpid_set        = dpaa2_vlan_tpid_set,
    2459                 :            :         .rx_queue_setup    = dpaa2_dev_rx_queue_setup,
    2460                 :            :         .rx_queue_release  = dpaa2_dev_rx_queue_release,
    2461                 :            :         .tx_queue_setup    = dpaa2_dev_tx_queue_setup,
    2462                 :            :         .rx_burst_mode_get = dpaa2_dev_rx_burst_mode_get,
    2463                 :            :         .tx_burst_mode_get = dpaa2_dev_tx_burst_mode_get,
    2464                 :            :         .flow_ctrl_get        = dpaa2_flow_ctrl_get,
    2465                 :            :         .flow_ctrl_set        = dpaa2_flow_ctrl_set,
    2466                 :            :         .mac_addr_add         = dpaa2_dev_add_mac_addr,
    2467                 :            :         .mac_addr_remove      = dpaa2_dev_remove_mac_addr,
    2468                 :            :         .mac_addr_set         = dpaa2_dev_set_mac_addr,
    2469                 :            :         .rss_hash_update      = dpaa2_dev_rss_hash_update,
    2470                 :            :         .rss_hash_conf_get    = dpaa2_dev_rss_hash_conf_get,
    2471                 :            :         .flow_ops_get         = dpaa2_dev_flow_ops_get,
    2472                 :            :         .rxq_info_get         = dpaa2_rxq_info_get,
    2473                 :            :         .txq_info_get         = dpaa2_txq_info_get,
    2474                 :            :         .tm_ops_get           = dpaa2_tm_ops_get,
    2475                 :            : #if defined(RTE_LIBRTE_IEEE1588)
    2476                 :            :         .timesync_enable      = dpaa2_timesync_enable,
    2477                 :            :         .timesync_disable     = dpaa2_timesync_disable,
    2478                 :            :         .timesync_read_time   = dpaa2_timesync_read_time,
    2479                 :            :         .timesync_write_time  = dpaa2_timesync_write_time,
    2480                 :            :         .timesync_adjust_time = dpaa2_timesync_adjust_time,
    2481                 :            :         .timesync_read_rx_timestamp = dpaa2_timesync_read_rx_timestamp,
    2482                 :            :         .timesync_read_tx_timestamp = dpaa2_timesync_read_tx_timestamp,
    2483                 :            : #endif
    2484                 :            : };
    2485                 :            : 
    2486                 :            : /* Populate the mac address from physically available (u-boot/firmware) and/or
    2487                 :            :  * one set by higher layers like MC (restool) etc.
    2488                 :            :  * Returns the table of MAC entries (multiple entries)
    2489                 :            :  */
    2490                 :            : static int
    2491                 :          0 : populate_mac_addr(struct fsl_mc_io *dpni_dev,
    2492                 :            :         struct dpaa2_dev_priv *priv, struct rte_ether_addr *mac_entry)
    2493                 :            : {
    2494                 :            :         int ret = 0;
    2495                 :            :         struct rte_ether_addr phy_mac, prime_mac;
    2496                 :            : 
    2497                 :            :         memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
    2498                 :            :         memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
    2499                 :            : 
    2500                 :            :         /* Get the physical device MAC address */
    2501                 :          0 :         ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
    2502                 :            :                                      phy_mac.addr_bytes);
    2503         [ #  # ]:          0 :         if (ret) {
    2504                 :          0 :                 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
    2505                 :          0 :                 goto cleanup;
    2506                 :            :         }
    2507                 :            : 
    2508                 :          0 :         ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
    2509                 :            :                                         prime_mac.addr_bytes);
    2510         [ #  # ]:          0 :         if (ret) {
    2511                 :          0 :                 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
    2512                 :          0 :                 goto cleanup;
    2513                 :            :         }
    2514                 :            : 
    2515                 :            :         /* Now that both MAC have been obtained, do:
    2516                 :            :          *  if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
    2517                 :            :          *     and return phy
    2518                 :            :          *  If empty_mac(phy), return prime.
    2519                 :            :          *  if both are empty, create random MAC, set as prime and return
    2520                 :            :          */
    2521         [ #  # ]:          0 :         if (!rte_is_zero_ether_addr(&phy_mac)) {
    2522                 :            :                 /* If the addresses are not same, overwrite prime */
    2523         [ #  # ]:          0 :                 if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
    2524                 :          0 :                         ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
    2525                 :          0 :                                                         priv->token,
    2526                 :            :                                                         phy_mac.addr_bytes);
    2527         [ #  # ]:          0 :                         if (ret) {
    2528                 :          0 :                                 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
    2529                 :            :                                               ret);
    2530                 :          0 :                                 goto cleanup;
    2531                 :            :                         }
    2532                 :            :                         memcpy(&prime_mac, &phy_mac,
    2533                 :            :                                 sizeof(struct rte_ether_addr));
    2534                 :            :                 }
    2535         [ #  # ]:          0 :         } else if (rte_is_zero_ether_addr(&prime_mac)) {
    2536                 :            :                 /* In case phys and prime, both are zero, create random MAC */
    2537                 :          0 :                 rte_eth_random_addr(prime_mac.addr_bytes);
    2538                 :          0 :                 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
    2539                 :          0 :                                                 priv->token,
    2540                 :            :                                                 prime_mac.addr_bytes);
    2541         [ #  # ]:          0 :                 if (ret) {
    2542                 :          0 :                         DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
    2543                 :          0 :                         goto cleanup;
    2544                 :            :                 }
    2545                 :            :         }
    2546                 :            : 
    2547                 :            :         /* prime_mac the final MAC address */
    2548                 :            :         memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
    2549                 :          0 :         return 0;
    2550                 :            : 
    2551                 :            : cleanup:
    2552                 :            :         return ret;
    2553                 :            : }
    2554                 :            : 
    2555                 :            : static int
    2556                 :          0 : check_devargs_handler(__rte_unused const char *key, const char *value,
    2557                 :            :                       __rte_unused void *opaque)
    2558                 :            : {
    2559         [ #  # ]:          0 :         if (strcmp(value, "1"))
    2560                 :          0 :                 return -1;
    2561                 :            : 
    2562                 :            :         return 0;
    2563                 :            : }
    2564                 :            : 
    2565                 :            : static int
    2566                 :          0 : dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
    2567                 :            : {
    2568                 :            :         struct rte_kvargs *kvlist;
    2569                 :            : 
    2570         [ #  # ]:          0 :         if (!devargs)
    2571                 :            :                 return 0;
    2572                 :            : 
    2573                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
    2574         [ #  # ]:          0 :         if (!kvlist)
    2575                 :            :                 return 0;
    2576                 :            : 
    2577         [ #  # ]:          0 :         if (!rte_kvargs_count(kvlist, key)) {
    2578                 :          0 :                 rte_kvargs_free(kvlist);
    2579                 :          0 :                 return 0;
    2580                 :            :         }
    2581                 :            : 
    2582         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist, key,
    2583                 :            :                                check_devargs_handler, NULL) < 0) {
    2584                 :          0 :                 rte_kvargs_free(kvlist);
    2585                 :          0 :                 return 0;
    2586                 :            :         }
    2587                 :          0 :         rte_kvargs_free(kvlist);
    2588                 :            : 
    2589                 :          0 :         return 1;
    2590                 :            : }
    2591                 :            : 
    2592                 :            : static int
    2593                 :          0 : dpaa2_dev_init(struct rte_eth_dev *eth_dev)
    2594                 :            : {
    2595                 :          0 :         struct rte_device *dev = eth_dev->device;
    2596                 :            :         struct rte_dpaa2_device *dpaa2_dev;
    2597                 :            :         struct fsl_mc_io *dpni_dev;
    2598                 :            :         struct dpni_attr attr;
    2599                 :          0 :         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
    2600                 :            :         struct dpni_buffer_layout layout;
    2601                 :            :         int ret, hw_id, i;
    2602                 :            : 
    2603                 :          0 :         PMD_INIT_FUNC_TRACE();
    2604                 :            : 
    2605                 :          0 :         dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
    2606         [ #  # ]:          0 :         if (!dpni_dev) {
    2607                 :          0 :                 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
    2608                 :          0 :                 return -1;
    2609                 :            :         }
    2610                 :          0 :         dpni_dev->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
    2611                 :          0 :         eth_dev->process_private = dpni_dev;
    2612                 :            : 
    2613                 :            :         /* For secondary processes, the primary has done all the work */
    2614         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    2615                 :            :                 /* In case of secondary, only burst and ops API need to be
    2616                 :            :                  * plugged.
    2617                 :            :                  */
    2618                 :          0 :                 eth_dev->dev_ops = &dpaa2_ethdev_ops;
    2619                 :          0 :                 eth_dev->rx_queue_count = dpaa2_dev_rx_queue_count;
    2620         [ #  # ]:          0 :                 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
    2621                 :          0 :                         eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
    2622         [ #  # ]:          0 :                 else if (dpaa2_get_devargs(dev->devargs,
    2623                 :            :                                         DRIVER_NO_PREFETCH_MODE))
    2624                 :          0 :                         eth_dev->rx_pkt_burst = dpaa2_dev_rx;
    2625                 :            :                 else
    2626                 :          0 :                         eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
    2627                 :          0 :                 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
    2628                 :          0 :                 return 0;
    2629                 :            :         }
    2630                 :            : 
    2631                 :          0 :         dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
    2632                 :            : 
    2633                 :          0 :         hw_id = dpaa2_dev->object_id;
    2634                 :          0 :         ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
    2635         [ #  # ]:          0 :         if (ret) {
    2636                 :          0 :                 DPAA2_PMD_ERR(
    2637                 :            :                              "Failure in opening dpni@%d with err code %d",
    2638                 :            :                              hw_id, ret);
    2639                 :          0 :                 rte_free(dpni_dev);
    2640                 :          0 :                 return ret;
    2641                 :            :         }
    2642                 :            : 
    2643         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.lpbk_mode)
    2644                 :          0 :                 dpaa2_dev_recycle_deconfig(eth_dev);
    2645                 :            : 
    2646                 :            :         /* Clean the device first */
    2647                 :          0 :         ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
    2648         [ #  # ]:          0 :         if (ret) {
    2649                 :          0 :                 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
    2650                 :            :                               hw_id, ret);
    2651                 :          0 :                 goto init_err;
    2652                 :            :         }
    2653                 :            : 
    2654                 :          0 :         ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
    2655         [ #  # ]:          0 :         if (ret) {
    2656                 :          0 :                 DPAA2_PMD_ERR(
    2657                 :            :                              "Failure in get dpni@%d attribute, err code %d",
    2658                 :            :                              hw_id, ret);
    2659                 :          0 :                 goto init_err;
    2660                 :            :         }
    2661                 :            : 
    2662                 :          0 :         priv->num_rx_tc = attr.num_rx_tcs;
    2663                 :          0 :         priv->num_tx_tc = attr.num_tx_tcs;
    2664                 :          0 :         priv->qos_entries = attr.qos_entries;
    2665                 :          0 :         priv->fs_entries = attr.fs_entries;
    2666                 :          0 :         priv->dist_queues = attr.num_queues;
    2667                 :          0 :         priv->num_channels = attr.num_channels;
    2668         [ #  # ]:          0 :         priv->channel_inuse = 0;
    2669                 :            :         rte_spinlock_init(&priv->lpbk_qp_lock);
    2670                 :            : 
    2671                 :            :         /* only if the custom CG is enabled */
    2672         [ #  # ]:          0 :         if (attr.options & DPNI_OPT_CUSTOM_CG)
    2673                 :          0 :                 priv->max_cgs = attr.num_cgs;
    2674                 :            :         else
    2675                 :          0 :                 priv->max_cgs = 0;
    2676                 :            : 
    2677         [ #  # ]:          0 :         for (i = 0; i < priv->max_cgs; i++)
    2678                 :          0 :                 priv->cgid_in_use[i] = 0;
    2679                 :            : 
    2680         [ #  # ]:          0 :         for (i = 0; i < attr.num_rx_tcs; i++)
    2681                 :          0 :                 priv->nb_rx_queues += attr.num_queues;
    2682                 :            : 
    2683                 :          0 :         priv->nb_tx_queues = attr.num_tx_tcs * attr.num_channels;
    2684                 :            : 
    2685                 :          0 :         DPAA2_PMD_DEBUG("RX-TC= %d, rx_queues= %d, tx_queues=%d, max_cgs=%d",
    2686                 :            :                         priv->num_rx_tc, priv->nb_rx_queues,
    2687                 :            :                         priv->nb_tx_queues, priv->max_cgs);
    2688                 :            : 
    2689                 :          0 :         priv->hw = dpni_dev;
    2690                 :          0 :         priv->hw_id = hw_id;
    2691                 :          0 :         priv->options = attr.options;
    2692                 :          0 :         priv->max_mac_filters = attr.mac_filter_entries;
    2693                 :          0 :         priv->max_vlan_filters = attr.vlan_filter_entries;
    2694                 :          0 :         priv->flags = 0;
    2695                 :            : #if defined(RTE_LIBRTE_IEEE1588)
    2696                 :            :         DPAA2_PMD_INFO("DPDK IEEE1588 is enabled");
    2697                 :            :         priv->flags |= DPAA2_TX_CONF_ENABLE;
    2698                 :            : #endif
    2699                 :            :         /* Used with ``fslmc:dpni.1,drv_tx_conf=1`` */
    2700         [ #  # ]:          0 :         if (dpaa2_get_devargs(dev->devargs, DRIVER_TX_CONF)) {
    2701                 :          0 :                 priv->flags |= DPAA2_TX_CONF_ENABLE;
    2702                 :          0 :                 DPAA2_PMD_INFO("TX_CONF Enabled");
    2703                 :            :         }
    2704                 :            : 
    2705         [ #  # ]:          0 :         if (dpaa2_get_devargs(dev->devargs, DRIVER_ERROR_QUEUE)) {
    2706                 :          0 :                 dpaa2_enable_err_queue = 1;
    2707                 :          0 :                 DPAA2_PMD_INFO("Enable DMA error checks");
    2708                 :            :         }
    2709                 :            : 
    2710         [ #  # ]:          0 :         if (getenv("DPAA2_PRINT_RX_PARSER_RESULT"))
    2711                 :          0 :                 dpaa2_print_parser_result = 1;
    2712                 :            : 
    2713                 :            :         /* Allocate memory for hardware structure for queues */
    2714                 :          0 :         ret = dpaa2_alloc_rx_tx_queues(eth_dev);
    2715         [ #  # ]:          0 :         if (ret) {
    2716                 :          0 :                 DPAA2_PMD_ERR("Queue allocation Failed");
    2717                 :          0 :                 goto init_err;
    2718                 :            :         }
    2719                 :            : 
    2720                 :            :         /* Allocate memory for storing MAC addresses.
    2721                 :            :          * Table of mac_filter_entries size is allocated so that RTE ether lib
    2722                 :            :          * can add MAC entries when rte_eth_dev_mac_addr_add is called.
    2723                 :            :          */
    2724                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("dpni",
    2725                 :          0 :                 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
    2726         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    2727                 :          0 :                 DPAA2_PMD_ERR(
    2728                 :            :                    "Failed to allocate %d bytes needed to store MAC addresses",
    2729                 :            :                    RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
    2730                 :            :                 ret = -ENOMEM;
    2731                 :          0 :                 goto init_err;
    2732                 :            :         }
    2733                 :            : 
    2734                 :          0 :         ret = populate_mac_addr(dpni_dev, priv, &eth_dev->data->mac_addrs[0]);
    2735         [ #  # ]:          0 :         if (ret) {
    2736                 :          0 :                 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
    2737                 :          0 :                 rte_free(eth_dev->data->mac_addrs);
    2738                 :          0 :                 eth_dev->data->mac_addrs = NULL;
    2739                 :          0 :                 goto init_err;
    2740                 :            :         }
    2741                 :            : 
    2742                 :            :         /* ... tx buffer layout ... */
    2743                 :            :         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
    2744         [ #  # ]:          0 :         if (priv->flags & DPAA2_TX_CONF_ENABLE) {
    2745                 :          0 :                 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
    2746                 :            :                                  DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
    2747                 :          0 :                 layout.pass_timestamp = true;
    2748                 :            :         } else {
    2749                 :          0 :                 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
    2750                 :            :         }
    2751                 :          0 :         layout.pass_frame_status = 1;
    2752                 :          0 :         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
    2753                 :            :                                      DPNI_QUEUE_TX, &layout);
    2754         [ #  # ]:          0 :         if (ret) {
    2755                 :          0 :                 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
    2756                 :          0 :                 goto init_err;
    2757                 :            :         }
    2758                 :            : 
    2759                 :            :         /* ... tx-conf and error buffer layout ... */
    2760                 :            :         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
    2761         [ #  # ]:          0 :         if (priv->flags & DPAA2_TX_CONF_ENABLE) {
    2762                 :          0 :                 layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
    2763                 :          0 :                 layout.pass_timestamp = true;
    2764                 :            :         }
    2765                 :          0 :         layout.options |= DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
    2766                 :          0 :         layout.pass_frame_status = 1;
    2767                 :          0 :         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
    2768                 :            :                                      DPNI_QUEUE_TX_CONFIRM, &layout);
    2769         [ #  # ]:          0 :         if (ret) {
    2770                 :          0 :                 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
    2771                 :            :                              ret);
    2772                 :          0 :                 goto init_err;
    2773                 :            :         }
    2774                 :            : 
    2775                 :          0 :         eth_dev->dev_ops = &dpaa2_ethdev_ops;
    2776                 :            : 
    2777         [ #  # ]:          0 :         if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
    2778                 :          0 :                 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
    2779                 :          0 :                 DPAA2_PMD_INFO("Loopback mode");
    2780         [ #  # ]:          0 :         } else if (dpaa2_get_devargs(dev->devargs, DRIVER_NO_PREFETCH_MODE)) {
    2781                 :          0 :                 eth_dev->rx_pkt_burst = dpaa2_dev_rx;
    2782                 :          0 :                 DPAA2_PMD_INFO("No Prefetch mode");
    2783                 :            :         } else {
    2784                 :          0 :                 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
    2785                 :            :         }
    2786                 :          0 :         eth_dev->tx_pkt_burst = dpaa2_dev_tx;
    2787                 :            : 
    2788                 :            :         /* Init fields w.r.t. classification */
    2789                 :          0 :         memset(&priv->extract.qos_key_extract, 0,
    2790                 :            :                 sizeof(struct dpaa2_key_extract));
    2791                 :          0 :         priv->extract.qos_extract_param = rte_malloc(NULL,
    2792                 :            :                 DPAA2_EXTRACT_PARAM_MAX_SIZE,
    2793                 :            :                 RTE_CACHE_LINE_SIZE);
    2794         [ #  # ]:          0 :         if (!priv->extract.qos_extract_param) {
    2795                 :          0 :                 DPAA2_PMD_ERR("Memory alloc failed");
    2796                 :          0 :                 goto init_err;
    2797                 :            :         }
    2798                 :            : 
    2799         [ #  # ]:          0 :         for (i = 0; i < MAX_TCS; i++) {
    2800                 :          0 :                 memset(&priv->extract.tc_key_extract[i], 0,
    2801                 :            :                         sizeof(struct dpaa2_key_extract));
    2802                 :          0 :                 priv->extract.tc_extract_param[i] = rte_malloc(NULL,
    2803                 :            :                         DPAA2_EXTRACT_PARAM_MAX_SIZE,
    2804                 :            :                         RTE_CACHE_LINE_SIZE);
    2805         [ #  # ]:          0 :                 if (!priv->extract.tc_extract_param[i]) {
    2806                 :          0 :                         DPAA2_PMD_ERR("Memory alloc failed");
    2807                 :          0 :                         goto init_err;
    2808                 :            :                 }
    2809                 :            :         }
    2810                 :            : 
    2811                 :          0 :         ret = dpni_set_max_frame_length(dpni_dev, CMD_PRI_LOW, priv->token,
    2812                 :            :                                         RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN
    2813                 :            :                                         + VLAN_TAG_SIZE);
    2814         [ #  # ]:          0 :         if (ret) {
    2815                 :          0 :                 DPAA2_PMD_ERR("Unable to set mtu. check config");
    2816                 :          0 :                 goto init_err;
    2817                 :            :         }
    2818                 :          0 :         eth_dev->data->mtu = RTE_ETHER_MTU;
    2819                 :            : 
    2820                 :            :         /*TODO To enable soft parser support DPAA2 driver needs to integrate
    2821                 :            :          * with external entity to receive byte code for software sequence
    2822                 :            :          * and same will be offload to the H/W using MC interface.
    2823                 :            :          * Currently it is assumed that DPAA2 driver has byte code by some
    2824                 :            :          * mean and same if offloaded to H/W.
    2825                 :            :          */
    2826         [ #  # ]:          0 :         if (getenv("DPAA2_ENABLE_SOFT_PARSER")) {
    2827                 :          0 :                 WRIOP_SS_INITIALIZER(priv);
    2828                 :          0 :                 ret = dpaa2_eth_load_wriop_soft_parser(priv, DPNI_SS_INGRESS);
    2829         [ #  # ]:          0 :                 if (ret < 0) {
    2830                 :          0 :                         DPAA2_PMD_ERR(" Error(%d) in loading softparser",
    2831                 :            :                                       ret);
    2832                 :          0 :                         return ret;
    2833                 :            :                 }
    2834                 :            : 
    2835                 :          0 :                 ret = dpaa2_eth_enable_wriop_soft_parser(priv,
    2836                 :            :                                                          DPNI_SS_INGRESS);
    2837         [ #  # ]:          0 :                 if (ret < 0) {
    2838                 :          0 :                         DPAA2_PMD_ERR(" Error(%d) in enabling softparser",
    2839                 :            :                                       ret);
    2840                 :          0 :                         return ret;
    2841                 :            :                 }
    2842                 :            :         }
    2843                 :            : 
    2844                 :          0 :         ret = dpaa2_soft_parser_loaded();
    2845         [ #  # ]:          0 :         if (ret > 0)
    2846                 :          0 :                 DPAA2_PMD_INFO("soft parser is loaded");
    2847                 :          0 :         DPAA2_PMD_INFO("%s: netdev created, connected to %s",
    2848                 :            :                 eth_dev->data->name, dpaa2_dev->ep_name);
    2849                 :            : 
    2850                 :          0 :         return 0;
    2851                 :          0 : init_err:
    2852                 :          0 :         dpaa2_dev_close(eth_dev);
    2853                 :            : 
    2854                 :          0 :         return ret;
    2855                 :            : }
    2856                 :            : 
    2857                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_dpaa2_dev_is_dpaa2, 24.11)
    2858                 :            : int
    2859                 :          0 : rte_pmd_dpaa2_dev_is_dpaa2(uint32_t eth_id)
    2860                 :            : {
    2861                 :            :         struct rte_eth_dev *dev;
    2862                 :            : 
    2863         [ #  # ]:          0 :         if (eth_id >= RTE_MAX_ETHPORTS)
    2864                 :            :                 return false;
    2865                 :            : 
    2866                 :            :         dev = &rte_eth_devices[eth_id];
    2867         [ #  # ]:          0 :         if (!dev->device)
    2868                 :            :                 return false;
    2869                 :            : 
    2870                 :          0 :         return dev->device->driver == &rte_dpaa2_pmd.driver;
    2871                 :            : }
    2872                 :            : 
    2873                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_dpaa2_ep_name, 24.11)
    2874                 :            : const char *
    2875                 :          0 : rte_pmd_dpaa2_ep_name(uint32_t eth_id)
    2876                 :            : {
    2877                 :            :         struct rte_eth_dev *dev;
    2878                 :            :         struct dpaa2_dev_priv *priv;
    2879                 :            : 
    2880         [ #  # ]:          0 :         if (eth_id >= RTE_MAX_ETHPORTS)
    2881                 :            :                 return NULL;
    2882                 :            : 
    2883         [ #  # ]:          0 :         if (!rte_pmd_dpaa2_dev_is_dpaa2(eth_id))
    2884                 :            :                 return NULL;
    2885                 :            : 
    2886                 :            :         dev = &rte_eth_devices[eth_id];
    2887         [ #  # ]:          0 :         if (!dev->data)
    2888                 :            :                 return NULL;
    2889                 :            : 
    2890         [ #  # ]:          0 :         if (!dev->data->dev_private)
    2891                 :            :                 return NULL;
    2892                 :            : 
    2893                 :            :         priv = dev->data->dev_private;
    2894                 :            : 
    2895                 :          0 :         return priv->ep_name;
    2896                 :            : }
    2897                 :            : 
    2898                 :            : #if defined(RTE_LIBRTE_IEEE1588)
    2899                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_dpaa2_get_one_step_ts, 24.11)
    2900                 :            : int
    2901                 :            : rte_pmd_dpaa2_get_one_step_ts(uint16_t port_id, bool mc_query)
    2902                 :            : {
    2903                 :            :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    2904                 :            :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    2905                 :            :         struct fsl_mc_io *dpni = priv->eth_dev->process_private;
    2906                 :            :         struct dpni_single_step_cfg ptp_cfg;
    2907                 :            :         int err;
    2908                 :            : 
    2909                 :            :         if (!mc_query)
    2910                 :            :                 return priv->ptp_correction_offset;
    2911                 :            : 
    2912                 :            :         err = dpni_get_single_step_cfg(dpni, CMD_PRI_LOW, priv->token, &ptp_cfg);
    2913                 :            :         if (err) {
    2914                 :            :                 DPAA2_PMD_ERR("Failed to retrieve onestep configuration");
    2915                 :            :                 return err;
    2916                 :            :         }
    2917                 :            : 
    2918                 :            :         if (!ptp_cfg.ptp_onestep_reg_base) {
    2919                 :            :                 DPAA2_PMD_ERR("1588 onestep reg not available");
    2920                 :            :                 return -1;
    2921                 :            :         }
    2922                 :            : 
    2923                 :            :         priv->ptp_correction_offset = ptp_cfg.offset;
    2924                 :            : 
    2925                 :            :         return priv->ptp_correction_offset;
    2926                 :            : }
    2927                 :            : 
    2928                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_dpaa2_set_one_step_ts, 24.11)
    2929                 :            : int
    2930                 :            : rte_pmd_dpaa2_set_one_step_ts(uint16_t port_id, uint16_t offset, uint8_t ch_update)
    2931                 :            : {
    2932                 :            :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
    2933                 :            :         struct dpaa2_dev_priv *priv = dev->data->dev_private;
    2934                 :            :         struct fsl_mc_io *dpni = dev->process_private;
    2935                 :            :         struct dpni_single_step_cfg cfg;
    2936                 :            :         int err;
    2937                 :            : 
    2938                 :            :         cfg.en = 1;
    2939                 :            :         cfg.ch_update = ch_update;
    2940                 :            :         cfg.offset = offset;
    2941                 :            :         cfg.peer_delay = 0;
    2942                 :            : 
    2943                 :            :         err = dpni_set_single_step_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
    2944                 :            :         if (err)
    2945                 :            :                 return err;
    2946                 :            : 
    2947                 :            :         priv->ptp_correction_offset = offset;
    2948                 :            : 
    2949                 :            :         return 0;
    2950                 :            : }
    2951                 :            : #endif
    2952                 :            : 
    2953                 :          0 : static int dpaa2_tx_sg_pool_init(void)
    2954                 :            : {
    2955                 :            :         char name[RTE_MEMZONE_NAMESIZE];
    2956                 :            : 
    2957         [ #  # ]:          0 :         if (dpaa2_tx_sg_pool)
    2958                 :            :                 return 0;
    2959                 :            : 
    2960                 :            :         sprintf(name, "dpaa2_mbuf_tx_sg_pool");
    2961         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    2962                 :          0 :                 dpaa2_tx_sg_pool = rte_pktmbuf_pool_create(name,
    2963                 :            :                         DPAA2_POOL_SIZE,
    2964                 :            :                         DPAA2_POOL_CACHE_SIZE, 0,
    2965                 :            :                         DPAA2_MAX_SGS * sizeof(struct qbman_sge),
    2966                 :          0 :                         rte_socket_id());
    2967         [ #  # ]:          0 :                 if (!dpaa2_tx_sg_pool) {
    2968                 :          0 :                         DPAA2_PMD_ERR("SG pool creation failed");
    2969                 :          0 :                         return -ENOMEM;
    2970                 :            :                 }
    2971                 :            :         } else {
    2972                 :          0 :                 dpaa2_tx_sg_pool = rte_mempool_lookup(name);
    2973         [ #  # ]:          0 :                 if (!dpaa2_tx_sg_pool) {
    2974                 :          0 :                         DPAA2_PMD_ERR("SG pool lookup failed");
    2975                 :          0 :                         return -ENOMEM;
    2976                 :            :                 }
    2977                 :            :         }
    2978                 :            : 
    2979                 :            :         return 0;
    2980                 :            : }
    2981                 :            : 
    2982                 :            : static int
    2983                 :          0 : rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
    2984                 :            :                 struct rte_dpaa2_device *dpaa2_dev)
    2985                 :            : {
    2986                 :            :         struct rte_eth_dev *eth_dev;
    2987                 :            :         struct dpaa2_dev_priv *dev_priv;
    2988                 :            :         int diag;
    2989                 :            : 
    2990                 :            :         if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
    2991                 :            :                 RTE_PKTMBUF_HEADROOM) {
    2992                 :            :                 DPAA2_PMD_ERR("RTE_PKTMBUF_HEADROOM(%d) < DPAA2 Annotation(%d)",
    2993                 :            :                         RTE_PKTMBUF_HEADROOM,
    2994                 :            :                         DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
    2995                 :            : 
    2996                 :            :                 return -EINVAL;
    2997                 :            :         }
    2998                 :            : 
    2999         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    3000                 :          0 :                 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
    3001         [ #  # ]:          0 :                 if (!eth_dev)
    3002                 :            :                         return -ENODEV;
    3003                 :          0 :                 dev_priv = rte_zmalloc("ethdev private structure",
    3004                 :            :                                        sizeof(struct dpaa2_dev_priv),
    3005                 :            :                                        RTE_CACHE_LINE_SIZE);
    3006         [ #  # ]:          0 :                 if (dev_priv == NULL) {
    3007                 :          0 :                         DPAA2_PMD_CRIT(
    3008                 :            :                                 "Unable to allocate memory for private data");
    3009                 :          0 :                         rte_eth_dev_release_port(eth_dev);
    3010                 :          0 :                         return -ENOMEM;
    3011                 :            :                 }
    3012                 :          0 :                 eth_dev->data->dev_private = (void *)dev_priv;
    3013                 :            :                 /* Store a pointer to eth_dev in dev_private */
    3014                 :          0 :                 dev_priv->eth_dev = eth_dev;
    3015                 :            :         } else {
    3016                 :          0 :                 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
    3017         [ #  # ]:          0 :                 if (!eth_dev) {
    3018                 :          0 :                         DPAA2_PMD_DEBUG("returning enodev");
    3019                 :          0 :                         return -ENODEV;
    3020                 :            :                 }
    3021                 :            :         }
    3022                 :            : 
    3023                 :          0 :         eth_dev->device = &dpaa2_dev->device;
    3024                 :            : 
    3025                 :          0 :         dpaa2_dev->eth_dev = eth_dev;
    3026                 :          0 :         eth_dev->data->rx_mbuf_alloc_failed = 0;
    3027                 :            : 
    3028         [ #  # ]:          0 :         if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
    3029                 :          0 :                 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
    3030                 :            : 
    3031                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    3032                 :            : 
    3033                 :            :         /* Invoke PMD device initialization function */
    3034                 :          0 :         diag = dpaa2_dev_init(eth_dev);
    3035         [ #  # ]:          0 :         if (!diag) {
    3036                 :          0 :                 diag = dpaa2_tx_sg_pool_init();
    3037         [ #  # ]:          0 :                 if (diag)
    3038                 :            :                         return diag;
    3039                 :          0 :                 rte_eth_dev_probing_finish(eth_dev);
    3040                 :          0 :                 dpaa2_valid_dev++;
    3041                 :          0 :                 return 0;
    3042                 :            :         }
    3043                 :            : 
    3044                 :          0 :         rte_eth_dev_release_port(eth_dev);
    3045                 :          0 :         return diag;
    3046                 :            : }
    3047                 :            : 
    3048                 :            : static int
    3049                 :          0 : rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
    3050                 :            : {
    3051                 :            :         struct rte_eth_dev *eth_dev;
    3052                 :            :         int ret;
    3053                 :            : 
    3054                 :          0 :         eth_dev = dpaa2_dev->eth_dev;
    3055                 :          0 :         dpaa2_dev_close(eth_dev);
    3056                 :          0 :         dpaa2_valid_dev--;
    3057         [ #  # ]:          0 :         if (!dpaa2_valid_dev)
    3058                 :          0 :                 rte_mempool_free(dpaa2_tx_sg_pool);
    3059                 :          0 :         ret = rte_eth_dev_release_port(eth_dev);
    3060                 :            : 
    3061                 :          0 :         return ret;
    3062                 :            : }
    3063                 :            : 
    3064                 :            : static struct rte_dpaa2_driver rte_dpaa2_pmd = {
    3065                 :            :         .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
    3066                 :            :         .drv_type = DPAA2_ETH,
    3067                 :            :         .probe = rte_dpaa2_probe,
    3068                 :            :         .remove = rte_dpaa2_remove,
    3069                 :            : };
    3070                 :            : 
    3071                 :        252 : RTE_PMD_REGISTER_DPAA2(NET_DPAA2_PMD_DRIVER_NAME, rte_dpaa2_pmd);
    3072                 :            : RTE_PMD_REGISTER_PARAM_STRING(NET_DPAA2_PMD_DRIVER_NAME,
    3073                 :            :                 DRIVER_LOOPBACK_MODE "=<int> "
    3074                 :            :                 DRIVER_NO_PREFETCH_MODE "=<int>"
    3075                 :            :                 DRIVER_TX_CONF "=<int>"
    3076                 :            :                 DRIVER_ERROR_QUEUE "=<int>");
    3077         [ -  + ]:        252 : RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_pmd, NOTICE);

Generated by: LCOV version 1.14