LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_hwrm.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 3426 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 178 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 3406 0.0 %

           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 <unistd.h>
       7                 :            : 
       8                 :            : #include <rte_byteorder.h>
       9                 :            : #include <rte_common.h>
      10                 :            : #include <rte_cycles.h>
      11                 :            : #include <rte_malloc.h>
      12                 :            : #include <rte_memzone.h>
      13                 :            : #include <rte_version.h>
      14                 :            : #include <rte_io.h>
      15                 :            : 
      16                 :            : #include "bnxt.h"
      17                 :            : #include "bnxt_filter.h"
      18                 :            : #include "bnxt_hwrm.h"
      19                 :            : #include "bnxt_rxq.h"
      20                 :            : #include "bnxt_rxr.h"
      21                 :            : #include "bnxt_ring.h"
      22                 :            : #include "bnxt_txq.h"
      23                 :            : #include "bnxt_txr.h"
      24                 :            : #include "bnxt_vnic.h"
      25                 :            : #include "hsi_struct_def_dpdk.h"
      26                 :            : 
      27                 :            : struct bnxt_plcmodes_cfg {
      28                 :            :         uint32_t        flags;
      29                 :            :         uint16_t        jumbo_thresh;
      30                 :            :         uint16_t        hds_offset;
      31                 :            :         uint16_t        hds_threshold;
      32                 :            : };
      33                 :            : 
      34                 :            : const char *bnxt_backing_store_types[] = {
      35                 :            :         "Queue pair",
      36                 :            :         "Shared receive queue",
      37                 :            :         "Completion queue",
      38                 :            :         "Virtual NIC",
      39                 :            :         "Statistic context",
      40                 :            :         "Slow-path TQM ring",
      41                 :            :         "Fast-path TQM ring",
      42                 :            :         "Unused",
      43                 :            :         "Unused",
      44                 :            :         "Unused",
      45                 :            :         "Unused",
      46                 :            :         "Unused",
      47                 :            :         "Unused",
      48                 :            :         "Unused",
      49                 :            :         "MR and MAV Context",
      50                 :            :         "TIM",
      51                 :            :         "Unused",
      52                 :            :         "Unused",
      53                 :            :         "Unused",
      54                 :            :         "Tx key context",
      55                 :            :         "Rx key context",
      56                 :            :         "Mid-path TQM ring",
      57                 :            :         "SQ Doorbell shadow region",
      58                 :            :         "RQ Doorbell shadow region",
      59                 :            :         "SRQ Doorbell shadow region",
      60                 :            :         "CQ Doorbell shadow region",
      61                 :            :         "QUIC Tx key context",
      62                 :            :         "QUIC Rx key context",
      63                 :            :         "Invalid type",
      64                 :            :         "Invalid type",
      65                 :            :         "Invalid type",
      66                 :            :         "Invalid type",
      67                 :            :         "Invalid type",
      68                 :            :         "Invalid type"
      69                 :            : };
      70                 :            : 
      71                 :            : const char *media_type[] = { "Unknown", "Twisted Pair",
      72                 :            :         "Direct Attached Copper", "Fiber"
      73                 :            : };
      74                 :            : 
      75                 :            : #define MAX_MEDIA_TYPE (sizeof(media_type) / sizeof(const char *))
      76                 :            : 
      77                 :            : const char *link_status_str[] = { "Down. No link or cable detected.",
      78                 :            :         "Down. No link, but a cable has been detected.", "Up.",
      79                 :            : };
      80                 :            : 
      81                 :            : #define MAX_LINK_STR (sizeof(link_status_str) / sizeof(const char *))
      82                 :            : 
      83                 :            : const char *fec_mode[] = {
      84                 :            :         "No active FEC",
      85                 :            :         "FEC CLAUSE 74 (Fire Code).",
      86                 :            :         "FEC CLAUSE 91 RS(528,514).",
      87                 :            :         "FEC RS544_1XN",
      88                 :            :         "FEC RS(544,528)",
      89                 :            :         "FEC RS272_1XN",
      90                 :            :         "FEC RS(272,257)"
      91                 :            : };
      92                 :            : 
      93                 :            : #define MAX_FEC_MODE (sizeof(fec_mode) / sizeof(const char *))
      94                 :            : 
      95                 :            : const char *signal_mode[] = {
      96                 :            :         "NRZ", "PAM4", "PAM4_112"
      97                 :            : };
      98                 :            : 
      99                 :            : #define MAX_SIG_MODE (sizeof(signal_mode) / sizeof(const char *))
     100                 :            : 
     101                 :            : /* multi-purpose multi-key table container.
     102                 :            :  * Add a unique entry for a new PHY attribs as per HW CAS.
     103                 :            :  * Query it using a helper functions.
     104                 :            :  */
     105                 :            : struct link_speeds2_tbl {
     106                 :            :         uint16_t force_val;
     107                 :            :         uint16_t auto_val;
     108                 :            :         uint32_t rte_speed;
     109                 :            :         uint32_t rte_speed_num;
     110                 :            :         uint16_t hwrm_speed;
     111                 :            :         uint16_t sig_mode;
     112                 :            :         const char *desc;
     113                 :            : } link_speeds2_tbl[] = {
     114                 :            :         {
     115                 :            :                 10,
     116                 :            :                 0,
     117                 :            :                 RTE_ETH_LINK_SPEED_1G,
     118                 :            :                 RTE_ETH_SPEED_NUM_1G,
     119                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_1GB,
     120                 :            :                 BNXT_SIG_MODE_NRZ,
     121                 :            :                 "1Gb NRZ",
     122                 :            :         }, {
     123                 :            :                 100,
     124                 :            :                 1,
     125                 :            :                 RTE_ETH_LINK_SPEED_10G,
     126                 :            :                 RTE_ETH_SPEED_NUM_10G,
     127                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_10GB,
     128                 :            :                 BNXT_SIG_MODE_NRZ,
     129                 :            :                 "10Gb NRZ",
     130                 :            :         }, {
     131                 :            :                 250,
     132                 :            :                 2,
     133                 :            :                 RTE_ETH_LINK_SPEED_25G,
     134                 :            :                 RTE_ETH_SPEED_NUM_25G,
     135                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_25GB,
     136                 :            :                 BNXT_SIG_MODE_NRZ,
     137                 :            :                 "25Gb NRZ",
     138                 :            :         }, {
     139                 :            :                 400,
     140                 :            :                 3,
     141                 :            :                 RTE_ETH_LINK_SPEED_40G,
     142                 :            :                 RTE_ETH_SPEED_NUM_40G,
     143                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_40GB,
     144                 :            :                 BNXT_SIG_MODE_NRZ,
     145                 :            :                 "40Gb NRZ",
     146                 :            :         }, {
     147                 :            :                 500,
     148                 :            :                 4,
     149                 :            :                 RTE_ETH_LINK_SPEED_50G,
     150                 :            :                 RTE_ETH_SPEED_NUM_50G,
     151                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_50GB,
     152                 :            :                 BNXT_SIG_MODE_NRZ,
     153                 :            :                 "50Gb NRZ",
     154                 :            :         }, {
     155                 :            :                 1000,
     156                 :            :                 5,
     157                 :            :                 RTE_ETH_LINK_SPEED_100G,
     158                 :            :                 RTE_ETH_SPEED_NUM_100G,
     159                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB,
     160                 :            :                 BNXT_SIG_MODE_NRZ,
     161                 :            :                 "100Gb NRZ",
     162                 :            :         }, {
     163                 :            :                 501,
     164                 :            :                 6,
     165                 :            :                 RTE_ETH_LINK_SPEED_50G,
     166                 :            :                 RTE_ETH_SPEED_NUM_50G,
     167                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_50GB_PAM4_56,
     168                 :            :                 BNXT_SIG_MODE_PAM4,
     169                 :            :                 "50Gb (PAM4-56: 50G per lane)",
     170                 :            :         }, {
     171                 :            :                 1001,
     172                 :            :                 7,
     173                 :            :                 RTE_ETH_LINK_SPEED_100G,
     174                 :            :                 RTE_ETH_SPEED_NUM_100G,
     175                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB_PAM4_56,
     176                 :            :                 BNXT_SIG_MODE_PAM4,
     177                 :            :                 "100Gb (PAM4-56: 50G per lane)",
     178                 :            :         }, {
     179                 :            :                 2001,
     180                 :            :                 8,
     181                 :            :                 RTE_ETH_LINK_SPEED_200G,
     182                 :            :                 RTE_ETH_SPEED_NUM_200G,
     183                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_200GB_PAM4_56,
     184                 :            :                 BNXT_SIG_MODE_PAM4,
     185                 :            :                 "200Gb (PAM4-56: 50G per lane)",
     186                 :            :         }, {
     187                 :            :                 4001,
     188                 :            :                 9,
     189                 :            :                 RTE_ETH_LINK_SPEED_400G,
     190                 :            :                 RTE_ETH_SPEED_NUM_400G,
     191                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_400GB_PAM4_56,
     192                 :            :                 BNXT_SIG_MODE_PAM4,
     193                 :            :                 "400Gb (PAM4-56: 50G per lane)",
     194                 :            :         }, {
     195                 :            :                 1002,
     196                 :            :                 10,
     197                 :            :                 RTE_ETH_LINK_SPEED_100G,
     198                 :            :                 RTE_ETH_SPEED_NUM_100G,
     199                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB_PAM4_112,
     200                 :            :                 BNXT_SIG_MODE_PAM4_112,
     201                 :            :                 "100Gb (PAM4-112: 100G per lane)",
     202                 :            :         }, {
     203                 :            :                 2002,
     204                 :            :                 11,
     205                 :            :                 RTE_ETH_LINK_SPEED_200G,
     206                 :            :                 RTE_ETH_SPEED_NUM_200G,
     207                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_200GB_PAM4_112,
     208                 :            :                 BNXT_SIG_MODE_PAM4_112,
     209                 :            :                 "200Gb (PAM4-112: 100G per lane)",
     210                 :            :         }, {
     211                 :            :                 4002,
     212                 :            :                 12,
     213                 :            :                 RTE_ETH_LINK_SPEED_400G,
     214                 :            :                 RTE_ETH_SPEED_NUM_400G,
     215                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_400GB_PAM4_112,
     216                 :            :                 BNXT_SIG_MODE_PAM4_112,
     217                 :            :                 "400Gb (PAM4-112: 100G per lane)",
     218                 :            :         }, {
     219                 :            :                 0,
     220                 :            :                 13,
     221                 :            :                 RTE_ETH_LINK_SPEED_AUTONEG, /* None matches, AN is default 0 */
     222                 :            :                 RTE_ETH_SPEED_NUM_NONE, /* None matches, No speed */
     223                 :            :                 HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_1GB, /* Placeholder for wrong HWRM */
     224                 :            :                 BNXT_SIG_MODE_NRZ, /* default sig */
     225                 :            :                 "Unknown",
     226                 :            :         },
     227                 :            : };
     228                 :            : 
     229                 :            : #define BNXT_SPEEDS2_TBL_SZ (sizeof(link_speeds2_tbl) / sizeof(*link_speeds2_tbl))
     230                 :            : 
     231                 :            : /* In hwrm_phy_qcfg reports trained up speeds in link_speed(offset:0x8[31:16]) */
     232                 :            : struct link_speeds_tbl {
     233                 :            :         uint16_t hwrm_speed;
     234                 :            :         uint32_t rte_speed_num;
     235                 :            :         const char *desc;
     236                 :            : } link_speeds_tbl[] = {
     237                 :            :         {
     238                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB,
     239                 :            :                 RTE_ETH_SPEED_NUM_100M, "100 MB",
     240                 :            :         }, {
     241                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB,
     242                 :            :                 RTE_ETH_SPEED_NUM_1G, "1 GB",
     243                 :            :         }, {
     244                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB,
     245                 :            :                 RTE_ETH_SPEED_NUM_2_5G, "25 GB",
     246                 :            :         }, {
     247                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB,
     248                 :            :                 RTE_ETH_SPEED_NUM_10G, "10 GB",
     249                 :            :         }, {
     250                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB,
     251                 :            :                 RTE_ETH_SPEED_NUM_20G, "20 GB",
     252                 :            :         }, {
     253                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB,
     254                 :            :                 RTE_ETH_SPEED_NUM_40G, "40 GB",
     255                 :            :         }, {
     256                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB,
     257                 :            :                 RTE_ETH_SPEED_NUM_50G, "50 GB",
     258                 :            :         }, {
     259                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB,
     260                 :            :                 RTE_ETH_SPEED_NUM_100G, "100 GB",
     261                 :            :         }, {
     262                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_200GB,
     263                 :            :                 RTE_ETH_SPEED_NUM_200G, "200 GB",
     264                 :            :         }, {
     265                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_400GB,
     266                 :            :                 RTE_ETH_SPEED_NUM_400G, "400 GB",
     267                 :            :         }, {
     268                 :            :                 0, RTE_ETH_SPEED_NUM_NONE, "None",
     269                 :            :         },
     270                 :            : };
     271                 :            : 
     272                 :            : #define BNXT_SPEEDS_TBL_SZ (sizeof(link_speeds_tbl) / sizeof(*link_speeds_tbl))
     273                 :            : 
     274                 :            : static const char *bnxt_get_xcvr_type(uint32_t xcvr_identifier_type_tx_lpi_timer)
     275                 :            : {
     276                 :          0 :         uint32_t xcvr_type = HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_MASK &
     277                 :            :                 xcvr_identifier_type_tx_lpi_timer;
     278                 :            : 
     279                 :            :         /* Addressing only known CMIS types */
     280                 :          0 :         switch (xcvr_type) {
     281                 :            :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_SFP:
     282                 :            :                 return "SFP";
     283                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP:
     284                 :          0 :                 return "QSFP";
     285                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFPPLUS:
     286                 :          0 :                 return "QSFP+";
     287                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP28:
     288                 :          0 :                 return "QSFP28";
     289                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFPDD:
     290                 :          0 :                 return "QSFP112";
     291                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP112:
     292                 :          0 :                 return "QSFP-DD";
     293                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_UNKNOWN:
     294                 :          0 :                 return "Unknown";
     295                 :          0 :         default:
     296                 :            :                 /* All other/new CMIS variants belong here */
     297                 :          0 :                 return "QSFP-xx new CMIS variant";
     298                 :            :         }
     299                 :            : }
     300                 :            : 
     301                 :            : /* Utility function to lookup speeds2 table and
     302                 :            :  * return a rte to hwrm speed matching row to the client
     303                 :            :  */
     304                 :            : static
     305                 :            : struct link_speeds2_tbl *bnxt_get_rte_hwrm_speeds2_entry(uint32_t speed)
     306                 :            : {
     307                 :            :         int i, max;
     308                 :            : 
     309                 :            :         max = BNXT_SPEEDS2_TBL_SZ - 1;
     310                 :          0 :         speed &= ~RTE_ETH_LINK_SPEED_FIXED;
     311         [ #  # ]:          0 :         for (i = 0; i < max; i++) {
     312         [ #  # ]:          0 :                 if (speed == link_speeds2_tbl[i].rte_speed)
     313                 :            :                         break;
     314                 :            :         }
     315                 :            :         return (struct link_speeds2_tbl *)&link_speeds2_tbl[i];
     316                 :            : }
     317                 :            : 
     318                 :            : /* Utility function to lookup speeds2 table and
     319                 :            :  * return a hwrm to rte speed matching row to the client
     320                 :            :  */
     321                 :            : static struct link_speeds2_tbl *bnxt_get_hwrm_to_rte_speeds2_entry(uint16_t speed)
     322                 :            : {
     323                 :            :         int i, max;
     324                 :            : 
     325                 :            :         max = BNXT_SPEEDS2_TBL_SZ - 1;
     326   [ #  #  #  # ]:          0 :         for (i = 0; i < max; i++) {
     327   [ #  #  #  # ]:          0 :                 if (speed == link_speeds2_tbl[i].hwrm_speed)
     328                 :            :                         break;
     329                 :            :         }
     330                 :            :         return (struct link_speeds2_tbl *)&link_speeds2_tbl[i];
     331                 :            : }
     332                 :            : 
     333                 :            : /* Helper function to lookup auto link_speed table */
     334                 :            : static struct link_speeds_tbl *bnxt_get_hwrm_to_rte_speeds_entry(uint16_t speed)
     335                 :            : {
     336                 :            :         int i, max;
     337                 :            : 
     338                 :            :         max = BNXT_SPEEDS_TBL_SZ - 1;
     339                 :            : 
     340         [ #  # ]:          0 :         for (i = 0; i < max ; i++) {
     341         [ #  # ]:          0 :                 if (speed == link_speeds_tbl[i].hwrm_speed)
     342                 :            :                         break;
     343                 :            :         }
     344                 :            :         return (struct link_speeds_tbl *)&link_speeds_tbl[i];
     345                 :            : }
     346                 :            : 
     347                 :          0 : static int page_getenum(size_t size)
     348                 :            : {
     349         [ #  # ]:          0 :         if (size <= 1 << 4)
     350                 :            :                 return 4;
     351         [ #  # ]:          0 :         if (size <= 1 << 12)
     352                 :            :                 return 12;
     353         [ #  # ]:          0 :         if (size <= 1 << 13)
     354                 :            :                 return 13;
     355         [ #  # ]:          0 :         if (size <= 1 << 16)
     356                 :            :                 return 16;
     357         [ #  # ]:          0 :         if (size <= 1 << 21)
     358                 :            :                 return 21;
     359         [ #  # ]:          0 :         if (size <= 1 << 22)
     360                 :            :                 return 22;
     361         [ #  # ]:          0 :         if (size <= 1 << 30)
     362                 :            :                 return 30;
     363                 :          0 :         PMD_DRV_LOG(ERR, "Page size %zu out of range\n", size);
     364                 :          0 :         return sizeof(int) * 8 - 1;
     365                 :            : }
     366                 :            : 
     367                 :            : static int page_roundup(size_t size)
     368                 :            : {
     369                 :          0 :         return 1 << page_getenum(size);
     370                 :            : }
     371                 :            : 
     372                 :            : static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem,
     373                 :            :                                   uint8_t *pg_attr,
     374                 :            :                                   uint64_t *pg_dir)
     375                 :            : {
     376                 :          0 :         if (rmem->nr_pages == 0)
     377                 :            :                 return;
     378                 :            : 
     379   [ #  #  #  #  :          0 :         if (rmem->nr_pages > 1) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     380                 :          0 :                 *pg_attr = 1;
     381                 :          0 :                 *pg_dir = rte_cpu_to_le_64(rmem->pg_tbl_map);
     382                 :            :         } else {
     383                 :          0 :                 *pg_dir = rte_cpu_to_le_64(rmem->dma_arr[0]);
     384                 :            :         }
     385                 :            : }
     386                 :            : 
     387                 :            : static struct bnxt_cp_ring_info*
     388                 :          0 : bnxt_get_ring_info_by_id(struct bnxt *bp, uint16_t rid, uint16_t type)
     389                 :            : {
     390                 :            :         struct bnxt_cp_ring_info *cp_ring = NULL;
     391                 :            :         uint16_t i;
     392                 :            : 
     393      [ #  #  # ]:          0 :         switch (type) {
     394                 :            :         case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
     395                 :            :         case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
     396                 :            :                 /* FALLTHROUGH */
     397         [ #  # ]:          0 :                 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
     398                 :          0 :                         struct bnxt_rx_queue *rxq = bp->rx_queues[i];
     399                 :            : 
     400         [ #  # ]:          0 :                         if (rxq->cp_ring->cp_ring_struct->fw_ring_id ==
     401                 :            :                             rte_cpu_to_le_16(rid)) {
     402                 :          0 :                                 return rxq->cp_ring;
     403                 :            :                         }
     404                 :            :                 }
     405                 :            :                 break;
     406                 :            :         case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
     407         [ #  # ]:          0 :                 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
     408                 :          0 :                         struct bnxt_tx_queue *txq = bp->tx_queues[i];
     409                 :            : 
     410         [ #  # ]:          0 :                         if (txq->cp_ring->cp_ring_struct->fw_ring_id ==
     411                 :            :                             rte_cpu_to_le_16(rid)) {
     412                 :          0 :                                 return txq->cp_ring;
     413                 :            :                         }
     414                 :            :                 }
     415                 :            :                 break;
     416                 :            :         default:
     417                 :            :                 return cp_ring;
     418                 :            :         }
     419                 :            :         return cp_ring;
     420                 :            : }
     421                 :            : 
     422                 :            : /* Complete a sweep of the CQ ring for the corresponding Tx/Rx/AGG ring.
     423                 :            :  * If the CMPL_BASE_TYPE_HWRM_DONE is not encountered by the last pass,
     424                 :            :  * before timeout, we force the done bit for the cleanup to proceed.
     425                 :            :  * Also if cpr is null, do nothing.. The HWRM command is  not for a
     426                 :            :  * Tx/Rx/AGG ring cleanup.
     427                 :            :  */
     428                 :            : static int
     429                 :          0 : bnxt_check_cq_hwrm_done(struct bnxt_cp_ring_info *cpr,
     430                 :            :                         bool tx, bool rx, bool timeout)
     431                 :            : {
     432                 :            :         int done = 0;
     433                 :            : 
     434         [ #  # ]:          0 :         if (cpr != NULL) {
     435         [ #  # ]:          0 :                 if (tx)
     436                 :          0 :                         done = bnxt_flush_tx_cmp(cpr);
     437                 :            : 
     438         [ #  # ]:          0 :                 if (rx)
     439                 :          0 :                         done = bnxt_flush_rx_cmp(cpr);
     440                 :            : 
     441         [ #  # ]:          0 :                 if (done)
     442         [ #  # ]:          0 :                         PMD_DRV_LOG(DEBUG, "HWRM DONE for %s ring\n",
     443                 :            :                                     rx ? "Rx" : "Tx");
     444                 :            : 
     445                 :            :                 /* We are about to timeout and still haven't seen the
     446                 :            :                  * HWRM done for the Ring free. Force the cleanup.
     447                 :            :                  */
     448         [ #  # ]:          0 :                 if (!done && timeout) {
     449                 :            :                         done = 1;
     450         [ #  # ]:          0 :                         PMD_DRV_LOG(DEBUG, "Timing out for %s ring\n",
     451                 :            :                                     rx ? "Rx" : "Tx");
     452                 :            :                 }
     453                 :            :         } else {
     454                 :            :                 /* This HWRM command is not for a Tx/Rx/AGG ring cleanup.
     455                 :            :                  * Otherwise the cpr would have been valid. So do nothing.
     456                 :            :                  */
     457                 :            :                 done = 1;
     458                 :            :         }
     459                 :            : 
     460                 :          0 :         return done;
     461                 :            : }
     462                 :            : 
     463                 :            : /*
     464                 :            :  * HWRM Functions (sent to HWRM)
     465                 :            :  * These are named bnxt_hwrm_*() and return 0 on success or -110 if the
     466                 :            :  * HWRM command times out, or a negative error code if the HWRM
     467                 :            :  * command was failed by the FW.
     468                 :            :  */
     469                 :            : 
     470                 :          0 : static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
     471                 :            :                                   uint32_t msg_len, bool use_kong_mb)
     472                 :            : {
     473                 :            :         unsigned int i;
     474                 :            :         struct input *req = msg;
     475                 :          0 :         struct output *resp = bp->hwrm_cmd_resp_addr;
     476                 :            :         uint32_t *data = msg;
     477                 :            :         uint8_t *bar;
     478                 :            :         uint8_t *valid;
     479                 :          0 :         uint16_t max_req_len = bp->max_req_len;
     480                 :          0 :         struct hwrm_short_input short_input = { 0 };
     481         [ #  # ]:          0 :         uint16_t bar_offset = use_kong_mb ?
     482                 :            :                 GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
     483         [ #  # ]:          0 :         uint16_t mb_trigger_offset = use_kong_mb ?
     484                 :            :                 GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
     485                 :            :         struct bnxt_cp_ring_info *cpr = NULL;
     486                 :            :         bool is_rx = false;
     487                 :            :         bool is_tx = false;
     488                 :            :         uint32_t timeout;
     489                 :            : 
     490                 :            :         /* Do not send HWRM commands to firmware in error state */
     491         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FATAL_ERROR)
     492                 :            :                 return 0;
     493                 :            : 
     494                 :            :         /* If previous HWRM command timed out, do not send new HWRM command */
     495         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_TIMEDOUT)
     496                 :            :                 return 0;
     497                 :            : 
     498                 :          0 :         timeout = bp->hwrm_cmd_timeout;
     499                 :            : 
     500                 :            :         /* Update the message length for backing store config for new FW. */
     501         [ #  # ]:          0 :         if (bp->fw_ver >= HWRM_VERSION_1_10_2_13 &&
     502         [ #  # ]:          0 :             rte_cpu_to_le_16(req->req_type) == HWRM_FUNC_BACKING_STORE_CFG)
     503                 :            :                 msg_len = BNXT_BACKING_STORE_CFG_LEGACY_LEN;
     504                 :            : 
     505         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_SHORT_CMD ||
     506         [ #  # ]:          0 :             msg_len > bp->max_req_len) {
     507                 :          0 :                 void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
     508                 :            : 
     509                 :          0 :                 memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
     510                 :          0 :                 memcpy(short_cmd_req, req, msg_len);
     511                 :            : 
     512                 :          0 :                 short_input.req_type = rte_cpu_to_le_16(req->req_type);
     513                 :          0 :                 short_input.signature = rte_cpu_to_le_16(
     514                 :            :                                         HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
     515                 :          0 :                 short_input.size = rte_cpu_to_le_16(msg_len);
     516                 :          0 :                 short_input.req_addr =
     517                 :          0 :                         rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
     518                 :            : 
     519                 :            :                 data = (uint32_t *)&short_input;
     520                 :            :                 msg_len = sizeof(short_input);
     521                 :            : 
     522                 :            :                 max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
     523                 :            :         }
     524                 :            : 
     525                 :            :         /* Write request msg to hwrm channel */
     526         [ #  # ]:          0 :         for (i = 0; i < msg_len; i += 4) {
     527                 :          0 :                 bar = (uint8_t *)bp->bar0 + bar_offset + i;
     528                 :          0 :                 rte_write32(*data, bar);
     529                 :          0 :                 data++;
     530                 :            :         }
     531                 :            : 
     532                 :            :         /* Zero the rest of the request space */
     533         [ #  # ]:          0 :         for (; i < max_req_len; i += 4) {
     534                 :          0 :                 bar = (uint8_t *)bp->bar0 + bar_offset + i;
     535                 :            :                 rte_write32(0, bar);
     536                 :            :         }
     537                 :            : 
     538                 :            :         /* Ring channel doorbell */
     539                 :          0 :         bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
     540                 :            :         rte_write32(1, bar);
     541                 :            :         /*
     542                 :            :          * Make sure the channel doorbell ring command complete before
     543                 :            :          * reading the response to avoid getting stale or invalid
     544                 :            :          * responses.
     545                 :            :          */
     546                 :            :         rte_io_mb();
     547                 :            : 
     548                 :            :         /* Check ring flush is done.
     549                 :            :          * This is valid only for Tx and Rx rings (including AGG rings).
     550                 :            :          * The Tx and Rx rings should be freed once the HW confirms all
     551                 :            :          * the internal buffers and BDs associated with the rings are
     552                 :            :          * consumed and the corresponding DMA is handled.
     553                 :            :          */
     554         [ #  # ]:          0 :         if (rte_cpu_to_le_16(req->cmpl_ring) != INVALID_HW_RING_ID) {
     555                 :            :                 /* Check if the TxCQ matches. If that fails check if RxCQ
     556                 :            :                  * matches. And if neither match, is_rx = false, is_tx = false.
     557                 :            :                  */
     558                 :          0 :                 cpr = bnxt_get_ring_info_by_id(bp, req->cmpl_ring,
     559                 :            :                                                HWRM_RING_FREE_INPUT_RING_TYPE_TX);
     560         [ #  # ]:          0 :                 if (cpr == NULL) {
     561                 :            :                         /* Not a TxCQ. Check if the RxCQ matches. */
     562                 :            :                         cpr =
     563                 :          0 :                         bnxt_get_ring_info_by_id(bp, req->cmpl_ring,
     564                 :            :                                                  HWRM_RING_FREE_INPUT_RING_TYPE_RX);
     565         [ #  # ]:          0 :                         if (cpr != NULL)
     566                 :            :                                 is_rx = true;
     567                 :            :                 } else {
     568                 :            :                         is_tx = true;
     569                 :            :                 }
     570                 :            :         }
     571                 :            : 
     572                 :            :         /* Poll for the valid bit */
     573         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
     574                 :            :                 int done;
     575                 :            : 
     576                 :          0 :                 done = bnxt_check_cq_hwrm_done(cpr, is_tx, is_rx,
     577                 :          0 :                                                i == timeout - 1);
     578                 :            :                 /* Sanity check on the resp->resp_len */
     579                 :          0 :                 rte_io_rmb();
     580   [ #  #  #  # ]:          0 :                 if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
     581                 :            :                         /* Last byte of resp contains the valid key */
     582                 :          0 :                         valid = (uint8_t *)resp + resp->resp_len - 1;
     583   [ #  #  #  # ]:          0 :                         if (*valid == HWRM_RESP_VALID_KEY && done)
     584                 :            :                                 break;
     585                 :            :                 }
     586                 :          0 :                 rte_delay_us(1);
     587                 :            :         }
     588                 :            : 
     589         [ #  # ]:          0 :         if (i >= timeout) {
     590                 :            :                 /* Suppress VER_GET timeout messages during reset recovery */
     591         [ #  # ]:          0 :                 if (bp->flags & BNXT_FLAG_FW_RESET &&
     592         [ #  # ]:          0 :                     rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
     593                 :            :                         return -ETIMEDOUT;
     594                 :            : 
     595                 :          0 :                 PMD_DRV_LOG(ERR,
     596                 :            :                             "Error(timeout) sending msg 0x%04x, seq_id %d\n",
     597                 :            :                             req->req_type, req->seq_id);
     598                 :          0 :                 bp->flags |= BNXT_FLAG_FW_TIMEDOUT;
     599                 :          0 :                 return -ETIMEDOUT;
     600                 :            :         }
     601                 :            :         return 0;
     602                 :            : }
     603                 :            : 
     604                 :            : /*
     605                 :            :  * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
     606                 :            :  * spinlock, and does initial processing.
     607                 :            :  *
     608                 :            :  * HWRM_CHECK_RESULT() returns errors on failure and may not be used.  It
     609                 :            :  * releases the spinlock only if it returns. If the regular int return codes
     610                 :            :  * are not used by the function, HWRM_CHECK_RESULT() should not be used
     611                 :            :  * directly, rather it should be copied and modified to suit the function.
     612                 :            :  *
     613                 :            :  * HWRM_UNLOCK() must be called after all response processing is completed.
     614                 :            :  */
     615                 :            : #define HWRM_PREP(req, type, kong) do { \
     616                 :            :         rte_spinlock_lock(&bp->hwrm_lock); \
     617                 :            :         if (bp->hwrm_cmd_resp_addr == NULL) { \
     618                 :            :                 rte_spinlock_unlock(&bp->hwrm_lock); \
     619                 :            :                 return -EACCES; \
     620                 :            :         } \
     621                 :            :         memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
     622                 :            :         (req)->req_type = rte_cpu_to_le_16(type); \
     623                 :            :         (req)->cmpl_ring = rte_cpu_to_le_16(-1); \
     624                 :            :         (req)->seq_id = kong ? rte_cpu_to_le_16(bp->kong_cmd_seq++) :\
     625                 :            :                 rte_cpu_to_le_16(bp->chimp_cmd_seq++); \
     626                 :            :         (req)->target_id = rte_cpu_to_le_16(0xffff); \
     627                 :            :         (req)->resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
     628                 :            : } while (0)
     629                 :            : 
     630                 :            : #define HWRM_CHECK_RESULT_SILENT() do {\
     631                 :            :         if (rc) { \
     632                 :            :                 rte_spinlock_unlock(&bp->hwrm_lock); \
     633                 :            :                 return rc; \
     634                 :            :         } \
     635                 :            :         if (resp->error_code) { \
     636                 :            :                 rc = rte_le_to_cpu_16(resp->error_code); \
     637                 :            :                 rte_spinlock_unlock(&bp->hwrm_lock); \
     638                 :            :                 return rc; \
     639                 :            :         } \
     640                 :            : } while (0)
     641                 :            : 
     642                 :            : #define HWRM_CHECK_RESULT() do {\
     643                 :            :         if (rc) { \
     644                 :            :                 PMD_DRV_LOG(ERR, "failed rc:%d\n", rc); \
     645                 :            :                 rte_spinlock_unlock(&bp->hwrm_lock); \
     646                 :            :                 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
     647                 :            :                         rc = -EACCES; \
     648                 :            :                 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
     649                 :            :                         rc = -ENOSPC; \
     650                 :            :                 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
     651                 :            :                         rc = -EINVAL; \
     652                 :            :                 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
     653                 :            :                         rc = -ENOTSUP; \
     654                 :            :                 else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
     655                 :            :                         rc = -EAGAIN; \
     656                 :            :                 else if (rc > 0) \
     657                 :            :                         rc = -EIO; \
     658                 :            :                 return rc; \
     659                 :            :         } \
     660                 :            :         if (resp->error_code) { \
     661                 :            :                 rc = rte_le_to_cpu_16(resp->error_code); \
     662                 :            :                 if (resp->resp_len >= 16) { \
     663                 :            :                         struct hwrm_err_output *tmp_hwrm_err_op = \
     664                 :            :                                                 (void *)resp; \
     665                 :            :                         PMD_DRV_LOG(ERR, \
     666                 :            :                                 "error %d:%d:%08x:%04x\n", \
     667                 :            :                                 rc, tmp_hwrm_err_op->cmd_err, \
     668                 :            :                                 rte_le_to_cpu_32(\
     669                 :            :                                         tmp_hwrm_err_op->opaque_0), \
     670                 :            :                                 rte_le_to_cpu_16(\
     671                 :            :                                         tmp_hwrm_err_op->opaque_1)); \
     672                 :            :                 } else { \
     673                 :            :                         PMD_DRV_LOG(ERR, "error %d\n", rc); \
     674                 :            :                 } \
     675                 :            :                 rte_spinlock_unlock(&bp->hwrm_lock); \
     676                 :            :                 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
     677                 :            :                         rc = -EACCES; \
     678                 :            :                 else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
     679                 :            :                         rc = -ENOSPC; \
     680                 :            :                 else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
     681                 :            :                         rc = -EINVAL; \
     682                 :            :                 else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
     683                 :            :                         rc = -ENOTSUP; \
     684                 :            :                 else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
     685                 :            :                         rc = -EAGAIN; \
     686                 :            :                 else if (rc > 0) \
     687                 :            :                         rc = -EIO; \
     688                 :            :                 return rc; \
     689                 :            :         } \
     690                 :            : } while (0)
     691                 :            : 
     692                 :            : #define HWRM_UNLOCK()           rte_spinlock_unlock(&bp->hwrm_lock)
     693                 :            : 
     694                 :          0 : int bnxt_hwrm_tf_message_direct(struct bnxt *bp,
     695                 :            :                                 bool use_kong_mb,
     696                 :            :                                 uint16_t msg_type,
     697                 :            :                                 void *msg,
     698                 :            :                                 uint32_t msg_len,
     699                 :            :                                 void *resp_msg,
     700                 :            :                                 uint32_t resp_len)
     701                 :            : {
     702                 :            :         int rc = 0;
     703                 :            :         bool mailbox = BNXT_USE_CHIMP_MB;
     704                 :            :         struct input *req = msg;
     705                 :          0 :         struct output *resp = bp->hwrm_cmd_resp_addr;
     706                 :            : 
     707         [ #  # ]:          0 :         if (use_kong_mb)
     708                 :          0 :                 mailbox = BNXT_USE_KONG(bp);
     709                 :            : 
     710   [ #  #  #  # ]:          0 :         HWRM_PREP(req, msg_type, mailbox);
     711                 :            : 
     712                 :          0 :         rc = bnxt_hwrm_send_message(bp, req, msg_len, mailbox);
     713                 :            : 
     714   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     715                 :            : 
     716         [ #  # ]:          0 :         if (resp_msg)
     717                 :          0 :                 memcpy(resp_msg, resp, resp_len);
     718                 :            : 
     719                 :            :         HWRM_UNLOCK();
     720                 :            : 
     721                 :          0 :         return rc;
     722                 :            : }
     723                 :            : 
     724                 :          0 : int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
     725                 :            : {
     726                 :            :         int rc = 0;
     727                 :          0 :         struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
     728                 :          0 :         struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
     729                 :            : 
     730         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
     731                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
     732                 :          0 :         req.mask = 0;
     733                 :            : 
     734                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     735                 :            : 
     736   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     737                 :            :         HWRM_UNLOCK();
     738                 :            : 
     739                 :          0 :         return rc;
     740                 :            : }
     741                 :            : 
     742                 :          0 : int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
     743                 :            :                                  struct bnxt_vnic_info *vnic,
     744                 :            :                                  uint16_t vlan_count,
     745                 :            :                                  struct bnxt_vlan_table_entry *vlan_table)
     746                 :            : {
     747                 :            :         int rc = 0;
     748                 :          0 :         struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
     749                 :          0 :         struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
     750                 :            :         uint32_t mask = 0;
     751                 :            : 
     752         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
     753                 :            :                 return rc;
     754                 :            : 
     755   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
     756                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
     757                 :            : 
     758         [ #  # ]:          0 :         if (vnic->flags & BNXT_VNIC_INFO_BCAST)
     759                 :            :                 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
     760         [ #  # ]:          0 :         if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
     761                 :          0 :                 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
     762                 :            : 
     763         [ #  # ]:          0 :         if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
     764                 :          0 :                 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
     765                 :            : 
     766         [ #  # ]:          0 :         if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
     767                 :          0 :                 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
     768         [ #  # ]:          0 :         } else if (vnic->flags & BNXT_VNIC_INFO_MCAST) {
     769                 :          0 :                 mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
     770                 :          0 :                 req.num_mc_entries = rte_cpu_to_le_32(bp->nb_mc_addr);
     771                 :          0 :                 req.mc_tbl_addr = rte_cpu_to_le_64(bp->mc_list_dma_addr);
     772                 :            :         }
     773         [ #  # ]:          0 :         if (vlan_table) {
     774         [ #  # ]:          0 :                 if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
     775                 :          0 :                         mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
     776                 :          0 :                 req.vlan_tag_tbl_addr =
     777                 :          0 :                         rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
     778                 :          0 :                 req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
     779                 :            :         }
     780                 :          0 :         req.mask = rte_cpu_to_le_32(mask);
     781                 :            : 
     782                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     783                 :            : 
     784   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     785                 :            :         HWRM_UNLOCK();
     786                 :            : 
     787                 :          0 :         return rc;
     788                 :            : }
     789                 :            : 
     790                 :          0 : int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
     791                 :            :                         uint16_t vlan_count,
     792                 :            :                         struct bnxt_vlan_antispoof_table_entry *vlan_table)
     793                 :            : {
     794                 :            :         int rc = 0;
     795                 :          0 :         struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
     796                 :          0 :         struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
     797                 :            :                                                 bp->hwrm_cmd_resp_addr;
     798                 :            : 
     799                 :            :         /*
     800                 :            :          * Older HWRM versions did not support this command, and the set_rx_mask
     801                 :            :          * list was used for anti-spoof. In 1.8.0, the TX path configuration was
     802                 :            :          * removed from set_rx_mask call, and this command was added.
     803                 :            :          *
     804                 :            :          * This command is also present from 1.7.8.11 and higher,
     805                 :            :          * as well as 1.7.8.0
     806                 :            :          */
     807         [ #  # ]:          0 :         if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
     808         [ #  # ]:          0 :                 if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
     809         [ #  # ]:          0 :                         if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
     810                 :            :                                         (11)))
     811                 :            :                                 return 0;
     812                 :            :                 }
     813                 :            :         }
     814         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
     815                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
     816                 :            : 
     817                 :          0 :         req.vlan_tag_mask_tbl_addr =
     818                 :          0 :                 rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
     819                 :          0 :         req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
     820                 :            : 
     821                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     822                 :            : 
     823   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     824                 :            :         HWRM_UNLOCK();
     825                 :            : 
     826                 :          0 :         return rc;
     827                 :            : }
     828                 :            : 
     829                 :          0 : int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
     830                 :            :                              struct bnxt_filter_info *filter)
     831                 :            : {
     832                 :            :         int rc = 0;
     833                 :            :         struct bnxt_filter_info *l2_filter = filter;
     834                 :            :         struct bnxt_vnic_info *vnic = NULL;
     835                 :          0 :         struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
     836                 :          0 :         struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
     837                 :            : 
     838         [ #  # ]:          0 :         if (filter->fw_l2_filter_id == UINT64_MAX)
     839                 :            :                 return 0;
     840                 :            : 
     841         [ #  # ]:          0 :         if (filter->matching_l2_fltr_ptr)
     842                 :            :                 l2_filter = filter->matching_l2_fltr_ptr;
     843                 :            : 
     844                 :          0 :         PMD_DRV_LOG(DEBUG, "filter: %p l2_filter: %p ref_cnt: %d\n",
     845                 :            :                     filter, l2_filter, l2_filter->l2_ref_cnt);
     846                 :            : 
     847         [ #  # ]:          0 :         if (l2_filter->l2_ref_cnt == 0)
     848                 :            :                 return 0;
     849                 :            : 
     850                 :            :         if (l2_filter->l2_ref_cnt > 0)
     851                 :          0 :                 l2_filter->l2_ref_cnt--;
     852                 :            : 
     853         [ #  # ]:          0 :         if (l2_filter->l2_ref_cnt > 0)
     854                 :            :                 return 0;
     855                 :            : 
     856         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
     857                 :            : 
     858                 :          0 :         req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
     859                 :            : 
     860                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     861                 :            : 
     862   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     863                 :            :         HWRM_UNLOCK();
     864                 :            : 
     865                 :          0 :         filter->fw_l2_filter_id = UINT64_MAX;
     866         [ #  # ]:          0 :         if (l2_filter->l2_ref_cnt == 0) {
     867                 :          0 :                 vnic = l2_filter->vnic;
     868         [ #  # ]:          0 :                 if (vnic) {
     869   [ #  #  #  #  :          0 :                         STAILQ_REMOVE(&vnic->filter, l2_filter,
             #  #  #  # ]
     870                 :            :                                       bnxt_filter_info, next);
     871                 :          0 :                         bnxt_free_filter(bp, l2_filter);
     872                 :            :                 }
     873                 :            :         }
     874                 :            : 
     875                 :            :         return 0;
     876                 :            : }
     877                 :            : 
     878                 :          0 : int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
     879                 :            :                          uint16_t dst_id,
     880                 :            :                          struct bnxt_filter_info *filter)
     881                 :            : {
     882                 :            :         int rc = 0;
     883                 :          0 :         struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
     884                 :          0 :         struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
     885                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
     886                 :            :         const struct rte_eth_vmdq_rx_conf *conf =
     887                 :            :                     &dev_conf->rx_adv_conf.vmdq_rx_conf;
     888                 :            :         uint32_t enables = 0;
     889                 :          0 :         uint16_t j = dst_id - 1;
     890                 :            : 
     891                 :            :         //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
     892         [ #  # ]:          0 :         if ((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) &&
     893         [ #  # ]:          0 :             conf->pool_map[j].pools & (1UL << j)) {
     894                 :          0 :                 PMD_DRV_LOG(DEBUG,
     895                 :            :                         "Add vlan %u to vmdq pool %u\n",
     896                 :            :                         conf->pool_map[j].vlan_id, j);
     897                 :            : 
     898                 :          0 :                 filter->l2_ivlan = conf->pool_map[j].vlan_id;
     899                 :          0 :                 filter->enables |=
     900                 :            :                         HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
     901                 :            :                         HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
     902                 :            :         }
     903                 :            : 
     904         [ #  # ]:          0 :         if (filter->fw_l2_filter_id != UINT64_MAX)
     905                 :          0 :                 bnxt_hwrm_clear_l2_filter(bp, filter);
     906                 :            : 
     907   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
     908                 :            : 
     909                 :            :         /* PMD does not support XDP and RoCE */
     910                 :          0 :         filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_XDP_DISABLE |
     911                 :            :                         HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_TRAFFIC_L2;
     912                 :          0 :         req.flags = rte_cpu_to_le_32(filter->flags);
     913                 :            : 
     914                 :          0 :         enables = filter->enables |
     915                 :            :               HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
     916                 :          0 :         req.dst_id = rte_cpu_to_le_16(dst_id);
     917                 :            : 
     918         [ #  # ]:          0 :         if (enables &
     919                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
     920                 :            :                 memcpy(req.l2_addr, filter->l2_addr,
     921                 :            :                        RTE_ETHER_ADDR_LEN);
     922         [ #  # ]:          0 :         if (enables &
     923                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
     924                 :            :                 memcpy(req.l2_addr_mask, filter->l2_addr_mask,
     925                 :            :                        RTE_ETHER_ADDR_LEN);
     926         [ #  # ]:          0 :         if (enables &
     927                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
     928                 :          0 :                 req.l2_ovlan = filter->l2_ovlan;
     929         [ #  # ]:          0 :         if (enables &
     930                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
     931                 :          0 :                 req.l2_ivlan = filter->l2_ivlan;
     932         [ #  # ]:          0 :         if (enables &
     933                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
     934                 :          0 :                 req.l2_ovlan_mask = filter->l2_ovlan_mask;
     935         [ #  # ]:          0 :         if (enables &
     936                 :            :             HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
     937                 :          0 :                 req.l2_ivlan_mask = filter->l2_ivlan_mask;
     938         [ #  # ]:          0 :         if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
     939                 :          0 :                 req.src_id = rte_cpu_to_le_32(filter->src_id);
     940         [ #  # ]:          0 :         if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
     941                 :          0 :                 req.src_type = filter->src_type;
     942         [ #  # ]:          0 :         if (filter->pri_hint) {
     943                 :          0 :                 req.pri_hint = filter->pri_hint;
     944                 :          0 :                 req.l2_filter_id_hint =
     945                 :          0 :                         rte_cpu_to_le_64(filter->l2_filter_id_hint);
     946                 :            :         }
     947                 :            : 
     948                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
     949                 :            : 
     950                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     951                 :            : 
     952   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
     953                 :            : 
     954                 :          0 :         filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
     955                 :          0 :         filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
     956                 :            :         HWRM_UNLOCK();
     957                 :            : 
     958                 :          0 :         filter->l2_ref_cnt++;
     959                 :            : 
     960                 :          0 :         return rc;
     961                 :            : }
     962                 :            : 
     963                 :          0 : int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
     964                 :            : {
     965                 :          0 :         struct hwrm_port_mac_cfg_input req = {.req_type = 0};
     966                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
     967                 :            :         uint32_t flags = 0;
     968                 :            :         int rc;
     969                 :            : 
     970         [ #  # ]:          0 :         if (!ptp)
     971                 :            :                 return 0;
     972                 :            : 
     973   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
     974                 :            : 
     975         [ #  # ]:          0 :         if (ptp->rx_filter)
     976                 :            :                 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
     977                 :            :         else
     978                 :            :                 flags |=
     979                 :            :                         HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
     980         [ #  # ]:          0 :         if (ptp->tx_tstamp_en)
     981                 :          0 :                 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
     982                 :            :         else
     983                 :          0 :                 flags |=
     984                 :            :                         HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
     985                 :            : 
     986         [ #  # ]:          0 :         if (ptp->filter_all)
     987                 :          0 :                 flags |=  HWRM_PORT_MAC_CFG_INPUT_FLAGS_ALL_RX_TS_CAPTURE_ENABLE;
     988         [ #  # ]:          0 :         else if (bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS)
     989                 :          0 :                 flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_ALL_RX_TS_CAPTURE_DISABLE;
     990                 :            : 
     991                 :          0 :         req.flags = rte_cpu_to_le_32(flags);
     992                 :          0 :         req.enables = rte_cpu_to_le_32
     993                 :            :                 (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
     994                 :          0 :         req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
     995                 :            : 
     996                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
     997                 :            :         HWRM_UNLOCK();
     998                 :            : 
     999                 :          0 :         return rc;
    1000                 :            : }
    1001                 :            : 
    1002                 :          0 : static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
    1003                 :            : {
    1004                 :            :         int rc = 0;
    1005                 :          0 :         struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
    1006                 :          0 :         struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    1007                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    1008                 :            : 
    1009         [ #  # ]:          0 :         if (ptp)
    1010                 :            :                 return 0;
    1011                 :            : 
    1012         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
    1013                 :            : 
    1014                 :          0 :         req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
    1015                 :            : 
    1016                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1017                 :            : 
    1018   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1019                 :            : 
    1020         [ #  # ]:          0 :         if (BNXT_CHIP_P5(bp)) {
    1021         [ #  # ]:          0 :                 if (!(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_HWRM_ACCESS))
    1022                 :            :                         return 0;
    1023                 :            :         } else {
    1024         [ #  # ]:          0 :                 if (!(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_DIRECT_ACCESS))
    1025                 :            :                         return 0;
    1026                 :            :         }
    1027                 :            : 
    1028         [ #  # ]:          0 :         if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
    1029                 :          0 :                 bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
    1030                 :            : 
    1031                 :          0 :         ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
    1032         [ #  # ]:          0 :         if (!ptp)
    1033                 :            :                 return -ENOMEM;
    1034                 :            : 
    1035         [ #  # ]:          0 :         if (!BNXT_CHIP_P5(bp)) {
    1036                 :          0 :                 ptp->rx_regs[BNXT_PTP_RX_TS_L] =
    1037                 :          0 :                         rte_le_to_cpu_32(resp->rx_ts_reg_off_lower);
    1038                 :          0 :                 ptp->rx_regs[BNXT_PTP_RX_TS_H] =
    1039                 :          0 :                         rte_le_to_cpu_32(resp->rx_ts_reg_off_upper);
    1040                 :          0 :                 ptp->rx_regs[BNXT_PTP_RX_SEQ] =
    1041                 :          0 :                         rte_le_to_cpu_32(resp->rx_ts_reg_off_seq_id);
    1042                 :          0 :                 ptp->rx_regs[BNXT_PTP_RX_FIFO] =
    1043                 :          0 :                         rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo);
    1044                 :          0 :                 ptp->rx_regs[BNXT_PTP_RX_FIFO_ADV] =
    1045                 :          0 :                         rte_le_to_cpu_32(resp->rx_ts_reg_off_fifo_adv);
    1046                 :          0 :                 ptp->tx_regs[BNXT_PTP_TX_TS_L] =
    1047                 :          0 :                         rte_le_to_cpu_32(resp->tx_ts_reg_off_lower);
    1048                 :          0 :                 ptp->tx_regs[BNXT_PTP_TX_TS_H] =
    1049                 :          0 :                         rte_le_to_cpu_32(resp->tx_ts_reg_off_upper);
    1050                 :          0 :                 ptp->tx_regs[BNXT_PTP_TX_SEQ] =
    1051                 :          0 :                         rte_le_to_cpu_32(resp->tx_ts_reg_off_seq_id);
    1052                 :          0 :                 ptp->tx_regs[BNXT_PTP_TX_FIFO] =
    1053                 :          0 :                         rte_le_to_cpu_32(resp->tx_ts_reg_off_fifo);
    1054                 :            :         }
    1055                 :            : 
    1056                 :          0 :         ptp->bp = bp;
    1057                 :          0 :         bp->ptp_cfg = ptp;
    1058                 :            : 
    1059                 :          0 :         return 0;
    1060                 :            : }
    1061                 :            : 
    1062                 :          0 : void bnxt_free_vf_info(struct bnxt *bp)
    1063                 :            : {
    1064                 :            :         int i;
    1065                 :            : 
    1066         [ #  # ]:          0 :         if (bp->pf == NULL)
    1067                 :            :                 return;
    1068                 :            : 
    1069         [ #  # ]:          0 :         if (bp->pf->vf_info == NULL)
    1070                 :            :                 return;
    1071                 :            : 
    1072         [ #  # ]:          0 :         for (i = 0; i < bp->pf->max_vfs; i++) {
    1073                 :          0 :                 rte_free(bp->pf->vf_info[i].vlan_table);
    1074                 :          0 :                 bp->pf->vf_info[i].vlan_table = NULL;
    1075                 :          0 :                 rte_free(bp->pf->vf_info[i].vlan_as_table);
    1076                 :          0 :                 bp->pf->vf_info[i].vlan_as_table = NULL;
    1077                 :            :         }
    1078                 :          0 :         rte_free(bp->pf->vf_info);
    1079                 :          0 :         bp->pf->vf_info = NULL;
    1080                 :            : }
    1081                 :            : 
    1082                 :          0 : static int bnxt_alloc_vf_info(struct bnxt *bp, uint16_t max_vfs)
    1083                 :            : {
    1084                 :          0 :         struct bnxt_child_vf_info *vf_info = bp->pf->vf_info;
    1085                 :            :         int i;
    1086                 :            : 
    1087         [ #  # ]:          0 :         if (vf_info)
    1088                 :          0 :                 bnxt_free_vf_info(bp);
    1089                 :            : 
    1090                 :          0 :         vf_info = rte_zmalloc("bnxt_vf_info", sizeof(*vf_info) * max_vfs, 0);
    1091         [ #  # ]:          0 :         if (vf_info == NULL) {
    1092                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to alloc vf info\n");
    1093                 :          0 :                 return -ENOMEM;
    1094                 :            :         }
    1095                 :            : 
    1096                 :          0 :         bp->pf->max_vfs = max_vfs;
    1097         [ #  # ]:          0 :         for (i = 0; i < max_vfs; i++) {
    1098                 :          0 :                 vf_info[i].fid = bp->pf->first_vf_id + i;
    1099                 :          0 :                 vf_info[i].vlan_table = rte_zmalloc("VF VLAN table",
    1100                 :          0 :                                                     getpagesize(), getpagesize());
    1101         [ #  # ]:          0 :                 if (vf_info[i].vlan_table == NULL) {
    1102                 :          0 :                         PMD_DRV_LOG(ERR, "Failed to alloc VLAN table for VF %d\n", i);
    1103                 :          0 :                         goto err;
    1104                 :            :                 }
    1105                 :          0 :                 rte_mem_lock_page(vf_info[i].vlan_table);
    1106                 :            : 
    1107                 :          0 :                 vf_info[i].vlan_as_table = rte_zmalloc("VF VLAN AS table",
    1108                 :            :                                                        getpagesize(), getpagesize());
    1109         [ #  # ]:          0 :                 if (vf_info[i].vlan_as_table == NULL) {
    1110                 :          0 :                         PMD_DRV_LOG(ERR, "Failed to alloc VLAN AS table for VF %d\n", i);
    1111                 :          0 :                         goto err;
    1112                 :            :                 }
    1113                 :          0 :                 rte_mem_lock_page(vf_info[i].vlan_as_table);
    1114                 :            : 
    1115                 :          0 :                 STAILQ_INIT(&vf_info[i].filter);
    1116                 :            :         }
    1117                 :            : 
    1118                 :          0 :         bp->pf->vf_info = vf_info;
    1119                 :            : 
    1120                 :          0 :         return 0;
    1121                 :          0 : err:
    1122                 :          0 :         bnxt_free_vf_info(bp);
    1123                 :          0 :         return -ENOMEM;
    1124                 :            : }
    1125                 :            : 
    1126                 :          0 : static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
    1127                 :            : {
    1128                 :            :         int rc = 0;
    1129                 :          0 :         struct hwrm_func_qcaps_input req = {.req_type = 0 };
    1130                 :          0 :         struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    1131                 :            :         uint16_t new_max_vfs;
    1132                 :            :         uint32_t flags, flags_ext2;
    1133                 :            : 
    1134         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
    1135                 :            : 
    1136                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    1137                 :            : 
    1138                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1139                 :            : 
    1140   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1141                 :            : 
    1142                 :          0 :         bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
    1143                 :          0 :         flags = rte_le_to_cpu_32(resp->flags);
    1144                 :          0 :         flags_ext2 = rte_le_to_cpu_32(resp->flags_ext2);
    1145                 :            : 
    1146         [ #  # ]:          0 :         if (BNXT_PF(bp)) {
    1147                 :          0 :                 bp->pf->port_id = resp->port_id;
    1148                 :          0 :                 bp->pf->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
    1149                 :          0 :                 bp->pf->total_vfs = rte_le_to_cpu_16(resp->max_vfs);
    1150                 :          0 :                 new_max_vfs = bp->pdev->max_vfs;
    1151         [ #  # ]:          0 :                 if (new_max_vfs != bp->pf->max_vfs) {
    1152                 :          0 :                         rc = bnxt_alloc_vf_info(bp, new_max_vfs);
    1153         [ #  # ]:          0 :                         if (rc)
    1154                 :          0 :                                 goto unlock;
    1155                 :            :                 }
    1156                 :            :         }
    1157                 :            : 
    1158                 :          0 :         bp->fw_fid = rte_le_to_cpu_32(resp->fid);
    1159         [ #  # ]:          0 :         if (!bnxt_check_zero_bytes(resp->mac_address, RTE_ETHER_ADDR_LEN)) {
    1160                 :          0 :                 bp->flags |= BNXT_FLAG_DFLT_MAC_SET;
    1161                 :          0 :                 memcpy(bp->mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
    1162                 :            :         } else {
    1163                 :          0 :                 bp->flags &= ~BNXT_FLAG_DFLT_MAC_SET;
    1164                 :            :         }
    1165                 :          0 :         bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
    1166                 :          0 :         bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
    1167                 :          0 :         bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
    1168                 :          0 :         bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
    1169                 :          0 :         bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
    1170                 :          0 :         bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
    1171                 :          0 :         bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
    1172   [ #  #  #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp) && !bp->pdev->max_vfs)
    1173                 :          0 :                 bp->max_l2_ctx += bp->max_rx_em_flows;
    1174         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
    1175                 :          0 :                 bp->max_vnics = rte_le_to_cpu_16(BNXT_MAX_VNICS_COS_CLASSIFY);
    1176                 :            :         else
    1177                 :          0 :                 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
    1178                 :          0 :         PMD_DRV_LOG(DEBUG, "Max l2_cntxts is %d vnics is %d\n",
    1179                 :            :                     bp->max_l2_ctx, bp->max_vnics);
    1180                 :          0 :         bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
    1181                 :          0 :         bp->max_mcast_addr = rte_le_to_cpu_32(resp->max_mcast_filters);
    1182         [ #  # ]:          0 :         if (!bp->max_mcast_addr)
    1183                 :          0 :                 bp->max_mcast_addr = BNXT_DFLT_MAX_MC_ADDR;
    1184         [ #  # ]:          0 :         memcpy(bp->dsn, resp->device_serial_number, sizeof(bp->dsn));
    1185                 :            : 
    1186         [ #  # ]:          0 :         if (BNXT_PF(bp))
    1187                 :          0 :                 bp->pf->total_vnics = rte_le_to_cpu_16(resp->max_vnics);
    1188                 :            : 
    1189         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
    1190         [ #  # ]:          0 :                 if (BNXT_CHIP_P5(bp) || BNXT_PF(bp)) {
    1191                 :          0 :                         bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
    1192                 :          0 :                         PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
    1193                 :            :                         HWRM_UNLOCK();
    1194                 :          0 :                         bnxt_hwrm_ptp_qcfg(bp);
    1195                 :            :                 }
    1196                 :            :         }
    1197                 :            : 
    1198         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
    1199                 :          0 :                 bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
    1200                 :            : 
    1201         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
    1202                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
    1203                 :          0 :                 PMD_DRV_LOG(DEBUG, "Adapter Error recovery SUPPORTED\n");
    1204                 :            :         }
    1205                 :            : 
    1206         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
    1207                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
    1208                 :            : 
    1209         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_HOT_RESET_CAPABLE)
    1210                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
    1211                 :            : 
    1212         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_LINK_ADMIN_STATUS_SUPPORTED)
    1213                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_LINK_ADMIN;
    1214                 :            : 
    1215         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_BS_V2_SUPPORTED) {
    1216                 :          0 :                 PMD_DRV_LOG(DEBUG, "Backing store v2 supported\n");
    1217         [ #  # ]:          0 :                 if (BNXT_CHIP_P7(bp))
    1218                 :          0 :                         bp->fw_cap |= BNXT_FW_CAP_BACKING_STORE_V2;
    1219                 :            :         }
    1220         [ #  # ]:          0 :         if (!(flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_VLAN_ACCELERATION_TX_DISABLED)) {
    1221                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_VLAN_TX_INSERT;
    1222                 :          0 :                 PMD_DRV_LOG(DEBUG, "VLAN acceleration for TX is enabled\n");
    1223                 :            :         }
    1224                 :            : 
    1225                 :          0 :         bp->tunnel_disable_flag = rte_le_to_cpu_16(resp->tunnel_disable_flag);
    1226         [ #  # ]:          0 :         if (bp->tunnel_disable_flag)
    1227                 :          0 :                 PMD_DRV_LOG(DEBUG, "Tunnel parsing capability is disabled, flags : %#x\n",
    1228                 :            :                             bp->tunnel_disable_flag);
    1229                 :            : 
    1230         [ #  # ]:          0 :         if (flags_ext2 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT2_RX_ALL_PKTS_TIMESTAMPS_SUPPORTED)
    1231                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_RX_ALL_PKT_TS;
    1232         [ #  # ]:          0 :         if (flags_ext2 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT2_UDP_GSO_SUPPORTED)
    1233                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_UDP_GSO;
    1234                 :            : 
    1235                 :          0 : unlock:
    1236                 :            :         HWRM_UNLOCK();
    1237                 :            : 
    1238                 :          0 :         return rc;
    1239                 :            : }
    1240                 :            : 
    1241                 :          0 : int bnxt_hwrm_func_qcaps(struct bnxt *bp)
    1242                 :            : {
    1243                 :            :         int rc;
    1244                 :            : 
    1245                 :          0 :         rc = __bnxt_hwrm_func_qcaps(bp);
    1246         [ #  # ]:          0 :         if (rc == -ENOMEM)
    1247                 :            :                 return rc;
    1248                 :            : 
    1249   [ #  #  #  # ]:          0 :         if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
    1250                 :          0 :                 rc = bnxt_alloc_ctx_mem(bp);
    1251         [ #  # ]:          0 :                 if (rc)
    1252                 :            :                         return rc;
    1253                 :            : 
    1254                 :            :                 /* On older FW,
    1255                 :            :                  * bnxt_hwrm_func_resc_qcaps can fail and cause init failure.
    1256                 :            :                  * But the error can be ignored. Return success.
    1257                 :            :                  */
    1258                 :          0 :                 rc = bnxt_hwrm_func_resc_qcaps(bp);
    1259         [ #  # ]:          0 :                 if (!rc)
    1260                 :          0 :                         bp->flags |= BNXT_FLAG_NEW_RM;
    1261                 :            :         }
    1262                 :            : 
    1263                 :            :         return 0;
    1264                 :            : }
    1265                 :            : 
    1266                 :            : /* VNIC cap covers capability of all VNICs. So no need to pass vnic_id */
    1267                 :          0 : int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
    1268                 :            : {
    1269                 :            :         int rc = 0;
    1270                 :            :         uint32_t flags;
    1271                 :          0 :         struct hwrm_vnic_qcaps_input req = {.req_type = 0 };
    1272                 :          0 :         struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    1273                 :            : 
    1274         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_QCAPS, BNXT_USE_CHIMP_MB);
    1275                 :            : 
    1276                 :            :         req.target_id = rte_cpu_to_le_16(0xffff);
    1277                 :            : 
    1278                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1279                 :            : 
    1280   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1281                 :            : 
    1282                 :          0 :         flags = rte_le_to_cpu_32(resp->flags);
    1283                 :            : 
    1284         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_COS_ASSIGNMENT_CAP) {
    1285                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_COS_CLASSIFY;
    1286                 :          0 :                 PMD_DRV_LOG(INFO, "CoS assignment capability enabled\n");
    1287                 :            :         }
    1288                 :            : 
    1289         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_OUTERMOST_RSS_CAP)
    1290                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_OUTER_RSS;
    1291                 :            : 
    1292         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_OUTERMOST_RSS_TRUSTED_VF_CAP) {
    1293                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_OUTER_RSS_TRUSTED_VF;
    1294                 :          0 :                 PMD_DRV_LOG(DEBUG, "Trusted VF's outer RSS capability is enabled\n");
    1295                 :            :         }
    1296                 :            : 
    1297         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RX_CMPL_V2_CAP)
    1298                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_RX_CMPL_V2;
    1299                 :            : 
    1300         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_VLAN_STRIP_CAP) {
    1301                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_VLAN_RX_STRIP;
    1302                 :          0 :                 PMD_DRV_LOG(DEBUG, "Rx VLAN strip capability enabled\n");
    1303                 :            :         }
    1304                 :            : 
    1305         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RING_SELECT_MODE_XOR_CAP)
    1306                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_XOR_MODE;
    1307                 :            : 
    1308         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RING_SELECT_MODE_TOEPLITZ_CHKSM_CAP)
    1309                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_CHKSM_MODE;
    1310                 :            : 
    1311         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPV6_FLOW_LABEL_CAP)
    1312                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE;
    1313                 :            : 
    1314         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_L2_CQE_MODE_CAP)
    1315                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_L2_CQE_MODE;
    1316                 :            : 
    1317         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_AH_SPI_IPV4_CAP)
    1318                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_AH_SPI4_CAP;
    1319                 :            : 
    1320         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_AH_SPI_IPV6_CAP)
    1321                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_AH_SPI6_CAP;
    1322                 :            : 
    1323         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_ESP_SPI_IPV4_CAP)
    1324                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_ESP_SPI4_CAP;
    1325                 :            : 
    1326         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_ESP_SPI_IPV6_CAP)
    1327                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_ESP_SPI6_CAP;
    1328                 :            : 
    1329         [ #  # ]:          0 :         if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_HW_TUNNEL_TPA_CAP)
    1330                 :          0 :                 bp->vnic_cap_flags |= BNXT_VNIC_CAP_VNIC_TUNNEL_TPA;
    1331                 :            : 
    1332                 :          0 :         bp->max_tpa_v2 = rte_le_to_cpu_16(resp->max_aggs_supported);
    1333                 :            : 
    1334                 :            :         HWRM_UNLOCK();
    1335                 :            : 
    1336                 :          0 :         return rc;
    1337                 :            : }
    1338                 :            : 
    1339                 :          0 : int bnxt_hwrm_func_reset(struct bnxt *bp)
    1340                 :            : {
    1341                 :            :         int rc = 0;
    1342                 :          0 :         struct hwrm_func_reset_input req = {.req_type = 0 };
    1343                 :          0 :         struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
    1344                 :            : 
    1345         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_RESET, BNXT_USE_CHIMP_MB);
    1346                 :            : 
    1347                 :          0 :         req.enables = rte_cpu_to_le_32(0);
    1348                 :            : 
    1349                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1350                 :            : 
    1351   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1352                 :            :         HWRM_UNLOCK();
    1353                 :            : 
    1354                 :          0 :         return rc;
    1355                 :            : }
    1356                 :            : 
    1357                 :          0 : int bnxt_hwrm_func_driver_register(struct bnxt *bp)
    1358                 :            : {
    1359                 :            :         int rc;
    1360                 :            :         uint32_t flags = 0;
    1361                 :          0 :         struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
    1362                 :          0 :         struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
    1363                 :            : 
    1364         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_REGISTERED)
    1365                 :            :                 return 0;
    1366                 :            : 
    1367         [ #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
    1368                 :            :                 flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
    1369         [ #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
    1370                 :          0 :                 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
    1371                 :            : 
    1372                 :            :         /* PFs and trusted VFs should indicate the support of the
    1373                 :            :          * Master capability on non Stingray platform
    1374                 :            :          */
    1375   [ #  #  #  # ]:          0 :         if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
    1376                 :          0 :                 flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
    1377                 :            : 
    1378   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
    1379                 :          0 :         req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
    1380                 :            :                         HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
    1381                 :          0 :         req.ver_maj_8b = RTE_VER_YEAR;
    1382                 :          0 :         req.ver_min_8b = RTE_VER_MONTH;
    1383                 :          0 :         req.ver_upd_8b = RTE_VER_MINOR;
    1384                 :            : 
    1385         [ #  # ]:          0 :         if (BNXT_PF(bp)) {
    1386                 :          0 :                 req.enables |= rte_cpu_to_le_32(
    1387                 :            :                         HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
    1388                 :          0 :                 memcpy(req.vf_req_fwd, bp->pf->vf_req_fwd,
    1389                 :            :                        RTE_MIN(sizeof(req.vf_req_fwd),
    1390                 :            :                                sizeof(bp->pf->vf_req_fwd)));
    1391                 :            :         }
    1392                 :            : 
    1393                 :          0 :         req.flags = rte_cpu_to_le_32(flags);
    1394                 :            : 
    1395                 :          0 :         req.async_event_fwd[0] |=
    1396                 :            :                 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
    1397                 :            :                                  ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
    1398                 :            :                                  ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
    1399                 :            :                                  ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
    1400                 :            :                                  ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
    1401         [ #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
    1402                 :          0 :                 req.async_event_fwd[0] |=
    1403                 :            :                         rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
    1404                 :          0 :         req.async_event_fwd[1] |=
    1405                 :            :                 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
    1406                 :            :                                  ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
    1407         [ #  # ]:          0 :         if (BNXT_PF(bp))
    1408                 :          0 :                 req.async_event_fwd[1] |=
    1409                 :            :                         rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DBG_NOTIFICATION);
    1410                 :            : 
    1411         [ #  # ]:          0 :         if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
    1412                 :          0 :                 req.async_event_fwd[1] |=
    1413                 :            :                 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DEFAULT_VNIC_CHANGE |
    1414                 :            :                                  ASYNC_CMPL_EVENT_ID_VF_FLR);
    1415                 :            :         }
    1416                 :            : 
    1417                 :          0 :         req.async_event_fwd[2] |=
    1418                 :            :                 rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ECHO_REQUEST |
    1419                 :            :                                  ASYNC_CMPL_EVENT_ID_ERROR_REPORT);
    1420                 :            : 
    1421                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1422                 :            : 
    1423   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1424                 :            : 
    1425                 :          0 :         flags = rte_le_to_cpu_32(resp->flags);
    1426         [ #  # ]:          0 :         if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
    1427                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
    1428                 :            : 
    1429                 :            :         HWRM_UNLOCK();
    1430                 :            : 
    1431                 :          0 :         bp->flags |= BNXT_FLAG_REGISTERED;
    1432                 :            : 
    1433                 :          0 :         return rc;
    1434                 :            : }
    1435                 :            : 
    1436                 :          0 : int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
    1437                 :            : {
    1438         [ #  # ]:          0 :         if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
    1439                 :            :                 return 0;
    1440                 :            : 
    1441                 :          0 :         return bnxt_hwrm_func_reserve_vf_resc(bp, true);
    1442                 :            : }
    1443                 :            : 
    1444                 :          0 : int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
    1445                 :            : {
    1446                 :            :         int rc;
    1447                 :            :         uint32_t flags = 0;
    1448                 :            :         uint32_t enables;
    1449                 :          0 :         struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    1450                 :          0 :         struct hwrm_func_vf_cfg_input req = {0};
    1451                 :            : 
    1452   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
    1453                 :            : 
    1454                 :            :         enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS  |
    1455                 :            :                   HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS   |
    1456                 :            :                   HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS  |
    1457                 :            :                   HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
    1458                 :            :                   HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
    1459                 :            : 
    1460         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
    1461                 :            :                 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
    1462                 :          0 :                 req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
    1463                 :            :         }
    1464                 :            : 
    1465                 :          0 :         req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings);
    1466                 :          0 :         req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
    1467                 :            :                                             AGG_RING_MULTIPLIER);
    1468                 :          0 :         req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings + bp->tx_nr_rings);
    1469                 :          0 :         req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
    1470                 :            :                                               bp->tx_nr_rings +
    1471                 :            :                                               BNXT_NUM_ASYNC_CPR(bp));
    1472         [ #  # ]:          0 :         if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
    1473                 :          0 :                 req.num_vnics = rte_cpu_to_le_16(RTE_MIN(BNXT_VNIC_MAX_SUPPORTED_ID,
    1474                 :            :                                                          bp->max_vnics));
    1475                 :          0 :                 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
    1476                 :          0 :                 req.num_rsscos_ctxs = rte_cpu_to_le_16(RTE_MIN(BNXT_VNIC_MAX_SUPPORTED_ID,
    1477                 :            :                                                                bp->max_rsscos_ctx));
    1478                 :            :         } else {
    1479                 :          0 :                 req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
    1480                 :            :         }
    1481                 :            : 
    1482         [ #  # ]:          0 :         if (bp->vf_resv_strategy ==
    1483                 :            :             HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
    1484                 :          0 :                 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
    1485                 :            :                            HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
    1486                 :            :                            HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
    1487                 :          0 :                 req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
    1488                 :          0 :                 req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
    1489                 :          0 :                 req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
    1490         [ #  # ]:          0 :         } else if (bp->vf_resv_strategy ==
    1491                 :            :                    HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MAXIMAL) {
    1492                 :          0 :                 enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
    1493                 :          0 :                 req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
    1494                 :            :         }
    1495                 :            : 
    1496         [ #  # ]:          0 :         if (test)
    1497                 :            :                 flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
    1498                 :            :                         HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
    1499                 :            :                         HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
    1500                 :            :                         HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
    1501                 :            :                         HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
    1502                 :            :                         HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
    1503                 :            : 
    1504   [ #  #  #  # ]:          0 :         if (test && BNXT_HAS_RING_GRPS(bp))
    1505                 :          0 :                 flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
    1506                 :            : 
    1507                 :          0 :         req.flags = rte_cpu_to_le_32(flags);
    1508                 :          0 :         req.enables |= rte_cpu_to_le_32(enables);
    1509                 :            : 
    1510                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1511                 :            : 
    1512         [ #  # ]:          0 :         if (test)
    1513   [ #  #  #  # ]:          0 :                 HWRM_CHECK_RESULT_SILENT();
    1514                 :            :         else
    1515   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1516                 :            : 
    1517                 :            :         HWRM_UNLOCK();
    1518                 :          0 :         return rc;
    1519                 :            : }
    1520                 :            : 
    1521                 :          0 : int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
    1522                 :            : {
    1523                 :            :         int rc;
    1524                 :          0 :         struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    1525                 :          0 :         struct hwrm_func_resource_qcaps_input req = {0};
    1526                 :            : 
    1527         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
    1528                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    1529                 :            : 
    1530                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1531                 :            : 
    1532   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    1533                 :            : 
    1534                 :          0 :         bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
    1535                 :          0 :         bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
    1536                 :          0 :         bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
    1537                 :          0 :         bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
    1538                 :          0 :         bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
    1539                 :            :         /* func_resource_qcaps does not return max_rx_em_flows.
    1540                 :            :          * So use the value provided by func_qcaps.
    1541                 :            :          */
    1542                 :          0 :         bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
    1543   [ #  #  #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp) && !bp->pdev->max_vfs)
    1544                 :          0 :                 bp->max_l2_ctx += bp->max_rx_em_flows;
    1545         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
    1546                 :          0 :                 bp->max_vnics = rte_le_to_cpu_16(BNXT_MAX_VNICS_COS_CLASSIFY);
    1547                 :            :         else
    1548                 :          0 :                 bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
    1549                 :          0 :         bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
    1550         [ #  # ]:          0 :         if (BNXT_CHIP_P7(bp))
    1551                 :          0 :                 bp->max_nq_rings = BNXT_P7_MAX_NQ_RING_CNT;
    1552                 :            :         else
    1553                 :          0 :                 bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
    1554                 :          0 :         bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
    1555         [ #  # ]:          0 :         if (bp->vf_resv_strategy >
    1556                 :            :             HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
    1557                 :          0 :                 bp->vf_resv_strategy =
    1558                 :            :                 HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
    1559                 :            : 
    1560                 :            :         HWRM_UNLOCK();
    1561                 :          0 :         return rc;
    1562                 :            : }
    1563                 :            : 
    1564                 :          0 : int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
    1565                 :            : {
    1566                 :            :         int rc = 0;
    1567                 :          0 :         struct hwrm_ver_get_input req = {.req_type = 0 };
    1568                 :          0 :         struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
    1569                 :            :         uint32_t fw_version;
    1570                 :            :         uint16_t max_resp_len;
    1571                 :            :         char type[RTE_MEMZONE_NAMESIZE];
    1572                 :            :         uint32_t dev_caps_cfg;
    1573                 :            : 
    1574                 :          0 :         bp->max_req_len = HWRM_MAX_REQ_LEN;
    1575                 :          0 :         bp->hwrm_cmd_timeout = timeout;
    1576         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
    1577                 :            : 
    1578                 :          0 :         req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
    1579                 :          0 :         req.hwrm_intf_min = HWRM_VERSION_MINOR;
    1580                 :          0 :         req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
    1581                 :            : 
    1582                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1583                 :            : 
    1584         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_FW_RESET)
    1585   [ #  #  #  # ]:          0 :                 HWRM_CHECK_RESULT_SILENT();
    1586                 :            :         else
    1587   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1588                 :            : 
    1589                 :          0 :         PMD_DRV_LOG(INFO, "%d.%d.%d:%d.%d.%d.%d\n",
    1590                 :            :                 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
    1591                 :            :                 resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
    1592                 :            :                 resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
    1593                 :            :                 resp->hwrm_fw_rsvd_8b);
    1594                 :          0 :         bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
    1595                 :          0 :                      ((uint32_t)resp->hwrm_fw_min_8b << 16) |
    1596                 :          0 :                      ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
    1597                 :          0 :                      resp->hwrm_fw_rsvd_8b;
    1598                 :          0 :         PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
    1599                 :            :                 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
    1600                 :            : 
    1601                 :          0 :         fw_version = resp->hwrm_intf_maj_8b << 16;
    1602                 :          0 :         fw_version |= resp->hwrm_intf_min_8b << 8;
    1603                 :          0 :         fw_version |= resp->hwrm_intf_upd_8b;
    1604                 :          0 :         bp->hwrm_spec_code = fw_version;
    1605                 :            : 
    1606                 :            :         /* def_req_timeout value is in milliseconds */
    1607                 :          0 :         bp->hwrm_cmd_timeout = rte_le_to_cpu_16(resp->def_req_timeout);
    1608                 :            :         /* convert timeout to usec */
    1609                 :          0 :         bp->hwrm_cmd_timeout *= 1000;
    1610         [ #  # ]:          0 :         if (!bp->hwrm_cmd_timeout)
    1611                 :          0 :                 bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
    1612                 :            : 
    1613         [ #  # ]:          0 :         if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
    1614                 :          0 :                 PMD_DRV_LOG(ERR, "Unsupported firmware API version\n");
    1615                 :            :                 rc = -EINVAL;
    1616                 :          0 :                 goto error;
    1617                 :            :         }
    1618                 :            : 
    1619         [ #  # ]:          0 :         if (bp->max_req_len > resp->max_req_win_len) {
    1620                 :          0 :                 PMD_DRV_LOG(ERR, "Unsupported request length\n");
    1621                 :            :                 rc = -EINVAL;
    1622                 :          0 :                 goto error;
    1623                 :            :         }
    1624                 :            : 
    1625                 :          0 :         bp->chip_num = rte_le_to_cpu_16(resp->chip_num);
    1626                 :            : 
    1627                 :          0 :         bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
    1628                 :          0 :         bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
    1629         [ #  # ]:          0 :         if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
    1630                 :          0 :                 bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
    1631                 :            : 
    1632                 :          0 :         max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
    1633                 :          0 :         dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
    1634                 :            : 
    1635         [ #  # ]:          0 :         RTE_VERIFY(max_resp_len <= bp->max_resp_len);
    1636                 :          0 :         bp->max_resp_len = max_resp_len;
    1637                 :            : 
    1638                 :          0 :         if ((dev_caps_cfg &
    1639         [ #  # ]:          0 :                 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
    1640                 :            :             (dev_caps_cfg &
    1641                 :            :              HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
    1642                 :          0 :                 PMD_DRV_LOG(DEBUG, "Short command supported\n");
    1643                 :          0 :                 bp->flags |= BNXT_FLAG_SHORT_CMD;
    1644                 :            :         }
    1645                 :            : 
    1646         [ #  # ]:          0 :         if (((dev_caps_cfg &
    1647                 :            :               HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
    1648                 :            :              (dev_caps_cfg &
    1649                 :          0 :               HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
    1650         [ #  # ]:          0 :             bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
    1651                 :          0 :                 sprintf(type, "bnxt_hwrm_short_" PCI_PRI_FMT,
    1652                 :          0 :                         bp->pdev->addr.domain, bp->pdev->addr.bus,
    1653                 :          0 :                         bp->pdev->addr.devid, bp->pdev->addr.function);
    1654                 :            : 
    1655                 :          0 :                 rte_free(bp->hwrm_short_cmd_req_addr);
    1656                 :            : 
    1657                 :          0 :                 bp->hwrm_short_cmd_req_addr =
    1658                 :          0 :                                 rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
    1659         [ #  # ]:          0 :                 if (bp->hwrm_short_cmd_req_addr == NULL) {
    1660                 :            :                         rc = -ENOMEM;
    1661                 :          0 :                         goto error;
    1662                 :            :                 }
    1663                 :          0 :                 bp->hwrm_short_cmd_req_dma_addr =
    1664                 :          0 :                         rte_malloc_virt2iova(bp->hwrm_short_cmd_req_addr);
    1665         [ #  # ]:          0 :                 if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
    1666                 :          0 :                         rte_free(bp->hwrm_short_cmd_req_addr);
    1667                 :          0 :                         PMD_DRV_LOG(ERR,
    1668                 :            :                                 "Unable to map buffer to physical memory.\n");
    1669                 :            :                         rc = -ENOMEM;
    1670                 :          0 :                         goto error;
    1671                 :            :                 }
    1672                 :            :         }
    1673         [ #  # ]:          0 :         if (dev_caps_cfg &
    1674                 :            :             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
    1675                 :          0 :                 bp->flags |= BNXT_FLAG_KONG_MB_EN;
    1676                 :          0 :                 PMD_DRV_LOG(DEBUG, "Kong mailbox channel enabled\n");
    1677                 :            :         }
    1678         [ #  # ]:          0 :         if (dev_caps_cfg &
    1679                 :            :             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
    1680                 :          0 :                 PMD_DRV_LOG(DEBUG, "FW supports Trusted VFs\n");
    1681         [ #  # ]:          0 :         if (dev_caps_cfg &
    1682                 :            :             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED) {
    1683                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_MGMT;
    1684                 :          0 :                 PMD_DRV_LOG(DEBUG, "FW supports advanced flow management\n");
    1685                 :            :         }
    1686                 :            : 
    1687         [ #  # ]:          0 :         if (dev_caps_cfg &
    1688                 :            :             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_ADV_FLOW_COUNTERS_SUPPORTED) {
    1689                 :          0 :                 PMD_DRV_LOG(DEBUG, "FW supports advanced flow counters\n");
    1690                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_COUNTERS;
    1691                 :            :         }
    1692                 :            : 
    1693         [ #  # ]:          0 :         if (dev_caps_cfg &
    1694                 :            :             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_TRUFLOW_SUPPORTED) {
    1695                 :          0 :                 PMD_DRV_LOG(DEBUG, "Host-based truflow feature enabled.\n");
    1696                 :          0 :                 bp->fw_cap |= BNXT_FW_CAP_TRUFLOW_EN;
    1697                 :            :         }
    1698                 :            : 
    1699                 :          0 : error:
    1700                 :            :         HWRM_UNLOCK();
    1701                 :          0 :         return rc;
    1702                 :            : }
    1703                 :            : 
    1704                 :          0 : int bnxt_hwrm_func_driver_unregister(struct bnxt *bp)
    1705                 :            : {
    1706                 :            :         int rc;
    1707                 :          0 :         struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
    1708                 :          0 :         struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
    1709                 :            : 
    1710         [ #  # ]:          0 :         if (!(bp->flags & BNXT_FLAG_REGISTERED))
    1711                 :            :                 return 0;
    1712                 :            : 
    1713         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
    1714                 :            : 
    1715                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1716                 :            : 
    1717   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1718                 :            :         HWRM_UNLOCK();
    1719                 :            : 
    1720                 :          0 :         PMD_DRV_LOG(DEBUG, "Port %u: Unregistered with fw\n",
    1721                 :            :                     bp->eth_dev->data->port_id);
    1722                 :            : 
    1723                 :          0 :         return rc;
    1724                 :            : }
    1725                 :            : 
    1726                 :          0 : static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
    1727                 :            : {
    1728                 :            :         int rc = 0;
    1729                 :          0 :         struct hwrm_port_phy_cfg_input req = {0};
    1730                 :          0 :         struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    1731                 :            :         uint32_t enables = 0;
    1732                 :            : 
    1733   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
    1734                 :            : 
    1735         [ #  # ]:          0 :         if (conf->link_up) {
    1736                 :            :                 /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
    1737   [ #  #  #  # ]:          0 :                 if (bp->link_info->auto_mode && conf->link_speed) {
    1738                 :          0 :                         req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
    1739                 :          0 :                         PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
    1740                 :            :                 }
    1741                 :            : 
    1742                 :          0 :                 req.flags = rte_cpu_to_le_32(conf->phy_flags);
    1743                 :            :                 /*
    1744                 :            :                  * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
    1745                 :            :                  * any auto mode, even "none".
    1746                 :            :                  */
    1747         [ #  # ]:          0 :                 if (!conf->link_speed) {
    1748                 :            :                         /* No speeds specified. Enable AutoNeg - all speeds */
    1749                 :            :                         enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
    1750                 :          0 :                         req.auto_mode =
    1751                 :            :                                 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
    1752                 :            :                 } else {
    1753         [ #  # ]:          0 :                         if (bp->link_info->link_signal_mode) {
    1754                 :            :                                 enables |=
    1755                 :            :                                 HWRM_PORT_PHY_CFG_IN_EN_FORCE_PAM4_LINK_SPEED;
    1756                 :          0 :                                 req.force_pam4_link_speed =
    1757                 :            :                                         rte_cpu_to_le_16(conf->link_speed);
    1758                 :            :                         } else {
    1759                 :          0 :                                 req.force_link_speed =
    1760                 :            :                                         rte_cpu_to_le_16(conf->link_speed);
    1761                 :            :                         }
    1762                 :            :                 }
    1763                 :            :                 /* AutoNeg - Advertise speeds specified. */
    1764   [ #  #  #  # ]:          0 :                 if ((conf->auto_link_speed_mask || conf->auto_pam4_link_speed_mask) &&
    1765         [ #  # ]:          0 :                     !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
    1766                 :          0 :                         req.auto_mode =
    1767                 :            :                                 HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
    1768         [ #  # ]:          0 :                         if (conf->auto_pam4_link_speed_mask) {
    1769                 :          0 :                                 enables |=
    1770                 :            :                                 HWRM_PORT_PHY_CFG_IN_EN_AUTO_PAM4_LINK_SPD_MASK;
    1771                 :          0 :                                 req.auto_link_pam4_speed_mask =
    1772                 :            :                                 rte_cpu_to_le_16(conf->auto_pam4_link_speed_mask);
    1773                 :            :                         }
    1774         [ #  # ]:          0 :                         if (conf->auto_link_speed_mask) {
    1775                 :          0 :                                 enables |=
    1776                 :            :                                 HWRM_PORT_PHY_CFG_IN_EN_AUTO_LINK_SPEED_MASK;
    1777                 :          0 :                                 req.auto_link_speed_mask =
    1778                 :            :                                 rte_cpu_to_le_16(conf->auto_link_speed_mask);
    1779                 :            :                         }
    1780                 :            :                 }
    1781         [ #  # ]:          0 :                 if (conf->auto_link_speed &&
    1782         [ #  # ]:          0 :                 !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE))
    1783                 :          0 :                         enables |=
    1784                 :            :                                 HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED;
    1785                 :            : 
    1786                 :          0 :                 req.auto_duplex = conf->duplex;
    1787                 :            :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
    1788                 :          0 :                 req.auto_pause = conf->auto_pause;
    1789                 :          0 :                 req.force_pause = conf->force_pause;
    1790                 :            :                 /* Set force_pause if there is no auto or if there is a force */
    1791   [ #  #  #  # ]:          0 :                 if (req.auto_pause && !req.force_pause)
    1792                 :          0 :                         enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
    1793                 :            :                 else
    1794                 :          0 :                         enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
    1795                 :            : 
    1796                 :          0 :                 req.enables = rte_cpu_to_le_32(enables);
    1797                 :            :         } else {
    1798                 :          0 :                 req.flags =
    1799                 :            :                 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
    1800                 :          0 :                 PMD_DRV_LOG(INFO, "Force Link Down\n");
    1801                 :            :         }
    1802                 :            : 
    1803                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1804                 :            : 
    1805   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1806                 :            :         HWRM_UNLOCK();
    1807                 :            : 
    1808                 :          0 :         return rc;
    1809                 :            : }
    1810                 :            : 
    1811                 :          0 : static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
    1812                 :            :                                    struct bnxt_link_info *link_info)
    1813                 :            : {
    1814                 :            :         int rc = 0;
    1815                 :          0 :         struct hwrm_port_phy_qcfg_input req = {0};
    1816                 :          0 :         struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    1817                 :            : 
    1818         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
    1819                 :            : 
    1820                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1821                 :            : 
    1822   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    1823                 :            : 
    1824                 :          0 :         link_info->phy_link_status = resp->link;
    1825                 :          0 :         link_info->link_up =
    1826                 :            :                 (link_info->phy_link_status ==
    1827                 :          0 :                  HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
    1828                 :          0 :         link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
    1829                 :          0 :         link_info->duplex = resp->duplex_cfg;
    1830                 :          0 :         link_info->pause = resp->pause;
    1831                 :          0 :         link_info->auto_pause = resp->auto_pause;
    1832                 :          0 :         link_info->force_pause = resp->force_pause;
    1833                 :          0 :         link_info->auto_mode = resp->auto_mode;
    1834                 :          0 :         link_info->phy_type = resp->phy_type;
    1835                 :          0 :         link_info->media_type = resp->media_type;
    1836                 :            : 
    1837                 :          0 :         link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
    1838                 :          0 :         link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
    1839                 :          0 :         link_info->auto_link_speed_mask = rte_le_to_cpu_16(resp->auto_link_speed_mask);
    1840                 :          0 :         link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
    1841                 :          0 :         link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
    1842                 :          0 :         link_info->phy_ver[0] = resp->phy_maj;
    1843                 :          0 :         link_info->phy_ver[1] = resp->phy_min;
    1844                 :          0 :         link_info->phy_ver[2] = resp->phy_bld;
    1845                 :          0 :         link_info->link_signal_mode =
    1846                 :          0 :                 resp->active_fec_signal_mode & HWRM_PORT_PHY_QCFG_OUTPUT_SIGNAL_MODE_MASK;
    1847                 :          0 :         link_info->option_flags = resp->option_flags;
    1848                 :          0 :         link_info->force_pam4_link_speed =
    1849                 :          0 :                         rte_le_to_cpu_16(resp->force_pam4_link_speed);
    1850                 :          0 :         link_info->support_pam4_speeds =
    1851                 :          0 :                         rte_le_to_cpu_16(resp->support_pam4_speeds);
    1852                 :          0 :         link_info->auto_pam4_link_speed_mask =
    1853                 :          0 :                         rte_le_to_cpu_16(resp->auto_pam4_link_speed_mask);
    1854                 :            :         /* P7 uses speeds2 fields */
    1855   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp) && BNXT_LINK_SPEEDS_V2_OPTIONS(link_info->option_flags)) {
          #  #  #  #  #  
                      # ]
    1856                 :          0 :                 link_info->support_speeds2 = rte_le_to_cpu_16(resp->support_speeds2);
    1857                 :          0 :                 link_info->force_link_speeds2 = rte_le_to_cpu_16(resp->force_link_speeds2);
    1858                 :          0 :                 link_info->auto_link_speeds2 = rte_le_to_cpu_16(resp->auto_link_speeds2);
    1859                 :          0 :                 link_info->active_lanes = resp->active_lanes;
    1860         [ #  # ]:          0 :                 if (!link_info->auto_mode)
    1861                 :          0 :                         link_info->link_speed = link_info->force_link_speeds2;
    1862                 :            :         }
    1863                 :          0 :         link_info->module_status = resp->module_status;
    1864                 :            :         HWRM_UNLOCK();
    1865                 :            : 
    1866                 :            :         /* Display the captured P7 phy details */
    1867   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp)) {
             #  #  #  # ]
    1868                 :          0 :                 PMD_DRV_LOG(DEBUG, "Phytype:%d, Media_type:%d, Status: %d, Link Signal:%d\n"
    1869                 :            :                             "Active Fec: %d Support_speeds2:%x, Force_link_speedsv2:%x\n"
    1870                 :            :                             "Auto_link_speedsv2:%x, Active_lanes:%d\n",
    1871                 :            :                             link_info->phy_type,
    1872                 :            :                             link_info->media_type,
    1873                 :            :                             link_info->phy_link_status,
    1874                 :            :                             link_info->link_signal_mode,
    1875                 :            :                             (resp->active_fec_signal_mode &
    1876                 :            :                                 HWRM_PORT_PHY_QCFG_OUTPUT_ACTIVE_FEC_MASK) >> 4,
    1877                 :            :                             link_info->support_speeds2, link_info->force_link_speeds2,
    1878                 :            :                             link_info->auto_link_speeds2,
    1879                 :            :                             link_info->active_lanes);
    1880                 :            : 
    1881                 :            :                 const char *desc;
    1882                 :            : 
    1883         [ #  # ]:          0 :                 if (link_info->auto_mode)
    1884                 :          0 :                         desc = ((struct link_speeds_tbl *)
    1885                 :          0 :                                 bnxt_get_hwrm_to_rte_speeds_entry(link_info->link_speed))->desc;
    1886                 :            :                 else
    1887                 :          0 :                         desc = ((struct link_speeds2_tbl *)
    1888                 :          0 :                                 bnxt_get_hwrm_to_rte_speeds2_entry(link_info->link_speed))->desc;
    1889                 :            : 
    1890   [ #  #  #  #  :          0 :                 PMD_DRV_LOG(INFO, "Link Speed: %s %s, Status: %s Signal-mode: %s\n"
          #  #  #  #  #  
                      # ]
    1891                 :            :                             "Media type: %s, Xcvr type: %s, Active FEC: %s Lanes: %d\n",
    1892                 :            :                             desc,
    1893                 :            :                             !(link_info->auto_mode) ? "Forced" : "AutoNegotiated",
    1894                 :            :                             link_status_str[link_info->phy_link_status % MAX_LINK_STR],
    1895                 :            :                             signal_mode[link_info->link_signal_mode % MAX_SIG_MODE],
    1896                 :            :                             media_type[link_info->media_type % MAX_MEDIA_TYPE],
    1897                 :            :                             bnxt_get_xcvr_type(rte_le_to_cpu_32
    1898                 :            :                                                (resp->xcvr_identifier_type_tx_lpi_timer)),
    1899                 :            :                             fec_mode[((resp->active_fec_signal_mode &
    1900                 :            :                                        HWRM_PORT_PHY_QCFG_OUTPUT_ACTIVE_FEC_MASK) >> 4) %
    1901                 :            :                             MAX_FEC_MODE], link_info->active_lanes);
    1902                 :          0 :                 return rc;
    1903                 :            :         }
    1904                 :            : 
    1905                 :          0 :         PMD_DRV_LOG(DEBUG, "Link Speed:%d,Auto:%d:%x:%x,Support:%x,Force:%x\n",
    1906                 :            :                     link_info->link_speed, link_info->auto_mode,
    1907                 :            :                     link_info->auto_link_speed, link_info->auto_link_speed_mask,
    1908                 :            :                     link_info->support_speeds, link_info->force_link_speed);
    1909                 :          0 :         PMD_DRV_LOG(DEBUG, "Link Signal:%d,PAM::Auto:%x,Support:%x,Force:%x\n",
    1910                 :            :                     link_info->link_signal_mode,
    1911                 :            :                     link_info->auto_pam4_link_speed_mask,
    1912                 :            :                     link_info->support_pam4_speeds,
    1913                 :            :                     link_info->force_pam4_link_speed);
    1914                 :          0 :         return rc;
    1915                 :            : }
    1916                 :            : 
    1917                 :          0 : int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp)
    1918                 :            : {
    1919                 :            :         int rc = 0;
    1920                 :          0 :         struct hwrm_port_phy_qcaps_input req = {0};
    1921                 :          0 :         struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    1922                 :          0 :         struct bnxt_link_info *link_info = bp->link_info;
    1923                 :            : 
    1924         [ #  # ]:          0 :         if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
    1925                 :            :                 return 0;
    1926                 :            : 
    1927         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_PHY_QCAPS, BNXT_USE_CHIMP_MB);
    1928                 :            : 
    1929                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    1930                 :            : 
    1931   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    1932                 :            : 
    1933                 :          0 :         bp->port_cnt = resp->port_cnt;
    1934         [ #  # ]:          0 :         if (resp->supported_speeds_auto_mode)
    1935                 :          0 :                 link_info->support_auto_speeds =
    1936                 :            :                         rte_le_to_cpu_16(resp->supported_speeds_auto_mode);
    1937         [ #  # ]:          0 :         if (resp->supported_pam4_speeds_auto_mode)
    1938                 :          0 :                 link_info->support_pam4_auto_speeds =
    1939                 :            :                         rte_le_to_cpu_16(resp->supported_pam4_speeds_auto_mode);
    1940                 :            :         /* P7 chips now report all speeds here */
    1941         [ #  # ]:          0 :         if (resp->flags2 & HWRM_PORT_PHY_QCAPS_OUTPUT_FLAGS2_SPEEDS2_SUPPORTED)
    1942                 :          0 :                 link_info->support_speeds_v2 = true;
    1943         [ #  # ]:          0 :         if (link_info->support_speeds_v2) {
    1944                 :          0 :                 link_info->supported_speeds2_force_mode =
    1945                 :          0 :                         rte_le_to_cpu_16(resp->supported_speeds2_force_mode);
    1946                 :          0 :                 link_info->supported_speeds2_auto_mode =
    1947                 :          0 :                         rte_le_to_cpu_16(resp->supported_speeds2_auto_mode);
    1948                 :            :         }
    1949                 :            : 
    1950                 :            :         HWRM_UNLOCK();
    1951                 :            : 
    1952                 :            :         /* Older firmware does not have supported_auto_speeds, so assume
    1953                 :            :          * that all supported speeds can be autonegotiated.
    1954                 :            :          */
    1955   [ #  #  #  # ]:          0 :         if (link_info->auto_link_speed_mask && !link_info->support_auto_speeds)
    1956                 :          0 :                 link_info->support_auto_speeds = link_info->support_speeds;
    1957                 :            : 
    1958                 :            :         return 0;
    1959                 :            : }
    1960                 :            : 
    1961                 :            : static bool _bnxt_find_lossy_profile(struct bnxt *bp)
    1962                 :            : {
    1963                 :            :         int i = 0;
    1964                 :            : 
    1965         [ #  # ]:          0 :         for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
    1966         [ #  # ]:          0 :                 if (bp->tx_cos_queue[i].profile ==
    1967                 :            :                     HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
    1968                 :          0 :                         bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
    1969                 :          0 :                         return true;
    1970                 :            :                 }
    1971                 :            :         }
    1972                 :            :         return false;
    1973                 :            : }
    1974                 :            : 
    1975                 :          0 : static bool _bnxt_find_lossy_nic_profile(struct bnxt *bp)
    1976                 :            : {
    1977                 :            :         int i = 0, j = 0;
    1978                 :            : 
    1979         [ #  # ]:          0 :         for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
    1980         [ #  # ]:          0 :                 for (j = 0; j < BNXT_COS_QUEUE_COUNT; j++) {
    1981         [ #  # ]:          0 :                         if (bp->tx_cos_queue[i].profile ==
    1982                 :          0 :                             HWRM_QUEUE_SERVICE_PROFILE_LOSSY &&
    1983         [ #  # ]:          0 :                             bp->tx_cos_queue[j].profile_type ==
    1984                 :            :                             HWRM_QUEUE_SERVICE_PROFILE_TYPE_NIC) {
    1985                 :          0 :                                 bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
    1986                 :          0 :                                 return true;
    1987                 :            :                         }
    1988                 :            :                 }
    1989                 :            :         }
    1990                 :            :         return false;
    1991                 :            : }
    1992                 :            : 
    1993                 :          0 : static bool bnxt_find_lossy_profile(struct bnxt *bp, bool use_prof_type)
    1994                 :            : {
    1995                 :            :         int i;
    1996                 :            : 
    1997         [ #  # ]:          0 :         for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
    1998                 :          0 :                 PMD_DRV_LOG(DEBUG, "profile %d, profile_id %d, type %d\n",
    1999                 :            :                             bp->tx_cos_queue[i].profile,
    2000                 :            :                             bp->tx_cos_queue[i].id,
    2001                 :            :                             bp->tx_cos_queue[i].profile_type);
    2002                 :            :         }
    2003                 :            : 
    2004         [ #  # ]:          0 :         if (use_prof_type)
    2005                 :          0 :                 return _bnxt_find_lossy_nic_profile(bp);
    2006                 :            :         else
    2007                 :          0 :                 return _bnxt_find_lossy_profile(bp);
    2008                 :            : }
    2009                 :            : 
    2010                 :            : static void bnxt_find_first_valid_profile(struct bnxt *bp)
    2011                 :            : {
    2012                 :            :         int i = 0;
    2013                 :            : 
    2014         [ #  # ]:          0 :         for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
    2015         [ #  # ]:          0 :                 if (bp->tx_cos_queue[i].profile !=
    2016                 :          0 :                     HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN &&
    2017         [ #  # ]:          0 :                     bp->tx_cos_queue[i].id !=
    2018                 :            :                     HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN) {
    2019                 :          0 :                         bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
    2020                 :          0 :                         break;
    2021                 :            :                 }
    2022                 :            :         }
    2023                 :            : }
    2024                 :            : 
    2025                 :          0 : int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
    2026                 :            : {
    2027                 :            :         int rc = 0;
    2028                 :          0 :         struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
    2029                 :          0 :         struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
    2030                 :            :         uint32_t dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
    2031                 :            :         bool use_prof_type = false;
    2032                 :            :         int i;
    2033                 :            : 
    2034                 :          0 : get_rx_info:
    2035   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
    2036                 :            : 
    2037                 :          0 :         req.flags = rte_cpu_to_le_32(dir);
    2038                 :            :         /* HWRM Version >= 1.9.1 only if COS Classification is not required. */
    2039         [ #  # ]:          0 :         if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1 &&
    2040         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
    2041                 :          0 :                 req.drv_qmap_cap =
    2042                 :            :                         HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
    2043                 :            : 
    2044                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2045                 :            : 
    2046   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2047                 :            : 
    2048         [ #  # ]:          0 :         if (resp->queue_cfg_info &
    2049                 :            :             HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_CFG_INFO_USE_PROFILE_TYPE)
    2050                 :            :                 use_prof_type = true;
    2051                 :            : 
    2052         [ #  # ]:          0 :         if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
    2053                 :          0 :                 GET_TX_QUEUE_INFO(0);
    2054                 :          0 :                 GET_TX_QUEUE_INFO(1);
    2055                 :          0 :                 GET_TX_QUEUE_INFO(2);
    2056                 :          0 :                 GET_TX_QUEUE_INFO(3);
    2057                 :          0 :                 GET_TX_QUEUE_INFO(4);
    2058                 :          0 :                 GET_TX_QUEUE_INFO(5);
    2059                 :          0 :                 GET_TX_QUEUE_INFO(6);
    2060                 :          0 :                 GET_TX_QUEUE_INFO(7);
    2061         [ #  # ]:          0 :                 if (use_prof_type) {
    2062                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(0);
    2063                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(1);
    2064                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(2);
    2065                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(3);
    2066                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(4);
    2067                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(5);
    2068                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(6);
    2069                 :          0 :                         GET_TX_QUEUE_TYPE_INFO(7);
    2070                 :            :                 }
    2071                 :            :         } else  {
    2072                 :          0 :                 GET_RX_QUEUE_INFO(0);
    2073                 :          0 :                 GET_RX_QUEUE_INFO(1);
    2074                 :          0 :                 GET_RX_QUEUE_INFO(2);
    2075                 :          0 :                 GET_RX_QUEUE_INFO(3);
    2076                 :          0 :                 GET_RX_QUEUE_INFO(4);
    2077                 :          0 :                 GET_RX_QUEUE_INFO(5);
    2078                 :          0 :                 GET_RX_QUEUE_INFO(6);
    2079                 :          0 :                 GET_RX_QUEUE_INFO(7);
    2080                 :            :         }
    2081                 :            : 
    2082                 :            :         HWRM_UNLOCK();
    2083                 :            : 
    2084         [ #  # ]:          0 :         if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX)
    2085                 :          0 :                 goto done;
    2086                 :            : 
    2087         [ #  # ]:          0 :         if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
    2088                 :          0 :                 bp->tx_cosq_id[0] = bp->tx_cos_queue[0].id;
    2089                 :            :         } else {
    2090                 :            :                 int j;
    2091                 :            : 
    2092                 :            :                 /* iterate and find the COSq profile to use for Tx */
    2093         [ #  # ]:          0 :                 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
    2094         [ #  # ]:          0 :                         for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
    2095         [ #  # ]:          0 :                                 if (bp->tx_cos_queue[i].id != 0xff)
    2096                 :          0 :                                         bp->tx_cosq_id[j++] =
    2097                 :            :                                                 bp->tx_cos_queue[i].id;
    2098                 :            :                         }
    2099                 :            :                 } else {
    2100                 :            :                         /* When CoS classification is disabled, for normal NIC
    2101                 :            :                          * operations, ideally we should look to use LOSSY.
    2102                 :            :                          * If not found, fallback to the first valid profile
    2103                 :            :                          */
    2104         [ #  # ]:          0 :                         if (!bnxt_find_lossy_profile(bp, use_prof_type))
    2105                 :            :                                 bnxt_find_first_valid_profile(bp);
    2106                 :            : 
    2107                 :            :                 }
    2108                 :            :         }
    2109                 :          0 :         PMD_DRV_LOG(DEBUG, "Tx COS Queue ID %d\n", bp->tx_cosq_id[0]);
    2110                 :            : 
    2111                 :          0 :         bp->max_tc = resp->max_configurable_queues;
    2112                 :          0 :         bp->max_lltc = resp->max_configurable_lossless_queues;
    2113         [ #  # ]:          0 :         if (bp->max_tc > BNXT_MAX_QUEUE)
    2114                 :          0 :                 bp->max_tc = BNXT_MAX_QUEUE;
    2115                 :          0 :         bp->max_q = bp->max_tc;
    2116                 :            : 
    2117                 :            :         if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
    2118                 :            :                 dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX;
    2119                 :          0 :                 goto get_rx_info;
    2120                 :            :         }
    2121                 :            : 
    2122                 :            : done:
    2123                 :          0 :         return rc;
    2124                 :            : }
    2125                 :            : 
    2126                 :          0 : int bnxt_hwrm_ring_alloc(struct bnxt *bp,
    2127                 :            :                          struct bnxt_ring *ring,
    2128                 :            :                          uint32_t ring_type, uint32_t map_index,
    2129                 :            :                          uint32_t stats_ctx_id, uint32_t cmpl_ring_id,
    2130                 :            :                          uint16_t tx_cosq_id)
    2131                 :            : {
    2132                 :            :         int rc = 0;
    2133                 :            :         uint32_t enables = 0;
    2134                 :          0 :         struct hwrm_ring_alloc_input req = {.req_type = 0 };
    2135                 :          0 :         struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    2136                 :            :         struct rte_mempool *mb_pool;
    2137                 :            :         uint16_t rx_buf_size;
    2138                 :            : 
    2139   [ #  #  #  #  :          0 :         HWRM_PREP(&req, HWRM_RING_ALLOC, BNXT_USE_CHIMP_MB);
             #  #  #  # ]
    2140                 :            : 
    2141                 :          0 :         req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
    2142                 :          0 :         req.fbo = rte_cpu_to_le_32(0);
    2143                 :            :         /* Association of ring index with doorbell index */
    2144                 :          0 :         req.logical_id = rte_cpu_to_le_16(map_index);
    2145                 :          0 :         req.length = rte_cpu_to_le_32(ring->ring_size);
    2146                 :            : 
    2147   [ #  #  #  #  :          0 :         switch (ring_type) {
                   #  # ]
    2148                 :          0 :         case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
    2149                 :          0 :                 req.ring_type = ring_type;
    2150                 :          0 :                 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
    2151                 :          0 :                 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
    2152                 :          0 :                 req.queue_id = rte_cpu_to_le_16(tx_cosq_id);
    2153         [ #  # ]:          0 :                 if (stats_ctx_id != INVALID_STATS_CTX_ID)
    2154                 :            :                         enables |=
    2155                 :            :                         HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
    2156                 :            :                 break;
    2157                 :          0 :         case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
    2158                 :          0 :                 req.ring_type = ring_type;
    2159                 :          0 :                 req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
    2160                 :          0 :                 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
    2161         [ #  # ]:          0 :                 if (BNXT_CHIP_P5_P7(bp)) {
    2162         [ #  # ]:          0 :                         mb_pool = bp->rx_queues[0]->mb_pool;
    2163                 :          0 :                         rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
    2164                 :            :                                       RTE_PKTMBUF_HEADROOM;
    2165                 :          0 :                         rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
    2166                 :          0 :                         req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
    2167                 :            :                         enables |=
    2168                 :            :                                 HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
    2169                 :            :                 }
    2170         [ #  # ]:          0 :                 if (stats_ctx_id != INVALID_STATS_CTX_ID)
    2171                 :          0 :                         enables |=
    2172                 :            :                                 HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
    2173                 :            :                 break;
    2174                 :          0 :         case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
    2175                 :          0 :                 req.ring_type = ring_type;
    2176         [ #  # ]:          0 :                 if (BNXT_HAS_NQ(bp)) {
    2177                 :            :                         /* Association of cp ring with nq */
    2178                 :          0 :                         req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
    2179                 :            :                         enables |=
    2180                 :            :                                 HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
    2181                 :            :                 }
    2182                 :          0 :                 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
    2183                 :          0 :                 break;
    2184                 :          0 :         case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
    2185                 :          0 :                 req.ring_type = ring_type;
    2186                 :          0 :                 req.page_size = BNXT_PAGE_SHFT;
    2187                 :          0 :                 req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
    2188                 :          0 :                 break;
    2189                 :          0 :         case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
    2190                 :          0 :                 req.ring_type = ring_type;
    2191                 :          0 :                 req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
    2192                 :            : 
    2193         [ #  # ]:          0 :                 mb_pool = bp->rx_queues[0]->mb_pool;
    2194                 :          0 :                 rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
    2195                 :            :                               RTE_PKTMBUF_HEADROOM;
    2196                 :          0 :                 rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
    2197                 :          0 :                 req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
    2198                 :            : 
    2199                 :          0 :                 req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
    2200                 :            :                 enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
    2201                 :            :                            HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
    2202                 :            :                            HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
    2203                 :          0 :                 break;
    2204                 :          0 :         default:
    2205                 :          0 :                 PMD_DRV_LOG(ERR, "hwrm alloc invalid ring type %d\n",
    2206                 :            :                         ring_type);
    2207                 :            :                 HWRM_UNLOCK();
    2208                 :          0 :                 return -EINVAL;
    2209                 :            :         }
    2210                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    2211                 :            : 
    2212                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2213                 :            : 
    2214   [ #  #  #  # ]:          0 :         if (rc || resp->error_code) {
    2215   [ #  #  #  # ]:          0 :                 if (rc == 0 && resp->error_code)
    2216                 :          0 :                         rc = rte_le_to_cpu_16(resp->error_code);
    2217   [ #  #  #  #  :          0 :                 switch (ring_type) {
                   #  # ]
    2218                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
    2219                 :          0 :                         PMD_DRV_LOG(ERR,
    2220                 :            :                                 "hwrm_ring_alloc cp failed. rc:%d\n", rc);
    2221                 :            :                         HWRM_UNLOCK();
    2222                 :          0 :                         return rc;
    2223                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
    2224                 :          0 :                         PMD_DRV_LOG(ERR,
    2225                 :            :                                     "hwrm_ring_alloc rx failed. rc:%d\n", rc);
    2226                 :            :                         HWRM_UNLOCK();
    2227                 :          0 :                         return rc;
    2228                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
    2229                 :          0 :                         PMD_DRV_LOG(ERR,
    2230                 :            :                                     "hwrm_ring_alloc rx agg failed. rc:%d\n",
    2231                 :            :                                     rc);
    2232                 :            :                         HWRM_UNLOCK();
    2233                 :          0 :                         return rc;
    2234                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
    2235                 :          0 :                         PMD_DRV_LOG(ERR,
    2236                 :            :                                     "hwrm_ring_alloc tx failed. rc:%d\n", rc);
    2237                 :            :                         HWRM_UNLOCK();
    2238                 :          0 :                         return rc;
    2239                 :          0 :                 case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
    2240                 :          0 :                         PMD_DRV_LOG(ERR,
    2241                 :            :                                     "hwrm_ring_alloc nq failed. rc:%d\n", rc);
    2242                 :            :                         HWRM_UNLOCK();
    2243                 :          0 :                         return rc;
    2244                 :          0 :                 default:
    2245                 :          0 :                         PMD_DRV_LOG(ERR, "Invalid ring. rc:%d\n", rc);
    2246                 :            :                         HWRM_UNLOCK();
    2247                 :          0 :                         return rc;
    2248                 :            :                 }
    2249                 :            :         }
    2250                 :            : 
    2251                 :          0 :         ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
    2252                 :            :         HWRM_UNLOCK();
    2253                 :          0 :         return rc;
    2254                 :            : }
    2255                 :            : 
    2256                 :          0 : int bnxt_hwrm_ring_free(struct bnxt *bp,
    2257                 :            :                         struct bnxt_ring *ring, uint32_t ring_type,
    2258                 :            :                         uint16_t cp_ring_id)
    2259                 :            : {
    2260                 :            :         int rc;
    2261                 :          0 :         struct hwrm_ring_free_input req = {.req_type = 0 };
    2262                 :          0 :         struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
    2263                 :            : 
    2264         [ #  # ]:          0 :         if (ring->fw_ring_id == INVALID_HW_RING_ID)
    2265                 :            :                 return -EINVAL;
    2266                 :            : 
    2267         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB);
    2268                 :            : 
    2269                 :          0 :         req.ring_type = ring_type;
    2270                 :          0 :         req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
    2271                 :          0 :         req.cmpl_ring = rte_cpu_to_le_16(cp_ring_id);
    2272                 :            : 
    2273                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2274                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
    2275                 :            : 
    2276   [ #  #  #  # ]:          0 :         if (rc || resp->error_code) {
    2277   [ #  #  #  # ]:          0 :                 if (rc == 0 && resp->error_code)
    2278                 :          0 :                         rc = rte_le_to_cpu_16(resp->error_code);
    2279                 :            :                 HWRM_UNLOCK();
    2280                 :            : 
    2281   [ #  #  #  #  :          0 :                 switch (ring_type) {
                   #  # ]
    2282                 :          0 :                 case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
    2283                 :          0 :                         PMD_DRV_LOG(ERR, "hwrm_ring_free cp failed. rc:%d\n",
    2284                 :            :                                 rc);
    2285                 :          0 :                         return rc;
    2286                 :          0 :                 case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
    2287                 :          0 :                         PMD_DRV_LOG(ERR, "hwrm_ring_free rx failed. rc:%d\n",
    2288                 :            :                                 rc);
    2289                 :          0 :                         return rc;
    2290                 :          0 :                 case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
    2291                 :          0 :                         PMD_DRV_LOG(ERR, "hwrm_ring_free tx failed. rc:%d\n",
    2292                 :            :                                 rc);
    2293                 :          0 :                         return rc;
    2294                 :          0 :                 case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
    2295                 :          0 :                         PMD_DRV_LOG(ERR,
    2296                 :            :                                     "hwrm_ring_free nq failed. rc:%d\n", rc);
    2297                 :          0 :                         return rc;
    2298                 :          0 :                 case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
    2299                 :          0 :                         PMD_DRV_LOG(ERR,
    2300                 :            :                                     "hwrm_ring_free agg failed. rc:%d\n", rc);
    2301                 :          0 :                         return rc;
    2302                 :          0 :                 default:
    2303                 :          0 :                         PMD_DRV_LOG(ERR, "Invalid ring, rc:%d\n", rc);
    2304                 :          0 :                         return rc;
    2305                 :            :                 }
    2306                 :            :         }
    2307                 :            :         HWRM_UNLOCK();
    2308                 :          0 :         return 0;
    2309                 :            : }
    2310                 :            : 
    2311                 :          0 : int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
    2312                 :            : {
    2313                 :            :         int rc = 0;
    2314                 :          0 :         struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
    2315                 :          0 :         struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    2316                 :            : 
    2317                 :            :         /* Don't attempt to re-create the ring group if it is already created */
    2318         [ #  # ]:          0 :         if (bp->grp_info[idx].fw_grp_id != INVALID_HW_RING_ID)
    2319                 :            :                 return 0;
    2320                 :            : 
    2321         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
    2322                 :            : 
    2323                 :          0 :         req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
    2324                 :          0 :         req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
    2325                 :          0 :         req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
    2326                 :          0 :         req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
    2327                 :            : 
    2328                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2329                 :            : 
    2330   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2331                 :            : 
    2332                 :          0 :         bp->grp_info[idx].fw_grp_id = rte_le_to_cpu_16(resp->ring_group_id);
    2333                 :            : 
    2334                 :            :         HWRM_UNLOCK();
    2335                 :            : 
    2336                 :          0 :         return rc;
    2337                 :            : }
    2338                 :            : 
    2339                 :          0 : int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
    2340                 :            : {
    2341                 :            :         int rc;
    2342                 :          0 :         struct hwrm_ring_grp_free_input req = {.req_type = 0 };
    2343                 :          0 :         struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
    2344                 :            : 
    2345         [ #  # ]:          0 :         if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
    2346                 :            :                 return 0;
    2347                 :            : 
    2348         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_RING_GRP_FREE, BNXT_USE_CHIMP_MB);
    2349                 :            : 
    2350                 :          0 :         req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
    2351                 :            : 
    2352                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2353                 :            : 
    2354   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2355                 :            :         HWRM_UNLOCK();
    2356                 :            : 
    2357                 :          0 :         bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
    2358                 :          0 :         return rc;
    2359                 :            : }
    2360                 :            : 
    2361                 :          0 : int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
    2362                 :            : {
    2363                 :            :         int rc = 0;
    2364                 :          0 :         struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
    2365                 :          0 :         struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
    2366                 :            : 
    2367         [ #  # ]:          0 :         if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
    2368                 :            :                 return rc;
    2369                 :            : 
    2370         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
    2371                 :            : 
    2372                 :          0 :         req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
    2373                 :            : 
    2374                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2375                 :            : 
    2376   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2377                 :            :         HWRM_UNLOCK();
    2378                 :            : 
    2379                 :          0 :         return rc;
    2380                 :            : }
    2381                 :            : 
    2382                 :          0 : int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
    2383                 :            : {
    2384                 :            :         int rc;
    2385                 :          0 :         struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
    2386                 :          0 :         struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    2387                 :            : 
    2388         [ #  # ]:          0 :         if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE)
    2389                 :            :                 return 0;
    2390                 :            : 
    2391   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
    2392                 :            : 
    2393   [ #  #  #  # ]:          0 :         req.stats_dma_length = rte_cpu_to_le_16(BNXT_HWRM_CTX_GET_SIZE(bp));
    2394                 :            : 
    2395                 :          0 :         req.update_period_ms = rte_cpu_to_le_32(0);
    2396                 :            : 
    2397                 :          0 :         req.stats_dma_addr = rte_cpu_to_le_64(cpr->hw_stats_map);
    2398                 :            : 
    2399                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2400                 :            : 
    2401   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2402                 :            : 
    2403                 :          0 :         cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
    2404                 :            : 
    2405                 :            :         HWRM_UNLOCK();
    2406                 :            : 
    2407                 :          0 :         return rc;
    2408                 :            : }
    2409                 :            : 
    2410                 :          0 : static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
    2411                 :            : {
    2412                 :            :         int rc;
    2413                 :          0 :         struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
    2414                 :          0 :         struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
    2415                 :            : 
    2416         [ #  # ]:          0 :         if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
    2417                 :            :                 return 0;
    2418                 :            : 
    2419         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
    2420                 :            : 
    2421                 :          0 :         req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
    2422                 :            : 
    2423                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2424                 :            : 
    2425   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2426                 :            :         HWRM_UNLOCK();
    2427                 :            : 
    2428                 :          0 :         cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
    2429                 :            : 
    2430                 :          0 :         return rc;
    2431                 :            : }
    2432                 :            : 
    2433                 :          0 : int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2434                 :            : {
    2435                 :            :         int rc = 0;
    2436                 :          0 :         struct hwrm_vnic_alloc_input req = { 0 };
    2437                 :          0 :         struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    2438                 :            : 
    2439                 :          0 :         vnic->mru = BNXT_VNIC_MRU(bp->eth_dev->data->mtu);
    2440   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_ALLOC, BNXT_USE_CHIMP_MB);
    2441                 :            : 
    2442         [ #  # ]:          0 :         if (vnic->func_default)
    2443                 :          0 :                 req.flags =
    2444                 :            :                         rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
    2445                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2446                 :            : 
    2447   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2448                 :            : 
    2449                 :          0 :         vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
    2450                 :            :         HWRM_UNLOCK();
    2451                 :          0 :         PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
    2452                 :          0 :         return rc;
    2453                 :            : }
    2454                 :            : 
    2455                 :          0 : static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
    2456                 :            :                                         struct bnxt_vnic_info *vnic,
    2457                 :            :                                         struct bnxt_plcmodes_cfg *pmode)
    2458                 :            : {
    2459                 :            :         int rc = 0;
    2460                 :          0 :         struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
    2461                 :          0 :         struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    2462                 :            : 
    2463         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
    2464                 :            : 
    2465                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2466                 :            : 
    2467                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2468                 :            : 
    2469   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2470                 :            : 
    2471                 :          0 :         pmode->flags = rte_le_to_cpu_32(resp->flags);
    2472                 :            :         /* dflt_vnic bit doesn't exist in the _cfg command */
    2473                 :          0 :         pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
    2474                 :          0 :         pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
    2475                 :          0 :         pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
    2476                 :          0 :         pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
    2477                 :            : 
    2478                 :            :         HWRM_UNLOCK();
    2479                 :            : 
    2480                 :          0 :         return rc;
    2481                 :            : }
    2482                 :            : 
    2483                 :          0 : static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
    2484                 :            :                                        struct bnxt_vnic_info *vnic,
    2485                 :            :                                        struct bnxt_plcmodes_cfg *pmode)
    2486                 :            : {
    2487                 :            :         int rc = 0;
    2488                 :          0 :         struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
    2489                 :          0 :         struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2490                 :            : 
    2491         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    2492                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
    2493                 :          0 :                 return rc;
    2494                 :            :         }
    2495                 :            : 
    2496         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
    2497                 :            : 
    2498                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2499                 :          0 :         req.flags = rte_cpu_to_le_32(pmode->flags);
    2500                 :          0 :         req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
    2501                 :          0 :         req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
    2502                 :          0 :         req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
    2503                 :          0 :         req.enables = rte_cpu_to_le_32(
    2504                 :            :             HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
    2505                 :            :             HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
    2506                 :            :             HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
    2507                 :            :         );
    2508                 :            : 
    2509                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2510                 :            : 
    2511   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2512                 :            :         HWRM_UNLOCK();
    2513                 :            : 
    2514                 :          0 :         return rc;
    2515                 :            : }
    2516                 :            : 
    2517                 :          0 : int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2518                 :            : {
    2519                 :            :         int rc = 0;
    2520                 :          0 :         struct hwrm_vnic_cfg_input req = {.req_type = 0 };
    2521                 :          0 :         struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2522                 :          0 :         struct bnxt_plcmodes_cfg pmodes = { 0 };
    2523                 :            :         uint32_t ctx_enable_flag = 0;
    2524                 :            :         uint32_t enables = 0;
    2525                 :            : 
    2526         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    2527                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
    2528                 :          0 :                 return rc;
    2529                 :            :         }
    2530                 :            : 
    2531                 :          0 :         rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
    2532         [ #  # ]:          0 :         if (rc)
    2533                 :            :                 return rc;
    2534                 :            : 
    2535   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_CFG, BNXT_USE_CHIMP_MB);
    2536                 :            : 
    2537         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
    2538                 :          0 :                 int dflt_rxq = vnic->start_grp_id;
    2539                 :            :                 struct bnxt_rx_ring_info *rxr;
    2540                 :            :                 struct bnxt_cp_ring_info *cpr;
    2541                 :            :                 struct bnxt_rx_queue *rxq;
    2542                 :            :                 int i;
    2543                 :            : 
    2544                 :            :                 /*
    2545                 :            :                  * The first active receive ring is used as the VNIC
    2546                 :            :                  * default receive ring. If there are no active receive
    2547                 :            :                  * rings (all corresponding receive queues are stopped),
    2548                 :            :                  * the first receive ring is used.
    2549                 :            :                  */
    2550         [ #  # ]:          0 :                 for (i = vnic->start_grp_id; i < vnic->end_grp_id; i++) {
    2551                 :          0 :                         rxq = bp->eth_dev->data->rx_queues[i];
    2552   [ #  #  #  # ]:          0 :                         if (rxq->rx_started &&
    2553                 :          0 :                             bnxt_vnic_queue_id_is_valid(vnic, i)) {
    2554                 :            :                                 dflt_rxq = i;
    2555                 :            :                                 break;
    2556                 :            :                         }
    2557                 :            :                 }
    2558                 :            : 
    2559                 :          0 :                 rxq = bp->eth_dev->data->rx_queues[dflt_rxq];
    2560                 :          0 :                 rxr = rxq->rx_ring;
    2561                 :          0 :                 cpr = rxq->cp_ring;
    2562                 :            : 
    2563                 :          0 :                 req.default_rx_ring_id =
    2564                 :          0 :                         rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
    2565                 :          0 :                 req.default_cmpl_ring_id =
    2566                 :          0 :                         rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
    2567                 :            :                 enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
    2568                 :            :                           HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
    2569         [ #  # ]:          0 :                 if (bp->vnic_cap_flags & BNXT_VNIC_CAP_RX_CMPL_V2) {
    2570                 :            :                         enables |= HWRM_VNIC_CFG_INPUT_ENABLES_RX_CSUM_V2_MODE;
    2571                 :          0 :                         req.rx_csum_v2_mode =
    2572                 :            :                                 HWRM_VNIC_CFG_INPUT_RX_CSUM_V2_MODE_ALL_OK;
    2573                 :            :                 }
    2574                 :          0 :                 goto config_mru;
    2575                 :            :         }
    2576                 :            : 
    2577                 :            :         /* Only RSS support for now TBD: COS & LB */
    2578                 :            :         enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
    2579         [ #  # ]:          0 :         if (vnic->lb_rule != 0xffff)
    2580                 :            :                 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
    2581         [ #  # ]:          0 :         if (vnic->cos_rule != 0xffff)
    2582                 :          0 :                 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
    2583         [ #  # ]:          0 :         if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
    2584                 :            :                 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
    2585                 :          0 :                 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
    2586                 :            :         }
    2587         [ #  # ]:          0 :         if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
    2588                 :          0 :                 ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_QUEUE_ID;
    2589                 :          0 :                 req.queue_id = rte_cpu_to_le_16(vnic->cos_queue_id);
    2590                 :            :         }
    2591                 :            : 
    2592                 :          0 :         enables |= ctx_enable_flag;
    2593                 :          0 :         req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
    2594                 :          0 :         req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
    2595                 :          0 :         req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
    2596                 :          0 :         req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
    2597                 :            : 
    2598                 :          0 : config_mru:
    2599         [ #  # ]:          0 :         if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
    2600                 :          0 :                 req.l2_cqe_mode = HWRM_VNIC_CFG_INPUT_L2_CQE_MODE_COMPRESSED;
    2601                 :          0 :                 enables |= HWRM_VNIC_CFG_INPUT_ENABLES_L2_CQE_MODE;
    2602                 :          0 :                 PMD_DRV_LOG(DEBUG, "Enabling compressed Rx CQE\n");
    2603                 :            :         }
    2604                 :            : 
    2605                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    2606                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2607                 :          0 :         req.mru = rte_cpu_to_le_16(vnic->mru);
    2608                 :            :         /* Configure default VNIC only once. */
    2609   [ #  #  #  # ]:          0 :         if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
    2610                 :          0 :                 req.flags |=
    2611                 :            :                     rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
    2612                 :          0 :                 bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
    2613                 :            :         }
    2614         [ #  # ]:          0 :         if (vnic->vlan_strip)
    2615                 :          0 :                 req.flags |=
    2616                 :            :                     rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
    2617         [ #  # ]:          0 :         if (vnic->bd_stall)
    2618                 :          0 :                 req.flags |=
    2619                 :            :                     rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
    2620         [ #  # ]:          0 :         if (vnic->rss_dflt_cr)
    2621                 :          0 :                 req.flags |= rte_cpu_to_le_32(
    2622                 :            :                         HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
    2623                 :            : 
    2624                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2625                 :            : 
    2626   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2627                 :            :         HWRM_UNLOCK();
    2628                 :            : 
    2629                 :          0 :         rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
    2630                 :            : 
    2631                 :          0 :         return rc;
    2632                 :            : }
    2633                 :            : 
    2634                 :          0 : int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
    2635                 :            :                 int16_t fw_vf_id)
    2636                 :            : {
    2637                 :            :         int rc = 0;
    2638                 :          0 :         struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
    2639                 :          0 :         struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    2640                 :            : 
    2641         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    2642                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC QCFG ID %d\n", vnic->fw_vnic_id);
    2643                 :          0 :                 return rc;
    2644                 :            :         }
    2645         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_QCFG, BNXT_USE_CHIMP_MB);
    2646                 :            : 
    2647                 :          0 :         req.enables =
    2648                 :            :                 rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
    2649                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2650                 :          0 :         req.vf_id = rte_cpu_to_le_16(fw_vf_id);
    2651                 :            : 
    2652                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2653                 :            : 
    2654   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2655                 :            : 
    2656                 :          0 :         vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
    2657                 :          0 :         vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
    2658                 :          0 :         vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
    2659                 :          0 :         vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
    2660                 :          0 :         vnic->mru = rte_le_to_cpu_16(resp->mru);
    2661                 :          0 :         vnic->func_default = rte_le_to_cpu_32(
    2662                 :          0 :                         resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
    2663                 :          0 :         vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
    2664                 :            :                         HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
    2665                 :          0 :         vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
    2666                 :            :                         HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
    2667                 :          0 :         vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
    2668                 :            :                         HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
    2669                 :            : 
    2670                 :            :         HWRM_UNLOCK();
    2671                 :            : 
    2672                 :          0 :         return rc;
    2673                 :            : }
    2674                 :            : 
    2675                 :          0 : int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
    2676                 :            :                              struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
    2677                 :            : {
    2678                 :            :         int rc = 0;
    2679                 :            :         uint16_t ctx_id;
    2680                 :          0 :         struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
    2681                 :          0 :         struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
    2682                 :            :                                                 bp->hwrm_cmd_resp_addr;
    2683                 :            : 
    2684         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
    2685                 :            : 
    2686                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2687   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2688                 :            : 
    2689                 :          0 :         ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
    2690         [ #  # ]:          0 :         if (!BNXT_HAS_RING_GRPS(bp))
    2691                 :          0 :                 vnic->fw_grp_ids[ctx_idx] = ctx_id;
    2692         [ #  # ]:          0 :         else if (ctx_idx == 0)
    2693                 :          0 :                 vnic->rss_rule = ctx_id;
    2694                 :            : 
    2695                 :            :         HWRM_UNLOCK();
    2696                 :            : 
    2697                 :          0 :         return rc;
    2698                 :            : }
    2699                 :            : 
    2700                 :            : static
    2701                 :          0 : int _bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
    2702                 :            :                              struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
    2703                 :            : {
    2704                 :            :         int rc = 0;
    2705                 :          0 :         struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
    2706                 :          0 :         struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
    2707                 :            :                                                 bp->hwrm_cmd_resp_addr;
    2708                 :            : 
    2709         [ #  # ]:          0 :         if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
    2710                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
    2711                 :          0 :                 return rc;
    2712                 :            :         }
    2713         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
    2714                 :            : 
    2715                 :          0 :         req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
    2716                 :            : 
    2717                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2718                 :            : 
    2719   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2720                 :            :         HWRM_UNLOCK();
    2721                 :            : 
    2722                 :          0 :         return rc;
    2723                 :            : }
    2724                 :            : 
    2725                 :          0 : int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2726                 :            : {
    2727                 :            :         int rc = 0;
    2728                 :            : 
    2729         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
    2730                 :            :                 int j;
    2731                 :            : 
    2732         [ #  # ]:          0 :                 for (j = 0; j < vnic->num_lb_ctxts; j++) {
    2733                 :          0 :                         rc = _bnxt_hwrm_vnic_ctx_free(bp,
    2734                 :            :                                                       vnic,
    2735                 :          0 :                                                       vnic->fw_grp_ids[j]);
    2736                 :          0 :                         vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
    2737                 :            :                 }
    2738                 :          0 :                 vnic->num_lb_ctxts = 0;
    2739                 :            :         } else {
    2740                 :          0 :                 rc = _bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
    2741                 :          0 :                 vnic->rss_rule = INVALID_HW_RING_ID;
    2742                 :            :         }
    2743                 :            : 
    2744                 :          0 :         return rc;
    2745                 :            : }
    2746                 :            : 
    2747                 :          0 : int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2748                 :            : {
    2749                 :            :         int rc = 0;
    2750                 :          0 :         struct hwrm_vnic_free_input req = {.req_type = 0 };
    2751                 :          0 :         struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
    2752                 :            : 
    2753         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    2754                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC FREE ID %x\n", vnic->fw_vnic_id);
    2755                 :          0 :                 return rc;
    2756                 :            :         }
    2757                 :            : 
    2758         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_FREE, BNXT_USE_CHIMP_MB);
    2759                 :            : 
    2760                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2761                 :            : 
    2762                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2763                 :            : 
    2764   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2765                 :            :         HWRM_UNLOCK();
    2766                 :            : 
    2767                 :          0 :         vnic->fw_vnic_id = INVALID_HW_RING_ID;
    2768                 :            :         /* Configure default VNIC again if necessary. */
    2769   [ #  #  #  # ]:          0 :         if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
    2770                 :          0 :                 bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
    2771                 :            : 
    2772                 :            :         return rc;
    2773                 :            : }
    2774                 :            : 
    2775                 :          0 : static uint32_t bnxt_sanitize_rss_type(struct bnxt *bp, uint32_t types)
    2776                 :            : {
    2777                 :            :         uint32_t hwrm_type = types;
    2778                 :            : 
    2779         [ #  # ]:          0 :         if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6_FLOW_LABEL &&
    2780         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE))
    2781                 :          0 :                 hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6_FLOW_LABEL;
    2782                 :            : 
    2783         [ #  # ]:          0 :         if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV4 &&
    2784         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI4_CAP))
    2785                 :          0 :                 hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV4;
    2786         [ #  # ]:          0 :         if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV6 &&
    2787         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI6_CAP))
    2788                 :          0 :                 hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV6;
    2789                 :            : 
    2790         [ #  # ]:          0 :         if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV4 &&
    2791         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI4_CAP))
    2792                 :          0 :                 hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV4;
    2793                 :            : 
    2794         [ #  # ]:          0 :         if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV6 &&
    2795         [ #  # ]:          0 :             !(bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI6_CAP))
    2796                 :          0 :                 hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV6;
    2797                 :            : 
    2798                 :          0 :         return hwrm_type;
    2799                 :            : }
    2800                 :            : 
    2801                 :            : #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
    2802                 :            : static int
    2803                 :            : bnxt_hwrm_vnic_rss_qcfg_p5(struct bnxt *bp)
    2804                 :            : {
    2805                 :            :         struct hwrm_vnic_rss_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    2806                 :            :         struct hwrm_vnic_rss_qcfg_input req = {0};
    2807                 :            :         int rc;
    2808                 :            : 
    2809                 :            :         HWRM_PREP(&req, HWRM_VNIC_RSS_QCFG, BNXT_USE_CHIMP_MB);
    2810                 :            :         /* vnic_id and rss_ctx_idx must be set to INVALID to read the
    2811                 :            :          * global hash mode.
    2812                 :            :          */
    2813                 :            :         req.vnic_id = rte_cpu_to_le_16(BNXT_DFLT_VNIC_ID_INVALID);
    2814                 :            :         req.rss_ctx_idx = rte_cpu_to_le_16(BNXT_RSS_CTX_IDX_INVALID);
    2815                 :            :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
    2816                 :            :                                     BNXT_USE_CHIMP_MB);
    2817                 :            :         HWRM_CHECK_RESULT();
    2818                 :            :         HWRM_UNLOCK();
    2819                 :            :         PMD_DRV_LOG(DEBUG, "RSS QCFG: Hash level %d\n", resp->hash_mode_flags);
    2820                 :            : 
    2821                 :            :         return rc;
    2822                 :            : }
    2823                 :            : #endif
    2824                 :            : 
    2825                 :            : static int
    2826                 :          0 : bnxt_hwrm_vnic_rss_cfg_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2827                 :            : {
    2828                 :            :         int i;
    2829                 :            :         int rc = 0;
    2830                 :          0 :         int nr_ctxs = vnic->num_lb_ctxts;
    2831                 :          0 :         struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
    2832                 :          0 :         struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2833                 :            : 
    2834         [ #  # ]:          0 :         for (i = 0; i < nr_ctxs; i++) {
    2835   [ #  #  #  # ]:          0 :                 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
    2836                 :            : 
    2837                 :          0 :                 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2838                 :          0 :                 req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
    2839                 :            :                 /* Update req with vnic ring_select_mode for P7 */
    2840         [ #  # ]:          0 :                 if (BNXT_CHIP_P7(bp))
    2841                 :          0 :                         req.ring_select_mode = vnic->ring_select_mode;
    2842                 :            :                 /* When the vnic_id in the request field is a valid
    2843                 :            :                  * one, the hash_mode_flags in the request field must
    2844                 :            :                  * be set to DEFAULT. And any request to change the
    2845                 :            :                  * default behavior must be done in a separate call
    2846                 :            :                  * to HWRM_VNIC_RSS_CFG by exclusively setting hash
    2847                 :            :                  * mode and vnic_id, rss_ctx_idx to INVALID.
    2848                 :            :                  */
    2849                 :          0 :                 req.hash_mode_flags = BNXT_HASH_MODE_DEFAULT;
    2850                 :            : 
    2851                 :          0 :                 req.hash_key_tbl_addr =
    2852                 :          0 :                         rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
    2853                 :            : 
    2854                 :          0 :                 req.ring_grp_tbl_addr =
    2855                 :          0 :                         rte_cpu_to_le_64(vnic->rss_table_dma_addr +
    2856                 :            :                                          i * BNXT_RSS_ENTRIES_PER_CTX_P5 *
    2857                 :            :                                          2 * sizeof(uint16_t));
    2858                 :          0 :                 req.ring_table_pair_index = i;
    2859                 :          0 :                 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
    2860                 :            : 
    2861                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
    2862                 :            :                                             BNXT_USE_CHIMP_MB);
    2863                 :            : 
    2864   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2865                 :            :                 HWRM_UNLOCK();
    2866                 :          0 :                 PMD_DRV_LOG(DEBUG, "RSS CFG: Hash level %d\n", req.hash_mode_flags);
    2867                 :            :         }
    2868                 :            : 
    2869                 :            :         return rc;
    2870                 :            : }
    2871                 :            : 
    2872                 :            : static int
    2873                 :          0 : bnxt_hwrm_vnic_rss_cfg_hash_mode_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2874                 :            : {
    2875                 :          0 :         struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2876                 :          0 :         struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
    2877                 :            :         int rc = 0;
    2878                 :            : 
    2879                 :            :         /* The reason we are returning success here is that this
    2880                 :            :          * call is in the context of user/stack RSS configuration.
    2881                 :            :          * Even though OUTER RSS is not supported, the normal RSS
    2882                 :            :          * configuration should continue to work.
    2883                 :            :          */
    2884   [ #  #  #  #  :          0 :         if ((BNXT_CHIP_P5(bp) && BNXT_VNIC_OUTER_RSS_UNSUPPORTED(bp)) ||
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    2885         [ #  # ]:          0 :             (!BNXT_CHIP_P5(bp) && !(bp->vnic_cap_flags & BNXT_VNIC_CAP_OUTER_RSS)))
    2886                 :            :                 return 0;
    2887                 :            : 
    2888                 :            :         /* Don't call RSS hash level configuration if the current
    2889                 :            :          * hash level is the same as the hash level that is requested.
    2890                 :            :          */
    2891         [ #  # ]:          0 :         if (vnic->prev_hash_mode == vnic->hash_mode)
    2892                 :            :                 return 0;
    2893                 :            : 
    2894   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
    2895                 :            : 
    2896                 :            :         /* For FW, hash_mode == DEFAULT means that
    2897                 :            :          * the FW is capable of doing INNER & OUTER RSS as well.
    2898                 :            :          * DEFAULT doesn't mean that the FW is
    2899                 :            :          * going to change the hash_mode to INNER. However, for
    2900                 :            :          * the USER, DEFAULT means, change the hash mode to the
    2901                 :            :          * NIC's DEFAULT hash mode which is INNER.
    2902                 :            :          *
    2903                 :            :          * Hence, driver should make the translation of hash_mode
    2904                 :            :          * to INNERMOST when hash_mode from the dpdk stack is
    2905                 :            :          * DEFAULT.
    2906                 :            :          */
    2907         [ #  # ]:          0 :         if (vnic->hash_mode == BNXT_HASH_MODE_DEFAULT)
    2908                 :          0 :                 req.hash_mode_flags = BNXT_HASH_MODE_INNERMOST;
    2909                 :            :         else
    2910                 :          0 :                 req.hash_mode_flags = vnic->hash_mode;
    2911                 :          0 :         req.vnic_id = rte_cpu_to_le_16(BNXT_DFLT_VNIC_ID_INVALID);
    2912                 :          0 :         req.rss_ctx_idx = rte_cpu_to_le_16(BNXT_RSS_CTX_IDX_INVALID);
    2913                 :            : 
    2914                 :          0 :         PMD_DRV_LOG(DEBUG, "RSS CFG: Hash level %d\n", req.hash_mode_flags);
    2915                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
    2916                 :            :                                     BNXT_USE_CHIMP_MB);
    2917                 :            : 
    2918   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2919                 :            :         /* Store the programmed hash_mode in prev_hash_mode so that
    2920                 :            :          * it can checked against the next user requested hash mode.
    2921                 :            :          */
    2922                 :            :         if (!rc)
    2923                 :          0 :                 vnic->prev_hash_mode = vnic->hash_mode;
    2924                 :            :         HWRM_UNLOCK();
    2925                 :          0 :         return rc;
    2926                 :            : }
    2927                 :            : 
    2928                 :            : static int
    2929                 :          0 : bnxt_hwrm_vnic_rss_cfg_non_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    2930                 :            : {
    2931                 :          0 :         struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
    2932                 :          0 :         struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2933                 :            :         int rc = 0;
    2934                 :            : 
    2935         [ #  # ]:          0 :         if (vnic->num_lb_ctxts == 0)
    2936                 :            :                 return rc;
    2937                 :            : 
    2938         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
    2939                 :            : 
    2940                 :          0 :         req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
    2941                 :          0 :         req.hash_mode_flags = vnic->hash_mode;
    2942                 :            : 
    2943                 :          0 :         req.ring_grp_tbl_addr =
    2944                 :          0 :             rte_cpu_to_le_64(vnic->rss_table_dma_addr);
    2945                 :          0 :         req.hash_key_tbl_addr =
    2946                 :          0 :             rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
    2947                 :          0 :         req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
    2948                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    2949                 :            : 
    2950                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    2951                 :            : 
    2952   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    2953                 :            :         HWRM_UNLOCK();
    2954                 :            : 
    2955                 :          0 :         return rc;
    2956                 :            : }
    2957                 :            : 
    2958                 :          0 : int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
    2959                 :            :                            struct bnxt_vnic_info *vnic)
    2960                 :            : {
    2961                 :            :         int rc = 0;
    2962                 :            : 
    2963         [ #  # ]:          0 :         if (!vnic->rss_table)
    2964                 :            :                 return 0;
    2965                 :            : 
    2966                 :            :         /* Handle all the non-thor skus rss here */
    2967         [ #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp))
    2968                 :          0 :                 return bnxt_hwrm_vnic_rss_cfg_non_p5(bp, vnic);
    2969                 :            : 
    2970                 :            :         /* Handle Thor2 and Thor skus rss here */
    2971                 :          0 :         rc = bnxt_hwrm_vnic_rss_cfg_p5(bp, vnic);
    2972                 :            : 
    2973                 :            :         /* configure hash mode for Thor/Thor2 */
    2974         [ #  # ]:          0 :         if (!rc)
    2975                 :          0 :                 return bnxt_hwrm_vnic_rss_cfg_hash_mode_p5(bp, vnic);
    2976                 :            : 
    2977                 :            :         return rc;
    2978                 :            : }
    2979                 :            : 
    2980                 :          0 : int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
    2981                 :            :                         struct bnxt_vnic_info *vnic)
    2982                 :            : {
    2983                 :            :         int rc = 0;
    2984                 :          0 :         struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
    2985                 :          0 :         struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    2986                 :            :         uint16_t size;
    2987                 :            : 
    2988         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    2989                 :          0 :                 PMD_DRV_LOG(DEBUG, "VNIC ID %x\n", vnic->fw_vnic_id);
    2990                 :          0 :                 return rc;
    2991                 :            :         }
    2992                 :            : 
    2993   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
    2994                 :            : 
    2995                 :          0 :         req.flags = rte_cpu_to_le_32(
    2996                 :            :                         HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT);
    2997                 :            : 
    2998                 :          0 :         req.enables = rte_cpu_to_le_32(
    2999                 :            :                 HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID);
    3000                 :            : 
    3001         [ #  # ]:          0 :         size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
    3002                 :          0 :         size -= RTE_PKTMBUF_HEADROOM;
    3003                 :          0 :         size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
    3004                 :            : 
    3005                 :          0 :         req.jumbo_thresh = rte_cpu_to_le_16(size);
    3006                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    3007                 :            : 
    3008                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3009                 :            : 
    3010   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3011                 :            :         HWRM_UNLOCK();
    3012                 :            : 
    3013                 :          0 :         return rc;
    3014                 :            : }
    3015                 :            : 
    3016                 :            : #define BNXT_DFLT_TUNL_TPA_BMAP                                 \
    3017                 :            :         (HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_GRE |        \
    3018                 :            :          HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_IPV4 |       \
    3019                 :            :          HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_IPV6)
    3020                 :            : 
    3021                 :            : static void bnxt_vnic_update_tunl_tpa_bmap(struct bnxt *bp,
    3022                 :            :                                            struct hwrm_vnic_tpa_cfg_input *req)
    3023                 :            : {
    3024                 :            :         uint32_t tunl_tpa_bmap = BNXT_DFLT_TUNL_TPA_BMAP;
    3025                 :            : 
    3026         [ #  # ]:          0 :         if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_VNIC_TUNNEL_TPA))
    3027                 :            :                 return;
    3028                 :            : 
    3029         [ #  # ]:          0 :         if (bp->vxlan_port_cnt)
    3030                 :            :                 tunl_tpa_bmap |= HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_VXLAN |
    3031                 :            :                         HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_VXLAN_GPE;
    3032                 :            : 
    3033         [ #  # ]:          0 :         if (bp->geneve_port_cnt)
    3034                 :          0 :                 tunl_tpa_bmap |= HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_GENEVE;
    3035                 :            : 
    3036                 :          0 :         req->enables |= rte_cpu_to_le_32(HWRM_VNIC_TPA_CFG_INPUT_ENABLES_TNL_TPA_EN);
    3037                 :          0 :         req->tnl_tpa_en_bitmap = rte_cpu_to_le_32(tunl_tpa_bmap);
    3038                 :            : }
    3039                 :            : 
    3040                 :          0 : int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
    3041                 :            :                         struct bnxt_vnic_info *vnic, bool enable)
    3042                 :            : {
    3043                 :            :         int rc = 0;
    3044                 :          0 :         struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
    3045                 :          0 :         struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    3046                 :            : 
    3047         [ #  # ]:          0 :         if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
    3048                 :            :                 /* Don't worry if disabling TPA */
    3049         [ #  # ]:          0 :                 if (!enable)
    3050                 :            :                         return 0;
    3051                 :            : 
    3052                 :            :                 /* Return an error if enabling TPA w/ compressed Rx CQE. */
    3053                 :          0 :                 PMD_DRV_LOG(ERR, "No HW support for LRO with compressed Rx\n");
    3054                 :          0 :                 return -ENOTSUP;
    3055                 :            :         }
    3056                 :            : 
    3057   [ #  #  #  # ]:          0 :         if ((BNXT_CHIP_P5(bp) || BNXT_CHIP_P7(bp)) && !bp->max_tpa_v2) {
    3058         [ #  # ]:          0 :                 if (enable)
    3059                 :          0 :                         PMD_DRV_LOG(ERR, "No HW support for LRO\n");
    3060                 :          0 :                 return -ENOTSUP;
    3061                 :            :         }
    3062                 :            : 
    3063         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
    3064                 :          0 :                 PMD_DRV_LOG(DEBUG, "Invalid vNIC ID\n");
    3065                 :          0 :                 return 0;
    3066                 :            :         }
    3067                 :            : 
    3068   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
    3069                 :            : 
    3070         [ #  # ]:          0 :         if (enable) {
    3071                 :          0 :                 req.enables = rte_cpu_to_le_32(
    3072                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
    3073                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
    3074                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
    3075                 :          0 :                 req.flags = rte_cpu_to_le_32(
    3076                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
    3077                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
    3078                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
    3079                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
    3080                 :            :                                 HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
    3081                 :            :                         HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
    3082         [ #  # ]:          0 :                 req.max_aggs = rte_cpu_to_le_16(BNXT_TPA_MAX_AGGS(bp));
    3083         [ #  # ]:          0 :                 req.max_agg_segs = rte_cpu_to_le_16(BNXT_TPA_MAX_SEGS(bp));
    3084                 :          0 :                 req.min_agg_len = rte_cpu_to_le_32(512);
    3085                 :            : 
    3086         [ #  # ]:          0 :                 if (BNXT_CHIP_P5_P7(bp))
    3087                 :          0 :                         req.max_aggs = rte_cpu_to_le_16(bp->max_tpa_v2);
    3088                 :            : 
    3089                 :            :                 /* For tpa v2 handle as per spec mss and log2 units */
    3090         [ #  # ]:          0 :                 if (BNXT_CHIP_P7(bp)) {
    3091                 :            :                         uint32_t nsegs, n, segs = 0;
    3092                 :          0 :                         uint16_t mss = bp->eth_dev->data->mtu - 40;
    3093                 :          0 :                         size_t page_size = rte_mem_page_size();
    3094                 :          0 :                         uint32_t max_mbuf_frags =
    3095                 :          0 :                                 BNXT_TPA_MAX_PAGES / (rte_mem_page_size() + 1);
    3096                 :            : 
    3097                 :            :                         /* Calculate the number of segs based on mss */
    3098         [ #  # ]:          0 :                         if (mss <= page_size) {
    3099                 :          0 :                                 n = page_size / mss;
    3100                 :          0 :                                 nsegs = (max_mbuf_frags - 1) * n;
    3101                 :            :                         } else {
    3102                 :          0 :                                 n = mss / page_size;
    3103         [ #  # ]:          0 :                                 if (mss & (page_size - 1))
    3104                 :          0 :                                         n++;
    3105                 :          0 :                                 nsegs = (max_mbuf_frags - n) / n;
    3106                 :            :                         }
    3107                 :            :                         segs = rte_log2_u32(nsegs);
    3108                 :          0 :                         req.max_agg_segs = rte_cpu_to_le_16(segs);
    3109                 :            :                 }
    3110                 :            :                 bnxt_vnic_update_tunl_tpa_bmap(bp, &req);
    3111                 :            :         }
    3112                 :          0 :         req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    3113                 :            : 
    3114                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3115                 :            : 
    3116   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3117                 :            :         HWRM_UNLOCK();
    3118                 :            : 
    3119                 :          0 :         return rc;
    3120                 :            : }
    3121                 :            : 
    3122                 :          0 : int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
    3123                 :            : {
    3124                 :          0 :         struct hwrm_func_cfg_input req = {0};
    3125                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    3126                 :            :         int rc;
    3127                 :            : 
    3128                 :          0 :         req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
    3129                 :          0 :         req.enables = rte_cpu_to_le_32(
    3130                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
    3131                 :            :         memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
    3132                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    3133                 :            : 
    3134         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    3135                 :            : 
    3136                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3137   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3138                 :            :         HWRM_UNLOCK();
    3139                 :            : 
    3140                 :          0 :         bp->pf->vf_info[vf].random_mac = false;
    3141                 :            : 
    3142                 :          0 :         return rc;
    3143                 :            : }
    3144                 :            : 
    3145                 :          0 : int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
    3146                 :            :                                   uint64_t *dropped)
    3147                 :            : {
    3148                 :            :         int rc = 0;
    3149                 :          0 :         struct hwrm_func_qstats_input req = {.req_type = 0};
    3150                 :          0 :         struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
    3151                 :            : 
    3152         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
    3153                 :            : 
    3154                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    3155                 :            : 
    3156                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3157                 :            : 
    3158   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3159                 :            : 
    3160         [ #  # ]:          0 :         if (dropped)
    3161                 :          0 :                 *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
    3162                 :            : 
    3163                 :            :         HWRM_UNLOCK();
    3164                 :            : 
    3165                 :          0 :         return rc;
    3166                 :            : }
    3167                 :            : 
    3168                 :          0 : int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
    3169                 :            :                           struct rte_eth_stats *stats,
    3170                 :            :                           struct hwrm_func_qstats_output *func_qstats)
    3171                 :            : {
    3172                 :            :         int rc = 0;
    3173                 :          0 :         struct hwrm_func_qstats_input req = {.req_type = 0};
    3174                 :          0 :         struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
    3175                 :            : 
    3176         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
    3177                 :            : 
    3178                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    3179                 :            : 
    3180                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3181                 :            : 
    3182   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3183         [ #  # ]:          0 :         if (func_qstats)
    3184                 :            :                 memcpy(func_qstats, resp,
    3185                 :            :                        sizeof(struct hwrm_func_qstats_output));
    3186                 :            : 
    3187         [ #  # ]:          0 :         if (!stats)
    3188                 :          0 :                 goto exit;
    3189                 :            : 
    3190                 :          0 :         stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
    3191                 :          0 :         stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
    3192                 :          0 :         stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
    3193                 :          0 :         stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
    3194                 :          0 :         stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
    3195                 :          0 :         stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
    3196                 :            : 
    3197                 :          0 :         stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
    3198                 :          0 :         stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
    3199                 :          0 :         stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
    3200                 :          0 :         stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
    3201                 :          0 :         stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
    3202                 :          0 :         stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
    3203                 :            : 
    3204                 :          0 :         stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
    3205                 :          0 :         stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
    3206                 :          0 :         stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
    3207                 :            : 
    3208                 :          0 : exit:
    3209                 :            :         HWRM_UNLOCK();
    3210                 :            : 
    3211                 :          0 :         return rc;
    3212                 :            : }
    3213                 :            : 
    3214                 :          0 : int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
    3215                 :            : {
    3216                 :            :         int rc = 0;
    3217                 :          0 :         struct hwrm_func_clr_stats_input req = {.req_type = 0};
    3218                 :          0 :         struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
    3219                 :            : 
    3220         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
    3221                 :            : 
    3222                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    3223                 :            : 
    3224                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3225                 :            : 
    3226   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3227                 :            :         HWRM_UNLOCK();
    3228                 :            : 
    3229                 :          0 :         return rc;
    3230                 :            : }
    3231                 :            : 
    3232                 :          0 : int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
    3233                 :            : {
    3234                 :            :         unsigned int i;
    3235                 :            :         int rc = 0;
    3236                 :            : 
    3237         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
    3238                 :            :                 struct bnxt_tx_queue *txq;
    3239                 :            :                 struct bnxt_rx_queue *rxq;
    3240                 :            :                 struct bnxt_cp_ring_info *cpr;
    3241                 :            : 
    3242         [ #  # ]:          0 :                 if (i >= bp->rx_cp_nr_rings) {
    3243                 :          0 :                         txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
    3244                 :          0 :                         cpr = txq->cp_ring;
    3245                 :            :                 } else {
    3246                 :          0 :                         rxq = bp->rx_queues[i];
    3247                 :          0 :                         cpr = rxq->cp_ring;
    3248                 :            :                 }
    3249                 :            : 
    3250                 :          0 :                 rc = bnxt_hwrm_stat_clear(bp, cpr);
    3251         [ #  # ]:          0 :                 if (rc)
    3252                 :          0 :                         return rc;
    3253                 :            :         }
    3254                 :            :         return 0;
    3255                 :            : }
    3256                 :            : 
    3257                 :            : static int
    3258                 :          0 : bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
    3259                 :            : {
    3260                 :            :         int rc;
    3261                 :            :         unsigned int i;
    3262                 :            :         struct bnxt_cp_ring_info *cpr;
    3263                 :            : 
    3264         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
    3265                 :            : 
    3266                 :          0 :                 cpr = bp->rx_queues[i]->cp_ring;
    3267         [ #  # ]:          0 :                 if (BNXT_HAS_RING_GRPS(bp))
    3268                 :          0 :                         bp->grp_info[i].fw_stats_ctx = -1;
    3269         [ #  # ]:          0 :                 if (cpr == NULL)
    3270                 :          0 :                         continue;
    3271                 :          0 :                 rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
    3272         [ #  # ]:          0 :                 if (rc)
    3273                 :          0 :                         return rc;
    3274                 :            :         }
    3275                 :            : 
    3276         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
    3277                 :          0 :                 cpr = bp->tx_queues[i]->cp_ring;
    3278         [ #  # ]:          0 :                 if (cpr == NULL)
    3279                 :          0 :                         continue;
    3280                 :          0 :                 rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
    3281         [ #  # ]:          0 :                 if (rc)
    3282                 :          0 :                         return rc;
    3283                 :            :         }
    3284                 :            : 
    3285                 :            :         return 0;
    3286                 :            : }
    3287                 :            : 
    3288                 :            : static int
    3289                 :          0 : bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
    3290                 :            : {
    3291                 :            :         uint16_t idx;
    3292                 :            :         uint32_t rc = 0;
    3293                 :            : 
    3294         [ #  # ]:          0 :         if (!BNXT_HAS_RING_GRPS(bp))
    3295                 :            :                 return 0;
    3296                 :            : 
    3297         [ #  # ]:          0 :         for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
    3298                 :            : 
    3299         [ #  # ]:          0 :                 if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
    3300                 :          0 :                         continue;
    3301                 :            : 
    3302                 :          0 :                 rc = bnxt_hwrm_ring_grp_free(bp, idx);
    3303                 :            : 
    3304         [ #  # ]:          0 :                 if (rc)
    3305                 :          0 :                         return rc;
    3306                 :            :         }
    3307                 :          0 :         return rc;
    3308                 :            : }
    3309                 :            : 
    3310                 :          0 : void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
    3311                 :            : {
    3312                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
    3313                 :            : 
    3314                 :          0 :         bnxt_hwrm_ring_free(bp, cp_ring,
    3315                 :            :                             HWRM_RING_FREE_INPUT_RING_TYPE_NQ,
    3316                 :            :                             INVALID_HW_RING_ID);
    3317                 :          0 :         memset(cpr->cp_desc_ring, 0,
    3318                 :          0 :                cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
    3319                 :          0 :         cpr->cp_raw_cons = 0;
    3320                 :          0 : }
    3321                 :            : 
    3322                 :          0 : void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
    3323                 :            : {
    3324                 :          0 :         struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
    3325                 :            : 
    3326                 :          0 :         bnxt_hwrm_ring_free(bp, cp_ring,
    3327                 :            :                             HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL,
    3328                 :            :                             INVALID_HW_RING_ID);
    3329                 :          0 :         memset(cpr->cp_desc_ring, 0,
    3330                 :          0 :                cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
    3331                 :          0 :         cpr->cp_raw_cons = 0;
    3332                 :          0 : }
    3333                 :            : 
    3334                 :          0 : void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
    3335                 :            : {
    3336                 :          0 :         struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
    3337         [ #  # ]:          0 :         struct bnxt_rx_ring_info *rxr = rxq ? rxq->rx_ring : NULL;
    3338         [ #  # ]:          0 :         struct bnxt_ring *ring = rxr ? rxr->rx_ring_struct : NULL;
    3339         [ #  # ]:          0 :         struct bnxt_cp_ring_info *cpr = rxq ? rxq->cp_ring : NULL;
    3340                 :            : 
    3341         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
    3342                 :          0 :                 bnxt_hwrm_ring_grp_free(bp, queue_index);
    3343                 :            : 
    3344         [ #  # ]:          0 :         if (ring != NULL && cpr != NULL)
    3345                 :          0 :                 bnxt_hwrm_ring_free(bp, ring,
    3346                 :            :                                     HWRM_RING_FREE_INPUT_RING_TYPE_RX,
    3347                 :          0 :                                     cpr->cp_ring_struct->fw_ring_id);
    3348         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
    3349                 :          0 :                 bp->grp_info[queue_index].rx_fw_ring_id = INVALID_HW_RING_ID;
    3350                 :            : 
    3351                 :            :         /* Check agg ring struct explicitly.
    3352                 :            :          * bnxt_need_agg_ring() returns the current state of offload flags,
    3353                 :            :          * but we may have to deal with agg ring struct before the offload
    3354                 :            :          * flags are updated.
    3355                 :            :          */
    3356   [ #  #  #  # ]:          0 :         if (!bnxt_need_agg_ring(bp->eth_dev) ||
    3357         [ #  # ]:          0 :             (rxr && rxr->ag_ring_struct == NULL))
    3358                 :          0 :                 goto no_agg;
    3359                 :            : 
    3360         [ #  # ]:          0 :         ring = rxr ? rxr->ag_ring_struct : NULL;
    3361         [ #  # ]:          0 :         if (ring != NULL && cpr != NULL) {
    3362                 :          0 :                 bnxt_hwrm_ring_free(bp, ring,
    3363                 :          0 :                                     BNXT_CHIP_P5_P7(bp) ?
    3364                 :            :                                     HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
    3365                 :            :                                     HWRM_RING_FREE_INPUT_RING_TYPE_RX,
    3366         [ #  # ]:          0 :                                     cpr->cp_ring_struct->fw_ring_id);
    3367                 :            :         }
    3368         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
    3369                 :          0 :                 bp->grp_info[queue_index].ag_fw_ring_id = INVALID_HW_RING_ID;
    3370                 :            : 
    3371                 :          0 : no_agg:
    3372         [ #  # ]:          0 :         if (cpr != NULL) {
    3373                 :          0 :                 bnxt_hwrm_stat_ctx_free(bp, cpr);
    3374                 :          0 :                 bnxt_free_cp_ring(bp, cpr);
    3375                 :            :         }
    3376                 :            : 
    3377         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp))
    3378                 :          0 :                 bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
    3379                 :          0 : }
    3380                 :            : 
    3381                 :          0 : int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int queue_index)
    3382                 :            : {
    3383                 :            :         int rc;
    3384                 :          0 :         struct hwrm_ring_reset_input req = {.req_type = 0 };
    3385                 :          0 :         struct hwrm_ring_reset_output *resp = bp->hwrm_cmd_resp_addr;
    3386                 :            : 
    3387         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_RING_RESET, BNXT_USE_CHIMP_MB);
    3388                 :            : 
    3389                 :          0 :         req.ring_type = HWRM_RING_RESET_INPUT_RING_TYPE_RX_RING_GRP;
    3390                 :          0 :         req.ring_id = rte_cpu_to_le_16(bp->grp_info[queue_index].fw_grp_id);
    3391                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3392                 :            : 
    3393   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3394                 :            : 
    3395                 :            :         HWRM_UNLOCK();
    3396                 :            : 
    3397                 :          0 :         return rc;
    3398                 :            : }
    3399                 :            : 
    3400                 :            : static int
    3401                 :          0 : bnxt_free_all_hwrm_rings(struct bnxt *bp)
    3402                 :            : {
    3403                 :            :         unsigned int i;
    3404                 :            : 
    3405         [ #  # ]:          0 :         for (i = 0; i < bp->tx_cp_nr_rings; i++)
    3406                 :          0 :                 bnxt_free_hwrm_tx_ring(bp, i);
    3407                 :            : 
    3408         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++)
    3409                 :          0 :                 bnxt_free_hwrm_rx_ring(bp, i);
    3410                 :            : 
    3411                 :          0 :         return 0;
    3412                 :            : }
    3413                 :            : 
    3414                 :          0 : int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
    3415                 :            : {
    3416                 :            :         uint16_t i;
    3417                 :            :         uint32_t rc = 0;
    3418                 :            : 
    3419         [ #  # ]:          0 :         if (!BNXT_HAS_RING_GRPS(bp))
    3420                 :            :                 return 0;
    3421                 :            : 
    3422         [ #  # ]:          0 :         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
    3423                 :          0 :                 rc = bnxt_hwrm_ring_grp_alloc(bp, i);
    3424         [ #  # ]:          0 :                 if (rc)
    3425                 :          0 :                         return rc;
    3426                 :            :         }
    3427                 :            :         return rc;
    3428                 :            : }
    3429                 :            : 
    3430                 :            : /*
    3431                 :            :  * HWRM utility functions
    3432                 :            :  */
    3433                 :            : 
    3434                 :          0 : void bnxt_free_hwrm_resources(struct bnxt *bp)
    3435                 :            : {
    3436                 :            :         /* Release memzone */
    3437                 :          0 :         rte_free(bp->hwrm_cmd_resp_addr);
    3438                 :          0 :         rte_free(bp->hwrm_short_cmd_req_addr);
    3439                 :          0 :         bp->hwrm_cmd_resp_addr = NULL;
    3440                 :          0 :         bp->hwrm_short_cmd_req_addr = NULL;
    3441                 :          0 :         bp->hwrm_cmd_resp_dma_addr = 0;
    3442                 :          0 :         bp->hwrm_short_cmd_req_dma_addr = 0;
    3443                 :          0 : }
    3444                 :            : 
    3445                 :          0 : int bnxt_alloc_hwrm_resources(struct bnxt *bp)
    3446                 :            : {
    3447                 :          0 :         struct rte_pci_device *pdev = bp->pdev;
    3448                 :            :         char type[RTE_MEMZONE_NAMESIZE];
    3449                 :            : 
    3450                 :          0 :         sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
    3451                 :          0 :                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
    3452                 :          0 :         bp->max_resp_len = BNXT_PAGE_SIZE;
    3453                 :          0 :         bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
    3454         [ #  # ]:          0 :         if (bp->hwrm_cmd_resp_addr == NULL)
    3455                 :            :                 return -ENOMEM;
    3456                 :          0 :         bp->hwrm_cmd_resp_dma_addr =
    3457                 :          0 :                 rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
    3458         [ #  # ]:          0 :         if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
    3459                 :          0 :                 PMD_DRV_LOG(ERR,
    3460                 :            :                         "unable to map response address to physical memory\n");
    3461                 :          0 :                 return -ENOMEM;
    3462                 :            :         }
    3463                 :            :         rte_spinlock_init(&bp->hwrm_lock);
    3464                 :            : 
    3465                 :          0 :         return 0;
    3466                 :            : }
    3467                 :            : 
    3468                 :            : int
    3469                 :          0 : bnxt_clear_one_vnic_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
    3470                 :            : {
    3471                 :            :         int rc = 0;
    3472                 :            : 
    3473         [ #  # ]:          0 :         if (filter->filter_type == HWRM_CFA_EM_FILTER) {
    3474                 :          0 :                 rc = bnxt_hwrm_clear_em_filter(bp, filter);
    3475         [ #  # ]:          0 :                 if (rc)
    3476                 :            :                         return rc;
    3477         [ #  # ]:          0 :         } else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER) {
    3478                 :          0 :                 rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
    3479         [ #  # ]:          0 :                 if (rc)
    3480                 :            :                         return rc;
    3481                 :            :         }
    3482                 :            : 
    3483                 :          0 :         rc = bnxt_hwrm_clear_l2_filter(bp, filter);
    3484                 :          0 :         return rc;
    3485                 :            : }
    3486                 :            : 
    3487                 :            : static int
    3488                 :          0 : bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    3489                 :            : {
    3490                 :            :         struct bnxt_filter_info *filter;
    3491                 :            :         int rc = 0;
    3492                 :            : 
    3493         [ #  # ]:          0 :         STAILQ_FOREACH(filter, &vnic->filter, next) {
    3494                 :          0 :                 rc = bnxt_clear_one_vnic_filter(bp, filter);
    3495   [ #  #  #  #  :          0 :                 STAILQ_REMOVE(&vnic->filter, filter, bnxt_filter_info, next);
             #  #  #  # ]
    3496                 :          0 :                 bnxt_free_filter(bp, filter);
    3497                 :            :         }
    3498                 :          0 :         return rc;
    3499                 :            : }
    3500                 :            : 
    3501                 :            : static int
    3502                 :          0 : bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    3503                 :            : {
    3504                 :            :         struct bnxt_filter_info *filter;
    3505                 :            :         struct rte_flow *flow;
    3506                 :            :         int rc = 0;
    3507                 :            : 
    3508         [ #  # ]:          0 :         while (!STAILQ_EMPTY(&vnic->flow_list)) {
    3509                 :            :                 flow = STAILQ_FIRST(&vnic->flow_list);
    3510                 :          0 :                 filter = flow->filter;
    3511                 :          0 :                 PMD_DRV_LOG(DEBUG, "filter type %d\n", filter->filter_type);
    3512                 :          0 :                 rc = bnxt_clear_one_vnic_filter(bp, filter);
    3513                 :            : 
    3514   [ #  #  #  #  :          0 :                 STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
             #  #  #  # ]
    3515                 :          0 :                 rte_free(flow);
    3516                 :            :         }
    3517                 :          0 :         return rc;
    3518                 :            : }
    3519                 :            : 
    3520                 :          0 : int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    3521                 :            : {
    3522                 :            :         struct bnxt_filter_info *filter;
    3523                 :            :         int rc = 0;
    3524                 :            : 
    3525         [ #  # ]:          0 :         STAILQ_FOREACH(filter, &vnic->filter, next) {
    3526         [ #  # ]:          0 :                 if (filter->filter_type == HWRM_CFA_EM_FILTER)
    3527                 :          0 :                         rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
    3528                 :            :                                                      filter);
    3529         [ #  # ]:          0 :                 else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
    3530                 :          0 :                         rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
    3531                 :            :                                                          filter);
    3532                 :            :                 else
    3533                 :          0 :                         rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
    3534                 :            :                                                      filter);
    3535         [ #  # ]:          0 :                 if (rc)
    3536                 :            :                         break;
    3537                 :            :         }
    3538                 :          0 :         return rc;
    3539                 :            : }
    3540                 :            : 
    3541                 :            : static void
    3542                 :          0 : bnxt_free_tunnel_ports(struct bnxt *bp)
    3543                 :            : {
    3544         [ #  # ]:          0 :         if (bp->vxlan_port_cnt)
    3545                 :          0 :                 bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
    3546                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
    3547                 :            : 
    3548         [ #  # ]:          0 :         if (bp->geneve_port_cnt)
    3549                 :          0 :                 bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
    3550                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
    3551                 :            : 
    3552         [ #  # ]:          0 :         if (bp->ecpri_port_cnt)
    3553                 :          0 :                 bnxt_hwrm_tunnel_dst_port_free(bp, bp->ecpri_fw_dst_port_id,
    3554                 :            :                         HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI);
    3555                 :          0 : }
    3556                 :            : 
    3557                 :          0 : void bnxt_free_all_hwrm_resources(struct bnxt *bp)
    3558                 :            : {
    3559                 :            :         int i;
    3560                 :            : 
    3561         [ #  # ]:          0 :         if (bp->vnic_info == NULL)
    3562                 :            :                 return;
    3563                 :            : 
    3564                 :            :         /*
    3565                 :            :          * Cleanup VNICs in reverse order, to make sure the L2 filter
    3566                 :            :          * from vnic0 is last to be cleaned up.
    3567                 :            :          */
    3568         [ #  # ]:          0 :         for (i = bp->max_vnics - 1; i >= 0; i--) {
    3569                 :          0 :                 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
    3570                 :            : 
    3571         [ #  # ]:          0 :                 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
    3572                 :          0 :                         continue;
    3573                 :            : 
    3574   [ #  #  #  # ]:          0 :                 if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
    3575                 :          0 :                         bnxt_hwrm_cfa_l2_clear_rx_mask(bp, vnic);
    3576                 :          0 :                 bnxt_clear_hwrm_vnic_flows(bp, vnic);
    3577                 :            : 
    3578                 :          0 :                 bnxt_clear_hwrm_vnic_filters(bp, vnic);
    3579                 :            : 
    3580                 :          0 :                 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
    3581                 :            : 
    3582                 :          0 :                 bnxt_hwrm_vnic_free(bp, vnic);
    3583                 :            : 
    3584                 :          0 :                 bnxt_hwrm_vnic_ctx_free(bp, vnic);
    3585                 :            : 
    3586                 :          0 :                 rte_free(vnic->fw_grp_ids);
    3587                 :          0 :                 vnic->fw_grp_ids = NULL;
    3588   [ #  #  #  # ]:          0 :                 if (vnic->ref_cnt && !vnic->rx_queue_cnt)
    3589                 :          0 :                         vnic->ref_cnt--;
    3590                 :            :         }
    3591                 :            :         /* Ring resources */
    3592                 :          0 :         bnxt_free_all_hwrm_rings(bp);
    3593                 :          0 :         bnxt_free_all_hwrm_ring_grps(bp);
    3594                 :          0 :         bnxt_free_all_hwrm_stat_ctxs(bp);
    3595                 :          0 :         bnxt_free_tunnel_ports(bp);
    3596                 :            : }
    3597                 :            : 
    3598                 :            : static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
    3599                 :            : {
    3600                 :            :         uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
    3601                 :            : 
    3602                 :          0 :         if ((conf_link_speed & RTE_ETH_LINK_SPEED_FIXED) == RTE_ETH_LINK_SPEED_AUTONEG)
    3603                 :            :                 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
    3604                 :            : 
    3605   [ #  #  #  # ]:          0 :         switch (conf_link_speed) {
    3606                 :            :         case RTE_ETH_LINK_SPEED_10M_HD:
    3607                 :            :         case RTE_ETH_LINK_SPEED_100M_HD:
    3608                 :            :                 /* FALLTHROUGH */
    3609                 :            :                 return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
    3610                 :            :         }
    3611                 :          0 :         return hw_link_duplex;
    3612                 :            : }
    3613                 :            : 
    3614                 :            : static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
    3615                 :            : {
    3616                 :          0 :         return !conf_link;
    3617                 :            : }
    3618                 :            : 
    3619                 :            : static uint16_t bnxt_parse_eth_link_speed_v2(uint32_t conf_link_speed)
    3620                 :            : {
    3621                 :            :         /* get bitmap value based on speed */
    3622                 :            :         return ((struct link_speeds2_tbl *)
    3623                 :          0 :                 bnxt_get_rte_hwrm_speeds2_entry(conf_link_speed))->force_val;
    3624                 :            : }
    3625                 :            : 
    3626                 :          0 : static uint16_t bnxt_parse_eth_link_speed(struct bnxt *bp, uint32_t conf_link_speed,
    3627                 :            :                                           struct bnxt_link_info *link_info)
    3628                 :            : {
    3629                 :          0 :         uint16_t support_pam4_speeds = link_info->support_pam4_speeds;
    3630                 :          0 :         uint16_t support_speeds = link_info->support_speeds;
    3631                 :            :         uint16_t eth_link_speed = 0;
    3632                 :            : 
    3633         [ #  # ]:          0 :         if (conf_link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
    3634                 :            :                 return RTE_ETH_LINK_SPEED_AUTONEG;
    3635                 :            : 
    3636                 :            :         /* Handle P7 chips saperately. It got enhanced phy attribs to choose from */
    3637   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    3638                 :          0 :                 return bnxt_parse_eth_link_speed_v2(conf_link_speed);
    3639                 :            : 
    3640   [ #  #  #  #  :          0 :         switch (conf_link_speed & ~RTE_ETH_LINK_SPEED_FIXED) {
          #  #  #  #  #  
                   #  # ]
    3641                 :            :         case RTE_ETH_LINK_SPEED_100M:
    3642                 :            :         case RTE_ETH_LINK_SPEED_100M_HD:
    3643                 :            :                 /* FALLTHROUGH */
    3644                 :            :                 eth_link_speed =
    3645                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
    3646                 :            :                 break;
    3647                 :          0 :         case RTE_ETH_LINK_SPEED_1G:
    3648                 :            :                 eth_link_speed =
    3649                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
    3650                 :          0 :                 break;
    3651                 :          0 :         case RTE_ETH_LINK_SPEED_2_5G:
    3652                 :            :                 eth_link_speed =
    3653                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
    3654                 :          0 :                 break;
    3655                 :          0 :         case RTE_ETH_LINK_SPEED_10G:
    3656                 :            :                 eth_link_speed =
    3657                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
    3658                 :          0 :                 break;
    3659                 :          0 :         case RTE_ETH_LINK_SPEED_20G:
    3660                 :            :                 eth_link_speed =
    3661                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
    3662                 :          0 :                 break;
    3663                 :          0 :         case RTE_ETH_LINK_SPEED_25G:
    3664                 :            :                 eth_link_speed =
    3665                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
    3666                 :          0 :                 link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
    3667                 :          0 :                 break;
    3668                 :          0 :         case RTE_ETH_LINK_SPEED_40G:
    3669                 :            :                 eth_link_speed =
    3670                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
    3671                 :          0 :                 break;
    3672                 :          0 :         case RTE_ETH_LINK_SPEED_50G:
    3673         [ #  # ]:          0 :                 if (support_speeds & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB) {
    3674                 :            :                         eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
    3675                 :          0 :                         link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
    3676         [ #  # ]:          0 :                 } else if (support_pam4_speeds &
    3677                 :            :                            HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_50G) {
    3678                 :            :                         eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_50GB;
    3679                 :          0 :                         link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
    3680                 :            :                 }
    3681                 :            :                 break;
    3682                 :          0 :         case RTE_ETH_LINK_SPEED_100G:
    3683         [ #  # ]:          0 :                 if (support_speeds & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB) {
    3684                 :            :                         eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
    3685                 :          0 :                         link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
    3686         [ #  # ]:          0 :                 } else if (support_pam4_speeds &
    3687                 :            :                            HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_100G) {
    3688                 :            :                         eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_100GB;
    3689                 :          0 :                         link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
    3690                 :            :                 }
    3691                 :            :                 break;
    3692                 :          0 :         case RTE_ETH_LINK_SPEED_200G:
    3693                 :            :                 eth_link_speed =
    3694                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB;
    3695                 :          0 :                 link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
    3696                 :          0 :                 break;
    3697                 :          0 :         default:
    3698                 :          0 :                 PMD_DRV_LOG(ERR,
    3699                 :            :                         "Unsupported link speed %d; default to AUTO\n",
    3700                 :            :                         conf_link_speed);
    3701                 :          0 :                 break;
    3702                 :            :         }
    3703                 :            :         return eth_link_speed;
    3704                 :            : }
    3705                 :            : 
    3706                 :            : #define BNXT_SUPPORTED_SPEEDS (RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_100M_HD | \
    3707                 :            :                 RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G | \
    3708                 :            :                 RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_20G | RTE_ETH_LINK_SPEED_25G | \
    3709                 :            :                 RTE_ETH_LINK_SPEED_40G | RTE_ETH_LINK_SPEED_50G | \
    3710                 :            :                 RTE_ETH_LINK_SPEED_100G | RTE_ETH_LINK_SPEED_200G)
    3711                 :            : #define BNXT_SUPPORTED_SPEEDS2 ((BNXT_SUPPORTED_SPEEDS | RTE_ETH_LINK_SPEED_400G) & \
    3712                 :            :                 ~(RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_100M_HD | \
    3713                 :            :                   RTE_ETH_LINK_SPEED_2_5G | RTE_ETH_LINK_SPEED_20G))
    3714                 :            : 
    3715                 :          0 : static int bnxt_validate_link_speed(struct bnxt *bp)
    3716                 :            : {
    3717                 :          0 :         uint32_t link_speed = bp->eth_dev->data->dev_conf.link_speeds;
    3718                 :          0 :         uint16_t port_id = bp->eth_dev->data->port_id;
    3719                 :            :         uint32_t link_speed_capa;
    3720                 :            :         uint32_t one_speed;
    3721                 :            : 
    3722         [ #  # ]:          0 :         if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
    3723                 :            :                 return 0;
    3724                 :            : 
    3725                 :          0 :         link_speed_capa = bnxt_get_speed_capabilities(bp);
    3726                 :            : 
    3727         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_FIXED) {
    3728                 :          0 :                 one_speed = link_speed & ~RTE_ETH_LINK_SPEED_FIXED;
    3729                 :            : 
    3730         [ #  # ]:          0 :                 if (one_speed & (one_speed - 1)) {
    3731                 :          0 :                         PMD_DRV_LOG(ERR,
    3732                 :            :                                 "Invalid advertised speeds (%u) for port %u\n",
    3733                 :            :                                 link_speed, port_id);
    3734                 :          0 :                         return -EINVAL;
    3735                 :            :                 }
    3736         [ #  # ]:          0 :                 if ((one_speed & link_speed_capa) != one_speed) {
    3737                 :          0 :                         PMD_DRV_LOG(ERR,
    3738                 :            :                                 "Unsupported advertised speed (%u) for port %u\n",
    3739                 :            :                                 link_speed, port_id);
    3740                 :          0 :                         return -EINVAL;
    3741                 :            :                 }
    3742                 :            :         } else {
    3743         [ #  # ]:          0 :                 if (!(link_speed & link_speed_capa)) {
    3744                 :          0 :                         PMD_DRV_LOG(ERR,
    3745                 :            :                                 "Unsupported advertised speeds (%u) for port %u\n",
    3746                 :            :                                 link_speed, port_id);
    3747                 :          0 :                         return -EINVAL;
    3748                 :            :                 }
    3749                 :            :         }
    3750                 :            :         return 0;
    3751                 :            : }
    3752                 :            : 
    3753                 :            : static uint16_t
    3754                 :            : bnxt_parse_eth_link_speed_mask_v2(struct bnxt *bp, uint32_t link_speed)
    3755                 :            : {
    3756                 :            :         uint16_t ret = 0;
    3757                 :            : 
    3758         [ #  # ]:          0 :         if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
    3759                 :          0 :                 return bp->link_info->supported_speeds2_auto_mode;
    3760                 :            : 
    3761                 :            :         return ret;
    3762                 :            : }
    3763                 :            : 
    3764                 :            : static uint16_t
    3765                 :          0 : bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
    3766                 :            : {
    3767                 :            :         uint16_t ret = 0;
    3768                 :            : 
    3769   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    3770                 :          0 :                 return bnxt_parse_eth_link_speed_mask_v2(bp, link_speed);
    3771                 :            : 
    3772         [ #  # ]:          0 :         if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG) {
    3773         [ #  # ]:          0 :                 if (bp->link_info->support_speeds)
    3774                 :            :                         return bp->link_info->support_speeds;
    3775                 :            :                 link_speed = BNXT_SUPPORTED_SPEEDS;
    3776                 :            :         }
    3777                 :            : 
    3778         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_100M)
    3779                 :            :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
    3780         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_100M_HD)
    3781                 :            :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
    3782         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_1G)
    3783                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
    3784         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_2_5G)
    3785                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
    3786         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_10G)
    3787                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
    3788         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_20G)
    3789                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
    3790         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_25G)
    3791                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
    3792         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_40G)
    3793                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
    3794         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_50G)
    3795                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
    3796         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_100G)
    3797                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
    3798         [ #  # ]:          0 :         if (link_speed & RTE_ETH_LINK_SPEED_200G)
    3799                 :          0 :                 ret |= HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB;
    3800                 :            :         return ret;
    3801                 :            : }
    3802                 :            : 
    3803                 :            : static uint32_t bnxt_parse_hw_link_speed_v2(uint16_t hw_link_speed)
    3804                 :            : {
    3805                 :            :         return ((struct link_speeds2_tbl *)
    3806                 :          0 :                 bnxt_get_hwrm_to_rte_speeds2_entry(hw_link_speed))->rte_speed_num;
    3807                 :            : }
    3808                 :            : 
    3809                 :          0 : static uint32_t bnxt_parse_hw_link_speed(struct bnxt *bp, uint16_t hw_link_speed)
    3810                 :            : {
    3811                 :            :         uint32_t eth_link_speed = RTE_ETH_SPEED_NUM_NONE;
    3812                 :            : 
    3813                 :            :         /* query fixed speed2 table if not autoneg */
    3814   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp) && !bp->link_info->auto_mode)
          #  #  #  #  #  
                      # ]
    3815                 :          0 :                 return bnxt_parse_hw_link_speed_v2(hw_link_speed);
    3816                 :            : 
    3817                 :            :         /* for P7 and earlier nics link_speed carries AN'd speed */
    3818   [ #  #  #  #  :          0 :         switch (hw_link_speed) {
          #  #  #  #  #  
                #  #  # ]
    3819                 :            :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
    3820                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_100M;
    3821                 :            :                 break;
    3822                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
    3823                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_1G;
    3824                 :          0 :                 break;
    3825                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
    3826                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_2_5G;
    3827                 :          0 :                 break;
    3828                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
    3829                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_10G;
    3830                 :          0 :                 break;
    3831                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
    3832                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_20G;
    3833                 :          0 :                 break;
    3834                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
    3835                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_25G;
    3836                 :          0 :                 break;
    3837                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
    3838                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_40G;
    3839                 :          0 :                 break;
    3840                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
    3841                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_50G;
    3842                 :          0 :                 break;
    3843                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
    3844                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_100G;
    3845                 :          0 :                 break;
    3846                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_200GB:
    3847                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_200G;
    3848                 :          0 :                 break;
    3849                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_400GB:
    3850                 :            :                 eth_link_speed = RTE_ETH_SPEED_NUM_400G;
    3851                 :          0 :                 break;
    3852                 :          0 :         case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
    3853                 :            :         default:
    3854                 :          0 :                 PMD_DRV_LOG(ERR, "HWRM link speed %d not defined\n",
    3855                 :            :                         hw_link_speed);
    3856                 :          0 :                 break;
    3857                 :            :         }
    3858                 :            :         return eth_link_speed;
    3859                 :            : }
    3860                 :            : 
    3861                 :          0 : static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
    3862                 :            : {
    3863                 :            :         uint16_t eth_link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    3864                 :            : 
    3865      [ #  #  # ]:          0 :         switch (hw_link_duplex) {
    3866                 :            :         case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
    3867                 :            :         case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
    3868                 :            :                 /* FALLTHROUGH */
    3869                 :            :                 eth_link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    3870                 :            :                 break;
    3871                 :          0 :         case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
    3872                 :            :                 eth_link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
    3873                 :          0 :                 break;
    3874                 :          0 :         default:
    3875                 :          0 :                 PMD_DRV_LOG(ERR, "HWRM link duplex %d not defined\n",
    3876                 :            :                         hw_link_duplex);
    3877                 :          0 :                 break;
    3878                 :            :         }
    3879                 :          0 :         return eth_link_duplex;
    3880                 :            : }
    3881                 :            : 
    3882                 :          0 : int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
    3883                 :            : {
    3884                 :            :         int rc = 0;
    3885                 :          0 :         struct bnxt_link_info *link_info = bp->link_info;
    3886                 :            : 
    3887                 :          0 :         rc = bnxt_hwrm_port_phy_qcaps(bp);
    3888         [ #  # ]:          0 :         if (rc)
    3889                 :          0 :                 PMD_DRV_LOG(ERR, "Get link config failed with rc %d\n", rc);
    3890                 :            : 
    3891                 :          0 :         rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
    3892         [ #  # ]:          0 :         if (rc) {
    3893                 :          0 :                 PMD_DRV_LOG(ERR, "Get link config failed with rc %d\n", rc);
    3894                 :          0 :                 goto exit;
    3895                 :            :         }
    3896                 :            : 
    3897         [ #  # ]:          0 :         if (link_info->link_speed)
    3898                 :          0 :                 link->link_speed = bnxt_parse_hw_link_speed(bp, link_info->link_speed);
    3899                 :            :         else
    3900                 :          0 :                 link->link_speed = RTE_ETH_SPEED_NUM_NONE;
    3901                 :          0 :         link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
    3902                 :          0 :         link->link_status = link_info->link_up;
    3903                 :          0 :         link->link_autoneg = link_info->auto_mode ==
    3904                 :            :                 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
    3905                 :          0 :                 RTE_ETH_LINK_FIXED : RTE_ETH_LINK_AUTONEG;
    3906                 :          0 : exit:
    3907                 :          0 :         return rc;
    3908                 :            : }
    3909                 :            : 
    3910                 :          0 : static int bnxt_hwrm_port_phy_cfg_v2(struct bnxt *bp, struct bnxt_link_info *conf)
    3911                 :            : {
    3912                 :          0 :         struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    3913                 :          0 :         struct hwrm_port_phy_cfg_input req = {0};
    3914                 :            :         uint32_t enables = 0;
    3915                 :            :         int rc = 0;
    3916                 :            : 
    3917   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
    3918                 :            : 
    3919         [ #  # ]:          0 :         if (!conf->link_up) {
    3920                 :          0 :                 req.flags =
    3921                 :            :                 rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
    3922                 :          0 :                 PMD_DRV_LOG(ERR, "Force Link Down\n");
    3923                 :          0 :                 goto link_down;
    3924                 :            :         }
    3925                 :            : 
    3926                 :            :         /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
    3927   [ #  #  #  # ]:          0 :         if (bp->link_info->auto_mode && conf->link_speed) {
    3928                 :          0 :                 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
    3929                 :          0 :                 PMD_DRV_LOG(DEBUG, "Disabling AutoNeg\n");
    3930                 :            :         }
    3931                 :          0 :         req.flags = rte_cpu_to_le_32(conf->phy_flags);
    3932         [ #  # ]:          0 :         if (!conf->link_speed) {
    3933                 :            :                 /* No speeds specified. Enable AutoNeg - all speeds */
    3934                 :            :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEEDS2_MASK;
    3935                 :            :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
    3936                 :          0 :                 req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
    3937                 :          0 :                 req.auto_link_speeds2_mask =
    3938                 :          0 :                         rte_cpu_to_le_16(bp->link_info->supported_speeds2_auto_mode);
    3939                 :            :         } else {
    3940                 :            :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_LINK_SPEEDS2;
    3941                 :          0 :                 req.force_link_speeds2 = rte_cpu_to_le_16(conf->link_speed);
    3942                 :            :         }
    3943                 :            : 
    3944                 :            :         /* Fill rest of the req message */
    3945                 :          0 :         req.auto_duplex = conf->duplex;
    3946         [ #  # ]:          0 :         if (req.auto_mode != HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK)
    3947                 :          0 :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
    3948                 :          0 :         req.auto_pause = conf->auto_pause;
    3949                 :          0 :         req.force_pause = conf->force_pause;
    3950         [ #  # ]:          0 :         if (req.auto_pause)
    3951                 :          0 :                 req.force_pause = 0;
    3952                 :            :         /* Set force_pause if there is no auto or if there is a force */
    3953   [ #  #  #  # ]:          0 :         if (req.auto_pause && !req.force_pause)
    3954                 :          0 :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
    3955                 :            :         else
    3956                 :          0 :                 enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
    3957                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    3958                 :            : 
    3959                 :          0 : link_down:
    3960                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    3961                 :            : 
    3962   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    3963                 :            :         HWRM_UNLOCK();
    3964                 :          0 :         return rc;
    3965                 :            : }
    3966                 :            : 
    3967                 :          0 : static int bnxt_set_hwrm_link_config_v2(struct bnxt *bp, bool link_up)
    3968                 :            : {
    3969         [ #  # ]:          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
    3970                 :            :         struct bnxt_link_info link_req;
    3971                 :            :         uint16_t speed, autoneg;
    3972                 :            :         int rc = 0;
    3973                 :            : 
    3974                 :            :         memset(&link_req, 0, sizeof(link_req));
    3975                 :          0 :         link_req.link_up = link_up;
    3976         [ #  # ]:          0 :         if (!link_up)
    3977                 :          0 :                 goto port_phy_cfg;
    3978                 :            : 
    3979                 :          0 :         autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
    3980                 :          0 :         speed = bnxt_parse_eth_link_speed(bp, dev_conf->link_speeds,
    3981                 :            :                                           bp->link_info);
    3982                 :          0 :         link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
    3983         [ #  # ]:          0 :         if (autoneg == 1) {
    3984                 :          0 :                 link_req.phy_flags |=
    3985                 :            :                         HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
    3986                 :          0 :                 link_req.cfg_auto_link_speeds2_mask =
    3987                 :          0 :                         bnxt_parse_eth_link_speed_mask(bp, dev_conf->link_speeds);
    3988                 :            :         } else {
    3989                 :          0 :                 if (bp->link_info->phy_type ==
    3990         [ #  # ]:          0 :                     HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
    3991                 :            :                     bp->link_info->phy_type ==
    3992                 :          0 :                     HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
    3993         [ #  # ]:          0 :                     bp->link_info->media_type ==
    3994                 :            :                     HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
    3995                 :          0 :                         PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
    3996                 :          0 :                         return -EINVAL;
    3997                 :            :                 }
    3998                 :            : 
    3999                 :          0 :                 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
    4000                 :            :                 /* If user wants a particular speed try that first. */
    4001                 :          0 :                 link_req.link_speed = speed;
    4002                 :            :         }
    4003         [ #  # ]:          0 :         link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
    4004                 :          0 :         link_req.auto_pause = bp->link_info->auto_pause;
    4005                 :          0 :         link_req.force_pause = bp->link_info->force_pause;
    4006                 :            : 
    4007                 :          0 : port_phy_cfg:
    4008                 :          0 :         rc = bnxt_hwrm_port_phy_cfg_v2(bp, &link_req);
    4009         [ #  # ]:          0 :         if (rc)
    4010                 :          0 :                 PMD_DRV_LOG(ERR, "Set link config failed with rc %d\n", rc);
    4011                 :            : 
    4012                 :            :         return rc;
    4013                 :            : }
    4014                 :            : 
    4015                 :          0 : int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
    4016                 :            : {
    4017                 :            :         int rc = 0;
    4018                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
    4019                 :            :         struct bnxt_link_info link_req;
    4020                 :            :         uint16_t speed, autoneg;
    4021                 :            : 
    4022         [ #  # ]:          0 :         if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
    4023                 :            :                 return 0;
    4024                 :            : 
    4025                 :          0 :         rc = bnxt_validate_link_speed(bp);
    4026         [ #  # ]:          0 :         if (rc)
    4027                 :          0 :                 goto error;
    4028                 :            : 
    4029   [ #  #  #  #  :          0 :         if (BNXT_LINK_SPEEDS_V2(bp))
             #  #  #  # ]
    4030                 :          0 :                 return bnxt_set_hwrm_link_config_v2(bp, link_up);
    4031                 :            : 
    4032                 :            :         memset(&link_req, 0, sizeof(link_req));
    4033                 :          0 :         link_req.link_up = link_up;
    4034         [ #  # ]:          0 :         if (!link_up)
    4035                 :          0 :                 goto port_phy_cfg;
    4036                 :            : 
    4037                 :            :         /* Get user requested autoneg setting */
    4038                 :          0 :         autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
    4039         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp) &&
    4040         [ #  # ]:          0 :             dev_conf->link_speeds & RTE_ETH_LINK_SPEED_40G) {
    4041                 :            :                 /* 40G is not supported as part of media auto detect.
    4042                 :            :                  * The speed should be forced and autoneg disabled
    4043                 :            :                  * to configure 40G speed.
    4044                 :            :                  */
    4045                 :          0 :                 PMD_DRV_LOG(INFO, "Disabling autoneg for 40G\n");
    4046                 :            :                 autoneg = 0;
    4047                 :            :         }
    4048                 :            : 
    4049                 :            :         /* Override based on current Autoneg setting in PHY for 200G */
    4050   [ #  #  #  #  :          0 :         if (autoneg == 1 && BNXT_CHIP_P5(bp) && bp->link_info->auto_mode == 0 &&
                   #  # ]
    4051         [ #  # ]:          0 :             bp->link_info->force_pam4_link_speed ==
    4052                 :            :             HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB) {
    4053                 :            :                 autoneg = 0;
    4054                 :          0 :                 PMD_DRV_LOG(DEBUG, "Disabling autoneg for 200G\n");
    4055                 :            :         }
    4056                 :            : 
    4057                 :          0 :         speed = bnxt_parse_eth_link_speed(bp, dev_conf->link_speeds,
    4058                 :            :                                           bp->link_info);
    4059                 :          0 :         link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
    4060                 :            :         /* Autoneg can be done only when the FW allows. */
    4061         [ #  # ]:          0 :         if (autoneg == 1 &&
    4062   [ #  #  #  # ]:          0 :             (bp->link_info->support_auto_speeds || bp->link_info->support_pam4_auto_speeds)) {
    4063                 :          0 :                 link_req.phy_flags |=
    4064                 :            :                                 HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
    4065                 :          0 :                 link_req.auto_link_speed_mask =
    4066                 :          0 :                         bnxt_parse_eth_link_speed_mask(bp,
    4067                 :            :                                                        dev_conf->link_speeds);
    4068                 :          0 :                 link_req.auto_pam4_link_speed_mask =
    4069                 :          0 :                         bp->link_info->auto_pam4_link_speed_mask;
    4070                 :            :         } else {
    4071                 :          0 :                 if (bp->link_info->phy_type ==
    4072         [ #  # ]:          0 :                     HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
    4073                 :            :                     bp->link_info->phy_type ==
    4074                 :          0 :                     HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
    4075         [ #  # ]:          0 :                     bp->link_info->media_type ==
    4076                 :            :                     HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
    4077                 :          0 :                         PMD_DRV_LOG(ERR, "10GBase-T devices must autoneg\n");
    4078                 :          0 :                         return -EINVAL;
    4079                 :            :                 }
    4080                 :            : 
    4081                 :          0 :                 link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
    4082                 :            :                 /* If user wants a particular speed try that first. */
    4083         [ #  # ]:          0 :                 if (speed)
    4084                 :          0 :                         link_req.link_speed = speed;
    4085         [ #  # ]:          0 :                 else if (bp->link_info->force_pam4_link_speed)
    4086                 :          0 :                         link_req.link_speed =
    4087                 :            :                                 bp->link_info->force_pam4_link_speed;
    4088         [ #  # ]:          0 :                 else if (bp->link_info->force_link_speed)
    4089                 :          0 :                         link_req.link_speed = bp->link_info->force_link_speed;
    4090         [ #  # ]:          0 :                 else if (bp->link_info->auto_pam4_link_speed_mask)
    4091                 :          0 :                         link_req.link_speed =
    4092                 :            :                                 bp->link_info->auto_pam4_link_speed_mask;
    4093         [ #  # ]:          0 :                 else if (bp->link_info->support_pam4_speeds)
    4094                 :          0 :                         link_req.link_speed =
    4095                 :            :                                 bp->link_info->support_pam4_speeds;
    4096                 :            :                 else
    4097                 :          0 :                         link_req.link_speed = bp->link_info->auto_link_speed;
    4098                 :            :                 /* Auto PAM4 link speed is zero, but auto_link_speed is not
    4099                 :            :                  * zero. Use the auto_link_speed.
    4100                 :            :                  */
    4101         [ #  # ]:          0 :                 if (bp->link_info->auto_link_speed != 0 &&
    4102         [ #  # ]:          0 :                     bp->link_info->auto_pam4_link_speed_mask == 0)
    4103                 :          0 :                         link_req.link_speed = bp->link_info->auto_link_speed;
    4104                 :            :         }
    4105         [ #  # ]:          0 :         link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
    4106                 :          0 :         link_req.auto_pause = bp->link_info->auto_pause;
    4107                 :          0 :         link_req.force_pause = bp->link_info->force_pause;
    4108                 :            : 
    4109                 :          0 : port_phy_cfg:
    4110                 :          0 :         rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
    4111         [ #  # ]:          0 :         if (rc) {
    4112                 :          0 :                 PMD_DRV_LOG(ERR,
    4113                 :            :                         "Set link config failed with rc %d\n", rc);
    4114                 :            :         }
    4115                 :            : 
    4116                 :          0 : error:
    4117                 :            :         return rc;
    4118                 :            : }
    4119                 :            : 
    4120                 :          0 : int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
    4121                 :            : {
    4122                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4123                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4124                 :            :         uint16_t flags;
    4125                 :            :         int rc = 0;
    4126                 :          0 :         bp->func_svif = BNXT_SVIF_INVALID;
    4127                 :            :         uint16_t svif_info;
    4128                 :            : 
    4129         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4130                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    4131                 :            : 
    4132                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4133                 :            : 
    4134   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4135                 :            : 
    4136                 :          0 :         bp->vlan = rte_le_to_cpu_16(resp->vlan) & RTE_ETH_VLAN_ID_MAX;
    4137                 :            : 
    4138                 :          0 :         svif_info = rte_le_to_cpu_16(resp->svif_info);
    4139         [ #  # ]:          0 :         if (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)
    4140                 :          0 :                 bp->func_svif =      svif_info &
    4141                 :            :                                      HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
    4142                 :            : 
    4143                 :          0 :         flags = rte_le_to_cpu_16(resp->flags);
    4144   [ #  #  #  # ]:          0 :         if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
    4145                 :          0 :                 bp->flags |= BNXT_FLAG_MULTI_HOST;
    4146                 :            : 
    4147         [ #  # ]:          0 :         if (BNXT_VF(bp) &&
    4148         [ #  # ]:          0 :             !BNXT_VF_IS_TRUSTED(bp) &&
    4149                 :            :             (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
    4150                 :          0 :                 bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
    4151                 :          0 :                 PMD_DRV_LOG(INFO, "Trusted VF cap enabled\n");
    4152         [ #  # ]:          0 :         } else if (BNXT_VF(bp) &&
    4153         [ #  # ]:          0 :                    BNXT_VF_IS_TRUSTED(bp) &&
    4154                 :            :                    !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
    4155                 :          0 :                 bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
    4156                 :          0 :                 PMD_DRV_LOG(INFO, "Trusted VF cap disabled\n");
    4157                 :            :         }
    4158                 :            : 
    4159         [ #  # ]:          0 :         if (mtu)
    4160                 :          0 :                 *mtu = rte_le_to_cpu_16(resp->admin_mtu);
    4161                 :            : 
    4162         [ #  # ]:          0 :         switch (resp->port_partition_type) {
    4163                 :          0 :         case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
    4164                 :            :         case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
    4165                 :            :         case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
    4166                 :            :                 /* FALLTHROUGH */
    4167                 :          0 :                 bp->flags |= BNXT_FLAG_NPAR_PF;
    4168                 :          0 :                 break;
    4169                 :          0 :         default:
    4170                 :          0 :                 bp->flags &= ~BNXT_FLAG_NPAR_PF;
    4171                 :          0 :                 break;
    4172                 :            :         }
    4173                 :            : 
    4174                 :          0 :         bp->legacy_db_size =
    4175                 :          0 :                 rte_le_to_cpu_16(resp->legacy_l2_db_size_kb) * 1024;
    4176                 :            : 
    4177                 :            :         HWRM_UNLOCK();
    4178                 :            : 
    4179                 :          0 :         return rc;
    4180                 :            : }
    4181                 :            : 
    4182                 :          0 : int bnxt_hwrm_parent_pf_qcfg(struct bnxt *bp)
    4183                 :            : {
    4184                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4185                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4186                 :            :         uint16_t flags;
    4187                 :            :         int rc;
    4188                 :            : 
    4189         [ #  # ]:          0 :         if (!BNXT_VF_IS_TRUSTED(bp))
    4190                 :            :                 return 0;
    4191                 :            : 
    4192         [ #  # ]:          0 :         if (!bp->parent)
    4193                 :            :                 return -EINVAL;
    4194                 :            : 
    4195                 :          0 :         bp->parent->fid = BNXT_PF_FID_INVALID;
    4196                 :            : 
    4197         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4198                 :            : 
    4199                 :          0 :         req.fid = rte_cpu_to_le_16(0xfffe); /* Request parent PF information. */
    4200                 :            : 
    4201                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4202                 :            : 
    4203   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    4204                 :            : 
    4205         [ #  # ]:          0 :         memcpy(bp->parent->mac_addr, resp->mac_address, RTE_ETHER_ADDR_LEN);
    4206                 :          0 :         bp->parent->vnic = rte_le_to_cpu_16(resp->dflt_vnic_id);
    4207                 :          0 :         bp->parent->fid = rte_le_to_cpu_16(resp->fid);
    4208                 :          0 :         bp->parent->port_id = rte_le_to_cpu_16(resp->port_id);
    4209                 :            : 
    4210                 :          0 :         flags = rte_le_to_cpu_16(resp->flags);
    4211                 :            : 
    4212                 :            :         /* check for the mulit-host support */
    4213         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST) {
    4214                 :          0 :                 bp->flags |= BNXT_FLAG_MULTI_HOST;
    4215                 :          0 :                 bp->multi_host_pf_pci_id = resp->pci_id;
    4216                 :          0 :                 PMD_DRV_LOG(INFO, "Mult-Host system Parent PCI-ID: 0x%x\n", resp->pci_id);
    4217                 :            :         }
    4218                 :            : 
    4219                 :            :         /* check for the multi-root support */
    4220         [ #  # ]:          0 :         if (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_ROOT) {
    4221                 :          0 :                 bp->flags2 |= BNXT_FLAGS2_MULTIROOT_EN;
    4222                 :          0 :                 PMD_DRV_LOG(DEBUG, "PF enabled with multi root capability\n");
    4223                 :            :         }
    4224                 :            : 
    4225                 :            :         HWRM_UNLOCK();
    4226                 :            : 
    4227                 :          0 :         return 0;
    4228                 :            : }
    4229                 :            : 
    4230                 :          0 : int bnxt_hwrm_get_dflt_vnic_svif(struct bnxt *bp, uint16_t fid,
    4231                 :            :                                  uint16_t *vnic_id, uint16_t *svif)
    4232                 :            : {
    4233                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4234                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4235                 :            :         uint16_t svif_info;
    4236                 :            :         int rc = 0;
    4237                 :            : 
    4238         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4239                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    4240                 :            : 
    4241                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4242                 :            : 
    4243   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4244                 :            : 
    4245         [ #  # ]:          0 :         if (vnic_id)
    4246                 :          0 :                 *vnic_id = rte_le_to_cpu_16(resp->dflt_vnic_id);
    4247                 :            : 
    4248                 :          0 :         svif_info = rte_le_to_cpu_16(resp->svif_info);
    4249         [ #  # ]:          0 :         if (svif && (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID))
    4250                 :          0 :                 *svif = svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
    4251                 :            : 
    4252                 :            :         HWRM_UNLOCK();
    4253                 :            : 
    4254                 :          0 :         return rc;
    4255                 :            : }
    4256                 :            : 
    4257                 :          0 : int bnxt_hwrm_port_mac_qcfg(struct bnxt *bp)
    4258                 :            : {
    4259                 :          0 :         struct hwrm_port_mac_qcfg_input req = {0};
    4260                 :          0 :         struct hwrm_port_mac_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4261                 :            :         uint16_t port_svif_info;
    4262                 :            :         int rc;
    4263                 :            : 
    4264                 :          0 :         bp->port_svif = BNXT_SVIF_INVALID;
    4265                 :            : 
    4266         [ #  # ]:          0 :         if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
    4267                 :            :                 return 0;
    4268                 :            : 
    4269         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_MAC_QCFG, BNXT_USE_CHIMP_MB);
    4270                 :            : 
    4271                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4272                 :            : 
    4273   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    4274                 :            : 
    4275                 :          0 :         port_svif_info = rte_le_to_cpu_16(resp->port_svif_info);
    4276         [ #  # ]:          0 :         if (port_svif_info &
    4277                 :            :             HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_VALID)
    4278                 :          0 :                 bp->port_svif = port_svif_info &
    4279                 :            :                         HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_MASK;
    4280                 :            : 
    4281                 :            :         HWRM_UNLOCK();
    4282                 :            : 
    4283                 :          0 :         return 0;
    4284                 :            : }
    4285                 :            : 
    4286                 :          0 : static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp,
    4287                 :            :                                  struct bnxt_pf_resource_info *pf_resc)
    4288                 :            : {
    4289                 :          0 :         struct hwrm_func_cfg_input req = {0};
    4290                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    4291                 :            :         uint32_t enables;
    4292                 :            :         int rc;
    4293                 :            : 
    4294                 :            :         enables = HWRM_FUNC_CFG_INPUT_ENABLES_ADMIN_MTU |
    4295                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_HOST_MTU |
    4296                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
    4297                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
    4298                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
    4299                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
    4300                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
    4301                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
    4302                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
    4303                 :            :                   HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
    4304                 :            : 
    4305         [ #  # ]:          0 :         if (BNXT_HAS_RING_GRPS(bp)) {
    4306                 :            :                 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
    4307                 :          0 :                 req.num_hw_ring_grps =
    4308                 :          0 :                         rte_cpu_to_le_16(pf_resc->num_hw_ring_grps);
    4309                 :            :         } else if (BNXT_HAS_NQ(bp)) {
    4310                 :            :                 enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
    4311                 :          0 :                 req.num_msix = rte_cpu_to_le_16(pf_resc->num_nq_rings);
    4312                 :            :         }
    4313                 :            : 
    4314                 :          0 :         req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
    4315                 :          0 :         req.admin_mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
    4316                 :          0 :         req.host_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu);
    4317                 :          0 :         req.mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
    4318                 :          0 :         req.num_rsscos_ctxs = rte_cpu_to_le_16(pf_resc->num_rsscos_ctxs);
    4319                 :          0 :         req.num_stat_ctxs = rte_cpu_to_le_16(pf_resc->num_stat_ctxs);
    4320                 :          0 :         req.num_cmpl_rings = rte_cpu_to_le_16(pf_resc->num_cp_rings);
    4321                 :          0 :         req.num_tx_rings = rte_cpu_to_le_16(pf_resc->num_tx_rings);
    4322                 :          0 :         req.num_rx_rings = rte_cpu_to_le_16(pf_resc->num_rx_rings);
    4323                 :          0 :         req.num_l2_ctxs = rte_cpu_to_le_16(pf_resc->num_l2_ctxs);
    4324                 :          0 :         req.num_vnics = rte_cpu_to_le_16(pf_resc->num_vnics);
    4325                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    4326                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    4327                 :            : 
    4328         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    4329                 :            : 
    4330                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4331                 :            : 
    4332   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4333                 :            :         HWRM_UNLOCK();
    4334                 :            : 
    4335                 :          0 :         return rc;
    4336                 :            : }
    4337                 :            : 
    4338                 :            : /* min values are the guaranteed resources and max values are subject
    4339                 :            :  * to availability. The strategy for now is to keep both min & max
    4340                 :            :  * values the same.
    4341                 :            :  */
    4342                 :            : static void
    4343                 :          0 : bnxt_fill_vf_func_cfg_req_new(struct bnxt *bp,
    4344                 :            :                               struct hwrm_func_vf_resource_cfg_input *req,
    4345                 :            :                               int num_vfs)
    4346                 :            : {
    4347                 :          0 :         req->max_rsscos_ctx = rte_cpu_to_le_16(bp->max_rsscos_ctx /
    4348                 :            :                                                (num_vfs + 1));
    4349                 :          0 :         req->min_rsscos_ctx = req->max_rsscos_ctx;
    4350                 :          0 :         req->max_stat_ctx = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
    4351                 :          0 :         req->min_stat_ctx = req->max_stat_ctx;
    4352                 :          0 :         req->max_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
    4353                 :            :                                                (num_vfs + 1));
    4354                 :          0 :         req->min_cmpl_rings = req->max_cmpl_rings;
    4355                 :          0 :         req->max_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
    4356                 :          0 :         req->min_tx_rings = req->max_tx_rings;
    4357                 :          0 :         req->max_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
    4358                 :          0 :         req->min_rx_rings = req->max_rx_rings;
    4359                 :          0 :         req->max_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
    4360                 :          0 :         req->min_l2_ctxs = req->max_l2_ctxs;
    4361                 :          0 :         req->max_vnics = rte_cpu_to_le_16(bp->max_vnics / (num_vfs + 1));
    4362                 :          0 :         req->min_vnics = req->max_vnics;
    4363                 :          0 :         req->max_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
    4364                 :            :                                                  (num_vfs + 1));
    4365                 :          0 :         req->min_hw_ring_grps = req->max_hw_ring_grps;
    4366                 :          0 :         req->max_msix = rte_cpu_to_le_16(bp->max_nq_rings / (num_vfs + 1));
    4367                 :          0 : }
    4368                 :            : 
    4369                 :            : static void
    4370                 :          0 : bnxt_fill_vf_func_cfg_req_old(struct bnxt *bp,
    4371                 :            :                               struct hwrm_func_cfg_input *req,
    4372                 :            :                               int num_vfs)
    4373                 :            : {
    4374                 :          0 :         req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_ADMIN_MTU |
    4375                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
    4376                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
    4377                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
    4378                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
    4379                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
    4380                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
    4381                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
    4382                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
    4383                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
    4384                 :            : 
    4385                 :          0 :         req->admin_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
    4386                 :            :                                           RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN *
    4387                 :            :                                           BNXT_NUM_VLANS);
    4388                 :          0 :         req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
    4389                 :          0 :         req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
    4390                 :            :                                                 (num_vfs + 1));
    4391                 :          0 :         req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
    4392                 :          0 :         req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
    4393                 :            :                                                (num_vfs + 1));
    4394                 :          0 :         req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
    4395                 :          0 :         req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
    4396                 :          0 :         req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
    4397                 :            :         /* TODO: For now, do not support VMDq/RFS on VFs. */
    4398                 :          0 :         req->num_vnics = rte_cpu_to_le_16(1);
    4399                 :          0 :         req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
    4400                 :            :                                                  (num_vfs + 1));
    4401                 :          0 : }
    4402                 :            : 
    4403                 :            : /* Update the port wide resource values based on how many resources
    4404                 :            :  * got allocated to the VF.
    4405                 :            :  */
    4406                 :          0 : static int bnxt_update_max_resources(struct bnxt *bp,
    4407                 :            :                                      int vf)
    4408                 :            : {
    4409                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4410                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4411                 :            :         int rc;
    4412                 :            : 
    4413                 :            :         /* Get the actual allocated values now */
    4414         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4415                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    4416                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4417   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4418                 :            : 
    4419                 :          0 :         bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
    4420                 :          0 :         bp->max_stat_ctx -= rte_le_to_cpu_16(resp->alloc_stat_ctx);
    4421                 :          0 :         bp->max_cp_rings -= rte_le_to_cpu_16(resp->alloc_cmpl_rings);
    4422                 :          0 :         bp->max_tx_rings -= rte_le_to_cpu_16(resp->alloc_tx_rings);
    4423                 :          0 :         bp->max_rx_rings -= rte_le_to_cpu_16(resp->alloc_rx_rings);
    4424                 :          0 :         bp->max_l2_ctx -= rte_le_to_cpu_16(resp->alloc_l2_ctx);
    4425                 :          0 :         bp->max_ring_grps -= rte_le_to_cpu_16(resp->alloc_hw_ring_grps);
    4426                 :          0 :         bp->max_nq_rings -= rte_le_to_cpu_16(resp->alloc_msix);
    4427                 :          0 :         bp->max_vnics -= rte_le_to_cpu_16(resp->alloc_vnics);
    4428                 :            : 
    4429                 :            :         HWRM_UNLOCK();
    4430                 :            : 
    4431                 :          0 :         return 0;
    4432                 :            : }
    4433                 :            : 
    4434                 :            : /* Update the PF resource values based on how many resources
    4435                 :            :  * got allocated to it.
    4436                 :            :  */
    4437                 :          0 : static int bnxt_update_max_resources_pf_only(struct bnxt *bp)
    4438                 :            : {
    4439                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4440                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4441                 :            :         int rc;
    4442                 :            : 
    4443                 :            :         /* Get the actual allocated values now */
    4444         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4445                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    4446                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4447   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4448                 :            : 
    4449                 :          0 :         bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
    4450                 :          0 :         bp->max_stat_ctx = rte_le_to_cpu_16(resp->alloc_stat_ctx);
    4451                 :          0 :         bp->max_cp_rings = rte_le_to_cpu_16(resp->alloc_cmpl_rings);
    4452                 :          0 :         bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
    4453                 :          0 :         bp->max_rx_rings = rte_le_to_cpu_16(resp->alloc_rx_rings);
    4454                 :          0 :         bp->max_l2_ctx = rte_le_to_cpu_16(resp->alloc_l2_ctx);
    4455                 :          0 :         bp->max_ring_grps = rte_le_to_cpu_16(resp->alloc_hw_ring_grps);
    4456                 :          0 :         bp->max_vnics = rte_le_to_cpu_16(resp->alloc_vnics);
    4457                 :            : 
    4458                 :            :         HWRM_UNLOCK();
    4459                 :            : 
    4460                 :          0 :         return 0;
    4461                 :            : }
    4462                 :            : 
    4463                 :          0 : int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
    4464                 :            : {
    4465                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4466                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4467                 :            :         int rc;
    4468                 :            : 
    4469                 :            :         /* Check for zero MAC address */
    4470         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4471                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    4472                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4473   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4474                 :          0 :         rc = rte_le_to_cpu_16(resp->vlan);
    4475                 :            : 
    4476                 :            :         HWRM_UNLOCK();
    4477                 :            : 
    4478                 :          0 :         return rc;
    4479                 :            : }
    4480                 :            : 
    4481                 :          0 : static int bnxt_query_pf_resources(struct bnxt *bp,
    4482                 :            :                                    struct bnxt_pf_resource_info *pf_resc)
    4483                 :            : {
    4484                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    4485                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    4486                 :            :         int rc;
    4487                 :            : 
    4488                 :            :         /* And copy the allocated numbers into the pf struct */
    4489         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    4490                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    4491                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4492   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4493                 :            : 
    4494                 :          0 :         pf_resc->num_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
    4495                 :          0 :         pf_resc->num_rsscos_ctxs = rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
    4496                 :          0 :         pf_resc->num_stat_ctxs = rte_le_to_cpu_16(resp->alloc_stat_ctx);
    4497                 :          0 :         pf_resc->num_cp_rings = rte_le_to_cpu_16(resp->alloc_cmpl_rings);
    4498                 :          0 :         pf_resc->num_rx_rings = rte_le_to_cpu_16(resp->alloc_rx_rings);
    4499                 :          0 :         pf_resc->num_l2_ctxs = rte_le_to_cpu_16(resp->alloc_l2_ctx);
    4500                 :          0 :         pf_resc->num_hw_ring_grps = rte_le_to_cpu_32(resp->alloc_hw_ring_grps);
    4501                 :          0 :         pf_resc->num_nq_rings = rte_le_to_cpu_32(resp->alloc_msix);
    4502                 :          0 :         pf_resc->num_vnics = rte_le_to_cpu_16(resp->alloc_vnics);
    4503                 :          0 :         bp->pf->evb_mode = resp->evb_mode;
    4504                 :            : 
    4505                 :            :         HWRM_UNLOCK();
    4506                 :            : 
    4507                 :          0 :         return rc;
    4508                 :            : }
    4509                 :            : 
    4510                 :            : static void
    4511                 :          0 : bnxt_calculate_pf_resources(struct bnxt *bp,
    4512                 :            :                             struct bnxt_pf_resource_info *pf_resc,
    4513                 :            :                             int num_vfs)
    4514                 :            : {
    4515         [ #  # ]:          0 :         if (!num_vfs) {
    4516                 :          0 :                 pf_resc->num_rsscos_ctxs = bp->max_rsscos_ctx;
    4517                 :          0 :                 pf_resc->num_stat_ctxs = bp->max_stat_ctx;
    4518                 :          0 :                 pf_resc->num_cp_rings = bp->max_cp_rings;
    4519                 :          0 :                 pf_resc->num_tx_rings = bp->max_tx_rings;
    4520                 :          0 :                 pf_resc->num_rx_rings = bp->max_rx_rings;
    4521                 :          0 :                 pf_resc->num_l2_ctxs = bp->max_l2_ctx;
    4522                 :          0 :                 pf_resc->num_hw_ring_grps = bp->max_ring_grps;
    4523                 :          0 :                 pf_resc->num_nq_rings = bp->max_nq_rings;
    4524                 :          0 :                 pf_resc->num_vnics = bp->max_vnics;
    4525                 :            : 
    4526                 :          0 :                 return;
    4527                 :            :         }
    4528                 :            : 
    4529                 :          0 :         pf_resc->num_rsscos_ctxs = bp->max_rsscos_ctx / (num_vfs + 1) +
    4530                 :          0 :                                    bp->max_rsscos_ctx % (num_vfs + 1);
    4531                 :          0 :         pf_resc->num_stat_ctxs = bp->max_stat_ctx / (num_vfs + 1) +
    4532                 :          0 :                                  bp->max_stat_ctx % (num_vfs + 1);
    4533                 :          0 :         pf_resc->num_cp_rings = bp->max_cp_rings / (num_vfs + 1) +
    4534                 :          0 :                                 bp->max_cp_rings % (num_vfs + 1);
    4535                 :          0 :         pf_resc->num_tx_rings = bp->max_tx_rings / (num_vfs + 1) +
    4536                 :          0 :                                 bp->max_tx_rings % (num_vfs + 1);
    4537                 :          0 :         pf_resc->num_rx_rings = bp->max_rx_rings / (num_vfs + 1) +
    4538                 :          0 :                                 bp->max_rx_rings % (num_vfs + 1);
    4539                 :          0 :         pf_resc->num_l2_ctxs = bp->max_l2_ctx / (num_vfs + 1) +
    4540                 :          0 :                                bp->max_l2_ctx % (num_vfs + 1);
    4541                 :          0 :         pf_resc->num_hw_ring_grps = bp->max_ring_grps / (num_vfs + 1) +
    4542                 :          0 :                                     bp->max_ring_grps % (num_vfs + 1);
    4543                 :          0 :         pf_resc->num_nq_rings = bp->max_nq_rings / (num_vfs + 1) +
    4544                 :          0 :                                 bp->max_nq_rings % (num_vfs + 1);
    4545                 :          0 :         pf_resc->num_vnics = bp->max_vnics / (num_vfs + 1) +
    4546                 :          0 :                                 bp->max_vnics % (num_vfs + 1);
    4547                 :            : }
    4548                 :            : 
    4549                 :          0 : int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
    4550                 :            : {
    4551                 :          0 :         struct bnxt_pf_resource_info pf_resc = { 0 };
    4552                 :            :         int rc;
    4553                 :            : 
    4554         [ #  # ]:          0 :         if (!BNXT_PF(bp)) {
    4555                 :          0 :                 PMD_DRV_LOG(ERR, "Attempt to allocate VFs on a VF!\n");
    4556                 :          0 :                 return -EINVAL;
    4557                 :            :         }
    4558                 :            : 
    4559                 :          0 :         rc = bnxt_hwrm_func_qcaps(bp);
    4560         [ #  # ]:          0 :         if (rc)
    4561                 :            :                 return rc;
    4562                 :            : 
    4563                 :            :         bnxt_calculate_pf_resources(bp, &pf_resc, 0);
    4564                 :            : 
    4565                 :          0 :         bp->pf->func_cfg_flags &=
    4566                 :            :                 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
    4567                 :            :                   HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
    4568                 :          0 :         bp->pf->func_cfg_flags |=
    4569                 :            :                 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
    4570                 :            : 
    4571                 :          0 :         rc = bnxt_hwrm_pf_func_cfg(bp, &pf_resc);
    4572         [ #  # ]:          0 :         if (rc)
    4573                 :            :                 return rc;
    4574                 :            : 
    4575                 :          0 :         rc = bnxt_update_max_resources_pf_only(bp);
    4576                 :            : 
    4577                 :          0 :         return rc;
    4578                 :            : }
    4579                 :            : 
    4580                 :            : static int
    4581                 :          0 : bnxt_configure_vf_req_buf(struct bnxt *bp, int num_vfs)
    4582                 :            : {
    4583                 :            :         size_t req_buf_sz, sz;
    4584                 :            :         int i, rc;
    4585                 :            : 
    4586                 :          0 :         req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
    4587                 :          0 :         bp->pf->vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
    4588                 :            :                 page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
    4589         [ #  # ]:          0 :         if (bp->pf->vf_req_buf == NULL) {
    4590                 :            :                 return -ENOMEM;
    4591                 :            :         }
    4592                 :            : 
    4593         [ #  # ]:          0 :         for (sz = 0; sz < req_buf_sz; sz += getpagesize())
    4594                 :          0 :                 rte_mem_lock_page(((char *)bp->pf->vf_req_buf) + sz);
    4595                 :            : 
    4596         [ #  # ]:          0 :         for (i = 0; i < num_vfs; i++)
    4597                 :          0 :                 bp->pf->vf_info[i].req_buf = ((char *)bp->pf->vf_req_buf) +
    4598                 :          0 :                                              (i * HWRM_MAX_REQ_LEN);
    4599                 :            : 
    4600                 :          0 :         rc = bnxt_hwrm_func_buf_rgtr(bp, num_vfs);
    4601         [ #  # ]:          0 :         if (rc)
    4602                 :          0 :                 rte_free(bp->pf->vf_req_buf);
    4603                 :            : 
    4604                 :            :         return rc;
    4605                 :            : }
    4606                 :            : 
    4607                 :            : static int
    4608                 :          0 : bnxt_process_vf_resc_config_new(struct bnxt *bp, int num_vfs)
    4609                 :            : {
    4610                 :          0 :         struct hwrm_func_vf_resource_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    4611                 :          0 :         struct hwrm_func_vf_resource_cfg_input req = {0};
    4612                 :            :         int i, rc = 0;
    4613                 :            : 
    4614                 :          0 :         bnxt_fill_vf_func_cfg_req_new(bp, &req, num_vfs);
    4615                 :          0 :         bp->pf->active_vfs = 0;
    4616         [ #  # ]:          0 :         for (i = 0; i < num_vfs; i++) {
    4617         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_FUNC_VF_RESOURCE_CFG, BNXT_USE_CHIMP_MB);
    4618                 :          0 :                 req.vf_id = rte_cpu_to_le_16(bp->pf->vf_info[i].fid);
    4619                 :          0 :                 rc = bnxt_hwrm_send_message(bp,
    4620                 :            :                                             &req,
    4621                 :            :                                             sizeof(req),
    4622                 :            :                                             BNXT_USE_CHIMP_MB);
    4623   [ #  #  #  # ]:          0 :                 if (rc || resp->error_code) {
    4624                 :          0 :                         PMD_DRV_LOG(ERR,
    4625                 :            :                                 "Failed to initialize VF %d\n", i);
    4626                 :          0 :                         PMD_DRV_LOG(ERR,
    4627                 :            :                                 "Not all VFs available. (%d, %d)\n",
    4628                 :            :                                 rc, resp->error_code);
    4629                 :            :                         HWRM_UNLOCK();
    4630                 :            : 
    4631                 :            :                         /* If the first VF configuration itself fails,
    4632                 :            :                          * unregister the vf_fwd_request buffer.
    4633                 :            :                          */
    4634         [ #  # ]:          0 :                         if (i == 0)
    4635                 :          0 :                                 bnxt_hwrm_func_buf_unrgtr(bp);
    4636                 :            :                         break;
    4637                 :            :                 }
    4638                 :            :                 HWRM_UNLOCK();
    4639                 :            : 
    4640                 :            :                 /* Update the max resource values based on the resource values
    4641                 :            :                  * allocated to the VF.
    4642                 :            :                  */
    4643                 :          0 :                 bnxt_update_max_resources(bp, i);
    4644                 :          0 :                 bp->pf->active_vfs++;
    4645                 :          0 :                 bnxt_hwrm_func_clr_stats(bp, bp->pf->vf_info[i].fid);
    4646                 :            :         }
    4647                 :            : 
    4648                 :            :         return 0;
    4649                 :            : }
    4650                 :            : 
    4651                 :            : static int
    4652                 :          0 : bnxt_process_vf_resc_config_old(struct bnxt *bp, int num_vfs)
    4653                 :            : {
    4654                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    4655                 :          0 :         struct hwrm_func_cfg_input req = {0};
    4656                 :            :         int i, rc;
    4657                 :            : 
    4658                 :          0 :         bnxt_fill_vf_func_cfg_req_old(bp, &req, num_vfs);
    4659                 :            : 
    4660                 :          0 :         bp->pf->active_vfs = 0;
    4661         [ #  # ]:          0 :         for (i = 0; i < num_vfs; i++) {
    4662         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    4663                 :          0 :                 req.flags = rte_cpu_to_le_32(bp->pf->vf_info[i].func_cfg_flags);
    4664                 :          0 :                 req.fid = rte_cpu_to_le_16(bp->pf->vf_info[i].fid);
    4665                 :          0 :                 rc = bnxt_hwrm_send_message(bp,
    4666                 :            :                                             &req,
    4667                 :            :                                             sizeof(req),
    4668                 :            :                                             BNXT_USE_CHIMP_MB);
    4669                 :            : 
    4670                 :            :                 /* Clear enable flag for next pass */
    4671                 :          0 :                 req.enables &= ~rte_cpu_to_le_32(
    4672                 :            :                                 HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
    4673                 :            : 
    4674   [ #  #  #  # ]:          0 :                 if (rc || resp->error_code) {
    4675                 :          0 :                         PMD_DRV_LOG(ERR,
    4676                 :            :                                 "Failed to initialize VF %d\n", i);
    4677                 :          0 :                         PMD_DRV_LOG(ERR,
    4678                 :            :                                 "Not all VFs available. (%d, %d)\n",
    4679                 :            :                                 rc, resp->error_code);
    4680                 :            :                         HWRM_UNLOCK();
    4681                 :            : 
    4682                 :            :                         /* If the first VF configuration itself fails,
    4683                 :            :                          * unregister the vf_fwd_request buffer.
    4684                 :            :                          */
    4685         [ #  # ]:          0 :                         if (i == 0)
    4686                 :          0 :                                 bnxt_hwrm_func_buf_unrgtr(bp);
    4687                 :            :                         break;
    4688                 :            :                 }
    4689                 :            : 
    4690                 :            :                 HWRM_UNLOCK();
    4691                 :            : 
    4692                 :            :                 /* Update the max resource values based on the resource values
    4693                 :            :                  * allocated to the VF.
    4694                 :            :                  */
    4695                 :          0 :                 bnxt_update_max_resources(bp, i);
    4696                 :          0 :                 bp->pf->active_vfs++;
    4697                 :          0 :                 bnxt_hwrm_func_clr_stats(bp, bp->pf->vf_info[i].fid);
    4698                 :            :         }
    4699                 :            : 
    4700                 :            :         return 0;
    4701                 :            : }
    4702                 :            : 
    4703                 :            : static void
    4704                 :          0 : bnxt_configure_vf_resources(struct bnxt *bp, int num_vfs)
    4705                 :            : {
    4706         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_NEW_RM)
    4707                 :          0 :                 bnxt_process_vf_resc_config_new(bp, num_vfs);
    4708                 :            :         else
    4709                 :          0 :                 bnxt_process_vf_resc_config_old(bp, num_vfs);
    4710                 :          0 : }
    4711                 :            : 
    4712                 :            : static void
    4713                 :            : bnxt_update_pf_resources(struct bnxt *bp,
    4714                 :            :                          struct bnxt_pf_resource_info *pf_resc)
    4715                 :            : {
    4716                 :          0 :         bp->max_rsscos_ctx = pf_resc->num_rsscos_ctxs;
    4717                 :          0 :         bp->max_stat_ctx = pf_resc->num_stat_ctxs;
    4718                 :          0 :         bp->max_cp_rings = pf_resc->num_cp_rings;
    4719                 :          0 :         bp->max_tx_rings = pf_resc->num_tx_rings;
    4720                 :          0 :         bp->max_rx_rings = pf_resc->num_rx_rings;
    4721                 :          0 :         bp->max_ring_grps = pf_resc->num_hw_ring_grps;
    4722                 :          0 :         bp->max_nq_rings = pf_resc->num_nq_rings;
    4723                 :          0 :         bp->max_vnics = pf_resc->num_vnics;
    4724                 :            : }
    4725                 :            : 
    4726                 :            : static int32_t
    4727                 :            : bnxt_configure_pf_resources(struct bnxt *bp,
    4728                 :            :                             struct bnxt_pf_resource_info *pf_resc)
    4729                 :            : {
    4730                 :            :         /*
    4731                 :            :          * We're using STD_TX_RING_MODE here which will limit the TX
    4732                 :            :          * rings. This will allow QoS to function properly. Not setting this
    4733                 :            :          * will cause PF rings to break bandwidth settings.
    4734                 :            :          */
    4735                 :          0 :         bp->pf->func_cfg_flags &=
    4736                 :            :                 ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
    4737                 :            :                   HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
    4738                 :          0 :         bp->pf->func_cfg_flags |=
    4739                 :            :                 HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
    4740                 :          0 :         return bnxt_hwrm_pf_func_cfg(bp, pf_resc);
    4741                 :            : }
    4742                 :            : 
    4743                 :          0 : int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
    4744                 :            : {
    4745                 :          0 :         struct bnxt_pf_resource_info pf_resc = { 0 };
    4746                 :            :         int rc;
    4747                 :            : 
    4748         [ #  # ]:          0 :         if (!BNXT_PF(bp)) {
    4749                 :          0 :                 PMD_DRV_LOG(ERR, "Attempt to allocate VFs on a VF!\n");
    4750                 :          0 :                 return -EINVAL;
    4751                 :            :         }
    4752                 :            : 
    4753                 :          0 :         rc = bnxt_hwrm_func_qcaps(bp);
    4754         [ #  # ]:          0 :         if (rc)
    4755                 :            :                 return rc;
    4756                 :            : 
    4757                 :          0 :         bnxt_calculate_pf_resources(bp, &pf_resc, num_vfs);
    4758                 :            : 
    4759                 :            :         rc = bnxt_configure_pf_resources(bp, &pf_resc);
    4760         [ #  # ]:          0 :         if (rc)
    4761                 :            :                 return rc;
    4762                 :            : 
    4763                 :          0 :         rc = bnxt_query_pf_resources(bp, &pf_resc);
    4764         [ #  # ]:          0 :         if (rc)
    4765                 :            :                 return rc;
    4766                 :            : 
    4767                 :            :         /*
    4768                 :            :          * Now, create and register a buffer to hold forwarded VF requests
    4769                 :            :          */
    4770                 :          0 :         rc = bnxt_configure_vf_req_buf(bp, num_vfs);
    4771         [ #  # ]:          0 :         if (rc)
    4772                 :            :                 return rc;
    4773                 :            : 
    4774                 :          0 :         bnxt_configure_vf_resources(bp, num_vfs);
    4775                 :            : 
    4776                 :            :         bnxt_update_pf_resources(bp, &pf_resc);
    4777                 :            : 
    4778                 :          0 :         return 0;
    4779                 :            : }
    4780                 :            : 
    4781                 :          0 : int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
    4782                 :            : {
    4783                 :          0 :         struct hwrm_func_cfg_input req = {0};
    4784                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    4785                 :            :         int rc;
    4786                 :            : 
    4787         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    4788                 :            : 
    4789                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    4790                 :          0 :         req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
    4791                 :          0 :         req.evb_mode = bp->pf->evb_mode;
    4792                 :            : 
    4793                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4794   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4795                 :            :         HWRM_UNLOCK();
    4796                 :            : 
    4797                 :          0 :         return rc;
    4798                 :            : }
    4799                 :            : 
    4800                 :          0 : static int bnxt_hwrm_set_tpa(struct bnxt *bp)
    4801                 :            : {
    4802                 :          0 :         struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
    4803                 :          0 :         uint64_t rx_offloads = dev_conf->rxmode.offloads;
    4804                 :            :         bool tpa_flags = 0;
    4805                 :            :         int rc, i;
    4806                 :            : 
    4807                 :          0 :         tpa_flags = (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) ?  true : false;
    4808         [ #  # ]:          0 :         for (i = 0; i < bp->max_vnics; i++) {
    4809                 :          0 :                 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
    4810                 :            : 
    4811         [ #  # ]:          0 :                 if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
    4812                 :          0 :                         continue;
    4813                 :            : 
    4814                 :          0 :                 rc = bnxt_hwrm_vnic_tpa_cfg(bp, vnic, tpa_flags);
    4815         [ #  # ]:          0 :                 if (rc)
    4816                 :          0 :                         return rc;
    4817                 :            :         }
    4818                 :            :         return 0;
    4819                 :            : }
    4820                 :            : 
    4821                 :          0 : int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
    4822                 :            :                                 uint8_t tunnel_type)
    4823                 :            : {
    4824                 :          0 :         struct hwrm_tunnel_dst_port_alloc_input req = {0};
    4825                 :          0 :         struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    4826                 :            :         int rc = 0;
    4827                 :            : 
    4828   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
    4829                 :          0 :         req.tunnel_type = tunnel_type;
    4830         [ #  # ]:          0 :         req.tunnel_dst_port_val = rte_cpu_to_be_16(port);
    4831                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4832   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4833                 :            : 
    4834   [ #  #  #  # ]:          0 :         switch (tunnel_type) {
    4835                 :          0 :         case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
    4836                 :          0 :                 bp->vxlan_fw_dst_port_id =
    4837                 :          0 :                         rte_le_to_cpu_16(resp->tunnel_dst_port_id);
    4838                 :          0 :                 bp->vxlan_port = port;
    4839                 :          0 :                 break;
    4840                 :          0 :         case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
    4841                 :          0 :                 bp->geneve_fw_dst_port_id =
    4842                 :          0 :                         rte_le_to_cpu_16(resp->tunnel_dst_port_id);
    4843                 :          0 :                 bp->geneve_port = port;
    4844                 :          0 :                 break;
    4845                 :          0 :         case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI:
    4846                 :          0 :                 bp->ecpri_fw_dst_port_id =
    4847                 :          0 :                         rte_le_to_cpu_16(resp->tunnel_dst_port_id);
    4848                 :          0 :                 bp->ecpri_port = port;
    4849                 :          0 :                 bp->ecpri_upar_in_use = resp->upar_in_use;
    4850                 :          0 :                 break;
    4851                 :            :         default:
    4852                 :            :                 break;
    4853                 :            :         }
    4854                 :            : 
    4855                 :            :         HWRM_UNLOCK();
    4856                 :            : 
    4857                 :          0 :         bnxt_hwrm_set_tpa(bp);
    4858                 :            : 
    4859                 :          0 :         return rc;
    4860                 :            : }
    4861                 :            : 
    4862                 :          0 : int bnxt_hwrm_tunnel_upar_id_get(struct bnxt *bp, uint8_t *upar_id,
    4863                 :            :                                  uint8_t tunnel_type)
    4864                 :            : {
    4865                 :          0 :         struct hwrm_tunnel_dst_port_query_input req = {0};
    4866                 :          0 :         struct hwrm_tunnel_dst_port_query_output *resp = bp->hwrm_cmd_resp_addr;
    4867                 :            :         int rc = 0;
    4868                 :            : 
    4869         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_QUERY, BNXT_USE_CHIMP_MB);
    4870                 :          0 :         req.tunnel_type = tunnel_type;
    4871                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4872   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4873                 :            : 
    4874      [ #  #  # ]:          0 :         switch (tunnel_type) {
    4875                 :          0 :         case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI:
    4876                 :          0 :                 *upar_id = resp->upar_in_use;
    4877                 :          0 :                 break;
    4878                 :          0 :         case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_SRV6:
    4879                 :          0 :                 *upar_id = resp->upar_in_use;
    4880                 :          0 :                 break;
    4881                 :          0 :         default:
    4882                 :            :                 /* INVALID UPAR Id if another tunnel type tries to retrieve */
    4883                 :          0 :                 *upar_id = 0xff;
    4884                 :          0 :                 break;
    4885                 :            :         }
    4886                 :            : 
    4887                 :            :         HWRM_UNLOCK();
    4888                 :            : 
    4889                 :          0 :         return rc;
    4890                 :            : }
    4891                 :            : 
    4892                 :          0 : int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
    4893                 :            :                                 uint8_t tunnel_type)
    4894                 :            : {
    4895                 :          0 :         struct hwrm_tunnel_dst_port_free_input req = {0};
    4896                 :          0 :         struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
    4897                 :            :         int rc = 0;
    4898                 :            : 
    4899   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
    4900                 :            : 
    4901                 :          0 :         req.tunnel_type = tunnel_type;
    4902         [ #  # ]:          0 :         req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
    4903                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4904                 :            : 
    4905   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4906                 :            :         HWRM_UNLOCK();
    4907                 :            : 
    4908         [ #  # ]:          0 :         if (tunnel_type ==
    4909                 :            :             HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN) {
    4910                 :          0 :                 bp->vxlan_port = 0;
    4911                 :          0 :                 bp->vxlan_port_cnt = 0;
    4912                 :            :         }
    4913                 :            : 
    4914         [ #  # ]:          0 :         if (tunnel_type ==
    4915                 :            :             HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE) {
    4916                 :          0 :                 bp->geneve_port = 0;
    4917                 :          0 :                 bp->geneve_port_cnt = 0;
    4918                 :            :         }
    4919                 :            : 
    4920         [ #  # ]:          0 :         if (tunnel_type ==
    4921                 :            :             HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI) {
    4922                 :          0 :                 bp->ecpri_port = 0;
    4923                 :          0 :                 bp->ecpri_upar_in_use = 0;
    4924                 :          0 :                 bp->ecpri_port_cnt = 0;
    4925                 :            :         }
    4926                 :            : 
    4927                 :          0 :         bnxt_hwrm_set_tpa(bp);
    4928                 :          0 :         return rc;
    4929                 :            : }
    4930                 :            : 
    4931                 :          0 : int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
    4932                 :            :                                         uint32_t flags)
    4933                 :            : {
    4934                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    4935                 :          0 :         struct hwrm_func_cfg_input req = {0};
    4936                 :            :         int rc;
    4937                 :            : 
    4938         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    4939                 :            : 
    4940                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    4941                 :          0 :         req.flags = rte_cpu_to_le_32(flags);
    4942                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4943                 :            : 
    4944   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4945                 :            :         HWRM_UNLOCK();
    4946                 :            : 
    4947                 :          0 :         return rc;
    4948                 :            : }
    4949                 :            : 
    4950                 :          0 : void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
    4951                 :            : {
    4952                 :            :         uint32_t *flag = flagp;
    4953                 :            : 
    4954                 :          0 :         vnic->flags = *flag;
    4955                 :          0 : }
    4956                 :            : 
    4957                 :          0 : int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    4958                 :            : {
    4959                 :          0 :         return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
    4960                 :            : }
    4961                 :            : 
    4962                 :          0 : int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp, int num_vfs)
    4963                 :            : {
    4964                 :          0 :         struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
    4965                 :          0 :         struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
    4966                 :            :         int rc;
    4967                 :            : 
    4968         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
    4969                 :            : 
    4970                 :          0 :         req.req_buf_num_pages = rte_cpu_to_le_16(1);
    4971                 :          0 :         req.req_buf_page_size =
    4972                 :          0 :                 rte_cpu_to_le_16(page_getenum(num_vfs * HWRM_MAX_REQ_LEN));
    4973                 :          0 :         req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
    4974                 :          0 :         req.req_buf_page_addr0 =
    4975                 :          0 :                 rte_cpu_to_le_64(rte_malloc_virt2iova(bp->pf->vf_req_buf));
    4976         [ #  # ]:          0 :         if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
    4977                 :          0 :                 PMD_DRV_LOG(ERR,
    4978                 :            :                         "unable to map buffer address to physical memory\n");
    4979                 :            :                 HWRM_UNLOCK();
    4980                 :          0 :                 return -ENOMEM;
    4981                 :            :         }
    4982                 :            : 
    4983                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    4984                 :            : 
    4985   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    4986                 :            :         HWRM_UNLOCK();
    4987                 :            : 
    4988                 :          0 :         return rc;
    4989                 :            : }
    4990                 :            : 
    4991                 :          0 : int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
    4992                 :            : {
    4993                 :            :         int rc = 0;
    4994                 :          0 :         struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
    4995                 :          0 :         struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
    4996                 :            : 
    4997   [ #  #  #  # ]:          0 :         if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
    4998                 :            :                 return 0;
    4999                 :            : 
    5000         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
    5001                 :            : 
    5002                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5003                 :            : 
    5004   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5005                 :            :         HWRM_UNLOCK();
    5006                 :            : 
    5007                 :          0 :         return rc;
    5008                 :            : }
    5009                 :            : 
    5010                 :          0 : int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
    5011                 :            : {
    5012                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5013                 :          0 :         struct hwrm_func_cfg_input req = {0};
    5014                 :            :         int rc;
    5015                 :            : 
    5016         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    5017                 :            : 
    5018                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    5019                 :          0 :         req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
    5020                 :          0 :         req.enables = rte_cpu_to_le_32(
    5021                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
    5022                 :          0 :         req.async_event_cr = rte_cpu_to_le_16(
    5023                 :            :                         bp->async_cp_ring->cp_ring_struct->fw_ring_id);
    5024                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5025                 :            : 
    5026   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5027                 :            :         HWRM_UNLOCK();
    5028                 :            : 
    5029                 :          0 :         return rc;
    5030                 :            : }
    5031                 :            : 
    5032                 :          0 : int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
    5033                 :            : {
    5034                 :          0 :         struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5035                 :          0 :         struct hwrm_func_vf_cfg_input req = {0};
    5036                 :            :         int rc;
    5037                 :            : 
    5038         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
    5039                 :            : 
    5040                 :          0 :         req.enables = rte_cpu_to_le_32(
    5041                 :            :                         HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
    5042                 :          0 :         req.async_event_cr = rte_cpu_to_le_16(
    5043                 :            :                         bp->async_cp_ring->cp_ring_struct->fw_ring_id);
    5044                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5045                 :            : 
    5046   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5047                 :            :         HWRM_UNLOCK();
    5048                 :            : 
    5049                 :          0 :         return rc;
    5050                 :            : }
    5051                 :            : 
    5052                 :          0 : int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
    5053                 :            : {
    5054                 :          0 :         struct hwrm_func_cfg_input req = {0};
    5055                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5056                 :            :         uint16_t dflt_vlan, fid;
    5057                 :            :         uint32_t func_cfg_flags;
    5058                 :            :         int rc = 0;
    5059                 :            : 
    5060   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    5061                 :            : 
    5062         [ #  # ]:          0 :         if (is_vf) {
    5063                 :          0 :                 dflt_vlan = bp->pf->vf_info[vf].dflt_vlan;
    5064                 :          0 :                 fid = bp->pf->vf_info[vf].fid;
    5065                 :          0 :                 func_cfg_flags = bp->pf->vf_info[vf].func_cfg_flags;
    5066                 :            :         } else {
    5067                 :            :                 fid = rte_cpu_to_le_16(0xffff);
    5068                 :          0 :                 func_cfg_flags = bp->pf->func_cfg_flags;
    5069                 :          0 :                 dflt_vlan = bp->vlan;
    5070                 :            :         }
    5071                 :            : 
    5072                 :          0 :         req.flags = rte_cpu_to_le_32(func_cfg_flags);
    5073                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    5074                 :          0 :         req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
    5075                 :          0 :         req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
    5076                 :            : 
    5077                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5078                 :            : 
    5079   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5080                 :            :         HWRM_UNLOCK();
    5081                 :            : 
    5082                 :          0 :         return rc;
    5083                 :            : }
    5084                 :            : 
    5085                 :          0 : int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
    5086                 :            :                         uint16_t max_bw, uint16_t enables)
    5087                 :            : {
    5088                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5089                 :          0 :         struct hwrm_func_cfg_input req = {0};
    5090                 :            :         int rc;
    5091                 :            : 
    5092         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    5093                 :            : 
    5094                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    5095                 :          0 :         req.enables |= rte_cpu_to_le_32(enables);
    5096                 :          0 :         req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
    5097                 :          0 :         req.max_bw = rte_cpu_to_le_32(max_bw);
    5098                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5099                 :            : 
    5100   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5101                 :            :         HWRM_UNLOCK();
    5102                 :            : 
    5103                 :          0 :         return rc;
    5104                 :            : }
    5105                 :            : 
    5106                 :          0 : int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
    5107                 :            : {
    5108                 :          0 :         struct hwrm_func_cfg_input req = {0};
    5109                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5110                 :            :         int rc = 0;
    5111                 :            : 
    5112         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    5113                 :            : 
    5114                 :          0 :         req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
    5115                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    5116                 :          0 :         req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
    5117                 :          0 :         req.dflt_vlan = rte_cpu_to_le_16(bp->pf->vf_info[vf].dflt_vlan);
    5118                 :            : 
    5119                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5120                 :            : 
    5121   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5122                 :            :         HWRM_UNLOCK();
    5123                 :            : 
    5124                 :          0 :         return rc;
    5125                 :            : }
    5126                 :            : 
    5127                 :          0 : int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
    5128                 :            : {
    5129                 :            :         int rc;
    5130                 :            : 
    5131         [ #  # ]:          0 :         if (BNXT_PF(bp))
    5132                 :          0 :                 rc = bnxt_hwrm_func_cfg_def_cp(bp);
    5133                 :            :         else
    5134                 :          0 :                 rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
    5135                 :            : 
    5136                 :          0 :         return rc;
    5137                 :            : }
    5138                 :            : 
    5139                 :          0 : int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
    5140                 :            :                               void *encaped, size_t ec_size)
    5141                 :            : {
    5142                 :            :         int rc = 0;
    5143                 :          0 :         struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
    5144                 :          0 :         struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
    5145                 :            : 
    5146         [ #  # ]:          0 :         if (ec_size > sizeof(req.encap_request))
    5147                 :            :                 return -1;
    5148                 :            : 
    5149         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
    5150                 :            : 
    5151                 :          0 :         req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
    5152                 :            :         memcpy(req.encap_request, encaped, ec_size);
    5153                 :            : 
    5154                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5155                 :            : 
    5156   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5157                 :            :         HWRM_UNLOCK();
    5158                 :            : 
    5159                 :          0 :         return rc;
    5160                 :            : }
    5161                 :            : 
    5162                 :          0 : int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
    5163                 :            :                                        struct rte_ether_addr *mac)
    5164                 :            : {
    5165                 :          0 :         struct hwrm_func_qcfg_input req = {0};
    5166                 :          0 :         struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    5167                 :            :         int rc;
    5168                 :            : 
    5169         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
    5170                 :            : 
    5171                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    5172                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5173                 :            : 
    5174   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5175                 :            : 
    5176                 :          0 :         memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
    5177                 :            : 
    5178                 :            :         HWRM_UNLOCK();
    5179                 :            : 
    5180                 :          0 :         return rc;
    5181                 :            : }
    5182                 :            : 
    5183                 :          0 : int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
    5184                 :            :                             void *encaped, size_t ec_size)
    5185                 :            : {
    5186                 :            :         int rc = 0;
    5187                 :          0 :         struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
    5188                 :          0 :         struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
    5189                 :            : 
    5190         [ #  # ]:          0 :         if (ec_size > sizeof(req.encap_request))
    5191                 :            :                 return -1;
    5192                 :            : 
    5193         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
    5194                 :            : 
    5195                 :          0 :         req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
    5196                 :            :         memcpy(req.encap_request, encaped, ec_size);
    5197                 :            : 
    5198                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5199                 :            : 
    5200   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5201                 :            :         HWRM_UNLOCK();
    5202                 :            : 
    5203                 :          0 :         return rc;
    5204                 :            : }
    5205                 :            : 
    5206                 :            : static void bnxt_update_prev_stat(uint64_t *cntr, uint64_t *prev_cntr)
    5207                 :            : {
    5208                 :            :         /* One of the HW stat values that make up this counter was zero as
    5209                 :            :          * returned by HW in this iteration, so use the previous
    5210                 :            :          * iteration's counter value
    5211                 :            :          */
    5212                 :          0 :         if (!cntr || !prev_cntr)
    5213                 :            :                 return;
    5214   [ #  #  #  #  :          0 :         if (*prev_cntr && *cntr == 0)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    5215                 :          0 :                 *cntr = *prev_cntr;
    5216                 :            :         else
    5217                 :          0 :                 *prev_cntr = *cntr;
    5218                 :            : }
    5219                 :            : 
    5220                 :          0 : int bnxt_hwrm_ring_stats(struct bnxt *bp, uint32_t cid, int idx,
    5221                 :            :                          struct bnxt_ring_stats *ring_stats, bool rx)
    5222                 :            : {
    5223                 :            :         int rc = 0;
    5224                 :          0 :         struct hwrm_stat_ctx_query_input req = {.req_type = 0};
    5225                 :          0 :         struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
    5226                 :            : 
    5227         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
    5228                 :            : 
    5229                 :          0 :         req.stat_ctx_id = rte_cpu_to_le_32(cid);
    5230                 :            : 
    5231                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5232                 :            : 
    5233   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5234                 :            : 
    5235         [ #  # ]:          0 :         if (rx) {
    5236                 :          0 :                 struct bnxt_ring_stats *prev_stats = &bp->prev_rx_ring_stats[idx];
    5237                 :            : 
    5238         [ #  # ]:          0 :                 ring_stats->rx_ucast_pkts = rte_le_to_cpu_64(resp->rx_ucast_pkts);
    5239                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_ucast_pkts,
    5240                 :            :                                       &prev_stats->rx_ucast_pkts);
    5241                 :            : 
    5242         [ #  # ]:          0 :                 ring_stats->rx_mcast_pkts = rte_le_to_cpu_64(resp->rx_mcast_pkts);
    5243                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_mcast_pkts,
    5244                 :            :                                       &prev_stats->rx_mcast_pkts);
    5245                 :            : 
    5246         [ #  # ]:          0 :                 ring_stats->rx_bcast_pkts = rte_le_to_cpu_64(resp->rx_bcast_pkts);
    5247                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_bcast_pkts,
    5248                 :            :                                       &prev_stats->rx_bcast_pkts);
    5249                 :            : 
    5250         [ #  # ]:          0 :                 ring_stats->rx_ucast_bytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
    5251                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_ucast_bytes,
    5252                 :            :                                       &prev_stats->rx_ucast_bytes);
    5253                 :            : 
    5254         [ #  # ]:          0 :                 ring_stats->rx_mcast_bytes = rte_le_to_cpu_64(resp->rx_mcast_bytes);
    5255                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_mcast_bytes,
    5256                 :            :                                       &prev_stats->rx_mcast_bytes);
    5257                 :            : 
    5258         [ #  # ]:          0 :                 ring_stats->rx_bcast_bytes = rte_le_to_cpu_64(resp->rx_bcast_bytes);
    5259                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_bcast_bytes,
    5260                 :            :                                       &prev_stats->rx_bcast_bytes);
    5261                 :            : 
    5262         [ #  # ]:          0 :                 ring_stats->rx_discard_pkts = rte_le_to_cpu_64(resp->rx_discard_pkts);
    5263                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_discard_pkts,
    5264                 :            :                                       &prev_stats->rx_discard_pkts);
    5265                 :            : 
    5266         [ #  # ]:          0 :                 ring_stats->rx_error_pkts = rte_le_to_cpu_64(resp->rx_error_pkts);
    5267                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_error_pkts,
    5268                 :            :                                       &prev_stats->rx_error_pkts);
    5269                 :            : 
    5270         [ #  # ]:          0 :                 ring_stats->rx_agg_pkts = rte_le_to_cpu_64(resp->rx_agg_pkts);
    5271                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_agg_pkts,
    5272                 :            :                                       &prev_stats->rx_agg_pkts);
    5273                 :            : 
    5274         [ #  # ]:          0 :                 ring_stats->rx_agg_bytes = rte_le_to_cpu_64(resp->rx_agg_bytes);
    5275                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_agg_bytes,
    5276                 :            :                                       &prev_stats->rx_agg_bytes);
    5277                 :            : 
    5278         [ #  # ]:          0 :                 ring_stats->rx_agg_events = rte_le_to_cpu_64(resp->rx_agg_events);
    5279                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_agg_events,
    5280                 :            :                                       &prev_stats->rx_agg_events);
    5281                 :            : 
    5282         [ #  # ]:          0 :                 ring_stats->rx_agg_aborts = rte_le_to_cpu_64(resp->rx_agg_aborts);
    5283                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_agg_aborts,
    5284                 :            :                                       &prev_stats->rx_agg_aborts);
    5285                 :            :         } else {
    5286                 :          0 :                 struct bnxt_ring_stats *prev_stats = &bp->prev_tx_ring_stats[idx];
    5287                 :            : 
    5288                 :          0 :                 ring_stats->tx_ucast_pkts = rte_le_to_cpu_64(resp->tx_ucast_pkts);
    5289         [ #  # ]:          0 :                 bnxt_update_prev_stat(&ring_stats->tx_ucast_pkts,
    5290                 :            :                                       &prev_stats->tx_ucast_pkts);
    5291                 :            : 
    5292         [ #  # ]:          0 :                 ring_stats->tx_mcast_pkts = rte_le_to_cpu_64(resp->tx_mcast_pkts);
    5293                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_mcast_pkts,
    5294                 :            :                                       &prev_stats->tx_mcast_pkts);
    5295                 :            : 
    5296         [ #  # ]:          0 :                 ring_stats->tx_bcast_pkts = rte_le_to_cpu_64(resp->tx_bcast_pkts);
    5297                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_bcast_pkts,
    5298                 :            :                                       &prev_stats->tx_bcast_pkts);
    5299                 :            : 
    5300         [ #  # ]:          0 :                 ring_stats->tx_ucast_bytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
    5301                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_ucast_bytes,
    5302                 :            :                                       &prev_stats->tx_ucast_bytes);
    5303                 :            : 
    5304         [ #  # ]:          0 :                 ring_stats->tx_mcast_bytes = rte_le_to_cpu_64(resp->tx_mcast_bytes);
    5305                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_mcast_bytes,
    5306                 :            :                                       &prev_stats->tx_mcast_bytes);
    5307                 :            : 
    5308         [ #  # ]:          0 :                 ring_stats->tx_bcast_bytes = rte_le_to_cpu_64(resp->tx_bcast_bytes);
    5309                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_bcast_bytes,
    5310                 :            :                                       &prev_stats->tx_bcast_bytes);
    5311                 :            : 
    5312         [ #  # ]:          0 :                 ring_stats->tx_discard_pkts = rte_le_to_cpu_64(resp->tx_discard_pkts);
    5313                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_discard_pkts,
    5314                 :            :                                       &prev_stats->tx_discard_pkts);
    5315                 :            :         }
    5316                 :            : 
    5317                 :            :         HWRM_UNLOCK();
    5318                 :            : 
    5319                 :          0 :         return rc;
    5320                 :            : }
    5321                 :            : 
    5322                 :          0 : int bnxt_hwrm_ring_stats_ext(struct bnxt *bp, uint32_t cid, int idx,
    5323                 :            :                              struct bnxt_ring_stats_ext *ring_stats, bool rx)
    5324                 :            : {
    5325                 :            :         int rc = 0;
    5326                 :          0 :         struct hwrm_stat_ext_ctx_query_input req = {.req_type = 0};
    5327                 :          0 :         struct hwrm_stat_ext_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
    5328                 :            : 
    5329         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_STAT_EXT_CTX_QUERY, BNXT_USE_CHIMP_MB);
    5330                 :            : 
    5331                 :          0 :         req.stat_ctx_id = rte_cpu_to_le_32(cid);
    5332                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5333                 :            : 
    5334   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5335                 :            : 
    5336         [ #  # ]:          0 :         if (rx) {
    5337                 :          0 :                 struct bnxt_ring_stats_ext *prev_stats = &bp->prev_rx_ring_stats_ext[idx];
    5338                 :            : 
    5339                 :          0 :                 ring_stats->rx_ucast_pkts = rte_le_to_cpu_64(resp->rx_ucast_pkts);
    5340         [ #  # ]:          0 :                 bnxt_update_prev_stat(&ring_stats->rx_ucast_pkts,
    5341                 :            :                                       &prev_stats->rx_ucast_pkts);
    5342                 :            : 
    5343         [ #  # ]:          0 :                 ring_stats->rx_mcast_pkts = rte_le_to_cpu_64(resp->rx_mcast_pkts);
    5344                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_mcast_pkts,
    5345                 :            :                                       &prev_stats->rx_mcast_pkts);
    5346                 :            : 
    5347         [ #  # ]:          0 :                 ring_stats->rx_bcast_pkts = rte_le_to_cpu_64(resp->rx_bcast_pkts);
    5348                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_bcast_pkts,
    5349                 :            :                                       &prev_stats->rx_bcast_pkts);
    5350                 :            : 
    5351         [ #  # ]:          0 :                 ring_stats->rx_ucast_bytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
    5352                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_ucast_bytes,
    5353                 :            :                                       &prev_stats->rx_ucast_bytes);
    5354                 :            : 
    5355         [ #  # ]:          0 :                 ring_stats->rx_mcast_bytes = rte_le_to_cpu_64(resp->rx_mcast_bytes);
    5356                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_mcast_bytes,
    5357                 :            :                                       &prev_stats->rx_mcast_bytes);
    5358                 :            : 
    5359         [ #  # ]:          0 :                 ring_stats->rx_bcast_bytes = rte_le_to_cpu_64(resp->rx_bcast_bytes);
    5360                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_bcast_bytes,
    5361                 :            :                                       &prev_stats->rx_bcast_bytes);
    5362                 :            : 
    5363         [ #  # ]:          0 :                 ring_stats->rx_discard_pkts = rte_le_to_cpu_64(resp->rx_discard_pkts);
    5364                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_discard_pkts,
    5365                 :            :                                       &prev_stats->rx_discard_pkts);
    5366                 :            : 
    5367         [ #  # ]:          0 :                 ring_stats->rx_error_pkts = rte_le_to_cpu_64(resp->rx_error_pkts);
    5368                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_error_pkts,
    5369                 :            :                                       &prev_stats->rx_error_pkts);
    5370                 :            : 
    5371         [ #  # ]:          0 :                 ring_stats->rx_tpa_eligible_pkt = rte_le_to_cpu_64(resp->rx_tpa_eligible_pkt);
    5372                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_eligible_pkt,
    5373                 :            :                                       &prev_stats->rx_tpa_eligible_pkt);
    5374                 :            : 
    5375         [ #  # ]:          0 :                 ring_stats->rx_tpa_eligible_bytes = rte_le_to_cpu_64(resp->rx_tpa_eligible_bytes);
    5376                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_eligible_bytes,
    5377                 :            :                                       &prev_stats->rx_tpa_eligible_bytes);
    5378                 :            : 
    5379         [ #  # ]:          0 :                 ring_stats->rx_tpa_pkt = rte_le_to_cpu_64(resp->rx_tpa_pkt);
    5380                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_pkt,
    5381                 :            :                                       &prev_stats->rx_tpa_pkt);
    5382                 :            : 
    5383         [ #  # ]:          0 :                 ring_stats->rx_tpa_bytes = rte_le_to_cpu_64(resp->rx_tpa_bytes);
    5384                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_bytes,
    5385                 :            :                                       &prev_stats->rx_tpa_bytes);
    5386                 :            : 
    5387         [ #  # ]:          0 :                 ring_stats->rx_tpa_errors = rte_le_to_cpu_64(resp->rx_tpa_errors);
    5388                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_errors,
    5389                 :            :                                       &prev_stats->rx_tpa_errors);
    5390                 :            : 
    5391         [ #  # ]:          0 :                 ring_stats->rx_tpa_events = rte_le_to_cpu_64(resp->rx_tpa_events);
    5392                 :            :                 bnxt_update_prev_stat(&ring_stats->rx_tpa_events,
    5393                 :            :                                       &prev_stats->rx_tpa_events);
    5394                 :            :         } else {
    5395                 :          0 :                 struct bnxt_ring_stats_ext *prev_stats = &bp->prev_tx_ring_stats_ext[idx];
    5396                 :            : 
    5397         [ #  # ]:          0 :                 ring_stats->tx_ucast_pkts = rte_le_to_cpu_64(resp->tx_ucast_pkts);
    5398                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_ucast_pkts,
    5399                 :            :                                       &prev_stats->tx_ucast_pkts);
    5400                 :            : 
    5401         [ #  # ]:          0 :                 ring_stats->tx_mcast_pkts = rte_le_to_cpu_64(resp->tx_mcast_pkts);
    5402                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_mcast_pkts,
    5403                 :            :                                       &prev_stats->tx_mcast_pkts);
    5404                 :            : 
    5405         [ #  # ]:          0 :                 ring_stats->tx_bcast_pkts = rte_le_to_cpu_64(resp->tx_bcast_pkts);
    5406                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_bcast_pkts,
    5407                 :            :                                       &prev_stats->tx_bcast_pkts);
    5408                 :            : 
    5409         [ #  # ]:          0 :                 ring_stats->tx_ucast_bytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
    5410                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_ucast_bytes,
    5411                 :            :                                       &prev_stats->tx_ucast_bytes);
    5412                 :            : 
    5413         [ #  # ]:          0 :                 ring_stats->tx_mcast_bytes = rte_le_to_cpu_64(resp->tx_mcast_bytes);
    5414                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_mcast_bytes,
    5415                 :            :                                       &prev_stats->tx_mcast_bytes);
    5416                 :            : 
    5417         [ #  # ]:          0 :                 ring_stats->tx_bcast_bytes = rte_le_to_cpu_64(resp->tx_bcast_bytes);
    5418                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_bcast_bytes,
    5419                 :            :                                       &prev_stats->tx_bcast_bytes);
    5420                 :            : 
    5421         [ #  # ]:          0 :                 ring_stats->tx_discard_pkts = rte_le_to_cpu_64(resp->tx_discard_pkts);
    5422                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_discard_pkts,
    5423                 :            :                                       &prev_stats->tx_discard_pkts);
    5424                 :            : 
    5425         [ #  # ]:          0 :                 ring_stats->tx_error_pkts = rte_le_to_cpu_64(resp->tx_error_pkts);
    5426                 :            :                 bnxt_update_prev_stat(&ring_stats->tx_error_pkts,
    5427                 :            :                                       &prev_stats->tx_error_pkts);
    5428                 :            :         }
    5429                 :            : 
    5430                 :            :         HWRM_UNLOCK();
    5431                 :            : 
    5432                 :          0 :         return rc;
    5433                 :            : }
    5434                 :            : 
    5435                 :          0 : int bnxt_hwrm_port_qstats(struct bnxt *bp)
    5436                 :            : {
    5437                 :          0 :         struct hwrm_port_qstats_input req = {0};
    5438                 :          0 :         struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
    5439                 :          0 :         struct bnxt_pf_info *pf = bp->pf;
    5440                 :            :         int rc;
    5441                 :            : 
    5442         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_QSTATS, BNXT_USE_CHIMP_MB);
    5443                 :            : 
    5444                 :          0 :         req.port_id = rte_cpu_to_le_16(pf->port_id);
    5445                 :          0 :         req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
    5446                 :          0 :         req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
    5447                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5448                 :            : 
    5449   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5450                 :            :         HWRM_UNLOCK();
    5451                 :            : 
    5452                 :          0 :         return rc;
    5453                 :            : }
    5454                 :            : 
    5455                 :          0 : int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
    5456                 :            : {
    5457                 :          0 :         struct hwrm_port_clr_stats_input req = {0};
    5458                 :          0 :         struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
    5459                 :          0 :         struct bnxt_pf_info *pf = bp->pf;
    5460                 :            :         int rc;
    5461                 :            : 
    5462                 :            :         /* Not allowed on NS2 device, NPAR, MultiHost, VF */
    5463         [ #  # ]:          0 :         if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
    5464         [ #  # ]:          0 :             BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
    5465                 :            :                 return 0;
    5466                 :            : 
    5467         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
    5468                 :            : 
    5469                 :          0 :         req.port_id = rte_cpu_to_le_16(pf->port_id);
    5470                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5471                 :            : 
    5472   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5473                 :            :         HWRM_UNLOCK();
    5474                 :            : 
    5475                 :          0 :         return rc;
    5476                 :            : }
    5477                 :            : 
    5478                 :          0 : int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
    5479                 :            : {
    5480                 :          0 :         struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    5481                 :          0 :         struct hwrm_port_led_qcaps_input req = {0};
    5482                 :            :         int rc;
    5483                 :            : 
    5484         [ #  # ]:          0 :         if (BNXT_VF(bp))
    5485                 :            :                 return 0;
    5486                 :            : 
    5487         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
    5488                 :          0 :         req.port_id = bp->pf->port_id;
    5489                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5490                 :            : 
    5491   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    5492                 :            : 
    5493         [ #  # ]:          0 :         if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
    5494                 :            :                 unsigned int i;
    5495                 :            : 
    5496                 :          0 :                 bp->leds->num_leds = resp->num_leds;
    5497                 :          0 :                 memcpy(bp->leds, &resp->led0_id,
    5498                 :          0 :                         sizeof(bp->leds[0]) * bp->leds->num_leds);
    5499         [ #  # ]:          0 :                 for (i = 0; i < bp->leds->num_leds; i++) {
    5500                 :          0 :                         struct bnxt_led_info *led = &bp->leds[i];
    5501                 :            : 
    5502                 :          0 :                         uint16_t caps = led->led_state_caps;
    5503                 :            : 
    5504   [ #  #  #  # ]:          0 :                         if (!led->led_group_id ||
    5505                 :            :                                 !BNXT_LED_ALT_BLINK_CAP(caps)) {
    5506                 :          0 :                                 bp->leds->num_leds = 0;
    5507                 :          0 :                                 break;
    5508                 :            :                         }
    5509                 :            :                 }
    5510                 :            :         }
    5511                 :            : 
    5512                 :            :         HWRM_UNLOCK();
    5513                 :            : 
    5514                 :          0 :         return rc;
    5515                 :            : }
    5516                 :            : 
    5517                 :          0 : int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
    5518                 :            : {
    5519                 :          0 :         struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5520                 :          0 :         struct hwrm_port_led_cfg_input req = {0};
    5521                 :            :         struct bnxt_led_cfg *led_cfg;
    5522                 :            :         uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
    5523                 :            :         uint16_t duration = 0;
    5524                 :            :         int rc, i;
    5525                 :            : 
    5526   [ #  #  #  #  :          0 :         if (BNXT_VF(bp) || !bp->leds || !bp->leds->num_leds)
                   #  # ]
    5527                 :            :                 return -EOPNOTSUPP;
    5528                 :            : 
    5529   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
    5530                 :            : 
    5531         [ #  # ]:          0 :         if (led_on) {
    5532                 :            :                 led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
    5533                 :            :                 duration = rte_cpu_to_le_16(500);
    5534                 :            :         }
    5535                 :          0 :         req.port_id = bp->pf->port_id;
    5536                 :          0 :         req.num_leds = bp->leds->num_leds;
    5537                 :            :         led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
    5538         [ #  # ]:          0 :         for (i = 0; i < bp->leds->num_leds; i++, led_cfg++) {
    5539                 :          0 :                 req.enables |= BNXT_LED_DFLT_ENABLES(i);
    5540                 :          0 :                 led_cfg->led_id = bp->leds[i].led_id;
    5541                 :          0 :                 led_cfg->led_state = led_state;
    5542                 :          0 :                 led_cfg->led_blink_on = duration;
    5543                 :          0 :                 led_cfg->led_blink_off = duration;
    5544                 :          0 :                 led_cfg->led_group_id = bp->leds[i].led_group_id;
    5545                 :            :         }
    5546                 :            : 
    5547                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5548                 :            : 
    5549   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5550                 :            :         HWRM_UNLOCK();
    5551                 :            : 
    5552                 :          0 :         return rc;
    5553                 :            : }
    5554                 :            : 
    5555                 :          0 : int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
    5556                 :            :                                uint32_t *length)
    5557                 :            : {
    5558                 :            :         int rc;
    5559                 :          0 :         struct hwrm_nvm_get_dir_info_input req = {0};
    5560                 :          0 :         struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
    5561                 :            : 
    5562         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
    5563                 :            : 
    5564                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5565                 :            : 
    5566   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5567                 :            : 
    5568                 :          0 :         *entries = rte_le_to_cpu_32(resp->entries);
    5569                 :          0 :         *length = rte_le_to_cpu_32(resp->entry_length);
    5570                 :            : 
    5571                 :            :         HWRM_UNLOCK();
    5572                 :          0 :         return rc;
    5573                 :            : }
    5574                 :            : 
    5575                 :          0 : int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
    5576                 :            : {
    5577                 :            :         int rc;
    5578                 :            :         uint32_t dir_entries;
    5579                 :            :         uint32_t entry_length;
    5580                 :            :         uint8_t *buf;
    5581                 :            :         size_t buflen;
    5582                 :            :         rte_iova_t dma_handle;
    5583                 :          0 :         struct hwrm_nvm_get_dir_entries_input req = {0};
    5584                 :          0 :         struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
    5585                 :            : 
    5586                 :          0 :         rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
    5587         [ #  # ]:          0 :         if (rc != 0)
    5588                 :            :                 return rc;
    5589                 :            : 
    5590                 :          0 :         *data++ = dir_entries;
    5591                 :          0 :         *data++ = entry_length;
    5592                 :          0 :         len -= 2;
    5593                 :          0 :         memset(data, 0xff, len);
    5594                 :            : 
    5595                 :          0 :         buflen = dir_entries * entry_length;
    5596                 :          0 :         buf = rte_malloc("nvm_dir", buflen, 0);
    5597         [ #  # ]:          0 :         if (buf == NULL)
    5598                 :            :                 return -ENOMEM;
    5599                 :          0 :         dma_handle = rte_malloc_virt2iova(buf);
    5600         [ #  # ]:          0 :         if (dma_handle == RTE_BAD_IOVA) {
    5601                 :          0 :                 rte_free(buf);
    5602                 :          0 :                 PMD_DRV_LOG(ERR,
    5603                 :            :                         "unable to map response address to physical memory\n");
    5604                 :          0 :                 return -ENOMEM;
    5605                 :            :         }
    5606         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
    5607                 :          0 :         req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
    5608                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5609                 :            : 
    5610         [ #  # ]:          0 :         if (rc == 0)
    5611                 :          0 :                 memcpy(data, buf, len > buflen ? buflen : len);
    5612                 :            : 
    5613                 :          0 :         rte_free(buf);
    5614   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5615                 :            :         HWRM_UNLOCK();
    5616                 :            : 
    5617                 :          0 :         return rc;
    5618                 :            : }
    5619                 :            : 
    5620                 :          0 : int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
    5621                 :            :                              uint32_t offset, uint32_t length,
    5622                 :            :                              uint8_t *data)
    5623                 :            : {
    5624                 :            :         int rc;
    5625                 :            :         uint8_t *buf;
    5626                 :            :         rte_iova_t dma_handle;
    5627                 :          0 :         struct hwrm_nvm_read_input req = {0};
    5628                 :          0 :         struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
    5629                 :            : 
    5630                 :          0 :         buf = rte_malloc("nvm_item", length, 0);
    5631         [ #  # ]:          0 :         if (!buf)
    5632                 :            :                 return -ENOMEM;
    5633                 :            : 
    5634                 :          0 :         dma_handle = rte_malloc_virt2iova(buf);
    5635         [ #  # ]:          0 :         if (dma_handle == RTE_BAD_IOVA) {
    5636                 :          0 :                 rte_free(buf);
    5637                 :          0 :                 PMD_DRV_LOG(ERR,
    5638                 :            :                         "unable to map response address to physical memory\n");
    5639                 :          0 :                 return -ENOMEM;
    5640                 :            :         }
    5641         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_NVM_READ, BNXT_USE_CHIMP_MB);
    5642                 :          0 :         req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
    5643                 :          0 :         req.dir_idx = rte_cpu_to_le_16(index);
    5644                 :          0 :         req.offset = rte_cpu_to_le_32(offset);
    5645                 :          0 :         req.len = rte_cpu_to_le_32(length);
    5646                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5647         [ #  # ]:          0 :         if (rc == 0)
    5648                 :            :                 memcpy(data, buf, length);
    5649                 :            : 
    5650                 :          0 :         rte_free(buf);
    5651   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5652                 :            :         HWRM_UNLOCK();
    5653                 :            : 
    5654                 :          0 :         return rc;
    5655                 :            : }
    5656                 :            : 
    5657                 :          0 : int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
    5658                 :            : {
    5659                 :            :         int rc;
    5660                 :          0 :         struct hwrm_nvm_erase_dir_entry_input req = {0};
    5661                 :          0 :         struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
    5662                 :            : 
    5663         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
    5664                 :          0 :         req.dir_idx = rte_cpu_to_le_16(index);
    5665                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5666   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5667                 :            :         HWRM_UNLOCK();
    5668                 :            : 
    5669                 :          0 :         return rc;
    5670                 :            : }
    5671                 :            : 
    5672                 :          0 : int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
    5673                 :            :                           uint16_t dir_ordinal, uint16_t dir_ext,
    5674                 :            :                           uint16_t dir_attr, const uint8_t *data,
    5675                 :            :                           size_t data_len)
    5676                 :            : {
    5677                 :            :         int rc;
    5678                 :          0 :         struct hwrm_nvm_write_input req = {0};
    5679                 :          0 :         struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
    5680                 :            :         rte_iova_t dma_handle;
    5681                 :            :         uint8_t *buf;
    5682                 :            : 
    5683                 :          0 :         buf = rte_malloc("nvm_write", data_len, 0);
    5684         [ #  # ]:          0 :         if (!buf)
    5685                 :            :                 return -ENOMEM;
    5686                 :            : 
    5687                 :          0 :         dma_handle = rte_malloc_virt2iova(buf);
    5688         [ #  # ]:          0 :         if (dma_handle == RTE_BAD_IOVA) {
    5689                 :          0 :                 rte_free(buf);
    5690                 :          0 :                 PMD_DRV_LOG(ERR,
    5691                 :            :                         "unable to map response address to physical memory\n");
    5692                 :          0 :                 return -ENOMEM;
    5693                 :            :         }
    5694                 :            :         memcpy(buf, data, data_len);
    5695                 :            : 
    5696         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_NVM_WRITE, BNXT_USE_CHIMP_MB);
    5697                 :            : 
    5698                 :          0 :         req.dir_type = rte_cpu_to_le_16(dir_type);
    5699                 :          0 :         req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
    5700                 :          0 :         req.dir_ext = rte_cpu_to_le_16(dir_ext);
    5701                 :          0 :         req.dir_attr = rte_cpu_to_le_16(dir_attr);
    5702                 :          0 :         req.dir_data_length = rte_cpu_to_le_32(data_len);
    5703                 :          0 :         req.host_src_addr = rte_cpu_to_le_64(dma_handle);
    5704                 :            : 
    5705                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5706                 :            : 
    5707                 :          0 :         rte_free(buf);
    5708   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5709                 :            :         HWRM_UNLOCK();
    5710                 :            : 
    5711                 :          0 :         return rc;
    5712                 :            : }
    5713                 :            : 
    5714                 :            : static void
    5715                 :          0 : bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
    5716                 :            : {
    5717                 :            :         uint32_t *count = cbdata;
    5718                 :            : 
    5719                 :          0 :         *count = *count + 1;
    5720                 :          0 : }
    5721                 :            : 
    5722                 :          0 : static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
    5723                 :            :                                      struct bnxt_vnic_info *vnic __rte_unused)
    5724                 :            : {
    5725                 :          0 :         return 0;
    5726                 :            : }
    5727                 :            : 
    5728                 :          0 : int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
    5729                 :            : {
    5730                 :          0 :         uint32_t count = 0;
    5731                 :            : 
    5732                 :          0 :         bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
    5733                 :            :             &count, bnxt_vnic_count_hwrm_stub);
    5734                 :            : 
    5735                 :          0 :         return count;
    5736                 :            : }
    5737                 :            : 
    5738                 :          0 : static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
    5739                 :            :                                         uint16_t *vnic_ids)
    5740                 :            : {
    5741                 :          0 :         struct hwrm_func_vf_vnic_ids_query_input req = {0};
    5742                 :          0 :         struct hwrm_func_vf_vnic_ids_query_output *resp =
    5743                 :            :                                                 bp->hwrm_cmd_resp_addr;
    5744                 :            :         int rc;
    5745                 :            : 
    5746                 :            :         /* First query all VNIC ids */
    5747         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
    5748                 :            : 
    5749                 :          0 :         req.vf_id = rte_cpu_to_le_16(bp->pf->first_vf_id + vf);
    5750                 :          0 :         req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf->total_vnics);
    5751                 :          0 :         req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_malloc_virt2iova(vnic_ids));
    5752                 :            : 
    5753         [ #  # ]:          0 :         if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
    5754                 :            :                 HWRM_UNLOCK();
    5755                 :          0 :                 PMD_DRV_LOG(ERR,
    5756                 :            :                 "unable to map VNIC ID table address to physical memory\n");
    5757                 :          0 :                 return -ENOMEM;
    5758                 :            :         }
    5759                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5760   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5761                 :          0 :         rc = rte_le_to_cpu_32(resp->vnic_id_cnt);
    5762                 :            : 
    5763                 :            :         HWRM_UNLOCK();
    5764                 :            : 
    5765                 :          0 :         return rc;
    5766                 :            : }
    5767                 :            : 
    5768                 :            : /*
    5769                 :            :  * This function queries the VNIC IDs  for a specified VF. It then calls
    5770                 :            :  * the vnic_cb to update the necessary field in vnic_info with cbdata.
    5771                 :            :  * Then it calls the hwrm_cb function to program this new vnic configuration.
    5772                 :            :  */
    5773                 :          0 : int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
    5774                 :            :         void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
    5775                 :            :         int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
    5776                 :            : {
    5777                 :            :         struct bnxt_vnic_info vnic;
    5778                 :            :         int rc = 0;
    5779                 :            :         int i, num_vnic_ids;
    5780                 :            :         uint16_t *vnic_ids;
    5781                 :            :         size_t vnic_id_sz;
    5782                 :            :         size_t sz;
    5783                 :            : 
    5784                 :            :         /* First query all VNIC ids */
    5785                 :          0 :         vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
    5786                 :          0 :         vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
    5787                 :            :                         RTE_CACHE_LINE_SIZE);
    5788         [ #  # ]:          0 :         if (vnic_ids == NULL)
    5789                 :            :                 return -ENOMEM;
    5790                 :            : 
    5791         [ #  # ]:          0 :         for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
    5792                 :          0 :                 rte_mem_lock_page(((char *)vnic_ids) + sz);
    5793                 :            : 
    5794                 :          0 :         num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
    5795                 :            : 
    5796         [ #  # ]:          0 :         if (num_vnic_ids < 0)
    5797                 :            :                 return num_vnic_ids;
    5798                 :            : 
    5799                 :            :         /* Retrieve VNIC, update bd_stall then update */
    5800                 :            : 
    5801         [ #  # ]:          0 :         for (i = 0; i < num_vnic_ids; i++) {
    5802                 :            :                 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
    5803                 :          0 :                 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
    5804                 :          0 :                 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf->first_vf_id + vf);
    5805         [ #  # ]:          0 :                 if (rc)
    5806                 :            :                         break;
    5807         [ #  # ]:          0 :                 if (vnic.mru <= 4)   /* Indicates unallocated */
    5808                 :          0 :                         continue;
    5809                 :            : 
    5810                 :          0 :                 vnic_cb(&vnic, cbdata);
    5811                 :            : 
    5812                 :          0 :                 rc = hwrm_cb(bp, &vnic);
    5813         [ #  # ]:          0 :                 if (rc)
    5814                 :            :                         break;
    5815                 :            :         }
    5816                 :            : 
    5817                 :          0 :         rte_free(vnic_ids);
    5818                 :            : 
    5819                 :          0 :         return rc;
    5820                 :            : }
    5821                 :            : 
    5822                 :          0 : int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
    5823                 :            :                                               bool on)
    5824                 :            : {
    5825                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    5826                 :          0 :         struct hwrm_func_cfg_input req = {0};
    5827                 :            :         int rc;
    5828                 :            : 
    5829   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    5830                 :            : 
    5831                 :          0 :         req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
    5832                 :          0 :         req.enables |= rte_cpu_to_le_32(
    5833                 :            :                         HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
    5834         [ #  # ]:          0 :         req.vlan_antispoof_mode = on ?
    5835                 :            :                 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
    5836                 :            :                 HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
    5837                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    5838                 :            : 
    5839   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5840                 :            :         HWRM_UNLOCK();
    5841                 :            : 
    5842                 :          0 :         return rc;
    5843                 :            : }
    5844                 :            : 
    5845                 :          0 : int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
    5846                 :            : {
    5847                 :            :         struct bnxt_vnic_info vnic;
    5848                 :            :         uint16_t *vnic_ids;
    5849                 :            :         size_t vnic_id_sz;
    5850                 :            :         int num_vnic_ids, i;
    5851                 :            :         size_t sz;
    5852                 :            :         int rc;
    5853                 :            : 
    5854                 :          0 :         vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
    5855                 :          0 :         vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
    5856                 :            :                         RTE_CACHE_LINE_SIZE);
    5857         [ #  # ]:          0 :         if (vnic_ids == NULL)
    5858                 :            :                 return -ENOMEM;
    5859                 :            : 
    5860         [ #  # ]:          0 :         for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
    5861                 :          0 :                 rte_mem_lock_page(((char *)vnic_ids) + sz);
    5862                 :            : 
    5863                 :          0 :         rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
    5864         [ #  # ]:          0 :         if (rc <= 0)
    5865                 :          0 :                 goto exit;
    5866                 :            :         num_vnic_ids = rc;
    5867                 :            : 
    5868                 :            :         /*
    5869                 :            :          * Loop through to find the default VNIC ID.
    5870                 :            :          * TODO: The easier way would be to obtain the resp->dflt_vnic_id
    5871                 :            :          * by sending the hwrm_func_qcfg command to the firmware.
    5872                 :            :          */
    5873         [ #  # ]:          0 :         for (i = 0; i < num_vnic_ids; i++) {
    5874                 :            :                 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
    5875                 :          0 :                 vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
    5876                 :          0 :                 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
    5877                 :          0 :                                         bp->pf->first_vf_id + vf);
    5878         [ #  # ]:          0 :                 if (rc)
    5879                 :          0 :                         goto exit;
    5880         [ #  # ]:          0 :                 if (vnic.func_default) {
    5881                 :          0 :                         rte_free(vnic_ids);
    5882                 :          0 :                         return vnic.fw_vnic_id;
    5883                 :            :                 }
    5884                 :            :         }
    5885                 :            :         /* Could not find a default VNIC. */
    5886                 :          0 :         PMD_DRV_LOG(ERR, "No default VNIC\n");
    5887                 :          0 : exit:
    5888                 :          0 :         rte_free(vnic_ids);
    5889                 :          0 :         return rc;
    5890                 :            : }
    5891                 :            : 
    5892                 :          0 : int bnxt_hwrm_set_em_filter(struct bnxt *bp,
    5893                 :            :                          uint16_t dst_id,
    5894                 :            :                          struct bnxt_filter_info *filter)
    5895                 :            : {
    5896                 :            :         int rc = 0;
    5897                 :          0 :         struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
    5898                 :          0 :         struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    5899                 :            :         uint32_t enables = 0;
    5900                 :            : 
    5901         [ #  # ]:          0 :         if (filter->fw_em_filter_id != UINT64_MAX)
    5902                 :          0 :                 bnxt_hwrm_clear_em_filter(bp, filter);
    5903                 :            : 
    5904   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
    5905                 :            : 
    5906                 :          0 :         req.flags = rte_cpu_to_le_32(filter->flags);
    5907                 :            : 
    5908                 :          0 :         enables = filter->enables |
    5909                 :            :               HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
    5910                 :          0 :         req.dst_id = rte_cpu_to_le_16(dst_id);
    5911                 :            : 
    5912         [ #  # ]:          0 :         if (filter->ip_addr_type) {
    5913                 :          0 :                 req.ip_addr_type = filter->ip_addr_type;
    5914                 :          0 :                 enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
    5915                 :            :         }
    5916         [ #  # ]:          0 :         if (enables &
    5917                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
    5918                 :          0 :                 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
    5919         [ #  # ]:          0 :         if (enables &
    5920                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
    5921                 :            :                 memcpy(req.src_macaddr, filter->src_macaddr,
    5922                 :            :                        RTE_ETHER_ADDR_LEN);
    5923         [ #  # ]:          0 :         if (enables &
    5924                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
    5925                 :            :                 memcpy(req.dst_macaddr, filter->dst_macaddr,
    5926                 :            :                        RTE_ETHER_ADDR_LEN);
    5927         [ #  # ]:          0 :         if (enables &
    5928                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
    5929                 :          0 :                 req.ovlan_vid = filter->l2_ovlan;
    5930         [ #  # ]:          0 :         if (enables &
    5931                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
    5932                 :          0 :                 req.ivlan_vid = filter->l2_ivlan;
    5933         [ #  # ]:          0 :         if (enables &
    5934                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
    5935         [ #  # ]:          0 :                 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
    5936         [ #  # ]:          0 :         if (enables &
    5937                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
    5938                 :          0 :                 req.ip_protocol = filter->ip_protocol;
    5939         [ #  # ]:          0 :         if (enables &
    5940                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
    5941         [ #  # ]:          0 :                 req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
    5942         [ #  # ]:          0 :         if (enables &
    5943                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
    5944         [ #  # ]:          0 :                 req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
    5945         [ #  # ]:          0 :         if (enables &
    5946                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
    5947         [ #  # ]:          0 :                 req.src_port = rte_cpu_to_be_16(filter->src_port);
    5948         [ #  # ]:          0 :         if (enables &
    5949                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
    5950         [ #  # ]:          0 :                 req.dst_port = rte_cpu_to_be_16(filter->dst_port);
    5951         [ #  # ]:          0 :         if (enables &
    5952                 :            :             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
    5953                 :          0 :                 req.mirror_vnic_id = filter->mirror_vnic_id;
    5954                 :            : 
    5955                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    5956                 :            : 
    5957                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    5958                 :            : 
    5959   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5960                 :            : 
    5961                 :          0 :         filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
    5962                 :            :         HWRM_UNLOCK();
    5963                 :            : 
    5964                 :          0 :         return rc;
    5965                 :            : }
    5966                 :            : 
    5967                 :          0 : int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
    5968                 :            : {
    5969                 :            :         int rc = 0;
    5970                 :          0 :         struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
    5971                 :          0 :         struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
    5972                 :            : 
    5973         [ #  # ]:          0 :         if (filter->fw_em_filter_id == UINT64_MAX)
    5974                 :            :                 return 0;
    5975                 :            : 
    5976   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
    5977                 :            : 
    5978                 :          0 :         req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
    5979                 :            : 
    5980                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    5981                 :            : 
    5982   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    5983                 :            :         HWRM_UNLOCK();
    5984                 :            : 
    5985                 :          0 :         filter->fw_em_filter_id = UINT64_MAX;
    5986                 :          0 :         filter->fw_l2_filter_id = UINT64_MAX;
    5987                 :            : 
    5988                 :          0 :         return 0;
    5989                 :            : }
    5990                 :            : 
    5991                 :          0 : int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
    5992                 :            :                          uint16_t dst_id,
    5993                 :            :                          struct bnxt_filter_info *filter)
    5994                 :            : {
    5995                 :            :         int rc = 0;
    5996                 :          0 :         struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
    5997                 :          0 :         struct hwrm_cfa_ntuple_filter_alloc_output *resp =
    5998                 :            :                                                 bp->hwrm_cmd_resp_addr;
    5999                 :            :         uint32_t enables = 0;
    6000                 :            : 
    6001         [ #  # ]:          0 :         if (filter->fw_ntuple_filter_id != UINT64_MAX)
    6002                 :          0 :                 bnxt_hwrm_clear_ntuple_filter(bp, filter);
    6003                 :            : 
    6004   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
    6005                 :            : 
    6006                 :          0 :         req.flags = rte_cpu_to_le_32(filter->flags);
    6007                 :            : 
    6008                 :          0 :         enables = filter->enables |
    6009                 :            :               HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
    6010                 :          0 :         req.dst_id = rte_cpu_to_le_16(dst_id);
    6011                 :            : 
    6012         [ #  # ]:          0 :         if (filter->ip_addr_type) {
    6013                 :          0 :                 req.ip_addr_type = filter->ip_addr_type;
    6014                 :          0 :                 enables |=
    6015                 :            :                         HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
    6016                 :            :         }
    6017         [ #  # ]:          0 :         if (enables &
    6018                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
    6019                 :          0 :                 req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
    6020         [ #  # ]:          0 :         if (enables &
    6021                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
    6022                 :            :                 memcpy(req.src_macaddr, filter->src_macaddr,
    6023                 :            :                        RTE_ETHER_ADDR_LEN);
    6024         [ #  # ]:          0 :         if (enables &
    6025                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
    6026         [ #  # ]:          0 :                 req.ethertype = rte_cpu_to_be_16(filter->ethertype);
    6027         [ #  # ]:          0 :         if (enables &
    6028                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
    6029                 :          0 :                 req.ip_protocol = filter->ip_protocol;
    6030         [ #  # ]:          0 :         if (enables &
    6031                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
    6032                 :          0 :                 req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
    6033         [ #  # ]:          0 :         if (enables &
    6034                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
    6035                 :          0 :                 req.src_ipaddr_mask[0] =
    6036                 :          0 :                         rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
    6037         [ #  # ]:          0 :         if (enables &
    6038                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
    6039                 :          0 :                 req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
    6040         [ #  # ]:          0 :         if (enables &
    6041                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
    6042                 :          0 :                 req.dst_ipaddr_mask[0] =
    6043         [ #  # ]:          0 :                         rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
    6044         [ #  # ]:          0 :         if (enables &
    6045                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
    6046                 :          0 :                 req.src_port = rte_cpu_to_le_16(filter->src_port);
    6047         [ #  # ]:          0 :         if (enables &
    6048                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
    6049                 :          0 :                 req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
    6050         [ #  # ]:          0 :         if (enables &
    6051                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
    6052                 :          0 :                 req.dst_port = rte_cpu_to_le_16(filter->dst_port);
    6053         [ #  # ]:          0 :         if (enables &
    6054                 :            :             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
    6055                 :          0 :                 req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
    6056                 :            : 
    6057                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    6058                 :            : 
    6059                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6060                 :            : 
    6061   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6062                 :            : 
    6063                 :          0 :         filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
    6064                 :          0 :         filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
    6065                 :            :         HWRM_UNLOCK();
    6066                 :            : 
    6067                 :          0 :         return rc;
    6068                 :            : }
    6069                 :            : 
    6070                 :          0 : int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
    6071                 :            :                                 struct bnxt_filter_info *filter)
    6072                 :            : {
    6073                 :            :         int rc = 0;
    6074                 :          0 :         struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
    6075                 :          0 :         struct hwrm_cfa_ntuple_filter_free_output *resp =
    6076                 :            :                                                 bp->hwrm_cmd_resp_addr;
    6077                 :            : 
    6078         [ #  # ]:          0 :         if (filter->fw_ntuple_filter_id == UINT64_MAX)
    6079                 :            :                 return 0;
    6080                 :            : 
    6081         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
    6082                 :            : 
    6083                 :          0 :         req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
    6084                 :            : 
    6085                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6086                 :            : 
    6087   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6088                 :            :         HWRM_UNLOCK();
    6089                 :            : 
    6090                 :          0 :         filter->fw_ntuple_filter_id = UINT64_MAX;
    6091                 :            : 
    6092                 :          0 :         return 0;
    6093                 :            : }
    6094                 :            : 
    6095                 :            : int
    6096                 :          0 : bnxt_vnic_rss_configure_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    6097                 :            : {
    6098                 :          0 :         struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    6099                 :          0 :         uint8_t *rxq_state = bp->eth_dev->data->rx_queue_state;
    6100                 :          0 :         struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
    6101                 :          0 :         struct bnxt_rx_queue **rxqs = bp->rx_queues;
    6102                 :          0 :         uint16_t *ring_tbl = vnic->rss_table;
    6103                 :          0 :         int nr_ctxs = vnic->num_lb_ctxts;
    6104                 :          0 :         int max_rings = bp->rx_nr_rings;
    6105                 :            :         int i, j, k, cnt;
    6106                 :            :         int rc = 0;
    6107                 :            : 
    6108         [ #  # ]:          0 :         for (i = 0, k = 0; i < nr_ctxs; i++) {
    6109                 :            :                 struct bnxt_rx_ring_info *rxr;
    6110                 :            :                 struct bnxt_cp_ring_info *cpr;
    6111                 :            : 
    6112         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
    6113                 :            : 
    6114                 :          0 :                 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    6115                 :          0 :                 req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
    6116                 :          0 :                 req.hash_mode_flags = vnic->hash_mode;
    6117                 :          0 :                 req.ring_select_mode = vnic->ring_select_mode;
    6118                 :            : 
    6119                 :          0 :                 req.ring_grp_tbl_addr =
    6120                 :          0 :                     rte_cpu_to_le_64(vnic->rss_table_dma_addr +
    6121                 :            :                                      i * BNXT_RSS_ENTRIES_PER_CTX_P5 *
    6122                 :            :                                      2 * sizeof(*ring_tbl));
    6123                 :          0 :                 req.hash_key_tbl_addr =
    6124                 :          0 :                     rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
    6125                 :            : 
    6126                 :          0 :                 req.ring_table_pair_index = i;
    6127                 :          0 :                 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
    6128                 :            : 
    6129         [ #  # ]:          0 :                 for (j = 0; j < 64; j++) {
    6130                 :            :                         uint16_t ring_id;
    6131                 :            : 
    6132                 :            :                         /* Find next active ring. */
    6133         [ #  # ]:          0 :                         for (cnt = 0; cnt < max_rings; cnt++) {
    6134         [ #  # ]:          0 :                                 if (rxq_state[k] != RTE_ETH_QUEUE_STATE_STOPPED)
    6135                 :            :                                         break;
    6136         [ #  # ]:          0 :                                 if (++k == max_rings)
    6137                 :            :                                         k = 0;
    6138                 :            :                         }
    6139                 :            : 
    6140                 :            :                         /* Return if no rings are active. */
    6141         [ #  # ]:          0 :                         if (cnt == max_rings) {
    6142                 :            :                                 HWRM_UNLOCK();
    6143                 :          0 :                                 return 0;
    6144                 :            :                         }
    6145                 :            : 
    6146                 :            :                         /* Add rx/cp ring pair to RSS table. */
    6147                 :          0 :                         rxr = rxqs[k]->rx_ring;
    6148                 :          0 :                         cpr = rxqs[k]->cp_ring;
    6149                 :            : 
    6150                 :          0 :                         ring_id = rxr->rx_ring_struct->fw_ring_id;
    6151                 :          0 :                         *ring_tbl++ = rte_cpu_to_le_16(ring_id);
    6152                 :          0 :                         ring_id = cpr->cp_ring_struct->fw_ring_id;
    6153                 :          0 :                         *ring_tbl++ = rte_cpu_to_le_16(ring_id);
    6154                 :            : 
    6155         [ #  # ]:          0 :                         if (++k == max_rings)
    6156                 :            :                                 k = 0;
    6157                 :            :                 }
    6158                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
    6159                 :            :                                             BNXT_USE_CHIMP_MB);
    6160                 :            : 
    6161   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6162                 :            :                 HWRM_UNLOCK();
    6163                 :            :         }
    6164                 :            : 
    6165                 :            :         return rc;
    6166                 :            : }
    6167                 :            : 
    6168                 :          0 : int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    6169                 :            : {
    6170                 :            :         unsigned int rss_idx, fw_idx, i;
    6171                 :            : 
    6172         [ #  # ]:          0 :         if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
    6173                 :            :                 return 0;
    6174                 :            : 
    6175   [ #  #  #  # ]:          0 :         if (!(vnic->rss_table && vnic->hash_type))
    6176                 :            :                 return 0;
    6177                 :            : 
    6178         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp))
    6179                 :          0 :                 return bnxt_vnic_rss_configure_p5(bp, vnic);
    6180                 :            : 
    6181                 :            :         /*
    6182                 :            :          * Fill the RSS hash & redirection table with
    6183                 :            :          * ring group ids for all VNICs
    6184                 :            :          */
    6185         [ #  # ]:          0 :         for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
    6186                 :          0 :              rss_idx++, fw_idx++) {
    6187         [ #  # ]:          0 :                 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
    6188                 :          0 :                         fw_idx %= bp->rx_cp_nr_rings;
    6189         [ #  # ]:          0 :                         if (vnic->fw_grp_ids[fw_idx] != INVALID_HW_RING_ID)
    6190                 :            :                                 break;
    6191                 :          0 :                         fw_idx++;
    6192                 :            :                 }
    6193                 :            : 
    6194         [ #  # ]:          0 :                 if (i == bp->rx_cp_nr_rings)
    6195                 :            :                         return 0;
    6196                 :            : 
    6197                 :          0 :                 vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
    6198                 :            :         }
    6199                 :            : 
    6200                 :          0 :         return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
    6201                 :            : }
    6202                 :            : 
    6203                 :            : static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
    6204                 :            :         struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
    6205                 :            : {
    6206                 :            :         uint16_t flags;
    6207                 :            : 
    6208                 :          0 :         req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
    6209                 :            : 
    6210                 :            :         /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
    6211                 :          0 :         req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
    6212                 :            : 
    6213                 :            :         /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
    6214                 :          0 :         req->num_cmpl_dma_aggr_during_int =
    6215                 :          0 :                 rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
    6216                 :            : 
    6217                 :          0 :         req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
    6218                 :            : 
    6219                 :            :         /* min timer set to 1/2 of interrupt timer */
    6220                 :          0 :         req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
    6221                 :            : 
    6222                 :            :         /* buf timer set to 1/4 of interrupt timer */
    6223                 :          0 :         req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
    6224                 :            : 
    6225                 :          0 :         req->cmpl_aggr_dma_tmr_during_int =
    6226                 :          0 :                 rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
    6227                 :            : 
    6228                 :            :         flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
    6229                 :            :                 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
    6230                 :          0 :         req->flags = rte_cpu_to_le_16(flags);
    6231                 :          0 : }
    6232                 :            : 
    6233                 :          0 : static int bnxt_hwrm_set_coal_params_p5(struct bnxt *bp,
    6234                 :            :                 struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
    6235                 :            : {
    6236                 :          0 :         struct hwrm_ring_aggint_qcaps_input req = {0};
    6237                 :          0 :         struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    6238                 :            :         uint32_t enables;
    6239                 :            :         uint16_t flags;
    6240                 :            :         int rc;
    6241                 :            : 
    6242         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
    6243                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6244   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6245                 :            : 
    6246                 :          0 :         agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
    6247                 :          0 :         agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
    6248                 :            : 
    6249                 :            :         flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
    6250                 :            :                 HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
    6251                 :          0 :         agg_req->flags = rte_cpu_to_le_16(flags);
    6252                 :            :         enables =
    6253                 :            :          HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
    6254                 :            :          HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
    6255                 :          0 :         agg_req->enables = rte_cpu_to_le_32(enables);
    6256                 :            : 
    6257                 :            :         HWRM_UNLOCK();
    6258                 :          0 :         return rc;
    6259                 :            : }
    6260                 :            : 
    6261                 :          0 : int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
    6262                 :            :                         struct bnxt_coal *coal, uint16_t ring_id)
    6263                 :            : {
    6264                 :          0 :         struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
    6265                 :          0 :         struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
    6266                 :            :                                                 bp->hwrm_cmd_resp_addr;
    6267                 :            :         int rc;
    6268                 :            : 
    6269                 :            :         /* Set ring coalesce parameters only for 100G NICs */
    6270         [ #  # ]:          0 :         if (BNXT_CHIP_P5_P7(bp)) {
    6271         [ #  # ]:          0 :                 if (bnxt_hwrm_set_coal_params_p5(bp, &req))
    6272                 :            :                         return -1;
    6273         [ #  # ]:          0 :         } else if (bnxt_stratus_device(bp)) {
    6274                 :            :                 bnxt_hwrm_set_coal_params(coal, &req);
    6275                 :            :         } else {
    6276                 :            :                 return 0;
    6277                 :            :         }
    6278                 :            : 
    6279         [ #  # ]:          0 :         HWRM_PREP(&req,
    6280                 :            :                   HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
    6281                 :            :                   BNXT_USE_CHIMP_MB);
    6282                 :          0 :         req.ring_id = rte_cpu_to_le_16(ring_id);
    6283                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6284   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6285                 :            :         HWRM_UNLOCK();
    6286                 :          0 :         return 0;
    6287                 :            : }
    6288                 :            : 
    6289                 :            : static void bnxt_init_ctx_initializer(struct bnxt_ctx_mem *ctxm,
    6290                 :            :                                       uint8_t init_val,
    6291                 :            :                                       uint8_t init_offset,
    6292                 :            :                                       bool init_mask_set)
    6293                 :            : {
    6294                 :          0 :         ctxm->init_value = init_val;
    6295                 :          0 :         ctxm->init_offset = BNXT_CTX_INIT_INVALID_OFFSET;
    6296                 :          0 :         if (init_mask_set)
    6297                 :          0 :                 ctxm->init_offset = init_offset * 4;
    6298                 :            :         else
    6299                 :          0 :                 ctxm->init_value = 0;
    6300                 :            : }
    6301                 :            : 
    6302                 :          0 : static int bnxt_alloc_all_ctx_pg_info(struct bnxt *bp)
    6303                 :            : {
    6304                 :          0 :         struct bnxt_ctx_mem_info *ctx = bp->ctx;
    6305                 :            :         char name[RTE_MEMZONE_NAMESIZE];
    6306                 :            :         uint16_t type;
    6307                 :            : 
    6308         [ #  # ]:          0 :         for (type = 0; type < ctx->types; type++) {
    6309                 :          0 :                 struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[type];
    6310                 :            :                 int n = 1;
    6311                 :            : 
    6312   [ #  #  #  # ]:          0 :                 if (!ctxm->max_entries || ctxm->pg_info)
    6313                 :          0 :                         continue;
    6314                 :            : 
    6315         [ #  # ]:          0 :                 if (ctxm->instance_bmap)
    6316                 :          0 :                         n = hweight32(ctxm->instance_bmap);
    6317                 :            : 
    6318                 :          0 :                 sprintf(name, "bnxt_ctx_pgmem_%d_%d",
    6319                 :          0 :                         bp->eth_dev->data->port_id, type);
    6320                 :          0 :                 ctxm->pg_info = rte_malloc(name, sizeof(*ctxm->pg_info) * n,
    6321                 :            :                                            RTE_CACHE_LINE_SIZE);
    6322         [ #  # ]:          0 :                 if (!ctxm->pg_info)
    6323                 :            :                         return -ENOMEM;
    6324                 :            :         }
    6325                 :            :         return 0;
    6326                 :            : }
    6327                 :            : 
    6328                 :            : static void bnxt_init_ctx_v2_driver_managed(struct bnxt *bp __rte_unused,
    6329                 :            :                                             struct bnxt_ctx_mem *ctxm)
    6330                 :            : {
    6331         [ #  # ]:          0 :         switch (ctxm->type) {
    6332                 :          0 :         case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_SQ_DB_SHADOW:
    6333                 :            :         case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_RQ_DB_SHADOW:
    6334                 :            :         case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_SRQ_DB_SHADOW:
    6335                 :            :         case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_CQ_DB_SHADOW:
    6336                 :            :                 /* FALLTHROUGH */
    6337                 :          0 :                 ctxm->entry_size = 0;
    6338                 :          0 :                 ctxm->min_entries = 1;
    6339                 :          0 :                 ctxm->max_entries = 1;
    6340                 :          0 :                 break;
    6341                 :            :         }
    6342                 :            : }
    6343                 :            : 
    6344                 :          0 : int bnxt_hwrm_func_backing_store_qcaps_v2(struct bnxt *bp)
    6345                 :            : {
    6346                 :          0 :         struct hwrm_func_backing_store_qcaps_v2_input req = {0};
    6347                 :          0 :         struct hwrm_func_backing_store_qcaps_v2_output *resp =
    6348                 :            :                 bp->hwrm_cmd_resp_addr;
    6349                 :          0 :         struct bnxt_ctx_mem_info *ctx = bp->ctx;
    6350                 :            :         uint16_t last_valid_type = BNXT_CTX_INV;
    6351                 :            :         uint16_t last_valid_idx = 0;
    6352                 :            :         uint16_t types, type;
    6353                 :            :         int rc;
    6354                 :            : 
    6355   [ #  #  #  # ]:          0 :         for (types = 0, type = 0; types < bp->ctx->types && type != BNXT_CTX_INV; types++) {
    6356                 :          0 :                 struct bnxt_ctx_mem *ctxm = &bp->ctx->ctx_arr[types];
    6357                 :            :                 uint8_t init_val, init_off, i;
    6358                 :            :                 uint32_t *p;
    6359                 :            :                 uint32_t flags;
    6360                 :            : 
    6361         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS_V2, BNXT_USE_CHIMP_MB);
    6362                 :          0 :                 req.type = rte_cpu_to_le_16(type);
    6363                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6364   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6365                 :            : 
    6366                 :          0 :                 flags = rte_le_to_cpu_32(resp->flags);
    6367                 :          0 :                 type = rte_le_to_cpu_16(resp->next_valid_type);
    6368         [ #  # ]:          0 :                 if (!(flags & HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_TYPE_VALID))
    6369                 :          0 :                         goto next;
    6370                 :            : 
    6371                 :          0 :                 ctxm->type = rte_le_to_cpu_16(resp->type);
    6372                 :            : 
    6373                 :          0 :                 ctxm->flags = flags;
    6374         [ #  # ]:          0 :                 if (flags &
    6375                 :            :                     HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_DRIVER_MANAGED_MEMORY) {
    6376                 :            :                         bnxt_init_ctx_v2_driver_managed(bp, ctxm);
    6377                 :          0 :                         goto next;
    6378                 :            :                 }
    6379                 :          0 :                 ctxm->entry_size = rte_le_to_cpu_16(resp->entry_size);
    6380                 :            : 
    6381         [ #  # ]:          0 :                 if (ctxm->entry_size == 0)
    6382                 :          0 :                         goto next;
    6383                 :            : 
    6384                 :          0 :                 ctxm->instance_bmap = rte_le_to_cpu_32(resp->instance_bit_map);
    6385                 :          0 :                 ctxm->entry_multiple = resp->entry_multiple;
    6386                 :          0 :                 ctxm->max_entries = rte_le_to_cpu_32(resp->max_num_entries);
    6387                 :          0 :                 ctxm->min_entries = rte_le_to_cpu_32(resp->min_num_entries);
    6388                 :          0 :                 init_val = resp->ctx_init_value;
    6389                 :          0 :                 init_off = resp->ctx_init_offset;
    6390                 :          0 :                 bnxt_init_ctx_initializer(ctxm, init_val, init_off,
    6391         [ #  # ]:          0 :                                           BNXT_CTX_INIT_VALID(flags));
    6392                 :          0 :                 ctxm->split_entry_cnt = RTE_MIN(resp->subtype_valid_cnt,
    6393                 :            :                                                 BNXT_MAX_SPLIT_ENTRY);
    6394         [ #  # ]:          0 :                 for (i = 0, p = &resp->split_entry_0; i < ctxm->split_entry_cnt;
    6395                 :          0 :                      i++, p++)
    6396                 :          0 :                         ctxm->split[i] = rte_le_to_cpu_32(*p);
    6397                 :            : 
    6398                 :          0 :                 PMD_DRV_LOG(DEBUG,
    6399                 :            :                             "type:%s size:%d multiple:%d max:%d min:%d split:%d init_val:%d init_off:%d init:%d bmap:0x%x\n",
    6400                 :            :                             bnxt_backing_store_types[ctxm->type], ctxm->entry_size,
    6401                 :            :                             ctxm->entry_multiple, ctxm->max_entries, ctxm->min_entries,
    6402                 :            :                             ctxm->split_entry_cnt, init_val, init_off,
    6403                 :            :                             BNXT_CTX_INIT_VALID(flags), ctxm->instance_bmap);
    6404                 :          0 :                 last_valid_type = ctxm->type;
    6405                 :            :                 last_valid_idx = types;
    6406                 :          0 : next:
    6407                 :            :                 HWRM_UNLOCK();
    6408                 :            :         }
    6409                 :          0 :         ctx->ctx_arr[last_valid_idx].last = true;
    6410                 :          0 :         PMD_DRV_LOG(DEBUG, "Last valid type 0x%x\n", last_valid_type);
    6411                 :            : 
    6412                 :          0 :         rc = bnxt_alloc_all_ctx_pg_info(bp);
    6413         [ #  # ]:          0 :         if (rc == 0)
    6414                 :          0 :                 rc = bnxt_alloc_ctx_pg_tbls(bp);
    6415                 :            :         return rc;
    6416                 :            : }
    6417                 :            : 
    6418                 :          0 : int bnxt_hwrm_func_backing_store_types_count(struct bnxt *bp)
    6419                 :            : {
    6420                 :          0 :         struct hwrm_func_backing_store_qcaps_v2_input req = {0};
    6421                 :          0 :         struct hwrm_func_backing_store_qcaps_v2_output *resp =
    6422                 :            :                 bp->hwrm_cmd_resp_addr;
    6423                 :            :         uint16_t type = 0;
    6424                 :            :         int types = 0;
    6425                 :            :         int rc;
    6426                 :            : 
    6427                 :            :         /* Calculate number of valid context types */
    6428                 :            :         do {
    6429                 :            :                 uint32_t flags;
    6430                 :            : 
    6431         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS_V2, BNXT_USE_CHIMP_MB);
    6432                 :          0 :                 req.type = rte_cpu_to_le_16(type);
    6433                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6434   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6435                 :            : 
    6436                 :          0 :                 flags = rte_le_to_cpu_32(resp->flags);
    6437                 :          0 :                 type = rte_le_to_cpu_16(resp->next_valid_type);
    6438                 :            :                 HWRM_UNLOCK();
    6439                 :            : 
    6440         [ #  # ]:          0 :                 if (flags & HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_TYPE_VALID) {
    6441                 :          0 :                         PMD_DRV_LOG(DEBUG, "Valid types 0x%x - %s\n",
    6442                 :            :                                     req.type, bnxt_backing_store_types[req.type]);
    6443                 :          0 :                         types++;
    6444                 :            :                 }
    6445         [ #  # ]:          0 :         } while (type != HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_INVALID);
    6446                 :          0 :         PMD_DRV_LOG(DEBUG, "Number of valid types %d\n", types);
    6447                 :            : 
    6448                 :          0 :         return types;
    6449                 :            : }
    6450                 :            : 
    6451                 :          0 : int bnxt_hwrm_func_backing_store_ctx_alloc(struct bnxt *bp, uint16_t types)
    6452                 :            : {
    6453                 :            :         int alloc_len = sizeof(struct bnxt_ctx_mem_info);
    6454                 :            : 
    6455         [ #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp) ||
    6456   [ #  #  #  # ]:          0 :             bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
    6457                 :          0 :             BNXT_VF(bp) ||
    6458         [ #  # ]:          0 :             bp->ctx)
    6459                 :            :                 return 0;
    6460                 :            : 
    6461                 :          0 :         bp->ctx = rte_zmalloc("bnxt_ctx_mem", alloc_len,
    6462                 :            :                               RTE_CACHE_LINE_SIZE);
    6463         [ #  # ]:          0 :         if (bp->ctx == NULL)
    6464                 :            :                 return -ENOMEM;
    6465                 :            : 
    6466                 :          0 :         alloc_len = sizeof(struct bnxt_ctx_mem) * types;
    6467                 :          0 :         bp->ctx->ctx_arr = rte_zmalloc("bnxt_ctx_mem_arr",
    6468                 :            :                                        alloc_len,
    6469                 :            :                                        RTE_CACHE_LINE_SIZE);
    6470         [ #  # ]:          0 :         if (bp->ctx->ctx_arr == NULL)
    6471                 :            :                 return -ENOMEM;
    6472                 :            : 
    6473                 :          0 :         bp->ctx->types = types;
    6474                 :          0 :         return 0;
    6475                 :            : }
    6476                 :            : 
    6477                 :          0 : int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
    6478                 :            : {
    6479                 :          0 :         struct hwrm_func_backing_store_qcaps_input req = {0};
    6480                 :          0 :         struct hwrm_func_backing_store_qcaps_output *resp =
    6481                 :            :                 bp->hwrm_cmd_resp_addr;
    6482                 :            :         struct bnxt_ctx_pg_info *ctx_pg;
    6483                 :            :         struct bnxt_ctx_mem_info *ctx;
    6484                 :            :         int rc, i, tqm_rings;
    6485                 :            : 
    6486         [ #  # ]:          0 :         if (!BNXT_CHIP_P5_P7(bp) ||
    6487   [ #  #  #  # ]:          0 :             bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
    6488                 :          0 :             BNXT_VF(bp) ||
    6489         [ #  # ]:          0 :             bp->ctx->flags & BNXT_CTX_FLAG_INITED)
    6490                 :            :                 return 0;
    6491                 :            : 
    6492                 :            :         ctx = bp->ctx;
    6493         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
    6494                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6495   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    6496                 :            : 
    6497                 :          0 :         ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
    6498                 :          0 :         ctx->qp_min_qp1_entries =
    6499                 :          0 :                 rte_le_to_cpu_16(resp->qp_min_qp1_entries);
    6500                 :          0 :         ctx->qp_max_l2_entries =
    6501                 :          0 :                 rte_le_to_cpu_16(resp->qp_max_l2_entries);
    6502                 :          0 :         ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
    6503                 :          0 :         ctx->srq_max_l2_entries =
    6504                 :          0 :                 rte_le_to_cpu_16(resp->srq_max_l2_entries);
    6505                 :          0 :         ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
    6506                 :          0 :         ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
    6507         [ #  # ]:          0 :         if (BNXT_CHIP_P7(bp))
    6508                 :          0 :                 ctx->cq_max_l2_entries =
    6509                 :          0 :                         RTE_MIN(BNXT_P7_CQ_MAX_L2_ENT,
    6510                 :            :                                 rte_le_to_cpu_16(resp->cq_max_l2_entries));
    6511                 :            :         else
    6512                 :          0 :                 ctx->cq_max_l2_entries =
    6513                 :          0 :                         rte_le_to_cpu_16(resp->cq_max_l2_entries);
    6514                 :          0 :         ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
    6515                 :          0 :         ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
    6516                 :          0 :         ctx->vnic_max_vnic_entries =
    6517                 :          0 :                 rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
    6518                 :          0 :         ctx->vnic_max_ring_table_entries =
    6519                 :          0 :                 rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
    6520                 :          0 :         ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
    6521                 :          0 :         ctx->stat_max_entries =
    6522                 :          0 :                 rte_le_to_cpu_32(resp->stat_max_entries);
    6523                 :          0 :         ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
    6524                 :          0 :         ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
    6525                 :          0 :         ctx->tqm_min_entries_per_ring =
    6526                 :          0 :                 rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
    6527                 :          0 :         ctx->tqm_max_entries_per_ring =
    6528                 :          0 :                 rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
    6529                 :          0 :         ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
    6530         [ #  # ]:          0 :         if (!ctx->tqm_entries_multiple)
    6531                 :          0 :                 ctx->tqm_entries_multiple = 1;
    6532                 :          0 :         ctx->mrav_max_entries =
    6533                 :          0 :                 rte_le_to_cpu_32(resp->mrav_max_entries);
    6534                 :          0 :         ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
    6535                 :          0 :         ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
    6536                 :          0 :         ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
    6537                 :          0 :         ctx->tqm_fp_rings_count = resp->tqm_fp_rings_count;
    6538                 :            : 
    6539         [ #  # ]:          0 :         ctx->tqm_fp_rings_count = ctx->tqm_fp_rings_count ?
    6540                 :          0 :                                   RTE_MIN(ctx->tqm_fp_rings_count,
    6541                 :            :                                           BNXT_MAX_TQM_FP_LEGACY_RINGS) :
    6542                 :            :                                   bp->max_q;
    6543                 :            : 
    6544                 :            :         /* Check if the ext ring count needs to be counted.
    6545                 :            :          * Ext ring count is available only with new FW so we should not
    6546                 :            :          * look at the field on older FW.
    6547                 :            :          */
    6548         [ #  # ]:          0 :         if (ctx->tqm_fp_rings_count == BNXT_MAX_TQM_FP_LEGACY_RINGS &&
    6549         [ #  # ]:          0 :             bp->hwrm_max_ext_req_len >= BNXT_BACKING_STORE_CFG_LEN) {
    6550                 :          0 :                 ctx->tqm_fp_rings_count += resp->tqm_fp_rings_count_ext;
    6551                 :          0 :                 ctx->tqm_fp_rings_count = RTE_MIN(BNXT_MAX_TQM_FP_RINGS,
    6552                 :            :                                                   ctx->tqm_fp_rings_count);
    6553                 :            :         }
    6554                 :            : 
    6555                 :          0 :         tqm_rings = ctx->tqm_fp_rings_count + 1;
    6556                 :            : 
    6557                 :          0 :         ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
    6558                 :            :                             sizeof(*ctx_pg) * tqm_rings,
    6559                 :            :                             RTE_CACHE_LINE_SIZE);
    6560         [ #  # ]:          0 :         if (!ctx_pg) {
    6561                 :            :                 rc = -ENOMEM;
    6562                 :          0 :                 goto ctx_err;
    6563                 :            :         }
    6564         [ #  # ]:          0 :         for (i = 0; i < tqm_rings; i++, ctx_pg++)
    6565                 :          0 :                 ctx->tqm_mem[i] = ctx_pg;
    6566                 :            : 
    6567                 :          0 : ctx_err:
    6568                 :            :         HWRM_UNLOCK();
    6569                 :          0 :         return rc;
    6570                 :            : }
    6571                 :            : 
    6572                 :          0 : int bnxt_hwrm_func_backing_store_cfg_v2(struct bnxt *bp,
    6573                 :            :                                         struct bnxt_ctx_mem *ctxm)
    6574                 :            : {
    6575                 :          0 :         struct hwrm_func_backing_store_cfg_v2_input req = {0};
    6576                 :          0 :         struct hwrm_func_backing_store_cfg_v2_output *resp =
    6577                 :            :                 bp->hwrm_cmd_resp_addr;
    6578                 :            :         struct bnxt_ctx_pg_info *ctx_pg;
    6579                 :            :         int i, j, k;
    6580                 :            :         uint32_t *p;
    6581                 :            :         int rc = 0;
    6582                 :            :         int w = 1;
    6583                 :            :         int b = 1;
    6584                 :            : 
    6585         [ #  # ]:          0 :         if (!BNXT_PF(bp)) {
    6586                 :          0 :                 PMD_DRV_LOG(INFO,
    6587                 :            :                             "Backing store config V2 can be issued on PF only\n");
    6588                 :          0 :                 return 0;
    6589                 :            :         }
    6590                 :            : 
    6591   [ #  #  #  # ]:          0 :         if (!(ctxm->flags & BNXT_CTX_MEM_TYPE_VALID) || !ctxm->pg_info)
    6592                 :            :                 return 0;
    6593                 :            : 
    6594                 :          0 :         if (ctxm->instance_bmap)
    6595                 :            :                 b = ctxm->instance_bmap;
    6596                 :            : 
    6597                 :          0 :         w = hweight32(b);
    6598                 :            : 
    6599         [ #  # ]:          0 :         for (i = 0, j = 0; i < w && rc == 0; i++) {
    6600         [ #  # ]:          0 :                 if (!(b & (1 << i)))
    6601                 :          0 :                         continue;
    6602                 :            : 
    6603         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG_V2, BNXT_USE_CHIMP_MB);
    6604                 :          0 :                 req.type = rte_cpu_to_le_16(ctxm->type);
    6605                 :          0 :                 req.entry_size = rte_cpu_to_le_16(ctxm->entry_size);
    6606                 :          0 :                 req.subtype_valid_cnt = ctxm->split_entry_cnt;
    6607         [ #  # ]:          0 :                 for (k = 0, p = &req.split_entry_0; k < ctxm->split_entry_cnt; k++)
    6608                 :          0 :                         p[k] = rte_cpu_to_le_32(ctxm->split[k]);
    6609                 :            : 
    6610                 :          0 :                 req.instance = rte_cpu_to_le_16(i);
    6611                 :          0 :                 ctx_pg = &ctxm->pg_info[j++];
    6612         [ #  # ]:          0 :                 if (!ctx_pg->entries)
    6613                 :          0 :                         goto unlock;
    6614                 :            : 
    6615         [ #  # ]:          0 :                 req.num_entries = rte_cpu_to_le_32(ctx_pg->entries);
    6616                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6617                 :            :                                       &req.page_size_pbl_level,
    6618                 :            :                                       &req.page_dir);
    6619                 :          0 :                 PMD_DRV_LOG(DEBUG,
    6620                 :            :                             "Backing store config V2 type:%s last %d, instance %d, hw %d\n",
    6621                 :            :                             bnxt_backing_store_types[req.type], ctxm->last, j, w);
    6622   [ #  #  #  # ]:          0 :                 if (ctxm->last && i == (w - 1))
    6623                 :          0 :                         req.flags =
    6624                 :            :                         rte_cpu_to_le_32(BACKING_STORE_CFG_V2_IN_FLG_CFG_ALL_DONE);
    6625                 :            : 
    6626                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6627   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6628                 :          0 : unlock:
    6629                 :            :                 HWRM_UNLOCK();
    6630                 :            :         }
    6631                 :            :         return rc;
    6632                 :            : }
    6633                 :            : 
    6634                 :          0 : int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
    6635                 :            : {
    6636                 :          0 :         struct hwrm_func_backing_store_cfg_input req = {0};
    6637                 :          0 :         struct hwrm_func_backing_store_cfg_output *resp =
    6638                 :            :                 bp->hwrm_cmd_resp_addr;
    6639                 :          0 :         struct bnxt_ctx_mem_info *ctx = bp->ctx;
    6640                 :            :         struct bnxt_ctx_pg_info *ctx_pg;
    6641                 :            :         uint32_t *num_entries;
    6642                 :            :         uint64_t *pg_dir;
    6643                 :            :         uint8_t *pg_attr;
    6644                 :            :         uint32_t ena;
    6645                 :            :         int i, rc;
    6646                 :            : 
    6647         [ #  # ]:          0 :         if (!ctx)
    6648                 :            :                 return 0;
    6649                 :            : 
    6650   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
    6651                 :          0 :         req.enables = rte_cpu_to_le_32(enables);
    6652                 :            : 
    6653         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
    6654                 :            :                 ctx_pg = &ctx->qp_mem;
    6655                 :          0 :                 req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
    6656                 :          0 :                 req.qp_num_qp1_entries =
    6657                 :          0 :                         rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
    6658                 :          0 :                 req.qp_num_l2_entries =
    6659                 :          0 :                         rte_cpu_to_le_16(ctx->qp_max_l2_entries);
    6660         [ #  # ]:          0 :                 req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
    6661                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6662                 :            :                                       &req.qpc_pg_size_qpc_lvl,
    6663                 :            :                                       &req.qpc_page_dir);
    6664                 :            :         }
    6665                 :            : 
    6666         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
    6667                 :            :                 ctx_pg = &ctx->srq_mem;
    6668                 :          0 :                 req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
    6669                 :          0 :                 req.srq_num_l2_entries =
    6670                 :          0 :                                  rte_cpu_to_le_16(ctx->srq_max_l2_entries);
    6671         [ #  # ]:          0 :                 req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
    6672                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6673                 :            :                                       &req.srq_pg_size_srq_lvl,
    6674                 :            :                                       &req.srq_page_dir);
    6675                 :            :         }
    6676                 :            : 
    6677         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
    6678                 :            :                 ctx_pg = &ctx->cq_mem;
    6679                 :          0 :                 req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
    6680                 :          0 :                 req.cq_num_l2_entries =
    6681                 :          0 :                                 rte_cpu_to_le_16(ctx->cq_max_l2_entries);
    6682         [ #  # ]:          0 :                 req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
    6683                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6684                 :            :                                       &req.cq_pg_size_cq_lvl,
    6685                 :            :                                       &req.cq_page_dir);
    6686                 :            :         }
    6687                 :            : 
    6688         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
    6689                 :            :                 ctx_pg = &ctx->vnic_mem;
    6690                 :          0 :                 req.vnic_num_vnic_entries =
    6691                 :          0 :                         rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
    6692                 :          0 :                 req.vnic_num_ring_table_entries =
    6693                 :          0 :                         rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
    6694         [ #  # ]:          0 :                 req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
    6695                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6696                 :            :                                       &req.vnic_pg_size_vnic_lvl,
    6697                 :            :                                       &req.vnic_page_dir);
    6698                 :            :         }
    6699                 :            : 
    6700         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
    6701                 :            :                 ctx_pg = &ctx->stat_mem;
    6702                 :          0 :                 req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
    6703         [ #  # ]:          0 :                 req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
    6704                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6705                 :            :                                       &req.stat_pg_size_stat_lvl,
    6706                 :            :                                       &req.stat_page_dir);
    6707                 :            :         }
    6708                 :            : 
    6709                 :          0 :         req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
    6710                 :            :         num_entries = &req.tqm_sp_num_entries;
    6711                 :            :         pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
    6712                 :            :         pg_dir = &req.tqm_sp_page_dir;
    6713                 :            :         ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
    6714         [ #  # ]:          0 :         for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
    6715         [ #  # ]:          0 :                 if (!(enables & ena))
    6716                 :          0 :                         continue;
    6717                 :            : 
    6718                 :          0 :                 req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
    6719                 :            : 
    6720                 :          0 :                 ctx_pg = ctx->tqm_mem[i];
    6721         [ #  # ]:          0 :                 *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
    6722                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
    6723                 :            :         }
    6724                 :            : 
    6725         [ #  # ]:          0 :         if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8) {
    6726                 :            :                 /* DPDK does not need to configure MRAV and TIM type.
    6727                 :            :                  * So we are skipping over MRAV and TIM. Skip to configure
    6728                 :            :                  * HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8.
    6729                 :            :                  */
    6730                 :          0 :                 ctx_pg = ctx->tqm_mem[BNXT_MAX_TQM_LEGACY_RINGS];
    6731         [ #  # ]:          0 :                 req.tqm_ring8_num_entries = rte_cpu_to_le_16(ctx_pg->entries);
    6732                 :            :                 bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
    6733                 :            :                                       &req.tqm_ring8_pg_size_tqm_ring_lvl,
    6734                 :            :                                       &req.tqm_ring8_page_dir);
    6735                 :            :         }
    6736                 :            : 
    6737                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6738   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6739                 :            :         HWRM_UNLOCK();
    6740                 :            : 
    6741                 :          0 :         return rc;
    6742                 :            : }
    6743                 :            : 
    6744                 :          0 : int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
    6745                 :            : {
    6746                 :          0 :         struct hwrm_port_qstats_ext_input req = {0};
    6747                 :          0 :         struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
    6748                 :          0 :         struct bnxt_pf_info *pf = bp->pf;
    6749                 :            :         int rc;
    6750                 :            : 
    6751         [ #  # ]:          0 :         if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
    6752                 :            :               bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
    6753                 :            :                 return 0;
    6754                 :            : 
    6755   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
    6756                 :            : 
    6757                 :          0 :         req.port_id = rte_cpu_to_le_16(pf->port_id);
    6758         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
    6759                 :          0 :                 req.tx_stat_host_addr =
    6760                 :          0 :                         rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
    6761                 :          0 :                 req.tx_stat_size =
    6762                 :            :                         rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
    6763                 :            :         }
    6764         [ #  # ]:          0 :         if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
    6765                 :          0 :                 req.rx_stat_host_addr =
    6766                 :          0 :                         rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
    6767                 :          0 :                 req.rx_stat_size =
    6768                 :            :                         rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
    6769                 :            :         }
    6770                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6771                 :            : 
    6772         [ #  # ]:          0 :         if (rc) {
    6773                 :          0 :                 bp->fw_rx_port_stats_ext_size = 0;
    6774                 :          0 :                 bp->fw_tx_port_stats_ext_size = 0;
    6775                 :            :         } else {
    6776                 :          0 :                 bp->fw_rx_port_stats_ext_size =
    6777                 :          0 :                         rte_le_to_cpu_16(resp->rx_stat_size);
    6778                 :          0 :                 bp->fw_tx_port_stats_ext_size =
    6779                 :          0 :                         rte_le_to_cpu_16(resp->tx_stat_size);
    6780                 :            :         }
    6781                 :            : 
    6782   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6783                 :            :         HWRM_UNLOCK();
    6784                 :            : 
    6785                 :          0 :         return rc;
    6786                 :            : }
    6787                 :            : 
    6788                 :            : int
    6789                 :          0 : bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
    6790                 :            : {
    6791                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
    6792                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
    6793                 :            :                 bp->hwrm_cmd_resp_addr;
    6794                 :            :         int rc = 0;
    6795                 :            : 
    6796         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
    6797                 :          0 :         req.tunnel_type = type;
    6798                 :          0 :         req.dest_fid = bp->fw_fid;
    6799                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6800   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6801                 :            : 
    6802                 :            :         HWRM_UNLOCK();
    6803                 :            : 
    6804                 :          0 :         return rc;
    6805                 :            : }
    6806                 :            : 
    6807                 :            : int
    6808                 :          0 : bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
    6809                 :            : {
    6810                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
    6811                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
    6812                 :            :                 bp->hwrm_cmd_resp_addr;
    6813                 :            :         int rc = 0;
    6814                 :            : 
    6815         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
    6816                 :          0 :         req.tunnel_type = type;
    6817                 :          0 :         req.dest_fid = bp->fw_fid;
    6818                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6819   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6820                 :            : 
    6821                 :            :         HWRM_UNLOCK();
    6822                 :            : 
    6823                 :          0 :         return rc;
    6824                 :            : }
    6825                 :            : 
    6826                 :          0 : int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
    6827                 :            : {
    6828                 :          0 :         struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
    6829                 :          0 :         struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
    6830                 :            :                 bp->hwrm_cmd_resp_addr;
    6831                 :            :         int rc = 0;
    6832                 :            : 
    6833         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
    6834                 :          0 :         req.src_fid = bp->fw_fid;
    6835                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6836   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6837                 :            : 
    6838         [ #  # ]:          0 :         if (type)
    6839                 :          0 :                 *type = rte_le_to_cpu_32(resp->tunnel_mask);
    6840                 :            : 
    6841                 :            :         HWRM_UNLOCK();
    6842                 :            : 
    6843                 :          0 :         return rc;
    6844                 :            : }
    6845                 :            : 
    6846                 :          0 : int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
    6847                 :            :                                    uint16_t *dst_fid)
    6848                 :            : {
    6849                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
    6850                 :          0 :         struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
    6851                 :            :                 bp->hwrm_cmd_resp_addr;
    6852                 :            :         int rc = 0;
    6853                 :            : 
    6854         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
    6855                 :          0 :         req.src_fid = bp->fw_fid;
    6856                 :          0 :         req.tunnel_type = tun_type;
    6857                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6858   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6859                 :            : 
    6860         [ #  # ]:          0 :         if (dst_fid)
    6861                 :          0 :                 *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
    6862                 :            : 
    6863                 :          0 :         PMD_DRV_LOG(DEBUG, "dst_fid: %x\n", resp->dest_fid);
    6864                 :            : 
    6865                 :            :         HWRM_UNLOCK();
    6866                 :            : 
    6867                 :          0 :         return rc;
    6868                 :            : }
    6869                 :            : 
    6870                 :          0 : int bnxt_hwrm_set_mac(struct bnxt *bp)
    6871                 :            : {
    6872                 :          0 :         struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    6873                 :          0 :         struct hwrm_func_vf_cfg_input req = {0};
    6874                 :            :         int rc = 0;
    6875                 :            : 
    6876         [ #  # ]:          0 :         if (!BNXT_VF(bp))
    6877                 :            :                 return 0;
    6878                 :            : 
    6879         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
    6880                 :            : 
    6881                 :          0 :         req.enables =
    6882                 :            :                 rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
    6883                 :            :         memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
    6884                 :            : 
    6885                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6886                 :            : 
    6887   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6888                 :            : 
    6889                 :            :         HWRM_UNLOCK();
    6890                 :            : 
    6891                 :          0 :         return rc;
    6892                 :            : }
    6893                 :            : 
    6894                 :          0 : int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
    6895                 :            : {
    6896                 :          0 :         struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
    6897                 :          0 :         struct hwrm_func_drv_if_change_input req = {0};
    6898                 :            :         uint32_t flags;
    6899                 :            :         int rc;
    6900                 :            : 
    6901         [ #  # ]:          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
    6902                 :            :                 return 0;
    6903                 :            : 
    6904                 :            :         /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
    6905                 :            :          * If we issue FUNC_DRV_IF_CHANGE with flags down before
    6906                 :            :          * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
    6907                 :            :          */
    6908   [ #  #  #  # ]:          0 :         if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
    6909                 :            :                 return 0;
    6910                 :            : 
    6911   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
    6912                 :            : 
    6913         [ #  # ]:          0 :         if (up)
    6914                 :          0 :                 req.flags =
    6915                 :            :                 rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
    6916                 :            : 
    6917                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6918                 :            : 
    6919   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6920                 :          0 :         flags = rte_le_to_cpu_32(resp->flags);
    6921                 :            :         HWRM_UNLOCK();
    6922                 :            : 
    6923         [ #  # ]:          0 :         if (!up)
    6924                 :            :                 return 0;
    6925                 :            : 
    6926         [ #  # ]:          0 :         if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
    6927                 :          0 :                 PMD_DRV_LOG(INFO, "FW reset happened while port was down\n");
    6928                 :          0 :                 bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
    6929                 :            :         }
    6930                 :            : 
    6931                 :            :         return 0;
    6932                 :            : }
    6933                 :            : 
    6934                 :          0 : int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
    6935                 :            : {
    6936                 :          0 :         struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
    6937                 :          0 :         struct bnxt_error_recovery_info *info = bp->recovery_info;
    6938                 :          0 :         struct hwrm_error_recovery_qcfg_input req = {0};
    6939                 :            :         uint32_t flags = 0;
    6940                 :            :         unsigned int i;
    6941                 :            :         int rc;
    6942                 :            : 
    6943                 :            :         /* Older FW does not have error recovery support */
    6944         [ #  # ]:          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
    6945                 :            :                 return 0;
    6946                 :            : 
    6947         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
    6948                 :            : 
    6949                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    6950                 :            : 
    6951   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    6952                 :            : 
    6953                 :          0 :         flags = rte_le_to_cpu_32(resp->flags);
    6954         [ #  # ]:          0 :         if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
    6955                 :          0 :                 info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
    6956         [ #  # ]:          0 :         else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
    6957                 :          0 :                 info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
    6958                 :            : 
    6959         [ #  # ]:          0 :         if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
    6960         [ #  # ]:          0 :             !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
    6961                 :            :                 rc = -EINVAL;
    6962                 :          0 :                 goto err;
    6963                 :            :         }
    6964                 :            : 
    6965                 :            :         /* FW returned values are in units of 100msec */
    6966                 :          0 :         info->driver_polling_freq =
    6967                 :          0 :                 rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
    6968                 :          0 :         info->primary_func_wait_period =
    6969                 :          0 :                 rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
    6970                 :          0 :         info->normal_func_wait_period =
    6971                 :          0 :                 rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
    6972                 :          0 :         info->primary_func_wait_period_after_reset =
    6973                 :          0 :                 rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
    6974                 :          0 :         info->max_bailout_time_after_reset =
    6975                 :          0 :                 rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
    6976                 :          0 :         info->status_regs[BNXT_FW_STATUS_REG] =
    6977                 :          0 :                 rte_le_to_cpu_32(resp->fw_health_status_reg);
    6978                 :          0 :         info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
    6979                 :          0 :                 rte_le_to_cpu_32(resp->fw_heartbeat_reg);
    6980                 :          0 :         info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
    6981                 :          0 :                 rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
    6982                 :          0 :         info->status_regs[BNXT_FW_RESET_INPROG_REG] =
    6983                 :          0 :                 rte_le_to_cpu_32(resp->reset_inprogress_reg);
    6984                 :          0 :         info->reg_array_cnt =
    6985                 :          0 :                 rte_le_to_cpu_32(resp->reg_array_cnt);
    6986                 :            : 
    6987         [ #  # ]:          0 :         if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
    6988                 :            :                 rc = -EINVAL;
    6989                 :          0 :                 goto err;
    6990                 :            :         }
    6991                 :            : 
    6992         [ #  # ]:          0 :         for (i = 0; i < info->reg_array_cnt; i++) {
    6993                 :          0 :                 info->reset_reg[i] =
    6994                 :          0 :                         rte_le_to_cpu_32(resp->reset_reg[i]);
    6995                 :          0 :                 info->reset_reg_val[i] =
    6996                 :          0 :                         rte_le_to_cpu_32(resp->reset_reg_val[i]);
    6997                 :          0 :                 info->delay_after_reset[i] =
    6998                 :          0 :                         resp->delay_after_reset[i];
    6999                 :            :         }
    7000                 :          0 : err:
    7001                 :            :         HWRM_UNLOCK();
    7002                 :            : 
    7003                 :            :         /* Map the FW status registers */
    7004         [ #  # ]:          0 :         if (!rc)
    7005                 :          0 :                 rc = bnxt_map_fw_health_status_regs(bp);
    7006                 :            : 
    7007         [ #  # ]:          0 :         if (rc) {
    7008                 :          0 :                 rte_free(bp->recovery_info);
    7009                 :          0 :                 bp->recovery_info = NULL;
    7010                 :            :         }
    7011                 :            :         return rc;
    7012                 :            : }
    7013                 :            : 
    7014                 :          0 : int bnxt_hwrm_fw_reset(struct bnxt *bp)
    7015                 :            : {
    7016                 :          0 :         struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
    7017                 :          0 :         struct hwrm_fw_reset_input req = {0};
    7018                 :            :         int rc;
    7019                 :            : 
    7020         [ #  # ]:          0 :         if (!BNXT_PF(bp))
    7021                 :            :                 return -EOPNOTSUPP;
    7022                 :            : 
    7023   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_FW_RESET, BNXT_USE_KONG(bp));
    7024                 :            : 
    7025                 :          0 :         req.embedded_proc_type =
    7026                 :            :                 HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
    7027                 :          0 :         req.selfrst_status =
    7028                 :            :                 HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
    7029                 :          0 :         req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
    7030                 :            : 
    7031                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
    7032                 :            :                                     BNXT_USE_KONG(bp));
    7033                 :            : 
    7034   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7035                 :            :         HWRM_UNLOCK();
    7036                 :            : 
    7037                 :          0 :         return rc;
    7038                 :            : }
    7039                 :            : 
    7040                 :          0 : int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
    7041                 :            : {
    7042                 :          0 :         struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
    7043                 :          0 :         struct hwrm_port_ts_query_input req = {0};
    7044                 :          0 :         struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
    7045                 :            :         uint32_t flags = 0;
    7046                 :            :         int rc;
    7047                 :            : 
    7048         [ #  # ]:          0 :         if (!ptp)
    7049                 :            :                 return 0;
    7050                 :            : 
    7051   [ #  #  #  #  :          0 :         HWRM_PREP(&req, HWRM_PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
                      # ]
    7052                 :            : 
    7053      [ #  #  # ]:          0 :         switch (path) {
    7054                 :            :         case BNXT_PTP_FLAGS_PATH_TX:
    7055                 :            :                 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
    7056                 :            :                 break;
    7057                 :          0 :         case BNXT_PTP_FLAGS_PATH_RX:
    7058                 :            :                 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
    7059                 :          0 :                 break;
    7060                 :          0 :         case BNXT_PTP_FLAGS_CURRENT_TIME:
    7061                 :            :                 flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
    7062                 :          0 :                 break;
    7063                 :            :         }
    7064                 :            : 
    7065                 :          0 :         req.flags = rte_cpu_to_le_32(flags);
    7066                 :          0 :         req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
    7067                 :            : 
    7068                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7069                 :            : 
    7070   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7071                 :            : 
    7072         [ #  # ]:          0 :         if (timestamp) {
    7073                 :          0 :                 *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
    7074                 :          0 :                 *timestamp |=
    7075                 :          0 :                         (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
    7076                 :            :         }
    7077                 :            :         HWRM_UNLOCK();
    7078                 :            : 
    7079                 :          0 :         return rc;
    7080                 :            : }
    7081                 :            : 
    7082                 :          0 : int bnxt_hwrm_cfa_counter_qcaps(struct bnxt *bp, uint16_t *max_fc)
    7083                 :            : {
    7084                 :            :         int rc = 0;
    7085                 :            : 
    7086                 :          0 :         struct hwrm_cfa_counter_qcaps_input req = {0};
    7087                 :          0 :         struct hwrm_cfa_counter_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    7088                 :            : 
    7089         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7090                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7091                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7092                 :          0 :                 return 0;
    7093                 :            :         }
    7094                 :            : 
    7095   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_COUNTER_QCAPS, BNXT_USE_KONG(bp));
    7096                 :          0 :         req.target_id = rte_cpu_to_le_16(bp->fw_fid);
    7097                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    7098                 :            : 
    7099   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7100         [ #  # ]:          0 :         if (max_fc)
    7101                 :          0 :                 *max_fc = rte_le_to_cpu_16(resp->max_rx_fc);
    7102                 :            :         HWRM_UNLOCK();
    7103                 :            : 
    7104                 :          0 :         return 0;
    7105                 :            : }
    7106                 :            : 
    7107                 :          0 : int bnxt_hwrm_ctx_rgtr(struct bnxt *bp, rte_iova_t dma_addr, uint16_t *ctx_id)
    7108                 :            : {
    7109                 :            :         int rc = 0;
    7110                 :          0 :         struct hwrm_cfa_ctx_mem_rgtr_input req = {.req_type = 0 };
    7111                 :          0 :         struct hwrm_cfa_ctx_mem_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
    7112                 :            : 
    7113         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7114                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7115                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7116                 :          0 :                 return 0;
    7117                 :            :         }
    7118                 :            : 
    7119   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_CTX_MEM_RGTR, BNXT_USE_KONG(bp));
    7120                 :            : 
    7121                 :          0 :         req.page_level = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_LEVEL_LVL_0;
    7122                 :          0 :         req.page_size = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_SIZE_2M;
    7123                 :          0 :         req.page_dir = rte_cpu_to_le_64(dma_addr);
    7124                 :            : 
    7125                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    7126                 :            : 
    7127   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7128         [ #  # ]:          0 :         if (ctx_id) {
    7129                 :          0 :                 *ctx_id  = rte_le_to_cpu_16(resp->ctx_id);
    7130                 :          0 :                 PMD_DRV_LOG(DEBUG, "ctx_id = %d\n", *ctx_id);
    7131                 :            :         }
    7132                 :            :         HWRM_UNLOCK();
    7133                 :            : 
    7134                 :          0 :         return 0;
    7135                 :            : }
    7136                 :            : 
    7137                 :          0 : int bnxt_hwrm_ctx_unrgtr(struct bnxt *bp, uint16_t ctx_id)
    7138                 :            : {
    7139                 :            :         int rc = 0;
    7140                 :          0 :         struct hwrm_cfa_ctx_mem_unrgtr_input req = {.req_type = 0 };
    7141                 :          0 :         struct hwrm_cfa_ctx_mem_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
    7142                 :            : 
    7143         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7144                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7145                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7146                 :          0 :                 return 0;
    7147                 :            :         }
    7148                 :            : 
    7149   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_CTX_MEM_UNRGTR, BNXT_USE_KONG(bp));
    7150                 :            : 
    7151                 :          0 :         req.ctx_id = rte_cpu_to_le_16(ctx_id);
    7152                 :            : 
    7153                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    7154                 :            : 
    7155   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7156                 :            :         HWRM_UNLOCK();
    7157                 :            : 
    7158                 :          0 :         return rc;
    7159                 :            : }
    7160                 :            : 
    7161                 :          0 : int bnxt_hwrm_cfa_counter_cfg(struct bnxt *bp, enum bnxt_flow_dir dir,
    7162                 :            :                               uint16_t cntr, uint16_t ctx_id,
    7163                 :            :                               uint32_t num_entries, bool enable)
    7164                 :            : {
    7165                 :          0 :         struct hwrm_cfa_counter_cfg_input req = {0};
    7166                 :          0 :         struct hwrm_cfa_counter_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    7167                 :            :         uint16_t flags = 0;
    7168                 :            :         int rc;
    7169                 :            : 
    7170         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7171                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7172                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7173                 :          0 :                 return 0;
    7174                 :            :         }
    7175                 :            : 
    7176   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_COUNTER_CFG, BNXT_USE_KONG(bp));
    7177                 :            : 
    7178                 :          0 :         req.target_id = rte_cpu_to_le_16(bp->fw_fid);
    7179                 :          0 :         req.counter_type = rte_cpu_to_le_16(cntr);
    7180         [ #  # ]:          0 :         flags = enable ? HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_ENABLE :
    7181                 :            :                 HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_DISABLE;
    7182                 :          0 :         flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_DATA_TRANSFER_MODE_PULL;
    7183         [ #  # ]:          0 :         if (dir == BNXT_DIR_RX)
    7184                 :          0 :                 flags |=  HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_RX;
    7185                 :            :         else if (dir == BNXT_DIR_TX)
    7186                 :            :                 flags |=  HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_TX;
    7187                 :          0 :         req.flags = rte_cpu_to_le_16(flags);
    7188                 :          0 :         req.ctx_id =  rte_cpu_to_le_16(ctx_id);
    7189                 :          0 :         req.num_entries = rte_cpu_to_le_32(num_entries);
    7190                 :            : 
    7191                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    7192   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7193                 :            :         HWRM_UNLOCK();
    7194                 :            : 
    7195                 :          0 :         return 0;
    7196                 :            : }
    7197                 :            : 
    7198                 :          0 : int bnxt_hwrm_cfa_counter_qstats(struct bnxt *bp,
    7199                 :            :                                  enum bnxt_flow_dir dir,
    7200                 :            :                                  uint16_t cntr,
    7201                 :            :                                  uint16_t num_entries)
    7202                 :            : {
    7203                 :          0 :         struct hwrm_cfa_counter_qstats_output *resp = bp->hwrm_cmd_resp_addr;
    7204                 :          0 :         struct hwrm_cfa_counter_qstats_input req = {0};
    7205                 :            :         uint16_t flow_ctx_id = 0;
    7206                 :            :         uint16_t flags = 0;
    7207                 :            :         int rc = 0;
    7208                 :            : 
    7209         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7210                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7211                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7212                 :          0 :                 return 0;
    7213                 :            :         }
    7214                 :            : 
    7215         [ #  # ]:          0 :         if (dir == BNXT_DIR_RX) {
    7216                 :          0 :                 flow_ctx_id = bp->flow_stat->rx_fc_in_tbl.ctx_id;
    7217                 :            :                 flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_RX;
    7218         [ #  # ]:          0 :         } else if (dir == BNXT_DIR_TX) {
    7219                 :          0 :                 flow_ctx_id = bp->flow_stat->tx_fc_in_tbl.ctx_id;
    7220                 :            :                 flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_TX;
    7221                 :            :         }
    7222                 :            : 
    7223   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_COUNTER_QSTATS, BNXT_USE_KONG(bp));
    7224                 :          0 :         req.target_id = rte_cpu_to_le_16(bp->fw_fid);
    7225                 :          0 :         req.counter_type = rte_cpu_to_le_16(cntr);
    7226                 :          0 :         req.input_flow_ctx_id = rte_cpu_to_le_16(flow_ctx_id);
    7227                 :          0 :         req.num_entries = rte_cpu_to_le_16(num_entries);
    7228                 :          0 :         req.flags = rte_cpu_to_le_16(flags);
    7229                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
    7230                 :            : 
    7231   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7232                 :            :         HWRM_UNLOCK();
    7233                 :            : 
    7234                 :          0 :         return 0;
    7235                 :            : }
    7236                 :            : 
    7237                 :          0 : int bnxt_hwrm_first_vf_id_query(struct bnxt *bp, uint16_t fid,
    7238                 :            :                                 uint16_t *first_vf_id)
    7239                 :            : {
    7240                 :            :         int rc = 0;
    7241                 :          0 :         struct hwrm_func_qcaps_input req = {.req_type = 0 };
    7242                 :          0 :         struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
    7243                 :            : 
    7244         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
    7245                 :            : 
    7246                 :          0 :         req.fid = rte_cpu_to_le_16(fid);
    7247                 :            : 
    7248                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7249                 :            : 
    7250   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7251                 :            : 
    7252         [ #  # ]:          0 :         if (first_vf_id)
    7253                 :          0 :                 *first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
    7254                 :            : 
    7255                 :            :         HWRM_UNLOCK();
    7256                 :            : 
    7257                 :          0 :         return rc;
    7258                 :            : }
    7259                 :            : 
    7260                 :          0 : int bnxt_hwrm_cfa_pair_exists(struct bnxt *bp, struct bnxt_representor *rep_bp)
    7261                 :            : {
    7262                 :          0 :         struct hwrm_cfa_pair_info_output *resp = bp->hwrm_cmd_resp_addr;
    7263                 :          0 :         struct hwrm_cfa_pair_info_input req = {0};
    7264                 :            :         int rc = 0;
    7265                 :            : 
    7266         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7267                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7268                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7269                 :          0 :                 return 0;
    7270                 :            :         }
    7271                 :            : 
    7272         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_PAIR_INFO, BNXT_USE_CHIMP_MB);
    7273                 :          0 :         snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
    7274                 :          0 :                  bp->eth_dev->data->name, rep_bp->vf_id);
    7275                 :          0 :         req.flags =
    7276                 :            :                 rte_cpu_to_le_32(HWRM_CFA_PAIR_INFO_INPUT_FLAGS_LOOKUP_TYPE);
    7277                 :            : 
    7278                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7279   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7280         [ #  # ]:          0 :         if (rc == HWRM_ERR_CODE_SUCCESS && strlen(resp->pair_name)) {
    7281                 :            :                 HWRM_UNLOCK();
    7282                 :          0 :                 return !rc;
    7283                 :            :         }
    7284                 :            :         HWRM_UNLOCK();
    7285                 :          0 :         return rc;
    7286                 :            : }
    7287                 :            : 
    7288                 :          0 : int bnxt_hwrm_cfa_pair_alloc(struct bnxt *bp, struct bnxt_representor *rep_bp)
    7289                 :            : {
    7290                 :          0 :         struct hwrm_cfa_pair_alloc_output *resp = bp->hwrm_cmd_resp_addr;
    7291                 :          0 :         struct hwrm_cfa_pair_alloc_input req = {0};
    7292                 :            :         int rc;
    7293                 :            : 
    7294         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7295                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7296                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7297                 :          0 :                 return 0;
    7298                 :            :         }
    7299                 :            : 
    7300   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_PAIR_ALLOC, BNXT_USE_CHIMP_MB);
    7301                 :          0 :         req.pair_mode = HWRM_CFA_PAIR_FREE_INPUT_PAIR_MODE_REP2FN_TRUFLOW;
    7302                 :          0 :         snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
    7303         [ #  # ]:          0 :                  bp->eth_dev->data->name, rep_bp->vf_id);
    7304                 :            : 
    7305                 :          0 :         req.pf_b_id = rep_bp->parent_pf_idx;
    7306         [ #  # ]:          0 :         req.vf_b_id = BNXT_REP_PF(rep_bp) ? rte_cpu_to_le_16(((uint16_t)-1)) :
    7307                 :            :                                                 rte_cpu_to_le_16(rep_bp->vf_id);
    7308                 :          0 :         req.vf_a_id = rte_cpu_to_le_16(bp->fw_fid);
    7309                 :          0 :         req.host_b_id = 1; /* TBD - Confirm if this is OK */
    7310                 :            : 
    7311                 :          0 :         req.enables |= rep_bp->flags & BNXT_REP_Q_R2F_VALID ?
    7312                 :          0 :                         HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_Q_AB_VALID : 0;
    7313                 :          0 :         req.enables |= rep_bp->flags & BNXT_REP_Q_F2R_VALID ?
    7314                 :          0 :                         HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_Q_BA_VALID : 0;
    7315                 :          0 :         req.enables |= rep_bp->flags & BNXT_REP_FC_R2F_VALID ?
    7316                 :          0 :                         HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_FC_AB_VALID : 0;
    7317                 :          0 :         req.enables |= rep_bp->flags & BNXT_REP_FC_F2R_VALID ?
    7318                 :          0 :                         HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_FC_BA_VALID : 0;
    7319                 :            : 
    7320                 :          0 :         req.q_ab = rep_bp->rep_q_r2f;
    7321                 :          0 :         req.q_ba = rep_bp->rep_q_f2r;
    7322                 :          0 :         req.fc_ab = rep_bp->rep_fc_r2f;
    7323                 :          0 :         req.fc_ba = rep_bp->rep_fc_f2r;
    7324                 :            : 
    7325                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7326   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7327                 :            : 
    7328                 :            :         HWRM_UNLOCK();
    7329         [ #  # ]:          0 :         PMD_DRV_LOG(DEBUG, "%s %d allocated\n",
    7330                 :            :                     BNXT_REP_PF(rep_bp) ? "PFR" : "VFR", rep_bp->vf_id);
    7331                 :          0 :         return rc;
    7332                 :            : }
    7333                 :            : 
    7334                 :          0 : int bnxt_hwrm_cfa_pair_free(struct bnxt *bp, struct bnxt_representor *rep_bp)
    7335                 :            : {
    7336                 :          0 :         struct hwrm_cfa_pair_free_output *resp = bp->hwrm_cmd_resp_addr;
    7337                 :          0 :         struct hwrm_cfa_pair_free_input req = {0};
    7338                 :            :         int rc;
    7339                 :            : 
    7340         [ #  # ]:          0 :         if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
    7341                 :          0 :                 PMD_DRV_LOG(DEBUG,
    7342                 :            :                             "Not a PF or trusted VF. Command not supported\n");
    7343                 :          0 :                 return 0;
    7344                 :            :         }
    7345                 :            : 
    7346   [ #  #  #  # ]:          0 :         HWRM_PREP(&req, HWRM_CFA_PAIR_FREE, BNXT_USE_CHIMP_MB);
    7347                 :          0 :         snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
    7348         [ #  # ]:          0 :                  bp->eth_dev->data->name, rep_bp->vf_id);
    7349                 :          0 :         req.pf_b_id = rep_bp->parent_pf_idx;
    7350                 :          0 :         req.pair_mode = HWRM_CFA_PAIR_FREE_INPUT_PAIR_MODE_REP2FN_TRUFLOW;
    7351         [ #  # ]:          0 :         req.vf_id = BNXT_REP_PF(rep_bp) ? rte_cpu_to_le_16(((uint16_t)-1)) :
    7352                 :            :                                                 rte_cpu_to_le_16(rep_bp->vf_id);
    7353                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7354   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7355                 :            :         HWRM_UNLOCK();
    7356         [ #  # ]:          0 :         PMD_DRV_LOG(DEBUG, "%s %d freed\n", BNXT_REP_PF(rep_bp) ? "PFR" : "VFR",
    7357                 :            :                     rep_bp->vf_id);
    7358                 :          0 :         return rc;
    7359                 :            : }
    7360                 :            : 
    7361                 :          0 : int bnxt_hwrm_fw_echo_reply(struct bnxt *bp, uint32_t echo_req_data1,
    7362                 :            :                             uint32_t echo_req_data2)
    7363                 :            : {
    7364                 :          0 :         struct hwrm_func_echo_response_input req = {0};
    7365                 :          0 :         struct hwrm_func_echo_response_output *resp = bp->hwrm_cmd_resp_addr;
    7366                 :            :         int rc;
    7367                 :            : 
    7368         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_ECHO_RESPONSE, BNXT_USE_CHIMP_MB);
    7369                 :          0 :         req.event_data1 = rte_cpu_to_le_32(echo_req_data1);
    7370                 :          0 :         req.event_data2 = rte_cpu_to_le_32(echo_req_data2);
    7371                 :            : 
    7372                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7373                 :            : 
    7374   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7375                 :            :         HWRM_UNLOCK();
    7376                 :            : 
    7377                 :          0 :         return rc;
    7378                 :            : }
    7379                 :            : 
    7380                 :          0 : int bnxt_hwrm_poll_ver_get(struct bnxt *bp)
    7381                 :            : {
    7382                 :          0 :         struct hwrm_ver_get_input req = {.req_type = 0 };
    7383                 :          0 :         struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
    7384                 :            :         int rc = 0;
    7385                 :            : 
    7386                 :          0 :         bp->max_req_len = HWRM_MAX_REQ_LEN;
    7387                 :          0 :         bp->max_resp_len = BNXT_PAGE_SIZE;
    7388                 :          0 :         bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
    7389                 :            : 
    7390         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
    7391                 :          0 :         req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
    7392                 :          0 :         req.hwrm_intf_min = HWRM_VERSION_MINOR;
    7393                 :          0 :         req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
    7394                 :            : 
    7395                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7396                 :            : 
    7397   [ #  #  #  # ]:          0 :         HWRM_CHECK_RESULT_SILENT();
    7398                 :            :         HWRM_UNLOCK();
    7399                 :            : 
    7400                 :          0 :         return rc;
    7401                 :            : }
    7402                 :            : 
    7403                 :          0 : int bnxt_hwrm_read_sfp_module_eeprom_info(struct bnxt *bp, uint16_t i2c_addr,
    7404                 :            :                                           uint16_t page_number, uint16_t start_addr,
    7405                 :            :                                           uint16_t data_length, uint8_t *buf)
    7406                 :            : {
    7407                 :          0 :         struct hwrm_port_phy_i2c_read_output *resp = bp->hwrm_cmd_resp_addr;
    7408                 :          0 :         struct hwrm_port_phy_i2c_read_input req = {0};
    7409                 :            :         uint32_t enables = HWRM_PORT_PHY_I2C_READ_INPUT_ENABLES_PAGE_OFFSET;
    7410                 :            :         int rc, byte_offset = 0;
    7411                 :            : 
    7412                 :            :         do {
    7413                 :            :                 uint16_t xfer_size;
    7414                 :            : 
    7415   [ #  #  #  # ]:          0 :                 HWRM_PREP(&req, HWRM_PORT_PHY_I2C_READ, BNXT_USE_CHIMP_MB);
    7416                 :          0 :                 req.i2c_slave_addr = i2c_addr;
    7417                 :          0 :                 req.page_number = rte_cpu_to_le_16(page_number);
    7418                 :          0 :                 req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
    7419                 :            : 
    7420                 :          0 :                 xfer_size = RTE_MIN(data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
    7421                 :          0 :                 req.page_offset = rte_cpu_to_le_16(start_addr + byte_offset);
    7422                 :          0 :                 req.data_length = xfer_size;
    7423         [ #  # ]:          0 :                 req.enables = rte_cpu_to_le_32(start_addr + byte_offset ? enables : 0);
    7424                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7425   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7426                 :            : 
    7427                 :          0 :                 memcpy(buf + byte_offset, resp->data, xfer_size);
    7428                 :            : 
    7429                 :          0 :                 data_length -= xfer_size;
    7430                 :          0 :                 byte_offset += xfer_size;
    7431                 :            : 
    7432                 :            :                 HWRM_UNLOCK();
    7433         [ #  # ]:          0 :         } while (data_length > 0);
    7434                 :            : 
    7435                 :            :         return rc;
    7436                 :            : }
    7437                 :            : 
    7438                 :          0 : void bnxt_free_hwrm_tx_ring(struct bnxt *bp, int queue_index)
    7439                 :            : {
    7440                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[queue_index];
    7441                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
    7442                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
    7443                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
    7444                 :            : 
    7445                 :          0 :         bnxt_hwrm_ring_free(bp, ring,
    7446                 :            :                             HWRM_RING_FREE_INPUT_RING_TYPE_TX,
    7447                 :          0 :                             cpr->cp_ring_struct->fw_ring_id);
    7448                 :          0 :         txr->tx_raw_prod = 0;
    7449                 :          0 :         txr->tx_raw_cons = 0;
    7450                 :          0 :         memset(txr->tx_desc_ring, 0,
    7451                 :          0 :                 txr->tx_ring_struct->ring_size * sizeof(*txr->tx_desc_ring));
    7452                 :          0 :         memset(txr->tx_buf_ring, 0,
    7453                 :          0 :                 txr->tx_ring_struct->ring_size * sizeof(*txr->tx_buf_ring));
    7454                 :            : 
    7455                 :          0 :         bnxt_hwrm_stat_ctx_free(bp, cpr);
    7456                 :            : 
    7457                 :          0 :         bnxt_free_cp_ring(bp, cpr);
    7458                 :          0 : }
    7459                 :            : 
    7460                 :          0 : int bnxt_hwrm_config_host_mtu(struct bnxt *bp)
    7461                 :            : {
    7462                 :          0 :         struct hwrm_func_cfg_input req = {0};
    7463                 :          0 :         struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    7464                 :            :         int rc;
    7465                 :            : 
    7466         [ #  # ]:          0 :         if (!BNXT_PF(bp))
    7467                 :            :                 return 0;
    7468                 :            : 
    7469         [ #  # ]:          0 :         HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
    7470                 :            : 
    7471                 :          0 :         req.fid = rte_cpu_to_le_16(0xffff);
    7472                 :          0 :         req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_HOST_MTU);
    7473                 :          0 :         req.host_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu);
    7474                 :            : 
    7475                 :          0 :         rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7476   [ #  #  #  #  :          0 :         HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7477                 :            :         HWRM_UNLOCK();
    7478                 :            : 
    7479                 :          0 :         return rc;
    7480                 :            : }
    7481                 :            : 
    7482                 :            : int
    7483                 :          0 : bnxt_vnic_rss_clear_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
    7484                 :            : {
    7485                 :          0 :         struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
    7486                 :          0 :         struct hwrm_vnic_rss_cfg_input req = {0};
    7487                 :          0 :         int nr_ctxs = vnic->num_lb_ctxts;
    7488                 :            :         int i, rc = 0;
    7489                 :            : 
    7490         [ #  # ]:          0 :         for (i = 0; i < nr_ctxs; i++) {
    7491         [ #  # ]:          0 :                 HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
    7492                 :            : 
    7493                 :          0 :                 req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
    7494                 :          0 :                 req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
    7495                 :            : 
    7496                 :          0 :                 rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
    7497                 :            : 
    7498   [ #  #  #  #  :          0 :                 HWRM_CHECK_RESULT();
          #  #  #  #  #  
                #  #  # ]
    7499                 :            :                 HWRM_UNLOCK();
    7500                 :            :         }
    7501                 :            : 
    7502                 :            :         return rc;
    7503                 :            : }

Generated by: LCOV version 1.14