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

Generated by: LCOV version 1.14