LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 3027 0.1 %
Date: 2024-12-01 18:57:19 Functions: 2 169 1.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 1900 0.1 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2014-2023 Broadcom
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <inttypes.h>
       7                 :            : #include <stdalign.h>
       8                 :            : #include <stdbool.h>
       9                 :            : 
      10                 :            : #include <dev_driver.h>
      11                 :            : #include <ethdev_driver.h>
      12                 :            : #include <ethdev_pci.h>
      13                 :            : #include <rte_malloc.h>
      14                 :            : #include <rte_cycles.h>
      15                 :            : #include <rte_alarm.h>
      16                 :            : #include <rte_kvargs.h>
      17                 :            : #include <rte_vect.h>
      18                 :            : 
      19                 :            : #include "bnxt.h"
      20                 :            : #include "bnxt_filter.h"
      21                 :            : #include "bnxt_hwrm.h"
      22                 :            : #include "bnxt_irq.h"
      23                 :            : #include "bnxt_reps.h"
      24                 :            : #include "bnxt_ring.h"
      25                 :            : #include "bnxt_rxq.h"
      26                 :            : #include "bnxt_rxr.h"
      27                 :            : #include "bnxt_stats.h"
      28                 :            : #include "bnxt_txq.h"
      29                 :            : #include "bnxt_txr.h"
      30                 :            : #include "bnxt_vnic.h"
      31                 :            : #include "hsi_struct_def_dpdk.h"
      32                 :            : #include "bnxt_nvm_defs.h"
      33                 :            : #include "bnxt_tf_common.h"
      34                 :            : #include "ulp_flow_db.h"
      35                 :            : #include "rte_pmd_bnxt.h"
      36                 :            : #include "bnxt_ulp_utils.h"
      37                 :            : 
      38                 :            : #define DRV_MODULE_NAME         "bnxt"
      39                 :            : static const char bnxt_version[] =
      40                 :            :         "Broadcom NetXtreme driver " DRV_MODULE_NAME;
      41                 :            : 
      42                 :            : /*
      43                 :            :  * The set of PCI devices this driver supports
      44                 :            :  */
      45                 :            : static const struct rte_pci_id bnxt_pci_id_map[] = {
      46                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
      47                 :            :                          BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
      48                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
      49                 :            :                          BROADCOM_DEV_ID_STRATUS_NIC_VF2) },
      50                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
      51                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
      52                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
      53                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
      54                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
      55                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
      56                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
      57                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
      58                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
      59                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
      60                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
      61                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
      62                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
      63                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
      64                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
      65                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
      66                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
      67                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
      68                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
      69                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
      70                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802) },
      71                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58804) },
      72                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58808) },
      73                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802_VF) },
      74                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
      75                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
      76                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
      77                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
      78                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
      79                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF1) },
      80                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF1) },
      81                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF1) },
      82                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF2) },
      83                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF2) },
      84                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF2) },
      85                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58812) },
      86                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58814) },
      87                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58818) },
      88                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58818_VF) },
      89                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57608) },
      90                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57604) },
      91                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57602) },
      92                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57601) },
      93                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5760X_VF) },
      94                 :            :         { .vendor_id = 0, /* sentinel */ },
      95                 :            : };
      96                 :            : 
      97                 :            : #define BNXT_DEVARG_FLOW_XSTAT  "flow-xstat"
      98                 :            : #define BNXT_DEVARG_MAX_NUM_KFLOWS  "max-num-kflows"
      99                 :            : #define BNXT_DEVARG_REPRESENTOR "representor"
     100                 :            : #define BNXT_DEVARG_REP_BASED_PF  "rep-based-pf"
     101                 :            : #define BNXT_DEVARG_REP_IS_PF  "rep-is-pf"
     102                 :            : #define BNXT_DEVARG_REP_Q_R2F  "rep-q-r2f"
     103                 :            : #define BNXT_DEVARG_REP_Q_F2R  "rep-q-f2r"
     104                 :            : #define BNXT_DEVARG_REP_FC_R2F  "rep-fc-r2f"
     105                 :            : #define BNXT_DEVARG_REP_FC_F2R  "rep-fc-f2r"
     106                 :            : #define BNXT_DEVARG_APP_ID      "app-id"
     107                 :            : #define BNXT_DEVARG_IEEE_1588   "ieee-1588"
     108                 :            : #define BNXT_DEVARG_CQE_MODE    "cqe-mode"
     109                 :            : #define BNXT_DEVARG_MPC         "mpc"
     110                 :            : 
     111                 :            : static const char *const bnxt_dev_args[] = {
     112                 :            :         BNXT_DEVARG_REPRESENTOR,
     113                 :            :         BNXT_DEVARG_FLOW_XSTAT,
     114                 :            :         BNXT_DEVARG_MAX_NUM_KFLOWS,
     115                 :            :         BNXT_DEVARG_REP_BASED_PF,
     116                 :            :         BNXT_DEVARG_REP_IS_PF,
     117                 :            :         BNXT_DEVARG_REP_Q_R2F,
     118                 :            :         BNXT_DEVARG_REP_Q_F2R,
     119                 :            :         BNXT_DEVARG_REP_FC_R2F,
     120                 :            :         BNXT_DEVARG_REP_FC_F2R,
     121                 :            :         BNXT_DEVARG_APP_ID,
     122                 :            :         BNXT_DEVARG_IEEE_1588,
     123                 :            :         BNXT_DEVARG_CQE_MODE,
     124                 :            :         BNXT_DEVARG_MPC,
     125                 :            :         NULL
     126                 :            : };
     127                 :            : 
     128                 :            : #define BNXT_SPEEDS_SUPP_SPEED_LANES (RTE_ETH_LINK_SPEED_10G | \
     129                 :            :                                       RTE_ETH_LINK_SPEED_25G | \
     130                 :            :                                       RTE_ETH_LINK_SPEED_40G | \
     131                 :            :                                       RTE_ETH_LINK_SPEED_50G | \
     132                 :            :                                       RTE_ETH_LINK_SPEED_100G | \
     133                 :            :                                       RTE_ETH_LINK_SPEED_200G | \
     134                 :            :                                       RTE_ETH_LINK_SPEED_400G)
     135                 :            : 
     136                 :            : static const struct rte_eth_speed_lanes_capa speed_lanes_capa_tbl[] = {
     137                 :            :         { RTE_ETH_SPEED_NUM_10G, RTE_BIT32(1) },
     138                 :            :         { RTE_ETH_SPEED_NUM_25G, RTE_BIT32(1) },
     139                 :            :         { RTE_ETH_SPEED_NUM_40G, RTE_BIT32(4) },
     140                 :            :         { RTE_ETH_SPEED_NUM_50G, RTE_BIT32(1) | RTE_BIT32(2) },
     141                 :            :         { RTE_ETH_SPEED_NUM_100G, RTE_BIT32(1) | RTE_BIT32(2) | RTE_BIT32(4) },
     142                 :            :         { RTE_ETH_SPEED_NUM_200G, RTE_BIT32(2) | RTE_BIT32(4) },
     143                 :            :         { RTE_ETH_SPEED_NUM_400G, RTE_BIT32(4) | RTE_BIT32(8) },
     144                 :            : };
     145                 :            : 
     146                 :            : /*
     147                 :            :  * cqe-mode = an non-negative 8-bit number
     148                 :            :  */
     149                 :            : #define BNXT_DEVARG_CQE_MODE_INVALID(val)               ((val) > 1)
     150                 :            : 
     151                 :            : /*
     152                 :            :  * mpc = an non-negative 8-bit number
     153                 :            :  */
     154                 :            : #define BNXT_DEVARG_MPC_INVALID(val)                    ((val) > 1)
     155                 :            : 
     156                 :            : /*
     157                 :            :  * app-id = an non-negative 8-bit number
     158                 :            :  */
     159                 :            : #define BNXT_DEVARG_APP_ID_INVALID(val)                 ((val) > 255)
     160                 :            : 
     161                 :            : /*
     162                 :            :  * ieee-1588 = an non-negative 8-bit number
     163                 :            :  */
     164                 :            : #define BNXT_DEVARG_IEEE_1588_INVALID(val)                      ((val) > 255)
     165                 :            : 
     166                 :            : /*
     167                 :            :  * flow_xstat == false to disable the feature
     168                 :            :  * flow_xstat == true to enable the feature
     169                 :            :  */
     170                 :            : #define BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)      ((flow_xstat) > 1)
     171                 :            : 
     172                 :            : /*
     173                 :            :  * rep_is_pf == false to indicate VF representor
     174                 :            :  * rep_is_pf == true to indicate PF representor
     175                 :            :  */
     176                 :            : #define BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf)        ((rep_is_pf) > 1)
     177                 :            : 
     178                 :            : /*
     179                 :            :  * rep_based_pf == Physical index of the PF
     180                 :            :  */
     181                 :            : #define BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf)  ((rep_based_pf) > 15)
     182                 :            : /*
     183                 :            :  * rep_q_r2f == Logical COS Queue index for the rep to endpoint direction
     184                 :            :  */
     185                 :            : #define BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f)        ((rep_q_r2f) > 3)
     186                 :            : 
     187                 :            : /*
     188                 :            :  * rep_q_f2r == Logical COS Queue index for the endpoint to rep direction
     189                 :            :  */
     190                 :            : #define BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r)        ((rep_q_f2r) > 3)
     191                 :            : 
     192                 :            : /*
     193                 :            :  * rep_fc_r2f == Flow control for the representor to endpoint direction
     194                 :            :  */
     195                 :            : #define BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f)      ((rep_fc_r2f) > 1)
     196                 :            : 
     197                 :            : /*
     198                 :            :  * rep_fc_f2r == Flow control for the endpoint to representor direction
     199                 :            :  */
     200                 :            : #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)      ((rep_fc_f2r) > 1)
     201                 :            : 
     202                 :            : int bnxt_cfa_code_dynfield_offset = -1;
     203                 :            : unsigned long mpc;
     204                 :            : 
     205                 :            : /*
     206                 :            :  * max_num_kflows must be >= 32
     207                 :            :  * and must be a power-of-2 supported value
     208                 :            :  * return: 1 -> invalid
     209                 :            :  *         0 -> valid
     210                 :            :  */
     211                 :            : static int bnxt_devarg_max_num_kflow_invalid(uint16_t max_num_kflows)
     212                 :            : {
     213         [ #  # ]:          0 :         if (max_num_kflows < 32 || !rte_is_power_of_2(max_num_kflows))
     214                 :            :                 return 1;
     215                 :            :         return 0;
     216                 :            : }
     217                 :            : 
     218                 :            : static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
     219                 :            : static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
     220                 :            : static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev);
     221                 :            : static int bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev);
     222                 :            : static void bnxt_cancel_fw_health_check(struct bnxt *bp);
     223                 :            : static int bnxt_restore_vlan_filters(struct bnxt *bp);
     224                 :            : static void bnxt_dev_recover(void *arg);
     225                 :            : static void bnxt_free_error_recovery_info(struct bnxt *bp);
     226                 :            : static void bnxt_free_rep_info(struct bnxt *bp);
     227                 :            : static int bnxt_check_fw_ready(struct bnxt *bp);
     228                 :            : static bool bnxt_enable_ulp(struct bnxt *bp);
     229                 :            : 
     230                 :          0 : int is_bnxt_in_error(struct bnxt *bp)
     231                 :            : {
     232         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FATAL_ERROR)
     233                 :            :                 return -EIO;
     234         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_RESET)
     235                 :          0 :                 return -EBUSY;
     236                 :            : 
     237                 :            :         return 0;
     238                 :            : }
     239                 :            : 
     240                 :            : /***********************/
     241                 :            : 
     242                 :            : /*
     243                 :            :  * High level utility functions
     244                 :            :  */
     245                 :            : 
     246                 :          0 : uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
     247                 :            : {
     248                 :          0 :         unsigned int num_rss_rings = RTE_MIN(bp->rx_nr_rings,
     249                 :            :                                              BNXT_RSS_TBL_SIZE_P5);
     250                 :            : 
     251         [ #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp))
     252                 :            :                 return 1;
     253                 :            : 
     254                 :          0 :         return RTE_ALIGN_MUL_CEIL(num_rss_rings,
     255                 :          0 :                                   BNXT_RSS_ENTRIES_PER_CTX_P5) /
     256                 :            :                                   BNXT_RSS_ENTRIES_PER_CTX_P5;
     257                 :            : }
     258                 :            : 
     259                 :          0 : uint16_t bnxt_rss_hash_tbl_size(const struct bnxt *bp)
     260                 :            : {
     261         [ #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp))
     262                 :            :                 return HW_HASH_INDEX_SIZE;
     263                 :            : 
     264                 :          0 :         return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_P5;
     265                 :            : }
     266                 :            : 
     267                 :            : static void bnxt_free_parent_info(struct bnxt *bp)
     268                 :            : {
     269                 :          0 :         rte_free(bp->parent);
     270                 :          0 :         bp->parent = NULL;
     271                 :            : }
     272                 :            : 
     273                 :            : static void bnxt_free_pf_info(struct bnxt *bp)
     274                 :            : {
     275                 :          0 :         rte_free(bp->pf);
     276                 :          0 :         bp->pf = NULL;
     277                 :            : }
     278                 :            : 
     279                 :            : static void bnxt_free_link_info(struct bnxt *bp)
     280                 :            : {
     281                 :          0 :         rte_free(bp->link_info);
     282                 :          0 :         bp->link_info = NULL;
     283                 :            : }
     284                 :            : 
     285                 :            : static void bnxt_free_leds_info(struct bnxt *bp)
     286                 :            : {
     287                 :          0 :         if (BNXT_VF(bp))
     288                 :            :                 return;
     289                 :            : 
     290                 :          0 :         rte_free(bp->leds);
     291                 :          0 :         bp->leds = NULL;
     292                 :            : }
     293                 :            : 
     294                 :            : static void bnxt_free_flow_stats_info(struct bnxt *bp)
     295                 :            : {
     296                 :          0 :         rte_free(bp->flow_stat);
     297                 :          0 :         bp->flow_stat = NULL;
     298                 :            : }
     299                 :            : 
     300                 :            : static void bnxt_free_cos_queues(struct bnxt *bp)
     301                 :            : {
     302                 :          0 :         rte_free(bp->rx_cos_queue);
     303                 :          0 :         bp->rx_cos_queue = NULL;
     304                 :          0 :         rte_free(bp->tx_cos_queue);
     305                 :          0 :         bp->tx_cos_queue = NULL;
     306                 :            : }
     307                 :            : 
     308                 :          0 : static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
     309                 :            : {
     310                 :          0 :         bnxt_free_filter_mem(bp);
     311                 :          0 :         bnxt_free_vnic_attributes(bp);
     312                 :          0 :         bnxt_free_vnic_mem(bp);
     313                 :            : 
     314                 :            :         /* tx/rx rings are configured as part of *_queue_setup callbacks.
     315                 :            :          * If the number of rings change across fw update,
     316                 :            :          * we don't have much choice except to warn the user.
     317                 :            :          */
     318         [ #  # ]:          0 :         if (!reconfig) {
     319                 :          0 :                 bnxt_free_stats(bp);
     320                 :          0 :                 bnxt_free_tx_rings(bp);
     321                 :          0 :                 bnxt_free_rx_rings(bp);
     322                 :            :         }
     323                 :          0 :         bnxt_free_async_cp_ring(bp);
     324                 :          0 :         bnxt_free_rxtx_nq_ring(bp);
     325                 :            : 
     326                 :          0 :         rte_free(bp->grp_info);
     327                 :          0 :         bp->grp_info = NULL;
     328                 :          0 : }
     329                 :            : 
     330                 :            : static int bnxt_alloc_parent_info(struct bnxt *bp)
     331                 :            : {
     332                 :          0 :         bp->parent = rte_zmalloc("bnxt_parent_info",
     333                 :            :                                  sizeof(struct bnxt_parent_info), 0);
     334         [ #  # ]:          0 :         if (bp->parent == NULL)
     335                 :            :                 return -ENOMEM;
     336                 :            : 
     337                 :            :         return 0;
     338                 :            : }
     339                 :            : 
     340                 :            : static int bnxt_alloc_pf_info(struct bnxt *bp)
     341                 :            : {
     342                 :          0 :         bp->pf = rte_zmalloc("bnxt_pf_info", sizeof(struct bnxt_pf_info), 0);
     343         [ #  # ]:          0 :         if (bp->pf == NULL)
     344                 :            :                 return -ENOMEM;
     345                 :            : 
     346                 :            :         return 0;
     347                 :            : }
     348                 :            : 
     349                 :            : static int bnxt_alloc_link_info(struct bnxt *bp)
     350                 :            : {
     351                 :          0 :         bp->link_info =
     352                 :          0 :                 rte_zmalloc("bnxt_link_info", sizeof(struct bnxt_link_info), 0);
     353         [ #  # ]:          0 :         if (bp->link_info == NULL)
     354                 :            :                 return -ENOMEM;
     355                 :            : 
     356                 :            :         return 0;
     357                 :            : }
     358                 :            : 
     359                 :          0 : static int bnxt_alloc_leds_info(struct bnxt *bp)
     360                 :            : {
     361         [ #  # ]:          0 :         if (BNXT_VF(bp))
     362                 :            :                 return 0;
     363                 :            : 
     364                 :          0 :         bp->leds = rte_zmalloc("bnxt_leds",
     365                 :            :                                BNXT_MAX_LED * sizeof(struct bnxt_led_info),
     366                 :            :                                0);
     367         [ #  # ]:          0 :         if (bp->leds == NULL)
     368                 :          0 :                 return -ENOMEM;
     369                 :            : 
     370                 :            :         return 0;
     371                 :            : }
     372                 :            : 
     373                 :          0 : static int bnxt_alloc_cos_queues(struct bnxt *bp)
     374                 :            : {
     375                 :          0 :         bp->rx_cos_queue =
     376                 :          0 :                 rte_zmalloc("bnxt_rx_cosq",
     377                 :            :                             BNXT_COS_QUEUE_COUNT *
     378                 :            :                             sizeof(struct bnxt_cos_queue_info),
     379                 :            :                             0);
     380         [ #  # ]:          0 :         if (bp->rx_cos_queue == NULL)
     381                 :            :                 return -ENOMEM;
     382                 :            : 
     383                 :          0 :         bp->tx_cos_queue =
     384                 :          0 :                 rte_zmalloc("bnxt_tx_cosq",
     385                 :            :                             BNXT_COS_QUEUE_COUNT *
     386                 :            :                             sizeof(struct bnxt_cos_queue_info),
     387                 :            :                             0);
     388         [ #  # ]:          0 :         if (bp->tx_cos_queue == NULL)
     389                 :          0 :                 return -ENOMEM;
     390                 :            : 
     391                 :            :         return 0;
     392                 :            : }
     393                 :            : 
     394                 :            : static int bnxt_alloc_flow_stats_info(struct bnxt *bp)
     395                 :            : {
     396                 :          0 :         bp->flow_stat = rte_zmalloc("bnxt_flow_xstat",
     397                 :            :                                     sizeof(struct bnxt_flow_stat_info), 0);
     398         [ #  # ]:          0 :         if (bp->flow_stat == NULL)
     399                 :            :                 return -ENOMEM;
     400                 :            : 
     401                 :            :         return 0;
     402                 :            : }
     403                 :            : 
     404                 :          0 : static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
     405                 :            : {
     406                 :            :         int rc;
     407                 :            : 
     408                 :          0 :         rc = bnxt_alloc_ring_grps(bp);
     409         [ #  # ]:          0 :         if (rc)
     410                 :          0 :                 goto alloc_mem_err;
     411                 :            : 
     412                 :          0 :         rc = bnxt_alloc_async_ring_struct(bp);
     413         [ #  # ]:          0 :         if (rc)
     414                 :          0 :                 goto alloc_mem_err;
     415                 :            : 
     416                 :          0 :         rc = bnxt_alloc_vnic_mem(bp);
     417         [ #  # ]:          0 :         if (rc)
     418                 :          0 :                 goto alloc_mem_err;
     419                 :            : 
     420                 :          0 :         rc = bnxt_alloc_vnic_attributes(bp, reconfig);
     421         [ #  # ]:          0 :         if (rc)
     422                 :          0 :                 goto alloc_mem_err;
     423                 :            : 
     424                 :          0 :         rc = bnxt_alloc_filter_mem(bp);
     425         [ #  # ]:          0 :         if (rc)
     426                 :          0 :                 goto alloc_mem_err;
     427                 :            : 
     428                 :          0 :         rc = bnxt_alloc_async_cp_ring(bp);
     429         [ #  # ]:          0 :         if (rc)
     430                 :          0 :                 goto alloc_mem_err;
     431                 :            : 
     432                 :          0 :         rc = bnxt_alloc_rxtx_nq_ring(bp);
     433         [ #  # ]:          0 :         if (rc)
     434                 :          0 :                 goto alloc_mem_err;
     435                 :            : 
     436         [ #  # ]:          0 :         if (BNXT_FLOW_XSTATS_EN(bp)) {
     437                 :            :                 rc = bnxt_alloc_flow_stats_info(bp);
     438                 :            :                 if (rc)
     439                 :          0 :                         goto alloc_mem_err;
     440                 :            :         }
     441                 :            : 
     442                 :            :         return 0;
     443                 :            : 
     444                 :          0 : alloc_mem_err:
     445                 :          0 :         bnxt_free_mem(bp, reconfig);
     446                 :          0 :         return rc;
     447                 :            : }
     448                 :            : 
     449                 :          0 : static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
     450                 :            : {
     451                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
     452                 :          0 :         struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
     453                 :          0 :         uint64_t rx_offloads = dev_conf->rxmode.offloads;
     454                 :            :         struct bnxt_rx_queue *rxq;
     455                 :            :         unsigned int j;
     456                 :            :         int rc;
     457                 :            : 
     458                 :          0 :         rc = bnxt_vnic_grp_alloc(bp, vnic);
     459         [ #  # ]:          0 :         if (rc)
     460                 :          0 :                 goto err_out;
     461                 :            : 
     462                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p",
     463                 :            :                     vnic_id, vnic, vnic->fw_grp_ids);
     464                 :            : 
     465                 :            :         /* populate the fw group table */
     466                 :          0 :         bnxt_vnic_ring_grp_populate(bp, vnic);
     467                 :          0 :         bnxt_vnic_rules_init(vnic);
     468                 :            : 
     469                 :          0 :         rc = bnxt_hwrm_vnic_alloc(bp, vnic);
     470         [ #  # ]:          0 :         if (rc)
     471                 :          0 :                 goto err_out;
     472                 :            : 
     473                 :            :         /* Alloc RSS context only if RSS mode is enabled */
     474         [ #  # ]:          0 :         if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS) {
     475                 :          0 :                 int j, nr_ctxs = bnxt_rss_ctxts(bp);
     476                 :            : 
     477                 :            :                 /* RSS table size in P5 is 512.
     478                 :            :                  * Cap max Rx rings to same value
     479                 :            :                  */
     480         [ #  # ]:          0 :                 if (bp->rx_nr_rings > BNXT_RSS_TBL_SIZE_P5) {
     481                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "RxQ cnt %d > reta_size %d",
     482                 :            :                                     bp->rx_nr_rings, BNXT_RSS_TBL_SIZE_P5);
     483                 :          0 :                         goto err_out;
     484                 :            :                 }
     485                 :            : 
     486                 :            :                 rc = 0;
     487         [ #  # ]:          0 :                 for (j = 0; j < nr_ctxs; j++) {
     488                 :          0 :                         rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, j);
     489         [ #  # ]:          0 :                         if (rc)
     490                 :            :                                 break;
     491                 :            :                 }
     492         [ #  # ]:          0 :                 if (rc) {
     493                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
     494                 :            :                                     "HWRM vnic %d ctx %d alloc failure rc: %x",
     495                 :            :                                     vnic_id, j, rc);
     496                 :          0 :                         goto err_out;
     497                 :            :                 }
     498                 :          0 :                 vnic->num_lb_ctxts = nr_ctxs;
     499                 :            :         }
     500                 :            : 
     501                 :            :         /*
     502                 :            :          * Firmware sets pf pair in default vnic cfg. If the VLAN strip
     503                 :            :          * setting is not available at this time, it will not be
     504                 :            :          * configured correctly in the CFA.
     505                 :            :          */
     506         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
     507                 :          0 :                 vnic->vlan_strip = true;
     508                 :            :         else
     509                 :          0 :                 vnic->vlan_strip = false;
     510                 :            : 
     511                 :          0 :         rc = bnxt_hwrm_vnic_cfg(bp, vnic);
     512         [ #  # ]:          0 :         if (rc)
     513                 :          0 :                 goto err_out;
     514                 :            : 
     515                 :          0 :         rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
     516         [ #  # ]:          0 :         if (rc)
     517                 :          0 :                 goto err_out;
     518                 :            : 
     519         [ #  # ]:          0 :         for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
     520                 :          0 :                 rxq = bp->eth_dev->data->rx_queues[j];
     521                 :            : 
     522                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG,
     523                 :            :                             "rxq[%d]->vnic=%p vnic->fw_grp_ids=%p",
     524                 :            :                             j, rxq->vnic, rxq->vnic->fw_grp_ids);
     525                 :            : 
     526   [ #  #  #  # ]:          0 :                 if (BNXT_HAS_RING_GRPS(bp) && rxq->rx_deferred_start)
     527                 :          0 :                         vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
     528                 :            :         }
     529                 :            : 
     530                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "vnic->rx_queue_cnt = %d", vnic->rx_queue_cnt);
     531                 :            : 
     532                 :          0 :         rc = bnxt_vnic_rss_configure(bp, vnic);
     533         [ #  # ]:          0 :         if (rc)
     534                 :          0 :                 goto err_out;
     535                 :            : 
     536                 :          0 :         bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
     537                 :            : 
     538                 :          0 :         rc = bnxt_hwrm_vnic_tpa_cfg(bp, vnic,
     539                 :            :                                     (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) ?
     540                 :          0 :                                     true : false);
     541         [ #  # ]:          0 :         if (rc)
     542                 :          0 :                 goto err_out;
     543                 :            : 
     544                 :            :         return 0;
     545                 :          0 : err_out:
     546                 :          0 :         PMD_DRV_LOG_LINE(ERR, "HWRM vnic %d cfg failure rc: %x",
     547                 :            :                     vnic_id, rc);
     548                 :          0 :         return rc;
     549                 :            : }
     550                 :            : 
     551                 :          0 : static int bnxt_register_fc_ctx_mem(struct bnxt *bp)
     552                 :            : {
     553                 :            :         int rc = 0;
     554                 :            : 
     555                 :          0 :         rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_in_tbl.dma,
     556                 :          0 :                                 &bp->flow_stat->rx_fc_in_tbl.ctx_id);
     557         [ #  # ]:          0 :         if (rc)
     558                 :            :                 return rc;
     559                 :            : 
     560                 :          0 :         PMD_DRV_LOG_LINE(DEBUG,
     561                 :            :                     "rx_fc_in_tbl.va = %p rx_fc_in_tbl.dma = %p"
     562                 :            :                     " rx_fc_in_tbl.ctx_id = %d",
     563                 :            :                     bp->flow_stat->rx_fc_in_tbl.va,
     564                 :            :                     (void *)((uintptr_t)bp->flow_stat->rx_fc_in_tbl.dma),
     565                 :            :                     bp->flow_stat->rx_fc_in_tbl.ctx_id);
     566                 :            : 
     567                 :          0 :         rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_out_tbl.dma,
     568                 :          0 :                                 &bp->flow_stat->rx_fc_out_tbl.ctx_id);
     569         [ #  # ]:          0 :         if (rc)
     570                 :            :                 return rc;
     571                 :            : 
     572                 :          0 :         PMD_DRV_LOG_LINE(DEBUG,
     573                 :            :                     "rx_fc_out_tbl.va = %p rx_fc_out_tbl.dma = %p"
     574                 :            :                     " rx_fc_out_tbl.ctx_id = %d",
     575                 :            :                     bp->flow_stat->rx_fc_out_tbl.va,
     576                 :            :                     (void *)((uintptr_t)bp->flow_stat->rx_fc_out_tbl.dma),
     577                 :            :                     bp->flow_stat->rx_fc_out_tbl.ctx_id);
     578                 :            : 
     579                 :          0 :         rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_in_tbl.dma,
     580                 :          0 :                                 &bp->flow_stat->tx_fc_in_tbl.ctx_id);
     581         [ #  # ]:          0 :         if (rc)
     582                 :            :                 return rc;
     583                 :            : 
     584                 :          0 :         PMD_DRV_LOG_LINE(DEBUG,
     585                 :            :                     "tx_fc_in_tbl.va = %p tx_fc_in_tbl.dma = %p"
     586                 :            :                     " tx_fc_in_tbl.ctx_id = %d",
     587                 :            :                     bp->flow_stat->tx_fc_in_tbl.va,
     588                 :            :                     (void *)((uintptr_t)bp->flow_stat->tx_fc_in_tbl.dma),
     589                 :            :                     bp->flow_stat->tx_fc_in_tbl.ctx_id);
     590                 :            : 
     591                 :          0 :         rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_out_tbl.dma,
     592                 :          0 :                                 &bp->flow_stat->tx_fc_out_tbl.ctx_id);
     593         [ #  # ]:          0 :         if (rc)
     594                 :            :                 return rc;
     595                 :            : 
     596                 :          0 :         PMD_DRV_LOG_LINE(DEBUG,
     597                 :            :                     "tx_fc_out_tbl.va = %p tx_fc_out_tbl.dma = %p"
     598                 :            :                     " tx_fc_out_tbl.ctx_id = %d",
     599                 :            :                     bp->flow_stat->tx_fc_out_tbl.va,
     600                 :            :                     (void *)((uintptr_t)bp->flow_stat->tx_fc_out_tbl.dma),
     601                 :            :                     bp->flow_stat->tx_fc_out_tbl.ctx_id);
     602                 :            : 
     603                 :          0 :         memset(bp->flow_stat->rx_fc_out_tbl.va,
     604                 :            :                0,
     605                 :          0 :                bp->flow_stat->rx_fc_out_tbl.size);
     606                 :          0 :         rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
     607                 :            :                                        CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
     608                 :          0 :                                        bp->flow_stat->rx_fc_out_tbl.ctx_id,
     609                 :          0 :                                        bp->flow_stat->max_fc,
     610                 :            :                                        true);
     611         [ #  # ]:          0 :         if (rc)
     612                 :            :                 return rc;
     613                 :            : 
     614                 :          0 :         memset(bp->flow_stat->tx_fc_out_tbl.va,
     615                 :            :                0,
     616                 :          0 :                bp->flow_stat->tx_fc_out_tbl.size);
     617                 :          0 :         rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
     618                 :            :                                        CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
     619                 :          0 :                                        bp->flow_stat->tx_fc_out_tbl.ctx_id,
     620                 :          0 :                                        bp->flow_stat->max_fc,
     621                 :            :                                        true);
     622                 :            : 
     623                 :          0 :         return rc;
     624                 :            : }
     625                 :            : 
     626                 :          0 : static int bnxt_alloc_ctx_mem_buf(struct bnxt *bp, char *type, size_t size,
     627                 :            :                                   struct bnxt_ctx_mem_buf_info *ctx)
     628                 :            : {
     629         [ #  # ]:          0 :         if (!ctx)
     630                 :            :                 return -EINVAL;
     631                 :            : 
     632                 :          0 :         ctx->va = rte_zmalloc_socket(type, size, 0,
     633                 :          0 :                                      bp->eth_dev->device->numa_node);
     634         [ #  # ]:          0 :         if (ctx->va == NULL)
     635                 :            :                 return -ENOMEM;
     636                 :          0 :         rte_mem_lock_page(ctx->va);
     637                 :          0 :         ctx->size = size;
     638                 :          0 :         ctx->dma = rte_mem_virt2iova(ctx->va);
     639         [ #  # ]:          0 :         if (ctx->dma == RTE_BAD_IOVA)
     640                 :          0 :                 return -ENOMEM;
     641                 :            : 
     642                 :            :         return 0;
     643                 :            : }
     644                 :            : 
     645                 :          0 : static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
     646                 :            : {
     647                 :          0 :         struct rte_pci_device *pdev = bp->pdev;
     648                 :            :         char type[RTE_MEMZONE_NAMESIZE];
     649                 :            :         uint16_t max_fc;
     650                 :            :         int rc = 0;
     651                 :            : 
     652                 :          0 :         max_fc = bp->flow_stat->max_fc;
     653                 :            : 
     654                 :          0 :         sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
     655                 :          0 :                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
     656                 :            :         /* 4 bytes for each counter-id */
     657                 :          0 :         rc = bnxt_alloc_ctx_mem_buf(bp, type,
     658                 :          0 :                                     max_fc * 4,
     659                 :          0 :                                     &bp->flow_stat->rx_fc_in_tbl);
     660         [ #  # ]:          0 :         if (rc)
     661                 :            :                 return rc;
     662                 :            : 
     663                 :          0 :         sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
     664                 :          0 :                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
     665                 :            :         /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
     666                 :          0 :         rc = bnxt_alloc_ctx_mem_buf(bp, type,
     667                 :          0 :                                     max_fc * 16,
     668                 :          0 :                                     &bp->flow_stat->rx_fc_out_tbl);
     669         [ #  # ]:          0 :         if (rc)
     670                 :            :                 return rc;
     671                 :            : 
     672                 :          0 :         sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
     673                 :          0 :                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
     674                 :            :         /* 4 bytes for each counter-id */
     675                 :          0 :         rc = bnxt_alloc_ctx_mem_buf(bp, type,
     676                 :            :                                     max_fc * 4,
     677                 :          0 :                                     &bp->flow_stat->tx_fc_in_tbl);
     678         [ #  # ]:          0 :         if (rc)
     679                 :            :                 return rc;
     680                 :            : 
     681                 :          0 :         sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
     682                 :          0 :                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
     683                 :            :         /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
     684                 :          0 :         rc = bnxt_alloc_ctx_mem_buf(bp, type,
     685                 :            :                                     max_fc * 16,
     686                 :          0 :                                     &bp->flow_stat->tx_fc_out_tbl);
     687         [ #  # ]:          0 :         if (rc)
     688                 :            :                 return rc;
     689                 :            : 
     690                 :          0 :         rc = bnxt_register_fc_ctx_mem(bp);
     691                 :            : 
     692                 :          0 :         return rc;
     693                 :            : }
     694                 :            : 
     695                 :          0 : static int bnxt_init_ctx_mem(struct bnxt *bp)
     696                 :            : {
     697                 :            :         int rc = 0;
     698                 :            : 
     699         [ #  # ]:          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS) ||
     700   [ #  #  #  # ]:          0 :             !(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) ||
     701                 :            :             !BNXT_FLOW_XSTATS_EN(bp))
     702                 :            :                 return 0;
     703                 :            : 
     704                 :          0 :         rc = bnxt_hwrm_cfa_counter_qcaps(bp, &bp->flow_stat->max_fc);
     705         [ #  # ]:          0 :         if (rc)
     706                 :            :                 return rc;
     707                 :            : 
     708                 :          0 :         rc = bnxt_init_fc_ctx_mem(bp);
     709                 :            : 
     710                 :          0 :         return rc;
     711                 :            : }
     712                 :            : 
     713                 :            : static inline bool bnxt_force_link_config(struct bnxt *bp)
     714                 :            : {
     715                 :          0 :         uint16_t subsystem_device_id = bp->pdev->id.subsystem_device_id;
     716                 :            : 
     717   [ #  #  #  # ]:          0 :         switch (subsystem_device_id) {
     718                 :            :         case BROADCOM_DEV_957508_N2100:
     719                 :            :         case BROADCOM_DEV_957414_N225:
     720                 :            :                 return true;
     721                 :            :         default:
     722                 :            :                 return false;
     723                 :            :         }
     724                 :            : }
     725                 :            : 
     726                 :          0 : static int bnxt_validate_speed_lanes_change(struct bnxt *bp)
     727                 :            : {
     728                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
     729                 :            :         struct rte_eth_link *link = &bp->eth_dev->data->dev_link;
     730                 :            :         uint32_t curr_speed_bit;
     731                 :            :         int rc;
     732                 :            : 
     733                 :            :         /* Check if speed x lanes combo is supported */
     734         [ #  # ]:          0 :         if (dev_conf->link_speeds)  {
     735                 :          0 :                 rc = bnxt_parse_eth_link_speed_v2(bp);
     736         [ #  # ]:          0 :                 if (rc == 0)
     737                 :            :                         return -EINVAL;
     738                 :            :         }
     739                 :            : 
     740                 :            :         /* convert to speedbit flag */
     741                 :          0 :         curr_speed_bit = rte_eth_speed_bitflag((uint32_t)link->link_speed, 1);
     742                 :            : 
     743                 :            :         /* check if speed and lanes have changed */
     744         [ #  # ]:          0 :         if (dev_conf->link_speeds != curr_speed_bit ||
     745         [ #  # ]:          0 :             bp->link_info->active_lanes != bp->link_info->pmd_speed_lanes)
     746                 :          0 :                 return 1;
     747                 :            : 
     748                 :            :         return 0;
     749                 :            : }
     750                 :            : 
     751                 :          0 : static int bnxt_update_phy_setting(struct bnxt *bp)
     752                 :            : {
     753                 :            :         struct rte_eth_link new;
     754                 :            :         int rc, rc1 = 0;
     755                 :            : 
     756                 :          0 :         rc = bnxt_get_hwrm_link_config(bp, &new);
     757         [ #  # ]:          0 :         if (rc) {
     758                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to get link settings");
     759                 :          0 :                 return rc;
     760                 :            :         }
     761                 :            : 
     762                 :            :         /* Validate speeds2 requirements */
     763   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp)) {
             #  #  #  # ]
     764                 :          0 :                 rc1 = bnxt_validate_speed_lanes_change(bp);
     765         [ #  # ]:          0 :                 if (rc1 == -EINVAL) {
     766                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to set correct lanes");
     767                 :          0 :                         return rc1;
     768                 :            :                 }
     769                 :            :         }
     770                 :            : 
     771                 :            :         /*
     772                 :            :          * Device is not obliged link down in certain scenarios, even
     773                 :            :          * when forced. When FW does not allow any user other than BMC
     774                 :            :          * to shutdown the port, bnxt_get_hwrm_link_config() call always
     775                 :            :          * returns link up. Force phy update always in that case.
     776                 :            :          */
     777   [ #  #  #  # ]:          0 :         if (!new.link_status || bnxt_force_link_config(bp) || rc1 == 1) {
     778                 :          0 :                 rc = bnxt_set_hwrm_link_config(bp, true);
     779         [ #  # ]:          0 :                 if (rc) {
     780                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to update PHY settings");
     781                 :          0 :                         return rc;
     782                 :            :                 }
     783                 :            :         }
     784                 :            : 
     785                 :            :         return rc;
     786                 :            : }
     787                 :            : 
     788                 :          0 : static void bnxt_free_prev_ring_stats(struct bnxt *bp)
     789                 :            : {
     790                 :            :         /* tpa v2 devices use ext variant local struct */
     791   [ #  #  #  # ]:          0 :         if (BNXT_TPA_V2_P7(bp)) {
     792                 :          0 :                 rte_free(bp->prev_rx_ring_stats_ext);
     793                 :          0 :                 rte_free(bp->prev_tx_ring_stats_ext);
     794                 :          0 :                 bp->prev_rx_ring_stats_ext = NULL;
     795                 :          0 :                 bp->prev_tx_ring_stats_ext = NULL;
     796                 :          0 :                 return;
     797                 :            :         }
     798                 :          0 :         rte_free(bp->prev_rx_ring_stats);
     799                 :          0 :         rte_free(bp->prev_tx_ring_stats);
     800                 :          0 :         bp->prev_rx_ring_stats = NULL;
     801                 :          0 :         bp->prev_tx_ring_stats = NULL;
     802                 :            : }
     803                 :            : 
     804                 :          0 : static int bnxt_alloc_prev_ring_ext_stats(struct bnxt *bp)
     805                 :            : {
     806                 :          0 :         bp->prev_rx_ring_stats_ext = rte_zmalloc("bnxt_prev_rx_ring_stats_ext",
     807                 :            :                                                  sizeof(struct bnxt_ring_stats_ext) *
     808                 :          0 :                                                  bp->rx_cp_nr_rings,
     809                 :            :                                                  0);
     810         [ #  # ]:          0 :         if (bp->prev_rx_ring_stats_ext == NULL)
     811                 :            :                 return -ENOMEM;
     812                 :            : 
     813                 :          0 :         bp->prev_tx_ring_stats_ext = rte_zmalloc("bnxt_prev_tx_ring_stats_ext",
     814                 :            :                                                  sizeof(struct bnxt_ring_stats_ext) *
     815                 :          0 :                                                  bp->tx_cp_nr_rings,
     816                 :            :                                                  0);
     817                 :            : 
     818   [ #  #  #  # ]:          0 :         if (bp->tx_cp_nr_rings > 0 && bp->prev_tx_ring_stats_ext == NULL)
     819                 :          0 :                 goto error;
     820                 :            : 
     821                 :            :         return 0;
     822                 :            : 
     823                 :            : error:
     824                 :          0 :         bnxt_free_prev_ring_stats(bp);
     825                 :          0 :         return -ENOMEM;
     826                 :            : }
     827                 :            : 
     828                 :          0 : static int bnxt_alloc_prev_ring_stats(struct bnxt *bp)
     829                 :            : {
     830   [ #  #  #  # ]:          0 :         if (BNXT_TPA_V2_P7(bp))
     831                 :          0 :                 return bnxt_alloc_prev_ring_ext_stats(bp);
     832                 :            : 
     833                 :          0 :         bp->prev_rx_ring_stats =  rte_zmalloc("bnxt_prev_rx_ring_stats",
     834                 :            :                                               sizeof(struct bnxt_ring_stats) *
     835                 :          0 :                                               bp->rx_cp_nr_rings,
     836                 :            :                                               0);
     837         [ #  # ]:          0 :         if (bp->prev_rx_ring_stats == NULL)
     838                 :            :                 return -ENOMEM;
     839                 :            : 
     840                 :          0 :         bp->prev_tx_ring_stats = rte_zmalloc("bnxt_prev_tx_ring_stats",
     841                 :            :                                              sizeof(struct bnxt_ring_stats) *
     842                 :          0 :                                              bp->tx_cp_nr_rings,
     843                 :            :                                              0);
     844   [ #  #  #  # ]:          0 :         if (bp->tx_cp_nr_rings > 0 && bp->prev_tx_ring_stats == NULL)
     845                 :          0 :                 goto error;
     846                 :            : 
     847                 :            :         return 0;
     848                 :            : 
     849                 :            : error:
     850                 :          0 :         bnxt_free_prev_ring_stats(bp);
     851                 :          0 :         return -ENOMEM;
     852                 :            : }
     853                 :            : 
     854                 :          0 : static int bnxt_start_nic(struct bnxt *bp)
     855                 :            : {
     856                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
     857                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     858                 :            :         uint32_t intr_vector = 0;
     859                 :            :         uint32_t queue_id, base = BNXT_MISC_VEC_ID;
     860                 :            :         uint32_t vec = BNXT_MISC_VEC_ID;
     861                 :            :         unsigned int i, j;
     862                 :            :         int rc;
     863                 :            : 
     864         [ #  # ]:          0 :         if (bp->eth_dev->data->mtu > RTE_ETHER_MTU)
     865                 :          0 :                 bp->flags |= BNXT_FLAG_JUMBO;
     866                 :            :         else
     867                 :          0 :                 bp->flags &= ~BNXT_FLAG_JUMBO;
     868                 :            : 
     869                 :            :         /* P5 does not support ring groups.
     870                 :            :          * But we will use the array to save RSS context IDs.
     871                 :            :          */
     872         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp))
     873                 :          0 :                 bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_P5;
     874                 :            : 
     875                 :          0 :         rc = bnxt_vnic_queue_db_init(bp);
     876         [ #  # ]:          0 :         if (rc) {
     877                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "could not allocate vnic db");
     878                 :          0 :                 goto err_out;
     879                 :            :         }
     880                 :            : 
     881                 :          0 :         rc = bnxt_alloc_hwrm_rings(bp);
     882         [ #  # ]:          0 :         if (rc) {
     883                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "HWRM ring alloc failure rc: %x", rc);
     884                 :          0 :                 goto err_out;
     885                 :            :         }
     886                 :            : 
     887                 :          0 :         rc = bnxt_alloc_all_hwrm_ring_grps(bp);
     888         [ #  # ]:          0 :         if (rc) {
     889                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "HWRM ring grp alloc failure: %x", rc);
     890                 :          0 :                 goto err_out;
     891                 :            :         }
     892                 :            : 
     893         [ #  # ]:          0 :         if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
     894                 :          0 :                 goto skip_cosq_cfg;
     895                 :            : 
     896         [ #  # ]:          0 :         for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
     897         [ #  # ]:          0 :                 if (bp->rx_cos_queue[i].id != 0xff) {
     898                 :          0 :                         struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
     899                 :            : 
     900         [ #  # ]:          0 :                         if (!vnic) {
     901                 :          0 :                                 PMD_DRV_LOG_LINE(ERR,
     902                 :            :                                             "Num pools more than FW profile");
     903                 :            :                                 rc = -EINVAL;
     904                 :          0 :                                 goto err_out;
     905                 :            :                         }
     906                 :          0 :                         vnic->cos_queue_id = bp->rx_cos_queue[i].id;
     907                 :          0 :                         bp->rx_cosq_cnt++;
     908                 :            :                 }
     909                 :            :         }
     910                 :            : 
     911                 :          0 : skip_cosq_cfg:
     912                 :          0 :         rc = bnxt_mq_rx_configure(bp);
     913         [ #  # ]:          0 :         if (rc) {
     914                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "MQ mode configure failure rc: %x", rc);
     915                 :          0 :                 goto err_out;
     916                 :            :         }
     917                 :            : 
     918         [ #  # ]:          0 :         for (j = 0; j < bp->rx_nr_rings; j++) {
     919                 :          0 :                 struct bnxt_rx_queue *rxq = bp->rx_queues[j];
     920                 :            : 
     921         [ #  # ]:          0 :                 if (!rxq->rx_deferred_start) {
     922         [ #  # ]:          0 :                         __rte_assume(j < RTE_MAX_QUEUES_PER_PORT);
     923                 :          0 :                         bp->eth_dev->data->rx_queue_state[j] =
     924                 :            :                                 RTE_ETH_QUEUE_STATE_STARTED;
     925                 :          0 :                         rxq->rx_started = true;
     926                 :            :                 }
     927                 :            :         }
     928                 :            : 
     929                 :            :         /* setup the default vnic details*/
     930                 :          0 :         bnxt_vnic_queue_db_update_dlft_vnic(bp);
     931                 :            : 
     932                 :            :         /* VNIC configuration */
     933         [ #  # ]:          0 :         for (i = 0; i < bp->nr_vnics; i++) {
     934                 :          0 :                 rc = bnxt_setup_one_vnic(bp, i);
     935         [ #  # ]:          0 :                 if (rc)
     936                 :          0 :                         goto err_out;
     937                 :            :         }
     938                 :            : 
     939         [ #  # ]:          0 :         for (j = 0; j < bp->tx_nr_rings; j++) {
     940                 :          0 :                 struct bnxt_tx_queue *txq = bp->tx_queues[j];
     941                 :            : 
     942         [ #  # ]:          0 :                 if (!txq->tx_deferred_start) {
     943         [ #  # ]:          0 :                         __rte_assume(j < RTE_MAX_QUEUES_PER_PORT);
     944                 :          0 :                         bp->eth_dev->data->tx_queue_state[j] =
     945                 :            :                                 RTE_ETH_QUEUE_STATE_STARTED;
     946                 :          0 :                         txq->tx_started = true;
     947                 :            :                 }
     948                 :            :         }
     949                 :            : 
     950                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
     951         [ #  # ]:          0 :         if (rc) {
     952                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
     953                 :            :                         "HWRM cfa l2 rx mask failure rc: %x", rc);
     954                 :          0 :                 goto err_out;
     955                 :            :         }
     956                 :            : 
     957                 :            :         /* check and configure queue intr-vector mapping */
     958         [ #  # ]:          0 :         if ((rte_intr_cap_multiple(intr_handle) ||
     959         [ #  # ]:          0 :              !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
     960         [ #  # ]:          0 :             bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
     961                 :          0 :                 intr_vector = bp->eth_dev->data->nb_rx_queues;
     962                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "intr_vector = %d", intr_vector);
     963         [ #  # ]:          0 :                 if (intr_vector > bp->rx_cp_nr_rings) {
     964                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "At most %d intr queues supported",
     965                 :            :                                         bp->rx_cp_nr_rings);
     966                 :          0 :                         return -ENOTSUP;
     967                 :            :                 }
     968                 :          0 :                 rc = rte_intr_efd_enable(intr_handle, intr_vector);
     969         [ #  # ]:          0 :                 if (rc)
     970                 :            :                         return rc;
     971                 :            :         }
     972                 :            : 
     973         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
     974         [ #  # ]:          0 :                 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
     975                 :          0 :                                         bp->eth_dev->data->nb_rx_queues)) {
     976                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to allocate %d rx_queues"
     977                 :            :                                 " intr_vec", bp->eth_dev->data->nb_rx_queues);
     978                 :            :                         rc = -ENOMEM;
     979                 :          0 :                         goto err_out;
     980                 :            :                 }
     981                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "intr_handle->nb_efd = %d "
     982                 :            :                             "intr_handle->max_intr = %d",
     983                 :            :                             rte_intr_nb_efd_get(intr_handle),
     984                 :            :                             rte_intr_max_intr_get(intr_handle));
     985         [ #  # ]:          0 :                 for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
     986                 :          0 :                      queue_id++) {
     987                 :          0 :                         rte_intr_vec_list_index_set(intr_handle,
     988                 :          0 :                                         queue_id, vec + BNXT_RX_VEC_START);
     989                 :          0 :                         if (vec < base + rte_intr_nb_efd_get(intr_handle)
     990         [ #  # ]:          0 :                             - 1)
     991                 :            :                                 vec++;
     992                 :            :                 }
     993                 :            :         }
     994                 :            : 
     995                 :            :         /* enable uio/vfio intr/eventfd mapping */
     996                 :          0 :         rc = rte_intr_enable(intr_handle);
     997                 :            : #ifndef RTE_EXEC_ENV_FREEBSD
     998                 :            :         /* In FreeBSD OS, nic_uio driver does not support interrupts */
     999         [ #  # ]:          0 :         if (rc)
    1000                 :          0 :                 goto err_out;
    1001                 :            : #endif
    1002                 :            : 
    1003                 :          0 :         rc = bnxt_update_phy_setting(bp);
    1004         [ #  # ]:          0 :         if (rc)
    1005                 :          0 :                 goto err_out;
    1006                 :            : 
    1007                 :          0 :         bp->mark_table = rte_zmalloc("bnxt_mark_table", BNXT_MARK_TABLE_SZ, 0);
    1008         [ #  # ]:          0 :         if (!bp->mark_table)
    1009                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Allocation of mark table failed");
    1010                 :            : 
    1011                 :            :         return 0;
    1012                 :            : 
    1013                 :          0 : err_out:
    1014                 :            :         /* Some of the error status returned by FW may not be from errno.h */
    1015         [ #  # ]:          0 :         if (rc > 0)
    1016                 :            :                 rc = -EIO;
    1017                 :            : 
    1018                 :            :         return rc;
    1019                 :            : }
    1020                 :            : 
    1021                 :          0 : static int bnxt_shutdown_nic(struct bnxt *bp)
    1022                 :            : {
    1023                 :          0 :         bnxt_free_all_hwrm_resources(bp);
    1024                 :          0 :         bnxt_free_all_filters(bp);
    1025                 :          0 :         bnxt_free_all_vnics(bp);
    1026                 :          0 :         bnxt_vnic_queue_db_deinit(bp);
    1027                 :          0 :         return 0;
    1028                 :            : }
    1029                 :            : 
    1030                 :            : /*
    1031                 :            :  * Device configuration and status function
    1032                 :            :  */
    1033                 :            : 
    1034                 :          0 : static uint32_t bnxt_get_speed_capabilities_v2(struct bnxt *bp)
    1035                 :            : {
    1036                 :            :         uint32_t link_speed = 0;
    1037                 :            :         uint32_t speed_capa = 0;
    1038                 :            : 
    1039         [ #  # ]:          0 :         if (bp->link_info == NULL)
    1040                 :            :                 return 0;
    1041                 :            : 
    1042                 :          0 :         link_speed = bp->link_info->support_speeds2;
    1043                 :            : 
    1044         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_1GB)
    1045                 :            :                 speed_capa |= RTE_ETH_LINK_SPEED_1G;
    1046         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_10GB)
    1047                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_10G;
    1048         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_25GB)
    1049                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_25G;
    1050         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_40GB)
    1051                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_40G;
    1052         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_50GB)
    1053                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_50G;
    1054         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB)
    1055                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100G;
    1056         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_50GB_PAM4_56)
    1057                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_50G;
    1058         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB_PAM4_56)
    1059                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100G;
    1060         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_200GB_PAM4_56)
    1061                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_200G;
    1062         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_400GB_PAM4_56)
    1063                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_400G;
    1064         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB_PAM4_112)
    1065                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100G;
    1066         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_200GB_PAM4_112)
    1067                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_200G;
    1068         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_400GB_PAM4_112)
    1069                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_400G;
    1070                 :            : 
    1071         [ #  # ]:          0 :         if (bp->link_info->auto_mode ==
    1072                 :            :             HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
    1073                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_FIXED;
    1074                 :            : 
    1075                 :            :         return speed_capa;
    1076                 :            : }
    1077                 :            : 
    1078                 :          0 : uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
    1079                 :            : {
    1080                 :            :         uint32_t pam4_link_speed = 0;
    1081                 :            :         uint32_t link_speed = 0;
    1082                 :            :         uint32_t speed_capa = 0;
    1083                 :            : 
    1084         [ #  # ]:          0 :         if (bp->link_info == NULL)
    1085                 :            :                 return 0;
    1086                 :            : 
    1087                 :            :         /* P7 uses speeds_v2 */
    1088   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp))
                   #  # ]
    1089                 :          0 :                 return bnxt_get_speed_capabilities_v2(bp);
    1090                 :            : 
    1091                 :          0 :         link_speed = bp->link_info->support_speeds;
    1092                 :            : 
    1093                 :            :         /* If PAM4 is configured, use PAM4 supported speed */
    1094                 :          0 :         if (bp->link_info->support_pam4_speeds > 0)
    1095                 :            :                 pam4_link_speed = bp->link_info->support_pam4_speeds;
    1096                 :            : 
    1097         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB)
    1098                 :            :                 speed_capa |= RTE_ETH_LINK_SPEED_100M;
    1099         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MBHD)
    1100                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100M_HD;
    1101         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
    1102                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_1G;
    1103         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
    1104                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_2_5G;
    1105         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
    1106                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_10G;
    1107         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
    1108                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_20G;
    1109         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
    1110                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_25G;
    1111         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
    1112                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_40G;
    1113         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
    1114                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_50G;
    1115         [ #  # ]:          0 :         if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
    1116                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100G;
    1117         [ #  # ]:          0 :         if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_50G)
    1118                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_50G;
    1119         [ #  # ]:          0 :         if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_100G)
    1120                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_100G;
    1121         [ #  # ]:          0 :         if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_200G)
    1122                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_200G;
    1123                 :            : 
    1124         [ #  # ]:          0 :         if (bp->link_info->auto_mode ==
    1125                 :            :             HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
    1126                 :          0 :                 speed_capa |= RTE_ETH_LINK_SPEED_FIXED;
    1127                 :            : 
    1128                 :            :         return speed_capa;
    1129                 :            : }
    1130                 :            : 
    1131                 :          0 : uint64_t bnxt_eth_rss_support(struct bnxt *bp)
    1132                 :            : {
    1133                 :            :         uint64_t support;
    1134                 :            : 
    1135                 :            :         support = RTE_ETH_RSS_IPV4 |
    1136                 :            :                   RTE_ETH_RSS_NONFRAG_IPV4_TCP |
    1137                 :            :                   RTE_ETH_RSS_NONFRAG_IPV4_UDP |
    1138                 :            :                   RTE_ETH_RSS_IPV6 |
    1139                 :            :                   RTE_ETH_RSS_NONFRAG_IPV6_TCP |
    1140                 :            :                   RTE_ETH_RSS_NONFRAG_IPV6_UDP |
    1141                 :            :                   RTE_ETH_RSS_LEVEL_MASK;
    1142                 :            : 
    1143         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_CHKSM_MODE)
    1144                 :            :                 support |= RTE_ETH_RSS_IPV4_CHKSUM |
    1145                 :            :                            RTE_ETH_RSS_L4_CHKSUM;
    1146         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE)
    1147                 :          0 :                 support |= RTE_ETH_RSS_IPV6_FLOW_LABEL;
    1148         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI_CAP)
    1149                 :          0 :                 support |= RTE_ETH_RSS_AH;
    1150         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI_CAP)
    1151                 :          0 :                 support |= RTE_ETH_RSS_ESP;
    1152                 :            : 
    1153                 :          0 :         return support;
    1154                 :            : }
    1155                 :            : 
    1156                 :          0 : static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
    1157                 :            :                                 struct rte_eth_dev_info *dev_info)
    1158                 :            : {
    1159                 :          0 :         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
    1160                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1161                 :            :         uint16_t max_vnics, i, j, vpool, vrxq;
    1162                 :            :         unsigned int max_rx_rings;
    1163                 :            :         int rc;
    1164                 :            : 
    1165                 :          0 :         rc = is_bnxt_in_error(bp);
    1166         [ #  # ]:          0 :         if (rc)
    1167                 :            :                 return rc;
    1168                 :            : 
    1169                 :            :         /* MAC Specifics */
    1170                 :          0 :         dev_info->max_mac_addrs = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
    1171                 :          0 :         dev_info->max_hash_mac_addrs = 0;
    1172                 :            : 
    1173                 :            :         /* PF/VF specifics */
    1174         [ #  # ]:          0 :         if (BNXT_PF(bp))
    1175                 :          0 :                 dev_info->max_vfs = pdev->max_vfs;
    1176                 :            : 
    1177                 :          0 :         max_rx_rings = bnxt_max_rings(bp);
    1178                 :            :         /* For the sake of symmetry, max_rx_queues = max_tx_queues */
    1179                 :          0 :         dev_info->max_rx_queues = max_rx_rings;
    1180                 :          0 :         dev_info->max_tx_queues = max_rx_rings;
    1181                 :          0 :         dev_info->reta_size = bnxt_rss_hash_tbl_size(bp);
    1182                 :          0 :         dev_info->hash_key_size = HW_HASH_KEY_SIZE;
    1183                 :          0 :         max_vnics = bp->max_vnics;
    1184                 :            : 
    1185                 :            :         /* MTU specifics */
    1186                 :          0 :         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
    1187                 :          0 :         dev_info->max_mtu = BNXT_MAX_MTU;
    1188                 :            : 
    1189                 :            :         /* Fast path specifics */
    1190                 :          0 :         dev_info->min_rx_bufsize = 1;
    1191                 :          0 :         dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
    1192                 :            : 
    1193                 :          0 :         dev_info->rx_offload_capa = bnxt_get_rx_port_offloads(bp);
    1194                 :          0 :         dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
    1195                 :          0 :         dev_info->tx_offload_capa = bnxt_get_tx_port_offloads(bp) |
    1196                 :          0 :                                     dev_info->tx_queue_offload_capa;
    1197                 :          0 :         dev_info->flow_type_rss_offloads = bnxt_eth_rss_support(bp);
    1198                 :          0 :         dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT) |
    1199                 :            :                                   RTE_ETH_HASH_ALGO_CAPA_MASK(TOEPLITZ);
    1200                 :            : 
    1201         [ #  # ]:          0 :         if (BNXT_CHIP_P7(bp))
    1202                 :          0 :                 dev_info->rss_algo_capa |= RTE_ETH_HASH_ALGO_CAPA_MASK(SIMPLE_XOR);
    1203                 :            : 
    1204                 :          0 :         dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
    1205                 :          0 :         dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
    1206                 :            :                              RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
    1207                 :            :         dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
    1208                 :            : 
    1209                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
    1210                 :            :                 .rx_thresh = {
    1211                 :            :                         .pthresh = 8,
    1212                 :            :                         .hthresh = 8,
    1213                 :            :                         .wthresh = 0,
    1214                 :            :                 },
    1215                 :            :                 .rx_free_thresh = 32,
    1216                 :            :                 .rx_drop_en = BNXT_DEFAULT_RX_DROP_EN,
    1217                 :            :         };
    1218                 :            : 
    1219                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
    1220                 :            :                 .tx_thresh = {
    1221                 :            :                         .pthresh = 32,
    1222                 :            :                         .hthresh = 0,
    1223                 :            :                         .wthresh = 0,
    1224                 :            :                 },
    1225                 :            :                 .tx_free_thresh = 32,
    1226                 :            :                 .tx_rs_thresh = 32,
    1227                 :            :         };
    1228                 :            : 
    1229                 :          0 :         dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
    1230                 :          0 :         dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
    1231                 :          0 :         dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
    1232                 :          0 :         dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
    1233                 :            : 
    1234         [ #  # ]:          0 :         if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
    1235                 :          0 :                 dev_info->switch_info.name = eth_dev->device->name;
    1236                 :          0 :                 dev_info->switch_info.domain_id = bp->switch_domain_id;
    1237         [ #  # ]:          0 :                 dev_info->switch_info.port_id =
    1238                 :            :                                 BNXT_PF(bp) ? BNXT_SWITCH_PORT_ID_PF :
    1239                 :            :                                     BNXT_SWITCH_PORT_ID_TRUSTED_VF;
    1240                 :            :         }
    1241                 :            : 
    1242                 :            :         /*
    1243                 :            :          * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
    1244                 :            :          *       need further investigation.
    1245                 :            :          */
    1246                 :            : 
    1247                 :            :         /* VMDq resources */
    1248                 :            :         vpool = 64; /* RTE_ETH_64_POOLS */
    1249                 :            :         vrxq = 128; /* RTE_ETH_VMDQ_DCB_NUM_QUEUES */
    1250         [ #  # ]:          0 :         for (i = 0; i < 4; vpool >>= 1, i++) {
    1251         [ #  # ]:          0 :                 if (max_vnics > vpool) {
    1252         [ #  # ]:          0 :                         for (j = 0; j < 5; vrxq >>= 1, j++) {
    1253         [ #  # ]:          0 :                                 if (dev_info->max_rx_queues > vrxq) {
    1254                 :            :                                         if (vpool > vrxq)
    1255                 :            :                                                 vpool = vrxq;
    1256                 :          0 :                                         goto found;
    1257                 :            :                                 }
    1258                 :            :                         }
    1259                 :            :                         /* Not enough resources to support VMDq */
    1260                 :            :                         break;
    1261                 :            :                 }
    1262                 :            :         }
    1263                 :            :         /* Not enough resources to support VMDq */
    1264                 :            :         vpool = 0;
    1265                 :            :         vrxq = 0;
    1266                 :          0 : found:
    1267                 :          0 :         dev_info->max_vmdq_pools = vpool;
    1268                 :          0 :         dev_info->vmdq_queue_num = vrxq;
    1269                 :            : 
    1270                 :          0 :         dev_info->vmdq_pool_base = 0;
    1271                 :          0 :         dev_info->vmdq_queue_base = 0;
    1272                 :            : 
    1273                 :          0 :         dev_info->rx_seg_capa.max_nseg = BNXT_MAX_BUFFER_SPLIT_SEGS;
    1274                 :          0 :         dev_info->rx_seg_capa.multi_pools = BNXT_MULTI_POOL_BUF_SPLIT_CAP;
    1275                 :          0 :         dev_info->rx_seg_capa.offset_allowed = BNXT_BUF_SPLIT_OFFSET_CAP;
    1276                 :          0 :         dev_info->rx_seg_capa.offset_align_log2 = BNXT_BUF_SPLIT_ALIGN_CAP;
    1277                 :            : 
    1278                 :          0 :         dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PROACTIVE;
    1279                 :            : 
    1280                 :          0 :         return 0;
    1281                 :            : }
    1282                 :            : 
    1283                 :            : /* Configure the device based on the configuration provided */
    1284                 :          0 : static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
    1285                 :            : {
    1286                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1287                 :          0 :         uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
    1288                 :            :         struct rte_eth_rss_conf *rss_conf = &eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
    1289                 :            :         int rc;
    1290                 :            : 
    1291                 :          0 :         bp->rx_queues = (void *)eth_dev->data->rx_queues;
    1292                 :          0 :         bp->tx_queues = (void *)eth_dev->data->tx_queues;
    1293                 :          0 :         bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
    1294                 :          0 :         bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
    1295                 :            : 
    1296                 :          0 :         rc = is_bnxt_in_error(bp);
    1297         [ #  # ]:          0 :         if (rc)
    1298                 :            :                 return rc;
    1299                 :            : 
    1300         [ #  # ]:          0 :         if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
    1301                 :          0 :                 rc = bnxt_hwrm_check_vf_rings(bp);
    1302         [ #  # ]:          0 :                 if (rc) {
    1303                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "HWRM insufficient resources");
    1304                 :          0 :                         return -ENOSPC;
    1305                 :            :                 }
    1306                 :            : 
    1307                 :            :                 /* If a resource has already been allocated - in this case
    1308                 :            :                  * it is the async completion ring, free it. Reallocate it after
    1309                 :            :                  * resource reservation. This will ensure the resource counts
    1310                 :            :                  * are calculated correctly.
    1311                 :            :                  */
    1312                 :            : 
    1313                 :          0 :                 pthread_mutex_lock(&bp->def_cp_lock);
    1314                 :            : 
    1315   [ #  #  #  # ]:          0 :                 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
    1316                 :          0 :                         bnxt_disable_int(bp);
    1317                 :          0 :                         bnxt_free_cp_ring(bp, bp->async_cp_ring);
    1318                 :            :                 }
    1319                 :            : 
    1320                 :          0 :                 rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
    1321         [ #  # ]:          0 :                 if (rc) {
    1322                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "HWRM resource alloc fail:%x", rc);
    1323                 :          0 :                         pthread_mutex_unlock(&bp->def_cp_lock);
    1324                 :          0 :                         return -ENOSPC;
    1325                 :            :                 }
    1326                 :            : 
    1327   [ #  #  #  # ]:          0 :                 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
    1328                 :          0 :                         rc = bnxt_alloc_async_cp_ring(bp);
    1329         [ #  # ]:          0 :                         if (rc) {
    1330                 :          0 :                                 pthread_mutex_unlock(&bp->def_cp_lock);
    1331                 :          0 :                                 return rc;
    1332                 :            :                         }
    1333                 :          0 :                         bnxt_enable_int(bp);
    1334                 :            :                 }
    1335                 :            : 
    1336                 :          0 :                 pthread_mutex_unlock(&bp->def_cp_lock);
    1337                 :            :         }
    1338                 :            : 
    1339                 :            :         /* Inherit new configurations */
    1340         [ #  # ]:          0 :         if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
    1341         [ #  # ]:          0 :             eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
    1342                 :          0 :             eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
    1343         [ #  # ]:          0 :                 + BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
    1344                 :            :             eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
    1345         [ #  # ]:          0 :             bp->max_stat_ctx)
    1346                 :          0 :                 goto resource_error;
    1347                 :            : 
    1348         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp) &&
    1349         [ #  # ]:          0 :             (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
    1350                 :          0 :                 goto resource_error;
    1351                 :            : 
    1352         [ #  # ]:          0 :         if (!(eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS) &&
    1353         [ #  # ]:          0 :             bp->max_vnics < eth_dev->data->nb_rx_queues)
    1354                 :          0 :                 goto resource_error;
    1355                 :            : 
    1356                 :          0 :         bp->rx_cp_nr_rings = bp->rx_nr_rings;
    1357                 :          0 :         bp->tx_cp_nr_rings = bp->tx_nr_rings;
    1358                 :            : 
    1359         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
    1360                 :          0 :                 rx_offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
    1361                 :          0 :         eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
    1362                 :            : 
    1363                 :            :         /* application provides the hash key to program */
    1364         [ #  # ]:          0 :         if (rss_conf->rss_key != NULL) {
    1365         [ #  # ]:          0 :                 if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE)
    1366                 :          0 :                         PMD_DRV_LOG_LINE(WARNING, "port %u RSS key len must be %d bytes long",
    1367                 :            :                                     eth_dev->data->port_id, HW_HASH_KEY_SIZE);
    1368                 :            :                 else
    1369                 :          0 :                         memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
    1370                 :            :         }
    1371                 :          0 :         bp->rss_conf.rss_key_len = HW_HASH_KEY_SIZE;
    1372                 :          0 :         bp->rss_conf.rss_hf = rss_conf->rss_hf;
    1373                 :            : 
    1374                 :          0 :         bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
    1375                 :            : 
    1376                 :          0 :         return 0;
    1377                 :            : 
    1378                 :          0 : resource_error:
    1379                 :          0 :         PMD_DRV_LOG_LINE(ERR,
    1380                 :            :                     "Insufficient resources to support requested config");
    1381                 :          0 :         PMD_DRV_LOG_LINE(ERR,
    1382                 :            :                     "Num Queues Requested: Tx %d, Rx %d",
    1383                 :            :                     eth_dev->data->nb_tx_queues,
    1384                 :            :                     eth_dev->data->nb_rx_queues);
    1385                 :          0 :         PMD_DRV_LOG_LINE(ERR,
    1386                 :            :                     "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d",
    1387                 :            :                     bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
    1388                 :            :                     bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
    1389                 :          0 :         return -ENOSPC;
    1390                 :            : }
    1391                 :            : 
    1392                 :          0 : void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
    1393                 :            : {
    1394                 :          0 :         struct rte_eth_link *link = &eth_dev->data->dev_link;
    1395                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1396                 :            : 
    1397         [ #  # ]:          0 :         if (link->link_status)
    1398         [ #  # ]:          0 :                 PMD_DRV_LOG_LINE(DEBUG, "Port %d Link Up - speed %u Mbps - %s Lanes - %d",
    1399                 :            :                         eth_dev->data->port_id,
    1400                 :            :                         (uint32_t)link->link_speed,
    1401                 :            :                         (link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
    1402                 :            :                         ("full-duplex") : ("half-duplex"),
    1403                 :            :                         (uint16_t)bp->link_info->active_lanes);
    1404                 :            :         else
    1405                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "Port %d Link Down", eth_dev->data->port_id);
    1406                 :          0 : }
    1407                 :            : 
    1408                 :            : /*
    1409                 :            :  * Determine whether the current configuration requires support for scattered
    1410                 :            :  * receive; return 1 if scattered receive is required and 0 if not.
    1411                 :            :  */
    1412                 :          0 : static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
    1413                 :            : {
    1414                 :            :         uint32_t overhead = BNXT_MAX_PKT_LEN - BNXT_MAX_MTU;
    1415                 :            :         uint16_t buf_size;
    1416                 :            :         int i;
    1417                 :            : 
    1418         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
    1419                 :            :                 return 1;
    1420                 :            : 
    1421         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)
    1422                 :            :                 return 1;
    1423                 :            : 
    1424         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
    1425                 :          0 :                 struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
    1426                 :            : 
    1427         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
    1428                 :            :                                       RTE_PKTMBUF_HEADROOM);
    1429         [ #  # ]:          0 :                 if (eth_dev->data->mtu + overhead > buf_size)
    1430                 :            :                         return 1;
    1431                 :            :         }
    1432                 :            :         return 0;
    1433                 :            : }
    1434                 :            : 
    1435                 :            : static eth_rx_burst_t
    1436                 :          0 : bnxt_receive_function(struct rte_eth_dev *eth_dev)
    1437                 :            : {
    1438                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1439                 :            : 
    1440                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
    1441                 :            :         /* Vector mode receive cannot be enabled if scattered rx is in use. */
    1442         [ #  # ]:          0 :         if (eth_dev->data->scattered_rx)
    1443                 :          0 :                 goto use_scalar_rx;
    1444                 :            : 
    1445                 :            :         /*
    1446                 :            :          * Vector mode receive cannot be enabled if Truflow is enabled or if
    1447                 :            :          * asynchronous completions and receive completions can be placed in
    1448                 :            :          * the same completion ring.
    1449                 :            :          */
    1450   [ #  #  #  #  :          0 :         if ((BNXT_TRUFLOW_EN(bp) && !BNXT_CHIP_P7(bp)) ||
                   #  # ]
    1451                 :            :             !BNXT_NUM_ASYNC_CPR(bp))
    1452                 :          0 :                 goto use_scalar_rx;
    1453                 :            : 
    1454                 :            :         /*
    1455                 :            :          * Vector mode receive cannot be enabled if any receive offloads outside
    1456                 :            :          * a limited subset have been enabled.
    1457                 :            :          */
    1458         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.rxmode.offloads &
    1459                 :            :                 ~(RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
    1460                 :            :                   RTE_ETH_RX_OFFLOAD_KEEP_CRC |
    1461                 :            :                   RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
    1462                 :            :                   RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
    1463                 :            :                   RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
    1464                 :            :                   RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
    1465                 :            :                   RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM |
    1466                 :            :                   RTE_ETH_RX_OFFLOAD_RSS_HASH |
    1467                 :            :                   RTE_ETH_RX_OFFLOAD_VLAN_FILTER))
    1468                 :          0 :                 goto use_scalar_rx;
    1469                 :            : 
    1470         [ #  # ]:          0 :         if (bp->ieee_1588)
    1471                 :          0 :                 goto use_scalar_rx;
    1472                 :            : 
    1473                 :            : #if defined(RTE_ARCH_X86)
    1474   [ #  #  #  # ]:          0 :         if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
    1475                 :          0 :             rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1) {
    1476                 :          0 :                 PMD_DRV_LOG_LINE(INFO,
    1477                 :            :                             "Using AVX2 vector mode receive for port %d",
    1478                 :            :                             eth_dev->data->port_id);
    1479                 :          0 :                 bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
    1480         [ #  # ]:          0 :                 if (bnxt_compressed_rx_cqe_mode_enabled(bp))
    1481                 :            :                         return bnxt_crx_pkts_vec_avx2;
    1482                 :          0 :                 return bnxt_recv_pkts_vec_avx2;
    1483                 :            :         }
    1484                 :            : #endif
    1485         [ #  # ]:          0 :         if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
    1486                 :          0 :                 PMD_DRV_LOG_LINE(INFO,
    1487                 :            :                             "Using SSE vector mode receive for port %d",
    1488                 :            :                             eth_dev->data->port_id);
    1489                 :          0 :                 bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
    1490         [ #  # ]:          0 :                 if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
    1491                 :            : #if defined(RTE_ARCH_ARM64)
    1492                 :            :                         goto use_scalar_rx;
    1493                 :            : #else
    1494                 :            :                         return bnxt_crx_pkts_vec;
    1495                 :            : #endif
    1496                 :            :                 }
    1497                 :          0 :                 return bnxt_recv_pkts_vec;
    1498                 :            :         }
    1499                 :            : 
    1500                 :          0 : use_scalar_rx:
    1501                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Vector mode receive disabled for port %d",
    1502                 :            :                     eth_dev->data->port_id);
    1503                 :          0 :         PMD_DRV_LOG_LINE(INFO,
    1504                 :            :                     "Port %d scatter: %d rx offload: %" PRIX64,
    1505                 :            :                     eth_dev->data->port_id,
    1506                 :            :                     eth_dev->data->scattered_rx,
    1507                 :            :                     eth_dev->data->dev_conf.rxmode.offloads);
    1508                 :            : #endif
    1509                 :          0 :         bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
    1510                 :          0 :         return bnxt_recv_pkts;
    1511                 :            : }
    1512                 :            : 
    1513                 :            : static eth_tx_burst_t
    1514                 :          0 : bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
    1515                 :            : {
    1516                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
    1517                 :          0 :         uint64_t offloads = eth_dev->data->dev_conf.txmode.offloads;
    1518                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1519                 :            : 
    1520                 :            :         /*
    1521                 :            :          * Vector mode transmit can be enabled only if not using scatter rx
    1522                 :            :          * or tx offloads.
    1523                 :            :          */
    1524         [ #  # ]:          0 :         if (eth_dev->data->scattered_rx ||
    1525         [ #  # ]:          0 :             (offloads & ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) ||
    1526   [ #  #  #  #  :          0 :             (BNXT_TRUFLOW_EN(bp) && !BNXT_CHIP_P7(bp)) ||
                   #  # ]
    1527         [ #  # ]:          0 :             bp->ieee_1588)
    1528                 :          0 :                 goto use_scalar_tx;
    1529                 :            : 
    1530                 :            : #if defined(RTE_ARCH_X86)
    1531   [ #  #  #  # ]:          0 :         if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
    1532                 :          0 :             rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1) {
    1533                 :          0 :                 PMD_DRV_LOG_LINE(INFO,
    1534                 :            :                             "Using AVX2 vector mode transmit for port %d",
    1535                 :            :                             eth_dev->data->port_id);
    1536                 :          0 :                 return bnxt_xmit_pkts_vec_avx2;
    1537                 :            :         }
    1538                 :            : #endif
    1539         [ #  # ]:          0 :         if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
    1540                 :          0 :                 PMD_DRV_LOG_LINE(INFO,
    1541                 :            :                             "Using SSE vector mode transmit for port %d",
    1542                 :            :                             eth_dev->data->port_id);
    1543                 :          0 :                 return bnxt_xmit_pkts_vec;
    1544                 :            :         }
    1545                 :            : 
    1546                 :          0 : use_scalar_tx:
    1547                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Vector mode transmit disabled for port %d",
    1548                 :            :                     eth_dev->data->port_id);
    1549                 :          0 :         PMD_DRV_LOG_LINE(INFO,
    1550                 :            :                     "Port %d scatter: %d tx offload: %" PRIX64,
    1551                 :            :                     eth_dev->data->port_id,
    1552                 :            :                     eth_dev->data->scattered_rx,
    1553                 :            :                     offloads);
    1554                 :            : #endif
    1555                 :          0 :         return bnxt_xmit_pkts;
    1556                 :            : }
    1557                 :            : 
    1558                 :          0 : static int bnxt_handle_if_change_status(struct bnxt *bp)
    1559                 :            : {
    1560                 :            :         int rc;
    1561                 :            : 
    1562                 :            :         /* Since fw has undergone a reset and lost all contexts,
    1563                 :            :          * set fatal flag to not issue hwrm during cleanup
    1564                 :            :          */
    1565                 :          0 :         bp->flags |= BNXT_FLAG_FATAL_ERROR;
    1566                 :          0 :         bnxt_uninit_resources(bp, true);
    1567                 :            : 
    1568                 :            :         /* clear fatal flag so that re-init happens */
    1569                 :          0 :         bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
    1570                 :            : 
    1571                 :          0 :         rc = bnxt_check_fw_ready(bp);
    1572         [ #  # ]:          0 :         if (rc)
    1573                 :            :                 return rc;
    1574                 :            : 
    1575                 :          0 :         rc = bnxt_init_resources(bp, true);
    1576                 :            : 
    1577                 :          0 :         bp->flags &= ~BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
    1578                 :            : 
    1579                 :          0 :         return rc;
    1580                 :            : }
    1581                 :            : 
    1582                 :          0 : static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
    1583                 :            : {
    1584                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1585                 :            :         int rc = 0;
    1586                 :            : 
    1587         [ #  # ]:          0 :         if (!BNXT_SINGLE_PF(bp))
    1588                 :            :                 return -ENOTSUP;
    1589                 :            : 
    1590         [ #  # ]:          0 :         if (!bp->link_info->link_up)
    1591                 :          0 :                 rc = bnxt_set_hwrm_link_config(bp, true);
    1592         [ #  # ]:          0 :         if (!rc)
    1593                 :          0 :                 eth_dev->data->dev_link.link_status = 1;
    1594                 :            : 
    1595                 :          0 :         bnxt_print_link_info(eth_dev);
    1596                 :          0 :         return rc;
    1597                 :            : }
    1598                 :            : 
    1599                 :          0 : static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
    1600                 :            : {
    1601                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1602                 :            : 
    1603         [ #  # ]:          0 :         if (!BNXT_SINGLE_PF(bp))
    1604                 :            :                 return -ENOTSUP;
    1605                 :            : 
    1606                 :          0 :         eth_dev->data->dev_link.link_status = 0;
    1607                 :          0 :         bnxt_set_hwrm_link_config(bp, false);
    1608                 :          0 :         bp->link_info->link_up = 0;
    1609                 :            : 
    1610                 :          0 :         return 0;
    1611                 :            : }
    1612                 :            : 
    1613                 :          0 : static void bnxt_free_switch_domain(struct bnxt *bp)
    1614                 :            : {
    1615                 :            :         int rc = 0;
    1616                 :            : 
    1617         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)))
    1618                 :            :                 return;
    1619                 :            : 
    1620                 :          0 :         rc = rte_eth_switch_domain_free(bp->switch_domain_id);
    1621         [ #  # ]:          0 :         if (rc)
    1622                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "free switch domain:%d fail: %d",
    1623                 :            :                             bp->switch_domain_id, rc);
    1624                 :            : }
    1625                 :            : 
    1626                 :          0 : static void bnxt_ptp_get_current_time(void *arg)
    1627                 :            : {
    1628                 :            :         struct bnxt *bp = arg;
    1629                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    1630                 :            :         int rc;
    1631                 :            : 
    1632                 :          0 :         rc = is_bnxt_in_error(bp);
    1633         [ #  # ]:          0 :         if (rc)
    1634                 :            :                 return;
    1635                 :            : 
    1636         [ #  # ]:          0 :         if (!ptp)
    1637                 :            :                 return;
    1638                 :            : 
    1639                 :          0 :         rte_spinlock_lock(&ptp->ptp_lock);
    1640                 :          0 :         ptp->old_time = ptp->current_time;
    1641                 :          0 :         bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
    1642                 :            :                                 &ptp->current_time);
    1643                 :            :         rte_spinlock_unlock(&ptp->ptp_lock);
    1644                 :          0 :         rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
    1645         [ #  # ]:          0 :         if (rc != 0) {
    1646                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to re-schedule PTP alarm");
    1647                 :          0 :                 bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
    1648                 :            :         }
    1649                 :            : }
    1650                 :            : 
    1651                 :          0 : static int bnxt_schedule_ptp_alarm(struct bnxt *bp)
    1652                 :            : {
    1653                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    1654                 :            :         int rc;
    1655                 :            : 
    1656         [ #  # ]:          0 :         if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED)
    1657                 :            :                 return 0;
    1658                 :            : 
    1659                 :          0 :         rte_spinlock_lock(&ptp->ptp_lock);
    1660                 :          0 :         bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
    1661                 :            :                                 &ptp->current_time);
    1662                 :          0 :         ptp->old_time = ptp->current_time;
    1663                 :            :         rte_spinlock_unlock(&ptp->ptp_lock);
    1664                 :            : 
    1665                 :            : 
    1666                 :          0 :         rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
    1667                 :          0 :         return rc;
    1668                 :            : }
    1669                 :            : 
    1670                 :            : static void bnxt_cancel_ptp_alarm(struct bnxt *bp)
    1671                 :            : {
    1672         [ #  # ]:          0 :         if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED) {
    1673                 :          0 :                 rte_eal_alarm_cancel(bnxt_ptp_get_current_time, (void *)bp);
    1674                 :          0 :                 bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
    1675                 :            :         }
    1676                 :            : }
    1677                 :            : 
    1678         [ #  # ]:          0 : static void bnxt_ptp_stop(struct bnxt *bp)
    1679                 :            : {
    1680                 :            :         bnxt_cancel_ptp_alarm(bp);
    1681                 :          0 :         bp->flags2 &= ~BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
    1682                 :          0 : }
    1683                 :            : 
    1684                 :          0 : static int bnxt_ptp_start(struct bnxt *bp)
    1685                 :            : {
    1686                 :            :         int rc;
    1687                 :            : 
    1688                 :          0 :         rc = bnxt_schedule_ptp_alarm(bp);
    1689         [ #  # ]:          0 :         if (rc != 0) {
    1690                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to schedule PTP alarm");
    1691                 :            :         } else {
    1692                 :          0 :                 bp->flags2 |= BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
    1693                 :          0 :                 bp->flags2 |= BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
    1694                 :            :         }
    1695                 :            : 
    1696                 :          0 :         return rc;
    1697                 :            : }
    1698                 :            : 
    1699                 :          0 : static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
    1700                 :            : {
    1701                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1702                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    1703                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1704                 :            :         struct rte_eth_link link;
    1705                 :            :         uint16_t i;
    1706                 :            :         int ret;
    1707                 :            : 
    1708                 :          0 :         eth_dev->data->dev_started = 0;
    1709                 :            : 
    1710                 :            :         /* Prevent crashes when queues are still in use */
    1711                 :          0 :         bnxt_stop_rxtx(eth_dev);
    1712                 :            : 
    1713                 :          0 :         bnxt_disable_int(bp);
    1714                 :            : 
    1715                 :            :         /* disable uio/vfio intr/eventfd mapping */
    1716                 :          0 :         rte_intr_disable(intr_handle);
    1717                 :            : 
    1718                 :            :         /* Stop the child representors for this device */
    1719                 :          0 :         ret = bnxt_rep_stop_all(bp);
    1720         [ #  # ]:          0 :         if (ret != 0)
    1721                 :            :                 return ret;
    1722                 :            : 
    1723                 :            :         /* delete the bnxt ULP port details */
    1724                 :            :         if (bnxt_enable_ulp(bp))
    1725                 :          0 :                 bnxt_ulp_port_deinit(bp);
    1726                 :            : 
    1727                 :            :         bnxt_cancel_fw_health_check(bp);
    1728                 :            : 
    1729                 :          0 :         if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
    1730                 :            :                 bnxt_cancel_ptp_alarm(bp);
    1731                 :            : 
    1732                 :            :         /* Do not bring link down during reset recovery */
    1733         [ #  # ]:          0 :         if (!is_bnxt_in_error(bp)) {
    1734                 :          0 :                 bnxt_dev_set_link_down_op(eth_dev);
    1735                 :            :                 /* Wait for link to be reset */
    1736         [ #  # ]:          0 :                 if (BNXT_SINGLE_PF(bp))
    1737                 :            :                         rte_delay_ms(500);
    1738                 :            :                 /* clear the recorded link status */
    1739                 :            :                 memset(&link, 0, sizeof(link));
    1740                 :          0 :                 rte_eth_linkstatus_set(eth_dev, &link);
    1741                 :            :         }
    1742                 :            : 
    1743                 :            :         /* Clean queue intr-vector mapping */
    1744                 :          0 :         rte_intr_efd_disable(intr_handle);
    1745                 :          0 :         rte_intr_vec_list_free(intr_handle);
    1746                 :            : 
    1747                 :          0 :         bnxt_hwrm_port_clr_stats(bp);
    1748                 :          0 :         bnxt_free_tx_mbufs(bp);
    1749                 :          0 :         bnxt_free_rx_mbufs(bp);
    1750                 :            :         /* Process any remaining notifications in default completion queue */
    1751                 :          0 :         bnxt_int_handler(eth_dev);
    1752                 :            : 
    1753         [ #  # ]:          0 :         if (mpc != 0)
    1754                 :          0 :                 bnxt_mpc_close(bp);
    1755                 :            : 
    1756                 :          0 :         bnxt_shutdown_nic(bp);
    1757                 :          0 :         bnxt_hwrm_if_change(bp, false);
    1758                 :            : 
    1759                 :          0 :         bnxt_free_prev_ring_stats(bp);
    1760                 :          0 :         rte_free(bp->mark_table);
    1761                 :          0 :         bp->mark_table = NULL;
    1762                 :            : 
    1763                 :          0 :         bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
    1764                 :          0 :         bp->rx_cosq_cnt = 0;
    1765                 :            :         /* All filters are deleted on a port stop. */
    1766         [ #  # ]:          0 :         if (BNXT_FLOW_XSTATS_EN(bp))
    1767                 :          0 :                 bp->flow_stat->flow_count = 0;
    1768                 :            : 
    1769                 :          0 :         eth_dev->data->scattered_rx = 0;
    1770                 :            : 
    1771         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
    1772                 :          0 :                 eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1773         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
    1774                 :          0 :                 eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1775                 :            : 
    1776                 :            :         return 0;
    1777                 :            : }
    1778                 :            : 
    1779                 :            : /* Unload the driver, release resources */
    1780                 :          0 : int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
    1781                 :            : {
    1782                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1783                 :            : 
    1784                 :          0 :         pthread_mutex_lock(&bp->err_recovery_lock);
    1785         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_RESET) {
    1786                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    1787                 :            :                             "Adapter recovering from error..Please retry");
    1788                 :          0 :                 pthread_mutex_unlock(&bp->err_recovery_lock);
    1789                 :          0 :                 return -EAGAIN;
    1790                 :            :         }
    1791                 :          0 :         pthread_mutex_unlock(&bp->err_recovery_lock);
    1792                 :            : 
    1793                 :          0 :         return bnxt_dev_stop(eth_dev);
    1794                 :            : }
    1795                 :            : 
    1796                 :          0 : int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
    1797                 :            : {
    1798                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1799                 :          0 :         uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
    1800                 :            :         int vlan_mask = 0;
    1801                 :            :         int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
    1802                 :            : 
    1803         [ #  # ]:          0 :         if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS)
    1804                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    1805                 :            :                             "RxQ cnt %d > RTE_ETHDEV_QUEUE_STAT_CNTRS %d",
    1806                 :            :                             bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
    1807                 :            : 
    1808                 :            :         do {
    1809                 :          0 :                 rc = bnxt_hwrm_if_change(bp, true);
    1810         [ #  # ]:          0 :                 if (rc == 0 || rc != -EAGAIN)
    1811                 :            :                         break;
    1812                 :            : 
    1813                 :            :                 rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
    1814         [ #  # ]:          0 :         } while (retry_cnt--);
    1815                 :            : 
    1816         [ #  # ]:          0 :         if (rc)
    1817                 :            :                 return rc;
    1818                 :            : 
    1819         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
    1820                 :          0 :                 rc = bnxt_handle_if_change_status(bp);
    1821         [ #  # ]:          0 :                 if (rc)
    1822                 :            :                         return rc;
    1823                 :            :         }
    1824                 :            : 
    1825                 :          0 :         bnxt_enable_int(bp);
    1826                 :            : 
    1827                 :          0 :         eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
    1828                 :            : 
    1829                 :          0 :         rc = bnxt_start_nic(bp);
    1830         [ #  # ]:          0 :         if (rc)
    1831                 :          0 :                 goto error;
    1832                 :            : 
    1833         [ #  # ]:          0 :         if (mpc != 0) {
    1834                 :          0 :                 rc = bnxt_mpc_open(bp);
    1835         [ #  # ]:          0 :                 if (rc != 0)
    1836                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG, "MPC open failed");
    1837                 :            :         }
    1838                 :            : 
    1839                 :          0 :         rc = bnxt_alloc_prev_ring_stats(bp);
    1840         [ #  # ]:          0 :         if (rc)
    1841                 :          0 :                 goto error;
    1842                 :            : 
    1843                 :          0 :         eth_dev->data->dev_started = 1;
    1844                 :            : 
    1845                 :          0 :         bnxt_link_update_op(eth_dev, 0);
    1846                 :            : 
    1847         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
    1848                 :            :                 vlan_mask |= RTE_ETH_VLAN_FILTER_MASK;
    1849         [ #  # ]:          0 :         if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    1850                 :          0 :                 vlan_mask |= RTE_ETH_VLAN_STRIP_MASK;
    1851                 :          0 :         rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
    1852         [ #  # ]:          0 :         if (rc)
    1853                 :          0 :                 goto error;
    1854                 :            : 
    1855                 :            :         /* Initialize bnxt ULP port details */
    1856                 :            :         if (bnxt_enable_ulp(bp)) {
    1857         [ #  # ]:          0 :                 if (BNXT_CHIP_P7(bp)) {
    1858                 :            :                         /* Need to release the Fid from AFM control */
    1859                 :          0 :                         rc = bnxt_hwrm_release_afm_func(bp, bp->fw_fid,
    1860                 :          0 :                                                         bp->fw_fid,
    1861                 :            :                                                         HWRM_CFA_RELEASE_AFM_FUNC_INPUT_TYPE_RFID,
    1862                 :            :                                                         0);
    1863         [ #  # ]:          0 :                         if (rc) {
    1864                 :          0 :                                 PMD_DRV_LOG_LINE(ERR,
    1865                 :            :                                                  "Failed in hwrm release afm func:%u rc=%d",
    1866                 :            :                                                  bp->fw_fid, rc);
    1867                 :          0 :                                 goto error;
    1868                 :            :                         }
    1869                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG, "Released RFID:%d", bp->fw_fid);
    1870                 :            :                 }
    1871                 :            : 
    1872                 :          0 :                 rc = bnxt_ulp_port_init(bp);
    1873         [ #  # ]:          0 :                 if (rc)
    1874                 :          0 :                         goto error;
    1875                 :            :         }
    1876                 :            : 
    1877                 :          0 :         eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
    1878                 :          0 :         eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
    1879                 :            : 
    1880                 :          0 :         bnxt_schedule_fw_health_check(bp);
    1881                 :            : 
    1882         [ #  # ]:          0 :         if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
    1883                 :          0 :                 bnxt_schedule_ptp_alarm(bp);
    1884                 :            : 
    1885                 :            :         return 0;
    1886                 :            : 
    1887                 :          0 : error:
    1888                 :          0 :         bnxt_dev_stop(eth_dev);
    1889                 :          0 :         return rc;
    1890                 :            : }
    1891                 :            : 
    1892                 :            : static void
    1893                 :          0 : bnxt_uninit_locks(struct bnxt *bp)
    1894                 :            : {
    1895                 :          0 :         pthread_mutex_destroy(&bp->flow_lock);
    1896                 :          0 :         pthread_mutex_destroy(&bp->def_cp_lock);
    1897                 :          0 :         pthread_mutex_destroy(&bp->health_check_lock);
    1898                 :          0 :         pthread_mutex_destroy(&bp->err_recovery_lock);
    1899         [ #  # ]:          0 :         if (bp->rep_info)
    1900                 :          0 :                 pthread_mutex_destroy(&bp->rep_info->vfr_start_lock);
    1901                 :          0 : }
    1902                 :            : 
    1903         [ #  # ]:          0 : static void bnxt_drv_uninit(struct bnxt *bp)
    1904                 :            : {
    1905                 :            :         bnxt_free_leds_info(bp);
    1906                 :            :         bnxt_free_cos_queues(bp);
    1907                 :            :         bnxt_free_link_info(bp);
    1908                 :            :         bnxt_free_parent_info(bp);
    1909                 :          0 :         bnxt_uninit_locks(bp);
    1910                 :            :         bnxt_free_rep_info(bp);
    1911                 :            : 
    1912                 :          0 :         rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
    1913                 :          0 :         bp->tx_mem_zone = NULL;
    1914                 :          0 :         rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
    1915                 :          0 :         bp->rx_mem_zone = NULL;
    1916                 :            : 
    1917                 :          0 :         bnxt_free_vf_info(bp);
    1918                 :            :         bnxt_free_pf_info(bp);
    1919                 :            : 
    1920                 :          0 :         rte_free(bp->grp_info);
    1921                 :          0 :         bp->grp_info = NULL;
    1922                 :          0 : }
    1923                 :            : 
    1924                 :          0 : static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
    1925                 :            : {
    1926                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1927                 :            :         int ret = 0;
    1928                 :            : 
    1929         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1930                 :            :                 return 0;
    1931                 :            : 
    1932                 :          0 :         pthread_mutex_lock(&bp->err_recovery_lock);
    1933         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_RESET) {
    1934                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    1935                 :            :                             "Adapter recovering from error...Please retry");
    1936                 :          0 :                 pthread_mutex_unlock(&bp->err_recovery_lock);
    1937                 :          0 :                 return -EAGAIN;
    1938                 :            :         }
    1939                 :          0 :         pthread_mutex_unlock(&bp->err_recovery_lock);
    1940                 :            : 
    1941                 :            :         /* cancel the recovery handler before remove dev */
    1942                 :          0 :         rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
    1943                 :          0 :         rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
    1944                 :          0 :         bnxt_cancel_fc_thread(bp);
    1945                 :          0 :         rte_eal_alarm_cancel(bnxt_handle_vf_cfg_change, (void *)bp);
    1946                 :            : 
    1947         [ #  # ]:          0 :         if (eth_dev->data->dev_started)
    1948                 :          0 :                 ret = bnxt_dev_stop(eth_dev);
    1949                 :            : 
    1950                 :          0 :         bnxt_uninit_resources(bp, false);
    1951                 :            : 
    1952                 :          0 :         bnxt_drv_uninit(bp);
    1953                 :            : 
    1954                 :          0 :         return ret;
    1955                 :            : }
    1956                 :            : 
    1957                 :          0 : static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
    1958                 :            :                                     uint32_t index)
    1959                 :            : {
    1960                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    1961                 :          0 :         uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
    1962                 :            :         struct bnxt_vnic_info *vnic;
    1963                 :            :         struct bnxt_filter_info *filter, *temp_filter;
    1964                 :            :         uint32_t i;
    1965                 :            : 
    1966         [ #  # ]:          0 :         if (is_bnxt_in_error(bp))
    1967                 :            :                 return;
    1968                 :            : 
    1969                 :            :         /*
    1970                 :            :          * Loop through all VNICs from the specified filter flow pools to
    1971                 :            :          * remove the corresponding MAC addr filter
    1972                 :            :          */
    1973         [ #  # ]:          0 :         for (i = 0; i < bp->nr_vnics; i++) {
    1974         [ #  # ]:          0 :                 if (!(pool_mask & (1ULL << i)))
    1975                 :          0 :                         continue;
    1976                 :            : 
    1977                 :          0 :                 vnic = &bp->vnic_info[i];
    1978                 :          0 :                 filter = STAILQ_FIRST(&vnic->filter);
    1979         [ #  # ]:          0 :                 while (filter) {
    1980                 :          0 :                         temp_filter = STAILQ_NEXT(filter, next);
    1981         [ #  # ]:          0 :                         if (filter->mac_index == index) {
    1982   [ #  #  #  #  :          0 :                                 STAILQ_REMOVE(&vnic->filter, filter,
             #  #  #  # ]
    1983                 :            :                                                 bnxt_filter_info, next);
    1984                 :          0 :                                 bnxt_hwrm_clear_l2_filter(bp, filter);
    1985                 :          0 :                                 bnxt_free_filter(bp, filter);
    1986                 :            :                         }
    1987                 :            :                         filter = temp_filter;
    1988                 :            :                 }
    1989                 :            :         }
    1990                 :            : }
    1991                 :            : 
    1992                 :          0 : static int bnxt_add_mac_filter(struct bnxt *bp, struct bnxt_vnic_info *vnic,
    1993                 :            :                                struct rte_ether_addr *mac_addr, uint32_t index,
    1994                 :            :                                uint32_t pool)
    1995                 :            : {
    1996                 :            :         struct bnxt_filter_info *filter;
    1997                 :            :         int rc = 0;
    1998                 :            : 
    1999                 :            :         /* Attach requested MAC address to the new l2_filter */
    2000         [ #  # ]:          0 :         STAILQ_FOREACH(filter, &vnic->filter, next) {
    2001         [ #  # ]:          0 :                 if (filter->mac_index == index) {
    2002                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG,
    2003                 :            :                                     "MAC addr already existed for pool %d",
    2004                 :            :                                     pool);
    2005                 :          0 :                         return 0;
    2006                 :            :                 }
    2007                 :            :         }
    2008                 :            : 
    2009                 :          0 :         filter = bnxt_alloc_filter(bp);
    2010         [ #  # ]:          0 :         if (!filter) {
    2011                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "L2 filter alloc failed");
    2012                 :          0 :                 return -ENODEV;
    2013                 :            :         }
    2014                 :            : 
    2015                 :            :         /* bnxt_alloc_filter copies default MAC to filter->l2_addr. So,
    2016                 :            :          * if the MAC that's been programmed now is a different one, then,
    2017                 :            :          * copy that addr to filter->l2_addr
    2018                 :            :          */
    2019         [ #  # ]:          0 :         if (mac_addr)
    2020                 :          0 :                 memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
    2021                 :          0 :         filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
    2022                 :            : 
    2023                 :          0 :         rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
    2024         [ #  # ]:          0 :         if (!rc) {
    2025                 :          0 :                 filter->mac_index = index;
    2026         [ #  # ]:          0 :                 if (filter->mac_index == 0)
    2027         [ #  # ]:          0 :                         STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
    2028                 :            :                 else
    2029                 :          0 :                         STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
    2030                 :            :         } else {
    2031                 :          0 :                 bnxt_free_filter(bp, filter);
    2032                 :            :         }
    2033                 :            : 
    2034                 :            :         return rc;
    2035                 :            : }
    2036                 :            : 
    2037                 :          0 : static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
    2038                 :            :                                 struct rte_ether_addr *mac_addr,
    2039                 :            :                                 uint32_t index, uint32_t pool)
    2040                 :            : {
    2041                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2042                 :          0 :         struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
    2043                 :            :         int rc = 0;
    2044                 :            : 
    2045                 :          0 :         rc = is_bnxt_in_error(bp);
    2046         [ #  # ]:          0 :         if (rc)
    2047                 :            :                 return rc;
    2048                 :            : 
    2049         [ #  # ]:          0 :         if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
    2050                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Cannot add MAC address to a VF interface");
    2051                 :          0 :                 return -ENOTSUP;
    2052                 :            :         }
    2053                 :            : 
    2054         [ #  # ]:          0 :         if (!vnic) {
    2055                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "VNIC not found for pool %d!", pool);
    2056                 :          0 :                 return -EINVAL;
    2057                 :            :         }
    2058                 :            : 
    2059                 :            :         /* Filter settings will get applied when port is started */
    2060         [ #  # ]:          0 :         if (!eth_dev->data->dev_started)
    2061                 :            :                 return 0;
    2062                 :            : 
    2063                 :          0 :         rc = bnxt_add_mac_filter(bp, vnic, mac_addr, index, pool);
    2064                 :            : 
    2065                 :          0 :         return rc;
    2066                 :            : }
    2067                 :            : 
    2068                 :          0 : int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
    2069                 :            : {
    2070                 :            :         int rc = 0;
    2071                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2072                 :            :         struct rte_eth_link new;
    2073         [ #  # ]:          0 :         int cnt = wait_to_complete ? BNXT_MAX_LINK_WAIT_CNT :
    2074                 :            :                         BNXT_MIN_LINK_WAIT_CNT;
    2075                 :            : 
    2076                 :          0 :         rc = is_bnxt_in_error(bp);
    2077         [ #  # ]:          0 :         if (rc)
    2078                 :            :                 return rc;
    2079                 :            : 
    2080                 :            :         memset(&new, 0, sizeof(new));
    2081                 :            : 
    2082         [ #  # ]:          0 :         if (bp->link_info == NULL)
    2083                 :          0 :                 goto out;
    2084                 :            : 
    2085                 :            :         /* Only single function PF can bring the phy down.
    2086                 :            :          * In certain scenarios, device is not obliged link down even when forced.
    2087                 :            :          * When port is stopped, report link down in those cases.
    2088                 :            :          */
    2089         [ #  # ]:          0 :         if (!eth_dev->data->dev_started &&
    2090         [ #  # ]:          0 :             (!BNXT_SINGLE_PF(bp) || bnxt_force_link_config(bp)))
    2091                 :          0 :                 goto out;
    2092                 :            : 
    2093                 :            :         do {
    2094                 :            :                 /* Retrieve link info from hardware */
    2095                 :          0 :                 rc = bnxt_get_hwrm_link_config(bp, &new);
    2096         [ #  # ]:          0 :                 if (rc) {
    2097                 :          0 :                         new.link_speed = RTE_ETH_LINK_SPEED_100M;
    2098                 :          0 :                         new.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    2099                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
    2100                 :            :                                 "Failed to retrieve link rc = 0x%x!", rc);
    2101                 :          0 :                         goto out;
    2102                 :            :                 }
    2103                 :            : 
    2104   [ #  #  #  # ]:          0 :                 if (!wait_to_complete || new.link_status)
    2105                 :            :                         break;
    2106                 :            : 
    2107                 :            :                 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
    2108         [ #  # ]:          0 :         } while (cnt--);
    2109                 :            : 
    2110                 :          0 : out:
    2111                 :            :         /* Timed out or success */
    2112         [ #  # ]:          0 :         if (new.link_status != eth_dev->data->dev_link.link_status ||
    2113                 :            :             new.link_speed != eth_dev->data->dev_link.link_speed) {
    2114                 :          0 :                 rte_eth_linkstatus_set(eth_dev, &new);
    2115                 :          0 :                 bnxt_print_link_info(eth_dev);
    2116                 :            :         }
    2117                 :            : 
    2118                 :            :         return rc;
    2119                 :            : }
    2120                 :            : 
    2121                 :          0 : static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
    2122                 :            : {
    2123                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2124                 :            :         struct bnxt_vnic_info *vnic;
    2125                 :            :         uint32_t old_flags;
    2126                 :            :         int rc;
    2127                 :            : 
    2128                 :          0 :         rc = is_bnxt_in_error(bp);
    2129         [ #  # ]:          0 :         if (rc)
    2130                 :            :                 return rc;
    2131                 :            : 
    2132                 :            :         /* Filter settings will get applied when port is started */
    2133         [ #  # ]:          0 :         if (!eth_dev->data->dev_started)
    2134                 :            :                 return 0;
    2135                 :            : 
    2136         [ #  # ]:          0 :         if (bp->vnic_info == NULL)
    2137                 :            :                 return 0;
    2138                 :            : 
    2139                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2140                 :            : 
    2141                 :          0 :         old_flags = vnic->flags;
    2142                 :          0 :         vnic->flags |= BNXT_VNIC_INFO_PROMISC;
    2143                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    2144         [ #  # ]:          0 :         if (rc != 0)
    2145                 :          0 :                 vnic->flags = old_flags;
    2146                 :            : 
    2147                 :            :         return rc;
    2148                 :            : }
    2149                 :            : 
    2150                 :          0 : static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
    2151                 :            : {
    2152                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2153                 :            :         struct bnxt_vnic_info *vnic;
    2154                 :            :         uint32_t old_flags;
    2155                 :            :         int rc;
    2156                 :            : 
    2157                 :          0 :         rc = is_bnxt_in_error(bp);
    2158         [ #  # ]:          0 :         if (rc)
    2159                 :            :                 return rc;
    2160                 :            : 
    2161                 :            :         /* Filter settings will get applied when port is started */
    2162         [ #  # ]:          0 :         if (!eth_dev->data->dev_started)
    2163                 :            :                 return 0;
    2164                 :            : 
    2165         [ #  # ]:          0 :         if (bp->vnic_info == NULL)
    2166                 :            :                 return 0;
    2167                 :            : 
    2168                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2169                 :            : 
    2170                 :          0 :         old_flags = vnic->flags;
    2171                 :          0 :         vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
    2172                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    2173         [ #  # ]:          0 :         if (rc != 0)
    2174                 :          0 :                 vnic->flags = old_flags;
    2175                 :            : 
    2176                 :            :         return rc;
    2177                 :            : }
    2178                 :            : 
    2179                 :          0 : static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
    2180                 :            : {
    2181                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2182                 :            :         struct bnxt_vnic_info *vnic;
    2183                 :            :         uint32_t old_flags;
    2184                 :            :         int rc;
    2185                 :            : 
    2186                 :          0 :         rc = is_bnxt_in_error(bp);
    2187         [ #  # ]:          0 :         if (rc)
    2188                 :            :                 return rc;
    2189                 :            : 
    2190                 :            :         /* Filter settings will get applied when port is started */
    2191         [ #  # ]:          0 :         if (!eth_dev->data->dev_started)
    2192                 :            :                 return 0;
    2193                 :            : 
    2194         [ #  # ]:          0 :         if (bp->vnic_info == NULL)
    2195                 :            :                 return 0;
    2196                 :            : 
    2197                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2198                 :            : 
    2199                 :          0 :         old_flags = vnic->flags;
    2200                 :          0 :         vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
    2201                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    2202         [ #  # ]:          0 :         if (rc != 0)
    2203                 :          0 :                 vnic->flags = old_flags;
    2204                 :            : 
    2205                 :            :         return rc;
    2206                 :            : }
    2207                 :            : 
    2208                 :          0 : static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
    2209                 :            : {
    2210                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2211                 :            :         struct bnxt_vnic_info *vnic;
    2212                 :            :         uint32_t old_flags;
    2213                 :            :         int rc;
    2214                 :            : 
    2215                 :          0 :         rc = is_bnxt_in_error(bp);
    2216         [ #  # ]:          0 :         if (rc)
    2217                 :            :                 return rc;
    2218                 :            : 
    2219                 :            :         /* Filter settings will get applied when port is started */
    2220         [ #  # ]:          0 :         if (!eth_dev->data->dev_started)
    2221                 :            :                 return 0;
    2222                 :            : 
    2223         [ #  # ]:          0 :         if (bp->vnic_info == NULL)
    2224                 :            :                 return 0;
    2225                 :            : 
    2226                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2227                 :            : 
    2228                 :          0 :         old_flags = vnic->flags;
    2229                 :          0 :         vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
    2230                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    2231         [ #  # ]:          0 :         if (rc != 0)
    2232                 :          0 :                 vnic->flags = old_flags;
    2233                 :            : 
    2234                 :            :         return rc;
    2235                 :            : }
    2236                 :            : 
    2237                 :            : /* Return bnxt_rx_queue pointer corresponding to a given rxq. */
    2238                 :            : static struct bnxt_rx_queue *bnxt_qid_to_rxq(struct bnxt *bp, uint16_t qid)
    2239                 :            : {
    2240                 :          0 :         if (qid >= bp->rx_nr_rings)
    2241                 :            :                 return NULL;
    2242                 :            : 
    2243                 :          0 :         return bp->eth_dev->data->rx_queues[qid];
    2244                 :            : }
    2245                 :            : 
    2246                 :            : /* Return rxq corresponding to a given rss table ring/group ID. */
    2247                 :          0 : static uint16_t bnxt_rss_to_qid(struct bnxt *bp, uint16_t fwr)
    2248                 :            : {
    2249                 :            :         struct bnxt_rx_queue *rxq;
    2250                 :            :         unsigned int i;
    2251                 :            : 
    2252         [ #  # ]:          0 :         if (!BNXT_HAS_RING_GRPS(bp)) {
    2253         [ #  # ]:          0 :                 for (i = 0; i < bp->rx_nr_rings; i++) {
    2254                 :          0 :                         rxq = bp->eth_dev->data->rx_queues[i];
    2255         [ #  # ]:          0 :                         if (rxq->rx_ring->rx_ring_struct->fw_ring_id == fwr)
    2256                 :          0 :                                 return rxq->index;
    2257                 :            :                 }
    2258                 :            :         } else {
    2259         [ #  # ]:          0 :                 for (i = 0; i < bp->rx_nr_rings; i++) {
    2260         [ #  # ]:          0 :                         if (bp->grp_info[i].fw_grp_id == fwr)
    2261                 :          0 :                                 return i;
    2262                 :            :                 }
    2263                 :            :         }
    2264                 :            : 
    2265                 :            :         return INVALID_HW_RING_ID;
    2266                 :            : }
    2267                 :            : 
    2268                 :          0 : static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
    2269                 :            :                             struct rte_eth_rss_reta_entry64 *reta_conf,
    2270                 :            :                             uint16_t reta_size)
    2271                 :            : {
    2272                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2273                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
    2274                 :          0 :         struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
    2275                 :          0 :         uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
    2276                 :            :         uint16_t idx, sft;
    2277                 :            :         int i, rc;
    2278                 :            : 
    2279                 :          0 :         rc = is_bnxt_in_error(bp);
    2280         [ #  # ]:          0 :         if (rc)
    2281                 :            :                 return rc;
    2282                 :            : 
    2283         [ #  # ]:          0 :         if (!vnic->rss_table)
    2284                 :            :                 return -EINVAL;
    2285                 :            : 
    2286         [ #  # ]:          0 :         if (!(dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
    2287                 :            :                 return -EINVAL;
    2288                 :            : 
    2289         [ #  # ]:          0 :         if (reta_size != tbl_size) {
    2290                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "The configured hash table lookup size "
    2291                 :            :                         "(%d) must equal the size supported by the hardware "
    2292                 :            :                         "(%d)", reta_size, tbl_size);
    2293                 :          0 :                 return -EINVAL;
    2294                 :            :         }
    2295                 :            : 
    2296         [ #  # ]:          0 :         if (bnxt_vnic_reta_config_update(bp, vnic, reta_conf, reta_size)) {
    2297                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Error in setting the reta config");
    2298                 :          0 :                 return -EINVAL;
    2299                 :            :         }
    2300         [ #  # ]:          0 :         for (i = 0; i < reta_size; i++) {
    2301                 :            :                 struct bnxt_rx_queue *rxq;
    2302                 :            : 
    2303                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    2304                 :          0 :                 sft = i % RTE_ETH_RETA_GROUP_SIZE;
    2305                 :            : 
    2306         [ #  # ]:          0 :                 if (!(reta_conf[idx].mask & (1ULL << sft)))
    2307                 :          0 :                         continue;
    2308                 :            : 
    2309         [ #  # ]:          0 :                 rxq = bnxt_qid_to_rxq(bp, reta_conf[idx].reta[sft]);
    2310         [ #  # ]:          0 :                 if (!rxq) {
    2311                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Invalid ring in reta_conf");
    2312                 :          0 :                         return -EINVAL;
    2313                 :            :                 }
    2314                 :            : 
    2315         [ #  # ]:          0 :                 if (BNXT_CHIP_P5_P7(bp)) {
    2316                 :          0 :                         vnic->rss_table[i * 2] =
    2317                 :          0 :                                 rxq->rx_ring->rx_ring_struct->fw_ring_id;
    2318                 :          0 :                         vnic->rss_table[i * 2 + 1] =
    2319                 :          0 :                                 rxq->cp_ring->cp_ring_struct->fw_ring_id;
    2320                 :            :                 } else {
    2321                 :          0 :                         vnic->rss_table[i] =
    2322                 :          0 :                             vnic->fw_grp_ids[reta_conf[idx].reta[sft]];
    2323                 :            :                 }
    2324                 :            :         }
    2325                 :          0 :         rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
    2326                 :          0 :         return rc;
    2327                 :            : }
    2328                 :            : 
    2329                 :          0 : static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
    2330                 :            :                               struct rte_eth_rss_reta_entry64 *reta_conf,
    2331                 :            :                               uint16_t reta_size)
    2332                 :            : {
    2333                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2334                 :          0 :         struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
    2335                 :          0 :         uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
    2336                 :            :         uint16_t idx, sft, i;
    2337                 :            :         int rc;
    2338                 :            : 
    2339                 :          0 :         rc = is_bnxt_in_error(bp);
    2340         [ #  # ]:          0 :         if (rc)
    2341                 :            :                 return rc;
    2342                 :            : 
    2343         [ #  # ]:          0 :         if (!vnic)
    2344                 :            :                 return -EINVAL;
    2345         [ #  # ]:          0 :         if (!vnic->rss_table)
    2346                 :            :                 return -EINVAL;
    2347                 :            : 
    2348         [ #  # ]:          0 :         if (reta_size != tbl_size) {
    2349                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "The configured hash table lookup size "
    2350                 :            :                         "(%d) must equal the size supported by the hardware "
    2351                 :            :                         "(%d)", reta_size, tbl_size);
    2352                 :          0 :                 return -EINVAL;
    2353                 :            :         }
    2354                 :            : 
    2355         [ #  # ]:          0 :         for (idx = 0, i = 0; i < reta_size; i++) {
    2356                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    2357                 :          0 :                 sft = i % RTE_ETH_RETA_GROUP_SIZE;
    2358                 :            : 
    2359         [ #  # ]:          0 :                 if (reta_conf[idx].mask & (1ULL << sft)) {
    2360                 :            :                         uint16_t qid;
    2361                 :            : 
    2362         [ #  # ]:          0 :                         if (BNXT_CHIP_P5_P7(bp))
    2363                 :          0 :                                 qid = bnxt_rss_to_qid(bp,
    2364                 :          0 :                                                       vnic->rss_table[i * 2]);
    2365                 :            :                         else
    2366                 :          0 :                                 qid = bnxt_rss_to_qid(bp, vnic->rss_table[i]);
    2367                 :            : 
    2368         [ #  # ]:          0 :                         if (qid == INVALID_HW_RING_ID) {
    2369                 :          0 :                                 PMD_DRV_LOG_LINE(ERR, "Inv. entry in rss table.");
    2370                 :          0 :                                 return -EINVAL;
    2371                 :            :                         }
    2372                 :          0 :                         reta_conf[idx].reta[sft] = qid;
    2373                 :            :                 }
    2374                 :            :         }
    2375                 :            : 
    2376                 :            :         return 0;
    2377                 :            : }
    2378                 :            : 
    2379                 :          0 : static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
    2380                 :            :                                    struct rte_eth_rss_conf *rss_conf)
    2381                 :            : {
    2382                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2383                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
    2384                 :            :         struct bnxt_vnic_info *vnic;
    2385                 :            :         int rc;
    2386                 :            : 
    2387                 :          0 :         rc = is_bnxt_in_error(bp);
    2388         [ #  # ]:          0 :         if (rc)
    2389                 :            :                 return rc;
    2390                 :            : 
    2391                 :            :         /*
    2392                 :            :          * If RSS enablement were different than dev_configure,
    2393                 :            :          * then return -EINVAL
    2394                 :            :          */
    2395         [ #  # ]:          0 :         if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) {
    2396         [ #  # ]:          0 :                 if (!rss_conf->rss_hf)
    2397                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Hash type NONE");
    2398                 :            :         } else {
    2399         [ #  # ]:          0 :                 if (rss_conf->rss_hf & bnxt_eth_rss_support(bp))
    2400                 :            :                         return -EINVAL;
    2401                 :            :         }
    2402                 :            : 
    2403                 :            :         /* Update the default RSS VNIC(s) */
    2404                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2405                 :          0 :         vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
    2406                 :          0 :         vnic->hash_mode =
    2407                 :          0 :                 bnxt_rte_to_hwrm_hash_level(bp, rss_conf->rss_hf,
    2408                 :          0 :                                             RTE_ETH_RSS_LEVEL(rss_conf->rss_hf));
    2409                 :          0 :         rc = bnxt_rte_eth_to_hwrm_ring_select_mode(bp, rss_conf->rss_hf, vnic);
    2410         [ #  # ]:          0 :         if (rc != 0)
    2411                 :            :                 return rc;
    2412                 :            : 
    2413                 :            :         /* Cache the hash function */
    2414                 :          0 :         bp->rss_conf.rss_hf = rss_conf->rss_hf;
    2415                 :            : 
    2416                 :            :         /* Cache the hash function */
    2417                 :            :         bp->rss_conf.rss_hf = rss_conf->rss_hf;
    2418                 :            : 
    2419                 :            :         /*
    2420                 :            :          * If hashkey is not specified, use the previously configured
    2421                 :            :          * hashkey
    2422                 :            :          */
    2423         [ #  # ]:          0 :         if (!rss_conf->rss_key)
    2424                 :          0 :                 goto rss_config;
    2425                 :            : 
    2426         [ #  # ]:          0 :         if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE) {
    2427                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    2428                 :            :                             "Invalid hashkey length, should be %d bytes",
    2429                 :            :                             HW_HASH_KEY_SIZE);
    2430                 :          0 :                 return -EINVAL;
    2431                 :            :         }
    2432                 :          0 :         memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
    2433                 :            : 
    2434                 :            :         /* Cache the hash key */
    2435                 :          0 :         memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
    2436                 :            : 
    2437                 :          0 : rss_config:
    2438                 :          0 :         rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
    2439                 :          0 :         return rc;
    2440                 :            : }
    2441                 :            : 
    2442                 :          0 : static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
    2443                 :            :                                      struct rte_eth_rss_conf *rss_conf)
    2444                 :            : {
    2445                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2446                 :          0 :         struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
    2447                 :            :         int len, rc;
    2448                 :            : 
    2449                 :          0 :         rc = is_bnxt_in_error(bp);
    2450         [ #  # ]:          0 :         if (rc)
    2451                 :            :                 return rc;
    2452                 :            : 
    2453                 :            :         /* Return the RSS configuration of the default VNIC. */
    2454   [ #  #  #  # ]:          0 :         if (vnic && vnic->rss_hash_key) {
    2455         [ #  # ]:          0 :                 if (rss_conf->rss_key) {
    2456                 :          0 :                         len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
    2457                 :          0 :                               rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
    2458                 :          0 :                         memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
    2459                 :            :                 }
    2460                 :          0 :                 bnxt_hwrm_rss_to_rte_hash_conf(vnic, &rss_conf->rss_hf);
    2461                 :          0 :                 rss_conf->rss_hf |=
    2462                 :          0 :                         bnxt_hwrm_to_rte_rss_level(bp, vnic->hash_mode);
    2463                 :            :         } else {
    2464                 :          0 :                 rss_conf->rss_hf = 0;
    2465                 :            :         }
    2466                 :            :         return 0;
    2467                 :            : }
    2468                 :            : 
    2469                 :          0 : static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
    2470                 :            :                                struct rte_eth_fc_conf *fc_conf)
    2471                 :            : {
    2472                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    2473                 :            :         struct rte_eth_link link_info;
    2474                 :            :         int rc;
    2475                 :            : 
    2476                 :          0 :         rc = is_bnxt_in_error(bp);
    2477         [ #  # ]:          0 :         if (rc)
    2478                 :            :                 return rc;
    2479                 :            : 
    2480                 :          0 :         rc = bnxt_get_hwrm_link_config(bp, &link_info);
    2481         [ #  # ]:          0 :         if (rc)
    2482                 :            :                 return rc;
    2483                 :            : 
    2484                 :            :         memset(fc_conf, 0, sizeof(*fc_conf));
    2485         [ #  # ]:          0 :         if (bp->link_info->auto_pause)
    2486                 :          0 :                 fc_conf->autoneg = 1;
    2487   [ #  #  #  # ]:          0 :         switch (bp->link_info->pause) {
    2488                 :            :         case 0:
    2489                 :            :                 fc_conf->mode = RTE_ETH_FC_NONE;
    2490                 :            :                 break;
    2491                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
    2492                 :          0 :                 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    2493                 :          0 :                 break;
    2494                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
    2495                 :          0 :                 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
    2496                 :          0 :                 break;
    2497                 :          0 :         case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
    2498                 :            :                         HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
    2499                 :          0 :                 fc_conf->mode = RTE_ETH_FC_FULL;
    2500                 :          0 :                 break;
    2501                 :            :         }
    2502                 :            :         return 0;
    2503                 :            : }
    2504                 :            : 
    2505                 :          0 : static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
    2506                 :            :                                struct rte_eth_fc_conf *fc_conf)
    2507                 :            : {
    2508                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    2509                 :            :         int rc;
    2510                 :            : 
    2511                 :          0 :         rc = is_bnxt_in_error(bp);
    2512         [ #  # ]:          0 :         if (rc)
    2513                 :            :                 return rc;
    2514                 :            : 
    2515         [ #  # ]:          0 :         if (!BNXT_SINGLE_PF(bp)) {
    2516                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    2517                 :            :                             "Flow Control Settings cannot be modified on VF or on shared PF");
    2518                 :          0 :                 return -ENOTSUP;
    2519                 :            :         }
    2520                 :            : 
    2521   [ #  #  #  #  :          0 :         switch (fc_conf->mode) {
                      # ]
    2522                 :          0 :         case RTE_ETH_FC_NONE:
    2523                 :          0 :                 bp->link_info->auto_pause = 0;
    2524                 :          0 :                 bp->link_info->force_pause = 0;
    2525                 :          0 :                 break;
    2526                 :          0 :         case RTE_ETH_FC_RX_PAUSE:
    2527         [ #  # ]:          0 :                 if (fc_conf->autoneg) {
    2528                 :          0 :                         bp->link_info->auto_pause =
    2529                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
    2530                 :          0 :                         bp->link_info->force_pause = 0;
    2531                 :            :                 } else {
    2532                 :          0 :                         bp->link_info->auto_pause = 0;
    2533                 :          0 :                         bp->link_info->force_pause =
    2534                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
    2535                 :            :                 }
    2536                 :            :                 break;
    2537                 :          0 :         case RTE_ETH_FC_TX_PAUSE:
    2538         [ #  # ]:          0 :                 if (fc_conf->autoneg) {
    2539                 :          0 :                         bp->link_info->auto_pause =
    2540                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
    2541                 :          0 :                         bp->link_info->force_pause = 0;
    2542                 :            :                 } else {
    2543                 :          0 :                         bp->link_info->auto_pause = 0;
    2544                 :          0 :                         bp->link_info->force_pause =
    2545                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
    2546                 :            :                 }
    2547                 :            :                 break;
    2548                 :          0 :         case RTE_ETH_FC_FULL:
    2549         [ #  # ]:          0 :                 if (fc_conf->autoneg) {
    2550                 :          0 :                         bp->link_info->auto_pause =
    2551                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
    2552                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
    2553                 :          0 :                         bp->link_info->force_pause = 0;
    2554                 :            :                 } else {
    2555                 :          0 :                         bp->link_info->auto_pause = 0;
    2556                 :          0 :                         bp->link_info->force_pause =
    2557                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
    2558                 :            :                                         HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
    2559                 :            :                 }
    2560                 :            :                 break;
    2561                 :            :         }
    2562                 :          0 :         return bnxt_set_hwrm_link_config(bp, true);
    2563                 :            : }
    2564                 :            : 
    2565                 :            : /* Add UDP tunneling port */
    2566                 :            : int
    2567                 :          0 : bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
    2568                 :            :                          struct rte_eth_udp_tunnel *udp_tunnel)
    2569                 :            : {
    2570                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2571                 :            :         uint16_t tunnel_type = 0;
    2572                 :            :         int rc = 0;
    2573                 :            : 
    2574                 :          0 :         rc = is_bnxt_in_error(bp);
    2575         [ #  # ]:          0 :         if (rc)
    2576                 :            :                 return rc;
    2577                 :            : 
    2578   [ #  #  #  # ]:          0 :         switch (udp_tunnel->prot_type) {
    2579                 :          0 :         case RTE_ETH_TUNNEL_TYPE_VXLAN:
    2580         [ #  # ]:          0 :                 if (bp->vxlan_port_cnt) {
    2581                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
    2582                 :            :                                 udp_tunnel->udp_port);
    2583         [ #  # ]:          0 :                         if (bp->vxlan_port != udp_tunnel->udp_port) {
    2584                 :          0 :                                 PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
    2585                 :          0 :                                 return -ENOSPC;
    2586                 :            :                         }
    2587                 :          0 :                         bp->vxlan_port_cnt++;
    2588                 :          0 :                         return 0;
    2589                 :            :                 }
    2590                 :            :                 tunnel_type =
    2591                 :            :                         HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
    2592                 :            :                 break;
    2593                 :          0 :         case RTE_ETH_TUNNEL_TYPE_GENEVE:
    2594         [ #  # ]:          0 :                 if (bp->geneve_port_cnt) {
    2595                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
    2596                 :            :                                 udp_tunnel->udp_port);
    2597         [ #  # ]:          0 :                         if (bp->geneve_port != udp_tunnel->udp_port) {
    2598                 :          0 :                                 PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
    2599                 :          0 :                                 return -ENOSPC;
    2600                 :            :                         }
    2601                 :          0 :                         bp->geneve_port_cnt++;
    2602                 :          0 :                         return 0;
    2603                 :            :                 }
    2604                 :            :                 tunnel_type =
    2605                 :            :                         HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
    2606                 :            :                 break;
    2607                 :          0 :         case RTE_ETH_TUNNEL_TYPE_ECPRI:
    2608         [ #  # ]:          0 :                 if (bp->ecpri_port_cnt) {
    2609                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
    2610                 :            :                                 udp_tunnel->udp_port);
    2611         [ #  # ]:          0 :                         if (bp->ecpri_port != udp_tunnel->udp_port) {
    2612                 :          0 :                                 PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
    2613                 :          0 :                                 return -ENOSPC;
    2614                 :            :                         }
    2615                 :          0 :                         bp->ecpri_port_cnt++;
    2616                 :          0 :                         return 0;
    2617                 :            :                 }
    2618                 :            :                 tunnel_type =
    2619                 :            :                         HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI;
    2620                 :            :                 break;
    2621                 :          0 :         default:
    2622                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Tunnel type is not supported");
    2623                 :          0 :                 return -ENOTSUP;
    2624                 :            :         }
    2625                 :          0 :         rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
    2626                 :            :                                              tunnel_type);
    2627                 :            : 
    2628         [ #  # ]:          0 :         if (rc != 0)
    2629                 :            :                 return rc;
    2630                 :            : 
    2631         [ #  # ]:          0 :         if (tunnel_type ==
    2632                 :            :             HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN)
    2633                 :          0 :                 bp->vxlan_port_cnt++;
    2634                 :            : 
    2635         [ #  # ]:          0 :         if (tunnel_type ==
    2636                 :            :             HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE)
    2637                 :          0 :                 bp->geneve_port_cnt++;
    2638                 :            : 
    2639         [ #  # ]:          0 :         if (tunnel_type ==
    2640                 :            :             HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI)
    2641                 :          0 :                 bp->ecpri_port_cnt++;
    2642                 :            : 
    2643                 :            :         return rc;
    2644                 :            : }
    2645                 :            : 
    2646                 :            : int
    2647                 :          0 : bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
    2648                 :            :                          struct rte_eth_udp_tunnel *udp_tunnel)
    2649                 :            : {
    2650                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2651                 :            :         uint16_t tunnel_type = 0;
    2652                 :            :         uint16_t port = 0;
    2653                 :            :         int rc = 0;
    2654                 :            : 
    2655                 :          0 :         rc = is_bnxt_in_error(bp);
    2656         [ #  # ]:          0 :         if (rc)
    2657                 :            :                 return rc;
    2658                 :            : 
    2659   [ #  #  #  # ]:          0 :         switch (udp_tunnel->prot_type) {
    2660                 :          0 :         case RTE_ETH_TUNNEL_TYPE_VXLAN:
    2661         [ #  # ]:          0 :                 if (!bp->vxlan_port_cnt) {
    2662                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
    2663                 :          0 :                         return -EINVAL;
    2664                 :            :                 }
    2665         [ #  # ]:          0 :                 if (bp->vxlan_port != udp_tunnel->udp_port) {
    2666                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
    2667                 :            :                                 udp_tunnel->udp_port, bp->vxlan_port);
    2668                 :          0 :                         return -EINVAL;
    2669                 :            :                 }
    2670         [ #  # ]:          0 :                 if (--bp->vxlan_port_cnt)
    2671                 :            :                         return 0;
    2672                 :            : 
    2673                 :            :                 tunnel_type =
    2674                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
    2675                 :          0 :                 port = bp->vxlan_fw_dst_port_id;
    2676                 :          0 :                 break;
    2677                 :          0 :         case RTE_ETH_TUNNEL_TYPE_GENEVE:
    2678         [ #  # ]:          0 :                 if (!bp->geneve_port_cnt) {
    2679                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
    2680                 :          0 :                         return -EINVAL;
    2681                 :            :                 }
    2682         [ #  # ]:          0 :                 if (bp->geneve_port != udp_tunnel->udp_port) {
    2683                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
    2684                 :            :                                 udp_tunnel->udp_port, bp->geneve_port);
    2685                 :          0 :                         return -EINVAL;
    2686                 :            :                 }
    2687         [ #  # ]:          0 :                 if (--bp->geneve_port_cnt)
    2688                 :            :                         return 0;
    2689                 :            : 
    2690                 :            :                 tunnel_type =
    2691                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
    2692                 :          0 :                 port = bp->geneve_fw_dst_port_id;
    2693                 :          0 :                 break;
    2694                 :          0 :         case RTE_ETH_TUNNEL_TYPE_ECPRI:
    2695         [ #  # ]:          0 :                 if (!bp->ecpri_port_cnt) {
    2696                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
    2697                 :          0 :                         return -EINVAL;
    2698                 :            :                 }
    2699         [ #  # ]:          0 :                 if (bp->ecpri_port != udp_tunnel->udp_port) {
    2700                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
    2701                 :            :                                 udp_tunnel->udp_port, bp->ecpri_port);
    2702                 :          0 :                         return -EINVAL;
    2703                 :            :                 }
    2704         [ #  # ]:          0 :                 if (--bp->ecpri_port_cnt)
    2705                 :            :                         return 0;
    2706                 :            : 
    2707                 :            :                 tunnel_type =
    2708                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI;
    2709                 :          0 :                 port = bp->ecpri_fw_dst_port_id;
    2710                 :          0 :                 break;
    2711                 :          0 :         default:
    2712                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Tunnel type is not supported");
    2713                 :          0 :                 return -ENOTSUP;
    2714                 :            :         }
    2715                 :            : 
    2716                 :          0 :         rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
    2717                 :          0 :         return rc;
    2718                 :            : }
    2719                 :            : 
    2720                 :          0 : static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
    2721                 :            : {
    2722                 :            :         struct bnxt_filter_info *filter;
    2723                 :            :         struct bnxt_vnic_info *vnic;
    2724                 :            :         int rc = 0;
    2725                 :            :         uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
    2726                 :            : 
    2727                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2728                 :          0 :         filter = STAILQ_FIRST(&vnic->filter);
    2729         [ #  # ]:          0 :         while (filter) {
    2730                 :            :                 /* Search for this matching MAC+VLAN filter */
    2731   [ #  #  #  #  :          0 :                 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id)) {
             #  #  #  # ]
    2732                 :            :                         /* Delete the filter */
    2733                 :          0 :                         rc = bnxt_hwrm_clear_l2_filter(bp, filter);
    2734         [ #  # ]:          0 :                         if (rc)
    2735                 :            :                                 return rc;
    2736   [ #  #  #  #  :          0 :                         STAILQ_REMOVE(&vnic->filter, filter,
             #  #  #  # ]
    2737                 :            :                                       bnxt_filter_info, next);
    2738                 :          0 :                         bnxt_free_filter(bp, filter);
    2739                 :          0 :                         PMD_DRV_LOG_LINE(INFO,
    2740                 :            :                                     "Deleted vlan filter for %d",
    2741                 :            :                                     vlan_id);
    2742                 :          0 :                         return 0;
    2743                 :            :                 }
    2744                 :          0 :                 filter = STAILQ_NEXT(filter, next);
    2745                 :            :         }
    2746                 :            :         return -ENOENT;
    2747                 :            : }
    2748                 :            : 
    2749                 :          0 : static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
    2750                 :            : {
    2751                 :            :         struct bnxt_filter_info *filter;
    2752                 :            :         struct bnxt_vnic_info *vnic;
    2753                 :            :         int rc = 0;
    2754                 :            :         uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
    2755                 :            :                 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
    2756                 :            :         uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
    2757                 :            : 
    2758                 :            :         /* Implementation notes on the use of VNIC in this command:
    2759                 :            :          *
    2760                 :            :          * By default, these filters belong to default vnic for the function.
    2761                 :            :          * Once these filters are set up, only destination VNIC can be modified.
    2762                 :            :          * If the destination VNIC is not specified in this command,
    2763                 :            :          * then the HWRM shall only create an l2 context id.
    2764                 :            :          */
    2765                 :            : 
    2766                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2767                 :          0 :         filter = STAILQ_FIRST(&vnic->filter);
    2768                 :            :         /* Check if the VLAN has already been added */
    2769         [ #  # ]:          0 :         while (filter) {
    2770   [ #  #  #  #  :          0 :                 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id))
             #  #  #  # ]
    2771                 :            :                         return -EEXIST;
    2772                 :            : 
    2773                 :          0 :                 filter = STAILQ_NEXT(filter, next);
    2774                 :            :         }
    2775                 :            : 
    2776                 :            :         /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
    2777                 :            :          * command to create MAC+VLAN filter with the right flags, enables set.
    2778                 :            :          */
    2779                 :          0 :         filter = bnxt_alloc_filter(bp);
    2780         [ #  # ]:          0 :         if (!filter) {
    2781                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    2782                 :            :                             "MAC/VLAN filter alloc failed");
    2783                 :          0 :                 return -ENOMEM;
    2784                 :            :         }
    2785                 :            :         /* MAC + VLAN ID filter */
    2786                 :            :         /* If l2_ivlan == 0 and l2_ivlan_mask != 0, only
    2787                 :            :          * untagged packets are received
    2788                 :            :          *
    2789                 :            :          * If l2_ivlan != 0 and l2_ivlan_mask != 0, untagged
    2790                 :            :          * packets and only the programmed vlan's packets are received
    2791                 :            :          */
    2792                 :          0 :         filter->l2_ivlan = vlan_id;
    2793                 :          0 :         filter->l2_ivlan_mask = 0x0FFF;
    2794                 :          0 :         filter->enables |= en;
    2795                 :          0 :         filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
    2796                 :            : 
    2797                 :          0 :         rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
    2798         [ #  # ]:          0 :         if (rc) {
    2799                 :            :                 /* Free the newly allocated filter as we were
    2800                 :            :                  * not able to create the filter in hardware.
    2801                 :            :                  */
    2802                 :          0 :                 bnxt_free_filter(bp, filter);
    2803                 :          0 :                 return rc;
    2804                 :            :         }
    2805                 :            : 
    2806                 :          0 :         filter->mac_index = 0;
    2807                 :            :         /* Add this new filter to the list */
    2808         [ #  # ]:          0 :         if (vlan_id == 0)
    2809         [ #  # ]:          0 :                 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
    2810                 :            :         else
    2811                 :          0 :                 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
    2812                 :            : 
    2813                 :          0 :         PMD_DRV_LOG_LINE(INFO,
    2814                 :            :                     "Added Vlan filter for %d", vlan_id);
    2815                 :          0 :         return rc;
    2816                 :            : }
    2817                 :            : 
    2818                 :          0 : static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
    2819                 :            :                 uint16_t vlan_id, int on)
    2820                 :            : {
    2821                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    2822                 :            :         int rc;
    2823                 :            : 
    2824                 :          0 :         rc = is_bnxt_in_error(bp);
    2825         [ #  # ]:          0 :         if (rc)
    2826                 :            :                 return rc;
    2827                 :            : 
    2828         [ #  # ]:          0 :         if (!eth_dev->data->dev_started) {
    2829                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "port must be started before setting vlan");
    2830                 :          0 :                 return -EINVAL;
    2831                 :            :         }
    2832                 :            : 
    2833                 :            :         /* These operations apply to ALL existing MAC/VLAN filters */
    2834         [ #  # ]:          0 :         if (on)
    2835                 :          0 :                 return bnxt_add_vlan_filter(bp, vlan_id);
    2836                 :            :         else
    2837                 :          0 :                 return bnxt_del_vlan_filter(bp, vlan_id);
    2838                 :            : }
    2839                 :            : 
    2840                 :          0 : static int bnxt_del_dflt_mac_filter(struct bnxt *bp,
    2841                 :            :                                     struct bnxt_vnic_info *vnic)
    2842                 :            : {
    2843                 :            :         struct bnxt_filter_info *filter;
    2844                 :            :         int rc;
    2845                 :            : 
    2846                 :          0 :         filter = STAILQ_FIRST(&vnic->filter);
    2847         [ #  # ]:          0 :         while (filter) {
    2848         [ #  # ]:          0 :                 if (filter->mac_index == 0 &&
    2849         [ #  # ]:          0 :                     !memcmp(filter->l2_addr, bp->mac_addr,
    2850                 :            :                             RTE_ETHER_ADDR_LEN)) {
    2851                 :          0 :                         rc = bnxt_hwrm_clear_l2_filter(bp, filter);
    2852         [ #  # ]:          0 :                         if (!rc) {
    2853   [ #  #  #  #  :          0 :                                 STAILQ_REMOVE(&vnic->filter, filter,
             #  #  #  # ]
    2854                 :            :                                               bnxt_filter_info, next);
    2855                 :          0 :                                 bnxt_free_filter(bp, filter);
    2856                 :            :                         }
    2857                 :          0 :                         return rc;
    2858                 :            :                 }
    2859                 :          0 :                 filter = STAILQ_NEXT(filter, next);
    2860                 :            :         }
    2861                 :            :         return 0;
    2862                 :            : }
    2863                 :            : 
    2864                 :            : static int
    2865                 :          0 : bnxt_config_vlan_hw_filter(struct bnxt *bp, uint64_t rx_offloads)
    2866                 :            : {
    2867                 :            :         struct bnxt_vnic_info *vnic;
    2868                 :            :         unsigned int i;
    2869                 :            :         int rc;
    2870                 :            : 
    2871                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    2872         [ #  # ]:          0 :         if (!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
    2873                 :            :                 /* Remove any VLAN filters programmed */
    2874         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
    2875                 :          0 :                         bnxt_del_vlan_filter(bp, i);
    2876                 :            : 
    2877                 :          0 :                 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
    2878         [ #  # ]:          0 :                 if (rc)
    2879                 :            :                         return rc;
    2880                 :            :         } else {
    2881                 :            :                 /* Default filter will allow packets that match the
    2882                 :            :                  * dest mac. So, it has to be deleted, otherwise, we
    2883                 :            :                  * will endup receiving vlan packets for which the
    2884                 :            :                  * filter is not programmed, when hw-vlan-filter
    2885                 :            :                  * configuration is ON
    2886                 :            :                  */
    2887                 :          0 :                 bnxt_del_dflt_mac_filter(bp, vnic);
    2888                 :            :                 /* This filter will allow only untagged packets */
    2889                 :          0 :                 bnxt_add_vlan_filter(bp, 0);
    2890                 :            :         }
    2891                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "VLAN Filtering: %d",
    2892                 :            :                     !!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER));
    2893                 :            : 
    2894                 :          0 :         return 0;
    2895                 :            : }
    2896                 :            : 
    2897                 :          0 : static int bnxt_free_one_vnic(struct bnxt *bp, uint16_t vnic_id)
    2898                 :            : {
    2899                 :          0 :         struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
    2900                 :            :         unsigned int i;
    2901                 :            :         int rc;
    2902                 :            : 
    2903                 :            :         /* Destroy vnic filters and vnic */
    2904         [ #  # ]:          0 :         if (bp->eth_dev->data->dev_conf.rxmode.offloads &
    2905                 :            :             RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
    2906         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
    2907                 :          0 :                         bnxt_del_vlan_filter(bp, i);
    2908                 :            :         }
    2909                 :          0 :         bnxt_del_dflt_mac_filter(bp, vnic);
    2910                 :            : 
    2911                 :          0 :         rc = bnxt_hwrm_vnic_ctx_free(bp, vnic);
    2912         [ #  # ]:          0 :         if (rc)
    2913                 :            :                 return rc;
    2914                 :            : 
    2915                 :          0 :         rc = bnxt_hwrm_vnic_free(bp, vnic);
    2916         [ #  # ]:          0 :         if (rc)
    2917                 :            :                 return rc;
    2918                 :            : 
    2919                 :          0 :         rte_free(vnic->fw_grp_ids);
    2920                 :          0 :         vnic->fw_grp_ids = NULL;
    2921                 :            : 
    2922                 :          0 :         vnic->rx_queue_cnt = 0;
    2923                 :            : 
    2924                 :          0 :         return 0;
    2925                 :            : }
    2926                 :            : 
    2927                 :            : static int
    2928                 :          0 : bnxt_config_vlan_hw_stripping(struct bnxt *bp, uint64_t rx_offloads)
    2929                 :            : {
    2930                 :          0 :         struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
    2931                 :            :         int rc;
    2932                 :            : 
    2933                 :            :         /* Destroy, recreate and reconfigure the default vnic */
    2934                 :          0 :         rc = bnxt_free_one_vnic(bp, bp->vnic_queue_db.dflt_vnic_id);
    2935         [ #  # ]:          0 :         if (rc)
    2936                 :            :                 return rc;
    2937                 :            : 
    2938                 :            :         /* setup the default vnic details*/
    2939                 :          0 :         bnxt_vnic_queue_db_update_dlft_vnic(bp);
    2940                 :            : 
    2941                 :          0 :         rc = bnxt_setup_one_vnic(bp, bp->vnic_queue_db.dflt_vnic_id);
    2942         [ #  # ]:          0 :         if (rc)
    2943                 :            :                 return rc;
    2944                 :            : 
    2945         [ #  # ]:          0 :         if (bp->eth_dev->data->dev_conf.rxmode.offloads &
    2946                 :            :             RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
    2947                 :          0 :                 rc = bnxt_add_vlan_filter(bp, 0);
    2948         [ #  # ]:          0 :                 if (rc)
    2949                 :            :                         return rc;
    2950                 :          0 :                 rc = bnxt_restore_vlan_filters(bp);
    2951         [ #  # ]:          0 :                 if (rc)
    2952                 :            :                         return rc;
    2953                 :            :         } else {
    2954                 :          0 :                 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
    2955         [ #  # ]:          0 :                 if (rc)
    2956                 :            :                         return rc;
    2957                 :            :         }
    2958                 :            : 
    2959                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    2960         [ #  # ]:          0 :         if (rc)
    2961                 :            :                 return rc;
    2962                 :            : 
    2963                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "VLAN Strip Offload: %d",
    2964                 :            :                     !!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP));
    2965                 :            : 
    2966                 :          0 :         return rc;
    2967                 :            : }
    2968                 :            : 
    2969                 :            : static int
    2970                 :          0 : bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
    2971                 :            : {
    2972                 :          0 :         uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
    2973                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    2974                 :            :         int rc = 0;
    2975                 :            : 
    2976                 :          0 :         rc = is_bnxt_in_error(bp);
    2977         [ #  # ]:          0 :         if (rc)
    2978                 :            :                 return rc;
    2979                 :            : 
    2980                 :            :         /* Filter settings will get applied when port is started */
    2981         [ #  # ]:          0 :         if (!dev->data->dev_started)
    2982                 :            :                 return 0;
    2983                 :            : 
    2984                 :            :         /* For P7 platform, cannot support if truflow is enabled */
    2985   [ #  #  #  #  :          0 :         if (BNXT_TRUFLOW_EN(bp) && BNXT_CHIP_P7(bp))
                   #  # ]
    2986                 :            :                 return rc;
    2987                 :            : 
    2988         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_FILTER_MASK) {
    2989                 :            :                 /* Enable or disable VLAN filtering */
    2990                 :          0 :                 rc = bnxt_config_vlan_hw_filter(bp, rx_offloads);
    2991         [ #  # ]:          0 :                 if (rc)
    2992                 :            :                         return rc;
    2993                 :            :         }
    2994                 :            : 
    2995         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
    2996                 :            :                 /* Enable or disable VLAN stripping */
    2997                 :          0 :                 rc = bnxt_config_vlan_hw_stripping(bp, rx_offloads);
    2998         [ #  # ]:          0 :                 if (rc)
    2999                 :            :                         return rc;
    3000                 :            :         }
    3001                 :            : 
    3002         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
    3003         [ #  # ]:          0 :                 if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
    3004                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG, "Extend VLAN supported");
    3005                 :            :                 else
    3006                 :          0 :                         PMD_DRV_LOG_LINE(INFO, "Extend VLAN unsupported");
    3007                 :            :         }
    3008                 :            : 
    3009                 :            :         return 0;
    3010                 :            : }
    3011                 :            : 
    3012                 :            : static int
    3013                 :          0 : bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
    3014                 :            :                       uint16_t tpid)
    3015                 :            : {
    3016                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3017                 :          0 :         int qinq = dev->data->dev_conf.rxmode.offloads &
    3018                 :            :                    RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
    3019                 :            : 
    3020         [ #  # ]:          0 :         if (vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
    3021                 :            :             vlan_type != RTE_ETH_VLAN_TYPE_OUTER) {
    3022                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    3023                 :            :                             "Unsupported vlan type.");
    3024                 :          0 :                 return -EINVAL;
    3025                 :            :         }
    3026         [ #  # ]:          0 :         if (!qinq) {
    3027                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    3028                 :            :                             "QinQ not enabled. Needs to be ON as we can "
    3029                 :            :                             "accelerate only outer vlan");
    3030                 :          0 :                 return -EINVAL;
    3031                 :            :         }
    3032                 :            : 
    3033         [ #  # ]:          0 :         if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
    3034   [ #  #  #  #  :          0 :                 switch (tpid) {
                   #  # ]
    3035                 :          0 :                 case RTE_ETHER_TYPE_QINQ:
    3036                 :          0 :                         bp->outer_tpid_bd =
    3037                 :            :                                 TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
    3038                 :          0 :                                 break;
    3039                 :          0 :                 case RTE_ETHER_TYPE_VLAN:
    3040                 :          0 :                         bp->outer_tpid_bd =
    3041                 :            :                                 TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
    3042                 :          0 :                                 break;
    3043                 :          0 :                 case RTE_ETHER_TYPE_QINQ1:
    3044                 :          0 :                         bp->outer_tpid_bd =
    3045                 :            :                                 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
    3046                 :          0 :                                 break;
    3047                 :          0 :                 case RTE_ETHER_TYPE_QINQ2:
    3048                 :          0 :                         bp->outer_tpid_bd =
    3049                 :            :                                 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
    3050                 :          0 :                                 break;
    3051                 :          0 :                 case RTE_ETHER_TYPE_QINQ3:
    3052                 :          0 :                         bp->outer_tpid_bd =
    3053                 :            :                                  TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
    3054                 :          0 :                                 break;
    3055                 :          0 :                 default:
    3056                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Invalid TPID: %x", tpid);
    3057                 :          0 :                         return -EINVAL;
    3058                 :            :                 }
    3059                 :          0 :                 bp->outer_tpid_bd |= tpid;
    3060                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "outer_tpid_bd = %x", bp->outer_tpid_bd);
    3061                 :            :         } else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER) {
    3062                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    3063                 :            :                             "Can accelerate only outer vlan in QinQ");
    3064                 :          0 :                 return -EINVAL;
    3065                 :            :         }
    3066                 :            : 
    3067                 :          0 :         return 0;
    3068                 :            : }
    3069                 :            : 
    3070                 :            : static int
    3071                 :          0 : bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
    3072                 :            :                              struct rte_ether_addr *addr)
    3073                 :            : {
    3074                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3075                 :            :         /* Default Filter is tied to VNIC 0 */
    3076                 :          0 :         struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
    3077                 :            :         int rc;
    3078                 :            : 
    3079                 :          0 :         rc = is_bnxt_in_error(bp);
    3080         [ #  # ]:          0 :         if (rc)
    3081                 :            :                 return rc;
    3082                 :            : 
    3083         [ #  # ]:          0 :         if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
    3084                 :            :                 return -EPERM;
    3085                 :            : 
    3086         [ #  # ]:          0 :         if (rte_is_zero_ether_addr(addr))
    3087                 :            :                 return -EINVAL;
    3088                 :            : 
    3089                 :            :         /* Filter settings will get applied when port is started */
    3090         [ #  # ]:          0 :         if (!dev->data->dev_started)
    3091                 :            :                 return 0;
    3092                 :            : 
    3093                 :            :         /* Check if the requested MAC is already added */
    3094         [ #  # ]:          0 :         if (memcmp(addr, bp->mac_addr, RTE_ETHER_ADDR_LEN) == 0)
    3095                 :            :                 return 0;
    3096                 :            : 
    3097                 :            :         /* Destroy filter and re-create it */
    3098                 :          0 :         bnxt_del_dflt_mac_filter(bp, vnic);
    3099                 :            : 
    3100                 :            :         memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
    3101         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
    3102                 :            :                 /* This filter will allow only untagged packets */
    3103                 :          0 :                 rc = bnxt_add_vlan_filter(bp, 0);
    3104                 :            :         } else {
    3105                 :          0 :                 rc = bnxt_add_mac_filter(bp, vnic, addr, 0, 0);
    3106                 :            :         }
    3107                 :            : 
    3108                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "Set MAC addr");
    3109                 :          0 :         return rc;
    3110                 :            : }
    3111                 :            : 
    3112                 :            : static int
    3113                 :          0 : bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
    3114                 :            :                           struct rte_ether_addr *mc_addr_set,
    3115                 :            :                           uint32_t nb_mc_addr)
    3116                 :            : {
    3117                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    3118                 :            :         struct bnxt_vnic_info *vnic;
    3119                 :            :         uint32_t i = 0;
    3120                 :            :         int rc;
    3121                 :            : 
    3122                 :          0 :         rc = is_bnxt_in_error(bp);
    3123         [ #  # ]:          0 :         if (rc)
    3124                 :            :                 return rc;
    3125                 :            : 
    3126                 :          0 :         vnic = bnxt_get_default_vnic(bp);
    3127                 :            : 
    3128                 :          0 :         bp->nb_mc_addr = nb_mc_addr;
    3129                 :            : 
    3130         [ #  # ]:          0 :         if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
    3131                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "Number of Mcast MACs added (%u) exceeded Max supported (%u)",
    3132                 :            :                             nb_mc_addr, BNXT_MAX_MC_ADDRS);
    3133                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "Turning on Mcast promiscuous mode");
    3134                 :          0 :                 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
    3135                 :          0 :                 goto allmulti;
    3136                 :            :         }
    3137                 :            : 
    3138                 :            :         /* TODO Check for Duplicate mcast addresses */
    3139         [ #  # ]:          0 :         if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
    3140                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "Turning off Mcast promiscuous mode");
    3141                 :          0 :                 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
    3142                 :            :         }
    3143         [ #  # ]:          0 :         for (i = 0; i < nb_mc_addr; i++)
    3144                 :          0 :                 rte_ether_addr_copy(&mc_addr_set[i], &bp->mcast_addr_list[i]);
    3145                 :            : 
    3146         [ #  # ]:          0 :         if (bp->nb_mc_addr)
    3147                 :          0 :                 vnic->flags |= BNXT_VNIC_INFO_MCAST;
    3148                 :            :         else
    3149                 :          0 :                 vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
    3150                 :            : 
    3151                 :            : allmulti:
    3152                 :          0 :         rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    3153   [ #  #  #  # ]:          0 :         if (rc == -ENOSPC && (vnic->flags & BNXT_VNIC_INFO_MCAST)) {
    3154                 :            :                 /* If MCAST addition failed because FW ran out of
    3155                 :            :                  * multicast filters, enable all multicast mode.
    3156                 :            :                  */
    3157                 :          0 :                 vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
    3158                 :          0 :                 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
    3159                 :          0 :                 goto allmulti;
    3160                 :            :         }
    3161                 :            : 
    3162                 :            :         return rc;
    3163                 :            : }
    3164                 :            : 
    3165                 :            : static int
    3166                 :          0 : bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
    3167                 :            : {
    3168                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3169                 :          0 :         uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
    3170                 :          0 :         uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
    3171                 :          0 :         uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
    3172                 :            :         uint8_t fw_rsvd = bp->fw_ver & 0xff;
    3173                 :            :         int ret;
    3174                 :            : 
    3175         [ #  # ]:          0 :         ret = snprintf(fw_version, fw_size, "%d.%d.%d.%d",
    3176                 :            :                         fw_major, fw_minor, fw_updt, fw_rsvd);
    3177         [ #  # ]:          0 :         if (ret < 0)
    3178                 :            :                 return -EINVAL;
    3179                 :            : 
    3180                 :          0 :         ret += 1; /* add the size of '\0' */
    3181         [ #  # ]:          0 :         if (fw_size < (size_t)ret)
    3182                 :            :                 return ret;
    3183                 :            :         else
    3184                 :          0 :                 return 0;
    3185                 :            : }
    3186                 :            : 
    3187                 :            : static void
    3188                 :          0 : bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
    3189                 :            :         struct rte_eth_rxq_info *qinfo)
    3190                 :            : {
    3191                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3192                 :            :         struct bnxt_rx_queue *rxq;
    3193                 :            : 
    3194         [ #  # ]:          0 :         if (is_bnxt_in_error(bp))
    3195                 :            :                 return;
    3196                 :            : 
    3197                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    3198                 :            : 
    3199                 :          0 :         qinfo->mp = rxq->mb_pool;
    3200                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    3201                 :          0 :         qinfo->nb_desc = rxq->nb_rx_desc;
    3202                 :            : 
    3203                 :          0 :         qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
    3204                 :          0 :         qinfo->conf.rx_drop_en = rxq->drop_en;
    3205                 :          0 :         qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
    3206                 :          0 :         qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
    3207                 :            : }
    3208                 :            : 
    3209                 :            : static void
    3210                 :          0 : bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
    3211                 :            :         struct rte_eth_txq_info *qinfo)
    3212                 :            : {
    3213                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3214                 :            :         struct bnxt_tx_queue *txq;
    3215                 :            : 
    3216         [ #  # ]:          0 :         if (is_bnxt_in_error(bp))
    3217                 :            :                 return;
    3218                 :            : 
    3219                 :          0 :         txq = dev->data->tx_queues[queue_id];
    3220                 :            : 
    3221                 :          0 :         qinfo->nb_desc = txq->nb_tx_desc;
    3222                 :            : 
    3223                 :          0 :         qinfo->conf.tx_thresh.pthresh = txq->pthresh;
    3224                 :          0 :         qinfo->conf.tx_thresh.hthresh = txq->hthresh;
    3225                 :          0 :         qinfo->conf.tx_thresh.wthresh = txq->wthresh;
    3226                 :            : 
    3227                 :          0 :         qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
    3228                 :          0 :         qinfo->conf.tx_rs_thresh = 0;
    3229                 :          0 :         qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
    3230                 :          0 :         qinfo->conf.offloads = txq->offloads;
    3231                 :            : }
    3232                 :            : 
    3233                 :            : static const struct {
    3234                 :            :         eth_rx_burst_t pkt_burst;
    3235                 :            :         const char *info;
    3236                 :            : } bnxt_rx_burst_info[] = {
    3237                 :            :         {bnxt_recv_pkts,                "Scalar"},
    3238                 :            : #if defined(RTE_ARCH_X86)
    3239                 :            :         {bnxt_crx_pkts_vec,             "Vector SSE"},
    3240                 :            :         {bnxt_recv_pkts_vec,            "Vector SSE"},
    3241                 :            : #endif
    3242                 :            : #if defined(RTE_ARCH_X86) && defined(CC_AVX2_SUPPORT)
    3243                 :            :         {bnxt_crx_pkts_vec_avx2,        "Vector AVX2"},
    3244                 :            :         {bnxt_recv_pkts_vec_avx2,       "Vector AVX2"},
    3245                 :            : #endif
    3246                 :            : #if defined(RTE_ARCH_ARM64)
    3247                 :            :         {bnxt_recv_pkts_vec,            "Vector Neon"},
    3248                 :            : #endif
    3249                 :            : };
    3250                 :            : 
    3251                 :            : static int
    3252                 :          0 : bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
    3253                 :            :                        struct rte_eth_burst_mode *mode)
    3254                 :            : {
    3255                 :          0 :         eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
    3256                 :            :         size_t i;
    3257                 :            : 
    3258         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(bnxt_rx_burst_info); i++) {
    3259         [ #  # ]:          0 :                 if (pkt_burst == bnxt_rx_burst_info[i].pkt_burst) {
    3260                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
    3261                 :          0 :                                  bnxt_rx_burst_info[i].info);
    3262                 :          0 :                         return 0;
    3263                 :            :                 }
    3264                 :            :         }
    3265                 :            : 
    3266                 :            :         return -EINVAL;
    3267                 :            : }
    3268                 :            : 
    3269                 :            : static const struct {
    3270                 :            :         eth_tx_burst_t pkt_burst;
    3271                 :            :         const char *info;
    3272                 :            : } bnxt_tx_burst_info[] = {
    3273                 :            :         {bnxt_xmit_pkts,                "Scalar"},
    3274                 :            : #if defined(RTE_ARCH_X86)
    3275                 :            :         {bnxt_xmit_pkts_vec,            "Vector SSE"},
    3276                 :            :         {bnxt_xmit_pkts_vec_avx2,       "Vector AVX2"},
    3277                 :            : #endif
    3278                 :            : #if defined(RTE_ARCH_ARM64)
    3279                 :            :         {bnxt_xmit_pkts_vec,            "Vector Neon"},
    3280                 :            : #endif
    3281                 :            : };
    3282                 :            : 
    3283                 :            : static int
    3284                 :          0 : bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
    3285                 :            :                        struct rte_eth_burst_mode *mode)
    3286                 :            : {
    3287                 :          0 :         eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
    3288                 :            :         size_t i;
    3289                 :            : 
    3290         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(bnxt_tx_burst_info); i++) {
    3291         [ #  # ]:          0 :                 if (pkt_burst == bnxt_tx_burst_info[i].pkt_burst) {
    3292                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
    3293                 :          0 :                                  bnxt_tx_burst_info[i].info);
    3294                 :          0 :                         return 0;
    3295                 :            :                 }
    3296                 :            :         }
    3297                 :            : 
    3298                 :            :         return -EINVAL;
    3299                 :            : }
    3300                 :            : 
    3301                 :          0 : int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
    3302                 :            : {
    3303                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    3304                 :            :         uint32_t rc = 0;
    3305                 :            : 
    3306                 :          0 :         rc = is_bnxt_in_error(bp);
    3307         [ #  # ]:          0 :         if (rc)
    3308                 :            :                 return rc;
    3309                 :            : 
    3310                 :            :         /* Return if port is active */
    3311         [ #  # ]:          0 :         if (eth_dev->data->dev_started) {
    3312                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Stop port before changing MTU");
    3313                 :          0 :                 return -EBUSY;
    3314                 :            :         }
    3315                 :            : 
    3316                 :            :         /* Exit if receive queues are not configured yet */
    3317         [ #  # ]:          0 :         if (!eth_dev->data->nb_rx_queues)
    3318                 :            :                 return -ENOTSUP;
    3319                 :            : 
    3320                 :            :         /* Is there a change in mtu setting? */
    3321         [ #  # ]:          0 :         if (eth_dev->data->mtu == new_mtu)
    3322                 :            :                 return rc;
    3323                 :            : 
    3324         [ #  # ]:          0 :         if (new_mtu > RTE_ETHER_MTU)
    3325                 :          0 :                 bp->flags |= BNXT_FLAG_JUMBO;
    3326                 :            :         else
    3327                 :          0 :                 bp->flags &= ~BNXT_FLAG_JUMBO;
    3328                 :            : 
    3329                 :          0 :         rc = bnxt_vnic_mru_config(bp, new_mtu);
    3330         [ #  # ]:          0 :         if (rc) {
    3331                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "failed to update mtu in vnic context");
    3332                 :          0 :                 return rc;
    3333                 :            :         }
    3334                 :            : 
    3335         [ #  # ]:          0 :         if (bnxt_hwrm_config_host_mtu(bp))
    3336                 :          0 :                 PMD_DRV_LOG_LINE(WARNING, "Failed to configure host MTU");
    3337                 :            : 
    3338                 :          0 :         PMD_DRV_LOG_LINE(INFO, "New MTU is %d", new_mtu);
    3339                 :            : 
    3340                 :          0 :         return rc;
    3341                 :            : }
    3342                 :            : 
    3343                 :            : static int
    3344                 :          0 : bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
    3345                 :            : {
    3346                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3347                 :          0 :         uint16_t vlan = bp->vlan;
    3348                 :            :         int rc;
    3349                 :            : 
    3350                 :          0 :         rc = is_bnxt_in_error(bp);
    3351         [ #  # ]:          0 :         if (rc)
    3352                 :            :                 return rc;
    3353                 :            : 
    3354         [ #  # ]:          0 :         if (!BNXT_SINGLE_PF(bp)) {
    3355                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "PVID cannot be modified on VF or on shared PF");
    3356                 :          0 :                 return -ENOTSUP;
    3357                 :            :         }
    3358         [ #  # ]:          0 :         bp->vlan = on ? pvid : 0;
    3359                 :            : 
    3360                 :          0 :         rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
    3361         [ #  # ]:          0 :         if (rc)
    3362                 :          0 :                 bp->vlan = vlan;
    3363                 :            :         return rc;
    3364                 :            : }
    3365                 :            : 
    3366                 :            : static int
    3367                 :          0 : bnxt_dev_led_on_op(struct rte_eth_dev *dev)
    3368                 :            : {
    3369                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3370                 :            :         int rc;
    3371                 :            : 
    3372                 :          0 :         rc = is_bnxt_in_error(bp);
    3373         [ #  # ]:          0 :         if (rc)
    3374                 :            :                 return rc;
    3375                 :            : 
    3376                 :          0 :         return bnxt_hwrm_port_led_cfg(bp, true);
    3377                 :            : }
    3378                 :            : 
    3379                 :            : static int
    3380                 :          0 : bnxt_dev_led_off_op(struct rte_eth_dev *dev)
    3381                 :            : {
    3382                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3383                 :            :         int rc;
    3384                 :            : 
    3385                 :          0 :         rc = is_bnxt_in_error(bp);
    3386         [ #  # ]:          0 :         if (rc)
    3387                 :            :                 return rc;
    3388                 :            : 
    3389                 :          0 :         return bnxt_hwrm_port_led_cfg(bp, false);
    3390                 :            : }
    3391                 :            : 
    3392                 :            : static uint32_t
    3393                 :          0 : bnxt_rx_queue_count_op(void *rx_queue)
    3394                 :            : {
    3395                 :            :         struct bnxt *bp;
    3396                 :            :         struct bnxt_cp_ring_info *cpr;
    3397                 :            :         uint32_t desc = 0, raw_cons, cp_ring_size;
    3398                 :            :         struct bnxt_rx_queue *rxq;
    3399                 :            :         struct rx_pkt_cmpl *rxcmp;
    3400                 :            :         int rc;
    3401                 :            : 
    3402                 :            :         rxq = rx_queue;
    3403                 :          0 :         bp = rxq->bp;
    3404                 :            : 
    3405                 :          0 :         rc = is_bnxt_in_error(bp);
    3406         [ #  # ]:          0 :         if (rc)
    3407                 :          0 :                 return rc;
    3408                 :            : 
    3409                 :          0 :         cpr = rxq->cp_ring;
    3410                 :          0 :         raw_cons = cpr->cp_raw_cons;
    3411                 :          0 :         cp_ring_size = cpr->cp_ring_struct->ring_size;
    3412                 :            : 
    3413                 :            :         while (1) {
    3414                 :            :                 uint32_t agg_cnt, cons, cmpl_type;
    3415                 :            : 
    3416                 :          0 :                 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
    3417         [ #  # ]:          0 :                 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
    3418                 :            : 
    3419                 :            :                 if (!bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
    3420                 :            :                         break;
    3421                 :            : 
    3422                 :          0 :                 cmpl_type = CMP_TYPE(rxcmp);
    3423                 :            : 
    3424      [ #  #  # ]:          0 :                 switch (cmpl_type) {
    3425                 :          0 :                 case CMPL_BASE_TYPE_RX_L2:
    3426                 :            :                 case CMPL_BASE_TYPE_RX_L2_V2:
    3427                 :          0 :                         agg_cnt = BNXT_RX_L2_AGG_BUFS(rxcmp);
    3428                 :          0 :                         raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
    3429                 :          0 :                         desc++;
    3430                 :          0 :                         break;
    3431                 :            : 
    3432                 :          0 :                 case CMPL_BASE_TYPE_RX_TPA_END:
    3433         [ #  # ]:          0 :                         if (BNXT_CHIP_P5_P7(rxq->bp)) {
    3434                 :            :                                 struct rx_tpa_v2_end_cmpl_hi *p5_tpa_end;
    3435                 :            : 
    3436                 :            :                                 p5_tpa_end = (void *)rxcmp;
    3437                 :          0 :                                 agg_cnt = BNXT_TPA_END_AGG_BUFS_TH(p5_tpa_end);
    3438                 :            :                         } else {
    3439                 :            :                                 struct rx_tpa_end_cmpl *tpa_end;
    3440                 :            : 
    3441                 :            :                                 tpa_end = (void *)rxcmp;
    3442                 :          0 :                                 agg_cnt = BNXT_TPA_END_AGG_BUFS(tpa_end);
    3443                 :            :                         }
    3444                 :            : 
    3445                 :          0 :                         raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
    3446                 :          0 :                         desc++;
    3447                 :          0 :                         break;
    3448                 :            : 
    3449                 :          0 :                 default:
    3450                 :          0 :                         raw_cons += CMP_LEN(cmpl_type);
    3451                 :            :                 }
    3452                 :            :         }
    3453                 :            : 
    3454                 :            :         return desc;
    3455                 :            : }
    3456                 :            : 
    3457                 :            : static int
    3458                 :          0 : bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
    3459                 :            : {
    3460                 :            :         struct bnxt_rx_queue *rxq = rx_queue;
    3461                 :            :         struct bnxt_cp_ring_info *cpr;
    3462                 :            :         struct bnxt_rx_ring_info *rxr;
    3463                 :            :         uint32_t desc, raw_cons, cp_ring_size;
    3464                 :          0 :         struct bnxt *bp = rxq->bp;
    3465                 :            :         struct rx_pkt_cmpl *rxcmp;
    3466                 :            :         int rc;
    3467                 :            : 
    3468                 :          0 :         rc = is_bnxt_in_error(bp);
    3469         [ #  # ]:          0 :         if (rc)
    3470                 :            :                 return rc;
    3471                 :            : 
    3472         [ #  # ]:          0 :         if (offset >= rxq->nb_rx_desc)
    3473                 :            :                 return -EINVAL;
    3474                 :            : 
    3475                 :          0 :         rxr = rxq->rx_ring;
    3476                 :          0 :         cpr = rxq->cp_ring;
    3477                 :          0 :         cp_ring_size = cpr->cp_ring_struct->ring_size;
    3478                 :            : 
    3479                 :            :         /*
    3480                 :            :          * For the vector receive case, the completion at the requested
    3481                 :            :          * offset can be indexed directly.
    3482                 :            :          */
    3483                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
    3484         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_RX_VECTOR_PKT_MODE) {
    3485                 :            :                 struct rx_pkt_cmpl *rxcmp;
    3486                 :            :                 uint32_t cons;
    3487                 :            : 
    3488                 :            :                 /* Check status of completion descriptor. */
    3489                 :          0 :                 raw_cons = cpr->cp_raw_cons +
    3490                 :          0 :                            offset * CMP_LEN(CMPL_BASE_TYPE_RX_L2);
    3491                 :          0 :                 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
    3492         [ #  # ]:          0 :                 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
    3493                 :            : 
    3494                 :            :                 if (bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
    3495                 :          0 :                         return RTE_ETH_RX_DESC_DONE;
    3496                 :            : 
    3497                 :            :                 /* Check whether rx desc has an mbuf attached. */
    3498                 :          0 :                 cons = RING_CMP(rxr->rx_ring_struct, raw_cons / 2);
    3499         [ #  # ]:          0 :                 if (cons >= rxq->rxrearm_start &&
    3500         [ #  # ]:          0 :                     cons < rxq->rxrearm_start + rxq->rxrearm_nb) {
    3501                 :            :                         return RTE_ETH_RX_DESC_UNAVAIL;
    3502                 :            :                 }
    3503                 :            : 
    3504                 :          0 :                 return RTE_ETH_RX_DESC_AVAIL;
    3505                 :            :         }
    3506                 :            : #endif
    3507                 :            : 
    3508                 :            :         /*
    3509                 :            :          * For the non-vector receive case, scan the completion ring to
    3510                 :            :          * locate the completion descriptor for the requested offset.
    3511                 :            :          */
    3512                 :          0 :         raw_cons = cpr->cp_raw_cons;
    3513                 :            :         desc = 0;
    3514                 :            :         while (1) {
    3515                 :            :                 uint32_t agg_cnt, cons, cmpl_type;
    3516                 :            : 
    3517                 :          0 :                 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
    3518         [ #  # ]:          0 :                 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
    3519                 :            : 
    3520                 :            :                 if (!bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
    3521                 :            :                         break;
    3522                 :            : 
    3523                 :          0 :                 cmpl_type = CMP_TYPE(rxcmp);
    3524                 :            : 
    3525      [ #  #  # ]:          0 :                 switch (cmpl_type) {
    3526                 :          0 :                 case CMPL_BASE_TYPE_RX_L2:
    3527                 :            :                 case CMPL_BASE_TYPE_RX_L2_V2:
    3528         [ #  # ]:          0 :                         if (desc == offset) {
    3529                 :          0 :                                 cons = rxcmp->opaque;
    3530         [ #  # ]:          0 :                                 if (rxr->rx_buf_ring[cons])
    3531                 :            :                                         return RTE_ETH_RX_DESC_DONE;
    3532                 :            :                                 else
    3533                 :          0 :                                         return RTE_ETH_RX_DESC_UNAVAIL;
    3534                 :            :                         }
    3535                 :          0 :                         agg_cnt = BNXT_RX_L2_AGG_BUFS(rxcmp);
    3536                 :          0 :                         raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
    3537                 :          0 :                         desc++;
    3538                 :          0 :                         break;
    3539                 :            : 
    3540                 :          0 :                 case CMPL_BASE_TYPE_RX_TPA_END:
    3541         [ #  # ]:          0 :                         if (desc == offset)
    3542                 :            :                                 return RTE_ETH_RX_DESC_DONE;
    3543                 :            : 
    3544         [ #  # ]:          0 :                         if (BNXT_CHIP_P5_P7(rxq->bp)) {
    3545                 :            :                                 struct rx_tpa_v2_end_cmpl_hi *p5_tpa_end;
    3546                 :            : 
    3547                 :            :                                 p5_tpa_end = (void *)rxcmp;
    3548                 :          0 :                                 agg_cnt = BNXT_TPA_END_AGG_BUFS_TH(p5_tpa_end);
    3549                 :            :                         } else {
    3550                 :            :                                 struct rx_tpa_end_cmpl *tpa_end;
    3551                 :            : 
    3552                 :            :                                 tpa_end = (void *)rxcmp;
    3553                 :          0 :                                 agg_cnt = BNXT_TPA_END_AGG_BUFS(tpa_end);
    3554                 :            :                         }
    3555                 :            : 
    3556                 :          0 :                         raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
    3557                 :          0 :                         desc++;
    3558                 :          0 :                         break;
    3559                 :            : 
    3560                 :          0 :                 default:
    3561                 :          0 :                         raw_cons += CMP_LEN(cmpl_type);
    3562                 :            :                 }
    3563                 :            :         }
    3564                 :            : 
    3565                 :            :         return RTE_ETH_RX_DESC_AVAIL;
    3566                 :            : }
    3567                 :            : 
    3568                 :            : static int
    3569                 :          0 : bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
    3570                 :            : {
    3571                 :            :         struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
    3572                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
    3573                 :            :         uint32_t ring_mask, raw_cons, nb_tx_pkts = 0;
    3574                 :            :         struct cmpl_base *cp_desc_ring;
    3575                 :            :         int rc;
    3576                 :            : 
    3577                 :          0 :         rc = is_bnxt_in_error(txq->bp);
    3578         [ #  # ]:          0 :         if (rc)
    3579                 :            :                 return rc;
    3580                 :            : 
    3581         [ #  # ]:          0 :         if (offset >= txq->nb_tx_desc)
    3582                 :            :                 return -EINVAL;
    3583                 :            : 
    3584                 :            :         /* Return "desc done" if descriptor is available for use. */
    3585         [ #  # ]:          0 :         if (bnxt_tx_bds_in_hw(txq) <= offset)
    3586                 :            :                 return RTE_ETH_TX_DESC_DONE;
    3587                 :            : 
    3588                 :          0 :         raw_cons = cpr->cp_raw_cons;
    3589                 :          0 :         cp_desc_ring = cpr->cp_desc_ring;
    3590                 :          0 :         ring_mask = cpr->cp_ring_struct->ring_mask;
    3591                 :            : 
    3592                 :            :         /* Check to see if hw has posted a completion for the descriptor. */
    3593                 :          0 :         while (1) {
    3594                 :            :                 struct tx_cmpl *txcmp;
    3595                 :            :                 uint32_t cons;
    3596                 :            : 
    3597                 :          0 :                 cons = RING_CMPL(ring_mask, raw_cons);
    3598                 :          0 :                 txcmp = (struct tx_cmpl *)&cp_desc_ring[cons];
    3599                 :            : 
    3600         [ #  # ]:          0 :                 if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
    3601                 :            :                         break;
    3602                 :            : 
    3603         [ #  # ]:          0 :                 if (CMP_TYPE(txcmp) == TX_CMPL_TYPE_TX_L2)
    3604                 :          0 :                         nb_tx_pkts += rte_le_to_cpu_32(txcmp->opaque);
    3605                 :            : 
    3606         [ #  # ]:          0 :                 if (nb_tx_pkts > offset)
    3607                 :            :                         return RTE_ETH_TX_DESC_DONE;
    3608                 :            : 
    3609                 :          0 :                 raw_cons = NEXT_RAW_CMP(raw_cons);
    3610                 :            :         }
    3611                 :            : 
    3612                 :            :         /* Descriptor is pending transmit, not yet completed by hardware. */
    3613                 :            :         return RTE_ETH_TX_DESC_FULL;
    3614                 :            : }
    3615                 :            : 
    3616                 :            : int
    3617                 :          0 : bnxt_flow_ops_get_op(struct rte_eth_dev *dev,
    3618                 :            :                      const struct rte_flow_ops **ops)
    3619                 :            : {
    3620                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3621                 :            :         int ret = 0;
    3622                 :            : 
    3623         [ #  # ]:          0 :         if (!bp)
    3624                 :            :                 return -EIO;
    3625                 :            : 
    3626         [ #  # ]:          0 :         if (rte_eth_dev_is_repr(dev)) {
    3627                 :            :                 struct bnxt_representor *vfr = dev->data->dev_private;
    3628                 :          0 :                 bp = vfr->parent_dev->data->dev_private;
    3629                 :            :                 /* parent is deleted while children are still valid */
    3630         [ #  # ]:          0 :                 if (!bp) {
    3631                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR Error",
    3632                 :            :                                     dev->data->port_id);
    3633                 :          0 :                         return -EIO;
    3634                 :            :                 }
    3635                 :            :         }
    3636                 :            : 
    3637                 :          0 :         ret = is_bnxt_in_error(bp);
    3638         [ #  # ]:          0 :         if (ret)
    3639                 :            :                 return ret;
    3640                 :            : 
    3641                 :            :         /* PMD supports thread-safe flow operations.  rte_flow API
    3642                 :            :          * functions can avoid mutex for multi-thread safety.
    3643                 :            :          */
    3644                 :          0 :         dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
    3645                 :            : 
    3646                 :            :         if (bnxt_enable_ulp(bp))
    3647                 :          0 :                 *ops = &bnxt_ulp_rte_flow_ops;
    3648                 :            :         else
    3649                 :          0 :                 *ops = &bnxt_flow_ops;
    3650                 :            : 
    3651                 :            :         return ret;
    3652                 :            : }
    3653                 :            : 
    3654                 :            : static const uint32_t *
    3655                 :          0 : bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev,
    3656                 :            :                                  size_t *no_of_elements)
    3657                 :            : {
    3658                 :            :         static const uint32_t ptypes[] = {
    3659                 :            :                 RTE_PTYPE_L2_ETHER_VLAN,
    3660                 :            :                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
    3661                 :            :                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
    3662                 :            :                 RTE_PTYPE_L4_ICMP,
    3663                 :            :                 RTE_PTYPE_L4_TCP,
    3664                 :            :                 RTE_PTYPE_L4_UDP,
    3665                 :            :                 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
    3666                 :            :                 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
    3667                 :            :                 RTE_PTYPE_INNER_L4_ICMP,
    3668                 :            :                 RTE_PTYPE_INNER_L4_TCP,
    3669                 :            :                 RTE_PTYPE_INNER_L4_UDP,
    3670                 :            :         };
    3671                 :            : 
    3672         [ #  # ]:          0 :         if (!dev->rx_pkt_burst)
    3673                 :            :                 return NULL;
    3674                 :            : 
    3675                 :          0 :         *no_of_elements = RTE_DIM(ptypes);
    3676                 :          0 :         return ptypes;
    3677                 :            : }
    3678                 :            : 
    3679                 :            : static int bnxt_map_regs(struct bnxt *bp, uint32_t *reg_arr, int count,
    3680                 :            :                          int reg_win)
    3681                 :            : {
    3682                 :          0 :         uint32_t reg_base = *reg_arr & 0xfffff000;
    3683                 :            :         uint32_t win_off;
    3684                 :            :         int i;
    3685                 :            : 
    3686   [ #  #  #  # ]:          0 :         for (i = 0; i < count; i++) {
    3687   [ #  #  #  # ]:          0 :                 if ((reg_arr[i] & 0xfffff000) != reg_base)
    3688                 :            :                         return -ERANGE;
    3689                 :            :         }
    3690                 :            :         win_off = BNXT_GRCPF_REG_WINDOW_BASE_OUT + (reg_win - 1) * 4;
    3691                 :          0 :         rte_write32(reg_base, (uint8_t *)bp->bar0 + win_off);
    3692                 :            :         return 0;
    3693                 :            : }
    3694                 :            : 
    3695                 :          0 : static int bnxt_map_ptp_regs(struct bnxt *bp)
    3696                 :            : {
    3697                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3698                 :            :         uint32_t *reg_arr;
    3699                 :            :         int rc, i;
    3700                 :            : 
    3701                 :          0 :         reg_arr = ptp->rx_regs;
    3702                 :            :         rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_RX_REGS, 5);
    3703                 :            :         if (rc)
    3704                 :            :                 return rc;
    3705                 :            : 
    3706                 :          0 :         reg_arr = ptp->tx_regs;
    3707                 :            :         rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_TX_REGS, 6);
    3708                 :            :         if (rc)
    3709                 :            :                 return rc;
    3710                 :            : 
    3711         [ #  # ]:          0 :         for (i = 0; i < BNXT_PTP_RX_REGS; i++)
    3712                 :          0 :                 ptp->rx_mapped_regs[i] = 0x5000 + (ptp->rx_regs[i] & 0xfff);
    3713                 :            : 
    3714         [ #  # ]:          0 :         for (i = 0; i < BNXT_PTP_TX_REGS; i++)
    3715                 :          0 :                 ptp->tx_mapped_regs[i] = 0x6000 + (ptp->tx_regs[i] & 0xfff);
    3716                 :            : 
    3717                 :            :         return 0;
    3718                 :            : }
    3719                 :            : 
    3720                 :            : static void bnxt_unmap_ptp_regs(struct bnxt *bp)
    3721                 :            : {
    3722                 :          0 :         rte_write32(0, (uint8_t *)bp->bar0 +
    3723                 :            :                          BNXT_GRCPF_REG_WINDOW_BASE_OUT + 16);
    3724                 :          0 :         rte_write32(0, (uint8_t *)bp->bar0 +
    3725                 :            :                          BNXT_GRCPF_REG_WINDOW_BASE_OUT + 20);
    3726                 :          0 : }
    3727                 :            : 
    3728                 :            : static uint64_t bnxt_cc_read(struct bnxt *bp)
    3729                 :            : {
    3730                 :            :         uint64_t ns;
    3731                 :            : 
    3732                 :          0 :         ns = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3733                 :            :                               BNXT_GRCPF_REG_SYNC_TIME));
    3734                 :          0 :         ns |= (uint64_t)(rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3735                 :          0 :                                           BNXT_GRCPF_REG_SYNC_TIME + 4))) << 32;
    3736                 :            :         return ns;
    3737                 :            : }
    3738                 :            : 
    3739                 :          0 : static int bnxt_get_tx_ts(struct bnxt *bp, uint64_t *ts)
    3740                 :            : {
    3741                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3742                 :            :         uint32_t fifo;
    3743                 :            : 
    3744                 :          0 :         fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3745                 :            :                                 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
    3746         [ #  # ]:          0 :         if (fifo & BNXT_PTP_TX_FIFO_EMPTY)
    3747                 :            :                 return -EAGAIN;
    3748                 :            : 
    3749                 :          0 :         fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3750                 :            :                                 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
    3751                 :          0 :         *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3752                 :            :                                 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_L]));
    3753                 :          0 :         *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3754                 :          0 :                                 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_H])) << 32;
    3755                 :          0 :         rte_read32((uint8_t *)bp->bar0 + ptp->tx_mapped_regs[BNXT_PTP_TX_SEQ]);
    3756                 :            : 
    3757                 :          0 :         return 0;
    3758                 :            : }
    3759                 :            : 
    3760                 :          0 : static int bnxt_clr_rx_ts(struct bnxt *bp, uint64_t *last_ts)
    3761                 :            : {
    3762                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3763                 :          0 :         struct bnxt_pf_info *pf = bp->pf;
    3764                 :            :         uint16_t port_id;
    3765                 :            :         int i = 0;
    3766                 :            :         uint32_t fifo;
    3767                 :            : 
    3768   [ #  #  #  # ]:          0 :         if (!ptp || (bp->flags & BNXT_FLAG_CHIP_P5))
    3769                 :            :                 return -EINVAL;
    3770                 :            : 
    3771                 :          0 :         port_id = pf->port_id;
    3772                 :          0 :         fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3773                 :            :                                 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
    3774   [ #  #  #  # ]:          0 :         while ((fifo & BNXT_PTP_RX_FIFO_PENDING) && (i < BNXT_PTP_RX_PND_CNT)) {
    3775                 :          0 :                 rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
    3776                 :          0 :                             ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
    3777                 :          0 :                 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3778                 :            :                                         ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
    3779                 :          0 :                 *last_ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3780                 :            :                                         ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
    3781                 :          0 :                 *last_ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3782                 :          0 :                                         ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
    3783                 :          0 :                 i++;
    3784                 :            :         }
    3785                 :            : 
    3786         [ #  # ]:          0 :         if (i >= BNXT_PTP_RX_PND_CNT)
    3787                 :          0 :                 return -EBUSY;
    3788                 :            : 
    3789                 :            :         return 0;
    3790                 :            : }
    3791                 :            : 
    3792                 :          0 : static int bnxt_get_rx_ts(struct bnxt *bp, uint64_t *ts)
    3793                 :            : {
    3794                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3795                 :          0 :         struct bnxt_pf_info *pf = bp->pf;
    3796                 :            :         uint16_t port_id;
    3797                 :            :         uint32_t fifo;
    3798                 :            : 
    3799                 :          0 :         fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3800                 :            :                                 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
    3801         [ #  # ]:          0 :         if (!(fifo & BNXT_PTP_RX_FIFO_PENDING))
    3802                 :            :                 return -EAGAIN;
    3803                 :            : 
    3804                 :          0 :         port_id = pf->port_id;
    3805                 :          0 :         rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
    3806                 :          0 :                ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
    3807                 :            : 
    3808                 :          0 :         fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3809                 :            :                                    ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
    3810         [ #  # ]:          0 :         if (fifo & BNXT_PTP_RX_FIFO_PENDING)
    3811                 :          0 :                 return bnxt_clr_rx_ts(bp, ts);
    3812                 :            : 
    3813                 :          0 :         *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3814                 :            :                                 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
    3815                 :          0 :         *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    3816                 :          0 :                                 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
    3817                 :            : 
    3818                 :          0 :         return 0;
    3819                 :            : }
    3820                 :            : 
    3821                 :            : static int
    3822                 :          0 : bnxt_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
    3823                 :            : {
    3824                 :            :         uint64_t ns;
    3825                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3826                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3827                 :            : 
    3828         [ #  # ]:          0 :         if (!ptp)
    3829                 :            :                 return -ENOTSUP;
    3830                 :            : 
    3831                 :            :         ns = rte_timespec_to_ns(ts);
    3832                 :            :         /* Set the timecounters to a new value. */
    3833                 :          0 :         ptp->tc.nsec = ns;
    3834                 :          0 :         ptp->tx_tstamp_tc.nsec = ns;
    3835                 :          0 :         ptp->rx_tstamp_tc.nsec = ns;
    3836                 :            : 
    3837                 :          0 :         return 0;
    3838                 :            : }
    3839                 :            : 
    3840                 :            : static int
    3841                 :          0 : bnxt_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
    3842                 :            : {
    3843                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3844                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3845                 :          0 :         uint64_t ns, systime_cycles = 0;
    3846                 :            :         int rc = 0;
    3847                 :            : 
    3848         [ #  # ]:          0 :         if (!ptp)
    3849                 :            :                 return -ENOTSUP;
    3850                 :            : 
    3851                 :            :         /* TODO Revisit for Thor 2 */
    3852         [ #  # ]:          0 :         if (BNXT_CHIP_P5(bp))
    3853                 :          0 :                 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
    3854                 :            :                                              &systime_cycles);
    3855                 :            :         else
    3856                 :          0 :                 systime_cycles = bnxt_cc_read(bp);
    3857                 :            : 
    3858         [ #  # ]:          0 :         ns = rte_timecounter_update(&ptp->tc, systime_cycles);
    3859                 :          0 :         *ts = rte_ns_to_timespec(ns);
    3860                 :            : 
    3861                 :          0 :         return rc;
    3862                 :            : }
    3863                 :            : static int
    3864                 :          0 : bnxt_timesync_enable(struct rte_eth_dev *dev)
    3865                 :            : {
    3866                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3867                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3868                 :            :         uint32_t shift = 0;
    3869                 :            :         int rc;
    3870                 :            : 
    3871         [ #  # ]:          0 :         if (!ptp)
    3872                 :            :                 return -ENOTSUP;
    3873                 :            : 
    3874                 :          0 :         ptp->rx_filter = 1;
    3875                 :          0 :         ptp->tx_tstamp_en = 1;
    3876                 :          0 :         ptp->filter_all = 1;
    3877                 :          0 :         ptp->rxctl = BNXT_PTP_MSG_EVENTS;
    3878                 :            : 
    3879                 :          0 :         rc = bnxt_hwrm_ptp_cfg(bp);
    3880         [ #  # ]:          0 :         if (rc)
    3881                 :            :                 return rc;
    3882                 :            : 
    3883                 :            :         rte_spinlock_init(&ptp->ptp_lock);
    3884                 :          0 :         bp->ptp_all_rx_tstamp = 1;
    3885         [ #  # ]:          0 :         memset(&ptp->tc, 0, sizeof(struct rte_timecounter));
    3886                 :          0 :         memset(&ptp->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
    3887                 :          0 :         memset(&ptp->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
    3888                 :            : 
    3889                 :          0 :         ptp->tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
    3890                 :            :         ptp->tc.cc_shift = shift;
    3891                 :            :         ptp->tc.nsec_mask = (1ULL << shift) - 1;
    3892                 :            : 
    3893                 :          0 :         ptp->rx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
    3894                 :            :         ptp->rx_tstamp_tc.cc_shift = shift;
    3895                 :            :         ptp->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
    3896                 :            : 
    3897                 :          0 :         ptp->tx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
    3898                 :            :         ptp->tx_tstamp_tc.cc_shift = shift;
    3899                 :            :         ptp->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
    3900                 :            : 
    3901                 :            :         /* TODO Revisit for Thor 2 */
    3902         [ #  # ]:          0 :         if (!BNXT_CHIP_P5(bp))
    3903                 :          0 :                 bnxt_map_ptp_regs(bp);
    3904                 :            :         else
    3905                 :          0 :                 rc = bnxt_ptp_start(bp);
    3906                 :            : 
    3907                 :            :         return rc;
    3908                 :            : }
    3909                 :            : 
    3910                 :            : static int
    3911                 :          0 : bnxt_timesync_disable(struct rte_eth_dev *dev)
    3912                 :            : {
    3913                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3914                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3915                 :            : 
    3916         [ #  # ]:          0 :         if (!ptp)
    3917                 :            :                 return -ENOTSUP;
    3918                 :            : 
    3919                 :          0 :         ptp->rx_filter = 0;
    3920                 :          0 :         ptp->tx_tstamp_en = 0;
    3921                 :          0 :         ptp->rxctl = 0;
    3922                 :          0 :         ptp->filter_all = 0;
    3923                 :            : 
    3924                 :          0 :         bnxt_hwrm_ptp_cfg(bp);
    3925                 :            : 
    3926                 :            :         /* TODO Revisit for Thor 2 */
    3927                 :          0 :         bp->ptp_all_rx_tstamp = 0;
    3928         [ #  # ]:          0 :         if (!BNXT_CHIP_P5(bp))
    3929                 :            :                 bnxt_unmap_ptp_regs(bp);
    3930                 :            :         else
    3931                 :          0 :                 bnxt_ptp_stop(bp);
    3932                 :            : 
    3933                 :            :         return 0;
    3934                 :            : }
    3935                 :            : 
    3936                 :            : static int
    3937                 :          0 : bnxt_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
    3938                 :            :                                  struct timespec *timestamp,
    3939                 :            :                                  uint32_t flags __rte_unused)
    3940                 :            : {
    3941                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3942                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3943                 :          0 :         uint64_t rx_tstamp_cycles = 0;
    3944                 :            :         uint64_t ns;
    3945                 :            : 
    3946         [ #  # ]:          0 :         if (!ptp)
    3947                 :            :                 return -ENOTSUP;
    3948                 :            : 
    3949                 :            :         /* TODO Revisit for Thor 2 */
    3950         [ #  # ]:          0 :         if (BNXT_CHIP_P5(bp))
    3951                 :          0 :                 rx_tstamp_cycles = ptp->rx_timestamp;
    3952                 :            :         else
    3953                 :          0 :                 bnxt_get_rx_ts(bp, &rx_tstamp_cycles);
    3954                 :            : 
    3955         [ #  # ]:          0 :         ns = rte_timecounter_update(&ptp->rx_tstamp_tc, rx_tstamp_cycles);
    3956                 :          0 :         *timestamp = rte_ns_to_timespec(ns);
    3957                 :          0 :         return  0;
    3958                 :            : }
    3959                 :            : 
    3960                 :            : static int
    3961                 :          0 : bnxt_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
    3962                 :            :                                  struct timespec *timestamp)
    3963                 :            : {
    3964                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3965                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3966                 :          0 :         uint64_t tx_tstamp_cycles = 0;
    3967                 :            :         uint64_t ns;
    3968                 :            :         int rc = 0;
    3969                 :            : 
    3970         [ #  # ]:          0 :         if (!ptp)
    3971                 :            :                 return -ENOTSUP;
    3972                 :            : 
    3973                 :            :         /* TODO Revisit for Thor 2 */
    3974         [ #  # ]:          0 :         if (BNXT_CHIP_P5(bp))
    3975                 :          0 :                 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_PATH_TX,
    3976                 :            :                                              &tx_tstamp_cycles);
    3977                 :            :         else
    3978                 :          0 :                 rc = bnxt_get_tx_ts(bp, &tx_tstamp_cycles);
    3979                 :            : 
    3980         [ #  # ]:          0 :         ns = rte_timecounter_update(&ptp->tx_tstamp_tc, tx_tstamp_cycles);
    3981                 :          0 :         *timestamp = rte_ns_to_timespec(ns);
    3982                 :            : 
    3983                 :          0 :         return rc;
    3984                 :            : }
    3985                 :            : 
    3986                 :            : static int
    3987                 :          0 : bnxt_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
    3988                 :            : {
    3989                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    3990                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    3991                 :            : 
    3992         [ #  # ]:          0 :         if (!ptp)
    3993                 :            :                 return -ENOTSUP;
    3994                 :            : 
    3995                 :          0 :         ptp->tc.nsec += delta;
    3996                 :          0 :         ptp->tx_tstamp_tc.nsec += delta;
    3997                 :          0 :         ptp->rx_tstamp_tc.nsec += delta;
    3998                 :            : 
    3999                 :          0 :         return 0;
    4000                 :            : }
    4001                 :            : 
    4002                 :            : static int
    4003                 :          0 : bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
    4004                 :            : {
    4005                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4006                 :            :         int rc;
    4007                 :            :         uint32_t dir_entries;
    4008                 :            :         uint32_t entry_length;
    4009                 :            : 
    4010                 :          0 :         rc = is_bnxt_in_error(bp);
    4011         [ #  # ]:          0 :         if (rc)
    4012                 :            :                 return rc;
    4013                 :            : 
    4014                 :          0 :         PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT,
    4015                 :            :                     bp->pdev->addr.domain, bp->pdev->addr.bus,
    4016                 :            :                     bp->pdev->addr.devid, bp->pdev->addr.function);
    4017                 :            : 
    4018                 :          0 :         rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
    4019         [ #  # ]:          0 :         if (rc != 0)
    4020                 :            :                 return rc;
    4021                 :            : 
    4022                 :          0 :         return dir_entries * entry_length;
    4023                 :            : }
    4024                 :            : 
    4025                 :            : static int
    4026                 :          0 : bnxt_get_eeprom_op(struct rte_eth_dev *dev,
    4027                 :            :                 struct rte_dev_eeprom_info *in_eeprom)
    4028                 :            : {
    4029                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4030                 :            :         uint32_t index;
    4031                 :            :         uint32_t offset;
    4032                 :            :         int rc;
    4033                 :            : 
    4034                 :          0 :         rc = is_bnxt_in_error(bp);
    4035         [ #  # ]:          0 :         if (rc)
    4036                 :            :                 return rc;
    4037                 :            : 
    4038                 :          0 :         PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d",
    4039                 :            :                     bp->pdev->addr.domain, bp->pdev->addr.bus,
    4040                 :            :                     bp->pdev->addr.devid, bp->pdev->addr.function,
    4041                 :            :                     in_eeprom->offset, in_eeprom->length);
    4042                 :            : 
    4043         [ #  # ]:          0 :         if (in_eeprom->offset == 0) /* special offset value to get directory */
    4044                 :          0 :                 return bnxt_get_nvram_directory(bp, in_eeprom->length,
    4045                 :          0 :                                                 in_eeprom->data);
    4046                 :            : 
    4047                 :          0 :         index = in_eeprom->offset >> 24;
    4048                 :          0 :         offset = in_eeprom->offset & 0xffffff;
    4049                 :            : 
    4050         [ #  # ]:          0 :         if (index != 0)
    4051                 :          0 :                 return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
    4052                 :          0 :                                            in_eeprom->length, in_eeprom->data);
    4053                 :            : 
    4054                 :            :         return 0;
    4055                 :            : }
    4056                 :            : 
    4057                 :            : static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
    4058                 :            : {
    4059                 :          0 :         switch (dir_type) {
    4060                 :            :         case BNX_DIR_TYPE_CHIMP_PATCH:
    4061                 :            :         case BNX_DIR_TYPE_BOOTCODE:
    4062                 :            :         case BNX_DIR_TYPE_BOOTCODE_2:
    4063                 :            :         case BNX_DIR_TYPE_APE_FW:
    4064                 :            :         case BNX_DIR_TYPE_APE_PATCH:
    4065                 :            :         case BNX_DIR_TYPE_KONG_FW:
    4066                 :            :         case BNX_DIR_TYPE_KONG_PATCH:
    4067                 :            :         case BNX_DIR_TYPE_BONO_FW:
    4068                 :            :         case BNX_DIR_TYPE_BONO_PATCH:
    4069                 :            :                 /* FALLTHROUGH */
    4070                 :            :                 return true;
    4071                 :            :         }
    4072                 :            : 
    4073                 :            :         return false;
    4074                 :            : }
    4075                 :            : 
    4076                 :            : static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
    4077                 :            : {
    4078         [ #  # ]:          0 :         switch (dir_type) {
    4079                 :            :         case BNX_DIR_TYPE_AVS:
    4080                 :            :         case BNX_DIR_TYPE_EXP_ROM_MBA:
    4081                 :            :         case BNX_DIR_TYPE_PCIE:
    4082                 :            :         case BNX_DIR_TYPE_TSCF_UCODE:
    4083                 :            :         case BNX_DIR_TYPE_EXT_PHY:
    4084                 :            :         case BNX_DIR_TYPE_CCM:
    4085                 :            :         case BNX_DIR_TYPE_ISCSI_BOOT:
    4086                 :            :         case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
    4087                 :            :         case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
    4088                 :            :                 /* FALLTHROUGH */
    4089                 :            :                 return true;
    4090                 :            :         }
    4091                 :            : 
    4092                 :            :         return false;
    4093                 :            : }
    4094                 :            : 
    4095         [ #  # ]:          0 : static bool bnxt_dir_type_is_executable(uint16_t dir_type)
    4096                 :            : {
    4097                 :          0 :         return bnxt_dir_type_is_ape_bin_format(dir_type) ||
    4098                 :            :                 bnxt_dir_type_is_other_exec_format(dir_type);
    4099                 :            : }
    4100                 :            : 
    4101                 :            : static int
    4102                 :          0 : bnxt_set_eeprom_op(struct rte_eth_dev *dev,
    4103                 :            :                 struct rte_dev_eeprom_info *in_eeprom)
    4104                 :            : {
    4105                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4106                 :            :         uint8_t index, dir_op;
    4107                 :            :         uint16_t type, ext, ordinal, attr;
    4108                 :            :         int rc;
    4109                 :            : 
    4110                 :          0 :         rc = is_bnxt_in_error(bp);
    4111         [ #  # ]:          0 :         if (rc)
    4112                 :            :                 return rc;
    4113                 :            : 
    4114                 :          0 :         PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d",
    4115                 :            :                     bp->pdev->addr.domain, bp->pdev->addr.bus,
    4116                 :            :                     bp->pdev->addr.devid, bp->pdev->addr.function,
    4117                 :            :                     in_eeprom->offset, in_eeprom->length);
    4118                 :            : 
    4119         [ #  # ]:          0 :         if (!BNXT_PF(bp)) {
    4120                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "NVM write not supported from a VF");
    4121                 :          0 :                 return -EINVAL;
    4122                 :            :         }
    4123                 :            : 
    4124                 :          0 :         type = in_eeprom->magic >> 16;
    4125                 :            : 
    4126         [ #  # ]:          0 :         if (type == 0xffff) { /* special value for directory operations */
    4127                 :          0 :                 index = in_eeprom->magic & 0xff;
    4128                 :          0 :                 dir_op = in_eeprom->magic >> 8;
    4129         [ #  # ]:          0 :                 if (index == 0)
    4130                 :            :                         return -EINVAL;
    4131         [ #  # ]:          0 :                 switch (dir_op) {
    4132                 :          0 :                 case 0x0e: /* erase */
    4133         [ #  # ]:          0 :                         if (in_eeprom->offset != ~in_eeprom->magic)
    4134                 :            :                                 return -EINVAL;
    4135                 :          0 :                         return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
    4136                 :            :                 default:
    4137                 :            :                         return -EINVAL;
    4138                 :            :                 }
    4139                 :            :         }
    4140                 :            : 
    4141                 :            :         /* Create or re-write an NVM item: */
    4142         [ #  # ]:          0 :         if (bnxt_dir_type_is_executable(type) == true)
    4143                 :            :                 return -EOPNOTSUPP;
    4144                 :            :         ext = in_eeprom->magic & 0xffff;
    4145                 :          0 :         ordinal = in_eeprom->offset >> 16;
    4146                 :            :         attr = in_eeprom->offset & 0xffff;
    4147                 :            : 
    4148                 :          0 :         return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
    4149                 :          0 :                                      in_eeprom->data, in_eeprom->length);
    4150                 :            : }
    4151                 :            : 
    4152                 :          0 : static int bnxt_get_module_info(struct rte_eth_dev *dev,
    4153                 :            :                                 struct rte_eth_dev_module_info *modinfo)
    4154                 :            : {
    4155                 :            :         uint8_t module_info[SFF_DIAG_SUPPORT_OFFSET + 1];
    4156                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4157                 :            :         int rc;
    4158                 :            : 
    4159                 :            :         /* No point in going further if phy status indicates
    4160                 :            :          * module is not inserted or if it is powered down or
    4161                 :            :          * if it is of type 10GBase-T
    4162                 :            :          */
    4163         [ #  # ]:          0 :         if (bp->link_info->module_status >
    4164                 :            :             HWRM_PORT_PHY_QCFG_OUTPUT_MODULE_STATUS_WARNINGMSG) {
    4165                 :          0 :                 PMD_DRV_LOG_LINE(NOTICE, "Port %u : Module is not inserted or is powered down",
    4166                 :            :                             dev->data->port_id);
    4167                 :          0 :                 return -ENOTSUP;
    4168                 :            :         }
    4169                 :            : 
    4170                 :            :         /* This feature is not supported in older firmware versions */
    4171         [ #  # ]:          0 :         if (bp->hwrm_spec_code < 0x10202) {
    4172                 :          0 :                 PMD_DRV_LOG_LINE(NOTICE, "Port %u : Feature is not supported in older firmware",
    4173                 :            :                             dev->data->port_id);
    4174                 :          0 :                 return -ENOTSUP;
    4175                 :            :         }
    4176                 :            : 
    4177                 :          0 :         rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
    4178                 :            :                                                    SFF_DIAG_SUPPORT_OFFSET + 1,
    4179                 :            :                                                    module_info);
    4180                 :            : 
    4181         [ #  # ]:          0 :         if (rc)
    4182                 :            :                 return rc;
    4183                 :            : 
    4184   [ #  #  #  # ]:          0 :         switch (module_info[0]) {
    4185                 :          0 :         case SFF_MODULE_ID_SFP:
    4186                 :          0 :                 modinfo->type = RTE_ETH_MODULE_SFF_8472;
    4187                 :          0 :                 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
    4188         [ #  # ]:          0 :                 if (module_info[SFF_DIAG_SUPPORT_OFFSET] == 0)
    4189                 :          0 :                         modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_LEN;
    4190                 :            :                 break;
    4191                 :          0 :         case SFF_MODULE_ID_QSFP:
    4192                 :            :         case SFF_MODULE_ID_QSFP_PLUS:
    4193                 :          0 :                 modinfo->type = RTE_ETH_MODULE_SFF_8436;
    4194                 :          0 :                 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_LEN;
    4195                 :          0 :                 break;
    4196                 :          0 :         case SFF_MODULE_ID_QSFP28:
    4197                 :          0 :                 modinfo->type = RTE_ETH_MODULE_SFF_8636;
    4198                 :          0 :                 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
    4199         [ #  # ]:          0 :                 if (module_info[SFF8636_FLATMEM_OFFSET] & SFF8636_FLATMEM_MASK)
    4200                 :          0 :                         modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_LEN;
    4201                 :            :                 break;
    4202                 :          0 :         default:
    4203                 :          0 :                 PMD_DRV_LOG_LINE(NOTICE, "Port %u : Unsupported module", dev->data->port_id);
    4204                 :          0 :                 return -ENOTSUP;
    4205                 :            :         }
    4206                 :            : 
    4207                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Port %u : modinfo->type = %d modinfo->eeprom_len = %d",
    4208                 :            :                     dev->data->port_id, modinfo->type, modinfo->eeprom_len);
    4209                 :            : 
    4210                 :          0 :         return 0;
    4211                 :            : }
    4212                 :            : 
    4213                 :          0 : static int bnxt_get_module_eeprom(struct rte_eth_dev *dev,
    4214                 :            :                                   struct rte_dev_eeprom_info *info)
    4215                 :            : {
    4216                 :          0 :         uint8_t pg_addr[5] = { I2C_DEV_ADDR_A0, I2C_DEV_ADDR_A0 };
    4217                 :          0 :         uint32_t offset = info->offset, length = info->length;
    4218                 :            :         uint8_t module_info[SFF_DIAG_SUPPORT_OFFSET + 1];
    4219                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4220                 :          0 :         uint8_t *data = info->data;
    4221                 :          0 :         uint8_t page = offset >> 7;
    4222                 :            :         uint8_t max_pages = 2;
    4223                 :            :         uint8_t opt_pages;
    4224                 :            :         int rc;
    4225                 :            : 
    4226                 :          0 :         rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
    4227                 :            :                                                    SFF_DIAG_SUPPORT_OFFSET + 1,
    4228                 :            :                                                    module_info);
    4229         [ #  # ]:          0 :         if (rc)
    4230                 :            :                 return rc;
    4231                 :            : 
    4232      [ #  #  # ]:          0 :         switch (module_info[0]) {
    4233                 :          0 :         case SFF_MODULE_ID_SFP:
    4234         [ #  # ]:          0 :                 if (module_info[SFF_DIAG_SUPPORT_OFFSET]) {
    4235                 :          0 :                         pg_addr[2] = I2C_DEV_ADDR_A2;
    4236                 :          0 :                         pg_addr[3] = I2C_DEV_ADDR_A2;
    4237                 :            :                         max_pages = 4;
    4238                 :            :                 }
    4239                 :            :                 break;
    4240                 :          0 :         case SFF_MODULE_ID_QSFP28:
    4241                 :          0 :                 rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
    4242                 :            :                                                            SFF8636_OPT_PAGES_OFFSET,
    4243                 :            :                                                            1, &opt_pages);
    4244         [ #  # ]:          0 :                 if (rc)
    4245                 :            :                         return rc;
    4246                 :            : 
    4247         [ #  # ]:          0 :                 if (opt_pages & SFF8636_PAGE1_MASK) {
    4248                 :          0 :                         pg_addr[2] = I2C_DEV_ADDR_A0;
    4249                 :            :                         max_pages = 3;
    4250                 :            :                 }
    4251         [ #  # ]:          0 :                 if (opt_pages & SFF8636_PAGE2_MASK) {
    4252                 :          0 :                         pg_addr[3] = I2C_DEV_ADDR_A0;
    4253                 :            :                         max_pages = 4;
    4254                 :            :                 }
    4255         [ #  # ]:          0 :                 if (~module_info[SFF8636_FLATMEM_OFFSET] & SFF8636_FLATMEM_MASK) {
    4256                 :          0 :                         pg_addr[4] = I2C_DEV_ADDR_A0;
    4257                 :            :                         max_pages = 5;
    4258                 :            :                 }
    4259                 :            :                 break;
    4260                 :            :         default:
    4261                 :            :                 break;
    4262                 :            :         }
    4263                 :            : 
    4264                 :          0 :         memset(data, 0, length);
    4265                 :            : 
    4266                 :          0 :         offset &= 0xff;
    4267         [ #  # ]:          0 :         while (length && page < max_pages) {
    4268         [ #  # ]:          0 :                 uint8_t raw_page = page ? page - 1 : 0;
    4269                 :            :                 uint16_t chunk;
    4270                 :            : 
    4271         [ #  # ]:          0 :                 if (pg_addr[page] == I2C_DEV_ADDR_A2)
    4272                 :            :                         raw_page = 0;
    4273         [ #  # ]:          0 :                 else if (page)
    4274                 :          0 :                         offset |= 0x80;
    4275                 :          0 :                 chunk = RTE_MIN(length, 256 - offset);
    4276                 :            : 
    4277         [ #  # ]:          0 :                 if (pg_addr[page]) {
    4278                 :          0 :                         rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, pg_addr[page],
    4279                 :            :                                                                    raw_page, offset,
    4280                 :            :                                                                    chunk, data);
    4281         [ #  # ]:          0 :                         if (rc)
    4282                 :          0 :                                 return rc;
    4283                 :            :                 }
    4284                 :            : 
    4285                 :          0 :                 data += chunk;
    4286                 :          0 :                 length -= chunk;
    4287                 :            :                 offset = 0;
    4288         [ #  # ]:          0 :                 page += 1 + (chunk > 128);
    4289                 :            :         }
    4290                 :            : 
    4291         [ #  # ]:          0 :         return length ? -EINVAL : 0;
    4292                 :            : }
    4293                 :            : 
    4294                 :            : #if (RTE_VERSION_NUM(22, 11, 0, 0) <= RTE_VERSION)
    4295                 :          0 : static int bnxt_speed_lanes_set(struct rte_eth_dev *dev, uint32_t speed_lanes)
    4296                 :            : {
    4297                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4298                 :            : 
    4299   [ #  #  #  #  :          0 :         if (!BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    4300                 :            :                 return -ENOTSUP;
    4301                 :            : 
    4302                 :          0 :         bp->link_info->pmd_speed_lanes = speed_lanes;
    4303                 :            : 
    4304                 :          0 :         return 0;
    4305                 :            : }
    4306                 :            : 
    4307                 :            : static uint32_t
    4308                 :          0 : bnxt_get_speed_lanes_capa(struct rte_eth_speed_lanes_capa *speed_lanes_capa,
    4309                 :            :                           uint32_t speed_capa)
    4310                 :            : {
    4311                 :            :         uint32_t speed_bit;
    4312                 :            :         uint32_t num = 0;
    4313                 :            :         uint32_t i;
    4314                 :            : 
    4315         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(speed_lanes_capa_tbl); i++) {
    4316                 :            :                 speed_bit =
    4317                 :          0 :                         rte_eth_speed_bitflag(speed_lanes_capa_tbl[i].speed,
    4318                 :            :                                               RTE_ETH_LINK_FULL_DUPLEX);
    4319         [ #  # ]:          0 :                 if ((speed_capa & speed_bit) == 0)
    4320                 :          0 :                         continue;
    4321                 :            : 
    4322                 :          0 :                 speed_lanes_capa[num].speed = speed_lanes_capa_tbl[i].speed;
    4323                 :          0 :                 speed_lanes_capa[num].capa = speed_lanes_capa_tbl[i].capa;
    4324                 :          0 :                 num++;
    4325                 :            :         }
    4326                 :            : 
    4327                 :          0 :         return num;
    4328                 :            : }
    4329                 :            : 
    4330                 :          0 : static int bnxt_speed_lanes_get_capa(struct rte_eth_dev *dev,
    4331                 :            :                                      struct rte_eth_speed_lanes_capa *speed_lanes_capa,
    4332                 :            :                                      unsigned int num)
    4333                 :            : {
    4334                 :          0 :         struct rte_eth_link *link = &dev->data->dev_link;
    4335                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4336                 :            :         unsigned int speed_num;
    4337                 :            :         uint32_t speed_capa;
    4338                 :            :         int rc;
    4339                 :            : 
    4340                 :          0 :         rc = is_bnxt_in_error(bp);
    4341         [ #  # ]:          0 :         if (rc)
    4342                 :            :                 return rc;
    4343                 :            : 
    4344   [ #  #  #  #  :          0 :         if (!BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    4345                 :            :                 return -ENOTSUP;
    4346                 :            : 
    4347                 :            :         /* speed_num counts number of speed capabilities.
    4348                 :            :          * When link is down, show the user choice all combinations of speeds x lanes
    4349                 :            :          */
    4350         [ #  # ]:          0 :         if (link->link_status) {
    4351                 :          0 :                 speed_capa = bnxt_get_speed_capabilities_v2(bp);
    4352         [ #  # ]:          0 :                 speed_num = rte_popcount32(speed_capa & BNXT_SPEEDS_SUPP_SPEED_LANES);
    4353                 :            :         } else {
    4354                 :            :                 speed_capa = BNXT_SPEEDS_SUPP_SPEED_LANES;
    4355                 :            :                 speed_num = rte_popcount32(BNXT_SPEEDS_SUPP_SPEED_LANES);
    4356                 :            :         }
    4357         [ #  # ]:          0 :         if (speed_num == 0)
    4358                 :            :                 return -ENOTSUP;
    4359                 :            : 
    4360         [ #  # ]:          0 :         if (speed_lanes_capa == NULL)
    4361                 :          0 :                 return speed_num;
    4362                 :            : 
    4363         [ #  # ]:          0 :         if (num < speed_num)
    4364                 :            :                 return -EINVAL;
    4365                 :            : 
    4366                 :          0 :         return bnxt_get_speed_lanes_capa(speed_lanes_capa, speed_capa);
    4367                 :            : }
    4368                 :            : 
    4369                 :          0 : static int bnxt_speed_lanes_get(struct rte_eth_dev *dev, uint32_t *lanes)
    4370                 :            : {
    4371                 :          0 :         struct rte_eth_link *link = &dev->data->dev_link;
    4372                 :          0 :         struct bnxt *bp = dev->data->dev_private;
    4373                 :            :         int rc;
    4374                 :            : 
    4375                 :          0 :         rc = is_bnxt_in_error(bp);
    4376         [ #  # ]:          0 :         if (rc)
    4377                 :            :                 return rc;
    4378                 :            : 
    4379   [ #  #  #  #  :          0 :         if (!BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    4380                 :            :                 return -ENOTSUP;
    4381                 :            : 
    4382         [ #  # ]:          0 :         if (!link->link_status)
    4383                 :            :                 return -EINVAL;
    4384                 :            : 
    4385                 :            :          /* user app expects lanes 1 for zero */
    4386                 :          0 :         *lanes = (bp->link_info->active_lanes) ?
    4387                 :            :                 bp->link_info->active_lanes : 1;
    4388                 :          0 :         return 0;
    4389                 :            : }
    4390                 :            : 
    4391                 :            : #endif
    4392                 :            : 
    4393                 :            : /*
    4394                 :            :  * Initialization
    4395                 :            :  */
    4396                 :            : 
    4397                 :            : static const struct eth_dev_ops bnxt_dev_ops = {
    4398                 :            :         .dev_infos_get = bnxt_dev_info_get_op,
    4399                 :            :         .dev_close = bnxt_dev_close_op,
    4400                 :            :         .dev_configure = bnxt_dev_configure_op,
    4401                 :            :         .dev_start = bnxt_dev_start_op,
    4402                 :            :         .dev_stop = bnxt_dev_stop_op,
    4403                 :            :         .dev_set_link_up = bnxt_dev_set_link_up_op,
    4404                 :            :         .dev_set_link_down = bnxt_dev_set_link_down_op,
    4405                 :            :         .stats_get = bnxt_stats_get_op,
    4406                 :            :         .stats_reset = bnxt_stats_reset_op,
    4407                 :            :         .rx_queue_setup = bnxt_rx_queue_setup_op,
    4408                 :            :         .rx_queue_release = bnxt_rx_queue_release_op,
    4409                 :            :         .tx_queue_setup = bnxt_tx_queue_setup_op,
    4410                 :            :         .tx_queue_release = bnxt_tx_queue_release_op,
    4411                 :            :         .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
    4412                 :            :         .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
    4413                 :            :         .reta_update = bnxt_reta_update_op,
    4414                 :            :         .reta_query = bnxt_reta_query_op,
    4415                 :            :         .rss_hash_update = bnxt_rss_hash_update_op,
    4416                 :            :         .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
    4417                 :            :         .link_update = bnxt_link_update_op,
    4418                 :            :         .promiscuous_enable = bnxt_promiscuous_enable_op,
    4419                 :            :         .promiscuous_disable = bnxt_promiscuous_disable_op,
    4420                 :            :         .allmulticast_enable = bnxt_allmulticast_enable_op,
    4421                 :            :         .allmulticast_disable = bnxt_allmulticast_disable_op,
    4422                 :            :         .mac_addr_add = bnxt_mac_addr_add_op,
    4423                 :            :         .mac_addr_remove = bnxt_mac_addr_remove_op,
    4424                 :            :         .flow_ctrl_get = bnxt_flow_ctrl_get_op,
    4425                 :            :         .flow_ctrl_set = bnxt_flow_ctrl_set_op,
    4426                 :            :         .udp_tunnel_port_add  = bnxt_udp_tunnel_port_add_op,
    4427                 :            :         .udp_tunnel_port_del  = bnxt_udp_tunnel_port_del_op,
    4428                 :            :         .vlan_filter_set = bnxt_vlan_filter_set_op,
    4429                 :            :         .vlan_offload_set = bnxt_vlan_offload_set_op,
    4430                 :            :         .vlan_tpid_set = bnxt_vlan_tpid_set_op,
    4431                 :            :         .vlan_pvid_set = bnxt_vlan_pvid_set_op,
    4432                 :            :         .mtu_set = bnxt_mtu_set_op,
    4433                 :            :         .mac_addr_set = bnxt_set_default_mac_addr_op,
    4434                 :            :         .xstats_get = bnxt_dev_xstats_get_op,
    4435                 :            :         .xstats_get_names = bnxt_dev_xstats_get_names_op,
    4436                 :            :         .xstats_reset = bnxt_dev_xstats_reset_op,
    4437                 :            :         .fw_version_get = bnxt_fw_version_get,
    4438                 :            :         .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
    4439                 :            :         .rxq_info_get = bnxt_rxq_info_get_op,
    4440                 :            :         .txq_info_get = bnxt_txq_info_get_op,
    4441                 :            :         .rx_burst_mode_get = bnxt_rx_burst_mode_get,
    4442                 :            :         .tx_burst_mode_get = bnxt_tx_burst_mode_get,
    4443                 :            :         .dev_led_on = bnxt_dev_led_on_op,
    4444                 :            :         .dev_led_off = bnxt_dev_led_off_op,
    4445                 :            :         .rx_queue_start = bnxt_rx_queue_start,
    4446                 :            :         .rx_queue_stop = bnxt_rx_queue_stop,
    4447                 :            :         .tx_queue_start = bnxt_tx_queue_start,
    4448                 :            :         .tx_queue_stop = bnxt_tx_queue_stop,
    4449                 :            :         .flow_ops_get = bnxt_flow_ops_get_op,
    4450                 :            :         .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
    4451                 :            :         .get_eeprom_length    = bnxt_get_eeprom_length_op,
    4452                 :            :         .get_eeprom           = bnxt_get_eeprom_op,
    4453                 :            :         .set_eeprom           = bnxt_set_eeprom_op,
    4454                 :            :         .get_module_info = bnxt_get_module_info,
    4455                 :            :         .get_module_eeprom = bnxt_get_module_eeprom,
    4456                 :            :         .timesync_enable      = bnxt_timesync_enable,
    4457                 :            :         .timesync_disable     = bnxt_timesync_disable,
    4458                 :            :         .timesync_read_time   = bnxt_timesync_read_time,
    4459                 :            :         .timesync_write_time   = bnxt_timesync_write_time,
    4460                 :            :         .timesync_adjust_time = bnxt_timesync_adjust_time,
    4461                 :            :         .timesync_read_rx_timestamp = bnxt_timesync_read_rx_timestamp,
    4462                 :            :         .timesync_read_tx_timestamp = bnxt_timesync_read_tx_timestamp,
    4463                 :            :         .mtr_ops_get = bnxt_flow_meter_ops_get,
    4464                 :            : #if (RTE_VERSION_NUM(22, 11, 0, 0) <= RTE_VERSION)
    4465                 :            :         .speed_lanes_get = bnxt_speed_lanes_get,
    4466                 :            :         .speed_lanes_set = bnxt_speed_lanes_set,
    4467                 :            :         .speed_lanes_get_capa = bnxt_speed_lanes_get_capa,
    4468                 :            : #endif
    4469                 :            : };
    4470                 :            : 
    4471                 :            : static uint32_t bnxt_map_reset_regs(struct bnxt *bp, uint32_t reg)
    4472                 :            : {
    4473                 :            :         uint32_t offset;
    4474                 :            : 
    4475                 :            :         /* Only pre-map the reset GRC registers using window 3 */
    4476                 :          0 :         rte_write32(reg & 0xfffff000, (uint8_t *)bp->bar0 +
    4477                 :            :                     BNXT_GRCPF_REG_WINDOW_BASE_OUT + 8);
    4478                 :            : 
    4479                 :          0 :         offset = BNXT_GRCP_WINDOW_3_BASE + (reg & 0xffc);
    4480                 :            : 
    4481                 :            :         return offset;
    4482                 :            : }
    4483                 :            : 
    4484                 :          0 : int bnxt_map_fw_health_status_regs(struct bnxt *bp)
    4485                 :            : {
    4486                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4487                 :            :         uint32_t reg_base = 0xffffffff;
    4488                 :            :         int i;
    4489                 :            : 
    4490                 :            :         /* Only pre-map the monitoring GRC registers using window 2 */
    4491         [ #  # ]:          0 :         for (i = 0; i < BNXT_FW_STATUS_REG_CNT; i++) {
    4492                 :          0 :                 uint32_t reg = info->status_regs[i];
    4493                 :            : 
    4494         [ #  # ]:          0 :                 if (BNXT_FW_STATUS_REG_TYPE(reg) != BNXT_FW_STATUS_REG_TYPE_GRC)
    4495                 :          0 :                         continue;
    4496                 :            : 
    4497         [ #  # ]:          0 :                 if (reg_base == 0xffffffff)
    4498                 :          0 :                         reg_base = reg & 0xfffff000;
    4499         [ #  # ]:          0 :                 if ((reg & 0xfffff000) != reg_base)
    4500                 :            :                         return -ERANGE;
    4501                 :            : 
    4502                 :            :                 /* Use mask 0xffc as the Lower 2 bits indicates
    4503                 :            :                  * address space location
    4504                 :            :                  */
    4505                 :          0 :                 info->mapped_status_regs[i] = BNXT_GRCP_WINDOW_2_BASE +
    4506                 :          0 :                                                 (reg & 0xffc);
    4507                 :            :         }
    4508                 :            : 
    4509         [ #  # ]:          0 :         if (reg_base == 0xffffffff)
    4510                 :            :                 return 0;
    4511                 :            : 
    4512                 :          0 :         rte_write32(reg_base, (uint8_t *)bp->bar0 +
    4513                 :            :                     BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
    4514                 :            : 
    4515                 :          0 :         return 0;
    4516                 :            : }
    4517                 :            : 
    4518                 :          0 : static void bnxt_write_fw_reset_reg(struct bnxt *bp, uint32_t index)
    4519                 :            : {
    4520                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4521                 :          0 :         uint32_t delay = info->delay_after_reset[index];
    4522                 :          0 :         uint32_t val = info->reset_reg_val[index];
    4523                 :          0 :         uint32_t reg = info->reset_reg[index];
    4524                 :            :         uint32_t type, offset;
    4525                 :            :         int ret;
    4526                 :            : 
    4527                 :          0 :         type = BNXT_FW_STATUS_REG_TYPE(reg);
    4528                 :          0 :         offset = BNXT_FW_STATUS_REG_OFF(reg);
    4529                 :            : 
    4530   [ #  #  #  # ]:          0 :         switch (type) {
    4531                 :          0 :         case BNXT_FW_STATUS_REG_TYPE_CFG:
    4532                 :          0 :                 ret = rte_pci_write_config(bp->pdev, &val, sizeof(val), offset);
    4533         [ #  # ]:          0 :                 if (ret < 0) {
    4534                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to write %#x at PCI offset %#x",
    4535                 :            :                                     val, offset);
    4536                 :          0 :                         return;
    4537                 :            :                 }
    4538                 :            :                 break;
    4539                 :            :         case BNXT_FW_STATUS_REG_TYPE_GRC:
    4540                 :            :                 offset = bnxt_map_reset_regs(bp, offset);
    4541                 :          0 :                 rte_write32(val, (uint8_t *)bp->bar0 + offset);
    4542                 :            :                 break;
    4543                 :          0 :         case BNXT_FW_STATUS_REG_TYPE_BAR0:
    4544                 :          0 :                 rte_write32(val, (uint8_t *)bp->bar0 + offset);
    4545                 :            :                 break;
    4546                 :            :         }
    4547                 :            :         /* wait on a specific interval of time until core reset is complete */
    4548         [ #  # ]:          0 :         if (delay)
    4549                 :            :                 rte_delay_ms(delay);
    4550                 :            : }
    4551                 :            : 
    4552                 :          0 : static void bnxt_dev_cleanup(struct bnxt *bp)
    4553                 :            : {
    4554                 :          0 :         bp->eth_dev->data->dev_link.link_status = 0;
    4555                 :          0 :         bp->link_info->link_up = 0;
    4556         [ #  # ]:          0 :         if (bp->eth_dev->data->dev_started)
    4557                 :          0 :                 bnxt_dev_stop(bp->eth_dev);
    4558                 :            : 
    4559                 :          0 :         bnxt_uninit_resources(bp, true);
    4560                 :          0 : }
    4561                 :            : 
    4562                 :            : static int
    4563                 :          0 : bnxt_check_fw_reset_done(struct bnxt *bp)
    4564                 :            : {
    4565                 :          0 :         int timeout = bp->fw_reset_max_msecs;
    4566                 :          0 :         uint16_t val = 0;
    4567                 :            :         int rc;
    4568                 :            : 
    4569                 :            :         do {
    4570                 :          0 :                 rc = rte_pci_read_config(bp->pdev, &val, sizeof(val), PCI_SUBSYSTEM_ID_OFFSET);
    4571         [ #  # ]:          0 :                 if (rc < 0) {
    4572                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset 0x%x",
    4573                 :            :                                 PCI_SUBSYSTEM_ID_OFFSET);
    4574                 :          0 :                         return rc;
    4575                 :            :                 }
    4576         [ #  # ]:          0 :                 if (val != 0xffff)
    4577                 :            :                         break;
    4578                 :            :                 rte_delay_ms(1);
    4579         [ #  # ]:          0 :         } while (timeout--);
    4580                 :            : 
    4581         [ #  # ]:          0 :         if (val == 0xffff) {
    4582                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Firmware reset aborted, PCI config space invalid");
    4583                 :          0 :                 return -1;
    4584                 :            :         }
    4585                 :            : 
    4586                 :            :         return 0;
    4587                 :            : }
    4588                 :            : 
    4589                 :          0 : static int bnxt_restore_vlan_filters(struct bnxt *bp)
    4590                 :            : {
    4591                 :          0 :         struct rte_eth_dev *dev = bp->eth_dev;
    4592                 :            :         struct rte_vlan_filter_conf *vfc;
    4593                 :            :         int vidx, vbit, rc;
    4594                 :            :         uint16_t vlan_id;
    4595                 :            : 
    4596         [ #  # ]:          0 :         for (vlan_id = 1; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
    4597                 :          0 :                 vfc = &dev->data->vlan_filter_conf;
    4598                 :          0 :                 vidx = vlan_id / 64;
    4599                 :          0 :                 vbit = vlan_id % 64;
    4600                 :            : 
    4601                 :            :                 /* Each bit corresponds to a VLAN id */
    4602         [ #  # ]:          0 :                 if (vfc->ids[vidx] & (UINT64_C(1) << vbit)) {
    4603                 :          0 :                         rc = bnxt_add_vlan_filter(bp, vlan_id);
    4604         [ #  # ]:          0 :                         if (rc)
    4605                 :          0 :                                 return rc;
    4606                 :            :                 }
    4607                 :            :         }
    4608                 :            : 
    4609                 :            :         return 0;
    4610                 :            : }
    4611                 :            : 
    4612                 :          0 : static int bnxt_restore_mac_filters(struct bnxt *bp)
    4613                 :            : {
    4614                 :          0 :         struct rte_eth_dev *dev = bp->eth_dev;
    4615                 :            :         struct rte_eth_dev_info dev_info;
    4616                 :            :         struct rte_ether_addr *addr;
    4617                 :            :         uint64_t pool_mask;
    4618                 :            :         uint32_t pool = 0;
    4619                 :            :         uint32_t i;
    4620                 :            :         int rc;
    4621                 :            : 
    4622         [ #  # ]:          0 :         if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
    4623                 :            :                 return 0;
    4624                 :            : 
    4625                 :          0 :         rc = bnxt_dev_info_get_op(dev, &dev_info);
    4626         [ #  # ]:          0 :         if (rc)
    4627                 :            :                 return rc;
    4628                 :            : 
    4629                 :            :         /* replay MAC address configuration */
    4630         [ #  # ]:          0 :         for (i = 1; i < dev_info.max_mac_addrs; i++) {
    4631         [ #  # ]:          0 :                 addr = &dev->data->mac_addrs[i];
    4632                 :            : 
    4633                 :            :                 /* skip zero address */
    4634         [ #  # ]:          0 :                 if (rte_is_zero_ether_addr(addr))
    4635                 :          0 :                         continue;
    4636                 :            : 
    4637                 :            :                 pool = 0;
    4638                 :          0 :                 pool_mask = dev->data->mac_pool_sel[i];
    4639                 :            : 
    4640                 :            :                 do {
    4641         [ #  # ]:          0 :                         if (pool_mask & 1ULL) {
    4642                 :          0 :                                 rc = bnxt_mac_addr_add_op(dev, addr, i, pool);
    4643         [ #  # ]:          0 :                                 if (rc)
    4644                 :          0 :                                         return rc;
    4645                 :            :                         }
    4646                 :          0 :                         pool_mask >>= 1;
    4647                 :          0 :                         pool++;
    4648         [ #  # ]:          0 :                 } while (pool_mask);
    4649                 :            :         }
    4650                 :            : 
    4651                 :            :         return 0;
    4652                 :            : }
    4653                 :            : 
    4654                 :          0 : static int bnxt_restore_mcast_mac_filters(struct bnxt *bp)
    4655                 :            : {
    4656                 :            :         int ret = 0;
    4657                 :            : 
    4658                 :          0 :         ret = bnxt_dev_set_mc_addr_list_op(bp->eth_dev, bp->mcast_addr_list,
    4659                 :            :                                            bp->nb_mc_addr);
    4660         [ #  # ]:          0 :         if (ret)
    4661                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to restore multicast MAC addreeses");
    4662                 :            : 
    4663                 :          0 :         return ret;
    4664                 :            : }
    4665                 :            : 
    4666                 :          0 : static int bnxt_restore_filters(struct bnxt *bp)
    4667                 :            : {
    4668                 :          0 :         struct rte_eth_dev *dev = bp->eth_dev;
    4669                 :            :         int ret = 0;
    4670                 :            : 
    4671         [ #  # ]:          0 :         if (dev->data->all_multicast) {
    4672                 :          0 :                 ret = bnxt_allmulticast_enable_op(dev);
    4673         [ #  # ]:          0 :                 if (ret)
    4674                 :            :                         return ret;
    4675                 :            :         }
    4676         [ #  # ]:          0 :         if (dev->data->promiscuous) {
    4677                 :          0 :                 ret = bnxt_promiscuous_enable_op(dev);
    4678         [ #  # ]:          0 :                 if (ret)
    4679                 :            :                         return ret;
    4680                 :            :         }
    4681                 :            : 
    4682                 :          0 :         ret = bnxt_restore_mac_filters(bp);
    4683         [ #  # ]:          0 :         if (ret)
    4684                 :            :                 return ret;
    4685                 :            : 
    4686                 :            :         /* if vlans are already programmed, this can fail with -EEXIST */
    4687                 :          0 :         ret = bnxt_restore_vlan_filters(bp);
    4688         [ #  # ]:          0 :         if (ret && ret != -EEXIST)
    4689                 :            :                 return ret;
    4690                 :            : 
    4691                 :          0 :         ret = bnxt_restore_mcast_mac_filters(bp);
    4692         [ #  # ]:          0 :         if (ret)
    4693                 :          0 :                 return ret;
    4694                 :            : 
    4695                 :            :         return ret;
    4696                 :            : }
    4697                 :            : 
    4698                 :          0 : static int bnxt_check_fw_ready(struct bnxt *bp)
    4699                 :            : {
    4700         [ #  # ]:          0 :         int timeout = bp->fw_reset_max_msecs ? : BNXT_MAX_FW_RESET_TIMEOUT;
    4701                 :            :         int rc = 0;
    4702                 :            : 
    4703                 :            :         do {
    4704                 :          0 :                 rc = bnxt_hwrm_poll_ver_get(bp);
    4705         [ #  # ]:          0 :                 if (rc == 0)
    4706                 :            :                         break;
    4707                 :            :                 rte_delay_ms(BNXT_FW_READY_WAIT_INTERVAL);
    4708                 :          0 :                 timeout -= BNXT_FW_READY_WAIT_INTERVAL;
    4709         [ #  # ]:          0 :         } while (rc && timeout > 0);
    4710                 :            : 
    4711         [ #  # ]:          0 :         if (rc)
    4712                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "FW is not Ready after reset");
    4713                 :            : 
    4714                 :          0 :         return rc;
    4715                 :            : }
    4716                 :            : 
    4717                 :          0 : static void bnxt_dev_recover(void *arg)
    4718                 :            : {
    4719                 :            :         struct bnxt *bp = arg;
    4720                 :            :         int rc = 0;
    4721                 :            : 
    4722                 :          0 :         pthread_mutex_lock(&bp->err_recovery_lock);
    4723                 :            : 
    4724         [ #  # ]:          0 :         if (!bp->fw_reset_min_msecs) {
    4725                 :          0 :                 rc = bnxt_check_fw_reset_done(bp);
    4726         [ #  # ]:          0 :                 if (rc)
    4727                 :          0 :                         goto err;
    4728                 :            :         }
    4729                 :            : 
    4730                 :            :         /* Clear Error flag so that device re-init should happen */
    4731                 :          0 :         bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
    4732                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Port: %u Starting recovery...",
    4733                 :            :                     bp->eth_dev->data->port_id);
    4734                 :            : 
    4735                 :          0 :         rc = bnxt_check_fw_ready(bp);
    4736         [ #  # ]:          0 :         if (rc)
    4737                 :          0 :                 goto err;
    4738                 :            : 
    4739                 :          0 :         rc = bnxt_init_resources(bp, true);
    4740         [ #  # ]:          0 :         if (rc) {
    4741                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    4742                 :            :                             "Failed to initialize resources after reset");
    4743                 :          0 :                 goto err;
    4744                 :            :         }
    4745                 :            :         /* clear reset flag as the device is initialized now */
    4746                 :          0 :         bp->flags &= ~BNXT_FLAG_FW_RESET;
    4747                 :            : 
    4748                 :          0 :         rc = bnxt_dev_start_op(bp->eth_dev);
    4749         [ #  # ]:          0 :         if (rc) {
    4750                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to start port after reset");
    4751                 :          0 :                 goto err_start;
    4752                 :            :         }
    4753                 :            : 
    4754                 :          0 :         rc = bnxt_restore_filters(bp);
    4755         [ #  # ]:          0 :         if (rc)
    4756                 :          0 :                 goto err_start;
    4757                 :            : 
    4758                 :          0 :         rte_eth_fp_ops[bp->eth_dev->data->port_id].rx_pkt_burst =
    4759                 :          0 :                 bp->eth_dev->rx_pkt_burst;
    4760                 :          0 :         rte_eth_fp_ops[bp->eth_dev->data->port_id].tx_pkt_burst =
    4761                 :          0 :                 bp->eth_dev->tx_pkt_burst;
    4762                 :            :         rte_mb();
    4763                 :            : 
    4764                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Port: %u Recovered from FW reset",
    4765                 :            :                     bp->eth_dev->data->port_id);
    4766                 :          0 :         pthread_mutex_unlock(&bp->err_recovery_lock);
    4767                 :          0 :         rte_eth_dev_callback_process(bp->eth_dev,
    4768                 :            :                                      RTE_ETH_EVENT_RECOVERY_SUCCESS,
    4769                 :            :                                      NULL);
    4770                 :          0 :         return;
    4771                 :          0 : err_start:
    4772                 :          0 :         bnxt_dev_stop(bp->eth_dev);
    4773                 :          0 : err:
    4774                 :          0 :         bp->flags |= BNXT_FLAG_FATAL_ERROR;
    4775                 :          0 :         bnxt_uninit_resources(bp, false);
    4776                 :          0 :         rte_eth_dev_callback_process(bp->eth_dev,
    4777                 :            :                                      RTE_ETH_EVENT_RECOVERY_FAILED,
    4778                 :            :                                      NULL);
    4779         [ #  # ]:          0 :         if (bp->eth_dev->data->dev_conf.intr_conf.rmv)
    4780                 :          0 :                 rte_eth_dev_callback_process(bp->eth_dev,
    4781                 :            :                                              RTE_ETH_EVENT_INTR_RMV,
    4782                 :            :                                              NULL);
    4783                 :          0 :         pthread_mutex_unlock(&bp->err_recovery_lock);
    4784                 :          0 :         PMD_DRV_LOG_LINE(ERR, "Port %u: Failed to recover from FW reset",
    4785                 :            :                     bp->eth_dev->data->port_id);
    4786                 :            : }
    4787                 :            : 
    4788                 :          0 : void bnxt_dev_reset_and_resume(void *arg)
    4789                 :            : {
    4790                 :            :         struct bnxt *bp = arg;
    4791                 :          0 :         uint32_t us = US_PER_MS * bp->fw_reset_min_msecs;
    4792                 :          0 :         uint16_t val = 0;
    4793                 :            :         int rc;
    4794                 :            : 
    4795                 :          0 :         bnxt_dev_cleanup(bp);
    4796                 :          0 :         PMD_DRV_LOG_LINE(INFO, "Port: %u Finished bnxt_dev_cleanup",
    4797                 :            :                     bp->eth_dev->data->port_id);
    4798                 :            : 
    4799                 :          0 :         bnxt_wait_for_device_shutdown(bp);
    4800                 :            : 
    4801                 :            :         /* During some fatal firmware error conditions, the PCI config space
    4802                 :            :          * register 0x2e which normally contains the subsystem ID will become
    4803                 :            :          * 0xffff. This register will revert back to the normal value after
    4804                 :            :          * the chip has completed core reset. If we detect this condition,
    4805                 :            :          * we can poll this config register immediately for the value to revert.
    4806                 :            :          */
    4807         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FATAL_ERROR) {
    4808                 :          0 :                 rc = rte_pci_read_config(bp->pdev, &val, sizeof(val), PCI_SUBSYSTEM_ID_OFFSET);
    4809         [ #  # ]:          0 :                 if (rc < 0) {
    4810                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset 0x%x",
    4811                 :            :                                 PCI_SUBSYSTEM_ID_OFFSET);
    4812                 :          0 :                         return;
    4813                 :            :                 }
    4814         [ #  # ]:          0 :                 if (val == 0xffff) {
    4815                 :          0 :                         bp->fw_reset_min_msecs = 0;
    4816                 :            :                         us = 1;
    4817                 :            :                 }
    4818                 :            :         }
    4819                 :            : 
    4820                 :          0 :         rc = rte_eal_alarm_set(us, bnxt_dev_recover, (void *)bp);
    4821         [ #  # ]:          0 :         if (rc)
    4822                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Port %u: Error setting recovery alarm",
    4823                 :            :                             bp->eth_dev->data->port_id);
    4824                 :            : }
    4825                 :            : 
    4826                 :          0 : uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
    4827                 :            : {
    4828                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4829                 :          0 :         uint32_t reg = info->status_regs[index];
    4830                 :          0 :         uint32_t type, offset, val = 0;
    4831                 :            :         int ret = 0;
    4832                 :            : 
    4833                 :          0 :         type = BNXT_FW_STATUS_REG_TYPE(reg);
    4834                 :          0 :         offset = BNXT_FW_STATUS_REG_OFF(reg);
    4835                 :            : 
    4836   [ #  #  #  # ]:          0 :         switch (type) {
    4837                 :          0 :         case BNXT_FW_STATUS_REG_TYPE_CFG:
    4838                 :          0 :                 ret = rte_pci_read_config(bp->pdev, &val, sizeof(val), offset);
    4839         [ #  # ]:          0 :                 if (ret < 0)
    4840                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset %#x",
    4841                 :            :                                     offset);
    4842                 :            :                 break;
    4843                 :          0 :         case BNXT_FW_STATUS_REG_TYPE_GRC:
    4844                 :          0 :                 offset = info->mapped_status_regs[index];
    4845                 :            :                 /* FALLTHROUGH */
    4846                 :          0 :         case BNXT_FW_STATUS_REG_TYPE_BAR0:
    4847                 :          0 :                 val = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    4848                 :            :                                        offset));
    4849                 :          0 :                 break;
    4850                 :            :         }
    4851                 :            : 
    4852                 :          0 :         return val;
    4853                 :            : }
    4854                 :            : 
    4855                 :          0 : static int bnxt_fw_reset_all(struct bnxt *bp)
    4856                 :            : {
    4857                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4858                 :            :         uint32_t i;
    4859                 :            :         int rc = 0;
    4860                 :            : 
    4861         [ #  # ]:          0 :         if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
    4862                 :            :                 /* Reset through primary function driver */
    4863         [ #  # ]:          0 :                 for (i = 0; i < info->reg_array_cnt; i++)
    4864                 :          0 :                         bnxt_write_fw_reset_reg(bp, i);
    4865                 :            :                 /* Wait for time specified by FW after triggering reset */
    4866                 :          0 :                 rte_delay_ms(info->primary_func_wait_period_after_reset);
    4867         [ #  # ]:          0 :         } else if (info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) {
    4868                 :            :                 /* Reset with the help of Kong processor */
    4869                 :          0 :                 rc = bnxt_hwrm_fw_reset(bp);
    4870         [ #  # ]:          0 :                 if (rc)
    4871                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to reset FW");
    4872                 :            :         }
    4873                 :            : 
    4874                 :          0 :         return rc;
    4875                 :            : }
    4876                 :            : 
    4877                 :          0 : static void bnxt_fw_reset_cb(void *arg)
    4878                 :            : {
    4879                 :            :         struct bnxt *bp = arg;
    4880                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4881                 :            :         int rc = 0;
    4882                 :            : 
    4883                 :            :         /* Only Primary function can do FW reset */
    4884   [ #  #  #  # ]:          0 :         if (bnxt_is_primary_func(bp) &&
    4885                 :          0 :             bnxt_is_recovery_enabled(bp)) {
    4886                 :          0 :                 rc = bnxt_fw_reset_all(bp);
    4887         [ #  # ]:          0 :                 if (rc) {
    4888                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Adapter recovery failed");
    4889                 :          0 :                         return;
    4890                 :            :                 }
    4891                 :            :         }
    4892                 :            : 
    4893                 :            :         /* if recovery method is ERROR_RECOVERY_CO_CPU, KONG will send
    4894                 :            :          * EXCEPTION_FATAL_ASYNC event to all the functions
    4895                 :            :          * (including MASTER FUNC). After receiving this Async, all the active
    4896                 :            :          * drivers should treat this case as FW initiated recovery
    4897                 :            :          */
    4898         [ #  # ]:          0 :         if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
    4899                 :          0 :                 bp->fw_reset_min_msecs = BNXT_MIN_FW_READY_TIMEOUT;
    4900                 :          0 :                 bp->fw_reset_max_msecs = BNXT_MAX_FW_RESET_TIMEOUT;
    4901                 :            : 
    4902                 :            :                 /* To recover from error */
    4903                 :          0 :                 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
    4904                 :            :                                   (void *)bp);
    4905                 :            :         }
    4906                 :            : }
    4907                 :            : 
    4908                 :            : /* Driver should poll FW heartbeat, reset_counter with the frequency
    4909                 :            :  * advertised by FW in HWRM_ERROR_RECOVERY_QCFG.
    4910                 :            :  * When the driver detects heartbeat stop or change in reset_counter,
    4911                 :            :  * it has to trigger a reset to recover from the error condition.
    4912                 :            :  * A “primary function” is the function who will have the privilege to
    4913                 :            :  * initiate the chimp reset. The primary function will be elected by the
    4914                 :            :  * firmware and will be notified through async message.
    4915                 :            :  */
    4916                 :          0 : static void bnxt_check_fw_health(void *arg)
    4917                 :            : {
    4918                 :            :         struct bnxt *bp = arg;
    4919                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    4920                 :            :         uint32_t val = 0, wait_msec;
    4921                 :            : 
    4922   [ #  #  #  #  :          0 :         if (!info || !bnxt_is_recovery_enabled(bp) ||
                   #  # ]
    4923                 :          0 :             is_bnxt_in_error(bp))
    4924                 :          0 :                 return;
    4925                 :            : 
    4926                 :          0 :         val = bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
    4927         [ #  # ]:          0 :         if (val == info->last_heart_beat)
    4928                 :          0 :                 goto reset;
    4929                 :            : 
    4930                 :          0 :         info->last_heart_beat = val;
    4931                 :            : 
    4932                 :          0 :         val = bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
    4933         [ #  # ]:          0 :         if (val != info->last_reset_counter)
    4934                 :          0 :                 goto reset;
    4935                 :            : 
    4936                 :          0 :         info->last_reset_counter = val;
    4937                 :            : 
    4938                 :          0 :         rte_eal_alarm_set(US_PER_MS * info->driver_polling_freq,
    4939                 :            :                           bnxt_check_fw_health, (void *)bp);
    4940                 :            : 
    4941                 :          0 :         return;
    4942                 :          0 : reset:
    4943                 :            :         /* Stop DMA to/from device */
    4944                 :          0 :         bp->flags |= BNXT_FLAG_FATAL_ERROR;
    4945                 :          0 :         bp->flags |= BNXT_FLAG_FW_RESET;
    4946                 :            : 
    4947                 :          0 :         bnxt_stop_rxtx(bp->eth_dev);
    4948                 :            : 
    4949                 :          0 :         PMD_DRV_LOG_LINE(ERR, "Detected FW dead condition");
    4950                 :            : 
    4951                 :          0 :         rte_eth_dev_callback_process(bp->eth_dev,
    4952                 :            :                                      RTE_ETH_EVENT_ERR_RECOVERING,
    4953                 :            :                                      NULL);
    4954                 :            : 
    4955         [ #  # ]:          0 :         if (bnxt_is_primary_func(bp))
    4956                 :          0 :                 wait_msec = info->primary_func_wait_period;
    4957                 :            :         else
    4958                 :          0 :                 wait_msec = info->normal_func_wait_period;
    4959                 :            : 
    4960                 :          0 :         rte_eal_alarm_set(US_PER_MS * wait_msec,
    4961                 :            :                           bnxt_fw_reset_cb, (void *)bp);
    4962                 :            : }
    4963                 :            : 
    4964                 :          0 : void bnxt_schedule_fw_health_check(struct bnxt *bp)
    4965                 :            : {
    4966                 :            :         uint32_t polling_freq;
    4967                 :            : 
    4968                 :          0 :         pthread_mutex_lock(&bp->health_check_lock);
    4969                 :            : 
    4970         [ #  # ]:          0 :         if (!bnxt_is_recovery_enabled(bp))
    4971                 :          0 :                 goto done;
    4972                 :            : 
    4973         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
    4974                 :          0 :                 goto done;
    4975                 :            : 
    4976                 :          0 :         polling_freq = bp->recovery_info->driver_polling_freq;
    4977                 :            : 
    4978                 :          0 :         rte_eal_alarm_set(US_PER_MS * polling_freq,
    4979                 :            :                           bnxt_check_fw_health, (void *)bp);
    4980                 :          0 :         bp->flags |= BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
    4981                 :            : 
    4982                 :          0 : done:
    4983                 :          0 :         pthread_mutex_unlock(&bp->health_check_lock);
    4984                 :          0 : }
    4985                 :            : 
    4986                 :            : static void bnxt_cancel_fw_health_check(struct bnxt *bp)
    4987                 :            : {
    4988                 :          0 :         rte_eal_alarm_cancel(bnxt_check_fw_health, (void *)bp);
    4989         [ #  # ]:          0 :         bp->flags &= ~BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
    4990                 :            : }
    4991                 :            : 
    4992                 :          0 : static bool bnxt_vf_pciid(uint16_t device_id)
    4993                 :            : {
    4994         [ #  # ]:          0 :         switch (device_id) {
    4995                 :            :         case BROADCOM_DEV_ID_57304_VF:
    4996                 :            :         case BROADCOM_DEV_ID_57406_VF:
    4997                 :            :         case BROADCOM_DEV_ID_5731X_VF:
    4998                 :            :         case BROADCOM_DEV_ID_5741X_VF:
    4999                 :            :         case BROADCOM_DEV_ID_57414_VF:
    5000                 :            :         case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
    5001                 :            :         case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
    5002                 :            :         case BROADCOM_DEV_ID_58802_VF:
    5003                 :            :         case BROADCOM_DEV_ID_57500_VF1:
    5004                 :            :         case BROADCOM_DEV_ID_57500_VF2:
    5005                 :            :         case BROADCOM_DEV_ID_58818_VF:
    5006                 :            :         case BROADCOM_DEV_ID_5760X_VF:
    5007                 :            :                 /* FALLTHROUGH */
    5008                 :            :                 return true;
    5009                 :          0 :         default:
    5010                 :          0 :                 return false;
    5011                 :            :         }
    5012                 :            : }
    5013                 :            : 
    5014                 :            : /* Phase 5 device */
    5015                 :            : static bool bnxt_p5_device(uint16_t device_id)
    5016                 :            : {
    5017         [ #  # ]:          0 :         switch (device_id) {
    5018                 :            :         case BROADCOM_DEV_ID_57508:
    5019                 :            :         case BROADCOM_DEV_ID_57504:
    5020                 :            :         case BROADCOM_DEV_ID_57502:
    5021                 :            :         case BROADCOM_DEV_ID_57508_MF1:
    5022                 :            :         case BROADCOM_DEV_ID_57504_MF1:
    5023                 :            :         case BROADCOM_DEV_ID_57502_MF1:
    5024                 :            :         case BROADCOM_DEV_ID_57508_MF2:
    5025                 :            :         case BROADCOM_DEV_ID_57504_MF2:
    5026                 :            :         case BROADCOM_DEV_ID_57502_MF2:
    5027                 :            :         case BROADCOM_DEV_ID_57500_VF1:
    5028                 :            :         case BROADCOM_DEV_ID_57500_VF2:
    5029                 :            :         case BROADCOM_DEV_ID_58812:
    5030                 :            :         case BROADCOM_DEV_ID_58814:
    5031                 :            :         case BROADCOM_DEV_ID_58818:
    5032                 :            :                 /* FALLTHROUGH */
    5033                 :            :                 return true;
    5034                 :            :         default:
    5035                 :            :                 return false;
    5036                 :            :         }
    5037                 :            : }
    5038                 :            : 
    5039                 :            : /* Phase 7 device */
    5040                 :            : static bool bnxt_p7_device(uint16_t device_id)
    5041                 :            : {
    5042         [ #  # ]:          0 :         switch (device_id) {
    5043                 :            :         case BROADCOM_DEV_ID_58818_VF:
    5044                 :            :         case BROADCOM_DEV_ID_57608:
    5045                 :            :         case BROADCOM_DEV_ID_57604:
    5046                 :            :         case BROADCOM_DEV_ID_57602:
    5047                 :            :         case BROADCOM_DEV_ID_57601:
    5048                 :            :         case BROADCOM_DEV_ID_5760X_VF:
    5049                 :            :                 /* FALLTHROUGH */
    5050                 :            :                 return true;
    5051                 :            :         default:
    5052                 :            :                 return false;
    5053                 :            :         }
    5054                 :            : }
    5055                 :            : 
    5056                 :          0 : bool bnxt_stratus_device(struct bnxt *bp)
    5057                 :            : {
    5058                 :          0 :         uint16_t device_id = bp->pdev->id.device_id;
    5059                 :            : 
    5060         [ #  # ]:          0 :         switch (device_id) {
    5061                 :            :         case BROADCOM_DEV_ID_STRATUS_NIC:
    5062                 :            :         case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
    5063                 :            :         case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
    5064                 :            :                 /* FALLTHROUGH */
    5065                 :            :                 return true;
    5066                 :          0 :         default:
    5067                 :          0 :                 return false;
    5068                 :            :         }
    5069                 :            : }
    5070                 :            : 
    5071                 :          0 : static int bnxt_map_pci_bars(struct rte_eth_dev *eth_dev)
    5072                 :            : {
    5073                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    5074                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    5075                 :            : 
    5076                 :            :         /* enable device (incl. PCI PM wakeup), and bus-mastering */
    5077                 :          0 :         bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
    5078                 :          0 :         bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
    5079   [ #  #  #  # ]:          0 :         if (!bp->bar0 || !bp->doorbell_base) {
    5080                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to access Hardware");
    5081                 :          0 :                 return -ENODEV;
    5082                 :            :         }
    5083                 :            : 
    5084                 :          0 :         bp->eth_dev = eth_dev;
    5085                 :          0 :         bp->pdev = pci_dev;
    5086                 :            : 
    5087                 :          0 :         return 0;
    5088                 :            : }
    5089                 :            : 
    5090                 :          0 : static void bnxt_init_ctxm_mem(struct bnxt_ctx_mem *ctxm, void *p, int len)
    5091                 :            : {
    5092                 :          0 :         uint8_t init_val = ctxm->init_value;
    5093                 :          0 :         uint16_t offset = ctxm->init_offset;
    5094                 :            :         uint8_t *p2 = p;
    5095                 :            :         int i;
    5096                 :            : 
    5097         [ #  # ]:          0 :         if (!init_val)
    5098                 :            :                 return;
    5099         [ #  # ]:          0 :         if (offset == BNXT_CTX_INIT_INVALID_OFFSET) {
    5100                 :          0 :                 memset(p, init_val, len);
    5101                 :          0 :                 return;
    5102                 :            :         }
    5103         [ #  # ]:          0 :         for (i = 0; i < len; i += ctxm->entry_size)
    5104                 :          0 :                 *(p2 + i + offset) = init_val;
    5105                 :            : }
    5106                 :            : 
    5107                 :          0 : static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
    5108                 :            :                                   struct bnxt_ctx_pg_info *ctx_pg,
    5109                 :            :                                   struct bnxt_ctx_mem *ctxm,
    5110                 :            :                                   uint32_t mem_size,
    5111                 :            :                                   const char *suffix,
    5112                 :            :                                   uint16_t idx)
    5113                 :            : {
    5114                 :            :         struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
    5115                 :            :         const struct rte_memzone *mz = NULL;
    5116                 :            :         char name[RTE_MEMZONE_NAMESIZE];
    5117                 :            :         rte_iova_t mz_phys_addr;
    5118                 :            :         uint64_t valid_bits = 0;
    5119                 :            :         uint32_t sz;
    5120                 :            :         int i;
    5121                 :            : 
    5122         [ #  # ]:          0 :         if (!mem_size)
    5123                 :            :                 return 0;
    5124                 :            : 
    5125                 :          0 :         rmem->nr_pages =
    5126                 :          0 :                 RTE_ALIGN_MUL_CEIL(mem_size, BNXT_PAGE_SIZE) / BNXT_PAGE_SIZE;
    5127                 :          0 :         rmem->page_size = BNXT_PAGE_SIZE;
    5128                 :            : 
    5129                 :          0 :         snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_pg_arr%s_%x_%d",
    5130                 :          0 :                  suffix, idx, bp->eth_dev->data->port_id);
    5131                 :          0 :         ctx_pg->ctx_pg_arr = rte_zmalloc(name, sizeof(void *) * rmem->nr_pages, 0);
    5132         [ #  # ]:          0 :         if (ctx_pg->ctx_pg_arr == NULL)
    5133                 :            :                 return -ENOMEM;
    5134                 :            : 
    5135                 :          0 :         snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_dma_arr%s_%x_%d",
    5136                 :          0 :                  suffix, idx, bp->eth_dev->data->port_id);
    5137                 :          0 :         ctx_pg->ctx_dma_arr = rte_zmalloc(name, sizeof(rte_iova_t *) * rmem->nr_pages, 0);
    5138         [ #  # ]:          0 :         if (ctx_pg->ctx_dma_arr == NULL)
    5139                 :            :                 return -ENOMEM;
    5140                 :            : 
    5141                 :          0 :         rmem->pg_arr = ctx_pg->ctx_pg_arr;
    5142                 :          0 :         rmem->dma_arr = ctx_pg->ctx_dma_arr;
    5143                 :          0 :         rmem->flags = BNXT_RMEM_VALID_PTE_FLAG | BNXT_RMEM_USE_FULL_PAGE_FLAG;
    5144                 :            : 
    5145                 :            :         valid_bits = PTU_PTE_VALID;
    5146                 :            : 
    5147         [ #  # ]:          0 :         if (rmem->nr_pages > 1) {
    5148                 :          0 :                 snprintf(name, RTE_MEMZONE_NAMESIZE,
    5149                 :            :                          "bnxt_ctxpgtbl%s_%x_%d",
    5150                 :          0 :                          suffix, idx, bp->eth_dev->data->port_id);
    5151                 :          0 :                 name[RTE_MEMZONE_NAMESIZE - 1] = 0;
    5152                 :          0 :                 mz = rte_memzone_lookup(name);
    5153         [ #  # ]:          0 :                 if (!mz) {
    5154                 :          0 :                         mz = rte_memzone_reserve_aligned(name,
    5155                 :          0 :                                                 rmem->nr_pages * 8,
    5156                 :          0 :                                                 bp->eth_dev->device->numa_node,
    5157                 :            :                                                 RTE_MEMZONE_2MB |
    5158                 :            :                                                 RTE_MEMZONE_SIZE_HINT_ONLY,
    5159                 :            :                                                 BNXT_PAGE_SIZE);
    5160         [ #  # ]:          0 :                         if (mz == NULL)
    5161                 :            :                                 return -ENOMEM;
    5162                 :            :                 }
    5163                 :            : 
    5164         [ #  # ]:          0 :                 memset(mz->addr, 0xff, mz->len);
    5165                 :          0 :                 mz_phys_addr = mz->iova;
    5166                 :            : 
    5167         [ #  # ]:          0 :                 if (ctxm != NULL)
    5168                 :          0 :                         bnxt_init_ctxm_mem(ctxm, mz->addr, mz->len);
    5169                 :          0 :                 rmem->pg_tbl = mz->addr;
    5170                 :          0 :                 rmem->pg_tbl_map = mz_phys_addr;
    5171                 :          0 :                 rmem->pg_tbl_mz = mz;
    5172                 :            :         }
    5173                 :            : 
    5174                 :          0 :         snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_%s_%x_%d",
    5175                 :          0 :                  suffix, idx, bp->eth_dev->data->port_id);
    5176                 :          0 :         mz = rte_memzone_lookup(name);
    5177         [ #  # ]:          0 :         if (!mz) {
    5178                 :          0 :                 mz = rte_memzone_reserve_aligned(name,
    5179                 :            :                                                  mem_size,
    5180                 :          0 :                                                  bp->eth_dev->device->numa_node,
    5181                 :            :                                                  RTE_MEMZONE_1GB |
    5182                 :            :                                                  RTE_MEMZONE_SIZE_HINT_ONLY,
    5183                 :            :                                                  BNXT_PAGE_SIZE);
    5184         [ #  # ]:          0 :                 if (mz == NULL)
    5185                 :            :                         return -ENOMEM;
    5186                 :            :         }
    5187                 :            : 
    5188         [ #  # ]:          0 :         memset(mz->addr, 0xff, mz->len);
    5189                 :          0 :         mz_phys_addr = mz->iova;
    5190                 :            : 
    5191         [ #  # ]:          0 :         if (ctxm != NULL)
    5192                 :          0 :                 bnxt_init_ctxm_mem(ctxm, mz->addr, mz->len);
    5193         [ #  # ]:          0 :         for (sz = 0, i = 0; sz < mem_size; sz += BNXT_PAGE_SIZE, i++) {
    5194                 :          0 :                 rmem->pg_arr[i] = ((char *)mz->addr) + sz;
    5195                 :          0 :                 rmem->dma_arr[i] = mz_phys_addr + sz;
    5196                 :            : 
    5197         [ #  # ]:          0 :                 if (rmem->nr_pages > 1) {
    5198         [ #  # ]:          0 :                         if (i == rmem->nr_pages - 2 &&
    5199         [ #  # ]:          0 :                             (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
    5200                 :          0 :                                 valid_bits |= PTU_PTE_NEXT_TO_LAST;
    5201         [ #  # ]:          0 :                         else if (i == rmem->nr_pages - 1 &&
    5202         [ #  # ]:          0 :                                  (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
    5203                 :          0 :                                 valid_bits |= PTU_PTE_LAST;
    5204                 :            : 
    5205                 :          0 :                         rmem->pg_tbl[i] = rte_cpu_to_le_64(rmem->dma_arr[i] |
    5206                 :            :                                                            valid_bits);
    5207                 :            :                 }
    5208                 :            :         }
    5209                 :            : 
    5210                 :          0 :         rmem->mz = mz;
    5211         [ #  # ]:          0 :         if (rmem->vmem_size)
    5212                 :          0 :                 rmem->vmem = (void **)mz->addr;
    5213                 :          0 :         rmem->dma_arr[0] = mz_phys_addr;
    5214                 :          0 :         return 0;
    5215                 :            : }
    5216                 :            : 
    5217                 :          0 : static void bnxt_free_ctx_mem_v2(struct bnxt *bp)
    5218                 :            : {
    5219                 :            :         uint16_t type;
    5220                 :            : 
    5221         [ #  # ]:          0 :         for (type = 0; type < bp->ctx->types; type++) {
    5222                 :          0 :                 struct bnxt_ctx_mem *ctxm = &bp->ctx->ctx_arr[type];
    5223                 :          0 :                 struct bnxt_ctx_pg_info *ctx_pg = ctxm->pg_info;
    5224                 :            :                 int i, n = 1;
    5225                 :            : 
    5226         [ #  # ]:          0 :                 if (!ctx_pg)
    5227                 :          0 :                         continue;
    5228         [ #  # ]:          0 :                 if (ctxm->instance_bmap)
    5229                 :          0 :                         n = hweight32(ctxm->instance_bmap);
    5230                 :            : 
    5231         [ #  # ]:          0 :                 for (i = 0; i < n; i++) {
    5232                 :          0 :                         rte_free(ctx_pg[i].ctx_pg_arr);
    5233                 :          0 :                         rte_free(ctx_pg[i].ctx_dma_arr);
    5234                 :          0 :                         rte_memzone_free(ctx_pg[i].ring_mem.mz);
    5235                 :          0 :                         rte_memzone_free(ctx_pg[i].ring_mem.pg_tbl_mz);
    5236                 :            :                 }
    5237                 :            : 
    5238                 :          0 :                 rte_free(ctx_pg);
    5239                 :          0 :                 ctxm->pg_info = NULL;
    5240                 :            :         }
    5241                 :          0 :         rte_free(bp->ctx->ctx_arr);
    5242                 :          0 :         bp->ctx->ctx_arr = NULL;
    5243                 :          0 : }
    5244                 :            : 
    5245                 :          0 : static void bnxt_free_ctx_mem(struct bnxt *bp)
    5246                 :            : {
    5247                 :            :         int i;
    5248                 :            : 
    5249   [ #  #  #  # ]:          0 :         if (!bp->ctx || !(bp->ctx->flags & BNXT_CTX_FLAG_INITED))
    5250                 :            :                 return;
    5251                 :            : 
    5252                 :          0 :         bp->ctx->flags &= ~BNXT_CTX_FLAG_INITED;
    5253                 :            : 
    5254         [ #  # ]:          0 :         if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
    5255                 :          0 :                 bnxt_free_ctx_mem_v2(bp);
    5256                 :          0 :                 goto free_ctx;
    5257                 :            :         }
    5258                 :            : 
    5259                 :          0 :         rte_free(bp->ctx->qp_mem.ctx_pg_arr);
    5260                 :          0 :         rte_free(bp->ctx->srq_mem.ctx_pg_arr);
    5261                 :          0 :         rte_free(bp->ctx->cq_mem.ctx_pg_arr);
    5262                 :          0 :         rte_free(bp->ctx->vnic_mem.ctx_pg_arr);
    5263                 :          0 :         rte_free(bp->ctx->stat_mem.ctx_pg_arr);
    5264                 :          0 :         rte_free(bp->ctx->qp_mem.ctx_dma_arr);
    5265                 :          0 :         rte_free(bp->ctx->srq_mem.ctx_dma_arr);
    5266                 :          0 :         rte_free(bp->ctx->cq_mem.ctx_dma_arr);
    5267                 :          0 :         rte_free(bp->ctx->vnic_mem.ctx_dma_arr);
    5268                 :          0 :         rte_free(bp->ctx->stat_mem.ctx_dma_arr);
    5269                 :            : 
    5270                 :          0 :         rte_memzone_free(bp->ctx->qp_mem.ring_mem.mz);
    5271                 :          0 :         rte_memzone_free(bp->ctx->srq_mem.ring_mem.mz);
    5272                 :          0 :         rte_memzone_free(bp->ctx->cq_mem.ring_mem.mz);
    5273                 :          0 :         rte_memzone_free(bp->ctx->vnic_mem.ring_mem.mz);
    5274                 :          0 :         rte_memzone_free(bp->ctx->stat_mem.ring_mem.mz);
    5275                 :          0 :         rte_memzone_free(bp->ctx->qp_mem.ring_mem.pg_tbl_mz);
    5276                 :          0 :         rte_memzone_free(bp->ctx->srq_mem.ring_mem.pg_tbl_mz);
    5277                 :          0 :         rte_memzone_free(bp->ctx->cq_mem.ring_mem.pg_tbl_mz);
    5278                 :          0 :         rte_memzone_free(bp->ctx->vnic_mem.ring_mem.pg_tbl_mz);
    5279                 :          0 :         rte_memzone_free(bp->ctx->stat_mem.ring_mem.pg_tbl_mz);
    5280                 :            : 
    5281         [ #  # ]:          0 :         for (i = 0; i < bp->ctx->tqm_fp_rings_count + 1; i++) {
    5282                 :          0 :                 rte_free(bp->ctx->tqm_mem[i]->ctx_pg_arr);
    5283                 :          0 :                 rte_free(bp->ctx->tqm_mem[i]->ctx_dma_arr);
    5284         [ #  # ]:          0 :                 if (bp->ctx->tqm_mem[i])
    5285                 :          0 :                         rte_memzone_free(bp->ctx->tqm_mem[i]->ring_mem.mz);
    5286                 :            :         }
    5287                 :            : 
    5288                 :          0 : free_ctx:
    5289                 :          0 :         rte_free(bp->ctx);
    5290                 :          0 :         bp->ctx = NULL;
    5291                 :            : }
    5292                 :            : 
    5293                 :            : #define bnxt_roundup(x, y)   ((((x) + ((y) - 1)) / (y)) * (y))
    5294                 :            : 
    5295                 :            : #define clamp_t(type, _x, min, max) RTE_MIN_T(RTE_MAX_T(_x, min, type), max, type)
    5296                 :            : 
    5297                 :          0 : int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
    5298                 :            : {
    5299                 :          0 :         struct bnxt_ctx_mem_info *ctx = bp->ctx;
    5300                 :            :         struct bnxt_ctx_mem *ctx2;
    5301                 :            :         uint16_t type;
    5302                 :            :         int rc = 0;
    5303                 :            : 
    5304                 :          0 :         ctx2 = &ctx->ctx_arr[0];
    5305   [ #  #  #  # ]:          0 :         for (type = 0; type < ctx->types && rc == 0; type++) {
    5306                 :          0 :                 struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[type];
    5307                 :            :                 struct bnxt_ctx_pg_info *ctx_pg;
    5308                 :            :                 uint32_t entries, mem_size;
    5309                 :            :                 int w = 1;
    5310                 :            :                 int i;
    5311                 :            : 
    5312         [ #  # ]:          0 :                 if (ctxm->entry_size == 0)
    5313                 :          0 :                         continue;
    5314                 :            : 
    5315                 :          0 :                 ctx_pg = ctxm->pg_info;
    5316                 :            : 
    5317         [ #  # ]:          0 :                 if (ctxm->instance_bmap)
    5318                 :          0 :                         w = hweight32(ctxm->instance_bmap);
    5319                 :            : 
    5320         [ #  # ]:          0 :                 for (i = 0; i < w && rc == 0; i++) {
    5321                 :          0 :                         char name[RTE_MEMZONE_NAMESIZE] = {0};
    5322                 :            : 
    5323         [ #  # ]:          0 :                         sprintf(name, "_%d_%d", i, type);
    5324                 :            : 
    5325         [ #  # ]:          0 :                         if (ctxm->entry_multiple)
    5326                 :          0 :                                 entries = bnxt_roundup(ctxm->max_entries,
    5327                 :            :                                                        ctxm->entry_multiple);
    5328                 :            :                         else
    5329                 :          0 :                                 entries = ctxm->max_entries;
    5330                 :            : 
    5331         [ #  # ]:          0 :                         if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_CQ)
    5332                 :          0 :                                 entries = ctxm->cq_l2_entries;
    5333         [ #  # ]:          0 :                         else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_QP)
    5334                 :          0 :                                 entries = ctxm->qp_l2_entries;
    5335         [ #  # ]:          0 :                         else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_MRAV)
    5336                 :          0 :                                 entries = ctxm->mrav_av_entries;
    5337         [ #  # ]:          0 :                         else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_TIM)
    5338                 :          0 :                                 entries = ctx2->qp_l2_entries;
    5339                 :          0 :                         entries = clamp_t(uint32_t, entries, ctxm->min_entries,
    5340                 :            :                                           ctxm->max_entries);
    5341                 :          0 :                         ctx_pg[i].entries = entries;
    5342                 :          0 :                         mem_size = ctxm->entry_size * entries;
    5343                 :          0 :                         PMD_DRV_LOG_LINE(DEBUG,
    5344                 :            :                                     "Type:0x%x instance:%d entries:%d size:%d",
    5345                 :            :                                     ctxm->type, i, ctx_pg[i].entries, mem_size);
    5346                 :          0 :                         rc = bnxt_alloc_ctx_mem_blk(bp, &ctx_pg[i],
    5347         [ #  # ]:          0 :                                                     ctxm->init_value ? ctxm : NULL,
    5348                 :            :                                                     mem_size, name, i);
    5349                 :            :                 }
    5350                 :            :         }
    5351                 :            : 
    5352                 :          0 :         return rc;
    5353                 :            : }
    5354                 :            : 
    5355                 :          0 : int bnxt_alloc_ctx_mem(struct bnxt *bp)
    5356                 :            : {
    5357                 :            :         struct bnxt_ctx_pg_info *ctx_pg;
    5358                 :            :         struct bnxt_ctx_mem_info *ctx;
    5359                 :            :         uint32_t mem_size, ena, entries;
    5360                 :            :         int types = BNXT_CTX_MIN;
    5361                 :            :         uint32_t entries_sp, min;
    5362                 :            :         int i, rc = 0;
    5363                 :            : 
    5364   [ #  #  #  #  :          0 :         if (!BNXT_FW_BACKING_STORE_V1_EN(bp) &&
                   #  # ]
    5365         [ #  # ]:          0 :             !BNXT_FW_BACKING_STORE_V2_EN(bp))
    5366                 :            :                 return rc;
    5367                 :            : 
    5368         [ #  # ]:          0 :         if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
    5369                 :          0 :                 types = bnxt_hwrm_func_backing_store_types_count(bp);
    5370         [ #  # ]:          0 :                 if (types <= 0)
    5371                 :            :                         return types;
    5372                 :            :         }
    5373                 :            : 
    5374                 :          0 :         rc = bnxt_hwrm_func_backing_store_ctx_alloc(bp, types);
    5375         [ #  # ]:          0 :         if (rc != 0)
    5376                 :            :                 return rc;
    5377                 :            : 
    5378         [ #  # ]:          0 :         if (bp->ctx->flags & BNXT_CTX_FLAG_INITED)
    5379                 :            :                 return 0;
    5380                 :            : 
    5381                 :            :         ctx = bp->ctx;
    5382         [ #  # ]:          0 :         if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
    5383                 :          0 :                 rc = bnxt_hwrm_func_backing_store_qcaps_v2(bp);
    5384                 :            : 
    5385   [ #  #  #  # ]:          0 :                 for (i = 0 ; i < bp->ctx->types && rc == 0; i++) {
    5386                 :          0 :                         struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[i];
    5387                 :            : 
    5388                 :          0 :                         rc = bnxt_hwrm_func_backing_store_cfg_v2(bp, ctxm);
    5389                 :            :                 }
    5390                 :          0 :                 goto done;
    5391                 :            :         }
    5392                 :            : 
    5393                 :          0 :         rc = bnxt_hwrm_func_backing_store_qcaps(bp);
    5394         [ #  # ]:          0 :         if (rc) {
    5395                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Query context mem capability failed");
    5396                 :          0 :                 return rc;
    5397                 :            :         }
    5398                 :            : 
    5399                 :          0 :         ctx_pg = &ctx->qp_mem;
    5400                 :          0 :         ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries;
    5401         [ #  # ]:          0 :         if (ctx->qp_entry_size) {
    5402                 :          0 :                 mem_size = ctx->qp_entry_size * ctx_pg->entries;
    5403                 :          0 :                 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "qp_mem", 0);
    5404         [ #  # ]:          0 :                 if (rc)
    5405                 :            :                         return rc;
    5406                 :            :         }
    5407                 :            : 
    5408                 :          0 :         ctx_pg = &ctx->srq_mem;
    5409                 :          0 :         ctx_pg->entries = ctx->srq_max_l2_entries;
    5410         [ #  # ]:          0 :         if (ctx->srq_entry_size) {
    5411                 :          0 :                 mem_size = ctx->srq_entry_size * ctx_pg->entries;
    5412                 :          0 :                 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "srq_mem", 0);
    5413         [ #  # ]:          0 :                 if (rc)
    5414                 :            :                         return rc;
    5415                 :            :         }
    5416                 :            : 
    5417                 :          0 :         ctx_pg = &ctx->cq_mem;
    5418                 :          0 :         ctx_pg->entries = ctx->cq_max_l2_entries;
    5419         [ #  # ]:          0 :         if (ctx->cq_entry_size) {
    5420                 :          0 :                 mem_size = ctx->cq_entry_size * ctx_pg->entries;
    5421                 :          0 :                 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "cq_mem", 0);
    5422         [ #  # ]:          0 :                 if (rc)
    5423                 :            :                         return rc;
    5424                 :            :         }
    5425                 :            : 
    5426                 :          0 :         ctx_pg = &ctx->vnic_mem;
    5427                 :          0 :         ctx_pg->entries = ctx->vnic_max_vnic_entries +
    5428                 :          0 :                 ctx->vnic_max_ring_table_entries;
    5429         [ #  # ]:          0 :         if (ctx->vnic_entry_size) {
    5430                 :          0 :                 mem_size = ctx->vnic_entry_size * ctx_pg->entries;
    5431                 :          0 :                 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "vnic_mem", 0);
    5432         [ #  # ]:          0 :                 if (rc)
    5433                 :            :                         return rc;
    5434                 :            :         }
    5435                 :            : 
    5436                 :          0 :         ctx_pg = &ctx->stat_mem;
    5437                 :          0 :         ctx_pg->entries = ctx->stat_max_entries;
    5438         [ #  # ]:          0 :         if (ctx->stat_entry_size) {
    5439                 :          0 :                 mem_size = ctx->stat_entry_size * ctx_pg->entries;
    5440                 :          0 :                 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "stat_mem", 0);
    5441         [ #  # ]:          0 :                 if (rc)
    5442                 :            :                         return rc;
    5443                 :            :         }
    5444                 :            : 
    5445                 :          0 :         min = ctx->tqm_min_entries_per_ring;
    5446                 :            : 
    5447                 :          0 :         entries_sp = ctx->qp_max_l2_entries +
    5448                 :          0 :                      ctx->vnic_max_vnic_entries +
    5449                 :          0 :                      2 * ctx->qp_min_qp1_entries + min;
    5450                 :          0 :         entries_sp = bnxt_roundup(entries_sp, ctx->tqm_entries_multiple);
    5451                 :            : 
    5452                 :          0 :         entries = ctx->qp_max_l2_entries + ctx->qp_min_qp1_entries;
    5453                 :          0 :         entries = bnxt_roundup(entries, ctx->tqm_entries_multiple);
    5454                 :          0 :         entries = clamp_t(uint32_t, entries, min,
    5455                 :            :                           ctx->tqm_max_entries_per_ring);
    5456         [ #  # ]:          0 :         for (i = 0, ena = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
    5457                 :            :                 /* i=0 is for TQM_SP. i=1 to i=8 applies to RING0 to RING7.
    5458                 :            :                  * i > 8 is other ext rings.
    5459                 :            :                  */
    5460                 :          0 :                 ctx_pg = ctx->tqm_mem[i];
    5461         [ #  # ]:          0 :                 ctx_pg->entries = i ? entries : entries_sp;
    5462         [ #  # ]:          0 :                 if (ctx->tqm_entry_size) {
    5463                 :          0 :                         mem_size = ctx->tqm_entry_size * ctx_pg->entries;
    5464                 :          0 :                         rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL,
    5465                 :            :                                                     mem_size, "tqm_mem", i);
    5466         [ #  # ]:          0 :                         if (rc)
    5467                 :          0 :                                 return rc;
    5468                 :            :                 }
    5469         [ #  # ]:          0 :                 if (i < BNXT_MAX_TQM_LEGACY_RINGS)
    5470                 :          0 :                         ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP << i;
    5471                 :            :                 else
    5472                 :          0 :                         ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8;
    5473                 :            :         }
    5474                 :            : 
    5475                 :          0 :         ena |= FUNC_BACKING_STORE_CFG_INPUT_DFLT_ENABLES;
    5476                 :          0 :         rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
    5477                 :          0 : done:
    5478         [ #  # ]:          0 :         if (rc)
    5479                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    5480                 :            :                             "Failed to configure context mem: rc = %d", rc);
    5481                 :            :         else
    5482                 :          0 :                 ctx->flags |= BNXT_CTX_FLAG_INITED;
    5483                 :            : 
    5484                 :            :         return rc;
    5485                 :            : }
    5486                 :            : 
    5487                 :          0 : static int bnxt_alloc_stats_mem(struct bnxt *bp)
    5488                 :            : {
    5489                 :          0 :         struct rte_pci_device *pci_dev = bp->pdev;
    5490                 :            :         char mz_name[RTE_MEMZONE_NAMESIZE];
    5491                 :            :         const struct rte_memzone *mz = NULL;
    5492                 :            :         uint32_t total_alloc_len;
    5493                 :            :         rte_iova_t mz_phys_addr;
    5494                 :            : 
    5495         [ #  # ]:          0 :         if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
    5496                 :            :                 return 0;
    5497                 :            : 
    5498                 :          0 :         snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
    5499                 :            :                  "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
    5500                 :          0 :                  pci_dev->addr.bus, pci_dev->addr.devid,
    5501                 :          0 :                  pci_dev->addr.function, "rx_port_stats");
    5502                 :          0 :         mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
    5503                 :          0 :         mz = rte_memzone_lookup(mz_name);
    5504                 :            :         total_alloc_len =
    5505                 :            :                 RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
    5506                 :            :                                        sizeof(struct rx_port_stats_ext) + 512);
    5507         [ #  # ]:          0 :         if (!mz) {
    5508                 :          0 :                 mz = rte_memzone_reserve(mz_name, total_alloc_len,
    5509                 :            :                                          SOCKET_ID_ANY,
    5510                 :            :                                          RTE_MEMZONE_2MB |
    5511                 :            :                                          RTE_MEMZONE_SIZE_HINT_ONLY |
    5512                 :            :                                          RTE_MEMZONE_IOVA_CONTIG);
    5513         [ #  # ]:          0 :                 if (mz == NULL)
    5514                 :            :                         return -ENOMEM;
    5515                 :            :         }
    5516                 :          0 :         memset(mz->addr, 0, mz->len);
    5517                 :          0 :         mz_phys_addr = mz->iova;
    5518                 :            : 
    5519                 :          0 :         bp->rx_mem_zone = (const void *)mz;
    5520                 :          0 :         bp->hw_rx_port_stats = mz->addr;
    5521                 :          0 :         bp->hw_rx_port_stats_map = mz_phys_addr;
    5522                 :            : 
    5523                 :          0 :         snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
    5524                 :            :                  "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
    5525                 :          0 :                  pci_dev->addr.bus, pci_dev->addr.devid,
    5526                 :          0 :                  pci_dev->addr.function, "tx_port_stats");
    5527                 :          0 :         mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
    5528                 :          0 :         mz = rte_memzone_lookup(mz_name);
    5529                 :            :         total_alloc_len =
    5530                 :            :                 RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
    5531                 :            :                                        sizeof(struct tx_port_stats_ext) + 512);
    5532         [ #  # ]:          0 :         if (!mz) {
    5533                 :          0 :                 mz = rte_memzone_reserve(mz_name,
    5534                 :            :                                          total_alloc_len,
    5535                 :            :                                          SOCKET_ID_ANY,
    5536                 :            :                                          RTE_MEMZONE_2MB |
    5537                 :            :                                          RTE_MEMZONE_SIZE_HINT_ONLY |
    5538                 :            :                                          RTE_MEMZONE_IOVA_CONTIG);
    5539         [ #  # ]:          0 :                 if (mz == NULL)
    5540                 :            :                         return -ENOMEM;
    5541                 :            :         }
    5542         [ #  # ]:          0 :         memset(mz->addr, 0, mz->len);
    5543                 :          0 :         mz_phys_addr = mz->iova;
    5544                 :            : 
    5545                 :          0 :         bp->tx_mem_zone = (const void *)mz;
    5546                 :          0 :         bp->hw_tx_port_stats = mz->addr;
    5547                 :          0 :         bp->hw_tx_port_stats_map = mz_phys_addr;
    5548                 :          0 :         bp->flags |= BNXT_FLAG_PORT_STATS;
    5549                 :            : 
    5550                 :            :         /* Display extended statistics if FW supports it */
    5551         [ #  # ]:          0 :         if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
    5552         [ #  # ]:          0 :             bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0 ||
    5553                 :            :             !(bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED))
    5554                 :            :                 return 0;
    5555                 :            : 
    5556                 :          0 :         bp->hw_rx_port_stats_ext = (void *)
    5557                 :          0 :                 ((uint8_t *)bp->hw_rx_port_stats +
    5558                 :            :                  sizeof(struct rx_port_stats));
    5559                 :          0 :         bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
    5560                 :            :                 sizeof(struct rx_port_stats);
    5561                 :          0 :         bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
    5562                 :            : 
    5563                 :            :         if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2 ||
    5564                 :            :             bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED) {
    5565                 :          0 :                 bp->hw_tx_port_stats_ext = (void *)
    5566                 :            :                         ((uint8_t *)bp->hw_tx_port_stats +
    5567                 :            :                          sizeof(struct tx_port_stats));
    5568                 :          0 :                 bp->hw_tx_port_stats_ext_map =
    5569                 :          0 :                         bp->hw_tx_port_stats_map +
    5570                 :            :                         sizeof(struct tx_port_stats);
    5571                 :          0 :                 bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
    5572                 :            :         }
    5573                 :            : 
    5574                 :          0 :         return 0;
    5575                 :            : }
    5576                 :            : 
    5577                 :          0 : static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
    5578                 :            : {
    5579                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    5580                 :          0 :         size_t max_mac_addr = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
    5581                 :            :         int rc = 0;
    5582                 :            : 
    5583         [ #  # ]:          0 :         if (bp->max_l2_ctx > RTE_ETH_NUM_RECEIVE_MAC_ADDR)
    5584                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "Max number of MAC addrs supported is %d, but will be limited to %d",
    5585                 :            :                             bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
    5586                 :            : 
    5587                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
    5588                 :            :                                                RTE_ETHER_ADDR_LEN * max_mac_addr,
    5589                 :            :                                                0);
    5590         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    5591                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to alloc MAC addr tbl");
    5592                 :          0 :                 return -ENOMEM;
    5593                 :            :         }
    5594                 :            : 
    5595         [ #  # ]:          0 :         if (!BNXT_HAS_DFLT_MAC_SET(bp)) {
    5596         [ #  # ]:          0 :                 if (BNXT_PF(bp))
    5597                 :            :                         return -EINVAL;
    5598                 :            : 
    5599                 :            :                 /* Generate a random MAC address, if none was assigned by PF */
    5600                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "VF MAC address not assigned by Host PF");
    5601                 :          0 :                 bnxt_eth_hw_addr_random(bp->mac_addr);
    5602                 :          0 :                 PMD_DRV_LOG_LINE(INFO,
    5603                 :            :                             "Assign random MAC:" RTE_ETHER_ADDR_PRT_FMT,
    5604                 :            :                             bp->mac_addr[0], bp->mac_addr[1], bp->mac_addr[2],
    5605                 :            :                             bp->mac_addr[3], bp->mac_addr[4], bp->mac_addr[5]);
    5606                 :            : 
    5607                 :          0 :                 rc = bnxt_hwrm_set_mac(bp);
    5608         [ #  # ]:          0 :                 if (rc)
    5609                 :            :                         return rc;
    5610                 :            :         }
    5611                 :            : 
    5612                 :            :         /* Copy the permanent MAC from the FUNC_QCAPS response */
    5613                 :          0 :         memcpy(&eth_dev->data->mac_addrs[0], bp->mac_addr, RTE_ETHER_ADDR_LEN);
    5614                 :            : 
    5615                 :            :         /*
    5616                 :            :          *  Allocate memory to hold multicast mac addresses added.
    5617                 :            :          *  Used to restore them during reset recovery
    5618                 :            :          */
    5619                 :          0 :         bp->mcast_addr_list = rte_zmalloc("bnxt_mcast_addr_tbl",
    5620                 :            :                                           sizeof(struct rte_ether_addr) *
    5621                 :          0 :                                           BNXT_MAX_MC_ADDRS, 0);
    5622         [ #  # ]:          0 :         if (bp->mcast_addr_list == NULL) {
    5623                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to allocate multicast addr table");
    5624                 :          0 :                 return -ENOMEM;
    5625                 :            :         }
    5626                 :          0 :         bp->mc_list_dma_addr = rte_malloc_virt2iova(bp->mcast_addr_list);
    5627         [ #  # ]:          0 :         if (bp->mc_list_dma_addr == RTE_BAD_IOVA) {
    5628                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Fail to map mcast_addr_list to physical memory");
    5629                 :          0 :                 return -ENOMEM;
    5630                 :            :         }
    5631                 :            : 
    5632                 :            :         return rc;
    5633                 :            : }
    5634                 :            : 
    5635                 :          0 : static int bnxt_restore_dflt_mac(struct bnxt *bp)
    5636                 :            : {
    5637                 :            :         int rc = 0;
    5638                 :            : 
    5639                 :            :         /* MAC is already configured in FW */
    5640         [ #  # ]:          0 :         if (BNXT_HAS_DFLT_MAC_SET(bp))
    5641                 :            :                 return 0;
    5642                 :            : 
    5643                 :            :         /* Restore the old MAC configured */
    5644                 :          0 :         rc = bnxt_hwrm_set_mac(bp);
    5645         [ #  # ]:          0 :         if (rc)
    5646                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to restore MAC address");
    5647                 :            : 
    5648                 :            :         return rc;
    5649                 :            : }
    5650                 :            : 
    5651                 :          0 : static void bnxt_config_vf_req_fwd(struct bnxt *bp)
    5652                 :            : {
    5653         [ #  # ]:          0 :         if (!BNXT_PF(bp))
    5654                 :            :                 return;
    5655                 :            : 
    5656         [ #  # ]:          0 :         memset(bp->pf->vf_req_fwd, 0, sizeof(bp->pf->vf_req_fwd));
    5657                 :            : 
    5658         [ #  # ]:          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_LINK_ADMIN))
    5659                 :          0 :                 BNXT_HWRM_CMD_TO_FORWARD(HWRM_PORT_PHY_QCFG);
    5660                 :          0 :         BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_CFG);
    5661                 :          0 :         BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_VF_CFG);
    5662                 :          0 :         BNXT_HWRM_CMD_TO_FORWARD(HWRM_CFA_L2_FILTER_ALLOC);
    5663                 :          0 :         BNXT_HWRM_CMD_TO_FORWARD(HWRM_OEM_CMD);
    5664                 :            : }
    5665                 :            : 
    5666                 :          0 : static void bnxt_alloc_error_recovery_info(struct bnxt *bp)
    5667                 :            : {
    5668                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    5669                 :            : 
    5670         [ #  # ]:          0 :         if (info) {
    5671         [ #  # ]:          0 :                 if (!(bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS))
    5672                 :            :                         memset(info, 0, sizeof(*info));
    5673                 :          0 :                 return;
    5674                 :            :         }
    5675                 :            : 
    5676         [ #  # ]:          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
    5677                 :            :                 return;
    5678                 :            : 
    5679                 :          0 :         info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
    5680                 :            :                            sizeof(*info), 0);
    5681         [ #  # ]:          0 :         if (!info)
    5682                 :          0 :                 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
    5683                 :            : 
    5684                 :          0 :         bp->recovery_info = info;
    5685                 :            : }
    5686                 :            : 
    5687                 :          0 : static void bnxt_check_fw_status(struct bnxt *bp)
    5688                 :            : {
    5689                 :            :         uint32_t fw_status;
    5690                 :            : 
    5691         [ #  # ]:          0 :         if (!(bp->recovery_info &&
    5692         [ #  # ]:          0 :               (bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS)))
    5693                 :            :                 return;
    5694                 :            : 
    5695                 :          0 :         fw_status = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
    5696         [ #  # ]:          0 :         if (fw_status != BNXT_FW_STATUS_HEALTHY)
    5697                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Firmware not responding, status: %#x",
    5698                 :            :                             fw_status);
    5699                 :            : }
    5700                 :            : 
    5701                 :          0 : static int bnxt_map_hcomm_fw_status_reg(struct bnxt *bp)
    5702                 :            : {
    5703                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    5704                 :            :         uint32_t status_loc;
    5705                 :            :         uint32_t sig_ver;
    5706                 :            : 
    5707                 :          0 :         rte_write32(HCOMM_STATUS_STRUCT_LOC, (uint8_t *)bp->bar0 +
    5708                 :            :                     BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
    5709                 :          0 :         sig_ver = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    5710                 :            :                                    BNXT_GRCP_WINDOW_2_BASE +
    5711                 :            :                                    offsetof(struct hcomm_status,
    5712                 :            :                                             sig_ver)));
    5713                 :            :         /* If the signature is absent, then FW does not support this feature */
    5714         [ #  # ]:          0 :         if ((sig_ver & HCOMM_STATUS_SIGNATURE_MASK) !=
    5715                 :            :             HCOMM_STATUS_SIGNATURE_VAL)
    5716                 :            :                 return 0;
    5717                 :            : 
    5718         [ #  # ]:          0 :         if (!info) {
    5719                 :          0 :                 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
    5720                 :            :                                    sizeof(*info), 0);
    5721         [ #  # ]:          0 :                 if (!info)
    5722                 :            :                         return -ENOMEM;
    5723                 :          0 :                 bp->recovery_info = info;
    5724                 :            :         } else {
    5725                 :            :                 memset(info, 0, sizeof(*info));
    5726                 :            :         }
    5727                 :            : 
    5728                 :          0 :         status_loc = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
    5729                 :            :                                       BNXT_GRCP_WINDOW_2_BASE +
    5730                 :            :                                       offsetof(struct hcomm_status,
    5731                 :            :                                                fw_status_loc)));
    5732                 :            : 
    5733                 :            :         /* Only pre-map the FW health status GRC register */
    5734         [ #  # ]:          0 :         if (BNXT_FW_STATUS_REG_TYPE(status_loc) != BNXT_FW_STATUS_REG_TYPE_GRC)
    5735                 :            :                 return 0;
    5736                 :            : 
    5737                 :          0 :         info->status_regs[BNXT_FW_STATUS_REG] = status_loc;
    5738                 :          0 :         info->mapped_status_regs[BNXT_FW_STATUS_REG] =
    5739                 :          0 :                 BNXT_GRCP_WINDOW_2_BASE + (status_loc & BNXT_GRCP_OFFSET_MASK);
    5740                 :            : 
    5741                 :          0 :         rte_write32((status_loc & BNXT_GRCP_BASE_MASK), (uint8_t *)bp->bar0 +
    5742                 :            :                     BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
    5743                 :            : 
    5744                 :          0 :         bp->fw_cap |= BNXT_FW_CAP_HCOMM_FW_STATUS;
    5745                 :            : 
    5746                 :          0 :         return 0;
    5747                 :            : }
    5748                 :            : 
    5749                 :            : /* This function gets the FW version along with the
    5750                 :            :  * capabilities(MAX and current) of the function, vnic,
    5751                 :            :  * error recovery, phy and other chip related info
    5752                 :            :  */
    5753                 :          0 : static int bnxt_get_config(struct bnxt *bp)
    5754                 :            : {
    5755                 :            :         uint16_t mtu;
    5756                 :            :         int timeout;
    5757                 :            :         int rc = 0;
    5758                 :            : 
    5759                 :          0 :         bp->fw_cap = 0;
    5760                 :            : 
    5761                 :          0 :         rc = bnxt_map_hcomm_fw_status_reg(bp);
    5762         [ #  # ]:          0 :         if (rc)
    5763                 :            :                 return rc;
    5764                 :            : 
    5765                 :          0 :         timeout = BNXT_CHIP_P7(bp) ?
    5766         [ #  # ]:          0 :                   PCI_FUNC_RESET_WAIT_TIMEOUT :
    5767                 :            :                   DFLT_HWRM_CMD_TIMEOUT;
    5768                 :          0 : try_again:
    5769                 :          0 :         rc = bnxt_hwrm_ver_get(bp, timeout);
    5770         [ #  # ]:          0 :         if (rc) {
    5771         [ #  # ]:          0 :                 if (rc == -ETIMEDOUT && timeout == PCI_FUNC_RESET_WAIT_TIMEOUT) {
    5772                 :          0 :                         bp->flags &= ~BNXT_FLAG_FW_TIMEDOUT;
    5773                 :            :                         timeout = DFLT_HWRM_CMD_TIMEOUT;
    5774                 :          0 :                         goto try_again;
    5775                 :            :                 }
    5776                 :          0 :                 bnxt_check_fw_status(bp);
    5777                 :          0 :                 return rc;
    5778                 :            :         }
    5779                 :            : 
    5780                 :          0 :         rc = bnxt_hwrm_func_reset(bp);
    5781         [ #  # ]:          0 :         if (rc)
    5782                 :            :                 return -EIO;
    5783                 :            : 
    5784                 :          0 :         rc = bnxt_hwrm_vnic_qcaps(bp);
    5785         [ #  # ]:          0 :         if (rc)
    5786                 :            :                 return rc;
    5787                 :            : 
    5788                 :          0 :         rc = bnxt_hwrm_queue_qportcfg(bp);
    5789         [ #  # ]:          0 :         if (rc)
    5790                 :            :                 return rc;
    5791                 :            : 
    5792                 :            :         /* Get the MAX capabilities for this function.
    5793                 :            :          * This function also allocates context memory for TQM rings and
    5794                 :            :          * informs the firmware about this allocated backing store memory.
    5795                 :            :          */
    5796                 :          0 :         rc = bnxt_hwrm_func_qcaps(bp);
    5797         [ #  # ]:          0 :         if (rc)
    5798                 :            :                 return rc;
    5799                 :            : 
    5800                 :          0 :         rc = bnxt_hwrm_func_qcfg(bp, &mtu);
    5801         [ #  # ]:          0 :         if (rc)
    5802                 :            :                 return rc;
    5803                 :            : 
    5804                 :          0 :         bnxt_hwrm_port_mac_qcfg(bp);
    5805                 :            : 
    5806                 :          0 :         bnxt_hwrm_parent_pf_qcfg(bp);
    5807                 :            : 
    5808                 :          0 :         bnxt_hwrm_port_phy_qcaps(bp);
    5809                 :            : 
    5810                 :          0 :         bnxt_alloc_error_recovery_info(bp);
    5811                 :            :         /* Get the adapter error recovery support info */
    5812                 :          0 :         rc = bnxt_hwrm_error_recovery_qcfg(bp);
    5813         [ #  # ]:          0 :         if (rc)
    5814                 :          0 :                 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
    5815                 :            : 
    5816                 :          0 :         bnxt_hwrm_port_led_qcaps(bp);
    5817                 :            : 
    5818                 :          0 :         return 0;
    5819                 :            : }
    5820                 :            : 
    5821                 :            : static int
    5822                 :          0 : bnxt_init_locks(struct bnxt *bp)
    5823                 :            : {
    5824                 :            :         int err;
    5825                 :            : 
    5826                 :          0 :         err = pthread_mutex_init(&bp->flow_lock, NULL);
    5827         [ #  # ]:          0 :         if (err) {
    5828                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to initialize flow_lock");
    5829                 :          0 :                 return err;
    5830                 :            :         }
    5831                 :            : 
    5832                 :          0 :         err = pthread_mutex_init(&bp->def_cp_lock, NULL);
    5833         [ #  # ]:          0 :         if (err) {
    5834                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to initialize def_cp_lock");
    5835                 :          0 :                 return err;
    5836                 :            :         }
    5837                 :            : 
    5838                 :          0 :         err = pthread_mutex_init(&bp->health_check_lock, NULL);
    5839         [ #  # ]:          0 :         if (err) {
    5840                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to initialize health_check_lock");
    5841                 :          0 :                 return err;
    5842                 :            :         }
    5843                 :            : 
    5844                 :          0 :         err = pthread_mutex_init(&bp->err_recovery_lock, NULL);
    5845         [ #  # ]:          0 :         if (err)
    5846                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to initialize err_recovery_lock");
    5847                 :            : 
    5848                 :            :         return err;
    5849                 :            : }
    5850                 :            : 
    5851                 :            : /* This should be called after we have queried trusted VF cap */
    5852                 :          0 : static int bnxt_alloc_switch_domain(struct bnxt *bp)
    5853                 :            : {
    5854                 :            :         int rc = 0;
    5855                 :            : 
    5856         [ #  # ]:          0 :         if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
    5857                 :          0 :                 rc = rte_eth_switch_domain_alloc(&bp->switch_domain_id);
    5858         [ #  # ]:          0 :                 if (rc)
    5859                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
    5860                 :            :                                     "Failed to alloc switch domain: %d", rc);
    5861                 :            :                 else
    5862                 :          0 :                         PMD_DRV_LOG_LINE(INFO,
    5863                 :            :                                     "Switch domain allocated %d",
    5864                 :            :                                     bp->switch_domain_id);
    5865                 :            :         }
    5866                 :            : 
    5867                 :          0 :         return rc;
    5868                 :            : }
    5869                 :            : 
    5870                 :          0 : static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
    5871                 :            : {
    5872                 :            :         int rc = 0;
    5873                 :            : 
    5874         [ #  # ]:          0 :         if (reconfig_dev) {
    5875                 :          0 :                 rc = bnxt_get_config(bp);
    5876         [ #  # ]:          0 :                 if (rc)
    5877                 :            :                         return rc;
    5878                 :            :         }
    5879                 :            : 
    5880                 :          0 :         rc = bnxt_alloc_switch_domain(bp);
    5881         [ #  # ]:          0 :         if (rc)
    5882                 :            :                 return rc;
    5883                 :            : 
    5884         [ #  # ]:          0 :         if (!reconfig_dev) {
    5885                 :          0 :                 rc = bnxt_setup_mac_addr(bp->eth_dev);
    5886         [ #  # ]:          0 :                 if (rc)
    5887                 :            :                         return rc;
    5888                 :            :         } else {
    5889                 :          0 :                 rc = bnxt_restore_dflt_mac(bp);
    5890         [ #  # ]:          0 :                 if (rc)
    5891                 :            :                         return rc;
    5892                 :            :         }
    5893                 :            : 
    5894                 :          0 :         bnxt_config_vf_req_fwd(bp);
    5895                 :            : 
    5896                 :          0 :         rc = bnxt_hwrm_func_driver_register(bp);
    5897         [ #  # ]:          0 :         if (rc) {
    5898                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to register driver");
    5899                 :          0 :                 return -EBUSY;
    5900                 :            :         }
    5901                 :            : 
    5902         [ #  # ]:          0 :         if (BNXT_PF(bp)) {
    5903         [ #  # ]:          0 :                 if (bp->pdev->max_vfs) {
    5904                 :          0 :                         rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
    5905         [ #  # ]:          0 :                         if (rc) {
    5906                 :          0 :                                 PMD_DRV_LOG_LINE(ERR, "Failed to allocate VFs");
    5907                 :          0 :                                 return rc;
    5908                 :            :                         }
    5909                 :            :                 } else {
    5910                 :          0 :                         rc = bnxt_hwrm_allocate_pf_only(bp);
    5911         [ #  # ]:          0 :                         if (rc) {
    5912                 :          0 :                                 PMD_DRV_LOG_LINE(ERR,
    5913                 :            :                                             "Failed to allocate PF resources");
    5914                 :          0 :                                 return rc;
    5915                 :            :                         }
    5916                 :            :                 }
    5917                 :            :         }
    5918                 :            : 
    5919         [ #  # ]:          0 :         if (!reconfig_dev) {
    5920                 :          0 :                 bp->rss_conf.rss_key = rte_zmalloc("bnxt_rss_key",
    5921                 :            :                                                    HW_HASH_KEY_SIZE, 0);
    5922         [ #  # ]:          0 :                 if (bp->rss_conf.rss_key == NULL) {
    5923                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "port %u cannot allocate RSS hash key memory",
    5924                 :            :                                     bp->eth_dev->data->port_id);
    5925                 :          0 :                         return -ENOMEM;
    5926                 :            :                 }
    5927                 :            :         }
    5928                 :            : 
    5929                 :          0 :         rc = bnxt_alloc_mem(bp, reconfig_dev);
    5930         [ #  # ]:          0 :         if (rc)
    5931                 :            :                 return rc;
    5932                 :            : 
    5933                 :          0 :         rc = bnxt_setup_int(bp);
    5934         [ #  # ]:          0 :         if (rc)
    5935                 :            :                 return rc;
    5936                 :            : 
    5937                 :          0 :         rc = bnxt_request_int(bp);
    5938         [ #  # ]:          0 :         if (rc)
    5939                 :            :                 return rc;
    5940                 :            : 
    5941                 :          0 :         rc = bnxt_init_ctx_mem(bp);
    5942         [ #  # ]:          0 :         if (rc) {
    5943                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to init adv_flow_counters");
    5944                 :          0 :                 return rc;
    5945                 :            :         }
    5946                 :            : 
    5947                 :            :         return 0;
    5948                 :            : }
    5949                 :            : 
    5950                 :            : static int
    5951                 :          0 : bnxt_parse_devarg_flow_xstat(__rte_unused const char *key,
    5952                 :            :                              const char *value, void *opaque_arg)
    5953                 :            : {
    5954                 :            :         struct bnxt *bp = opaque_arg;
    5955                 :            :         unsigned long flow_xstat;
    5956                 :          0 :         char *end = NULL;
    5957                 :            : 
    5958         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    5959                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    5960                 :            :                             "Invalid parameter passed to flow_xstat devarg.");
    5961                 :          0 :                 return -EINVAL;
    5962                 :            :         }
    5963                 :            : 
    5964                 :          0 :         flow_xstat = strtoul(value, &end, 10);
    5965   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    5966         [ #  # ]:          0 :             (flow_xstat == ULONG_MAX && errno == ERANGE)) {
    5967                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    5968                 :            :                             "Invalid parameter passed to flow_xstat devarg.");
    5969                 :          0 :                 return -EINVAL;
    5970                 :            :         }
    5971                 :            : 
    5972         [ #  # ]:          0 :         if (BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)) {
    5973                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    5974                 :            :                             "Invalid value passed to flow_xstat devarg.");
    5975                 :          0 :                 return -EINVAL;
    5976                 :            :         }
    5977                 :            : 
    5978                 :          0 :         bp->flags |= BNXT_FLAG_FLOW_XSTATS_EN;
    5979                 :            :         if (BNXT_FLOW_XSTATS_EN(bp))
    5980                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "flow_xstat feature enabled.");
    5981                 :            : 
    5982                 :          0 :         return 0;
    5983                 :            : }
    5984                 :            : 
    5985                 :            : static int
    5986                 :          0 : bnxt_parse_devarg_max_num_kflows(__rte_unused const char *key,
    5987                 :            :                                         const char *value, void *opaque_arg)
    5988                 :            : {
    5989                 :            :         struct bnxt *bp = opaque_arg;
    5990                 :            :         unsigned long max_num_kflows;
    5991                 :          0 :         char *end = NULL;
    5992                 :            : 
    5993         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    5994                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    5995                 :            :                         "Invalid parameter passed to max_num_kflows devarg.");
    5996                 :          0 :                 return -EINVAL;
    5997                 :            :         }
    5998                 :            : 
    5999                 :          0 :         max_num_kflows = strtoul(value, &end, 10);
    6000   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6001         [ #  # ]:          0 :                 (max_num_kflows == ULONG_MAX && errno == ERANGE)) {
    6002                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6003                 :            :                         "Invalid parameter passed to max_num_kflows devarg.");
    6004                 :          0 :                 return -EINVAL;
    6005                 :            :         }
    6006                 :            : 
    6007         [ #  # ]:          0 :         if (bnxt_devarg_max_num_kflow_invalid(max_num_kflows)) {
    6008                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6009                 :            :                         "Invalid value passed to max_num_kflows devarg.");
    6010                 :          0 :                 return -EINVAL;
    6011                 :            :         }
    6012                 :            : 
    6013                 :          0 :         bp->max_num_kflows = max_num_kflows;
    6014                 :            :         if (bp->max_num_kflows)
    6015                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "max_num_kflows set as %ldK.",
    6016                 :            :                                 max_num_kflows);
    6017                 :            : 
    6018                 :          0 :         return 0;
    6019                 :            : }
    6020                 :            : 
    6021                 :            : static int
    6022                 :          0 : bnxt_parse_devarg_cqe_mode(__rte_unused const char *key,
    6023                 :            :                            const char *value, void *opaque_arg)
    6024                 :            : {
    6025                 :            :         struct bnxt *bp = opaque_arg;
    6026                 :            :         unsigned long cqe_mode;
    6027                 :          0 :         char *end = NULL;
    6028                 :            : 
    6029         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6030                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6031                 :            :                             "Invalid parameter passed to cqe-mode "
    6032                 :            :                             "devargs.");
    6033                 :          0 :                 return -EINVAL;
    6034                 :            :         }
    6035                 :            : 
    6036                 :          0 :         cqe_mode = strtoul(value, &end, 10);
    6037   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6038         [ #  # ]:          0 :             (cqe_mode == ULONG_MAX && errno == ERANGE)) {
    6039                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6040                 :            :                             "Invalid parameter passed to cqe-mode "
    6041                 :            :                             "devargs.");
    6042                 :          0 :                 return -EINVAL;
    6043                 :            :         }
    6044                 :            : 
    6045         [ #  # ]:          0 :         if (BNXT_DEVARG_CQE_MODE_INVALID(cqe_mode)) {
    6046                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid cqe-mode(%d) devargs.",
    6047                 :            :                             (uint16_t)cqe_mode);
    6048                 :          0 :                 return -EINVAL;
    6049                 :            :         }
    6050                 :            : 
    6051         [ #  # ]:          0 :         if (cqe_mode == 1)
    6052                 :          0 :                 bp->flags2 |= BNXT_FLAGS2_COMPRESSED_RX_CQE;
    6053                 :          0 :         PMD_DRV_LOG_LINE(INFO, "cqe-mode=%d feature enabled.", (uint8_t)cqe_mode);
    6054                 :            : 
    6055                 :          0 :         return 0;
    6056                 :            : }
    6057                 :            : 
    6058                 :            : static int
    6059                 :          0 : bnxt_parse_devarg_app_id(__rte_unused const char *key,
    6060                 :            :                                  const char *value, void *opaque_arg)
    6061                 :            : {
    6062                 :            :         struct bnxt *bp = opaque_arg;
    6063                 :            :         unsigned long app_id;
    6064                 :          0 :         char *end = NULL;
    6065                 :            : 
    6066         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6067                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6068                 :            :                             "Invalid parameter passed to app-id "
    6069                 :            :                             "devargs.");
    6070                 :          0 :                 return -EINVAL;
    6071                 :            :         }
    6072                 :            : 
    6073                 :          0 :         app_id = strtoul(value, &end, 10);
    6074   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6075         [ #  # ]:          0 :             (app_id == ULONG_MAX && errno == ERANGE)) {
    6076                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6077                 :            :                             "Invalid parameter passed to app_id "
    6078                 :            :                             "devargs.");
    6079                 :          0 :                 return -EINVAL;
    6080                 :            :         }
    6081                 :            : 
    6082         [ #  # ]:          0 :         if (BNXT_DEVARG_APP_ID_INVALID(app_id)) {
    6083                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid app-id(%d) devargs.",
    6084                 :            :                             (uint16_t)app_id);
    6085                 :          0 :                 return -EINVAL;
    6086                 :            :         }
    6087                 :            : 
    6088                 :          0 :         bp->app_id = app_id;
    6089                 :          0 :         PMD_DRV_LOG_LINE(INFO, "app-id=%d feature enabled.", (uint16_t)app_id);
    6090                 :            : 
    6091                 :          0 :         return 0;
    6092                 :            : }
    6093                 :            : 
    6094                 :            : static int
    6095                 :          0 : bnxt_parse_devarg_mpc(__rte_unused const char *key,
    6096                 :            :                       const char *value, __rte_unused void *opaque_arg)
    6097                 :            : {
    6098                 :          0 :         char *end = NULL;
    6099                 :            : 
    6100         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6101                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6102                 :            :                                  "Invalid parameter passed to app-id "
    6103                 :            :                                  "devargs");
    6104                 :          0 :                 return -EINVAL;
    6105                 :            :         }
    6106                 :            : 
    6107                 :          0 :         mpc = strtoul(value, &end, 10);
    6108   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6109         [ #  # ]:          0 :             (mpc == ULONG_MAX && errno == ERANGE)) {
    6110                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid parameter passed to mpc "
    6111                 :            :                                  "devargs");
    6112                 :          0 :                 return -EINVAL;
    6113                 :            :         }
    6114                 :            : 
    6115         [ #  # ]:          0 :         if (BNXT_DEVARG_MPC_INVALID(mpc)) {
    6116                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid mpc(%d) devargs",
    6117                 :            :                                  (uint16_t)mpc);
    6118                 :          0 :                 return -EINVAL;
    6119                 :            :         }
    6120                 :            : 
    6121                 :          0 :         PMD_DRV_LOG_LINE(INFO, "MPC%d feature enabled", (uint16_t)mpc);
    6122                 :          0 :         return 0;
    6123                 :            : }
    6124                 :            : 
    6125                 :            : static int
    6126                 :          0 : bnxt_parse_devarg_ieee_1588(__rte_unused const char *key,
    6127                 :            :                             const char *value, void *opaque_arg)
    6128                 :            : {
    6129                 :            :         struct bnxt *bp = opaque_arg;
    6130                 :            :         unsigned long ieee_1588;
    6131                 :          0 :         char *end = NULL;
    6132                 :            : 
    6133         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6134                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6135                 :            :                             "Invalid parameter passed to ieee-1588 "
    6136                 :            :                             "devargs.");
    6137                 :          0 :                 return -EINVAL;
    6138                 :            :         }
    6139                 :            : 
    6140                 :          0 :         ieee_1588 = strtoul(value, &end, 10);
    6141   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6142         [ #  # ]:          0 :             (ieee_1588 == ULONG_MAX && errno == ERANGE)) {
    6143                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6144                 :            :                             "Invalid parameter passed to ieee_1588 "
    6145                 :            :                             "devargs.");
    6146                 :          0 :                 return -EINVAL;
    6147                 :            :         }
    6148                 :            : 
    6149         [ #  # ]:          0 :         if (BNXT_DEVARG_IEEE_1588_INVALID(ieee_1588)) {
    6150                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid ieee-1588(%d) devargs.",
    6151                 :            :                             (uint16_t)ieee_1588);
    6152                 :          0 :                 return -EINVAL;
    6153                 :            :         }
    6154                 :            : 
    6155                 :          0 :         bp->ieee_1588 = ieee_1588;
    6156                 :          0 :         PMD_DRV_LOG_LINE(INFO, "ieee-1588=%d feature enabled.", (uint16_t)ieee_1588);
    6157                 :            : 
    6158                 :          0 :         return 0;
    6159                 :            : }
    6160                 :            : 
    6161                 :            : static int
    6162                 :          0 : bnxt_parse_devarg_rep_is_pf(__rte_unused const char *key,
    6163                 :            :                             const char *value, void *opaque_arg)
    6164                 :            : {
    6165                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6166                 :            :         unsigned long rep_is_pf;
    6167                 :          0 :         char *end = NULL;
    6168                 :            : 
    6169         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6170                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6171                 :            :                             "Invalid parameter passed to rep_is_pf devargs.");
    6172                 :          0 :                 return -EINVAL;
    6173                 :            :         }
    6174                 :            : 
    6175                 :          0 :         rep_is_pf = strtoul(value, &end, 10);
    6176   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6177         [ #  # ]:          0 :             (rep_is_pf == ULONG_MAX && errno == ERANGE)) {
    6178                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6179                 :            :                             "Invalid parameter passed to rep_is_pf devargs.");
    6180                 :          0 :                 return -EINVAL;
    6181                 :            :         }
    6182                 :            : 
    6183         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf)) {
    6184                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6185                 :            :                             "Invalid value passed to rep_is_pf devargs.");
    6186                 :          0 :                 return -EINVAL;
    6187                 :            :         }
    6188                 :            : 
    6189                 :          0 :         vfr_bp->flags |= rep_is_pf;
    6190         [ #  # ]:          0 :         if (BNXT_REP_PF(vfr_bp))
    6191                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "PF representor");
    6192                 :            :         else
    6193                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "VF representor");
    6194                 :            : 
    6195                 :            :         return 0;
    6196                 :            : }
    6197                 :            : 
    6198                 :            : static int
    6199                 :          0 : bnxt_parse_devarg_rep_based_pf(__rte_unused const char *key,
    6200                 :            :                                const char *value, void *opaque_arg)
    6201                 :            : {
    6202                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6203                 :            :         unsigned long rep_based_pf;
    6204                 :          0 :         char *end = NULL;
    6205                 :            : 
    6206         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6207                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6208                 :            :                             "Invalid parameter passed to rep_based_pf "
    6209                 :            :                             "devargs.");
    6210                 :          0 :                 return -EINVAL;
    6211                 :            :         }
    6212                 :            : 
    6213                 :          0 :         rep_based_pf = strtoul(value, &end, 10);
    6214   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6215         [ #  # ]:          0 :             (rep_based_pf == ULONG_MAX && errno == ERANGE)) {
    6216                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6217                 :            :                             "Invalid parameter passed to rep_based_pf "
    6218                 :            :                             "devargs.");
    6219                 :          0 :                 return -EINVAL;
    6220                 :            :         }
    6221                 :            : 
    6222         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf)) {
    6223                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6224                 :            :                             "Invalid value passed to rep_based_pf devargs.");
    6225                 :          0 :                 return -EINVAL;
    6226                 :            :         }
    6227                 :            : 
    6228                 :          0 :         vfr_bp->rep_based_pf = rep_based_pf;
    6229                 :          0 :         vfr_bp->flags |= BNXT_REP_BASED_PF_VALID;
    6230                 :            : 
    6231                 :          0 :         PMD_DRV_LOG_LINE(INFO, "rep-based-pf = %d", vfr_bp->rep_based_pf);
    6232                 :            : 
    6233                 :          0 :         return 0;
    6234                 :            : }
    6235                 :            : 
    6236                 :            : static int
    6237                 :          0 : bnxt_parse_devarg_rep_q_r2f(__rte_unused const char *key,
    6238                 :            :                             const char *value, void *opaque_arg)
    6239                 :            : {
    6240                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6241                 :            :         unsigned long rep_q_r2f;
    6242                 :          0 :         char *end = NULL;
    6243                 :            : 
    6244         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6245                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6246                 :            :                             "Invalid parameter passed to rep_q_r2f "
    6247                 :            :                             "devargs.");
    6248                 :          0 :                 return -EINVAL;
    6249                 :            :         }
    6250                 :            : 
    6251                 :          0 :         rep_q_r2f = strtoul(value, &end, 10);
    6252   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6253         [ #  # ]:          0 :             (rep_q_r2f == ULONG_MAX && errno == ERANGE)) {
    6254                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6255                 :            :                             "Invalid parameter passed to rep_q_r2f "
    6256                 :            :                             "devargs.");
    6257                 :          0 :                 return -EINVAL;
    6258                 :            :         }
    6259                 :            : 
    6260         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f)) {
    6261                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6262                 :            :                             "Invalid value passed to rep_q_r2f devargs.");
    6263                 :          0 :                 return -EINVAL;
    6264                 :            :         }
    6265                 :            : 
    6266                 :          0 :         vfr_bp->rep_q_r2f = rep_q_r2f;
    6267                 :          0 :         vfr_bp->flags |= BNXT_REP_Q_R2F_VALID;
    6268                 :          0 :         PMD_DRV_LOG_LINE(INFO, "rep-q-r2f = %d", vfr_bp->rep_q_r2f);
    6269                 :            : 
    6270                 :          0 :         return 0;
    6271                 :            : }
    6272                 :            : 
    6273                 :            : static int
    6274                 :          0 : bnxt_parse_devarg_rep_q_f2r(__rte_unused const char *key,
    6275                 :            :                             const char *value, void *opaque_arg)
    6276                 :            : {
    6277                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6278                 :            :         unsigned long rep_q_f2r;
    6279                 :          0 :         char *end = NULL;
    6280                 :            : 
    6281         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6282                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6283                 :            :                             "Invalid parameter passed to rep_q_f2r "
    6284                 :            :                             "devargs.");
    6285                 :          0 :                 return -EINVAL;
    6286                 :            :         }
    6287                 :            : 
    6288                 :          0 :         rep_q_f2r = strtoul(value, &end, 10);
    6289   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6290         [ #  # ]:          0 :             (rep_q_f2r == ULONG_MAX && errno == ERANGE)) {
    6291                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6292                 :            :                             "Invalid parameter passed to rep_q_f2r "
    6293                 :            :                             "devargs.");
    6294                 :          0 :                 return -EINVAL;
    6295                 :            :         }
    6296                 :            : 
    6297         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r)) {
    6298                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6299                 :            :                             "Invalid value passed to rep_q_f2r devargs.");
    6300                 :          0 :                 return -EINVAL;
    6301                 :            :         }
    6302                 :            : 
    6303                 :          0 :         vfr_bp->rep_q_f2r = rep_q_f2r;
    6304                 :          0 :         vfr_bp->flags |= BNXT_REP_Q_F2R_VALID;
    6305                 :          0 :         PMD_DRV_LOG_LINE(INFO, "rep-q-f2r = %d", vfr_bp->rep_q_f2r);
    6306                 :            : 
    6307                 :          0 :         return 0;
    6308                 :            : }
    6309                 :            : 
    6310                 :            : static int
    6311                 :          0 : bnxt_parse_devarg_rep_fc_r2f(__rte_unused const char *key,
    6312                 :            :                              const char *value, void *opaque_arg)
    6313                 :            : {
    6314                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6315                 :            :         unsigned long rep_fc_r2f;
    6316                 :          0 :         char *end = NULL;
    6317                 :            : 
    6318         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6319                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6320                 :            :                             "Invalid parameter passed to rep_fc_r2f "
    6321                 :            :                             "devargs.");
    6322                 :          0 :                 return -EINVAL;
    6323                 :            :         }
    6324                 :            : 
    6325                 :          0 :         rep_fc_r2f = strtoul(value, &end, 10);
    6326   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6327         [ #  # ]:          0 :             (rep_fc_r2f == ULONG_MAX && errno == ERANGE)) {
    6328                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6329                 :            :                             "Invalid parameter passed to rep_fc_r2f "
    6330                 :            :                             "devargs.");
    6331                 :          0 :                 return -EINVAL;
    6332                 :            :         }
    6333                 :            : 
    6334         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f)) {
    6335                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6336                 :            :                             "Invalid value passed to rep_fc_r2f devargs.");
    6337                 :          0 :                 return -EINVAL;
    6338                 :            :         }
    6339                 :            : 
    6340                 :          0 :         vfr_bp->flags |= BNXT_REP_FC_R2F_VALID;
    6341                 :          0 :         vfr_bp->rep_fc_r2f = rep_fc_r2f;
    6342                 :          0 :         PMD_DRV_LOG_LINE(INFO, "rep-fc-r2f = %lu", rep_fc_r2f);
    6343                 :            : 
    6344                 :          0 :         return 0;
    6345                 :            : }
    6346                 :            : 
    6347                 :            : static int
    6348                 :          0 : bnxt_parse_devarg_rep_fc_f2r(__rte_unused const char *key,
    6349                 :            :                              const char *value, void *opaque_arg)
    6350                 :            : {
    6351                 :            :         struct bnxt_representor *vfr_bp = opaque_arg;
    6352                 :            :         unsigned long rep_fc_f2r;
    6353                 :          0 :         char *end = NULL;
    6354                 :            : 
    6355         [ #  # ]:          0 :         if (!value || !opaque_arg) {
    6356                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6357                 :            :                             "Invalid parameter passed to rep_fc_f2r "
    6358                 :            :                             "devargs.");
    6359                 :          0 :                 return -EINVAL;
    6360                 :            :         }
    6361                 :            : 
    6362                 :          0 :         rep_fc_f2r = strtoul(value, &end, 10);
    6363   [ #  #  #  #  :          0 :         if (end == NULL || *end != '\0' ||
                   #  # ]
    6364         [ #  # ]:          0 :             (rep_fc_f2r == ULONG_MAX && errno == ERANGE)) {
    6365                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6366                 :            :                             "Invalid parameter passed to rep_fc_f2r "
    6367                 :            :                             "devargs.");
    6368                 :          0 :                 return -EINVAL;
    6369                 :            :         }
    6370                 :            : 
    6371         [ #  # ]:          0 :         if (BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)) {
    6372                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6373                 :            :                             "Invalid value passed to rep_fc_f2r devargs.");
    6374                 :          0 :                 return -EINVAL;
    6375                 :            :         }
    6376                 :            : 
    6377                 :          0 :         vfr_bp->flags |= BNXT_REP_FC_F2R_VALID;
    6378                 :          0 :         vfr_bp->rep_fc_f2r = rep_fc_f2r;
    6379                 :          0 :         PMD_DRV_LOG_LINE(INFO, "rep-fc-f2r = %lu", rep_fc_f2r);
    6380                 :            : 
    6381                 :          0 :         return 0;
    6382                 :            : }
    6383                 :            : 
    6384                 :            : static int
    6385                 :          0 : bnxt_parse_dev_args(struct bnxt *bp, struct rte_devargs *devargs)
    6386                 :            : {
    6387                 :            :         struct rte_kvargs *kvlist;
    6388                 :            :         int ret = 0;
    6389                 :            : 
    6390         [ #  # ]:          0 :         if (devargs == NULL)
    6391                 :            :                 return 0;
    6392                 :            : 
    6393                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, bnxt_dev_args);
    6394         [ #  # ]:          0 :         if (kvlist == NULL)
    6395                 :            :                 return -EINVAL;
    6396                 :            : 
    6397                 :            :         /*
    6398                 :            :          * Handler for "flow_xstat" devarg.
    6399                 :            :          * Invoked as for ex: "-a 0000:00:0d.0,flow_xstat=1"
    6400                 :            :          */
    6401                 :          0 :         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_FLOW_XSTAT,
    6402                 :            :                                  bnxt_parse_devarg_flow_xstat, bp);
    6403         [ #  # ]:          0 :         if (ret)
    6404                 :          0 :                 goto err;
    6405                 :            : 
    6406                 :            :         /*
    6407                 :            :          * Handler for "max_num_kflows" devarg.
    6408                 :            :          * Invoked as for ex: "-a 000:00:0d.0,max_num_kflows=32"
    6409                 :            :          */
    6410                 :          0 :         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_MAX_NUM_KFLOWS,
    6411                 :            :                                  bnxt_parse_devarg_max_num_kflows, bp);
    6412         [ #  # ]:          0 :         if (ret)
    6413                 :          0 :                 goto err;
    6414                 :            : 
    6415                 :          0 : err:
    6416                 :            :         /*
    6417                 :            :          * Handler for "app-id" devarg.
    6418                 :            :          * Invoked as for ex: "-a 000:00:0d.0,app-id=1"
    6419                 :            :          */
    6420                 :          0 :         rte_kvargs_process(kvlist, BNXT_DEVARG_APP_ID,
    6421                 :            :                            bnxt_parse_devarg_app_id, bp);
    6422                 :            : 
    6423                 :            :         /*
    6424                 :            :          * Handler for "ieee-1588" devarg.
    6425                 :            :          * Invoked as for ex: "-a 000:00:0d.0,ieee-1588=1"
    6426                 :            :          */
    6427                 :          0 :         rte_kvargs_process(kvlist, BNXT_DEVARG_IEEE_1588,
    6428                 :            :                            bnxt_parse_devarg_ieee_1588, bp);
    6429                 :            : 
    6430                 :            :         /*
    6431                 :            :          * Handler for "mpc" devarg.
    6432                 :            :          * Invoked as for ex: "-a 000:00:0d.0,mpc=1"
    6433                 :            :          */
    6434                 :          0 :         rte_kvargs_process(kvlist, BNXT_DEVARG_MPC,
    6435                 :            :                            bnxt_parse_devarg_mpc, bp);
    6436                 :            : 
    6437                 :            :         /*
    6438                 :            :          * Handler for "cqe-mode" devarg.
    6439                 :            :          * Invoked as for ex: "-a 000:00:0d.0,cqe-mode=1"
    6440                 :            :          */
    6441                 :          0 :         rte_kvargs_process(kvlist, BNXT_DEVARG_CQE_MODE,
    6442                 :            :                            bnxt_parse_devarg_cqe_mode, bp);
    6443                 :            : 
    6444                 :          0 :         rte_kvargs_free(kvlist);
    6445                 :          0 :         return ret;
    6446                 :            : }
    6447                 :            : 
    6448                 :            : /* Allocate and initialize various fields in bnxt struct that
    6449                 :            :  * need to be allocated/destroyed only once in the lifetime of the driver
    6450                 :            :  */
    6451                 :          0 : static int bnxt_drv_init(struct rte_eth_dev *eth_dev)
    6452                 :            : {
    6453                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    6454                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    6455                 :            :         int rc = 0;
    6456                 :            : 
    6457                 :          0 :         bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
    6458                 :            : 
    6459         [ #  # ]:          0 :         if (bnxt_vf_pciid(pci_dev->id.device_id))
    6460                 :          0 :                 bp->flags |= BNXT_FLAG_VF;
    6461                 :            : 
    6462                 :            :         if (bnxt_p5_device(pci_dev->id.device_id))
    6463                 :          0 :                 bp->flags |= BNXT_FLAG_CHIP_P5;
    6464                 :            : 
    6465                 :            :         if (bnxt_p7_device(pci_dev->id.device_id))
    6466                 :          0 :                 bp->flags |= BNXT_FLAG_CHIP_P7;
    6467                 :            : 
    6468         [ #  # ]:          0 :         if (pci_dev->id.device_id == BROADCOM_DEV_ID_58802 ||
    6469         [ #  # ]:          0 :             pci_dev->id.device_id == BROADCOM_DEV_ID_58804 ||
    6470         [ #  # ]:          0 :             pci_dev->id.device_id == BROADCOM_DEV_ID_58808 ||
    6471                 :            :             pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
    6472                 :          0 :                 bp->flags |= BNXT_FLAG_STINGRAY;
    6473                 :            : 
    6474                 :          0 :         rc = bnxt_map_pci_bars(eth_dev);
    6475         [ #  # ]:          0 :         if (rc) {
    6476                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6477                 :            :                             "Failed to initialize board rc: %x", rc);
    6478                 :          0 :                 return rc;
    6479                 :            :         }
    6480                 :            : 
    6481                 :            :         rc = bnxt_alloc_pf_info(bp);
    6482                 :            :         if (rc)
    6483                 :            :                 return rc;
    6484                 :            : 
    6485                 :            :         rc = bnxt_alloc_link_info(bp);
    6486                 :            :         if (rc)
    6487                 :            :                 return rc;
    6488                 :            : 
    6489                 :            :         rc = bnxt_alloc_parent_info(bp);
    6490                 :            :         if (rc)
    6491                 :            :                 return rc;
    6492                 :            : 
    6493                 :          0 :         rc = bnxt_alloc_hwrm_resources(bp);
    6494         [ #  # ]:          0 :         if (rc) {
    6495                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6496                 :            :                             "Failed to allocate response buffer rc: %x", rc);
    6497                 :          0 :                 return rc;
    6498                 :            :         }
    6499                 :          0 :         rc = bnxt_alloc_leds_info(bp);
    6500         [ #  # ]:          0 :         if (rc)
    6501                 :            :                 return rc;
    6502                 :            : 
    6503                 :          0 :         rc = bnxt_alloc_cos_queues(bp);
    6504         [ #  # ]:          0 :         if (rc)
    6505                 :            :                 return rc;
    6506                 :            : 
    6507                 :          0 :         rc = bnxt_init_locks(bp);
    6508         [ #  # ]:          0 :         if (rc)
    6509                 :            :                 return rc;
    6510                 :            : 
    6511                 :          0 :         rc = bnxt_get_config(bp);
    6512         [ #  # ]:          0 :         if (rc)
    6513                 :            :                 return rc;
    6514                 :            : 
    6515   [ #  #  #  # ]:          0 :         if (BNXT_TRUFLOW_EN(bp)) {
    6516                 :            :                 /* extra mbuf field is required to store CFA code from mark */
    6517                 :            :                 static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
    6518                 :            :                         .name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
    6519                 :            :                         .size = sizeof(bnxt_cfa_code_dynfield_t),
    6520                 :            :                         .align = alignof(bnxt_cfa_code_dynfield_t),
    6521                 :            :                 };
    6522                 :          0 :                 bnxt_cfa_code_dynfield_offset =
    6523                 :          0 :                         rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
    6524         [ #  # ]:          0 :                 if (bnxt_cfa_code_dynfield_offset < 0) {
    6525                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
    6526                 :            :                             "Failed to register mbuf field for TruFlow mark");
    6527                 :          0 :                         return -rte_errno;
    6528                 :            :                 }
    6529                 :            :         }
    6530                 :            : 
    6531                 :            :         return rc;
    6532                 :            : }
    6533                 :            : 
    6534                 :            : static int
    6535                 :          0 : bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
    6536                 :            : {
    6537                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    6538                 :            :         static int version_printed;
    6539                 :            :         struct bnxt *bp;
    6540                 :            :         int rc;
    6541                 :            : 
    6542         [ #  # ]:          0 :         if (version_printed++ == 0)
    6543                 :          0 :                 PMD_DRV_LOG_LINE(INFO, "%s", bnxt_version);
    6544                 :            : 
    6545                 :          0 :         eth_dev->dev_ops = &bnxt_dev_ops;
    6546                 :          0 :         eth_dev->rx_queue_count = bnxt_rx_queue_count_op;
    6547                 :          0 :         eth_dev->rx_descriptor_status = bnxt_rx_descriptor_status_op;
    6548                 :          0 :         eth_dev->tx_descriptor_status = bnxt_tx_descriptor_status_op;
    6549                 :          0 :         eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
    6550                 :          0 :         eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
    6551                 :            : 
    6552                 :            :         /*
    6553                 :            :          * For secondary processes, we don't initialise any further
    6554                 :            :          * as primary has already done this work.
    6555                 :            :          */
    6556         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    6557                 :            :                 return 0;
    6558                 :            : 
    6559                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
    6560                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    6561                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
    6562                 :            : 
    6563                 :          0 :         bp = eth_dev->data->dev_private;
    6564                 :            : 
    6565                 :            :         /* set the default app id */
    6566                 :          0 :         bp->app_id = bnxt_ulp_default_app_id_get();
    6567                 :            : 
    6568                 :            :         /* Parse dev arguments passed on when starting the DPDK application. */
    6569                 :          0 :         rc = bnxt_parse_dev_args(bp, pci_dev->device.devargs);
    6570         [ #  # ]:          0 :         if (rc)
    6571                 :          0 :                 goto error_free;
    6572                 :            : 
    6573                 :          0 :         rc = bnxt_drv_init(eth_dev);
    6574         [ #  # ]:          0 :         if (rc)
    6575                 :          0 :                 goto error_free;
    6576                 :            : 
    6577                 :          0 :         rc = bnxt_init_resources(bp, false);
    6578         [ #  # ]:          0 :         if (rc)
    6579                 :          0 :                 goto error_free;
    6580                 :            : 
    6581                 :          0 :         rc = bnxt_alloc_stats_mem(bp);
    6582         [ #  # ]:          0 :         if (rc)
    6583                 :          0 :                 goto error_free;
    6584                 :            : 
    6585                 :          0 :         PMD_DRV_LOG_LINE(INFO,
    6586                 :            :                     "Found %s device at mem %" PRIX64 ", node addr %pM",
    6587                 :            :                     DRV_MODULE_NAME,
    6588                 :            :                     pci_dev->mem_resource[0].phys_addr,
    6589                 :            :                     pci_dev->mem_resource[0].addr);
    6590                 :            : 
    6591                 :          0 :         return 0;
    6592                 :            : 
    6593                 :          0 : error_free:
    6594                 :          0 :         bnxt_dev_uninit(eth_dev);
    6595                 :          0 :         return rc;
    6596                 :            : }
    6597                 :            : 
    6598                 :            : 
    6599                 :            : static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
    6600                 :            : {
    6601                 :            :         if (!ctx)
    6602                 :            :                 return;
    6603                 :            : 
    6604                 :          0 :         rte_free(ctx->va);
    6605                 :            : 
    6606                 :          0 :         ctx->va = NULL;
    6607                 :          0 :         ctx->dma = RTE_BAD_IOVA;
    6608                 :          0 :         ctx->ctx_id = BNXT_CTX_VAL_INVAL;
    6609                 :            : }
    6610                 :            : 
    6611                 :          0 : static void bnxt_unregister_fc_ctx_mem(struct bnxt *bp)
    6612                 :            : {
    6613                 :          0 :         bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
    6614                 :            :                                   CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
    6615                 :          0 :                                   bp->flow_stat->rx_fc_out_tbl.ctx_id,
    6616                 :          0 :                                   bp->flow_stat->max_fc,
    6617                 :            :                                   false);
    6618                 :            : 
    6619                 :          0 :         bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
    6620                 :            :                                   CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
    6621                 :          0 :                                   bp->flow_stat->tx_fc_out_tbl.ctx_id,
    6622                 :          0 :                                   bp->flow_stat->max_fc,
    6623                 :            :                                   false);
    6624                 :            : 
    6625         [ #  # ]:          0 :         if (bp->flow_stat->rx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
    6626                 :          0 :                 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_in_tbl.ctx_id);
    6627                 :          0 :         bp->flow_stat->rx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
    6628                 :            : 
    6629         [ #  # ]:          0 :         if (bp->flow_stat->rx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
    6630                 :          0 :                 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_out_tbl.ctx_id);
    6631                 :          0 :         bp->flow_stat->rx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
    6632                 :            : 
    6633         [ #  # ]:          0 :         if (bp->flow_stat->tx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
    6634                 :          0 :                 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_in_tbl.ctx_id);
    6635                 :          0 :         bp->flow_stat->tx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
    6636                 :            : 
    6637         [ #  # ]:          0 :         if (bp->flow_stat->tx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
    6638                 :          0 :                 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_out_tbl.ctx_id);
    6639                 :          0 :         bp->flow_stat->tx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
    6640                 :          0 : }
    6641                 :            : 
    6642                 :          0 : static void bnxt_uninit_fc_ctx_mem(struct bnxt *bp)
    6643                 :            : {
    6644                 :          0 :         bnxt_unregister_fc_ctx_mem(bp);
    6645                 :            : 
    6646                 :          0 :         bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_in_tbl);
    6647                 :          0 :         bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_out_tbl);
    6648                 :          0 :         bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_in_tbl);
    6649                 :          0 :         bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_out_tbl);
    6650                 :          0 : }
    6651                 :            : 
    6652                 :            : static void bnxt_uninit_ctx_mem(struct bnxt *bp)
    6653                 :            : {
    6654         [ #  # ]:          0 :         if (BNXT_FLOW_XSTATS_EN(bp))
    6655                 :          0 :                 bnxt_uninit_fc_ctx_mem(bp);
    6656                 :            : }
    6657                 :            : 
    6658                 :            : static void
    6659                 :            : bnxt_free_error_recovery_info(struct bnxt *bp)
    6660                 :            : {
    6661                 :          0 :         rte_free(bp->recovery_info);
    6662                 :          0 :         bp->recovery_info = NULL;
    6663                 :          0 :         bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
    6664                 :            : }
    6665                 :            : 
    6666                 :            : static int
    6667                 :          0 : bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
    6668                 :            : {
    6669                 :            :         int rc;
    6670                 :            : 
    6671                 :          0 :         bnxt_free_int(bp);
    6672                 :          0 :         bnxt_free_mem(bp, reconfig_dev);
    6673                 :            : 
    6674                 :          0 :         bnxt_hwrm_func_buf_unrgtr(bp);
    6675         [ #  # ]:          0 :         if (bp->pf != NULL) {
    6676                 :          0 :                 rte_free(bp->pf->vf_req_buf);
    6677                 :          0 :                 bp->pf->vf_req_buf = NULL;
    6678                 :            :         }
    6679                 :            : 
    6680                 :          0 :         rc = bnxt_hwrm_func_driver_unregister(bp);
    6681                 :          0 :         bp->flags &= ~BNXT_FLAG_REGISTERED;
    6682                 :          0 :         bnxt_free_ctx_mem(bp);
    6683         [ #  # ]:          0 :         if (!reconfig_dev) {
    6684                 :          0 :                 bnxt_free_hwrm_resources(bp);
    6685                 :            :                 bnxt_free_error_recovery_info(bp);
    6686                 :          0 :                 rte_free(bp->mcast_addr_list);
    6687                 :          0 :                 bp->mcast_addr_list = NULL;
    6688                 :          0 :                 rte_free(bp->rss_conf.rss_key);
    6689                 :          0 :                 bp->rss_conf.rss_key = NULL;
    6690                 :            :         }
    6691                 :            : 
    6692                 :            :         bnxt_uninit_ctx_mem(bp);
    6693                 :            : 
    6694                 :            :         bnxt_free_flow_stats_info(bp);
    6695                 :          0 :         bnxt_free_switch_domain(bp);
    6696                 :          0 :         rte_free(bp->ptp_cfg);
    6697                 :          0 :         bp->ptp_cfg = NULL;
    6698                 :          0 :         return rc;
    6699                 :            : }
    6700                 :            : 
    6701                 :            : static int
    6702                 :          0 : bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
    6703                 :            : {
    6704         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    6705                 :            :                 return -EPERM;
    6706                 :            : 
    6707                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "Calling Device uninit");
    6708                 :            : 
    6709         [ #  # ]:          0 :         if (eth_dev->state != RTE_ETH_DEV_UNUSED)
    6710                 :          0 :                 bnxt_dev_close_op(eth_dev);
    6711                 :            : 
    6712                 :            :         return 0;
    6713                 :            : }
    6714                 :            : 
    6715                 :          0 : static int bnxt_pci_remove_dev_with_reps(struct rte_eth_dev *eth_dev)
    6716                 :            : {
    6717                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
    6718                 :            :         struct rte_eth_dev *vf_rep_eth_dev;
    6719                 :            :         int ret = 0, i;
    6720                 :            : 
    6721         [ #  # ]:          0 :         if (!bp)
    6722                 :            :                 return -EINVAL;
    6723                 :            : 
    6724         [ #  # ]:          0 :         for (i = 0; i < bp->num_reps; i++) {
    6725                 :          0 :                 vf_rep_eth_dev = bp->rep_info[i].vfr_eth_dev;
    6726         [ #  # ]:          0 :                 if (!vf_rep_eth_dev)
    6727                 :          0 :                         continue;
    6728                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR pci remove",
    6729                 :            :                             vf_rep_eth_dev->data->port_id);
    6730                 :          0 :                 rte_eth_dev_destroy(vf_rep_eth_dev, bnxt_representor_uninit);
    6731                 :            :         }
    6732                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci remove",
    6733                 :            :                     eth_dev->data->port_id);
    6734                 :          0 :         ret = rte_eth_dev_destroy(eth_dev, bnxt_dev_uninit);
    6735                 :            : 
    6736                 :          0 :         return ret;
    6737                 :            : }
    6738                 :            : 
    6739                 :            : static void bnxt_free_rep_info(struct bnxt *bp)
    6740                 :            : {
    6741                 :          0 :         rte_free(bp->rep_info);
    6742                 :          0 :         bp->rep_info = NULL;
    6743                 :          0 :         rte_free(bp->cfa_code_map);
    6744                 :          0 :         bp->cfa_code_map = NULL;
    6745                 :            : }
    6746                 :            : 
    6747                 :          0 : static int bnxt_init_rep_info(struct bnxt *bp)
    6748                 :            : {
    6749                 :            :         int i = 0, rc;
    6750                 :            : 
    6751         [ #  # ]:          0 :         if (bp->rep_info)
    6752                 :            :                 return 0;
    6753                 :            : 
    6754                 :          0 :         bp->rep_info = rte_zmalloc("bnxt_rep_info",
    6755         [ #  # ]:          0 :                                    sizeof(bp->rep_info[0]) * BNXT_MAX_VF_REPS(bp),
    6756                 :            :                                    0);
    6757         [ #  # ]:          0 :         if (!bp->rep_info) {
    6758                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to alloc memory for rep info");
    6759                 :          0 :                 return -ENOMEM;
    6760                 :            :         }
    6761                 :          0 :         bp->cfa_code_map = rte_zmalloc("bnxt_cfa_code_map",
    6762                 :            :                                        sizeof(*bp->cfa_code_map) *
    6763                 :            :                                        BNXT_MAX_CFA_CODE, 0);
    6764         [ #  # ]:          0 :         if (!bp->cfa_code_map) {
    6765                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Failed to alloc memory for cfa_code_map");
    6766                 :            :                 bnxt_free_rep_info(bp);
    6767                 :          0 :                 return -ENOMEM;
    6768                 :            :         }
    6769                 :            : 
    6770         [ #  # ]:          0 :         for (i = 0; i < BNXT_MAX_CFA_CODE; i++)
    6771                 :          0 :                 bp->cfa_code_map[i] = BNXT_VF_IDX_INVALID;
    6772                 :            : 
    6773                 :          0 :         rc = pthread_mutex_init(&bp->rep_info->vfr_start_lock, NULL);
    6774         [ #  # ]:          0 :         if (rc) {
    6775                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Unable to initialize vfr_start_lock");
    6776                 :            :                 bnxt_free_rep_info(bp);
    6777                 :          0 :                 return rc;
    6778                 :            :         }
    6779                 :            : 
    6780                 :            :         return rc;
    6781                 :            : }
    6782                 :            : 
    6783                 :          0 : static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
    6784                 :            :                                struct rte_eth_devargs *eth_da,
    6785                 :            :                                struct rte_eth_dev *backing_eth_dev,
    6786                 :            :                                const char *dev_args)
    6787                 :            : {
    6788                 :            :         struct rte_eth_dev *vf_rep_eth_dev;
    6789                 :            :         char name[RTE_ETH_NAME_MAX_LEN];
    6790                 :          0 :         struct bnxt *backing_bp = backing_eth_dev->data->dev_private;
    6791         [ #  # ]:          0 :         uint16_t max_vf_reps = BNXT_MAX_VF_REPS(backing_bp);
    6792                 :            : 
    6793                 :            :         uint16_t num_rep;
    6794                 :            :         int i, ret = 0;
    6795                 :            :         struct rte_kvargs *kvlist = NULL;
    6796                 :            : 
    6797         [ #  # ]:          0 :         if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
    6798                 :            :                 return 0;
    6799         [ #  # ]:          0 :         if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
    6800                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "unsupported representor type %d",
    6801                 :            :                             eth_da->type);
    6802                 :          0 :                 return -ENOTSUP;
    6803                 :            :         }
    6804                 :          0 :         num_rep = eth_da->nb_representor_ports;
    6805         [ #  # ]:          0 :         if (num_rep > max_vf_reps) {
    6806                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "nb_representor_ports = %d > %d MAX VF REPS",
    6807                 :            :                             num_rep, max_vf_reps);
    6808                 :          0 :                 return -EINVAL;
    6809                 :            :         }
    6810                 :            : 
    6811         [ #  # ]:          0 :         if (num_rep >= RTE_MAX_ETHPORTS) {
    6812                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6813                 :            :                             "nb_representor_ports = %d > %d MAX ETHPORTS",
    6814                 :            :                             num_rep, RTE_MAX_ETHPORTS);
    6815                 :          0 :                 return -EINVAL;
    6816                 :            :         }
    6817                 :            : 
    6818         [ #  # ]:          0 :         if (!(BNXT_PF(backing_bp) || BNXT_VF_IS_TRUSTED(backing_bp))) {
    6819                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
    6820                 :            :                             "Not a PF or trusted VF. No Representor support");
    6821                 :            :                 /* Returning an error is not an option.
    6822                 :            :                  * Applications are not handling this correctly
    6823                 :            :                  */
    6824                 :          0 :                 return 0;
    6825                 :            :         }
    6826                 :            : 
    6827         [ #  # ]:          0 :         if (bnxt_init_rep_info(backing_bp))
    6828                 :            :                 return 0;
    6829                 :            : 
    6830         [ #  # ]:          0 :         for (i = 0; i < num_rep; i++) {
    6831                 :          0 :                 struct bnxt_representor representor = {
    6832                 :          0 :                         .vf_id = eth_da->representor_ports[i],
    6833                 :          0 :                         .switch_domain_id = backing_bp->switch_domain_id,
    6834                 :            :                         .parent_dev = backing_eth_dev
    6835                 :            :                 };
    6836                 :            : 
    6837         [ #  # ]:          0 :                 if (representor.vf_id >= max_vf_reps) {
    6838                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "VF-Rep id %d >= %d MAX VF ID",
    6839                 :            :                                     representor.vf_id, max_vf_reps);
    6840                 :          0 :                         continue;
    6841                 :            :                 }
    6842                 :            : 
    6843                 :            :                 /* representor port net_bdf_port */
    6844                 :          0 :                 snprintf(name, sizeof(name), "net_%s_representor_%d",
    6845                 :            :                          pci_dev->device.name, eth_da->representor_ports[i]);
    6846                 :            : 
    6847                 :          0 :                 kvlist = rte_kvargs_parse(dev_args, bnxt_dev_args);
    6848         [ #  # ]:          0 :                 if (kvlist) {
    6849                 :            :                         /*
    6850                 :            :                          * Handler for "rep_is_pf" devarg.
    6851                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6852                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6853                 :            :                          */
    6854                 :          0 :                         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_IS_PF,
    6855                 :            :                                                  bnxt_parse_devarg_rep_is_pf,
    6856                 :            :                                                  (void *)&representor);
    6857         [ #  # ]:          0 :                         if (ret) {
    6858                 :            :                                 ret = -EINVAL;
    6859                 :          0 :                                 goto err;
    6860                 :            :                         }
    6861                 :            :                         /*
    6862                 :            :                          * Handler for "rep_based_pf" devarg.
    6863                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6864                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6865                 :            :                          */
    6866                 :          0 :                         ret = rte_kvargs_process(kvlist,
    6867                 :            :                                                  BNXT_DEVARG_REP_BASED_PF,
    6868                 :            :                                                  bnxt_parse_devarg_rep_based_pf,
    6869                 :            :                                                  (void *)&representor);
    6870         [ #  # ]:          0 :                         if (ret) {
    6871                 :            :                                 ret = -EINVAL;
    6872                 :          0 :                                 goto err;
    6873                 :            :                         }
    6874                 :            :                         /*
    6875                 :            :                          * Handler for "rep_based_pf" devarg.
    6876                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6877                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6878                 :            :                          */
    6879                 :          0 :                         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_R2F,
    6880                 :            :                                                  bnxt_parse_devarg_rep_q_r2f,
    6881                 :            :                                                  (void *)&representor);
    6882         [ #  # ]:          0 :                         if (ret) {
    6883                 :            :                                 ret = -EINVAL;
    6884                 :          0 :                                 goto err;
    6885                 :            :                         }
    6886                 :            :                         /*
    6887                 :            :                          * Handler for "rep_based_pf" devarg.
    6888                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6889                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6890                 :            :                          */
    6891                 :          0 :                         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_F2R,
    6892                 :            :                                                  bnxt_parse_devarg_rep_q_f2r,
    6893                 :            :                                                  (void *)&representor);
    6894         [ #  # ]:          0 :                         if (ret) {
    6895                 :            :                                 ret = -EINVAL;
    6896                 :          0 :                                 goto err;
    6897                 :            :                         }
    6898                 :            :                         /*
    6899                 :            :                          * Handler for "rep_based_pf" devarg.
    6900                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6901                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6902                 :            :                          */
    6903                 :          0 :                         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_R2F,
    6904                 :            :                                                  bnxt_parse_devarg_rep_fc_r2f,
    6905                 :            :                                                  (void *)&representor);
    6906         [ #  # ]:          0 :                         if (ret) {
    6907                 :            :                                 ret = -EINVAL;
    6908                 :          0 :                                 goto err;
    6909                 :            :                         }
    6910                 :            :                         /*
    6911                 :            :                          * Handler for "rep_based_pf" devarg.
    6912                 :            :                          * Invoked as for ex: "-a 000:00:0d.0,
    6913                 :            :                          * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
    6914                 :            :                          */
    6915                 :          0 :                         ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_F2R,
    6916                 :            :                                                  bnxt_parse_devarg_rep_fc_f2r,
    6917                 :            :                                                  (void *)&representor);
    6918         [ #  # ]:          0 :                         if (ret) {
    6919                 :            :                                 ret = -EINVAL;
    6920                 :          0 :                                 goto err;
    6921                 :            :                         }
    6922                 :            :                 }
    6923                 :            : 
    6924                 :          0 :                 ret = rte_eth_dev_create(&pci_dev->device, name,
    6925                 :            :                                          sizeof(struct bnxt_representor),
    6926                 :            :                                          NULL, NULL,
    6927                 :            :                                          bnxt_representor_init,
    6928                 :            :                                          &representor);
    6929         [ #  # ]:          0 :                 if (ret) {
    6930                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "failed to create bnxt vf "
    6931                 :            :                                     "representor %s.", name);
    6932                 :          0 :                         goto err;
    6933                 :            :                 }
    6934                 :            : 
    6935                 :          0 :                 vf_rep_eth_dev = rte_eth_dev_allocated(name);
    6936         [ #  # ]:          0 :                 if (!vf_rep_eth_dev) {
    6937                 :          0 :                         PMD_DRV_LOG_LINE(ERR, "Failed to find the eth_dev"
    6938                 :            :                                     " for VF-Rep: %s.", name);
    6939                 :            :                         ret = -ENODEV;
    6940                 :          0 :                         goto err;
    6941                 :            :                 }
    6942                 :            : 
    6943                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR pci probe",
    6944                 :            :                             backing_eth_dev->data->port_id);
    6945                 :          0 :                 backing_bp->rep_info[representor.vf_id].vfr_eth_dev =
    6946                 :            :                                                          vf_rep_eth_dev;
    6947                 :          0 :                 backing_bp->num_reps++;
    6948                 :            : 
    6949                 :            :         }
    6950                 :            : 
    6951                 :          0 :         rte_kvargs_free(kvlist);
    6952                 :          0 :         return 0;
    6953                 :            : 
    6954                 :            : err:
    6955                 :            :         /* If num_rep > 1, then rollback already created
    6956                 :            :          * ports, since we'll be failing the probe anyway
    6957                 :            :          */
    6958         [ #  # ]:          0 :         if (num_rep > 1)
    6959                 :          0 :                 bnxt_pci_remove_dev_with_reps(backing_eth_dev);
    6960                 :          0 :         rte_errno = -ret;
    6961                 :          0 :         rte_kvargs_free(kvlist);
    6962                 :            : 
    6963                 :          0 :         return ret;
    6964                 :            : }
    6965                 :            : 
    6966                 :          0 : static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
    6967                 :            :                           struct rte_pci_device *pci_dev)
    6968                 :            : {
    6969                 :          0 :         struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
    6970                 :            :         struct rte_eth_dev *backing_eth_dev;
    6971                 :            :         uint16_t num_rep;
    6972                 :            :         int ret = 0;
    6973                 :            : 
    6974         [ #  # ]:          0 :         if (pci_dev->device.devargs) {
    6975                 :          0 :                 ret = rte_eth_devargs_parse(pci_dev->device.devargs->args,
    6976                 :            :                                             &eth_da, 1);
    6977         [ #  # ]:          0 :                 if (ret < 0)
    6978                 :            :                         return ret;
    6979                 :            :         }
    6980                 :            : 
    6981                 :          0 :         num_rep = eth_da.nb_representor_ports;
    6982                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "nb_representor_ports = %d",
    6983                 :            :                     num_rep);
    6984                 :            : 
    6985                 :            :         /* We could come here after first level of probe is already invoked
    6986                 :            :          * as part of an application bringup(OVS-DPDK vswitchd), so first check
    6987                 :            :          * for already allocated eth_dev for the backing device (PF/Trusted VF)
    6988                 :            :          */
    6989                 :          0 :         backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
    6990         [ #  # ]:          0 :         if (backing_eth_dev == NULL) {
    6991                 :          0 :                 ret = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
    6992                 :            :                                          sizeof(struct bnxt),
    6993                 :            :                                          eth_dev_pci_specific_init, pci_dev,
    6994                 :            :                                          bnxt_dev_init, NULL);
    6995                 :            : 
    6996         [ #  # ]:          0 :                 if (ret || !num_rep)
    6997                 :            :                         return ret;
    6998                 :            : 
    6999                 :          0 :                 backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
    7000                 :            :         }
    7001                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci probe",
    7002                 :            :                     backing_eth_dev->data->port_id);
    7003                 :            : 
    7004         [ #  # ]:          0 :         if (!num_rep)
    7005                 :            :                 return ret;
    7006                 :            : 
    7007                 :            :         /* probe representor ports now */
    7008                 :          0 :         ret = bnxt_rep_port_probe(pci_dev, &eth_da, backing_eth_dev,
    7009                 :          0 :                                   pci_dev->device.devargs->args);
    7010                 :            : 
    7011                 :          0 :         return ret;
    7012                 :            : }
    7013                 :            : 
    7014                 :          0 : static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
    7015                 :            : {
    7016                 :            :         struct rte_eth_dev *eth_dev;
    7017                 :            : 
    7018                 :          0 :         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
    7019         [ #  # ]:          0 :         if (!eth_dev)
    7020                 :            :                 return 0; /* Invoked typically only by OVS-DPDK, by the
    7021                 :            :                            * time it comes here the eth_dev is already
    7022                 :            :                            * deleted by rte_eth_dev_close(), so returning
    7023                 :            :                            * +ve value will at least help in proper cleanup
    7024                 :            :                            */
    7025                 :            : 
    7026                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci remove", eth_dev->data->port_id);
    7027         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    7028         [ #  # ]:          0 :                 if (rte_eth_dev_is_repr(eth_dev))
    7029                 :          0 :                         return rte_eth_dev_destroy(eth_dev,
    7030                 :            :                                                    bnxt_representor_uninit);
    7031                 :            :                 else
    7032                 :          0 :                         return rte_eth_dev_destroy(eth_dev,
    7033                 :            :                                                    bnxt_dev_uninit);
    7034                 :            :         } else {
    7035                 :          0 :                 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
    7036                 :            :         }
    7037                 :            : }
    7038                 :            : 
    7039                 :            : static struct rte_pci_driver bnxt_rte_pmd = {
    7040                 :            :         .id_table = bnxt_pci_id_map,
    7041                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
    7042                 :            :                         RTE_PCI_DRV_INTR_RMV |
    7043                 :            :                         RTE_PCI_DRV_PROBE_AGAIN, /* Needed in case of VF-REPs
    7044                 :            :                                                   * and OVS-DPDK
    7045                 :            :                                                   */
    7046                 :            :         .probe = bnxt_pci_probe,
    7047                 :            :         .remove = bnxt_pci_remove,
    7048                 :            : };
    7049                 :            : 
    7050                 :            : static bool
    7051                 :            : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
    7052                 :            : {
    7053                 :          0 :         if (strcmp(dev->device->driver->name, drv->driver.name))
    7054                 :          0 :                 return false;
    7055                 :            : 
    7056                 :            :         return true;
    7057                 :            : }
    7058                 :            : 
    7059         [ #  # ]:          0 : bool is_bnxt_supported(struct rte_eth_dev *dev)
    7060                 :            : {
    7061                 :          0 :         return is_device_supported(dev, &bnxt_rte_pmd);
    7062                 :            : }
    7063                 :            : 
    7064                 :            : struct bnxt *
    7065                 :          0 : bnxt_pmd_get_bp(uint16_t port)
    7066                 :            : {
    7067                 :            :         struct bnxt *bp;
    7068                 :            :         struct rte_eth_dev *dev;
    7069                 :            : 
    7070         [ #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port)) {
    7071                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Invalid port %d", port);
    7072                 :          0 :                 return NULL;
    7073                 :            :         }
    7074                 :            : 
    7075                 :          0 :         dev = &rte_eth_devices[port];
    7076         [ #  # ]:          0 :         if (!is_bnxt_supported(dev)) {
    7077                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "Device %d not supported", port);
    7078                 :          0 :                 return NULL;
    7079                 :            :         }
    7080                 :            : 
    7081                 :          0 :         bp = (struct bnxt *)dev->data->dev_private;
    7082   [ #  #  #  # ]:          0 :         if (!BNXT_TRUFLOW_EN(bp)) {
    7083                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "TRUFLOW not enabled");
    7084                 :          0 :                 return NULL;
    7085                 :            :         }
    7086                 :            : 
    7087                 :            :         return bp;
    7088                 :            : }
    7089                 :            : 
    7090                 :            : /* check if ULP should be enabled or not */
    7091                 :            : static bool bnxt_enable_ulp(struct bnxt *bp)
    7092                 :            : {
    7093                 :            :         /* truflow and MPC should be enabled */
    7094                 :            :         /* not enabling ulp for cli and no truflow apps */
    7095   [ #  #  #  #  :          0 :         if (BNXT_TRUFLOW_EN(bp) && bp->app_id != 254 &&
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    7096                 :            :             bp->app_id != 255) {
    7097   [ #  #  #  #  :          0 :                 if (BNXT_CHIP_P7(bp) && !mpc)
          #  #  #  #  #  
                #  #  # ]
    7098                 :            :                         return false;
    7099                 :            :                 return true;
    7100                 :            :         }
    7101                 :            :         return false;
    7102                 :            : }
    7103                 :            : 
    7104         [ -  + ]:        251 : RTE_LOG_REGISTER_SUFFIX(bnxt_logtype_driver, driver, NOTICE);
    7105                 :        251 : RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
    7106                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
    7107                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");

Generated by: LCOV version 1.14