LCOV - code coverage report
Current view: top level - drivers/net/dpaa2 - dpaa2_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 1423 0.1 %
Date: 2026-07-01 18:02:41 Functions: 2 62 3.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 759 0.1 %

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

Generated by: LCOV version 1.14