LCOV - code coverage report
Current view: top level - drivers/net/bnx2x - bnx2x.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 4245 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 237 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 2611 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2007-2013 Broadcom Corporation.
       3                 :            :  *
       4                 :            :  * Eric Davis        <edavis@broadcom.com>
       5                 :            :  * David Christensen <davidch@broadcom.com>
       6                 :            :  * Gary Zambrano     <zambrano@broadcom.com>
       7                 :            :  *
       8                 :            :  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
       9                 :            :  * Copyright (c) 2015-2018 Cavium Inc.
      10                 :            :  * All rights reserved.
      11                 :            :  * www.cavium.com
      12                 :            :  */
      13                 :            : 
      14                 :            : #define BNX2X_DRIVER_VERSION "1.78.18"
      15                 :            : 
      16                 :            : #include "bnx2x.h"
      17                 :            : #include "bnx2x_vfpf.h"
      18                 :            : #include "ecore_sp.h"
      19                 :            : #include "ecore_init.h"
      20                 :            : #include "ecore_init_ops.h"
      21                 :            : 
      22                 :            : #include "rte_version.h"
      23                 :            : 
      24                 :            : #include <sys/types.h>
      25                 :            : #include <sys/stat.h>
      26                 :            : #include <arpa/inet.h>
      27                 :            : #include <fcntl.h>
      28                 :            : #include <zlib.h>
      29                 :            : 
      30                 :            : #include <rte_bitops.h>
      31                 :            : #include <rte_string_fns.h>
      32                 :            : 
      33                 :            : #include "eal_firmware.h"
      34                 :            : 
      35                 :            : #define BNX2X_PMD_VER_PREFIX "BNX2X PMD"
      36                 :            : #define BNX2X_PMD_VERSION_MAJOR 1
      37                 :            : #define BNX2X_PMD_VERSION_MINOR 1
      38                 :            : #define BNX2X_PMD_VERSION_REVISION 0
      39                 :            : #define BNX2X_PMD_VERSION_PATCH 1
      40                 :            : 
      41                 :            : static inline const char *
      42                 :          0 : bnx2x_pmd_version(void)
      43                 :            : {
      44                 :            :         static char version[32];
      45                 :            : 
      46                 :            :         snprintf(version, sizeof(version), "%s %s_%d.%d.%d.%d",
      47                 :            :                         BNX2X_PMD_VER_PREFIX,
      48                 :            :                         BNX2X_DRIVER_VERSION,
      49                 :            :                         BNX2X_PMD_VERSION_MAJOR,
      50                 :            :                         BNX2X_PMD_VERSION_MINOR,
      51                 :            :                         BNX2X_PMD_VERSION_REVISION,
      52                 :            :                         BNX2X_PMD_VERSION_PATCH);
      53                 :            : 
      54                 :          0 :         return version;
      55                 :            : }
      56                 :            : 
      57                 :            : static z_stream zlib_stream;
      58                 :            : 
      59                 :            : #define EVL_VLID_MASK 0x0FFF
      60                 :            : 
      61                 :            : #define BNX2X_DEF_SB_ATT_IDX 0x0001
      62                 :            : #define BNX2X_DEF_SB_IDX     0x0002
      63                 :            : 
      64                 :            : /*
      65                 :            :  * FLR Support - bnx2x_pf_flr_clnup() is called during nic_load in the per
      66                 :            :  * function HW initialization.
      67                 :            :  */
      68                 :            : #define FLR_WAIT_USEC     10000 /* 10 msecs */
      69                 :            : #define FLR_WAIT_INTERVAL 50    /* usecs */
      70                 :            : #define FLR_POLL_CNT      (FLR_WAIT_USEC / FLR_WAIT_INTERVAL)   /* 200 */
      71                 :            : 
      72                 :            : struct pbf_pN_buf_regs {
      73                 :            :         int pN;
      74                 :            :         uint32_t init_crd;
      75                 :            :         uint32_t crd;
      76                 :            :         uint32_t crd_freed;
      77                 :            : };
      78                 :            : 
      79                 :            : struct pbf_pN_cmd_regs {
      80                 :            :         int pN;
      81                 :            :         uint32_t lines_occup;
      82                 :            :         uint32_t lines_freed;
      83                 :            : };
      84                 :            : 
      85                 :            : /* resources needed for unloading a previously loaded device */
      86                 :            : 
      87                 :            : #define BNX2X_PREV_WAIT_NEEDED 1
      88                 :            : rte_spinlock_t bnx2x_prev_mtx;
      89                 :            : struct bnx2x_prev_list_node {
      90                 :            :         LIST_ENTRY(bnx2x_prev_list_node) node;
      91                 :            :         uint8_t bus;
      92                 :            :         uint8_t slot;
      93                 :            :         uint8_t path;
      94                 :            :         uint8_t aer;
      95                 :            :         uint8_t undi;
      96                 :            : };
      97                 :            : 
      98                 :            : static LIST_HEAD(, bnx2x_prev_list_node) bnx2x_prev_list
      99                 :            :         = LIST_HEAD_INITIALIZER(bnx2x_prev_list);
     100                 :            : 
     101                 :            : static int load_count[2][3] = { { 0 } };
     102                 :            :         /* per-path: 0-common, 1-port0, 2-port1 */
     103                 :            : 
     104                 :            : static void bnx2x_cmng_fns_init(struct bnx2x_softc *sc, uint8_t read_cfg,
     105                 :            :                                 uint8_t cmng_type);
     106                 :            : static int bnx2x_get_cmng_fns_mode(struct bnx2x_softc *sc);
     107                 :            : static void storm_memset_cmng(struct bnx2x_softc *sc, struct cmng_init *cmng,
     108                 :            :                               uint8_t port);
     109                 :            : static void bnx2x_set_reset_global(struct bnx2x_softc *sc);
     110                 :            : static void bnx2x_set_reset_in_progress(struct bnx2x_softc *sc);
     111                 :            : static uint8_t bnx2x_reset_is_done(struct bnx2x_softc *sc, int engine);
     112                 :            : static uint8_t bnx2x_clear_pf_load(struct bnx2x_softc *sc);
     113                 :            : static uint8_t bnx2x_chk_parity_attn(struct bnx2x_softc *sc, uint8_t * global,
     114                 :            :                                      uint8_t print);
     115                 :            : static void bnx2x_int_disable(struct bnx2x_softc *sc);
     116                 :            : static int bnx2x_release_leader_lock(struct bnx2x_softc *sc);
     117                 :            : static void bnx2x_pf_disable(struct bnx2x_softc *sc);
     118                 :            : static void bnx2x_update_rx_prod(struct bnx2x_softc *sc,
     119                 :            :                                  struct bnx2x_fastpath *fp,
     120                 :            :                                  uint16_t rx_bd_prod, uint16_t rx_cq_prod);
     121                 :            : static void bnx2x_link_report_locked(struct bnx2x_softc *sc);
     122                 :            : static void bnx2x_link_report(struct bnx2x_softc *sc);
     123                 :            : void bnx2x_link_status_update(struct bnx2x_softc *sc);
     124                 :            : static int bnx2x_alloc_mem(struct bnx2x_softc *sc);
     125                 :            : static void bnx2x_free_mem(struct bnx2x_softc *sc);
     126                 :            : static int bnx2x_alloc_fw_stats_mem(struct bnx2x_softc *sc);
     127                 :            : static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc);
     128                 :            : static __rte_noinline
     129                 :            : int bnx2x_nic_load(struct bnx2x_softc *sc);
     130                 :            : 
     131                 :            : static int bnx2x_handle_sp_tq(struct bnx2x_softc *sc);
     132                 :            : static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp);
     133                 :            : static void bnx2x_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id,
     134                 :            :                          uint8_t storm, uint16_t index, uint8_t op,
     135                 :            :                          uint8_t update);
     136                 :            : 
     137                 :          0 : int bnx2x_cmpxchg(volatile int *addr, int old, int new)
     138                 :            : {
     139                 :          0 :         return __sync_val_compare_and_swap(addr, old, new);
     140                 :            : }
     141                 :            : 
     142                 :            : int
     143                 :          0 : bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma,
     144                 :            :               const char *msg, uint32_t align)
     145                 :            : {
     146                 :            :         char mz_name[RTE_MEMZONE_NAMESIZE];
     147                 :            :         const struct rte_memzone *z;
     148                 :            : 
     149                 :          0 :         dma->sc = sc;
     150         [ #  # ]:          0 :         if (IS_PF(sc))
     151                 :          0 :                 snprintf(mz_name, sizeof(mz_name), "bnx2x%d_%s_%" PRIx64, SC_ABS_FUNC(sc), msg,
     152                 :            :                         rte_get_timer_cycles());
     153                 :            :         else
     154                 :          0 :                 snprintf(mz_name, sizeof(mz_name), "bnx2x%d_%s_%" PRIx64, sc->pcie_device, msg,
     155                 :            :                         rte_get_timer_cycles());
     156                 :            : 
     157                 :            :         /* Caller must take care that strlen(mz_name) < RTE_MEMZONE_NAMESIZE */
     158                 :          0 :         z = rte_memzone_reserve_aligned(mz_name, (uint64_t)size,
     159                 :            :                                         SOCKET_ID_ANY,
     160                 :            :                                         RTE_MEMZONE_IOVA_CONTIG, align);
     161         [ #  # ]:          0 :         if (z == NULL) {
     162                 :          0 :                 PMD_DRV_LOG(ERR, sc, "DMA alloc failed for %s", msg);
     163                 :          0 :                 return -ENOMEM;
     164                 :            :         }
     165                 :          0 :         dma->paddr = (uint64_t) z->iova;
     166                 :          0 :         dma->vaddr = z->addr;
     167                 :          0 :         dma->mzone = (const void *)z;
     168                 :            : 
     169                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
     170                 :            :                     "%s: virt=%p phys=%" PRIx64, msg, dma->vaddr, dma->paddr);
     171                 :            : 
     172                 :          0 :         return 0;
     173                 :            : }
     174                 :            : 
     175                 :          0 : void bnx2x_dma_free(struct bnx2x_dma *dma)
     176                 :            : {
     177         [ #  # ]:          0 :         if (dma->mzone == NULL)
     178                 :            :                 return;
     179                 :            : 
     180                 :          0 :         rte_memzone_free((const struct rte_memzone *)dma->mzone);
     181                 :          0 :         dma->sc = NULL;
     182                 :          0 :         dma->paddr = 0;
     183                 :          0 :         dma->vaddr = NULL;
     184                 :          0 :         dma->nseg = 0;
     185                 :          0 :         dma->mzone = NULL;
     186                 :            : }
     187                 :            : 
     188                 :          0 : static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
     189                 :            : {
     190                 :            :         uint32_t lock_status;
     191                 :          0 :         uint32_t resource_bit = (1 << resource);
     192                 :          0 :         int func = SC_FUNC(sc);
     193                 :            :         uint32_t hw_lock_control_reg;
     194                 :            :         int cnt;
     195                 :            : 
     196                 :            : #ifndef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
     197         [ #  # ]:          0 :         if (resource)
     198                 :          0 :                 PMD_INIT_FUNC_TRACE(sc);
     199                 :            : #else
     200                 :            :         PMD_INIT_FUNC_TRACE(sc);
     201                 :            : #endif
     202                 :            : 
     203                 :            :         /* validate the resource is within range */
     204         [ #  # ]:          0 :         if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
     205                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
     206                 :            :                             "resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE",
     207                 :            :                             resource);
     208                 :          0 :                 return -1;
     209                 :            :         }
     210                 :            : 
     211         [ #  # ]:          0 :         if (func <= 5) {
     212                 :          0 :                 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
     213                 :            :         } else {
     214                 :          0 :                 hw_lock_control_reg =
     215                 :          0 :                     (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
     216                 :            :         }
     217                 :            : 
     218                 :            :         /* validate the resource is not already taken */
     219                 :          0 :         lock_status = REG_RD(sc, hw_lock_control_reg);
     220         [ #  # ]:          0 :         if (lock_status & resource_bit) {
     221                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
     222                 :            :                             "resource in use (status 0x%x bit 0x%x)",
     223                 :            :                             lock_status, resource_bit);
     224                 :          0 :                 return -1;
     225                 :            :         }
     226                 :            : 
     227                 :            :         /* try every 5ms for 5 seconds */
     228         [ #  # ]:          0 :         for (cnt = 0; cnt < 1000; cnt++) {
     229                 :          0 :                 REG_WR(sc, (hw_lock_control_reg + 4), resource_bit);
     230                 :            :                 lock_status = REG_RD(sc, hw_lock_control_reg);
     231         [ #  # ]:          0 :                 if (lock_status & resource_bit) {
     232                 :            :                         return 0;
     233                 :            :                 }
     234                 :          0 :                 DELAY(5000);
     235                 :            :         }
     236                 :            : 
     237                 :          0 :         PMD_DRV_LOG(NOTICE, sc, "Resource 0x%x resource_bit 0x%x lock timeout!",
     238                 :            :                     resource, resource_bit);
     239                 :          0 :         return -1;
     240                 :            : }
     241                 :            : 
     242                 :          0 : static int bnx2x_release_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
     243                 :            : {
     244                 :            :         uint32_t lock_status;
     245                 :          0 :         uint32_t resource_bit = (1 << resource);
     246                 :          0 :         int func = SC_FUNC(sc);
     247                 :            :         uint32_t hw_lock_control_reg;
     248                 :            : 
     249                 :            : #ifndef RTE_LIBRTE_BNX2X_DEBUG_PERIODIC
     250         [ #  # ]:          0 :         if (resource)
     251                 :          0 :                 PMD_INIT_FUNC_TRACE(sc);
     252                 :            : #else
     253                 :            :         PMD_INIT_FUNC_TRACE(sc);
     254                 :            : #endif
     255                 :            : 
     256                 :            :         /* validate the resource is within range */
     257         [ #  # ]:          0 :         if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
     258                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
     259                 :            :                             "(resource 0x%x > HW_LOCK_MAX_RESOURCE_VALUE)"
     260                 :            :                             " resource_bit 0x%x", resource, resource_bit);
     261                 :          0 :                 return -1;
     262                 :            :         }
     263                 :            : 
     264         [ #  # ]:          0 :         if (func <= 5) {
     265                 :          0 :                 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + (func * 8));
     266                 :            :         } else {
     267                 :          0 :                 hw_lock_control_reg =
     268                 :          0 :                     (MISC_REG_DRIVER_CONTROL_7 + ((func - 6) * 8));
     269                 :            :         }
     270                 :            : 
     271                 :            :         /* validate the resource is currently taken */
     272                 :          0 :         lock_status = REG_RD(sc, hw_lock_control_reg);
     273         [ #  # ]:          0 :         if (!(lock_status & resource_bit)) {
     274                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
     275                 :            :                             "resource not in use (status 0x%x bit 0x%x)",
     276                 :            :                             lock_status, resource_bit);
     277                 :          0 :                 return -1;
     278                 :            :         }
     279                 :            : 
     280                 :            :         REG_WR(sc, hw_lock_control_reg, resource_bit);
     281                 :          0 :         return 0;
     282                 :            : }
     283                 :            : 
     284                 :          0 : static void bnx2x_acquire_phy_lock(struct bnx2x_softc *sc)
     285                 :            : {
     286                 :          0 :         BNX2X_PHY_LOCK(sc);
     287                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_MDIO);
     288                 :          0 : }
     289                 :            : 
     290                 :            : static void bnx2x_release_phy_lock(struct bnx2x_softc *sc)
     291                 :            : {
     292                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_MDIO);
     293                 :          0 :         BNX2X_PHY_UNLOCK(sc);
     294                 :          0 : }
     295                 :            : 
     296                 :            : /* copy command into DMAE command memory and set DMAE command Go */
     297                 :          0 : void bnx2x_post_dmae(struct bnx2x_softc *sc, struct dmae_command *dmae, int idx)
     298                 :            : {
     299                 :            :         uint32_t cmd_offset;
     300                 :            :         uint32_t i;
     301                 :            : 
     302                 :          0 :         cmd_offset = (DMAE_REG_CMD_MEM + (sizeof(struct dmae_command) * idx));
     303         [ #  # ]:          0 :         for (i = 0; i < ((sizeof(struct dmae_command) / 4)); i++) {
     304                 :          0 :                 REG_WR(sc, (cmd_offset + (i * 4)), *(((uint32_t *) dmae) + i));
     305                 :            :         }
     306                 :            : 
     307                 :          0 :         REG_WR(sc, dmae_reg_go_c[idx], 1);
     308                 :          0 : }
     309                 :            : 
     310                 :          0 : uint32_t bnx2x_dmae_opcode_add_comp(uint32_t opcode, uint8_t comp_type)
     311                 :            : {
     312                 :          0 :         return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
     313                 :            :                           DMAE_COMMAND_C_TYPE_ENABLE);
     314                 :            : }
     315                 :            : 
     316                 :          0 : uint32_t bnx2x_dmae_opcode_clr_src_reset(uint32_t opcode)
     317                 :            : {
     318                 :          0 :         return opcode & ~DMAE_COMMAND_SRC_RESET;
     319                 :            : }
     320                 :            : 
     321                 :            : uint32_t
     322                 :          0 : bnx2x_dmae_opcode(struct bnx2x_softc * sc, uint8_t src_type, uint8_t dst_type,
     323                 :            :                 uint8_t with_comp, uint8_t comp_type)
     324                 :            : {
     325                 :            :         uint32_t opcode = 0;
     326                 :            : 
     327                 :          0 :         opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
     328                 :          0 :                    (dst_type << DMAE_COMMAND_DST_SHIFT));
     329                 :            : 
     330                 :          0 :         opcode |= (DMAE_COMMAND_SRC_RESET | DMAE_COMMAND_DST_RESET);
     331                 :            : 
     332                 :          0 :         opcode |= (SC_PORT(sc) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
     333                 :            : 
     334                 :          0 :         opcode |= ((SC_VN(sc) << DMAE_COMMAND_E1HVN_SHIFT) |
     335                 :          0 :                    (SC_VN(sc) << DMAE_COMMAND_DST_VN_SHIFT));
     336                 :            : 
     337                 :            :         opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
     338                 :            : 
     339                 :            : #ifdef __BIG_ENDIAN
     340                 :            :         opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
     341                 :            : #else
     342                 :          0 :         opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
     343                 :            : #endif
     344                 :            : 
     345         [ #  # ]:          0 :         if (with_comp) {
     346                 :          0 :                 opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
     347                 :            :         }
     348                 :            : 
     349                 :          0 :         return opcode;
     350                 :            : }
     351                 :            : 
     352                 :            : static void
     353                 :          0 : bnx2x_prep_dmae_with_comp(struct bnx2x_softc *sc, struct dmae_command *dmae,
     354                 :            :                         uint8_t src_type, uint8_t dst_type)
     355                 :            : {
     356                 :            :         memset(dmae, 0, sizeof(struct dmae_command));
     357                 :            : 
     358                 :            :         /* set the opcode */
     359                 :          0 :         dmae->opcode = bnx2x_dmae_opcode(sc, src_type, dst_type,
     360                 :            :                                        TRUE, DMAE_COMP_PCI);
     361                 :            : 
     362                 :            :         /* fill in the completion parameters */
     363                 :          0 :         dmae->comp_addr_lo = U64_LO(BNX2X_SP_MAPPING(sc, wb_comp));
     364                 :          0 :         dmae->comp_addr_hi = U64_HI(BNX2X_SP_MAPPING(sc, wb_comp));
     365                 :          0 :         dmae->comp_val = DMAE_COMP_VAL;
     366                 :          0 : }
     367                 :            : 
     368                 :            : /* issue a DMAE command over the init channel and wait for completion */
     369                 :            : static int
     370                 :          0 : bnx2x_issue_dmae_with_comp(struct bnx2x_softc *sc, struct dmae_command *dmae)
     371                 :            : {
     372                 :          0 :         uint32_t *wb_comp = BNX2X_SP(sc, wb_comp);
     373         [ #  # ]:          0 :         int timeout = CHIP_REV_IS_SLOW(sc) ? 400000 : 4000;
     374                 :            : 
     375                 :            :         /* reset completion */
     376                 :          0 :         *wb_comp = 0;
     377                 :            : 
     378                 :            :         /* post the command on the channel used for initializations */
     379                 :          0 :         bnx2x_post_dmae(sc, dmae, INIT_DMAE_C(sc));
     380                 :            : 
     381                 :            :         /* wait for completion */
     382                 :          0 :         DELAY(500);
     383                 :            : 
     384         [ #  # ]:          0 :         while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
     385         [ #  # ]:          0 :                 if (!timeout ||
     386         [ #  # ]:          0 :                     (sc->recovery_state != BNX2X_RECOVERY_DONE &&
     387                 :            :                      sc->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
     388                 :          0 :                         PMD_DRV_LOG(INFO, sc, "DMAE timeout!");
     389                 :          0 :                         return DMAE_TIMEOUT;
     390                 :            :                 }
     391                 :            : 
     392                 :          0 :                 timeout--;
     393                 :          0 :                 DELAY(50);
     394                 :            :         }
     395                 :            : 
     396         [ #  # ]:          0 :         if (*wb_comp & DMAE_PCI_ERR_FLAG) {
     397                 :          0 :                 PMD_DRV_LOG(INFO, sc, "DMAE PCI error!");
     398                 :          0 :                 return DMAE_PCI_ERROR;
     399                 :            :         }
     400                 :            : 
     401                 :            :         return 0;
     402                 :            : }
     403                 :            : 
     404                 :          0 : void bnx2x_read_dmae(struct bnx2x_softc *sc, uint32_t src_addr, uint32_t len32)
     405                 :            : {
     406                 :            :         struct dmae_command dmae;
     407                 :            :         uint32_t *data;
     408                 :            :         uint32_t i;
     409                 :            :         int rc;
     410                 :            : 
     411         [ #  # ]:          0 :         if (!sc->dmae_ready) {
     412                 :          0 :                 data = BNX2X_SP(sc, wb_data[0]);
     413                 :            : 
     414         [ #  # ]:          0 :                 for (i = 0; i < len32; i++) {
     415                 :          0 :                         data[i] = REG_RD(sc, (src_addr + (i * 4)));
     416                 :            :                 }
     417                 :            : 
     418                 :          0 :                 return;
     419                 :            :         }
     420                 :            : 
     421                 :            :         /* set opcode and fixed command fields */
     422                 :          0 :         bnx2x_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
     423                 :            : 
     424                 :            :         /* fill in addresses and len */
     425                 :          0 :         dmae.src_addr_lo = (src_addr >> 2);       /* GRC addr has dword resolution */
     426                 :          0 :         dmae.src_addr_hi = 0;
     427                 :          0 :         dmae.dst_addr_lo = U64_LO(BNX2X_SP_MAPPING(sc, wb_data));
     428                 :          0 :         dmae.dst_addr_hi = U64_HI(BNX2X_SP_MAPPING(sc, wb_data));
     429                 :          0 :         dmae.len = len32;
     430                 :            : 
     431                 :            :         /* issue the command and wait for completion */
     432         [ #  # ]:          0 :         if ((rc = bnx2x_issue_dmae_with_comp(sc, &dmae)) != 0) {
     433                 :          0 :                 rte_panic("DMAE failed (%d)", rc);
     434                 :            :         };
     435                 :            : }
     436                 :            : 
     437                 :            : void
     438                 :          0 : bnx2x_write_dmae(struct bnx2x_softc *sc, rte_iova_t dma_addr, uint32_t dst_addr,
     439                 :            :                uint32_t len32)
     440                 :            : {
     441                 :            :         struct dmae_command dmae;
     442                 :            :         int rc;
     443                 :            : 
     444         [ #  # ]:          0 :         if (!sc->dmae_ready) {
     445                 :          0 :                 ecore_init_str_wr(sc, dst_addr, BNX2X_SP(sc, wb_data[0]), len32);
     446                 :          0 :                 return;
     447                 :            :         }
     448                 :            : 
     449                 :            :         /* set opcode and fixed command fields */
     450                 :          0 :         bnx2x_prep_dmae_with_comp(sc, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
     451                 :            : 
     452                 :            :         /* fill in addresses and len */
     453                 :          0 :         dmae.src_addr_lo = U64_LO(dma_addr);
     454                 :          0 :         dmae.src_addr_hi = U64_HI(dma_addr);
     455                 :          0 :         dmae.dst_addr_lo = (dst_addr >> 2);       /* GRC addr has dword resolution */
     456                 :          0 :         dmae.dst_addr_hi = 0;
     457                 :          0 :         dmae.len = len32;
     458                 :            : 
     459                 :            :         /* issue the command and wait for completion */
     460         [ #  # ]:          0 :         if ((rc = bnx2x_issue_dmae_with_comp(sc, &dmae)) != 0) {
     461                 :          0 :                 rte_panic("DMAE failed (%d)", rc);
     462                 :            :         }
     463                 :            : }
     464                 :            : 
     465                 :            : static void
     466                 :          0 : bnx2x_write_dmae_phys_len(struct bnx2x_softc *sc, rte_iova_t phys_addr,
     467                 :            :                         uint32_t addr, uint32_t len)
     468                 :            : {
     469                 :            :         uint32_t dmae_wr_max = DMAE_LEN32_WR_MAX(sc);
     470                 :            :         uint32_t offset = 0;
     471                 :            : 
     472         [ #  # ]:          0 :         while (len > dmae_wr_max) {
     473                 :          0 :                 bnx2x_write_dmae(sc, (phys_addr + offset),      /* src DMA address */
     474                 :            :                                (addr + offset), /* dst GRC address */
     475                 :            :                                dmae_wr_max);
     476                 :          0 :                 offset += (dmae_wr_max * 4);
     477                 :          0 :                 len -= dmae_wr_max;
     478                 :            :         }
     479                 :            : 
     480                 :          0 :         bnx2x_write_dmae(sc, (phys_addr + offset),      /* src DMA address */
     481                 :            :                        (addr + offset), /* dst GRC address */
     482                 :            :                        len);
     483                 :          0 : }
     484                 :            : 
     485                 :            : void
     486                 :          0 : bnx2x_set_ctx_validation(struct bnx2x_softc *sc, struct eth_context *cxt,
     487                 :            :                        uint32_t cid)
     488                 :            : {
     489                 :            :         /* ustorm cxt validation */
     490                 :          0 :         cxt->ustorm_ag_context.cdu_usage =
     491                 :          0 :             CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
     492                 :            :                                    CDU_REGION_NUMBER_UCM_AG,
     493                 :            :                                    ETH_CONNECTION_TYPE);
     494                 :            :         /* xcontext validation */
     495                 :          0 :         cxt->xstorm_ag_context.cdu_reserved =
     496                 :          0 :             CDU_RSRVD_VALUE_TYPE_A(HW_CID(sc, cid),
     497                 :            :                                    CDU_REGION_NUMBER_XCM_AG,
     498                 :            :                                    ETH_CONNECTION_TYPE);
     499                 :          0 : }
     500                 :            : 
     501                 :            : static void
     502                 :            : bnx2x_storm_memset_hc_timeout(struct bnx2x_softc *sc, uint8_t fw_sb_id,
     503                 :            :                             uint8_t sb_index, uint8_t ticks)
     504                 :            : {
     505                 :          0 :         uint32_t addr =
     506                 :            :             (BAR_CSTRORM_INTMEM +
     507                 :          0 :              CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index));
     508                 :            : 
     509                 :          0 :         REG_WR8(sc, addr, ticks);
     510                 :            : }
     511                 :            : 
     512                 :            : static void
     513                 :          0 : bnx2x_storm_memset_hc_disable(struct bnx2x_softc *sc, uint16_t fw_sb_id,
     514                 :            :                             uint8_t sb_index, uint8_t disable)
     515                 :            : {
     516                 :            :         uint32_t enable_flag =
     517         [ #  # ]:          0 :             (disable) ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
     518                 :          0 :         uint32_t addr =
     519                 :            :             (BAR_CSTRORM_INTMEM +
     520                 :          0 :              CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index));
     521                 :            :         uint8_t flags;
     522                 :            : 
     523                 :            :         /* clear and set */
     524                 :          0 :         flags = REG_RD8(sc, addr);
     525                 :          0 :         flags &= ~HC_INDEX_DATA_HC_ENABLED;
     526                 :          0 :         flags |= enable_flag;
     527                 :            :         REG_WR8(sc, addr, flags);
     528                 :          0 : }
     529                 :            : 
     530                 :            : void
     531                 :          0 : bnx2x_update_coalesce_sb_index(struct bnx2x_softc *sc, uint8_t fw_sb_id,
     532                 :            :                              uint8_t sb_index, uint8_t disable, uint16_t usec)
     533                 :            : {
     534                 :          0 :         uint8_t ticks = (usec / 4);
     535                 :            : 
     536                 :          0 :         bnx2x_storm_memset_hc_timeout(sc, fw_sb_id, sb_index, ticks);
     537                 :            : 
     538                 :          0 :         disable = (disable) ? 1 : ((usec) ? 0 : 1);
     539                 :          0 :         bnx2x_storm_memset_hc_disable(sc, fw_sb_id, sb_index, disable);
     540                 :          0 : }
     541                 :            : 
     542                 :          0 : uint32_t elink_cb_reg_read(struct bnx2x_softc *sc, uint32_t reg_addr)
     543                 :            : {
     544                 :          0 :         return REG_RD(sc, reg_addr);
     545                 :            : }
     546                 :            : 
     547                 :          0 : void elink_cb_reg_write(struct bnx2x_softc *sc, uint32_t reg_addr, uint32_t val)
     548                 :            : {
     549                 :          0 :         REG_WR(sc, reg_addr, val);
     550                 :          0 : }
     551                 :            : 
     552                 :            : void
     553                 :          0 : elink_cb_event_log(__rte_unused struct bnx2x_softc *sc,
     554                 :            :                    __rte_unused const elink_log_id_t elink_log_id, ...)
     555                 :            : {
     556                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "ELINK EVENT LOG (%d)", elink_log_id);
     557                 :          0 : }
     558                 :            : 
     559                 :          0 : static int bnx2x_set_spio(struct bnx2x_softc *sc, int spio, uint32_t mode)
     560                 :            : {
     561                 :            :         uint32_t spio_reg;
     562                 :            : 
     563                 :            :         /* Only 2 SPIOs are configurable */
     564         [ #  # ]:          0 :         if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
     565                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid SPIO 0x%x", spio);
     566                 :          0 :                 return -1;
     567                 :            :         }
     568                 :            : 
     569                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
     570                 :            : 
     571                 :            :         /* read SPIO and mask except the float bits */
     572                 :          0 :         spio_reg = (REG_RD(sc, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
     573                 :            : 
     574   [ #  #  #  # ]:          0 :         switch (mode) {
     575                 :          0 :         case MISC_SPIO_OUTPUT_LOW:
     576                 :            :                 /* clear FLOAT and set CLR */
     577                 :          0 :                 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
     578                 :          0 :                 spio_reg |= (spio << MISC_SPIO_CLR_POS);
     579                 :          0 :                 break;
     580                 :            : 
     581                 :          0 :         case MISC_SPIO_OUTPUT_HIGH:
     582                 :            :                 /* clear FLOAT and set SET */
     583                 :          0 :                 spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
     584                 :          0 :                 spio_reg |= (spio << MISC_SPIO_SET_POS);
     585                 :          0 :                 break;
     586                 :            : 
     587                 :          0 :         case MISC_SPIO_INPUT_HI_Z:
     588                 :            :                 /* set FLOAT */
     589                 :          0 :                 spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
     590                 :          0 :                 break;
     591                 :            : 
     592                 :            :         default:
     593                 :            :                 break;
     594                 :            :         }
     595                 :            : 
     596                 :            :         REG_WR(sc, MISC_REG_SPIO, spio_reg);
     597                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_SPIO);
     598                 :            : 
     599                 :          0 :         return 0;
     600                 :            : }
     601                 :            : 
     602                 :          0 : static int bnx2x_gpio_read(struct bnx2x_softc *sc, int gpio_num, uint8_t port)
     603                 :            : {
     604                 :            :         /* The GPIO should be swapped if swap register is set and active */
     605   [ #  #  #  # ]:          0 :         int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
     606                 :          0 :                           REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
     607                 :            :         int gpio_shift = gpio_num;
     608         [ #  # ]:          0 :         if (gpio_port)
     609                 :          0 :                 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
     610                 :            : 
     611                 :          0 :         uint32_t gpio_mask = (1 << gpio_shift);
     612                 :            :         uint32_t gpio_reg;
     613                 :            : 
     614         [ #  # ]:          0 :         if (gpio_num > MISC_REGISTERS_GPIO_3) {
     615                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
     616                 :          0 :                 return -1;
     617                 :            :         }
     618                 :            : 
     619                 :            :         /* read GPIO value */
     620                 :            :         gpio_reg = REG_RD(sc, MISC_REG_GPIO);
     621                 :            : 
     622                 :            :         /* get the requested pin value */
     623                 :          0 :         return ((gpio_reg & gpio_mask) == gpio_mask) ? 1 : 0;
     624                 :            : }
     625                 :            : 
     626                 :            : static int
     627                 :          0 : bnx2x_gpio_write(struct bnx2x_softc *sc, int gpio_num, uint32_t mode, uint8_t port)
     628                 :            : {
     629                 :            :         /* The GPIO should be swapped if swap register is set and active */
     630   [ #  #  #  # ]:          0 :         int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
     631                 :          0 :                           REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
     632                 :            :         int gpio_shift = gpio_num;
     633         [ #  # ]:          0 :         if (gpio_port)
     634                 :          0 :                 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
     635                 :            : 
     636                 :          0 :         uint32_t gpio_mask = (1 << gpio_shift);
     637                 :            :         uint32_t gpio_reg;
     638                 :            : 
     639         [ #  # ]:          0 :         if (gpio_num > MISC_REGISTERS_GPIO_3) {
     640                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
     641                 :          0 :                 return -1;
     642                 :            :         }
     643                 :            : 
     644                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     645                 :            : 
     646                 :            :         /* read GPIO and mask except the float bits */
     647                 :          0 :         gpio_reg = (REG_RD(sc, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
     648                 :            : 
     649   [ #  #  #  # ]:          0 :         switch (mode) {
     650                 :          0 :         case MISC_REGISTERS_GPIO_OUTPUT_LOW:
     651                 :            :                 /* clear FLOAT and set CLR */
     652                 :          0 :                 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
     653                 :          0 :                 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
     654                 :          0 :                 break;
     655                 :            : 
     656                 :          0 :         case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
     657                 :            :                 /* clear FLOAT and set SET */
     658                 :          0 :                 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
     659                 :          0 :                 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
     660                 :          0 :                 break;
     661                 :            : 
     662                 :          0 :         case MISC_REGISTERS_GPIO_INPUT_HI_Z:
     663                 :            :                 /* set FLOAT */
     664                 :          0 :                 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
     665                 :          0 :                 break;
     666                 :            : 
     667                 :            :         default:
     668                 :            :                 break;
     669                 :            :         }
     670                 :            : 
     671                 :            :         REG_WR(sc, MISC_REG_GPIO, gpio_reg);
     672                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     673                 :            : 
     674                 :          0 :         return 0;
     675                 :            : }
     676                 :            : 
     677                 :            : static int
     678                 :          0 : bnx2x_gpio_mult_write(struct bnx2x_softc *sc, uint8_t pins, uint32_t mode)
     679                 :            : {
     680                 :            :         uint32_t gpio_reg;
     681                 :            : 
     682                 :            :         /* any port swapping should be handled by caller */
     683                 :            : 
     684                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     685                 :            : 
     686                 :            :         /* read GPIO and mask except the float bits */
     687                 :            :         gpio_reg = REG_RD(sc, MISC_REG_GPIO);
     688                 :          0 :         gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
     689                 :          0 :         gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
     690                 :          0 :         gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
     691                 :            : 
     692   [ #  #  #  # ]:          0 :         switch (mode) {
     693                 :          0 :         case MISC_REGISTERS_GPIO_OUTPUT_LOW:
     694                 :            :                 /* set CLR */
     695                 :          0 :                 gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
     696                 :          0 :                 break;
     697                 :            : 
     698                 :          0 :         case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
     699                 :            :                 /* set SET */
     700                 :          0 :                 gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
     701                 :          0 :                 break;
     702                 :            : 
     703                 :          0 :         case MISC_REGISTERS_GPIO_INPUT_HI_Z:
     704                 :            :                 /* set FLOAT */
     705                 :          0 :                 gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
     706                 :          0 :                 break;
     707                 :            : 
     708                 :          0 :         default:
     709                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
     710                 :            :                             "Invalid GPIO mode assignment %d", mode);
     711                 :          0 :                 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     712                 :          0 :                 return -1;
     713                 :            :         }
     714                 :            : 
     715                 :            :         REG_WR(sc, MISC_REG_GPIO, gpio_reg);
     716                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     717                 :            : 
     718                 :          0 :         return 0;
     719                 :            : }
     720                 :            : 
     721                 :            : static int
     722                 :          0 : bnx2x_gpio_int_write(struct bnx2x_softc *sc, int gpio_num, uint32_t mode,
     723                 :            :                    uint8_t port)
     724                 :            : {
     725                 :            :         /* The GPIO should be swapped if swap register is set and active */
     726   [ #  #  #  # ]:          0 :         int gpio_port = ((REG_RD(sc, NIG_REG_PORT_SWAP) &&
     727                 :          0 :                           REG_RD(sc, NIG_REG_STRAP_OVERRIDE)) ^ port);
     728                 :            :         int gpio_shift = gpio_num;
     729         [ #  # ]:          0 :         if (gpio_port)
     730                 :          0 :                 gpio_shift += MISC_REGISTERS_GPIO_PORT_SHIFT;
     731                 :            : 
     732                 :          0 :         uint32_t gpio_mask = (1 << gpio_shift);
     733                 :            :         uint32_t gpio_reg;
     734                 :            : 
     735         [ #  # ]:          0 :         if (gpio_num > MISC_REGISTERS_GPIO_3) {
     736                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid GPIO %d", gpio_num);
     737                 :          0 :                 return -1;
     738                 :            :         }
     739                 :            : 
     740                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     741                 :            : 
     742                 :            :         /* read GPIO int */
     743                 :            :         gpio_reg = REG_RD(sc, MISC_REG_GPIO_INT);
     744                 :            : 
     745      [ #  #  # ]:          0 :         switch (mode) {
     746                 :          0 :         case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
     747                 :            :                 /* clear SET and set CLR */
     748                 :          0 :                 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
     749                 :          0 :                 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
     750                 :          0 :                 break;
     751                 :            : 
     752                 :          0 :         case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
     753                 :            :                 /* clear CLR and set SET */
     754                 :          0 :                 gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
     755                 :          0 :                 gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
     756                 :          0 :                 break;
     757                 :            : 
     758                 :            :         default:
     759                 :            :                 break;
     760                 :            :         }
     761                 :            : 
     762                 :            :         REG_WR(sc, MISC_REG_GPIO_INT, gpio_reg);
     763                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_GPIO);
     764                 :            : 
     765                 :          0 :         return 0;
     766                 :            : }
     767                 :            : 
     768                 :            : uint32_t
     769                 :          0 : elink_cb_gpio_read(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t port)
     770                 :            : {
     771                 :          0 :         return bnx2x_gpio_read(sc, gpio_num, port);
     772                 :            : }
     773                 :            : 
     774                 :          0 : uint8_t elink_cb_gpio_write(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t mode,   /* 0=low 1=high */
     775                 :            :                             uint8_t port)
     776                 :            : {
     777                 :          0 :         return bnx2x_gpio_write(sc, gpio_num, mode, port);
     778                 :            : }
     779                 :            : 
     780                 :            : uint8_t
     781                 :          0 : elink_cb_gpio_mult_write(struct bnx2x_softc * sc, uint8_t pins,
     782                 :            :                          uint8_t mode /* 0=low 1=high */ )
     783                 :            : {
     784                 :          0 :         return bnx2x_gpio_mult_write(sc, pins, mode);
     785                 :            : }
     786                 :            : 
     787                 :          0 : uint8_t elink_cb_gpio_int_write(struct bnx2x_softc * sc, uint16_t gpio_num, uint8_t mode,       /* 0=low 1=high */
     788                 :            :                                 uint8_t port)
     789                 :            : {
     790                 :          0 :         return bnx2x_gpio_int_write(sc, gpio_num, mode, port);
     791                 :            : }
     792                 :            : 
     793                 :          0 : void elink_cb_notify_link_changed(struct bnx2x_softc *sc)
     794                 :            : {
     795                 :          0 :         REG_WR(sc, (MISC_REG_AEU_GENERAL_ATTN_12 +
     796                 :            :                     (SC_FUNC(sc) * sizeof(uint32_t))), 1);
     797                 :          0 : }
     798                 :            : 
     799                 :            : /* send the MCP a request, block until there is a reply */
     800                 :            : uint32_t
     801                 :          0 : elink_cb_fw_command(struct bnx2x_softc *sc, uint32_t command, uint32_t param)
     802                 :            : {
     803   [ #  #  #  # ]:          0 :         int mb_idx = SC_FW_MB_IDX(sc);
     804                 :            :         uint32_t seq;
     805                 :            :         uint32_t rc = 0;
     806                 :            :         uint32_t cnt = 1;
     807         [ #  # ]:          0 :         uint8_t delay = CHIP_REV_IS_SLOW(sc) ? 100 : 10;
     808                 :            : 
     809                 :          0 :         seq = ++sc->fw_seq;
     810                 :          0 :         SHMEM_WR(sc, func_mb[mb_idx].drv_mb_param, param);
     811                 :          0 :         SHMEM_WR(sc, func_mb[mb_idx].drv_mb_header, (command | seq));
     812                 :            : 
     813                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
     814                 :            :                     "wrote command 0x%08x to FW MB param 0x%08x",
     815                 :            :                     (command | seq), param);
     816                 :            : 
     817                 :            :         /* Let the FW do it's magic. GIve it up to 5 seconds... */
     818                 :            :         do {
     819                 :          0 :                 DELAY(delay * 1000);
     820                 :          0 :                 rc = SHMEM_RD(sc, func_mb[mb_idx].fw_mb_header);
     821   [ #  #  #  # ]:          0 :         } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
     822                 :            : 
     823                 :            :         /* is this a reply to our command? */
     824         [ #  # ]:          0 :         if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
     825                 :          0 :                 rc &= FW_MSG_CODE_MASK;
     826                 :            :         } else {
     827                 :            :                 /* Ruh-roh! */
     828                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "FW failed to respond!");
     829                 :            :                 rc = 0;
     830                 :            :         }
     831                 :            : 
     832                 :          0 :         return rc;
     833                 :            : }
     834                 :            : 
     835                 :            : static uint32_t
     836                 :            : bnx2x_fw_command(struct bnx2x_softc *sc, uint32_t command, uint32_t param)
     837                 :            : {
     838                 :          0 :         return elink_cb_fw_command(sc, command, param);
     839                 :            : }
     840                 :            : 
     841                 :            : static void
     842                 :            : __storm_memset_dma_mapping(struct bnx2x_softc *sc, uint32_t addr,
     843                 :            :                            rte_iova_t mapping)
     844                 :            : {
     845                 :          0 :         REG_WR(sc, addr, U64_LO(mapping));
     846                 :          0 :         REG_WR(sc, (addr + 4), U64_HI(mapping));
     847                 :            : }
     848                 :            : 
     849                 :            : static void
     850                 :            : storm_memset_spq_addr(struct bnx2x_softc *sc, rte_iova_t mapping,
     851                 :            :                       uint16_t abs_fid)
     852                 :            : {
     853                 :          0 :         uint32_t addr = (XSEM_REG_FAST_MEMORY +
     854                 :          0 :                          XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid));
     855                 :            :         __storm_memset_dma_mapping(sc, addr, mapping);
     856                 :            : }
     857                 :            : 
     858                 :            : static void
     859                 :          0 : storm_memset_vf_to_pf(struct bnx2x_softc *sc, uint16_t abs_fid, uint16_t pf_id)
     860                 :            : {
     861                 :          0 :         REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid)),
     862                 :            :                 pf_id);
     863                 :          0 :         REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid)),
     864                 :            :                 pf_id);
     865                 :          0 :         REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid)),
     866                 :            :                 pf_id);
     867                 :          0 :         REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid)),
     868                 :            :                 pf_id);
     869                 :          0 : }
     870                 :            : 
     871                 :            : static void
     872                 :          0 : storm_memset_func_en(struct bnx2x_softc *sc, uint16_t abs_fid, uint8_t enable)
     873                 :            : {
     874                 :          0 :         REG_WR8(sc, (BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid)),
     875                 :            :                 enable);
     876                 :          0 :         REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid)),
     877                 :            :                 enable);
     878                 :          0 :         REG_WR8(sc, (BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid)),
     879                 :            :                 enable);
     880                 :          0 :         REG_WR8(sc, (BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid)),
     881                 :            :                 enable);
     882                 :          0 : }
     883                 :            : 
     884                 :            : static void
     885                 :          0 : storm_memset_eq_data(struct bnx2x_softc *sc, struct event_ring_data *eq_data,
     886                 :            :                      uint16_t pfid)
     887                 :            : {
     888                 :            :         uint32_t addr;
     889                 :            :         size_t size;
     890                 :            : 
     891                 :          0 :         addr = (BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid));
     892                 :            :         size = sizeof(struct event_ring_data);
     893                 :          0 :         ecore_storm_memset_struct(sc, addr, size, (uint32_t *) eq_data);
     894                 :          0 : }
     895                 :            : 
     896                 :            : static void
     897                 :            : storm_memset_eq_prod(struct bnx2x_softc *sc, uint16_t eq_prod, uint16_t pfid)
     898                 :            : {
     899                 :          0 :         uint32_t addr = (BAR_CSTRORM_INTMEM +
     900                 :          0 :                          CSTORM_EVENT_RING_PROD_OFFSET(pfid));
     901                 :          0 :         REG_WR16(sc, addr, eq_prod);
     902                 :            : }
     903                 :            : 
     904                 :            : /*
     905                 :            :  * Post a slowpath command.
     906                 :            :  *
     907                 :            :  * A slowpath command is used to propagate a configuration change through
     908                 :            :  * the controller in a controlled manner, allowing each STORM processor and
     909                 :            :  * other H/W blocks to phase in the change.  The commands sent on the
     910                 :            :  * slowpath are referred to as ramrods.  Depending on the ramrod used the
     911                 :            :  * completion of the ramrod will occur in different ways.  Here's a
     912                 :            :  * breakdown of ramrods and how they complete:
     913                 :            :  *
     914                 :            :  * RAMROD_CMD_ID_ETH_PORT_SETUP
     915                 :            :  *   Used to setup the leading connection on a port.  Completes on the
     916                 :            :  *   Receive Completion Queue (RCQ) of that port (typically fp[0]).
     917                 :            :  *
     918                 :            :  * RAMROD_CMD_ID_ETH_CLIENT_SETUP
     919                 :            :  *   Used to setup an additional connection on a port.  Completes on the
     920                 :            :  *   RCQ of the multi-queue/RSS connection being initialized.
     921                 :            :  *
     922                 :            :  * RAMROD_CMD_ID_ETH_STAT_QUERY
     923                 :            :  *   Used to force the storm processors to update the statistics database
     924                 :            :  *   in host memory.  This ramrod is send on the leading connection CID and
     925                 :            :  *   completes as an index increment of the CSTORM on the default status
     926                 :            :  *   block.
     927                 :            :  *
     928                 :            :  * RAMROD_CMD_ID_ETH_UPDATE
     929                 :            :  *   Used to update the state of the leading connection, usually to update
     930                 :            :  *   the RSS indirection table.  Completes on the RCQ of the leading
     931                 :            :  *   connection. (Not currently used under FreeBSD until OS support becomes
     932                 :            :  *   available.)
     933                 :            :  *
     934                 :            :  * RAMROD_CMD_ID_ETH_HALT
     935                 :            :  *   Used when tearing down a connection prior to driver unload.  Completes
     936                 :            :  *   on the RCQ of the multi-queue/RSS connection being torn down.  Don't
     937                 :            :  *   use this on the leading connection.
     938                 :            :  *
     939                 :            :  * RAMROD_CMD_ID_ETH_SET_MAC
     940                 :            :  *   Sets the Unicast/Broadcast/Multicast used by the port.  Completes on
     941                 :            :  *   the RCQ of the leading connection.
     942                 :            :  *
     943                 :            :  * RAMROD_CMD_ID_ETH_CFC_DEL
     944                 :            :  *   Used when tearing down a connection prior to driver unload.  Completes
     945                 :            :  *   on the RCQ of the leading connection (since the current connection
     946                 :            :  *   has been completely removed from controller memory).
     947                 :            :  *
     948                 :            :  * RAMROD_CMD_ID_ETH_PORT_DEL
     949                 :            :  *   Used to tear down the leading connection prior to driver unload,
     950                 :            :  *   typically fp[0].  Completes as an index increment of the CSTORM on the
     951                 :            :  *   default status block.
     952                 :            :  *
     953                 :            :  * RAMROD_CMD_ID_ETH_FORWARD_SETUP
     954                 :            :  *   Used for connection offload.  Completes on the RCQ of the multi-queue
     955                 :            :  *   RSS connection that is being offloaded.  (Not currently used under
     956                 :            :  *   FreeBSD.)
     957                 :            :  *
     958                 :            :  * There can only be one command pending per function.
     959                 :            :  *
     960                 :            :  * Returns:
     961                 :            :  *   0 = Success, !0 = Failure.
     962                 :            :  */
     963                 :            : 
     964                 :            : /* must be called under the spq lock */
     965                 :            : static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x_softc *sc)
     966                 :            : {
     967                 :          0 :         struct eth_spe *next_spe = sc->spq_prod_bd;
     968                 :            : 
     969         [ #  # ]:          0 :         if (sc->spq_prod_bd == sc->spq_last_bd) {
     970                 :            :                 /* wrap back to the first eth_spq */
     971                 :          0 :                 sc->spq_prod_bd = sc->spq;
     972                 :          0 :                 sc->spq_prod_idx = 0;
     973                 :            :         } else {
     974                 :          0 :                 sc->spq_prod_bd++;
     975                 :          0 :                 sc->spq_prod_idx++;
     976                 :            :         }
     977                 :            : 
     978                 :            :         return next_spe;
     979                 :            : }
     980                 :            : 
     981                 :            : /* must be called under the spq lock */
     982                 :            : static void bnx2x_sp_prod_update(struct bnx2x_softc *sc)
     983                 :            : {
     984                 :          0 :         int func = SC_FUNC(sc);
     985                 :            : 
     986                 :            :         /*
     987                 :            :          * Make sure that BD data is updated before writing the producer.
     988                 :            :          * BD data is written to the memory, the producer is read from the
     989                 :            :          * memory, thus we need a full memory barrier to ensure the ordering.
     990                 :            :          */
     991                 :            :         mb();
     992                 :            : 
     993                 :          0 :         REG_WR16(sc, (BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func)),
     994                 :            :                  sc->spq_prod_idx);
     995                 :            : 
     996                 :            :         mb();
     997                 :            : }
     998                 :            : 
     999                 :            : /**
    1000                 :            :  * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
    1001                 :            :  *
    1002                 :            :  * @cmd:      command to check
    1003                 :            :  * @cmd_type: command type
    1004                 :            :  */
    1005                 :            : static int bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
    1006                 :            : {
    1007                 :          0 :         if ((cmd_type == NONE_CONNECTION_TYPE) ||
    1008                 :          0 :             (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
    1009         [ #  # ]:          0 :             (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
    1010                 :            :             (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
    1011                 :          0 :             (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
    1012   [ #  #  #  # ]:          0 :             (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
    1013                 :            :             (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE)) {
    1014                 :            :                 return TRUE;
    1015                 :            :         } else {
    1016                 :            :                 return FALSE;
    1017                 :            :         }
    1018                 :            : }
    1019                 :            : 
    1020                 :            : /**
    1021                 :            :  * bnx2x_sp_post - place a single command on an SP ring
    1022                 :            :  *
    1023                 :            :  * @sc:         driver handle
    1024                 :            :  * @command:    command to place (e.g. SETUP, FILTER_RULES, etc.)
    1025                 :            :  * @cid:        SW CID the command is related to
    1026                 :            :  * @data_hi:    command private data address (high 32 bits)
    1027                 :            :  * @data_lo:    command private data address (low 32 bits)
    1028                 :            :  * @cmd_type:   command type (e.g. NONE, ETH)
    1029                 :            :  *
    1030                 :            :  * SP data is handled as if it's always an address pair, thus data fields are
    1031                 :            :  * not swapped to little endian in upper functions. Instead this function swaps
    1032                 :            :  * data as if it's two uint32 fields.
    1033                 :            :  */
    1034                 :            : int
    1035         [ #  # ]:          0 : bnx2x_sp_post(struct bnx2x_softc *sc, int command, int cid, uint32_t data_hi,
    1036                 :            :             uint32_t data_lo, int cmd_type)
    1037                 :            : {
    1038                 :            :         struct eth_spe *spe;
    1039                 :            :         uint16_t type;
    1040                 :            :         int common;
    1041                 :            : 
    1042                 :            :         common = bnx2x_is_contextless_ramrod(command, cmd_type);
    1043                 :            : 
    1044                 :            :         if (common) {
    1045         [ #  # ]:          0 :                 if (!atomic_load_acq_long(&sc->eq_spq_left)) {
    1046                 :          0 :                         PMD_DRV_LOG(INFO, sc, "EQ ring is full!");
    1047                 :          0 :                         return -1;
    1048                 :            :                 }
    1049                 :            :         } else {
    1050         [ #  # ]:          0 :                 if (!atomic_load_acq_long(&sc->cq_spq_left)) {
    1051                 :          0 :                         PMD_DRV_LOG(INFO, sc, "SPQ ring is full!");
    1052                 :          0 :                         return -1;
    1053                 :            :                 }
    1054                 :            :         }
    1055                 :            : 
    1056                 :            :         spe = bnx2x_sp_get_next(sc);
    1057                 :            : 
    1058                 :            :         /* CID needs port number to be encoded int it */
    1059                 :          0 :         spe->hdr.conn_and_cmd_data =
    1060                 :          0 :             htole32((command << SPE_HDR_CMD_ID_SHIFT) | HW_CID(sc, cid));
    1061                 :            : 
    1062                 :          0 :         type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
    1063                 :            : 
    1064                 :            :         /* TBD: Check if it works for VFs */
    1065                 :          0 :         type |= ((SC_FUNC(sc) << SPE_HDR_FUNCTION_ID_SHIFT) &
    1066                 :            :                  SPE_HDR_FUNCTION_ID);
    1067                 :            : 
    1068                 :          0 :         spe->hdr.type = htole16(type);
    1069                 :            : 
    1070                 :          0 :         spe->data.update_data_addr.hi = htole32(data_hi);
    1071                 :          0 :         spe->data.update_data_addr.lo = htole32(data_lo);
    1072                 :            : 
    1073                 :            :         /*
    1074                 :            :          * It's ok if the actual decrement is issued towards the memory
    1075                 :            :          * somewhere between the lock and unlock. Thus no more explicit
    1076                 :            :          * memory barrier is needed.
    1077                 :            :          */
    1078         [ #  # ]:          0 :         if (common) {
    1079                 :          0 :                 atomic_subtract_acq_long(&sc->eq_spq_left, 1);
    1080                 :            :         } else {
    1081                 :          0 :                 atomic_subtract_acq_long(&sc->cq_spq_left, 1);
    1082                 :            :         }
    1083                 :            : 
    1084                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
    1085                 :            :                     "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x"
    1086                 :            :                     "data (%x:%x) type(0x%x) left (CQ, EQ) (%lx,%lx)",
    1087                 :            :                     sc->spq_prod_idx,
    1088                 :            :                     (uint32_t) U64_HI(sc->spq_dma.paddr),
    1089                 :            :                     (uint32_t) (U64_LO(sc->spq_dma.paddr) +
    1090                 :            :                                 (uint8_t *) sc->spq_prod_bd -
    1091                 :            :                                 (uint8_t *) sc->spq), command, common,
    1092                 :            :                     HW_CID(sc, cid), data_hi, data_lo, type,
    1093                 :            :                     atomic_load_acq_long(&sc->cq_spq_left),
    1094                 :            :                     atomic_load_acq_long(&sc->eq_spq_left));
    1095                 :            : 
    1096                 :            :         /* RAMROD completion is processed in bnx2x_intr_legacy()
    1097                 :            :          * which can run from different contexts.
    1098                 :            :          * Ask bnx2x_intr_intr() to process RAMROD
    1099                 :            :          * completion whenever it gets scheduled.
    1100                 :            :          */
    1101                 :            :         rte_atomic32_set(&sc->scan_fp, 1);
    1102                 :            :         bnx2x_sp_prod_update(sc);
    1103                 :            : 
    1104                 :          0 :         return 0;
    1105                 :            : }
    1106                 :            : 
    1107                 :          0 : static void bnx2x_drv_pulse(struct bnx2x_softc *sc)
    1108                 :            : {
    1109   [ #  #  #  # ]:          0 :         SHMEM_WR(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb,
    1110                 :            :                  sc->fw_drv_pulse_wr_seq);
    1111                 :          0 : }
    1112                 :            : 
    1113                 :            : static int bnx2x_tx_queue_has_work(const struct bnx2x_fastpath *fp)
    1114                 :            : {
    1115                 :            :         uint16_t hw_cons;
    1116                 :          0 :         struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
    1117                 :            : 
    1118         [ #  # ]:          0 :         if (unlikely(!txq)) {
    1119                 :            :                 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
    1120                 :            :                 return 0;
    1121                 :            :         }
    1122                 :            : 
    1123                 :            :         mb();                   /* status block fields can change */
    1124                 :          0 :         hw_cons = le16toh(*fp->tx_cons_sb);
    1125                 :          0 :         return hw_cons != txq->tx_pkt_head;
    1126                 :            : }
    1127                 :            : 
    1128                 :            : static uint8_t bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
    1129                 :            : {
    1130                 :            :         /* expand this for multi-cos if ever supported */
    1131                 :          0 :         return bnx2x_tx_queue_has_work(fp);
    1132                 :            : }
    1133                 :            : 
    1134                 :          0 : static int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
    1135                 :            : {
    1136                 :            :         uint16_t rx_cq_cons_sb;
    1137                 :            :         struct bnx2x_rx_queue *rxq;
    1138                 :          0 :         rxq = fp->sc->rx_queues[fp->index];
    1139         [ #  # ]:          0 :         if (unlikely(!rxq)) {
    1140                 :            :                 PMD_RX_LOG(ERR, "ERROR: RX queue is NULL");
    1141                 :            :                 return 0;
    1142                 :            :         }
    1143                 :            : 
    1144                 :            :         mb();                   /* status block fields can change */
    1145                 :          0 :         rx_cq_cons_sb = le16toh(*fp->rx_cq_cons_sb);
    1146         [ #  # ]:          0 :         if (unlikely((rx_cq_cons_sb & MAX_RCQ_ENTRIES(rxq)) ==
    1147                 :            :                      MAX_RCQ_ENTRIES(rxq)))
    1148                 :          0 :                 rx_cq_cons_sb++;
    1149                 :            : 
    1150                 :            :         PMD_RX_LOG(DEBUG, "hw CQ cons = %d, sw CQ cons = %d",
    1151                 :            :                    rx_cq_cons_sb, rxq->rx_cq_head);
    1152                 :            : 
    1153                 :          0 :         return rxq->rx_cq_head != rx_cq_cons_sb;
    1154                 :            : }
    1155                 :            : 
    1156                 :            : static void
    1157                 :          0 : bnx2x_sp_event(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    1158                 :            :              union eth_rx_cqe *rr_cqe)
    1159                 :            : {
    1160                 :          0 :         int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
    1161                 :          0 :         int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
    1162                 :            :         enum ecore_queue_cmd drv_cmd = ECORE_Q_CMD_MAX;
    1163                 :          0 :         struct ecore_queue_sp_obj *q_obj = &BNX2X_SP_OBJ(sc, fp).q_obj;
    1164                 :            : 
    1165                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
    1166                 :            :                     "fp=%d cid=%d got ramrod #%d state is %x type is %d",
    1167                 :            :                     fp->index, cid, command, sc->state,
    1168                 :            :                     rr_cqe->ramrod_cqe.ramrod_type);
    1169                 :            : 
    1170   [ #  #  #  #  :          0 :         switch (command) {
                #  #  # ]
    1171                 :            :         case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
    1172                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "got UPDATE ramrod. CID %d", cid);
    1173                 :            :                 drv_cmd = ECORE_Q_CMD_UPDATE;
    1174                 :            :                 break;
    1175                 :            : 
    1176                 :            :         case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
    1177                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] setup ramrod", cid);
    1178                 :            :                 drv_cmd = ECORE_Q_CMD_SETUP;
    1179                 :            :                 break;
    1180                 :            : 
    1181                 :            :         case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
    1182                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
    1183                 :            :                             "got MULTI[%d] tx-only setup ramrod", cid);
    1184                 :            :                 drv_cmd = ECORE_Q_CMD_SETUP_TX_ONLY;
    1185                 :            :                 break;
    1186                 :            : 
    1187                 :            :         case (RAMROD_CMD_ID_ETH_HALT):
    1188                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] halt ramrod", cid);
    1189                 :            :                 drv_cmd = ECORE_Q_CMD_HALT;
    1190                 :            :                 break;
    1191                 :            : 
    1192                 :            :         case (RAMROD_CMD_ID_ETH_TERMINATE):
    1193                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] terminate ramrod", cid);
    1194                 :            :                 drv_cmd = ECORE_Q_CMD_TERMINATE;
    1195                 :            :                 break;
    1196                 :            : 
    1197                 :            :         case (RAMROD_CMD_ID_ETH_EMPTY):
    1198                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "got MULTI[%d] empty ramrod", cid);
    1199                 :            :                 drv_cmd = ECORE_Q_CMD_EMPTY;
    1200                 :            :                 break;
    1201                 :            : 
    1202                 :          0 :         default:
    1203                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
    1204                 :            :                             "ERROR: unexpected MC reply (%d)"
    1205                 :            :                             "on fp[%d]", command, fp->index);
    1206                 :          0 :                 return;
    1207                 :            :         }
    1208                 :            : 
    1209         [ #  # ]:          0 :         if ((drv_cmd != ECORE_Q_CMD_MAX) &&
    1210                 :          0 :             q_obj->complete_cmd(sc, q_obj, drv_cmd)) {
    1211                 :            :                 /*
    1212                 :            :                  * q_obj->complete_cmd() failure means that this was
    1213                 :            :                  * an unexpected completion.
    1214                 :            :                  *
    1215                 :            :                  * In this case we don't want to increase the sc->spq_left
    1216                 :            :                  * because apparently we haven't sent this command the first
    1217                 :            :                  * place.
    1218                 :            :                  */
    1219                 :            :                 // rte_panic("Unexpected SP completion");
    1220                 :            :                 return;
    1221                 :            :         }
    1222                 :            : 
    1223                 :          0 :         atomic_add_acq_long(&sc->cq_spq_left, 1);
    1224                 :            : 
    1225                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "sc->cq_spq_left 0x%lx",
    1226                 :            :                     atomic_load_acq_long(&sc->cq_spq_left));
    1227                 :            : }
    1228                 :            : 
    1229                 :          0 : static uint8_t bnx2x_rxeof(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp)
    1230                 :            : {
    1231                 :            :         struct bnx2x_rx_queue *rxq;
    1232                 :            :         uint16_t bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
    1233                 :            :         uint16_t hw_cq_cons, sw_cq_cons, sw_cq_prod;
    1234                 :            : 
    1235                 :          0 :         rte_spinlock_lock(&(fp)->rx_mtx);
    1236                 :            : 
    1237                 :          0 :         rxq = sc->rx_queues[fp->index];
    1238         [ #  # ]:          0 :         if (!rxq) {
    1239                 :            :                 PMD_RX_LOG(ERR, "RX queue %d is NULL", fp->index);
    1240                 :            :                 rte_spinlock_unlock(&(fp)->rx_mtx);
    1241                 :          0 :                 return 0;
    1242                 :            :         }
    1243                 :            : 
    1244                 :            :         /* CQ "next element" is of the size of the regular element */
    1245                 :          0 :         hw_cq_cons = le16toh(*fp->rx_cq_cons_sb);
    1246         [ #  # ]:          0 :         if (unlikely((hw_cq_cons & USABLE_RCQ_ENTRIES_PER_PAGE) ==
    1247                 :            :                      USABLE_RCQ_ENTRIES_PER_PAGE)) {
    1248                 :          0 :                 hw_cq_cons++;
    1249                 :            :         }
    1250                 :            : 
    1251                 :          0 :         bd_cons = rxq->rx_bd_head;
    1252                 :          0 :         bd_prod = rxq->rx_bd_tail;
    1253                 :            :         bd_prod_fw = bd_prod;
    1254                 :          0 :         sw_cq_cons = rxq->rx_cq_head;
    1255                 :          0 :         sw_cq_prod = rxq->rx_cq_tail;
    1256                 :            : 
    1257                 :            :         /*
    1258                 :            :          * Memory barrier necessary as speculative reads of the rx
    1259                 :            :          * buffer can be ahead of the index in the status block
    1260                 :            :          */
    1261                 :            :         rmb();
    1262                 :            : 
    1263         [ #  # ]:          0 :         while (sw_cq_cons != hw_cq_cons) {
    1264                 :            :                 union eth_rx_cqe *cqe;
    1265                 :            :                 struct eth_fast_path_rx_cqe *cqe_fp;
    1266                 :            :                 uint8_t cqe_fp_flags;
    1267                 :            :                 enum eth_rx_cqe_type cqe_fp_type;
    1268                 :            : 
    1269                 :          0 :                 comp_ring_cons = RCQ_ENTRY(sw_cq_cons, rxq);
    1270                 :          0 :                 bd_prod = RX_BD(bd_prod, rxq);
    1271                 :          0 :                 bd_cons = RX_BD(bd_cons, rxq);
    1272                 :            : 
    1273                 :          0 :                 cqe = &rxq->cq_ring[comp_ring_cons];
    1274                 :            :                 cqe_fp = &cqe->fast_path_cqe;
    1275                 :          0 :                 cqe_fp_flags = cqe_fp->type_error_flags;
    1276                 :            :                 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
    1277                 :            : 
    1278                 :            :                 /* is this a slowpath msg? */
    1279         [ #  # ]:          0 :                 if (CQE_TYPE_SLOW(cqe_fp_type)) {
    1280                 :          0 :                         bnx2x_sp_event(sc, fp, cqe);
    1281                 :          0 :                         goto next_cqe;
    1282                 :            :                 }
    1283                 :            : 
    1284                 :            :                 /* is this an error packet? */
    1285                 :            :                 if (unlikely(cqe_fp_flags &
    1286                 :            :                              ETH_FAST_PATH_RX_CQE_PHY_DECODE_ERR_FLG)) {
    1287                 :            :                         PMD_RX_LOG(DEBUG, "flags 0x%x rx packet %u",
    1288                 :            :                                    cqe_fp_flags, sw_cq_cons);
    1289                 :            :                         goto next_rx;
    1290                 :            :                 }
    1291                 :            : 
    1292                 :            :                 PMD_RX_LOG(DEBUG, "Dropping fastpath called from attn poller!");
    1293                 :            : 
    1294                 :          0 : next_rx:
    1295         [ #  # ]:          0 :                 bd_cons = NEXT_RX_BD(bd_cons);
    1296                 :            :                 bd_prod = NEXT_RX_BD(bd_prod);
    1297         [ #  # ]:          0 :                 bd_prod_fw = NEXT_RX_BD(bd_prod_fw);
    1298                 :            : 
    1299                 :          0 : next_cqe:
    1300         [ #  # ]:          0 :                 sw_cq_prod = NEXT_RCQ_IDX(sw_cq_prod);
    1301         [ #  # ]:          0 :                 sw_cq_cons = NEXT_RCQ_IDX(sw_cq_cons);
    1302                 :            : 
    1303                 :            :         }                       /* while work to do */
    1304                 :            : 
    1305                 :          0 :         rxq->rx_bd_head = bd_cons;
    1306                 :          0 :         rxq->rx_bd_tail = bd_prod_fw;
    1307                 :          0 :         rxq->rx_cq_head = sw_cq_cons;
    1308                 :          0 :         rxq->rx_cq_tail = sw_cq_prod;
    1309                 :            : 
    1310                 :            :         PMD_RX_LOG(DEBUG, "BD prod = %d, sw CQ prod = %d",
    1311                 :            :                    bd_prod_fw, sw_cq_prod);
    1312                 :            : 
    1313                 :            :         /* Update producers */
    1314                 :          0 :         bnx2x_update_rx_prod(sc, fp, bd_prod_fw, sw_cq_prod);
    1315                 :            : 
    1316                 :            :         rte_spinlock_unlock(&(fp)->rx_mtx);
    1317                 :            : 
    1318                 :          0 :         return sw_cq_cons != hw_cq_cons;
    1319                 :            : }
    1320                 :            : 
    1321                 :            : static uint16_t
    1322                 :          0 : bnx2x_free_tx_pkt(__rte_unused struct bnx2x_fastpath *fp, struct bnx2x_tx_queue *txq,
    1323                 :            :                 uint16_t pkt_idx, uint16_t bd_idx)
    1324                 :            : {
    1325                 :            :         struct eth_tx_start_bd *tx_start_bd =
    1326                 :          0 :             &txq->tx_ring[TX_BD(bd_idx, txq)].start_bd;
    1327                 :          0 :         uint16_t nbd = rte_le_to_cpu_16(tx_start_bd->nbd);
    1328                 :          0 :         struct rte_mbuf *tx_mbuf = txq->sw_ring[TX_BD(pkt_idx, txq)];
    1329                 :            : 
    1330         [ #  # ]:          0 :         if (likely(tx_mbuf != NULL)) {
    1331                 :            :                 rte_pktmbuf_free_seg(tx_mbuf);
    1332                 :            :         } else {
    1333                 :            :                 PMD_RX_LOG(ERR, "fp[%02d] lost mbuf %lu",
    1334                 :            :                            fp->index, (unsigned long)TX_BD(pkt_idx, txq));
    1335                 :            :         }
    1336                 :            : 
    1337                 :          0 :         txq->sw_ring[TX_BD(pkt_idx, txq)] = NULL;
    1338                 :          0 :         txq->nb_tx_avail += nbd;
    1339                 :            : 
    1340         [ #  # ]:          0 :         while (nbd--)
    1341         [ #  # ]:          0 :                 bd_idx = NEXT_TX_BD(bd_idx);
    1342                 :            : 
    1343                 :          0 :         return bd_idx;
    1344                 :            : }
    1345                 :            : 
    1346                 :            : /* processes transmit completions */
    1347                 :          0 : uint8_t bnx2x_txeof(__rte_unused struct bnx2x_softc * sc, struct bnx2x_fastpath * fp)
    1348                 :            : {
    1349                 :            :         uint16_t bd_cons, hw_cons, sw_cons;
    1350                 :            :         __rte_unused uint16_t tx_bd_avail;
    1351                 :            : 
    1352                 :          0 :         struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
    1353                 :            : 
    1354         [ #  # ]:          0 :         if (unlikely(!txq)) {
    1355                 :            :                 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
    1356                 :            :                 return 0;
    1357                 :            :         }
    1358                 :            : 
    1359                 :          0 :         bd_cons = txq->tx_bd_head;
    1360                 :          0 :         hw_cons = rte_le_to_cpu_16(*fp->tx_cons_sb);
    1361                 :          0 :         sw_cons = txq->tx_pkt_head;
    1362                 :            : 
    1363         [ #  # ]:          0 :         while (sw_cons != hw_cons) {
    1364                 :          0 :                 bd_cons = bnx2x_free_tx_pkt(fp, txq, sw_cons, bd_cons);
    1365                 :          0 :                 sw_cons++;
    1366                 :            :         }
    1367                 :            : 
    1368                 :          0 :         txq->tx_pkt_head = sw_cons;
    1369                 :          0 :         txq->tx_bd_head = bd_cons;
    1370                 :            : 
    1371                 :            :         tx_bd_avail = txq->nb_tx_avail;
    1372                 :            : 
    1373                 :            :         PMD_TX_LOG(DEBUG, "fp[%02d] avail=%u cons_sb=%u, "
    1374                 :            :                    "pkt_head=%u pkt_tail=%u bd_head=%u bd_tail=%u",
    1375                 :            :                    fp->index, tx_bd_avail, hw_cons,
    1376                 :            :                    txq->tx_pkt_head, txq->tx_pkt_tail,
    1377                 :            :                    txq->tx_bd_head, txq->tx_bd_tail);
    1378                 :          0 :         return TRUE;
    1379                 :            : }
    1380                 :            : 
    1381                 :          0 : static void bnx2x_drain_tx_queues(struct bnx2x_softc *sc)
    1382                 :            : {
    1383                 :            :         struct bnx2x_fastpath *fp;
    1384                 :            :         int i, count;
    1385                 :            : 
    1386                 :            :         /* wait until all TX fastpath tasks have completed */
    1387         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    1388                 :          0 :                 fp = &sc->fp[i];
    1389                 :            : 
    1390                 :            :                 count = 1000;
    1391                 :            : 
    1392         [ #  # ]:          0 :                 while (bnx2x_has_tx_work(fp)) {
    1393                 :          0 :                         bnx2x_txeof(sc, fp);
    1394                 :            : 
    1395         [ #  # ]:          0 :                         if (count == 0) {
    1396                 :            :                                 PMD_TX_LOG(ERR,
    1397                 :            :                                            "Timeout waiting for fp[%d] "
    1398                 :            :                                            "transmits to complete!", i);
    1399                 :          0 :                                 rte_panic("tx drain failure");
    1400                 :            :                                 return;
    1401                 :            :                         }
    1402                 :            : 
    1403                 :          0 :                         count--;
    1404                 :          0 :                         DELAY(1000);
    1405                 :            :                         rmb();
    1406                 :            :                 }
    1407                 :            :         }
    1408                 :            : 
    1409                 :            :         return;
    1410                 :            : }
    1411                 :            : 
    1412                 :            : static int
    1413                 :          0 : bnx2x_del_all_macs(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *mac_obj,
    1414                 :            :                  int mac_type, uint8_t wait_for_comp)
    1415                 :            : {
    1416                 :          0 :         uint32_t ramrod_flags = 0, vlan_mac_flags = 0;
    1417                 :            :         int rc;
    1418                 :            : 
    1419                 :            :         /* wait for completion of requested */
    1420         [ #  # ]:          0 :         if (wait_for_comp) {
    1421                 :            :                 rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &ramrod_flags);
    1422                 :            :         }
    1423                 :            : 
    1424                 :            :         /* Set the mac type of addresses we want to clear */
    1425                 :          0 :         rte_bit_relaxed_set32(mac_type, &vlan_mac_flags);
    1426                 :            : 
    1427                 :          0 :         rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
    1428         [ #  # ]:          0 :         if (rc < 0)
    1429                 :          0 :                 PMD_DRV_LOG(ERR, sc, "Failed to delete MACs (%d)", rc);
    1430                 :            : 
    1431                 :          0 :         return rc;
    1432                 :            : }
    1433                 :            : 
    1434                 :            : static int
    1435                 :          0 : bnx2x_fill_accept_flags(struct bnx2x_softc *sc, uint32_t rx_mode,
    1436                 :            :                         uint32_t *rx_accept_flags, uint32_t *tx_accept_flags)
    1437                 :            : {
    1438                 :            :         /* Clear the flags first */
    1439                 :          0 :         *rx_accept_flags = 0;
    1440                 :          0 :         *tx_accept_flags = 0;
    1441                 :            : 
    1442   [ #  #  #  #  :          0 :         switch (rx_mode) {
                      # ]
    1443                 :            :         case BNX2X_RX_MODE_NONE:
    1444                 :            :                 /*
    1445                 :            :                  * 'drop all' supersedes any accept flags that may have been
    1446                 :            :                  * passed to the function.
    1447                 :            :                  */
    1448                 :            :                 break;
    1449                 :            : 
    1450                 :            :         case BNX2X_RX_MODE_NORMAL:
    1451                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST, rx_accept_flags);
    1452                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_MULTICAST, rx_accept_flags);
    1453                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
    1454                 :            : 
    1455                 :            :                 /* internal switching mode */
    1456                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST, tx_accept_flags);
    1457                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_MULTICAST, tx_accept_flags);
    1458                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
    1459                 :            : 
    1460                 :            :                 break;
    1461                 :            : 
    1462                 :            :         case BNX2X_RX_MODE_ALLMULTI:
    1463                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST, rx_accept_flags);
    1464                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ALL_MULTICAST,
    1465                 :            :                                       rx_accept_flags);
    1466                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
    1467                 :            : 
    1468                 :            :                 /* internal switching mode */
    1469                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST, tx_accept_flags);
    1470                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ALL_MULTICAST,
    1471                 :            :                                       tx_accept_flags);
    1472                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
    1473                 :            : 
    1474                 :            :                 break;
    1475                 :            : 
    1476                 :            :         case BNX2X_RX_MODE_ALLMULTI_PROMISC:
    1477                 :            :         case BNX2X_RX_MODE_PROMISC:
    1478                 :            :                 /*
    1479                 :            :                  * According to definition of SI mode, iface in promisc mode
    1480                 :            :                  * should receive matched and unmatched (in resolution of port)
    1481                 :            :                  * unicast packets.
    1482                 :            :                  */
    1483                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNMATCHED, rx_accept_flags);
    1484                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST, rx_accept_flags);
    1485                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ALL_MULTICAST,
    1486                 :            :                                       rx_accept_flags);
    1487                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, rx_accept_flags);
    1488                 :            : 
    1489                 :            :                 /* internal switching mode */
    1490                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ALL_MULTICAST,
    1491                 :            :                                       tx_accept_flags);
    1492                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_BROADCAST, tx_accept_flags);
    1493                 :            : 
    1494   [ #  #  #  # ]:          0 :                 if (IS_MF_SI(sc)) {
    1495                 :            :                         rte_bit_relaxed_set32(ECORE_ACCEPT_ALL_UNICAST,
    1496                 :            :                                         tx_accept_flags);
    1497                 :            :                 } else {
    1498                 :            :                         rte_bit_relaxed_set32(ECORE_ACCEPT_UNICAST,
    1499                 :            :                                               tx_accept_flags);
    1500                 :            :                 }
    1501                 :            : 
    1502                 :            :                 break;
    1503                 :            : 
    1504                 :            :         default:
    1505                 :            :                 PMD_RX_LOG(ERR, "Unknown rx_mode (%d)", rx_mode);
    1506                 :            :                 return -1;
    1507                 :            :         }
    1508                 :            : 
    1509                 :            :         /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
    1510         [ #  # ]:          0 :         if (rx_mode != BNX2X_RX_MODE_NONE) {
    1511                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ANY_VLAN, rx_accept_flags);
    1512                 :            :                 rte_bit_relaxed_set32(ECORE_ACCEPT_ANY_VLAN, tx_accept_flags);
    1513                 :            :         }
    1514                 :            : 
    1515                 :            :         return 0;
    1516                 :            : }
    1517                 :            : 
    1518                 :            : static int
    1519                 :          0 : bnx2x_set_q_rx_mode(struct bnx2x_softc *sc, uint8_t cl_id,
    1520                 :            :                   unsigned long rx_mode_flags,
    1521                 :            :                   unsigned long rx_accept_flags,
    1522                 :            :                   unsigned long tx_accept_flags, unsigned long ramrod_flags)
    1523                 :            : {
    1524                 :            :         struct ecore_rx_mode_ramrod_params ramrod_param;
    1525                 :            :         int rc;
    1526                 :            : 
    1527                 :            :         memset(&ramrod_param, 0, sizeof(ramrod_param));
    1528                 :            : 
    1529                 :            :         /* Prepare ramrod parameters */
    1530                 :            :         ramrod_param.cid = 0;
    1531                 :          0 :         ramrod_param.cl_id = cl_id;
    1532                 :          0 :         ramrod_param.rx_mode_obj = &sc->rx_mode_obj;
    1533                 :          0 :         ramrod_param.func_id = SC_FUNC(sc);
    1534                 :            : 
    1535                 :          0 :         ramrod_param.pstate = &sc->sp_state;
    1536                 :          0 :         ramrod_param.state = ECORE_FILTER_RX_MODE_PENDING;
    1537                 :            : 
    1538                 :          0 :         ramrod_param.rdata = BNX2X_SP(sc, rx_mode_rdata);
    1539                 :          0 :         ramrod_param.rdata_mapping =
    1540                 :          0 :             (rte_iova_t)BNX2X_SP_MAPPING(sc, rx_mode_rdata),
    1541                 :            :             rte_bit_relaxed_set32(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
    1542                 :            : 
    1543                 :          0 :         ramrod_param.ramrod_flags = ramrod_flags;
    1544                 :          0 :         ramrod_param.rx_mode_flags = rx_mode_flags;
    1545                 :            : 
    1546                 :          0 :         ramrod_param.rx_accept_flags = rx_accept_flags;
    1547                 :          0 :         ramrod_param.tx_accept_flags = tx_accept_flags;
    1548                 :            : 
    1549                 :          0 :         rc = ecore_config_rx_mode(sc, &ramrod_param);
    1550                 :            :         if (rc < 0) {
    1551                 :            :                 PMD_RX_LOG(ERR, "Set rx_mode %d failed", sc->rx_mode);
    1552                 :            :                 return rc;
    1553                 :            :         }
    1554                 :            : 
    1555                 :            :         return 0;
    1556                 :            : }
    1557                 :            : 
    1558                 :          0 : int bnx2x_set_storm_rx_mode(struct bnx2x_softc *sc)
    1559                 :            : {
    1560                 :          0 :         uint32_t rx_mode_flags = 0, ramrod_flags = 0;
    1561                 :          0 :         uint32_t rx_accept_flags = 0, tx_accept_flags = 0;
    1562                 :            :         int rc;
    1563                 :            : 
    1564                 :          0 :         rc = bnx2x_fill_accept_flags(sc, sc->rx_mode, &rx_accept_flags,
    1565                 :            :                                    &tx_accept_flags);
    1566         [ #  # ]:          0 :         if (rc) {
    1567                 :            :                 return rc;
    1568                 :            :         }
    1569                 :            : 
    1570                 :            :         rte_bit_relaxed_set32(RAMROD_RX, &ramrod_flags);
    1571                 :            :         rte_bit_relaxed_set32(RAMROD_TX, &ramrod_flags);
    1572                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &ramrod_flags);
    1573                 :            : 
    1574                 :          0 :         return bnx2x_set_q_rx_mode(sc, sc->fp[0].cl_id, rx_mode_flags,
    1575                 :            :                                  rx_accept_flags, tx_accept_flags,
    1576                 :            :                                  ramrod_flags);
    1577                 :            : }
    1578                 :            : 
    1579                 :            : /* returns the "mcp load_code" according to global load_count array */
    1580                 :          0 : static int bnx2x_nic_load_no_mcp(struct bnx2x_softc *sc)
    1581                 :            : {
    1582                 :          0 :         int path = SC_PATH(sc);
    1583                 :          0 :         int port = SC_PORT(sc);
    1584                 :            : 
    1585                 :          0 :         PMD_DRV_LOG(INFO, sc, "NO MCP - load counts[%d]      %d, %d, %d",
    1586                 :            :                     path, load_count[path][0], load_count[path][1],
    1587                 :            :                     load_count[path][2]);
    1588                 :            : 
    1589                 :          0 :         load_count[path][0]++;
    1590                 :          0 :         load_count[path][1 + port]++;
    1591                 :          0 :         PMD_DRV_LOG(INFO, sc, "NO MCP - new load counts[%d]  %d, %d, %d",
    1592                 :            :                     path, load_count[path][0], load_count[path][1],
    1593                 :            :                     load_count[path][2]);
    1594         [ #  # ]:          0 :         if (load_count[path][0] == 1)
    1595                 :            :                 return FW_MSG_CODE_DRV_LOAD_COMMON;
    1596         [ #  # ]:          0 :         else if (load_count[path][1 + port] == 1)
    1597                 :            :                 return FW_MSG_CODE_DRV_LOAD_PORT;
    1598                 :            :         else
    1599                 :          0 :                 return FW_MSG_CODE_DRV_LOAD_FUNCTION;
    1600                 :            : }
    1601                 :            : 
    1602                 :            : /* returns the "mcp load_code" according to global load_count array */
    1603                 :          0 : static int bnx2x_nic_unload_no_mcp(struct bnx2x_softc *sc)
    1604                 :            : {
    1605                 :          0 :         int port = SC_PORT(sc);
    1606                 :          0 :         int path = SC_PATH(sc);
    1607                 :            : 
    1608                 :          0 :         PMD_DRV_LOG(INFO, sc, "NO MCP - load counts[%d]      %d, %d, %d",
    1609                 :            :                     path, load_count[path][0], load_count[path][1],
    1610                 :            :                     load_count[path][2]);
    1611                 :          0 :         load_count[path][0]--;
    1612                 :          0 :         load_count[path][1 + port]--;
    1613                 :          0 :         PMD_DRV_LOG(INFO, sc, "NO MCP - new load counts[%d]  %d, %d, %d",
    1614                 :            :                     path, load_count[path][0], load_count[path][1],
    1615                 :            :                     load_count[path][2]);
    1616         [ #  # ]:          0 :         if (load_count[path][0] == 0) {
    1617                 :            :                 return FW_MSG_CODE_DRV_UNLOAD_COMMON;
    1618         [ #  # ]:          0 :         } else if (load_count[path][1 + port] == 0) {
    1619                 :            :                 return FW_MSG_CODE_DRV_UNLOAD_PORT;
    1620                 :            :         } else {
    1621                 :          0 :                 return FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
    1622                 :            :         }
    1623                 :            : }
    1624                 :            : 
    1625                 :            : /* request unload mode from the MCP: COMMON, PORT or FUNCTION */
    1626                 :          0 : static uint32_t bnx2x_send_unload_req(struct bnx2x_softc *sc, int unload_mode __rte_unused)
    1627                 :            : {
    1628                 :            :         uint32_t reset_code = 0;
    1629                 :            : 
    1630                 :            :         /* Select the UNLOAD request mode */
    1631                 :            :         reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
    1632                 :            : 
    1633                 :            :         /* Send the request to the MCP */
    1634         [ #  # ]:          0 :         if (!BNX2X_NOMCP(sc)) {
    1635                 :            :                 reset_code = bnx2x_fw_command(sc, reset_code, 0);
    1636                 :            :         } else {
    1637                 :          0 :                 reset_code = bnx2x_nic_unload_no_mcp(sc);
    1638                 :            :         }
    1639                 :            : 
    1640                 :          0 :         return reset_code;
    1641                 :            : }
    1642                 :            : 
    1643                 :            : /* send UNLOAD_DONE command to the MCP */
    1644                 :            : static void bnx2x_send_unload_done(struct bnx2x_softc *sc, uint8_t keep_link)
    1645                 :            : {
    1646                 :            :         uint32_t reset_param =
    1647         [ #  # ]:          0 :             keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
    1648                 :            : 
    1649                 :            :         /* Report UNLOAD_DONE to MCP */
    1650   [ #  #  #  # ]:          0 :         if (!BNX2X_NOMCP(sc)) {
    1651                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
    1652                 :            :         }
    1653                 :            : }
    1654                 :            : 
    1655                 :          0 : static int bnx2x_func_wait_started(struct bnx2x_softc *sc)
    1656                 :            : {
    1657                 :            :         int tout = 50;
    1658                 :            : 
    1659         [ #  # ]:          0 :         if (!sc->port.pmf) {
    1660                 :            :                 return 0;
    1661                 :            :         }
    1662                 :            : 
    1663                 :            :         /*
    1664                 :            :          * (assumption: No Attention from MCP at this stage)
    1665                 :            :          * PMF probably in the middle of TX disable/enable transaction
    1666                 :            :          * 1. Sync IRS for default SB
    1667                 :            :          * 2. Sync SP queue - this guarantees us that attention handling started
    1668                 :            :          * 3. Wait, that TX disable/enable transaction completes
    1669                 :            :          *
    1670                 :            :          * 1+2 guarantee that if DCBX attention was scheduled it already changed
    1671                 :            :          * pending bit of transaction from STARTED-->TX_STOPPED, if we already
    1672                 :            :          * received completion for the transaction the state is TX_STOPPED.
    1673                 :            :          * State will return to STARTED after completion of TX_STOPPED-->STARTED
    1674                 :            :          * transaction.
    1675                 :            :          */
    1676                 :            : 
    1677                 :          0 :         while (ecore_func_get_state(sc, &sc->func_obj) !=
    1678   [ #  #  #  # ]:          0 :                ECORE_F_STATE_STARTED && tout--) {
    1679                 :          0 :                 DELAY(20000);
    1680                 :            :         }
    1681                 :            : 
    1682         [ #  # ]:          0 :         if (ecore_func_get_state(sc, &sc->func_obj) != ECORE_F_STATE_STARTED) {
    1683                 :            :                 /*
    1684                 :            :                  * Failed to complete the transaction in a "good way"
    1685                 :            :                  * Force both transactions with CLR bit.
    1686                 :            :                  */
    1687                 :          0 :                 struct ecore_func_state_params func_params = { NULL };
    1688                 :            : 
    1689                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Unexpected function state! "
    1690                 :            :                             "Forcing STARTED-->TX_STOPPED-->STARTED");
    1691                 :            : 
    1692                 :          0 :                 func_params.f_obj = &sc->func_obj;
    1693                 :            :                 rte_bit_relaxed_set32(RAMROD_DRV_CLR_ONLY,
    1694                 :            :                                       &func_params.ramrod_flags);
    1695                 :            : 
    1696                 :            :                 /* STARTED-->TX_STOPPED */
    1697                 :          0 :                 func_params.cmd = ECORE_F_CMD_TX_STOP;
    1698                 :          0 :                 ecore_func_state_change(sc, &func_params);
    1699                 :            : 
    1700                 :            :                 /* TX_STOPPED-->STARTED */
    1701                 :          0 :                 func_params.cmd = ECORE_F_CMD_TX_START;
    1702                 :          0 :                 return ecore_func_state_change(sc, &func_params);
    1703                 :            :         }
    1704                 :            : 
    1705                 :            :         return 0;
    1706                 :            : }
    1707                 :            : 
    1708                 :          0 : static int bnx2x_stop_queue(struct bnx2x_softc *sc, int index)
    1709                 :            : {
    1710                 :            :         struct bnx2x_fastpath *fp = &sc->fp[index];
    1711                 :          0 :         struct ecore_queue_state_params q_params = { NULL };
    1712                 :            :         int rc;
    1713                 :            : 
    1714                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "stopping queue %d cid %d", index, fp->index);
    1715                 :            : 
    1716                 :          0 :         q_params.q_obj = &sc->sp_objs[fp->index].q_obj;
    1717                 :            :         /* We want to wait for completion in this context */
    1718                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
    1719                 :            : 
    1720                 :            :         /* Stop the primary connection: */
    1721                 :            : 
    1722                 :            :         /* ...halt the connection */
    1723                 :          0 :         q_params.cmd = ECORE_Q_CMD_HALT;
    1724                 :          0 :         rc = ecore_queue_state_change(sc, &q_params);
    1725         [ #  # ]:          0 :         if (rc) {
    1726                 :            :                 return rc;
    1727                 :            :         }
    1728                 :            : 
    1729                 :            :         /* ...terminate the connection */
    1730                 :          0 :         q_params.cmd = ECORE_Q_CMD_TERMINATE;
    1731                 :            :         memset(&q_params.params.terminate, 0,
    1732                 :            :                sizeof(q_params.params.terminate));
    1733                 :            :         q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
    1734                 :          0 :         rc = ecore_queue_state_change(sc, &q_params);
    1735         [ #  # ]:          0 :         if (rc) {
    1736                 :            :                 return rc;
    1737                 :            :         }
    1738                 :            : 
    1739                 :            :         /* ...delete cfc entry */
    1740                 :          0 :         q_params.cmd = ECORE_Q_CMD_CFC_DEL;
    1741                 :            :         memset(&q_params.params.cfc_del, 0, sizeof(q_params.params.cfc_del));
    1742                 :            :         q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
    1743                 :          0 :         return ecore_queue_state_change(sc, &q_params);
    1744                 :            : }
    1745                 :            : 
    1746                 :            : /* wait for the outstanding SP commands */
    1747                 :          0 : static uint8_t bnx2x_wait_sp_comp(struct bnx2x_softc *sc, uint32_t mask)
    1748                 :            : {
    1749                 :            :         uint32_t tmp;
    1750                 :            :         int tout = 5000;        /* wait for 5 secs tops */
    1751                 :            : 
    1752         [ #  # ]:          0 :         while (tout--) {
    1753                 :            :                 mb();
    1754         [ #  # ]:          0 :                 if (!(atomic_load_acq_int(&sc->sp_state) & mask))
    1755                 :            :                         return TRUE;
    1756                 :            : 
    1757                 :          0 :                 DELAY(1000);
    1758                 :            :         }
    1759                 :            : 
    1760                 :            :         mb();
    1761                 :            : 
    1762                 :          0 :         tmp = atomic_load_acq_int(&sc->sp_state);
    1763         [ #  # ]:          0 :         if (tmp & mask) {
    1764                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Filtering completion timed out: "
    1765                 :            :                             "sp_state 0x%x, mask 0x%x", tmp, mask);
    1766                 :          0 :                 return FALSE;
    1767                 :            :         }
    1768                 :            : 
    1769                 :            :         return FALSE;
    1770                 :            : }
    1771                 :            : 
    1772                 :          0 : static int bnx2x_func_stop(struct bnx2x_softc *sc)
    1773                 :            : {
    1774                 :          0 :         struct ecore_func_state_params func_params = { NULL };
    1775                 :            :         int rc;
    1776                 :            : 
    1777                 :            :         /* prepare parameters for function state transitions */
    1778                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
    1779                 :          0 :         func_params.f_obj = &sc->func_obj;
    1780                 :          0 :         func_params.cmd = ECORE_F_CMD_STOP;
    1781                 :            : 
    1782                 :            :         /*
    1783                 :            :          * Try to stop the function the 'good way'. If it fails (in case
    1784                 :            :          * of a parity error during bnx2x_chip_cleanup()) and we are
    1785                 :            :          * not in a debug mode, perform a state transaction in order to
    1786                 :            :          * enable further HW_RESET transaction.
    1787                 :            :          */
    1788                 :          0 :         rc = ecore_func_state_change(sc, &func_params);
    1789         [ #  # ]:          0 :         if (rc) {
    1790                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "FUNC_STOP ramrod failed. "
    1791                 :            :                             "Running a dry transaction");
    1792                 :            :                 rte_bit_relaxed_set32(RAMROD_DRV_CLR_ONLY,
    1793                 :            :                                       &func_params.ramrod_flags);
    1794                 :          0 :                 return ecore_func_state_change(sc, &func_params);
    1795                 :            :         }
    1796                 :            : 
    1797                 :            :         return 0;
    1798                 :            : }
    1799                 :            : 
    1800                 :          0 : static int bnx2x_reset_hw(struct bnx2x_softc *sc, uint32_t load_code)
    1801                 :            : {
    1802                 :          0 :         struct ecore_func_state_params func_params = { NULL };
    1803                 :            : 
    1804                 :            :         /* Prepare parameters for function state transitions */
    1805                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
    1806                 :            : 
    1807                 :          0 :         func_params.f_obj = &sc->func_obj;
    1808                 :          0 :         func_params.cmd = ECORE_F_CMD_HW_RESET;
    1809                 :            : 
    1810                 :          0 :         func_params.params.hw_init.load_phase = load_code;
    1811                 :            : 
    1812                 :          0 :         return ecore_func_state_change(sc, &func_params);
    1813                 :            : }
    1814                 :            : 
    1815                 :            : static void bnx2x_int_disable_sync(struct bnx2x_softc *sc, int disable_hw)
    1816                 :            : {
    1817                 :            :         if (disable_hw) {
    1818                 :            :                 /* prevent the HW from sending interrupts */
    1819                 :          0 :                 bnx2x_int_disable(sc);
    1820                 :            :         }
    1821                 :            : }
    1822                 :            : 
    1823                 :            : static void
    1824                 :          0 : bnx2x_chip_cleanup(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link)
    1825                 :            : {
    1826                 :          0 :         int port = SC_PORT(sc);
    1827                 :          0 :         struct ecore_mcast_ramrod_params rparam = { NULL };
    1828                 :            :         uint32_t reset_code;
    1829                 :            :         int i, rc = 0;
    1830                 :            : 
    1831                 :          0 :         bnx2x_drain_tx_queues(sc);
    1832                 :            : 
    1833                 :            :         /* give HW time to discard old tx messages */
    1834                 :          0 :         DELAY(1000);
    1835                 :            : 
    1836                 :            :         /* Clean all ETH MACs */
    1837                 :          0 :         rc = bnx2x_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_ETH_MAC,
    1838                 :            :                               FALSE);
    1839         [ #  # ]:          0 :         if (rc < 0) {
    1840                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    1841                 :            :                             "Failed to delete all ETH MACs (%d)", rc);
    1842                 :            :         }
    1843                 :            : 
    1844                 :            :         /* Clean up UC list  */
    1845                 :          0 :         rc = bnx2x_del_all_macs(sc, &sc->sp_objs[0].mac_obj, ECORE_UC_LIST_MAC,
    1846                 :            :                               TRUE);
    1847         [ #  # ]:          0 :         if (rc < 0) {
    1848                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    1849                 :            :                             "Failed to delete UC MACs list (%d)", rc);
    1850                 :            :         }
    1851                 :            : 
    1852                 :            :         /* Disable LLH */
    1853                 :          0 :         REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 0);
    1854                 :            : 
    1855                 :            :         /* Set "drop all" to stop Rx */
    1856                 :            : 
    1857                 :            :         /*
    1858                 :            :          * We need to take the if_maddr_lock() here in order to prevent
    1859                 :            :          * a race between the completion code and this code.
    1860                 :            :          */
    1861                 :            : 
    1862         [ #  # ]:          0 :         if (rte_bit_relaxed_get32(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state))
    1863                 :            :                 rte_bit_relaxed_set32(ECORE_FILTER_RX_MODE_SCHED,
    1864                 :            :                                       &sc->sp_state);
    1865                 :            :         else
    1866                 :          0 :                 bnx2x_set_storm_rx_mode(sc);
    1867                 :            : 
    1868                 :            :         /* Clean up multicast configuration */
    1869                 :          0 :         rparam.mcast_obj = &sc->mcast_obj;
    1870                 :          0 :         rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
    1871         [ #  # ]:          0 :         if (rc < 0) {
    1872                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    1873                 :            :                             "Failed to send DEL MCAST command (%d)", rc);
    1874                 :            :         }
    1875                 :            : 
    1876                 :            :         /*
    1877                 :            :          * Send the UNLOAD_REQUEST to the MCP. This will return if
    1878                 :            :          * this function should perform FUNCTION, PORT, or COMMON HW
    1879                 :            :          * reset.
    1880                 :            :          */
    1881                 :          0 :         reset_code = bnx2x_send_unload_req(sc, unload_mode);
    1882                 :            : 
    1883                 :            :         /*
    1884                 :            :          * (assumption: No Attention from MCP at this stage)
    1885                 :            :          * PMF probably in the middle of TX disable/enable transaction
    1886                 :            :          */
    1887                 :          0 :         rc = bnx2x_func_wait_started(sc);
    1888         [ #  # ]:          0 :         if (rc) {
    1889                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "bnx2x_func_wait_started failed");
    1890                 :            :         }
    1891                 :            : 
    1892                 :            :         /*
    1893                 :            :          * Close multi and leading connections
    1894                 :            :          * Completions for ramrods are collected in a synchronous way
    1895                 :            :          */
    1896         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    1897         [ #  # ]:          0 :                 if (bnx2x_stop_queue(sc, i)) {
    1898                 :          0 :                         goto unload_error;
    1899                 :            :                 }
    1900                 :            :         }
    1901                 :            : 
    1902                 :            :         /*
    1903                 :            :          * If SP settings didn't get completed so far - something
    1904                 :            :          * very wrong has happen.
    1905                 :            :          */
    1906         [ #  # ]:          0 :         if (!bnx2x_wait_sp_comp(sc, ~0x0U))
    1907                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Common slow path ramrods got stuck!");
    1908                 :            : 
    1909                 :          0 : unload_error:
    1910                 :            : 
    1911                 :          0 :         rc = bnx2x_func_stop(sc);
    1912         [ #  # ]:          0 :         if (rc) {
    1913                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Function stop failed!");
    1914                 :            :         }
    1915                 :            : 
    1916                 :            :         /* disable HW interrupts */
    1917                 :            :         bnx2x_int_disable_sync(sc, TRUE);
    1918                 :            : 
    1919                 :            :         /* Reset the chip */
    1920                 :          0 :         rc = bnx2x_reset_hw(sc, reset_code);
    1921         [ #  # ]:          0 :         if (rc) {
    1922                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Hardware reset failed");
    1923                 :            :         }
    1924                 :            : 
    1925                 :            :         /* Report UNLOAD_DONE to MCP */
    1926                 :            :         bnx2x_send_unload_done(sc, keep_link);
    1927                 :          0 : }
    1928                 :            : 
    1929                 :          0 : static void bnx2x_disable_close_the_gate(struct bnx2x_softc *sc)
    1930                 :            : {
    1931                 :            :         uint32_t val;
    1932                 :            : 
    1933                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Disabling 'close the gates'");
    1934                 :            : 
    1935                 :            :         val = REG_RD(sc, MISC_REG_AEU_GENERAL_MASK);
    1936                 :          0 :         val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
    1937                 :            :                  MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
    1938                 :            :         REG_WR(sc, MISC_REG_AEU_GENERAL_MASK, val);
    1939                 :          0 : }
    1940                 :            : 
    1941                 :            : /*
    1942                 :            :  * Cleans the object that have internal lists without sending
    1943                 :            :  * ramrods. Should be run when interrupts are disabled.
    1944                 :            :  */
    1945                 :          0 : static void bnx2x_squeeze_objects(struct bnx2x_softc *sc)
    1946                 :            : {
    1947                 :          0 :         uint32_t ramrod_flags = 0, vlan_mac_flags = 0;
    1948                 :          0 :         struct ecore_mcast_ramrod_params rparam = { NULL };
    1949                 :          0 :         struct ecore_vlan_mac_obj *mac_obj = &sc->sp_objs->mac_obj;
    1950                 :            :         int rc;
    1951                 :            : 
    1952                 :            :         /* Cleanup MACs' object first... */
    1953                 :            : 
    1954                 :            :         /* Wait for completion of requested */
    1955                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &ramrod_flags);
    1956                 :            :         /* Perform a dry cleanup */
    1957                 :            :         rte_bit_relaxed_set32(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
    1958                 :            : 
    1959                 :            :         /* Clean ETH primary MAC */
    1960                 :            :         rte_bit_relaxed_set32(ECORE_ETH_MAC, &vlan_mac_flags);
    1961                 :          0 :         rc = mac_obj->delete_all(sc, &sc->sp_objs->mac_obj, &vlan_mac_flags,
    1962                 :            :                                  &ramrod_flags);
    1963         [ #  # ]:          0 :         if (rc != 0) {
    1964                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Failed to clean ETH MACs (%d)", rc);
    1965                 :            :         }
    1966                 :            : 
    1967                 :            :         /* Cleanup UC list */
    1968                 :          0 :         vlan_mac_flags = 0;
    1969                 :            :         rte_bit_relaxed_set32(ECORE_UC_LIST_MAC, &vlan_mac_flags);
    1970                 :          0 :         rc = mac_obj->delete_all(sc, mac_obj, &vlan_mac_flags, &ramrod_flags);
    1971         [ #  # ]:          0 :         if (rc != 0) {
    1972                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    1973                 :            :                             "Failed to clean UC list MACs (%d)", rc);
    1974                 :            :         }
    1975                 :            : 
    1976                 :            :         /* Now clean mcast object... */
    1977                 :            : 
    1978                 :          0 :         rparam.mcast_obj = &sc->mcast_obj;
    1979                 :            :         rte_bit_relaxed_set32(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
    1980                 :            : 
    1981                 :            :         /* Add a DEL command... */
    1982                 :          0 :         rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_DEL);
    1983         [ #  # ]:          0 :         if (rc < 0) {
    1984                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    1985                 :            :                             "Failed to send DEL MCAST command (%d)", rc);
    1986                 :            :         }
    1987                 :            : 
    1988                 :            :         /* now wait until all pending commands are cleared */
    1989                 :            : 
    1990                 :          0 :         rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
    1991         [ #  # ]:          0 :         while (rc != 0) {
    1992         [ #  # ]:          0 :                 if (rc < 0) {
    1993                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    1994                 :            :                                     "Failed to clean MCAST object (%d)", rc);
    1995                 :          0 :                         return;
    1996                 :            :                 }
    1997                 :            : 
    1998                 :          0 :                 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
    1999                 :            :         }
    2000                 :            : }
    2001                 :            : 
    2002                 :            : /* stop the controller */
    2003                 :            : __rte_noinline
    2004                 :            : int
    2005                 :          0 : bnx2x_nic_unload(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link)
    2006                 :            : {
    2007                 :          0 :         uint8_t global = FALSE;
    2008                 :            :         uint32_t val;
    2009                 :            : 
    2010                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    2011                 :            : 
    2012                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Starting NIC unload...");
    2013                 :            : 
    2014                 :            :         /* mark driver as unloaded in shmem2 */
    2015   [ #  #  #  #  :          0 :         if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
                   #  # ]
    2016   [ #  #  #  # ]:          0 :                 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
    2017   [ #  #  #  # ]:          0 :                 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
    2018                 :            :                           val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
    2019                 :            :         }
    2020                 :            : 
    2021   [ #  #  #  # ]:          0 :         if (IS_PF(sc) && sc->recovery_state != BNX2X_RECOVERY_DONE &&
    2022         [ #  # ]:          0 :             (sc->state == BNX2X_STATE_CLOSED || sc->state == BNX2X_STATE_ERROR)) {
    2023                 :            :                 /*
    2024                 :            :                  * We can get here if the driver has been unloaded
    2025                 :            :                  * during parity error recovery and is either waiting for a
    2026                 :            :                  * leader to complete or for other functions to unload and
    2027                 :            :                  * then ifconfig down has been issued. In this case we want to
    2028                 :            :                  * unload and let other functions to complete a recovery
    2029                 :            :                  * process.
    2030                 :            :                  */
    2031                 :          0 :                 sc->recovery_state = BNX2X_RECOVERY_DONE;
    2032                 :          0 :                 sc->is_leader = 0;
    2033                 :            :                 bnx2x_release_leader_lock(sc);
    2034                 :            :                 mb();
    2035                 :            : 
    2036                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Can't unload in closed or error state");
    2037                 :          0 :                 return -1;
    2038                 :            :         }
    2039                 :            : 
    2040                 :            :         /*
    2041                 :            :          * Nothing to do during unload if previous bnx2x_nic_load()
    2042                 :            :          * did not complete successfully - all resources are released.
    2043                 :            :          */
    2044         [ #  # ]:          0 :         if ((sc->state == BNX2X_STATE_CLOSED) || (sc->state == BNX2X_STATE_ERROR)) {
    2045                 :            :                 return 0;
    2046                 :            :         }
    2047                 :            : 
    2048                 :          0 :         sc->state = BNX2X_STATE_CLOSING_WAITING_HALT;
    2049                 :            :         mb();
    2050                 :            : 
    2051                 :          0 :         sc->rx_mode = BNX2X_RX_MODE_NONE;
    2052                 :          0 :         bnx2x_set_rx_mode(sc);
    2053                 :            :         mb();
    2054                 :            : 
    2055         [ #  # ]:          0 :         if (IS_PF(sc)) {
    2056                 :            :                 /* set ALWAYS_ALIVE bit in shmem */
    2057                 :          0 :                 sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
    2058                 :            : 
    2059                 :          0 :                 bnx2x_drv_pulse(sc);
    2060                 :            : 
    2061                 :          0 :                 bnx2x_stats_handle(sc, STATS_EVENT_STOP);
    2062                 :          0 :                 bnx2x_save_statistics(sc);
    2063                 :            :         }
    2064                 :            : 
    2065                 :            :         /* wait till consumers catch up with producers in all queues */
    2066                 :          0 :         bnx2x_drain_tx_queues(sc);
    2067                 :            : 
    2068                 :            :         /* if VF indicate to PF this function is going down (PF will delete sp
    2069                 :            :          * elements and clear initializations
    2070                 :            :          */
    2071         [ #  # ]:          0 :         if (IS_VF(sc)) {
    2072                 :          0 :                 bnx2x_vf_unload(sc);
    2073         [ #  # ]:          0 :         } else if (unload_mode != UNLOAD_RECOVERY) {
    2074                 :            :                 /* if this is a normal/close unload need to clean up chip */
    2075                 :          0 :                 bnx2x_chip_cleanup(sc, unload_mode, keep_link);
    2076                 :            :         } else {
    2077                 :            :                 /* Send the UNLOAD_REQUEST to the MCP */
    2078                 :          0 :                 bnx2x_send_unload_req(sc, unload_mode);
    2079                 :            : 
    2080                 :            :                 /*
    2081                 :            :                  * Prevent transactions to host from the functions on the
    2082                 :            :                  * engine that doesn't reset global blocks in case of global
    2083                 :            :                  * attention once global blocks are reset and gates are opened
    2084                 :            :                  * (the engine which leader will perform the recovery
    2085                 :            :                  * last).
    2086                 :            :                  */
    2087         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
    2088                 :            :                         bnx2x_pf_disable(sc);
    2089                 :            :                 }
    2090                 :            : 
    2091                 :            :                 /* disable HW interrupts */
    2092                 :            :                 bnx2x_int_disable_sync(sc, TRUE);
    2093                 :            : 
    2094                 :            :                 /* Report UNLOAD_DONE to MCP */
    2095                 :            :                 bnx2x_send_unload_done(sc, FALSE);
    2096                 :            :         }
    2097                 :            : 
    2098                 :            :         /*
    2099                 :            :          * At this stage no more interrupts will arrive so we may safely clean
    2100                 :            :          * the queueable objects here in case they failed to get cleaned so far.
    2101                 :            :          */
    2102         [ #  # ]:          0 :         if (IS_PF(sc)) {
    2103                 :          0 :                 bnx2x_squeeze_objects(sc);
    2104                 :            :         }
    2105                 :            : 
    2106                 :            :         /* There should be no more pending SP commands at this stage */
    2107                 :          0 :         sc->sp_state = 0;
    2108                 :            : 
    2109                 :          0 :         sc->port.pmf = 0;
    2110                 :            : 
    2111         [ #  # ]:          0 :         if (IS_PF(sc)) {
    2112                 :          0 :                 bnx2x_free_mem(sc);
    2113                 :            :         }
    2114                 :            : 
    2115                 :            :         /* free the host hardware/software hsi structures */
    2116                 :          0 :         bnx2x_free_hsi_mem(sc);
    2117                 :            : 
    2118                 :            :         bnx2x_free_fw_stats_mem(sc);
    2119                 :            : 
    2120                 :          0 :         sc->state = BNX2X_STATE_CLOSED;
    2121                 :            : 
    2122                 :            :         /*
    2123                 :            :          * Check if there are pending parity attentions. If there are - set
    2124                 :            :          * RECOVERY_IN_PROGRESS.
    2125                 :            :          */
    2126         [ #  # ]:          0 :         if (IS_PF(sc) && bnx2x_chk_parity_attn(sc, &global, FALSE)) {
    2127                 :          0 :                 bnx2x_set_reset_in_progress(sc);
    2128                 :            : 
    2129                 :            :                 /* Set RESET_IS_GLOBAL if needed */
    2130         [ #  # ]:          0 :                 if (global) {
    2131                 :          0 :                         bnx2x_set_reset_global(sc);
    2132                 :            :                 }
    2133                 :            :         }
    2134                 :            : 
    2135                 :            :         /*
    2136                 :            :          * The last driver must disable a "close the gate" if there is no
    2137                 :            :          * parity attention or "process kill" pending.
    2138                 :            :          */
    2139   [ #  #  #  # ]:          0 :         if (IS_PF(sc) && !bnx2x_clear_pf_load(sc) &&
    2140                 :          0 :             bnx2x_reset_is_done(sc, SC_PATH(sc))) {
    2141                 :          0 :                 bnx2x_disable_close_the_gate(sc);
    2142                 :            :         }
    2143                 :            : 
    2144                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Ended NIC unload");
    2145                 :            : 
    2146                 :          0 :         return 0;
    2147                 :            : }
    2148                 :            : 
    2149                 :            : /*
    2150                 :            :  * Encapsulate an mbuf cluster into the Tx BD chain and makes the memory
    2151                 :            :  * visible to the controller.
    2152                 :            :  *
    2153                 :            :  * If an mbuf is submitted to this routine and cannot be given to the
    2154                 :            :  * controller (e.g. it has too many fragments) then the function may free
    2155                 :            :  * the mbuf and return to the caller.
    2156                 :            :  *
    2157                 :            :  * Returns:
    2158                 :            :  *     int: Number of TX BDs used for the mbuf
    2159                 :            :  *
    2160                 :            :  *   Note the side effect that an mbuf may be freed if it causes a problem.
    2161                 :            :  */
    2162                 :          0 : int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf *m0)
    2163                 :            : {
    2164                 :            :         struct eth_tx_start_bd *tx_start_bd;
    2165                 :            :         uint16_t bd_prod, pkt_prod;
    2166                 :            :         struct bnx2x_softc *sc;
    2167                 :            :         uint32_t nbds = 0;
    2168                 :            : 
    2169                 :          0 :         sc = txq->sc;
    2170                 :          0 :         bd_prod = txq->tx_bd_tail;
    2171                 :          0 :         pkt_prod = txq->tx_pkt_tail;
    2172                 :            : 
    2173                 :          0 :         txq->sw_ring[TX_BD(pkt_prod, txq)] = m0;
    2174                 :            : 
    2175         [ #  # ]:          0 :         tx_start_bd = &txq->tx_ring[TX_BD(bd_prod, txq)].start_bd;
    2176                 :            : 
    2177                 :          0 :         tx_start_bd->addr_lo =
    2178                 :          0 :             rte_cpu_to_le_32(U64_LO(rte_mbuf_data_iova(m0)));
    2179                 :          0 :         tx_start_bd->addr_hi =
    2180                 :          0 :             rte_cpu_to_le_32(U64_HI(rte_mbuf_data_iova(m0)));
    2181                 :          0 :         tx_start_bd->nbytes = rte_cpu_to_le_16(m0->data_len);
    2182                 :          0 :         tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
    2183                 :          0 :         tx_start_bd->general_data =
    2184                 :            :             (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
    2185                 :            : 
    2186                 :          0 :         tx_start_bd->nbd = rte_cpu_to_le_16(2);
    2187                 :            : 
    2188         [ #  # ]:          0 :         if (m0->ol_flags & RTE_MBUF_F_TX_VLAN) {
    2189                 :          0 :                 tx_start_bd->vlan_or_ethertype =
    2190                 :          0 :                     rte_cpu_to_le_16(m0->vlan_tci);
    2191                 :          0 :                 tx_start_bd->bd_flags.as_bitfield |=
    2192                 :            :                     (X_ETH_OUTBAND_VLAN <<
    2193                 :            :                      ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
    2194                 :            :         } else {
    2195         [ #  # ]:          0 :                 if (IS_PF(sc))
    2196                 :          0 :                         tx_start_bd->vlan_or_ethertype =
    2197                 :            :                             rte_cpu_to_le_16(pkt_prod);
    2198                 :            :                 else {
    2199                 :            :                         /* when transmitting in a vf, start bd
    2200                 :            :                          * must hold the ethertype for fw to enforce it
    2201                 :            :                          */
    2202                 :          0 :                         struct rte_ether_hdr *eh =
    2203                 :          0 :                             rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
    2204                 :            : 
    2205                 :            :                         /* Still need to consider inband vlan for enforced */
    2206         [ #  # ]:          0 :                         if (eh->ether_type ==
    2207                 :            :                                         rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)) {
    2208                 :            :                                 struct rte_vlan_hdr *vh =
    2209                 :            :                                         (struct rte_vlan_hdr *)(eh + 1);
    2210                 :          0 :                                 tx_start_bd->bd_flags.as_bitfield |=
    2211                 :            :                                         (X_ETH_INBAND_VLAN <<
    2212                 :            :                                         ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
    2213                 :          0 :                                 tx_start_bd->vlan_or_ethertype =
    2214                 :          0 :                                         rte_cpu_to_le_16(ntohs(vh->vlan_tci));
    2215                 :            :                         } else {
    2216                 :          0 :                                 tx_start_bd->vlan_or_ethertype =
    2217         [ #  # ]:          0 :                                         (rte_cpu_to_le_16
    2218                 :            :                                         (rte_be_to_cpu_16(eh->ether_type)));
    2219                 :            :                         }
    2220                 :            :                 }
    2221                 :            :         }
    2222                 :            : 
    2223         [ #  # ]:          0 :         bd_prod = NEXT_TX_BD(bd_prod);
    2224         [ #  # ]:          0 :         if (IS_VF(sc)) {
    2225                 :            :                 struct eth_tx_parse_bd_e2 *tx_parse_bd;
    2226                 :          0 :                 const struct rte_ether_hdr *eh =
    2227                 :          0 :                     rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
    2228                 :            :                 uint8_t mac_type = UNICAST_ADDRESS;
    2229                 :            : 
    2230                 :            :                 tx_parse_bd =
    2231         [ #  # ]:          0 :                     &txq->tx_ring[TX_BD(bd_prod, txq)].parse_bd_e2;
    2232         [ #  # ]:          0 :                 if (rte_is_multicast_ether_addr(&eh->dst_addr)) {
    2233         [ #  # ]:          0 :                         if (rte_is_broadcast_ether_addr(&eh->dst_addr))
    2234                 :            :                                 mac_type = BROADCAST_ADDRESS;
    2235                 :            :                         else
    2236                 :            :                                 mac_type = MULTICAST_ADDRESS;
    2237                 :            :                 }
    2238                 :          0 :                 tx_parse_bd->parsing_data =
    2239                 :          0 :                     (mac_type << ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE_SHIFT);
    2240                 :            : 
    2241                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_hi,
    2242         [ #  # ]:          0 :                            &eh->dst_addr.addr_bytes[0], 2);
    2243                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_mid,
    2244         [ #  # ]:          0 :                            &eh->dst_addr.addr_bytes[2], 2);
    2245                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.dst_lo,
    2246         [ #  # ]:          0 :                            &eh->dst_addr.addr_bytes[4], 2);
    2247                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.src_hi,
    2248         [ #  # ]:          0 :                            &eh->src_addr.addr_bytes[0], 2);
    2249                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.src_mid,
    2250         [ #  # ]:          0 :                            &eh->src_addr.addr_bytes[2], 2);
    2251                 :          0 :                 rte_memcpy(&tx_parse_bd->data.mac_addr.src_lo,
    2252         [ #  # ]:          0 :                            &eh->src_addr.addr_bytes[4], 2);
    2253                 :            : 
    2254                 :          0 :                 tx_parse_bd->data.mac_addr.dst_hi =
    2255         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.dst_hi);
    2256                 :          0 :                 tx_parse_bd->data.mac_addr.dst_mid =
    2257         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.
    2258                 :            :                                      mac_addr.dst_mid);
    2259                 :          0 :                 tx_parse_bd->data.mac_addr.dst_lo =
    2260         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.dst_lo);
    2261                 :          0 :                 tx_parse_bd->data.mac_addr.src_hi =
    2262         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.src_hi);
    2263                 :          0 :                 tx_parse_bd->data.mac_addr.src_mid =
    2264         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.
    2265                 :            :                                      mac_addr.src_mid);
    2266                 :          0 :                 tx_parse_bd->data.mac_addr.src_lo =
    2267         [ #  # ]:          0 :                     rte_cpu_to_be_16(tx_parse_bd->data.mac_addr.src_lo);
    2268                 :            : 
    2269                 :            :                 PMD_TX_LOG(DEBUG,
    2270                 :            :                            "PBD dst %x %x %x src %x %x %x p_data %x",
    2271                 :            :                            tx_parse_bd->data.mac_addr.dst_hi,
    2272                 :            :                            tx_parse_bd->data.mac_addr.dst_mid,
    2273                 :            :                            tx_parse_bd->data.mac_addr.dst_lo,
    2274                 :            :                            tx_parse_bd->data.mac_addr.src_hi,
    2275                 :            :                            tx_parse_bd->data.mac_addr.src_mid,
    2276                 :            :                            tx_parse_bd->data.mac_addr.src_lo,
    2277                 :            :                            tx_parse_bd->parsing_data);
    2278                 :            :         }
    2279                 :            : 
    2280                 :            :         PMD_TX_LOG(DEBUG,
    2281                 :            :                    "start bd: nbytes %d flags %x vlan %x",
    2282                 :            :                    tx_start_bd->nbytes,
    2283                 :            :                    tx_start_bd->bd_flags.as_bitfield,
    2284                 :            :                    tx_start_bd->vlan_or_ethertype);
    2285                 :            : 
    2286         [ #  # ]:          0 :         bd_prod = NEXT_TX_BD(bd_prod);
    2287                 :          0 :         pkt_prod++;
    2288                 :            : 
    2289         [ #  # ]:          0 :         if (TX_IDX(bd_prod) < 2)
    2290                 :            :                 nbds++;
    2291                 :            : 
    2292                 :          0 :         txq->nb_tx_avail -= 2;
    2293                 :          0 :         txq->tx_bd_tail = bd_prod;
    2294                 :          0 :         txq->tx_pkt_tail = pkt_prod;
    2295                 :            : 
    2296                 :          0 :         return nbds + 2;
    2297                 :            : }
    2298                 :            : 
    2299                 :            : static uint16_t bnx2x_cid_ilt_lines(struct bnx2x_softc *sc)
    2300                 :            : {
    2301                 :          0 :         return L2_ILT_LINES(sc);
    2302                 :            : }
    2303                 :            : 
    2304                 :          0 : static void bnx2x_ilt_set_info(struct bnx2x_softc *sc)
    2305                 :            : {
    2306                 :            :         struct ilt_client_info *ilt_client;
    2307                 :          0 :         struct ecore_ilt *ilt = sc->ilt;
    2308                 :            :         uint16_t line = 0;
    2309                 :            : 
    2310                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    2311                 :            : 
    2312                 :          0 :         ilt->start_line = FUNC_ILT_BASE(SC_FUNC(sc));
    2313                 :            : 
    2314                 :            :         /* CDU */
    2315                 :            :         ilt_client = &ilt->clients[ILT_CLIENT_CDU];
    2316                 :          0 :         ilt_client->client_num = ILT_CLIENT_CDU;
    2317                 :          0 :         ilt_client->page_size = CDU_ILT_PAGE_SZ;
    2318                 :          0 :         ilt_client->flags = ILT_CLIENT_SKIP_MEM;
    2319                 :          0 :         ilt_client->start = line;
    2320                 :            :         line += bnx2x_cid_ilt_lines(sc);
    2321                 :            : 
    2322                 :            :         if (CNIC_SUPPORT(sc)) {
    2323                 :            :                 line += CNIC_ILT_LINES;
    2324                 :            :         }
    2325                 :            : 
    2326                 :          0 :         ilt_client->end = (line - 1);
    2327                 :            : 
    2328                 :            :         /* QM */
    2329         [ #  # ]:          0 :         if (QM_INIT(sc->qm_cid_count)) {
    2330                 :            :                 ilt_client = &ilt->clients[ILT_CLIENT_QM];
    2331                 :          0 :                 ilt_client->client_num = ILT_CLIENT_QM;
    2332                 :          0 :                 ilt_client->page_size = QM_ILT_PAGE_SZ;
    2333                 :          0 :                 ilt_client->flags = 0;
    2334                 :          0 :                 ilt_client->start = line;
    2335                 :            : 
    2336                 :            :                 /* 4 bytes for each cid */
    2337                 :          0 :                 line += DIV_ROUND_UP(sc->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
    2338                 :            :                                      QM_ILT_PAGE_SZ);
    2339                 :            : 
    2340                 :          0 :                 ilt_client->end = (line - 1);
    2341                 :            :         }
    2342                 :            : 
    2343                 :            :         if (CNIC_SUPPORT(sc)) {
    2344                 :            :                 /* SRC */
    2345                 :            :                 ilt_client = &ilt->clients[ILT_CLIENT_SRC];
    2346                 :            :                 ilt_client->client_num = ILT_CLIENT_SRC;
    2347                 :            :                 ilt_client->page_size = SRC_ILT_PAGE_SZ;
    2348                 :            :                 ilt_client->flags = 0;
    2349                 :            :                 ilt_client->start = line;
    2350                 :            :                 line += SRC_ILT_LINES;
    2351                 :            :                 ilt_client->end = (line - 1);
    2352                 :            : 
    2353                 :            :                 /* TM */
    2354                 :            :                 ilt_client = &ilt->clients[ILT_CLIENT_TM];
    2355                 :            :                 ilt_client->client_num = ILT_CLIENT_TM;
    2356                 :            :                 ilt_client->page_size = TM_ILT_PAGE_SZ;
    2357                 :            :                 ilt_client->flags = 0;
    2358                 :            :                 ilt_client->start = line;
    2359                 :            :                 line += TM_ILT_LINES;
    2360                 :            :                 ilt_client->end = (line - 1);
    2361                 :            :         }
    2362                 :            : 
    2363         [ #  # ]:          0 :         assert((line <= ILT_MAX_LINES));
    2364                 :          0 : }
    2365                 :            : 
    2366                 :            : static void bnx2x_set_fp_rx_buf_size(struct bnx2x_softc *sc)
    2367                 :            : {
    2368                 :            :         int i;
    2369                 :            : 
    2370         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    2371                 :            :                 /* get the Rx buffer size for RX frames */
    2372                 :          0 :                 sc->fp[i].rx_buf_size =
    2373                 :          0 :                     (IP_HEADER_ALIGNMENT_PADDING + ETH_OVERHEAD + sc->mtu);
    2374                 :            :         }
    2375                 :            : }
    2376                 :            : 
    2377                 :          0 : int bnx2x_alloc_ilt_mem(struct bnx2x_softc *sc)
    2378                 :            : {
    2379                 :            : 
    2380                 :          0 :         sc->ilt = rte_malloc("", sizeof(struct ecore_ilt), RTE_CACHE_LINE_SIZE);
    2381                 :            : 
    2382                 :          0 :         return sc->ilt == NULL;
    2383                 :            : }
    2384                 :            : 
    2385                 :          0 : static int bnx2x_alloc_ilt_lines_mem(struct bnx2x_softc *sc)
    2386                 :            : {
    2387                 :          0 :         sc->ilt->lines = rte_calloc("",
    2388                 :            :                                     ILT_MAX_LINES, sizeof(struct ilt_line),
    2389                 :            :                                     RTE_CACHE_LINE_SIZE);
    2390                 :          0 :         return sc->ilt->lines == NULL;
    2391                 :            : }
    2392                 :            : 
    2393                 :          0 : void bnx2x_free_ilt_mem(struct bnx2x_softc *sc)
    2394                 :            : {
    2395                 :          0 :         rte_free(sc->ilt);
    2396                 :          0 :         sc->ilt = NULL;
    2397                 :          0 : }
    2398                 :            : 
    2399                 :            : static void bnx2x_free_ilt_lines_mem(struct bnx2x_softc *sc)
    2400                 :            : {
    2401         [ #  # ]:          0 :         if (sc->ilt->lines != NULL) {
    2402                 :          0 :                 rte_free(sc->ilt->lines);
    2403                 :          0 :                 sc->ilt->lines = NULL;
    2404                 :            :         }
    2405                 :            : }
    2406                 :            : 
    2407                 :          0 : static void bnx2x_free_mem(struct bnx2x_softc *sc)
    2408                 :            : {
    2409                 :            :         uint32_t i;
    2410                 :            : 
    2411         [ #  # ]:          0 :         for (i = 0; i < L2_ILT_LINES(sc); i++) {
    2412                 :          0 :                 sc->context[i].vcxt = NULL;
    2413                 :          0 :                 sc->context[i].size = 0;
    2414                 :            :         }
    2415                 :            : 
    2416                 :          0 :         ecore_ilt_mem_op(sc, ILT_MEMOP_FREE);
    2417                 :            : 
    2418                 :            :         bnx2x_free_ilt_lines_mem(sc);
    2419                 :          0 : }
    2420                 :            : 
    2421                 :          0 : static int bnx2x_alloc_mem(struct bnx2x_softc *sc)
    2422                 :            : {
    2423                 :            :         int context_size;
    2424                 :            :         int allocated;
    2425                 :            :         int i;
    2426                 :            :         char cdu_name[RTE_MEMZONE_NAMESIZE];
    2427                 :            : 
    2428                 :            :         /*
    2429                 :            :          * Allocate memory for CDU context:
    2430                 :            :          * This memory is allocated separately and not in the generic ILT
    2431                 :            :          * functions because CDU differs in few aspects:
    2432                 :            :          * 1. There can be multiple entities allocating memory for context -
    2433                 :            :          * regular L2, CNIC, and SRIOV drivers. Each separately controls
    2434                 :            :          * its own ILT lines.
    2435                 :            :          * 2. Since CDU page-size is not a single 4KB page (which is the case
    2436                 :            :          * for the other ILT clients), to be efficient we want to support
    2437                 :            :          * allocation of sub-page-size in the last entry.
    2438                 :            :          * 3. Context pointers are used by the driver to pass to FW / update
    2439                 :            :          * the context (for the other ILT clients the pointers are used just to
    2440                 :            :          * free the memory during unload).
    2441                 :            :          */
    2442                 :          0 :         context_size = (sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(sc));
    2443         [ #  # ]:          0 :         for (i = 0, allocated = 0; allocated < context_size; i++) {
    2444                 :          0 :                 sc->context[i].size = min(CDU_ILT_PAGE_SZ,
    2445                 :            :                                           (context_size - allocated));
    2446                 :            : 
    2447                 :            :                 snprintf(cdu_name, sizeof(cdu_name), "cdu_%d", i);
    2448         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, sc->context[i].size,
    2449                 :            :                                   &sc->context[i].vcxt_dma,
    2450                 :            :                                   cdu_name, BNX2X_PAGE_SIZE) != 0) {
    2451                 :          0 :                         bnx2x_free_mem(sc);
    2452                 :          0 :                         return -1;
    2453                 :            :                 }
    2454                 :            : 
    2455                 :          0 :                 sc->context[i].vcxt =
    2456                 :          0 :                     (union cdu_context *)sc->context[i].vcxt_dma.vaddr;
    2457                 :            : 
    2458                 :          0 :                 allocated += sc->context[i].size;
    2459                 :            :         }
    2460                 :            : 
    2461                 :          0 :         bnx2x_alloc_ilt_lines_mem(sc);
    2462                 :            : 
    2463         [ #  # ]:          0 :         if (ecore_ilt_mem_op(sc, ILT_MEMOP_ALLOC)) {
    2464                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "ecore_ilt_mem_op ILT_MEMOP_ALLOC failed");
    2465                 :          0 :                 bnx2x_free_mem(sc);
    2466                 :          0 :                 return -1;
    2467                 :            :         }
    2468                 :            : 
    2469                 :            :         return 0;
    2470                 :            : }
    2471                 :            : 
    2472                 :            : static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc)
    2473                 :            : {
    2474                 :          0 :         bnx2x_dma_free(&sc->fw_stats_dma);
    2475                 :          0 :         sc->fw_stats_num = 0;
    2476                 :            : 
    2477                 :          0 :         sc->fw_stats_req_size = 0;
    2478                 :          0 :         sc->fw_stats_req = NULL;
    2479                 :          0 :         sc->fw_stats_req_mapping = 0;
    2480                 :            : 
    2481                 :          0 :         sc->fw_stats_data_size = 0;
    2482                 :          0 :         sc->fw_stats_data = NULL;
    2483         [ #  # ]:          0 :         sc->fw_stats_data_mapping = 0;
    2484                 :            : }
    2485                 :            : 
    2486                 :          0 : static int bnx2x_alloc_fw_stats_mem(struct bnx2x_softc *sc)
    2487                 :            : {
    2488                 :            :         uint8_t num_queue_stats;
    2489                 :            :         int num_groups, vf_headroom = 0;
    2490                 :            : 
    2491                 :            :         /* number of queues for statistics is number of eth queues */
    2492                 :          0 :         num_queue_stats = BNX2X_NUM_ETH_QUEUES(sc);
    2493                 :            : 
    2494                 :            :         /*
    2495                 :            :          * Total number of FW statistics requests =
    2496                 :            :          *   1 for port stats + 1 for PF stats + num of queues
    2497                 :            :          */
    2498                 :          0 :         sc->fw_stats_num = (2 + num_queue_stats);
    2499                 :            : 
    2500                 :            :         /*
    2501                 :            :          * Request is built from stats_query_header and an array of
    2502                 :            :          * stats_query_cmd_group each of which contains STATS_QUERY_CMD_COUNT
    2503                 :            :          * rules. The real number or requests is configured in the
    2504                 :            :          * stats_query_header.
    2505                 :            :          */
    2506                 :          0 :         num_groups = (sc->fw_stats_num + vf_headroom) / STATS_QUERY_CMD_COUNT;
    2507         [ #  # ]:          0 :         if ((sc->fw_stats_num + vf_headroom) % STATS_QUERY_CMD_COUNT)
    2508                 :          0 :                 num_groups++;
    2509                 :            : 
    2510                 :          0 :         sc->fw_stats_req_size =
    2511                 :          0 :             (sizeof(struct stats_query_header) +
    2512                 :            :              (num_groups * sizeof(struct stats_query_cmd_group)));
    2513                 :            : 
    2514                 :            :         /*
    2515                 :            :          * Data for statistics requests + stats_counter.
    2516                 :            :          * stats_counter holds per-STORM counters that are incremented when
    2517                 :            :          * STORM has finished with the current request. Memory for FCoE
    2518                 :            :          * offloaded statistics are counted anyway, even if they will not be sent.
    2519                 :            :          * VF stats are not accounted for here as the data of VF stats is stored
    2520                 :            :          * in memory allocated by the VF, not here.
    2521                 :            :          */
    2522                 :          0 :         sc->fw_stats_data_size =
    2523                 :            :             (sizeof(struct stats_counter) +
    2524                 :          0 :              sizeof(struct per_port_stats) + sizeof(struct per_pf_stats) +
    2525                 :            :              /* sizeof(struct fcoe_statistics_params) + */
    2526                 :          0 :              (sizeof(struct per_queue_stats) * num_queue_stats));
    2527                 :            : 
    2528         [ #  # ]:          0 :         if (bnx2x_dma_alloc(sc, (sc->fw_stats_req_size + sc->fw_stats_data_size),
    2529                 :            :                           &sc->fw_stats_dma, "fw_stats",
    2530                 :            :                           RTE_CACHE_LINE_SIZE) != 0) {
    2531                 :            :                 bnx2x_free_fw_stats_mem(sc);
    2532                 :          0 :                 return -1;
    2533                 :            :         }
    2534                 :            : 
    2535                 :            :         /* set up the shortcuts */
    2536                 :            : 
    2537                 :          0 :         sc->fw_stats_req = (struct bnx2x_fw_stats_req *)sc->fw_stats_dma.vaddr;
    2538                 :          0 :         sc->fw_stats_req_mapping = sc->fw_stats_dma.paddr;
    2539                 :            : 
    2540                 :          0 :         sc->fw_stats_data =
    2541                 :          0 :             (struct bnx2x_fw_stats_data *)((uint8_t *) sc->fw_stats_dma.vaddr +
    2542                 :          0 :                                          sc->fw_stats_req_size);
    2543                 :          0 :         sc->fw_stats_data_mapping = (sc->fw_stats_dma.paddr +
    2544                 :            :                                      sc->fw_stats_req_size);
    2545                 :            : 
    2546                 :          0 :         return 0;
    2547                 :            : }
    2548                 :            : 
    2549                 :            : /*
    2550                 :            :  * Bits map:
    2551                 :            :  * 0-7  - Engine0 load counter.
    2552                 :            :  * 8-15 - Engine1 load counter.
    2553                 :            :  * 16   - Engine0 RESET_IN_PROGRESS bit.
    2554                 :            :  * 17   - Engine1 RESET_IN_PROGRESS bit.
    2555                 :            :  * 18   - Engine0 ONE_IS_LOADED. Set when there is at least one active
    2556                 :            :  *        function on the engine
    2557                 :            :  * 19   - Engine1 ONE_IS_LOADED.
    2558                 :            :  * 20   - Chip reset flow bit. When set none-leader must wait for both engines
    2559                 :            :  *        leader to complete (check for both RESET_IN_PROGRESS bits and not
    2560                 :            :  *        for just the one belonging to its engine).
    2561                 :            :  */
    2562                 :            : #define BNX2X_RECOVERY_GLOB_REG     MISC_REG_GENERIC_POR_1
    2563                 :            : #define BNX2X_PATH0_LOAD_CNT_MASK   0x000000ff
    2564                 :            : #define BNX2X_PATH0_LOAD_CNT_SHIFT  0
    2565                 :            : #define BNX2X_PATH1_LOAD_CNT_MASK   0x0000ff00
    2566                 :            : #define BNX2X_PATH1_LOAD_CNT_SHIFT  8
    2567                 :            : #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
    2568                 :            : #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
    2569                 :            : #define BNX2X_GLOBAL_RESET_BIT      0x00040000
    2570                 :            : 
    2571                 :            : /* set the GLOBAL_RESET bit, should be run under rtnl lock */
    2572                 :          0 : static void bnx2x_set_reset_global(struct bnx2x_softc *sc)
    2573                 :            : {
    2574                 :            :         uint32_t val;
    2575                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2576                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2577                 :          0 :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
    2578                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2579                 :          0 : }
    2580                 :            : 
    2581                 :            : /* clear the GLOBAL_RESET bit, should be run under rtnl lock */
    2582                 :            : static void bnx2x_clear_reset_global(struct bnx2x_softc *sc)
    2583                 :            : {
    2584                 :            :         uint32_t val;
    2585                 :            :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2586                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2587                 :            :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
    2588                 :            :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2589                 :            : }
    2590                 :            : 
    2591                 :            : /* checks the GLOBAL_RESET bit, should be run under rtnl lock */
    2592                 :            : static uint8_t bnx2x_reset_is_global(struct bnx2x_softc *sc)
    2593                 :            : {
    2594                 :            :         return REG_RD(sc, BNX2X_RECOVERY_GLOB_REG) & BNX2X_GLOBAL_RESET_BIT;
    2595                 :            : }
    2596                 :            : 
    2597                 :            : /* clear RESET_IN_PROGRESS bit for the engine, should be run under rtnl lock */
    2598                 :          0 : static void bnx2x_set_reset_done(struct bnx2x_softc *sc)
    2599                 :            : {
    2600                 :            :         uint32_t val;
    2601         [ #  # ]:          0 :         uint32_t bit = SC_PATH(sc) ? BNX2X_PATH1_RST_IN_PROG_BIT :
    2602                 :            :             BNX2X_PATH0_RST_IN_PROG_BIT;
    2603                 :            : 
    2604                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2605                 :            : 
    2606                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2607                 :            :         /* Clear the bit */
    2608                 :          0 :         val &= ~bit;
    2609                 :            :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
    2610                 :            : 
    2611                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2612                 :          0 : }
    2613                 :            : 
    2614                 :            : /* set RESET_IN_PROGRESS for the engine, should be run under rtnl lock */
    2615                 :          0 : static void bnx2x_set_reset_in_progress(struct bnx2x_softc *sc)
    2616                 :            : {
    2617                 :            :         uint32_t val;
    2618         [ #  # ]:          0 :         uint32_t bit = SC_PATH(sc) ? BNX2X_PATH1_RST_IN_PROG_BIT :
    2619                 :            :             BNX2X_PATH0_RST_IN_PROG_BIT;
    2620                 :            : 
    2621                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2622                 :            : 
    2623                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2624                 :            :         /* Set the bit */
    2625                 :          0 :         val |= bit;
    2626                 :            :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
    2627                 :            : 
    2628                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2629                 :          0 : }
    2630                 :            : 
    2631                 :            : /* check RESET_IN_PROGRESS bit for an engine, should be run under rtnl lock */
    2632                 :            : static uint8_t bnx2x_reset_is_done(struct bnx2x_softc *sc, int engine)
    2633                 :            : {
    2634                 :            :         uint32_t val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2635   [ #  #  #  # ]:          0 :         uint32_t bit = engine ? BNX2X_PATH1_RST_IN_PROG_BIT :
    2636                 :            :             BNX2X_PATH0_RST_IN_PROG_BIT;
    2637                 :            : 
    2638                 :            :         /* return false if bit is set */
    2639         [ #  # ]:          0 :         return (val & bit) ? FALSE : TRUE;
    2640                 :            : }
    2641                 :            : 
    2642                 :            : /* get the load status for an engine, should be run under rtnl lock */
    2643                 :            : static uint8_t bnx2x_get_load_status(struct bnx2x_softc *sc, int engine)
    2644                 :            : {
    2645         [ #  # ]:          0 :         uint32_t mask = engine ? BNX2X_PATH1_LOAD_CNT_MASK :
    2646                 :            :             BNX2X_PATH0_LOAD_CNT_MASK;
    2647   [ #  #  #  # ]:          0 :         uint32_t shift = engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
    2648                 :            :             BNX2X_PATH0_LOAD_CNT_SHIFT;
    2649                 :            :         uint32_t val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2650                 :            : 
    2651                 :          0 :         val = ((val & mask) >> shift);
    2652                 :            : 
    2653                 :            :         return val != 0;
    2654                 :            : }
    2655                 :            : 
    2656                 :            : /* set pf load mark */
    2657                 :          0 : static void bnx2x_set_pf_load(struct bnx2x_softc *sc)
    2658                 :            : {
    2659                 :            :         uint32_t val;
    2660                 :            :         uint32_t val1;
    2661         [ #  # ]:          0 :         uint32_t mask = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_MASK :
    2662                 :            :             BNX2X_PATH0_LOAD_CNT_MASK;
    2663         [ #  # ]:          0 :         uint32_t shift = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
    2664                 :            :             BNX2X_PATH0_LOAD_CNT_SHIFT;
    2665                 :            : 
    2666                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2667                 :            : 
    2668                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    2669                 :            : 
    2670                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2671                 :            : 
    2672                 :            :         /* get the current counter value */
    2673                 :          0 :         val1 = ((val & mask) >> shift);
    2674                 :            : 
    2675                 :            :         /* set bit of this PF */
    2676                 :          0 :         val1 |= (1 << SC_ABS_FUNC(sc));
    2677                 :            : 
    2678                 :            :         /* clear the old value */
    2679                 :            :         val &= ~mask;
    2680                 :            : 
    2681                 :            :         /* set the new one */
    2682                 :          0 :         val |= ((val1 << shift) & mask);
    2683                 :            : 
    2684                 :            :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
    2685                 :            : 
    2686                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2687                 :          0 : }
    2688                 :            : 
    2689                 :            : /* clear pf load mark */
    2690                 :          0 : static uint8_t bnx2x_clear_pf_load(struct bnx2x_softc *sc)
    2691                 :            : {
    2692                 :            :         uint32_t val1, val;
    2693         [ #  # ]:          0 :         uint32_t mask = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_MASK :
    2694                 :            :             BNX2X_PATH0_LOAD_CNT_MASK;
    2695         [ #  # ]:          0 :         uint32_t shift = SC_PATH(sc) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
    2696                 :            :             BNX2X_PATH0_LOAD_CNT_SHIFT;
    2697                 :            : 
    2698                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2699                 :            :         val = REG_RD(sc, BNX2X_RECOVERY_GLOB_REG);
    2700                 :            : 
    2701                 :            :         /* get the current counter value */
    2702                 :          0 :         val1 = (val & mask) >> shift;
    2703                 :            : 
    2704                 :            :         /* clear bit of that PF */
    2705                 :          0 :         val1 &= ~(1 << SC_ABS_FUNC(sc));
    2706                 :            : 
    2707                 :            :         /* clear the old value */
    2708                 :            :         val &= ~mask;
    2709                 :            : 
    2710                 :            :         /* set the new one */
    2711                 :          0 :         val |= ((val1 << shift) & mask);
    2712                 :            : 
    2713                 :            :         REG_WR(sc, BNX2X_RECOVERY_GLOB_REG, val);
    2714                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RECOVERY_REG);
    2715                 :          0 :         return val1 != 0;
    2716                 :            : }
    2717                 :            : 
    2718                 :            : /* send load request to MCP and analyze response */
    2719                 :          0 : static int bnx2x_nic_load_request(struct bnx2x_softc *sc, uint32_t * load_code)
    2720                 :            : {
    2721                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    2722                 :            : 
    2723                 :            :         /* init fw_seq */
    2724                 :          0 :         sc->fw_seq =
    2725   [ #  #  #  # ]:          0 :             (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
    2726                 :            :              DRV_MSG_SEQ_NUMBER_MASK);
    2727                 :            : 
    2728                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "initial fw_seq 0x%04x", sc->fw_seq);
    2729                 :            : 
    2730                 :            : #ifdef BNX2X_PULSE
    2731                 :            :         /* get the current FW pulse sequence */
    2732                 :            :         sc->fw_drv_pulse_wr_seq =
    2733                 :            :             (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_pulse_mb) &
    2734                 :            :              DRV_PULSE_SEQ_MASK);
    2735                 :            : #else
    2736                 :            :         /* set ALWAYS_ALIVE bit in shmem */
    2737                 :          0 :         sc->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
    2738                 :          0 :         bnx2x_drv_pulse(sc);
    2739                 :            : #endif
    2740                 :            : 
    2741                 :            :         /* load request */
    2742                 :          0 :         (*load_code) = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
    2743                 :            :                                       DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
    2744                 :            : 
    2745                 :            :         /* if the MCP fails to respond we must abort */
    2746         [ #  # ]:          0 :         if (!(*load_code)) {
    2747                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "MCP response failure!");
    2748                 :          0 :                 return -1;
    2749                 :            :         }
    2750                 :            : 
    2751                 :            :         /* if MCP refused then must abort */
    2752         [ #  # ]:          0 :         if ((*load_code) == FW_MSG_CODE_DRV_LOAD_REFUSED) {
    2753                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "MCP refused load request");
    2754                 :          0 :                 return -1;
    2755                 :            :         }
    2756                 :            : 
    2757                 :            :         return 0;
    2758                 :            : }
    2759                 :            : 
    2760                 :            : /*
    2761                 :            :  * Check whether another PF has already loaded FW to chip. In virtualized
    2762                 :            :  * environments a pf from anoth VM may have already initialized the device
    2763                 :            :  * including loading FW.
    2764                 :            :  */
    2765                 :          0 : static int bnx2x_nic_load_analyze_req(struct bnx2x_softc *sc, uint32_t load_code)
    2766                 :            : {
    2767                 :            :         uint32_t my_fw, loaded_fw;
    2768                 :            : 
    2769                 :            :         /* is another pf loaded on this engine? */
    2770                 :          0 :         if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
    2771         [ #  # ]:          0 :             (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
    2772                 :            :                 /* build my FW version dword */
    2773                 :            :                 my_fw = (BNX2X_5710_FW_MAJOR_VERSION +
    2774                 :            :                          (BNX2X_5710_FW_MINOR_VERSION << 8) +
    2775                 :            :                          (BNX2X_5710_FW_REVISION_VERSION << 16) +
    2776                 :            :                          (BNX2X_5710_FW_ENGINEERING_VERSION << 24));
    2777                 :            : 
    2778                 :            :                 /* read loaded FW from chip */
    2779                 :            :                 loaded_fw = REG_RD(sc, XSEM_REG_PRAM);
    2780                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "loaded FW 0x%08x / my FW 0x%08x",
    2781                 :            :                             loaded_fw, my_fw);
    2782                 :            : 
    2783                 :            :                 /* abort nic load if version mismatch */
    2784         [ #  # ]:          0 :                 if (my_fw != loaded_fw) {
    2785                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    2786                 :            :                                     "FW 0x%08x already loaded (mine is 0x%08x)",
    2787                 :            :                                     loaded_fw, my_fw);
    2788                 :          0 :                         return -1;
    2789                 :            :                 }
    2790                 :            :         }
    2791                 :            : 
    2792                 :            :         return 0;
    2793                 :            : }
    2794                 :            : 
    2795                 :            : /* mark PMF if applicable */
    2796                 :          0 : static void bnx2x_nic_load_pmf(struct bnx2x_softc *sc, uint32_t load_code)
    2797                 :            : {
    2798                 :            :         uint32_t ncsi_oem_data_addr;
    2799                 :            : 
    2800                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    2801                 :            : 
    2802                 :          0 :         if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
    2803   [ #  #  #  # ]:          0 :             (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
    2804                 :            :             (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
    2805                 :            :                 /*
    2806                 :            :                  * Barrier here for ordering between the writing to sc->port.pmf here
    2807                 :            :                  * and reading it from the periodic task.
    2808                 :            :                  */
    2809                 :          0 :                 sc->port.pmf = 1;
    2810                 :            :                 mb();
    2811                 :            :         } else {
    2812                 :          0 :                 sc->port.pmf = 0;
    2813                 :            :         }
    2814                 :            : 
    2815                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "pmf %d", sc->port.pmf);
    2816                 :            : 
    2817         [ #  # ]:          0 :         if (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) {
    2818   [ #  #  #  # ]:          0 :                 if (SHMEM2_HAS(sc, ncsi_oem_data_addr)) {
    2819                 :          0 :                         ncsi_oem_data_addr = SHMEM2_RD(sc, ncsi_oem_data_addr);
    2820         [ #  # ]:          0 :                         if (ncsi_oem_data_addr) {
    2821                 :          0 :                                 REG_WR(sc,
    2822                 :            :                                        (ncsi_oem_data_addr +
    2823                 :            :                                         offsetof(struct glob_ncsi_oem_data,
    2824                 :            :                                                  driver_version)), 0);
    2825                 :            :                         }
    2826                 :            :                 }
    2827                 :            :         }
    2828                 :          0 : }
    2829                 :            : 
    2830                 :          0 : static void bnx2x_read_mf_cfg(struct bnx2x_softc *sc)
    2831                 :            : {
    2832         [ #  # ]:          0 :         int n = (CHIP_IS_MODE_4_PORT(sc) ? 2 : 1);
    2833                 :            :         int abs_func;
    2834                 :            :         int vn;
    2835                 :            : 
    2836         [ #  # ]:          0 :         if (BNX2X_NOMCP(sc)) {
    2837                 :            :                 return;         /* what should be the default bvalue in this case */
    2838                 :            :         }
    2839                 :            : 
    2840                 :            :         /*
    2841                 :            :          * The formula for computing the absolute function number is...
    2842                 :            :          * For 2 port configuration (4 functions per port):
    2843                 :            :          *   abs_func = 2 * vn + SC_PORT + SC_PATH
    2844                 :            :          * For 4 port configuration (2 functions per port):
    2845                 :            :          *   abs_func = 4 * vn + 2 * SC_PORT + SC_PATH
    2846                 :            :          */
    2847   [ #  #  #  # ]:          0 :         for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
    2848                 :          0 :                 abs_func = (n * (2 * vn + SC_PORT(sc)) + SC_PATH(sc));
    2849         [ #  # ]:          0 :                 if (abs_func >= E1H_FUNC_MAX) {
    2850                 :            :                         break;
    2851                 :            :                 }
    2852                 :          0 :                 sc->devinfo.mf_info.mf_config[vn] =
    2853                 :          0 :                     MFCFG_RD(sc, func_mf_config[abs_func].config);
    2854                 :            :         }
    2855                 :            : 
    2856         [ #  # ]:          0 :         if (sc->devinfo.mf_info.mf_config[SC_VN(sc)] &
    2857                 :            :             FUNC_MF_CFG_FUNC_DISABLED) {
    2858                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function disabled");
    2859                 :          0 :                 sc->flags |= BNX2X_MF_FUNC_DIS;
    2860                 :            :         } else {
    2861                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "mf_cfg function enabled");
    2862                 :          0 :                 sc->flags &= ~BNX2X_MF_FUNC_DIS;
    2863                 :            :         }
    2864                 :            : }
    2865                 :            : 
    2866                 :            : /* acquire split MCP access lock register */
    2867                 :          0 : static int bnx2x_acquire_alr(struct bnx2x_softc *sc)
    2868                 :            : {
    2869                 :            :         uint32_t j, val;
    2870                 :            : 
    2871         [ #  # ]:          0 :         for (j = 0; j < 1000; j++) {
    2872                 :            :                 val = (1UL << 31);
    2873                 :            :                 REG_WR(sc, GRCBASE_MCP + 0x9c, val);
    2874                 :            :                 val = REG_RD(sc, GRCBASE_MCP + 0x9c);
    2875         [ #  # ]:          0 :                 if (val & (1L << 31))
    2876                 :            :                         break;
    2877                 :            : 
    2878                 :          0 :                 DELAY(5000);
    2879                 :            :         }
    2880                 :            : 
    2881         [ #  # ]:          0 :         if (!(val & (1L << 31))) {
    2882                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Cannot acquire MCP access lock register");
    2883                 :          0 :                 return -1;
    2884                 :            :         }
    2885                 :            : 
    2886                 :            :         return 0;
    2887                 :            : }
    2888                 :            : 
    2889                 :            : /* release split MCP access lock register */
    2890                 :            : static void bnx2x_release_alr(struct bnx2x_softc *sc)
    2891                 :            : {
    2892                 :            :         REG_WR(sc, GRCBASE_MCP + 0x9c, 0);
    2893                 :            : }
    2894                 :            : 
    2895                 :          0 : static void bnx2x_fan_failure(struct bnx2x_softc *sc)
    2896                 :            : {
    2897                 :          0 :         int port = SC_PORT(sc);
    2898                 :            :         uint32_t ext_phy_config;
    2899                 :            : 
    2900                 :            :         /* mark the failure */
    2901                 :            :         ext_phy_config =
    2902                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
    2903                 :            : 
    2904                 :          0 :         ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
    2905                 :          0 :         ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
    2906                 :          0 :         SHMEM_WR(sc, dev_info.port_hw_config[port].external_phy_config,
    2907                 :            :                  ext_phy_config);
    2908                 :            : 
    2909                 :            :         /* log the failure */
    2910                 :          0 :         PMD_DRV_LOG(INFO, sc,
    2911                 :            :                     "Fan Failure has caused the driver to shutdown "
    2912                 :            :                     "the card to prevent permanent damage. "
    2913                 :            :                     "Please contact OEM Support for assistance");
    2914                 :            : 
    2915                 :          0 :         rte_panic("Schedule task to handle fan failure");
    2916                 :            : }
    2917                 :            : 
    2918                 :            : /* this function is called upon a link interrupt */
    2919                 :          0 : static void bnx2x_link_attn(struct bnx2x_softc *sc)
    2920                 :            : {
    2921                 :            :         uint32_t pause_enabled = 0;
    2922                 :            :         struct host_port_stats *pstats;
    2923                 :            :         int cmng_fns;
    2924                 :            : 
    2925                 :            :         /* Make sure that we are synced with the current statistics */
    2926                 :          0 :         bnx2x_stats_handle(sc, STATS_EVENT_STOP);
    2927                 :            : 
    2928                 :          0 :         elink_link_update(&sc->link_params, &sc->link_vars);
    2929                 :            : 
    2930         [ #  # ]:          0 :         if (sc->link_vars.link_up) {
    2931                 :            : 
    2932                 :            :                 /* dropless flow control */
    2933         [ #  # ]:          0 :                 if (sc->dropless_fc) {
    2934                 :            :                         pause_enabled = 0;
    2935                 :            : 
    2936         [ #  # ]:          0 :                         if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
    2937                 :            :                                 pause_enabled = 1;
    2938                 :            :                         }
    2939                 :            : 
    2940                 :          0 :                         REG_WR(sc,
    2941                 :            :                                (BAR_USTRORM_INTMEM +
    2942                 :            :                                 USTORM_ETH_PAUSE_ENABLED_OFFSET(SC_PORT(sc))),
    2943                 :            :                                pause_enabled);
    2944                 :            :                 }
    2945                 :            : 
    2946         [ #  # ]:          0 :                 if (sc->link_vars.mac_type != ELINK_MAC_TYPE_EMAC) {
    2947                 :          0 :                         pstats = BNX2X_SP(sc, port_stats);
    2948                 :            :                         /* reset old mac stats */
    2949                 :          0 :                         memset(&(pstats->mac_stx[0]), 0,
    2950                 :            :                                sizeof(struct mac_stx));
    2951                 :            :                 }
    2952                 :            : 
    2953         [ #  # ]:          0 :                 if (sc->state == BNX2X_STATE_OPEN) {
    2954                 :          0 :                         bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
    2955                 :            :                 }
    2956                 :            :         }
    2957                 :            : 
    2958   [ #  #  #  # ]:          0 :         if (sc->link_vars.link_up && sc->link_vars.line_speed) {
    2959                 :            :                 cmng_fns = bnx2x_get_cmng_fns_mode(sc);
    2960                 :            : 
    2961                 :            :                 if (cmng_fns != CMNG_FNS_NONE) {
    2962                 :          0 :                         bnx2x_cmng_fns_init(sc, FALSE, cmng_fns);
    2963                 :          0 :                         storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
    2964                 :            :                 }
    2965                 :            :         }
    2966                 :            : 
    2967                 :          0 :         bnx2x_link_report_locked(sc);
    2968                 :            : 
    2969   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    2970                 :          0 :                 bnx2x_link_sync_notify(sc);
    2971                 :            :         }
    2972                 :          0 : }
    2973                 :            : 
    2974                 :          0 : static void bnx2x_attn_int_asserted(struct bnx2x_softc *sc, uint32_t asserted)
    2975                 :            : {
    2976                 :          0 :         int port = SC_PORT(sc);
    2977         [ #  # ]:          0 :         uint32_t aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
    2978                 :            :             MISC_REG_AEU_MASK_ATTN_FUNC_0;
    2979         [ #  # ]:          0 :         uint32_t nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
    2980                 :            :             NIG_REG_MASK_INTERRUPT_PORT0;
    2981                 :            :         uint32_t aeu_mask;
    2982                 :            :         uint32_t nig_mask = 0;
    2983                 :            :         uint32_t reg_addr;
    2984                 :            :         uint32_t igu_acked;
    2985                 :            :         uint32_t cnt;
    2986                 :            : 
    2987         [ #  # ]:          0 :         if (sc->attn_state & asserted) {
    2988                 :          0 :                 PMD_DRV_LOG(ERR, sc, "IGU ERROR attn=0x%08x", asserted);
    2989                 :            :         }
    2990                 :            : 
    2991                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
    2992                 :            : 
    2993                 :          0 :         aeu_mask = REG_RD(sc, aeu_addr);
    2994                 :            : 
    2995                 :          0 :         aeu_mask &= ~(asserted & 0x3ff);
    2996                 :            : 
    2997                 :            :         REG_WR(sc, aeu_addr, aeu_mask);
    2998                 :            : 
    2999                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
    3000                 :            : 
    3001                 :          0 :         sc->attn_state |= asserted;
    3002                 :            : 
    3003         [ #  # ]:          0 :         if (asserted & ATTN_HARD_WIRED_MASK) {
    3004         [ #  # ]:          0 :                 if (asserted & ATTN_NIG_FOR_FUNC) {
    3005                 :            : 
    3006                 :          0 :                         bnx2x_acquire_phy_lock(sc);
    3007                 :            :                         /* save nig interrupt mask */
    3008                 :          0 :                         nig_mask = REG_RD(sc, nig_int_mask_addr);
    3009                 :            : 
    3010                 :            :                         /* If nig_mask is not set, no need to call the update function */
    3011         [ #  # ]:          0 :                         if (nig_mask) {
    3012                 :            :                                 REG_WR(sc, nig_int_mask_addr, 0);
    3013                 :            : 
    3014                 :          0 :                                 bnx2x_link_attn(sc);
    3015                 :            :                         }
    3016                 :            : 
    3017                 :            :                         /* handle unicore attn? */
    3018                 :            :                 }
    3019                 :            : 
    3020         [ #  # ]:          0 :                 if (asserted & ATTN_SW_TIMER_4_FUNC) {
    3021                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "ATTN_SW_TIMER_4_FUNC!");
    3022                 :            :                 }
    3023                 :            : 
    3024         [ #  # ]:          0 :                 if (asserted & GPIO_2_FUNC) {
    3025                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "GPIO_2_FUNC!");
    3026                 :            :                 }
    3027                 :            : 
    3028         [ #  # ]:          0 :                 if (asserted & GPIO_3_FUNC) {
    3029                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "GPIO_3_FUNC!");
    3030                 :            :                 }
    3031                 :            : 
    3032         [ #  # ]:          0 :                 if (asserted & GPIO_4_FUNC) {
    3033                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "GPIO_4_FUNC!");
    3034                 :            :                 }
    3035                 :            : 
    3036         [ #  # ]:          0 :                 if (port == 0) {
    3037         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_1) {
    3038                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_1!");
    3039                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
    3040                 :            :                         }
    3041         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_2) {
    3042                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_2!");
    3043                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
    3044                 :            :                         }
    3045         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_3) {
    3046                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_3!");
    3047                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
    3048                 :            :                         }
    3049                 :            :                 } else {
    3050         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_4) {
    3051                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_4!");
    3052                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
    3053                 :            :                         }
    3054         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_5) {
    3055                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_5!");
    3056                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
    3057                 :            :                         }
    3058         [ #  # ]:          0 :                         if (asserted & ATTN_GENERAL_ATTN_6) {
    3059                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "ATTN_GENERAL_ATTN_6!");
    3060                 :            :                                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
    3061                 :            :                         }
    3062                 :            :                 }
    3063                 :            :         }
    3064                 :            :         /* hardwired */
    3065         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    3066                 :          0 :                 reg_addr =
    3067                 :          0 :                     (HC_REG_COMMAND_REG + port * 32 +
    3068                 :            :                      COMMAND_REG_ATTN_BITS_SET);
    3069                 :            :         } else {
    3070                 :            :                 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER * 8);
    3071                 :            :         }
    3072                 :            : 
    3073         [ #  # ]:          0 :         PMD_DRV_LOG(DEBUG, sc, "about to mask 0x%08x at %s addr 0x%08x",
    3074                 :            :                     asserted,
    3075                 :            :                     (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU",
    3076                 :            :                     reg_addr);
    3077                 :          0 :         REG_WR(sc, reg_addr, asserted);
    3078                 :            : 
    3079                 :            :         /* now set back the mask */
    3080         [ #  # ]:          0 :         if (asserted & ATTN_NIG_FOR_FUNC) {
    3081                 :            :                 /*
    3082                 :            :                  * Verify that IGU ack through BAR was written before restoring
    3083                 :            :                  * NIG mask. This loop should exit after 2-3 iterations max.
    3084                 :            :                  */
    3085         [ #  # ]:          0 :                 if (sc->devinfo.int_block != INT_BLOCK_HC) {
    3086                 :            :                         cnt = 0;
    3087                 :            : 
    3088                 :            :                         do {
    3089                 :            :                                 igu_acked =
    3090                 :            :                                     REG_RD(sc, IGU_REG_ATTENTION_ACK_BITS);
    3091                 :            :                         } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0)
    3092   [ #  #  #  # ]:          0 :                                  && (++cnt < MAX_IGU_ATTN_ACK_TO));
    3093                 :            : 
    3094         [ #  # ]:          0 :                         if (!igu_acked) {
    3095                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    3096                 :            :                                             "Failed to verify IGU ack on time");
    3097                 :            :                         }
    3098                 :            : 
    3099                 :            :                         mb();
    3100                 :            :                 }
    3101                 :            : 
    3102                 :          0 :                 REG_WR(sc, nig_int_mask_addr, nig_mask);
    3103                 :            : 
    3104                 :            :                 bnx2x_release_phy_lock(sc);
    3105                 :            :         }
    3106                 :          0 : }
    3107                 :            : 
    3108                 :            : static void
    3109                 :          0 : bnx2x_print_next_block(__rte_unused struct bnx2x_softc *sc, __rte_unused int idx,
    3110                 :            :                      __rte_unused const char *blk)
    3111                 :            : {
    3112         [ #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%s%s", idx ? ", " : "", blk);
    3113                 :          0 : }
    3114                 :            : 
    3115                 :            : static int
    3116                 :          0 : bnx2x_check_blocks_with_parity0(struct bnx2x_softc *sc, uint32_t sig, int par_num,
    3117                 :            :                               uint8_t print)
    3118                 :            : {
    3119                 :            :         uint32_t cur_bit = 0;
    3120                 :            :         int i = 0;
    3121                 :            : 
    3122         [ #  # ]:          0 :         for (i = 0; sig; i++) {
    3123                 :          0 :                 cur_bit = ((uint32_t) 0x1 << i);
    3124         [ #  # ]:          0 :                 if (sig & cur_bit) {
    3125   [ #  #  #  #  :          0 :                         switch (cur_bit) {
             #  #  #  # ]
    3126                 :          0 :                         case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
    3127         [ #  # ]:          0 :                                 if (print)
    3128                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3129                 :            :                                                              "BRB");
    3130                 :            :                                 break;
    3131                 :          0 :                         case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
    3132         [ #  # ]:          0 :                                 if (print)
    3133                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3134                 :            :                                                              "PARSER");
    3135                 :            :                                 break;
    3136                 :          0 :                         case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
    3137         [ #  # ]:          0 :                                 if (print)
    3138                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3139                 :            :                                                              "TSDM");
    3140                 :            :                                 break;
    3141                 :          0 :                         case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
    3142         [ #  # ]:          0 :                                 if (print)
    3143                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3144                 :            :                                                              "SEARCHER");
    3145                 :            :                                 break;
    3146                 :          0 :                         case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
    3147         [ #  # ]:          0 :                                 if (print)
    3148                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3149                 :            :                                                              "TCM");
    3150                 :            :                                 break;
    3151                 :          0 :                         case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
    3152         [ #  # ]:          0 :                                 if (print)
    3153                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3154                 :            :                                                              "TSEMI");
    3155                 :            :                                 break;
    3156                 :          0 :                         case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
    3157         [ #  # ]:          0 :                                 if (print)
    3158                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3159                 :            :                                                              "XPB");
    3160                 :            :                                 break;
    3161                 :            :                         }
    3162                 :            : 
    3163                 :            :                         /* Clear the bit */
    3164                 :          0 :                         sig &= ~cur_bit;
    3165                 :            :                 }
    3166                 :            :         }
    3167                 :            : 
    3168                 :          0 :         return par_num;
    3169                 :            : }
    3170                 :            : 
    3171                 :            : static int
    3172                 :          0 : bnx2x_check_blocks_with_parity1(struct bnx2x_softc *sc, uint32_t sig, int par_num,
    3173                 :            :                               uint8_t * global, uint8_t print)
    3174                 :            : {
    3175                 :            :         int i = 0;
    3176                 :            :         uint32_t cur_bit = 0;
    3177         [ #  # ]:          0 :         for (i = 0; sig; i++) {
    3178                 :          0 :                 cur_bit = ((uint32_t) 0x1 << i);
    3179         [ #  # ]:          0 :                 if (sig & cur_bit) {
    3180   [ #  #  #  #  :          0 :                         switch (cur_bit) {
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
    3181                 :          0 :                         case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
    3182         [ #  # ]:          0 :                                 if (print)
    3183                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3184                 :            :                                                              "PBF");
    3185                 :            :                                 break;
    3186                 :          0 :                         case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
    3187         [ #  # ]:          0 :                                 if (print)
    3188                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3189                 :            :                                                              "QM");
    3190                 :            :                                 break;
    3191                 :          0 :                         case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
    3192         [ #  # ]:          0 :                                 if (print)
    3193                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3194                 :            :                                                              "TM");
    3195                 :            :                                 break;
    3196                 :          0 :                         case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
    3197         [ #  # ]:          0 :                                 if (print)
    3198                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3199                 :            :                                                              "XSDM");
    3200                 :            :                                 break;
    3201                 :          0 :                         case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
    3202         [ #  # ]:          0 :                                 if (print)
    3203                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3204                 :            :                                                              "XCM");
    3205                 :            :                                 break;
    3206                 :          0 :                         case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
    3207         [ #  # ]:          0 :                                 if (print)
    3208                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3209                 :            :                                                              "XSEMI");
    3210                 :            :                                 break;
    3211                 :          0 :                         case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
    3212         [ #  # ]:          0 :                                 if (print)
    3213                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3214                 :            :                                                              "DOORBELLQ");
    3215                 :            :                                 break;
    3216                 :          0 :                         case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
    3217         [ #  # ]:          0 :                                 if (print)
    3218                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3219                 :            :                                                              "NIG");
    3220                 :            :                                 break;
    3221                 :          0 :                         case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
    3222         [ #  # ]:          0 :                                 if (print)
    3223                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3224                 :            :                                                              "VAUX PCI CORE");
    3225                 :          0 :                                 *global = TRUE;
    3226                 :          0 :                                 break;
    3227                 :          0 :                         case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
    3228         [ #  # ]:          0 :                                 if (print)
    3229                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3230                 :            :                                                              "DEBUG");
    3231                 :            :                                 break;
    3232                 :          0 :                         case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
    3233         [ #  # ]:          0 :                                 if (print)
    3234                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3235                 :            :                                                              "USDM");
    3236                 :            :                                 break;
    3237                 :          0 :                         case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
    3238         [ #  # ]:          0 :                                 if (print)
    3239                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3240                 :            :                                                              "UCM");
    3241                 :            :                                 break;
    3242                 :          0 :                         case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
    3243         [ #  # ]:          0 :                                 if (print)
    3244                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3245                 :            :                                                              "USEMI");
    3246                 :            :                                 break;
    3247                 :          0 :                         case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
    3248         [ #  # ]:          0 :                                 if (print)
    3249                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3250                 :            :                                                              "UPB");
    3251                 :            :                                 break;
    3252                 :          0 :                         case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
    3253         [ #  # ]:          0 :                                 if (print)
    3254                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3255                 :            :                                                              "CSDM");
    3256                 :            :                                 break;
    3257                 :          0 :                         case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
    3258         [ #  # ]:          0 :                                 if (print)
    3259                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3260                 :            :                                                              "CCM");
    3261                 :            :                                 break;
    3262                 :            :                         }
    3263                 :            : 
    3264                 :            :                         /* Clear the bit */
    3265                 :          0 :                         sig &= ~cur_bit;
    3266                 :            :                 }
    3267                 :            :         }
    3268                 :            : 
    3269                 :          0 :         return par_num;
    3270                 :            : }
    3271                 :            : 
    3272                 :            : static int
    3273                 :          0 : bnx2x_check_blocks_with_parity2(struct bnx2x_softc *sc, uint32_t sig, int par_num,
    3274                 :            :                               uint8_t print)
    3275                 :            : {
    3276                 :            :         uint32_t cur_bit = 0;
    3277                 :            :         int i = 0;
    3278                 :            : 
    3279         [ #  # ]:          0 :         for (i = 0; sig; i++) {
    3280                 :          0 :                 cur_bit = ((uint32_t) 0x1 << i);
    3281         [ #  # ]:          0 :                 if (sig & cur_bit) {
    3282   [ #  #  #  #  :          0 :                         switch (cur_bit) {
             #  #  #  #  
                      # ]
    3283                 :          0 :                         case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
    3284         [ #  # ]:          0 :                                 if (print)
    3285                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3286                 :            :                                                              "CSEMI");
    3287                 :            :                                 break;
    3288                 :          0 :                         case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
    3289         [ #  # ]:          0 :                                 if (print)
    3290                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3291                 :            :                                                              "PXP");
    3292                 :            :                                 break;
    3293                 :          0 :                         case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
    3294         [ #  # ]:          0 :                                 if (print)
    3295                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3296                 :            :                                                              "PXPPCICLOCKCLIENT");
    3297                 :            :                                 break;
    3298                 :          0 :                         case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
    3299         [ #  # ]:          0 :                                 if (print)
    3300                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3301                 :            :                                                              "CFC");
    3302                 :            :                                 break;
    3303                 :          0 :                         case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
    3304         [ #  # ]:          0 :                                 if (print)
    3305                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3306                 :            :                                                              "CDU");
    3307                 :            :                                 break;
    3308                 :          0 :                         case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
    3309         [ #  # ]:          0 :                                 if (print)
    3310                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3311                 :            :                                                              "DMAE");
    3312                 :            :                                 break;
    3313                 :          0 :                         case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
    3314         [ #  # ]:          0 :                                 if (print)
    3315                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3316                 :            :                                                              "IGU");
    3317                 :            :                                 break;
    3318                 :          0 :                         case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
    3319         [ #  # ]:          0 :                                 if (print)
    3320                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3321                 :            :                                                              "MISC");
    3322                 :            :                                 break;
    3323                 :            :                         }
    3324                 :            : 
    3325                 :            :                         /* Clear the bit */
    3326                 :          0 :                         sig &= ~cur_bit;
    3327                 :            :                 }
    3328                 :            :         }
    3329                 :            : 
    3330                 :          0 :         return par_num;
    3331                 :            : }
    3332                 :            : 
    3333                 :            : static int
    3334                 :          0 : bnx2x_check_blocks_with_parity3(struct bnx2x_softc *sc, uint32_t sig, int par_num,
    3335                 :            :                               uint8_t * global, uint8_t print)
    3336                 :            : {
    3337                 :            :         uint32_t cur_bit = 0;
    3338                 :            :         int i = 0;
    3339                 :            : 
    3340         [ #  # ]:          0 :         for (i = 0; sig; i++) {
    3341                 :          0 :                 cur_bit = ((uint32_t) 0x1 << i);
    3342         [ #  # ]:          0 :                 if (sig & cur_bit) {
    3343   [ #  #  #  #  :          0 :                         switch (cur_bit) {
                      # ]
    3344                 :          0 :                         case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
    3345         [ #  # ]:          0 :                                 if (print)
    3346                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3347                 :            :                                                              "MCP ROM");
    3348                 :          0 :                                 *global = TRUE;
    3349                 :          0 :                                 break;
    3350                 :          0 :                         case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
    3351         [ #  # ]:          0 :                                 if (print)
    3352                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3353                 :            :                                                              "MCP UMP RX");
    3354                 :          0 :                                 *global = TRUE;
    3355                 :          0 :                                 break;
    3356                 :          0 :                         case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
    3357         [ #  # ]:          0 :                                 if (print)
    3358                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3359                 :            :                                                              "MCP UMP TX");
    3360                 :          0 :                                 *global = TRUE;
    3361                 :          0 :                                 break;
    3362                 :          0 :                         case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
    3363         [ #  # ]:          0 :                                 if (print)
    3364                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3365                 :            :                                                              "MCP SCPAD");
    3366                 :          0 :                                 *global = TRUE;
    3367                 :          0 :                                 break;
    3368                 :            :                         }
    3369                 :            : 
    3370                 :            :                         /* Clear the bit */
    3371                 :          0 :                         sig &= ~cur_bit;
    3372                 :            :                 }
    3373                 :            :         }
    3374                 :            : 
    3375                 :          0 :         return par_num;
    3376                 :            : }
    3377                 :            : 
    3378                 :            : static int
    3379                 :          0 : bnx2x_check_blocks_with_parity4(struct bnx2x_softc *sc, uint32_t sig, int par_num,
    3380                 :            :                               uint8_t print)
    3381                 :            : {
    3382                 :            :         uint32_t cur_bit = 0;
    3383                 :            :         int i = 0;
    3384                 :            : 
    3385         [ #  # ]:          0 :         for (i = 0; sig; i++) {
    3386                 :          0 :                 cur_bit = ((uint32_t) 0x1 << i);
    3387         [ #  # ]:          0 :                 if (sig & cur_bit) {
    3388      [ #  #  # ]:          0 :                         switch (cur_bit) {
    3389                 :          0 :                         case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
    3390         [ #  # ]:          0 :                                 if (print)
    3391                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3392                 :            :                                                              "PGLUE_B");
    3393                 :            :                                 break;
    3394                 :          0 :                         case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
    3395         [ #  # ]:          0 :                                 if (print)
    3396                 :          0 :                                         bnx2x_print_next_block(sc, par_num++,
    3397                 :            :                                                              "ATC");
    3398                 :            :                                 break;
    3399                 :            :                         }
    3400                 :            : 
    3401                 :            :                         /* Clear the bit */
    3402                 :          0 :                         sig &= ~cur_bit;
    3403                 :            :                 }
    3404                 :            :         }
    3405                 :            : 
    3406                 :          0 :         return par_num;
    3407                 :            : }
    3408                 :            : 
    3409                 :            : static uint8_t
    3410                 :          0 : bnx2x_parity_attn(struct bnx2x_softc *sc, uint8_t * global, uint8_t print,
    3411                 :            :                 uint32_t * sig)
    3412                 :            : {
    3413                 :            :         int par_num = 0;
    3414                 :            : 
    3415         [ #  # ]:          0 :         if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
    3416         [ #  # ]:          0 :             (sig[1] & HW_PRTY_ASSERT_SET_1) ||
    3417         [ #  # ]:          0 :             (sig[2] & HW_PRTY_ASSERT_SET_2) ||
    3418         [ #  # ]:          0 :             (sig[3] & HW_PRTY_ASSERT_SET_3) ||
    3419         [ #  # ]:          0 :             (sig[4] & HW_PRTY_ASSERT_SET_4)) {
    3420                 :          0 :                 PMD_DRV_LOG(ERR, sc,
    3421                 :            :                             "Parity error: HW block parity attention:"
    3422                 :            :                             "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x",
    3423                 :            :                             (uint32_t) (sig[0] & HW_PRTY_ASSERT_SET_0),
    3424                 :            :                             (uint32_t) (sig[1] & HW_PRTY_ASSERT_SET_1),
    3425                 :            :                             (uint32_t) (sig[2] & HW_PRTY_ASSERT_SET_2),
    3426                 :            :                             (uint32_t) (sig[3] & HW_PRTY_ASSERT_SET_3),
    3427                 :            :                             (uint32_t) (sig[4] & HW_PRTY_ASSERT_SET_4));
    3428                 :            : 
    3429         [ #  # ]:          0 :                 if (print)
    3430                 :          0 :                         PMD_DRV_LOG(INFO, sc, "Parity errors detected in blocks: ");
    3431                 :            : 
    3432                 :            :                 par_num =
    3433                 :          0 :                     bnx2x_check_blocks_with_parity0(sc, sig[0] &
    3434                 :            :                                                   HW_PRTY_ASSERT_SET_0,
    3435                 :            :                                                   par_num, print);
    3436                 :            :                 par_num =
    3437                 :          0 :                     bnx2x_check_blocks_with_parity1(sc, sig[1] &
    3438                 :            :                                                   HW_PRTY_ASSERT_SET_1,
    3439                 :            :                                                   par_num, global, print);
    3440                 :            :                 par_num =
    3441                 :          0 :                     bnx2x_check_blocks_with_parity2(sc, sig[2] &
    3442                 :            :                                                   HW_PRTY_ASSERT_SET_2,
    3443                 :            :                                                   par_num, print);
    3444                 :            :                 par_num =
    3445                 :          0 :                     bnx2x_check_blocks_with_parity3(sc, sig[3] &
    3446                 :            :                                                   HW_PRTY_ASSERT_SET_3,
    3447                 :            :                                                   par_num, global, print);
    3448                 :            :                 par_num =
    3449                 :          0 :                     bnx2x_check_blocks_with_parity4(sc, sig[4] &
    3450                 :            :                                                   HW_PRTY_ASSERT_SET_4,
    3451                 :            :                                                   par_num, print);
    3452                 :            : 
    3453         [ #  # ]:          0 :                 if (print)
    3454                 :          0 :                         PMD_DRV_LOG(INFO, sc, "");
    3455                 :            : 
    3456                 :          0 :                 return TRUE;
    3457                 :            :         }
    3458                 :            : 
    3459                 :            :         return FALSE;
    3460                 :            : }
    3461                 :            : 
    3462                 :            : static uint8_t
    3463                 :          0 : bnx2x_chk_parity_attn(struct bnx2x_softc *sc, uint8_t * global, uint8_t print)
    3464                 :            : {
    3465                 :          0 :         struct attn_route attn = { {0} };
    3466                 :          0 :         int port = SC_PORT(sc);
    3467                 :            : 
    3468                 :          0 :         attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port * 4);
    3469                 :          0 :         attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port * 4);
    3470                 :          0 :         attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port * 4);
    3471                 :          0 :         attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port * 4);
    3472                 :            : 
    3473         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc))
    3474                 :          0 :                 attn.sig[4] =
    3475                 :          0 :                     REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port * 4);
    3476                 :            : 
    3477                 :          0 :         return bnx2x_parity_attn(sc, global, print, attn.sig);
    3478                 :            : }
    3479                 :            : 
    3480                 :          0 : static void bnx2x_attn_int_deasserted4(struct bnx2x_softc *sc, uint32_t attn)
    3481                 :            : {
    3482                 :            :         uint32_t val;
    3483                 :            : 
    3484         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
    3485                 :            :                 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
    3486                 :          0 :                 PMD_DRV_LOG(INFO, sc, "ERROR: PGLUE hw attention 0x%08x", val);
    3487         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
    3488                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3489                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR");
    3490         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
    3491                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3492                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR");
    3493         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
    3494                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3495                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN");
    3496         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
    3497                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3498                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN");
    3499         [ #  # ]:          0 :                 if (val &
    3500                 :            :                     PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
    3501                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3502                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN");
    3503         [ #  # ]:          0 :                 if (val &
    3504                 :            :                     PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
    3505                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3506                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN");
    3507         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
    3508                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3509                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN");
    3510         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
    3511                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3512                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN");
    3513         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
    3514                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3515                 :            :                                     "ERROR: PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW");
    3516                 :            :         }
    3517                 :            : 
    3518         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
    3519                 :            :                 val = REG_RD(sc, ATC_REG_ATC_INT_STS_CLR);
    3520                 :          0 :                 PMD_DRV_LOG(INFO, sc, "ERROR: ATC hw attention 0x%08x", val);
    3521         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
    3522                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3523                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ADDRESS_ERROR");
    3524         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
    3525                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3526                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND");
    3527         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
    3528                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3529                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS");
    3530         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
    3531                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3532                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT");
    3533         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
    3534                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3535                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR");
    3536         [ #  # ]:          0 :                 if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
    3537                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    3538                 :            :                                     "ERROR: ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU");
    3539                 :            :         }
    3540                 :            : 
    3541         [ #  # ]:          0 :         if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
    3542                 :            :                     AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
    3543                 :          0 :                 PMD_DRV_LOG(INFO, sc,
    3544                 :            :                             "ERROR: FATAL parity attention set4 0x%08x",
    3545                 :            :                             (uint32_t) (attn &
    3546                 :            :                                         (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR
    3547                 :            :                                          |
    3548                 :            :                                          AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
    3549                 :            :         }
    3550                 :          0 : }
    3551                 :            : 
    3552                 :            : static void bnx2x_e1h_disable(struct bnx2x_softc *sc)
    3553                 :            : {
    3554                 :          0 :         int port = SC_PORT(sc);
    3555                 :            : 
    3556                 :          0 :         REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 0);
    3557                 :          0 : }
    3558                 :            : 
    3559                 :            : static void bnx2x_e1h_enable(struct bnx2x_softc *sc)
    3560                 :            : {
    3561                 :          0 :         int port = SC_PORT(sc);
    3562                 :            : 
    3563                 :          0 :         REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
    3564                 :          0 : }
    3565                 :            : 
    3566                 :            : /*
    3567                 :            :  * called due to MCP event (on pmf):
    3568                 :            :  *   reread new bandwidth configuration
    3569                 :            :  *   configure FW
    3570                 :            :  *   notify others function about the change
    3571                 :            :  */
    3572                 :          0 : static void bnx2x_config_mf_bw(struct bnx2x_softc *sc)
    3573                 :            : {
    3574         [ #  # ]:          0 :         if (sc->link_vars.link_up) {
    3575                 :          0 :                 bnx2x_cmng_fns_init(sc, TRUE, CMNG_FNS_MINMAX);
    3576                 :          0 :                 bnx2x_link_sync_notify(sc);
    3577                 :            :         }
    3578                 :            : 
    3579                 :          0 :         storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
    3580                 :          0 : }
    3581                 :            : 
    3582                 :            : static void bnx2x_set_mf_bw(struct bnx2x_softc *sc)
    3583                 :            : {
    3584                 :          0 :         bnx2x_config_mf_bw(sc);
    3585                 :            :         bnx2x_fw_command(sc, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
    3586                 :          0 : }
    3587                 :            : 
    3588                 :            : static void bnx2x_handle_eee_event(struct bnx2x_softc *sc)
    3589                 :            : {
    3590                 :            :         bnx2x_fw_command(sc, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
    3591                 :          0 : }
    3592                 :            : 
    3593                 :            : #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
    3594                 :            : 
    3595                 :          0 : static void bnx2x_drv_info_ether_stat(struct bnx2x_softc *sc)
    3596                 :            : {
    3597                 :          0 :         struct eth_stats_info *ether_stat = &sc->sp->drv_info_to_mcp.ether_stat;
    3598                 :            : 
    3599                 :          0 :         strncpy(ether_stat->version, BNX2X_DRIVER_VERSION,
    3600                 :            :                 ETH_STAT_INFO_VERSION_LEN);
    3601                 :            : 
    3602                 :          0 :         sc->sp_objs[0].mac_obj.get_n_elements(sc, &sc->sp_objs[0].mac_obj,
    3603                 :            :                                               DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
    3604                 :            :                                               ether_stat->mac_local + MAC_PAD,
    3605                 :            :                                               MAC_PAD, ETH_ALEN);
    3606                 :            : 
    3607                 :          0 :         ether_stat->mtu_size = sc->mtu;
    3608                 :            : 
    3609                 :          0 :         ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
    3610                 :          0 :         ether_stat->promiscuous_mode = 0;    // (flags & PROMISC) ? 1 : 0;
    3611                 :            : 
    3612                 :          0 :         ether_stat->txq_size = sc->tx_ring_size;
    3613                 :          0 :         ether_stat->rxq_size = sc->rx_ring_size;
    3614                 :          0 : }
    3615                 :            : 
    3616                 :          0 : static void bnx2x_handle_drv_info_req(struct bnx2x_softc *sc)
    3617                 :            : {
    3618                 :            :         enum drv_info_opcode op_code;
    3619                 :          0 :         uint32_t drv_info_ctl = SHMEM2_RD(sc, drv_info_control);
    3620                 :            : 
    3621                 :            :         /* if drv_info version supported by MFW doesn't match - send NACK */
    3622         [ #  # ]:          0 :         if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
    3623                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
    3624                 :          0 :                 return;
    3625                 :            :         }
    3626                 :            : 
    3627                 :          0 :         op_code = ((drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
    3628                 :            :                    DRV_INFO_CONTROL_OP_CODE_SHIFT);
    3629                 :            : 
    3630         [ #  # ]:          0 :         memset(&sc->sp->drv_info_to_mcp, 0, sizeof(union drv_info_to_mcp));
    3631                 :            : 
    3632         [ #  # ]:          0 :         switch (op_code) {
    3633                 :          0 :         case ETH_STATS_OPCODE:
    3634                 :          0 :                 bnx2x_drv_info_ether_stat(sc);
    3635                 :            :                 break;
    3636                 :            :         case FCOE_STATS_OPCODE:
    3637                 :            :         case ISCSI_STATS_OPCODE:
    3638                 :            :         default:
    3639                 :            :                 /* if op code isn't supported - send NACK */
    3640                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_NACK, 0);
    3641                 :            :                 return;
    3642                 :            :         }
    3643                 :            : 
    3644                 :            :         /*
    3645                 :            :          * If we got drv_info attn from MFW then these fields are defined in
    3646                 :            :          * shmem2 for sure
    3647                 :            :          */
    3648                 :          0 :         SHMEM2_WR(sc, drv_info_host_addr_lo,
    3649                 :            :                   U64_LO(BNX2X_SP_MAPPING(sc, drv_info_to_mcp)));
    3650                 :          0 :         SHMEM2_WR(sc, drv_info_host_addr_hi,
    3651                 :            :                   U64_HI(BNX2X_SP_MAPPING(sc, drv_info_to_mcp)));
    3652                 :            : 
    3653                 :            :         bnx2x_fw_command(sc, DRV_MSG_CODE_DRV_INFO_ACK, 0);
    3654                 :            : }
    3655                 :            : 
    3656                 :          0 : static void bnx2x_dcc_event(struct bnx2x_softc *sc, uint32_t dcc_event)
    3657                 :            : {
    3658         [ #  # ]:          0 :         if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
    3659                 :            : /*
    3660                 :            :  * This is the only place besides the function initialization
    3661                 :            :  * where the sc->flags can change so it is done without any
    3662                 :            :  * locks
    3663                 :            :  */
    3664                 :          0 :                 if (sc->devinfo.
    3665         [ #  # ]:          0 :                     mf_info.mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_DISABLED) {
    3666                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "mf_cfg function disabled");
    3667                 :          0 :                         sc->flags |= BNX2X_MF_FUNC_DIS;
    3668                 :            :                         bnx2x_e1h_disable(sc);
    3669                 :            :                 } else {
    3670                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "mf_cfg function enabled");
    3671                 :          0 :                         sc->flags &= ~BNX2X_MF_FUNC_DIS;
    3672                 :            :                         bnx2x_e1h_enable(sc);
    3673                 :            :                 }
    3674                 :          0 :                 dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
    3675                 :            :         }
    3676                 :            : 
    3677         [ #  # ]:          0 :         if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
    3678                 :          0 :                 bnx2x_config_mf_bw(sc);
    3679                 :          0 :                 dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
    3680                 :            :         }
    3681                 :            : 
    3682                 :            :         /* Report results to MCP */
    3683         [ #  # ]:          0 :         if (dcc_event)
    3684                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_DCC_FAILURE, 0);
    3685                 :            :         else
    3686                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_DCC_OK, 0);
    3687                 :          0 : }
    3688                 :            : 
    3689                 :          0 : static void bnx2x_pmf_update(struct bnx2x_softc *sc)
    3690                 :            : {
    3691                 :          0 :         int port = SC_PORT(sc);
    3692                 :            :         uint32_t val;
    3693                 :            : 
    3694                 :          0 :         sc->port.pmf = 1;
    3695                 :            : 
    3696                 :            :         /*
    3697                 :            :          * We need the mb() to ensure the ordering between the writing to
    3698                 :            :          * sc->port.pmf here and reading it from the bnx2x_periodic_task().
    3699                 :            :          */
    3700                 :            :         mb();
    3701                 :            : 
    3702                 :            :         /* enable nig attention */
    3703                 :          0 :         val = (0xff0f | (1 << (SC_VN(sc) + 4)));
    3704         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    3705                 :          0 :                 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, val);
    3706                 :          0 :                 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, val);
    3707         [ #  # ]:          0 :         } else if (!CHIP_IS_E1x(sc)) {
    3708                 :            :                 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
    3709                 :            :                 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
    3710                 :            :         }
    3711                 :            : 
    3712                 :          0 :         bnx2x_stats_handle(sc, STATS_EVENT_PMF);
    3713                 :          0 : }
    3714                 :            : 
    3715                 :          0 : static int bnx2x_mc_assert(struct bnx2x_softc *sc)
    3716                 :            : {
    3717                 :            :         char last_idx;
    3718                 :            :         int i, rc = 0;
    3719                 :            :         __rte_unused uint32_t row0, row1, row2, row3;
    3720                 :            : 
    3721                 :            :         /* XSTORM */
    3722                 :          0 :         last_idx =
    3723                 :          0 :             REG_RD8(sc, BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_INDEX_OFFSET);
    3724         [ #  # ]:          0 :         if (last_idx)
    3725                 :          0 :                 PMD_DRV_LOG(ERR, sc, "XSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
    3726                 :            : 
    3727                 :            :         /* print the asserts */
    3728         [ #  # ]:          0 :         for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
    3729                 :            : 
    3730                 :            :                 row0 =
    3731                 :          0 :                     REG_RD(sc,
    3732                 :            :                            BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i));
    3733                 :            :                 row1 =
    3734                 :          0 :                     REG_RD(sc,
    3735                 :            :                            BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
    3736                 :            :                            4);
    3737                 :            :                 row2 =
    3738                 :          0 :                     REG_RD(sc,
    3739                 :            :                            BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
    3740                 :            :                            8);
    3741                 :            :                 row3 =
    3742                 :          0 :                     REG_RD(sc,
    3743                 :            :                            BAR_XSTRORM_INTMEM + XSTORM_ASSERT_LIST_OFFSET(i) +
    3744                 :            :                            12);
    3745                 :            : 
    3746         [ #  # ]:          0 :                 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
    3747                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    3748                 :            :                                     "XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
    3749                 :            :                                     i, row3, row2, row1, row0);
    3750                 :          0 :                         rc++;
    3751                 :            :                 } else {
    3752                 :            :                         break;
    3753                 :            :                 }
    3754                 :            :         }
    3755                 :            : 
    3756                 :            :         /* TSTORM */
    3757                 :          0 :         last_idx =
    3758                 :          0 :             REG_RD8(sc, BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_INDEX_OFFSET);
    3759         [ #  # ]:          0 :         if (last_idx) {
    3760                 :          0 :                 PMD_DRV_LOG(ERR, sc, "TSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
    3761                 :            :         }
    3762                 :            : 
    3763                 :            :         /* print the asserts */
    3764         [ #  # ]:          0 :         for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
    3765                 :            : 
    3766                 :            :                 row0 =
    3767                 :          0 :                     REG_RD(sc,
    3768                 :            :                            BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i));
    3769                 :            :                 row1 =
    3770                 :          0 :                     REG_RD(sc,
    3771                 :            :                            BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
    3772                 :            :                            4);
    3773                 :            :                 row2 =
    3774                 :          0 :                     REG_RD(sc,
    3775                 :            :                            BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
    3776                 :            :                            8);
    3777                 :            :                 row3 =
    3778                 :          0 :                     REG_RD(sc,
    3779                 :            :                            BAR_TSTRORM_INTMEM + TSTORM_ASSERT_LIST_OFFSET(i) +
    3780                 :            :                            12);
    3781                 :            : 
    3782         [ #  # ]:          0 :                 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
    3783                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    3784                 :            :                                     "TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
    3785                 :            :                                     i, row3, row2, row1, row0);
    3786                 :          0 :                         rc++;
    3787                 :            :                 } else {
    3788                 :            :                         break;
    3789                 :            :                 }
    3790                 :            :         }
    3791                 :            : 
    3792                 :            :         /* CSTORM */
    3793                 :          0 :         last_idx =
    3794                 :          0 :             REG_RD8(sc, BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_INDEX_OFFSET);
    3795         [ #  # ]:          0 :         if (last_idx) {
    3796                 :          0 :                 PMD_DRV_LOG(ERR, sc, "CSTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
    3797                 :            :         }
    3798                 :            : 
    3799                 :            :         /* print the asserts */
    3800         [ #  # ]:          0 :         for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
    3801                 :            : 
    3802                 :            :                 row0 =
    3803                 :          0 :                     REG_RD(sc,
    3804                 :            :                            BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i));
    3805                 :            :                 row1 =
    3806                 :          0 :                     REG_RD(sc,
    3807                 :            :                            BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
    3808                 :            :                            4);
    3809                 :            :                 row2 =
    3810                 :          0 :                     REG_RD(sc,
    3811                 :            :                            BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
    3812                 :            :                            8);
    3813                 :            :                 row3 =
    3814                 :          0 :                     REG_RD(sc,
    3815                 :            :                            BAR_CSTRORM_INTMEM + CSTORM_ASSERT_LIST_OFFSET(i) +
    3816                 :            :                            12);
    3817                 :            : 
    3818         [ #  # ]:          0 :                 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
    3819                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    3820                 :            :                                     "CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
    3821                 :            :                                     i, row3, row2, row1, row0);
    3822                 :          0 :                         rc++;
    3823                 :            :                 } else {
    3824                 :            :                         break;
    3825                 :            :                 }
    3826                 :            :         }
    3827                 :            : 
    3828                 :            :         /* USTORM */
    3829                 :          0 :         last_idx =
    3830                 :          0 :             REG_RD8(sc, BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_INDEX_OFFSET);
    3831         [ #  # ]:          0 :         if (last_idx) {
    3832                 :          0 :                 PMD_DRV_LOG(ERR, sc, "USTORM_ASSERT_LIST_INDEX 0x%x", last_idx);
    3833                 :            :         }
    3834                 :            : 
    3835                 :            :         /* print the asserts */
    3836         [ #  # ]:          0 :         for (i = 0; i < STORM_ASSERT_ARRAY_SIZE; i++) {
    3837                 :            : 
    3838                 :            :                 row0 =
    3839                 :          0 :                     REG_RD(sc,
    3840                 :            :                            BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i));
    3841                 :            :                 row1 =
    3842                 :          0 :                     REG_RD(sc,
    3843                 :            :                            BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
    3844                 :            :                            4);
    3845                 :            :                 row2 =
    3846                 :          0 :                     REG_RD(sc,
    3847                 :            :                            BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
    3848                 :            :                            8);
    3849                 :            :                 row3 =
    3850                 :          0 :                     REG_RD(sc,
    3851                 :            :                            BAR_USTRORM_INTMEM + USTORM_ASSERT_LIST_OFFSET(i) +
    3852                 :            :                            12);
    3853                 :            : 
    3854         [ #  # ]:          0 :                 if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
    3855                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    3856                 :            :                                     "USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x",
    3857                 :            :                                     i, row3, row2, row1, row0);
    3858                 :          0 :                         rc++;
    3859                 :            :                 } else {
    3860                 :            :                         break;
    3861                 :            :                 }
    3862                 :            :         }
    3863                 :            : 
    3864                 :          0 :         return rc;
    3865                 :            : }
    3866                 :            : 
    3867                 :          0 : static void bnx2x_attn_int_deasserted3(struct bnx2x_softc *sc, uint32_t attn)
    3868                 :            : {
    3869                 :          0 :         int func = SC_FUNC(sc);
    3870                 :            :         uint32_t val;
    3871                 :            : 
    3872         [ #  # ]:          0 :         if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
    3873                 :            : 
    3874         [ #  # ]:          0 :                 if (attn & BNX2X_PMF_LINK_ASSERT(sc)) {
    3875                 :            : 
    3876                 :          0 :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
    3877                 :          0 :                         bnx2x_read_mf_cfg(sc);
    3878                 :          0 :                         sc->devinfo.mf_info.mf_config[SC_VN(sc)] =
    3879                 :          0 :                             MFCFG_RD(sc,
    3880                 :            :                                      func_mf_config[SC_ABS_FUNC(sc)].config);
    3881                 :            :                         val =
    3882   [ #  #  #  # ]:          0 :                             SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_status);
    3883                 :            : 
    3884         [ #  # ]:          0 :                         if (val & DRV_STATUS_DCC_EVENT_MASK)
    3885                 :          0 :                                 bnx2x_dcc_event(sc,
    3886                 :            :                                               (val &
    3887                 :            :                                                DRV_STATUS_DCC_EVENT_MASK));
    3888                 :            : 
    3889         [ #  # ]:          0 :                         if (val & DRV_STATUS_SET_MF_BW)
    3890                 :            :                                 bnx2x_set_mf_bw(sc);
    3891                 :            : 
    3892         [ #  # ]:          0 :                         if (val & DRV_STATUS_DRV_INFO_REQ)
    3893                 :          0 :                                 bnx2x_handle_drv_info_req(sc);
    3894                 :            : 
    3895   [ #  #  #  # ]:          0 :                         if ((sc->port.pmf == 0) && (val & DRV_STATUS_PMF))
    3896                 :          0 :                                 bnx2x_pmf_update(sc);
    3897                 :            : 
    3898         [ #  # ]:          0 :                         if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
    3899                 :            :                                 bnx2x_handle_eee_event(sc);
    3900                 :            : 
    3901         [ #  # ]:          0 :                         if (sc->link_vars.periodic_flags &
    3902                 :            :                             ELINK_PERIODIC_FLAGS_LINK_EVENT) {
    3903                 :            :                                 /* sync with link */
    3904                 :          0 :                                 bnx2x_acquire_phy_lock(sc);
    3905                 :          0 :                                 sc->link_vars.periodic_flags &=
    3906                 :            :                                     ~ELINK_PERIODIC_FLAGS_LINK_EVENT;
    3907                 :            :                                 bnx2x_release_phy_lock(sc);
    3908   [ #  #  #  # ]:          0 :                                 if (IS_MF(sc)) {
    3909                 :          0 :                                         bnx2x_link_sync_notify(sc);
    3910                 :            :                                 }
    3911                 :          0 :                                 bnx2x_link_report(sc);
    3912                 :            :                         }
    3913                 :            : 
    3914                 :            :                         /*
    3915                 :            :                          * Always call it here: bnx2x_link_report() will
    3916                 :            :                          * prevent the link indication duplication.
    3917                 :            :                          */
    3918                 :          0 :                         bnx2x_link_status_update(sc);
    3919                 :            : 
    3920         [ #  # ]:          0 :                 } else if (attn & BNX2X_MC_ASSERT_BITS) {
    3921                 :            : 
    3922                 :          0 :                         PMD_DRV_LOG(ERR, sc, "MC assert!");
    3923                 :          0 :                         bnx2x_mc_assert(sc);
    3924                 :            :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_10, 0);
    3925                 :            :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_9, 0);
    3926                 :            :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_8, 0);
    3927                 :            :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_7, 0);
    3928                 :          0 :                         rte_panic("MC assert!");
    3929                 :            : 
    3930         [ #  # ]:          0 :                 } else if (attn & BNX2X_MCP_ASSERT) {
    3931                 :            : 
    3932                 :          0 :                         PMD_DRV_LOG(ERR, sc, "MCP assert!");
    3933                 :            :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_11, 0);
    3934                 :            : 
    3935                 :            :                 } else {
    3936                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    3937                 :            :                                     "Unknown HW assert! (attn 0x%08x)", attn);
    3938                 :            :                 }
    3939                 :            :         }
    3940                 :            : 
    3941         [ #  # ]:          0 :         if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
    3942                 :          0 :                 PMD_DRV_LOG(ERR, sc, "LATCHED attention 0x%08x (masked)", attn);
    3943         [ #  # ]:          0 :                 if (attn & BNX2X_GRC_TIMEOUT) {
    3944                 :            :                         val = REG_RD(sc, MISC_REG_GRC_TIMEOUT_ATTN);
    3945                 :          0 :                         PMD_DRV_LOG(ERR, sc, "GRC time-out 0x%08x", val);
    3946                 :            :                 }
    3947         [ #  # ]:          0 :                 if (attn & BNX2X_GRC_RSV) {
    3948                 :            :                         val = REG_RD(sc, MISC_REG_GRC_RSV_ATTN);
    3949                 :          0 :                         PMD_DRV_LOG(ERR, sc, "GRC reserved 0x%08x", val);
    3950                 :            :                 }
    3951                 :            :                 REG_WR(sc, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
    3952                 :            :         }
    3953                 :          0 : }
    3954                 :            : 
    3955                 :          0 : static void bnx2x_attn_int_deasserted2(struct bnx2x_softc *sc, uint32_t attn)
    3956                 :            : {
    3957                 :          0 :         int port = SC_PORT(sc);
    3958                 :            :         int reg_offset;
    3959                 :            :         uint32_t val0, mask0, val1, mask1;
    3960                 :            :         uint32_t val;
    3961                 :            : 
    3962         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
    3963                 :            :                 val = REG_RD(sc, CFC_REG_CFC_INT_STS_CLR);
    3964                 :          0 :                 PMD_DRV_LOG(ERR, sc, "CFC hw attention 0x%08x", val);
    3965                 :            : /* CFC error attention */
    3966         [ #  # ]:          0 :                 if (val & 0x2) {
    3967                 :          0 :                         PMD_DRV_LOG(ERR, sc, "FATAL error from CFC");
    3968                 :            :                 }
    3969                 :            :         }
    3970                 :            : 
    3971         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
    3972                 :            :                 val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_0);
    3973                 :          0 :                 PMD_DRV_LOG(ERR, sc, "PXP hw attention-0 0x%08x", val);
    3974                 :            : /* RQ_USDMDP_FIFO_OVERFLOW */
    3975         [ #  # ]:          0 :                 if (val & 0x18000) {
    3976                 :          0 :                         PMD_DRV_LOG(ERR, sc, "FATAL error from PXP");
    3977                 :            :                 }
    3978                 :            : 
    3979         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
    3980                 :            :                         val = REG_RD(sc, PXP_REG_PXP_INT_STS_CLR_1);
    3981                 :          0 :                         PMD_DRV_LOG(ERR, sc, "PXP hw attention-1 0x%08x", val);
    3982                 :            :                 }
    3983                 :            :         }
    3984                 :            : #define PXP2_EOP_ERROR_BIT  PXP2_PXP2_INT_STS_CLR_0_REG_WR_PGLUE_EOP_ERROR
    3985                 :            : #define AEU_PXP2_HW_INT_BIT AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT
    3986                 :            : 
    3987         [ #  # ]:          0 :         if (attn & AEU_PXP2_HW_INT_BIT) {
    3988                 :            : /*  CQ47854 workaround do not panic on
    3989                 :            :  *  PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
    3990                 :            :  */
    3991         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
    3992                 :            :                         mask0 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_0);
    3993                 :            :                         val1 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_1);
    3994                 :            :                         mask1 = REG_RD(sc, PXP2_REG_PXP2_INT_MASK_1);
    3995                 :            :                         val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_0);
    3996                 :            :                         /*
    3997                 :            :                          * If the only PXP2_EOP_ERROR_BIT is set in
    3998                 :            :                          * STS0 and STS1 - clear it
    3999                 :            :                          *
    4000                 :            :                          * probably we lose additional attentions between
    4001                 :            :                          * STS0 and STS_CLR0, in this case user will not
    4002                 :            :                          * be notified about them
    4003                 :            :                          */
    4004         [ #  # ]:          0 :                         if (val0 & mask0 & PXP2_EOP_ERROR_BIT &&
    4005         [ #  # ]:          0 :                             !(val1 & mask1))
    4006                 :            :                                 val0 = REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
    4007                 :            : 
    4008                 :            :                         /* print the register, since no one can restore it */
    4009                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    4010                 :            :                                     "PXP2_REG_PXP2_INT_STS_CLR_0 0x%08x", val0);
    4011                 :            : 
    4012                 :            :                         /*
    4013                 :            :                          * if PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR
    4014                 :            :                          * then notify
    4015                 :            :                          */
    4016         [ #  # ]:          0 :                         if (val0 & PXP2_EOP_ERROR_BIT) {
    4017                 :          0 :                                 PMD_DRV_LOG(ERR, sc, "PXP2_WR_PGLUE_EOP_ERROR");
    4018                 :            : 
    4019                 :            :                                 /*
    4020                 :            :                                  * if only PXP2_PXP2_INT_STS_0_REG_WR_PGLUE_EOP_ERROR is
    4021                 :            :                                  * set then clear attention from PXP2 block without panic
    4022                 :            :                                  */
    4023         [ #  # ]:          0 :                                 if (((val0 & mask0) == PXP2_EOP_ERROR_BIT) &&
    4024         [ #  # ]:          0 :                                     ((val1 & mask1) == 0))
    4025                 :          0 :                                         attn &= ~AEU_PXP2_HW_INT_BIT;
    4026                 :            :                         }
    4027                 :            :                 }
    4028                 :            :         }
    4029                 :            : 
    4030         [ #  # ]:          0 :         if (attn & HW_INTERRUT_ASSERT_SET_2) {
    4031         [ #  # ]:          0 :                 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
    4032                 :            :                               MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
    4033                 :            : 
    4034                 :          0 :                 val = REG_RD(sc, reg_offset);
    4035                 :          0 :                 val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
    4036                 :            :                 REG_WR(sc, reg_offset, val);
    4037                 :            : 
    4038                 :          0 :                 PMD_DRV_LOG(ERR, sc,
    4039                 :            :                             "FATAL HW block attention set2 0x%x",
    4040                 :            :                             (uint32_t) (attn & HW_INTERRUT_ASSERT_SET_2));
    4041                 :          0 :                 rte_panic("HW block attention set2");
    4042                 :            :         }
    4043                 :          0 : }
    4044                 :            : 
    4045                 :          0 : static void bnx2x_attn_int_deasserted1(struct bnx2x_softc *sc, uint32_t attn)
    4046                 :            : {
    4047                 :          0 :         int port = SC_PORT(sc);
    4048                 :            :         int reg_offset;
    4049                 :            :         uint32_t val;
    4050                 :            : 
    4051         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
    4052                 :            :                 val = REG_RD(sc, DORQ_REG_DORQ_INT_STS_CLR);
    4053                 :          0 :                 PMD_DRV_LOG(ERR, sc, "DB hw attention 0x%08x", val);
    4054                 :            : /* DORQ discard attention */
    4055         [ #  # ]:          0 :                 if (val & 0x2) {
    4056                 :          0 :                         PMD_DRV_LOG(ERR, sc, "FATAL error from DORQ");
    4057                 :            :                 }
    4058                 :            :         }
    4059                 :            : 
    4060         [ #  # ]:          0 :         if (attn & HW_INTERRUT_ASSERT_SET_1) {
    4061         [ #  # ]:          0 :                 reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
    4062                 :            :                               MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
    4063                 :            : 
    4064                 :          0 :                 val = REG_RD(sc, reg_offset);
    4065                 :          0 :                 val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
    4066                 :            :                 REG_WR(sc, reg_offset, val);
    4067                 :            : 
    4068                 :          0 :                 PMD_DRV_LOG(ERR, sc,
    4069                 :            :                             "FATAL HW block attention set1 0x%08x",
    4070                 :            :                             (uint32_t) (attn & HW_INTERRUT_ASSERT_SET_1));
    4071                 :          0 :                 rte_panic("HW block attention set1");
    4072                 :            :         }
    4073                 :          0 : }
    4074                 :            : 
    4075                 :          0 : static void bnx2x_attn_int_deasserted0(struct bnx2x_softc *sc, uint32_t attn)
    4076                 :            : {
    4077                 :          0 :         int port = SC_PORT(sc);
    4078                 :            :         int reg_offset;
    4079                 :            :         uint32_t val;
    4080                 :            : 
    4081         [ #  # ]:          0 :         reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
    4082                 :            :             MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
    4083                 :            : 
    4084         [ #  # ]:          0 :         if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
    4085                 :          0 :                 val = REG_RD(sc, reg_offset);
    4086                 :          0 :                 val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
    4087                 :            :                 REG_WR(sc, reg_offset, val);
    4088                 :            : 
    4089                 :          0 :                 PMD_DRV_LOG(WARNING, sc, "SPIO5 hw attention");
    4090                 :            : 
    4091                 :            : /* Fan failure attention */
    4092                 :          0 :                 elink_hw_reset_phy(&sc->link_params);
    4093                 :          0 :                 bnx2x_fan_failure(sc);
    4094                 :            :         }
    4095                 :            : 
    4096   [ #  #  #  # ]:          0 :         if ((attn & sc->link_vars.aeu_int_mask) && sc->port.pmf) {
    4097                 :          0 :                 bnx2x_acquire_phy_lock(sc);
    4098                 :          0 :                 elink_handle_module_detect_int(&sc->link_params);
    4099                 :            :                 bnx2x_release_phy_lock(sc);
    4100                 :            :         }
    4101                 :            : 
    4102         [ #  # ]:          0 :         if (attn & HW_INTERRUT_ASSERT_SET_0) {
    4103                 :          0 :                 val = REG_RD(sc, reg_offset);
    4104                 :          0 :                 val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
    4105                 :            :                 REG_WR(sc, reg_offset, val);
    4106                 :            : 
    4107                 :          0 :                 rte_panic("FATAL HW block attention set0 0x%lx",
    4108                 :            :                           (attn & (unsigned long)HW_INTERRUT_ASSERT_SET_0));
    4109                 :            :         }
    4110                 :          0 : }
    4111                 :            : 
    4112                 :          0 : static void bnx2x_attn_int_deasserted(struct bnx2x_softc *sc, uint32_t deasserted)
    4113                 :            : {
    4114                 :            :         struct attn_route attn;
    4115                 :            :         struct attn_route *group_mask;
    4116                 :          0 :         int port = SC_PORT(sc);
    4117                 :            :         int index;
    4118                 :            :         uint32_t reg_addr;
    4119                 :            :         uint32_t val;
    4120                 :            :         uint32_t aeu_mask;
    4121                 :          0 :         uint8_t global = FALSE;
    4122                 :            : 
    4123                 :            :         /*
    4124                 :            :          * Need to take HW lock because MCP or other port might also
    4125                 :            :          * try to handle this event.
    4126                 :            :          */
    4127                 :          0 :         bnx2x_acquire_alr(sc);
    4128                 :            : 
    4129         [ #  # ]:          0 :         if (bnx2x_chk_parity_attn(sc, &global, TRUE)) {
    4130                 :          0 :                 sc->recovery_state = BNX2X_RECOVERY_INIT;
    4131                 :            : 
    4132                 :            : /* disable HW interrupts */
    4133                 :          0 :                 bnx2x_int_disable(sc);
    4134                 :            :                 bnx2x_release_alr(sc);
    4135                 :          0 :                 return;
    4136                 :            :         }
    4137                 :            : 
    4138                 :          0 :         attn.sig[0] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port * 4);
    4139                 :          0 :         attn.sig[1] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port * 4);
    4140                 :          0 :         attn.sig[2] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port * 4);
    4141                 :          0 :         attn.sig[3] = REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port * 4);
    4142         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    4143                 :            :                 attn.sig[4] =
    4144                 :          0 :                     REG_RD(sc, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port * 4);
    4145                 :            :         } else {
    4146                 :            :                 attn.sig[4] = 0;
    4147                 :            :         }
    4148                 :            : 
    4149         [ #  # ]:          0 :         for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
    4150         [ #  # ]:          0 :                 if (deasserted & (1 << index)) {
    4151                 :            :                         group_mask = &sc->attn_group[index];
    4152                 :            : 
    4153                 :          0 :                         bnx2x_attn_int_deasserted4(sc,
    4154                 :            :                                                  attn.
    4155                 :          0 :                                                  sig[4] & group_mask->sig[4]);
    4156                 :          0 :                         bnx2x_attn_int_deasserted3(sc,
    4157                 :            :                                                  attn.
    4158                 :          0 :                                                  sig[3] & group_mask->sig[3]);
    4159                 :          0 :                         bnx2x_attn_int_deasserted1(sc,
    4160                 :            :                                                  attn.
    4161                 :          0 :                                                  sig[1] & group_mask->sig[1]);
    4162                 :          0 :                         bnx2x_attn_int_deasserted2(sc,
    4163                 :            :                                                  attn.
    4164                 :          0 :                                                  sig[2] & group_mask->sig[2]);
    4165                 :          0 :                         bnx2x_attn_int_deasserted0(sc,
    4166                 :            :                                                  attn.
    4167                 :          0 :                                                  sig[0] & group_mask->sig[0]);
    4168                 :            :                 }
    4169                 :            :         }
    4170                 :            : 
    4171                 :            :         bnx2x_release_alr(sc);
    4172                 :            : 
    4173         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    4174                 :          0 :                 reg_addr = (HC_REG_COMMAND_REG + port * 32 +
    4175                 :            :                             COMMAND_REG_ATTN_BITS_CLR);
    4176                 :            :         } else {
    4177                 :            :                 reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER * 8);
    4178                 :            :         }
    4179                 :            : 
    4180                 :          0 :         val = ~deasserted;
    4181         [ #  # ]:          0 :         PMD_DRV_LOG(DEBUG, sc,
    4182                 :            :                     "about to mask 0x%08x at %s addr 0x%08x", val,
    4183                 :            :                     (sc->devinfo.int_block == INT_BLOCK_HC) ? "HC" : "IGU",
    4184                 :            :                     reg_addr);
    4185                 :          0 :         REG_WR(sc, reg_addr, val);
    4186                 :            : 
    4187         [ #  # ]:          0 :         if (~sc->attn_state & deasserted) {
    4188                 :          0 :                 PMD_DRV_LOG(ERR, sc, "IGU error");
    4189                 :            :         }
    4190                 :            : 
    4191         [ #  # ]:          0 :         reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
    4192                 :            :             MISC_REG_AEU_MASK_ATTN_FUNC_0;
    4193                 :            : 
    4194                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
    4195                 :            : 
    4196                 :          0 :         aeu_mask = REG_RD(sc, reg_addr);
    4197                 :            : 
    4198                 :          0 :         aeu_mask |= (deasserted & 0x3ff);
    4199                 :            : 
    4200                 :            :         REG_WR(sc, reg_addr, aeu_mask);
    4201                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
    4202                 :            : 
    4203                 :          0 :         sc->attn_state &= ~deasserted;
    4204                 :            : }
    4205                 :            : 
    4206                 :          0 : static void bnx2x_attn_int(struct bnx2x_softc *sc)
    4207                 :            : {
    4208                 :            :         /* read local copy of bits */
    4209                 :          0 :         uint32_t attn_bits = le32toh(sc->def_sb->atten_status_block.attn_bits);
    4210                 :            :         uint32_t attn_ack =
    4211                 :          0 :             le32toh(sc->def_sb->atten_status_block.attn_bits_ack);
    4212                 :          0 :         uint32_t attn_state = sc->attn_state;
    4213                 :            : 
    4214                 :            :         /* look for changed bits */
    4215                 :          0 :         uint32_t asserted = attn_bits & ~attn_ack & ~attn_state;
    4216                 :          0 :         uint32_t deasserted = ~attn_bits & attn_ack & attn_state;
    4217                 :            : 
    4218                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
    4219                 :            :                     "attn_bits 0x%08x attn_ack 0x%08x asserted 0x%08x deasserted 0x%08x",
    4220                 :            :                     attn_bits, attn_ack, asserted, deasserted);
    4221                 :            : 
    4222         [ #  # ]:          0 :         if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) {
    4223                 :          0 :                 PMD_DRV_LOG(ERR, sc, "BAD attention state");
    4224                 :            :         }
    4225                 :            : 
    4226                 :            :         /* handle bits that were raised */
    4227         [ #  # ]:          0 :         if (asserted) {
    4228                 :          0 :                 bnx2x_attn_int_asserted(sc, asserted);
    4229                 :            :         }
    4230                 :            : 
    4231         [ #  # ]:          0 :         if (deasserted) {
    4232                 :          0 :                 bnx2x_attn_int_deasserted(sc, deasserted);
    4233                 :            :         }
    4234                 :          0 : }
    4235                 :            : 
    4236                 :            : static uint16_t bnx2x_update_dsb_idx(struct bnx2x_softc *sc)
    4237                 :            : {
    4238                 :          0 :         struct host_sp_status_block *def_sb = sc->def_sb;
    4239                 :            :         uint16_t rc = 0;
    4240                 :            : 
    4241   [ #  #  #  # ]:          0 :         if (!def_sb)
    4242                 :            :                 return 0;
    4243                 :            : 
    4244                 :            :         mb();                   /* status block is written to by the chip */
    4245                 :            : 
    4246   [ #  #  #  # ]:          0 :         if (sc->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
    4247                 :          0 :                 sc->def_att_idx = def_sb->atten_status_block.attn_bits_index;
    4248                 :            :                 rc |= BNX2X_DEF_SB_ATT_IDX;
    4249                 :            :         }
    4250                 :            : 
    4251   [ #  #  #  # ]:          0 :         if (sc->def_idx != def_sb->sp_sb.running_index) {
    4252                 :          0 :                 sc->def_idx = def_sb->sp_sb.running_index;
    4253                 :          0 :                 rc |= BNX2X_DEF_SB_IDX;
    4254                 :            :         }
    4255                 :            : 
    4256                 :            :         mb();
    4257                 :            : 
    4258                 :          0 :         return rc;
    4259                 :            : }
    4260                 :            : 
    4261                 :            : static struct ecore_queue_sp_obj *bnx2x_cid_to_q_obj(struct bnx2x_softc *sc,
    4262                 :            :                                                           uint32_t cid)
    4263                 :            : {
    4264                 :          0 :         return &sc->sp_objs[CID_TO_FP(cid, sc)].q_obj;
    4265                 :            : }
    4266                 :            : 
    4267                 :          0 : static void bnx2x_handle_mcast_eqe(struct bnx2x_softc *sc)
    4268                 :            : {
    4269                 :            :         struct ecore_mcast_ramrod_params rparam;
    4270                 :            :         int rc;
    4271                 :            : 
    4272                 :            :         memset(&rparam, 0, sizeof(rparam));
    4273                 :            : 
    4274                 :          0 :         rparam.mcast_obj = &sc->mcast_obj;
    4275                 :            : 
    4276                 :            :         /* clear pending state for the last command */
    4277                 :          0 :         sc->mcast_obj.raw.clear_pending(&sc->mcast_obj.raw);
    4278                 :            : 
    4279                 :            :         /* if there are pending mcast commands - send them */
    4280         [ #  # ]:          0 :         if (sc->mcast_obj.check_pending(&sc->mcast_obj)) {
    4281                 :          0 :                 rc = ecore_config_mcast(sc, &rparam, ECORE_MCAST_CMD_CONT);
    4282         [ #  # ]:          0 :                 if (rc < 0) {
    4283                 :          0 :                         PMD_DRV_LOG(INFO, sc,
    4284                 :            :                                     "Failed to send pending mcast commands (%d)",
    4285                 :            :                                     rc);
    4286                 :            :                 }
    4287                 :            :         }
    4288                 :          0 : }
    4289                 :            : 
    4290                 :            : static void
    4291                 :          0 : bnx2x_handle_classification_eqe(struct bnx2x_softc *sc, union event_ring_elem *elem)
    4292                 :            : {
    4293                 :          0 :         uint32_t ramrod_flags = 0;
    4294                 :            :         int rc = 0;
    4295      [ #  #  # ]:          0 :         uint32_t cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
    4296                 :            :         struct ecore_vlan_mac_obj *vlan_mac_obj;
    4297                 :            : 
    4298                 :            :         /* always push next commands out, don't wait here */
    4299                 :            :         rte_bit_relaxed_set32(RAMROD_CONT, &ramrod_flags);
    4300                 :            : 
    4301      [ #  #  # ]:          0 :         switch (le32toh(elem->message.data.eth_event.echo) >> BNX2X_SWCID_SHIFT) {
    4302                 :          0 :         case ECORE_FILTER_MAC_PENDING:
    4303                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Got SETUP_MAC completions");
    4304                 :          0 :                 vlan_mac_obj = &sc->sp_objs[cid].mac_obj;
    4305                 :            :                 break;
    4306                 :            : 
    4307                 :          0 :         case ECORE_FILTER_MCAST_PENDING:
    4308                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Got SETUP_MCAST completions");
    4309                 :          0 :                 bnx2x_handle_mcast_eqe(sc);
    4310                 :          0 :                 return;
    4311                 :            : 
    4312                 :          0 :         default:
    4313                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Unsupported classification command: %d",
    4314                 :            :                             elem->message.data.eth_event.echo);
    4315                 :          0 :                 return;
    4316                 :            :         }
    4317                 :            : 
    4318                 :          0 :         rc = vlan_mac_obj->complete(sc, vlan_mac_obj, elem, &ramrod_flags);
    4319                 :            : 
    4320         [ #  # ]:          0 :         if (rc < 0) {
    4321                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    4322                 :            :                             "Failed to schedule new commands (%d)", rc);
    4323         [ #  # ]:          0 :         } else if (rc > 0) {
    4324                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Scheduled next pending commands...");
    4325                 :            :         }
    4326                 :            : }
    4327                 :            : 
    4328                 :            : static void bnx2x_handle_rx_mode_eqe(struct bnx2x_softc *sc)
    4329                 :            : {
    4330                 :            :         rte_bit_relaxed_clear32(ECORE_FILTER_RX_MODE_PENDING, &sc->sp_state);
    4331                 :            : 
    4332                 :            :         /* send rx_mode command again if was requested */
    4333         [ #  # ]:          0 :         if (rte_bit_relaxed_test_and_clear32(ECORE_FILTER_RX_MODE_SCHED,
    4334                 :            :                                                 &sc->sp_state))
    4335                 :          0 :                 bnx2x_set_storm_rx_mode(sc);
    4336                 :            : }
    4337                 :            : 
    4338                 :            : static void bnx2x_update_eq_prod(struct bnx2x_softc *sc, uint16_t prod)
    4339                 :            : {
    4340                 :          0 :         storm_memset_eq_prod(sc, prod, SC_FUNC(sc));
    4341                 :            :         wmb();                  /* keep prod updates ordered */
    4342                 :            : }
    4343                 :            : 
    4344                 :          0 : static void bnx2x_eq_int(struct bnx2x_softc *sc)
    4345                 :            : {
    4346                 :            :         uint16_t hw_cons, sw_cons, sw_prod;
    4347                 :            :         union event_ring_elem *elem;
    4348                 :            :         uint8_t echo;
    4349                 :            :         uint32_t cid;
    4350                 :            :         uint8_t opcode;
    4351                 :            :         int spqe_cnt = 0;
    4352                 :            :         struct ecore_queue_sp_obj *q_obj;
    4353                 :          0 :         struct ecore_func_sp_obj *f_obj = &sc->func_obj;
    4354                 :          0 :         struct ecore_raw_obj *rss_raw = &sc->rss_conf_obj.raw;
    4355                 :            : 
    4356                 :          0 :         hw_cons = le16toh(*sc->eq_cons_sb);
    4357                 :            : 
    4358                 :            :         /*
    4359                 :            :          * The hw_cons range is 1-255, 257 - the sw_cons range is 0-254, 256.
    4360                 :            :          * when we get to the next-page we need to adjust so the loop
    4361                 :            :          * condition below will be met. The next element is the size of a
    4362                 :            :          * regular element and hence incrementing by 1
    4363                 :            :          */
    4364         [ #  # ]:          0 :         if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE) {
    4365                 :          0 :                 hw_cons++;
    4366                 :            :         }
    4367                 :            : 
    4368                 :            :         /*
    4369                 :            :          * This function may never run in parallel with itself for a
    4370                 :            :          * specific sc and no need for a read memory barrier here.
    4371                 :            :          */
    4372                 :          0 :         sw_cons = sc->eq_cons;
    4373                 :          0 :         sw_prod = sc->eq_prod;
    4374                 :            : 
    4375                 :          0 :         for (;
    4376         [ #  # ]:          0 :              sw_cons != hw_cons;
    4377         [ #  # ]:          0 :              sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
    4378                 :            : 
    4379                 :          0 :                 elem = &sc->eq[EQ_DESC(sw_cons)];
    4380                 :            : 
    4381                 :            : /* elem CID originates from FW, actually LE */
    4382                 :          0 :                 cid = SW_CID(elem->message.data.cfc_del_event.cid);
    4383                 :          0 :                 opcode = elem->message.opcode;
    4384                 :            : 
    4385                 :            : /* handle eq element */
    4386   [ #  #  #  #  :          0 :                 switch (opcode) {
             #  #  #  #  
                      # ]
    4387                 :          0 :                 case EVENT_RING_OPCODE_STAT_QUERY:
    4388                 :            :                         PMD_DEBUG_PERIODIC_LOG(DEBUG, sc, "got statistics completion event %d",
    4389                 :            :                                     sc->stats_comp++);
    4390                 :            :                         /* nothing to do with stats comp */
    4391                 :          0 :                         goto next_spqe;
    4392                 :            : 
    4393                 :          0 :                 case EVENT_RING_OPCODE_CFC_DEL:
    4394                 :            :                         /* handle according to cid range */
    4395                 :            :                         /* we may want to verify here that the sc state is HALTING */
    4396                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got delete ramrod for MULTI[%d]",
    4397                 :            :                                     cid);
    4398                 :            :                         q_obj = bnx2x_cid_to_q_obj(sc, cid);
    4399         [ #  # ]:          0 :                         if (q_obj->complete_cmd(sc, q_obj, ECORE_Q_CMD_CFC_DEL)) {
    4400                 :            :                                 break;
    4401                 :            :                         }
    4402                 :          0 :                         goto next_spqe;
    4403                 :            : 
    4404                 :          0 :                 case EVENT_RING_OPCODE_STOP_TRAFFIC:
    4405                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got STOP TRAFFIC");
    4406         [ #  # ]:          0 :                         if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_TX_STOP)) {
    4407                 :            :                                 break;
    4408                 :            :                         }
    4409                 :          0 :                         goto next_spqe;
    4410                 :            : 
    4411                 :          0 :                 case EVENT_RING_OPCODE_START_TRAFFIC:
    4412                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got START TRAFFIC");
    4413         [ #  # ]:          0 :                         if (f_obj->complete_cmd
    4414                 :            :                             (sc, f_obj, ECORE_F_CMD_TX_START)) {
    4415                 :            :                                 break;
    4416                 :            :                         }
    4417                 :          0 :                         goto next_spqe;
    4418                 :            : 
    4419                 :          0 :                 case EVENT_RING_OPCODE_FUNCTION_UPDATE:
    4420                 :          0 :                         echo = elem->message.data.function_update_event.echo;
    4421         [ #  # ]:          0 :                         if (echo == SWITCH_UPDATE) {
    4422                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc,
    4423                 :            :                                             "got FUNC_SWITCH_UPDATE ramrod");
    4424         [ #  # ]:          0 :                                 if (f_obj->complete_cmd(sc, f_obj,
    4425                 :            :                                                         ECORE_F_CMD_SWITCH_UPDATE))
    4426                 :            :                                 {
    4427                 :            :                                         break;
    4428                 :            :                                 }
    4429                 :            :                         } else {
    4430                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc,
    4431                 :            :                                             "AFEX: ramrod completed FUNCTION_UPDATE");
    4432                 :          0 :                                 f_obj->complete_cmd(sc, f_obj,
    4433                 :            :                                                     ECORE_F_CMD_AFEX_UPDATE);
    4434                 :            :                         }
    4435                 :          0 :                         goto next_spqe;
    4436                 :            : 
    4437                 :          0 :                 case EVENT_RING_OPCODE_FORWARD_SETUP:
    4438                 :          0 :                         q_obj = &bnx2x_fwd_sp_obj(sc, q_obj);
    4439         [ #  # ]:          0 :                         if (q_obj->complete_cmd(sc, q_obj,
    4440                 :            :                                                 ECORE_Q_CMD_SETUP_TX_ONLY)) {
    4441                 :            :                                 break;
    4442                 :            :                         }
    4443                 :          0 :                         goto next_spqe;
    4444                 :            : 
    4445                 :          0 :                 case EVENT_RING_OPCODE_FUNCTION_START:
    4446                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got FUNC_START ramrod");
    4447         [ #  # ]:          0 :                         if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_START)) {
    4448                 :            :                                 break;
    4449                 :            :                         }
    4450                 :          0 :                         goto next_spqe;
    4451                 :            : 
    4452                 :          0 :                 case EVENT_RING_OPCODE_FUNCTION_STOP:
    4453                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got FUNC_STOP ramrod");
    4454         [ #  # ]:          0 :                         if (f_obj->complete_cmd(sc, f_obj, ECORE_F_CMD_STOP)) {
    4455                 :            :                                 break;
    4456                 :            :                         }
    4457                 :          0 :                         goto next_spqe;
    4458                 :            :                 }
    4459                 :            : 
    4460   [ #  #  #  #  :          0 :                 switch (opcode | sc->state) {
                      # ]
    4461                 :          0 :                 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BNX2X_STATE_OPEN):
    4462                 :            :                 case (EVENT_RING_OPCODE_RSS_UPDATE_RULES | BNX2X_STATE_OPENING_WAITING_PORT):
    4463                 :          0 :                         cid =
    4464                 :          0 :                             elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
    4465                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "got RSS_UPDATE ramrod. CID %d",
    4466                 :            :                                     cid);
    4467                 :          0 :                         rss_raw->clear_pending(rss_raw);
    4468                 :          0 :                         break;
    4469                 :            : 
    4470                 :          0 :                 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
    4471                 :            :                 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
    4472                 :            :                 case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_CLOSING_WAITING_HALT):
    4473                 :            :                 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_OPEN):
    4474                 :            :                 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_DIAG):
    4475                 :            :                 case (EVENT_RING_OPCODE_CLASSIFICATION_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
    4476                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    4477                 :            :                                     "got (un)set mac ramrod");
    4478                 :          0 :                         bnx2x_handle_classification_eqe(sc, elem);
    4479                 :          0 :                         break;
    4480                 :            : 
    4481                 :          0 :                 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_OPEN):
    4482                 :            :                 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_DIAG):
    4483                 :            :                 case (EVENT_RING_OPCODE_MULTICAST_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
    4484                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    4485                 :            :                                     "got mcast ramrod");
    4486                 :          0 :                         bnx2x_handle_mcast_eqe(sc);
    4487                 :          0 :                         break;
    4488                 :            : 
    4489                 :          0 :                 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_OPEN):
    4490                 :            :                 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_DIAG):
    4491                 :            :                 case (EVENT_RING_OPCODE_FILTERS_RULES | BNX2X_STATE_CLOSING_WAITING_HALT):
    4492                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    4493                 :            :                                     "got rx_mode ramrod");
    4494                 :            :                         bnx2x_handle_rx_mode_eqe(sc);
    4495                 :            :                         break;
    4496                 :            : 
    4497                 :          0 :                 default:
    4498                 :            :                         /* unknown event log error and continue */
    4499                 :          0 :                         PMD_DRV_LOG(INFO, sc, "Unknown EQ event %d, sc->state 0x%x",
    4500                 :            :                                     elem->message.opcode, sc->state);
    4501                 :            :                 }
    4502                 :            : 
    4503                 :          0 : next_spqe:
    4504         [ #  # ]:          0 :                 spqe_cnt++;
    4505                 :            :         }                       /* for */
    4506                 :            : 
    4507                 :            :         mb();
    4508                 :          0 :         atomic_add_acq_long(&sc->eq_spq_left, spqe_cnt);
    4509                 :            : 
    4510                 :          0 :         sc->eq_cons = sw_cons;
    4511                 :          0 :         sc->eq_prod = sw_prod;
    4512                 :            : 
    4513                 :            :         /* make sure that above mem writes were issued towards the memory */
    4514                 :            :         wmb();
    4515                 :            : 
    4516                 :            :         /* update producer */
    4517                 :          0 :         bnx2x_update_eq_prod(sc, sc->eq_prod);
    4518                 :          0 : }
    4519                 :            : 
    4520                 :          0 : static int bnx2x_handle_sp_tq(struct bnx2x_softc *sc)
    4521                 :            : {
    4522                 :            :         uint16_t status;
    4523                 :            :         int rc = 0;
    4524                 :            : 
    4525                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "---> SP TASK <---");
    4526                 :            : 
    4527                 :            :         /* what work needs to be performed? */
    4528                 :            :         status = bnx2x_update_dsb_idx(sc);
    4529                 :            : 
    4530                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "dsb status 0x%04x", status);
    4531                 :            : 
    4532                 :            :         /* HW attentions */
    4533         [ #  # ]:          0 :         if (status & BNX2X_DEF_SB_ATT_IDX) {
    4534                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "---> ATTN INTR <---");
    4535                 :          0 :                 bnx2x_attn_int(sc);
    4536                 :          0 :                 status &= ~BNX2X_DEF_SB_ATT_IDX;
    4537                 :            :                 rc = 1;
    4538                 :            :         }
    4539                 :            : 
    4540                 :            :         /* SP events: STAT_QUERY and others */
    4541         [ #  # ]:          0 :         if (status & BNX2X_DEF_SB_IDX) {
    4542                 :            : /* handle EQ completions */
    4543                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "---> EQ INTR <---");
    4544                 :          0 :                 bnx2x_eq_int(sc);
    4545                 :          0 :                 bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
    4546                 :          0 :                            le16toh(sc->def_idx), IGU_INT_NOP, 1);
    4547                 :          0 :                 status &= ~BNX2X_DEF_SB_IDX;
    4548                 :            :         }
    4549                 :            : 
    4550                 :            :         /* if status is non zero then something went wrong */
    4551         [ #  # ]:          0 :         if (unlikely(status)) {
    4552                 :          0 :                 PMD_DRV_LOG(INFO, sc,
    4553                 :            :                             "Got an unknown SP interrupt! (0x%04x)", status);
    4554                 :            :         }
    4555                 :            : 
    4556                 :            :         /* ack status block only if something was actually handled */
    4557                 :          0 :         bnx2x_ack_sb(sc, sc->igu_dsb_id, ATTENTION_ID,
    4558                 :          0 :                    le16toh(sc->def_att_idx), IGU_INT_ENABLE, 1);
    4559                 :            : 
    4560                 :          0 :         return rc;
    4561                 :            : }
    4562                 :            : 
    4563                 :          0 : static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)
    4564                 :            : {
    4565                 :          0 :         struct bnx2x_softc *sc = fp->sc;
    4566                 :            :         uint8_t more_rx = FALSE;
    4567                 :            : 
    4568                 :            :         /* Make sure FP is initialized */
    4569         [ #  # ]:          0 :         if (!fp->sb_running_index)
    4570                 :            :                 return;
    4571                 :            : 
    4572                 :            :         PMD_DEBUG_PERIODIC_LOG(DEBUG, sc,
    4573                 :            :                                "---> FP TASK QUEUE (%d) <--", fp->index);
    4574                 :            : 
    4575                 :            :         /* update the fastpath index */
    4576                 :            :         bnx2x_update_fp_sb_idx(fp);
    4577                 :            : 
    4578         [ #  # ]:          0 :         if (rte_atomic32_read(&sc->scan_fp) == 1) {
    4579         [ #  # ]:          0 :                 if (bnx2x_has_rx_work(fp)) {
    4580                 :          0 :                         more_rx = bnx2x_rxeof(sc, fp);
    4581                 :            :                 }
    4582                 :            : 
    4583         [ #  # ]:          0 :                 if (more_rx) {
    4584                 :            :                         /* still more work to do */
    4585                 :            :                         bnx2x_handle_fp_tq(fp);
    4586                 :            :                         return;
    4587                 :            :                 }
    4588                 :            :                 /* We have completed slow path completion, clear the flag */
    4589                 :            :                 rte_atomic32_set(&sc->scan_fp, 0);
    4590                 :            :         }
    4591                 :            : 
    4592                 :          0 :         bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
    4593                 :          0 :                    le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
    4594                 :            : }
    4595                 :            : 
    4596                 :            : /*
    4597                 :            :  * Legacy interrupt entry point.
    4598                 :            :  *
    4599                 :            :  * Verifies that the controller generated the interrupt and
    4600                 :            :  * then calls a separate routine to handle the various
    4601                 :            :  * interrupt causes: link, RX, and TX.
    4602                 :            :  */
    4603                 :          0 : int bnx2x_intr_legacy(struct bnx2x_softc *sc)
    4604                 :            : {
    4605                 :            :         struct bnx2x_fastpath *fp;
    4606                 :            :         uint32_t status, mask;
    4607                 :            :         int i, rc = 0;
    4608                 :            : 
    4609                 :            :         /*
    4610                 :            :          * 0 for ustorm, 1 for cstorm
    4611                 :            :          * the bits returned from ack_int() are 0-15
    4612                 :            :          * bit 0 = attention status block
    4613                 :            :          * bit 1 = fast path status block
    4614                 :            :          * a mask of 0x2 or more = tx/rx event
    4615                 :            :          * a mask of 1 = slow path event
    4616                 :            :          */
    4617                 :            : 
    4618                 :            :         status = bnx2x_ack_int(sc);
    4619                 :            : 
    4620                 :            :         /* the interrupt is not for us */
    4621         [ #  # ]:          0 :         if (unlikely(status == 0)) {
    4622                 :            :                 return 0;
    4623                 :            :         }
    4624                 :            : 
    4625                 :            :         PMD_DEBUG_PERIODIC_LOG(DEBUG, sc, "Interrupt status 0x%04x", status);
    4626                 :            :         //bnx2x_dump_status_block(sc);
    4627                 :            : 
    4628         [ #  # ]:          0 :         FOR_EACH_ETH_QUEUE(sc, i) {
    4629                 :          0 :                 fp = &sc->fp[i];
    4630                 :          0 :                 mask = (0x2 << (fp->index + CNIC_SUPPORT(sc)));
    4631         [ #  # ]:          0 :                 if (status & mask) {
    4632                 :            :                 /* acknowledge and disable further fastpath interrupts */
    4633                 :          0 :                         bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
    4634                 :            :                                      0, IGU_INT_DISABLE, 0);
    4635                 :          0 :                         bnx2x_handle_fp_tq(fp);
    4636                 :          0 :                         status &= ~mask;
    4637                 :            :                 }
    4638                 :            :         }
    4639                 :            : 
    4640         [ #  # ]:          0 :         if (unlikely(status & 0x1)) {
    4641                 :            :                 /* acknowledge and disable further slowpath interrupts */
    4642                 :          0 :                 bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID,
    4643                 :            :                              0, IGU_INT_DISABLE, 0);
    4644                 :          0 :                 rc = bnx2x_handle_sp_tq(sc);
    4645                 :          0 :                 status &= ~0x1;
    4646                 :            :         }
    4647                 :            : 
    4648         [ #  # ]:          0 :         if (unlikely(status)) {
    4649                 :          0 :                 PMD_DRV_LOG(WARNING, sc,
    4650                 :            :                             "Unexpected fastpath status (0x%08x)!", status);
    4651                 :            :         }
    4652                 :            : 
    4653                 :            :         return rc;
    4654                 :            : }
    4655                 :            : 
    4656                 :            : static int bnx2x_init_hw_common_chip(struct bnx2x_softc *sc);
    4657                 :            : static int bnx2x_init_hw_common(struct bnx2x_softc *sc);
    4658                 :            : static int bnx2x_init_hw_port(struct bnx2x_softc *sc);
    4659                 :            : static int bnx2x_init_hw_func(struct bnx2x_softc *sc);
    4660                 :            : static void bnx2x_reset_common(struct bnx2x_softc *sc);
    4661                 :            : static void bnx2x_reset_port(struct bnx2x_softc *sc);
    4662                 :            : static void bnx2x_reset_func(struct bnx2x_softc *sc);
    4663                 :            : static int bnx2x_init_firmware(struct bnx2x_softc *sc);
    4664                 :            : static void bnx2x_release_firmware(struct bnx2x_softc *sc);
    4665                 :            : 
    4666                 :            : static struct
    4667                 :            : ecore_func_sp_drv_ops bnx2x_func_sp_drv = {
    4668                 :            :         .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
    4669                 :            :         .init_hw_cmn = bnx2x_init_hw_common,
    4670                 :            :         .init_hw_port = bnx2x_init_hw_port,
    4671                 :            :         .init_hw_func = bnx2x_init_hw_func,
    4672                 :            : 
    4673                 :            :         .reset_hw_cmn = bnx2x_reset_common,
    4674                 :            :         .reset_hw_port = bnx2x_reset_port,
    4675                 :            :         .reset_hw_func = bnx2x_reset_func,
    4676                 :            : 
    4677                 :            :         .init_fw = bnx2x_init_firmware,
    4678                 :            :         .release_fw = bnx2x_release_firmware,
    4679                 :            : };
    4680                 :            : 
    4681                 :          0 : static void bnx2x_init_func_obj(struct bnx2x_softc *sc)
    4682                 :            : {
    4683                 :          0 :         sc->dmae_ready = 0;
    4684                 :            : 
    4685                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    4686                 :            : 
    4687                 :          0 :         ecore_init_func_obj(sc,
    4688                 :            :                             &sc->func_obj,
    4689                 :          0 :                             BNX2X_SP(sc, func_rdata),
    4690                 :            :                             (rte_iova_t)BNX2X_SP_MAPPING(sc, func_rdata),
    4691                 :          0 :                             BNX2X_SP(sc, func_afex_rdata),
    4692                 :          0 :                             (rte_iova_t)BNX2X_SP_MAPPING(sc, func_afex_rdata),
    4693                 :            :                             &bnx2x_func_sp_drv);
    4694                 :          0 : }
    4695                 :            : 
    4696                 :          0 : static int bnx2x_init_hw(struct bnx2x_softc *sc, uint32_t load_code)
    4697                 :            : {
    4698                 :          0 :         struct ecore_func_state_params func_params = { NULL };
    4699                 :            :         int rc;
    4700                 :            : 
    4701                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    4702                 :            : 
    4703                 :            :         /* prepare the parameters for function state transitions */
    4704                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
    4705                 :            : 
    4706                 :          0 :         func_params.f_obj = &sc->func_obj;
    4707                 :          0 :         func_params.cmd = ECORE_F_CMD_HW_INIT;
    4708                 :            : 
    4709                 :          0 :         func_params.params.hw_init.load_phase = load_code;
    4710                 :            : 
    4711                 :            :         /*
    4712                 :            :          * Via a plethora of function pointers, we will eventually reach
    4713                 :            :          * bnx2x_init_hw_common(), bnx2x_init_hw_port(), or bnx2x_init_hw_func().
    4714                 :            :          */
    4715                 :          0 :         rc = ecore_func_state_change(sc, &func_params);
    4716                 :            : 
    4717                 :          0 :         return rc;
    4718                 :            : }
    4719                 :            : 
    4720                 :            : static void
    4721                 :          0 : bnx2x_fill(struct bnx2x_softc *sc, uint32_t addr, int fill, uint32_t len)
    4722                 :            : {
    4723                 :            :         uint32_t i;
    4724                 :            : 
    4725   [ #  #  #  # ]:          0 :         if (!(len % 4) && !(addr % 4)) {
    4726         [ #  # ]:          0 :                 for (i = 0; i < len; i += 4) {
    4727                 :          0 :                         REG_WR(sc, (addr + i), fill);
    4728                 :            :                 }
    4729                 :            :         } else {
    4730         [ #  # ]:          0 :                 for (i = 0; i < len; i++) {
    4731                 :          0 :                         REG_WR8(sc, (addr + i), fill);
    4732                 :            :                 }
    4733                 :            :         }
    4734                 :          0 : }
    4735                 :            : 
    4736                 :            : /* writes FP SP data to FW - data_size in dwords */
    4737                 :            : static void
    4738                 :            : bnx2x_wr_fp_sb_data(struct bnx2x_softc *sc, int fw_sb_id, uint32_t * sb_data_p,
    4739                 :            :                   uint32_t data_size)
    4740                 :            : {
    4741                 :            :         uint32_t index;
    4742                 :            : 
    4743   [ #  #  #  # ]:          0 :         for (index = 0; index < data_size; index++) {
    4744                 :          0 :                 REG_WR(sc,
    4745                 :            :                        (BAR_CSTRORM_INTMEM +
    4746                 :            :                         CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
    4747                 :            :                         (sizeof(uint32_t) * index)), *(sb_data_p + index));
    4748                 :            :         }
    4749                 :            : }
    4750                 :            : 
    4751                 :          0 : static void bnx2x_zero_fp_sb(struct bnx2x_softc *sc, int fw_sb_id)
    4752                 :            : {
    4753                 :            :         struct hc_status_block_data_e2 sb_data_e2;
    4754                 :            :         struct hc_status_block_data_e1x sb_data_e1x;
    4755                 :            :         uint32_t *sb_data_p;
    4756                 :            :         uint32_t data_size = 0;
    4757                 :            : 
    4758         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    4759                 :            :                 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
    4760                 :            :                 sb_data_e2.common.state = SB_DISABLED;
    4761                 :            :                 sb_data_e2.common.p_func.vf_valid = FALSE;
    4762                 :            :                 sb_data_p = (uint32_t *) & sb_data_e2;
    4763                 :            :                 data_size = (sizeof(struct hc_status_block_data_e2) /
    4764                 :            :                              sizeof(uint32_t));
    4765                 :            :         } else {
    4766                 :            :                 memset(&sb_data_e1x, 0,
    4767                 :            :                        sizeof(struct hc_status_block_data_e1x));
    4768                 :            :                 sb_data_e1x.common.state = SB_DISABLED;
    4769                 :            :                 sb_data_e1x.common.p_func.vf_valid = FALSE;
    4770                 :            :                 sb_data_p = (uint32_t *) & sb_data_e1x;
    4771                 :            :                 data_size = (sizeof(struct hc_status_block_data_e1x) /
    4772                 :            :                              sizeof(uint32_t));
    4773                 :            :         }
    4774                 :            : 
    4775                 :            :         bnx2x_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
    4776                 :            : 
    4777                 :          0 :         bnx2x_fill(sc,
    4778                 :          0 :                  (BAR_CSTRORM_INTMEM + CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id)), 0,
    4779                 :          0 :                  CSTORM_STATUS_BLOCK_SIZE);
    4780                 :          0 :         bnx2x_fill(sc, (BAR_CSTRORM_INTMEM + CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id)),
    4781                 :          0 :                  0, CSTORM_SYNC_BLOCK_SIZE);
    4782                 :          0 : }
    4783                 :            : 
    4784                 :            : static void
    4785                 :            : bnx2x_wr_sp_sb_data(struct bnx2x_softc *sc,
    4786                 :            :                   struct hc_sp_status_block_data *sp_sb_data)
    4787                 :            : {
    4788                 :            :         uint32_t i;
    4789                 :            : 
    4790                 :          0 :         for (i = 0;
    4791   [ #  #  #  # ]:          0 :              i < (sizeof(struct hc_sp_status_block_data) / sizeof(uint32_t));
    4792                 :          0 :              i++) {
    4793                 :          0 :                 REG_WR(sc,
    4794                 :            :                        (BAR_CSTRORM_INTMEM +
    4795                 :            :                         CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(SC_FUNC(sc)) +
    4796                 :            :                         (i * sizeof(uint32_t))),
    4797                 :            :                        *((uint32_t *) sp_sb_data + i));
    4798                 :            :         }
    4799                 :            : }
    4800                 :            : 
    4801                 :          0 : static void bnx2x_zero_sp_sb(struct bnx2x_softc *sc)
    4802                 :            : {
    4803                 :            :         struct hc_sp_status_block_data sp_sb_data;
    4804                 :            : 
    4805                 :            :         memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
    4806                 :            : 
    4807                 :            :         sp_sb_data.state = SB_DISABLED;
    4808                 :            :         sp_sb_data.p_func.vf_valid = FALSE;
    4809                 :            : 
    4810                 :            :         bnx2x_wr_sp_sb_data(sc, &sp_sb_data);
    4811                 :            : 
    4812                 :          0 :         bnx2x_fill(sc,
    4813                 :            :                  (BAR_CSTRORM_INTMEM +
    4814                 :          0 :                   CSTORM_SP_STATUS_BLOCK_OFFSET(SC_FUNC(sc))),
    4815                 :          0 :                  0, CSTORM_SP_STATUS_BLOCK_SIZE);
    4816                 :          0 :         bnx2x_fill(sc,
    4817                 :            :                  (BAR_CSTRORM_INTMEM +
    4818                 :          0 :                   CSTORM_SP_SYNC_BLOCK_OFFSET(SC_FUNC(sc))),
    4819                 :          0 :                  0, CSTORM_SP_SYNC_BLOCK_SIZE);
    4820                 :          0 : }
    4821                 :            : 
    4822                 :            : static void
    4823                 :            : bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm, int igu_sb_id,
    4824                 :            :                              int igu_seg_id)
    4825                 :            : {
    4826                 :          0 :         hc_sm->igu_sb_id = igu_sb_id;
    4827                 :          0 :         hc_sm->igu_seg_id = igu_seg_id;
    4828                 :          0 :         hc_sm->timer_value = 0xFF;
    4829                 :          0 :         hc_sm->time_to_expire = 0xFFFFFFFF;
    4830                 :            : }
    4831                 :            : 
    4832                 :            : static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
    4833                 :            : {
    4834                 :            :         /* zero out state machine indices */
    4835                 :            : 
    4836                 :            :         /* rx indices */
    4837                 :            :         index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
    4838                 :            : 
    4839                 :            :         /* tx indices */
    4840                 :            :         index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
    4841                 :            :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
    4842                 :            :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
    4843                 :            :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
    4844                 :            : 
    4845                 :            :         /* map indices */
    4846                 :            : 
    4847                 :            :         /* rx indices */
    4848                 :            :         index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
    4849                 :            :             (SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
    4850                 :            : 
    4851                 :            :         /* tx indices */
    4852                 :          0 :         index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
    4853                 :            :             (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
    4854                 :          0 :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
    4855                 :            :             (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
    4856                 :          0 :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
    4857                 :            :             (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
    4858                 :          0 :         index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
    4859                 :            :             (SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT);
    4860                 :          0 : }
    4861                 :            : 
    4862                 :            : static void
    4863                 :          0 : bnx2x_init_sb(struct bnx2x_softc *sc, rte_iova_t busaddr, int vfid,
    4864                 :            :             uint8_t vf_valid, int fw_sb_id, int igu_sb_id)
    4865                 :            : {
    4866                 :            :         struct hc_status_block_data_e2 sb_data_e2;
    4867                 :            :         struct hc_status_block_data_e1x sb_data_e1x;
    4868                 :            :         struct hc_status_block_sm *hc_sm_p;
    4869                 :            :         uint32_t *sb_data_p;
    4870                 :            :         int igu_seg_id;
    4871                 :            :         int data_size;
    4872                 :            : 
    4873                 :            :         if (CHIP_INT_MODE_IS_BC(sc)) {
    4874                 :            :                 igu_seg_id = HC_SEG_ACCESS_NORM;
    4875                 :            :         } else {
    4876                 :            :                 igu_seg_id = IGU_SEG_ACCESS_NORM;
    4877                 :            :         }
    4878                 :            : 
    4879                 :          0 :         bnx2x_zero_fp_sb(sc, fw_sb_id);
    4880                 :            : 
    4881         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    4882                 :            :                 memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
    4883                 :          0 :                 sb_data_e2.common.state = SB_ENABLED;
    4884                 :          0 :                 sb_data_e2.common.p_func.pf_id = SC_FUNC(sc);
    4885                 :          0 :                 sb_data_e2.common.p_func.vf_id = vfid;
    4886                 :          0 :                 sb_data_e2.common.p_func.vf_valid = vf_valid;
    4887                 :          0 :                 sb_data_e2.common.p_func.vnic_id = SC_VN(sc);
    4888                 :          0 :                 sb_data_e2.common.same_igu_sb_1b = TRUE;
    4889                 :          0 :                 sb_data_e2.common.host_sb_addr.hi = U64_HI(busaddr);
    4890                 :          0 :                 sb_data_e2.common.host_sb_addr.lo = U64_LO(busaddr);
    4891                 :            :                 hc_sm_p = sb_data_e2.common.state_machine;
    4892                 :            :                 sb_data_p = (uint32_t *) & sb_data_e2;
    4893                 :            :                 data_size = (sizeof(struct hc_status_block_data_e2) /
    4894                 :            :                              sizeof(uint32_t));
    4895                 :            :                 bnx2x_map_sb_state_machines(sb_data_e2.index_data);
    4896                 :            :         } else {
    4897                 :            :                 memset(&sb_data_e1x, 0,
    4898                 :            :                        sizeof(struct hc_status_block_data_e1x));
    4899                 :          0 :                 sb_data_e1x.common.state = SB_ENABLED;
    4900                 :          0 :                 sb_data_e1x.common.p_func.pf_id = SC_FUNC(sc);
    4901                 :          0 :                 sb_data_e1x.common.p_func.vf_id = 0xff;
    4902                 :            :                 sb_data_e1x.common.p_func.vf_valid = FALSE;
    4903                 :          0 :                 sb_data_e1x.common.p_func.vnic_id = SC_VN(sc);
    4904                 :          0 :                 sb_data_e1x.common.same_igu_sb_1b = TRUE;
    4905                 :          0 :                 sb_data_e1x.common.host_sb_addr.hi = U64_HI(busaddr);
    4906                 :          0 :                 sb_data_e1x.common.host_sb_addr.lo = U64_LO(busaddr);
    4907                 :            :                 hc_sm_p = sb_data_e1x.common.state_machine;
    4908                 :            :                 sb_data_p = (uint32_t *) & sb_data_e1x;
    4909                 :            :                 data_size = (sizeof(struct hc_status_block_data_e1x) /
    4910                 :            :                              sizeof(uint32_t));
    4911                 :            :                 bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
    4912                 :            :         }
    4913                 :            : 
    4914                 :            :         bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID], igu_sb_id, igu_seg_id);
    4915                 :            :         bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID], igu_sb_id, igu_seg_id);
    4916                 :            : 
    4917                 :            :         /* write indices to HW - PCI guarantees endianity of regpairs */
    4918                 :            :         bnx2x_wr_fp_sb_data(sc, fw_sb_id, sb_data_p, data_size);
    4919                 :          0 : }
    4920                 :            : 
    4921                 :            : static uint8_t bnx2x_fp_qzone_id(struct bnx2x_fastpath *fp)
    4922                 :            : {
    4923         [ #  # ]:          0 :         if (CHIP_IS_E1x(fp->sc)) {
    4924                 :          0 :                 return fp->cl_id + SC_PORT(fp->sc) * ETH_MAX_RX_CLIENTS_E1H;
    4925                 :            :         } else {
    4926                 :          0 :                 return fp->cl_id;
    4927                 :            :         }
    4928                 :            : }
    4929                 :            : 
    4930                 :            : static uint32_t
    4931                 :          0 : bnx2x_rx_ustorm_prods_offset(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp)
    4932                 :            : {
    4933                 :            :         uint32_t offset = BAR_USTRORM_INTMEM;
    4934                 :            : 
    4935         [ #  # ]:          0 :         if (IS_VF(sc)) {
    4936                 :          0 :                 return PXP_VF_ADDR_USDM_QUEUES_START +
    4937                 :          0 :                         (sc->acquire_resp.resc.hw_qid[fp->index] *
    4938                 :            :                          sizeof(struct ustorm_queue_zone_data));
    4939         [ #  # ]:          0 :         } else if (!CHIP_IS_E1x(sc)) {
    4940                 :          0 :                 offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
    4941                 :            :         } else {
    4942                 :          0 :                 offset += USTORM_RX_PRODS_E1X_OFFSET(SC_PORT(sc), fp->cl_id);
    4943                 :            :         }
    4944                 :            : 
    4945                 :            :         return offset;
    4946                 :            : }
    4947                 :            : 
    4948                 :          0 : static void bnx2x_init_eth_fp(struct bnx2x_softc *sc, int idx)
    4949                 :            : {
    4950                 :          0 :         struct bnx2x_fastpath *fp = &sc->fp[idx];
    4951                 :          0 :         uint32_t cids[ECORE_MULTI_TX_COS] = { 0 };
    4952                 :          0 :         uint32_t q_type = 0;
    4953                 :            :         int cos;
    4954                 :            : 
    4955                 :          0 :         fp->sc = sc;
    4956                 :          0 :         fp->index = idx;
    4957                 :            : 
    4958                 :          0 :         fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
    4959                 :          0 :         fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
    4960                 :            : 
    4961         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc))
    4962                 :          0 :                 fp->cl_id = SC_L_ID(sc) + idx;
    4963                 :            :         else
    4964                 :            : /* want client ID same as IGU SB ID for non-E1 */
    4965                 :          0 :                 fp->cl_id = fp->igu_sb_id;
    4966                 :          0 :         fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
    4967                 :            : 
    4968                 :            :         /* setup sb indices */
    4969         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    4970                 :          0 :                 fp->sb_index_values = fp->status_block.e2_sb->sb.index_values;
    4971                 :          0 :                 fp->sb_running_index = fp->status_block.e2_sb->sb.running_index;
    4972                 :            :         } else {
    4973                 :          0 :                 fp->sb_index_values = fp->status_block.e1x_sb->sb.index_values;
    4974                 :          0 :                 fp->sb_running_index =
    4975                 :          0 :                     fp->status_block.e1x_sb->sb.running_index;
    4976                 :            :         }
    4977                 :            : 
    4978                 :            :         /* init shortcut */
    4979                 :          0 :         fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(sc, fp);
    4980                 :            : 
    4981                 :          0 :         fp->rx_cq_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_RX_CQ_CONS];
    4982                 :            : 
    4983         [ #  # ]:          0 :         for (cos = 0; cos < sc->max_cos; cos++) {
    4984                 :          0 :                 cids[cos] = idx;
    4985                 :            :         }
    4986                 :          0 :         fp->tx_cons_sb = &fp->sb_index_values[HC_INDEX_ETH_TX_CQ_CONS_COS0];
    4987                 :            : 
    4988                 :            :         /* nothing more for a VF to do */
    4989         [ #  # ]:          0 :         if (IS_VF(sc)) {
    4990                 :          0 :                 return;
    4991                 :            :         }
    4992                 :            : 
    4993                 :          0 :         bnx2x_init_sb(sc, fp->sb_dma.paddr, BNX2X_VF_ID_INVALID, FALSE,
    4994                 :            :                     fp->fw_sb_id, fp->igu_sb_id);
    4995                 :            : 
    4996                 :            :         bnx2x_update_fp_sb_idx(fp);
    4997                 :            : 
    4998                 :            :         /* Configure Queue State object */
    4999                 :            :         rte_bit_relaxed_set32(ECORE_Q_TYPE_HAS_RX, &q_type);
    5000                 :            :         rte_bit_relaxed_set32(ECORE_Q_TYPE_HAS_TX, &q_type);
    5001                 :            : 
    5002                 :          0 :         ecore_init_queue_obj(sc,
    5003                 :            :                              &sc->sp_objs[idx].q_obj,
    5004                 :          0 :                              fp->cl_id,
    5005                 :            :                              cids,
    5006                 :          0 :                              sc->max_cos,
    5007                 :          0 :                              SC_FUNC(sc),
    5008                 :          0 :                              BNX2X_SP(sc, q_rdata),
    5009                 :          0 :                              (rte_iova_t)BNX2X_SP_MAPPING(sc, q_rdata),
    5010                 :            :                              q_type);
    5011                 :            : 
    5012                 :            :         /* configure classification DBs */
    5013                 :          0 :         ecore_init_mac_obj(sc,
    5014                 :            :                            &sc->sp_objs[idx].mac_obj,
    5015                 :          0 :                            fp->cl_id,
    5016                 :            :                            idx,
    5017                 :          0 :                            SC_FUNC(sc),
    5018                 :          0 :                            BNX2X_SP(sc, mac_rdata),
    5019                 :          0 :                            (rte_iova_t)BNX2X_SP_MAPPING(sc, mac_rdata),
    5020                 :            :                            ECORE_FILTER_MAC_PENDING, &sc->sp_state,
    5021                 :            :                            ECORE_OBJ_TYPE_RX_TX, &sc->macs_pool);
    5022                 :            : }
    5023                 :            : 
    5024                 :            : static void
    5025                 :          0 : bnx2x_update_rx_prod(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    5026                 :            :                    uint16_t rx_bd_prod, uint16_t rx_cq_prod)
    5027                 :            : {
    5028                 :            :         struct ustorm_eth_rx_producers rx_prods;
    5029                 :            :         uint32_t i;
    5030                 :            : 
    5031                 :            :         memset(&rx_prods, 0, sizeof(rx_prods));
    5032                 :            : 
    5033                 :            :         /* update producers */
    5034                 :          0 :         rx_prods.bd_prod = rx_bd_prod;
    5035                 :          0 :         rx_prods.cqe_prod = rx_cq_prod;
    5036                 :            : 
    5037                 :            :         /*
    5038                 :            :          * Make sure that the BD and SGE data is updated before updating the
    5039                 :            :          * producers since FW might read the BD/SGE right after the producer
    5040                 :            :          * is updated.
    5041                 :            :          * This is only applicable for weak-ordered memory model archs such
    5042                 :            :          * as IA-64. The following barrier is also mandatory since FW will
    5043                 :            :          * assumes BDs must have buffers.
    5044                 :            :          */
    5045                 :            :         wmb();
    5046                 :            : 
    5047         [ #  # ]:          0 :         for (i = 0; i < (sizeof(rx_prods) / 4); i++) {
    5048                 :          0 :                 REG_WR(sc, (fp->ustorm_rx_prods_offset + (i * 4)),
    5049                 :            :                        ((uint32_t *)&rx_prods)[i]);
    5050                 :            :         }
    5051                 :            : 
    5052                 :            :         wmb();                  /* keep prod updates ordered */
    5053                 :          0 : }
    5054                 :            : 
    5055                 :          0 : static void bnx2x_init_rx_rings(struct bnx2x_softc *sc)
    5056                 :            : {
    5057                 :            :         struct bnx2x_fastpath *fp;
    5058                 :            :         int i;
    5059                 :            :         struct bnx2x_rx_queue *rxq;
    5060                 :            : 
    5061         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    5062                 :          0 :                 fp = &sc->fp[i];
    5063                 :          0 :                 rxq = sc->rx_queues[fp->index];
    5064         [ #  # ]:          0 :                 if (!rxq) {
    5065                 :            :                         PMD_RX_LOG(ERR, "RX queue is NULL");
    5066                 :            :                         return;
    5067                 :            :                 }
    5068                 :            : 
    5069                 :          0 :                 rxq->rx_bd_head = 0;
    5070                 :          0 :                 rxq->rx_bd_tail = rxq->nb_rx_desc;
    5071                 :          0 :                 rxq->rx_cq_head = 0;
    5072                 :          0 :                 rxq->rx_cq_tail = TOTAL_RCQ_ENTRIES(rxq);
    5073                 :          0 :                 *fp->rx_cq_cons_sb = 0;
    5074                 :            : 
    5075                 :            :                 /*
    5076                 :            :                  * Activate the BD ring...
    5077                 :            :                  * Warning, this will generate an interrupt (to the TSTORM)
    5078                 :            :                  * so this can only be done after the chip is initialized
    5079                 :            :                  */
    5080                 :          0 :                 bnx2x_update_rx_prod(sc, fp, rxq->rx_bd_tail, rxq->rx_cq_tail);
    5081                 :            : 
    5082                 :            :                 if (i != 0) {
    5083                 :            :                         continue;
    5084                 :            :                 }
    5085                 :            :         }
    5086                 :            : }
    5087                 :            : 
    5088                 :            : static void bnx2x_init_tx_ring_one(struct bnx2x_fastpath *fp)
    5089                 :            : {
    5090                 :          0 :         struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
    5091                 :            : 
    5092                 :          0 :         fp->tx_db.data.header.header = 1 << DOORBELL_HDR_DB_TYPE_SHIFT;
    5093                 :          0 :         fp->tx_db.data.zero_fill1 = 0;
    5094                 :          0 :         fp->tx_db.data.prod = 0;
    5095                 :            : 
    5096         [ #  # ]:          0 :         if (!txq) {
    5097                 :            :                 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
    5098                 :            :                 return;
    5099                 :            :         }
    5100                 :            : 
    5101                 :          0 :         txq->tx_pkt_tail = 0;
    5102                 :          0 :         txq->tx_pkt_head = 0;
    5103                 :          0 :         txq->tx_bd_tail = 0;
    5104                 :          0 :         txq->tx_bd_head = 0;
    5105                 :            : }
    5106                 :            : 
    5107                 :          0 : static void bnx2x_init_tx_rings(struct bnx2x_softc *sc)
    5108                 :            : {
    5109                 :            :         int i;
    5110                 :            : 
    5111         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    5112                 :            :                 bnx2x_init_tx_ring_one(&sc->fp[i]);
    5113                 :            :         }
    5114                 :          0 : }
    5115                 :            : 
    5116                 :          0 : static void bnx2x_init_def_sb(struct bnx2x_softc *sc)
    5117                 :            : {
    5118                 :          0 :         struct host_sp_status_block *def_sb = sc->def_sb;
    5119                 :          0 :         rte_iova_t mapping = sc->def_sb_dma.paddr;
    5120                 :            :         int igu_sp_sb_index;
    5121                 :            :         int igu_seg_id;
    5122         [ #  # ]:          0 :         int port = SC_PORT(sc);
    5123                 :            :         int func = SC_FUNC(sc);
    5124                 :            :         int reg_offset, reg_offset_en5;
    5125                 :            :         uint64_t section;
    5126                 :            :         int index, sindex;
    5127                 :            :         struct hc_sp_status_block_data sp_sb_data;
    5128                 :            : 
    5129                 :            :         memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
    5130                 :            : 
    5131   [ #  #  #  # ]:          0 :         if (CHIP_INT_MODE_IS_BC(sc)) {
    5132                 :            :                 igu_sp_sb_index = DEF_SB_IGU_ID;
    5133                 :            :                 igu_seg_id = HC_SEG_ACCESS_DEF;
    5134                 :            :         } else {
    5135                 :          0 :                 igu_sp_sb_index = sc->igu_dsb_id;
    5136                 :            :                 igu_seg_id = IGU_SEG_ACCESS_DEF;
    5137                 :            :         }
    5138                 :            : 
    5139                 :            :         /* attentions */
    5140                 :            :         section = ((uint64_t) mapping +
    5141                 :            :                    offsetof(struct host_sp_status_block, atten_status_block));
    5142                 :          0 :         def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
    5143                 :          0 :         sc->attn_state = 0;
    5144                 :            : 
    5145         [ #  # ]:          0 :         reg_offset = (port) ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
    5146                 :            :             MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
    5147                 :            : 
    5148         [ #  # ]:          0 :         reg_offset_en5 = (port) ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
    5149                 :            :             MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0;
    5150                 :            : 
    5151         [ #  # ]:          0 :         for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
    5152                 :            : /* take care of sig[0]..sig[4] */
    5153         [ #  # ]:          0 :                 for (sindex = 0; sindex < 4; sindex++) {
    5154                 :          0 :                         sc->attn_group[index].sig[sindex] =
    5155                 :          0 :                             REG_RD(sc,
    5156                 :            :                                    (reg_offset + (sindex * 0x4) +
    5157                 :            :                                     (0x10 * index)));
    5158                 :            :                 }
    5159                 :            : 
    5160         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
    5161                 :            :                         /*
    5162                 :            :                          * enable5 is separate from the rest of the registers,
    5163                 :            :                          * and the address skip is 4 and not 16 between the
    5164                 :            :                          * different groups
    5165                 :            :                          */
    5166                 :          0 :                         sc->attn_group[index].sig[4] =
    5167                 :          0 :                             REG_RD(sc, (reg_offset_en5 + (0x4 * index)));
    5168                 :            :                 } else {
    5169                 :          0 :                         sc->attn_group[index].sig[4] = 0;
    5170                 :            :                 }
    5171                 :            :         }
    5172                 :            : 
    5173         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    5174                 :            :                 reg_offset =
    5175         [ #  # ]:          0 :                     port ? HC_REG_ATTN_MSG1_ADDR_L : HC_REG_ATTN_MSG0_ADDR_L;
    5176                 :          0 :                 REG_WR(sc, reg_offset, U64_LO(section));
    5177                 :          0 :                 REG_WR(sc, (reg_offset + 4), U64_HI(section));
    5178         [ #  # ]:          0 :         } else if (!CHIP_IS_E1x(sc)) {
    5179                 :          0 :                 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
    5180                 :          0 :                 REG_WR(sc, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
    5181                 :            :         }
    5182                 :            : 
    5183                 :          0 :         section = ((uint64_t) mapping +
    5184                 :            :                    offsetof(struct host_sp_status_block, sp_sb));
    5185                 :            : 
    5186                 :          0 :         bnx2x_zero_sp_sb(sc);
    5187                 :            : 
    5188                 :            :         /* PCI guarantees endianity of regpair */
    5189                 :          0 :         sp_sb_data.state = SB_ENABLED;
    5190                 :          0 :         sp_sb_data.host_sb_addr.lo = U64_LO(section);
    5191                 :          0 :         sp_sb_data.host_sb_addr.hi = U64_HI(section);
    5192                 :          0 :         sp_sb_data.igu_sb_id = igu_sp_sb_index;
    5193                 :          0 :         sp_sb_data.igu_seg_id = igu_seg_id;
    5194                 :          0 :         sp_sb_data.p_func.pf_id = func;
    5195                 :          0 :         sp_sb_data.p_func.vnic_id = SC_VN(sc);
    5196                 :          0 :         sp_sb_data.p_func.vf_id = 0xff;
    5197                 :            : 
    5198                 :            :         bnx2x_wr_sp_sb_data(sc, &sp_sb_data);
    5199                 :            : 
    5200                 :          0 :         bnx2x_ack_sb(sc, sc->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
    5201                 :          0 : }
    5202                 :            : 
    5203                 :            : static void bnx2x_init_sp_ring(struct bnx2x_softc *sc)
    5204                 :            : {
    5205                 :          0 :         atomic_store_rel_long(&sc->cq_spq_left, MAX_SPQ_PENDING);
    5206                 :          0 :         sc->spq_prod_idx = 0;
    5207                 :          0 :         sc->dsb_sp_prod =
    5208                 :          0 :             &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_ETH_DEF_CONS];
    5209                 :          0 :         sc->spq_prod_bd = sc->spq;
    5210                 :          0 :         sc->spq_last_bd = (sc->spq_prod_bd + MAX_SP_DESC_CNT);
    5211                 :            : }
    5212                 :            : 
    5213                 :            : static void bnx2x_init_eq_ring(struct bnx2x_softc *sc)
    5214                 :            : {
    5215                 :            :         union event_ring_elem *elem;
    5216                 :            :         int i;
    5217                 :            : 
    5218                 :            :         for (i = 1; i <= NUM_EQ_PAGES; i++) {
    5219                 :          0 :                 elem = &sc->eq[EQ_DESC_CNT_PAGE * i - 1];
    5220                 :            : 
    5221                 :          0 :                 elem->next_page.addr.hi = htole32(U64_HI(sc->eq_dma.paddr +
    5222                 :            :                                                          BNX2X_PAGE_SIZE *
    5223                 :            :                                                          (i % NUM_EQ_PAGES)));
    5224                 :          0 :                 elem->next_page.addr.lo = htole32(U64_LO(sc->eq_dma.paddr +
    5225                 :            :                                                          BNX2X_PAGE_SIZE *
    5226                 :            :                                                          (i % NUM_EQ_PAGES)));
    5227                 :            :         }
    5228                 :            : 
    5229                 :          0 :         sc->eq_cons = 0;
    5230                 :          0 :         sc->eq_prod = NUM_EQ_DESC;
    5231                 :          0 :         sc->eq_cons_sb = &sc->def_sb->sp_sb.index_values[HC_SP_INDEX_EQ_CONS];
    5232                 :            : 
    5233                 :          0 :         atomic_store_rel_long(&sc->eq_spq_left,
    5234                 :            :                               (min((MAX_SP_DESC_CNT - MAX_SPQ_PENDING),
    5235                 :            :                                    NUM_EQ_DESC) - 1));
    5236                 :            : }
    5237                 :            : 
    5238                 :          0 : static void bnx2x_init_internal_common(struct bnx2x_softc *sc)
    5239                 :            : {
    5240                 :            :         int i;
    5241                 :            : 
    5242                 :            :         /*
    5243                 :            :          * Zero this manually as its initialization is currently missing
    5244                 :            :          * in the initTool.
    5245                 :            :          */
    5246         [ #  # ]:          0 :         for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) {
    5247                 :          0 :                 REG_WR(sc,
    5248                 :            :                        (BAR_USTRORM_INTMEM + USTORM_AGG_DATA_OFFSET + (i * 4)),
    5249                 :            :                        0);
    5250                 :            :         }
    5251                 :            : 
    5252         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    5253         [ #  # ]:          0 :                 REG_WR8(sc, (BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET),
    5254                 :            :                         CHIP_INT_MODE_IS_BC(sc) ? HC_IGU_BC_MODE :
    5255                 :            :                         HC_IGU_NBC_MODE);
    5256                 :            :         }
    5257                 :          0 : }
    5258                 :            : 
    5259                 :          0 : static void bnx2x_init_internal(struct bnx2x_softc *sc, uint32_t load_code)
    5260                 :            : {
    5261      [ #  #  # ]:          0 :         switch (load_code) {
    5262                 :          0 :         case FW_MSG_CODE_DRV_LOAD_COMMON:
    5263                 :            :         case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
    5264                 :          0 :                 bnx2x_init_internal_common(sc);
    5265                 :            :                 /* no break */
    5266                 :            : 
    5267                 :            :         case FW_MSG_CODE_DRV_LOAD_PORT:
    5268                 :            :                 /* nothing to do */
    5269                 :            :                 /* no break */
    5270                 :            : 
    5271                 :            :         case FW_MSG_CODE_DRV_LOAD_FUNCTION:
    5272                 :            :                 /* internal memory per function is initialized inside bnx2x_pf_init */
    5273                 :            :                 break;
    5274                 :            : 
    5275                 :          0 :         default:
    5276                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Unknown load_code (0x%x) from MCP",
    5277                 :            :                             load_code);
    5278                 :          0 :                 break;
    5279                 :            :         }
    5280                 :          0 : }
    5281                 :            : 
    5282                 :            : static void
    5283                 :            : storm_memset_func_cfg(struct bnx2x_softc *sc,
    5284                 :            :                       struct tstorm_eth_function_common_config *tcfg,
    5285                 :            :                       uint16_t abs_fid)
    5286                 :            : {
    5287                 :            :         uint32_t addr;
    5288                 :            :         size_t size;
    5289                 :            : 
    5290                 :          0 :         addr = (BAR_TSTRORM_INTMEM +
    5291                 :          0 :                 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid));
    5292                 :            :         size = sizeof(struct tstorm_eth_function_common_config);
    5293                 :          0 :         ecore_storm_memset_struct(sc, addr, size, (uint32_t *) tcfg);
    5294                 :          0 : }
    5295                 :            : 
    5296                 :          0 : static void bnx2x_func_init(struct bnx2x_softc *sc, struct bnx2x_func_init_params *p)
    5297                 :            : {
    5298                 :          0 :         struct tstorm_eth_function_common_config tcfg = { 0 };
    5299                 :            : 
    5300         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
    5301                 :          0 :                 storm_memset_func_cfg(sc, &tcfg, p->func_id);
    5302                 :            :         }
    5303                 :            : 
    5304                 :            :         /* Enable the function in the FW */
    5305                 :          0 :         storm_memset_vf_to_pf(sc, p->func_id, p->pf_id);
    5306                 :          0 :         storm_memset_func_en(sc, p->func_id, 1);
    5307                 :            : 
    5308                 :            :         /* spq */
    5309         [ #  # ]:          0 :         if (p->func_flgs & FUNC_FLG_SPQ) {
    5310                 :          0 :                 storm_memset_spq_addr(sc, p->spq_map, p->func_id);
    5311                 :          0 :                 REG_WR(sc,
    5312                 :            :                        (XSEM_REG_FAST_MEMORY +
    5313                 :            :                         XSTORM_SPQ_PROD_OFFSET(p->func_id)), p->spq_prod);
    5314                 :            :         }
    5315                 :          0 : }
    5316                 :            : 
    5317                 :            : /*
    5318                 :            :  * Calculates the sum of vn_min_rates.
    5319                 :            :  * It's needed for further normalizing of the min_rates.
    5320                 :            :  * Returns:
    5321                 :            :  *   sum of vn_min_rates.
    5322                 :            :  *     or
    5323                 :            :  *   0 - if all the min_rates are 0.
    5324                 :            :  * In the later case fairness algorithm should be deactivated.
    5325                 :            :  * If all min rates are not zero then those that are zeroes will be set to 1.
    5326                 :            :  */
    5327                 :          0 : static void bnx2x_calc_vn_min(struct bnx2x_softc *sc, struct cmng_init_input *input)
    5328                 :            : {
    5329                 :            :         uint32_t vn_cfg;
    5330                 :            :         uint32_t vn_min_rate;
    5331                 :            :         int all_zero = 1;
    5332                 :            :         int vn;
    5333                 :            : 
    5334   [ #  #  #  # ]:          0 :         for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
    5335                 :          0 :                 vn_cfg = sc->devinfo.mf_info.mf_config[vn];
    5336                 :          0 :                 vn_min_rate = (((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
    5337                 :            :                                 FUNC_MF_CFG_MIN_BW_SHIFT) * 100);
    5338                 :            : 
    5339         [ #  # ]:          0 :                 if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
    5340                 :            :                         /* skip hidden VNs */
    5341                 :            :                         vn_min_rate = 0;
    5342         [ #  # ]:          0 :                 } else if (!vn_min_rate) {
    5343                 :            :                         /* If min rate is zero - set it to 100 */
    5344                 :            :                         vn_min_rate = DEF_MIN_RATE;
    5345                 :            :                 } else {
    5346                 :            :                         all_zero = 0;
    5347                 :            :                 }
    5348                 :            : 
    5349                 :          0 :                 input->vnic_min_rate[vn] = vn_min_rate;
    5350                 :            :         }
    5351                 :            : 
    5352                 :            :         /* if ETS or all min rates are zeros - disable fairness */
    5353         [ #  # ]:          0 :         if (all_zero) {
    5354                 :          0 :                 input->flags.cmng_enables &= ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
    5355                 :            :         } else {
    5356                 :          0 :                 input->flags.cmng_enables |= CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
    5357                 :            :         }
    5358                 :          0 : }
    5359                 :            : 
    5360                 :            : static uint16_t
    5361                 :          0 : bnx2x_extract_max_cfg(__rte_unused struct bnx2x_softc *sc, uint32_t mf_cfg)
    5362                 :            : {
    5363                 :          0 :         uint16_t max_cfg = ((mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
    5364                 :            :                             FUNC_MF_CFG_MAX_BW_SHIFT);
    5365                 :            : 
    5366         [ #  # ]:          0 :         if (!max_cfg) {
    5367                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
    5368                 :            :                             "Max BW configured to 0 - using 100 instead");
    5369                 :            :                 max_cfg = 100;
    5370                 :            :         }
    5371                 :            : 
    5372                 :          0 :         return max_cfg;
    5373                 :            : }
    5374                 :            : 
    5375                 :            : static void
    5376                 :          0 : bnx2x_calc_vn_max(struct bnx2x_softc *sc, int vn, struct cmng_init_input *input)
    5377                 :            : {
    5378                 :            :         uint16_t vn_max_rate;
    5379                 :          0 :         uint32_t vn_cfg = sc->devinfo.mf_info.mf_config[vn];
    5380                 :            :         uint32_t max_cfg;
    5381                 :            : 
    5382         [ #  # ]:          0 :         if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
    5383                 :            :                 vn_max_rate = 0;
    5384                 :            :         } else {
    5385                 :          0 :                 max_cfg = bnx2x_extract_max_cfg(sc, vn_cfg);
    5386                 :            : 
    5387   [ #  #  #  # ]:          0 :                 if (IS_MF_SI(sc)) {
    5388                 :            :                         /* max_cfg in percents of linkspeed */
    5389                 :          0 :                         vn_max_rate =
    5390                 :          0 :                             ((sc->link_vars.line_speed * max_cfg) / 100);
    5391                 :            :                 } else {        /* SD modes */
    5392                 :            :                         /* max_cfg is absolute in 100Mb units */
    5393                 :          0 :                         vn_max_rate = (max_cfg * 100);
    5394                 :            :                 }
    5395                 :            :         }
    5396                 :            : 
    5397                 :          0 :         input->vnic_max_rate[vn] = vn_max_rate;
    5398                 :          0 : }
    5399                 :            : 
    5400                 :            : static void
    5401         [ #  # ]:          0 : bnx2x_cmng_fns_init(struct bnx2x_softc *sc, uint8_t read_cfg, uint8_t cmng_type)
    5402                 :            : {
    5403                 :            :         struct cmng_init_input input;
    5404                 :            :         int vn;
    5405                 :            : 
    5406                 :            :         memset(&input, 0, sizeof(struct cmng_init_input));
    5407                 :            : 
    5408                 :          0 :         input.port_rate = sc->link_vars.line_speed;
    5409                 :            : 
    5410         [ #  # ]:          0 :         if (cmng_type == CMNG_FNS_MINMAX) {
    5411                 :            : /* read mf conf from shmem */
    5412         [ #  # ]:          0 :                 if (read_cfg) {
    5413                 :          0 :                         bnx2x_read_mf_cfg(sc);
    5414                 :            :                 }
    5415                 :            : 
    5416                 :            : /* get VN min rate and enable fairness if not 0 */
    5417                 :          0 :                 bnx2x_calc_vn_min(sc, &input);
    5418                 :            : 
    5419                 :            : /* get VN max rate */
    5420         [ #  # ]:          0 :                 if (sc->port.pmf) {
    5421   [ #  #  #  # ]:          0 :                         for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
    5422                 :          0 :                                 bnx2x_calc_vn_max(sc, vn, &input);
    5423                 :            :                         }
    5424                 :            :                 }
    5425                 :            : 
    5426                 :            : /* always enable rate shaping and fairness */
    5427                 :          0 :                 input.flags.cmng_enables |= CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
    5428                 :            : 
    5429                 :          0 :                 ecore_init_cmng(&input, &sc->cmng);
    5430                 :          0 :                 return;
    5431                 :            :         }
    5432                 :            : }
    5433                 :            : 
    5434                 :            : static int bnx2x_get_cmng_fns_mode(struct bnx2x_softc *sc)
    5435                 :            : {
    5436         [ #  # ]:          0 :         if (CHIP_REV_IS_SLOW(sc)) {
    5437                 :            :                 return CMNG_FNS_NONE;
    5438                 :            :         }
    5439                 :            : 
    5440   [ #  #  #  #  :          0 :         if (IS_MF(sc)) {
             #  #  #  # ]
    5441                 :          0 :                 return CMNG_FNS_MINMAX;
    5442                 :            :         }
    5443                 :            : 
    5444                 :            :         return CMNG_FNS_NONE;
    5445                 :            : }
    5446                 :            : 
    5447                 :            : static void
    5448                 :          0 : storm_memset_cmng(struct bnx2x_softc *sc, struct cmng_init *cmng, uint8_t port)
    5449                 :            : {
    5450                 :            :         int vn;
    5451                 :            :         int func;
    5452                 :            :         uint32_t addr;
    5453                 :            :         size_t size;
    5454                 :            : 
    5455                 :          0 :         addr = (BAR_XSTRORM_INTMEM + XSTORM_CMNG_PER_PORT_VARS_OFFSET(port));
    5456                 :            :         size = sizeof(struct cmng_struct_per_port);
    5457                 :          0 :         ecore_storm_memset_struct(sc, addr, size, (uint32_t *) & cmng->port);
    5458                 :            : 
    5459   [ #  #  #  # ]:          0 :         for (vn = VN_0; vn < SC_MAX_VN_NUM(sc); vn++) {
    5460                 :            :                 func = func_by_vn(sc, vn);
    5461                 :            : 
    5462                 :          0 :                 addr = (BAR_XSTRORM_INTMEM +
    5463                 :          0 :                         XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func));
    5464                 :            :                 size = sizeof(struct rate_shaping_vars_per_vn);
    5465                 :          0 :                 ecore_storm_memset_struct(sc, addr, size,
    5466                 :          0 :                                           (uint32_t *) & cmng->
    5467                 :            :                                           vnic.vnic_max_rate[vn]);
    5468                 :            : 
    5469                 :          0 :                 addr = (BAR_XSTRORM_INTMEM +
    5470                 :          0 :                         XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func));
    5471                 :            :                 size = sizeof(struct fairness_vars_per_vn);
    5472                 :          0 :                 ecore_storm_memset_struct(sc, addr, size,
    5473                 :          0 :                                           (uint32_t *) & cmng->
    5474                 :            :                                           vnic.vnic_min_rate[vn]);
    5475                 :            :         }
    5476                 :          0 : }
    5477                 :            : 
    5478         [ #  # ]:          0 : static void bnx2x_pf_init(struct bnx2x_softc *sc)
    5479                 :            : {
    5480                 :            :         struct bnx2x_func_init_params func_init;
    5481                 :            :         struct event_ring_data eq_data;
    5482                 :            :         uint16_t flags;
    5483                 :            : 
    5484                 :            :         memset(&eq_data, 0, sizeof(struct event_ring_data));
    5485                 :            :         memset(&func_init, 0, sizeof(struct bnx2x_func_init_params));
    5486                 :            : 
    5487         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    5488                 :            : /* reset IGU PF statistics: MSIX + ATTN */
    5489                 :            : /* PF */
    5490         [ #  # ]:          0 :                 REG_WR(sc,
    5491                 :            :                        (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
    5492                 :            :                         (BNX2X_IGU_STAS_MSG_VF_CNT * 4) +
    5493                 :            :                         ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) *
    5494                 :            :                          4)), 0);
    5495                 :            : /* ATTN */
    5496         [ #  # ]:          0 :                 REG_WR(sc,
    5497                 :            :                        (IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
    5498                 :            :                         (BNX2X_IGU_STAS_MSG_VF_CNT * 4) +
    5499                 :            :                         (BNX2X_IGU_STAS_MSG_PF_CNT * 4) +
    5500                 :            :                         ((CHIP_IS_MODE_4_PORT(sc) ? SC_FUNC(sc) : SC_VN(sc)) *
    5501                 :            :                          4)), 0);
    5502                 :            :         }
    5503                 :            : 
    5504                 :            :         /* function setup flags */
    5505                 :            :         flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
    5506                 :            : 
    5507                 :          0 :         func_init.func_flgs = flags;
    5508                 :          0 :         func_init.pf_id = SC_FUNC(sc);
    5509                 :          0 :         func_init.func_id = SC_FUNC(sc);
    5510                 :          0 :         func_init.spq_map = sc->spq_dma.paddr;
    5511                 :          0 :         func_init.spq_prod = sc->spq_prod_idx;
    5512                 :            : 
    5513                 :          0 :         bnx2x_func_init(sc, &func_init);
    5514                 :            : 
    5515         [ #  # ]:          0 :         memset(&sc->cmng, 0, sizeof(struct cmng_struct_per_port));
    5516                 :            : 
    5517                 :            :         /*
    5518                 :            :          * Congestion management values depend on the link rate.
    5519                 :            :          * There is no active link so initial link rate is set to 10Gbps.
    5520                 :            :          * When the link comes up the congestion management values are
    5521                 :            :          * re-calculated according to the actual link rate.
    5522                 :            :          */
    5523         [ #  # ]:          0 :         sc->link_vars.line_speed = SPEED_10000;
    5524                 :          0 :         bnx2x_cmng_fns_init(sc, TRUE, bnx2x_get_cmng_fns_mode(sc));
    5525                 :            : 
    5526                 :            :         /* Only the PMF sets the HW */
    5527         [ #  # ]:          0 :         if (sc->port.pmf) {
    5528                 :          0 :                 storm_memset_cmng(sc, &sc->cmng, SC_PORT(sc));
    5529                 :            :         }
    5530                 :            : 
    5531                 :            :         /* init Event Queue - PCI bus guarantees correct endainity */
    5532                 :          0 :         eq_data.base_addr.hi = U64_HI(sc->eq_dma.paddr);
    5533                 :          0 :         eq_data.base_addr.lo = U64_LO(sc->eq_dma.paddr);
    5534                 :          0 :         eq_data.producer = sc->eq_prod;
    5535                 :          0 :         eq_data.index_id = HC_SP_INDEX_EQ_CONS;
    5536                 :          0 :         eq_data.sb_id = DEF_SB_ID;
    5537                 :          0 :         storm_memset_eq_data(sc, &eq_data, SC_FUNC(sc));
    5538                 :          0 : }
    5539                 :            : 
    5540                 :          0 : static void bnx2x_hc_int_enable(struct bnx2x_softc *sc)
    5541                 :            : {
    5542                 :          0 :         int port = SC_PORT(sc);
    5543         [ #  # ]:          0 :         uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
    5544                 :          0 :         uint32_t val = REG_RD(sc, addr);
    5545                 :          0 :         uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX)
    5546                 :          0 :             || (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
    5547                 :            :         uint8_t single_msix = (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
    5548                 :            :         uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI);
    5549                 :            : 
    5550         [ #  # ]:          0 :         if (msix) {
    5551                 :          0 :                 val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
    5552                 :            :                          HC_CONFIG_0_REG_INT_LINE_EN_0);
    5553                 :          0 :                 val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
    5554                 :            :                         HC_CONFIG_0_REG_ATTN_BIT_EN_0);
    5555         [ #  # ]:          0 :                 if (single_msix) {
    5556                 :          0 :                         val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
    5557                 :            :                 }
    5558         [ #  # ]:          0 :         } else if (msi) {
    5559                 :          0 :                 val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
    5560                 :          0 :                 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
    5561                 :            :                         HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
    5562                 :            :                         HC_CONFIG_0_REG_ATTN_BIT_EN_0);
    5563                 :            :         } else {
    5564                 :          0 :                 val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
    5565                 :            :                         HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
    5566                 :            :                         HC_CONFIG_0_REG_INT_LINE_EN_0 |
    5567                 :            :                         HC_CONFIG_0_REG_ATTN_BIT_EN_0);
    5568                 :            : 
    5569                 :            :                 REG_WR(sc, addr, val);
    5570                 :            : 
    5571                 :          0 :                 val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
    5572                 :            :         }
    5573                 :            : 
    5574                 :            :         REG_WR(sc, addr, val);
    5575                 :            : 
    5576                 :            :         /* ensure that HC_CONFIG is written before leading/trailing edge config */
    5577                 :            :         mb();
    5578                 :            : 
    5579                 :            :         /* init leading/trailing edge */
    5580   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    5581                 :          0 :                 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
    5582         [ #  # ]:          0 :                 if (sc->port.pmf) {
    5583                 :            :                         /* enable nig and gpio3 attention */
    5584                 :          0 :                         val |= 0x1100;
    5585                 :            :                 }
    5586                 :            :         } else {
    5587                 :            :                 val = 0xffff;
    5588                 :            :         }
    5589                 :            : 
    5590                 :          0 :         REG_WR(sc, (HC_REG_TRAILING_EDGE_0 + port * 8), val);
    5591                 :          0 :         REG_WR(sc, (HC_REG_LEADING_EDGE_0 + port * 8), val);
    5592                 :            : 
    5593                 :            :         /* make sure that interrupts are indeed enabled from here on */
    5594                 :            :         mb();
    5595                 :          0 : }
    5596                 :            : 
    5597                 :          0 : static void bnx2x_igu_int_enable(struct bnx2x_softc *sc)
    5598                 :            : {
    5599                 :            :         uint32_t val;
    5600                 :          0 :         uint8_t msix = (sc->interrupt_mode == INTR_MODE_MSIX)
    5601                 :          0 :             || (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
    5602                 :          0 :         uint8_t single_msix = (sc->interrupt_mode == INTR_MODE_SINGLE_MSIX);
    5603                 :            :         uint8_t msi = (sc->interrupt_mode == INTR_MODE_MSI);
    5604                 :            : 
    5605                 :            :         val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
    5606                 :            : 
    5607         [ #  # ]:          0 :         if (msix) {
    5608                 :          0 :                 val &= ~(IGU_PF_CONF_INT_LINE_EN | IGU_PF_CONF_SINGLE_ISR_EN);
    5609                 :          0 :                 val |= (IGU_PF_CONF_MSI_MSIX_EN | IGU_PF_CONF_ATTN_BIT_EN);
    5610         [ #  # ]:          0 :                 if (single_msix) {
    5611                 :          0 :                         val |= IGU_PF_CONF_SINGLE_ISR_EN;
    5612                 :            :                 }
    5613         [ #  # ]:          0 :         } else if (msi) {
    5614                 :          0 :                 val &= ~IGU_PF_CONF_INT_LINE_EN;
    5615                 :          0 :                 val |= (IGU_PF_CONF_MSI_MSIX_EN |
    5616                 :            :                         IGU_PF_CONF_ATTN_BIT_EN | IGU_PF_CONF_SINGLE_ISR_EN);
    5617                 :            :         } else {
    5618                 :          0 :                 val &= ~IGU_PF_CONF_MSI_MSIX_EN;
    5619                 :          0 :                 val |= (IGU_PF_CONF_INT_LINE_EN |
    5620                 :            :                         IGU_PF_CONF_ATTN_BIT_EN | IGU_PF_CONF_SINGLE_ISR_EN);
    5621                 :            :         }
    5622                 :            : 
    5623                 :            :         /* clean previous status - need to configure igu prior to ack */
    5624         [ #  # ]:          0 :         if ((!msix) || single_msix) {
    5625                 :            :                 REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
    5626                 :            :                 bnx2x_ack_int(sc);
    5627                 :            :         }
    5628                 :            : 
    5629                 :          0 :         val |= IGU_PF_CONF_FUNC_EN;
    5630                 :            : 
    5631   [ #  #  #  # ]:          0 :         PMD_DRV_LOG(DEBUG, sc, "write 0x%x to IGU mode %s",
    5632                 :            :                     val, ((msix) ? "MSI-X" : ((msi) ? "MSI" : "INTx")));
    5633                 :            : 
    5634                 :            :         REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
    5635                 :            : 
    5636                 :            :         mb();
    5637                 :            : 
    5638                 :            :         /* init leading/trailing edge */
    5639   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    5640                 :          0 :                 val = (0xee0f | (1 << (SC_VN(sc) + 4)));
    5641         [ #  # ]:          0 :                 if (sc->port.pmf) {
    5642                 :            :                         /* enable nig and gpio3 attention */
    5643                 :          0 :                         val |= 0x1100;
    5644                 :            :                 }
    5645                 :            :         } else {
    5646                 :            :                 val = 0xffff;
    5647                 :            :         }
    5648                 :            : 
    5649                 :            :         REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, val);
    5650                 :            :         REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, val);
    5651                 :            : 
    5652                 :            :         /* make sure that interrupts are indeed enabled from here on */
    5653                 :            :         mb();
    5654                 :          0 : }
    5655                 :            : 
    5656                 :          0 : static void bnx2x_int_enable(struct bnx2x_softc *sc)
    5657                 :            : {
    5658         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    5659                 :          0 :                 bnx2x_hc_int_enable(sc);
    5660                 :            :         } else {
    5661                 :          0 :                 bnx2x_igu_int_enable(sc);
    5662                 :            :         }
    5663                 :          0 : }
    5664                 :            : 
    5665                 :          0 : static void bnx2x_hc_int_disable(struct bnx2x_softc *sc)
    5666                 :            : {
    5667                 :          0 :         int port = SC_PORT(sc);
    5668         [ #  # ]:          0 :         uint32_t addr = (port) ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
    5669                 :          0 :         uint32_t val = REG_RD(sc, addr);
    5670                 :            : 
    5671                 :          0 :         val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
    5672                 :            :                  HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
    5673                 :            :                  HC_CONFIG_0_REG_INT_LINE_EN_0 | HC_CONFIG_0_REG_ATTN_BIT_EN_0);
    5674                 :            :         /* flush all outstanding writes */
    5675                 :            :         mb();
    5676                 :            : 
    5677                 :            :         REG_WR(sc, addr, val);
    5678         [ #  # ]:          0 :         if (REG_RD(sc, addr) != val) {
    5679                 :          0 :                 PMD_DRV_LOG(ERR, sc, "proper val not read from HC IGU!");
    5680                 :            :         }
    5681                 :          0 : }
    5682                 :            : 
    5683                 :          0 : static void bnx2x_igu_int_disable(struct bnx2x_softc *sc)
    5684                 :            : {
    5685                 :            :         uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
    5686                 :            : 
    5687                 :          0 :         val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
    5688                 :            :                  IGU_PF_CONF_INT_LINE_EN | IGU_PF_CONF_ATTN_BIT_EN);
    5689                 :            : 
    5690                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "write %x to IGU", val);
    5691                 :            : 
    5692                 :            :         /* flush all outstanding writes */
    5693                 :            :         mb();
    5694                 :            : 
    5695                 :            :         REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
    5696         [ #  # ]:          0 :         if (REG_RD(sc, IGU_REG_PF_CONFIGURATION) != val) {
    5697                 :          0 :                 PMD_DRV_LOG(ERR, sc, "proper val not read from IGU!");
    5698                 :            :         }
    5699                 :          0 : }
    5700                 :            : 
    5701                 :          0 : static void bnx2x_int_disable(struct bnx2x_softc *sc)
    5702                 :            : {
    5703         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
    5704                 :          0 :                 bnx2x_hc_int_disable(sc);
    5705                 :            :         } else {
    5706                 :          0 :                 bnx2x_igu_int_disable(sc);
    5707                 :            :         }
    5708                 :          0 : }
    5709                 :            : 
    5710                 :          0 : static void bnx2x_nic_init(struct bnx2x_softc *sc, int load_code)
    5711                 :            : {
    5712                 :            :         int i;
    5713                 :            : 
    5714                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    5715                 :            : 
    5716         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    5717                 :          0 :                 bnx2x_init_eth_fp(sc, i);
    5718                 :            :         }
    5719                 :            : 
    5720                 :            :         rmb();                  /* ensure status block indices were read */
    5721                 :            : 
    5722                 :          0 :         bnx2x_init_rx_rings(sc);
    5723                 :          0 :         bnx2x_init_tx_rings(sc);
    5724                 :            : 
    5725         [ #  # ]:          0 :         if (IS_VF(sc)) {
    5726                 :          0 :                 bnx2x_memset_stats(sc);
    5727                 :          0 :                 return;
    5728                 :            :         }
    5729                 :            : 
    5730                 :            :         /* initialize MOD_ABS interrupts */
    5731                 :          0 :         elink_init_mod_abs_int(sc, &sc->link_vars,
    5732                 :            :                                sc->devinfo.chip_id,
    5733                 :            :                                sc->devinfo.shmem_base,
    5734                 :          0 :                                sc->devinfo.shmem2_base, SC_PORT(sc));
    5735                 :            : 
    5736                 :          0 :         bnx2x_init_def_sb(sc);
    5737                 :            :         bnx2x_update_dsb_idx(sc);
    5738                 :            :         bnx2x_init_sp_ring(sc);
    5739                 :            :         bnx2x_init_eq_ring(sc);
    5740                 :          0 :         bnx2x_init_internal(sc, load_code);
    5741                 :          0 :         bnx2x_pf_init(sc);
    5742                 :          0 :         bnx2x_stats_init(sc);
    5743                 :            : 
    5744                 :            :         /* flush all before enabling interrupts */
    5745                 :            :         mb();
    5746                 :            : 
    5747                 :          0 :         bnx2x_int_enable(sc);
    5748                 :            : 
    5749                 :            :         /* check for SPIO5 */
    5750                 :          0 :         bnx2x_attn_int_deasserted0(sc,
    5751                 :          0 :                                  REG_RD(sc,
    5752                 :            :                                         (MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
    5753                 :            :                                          SC_PORT(sc) * 4)) &
    5754                 :            :                                  AEU_INPUTS_ATTN_BITS_SPIO5);
    5755                 :            : }
    5756                 :            : 
    5757                 :          0 : static void bnx2x_init_objs(struct bnx2x_softc *sc)
    5758                 :            : {
    5759                 :            :         /* mcast rules must be added to tx if tx switching is enabled */
    5760                 :            :         ecore_obj_type o_type;
    5761         [ #  # ]:          0 :         if (sc->flags & BNX2X_TX_SWITCHING)
    5762                 :            :                 o_type = ECORE_OBJ_TYPE_RX_TX;
    5763                 :            :         else
    5764                 :            :                 o_type = ECORE_OBJ_TYPE_RX;
    5765                 :            : 
    5766                 :            :         /* RX_MODE controlling object */
    5767                 :          0 :         ecore_init_rx_mode_obj(sc, &sc->rx_mode_obj);
    5768                 :            : 
    5769                 :            :         /* multicast configuration controlling object */
    5770                 :          0 :         ecore_init_mcast_obj(sc,
    5771                 :            :                              &sc->mcast_obj,
    5772                 :          0 :                              sc->fp[0].cl_id,
    5773                 :          0 :                              sc->fp[0].index,
    5774                 :            :                              SC_FUNC(sc),
    5775                 :          0 :                              SC_FUNC(sc),
    5776                 :          0 :                              BNX2X_SP(sc, mcast_rdata),
    5777                 :          0 :                              (rte_iova_t)BNX2X_SP_MAPPING(sc, mcast_rdata),
    5778                 :            :                              ECORE_FILTER_MCAST_PENDING,
    5779                 :            :                              &sc->sp_state, o_type);
    5780                 :            : 
    5781                 :            :         /* Setup CAM credit pools */
    5782                 :          0 :         ecore_init_mac_credit_pool(sc,
    5783                 :            :                                    &sc->macs_pool,
    5784                 :          0 :                                    SC_FUNC(sc),
    5785         [ #  # ]:          0 :                                    CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
    5786         [ #  # ]:          0 :                                    VNICS_PER_PATH(sc));
    5787                 :            : 
    5788                 :          0 :         ecore_init_vlan_credit_pool(sc,
    5789                 :            :                                     &sc->vlans_pool,
    5790                 :          0 :                                     SC_ABS_FUNC(sc) >> 1,
    5791         [ #  # ]:          0 :                                     CHIP_IS_E1x(sc) ? VNICS_PER_PORT(sc) :
    5792         [ #  # ]:          0 :                                     VNICS_PER_PATH(sc));
    5793                 :            : 
    5794                 :            :         /* RSS configuration object */
    5795                 :          0 :         ecore_init_rss_config_obj(sc, &sc->rss_conf_obj, sc->fp->cl_id,
    5796                 :          0 :                                   sc->fp->index, SC_FUNC(sc), SC_FUNC(sc),
    5797                 :          0 :                                   BNX2X_SP(sc, rss_rdata),
    5798                 :          0 :                                   (rte_iova_t)BNX2X_SP_MAPPING(sc, rss_rdata),
    5799                 :            :                                   ECORE_FILTER_RSS_CONF_PENDING, &sc->sp_state,
    5800                 :            :                                   ECORE_OBJ_TYPE_RX);
    5801                 :          0 : }
    5802                 :            : 
    5803                 :            : /*
    5804                 :            :  * Initialize the function. This must be called before sending CLIENT_SETUP
    5805                 :            :  * for the first client.
    5806                 :            :  */
    5807                 :          0 : static int bnx2x_func_start(struct bnx2x_softc *sc)
    5808                 :            : {
    5809         [ #  # ]:          0 :         struct ecore_func_state_params func_params = { NULL };
    5810                 :            :         struct ecore_func_start_params *start_params =
    5811                 :            :             &func_params.params.start;
    5812                 :            : 
    5813                 :            :         /* Prepare parameters for function state transitions */
    5814                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
    5815                 :            : 
    5816                 :          0 :         func_params.f_obj = &sc->func_obj;
    5817                 :          0 :         func_params.cmd = ECORE_F_CMD_START;
    5818                 :            : 
    5819                 :            :         /* Function parameters */
    5820                 :          0 :         start_params->mf_mode = sc->devinfo.mf_info.mf_mode;
    5821                 :          0 :         start_params->sd_vlan_tag = OVLAN(sc);
    5822                 :            : 
    5823   [ #  #  #  # ]:          0 :         if (CHIP_IS_E2(sc) || CHIP_IS_E3(sc)) {
    5824                 :          0 :                 start_params->network_cos_mode = STATIC_COS;
    5825                 :            :         } else {                /* CHIP_IS_E1X */
    5826                 :          0 :                 start_params->network_cos_mode = FW_WRR;
    5827                 :            :         }
    5828                 :            : 
    5829                 :          0 :         return ecore_func_state_change(sc, &func_params);
    5830                 :            : }
    5831                 :            : 
    5832                 :          0 : static int bnx2x_set_power_state(struct bnx2x_softc *sc, uint8_t state)
    5833                 :            : {
    5834                 :            :         uint16_t pmcsr;
    5835                 :            : 
    5836                 :            :         /* If there is no power capability, silently succeed */
    5837         [ #  # ]:          0 :         if (!(sc->devinfo.pcie_cap_flags & BNX2X_PM_CAPABLE_FLAG)) {
    5838                 :          0 :                 PMD_DRV_LOG(INFO, sc, "No power capability");
    5839                 :          0 :                 return 0;
    5840                 :            :         }
    5841                 :            : 
    5842                 :          0 :         pci_read(sc, (sc->devinfo.pcie_pm_cap_reg + RTE_PCI_PM_CTRL), &pmcsr,
    5843                 :            :                  2);
    5844                 :            : 
    5845      [ #  #  # ]:          0 :         switch (state) {
    5846                 :          0 :         case PCI_PM_D0:
    5847                 :          0 :                 pci_write_word(sc, (sc->devinfo.pcie_pm_cap_reg + RTE_PCI_PM_CTRL),
    5848                 :          0 :                         ((pmcsr & ~RTE_PCI_PM_CTRL_STATE_MASK) | RTE_PCI_PM_CTRL_PME_STATUS));
    5849                 :            : 
    5850         [ #  # ]:          0 :                 if (pmcsr & RTE_PCI_PM_CTRL_STATE_MASK) {
    5851                 :            :                         /* delay required during transition out of D3hot */
    5852                 :          0 :                         DELAY(20000);
    5853                 :            :                 }
    5854                 :            : 
    5855                 :            :                 break;
    5856                 :            : 
    5857                 :          0 :         case PCI_PM_D3hot:
    5858                 :            :                 /* don't shut down the power for emulation and FPGA */
    5859         [ #  # ]:          0 :                 if (CHIP_REV_IS_SLOW(sc)) {
    5860                 :            :                         return 0;
    5861                 :            :                 }
    5862                 :            : 
    5863                 :          0 :                 pmcsr &= ~RTE_PCI_PM_CTRL_STATE_MASK;
    5864                 :            :                 /* D3 power state */
    5865                 :          0 :                 pmcsr |= 0x3;
    5866                 :            : 
    5867         [ #  # ]:          0 :                 if (sc->wol) {
    5868                 :          0 :                         pmcsr |= RTE_PCI_PM_CTRL_PME_ENABLE;
    5869                 :            :                 }
    5870                 :            : 
    5871                 :          0 :                 pci_write_long(sc,
    5872                 :          0 :                                (sc->devinfo.pcie_pm_cap_reg +
    5873                 :            :                                 RTE_PCI_PM_CTRL), pmcsr);
    5874                 :            : 
    5875                 :            :                 /*
    5876                 :            :                  * No more memory access after this point until device is brought back
    5877                 :            :                  * to D0 state.
    5878                 :            :                  */
    5879                 :          0 :                 break;
    5880                 :            : 
    5881                 :          0 :         default:
    5882                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Can't support PCI power state = %d",
    5883                 :            :                             state);
    5884                 :          0 :                 return -1;
    5885                 :            :         }
    5886                 :            : 
    5887                 :            :         return 0;
    5888                 :            : }
    5889                 :            : 
    5890                 :            : /* return true if succeeded to acquire the lock */
    5891                 :          0 : static uint8_t bnx2x_trylock_hw_lock(struct bnx2x_softc *sc, uint32_t resource)
    5892                 :            : {
    5893                 :            :         uint32_t lock_status;
    5894                 :          0 :         uint32_t resource_bit = (1 << resource);
    5895                 :          0 :         int func = SC_FUNC(sc);
    5896                 :            :         uint32_t hw_lock_control_reg;
    5897                 :            : 
    5898                 :            :         /* Validating that the resource is within range */
    5899         [ #  # ]:          0 :         if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
    5900                 :          0 :                 PMD_DRV_LOG(INFO, sc,
    5901                 :            :                             "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)",
    5902                 :            :                             resource, HW_LOCK_MAX_RESOURCE_VALUE);
    5903                 :          0 :                 return FALSE;
    5904                 :            :         }
    5905                 :            : 
    5906         [ #  # ]:          0 :         if (func <= 5) {
    5907                 :          0 :                 hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func * 8);
    5908                 :            :         } else {
    5909                 :          0 :                 hw_lock_control_reg =
    5910                 :          0 :                     (MISC_REG_DRIVER_CONTROL_7 + (func - 6) * 8);
    5911                 :            :         }
    5912                 :            : 
    5913                 :            :         /* try to acquire the lock */
    5914                 :          0 :         REG_WR(sc, hw_lock_control_reg + 4, resource_bit);
    5915                 :          0 :         lock_status = REG_RD(sc, hw_lock_control_reg);
    5916         [ #  # ]:          0 :         if (lock_status & resource_bit) {
    5917                 :            :                 return TRUE;
    5918                 :            :         }
    5919                 :            : 
    5920                 :          0 :         PMD_DRV_LOG(NOTICE, sc, "Failed to get a resource lock 0x%x", resource);
    5921                 :            : 
    5922                 :          0 :         return FALSE;
    5923                 :            : }
    5924                 :            : 
    5925                 :            : /*
    5926                 :            :  * Get the recovery leader resource id according to the engine this function
    5927                 :            :  * belongs to. Currently only 2 engines are supported.
    5928                 :            :  */
    5929                 :            : static int bnx2x_get_leader_lock_resource(struct bnx2x_softc *sc)
    5930                 :            : {
    5931   [ #  #  #  # ]:          0 :         if (SC_PATH(sc)) {
    5932                 :            :                 return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
    5933                 :            :         } else {
    5934                 :          0 :                 return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
    5935                 :            :         }
    5936                 :            : }
    5937                 :            : 
    5938                 :            : /* try to acquire a leader lock for current engine */
    5939                 :            : static uint8_t bnx2x_trylock_leader_lock(struct bnx2x_softc *sc)
    5940                 :            : {
    5941                 :          0 :         return bnx2x_trylock_hw_lock(sc, bnx2x_get_leader_lock_resource(sc));
    5942                 :            : }
    5943                 :            : 
    5944                 :            : static int bnx2x_release_leader_lock(struct bnx2x_softc *sc)
    5945                 :            : {
    5946                 :          0 :         return bnx2x_release_hw_lock(sc, bnx2x_get_leader_lock_resource(sc));
    5947                 :            : }
    5948                 :            : 
    5949                 :            : /* close gates #2, #3 and #4 */
    5950                 :          0 : static void bnx2x_set_234_gates(struct bnx2x_softc *sc, uint8_t close)
    5951                 :            : {
    5952                 :            :         uint32_t val;
    5953                 :            : 
    5954                 :            :         /* gates #2 and #4a are closed/opened */
    5955                 :            :         /* #4 */
    5956                 :          0 :         REG_WR(sc, PXP_REG_HST_DISCARD_DOORBELLS, ! !close);
    5957                 :            :         /* #2 */
    5958                 :            :         REG_WR(sc, PXP_REG_HST_DISCARD_INTERNAL_WRITES, ! !close);
    5959                 :            : 
    5960                 :            :         /* #3 */
    5961         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
    5962                 :            : /* prevent interrupts from HC on both ports */
    5963                 :            :                 val = REG_RD(sc, HC_REG_CONFIG_1);
    5964         [ #  # ]:          0 :                 if (close)
    5965                 :          0 :                         REG_WR(sc, HC_REG_CONFIG_1, (val & ~(uint32_t)
    5966                 :            :                                                      HC_CONFIG_1_REG_BLOCK_DISABLE_1));
    5967                 :            :                 else
    5968                 :          0 :                         REG_WR(sc, HC_REG_CONFIG_1,
    5969                 :            :                                (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1));
    5970                 :            : 
    5971                 :            :                 val = REG_RD(sc, HC_REG_CONFIG_0);
    5972         [ #  # ]:          0 :                 if (close)
    5973                 :          0 :                         REG_WR(sc, HC_REG_CONFIG_0, (val & ~(uint32_t)
    5974                 :            :                                                      HC_CONFIG_0_REG_BLOCK_DISABLE_0));
    5975                 :            :                 else
    5976                 :          0 :                         REG_WR(sc, HC_REG_CONFIG_0,
    5977                 :            :                                (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0));
    5978                 :            : 
    5979                 :            :         } else {
    5980                 :            : /* Prevent incoming interrupts in IGU */
    5981                 :            :                 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
    5982                 :            : 
    5983         [ #  # ]:          0 :                 if (close)
    5984                 :          0 :                         REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
    5985                 :            :                                (val & ~(uint32_t)
    5986                 :            :                                 IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
    5987                 :            :                 else
    5988                 :          0 :                         REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION,
    5989                 :            :                                (val |
    5990                 :            :                                 IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
    5991                 :            :         }
    5992                 :            : 
    5993                 :            :         wmb();
    5994                 :          0 : }
    5995                 :            : 
    5996                 :            : /* poll for pending writes bit, it should get cleared in no more than 1s */
    5997                 :          0 : static int bnx2x_er_poll_igu_vq(struct bnx2x_softc *sc)
    5998                 :            : {
    5999                 :            :         uint32_t cnt = 1000;
    6000                 :            :         uint32_t pend_bits = 0;
    6001                 :            : 
    6002                 :            :         do {
    6003                 :            :                 pend_bits = REG_RD(sc, IGU_REG_PENDING_BITS_STATUS);
    6004                 :            : 
    6005         [ #  # ]:          0 :                 if (pend_bits == 0) {
    6006                 :            :                         break;
    6007                 :            :                 }
    6008                 :            : 
    6009                 :          0 :                 DELAY(1000);
    6010         [ #  # ]:          0 :         } while (cnt-- > 0);
    6011                 :            : 
    6012         [ #  # ]:          0 :         if (cnt <= 0) {
    6013                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Still pending IGU requests bits=0x%08x!",
    6014                 :            :                             pend_bits);
    6015                 :          0 :                 return -1;
    6016                 :            :         }
    6017                 :            : 
    6018                 :            :         return 0;
    6019                 :            : }
    6020                 :            : 
    6021                 :            : #define SHARED_MF_CLP_MAGIC  0x80000000 /* 'magic' bit */
    6022                 :            : 
    6023                 :            : static void bnx2x_clp_reset_prep(struct bnx2x_softc *sc, uint32_t * magic_val)
    6024                 :            : {
    6025                 :            :         /* Do some magic... */
    6026                 :          0 :         uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
    6027                 :          0 :         *magic_val = val & SHARED_MF_CLP_MAGIC;
    6028                 :          0 :         MFCFG_WR(sc, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
    6029                 :            : }
    6030                 :            : 
    6031                 :            : /* restore the value of the 'magic' bit */
    6032                 :            : static void bnx2x_clp_reset_done(struct bnx2x_softc *sc, uint32_t magic_val)
    6033                 :            : {
    6034                 :            :         /* Restore the 'magic' bit value... */
    6035                 :          0 :         uint32_t val = MFCFG_RD(sc, shared_mf_config.clp_mb);
    6036                 :          0 :         MFCFG_WR(sc, shared_mf_config.clp_mb,
    6037                 :            :                  (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
    6038                 :            : }
    6039                 :            : 
    6040                 :            : /* prepare for MCP reset, takes care of CLP configurations */
    6041                 :          0 : static void bnx2x_reset_mcp_prep(struct bnx2x_softc *sc, uint32_t * magic_val)
    6042                 :            : {
    6043                 :            :         uint32_t shmem;
    6044                 :            :         uint32_t validity_offset;
    6045                 :            : 
    6046                 :            :         /* set `magic' bit in order to save MF config */
    6047                 :            :         bnx2x_clp_reset_prep(sc, magic_val);
    6048                 :            : 
    6049                 :            :         /* get shmem offset */
    6050                 :            :         shmem = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
    6051                 :          0 :         validity_offset =
    6052                 :          0 :             offsetof(struct shmem_region, validity_map[SC_PORT(sc)]);
    6053                 :            : 
    6054                 :            :         /* Clear validity map flags */
    6055         [ #  # ]:          0 :         if (shmem > 0) {
    6056                 :          0 :                 REG_WR(sc, shmem + validity_offset, 0);
    6057                 :            :         }
    6058                 :          0 : }
    6059                 :            : 
    6060                 :            : #define MCP_TIMEOUT      5000   /* 5 seconds (in ms) */
    6061                 :            : #define MCP_ONE_TIMEOUT  100    /* 100 ms */
    6062                 :            : 
    6063                 :            : static void bnx2x_mcp_wait_one(struct bnx2x_softc *sc)
    6064                 :            : {
    6065                 :            :         /* special handling for emulation and FPGA (10 times longer) */
    6066         [ #  # ]:          0 :         if (CHIP_REV_IS_SLOW(sc)) {
    6067                 :          0 :                 DELAY((MCP_ONE_TIMEOUT * 10) * 1000);
    6068                 :            :         } else {
    6069                 :          0 :                 DELAY((MCP_ONE_TIMEOUT) * 1000);
    6070                 :            :         }
    6071                 :            : }
    6072                 :            : 
    6073                 :            : /* initialize shmem_base and waits for validity signature to appear */
    6074                 :          0 : static int bnx2x_init_shmem(struct bnx2x_softc *sc)
    6075                 :            : {
    6076                 :            :         int cnt = 0;
    6077                 :            :         uint32_t val = 0;
    6078                 :            : 
    6079                 :            :         do {
    6080                 :          0 :                 sc->devinfo.shmem_base =
    6081                 :          0 :                     sc->link_params.shmem_base =
    6082                 :            :                     REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
    6083                 :            : 
    6084         [ #  # ]:          0 :                 if (sc->devinfo.shmem_base) {
    6085                 :          0 :                         val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
    6086         [ #  # ]:          0 :                         if (val & SHR_MEM_VALIDITY_MB)
    6087                 :            :                                 return 0;
    6088                 :            :                 }
    6089                 :            : 
    6090                 :            :                 bnx2x_mcp_wait_one(sc);
    6091                 :            : 
    6092         [ #  # ]:          0 :         } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
    6093                 :            : 
    6094                 :          0 :         PMD_DRV_LOG(NOTICE, sc, "BAD MCP validity signature");
    6095                 :            : 
    6096                 :          0 :         return -1;
    6097                 :            : }
    6098                 :            : 
    6099                 :          0 : static int bnx2x_reset_mcp_comp(struct bnx2x_softc *sc, uint32_t magic_val)
    6100                 :            : {
    6101                 :          0 :         int rc = bnx2x_init_shmem(sc);
    6102                 :            : 
    6103                 :            :         /* Restore the `magic' bit value */
    6104                 :            :         bnx2x_clp_reset_done(sc, magic_val);
    6105                 :            : 
    6106                 :          0 :         return rc;
    6107                 :            : }
    6108                 :            : 
    6109                 :            : static void bnx2x_pxp_prep(struct bnx2x_softc *sc)
    6110                 :            : {
    6111                 :            :         REG_WR(sc, PXP2_REG_RD_START_INIT, 0);
    6112                 :            :         REG_WR(sc, PXP2_REG_RQ_RBC_DONE, 0);
    6113                 :            :         wmb();
    6114                 :            : }
    6115                 :            : 
    6116                 :            : /*
    6117                 :            :  * Reset the whole chip except for:
    6118                 :            :  *      - PCIE core
    6119                 :            :  *      - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by one reset bit)
    6120                 :            :  *      - IGU
    6121                 :            :  *      - MISC (including AEU)
    6122                 :            :  *      - GRC
    6123                 :            :  *      - RBCN, RBCP
    6124                 :            :  */
    6125                 :          0 : static void bnx2x_process_kill_chip_reset(struct bnx2x_softc *sc, uint8_t global)
    6126                 :            : {
    6127                 :            :         uint32_t not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
    6128                 :            :         uint32_t global_bits2, stay_reset2;
    6129                 :            : 
    6130                 :            :         /*
    6131                 :            :          * Bits that have to be set in reset_mask2 if we want to reset 'global'
    6132                 :            :          * (per chip) blocks.
    6133                 :            :          */
    6134                 :            :         global_bits2 =
    6135                 :            :             MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
    6136                 :            :             MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
    6137                 :            : 
    6138                 :            :         /*
    6139                 :            :          * Don't reset the following blocks.
    6140                 :            :          * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
    6141                 :            :          *            reset, as in 4 port device they might still be owned
    6142                 :            :          *            by the MCP (there is only one leader per path).
    6143                 :            :          */
    6144                 :            :         not_reset_mask1 =
    6145                 :            :             MISC_REGISTERS_RESET_REG_1_RST_HC |
    6146                 :            :             MISC_REGISTERS_RESET_REG_1_RST_PXPV |
    6147                 :            :             MISC_REGISTERS_RESET_REG_1_RST_PXP;
    6148                 :            : 
    6149                 :            :         not_reset_mask2 =
    6150                 :            :             MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
    6151                 :            :             MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
    6152                 :            :             MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
    6153                 :            :             MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
    6154                 :            :             MISC_REGISTERS_RESET_REG_2_RST_RBCN |
    6155                 :            :             MISC_REGISTERS_RESET_REG_2_RST_GRC |
    6156                 :            :             MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
    6157                 :            :             MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
    6158                 :            :             MISC_REGISTERS_RESET_REG_2_RST_ATC |
    6159                 :            :             MISC_REGISTERS_RESET_REG_2_PGLC |
    6160                 :            :             MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
    6161                 :            :             MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
    6162                 :            :             MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
    6163                 :            :             MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
    6164                 :            :             MISC_REGISTERS_RESET_REG_2_UMAC0 | MISC_REGISTERS_RESET_REG_2_UMAC1;
    6165                 :            : 
    6166                 :            :         /*
    6167                 :            :          * Keep the following blocks in reset:
    6168                 :            :          *  - all xxMACs are handled by the elink code.
    6169                 :            :          */
    6170                 :            :         stay_reset2 =
    6171                 :            :             MISC_REGISTERS_RESET_REG_2_XMAC |
    6172                 :            :             MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
    6173                 :            : 
    6174                 :            :         /* Full reset masks according to the chip */
    6175                 :            :         reset_mask1 = 0xffffffff;
    6176                 :            : 
    6177         [ #  # ]:          0 :         if (CHIP_IS_E1H(sc))
    6178                 :            :                 reset_mask2 = 0x1ffff;
    6179         [ #  # ]:          0 :         else if (CHIP_IS_E2(sc))
    6180                 :            :                 reset_mask2 = 0xfffff;
    6181                 :            :         else                    /* CHIP_IS_E3 */
    6182                 :            :                 reset_mask2 = 0x3ffffff;
    6183                 :            : 
    6184                 :            :         /* Don't reset global blocks unless we need to */
    6185         [ #  # ]:          0 :         if (!global)
    6186                 :          0 :                 reset_mask2 &= ~global_bits2;
    6187                 :            : 
    6188                 :            :         /*
    6189                 :            :          * In case of attention in the QM, we need to reset PXP
    6190                 :            :          * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
    6191                 :            :          * because otherwise QM reset would release 'close the gates' shortly
    6192                 :            :          * before resetting the PXP, then the PSWRQ would send a write
    6193                 :            :          * request to PGLUE. Then when PXP is reset, PGLUE would try to
    6194                 :            :          * read the payload data from PSWWR, but PSWWR would not
    6195                 :            :          * respond. The write queue in PGLUE would stuck, dmae commands
    6196                 :            :          * would not return. Therefore it's important to reset the second
    6197                 :            :          * reset register (containing the
    6198                 :            :          * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
    6199                 :            :          * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
    6200                 :            :          * bit).
    6201                 :            :          */
    6202                 :          0 :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
    6203                 :            :                reset_mask2 & (~not_reset_mask2));
    6204                 :            : 
    6205                 :            :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
    6206                 :            :                reset_mask1 & (~not_reset_mask1));
    6207                 :            : 
    6208                 :            :         mb();
    6209                 :            :         wmb();
    6210                 :            : 
    6211                 :          0 :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
    6212                 :            :                reset_mask2 & (~stay_reset2));
    6213                 :            : 
    6214                 :            :         mb();
    6215                 :            :         wmb();
    6216                 :            : 
    6217                 :            :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
    6218                 :            :         wmb();
    6219                 :          0 : }
    6220                 :            : 
    6221                 :          0 : static int bnx2x_process_kill(struct bnx2x_softc *sc, uint8_t global)
    6222                 :            : {
    6223                 :            :         int cnt = 1000;
    6224                 :          0 :         uint32_t val = 0;
    6225                 :            :         uint32_t sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
    6226                 :            :         uint32_t tags_63_32 = 0;
    6227                 :            : 
    6228                 :            :         /* Empty the Tetris buffer, wait for 1s */
    6229                 :            :         do {
    6230                 :            :                 sr_cnt = REG_RD(sc, PXP2_REG_RD_SR_CNT);
    6231                 :            :                 blk_cnt = REG_RD(sc, PXP2_REG_RD_BLK_CNT);
    6232                 :            :                 port_is_idle_0 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_0);
    6233                 :            :                 port_is_idle_1 = REG_RD(sc, PXP2_REG_RD_PORT_IS_IDLE_1);
    6234                 :            :                 pgl_exp_rom2 = REG_RD(sc, PXP2_REG_PGL_EXP_ROM2);
    6235         [ #  # ]:          0 :                 if (CHIP_IS_E3(sc)) {
    6236                 :            :                         tags_63_32 = REG_RD(sc, PGLUE_B_REG_TAGS_63_32);
    6237                 :            :                 }
    6238                 :            : 
    6239         [ #  # ]:          0 :                 if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
    6240         [ #  # ]:          0 :                     ((port_is_idle_0 & 0x1) == 0x1) &&
    6241   [ #  #  #  # ]:          0 :                     ((port_is_idle_1 & 0x1) == 0x1) &&
    6242                 :          0 :                     (pgl_exp_rom2 == 0xffffffff) &&
    6243   [ #  #  #  #  :          0 :                     (!CHIP_IS_E3(sc) || (tags_63_32 == 0xffffffff)))
          #  #  #  #  #  
                #  #  # ]
    6244                 :            :                         break;
    6245                 :          0 :                 DELAY(1000);
    6246         [ #  # ]:          0 :         } while (cnt-- > 0);
    6247                 :            : 
    6248         [ #  # ]:          0 :         if (cnt <= 0) {
    6249                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    6250                 :            :                             "ERROR: Tetris buffer didn't get empty or there "
    6251                 :            :                             "are still outstanding read requests after 1s! "
    6252                 :            :                             "sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, "
    6253                 :            :                             "port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x",
    6254                 :            :                             sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
    6255                 :            :                             pgl_exp_rom2);
    6256                 :          0 :                 return -1;
    6257                 :            :         }
    6258                 :            : 
    6259                 :            :         mb();
    6260                 :            : 
    6261                 :            :         /* Close gates #2, #3 and #4 */
    6262                 :          0 :         bnx2x_set_234_gates(sc, TRUE);
    6263                 :            : 
    6264                 :            :         /* Poll for IGU VQs for 57712 and newer chips */
    6265   [ #  #  #  # ]:          0 :         if (!CHIP_IS_E1x(sc) && bnx2x_er_poll_igu_vq(sc)) {
    6266                 :            :                 return -1;
    6267                 :            :         }
    6268                 :            : 
    6269                 :            :         /* clear "unprepared" bit */
    6270                 :            :         REG_WR(sc, MISC_REG_UNPREPARED, 0);
    6271                 :            :         mb();
    6272                 :            : 
    6273                 :            :         /* Make sure all is written to the chip before the reset */
    6274                 :            :         wmb();
    6275                 :            : 
    6276                 :            :         /*
    6277                 :            :          * Wait for 1ms to empty GLUE and PCI-E core queues,
    6278                 :            :          * PSWHST, GRC and PSWRD Tetris buffer.
    6279                 :            :          */
    6280                 :          0 :         DELAY(1000);
    6281                 :            : 
    6282                 :            :         /* Prepare to chip reset: */
    6283                 :            :         /* MCP */
    6284         [ #  # ]:          0 :         if (global) {
    6285                 :          0 :                 bnx2x_reset_mcp_prep(sc, &val);
    6286                 :            :         }
    6287                 :            : 
    6288                 :            :         /* PXP */
    6289                 :            :         bnx2x_pxp_prep(sc);
    6290                 :            :         mb();
    6291                 :            : 
    6292                 :            :         /* reset the chip */
    6293                 :          0 :         bnx2x_process_kill_chip_reset(sc, global);
    6294                 :            :         mb();
    6295                 :            : 
    6296                 :            :         /* Recover after reset: */
    6297                 :            :         /* MCP */
    6298   [ #  #  #  # ]:          0 :         if (global && bnx2x_reset_mcp_comp(sc, val)) {
    6299                 :            :                 return -1;
    6300                 :            :         }
    6301                 :            : 
    6302                 :            :         /* Open the gates #2, #3 and #4 */
    6303                 :          0 :         bnx2x_set_234_gates(sc, FALSE);
    6304                 :            : 
    6305                 :          0 :         return 0;
    6306                 :            : }
    6307                 :            : 
    6308                 :          0 : static int bnx2x_leader_reset(struct bnx2x_softc *sc)
    6309                 :            : {
    6310                 :            :         int rc = 0;
    6311                 :            :         uint8_t global = bnx2x_reset_is_global(sc);
    6312                 :            :         uint32_t load_code;
    6313                 :            : 
    6314                 :            :         /*
    6315                 :            :          * If not going to reset MCP, load "fake" driver to reset HW while
    6316                 :            :          * driver is owner of the HW.
    6317                 :            :          */
    6318         [ #  # ]:          0 :         if (!global && !BNX2X_NOMCP(sc)) {
    6319                 :            :                 load_code = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_REQ,
    6320                 :            :                                            DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
    6321         [ #  # ]:          0 :                 if (!load_code) {
    6322                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
    6323                 :            :                         rc = -1;
    6324                 :          0 :                         goto exit_leader_reset;
    6325                 :            :                 }
    6326                 :            : 
    6327                 :          0 :                 if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
    6328         [ #  # ]:          0 :                     (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
    6329                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    6330                 :            :                                     "MCP unexpected response, aborting");
    6331                 :            :                         rc = -1;
    6332                 :          0 :                         goto exit_leader_reset2;
    6333                 :            :                 }
    6334                 :            : 
    6335                 :            :                 load_code = bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
    6336         [ #  # ]:          0 :                 if (!load_code) {
    6337                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
    6338                 :            :                         rc = -1;
    6339                 :          0 :                         goto exit_leader_reset2;
    6340                 :            :                 }
    6341                 :            :         }
    6342                 :            : 
    6343                 :            :         /* try to recover after the failure */
    6344         [ #  # ]:          0 :         if (bnx2x_process_kill(sc, global)) {
    6345                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Something bad occurred on engine %d!",
    6346                 :            :                             SC_PATH(sc));
    6347                 :            :                 rc = -1;
    6348                 :          0 :                 goto exit_leader_reset2;
    6349                 :            :         }
    6350                 :            : 
    6351                 :            :         /*
    6352                 :            :          * Clear the RESET_IN_PROGRESS and RESET_GLOBAL bits and update the driver
    6353                 :            :          * state.
    6354                 :            :          */
    6355                 :          0 :         bnx2x_set_reset_done(sc);
    6356                 :            :         if (global) {
    6357                 :            :                 bnx2x_clear_reset_global(sc);
    6358                 :            :         }
    6359                 :            : 
    6360                 :          0 : exit_leader_reset2:
    6361                 :            : 
    6362                 :            :         /* unload "fake driver" if it was loaded */
    6363         [ #  # ]:          0 :         if (!global &&!BNX2X_NOMCP(sc)) {
    6364                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
    6365                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
    6366                 :            :         }
    6367                 :            : 
    6368                 :          0 : exit_leader_reset:
    6369                 :            : 
    6370         [ #  # ]:          0 :         sc->is_leader = 0;
    6371                 :            :         bnx2x_release_leader_lock(sc);
    6372                 :            : 
    6373                 :            :         mb();
    6374                 :          0 :         return rc;
    6375                 :            : }
    6376                 :            : 
    6377                 :            : /*
    6378                 :            :  * prepare INIT transition, parameters configured:
    6379                 :            :  *   - HC configuration
    6380                 :            :  *   - Queue's CDU context
    6381                 :            :  */
    6382                 :            : static void
    6383         [ #  # ]:          0 : bnx2x_pf_q_prep_init(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    6384                 :            :                    struct ecore_queue_init_params *init_params)
    6385                 :            : {
    6386                 :            :         uint8_t cos;
    6387                 :            :         int cxt_index, cxt_offset;
    6388                 :            : 
    6389                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_HC, &init_params->rx.flags);
    6390                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_HC, &init_params->tx.flags);
    6391                 :            : 
    6392                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_HC_EN, &init_params->rx.flags);
    6393                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_HC_EN, &init_params->tx.flags);
    6394                 :            : 
    6395                 :            :         /* HC rate */
    6396                 :          0 :         init_params->rx.hc_rate =
    6397         [ #  # ]:          0 :             sc->hc_rx_ticks ? (1000000 / sc->hc_rx_ticks) : 0;
    6398                 :          0 :         init_params->tx.hc_rate =
    6399         [ #  # ]:          0 :             sc->hc_tx_ticks ? (1000000 / sc->hc_tx_ticks) : 0;
    6400                 :            : 
    6401                 :            :         /* FW SB ID */
    6402                 :          0 :         init_params->rx.fw_sb_id = init_params->tx.fw_sb_id = fp->fw_sb_id;
    6403                 :            : 
    6404                 :            :         /* CQ index among the SB indices */
    6405                 :          0 :         init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
    6406                 :          0 :         init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
    6407                 :            : 
    6408                 :            :         /* set maximum number of COSs supported by this queue */
    6409                 :          0 :         init_params->max_cos = sc->max_cos;
    6410                 :            : 
    6411                 :            :         /* set the context pointers queue object */
    6412         [ #  # ]:          0 :         for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
    6413                 :          0 :                 cxt_index = fp->index / ILT_PAGE_CIDS;
    6414                 :          0 :                 cxt_offset = fp->index - (cxt_index * ILT_PAGE_CIDS);
    6415                 :          0 :                 init_params->cxts[cos] =
    6416                 :          0 :                     &sc->context[cxt_index].vcxt[cxt_offset].eth;
    6417                 :            :         }
    6418                 :          0 : }
    6419                 :            : 
    6420                 :            : /* set flags that are common for the Tx-only and not normal connections */
    6421                 :            : static unsigned long
    6422                 :          0 : bnx2x_get_common_flags(struct bnx2x_softc *sc, uint8_t zero_stats)
    6423                 :            : {
    6424         [ #  # ]:          0 :         uint32_t flags = 0;
    6425                 :            : 
    6426                 :            :         /* PF driver will always initialize the Queue to an ACTIVE state */
    6427                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_ACTIVE, &flags);
    6428                 :            : 
    6429                 :            :         /*
    6430                 :            :          * tx only connections collect statistics (on the same index as the
    6431                 :            :          * parent connection). The statistics are zeroed when the parent
    6432                 :            :          * connection is initialized.
    6433                 :            :          */
    6434                 :            : 
    6435                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_STATS, &flags);
    6436         [ #  # ]:          0 :         if (zero_stats) {
    6437                 :            :                 rte_bit_relaxed_set32(ECORE_Q_FLG_ZERO_STATS, &flags);
    6438                 :            :         }
    6439                 :            : 
    6440                 :            :         /*
    6441                 :            :          * tx only connections can support tx-switching, though their
    6442                 :            :          * CoS-ness doesn't survive the loopback
    6443                 :            :          */
    6444         [ #  # ]:          0 :         if (sc->flags & BNX2X_TX_SWITCHING) {
    6445                 :            :                 rte_bit_relaxed_set32(ECORE_Q_FLG_TX_SWITCH, &flags);
    6446                 :            :         }
    6447                 :            : 
    6448                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_PCSUM_ON_PKT, &flags);
    6449                 :            : 
    6450                 :          0 :         return flags;
    6451                 :            : }
    6452                 :            : 
    6453                 :          0 : static unsigned long bnx2x_get_q_flags(struct bnx2x_softc *sc, uint8_t leading)
    6454                 :            : {
    6455                 :          0 :         uint32_t flags = 0;
    6456                 :            : 
    6457   [ #  #  #  # ]:          0 :         if (IS_MF_SD(sc)) {
    6458                 :            :                 rte_bit_relaxed_set32(ECORE_Q_FLG_OV, &flags);
    6459                 :            :         }
    6460                 :            : 
    6461         [ #  # ]:          0 :         if (leading) {
    6462                 :            :                 rte_bit_relaxed_set32(ECORE_Q_FLG_LEADING_RSS, &flags);
    6463                 :            :                 rte_bit_relaxed_set32(ECORE_Q_FLG_MCAST, &flags);
    6464                 :            :         }
    6465                 :            : 
    6466                 :            :         rte_bit_relaxed_set32(ECORE_Q_FLG_VLAN, &flags);
    6467                 :            : 
    6468                 :            :         /* merge with common flags */
    6469                 :          0 :         return flags | bnx2x_get_common_flags(sc, TRUE);
    6470                 :            : }
    6471                 :            : 
    6472                 :            : static void
    6473                 :            : bnx2x_pf_q_prep_general(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    6474                 :            :                       struct ecore_general_setup_params *gen_init, uint8_t cos)
    6475                 :            : {
    6476                 :          0 :         gen_init->stat_id = bnx2x_stats_id(fp);
    6477                 :          0 :         gen_init->spcl_id = fp->cl_id;
    6478                 :          0 :         gen_init->mtu = sc->mtu;
    6479                 :            :         gen_init->cos = cos;
    6480                 :            : }
    6481                 :            : 
    6482                 :            : static void
    6483                 :          0 : bnx2x_pf_rx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    6484                 :            :                  struct rxq_pause_params *pause,
    6485                 :            :                  struct ecore_rxq_setup_params *rxq_init)
    6486                 :            : {
    6487                 :            :         struct bnx2x_rx_queue *rxq;
    6488                 :            : 
    6489                 :          0 :         rxq = sc->rx_queues[fp->index];
    6490         [ #  # ]:          0 :         if (!rxq) {
    6491                 :            :                 PMD_RX_LOG(ERR, "RX queue is NULL");
    6492                 :            :                 return;
    6493                 :            :         }
    6494                 :            :         /* pause */
    6495   [ #  #  #  # ]:          0 :         pause->bd_th_lo = BD_TH_LO(sc);
    6496   [ #  #  #  # ]:          0 :         pause->bd_th_hi = BD_TH_HI(sc);
    6497                 :            : 
    6498   [ #  #  #  # ]:          0 :         pause->rcq_th_lo = RCQ_TH_LO(sc);
    6499   [ #  #  #  # ]:          0 :         pause->rcq_th_hi = RCQ_TH_HI(sc);
    6500                 :            : 
    6501                 :            :         /* validate rings have enough entries to cross high thresholds */
    6502         [ #  # ]:          0 :         if (sc->dropless_fc &&
    6503         [ #  # ]:          0 :             pause->bd_th_hi + FW_PREFETCH_CNT > sc->rx_ring_size) {
    6504                 :          0 :                 PMD_DRV_LOG(WARNING, sc, "rx bd ring threshold limit");
    6505                 :            :         }
    6506                 :            : 
    6507         [ #  # ]:          0 :         if (sc->dropless_fc &&
    6508         [ #  # ]:          0 :             pause->rcq_th_hi + FW_PREFETCH_CNT > USABLE_RCQ_ENTRIES(rxq)) {
    6509                 :          0 :                 PMD_DRV_LOG(WARNING, sc, "rcq ring threshold limit");
    6510                 :            :         }
    6511                 :            : 
    6512                 :          0 :         pause->pri_map = 1;
    6513                 :            : 
    6514                 :            :         /* rxq setup */
    6515                 :          0 :         rxq_init->dscr_map = (rte_iova_t)rxq->rx_ring_phys_addr;
    6516                 :          0 :         rxq_init->rcq_map = (rte_iova_t)rxq->cq_ring_phys_addr;
    6517                 :          0 :         rxq_init->rcq_np_map = (rte_iova_t)(rxq->cq_ring_phys_addr +
    6518                 :            :                                               BNX2X_PAGE_SIZE);
    6519                 :            : 
    6520                 :            :         /*
    6521                 :            :          * This should be a maximum number of data bytes that may be
    6522                 :            :          * placed on the BD (not including paddings).
    6523                 :            :          */
    6524                 :          0 :         rxq_init->buf_sz = (fp->rx_buf_size - IP_HEADER_ALIGNMENT_PADDING);
    6525                 :            : 
    6526                 :          0 :         rxq_init->cl_qzone_id = fp->cl_qzone_id;
    6527                 :          0 :         rxq_init->rss_engine_id = SC_FUNC(sc);
    6528                 :          0 :         rxq_init->mcast_engine_id = SC_FUNC(sc);
    6529                 :            : 
    6530                 :          0 :         rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
    6531                 :          0 :         rxq_init->fw_sb_id = fp->fw_sb_id;
    6532                 :            : 
    6533                 :          0 :         rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
    6534                 :            : 
    6535                 :            :         /*
    6536                 :            :          * configure silent vlan removal
    6537                 :            :          * if multi function mode is afex, then mask default vlan
    6538                 :            :          */
    6539   [ #  #  #  # ]:          0 :         if (IS_MF_AFEX(sc)) {
    6540                 :          0 :                 rxq_init->silent_removal_value =
    6541                 :          0 :                     sc->devinfo.mf_info.afex_def_vlan_tag;
    6542                 :          0 :                 rxq_init->silent_removal_mask = EVL_VLID_MASK;
    6543                 :            :         }
    6544                 :            : }
    6545                 :            : 
    6546                 :            : static void
    6547                 :            : bnx2x_pf_tx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
    6548                 :            :                  struct ecore_txq_setup_params *txq_init, uint8_t cos)
    6549                 :            : {
    6550                 :          0 :         struct bnx2x_tx_queue *txq = fp->sc->tx_queues[fp->index];
    6551                 :            : 
    6552         [ #  # ]:          0 :         if (!txq) {
    6553                 :            :                 PMD_TX_LOG(ERR, "ERROR: TX queue is NULL");
    6554                 :            :                 return;
    6555                 :            :         }
    6556                 :          0 :         txq_init->dscr_map = (rte_iova_t)txq->tx_ring_phys_addr;
    6557                 :          0 :         txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
    6558                 :          0 :         txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
    6559                 :          0 :         txq_init->fw_sb_id = fp->fw_sb_id;
    6560                 :            : 
    6561                 :            :         /*
    6562                 :            :          * set the TSS leading client id for Tx classification to the
    6563                 :            :          * leading RSS client id
    6564                 :            :          */
    6565                 :          0 :         txq_init->tss_leading_cl_id = BNX2X_FP(sc, 0, cl_id);
    6566                 :            : }
    6567                 :            : 
    6568                 :            : /*
    6569                 :            :  * This function performs 2 steps in a queue state machine:
    6570                 :            :  *   1) RESET->INIT
    6571                 :            :  *   2) INIT->SETUP
    6572                 :            :  */
    6573                 :            : static int
    6574                 :          0 : bnx2x_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, uint8_t leading)
    6575                 :            : {
    6576                 :          0 :         struct ecore_queue_state_params q_params = { NULL };
    6577                 :            :         struct ecore_queue_setup_params *setup_params = &q_params.params.setup;
    6578                 :            :         int rc;
    6579                 :            : 
    6580                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "setting up queue %d", fp->index);
    6581                 :            : 
    6582                 :          0 :         bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
    6583                 :            : 
    6584                 :          0 :         q_params.q_obj = &BNX2X_SP_OBJ(sc, fp).q_obj;
    6585                 :            : 
    6586                 :            :         /* we want to wait for completion in this context */
    6587                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
    6588                 :            : 
    6589                 :            :         /* prepare the INIT parameters */
    6590                 :          0 :         bnx2x_pf_q_prep_init(sc, fp, &q_params.params.init);
    6591                 :            : 
    6592                 :            :         /* Set the command */
    6593                 :          0 :         q_params.cmd = ECORE_Q_CMD_INIT;
    6594                 :            : 
    6595                 :            :         /* Change the state to INIT */
    6596                 :          0 :         rc = ecore_queue_state_change(sc, &q_params);
    6597         [ #  # ]:          0 :         if (rc) {
    6598                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Queue(%d) INIT failed", fp->index);
    6599                 :          0 :                 return rc;
    6600                 :            :         }
    6601                 :            : 
    6602                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "init complete");
    6603                 :            : 
    6604                 :            :         /* now move the Queue to the SETUP state */
    6605                 :            :         memset(setup_params, 0, sizeof(*setup_params));
    6606                 :            : 
    6607                 :            :         /* set Queue flags */
    6608         [ #  # ]:          0 :         setup_params->flags = bnx2x_get_q_flags(sc, leading);
    6609                 :            : 
    6610                 :            :         /* set general SETUP parameters */
    6611                 :            :         bnx2x_pf_q_prep_general(sc, fp, &setup_params->gen_params,
    6612                 :            :                               FIRST_TX_COS_INDEX);
    6613                 :            : 
    6614                 :          0 :         bnx2x_pf_rx_q_prep(sc, fp,
    6615                 :            :                          &setup_params->pause_params,
    6616                 :            :                          &setup_params->rxq_params);
    6617                 :            : 
    6618                 :            :         bnx2x_pf_tx_q_prep(sc, fp, &setup_params->txq_params, FIRST_TX_COS_INDEX);
    6619                 :            : 
    6620                 :            :         /* Set the command */
    6621                 :          0 :         q_params.cmd = ECORE_Q_CMD_SETUP;
    6622                 :            : 
    6623                 :            :         /* change the state to SETUP */
    6624                 :          0 :         rc = ecore_queue_state_change(sc, &q_params);
    6625         [ #  # ]:          0 :         if (rc) {
    6626                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Queue(%d) SETUP failed", fp->index);
    6627                 :          0 :                 return rc;
    6628                 :            :         }
    6629                 :            : 
    6630                 :            :         return rc;
    6631                 :            : }
    6632                 :            : 
    6633                 :          0 : static int bnx2x_setup_leading(struct bnx2x_softc *sc)
    6634                 :            : {
    6635         [ #  # ]:          0 :         if (IS_PF(sc))
    6636                 :          0 :                 return bnx2x_setup_queue(sc, &sc->fp[0], TRUE);
    6637                 :            :         else                    /* VF */
    6638                 :          0 :                 return bnx2x_vf_setup_queue(sc, &sc->fp[0], TRUE);
    6639                 :            : }
    6640                 :            : 
    6641                 :            : static int
    6642                 :          0 : bnx2x_config_rss_pf(struct bnx2x_softc *sc, struct ecore_rss_config_obj *rss_obj,
    6643                 :            :                   uint8_t config_hash)
    6644                 :            : {
    6645                 :          0 :         struct ecore_config_rss_params params = { NULL };
    6646                 :            :         uint32_t i;
    6647                 :            : 
    6648                 :            :         /*
    6649                 :            :          * Although RSS is meaningless when there is a single HW queue we
    6650                 :            :          * still need it enabled in order to have HW Rx hash generated.
    6651                 :            :          */
    6652                 :            : 
    6653         [ #  # ]:          0 :         params.rss_obj = rss_obj;
    6654                 :            : 
    6655                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &params.ramrod_flags);
    6656                 :            : 
    6657                 :            :         rte_bit_relaxed_set32(ECORE_RSS_MODE_REGULAR, &params.rss_flags);
    6658                 :            : 
    6659                 :            :         /* RSS configuration */
    6660                 :            :         rte_bit_relaxed_set32(ECORE_RSS_IPV4, &params.rss_flags);
    6661                 :            :         rte_bit_relaxed_set32(ECORE_RSS_IPV4_TCP, &params.rss_flags);
    6662                 :            :         rte_bit_relaxed_set32(ECORE_RSS_IPV6, &params.rss_flags);
    6663                 :            :         rte_bit_relaxed_set32(ECORE_RSS_IPV6_TCP, &params.rss_flags);
    6664         [ #  # ]:          0 :         if (rss_obj->udp_rss_v4) {
    6665                 :            :                 rte_bit_relaxed_set32(ECORE_RSS_IPV4_UDP, &params.rss_flags);
    6666                 :            :         }
    6667         [ #  # ]:          0 :         if (rss_obj->udp_rss_v6) {
    6668                 :            :                 rte_bit_relaxed_set32(ECORE_RSS_IPV6_UDP, &params.rss_flags);
    6669                 :            :         }
    6670                 :            : 
    6671                 :            :         /* Hash bits */
    6672         [ #  # ]:          0 :         params.rss_result_mask = MULTI_MASK;
    6673                 :            : 
    6674                 :            :         rte_memcpy(params.ind_table, rss_obj->ind_table,
    6675                 :            :                          sizeof(params.ind_table));
    6676                 :            : 
    6677         [ #  # ]:          0 :         if (config_hash) {
    6678                 :            : /* RSS keys */
    6679         [ #  # ]:          0 :                 for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
    6680                 :          0 :                         params.rss_key[i] = (uint32_t) rte_rand();
    6681                 :            :                 }
    6682                 :            : 
    6683                 :            :                 rte_bit_relaxed_set32(ECORE_RSS_SET_SRCH, &params.rss_flags);
    6684                 :            :         }
    6685                 :            : 
    6686         [ #  # ]:          0 :         if (IS_PF(sc))
    6687                 :          0 :                 return ecore_config_rss(sc, &params);
    6688                 :            :         else
    6689                 :          0 :                 return bnx2x_vf_config_rss(sc, &params);
    6690                 :            : }
    6691                 :            : 
    6692                 :            : static int bnx2x_config_rss_eth(struct bnx2x_softc *sc, uint8_t config_hash)
    6693                 :            : {
    6694                 :          0 :         return bnx2x_config_rss_pf(sc, &sc->rss_conf_obj, config_hash);
    6695                 :            : }
    6696                 :            : 
    6697                 :          0 : static int bnx2x_init_rss_pf(struct bnx2x_softc *sc)
    6698                 :            : {
    6699                 :          0 :         uint8_t num_eth_queues = BNX2X_NUM_ETH_QUEUES(sc);
    6700                 :            :         uint32_t i;
    6701                 :            : 
    6702                 :            :         /*
    6703                 :            :          * Prepare the initial contents of the indirection table if
    6704                 :            :          * RSS is enabled
    6705                 :            :          */
    6706         [ #  # ]:          0 :         for (i = 0; i < sizeof(sc->rss_conf_obj.ind_table); i++) {
    6707                 :          0 :                 sc->rss_conf_obj.ind_table[i] =
    6708                 :          0 :                     (sc->fp->cl_id + (i % num_eth_queues));
    6709                 :            :         }
    6710                 :            : 
    6711         [ #  # ]:          0 :         if (sc->udp_rss) {
    6712                 :          0 :                 sc->rss_conf_obj.udp_rss_v4 = sc->rss_conf_obj.udp_rss_v6 = 1;
    6713                 :            :         }
    6714                 :            : 
    6715                 :            :         /*
    6716                 :            :          * For 57711 SEARCHER configuration (rss_keys) is
    6717                 :            :          * per-port, so if explicit configuration is needed, do it only
    6718                 :            :          * for a PMF.
    6719                 :            :          *
    6720                 :            :          * For 57712 and newer it's a per-function configuration.
    6721                 :            :          */
    6722   [ #  #  #  # ]:          0 :         return bnx2x_config_rss_eth(sc, sc->port.pmf || !CHIP_IS_E1x(sc));
    6723                 :            : }
    6724                 :            : 
    6725                 :            : static int
    6726         [ #  # ]:          0 : bnx2x_set_mac_one(struct bnx2x_softc *sc, uint8_t * mac,
    6727                 :            :                 struct ecore_vlan_mac_obj *obj, uint8_t set, int mac_type,
    6728                 :            :                 uint32_t *ramrod_flags)
    6729                 :            : {
    6730                 :            :         struct ecore_vlan_mac_ramrod_params ramrod_param;
    6731                 :            :         int rc;
    6732                 :            : 
    6733                 :            :         memset(&ramrod_param, 0, sizeof(ramrod_param));
    6734                 :            : 
    6735                 :            :         /* fill in general parameters */
    6736                 :          0 :         ramrod_param.vlan_mac_obj = obj;
    6737         [ #  # ]:          0 :         ramrod_param.ramrod_flags = *ramrod_flags;
    6738                 :            : 
    6739                 :            :         /* fill a user request section if needed */
    6740         [ #  # ]:          0 :         if (!rte_bit_relaxed_get32(RAMROD_CONT, ramrod_flags)) {
    6741                 :            :                 rte_memcpy(ramrod_param.user_req.u.mac.mac, mac,
    6742                 :            :                                  ETH_ALEN);
    6743                 :            : 
    6744                 :          0 :                 rte_bit_relaxed_set32(mac_type,
    6745                 :            :                                       &ramrod_param.user_req.vlan_mac_flags);
    6746                 :            : 
    6747                 :            : /* Set the command: ADD or DEL */
    6748                 :          0 :                 ramrod_param.user_req.cmd = (set) ? ECORE_VLAN_MAC_ADD :
    6749                 :            :                     ECORE_VLAN_MAC_DEL;
    6750                 :            :         }
    6751                 :            : 
    6752                 :          0 :         rc = ecore_config_vlan_mac(sc, &ramrod_param);
    6753                 :            : 
    6754         [ #  # ]:          0 :         if (rc == ECORE_EXISTS) {
    6755                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Failed to schedule ADD operations (EEXIST)");
    6756                 :            : /* do not treat adding same MAC as error */
    6757                 :            :                 rc = 0;
    6758         [ #  # ]:          0 :         } else if (rc < 0) {
    6759         [ #  # ]:          0 :                 PMD_DRV_LOG(ERR, sc,
    6760                 :            :                             "%s MAC failed (%d)", (set ? "Set" : "Delete"), rc);
    6761                 :            :         }
    6762                 :            : 
    6763                 :          0 :         return rc;
    6764                 :            : }
    6765                 :            : 
    6766                 :          0 : static int bnx2x_set_eth_mac(struct bnx2x_softc *sc, uint8_t set)
    6767                 :            : {
    6768                 :          0 :         uint32_t ramrod_flags = 0;
    6769                 :            : 
    6770                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Adding Ethernet MAC");
    6771                 :            : 
    6772                 :            :         rte_bit_relaxed_set32(RAMROD_COMP_WAIT, &ramrod_flags);
    6773                 :            : 
    6774                 :            :         /* Eth MAC is set on RSS leading client (fp[0]) */
    6775                 :          0 :         return bnx2x_set_mac_one(sc, sc->link_params.mac_addr,
    6776                 :            :                                &sc->sp_objs->mac_obj,
    6777                 :            :                                set, ECORE_ETH_MAC, &ramrod_flags);
    6778                 :            : }
    6779                 :            : 
    6780                 :          0 : static int bnx2x_get_cur_phy_idx(struct bnx2x_softc *sc)
    6781                 :            : {
    6782                 :            :         uint32_t sel_phy_idx = 0;
    6783                 :            : 
    6784         [ #  # ]:          0 :         if (sc->link_params.num_phys <= 1) {
    6785                 :            :                 return ELINK_INT_PHY;
    6786                 :            :         }
    6787                 :            : 
    6788         [ #  # ]:          0 :         if (sc->link_vars.link_up) {
    6789                 :            :                 sel_phy_idx = ELINK_EXT_PHY1;
    6790                 :            : /* In case link is SERDES, check if the ELINK_EXT_PHY2 is the one */
    6791         [ #  # ]:          0 :                 if ((sc->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
    6792         [ #  # ]:          0 :                     (sc->link_params.phy[ELINK_EXT_PHY2].supported &
    6793                 :            :                      ELINK_SUPPORTED_FIBRE))
    6794                 :            :                         sel_phy_idx = ELINK_EXT_PHY2;
    6795                 :            :         } else {
    6796      [ #  #  # ]:          0 :                 switch (elink_phy_selection(&sc->link_params)) {
    6797                 :          0 :                 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
    6798                 :            :                 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
    6799                 :            :                 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
    6800                 :            :                         sel_phy_idx = ELINK_EXT_PHY1;
    6801                 :          0 :                         break;
    6802                 :          0 :                 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
    6803                 :            :                 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
    6804                 :            :                         sel_phy_idx = ELINK_EXT_PHY2;
    6805                 :          0 :                         break;
    6806                 :            :                 }
    6807                 :            :         }
    6808                 :            : 
    6809                 :          0 :         return sel_phy_idx;
    6810                 :            : }
    6811                 :            : 
    6812                 :          0 : static int bnx2x_get_link_cfg_idx(struct bnx2x_softc *sc)
    6813                 :            : {
    6814                 :          0 :         uint32_t sel_phy_idx = bnx2x_get_cur_phy_idx(sc);
    6815                 :            : 
    6816                 :            :         /*
    6817                 :            :          * The selected activated PHY is always after swapping (in case PHY
    6818                 :            :          * swapping is enabled). So when swapping is enabled, we need to reverse
    6819                 :            :          * the configuration
    6820                 :            :          */
    6821                 :            : 
    6822         [ #  # ]:          0 :         if (sc->link_params.multi_phy_config & PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
    6823         [ #  # ]:          0 :                 if (sel_phy_idx == ELINK_EXT_PHY1)
    6824                 :            :                         sel_phy_idx = ELINK_EXT_PHY2;
    6825         [ #  # ]:          0 :                 else if (sel_phy_idx == ELINK_EXT_PHY2)
    6826                 :            :                         sel_phy_idx = ELINK_EXT_PHY1;
    6827                 :            :         }
    6828                 :            : 
    6829         [ #  # ]:          0 :         return ELINK_LINK_CONFIG_IDX(sel_phy_idx);
    6830                 :            : }
    6831                 :            : 
    6832                 :            : static void bnx2x_set_requested_fc(struct bnx2x_softc *sc)
    6833                 :            : {
    6834                 :            :         /*
    6835                 :            :          * Initialize link parameters structure variables
    6836                 :            :          * It is recommended to turn off RX FC for jumbo frames
    6837                 :            :          * for better performance
    6838                 :            :          */
    6839   [ #  #  #  #  :          0 :         if (CHIP_IS_E1x(sc) && (sc->mtu > 5000)) {
                   #  # ]
    6840                 :          0 :                 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_TX;
    6841                 :            :         } else {
    6842                 :          0 :                 sc->link_params.req_fc_auto_adv = ELINK_FLOW_CTRL_BOTH;
    6843                 :            :         }
    6844                 :            : }
    6845                 :            : 
    6846                 :          0 : static void bnx2x_calc_fc_adv(struct bnx2x_softc *sc)
    6847                 :            : {
    6848                 :          0 :         uint8_t cfg_idx = bnx2x_get_link_cfg_idx(sc);
    6849      [ #  #  # ]:          0 :         switch (sc->link_vars.ieee_fc &
    6850                 :            :                 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
    6851                 :          0 :         case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
    6852                 :            :         default:
    6853                 :          0 :                 sc->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
    6854                 :            :                                                    ADVERTISED_Pause);
    6855                 :          0 :                 break;
    6856                 :            : 
    6857                 :          0 :         case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
    6858                 :          0 :                 sc->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
    6859                 :            :                                                   ADVERTISED_Pause);
    6860                 :          0 :                 break;
    6861                 :            : 
    6862                 :          0 :         case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
    6863                 :          0 :                 sc->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
    6864                 :          0 :                 break;
    6865                 :            :         }
    6866                 :          0 : }
    6867                 :            : 
    6868                 :          0 : static uint16_t bnx2x_get_mf_speed(struct bnx2x_softc *sc)
    6869                 :            : {
    6870                 :          0 :         uint16_t line_speed = sc->link_vars.line_speed;
    6871   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    6872                 :          0 :                 uint16_t maxCfg = bnx2x_extract_max_cfg(sc,
    6873                 :            :                                                       sc->devinfo.
    6874                 :          0 :                                                       mf_info.mf_config[SC_VN
    6875                 :            :                                                                         (sc)]);
    6876                 :            : 
    6877                 :            : /* calculate the current MAX line speed limit for the MF devices */
    6878   [ #  #  #  # ]:          0 :                 if (IS_MF_SI(sc)) {
    6879                 :          0 :                         line_speed = (line_speed * maxCfg) / 100;
    6880                 :            :                 } else {        /* SD mode */
    6881                 :          0 :                         uint16_t vn_max_rate = maxCfg * 100;
    6882                 :            : 
    6883                 :            :                         if (vn_max_rate < line_speed) {
    6884                 :            :                                 line_speed = vn_max_rate;
    6885                 :            :                         }
    6886                 :            :                 }
    6887                 :            :         }
    6888                 :            : 
    6889                 :          0 :         return line_speed;
    6890                 :            : }
    6891                 :            : 
    6892                 :            : static void
    6893                 :          0 : bnx2x_fill_report_data(struct bnx2x_softc *sc, struct bnx2x_link_report_data *data)
    6894                 :            : {
    6895                 :          0 :         uint16_t line_speed = bnx2x_get_mf_speed(sc);
    6896                 :            : 
    6897                 :            :         memset(data, 0, sizeof(*data));
    6898                 :            : 
    6899                 :            :         /* fill the report data with the effective line speed */
    6900                 :          0 :         data->line_speed = line_speed;
    6901                 :            : 
    6902                 :            :         /* Link is down */
    6903   [ #  #  #  # ]:          0 :         if (!sc->link_vars.link_up || (sc->flags & BNX2X_MF_FUNC_DIS)) {
    6904                 :            :                 rte_bit_relaxed_set32(BNX2X_LINK_REPORT_LINK_DOWN,
    6905                 :            :                             &data->link_report_flags);
    6906                 :            :         }
    6907                 :            : 
    6908                 :            :         /* Full DUPLEX */
    6909         [ #  # ]:          0 :         if (sc->link_vars.duplex == DUPLEX_FULL) {
    6910                 :            :                 rte_bit_relaxed_set32(BNX2X_LINK_REPORT_FULL_DUPLEX,
    6911                 :            :                             &data->link_report_flags);
    6912                 :            :         }
    6913                 :            : 
    6914                 :            :         /* Rx Flow Control is ON */
    6915         [ #  # ]:          0 :         if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_RX) {
    6916                 :            :                 rte_bit_relaxed_set32(BNX2X_LINK_REPORT_RX_FC_ON,
    6917                 :            :                                 &data->link_report_flags);
    6918                 :            :         }
    6919                 :            : 
    6920                 :            :         /* Tx Flow Control is ON */
    6921         [ #  # ]:          0 :         if (sc->link_vars.flow_ctrl & ELINK_FLOW_CTRL_TX) {
    6922                 :            :                 rte_bit_relaxed_set32(BNX2X_LINK_REPORT_TX_FC_ON,
    6923                 :            :                                 &data->link_report_flags);
    6924                 :            :         }
    6925                 :          0 : }
    6926                 :            : 
    6927                 :            : /* report link status to OS, should be called under phy_lock */
    6928                 :          0 : static void bnx2x_link_report_locked(struct bnx2x_softc *sc)
    6929                 :            : {
    6930                 :            :         struct bnx2x_link_report_data cur_data;
    6931                 :            : 
    6932                 :            :         /* reread mf_cfg */
    6933         [ #  # ]:          0 :         if (IS_PF(sc)) {
    6934                 :          0 :                 bnx2x_read_mf_cfg(sc);
    6935                 :            :         }
    6936                 :            : 
    6937                 :            :         /* Read the current link report info */
    6938                 :          0 :         bnx2x_fill_report_data(sc, &cur_data);
    6939                 :            : 
    6940                 :            :         /* Don't report link down or exactly the same link status twice */
    6941   [ #  #  #  # ]:          0 :         if (!memcmp(&cur_data, &sc->last_reported_link, sizeof(cur_data)) ||
    6942                 :            :             (rte_bit_relaxed_get32(BNX2X_LINK_REPORT_LINK_DOWN,
    6943         [ #  # ]:          0 :                           &sc->last_reported_link.link_report_flags) &&
    6944                 :            :              rte_bit_relaxed_get32(BNX2X_LINK_REPORT_LINK_DOWN,
    6945                 :            :                           &cur_data.link_report_flags))) {
    6946                 :          0 :                 return;
    6947                 :            :         }
    6948                 :            : 
    6949                 :          0 :         ELINK_DEBUG_P2(sc, "Change in link status : cur_data = %x, last_reported_link = %x",
    6950                 :            :                        cur_data.link_report_flags,
    6951                 :            :                        sc->last_reported_link.link_report_flags);
    6952                 :            : 
    6953                 :          0 :         sc->link_cnt++;
    6954                 :            : 
    6955                 :          0 :         ELINK_DEBUG_P1(sc, "link status change count = %x", sc->link_cnt);
    6956                 :            :         /* report new link params and remember the state for the next time */
    6957                 :            :         rte_memcpy(&sc->last_reported_link, &cur_data, sizeof(cur_data));
    6958                 :            : 
    6959         [ #  # ]:          0 :         if (rte_bit_relaxed_get32(BNX2X_LINK_REPORT_LINK_DOWN,
    6960                 :            :                          &cur_data.link_report_flags)) {
    6961                 :          0 :                 ELINK_DEBUG_P0(sc, "NIC Link is Down");
    6962                 :            :         } else {
    6963                 :            :                 __rte_unused const char *duplex;
    6964                 :            :                 __rte_unused const char *flow;
    6965                 :            : 
    6966         [ #  # ]:          0 :                 if (rte_bit_relaxed_test_and_clear32
    6967                 :            :                                         (BNX2X_LINK_REPORT_FULL_DUPLEX,
    6968                 :            :                                          &cur_data.link_report_flags)) {
    6969                 :            :                         duplex = "full";
    6970                 :          0 :                                 ELINK_DEBUG_P0(sc, "link set to full duplex");
    6971                 :            :                 } else {
    6972                 :            :                         duplex = "half";
    6973                 :          0 :                                 ELINK_DEBUG_P0(sc, "link set to half duplex");
    6974                 :            :                 }
    6975                 :            : 
    6976                 :            : /*
    6977                 :            :  * Handle the FC at the end so that only these flags would be
    6978                 :            :  * possibly set. This way we may easily check if there is no FC
    6979                 :            :  * enabled.
    6980                 :            :  */
    6981         [ #  # ]:          0 :                 if (cur_data.link_report_flags) {
    6982         [ #  # ]:          0 :                         if (rte_bit_relaxed_get32
    6983                 :            :                                         (BNX2X_LINK_REPORT_RX_FC_ON,
    6984         [ #  # ]:          0 :                                          &cur_data.link_report_flags) &&
    6985                 :            :                             rte_bit_relaxed_get32(BNX2X_LINK_REPORT_TX_FC_ON,
    6986                 :            :                                          &cur_data.link_report_flags)) {
    6987                 :            :                                 flow = "ON - receive & transmit";
    6988         [ #  # ]:          0 :                         } else if (rte_bit_relaxed_get32
    6989                 :            :                                                 (BNX2X_LINK_REPORT_RX_FC_ON,
    6990         [ #  # ]:          0 :                                                  &cur_data.link_report_flags) &&
    6991                 :            :                                    !rte_bit_relaxed_get32
    6992                 :            :                                                 (BNX2X_LINK_REPORT_TX_FC_ON,
    6993                 :            :                                                  &cur_data.link_report_flags)) {
    6994                 :            :                                 flow = "ON - receive";
    6995         [ #  # ]:          0 :                         } else if (!rte_bit_relaxed_get32
    6996                 :            :                                                 (BNX2X_LINK_REPORT_RX_FC_ON,
    6997         [ #  # ]:          0 :                                                  &cur_data.link_report_flags) &&
    6998                 :            :                                    rte_bit_relaxed_get32
    6999                 :            :                                                 (BNX2X_LINK_REPORT_TX_FC_ON,
    7000                 :            :                                                  &cur_data.link_report_flags)) {
    7001                 :            :                                 flow = "ON - transmit";
    7002                 :            :                         } else {
    7003                 :            :                                 flow = "none";        /* possible? */
    7004                 :            :                         }
    7005                 :            :                 } else {
    7006                 :            :                         flow = "none";
    7007                 :            :                 }
    7008                 :            : 
    7009                 :          0 :                 PMD_DRV_LOG(INFO, sc,
    7010                 :            :                             "NIC Link is Up, %d Mbps %s duplex, Flow control: %s",
    7011                 :            :                             cur_data.line_speed, duplex, flow);
    7012                 :            :         }
    7013                 :            : }
    7014                 :            : 
    7015                 :            : static void
    7016                 :          0 : bnx2x_link_report(struct bnx2x_softc *sc)
    7017                 :            : {
    7018                 :          0 :         bnx2x_acquire_phy_lock(sc);
    7019                 :          0 :         bnx2x_link_report_locked(sc);
    7020                 :            :         bnx2x_release_phy_lock(sc);
    7021                 :          0 : }
    7022                 :            : 
    7023                 :          0 : void bnx2x_link_status_update(struct bnx2x_softc *sc)
    7024                 :            : {
    7025         [ #  # ]:          0 :         if (sc->state != BNX2X_STATE_OPEN) {
    7026                 :            :                 return;
    7027                 :            :         }
    7028                 :            : 
    7029   [ #  #  #  # ]:          0 :         if (IS_PF(sc) && !CHIP_REV_IS_SLOW(sc)) {
    7030                 :          0 :                 elink_link_status_update(&sc->link_params, &sc->link_vars);
    7031                 :            :         } else {
    7032                 :          0 :                 sc->port.supported[0] |= (ELINK_SUPPORTED_10baseT_Half |
    7033                 :            :                                           ELINK_SUPPORTED_10baseT_Full |
    7034                 :            :                                           ELINK_SUPPORTED_100baseT_Half |
    7035                 :            :                                           ELINK_SUPPORTED_100baseT_Full |
    7036                 :            :                                           ELINK_SUPPORTED_1000baseT_Full |
    7037                 :            :                                           ELINK_SUPPORTED_2500baseX_Full |
    7038                 :            :                                           ELINK_SUPPORTED_10000baseT_Full |
    7039                 :            :                                           ELINK_SUPPORTED_TP |
    7040                 :            :                                           ELINK_SUPPORTED_FIBRE |
    7041                 :            :                                           ELINK_SUPPORTED_Autoneg |
    7042                 :            :                                           ELINK_SUPPORTED_Pause |
    7043                 :            :                                           ELINK_SUPPORTED_Asym_Pause);
    7044                 :          0 :                 sc->port.advertising[0] = sc->port.supported[0];
    7045                 :            : 
    7046                 :          0 :                 sc->link_params.sc = sc;
    7047                 :          0 :                 sc->link_params.port = SC_PORT(sc);
    7048                 :          0 :                 sc->link_params.req_duplex[0] = DUPLEX_FULL;
    7049                 :          0 :                 sc->link_params.req_flow_ctrl[0] = ELINK_FLOW_CTRL_NONE;
    7050                 :          0 :                 sc->link_params.req_line_speed[0] = SPEED_10000;
    7051                 :          0 :                 sc->link_params.speed_cap_mask[0] = 0x7f0000;
    7052                 :          0 :                 sc->link_params.switch_cfg = ELINK_SWITCH_CFG_10G;
    7053                 :            : 
    7054   [ #  #  #  # ]:          0 :                 if (CHIP_REV_IS_FPGA(sc)) {
    7055                 :          0 :                         sc->link_vars.mac_type = ELINK_MAC_TYPE_EMAC;
    7056                 :          0 :                         sc->link_vars.line_speed = ELINK_SPEED_1000;
    7057                 :          0 :                         sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
    7058                 :            :                                                      LINK_STATUS_SPEED_AND_DUPLEX_1000TFD);
    7059                 :            :                 } else {
    7060                 :          0 :                         sc->link_vars.mac_type = ELINK_MAC_TYPE_BMAC;
    7061                 :          0 :                         sc->link_vars.line_speed = ELINK_SPEED_10000;
    7062                 :          0 :                         sc->link_vars.link_status = (LINK_STATUS_LINK_UP |
    7063                 :            :                                                      LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
    7064                 :            :                 }
    7065                 :            : 
    7066                 :          0 :                 sc->link_vars.link_up = 1;
    7067                 :            : 
    7068                 :          0 :                 sc->link_vars.duplex = DUPLEX_FULL;
    7069                 :          0 :                 sc->link_vars.flow_ctrl = ELINK_FLOW_CTRL_NONE;
    7070                 :            : 
    7071         [ #  # ]:          0 :                 if (IS_PF(sc)) {
    7072                 :          0 :                         REG_WR(sc,
    7073                 :            :                                NIG_REG_EGRESS_DRAIN0_MODE +
    7074                 :            :                                sc->link_params.port * 4, 0);
    7075                 :          0 :                         bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
    7076                 :          0 :                         bnx2x_link_report(sc);
    7077                 :            :                 }
    7078                 :            :         }
    7079                 :            : 
    7080         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7081         [ #  # ]:          0 :                 if (sc->link_vars.link_up) {
    7082                 :          0 :                         bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
    7083                 :            :                 } else {
    7084                 :          0 :                         bnx2x_stats_handle(sc, STATS_EVENT_STOP);
    7085                 :            :                 }
    7086                 :          0 :                 bnx2x_link_report(sc);
    7087                 :            :         } else {
    7088                 :          0 :                 bnx2x_link_report_locked(sc);
    7089                 :          0 :                 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
    7090                 :            :         }
    7091                 :            : }
    7092                 :            : 
    7093                 :          0 : static int bnx2x_initial_phy_init(struct bnx2x_softc *sc, int load_mode)
    7094                 :            : {
    7095                 :          0 :         int rc, cfg_idx = bnx2x_get_link_cfg_idx(sc);
    7096                 :          0 :         uint16_t req_line_speed = sc->link_params.req_line_speed[cfg_idx];
    7097         [ #  # ]:          0 :         struct elink_params *lp = &sc->link_params;
    7098                 :            : 
    7099                 :            :         bnx2x_set_requested_fc(sc);
    7100                 :            : 
    7101                 :          0 :         bnx2x_acquire_phy_lock(sc);
    7102                 :            : 
    7103         [ #  # ]:          0 :         if (load_mode == LOAD_DIAG) {
    7104                 :          0 :                 lp->loopback_mode = ELINK_LOOPBACK_XGXS;
    7105                 :            : /* Prefer doing PHY loopback at 10G speed, if possible */
    7106         [ #  # ]:          0 :                 if (lp->req_line_speed[cfg_idx] < ELINK_SPEED_10000) {
    7107         [ #  # ]:          0 :                         if (lp->speed_cap_mask[cfg_idx] &
    7108                 :            :                             PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
    7109                 :          0 :                                 lp->req_line_speed[cfg_idx] = ELINK_SPEED_10000;
    7110                 :            :                         } else {
    7111                 :          0 :                                 lp->req_line_speed[cfg_idx] = ELINK_SPEED_1000;
    7112                 :            :                         }
    7113                 :            :                 }
    7114                 :            :         }
    7115                 :            : 
    7116         [ #  # ]:          0 :         if (load_mode == LOAD_LOOPBACK_EXT) {
    7117                 :          0 :                 lp->loopback_mode = ELINK_LOOPBACK_EXT;
    7118                 :            :         }
    7119                 :            : 
    7120                 :          0 :         rc = elink_phy_init(&sc->link_params, &sc->link_vars);
    7121                 :            : 
    7122                 :            :         bnx2x_release_phy_lock(sc);
    7123                 :            : 
    7124                 :          0 :         bnx2x_calc_fc_adv(sc);
    7125                 :            : 
    7126         [ #  # ]:          0 :         if (sc->link_vars.link_up) {
    7127                 :          0 :                 bnx2x_stats_handle(sc, STATS_EVENT_LINK_UP);
    7128                 :          0 :                 bnx2x_link_report(sc);
    7129                 :            :         }
    7130                 :            : 
    7131                 :          0 :         sc->link_params.req_line_speed[cfg_idx] = req_line_speed;
    7132                 :          0 :         return rc;
    7133                 :            : }
    7134                 :            : 
    7135                 :            : /* update flags in shmem */
    7136                 :            : static void
    7137                 :          0 : bnx2x_update_drv_flags(struct bnx2x_softc *sc, uint32_t flags, uint32_t set)
    7138                 :            : {
    7139                 :            :         uint32_t drv_flags;
    7140                 :            : 
    7141   [ #  #  #  # ]:          0 :         if (SHMEM2_HAS(sc, drv_flags)) {
    7142                 :          0 :                 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
    7143                 :          0 :                 drv_flags = SHMEM2_RD(sc, drv_flags);
    7144                 :            : 
    7145         [ #  # ]:          0 :                 if (set) {
    7146                 :          0 :                         drv_flags |= flags;
    7147                 :            :                 } else {
    7148                 :          0 :                         drv_flags &= ~flags;
    7149                 :            :                 }
    7150                 :            : 
    7151                 :          0 :                 SHMEM2_WR(sc, drv_flags, drv_flags);
    7152                 :            : 
    7153                 :          0 :                 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_DRV_FLAGS);
    7154                 :            :         }
    7155                 :          0 : }
    7156                 :            : 
    7157                 :            : /* periodic timer callout routine, only runs when the interface is up */
    7158                 :          0 : void bnx2x_periodic_callout(struct bnx2x_softc *sc)
    7159                 :            : {
    7160         [ #  # ]:          0 :         if ((sc->state != BNX2X_STATE_OPEN) ||
    7161         [ #  # ]:          0 :             (atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_STOP)) {
    7162                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "periodic callout exit (state=0x%x)",
    7163                 :            :                             sc->state);
    7164                 :          0 :                 return;
    7165                 :            :         }
    7166         [ #  # ]:          0 :         if (!CHIP_REV_IS_SLOW(sc)) {
    7167                 :            : /*
    7168                 :            :  * This barrier is needed to ensure the ordering between the writing
    7169                 :            :  * to the sc->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
    7170                 :            :  * the reading here.
    7171                 :            :  */
    7172                 :            :                 mb();
    7173         [ #  # ]:          0 :                 if (sc->port.pmf) {
    7174                 :          0 :                         bnx2x_acquire_phy_lock(sc);
    7175                 :          0 :                         elink_period_func(&sc->link_params, &sc->link_vars);
    7176                 :            :                         bnx2x_release_phy_lock(sc);
    7177                 :            :                 }
    7178                 :            :         }
    7179                 :            : #ifdef BNX2X_PULSE
    7180                 :            :         if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
    7181                 :            :                 int mb_idx = SC_FW_MB_IDX(sc);
    7182                 :            :                 uint32_t drv_pulse;
    7183                 :            :                 uint32_t mcp_pulse;
    7184                 :            : 
    7185                 :            :                 ++sc->fw_drv_pulse_wr_seq;
    7186                 :            :                 sc->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
    7187                 :            : 
    7188                 :            :                 drv_pulse = sc->fw_drv_pulse_wr_seq;
    7189                 :            :                 bnx2x_drv_pulse(sc);
    7190                 :            : 
    7191                 :            :                 mcp_pulse = (SHMEM_RD(sc, func_mb[mb_idx].mcp_pulse_mb) &
    7192                 :            :                              MCP_PULSE_SEQ_MASK);
    7193                 :            : 
    7194                 :            : /*
    7195                 :            :  * The delta between driver pulse and mcp response should
    7196                 :            :  * be 1 (before mcp response) or 0 (after mcp response).
    7197                 :            :  */
    7198                 :            :                 if ((drv_pulse != mcp_pulse) &&
    7199                 :            :                     (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
    7200                 :            :                         /* someone lost a heartbeat... */
    7201                 :            :                         PMD_DRV_LOG(ERR, sc,
    7202                 :            :                                     "drv_pulse (0x%x) != mcp_pulse (0x%x)",
    7203                 :            :                                     drv_pulse, mcp_pulse);
    7204                 :            :                 }
    7205                 :            :         }
    7206                 :            : #endif
    7207                 :            : }
    7208                 :            : 
    7209                 :            : /* start the controller */
    7210                 :            : static __rte_noinline
    7211                 :          0 : int bnx2x_nic_load(struct bnx2x_softc *sc)
    7212                 :            : {
    7213                 :            :         uint32_t val;
    7214                 :          0 :         uint32_t load_code = 0;
    7215                 :            :         int i, rc = 0;
    7216                 :            : 
    7217                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    7218                 :            : 
    7219                 :          0 :         sc->state = BNX2X_STATE_OPENING_WAITING_LOAD;
    7220                 :            : 
    7221         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7222                 :            : /* must be called before memory allocation and HW init */
    7223                 :          0 :                 bnx2x_ilt_set_info(sc);
    7224                 :            :         }
    7225                 :            : 
    7226                 :            :         bnx2x_set_fp_rx_buf_size(sc);
    7227                 :            : 
    7228         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7229         [ #  # ]:          0 :                 if (bnx2x_alloc_mem(sc) != 0) {
    7230                 :          0 :                         sc->state = BNX2X_STATE_CLOSED;
    7231                 :            :                         rc = -ENOMEM;
    7232                 :          0 :                         goto bnx2x_nic_load_error0;
    7233                 :            :                 }
    7234                 :            :         }
    7235                 :            : 
    7236                 :            :         /* allocate the host hardware/software hsi structures */
    7237         [ #  # ]:          0 :         if (bnx2x_alloc_hsi_mem(sc) != 0) {
    7238                 :          0 :                 PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_hsi_mem was failed");
    7239                 :          0 :                 sc->state = BNX2X_STATE_CLOSED;
    7240                 :            :                 rc = -ENOMEM;
    7241                 :          0 :                 goto bnx2x_nic_load_error0;
    7242                 :            :         }
    7243                 :            : 
    7244         [ #  # ]:          0 :         if (bnx2x_alloc_fw_stats_mem(sc) != 0) {
    7245                 :          0 :                 sc->state = BNX2X_STATE_CLOSED;
    7246                 :            :                 rc = -ENOMEM;
    7247                 :          0 :                 goto bnx2x_nic_load_error0;
    7248                 :            :         }
    7249                 :            : 
    7250         [ #  # ]:          0 :         if (IS_VF(sc)) {
    7251                 :          0 :                 rc = bnx2x_vf_init(sc);
    7252         [ #  # ]:          0 :                 if (rc) {
    7253                 :          0 :                         sc->state = BNX2X_STATE_ERROR;
    7254                 :          0 :                         goto bnx2x_nic_load_error0;
    7255                 :            :                 }
    7256                 :            :         }
    7257                 :            : 
    7258         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7259                 :            : /* set pf load just before approaching the MCP */
    7260                 :          0 :                 bnx2x_set_pf_load(sc);
    7261                 :            : 
    7262                 :            : /* if MCP exists send load request and analyze response */
    7263         [ #  # ]:          0 :                 if (!BNX2X_NOMCP(sc)) {
    7264                 :            :                         /* attempt to load pf */
    7265         [ #  # ]:          0 :                         if (bnx2x_nic_load_request(sc, &load_code) != 0) {
    7266                 :          0 :                                 sc->state = BNX2X_STATE_CLOSED;
    7267                 :            :                                 rc = -ENXIO;
    7268                 :          0 :                                 goto bnx2x_nic_load_error1;
    7269                 :            :                         }
    7270                 :            : 
    7271                 :            :                         /* what did the MCP say? */
    7272         [ #  # ]:          0 :                         if (bnx2x_nic_load_analyze_req(sc, load_code) != 0) {
    7273                 :            :                                 bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
    7274                 :          0 :                                 sc->state = BNX2X_STATE_CLOSED;
    7275                 :            :                                 rc = -ENXIO;
    7276                 :          0 :                                 goto bnx2x_nic_load_error2;
    7277                 :            :                         }
    7278                 :            :                 } else {
    7279                 :          0 :                         PMD_DRV_LOG(INFO, sc, "Device has no MCP!");
    7280                 :          0 :                         load_code = bnx2x_nic_load_no_mcp(sc);
    7281                 :            :                 }
    7282                 :            : 
    7283                 :            : /* mark PMF if applicable */
    7284                 :          0 :                 bnx2x_nic_load_pmf(sc, load_code);
    7285                 :            : 
    7286                 :            : /* Init Function state controlling object */
    7287                 :          0 :                 bnx2x_init_func_obj(sc);
    7288                 :            : 
    7289                 :            : /* Initialize HW */
    7290         [ #  # ]:          0 :                 if (bnx2x_init_hw(sc, load_code) != 0) {
    7291                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "HW init failed");
    7292                 :            :                         bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
    7293                 :          0 :                         sc->state = BNX2X_STATE_CLOSED;
    7294                 :            :                         rc = -ENXIO;
    7295                 :          0 :                         goto bnx2x_nic_load_error2;
    7296                 :            :                 }
    7297                 :            :         }
    7298                 :            : 
    7299                 :          0 :         bnx2x_nic_init(sc, load_code);
    7300                 :            : 
    7301                 :            :         /* Init per-function objects */
    7302         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7303                 :          0 :                 bnx2x_init_objs(sc);
    7304                 :            : 
    7305                 :            : /* set AFEX default VLAN tag to an invalid value */
    7306                 :          0 :                 sc->devinfo.mf_info.afex_def_vlan_tag = -1;
    7307                 :            : 
    7308                 :          0 :                 sc->state = BNX2X_STATE_OPENING_WAITING_PORT;
    7309                 :          0 :                 rc = bnx2x_func_start(sc);
    7310         [ #  # ]:          0 :                 if (rc) {
    7311                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Function start failed!");
    7312                 :            :                         bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
    7313                 :          0 :                         sc->state = BNX2X_STATE_ERROR;
    7314                 :          0 :                         goto bnx2x_nic_load_error3;
    7315                 :            :                 }
    7316                 :            : 
    7317                 :            : /* send LOAD_DONE command to MCP */
    7318         [ #  # ]:          0 :                 if (!BNX2X_NOMCP(sc)) {
    7319                 :          0 :                         load_code =
    7320                 :            :                             bnx2x_fw_command(sc, DRV_MSG_CODE_LOAD_DONE, 0);
    7321         [ #  # ]:          0 :                         if (!load_code) {
    7322                 :          0 :                                 PMD_DRV_LOG(NOTICE, sc,
    7323                 :            :                                             "MCP response failure, aborting");
    7324                 :          0 :                                 sc->state = BNX2X_STATE_ERROR;
    7325                 :            :                                 rc = -ENXIO;
    7326                 :          0 :                                 goto bnx2x_nic_load_error3;
    7327                 :            :                         }
    7328                 :            :                 }
    7329                 :            :         }
    7330                 :            : 
    7331                 :          0 :         rc = bnx2x_setup_leading(sc);
    7332         [ #  # ]:          0 :         if (rc) {
    7333                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Setup leading failed!");
    7334                 :          0 :                 sc->state = BNX2X_STATE_ERROR;
    7335                 :          0 :                 goto bnx2x_nic_load_error3;
    7336                 :            :         }
    7337                 :            : 
    7338         [ #  # ]:          0 :         FOR_EACH_NONDEFAULT_ETH_QUEUE(sc, i) {
    7339         [ #  # ]:          0 :                 if (IS_PF(sc))
    7340                 :          0 :                         rc = bnx2x_setup_queue(sc, &sc->fp[i], FALSE);
    7341                 :            :                 else            /* IS_VF(sc) */
    7342                 :          0 :                         rc = bnx2x_vf_setup_queue(sc, &sc->fp[i], FALSE);
    7343                 :            : 
    7344         [ #  # ]:          0 :                 if (rc) {
    7345                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Queue(%d) setup failed", i);
    7346                 :          0 :                         sc->state = BNX2X_STATE_ERROR;
    7347                 :          0 :                         goto bnx2x_nic_load_error3;
    7348                 :            :                 }
    7349                 :            :         }
    7350                 :            : 
    7351                 :          0 :         rc = bnx2x_init_rss_pf(sc);
    7352         [ #  # ]:          0 :         if (rc) {
    7353                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PF RSS init failed");
    7354                 :          0 :                 sc->state = BNX2X_STATE_ERROR;
    7355                 :          0 :                 goto bnx2x_nic_load_error3;
    7356                 :            :         }
    7357                 :            : 
    7358                 :            :         /* now when Clients are configured we are ready to work */
    7359                 :          0 :         sc->state = BNX2X_STATE_OPEN;
    7360                 :            : 
    7361                 :            :         /* Configure a ucast MAC */
    7362         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7363                 :          0 :                 rc = bnx2x_set_eth_mac(sc, TRUE);
    7364                 :            :         } else {                /* IS_VF(sc) */
    7365                 :          0 :                 rc = bnx2x_vf_set_mac(sc, TRUE);
    7366                 :            :         }
    7367                 :            : 
    7368         [ #  # ]:          0 :         if (rc) {
    7369                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Setting Ethernet MAC failed");
    7370                 :          0 :                 sc->state = BNX2X_STATE_ERROR;
    7371                 :          0 :                 goto bnx2x_nic_load_error3;
    7372                 :            :         }
    7373                 :            : 
    7374         [ #  # ]:          0 :         if (sc->port.pmf) {
    7375                 :          0 :                 rc = bnx2x_initial_phy_init(sc, LOAD_OPEN);
    7376         [ #  # ]:          0 :                 if (rc) {
    7377                 :          0 :                         sc->state = BNX2X_STATE_ERROR;
    7378                 :          0 :                         goto bnx2x_nic_load_error3;
    7379                 :            :                 }
    7380                 :            :         }
    7381                 :            : 
    7382                 :          0 :         sc->link_params.feature_config_flags &=
    7383                 :            :             ~ELINK_FEATURE_CONFIG_BOOT_FROM_SAN;
    7384                 :            : 
    7385                 :            :         /* start the Tx */
    7386                 :            :         switch (LOAD_OPEN) {
    7387                 :            :         case LOAD_NORMAL:
    7388                 :            :         case LOAD_OPEN:
    7389                 :            :                 break;
    7390                 :            : 
    7391                 :            :         case LOAD_DIAG:
    7392                 :            :         case LOAD_LOOPBACK_EXT:
    7393                 :            :                 sc->state = BNX2X_STATE_DIAG;
    7394                 :            :                 break;
    7395                 :            : 
    7396                 :            :         default:
    7397                 :            :                 break;
    7398                 :            :         }
    7399                 :            : 
    7400         [ #  # ]:          0 :         if (sc->port.pmf) {
    7401                 :          0 :                 bnx2x_update_drv_flags(sc, 1 << DRV_FLAGS_PORT_MASK, 0);
    7402                 :            :         } else {
    7403                 :          0 :                 bnx2x_link_status_update(sc);
    7404                 :            :         }
    7405                 :            : 
    7406   [ #  #  #  #  :          0 :         if (IS_PF(sc) && SHMEM2_HAS(sc, drv_capabilities_flag)) {
                   #  # ]
    7407                 :            : /* mark driver is loaded in shmem2 */
    7408   [ #  #  #  # ]:          0 :                 val = SHMEM2_RD(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)]);
    7409   [ #  #  #  # ]:          0 :                 SHMEM2_WR(sc, drv_capabilities_flag[SC_FW_MB_IDX(sc)],
    7410                 :            :                           (val |
    7411                 :            :                            DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
    7412                 :            :                            DRV_FLAGS_CAPABILITIES_LOADED_L2));
    7413                 :            :         }
    7414                 :            : 
    7415                 :            :         /* start fast path */
    7416                 :            :         /* Initialize Rx filter */
    7417                 :          0 :         bnx2x_set_rx_mode(sc);
    7418                 :            : 
    7419                 :            :         /* wait for all pending SP commands to complete */
    7420   [ #  #  #  # ]:          0 :         if (IS_PF(sc) && !bnx2x_wait_sp_comp(sc, ~0x0U)) {
    7421                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Timeout waiting for all SPs to complete!");
    7422                 :          0 :                 bnx2x_periodic_stop(sc);
    7423                 :          0 :                 bnx2x_nic_unload(sc, UNLOAD_CLOSE, FALSE);
    7424                 :          0 :                 return -ENXIO;
    7425                 :            :         }
    7426                 :            : 
    7427                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "NIC successfully loaded");
    7428                 :            : 
    7429                 :          0 :         return 0;
    7430                 :            : 
    7431                 :          0 : bnx2x_nic_load_error3:
    7432                 :            : 
    7433         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7434                 :            :                 bnx2x_int_disable_sync(sc, 1);
    7435                 :            : 
    7436                 :            : /* clean out queued objects */
    7437                 :          0 :                 bnx2x_squeeze_objects(sc);
    7438                 :            :         }
    7439                 :            : 
    7440                 :          0 : bnx2x_nic_load_error2:
    7441                 :            : 
    7442         [ #  # ]:          0 :         if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
    7443                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
    7444                 :            :                 bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE, 0);
    7445                 :            :         }
    7446                 :            : 
    7447                 :          0 :         sc->port.pmf = 0;
    7448                 :            : 
    7449                 :          0 : bnx2x_nic_load_error1:
    7450                 :            : 
    7451                 :            :         /* clear pf_load status, as it was already set */
    7452         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7453                 :          0 :                 bnx2x_clear_pf_load(sc);
    7454                 :            :         }
    7455                 :            : 
    7456                 :          0 : bnx2x_nic_load_error0:
    7457                 :            : 
    7458                 :            :         bnx2x_free_fw_stats_mem(sc);
    7459                 :          0 :         bnx2x_free_hsi_mem(sc);
    7460                 :          0 :         bnx2x_free_mem(sc);
    7461                 :            : 
    7462                 :          0 :         return rc;
    7463                 :            : }
    7464                 :            : 
    7465                 :            : /*
    7466                 :            : * Handles controller initialization.
    7467                 :            : */
    7468                 :          0 : int bnx2x_init(struct bnx2x_softc *sc)
    7469                 :            : {
    7470                 :          0 :         int other_engine = SC_PATH(sc) ? 0 : 1;
    7471                 :            :         uint8_t other_load_status, load_status;
    7472                 :          0 :         uint8_t global = FALSE;
    7473                 :            :         int rc;
    7474                 :            : 
    7475                 :            :         /* Check if the driver is still running and bail out if it is. */
    7476         [ #  # ]:          0 :         if (sc->state != BNX2X_STATE_CLOSED) {
    7477                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Init called while driver is running!");
    7478                 :            :                 rc = 0;
    7479                 :          0 :                 goto bnx2x_init_done;
    7480                 :            :         }
    7481                 :            : 
    7482                 :          0 :         bnx2x_set_power_state(sc, PCI_PM_D0);
    7483                 :            : 
    7484                 :            :         /*
    7485                 :            :          * If parity occurred during the unload, then attentions and/or
    7486                 :            :          * RECOVERY_IN_PROGRESS may still be set. If so we want the first function
    7487                 :            :          * loaded on the current engine to complete the recovery. Parity recovery
    7488                 :            :          * is only relevant for PF driver.
    7489                 :            :          */
    7490         [ #  # ]:          0 :         if (IS_PF(sc)) {
    7491                 :            :                 other_load_status = bnx2x_get_load_status(sc, other_engine);
    7492         [ #  # ]:          0 :                 load_status = bnx2x_get_load_status(sc, SC_PATH(sc));
    7493                 :            : 
    7494   [ #  #  #  # ]:          0 :                 if (!bnx2x_reset_is_done(sc, SC_PATH(sc)) ||
    7495                 :          0 :                     bnx2x_chk_parity_attn(sc, &global, TRUE)) {
    7496                 :            :                         do {
    7497                 :            :                                 /*
    7498                 :            :                                  * If there are attentions and they are in global blocks, set
    7499                 :            :                                  * the GLOBAL_RESET bit regardless whether it will be this
    7500                 :            :                                  * function that will complete the recovery or not.
    7501                 :            :                                  */
    7502         [ #  # ]:          0 :                                 if (global) {
    7503                 :          0 :                                         bnx2x_set_reset_global(sc);
    7504                 :            :                                 }
    7505                 :            : 
    7506                 :            :                                 /*
    7507                 :            :                                  * Only the first function on the current engine should try
    7508                 :            :                                  * to recover in open. In case of attentions in global blocks
    7509                 :            :                                  * only the first in the chip should try to recover.
    7510                 :            :                                  */
    7511         [ #  # ]:          0 :                                 if ((!load_status
    7512   [ #  #  #  # ]:          0 :                                      && (!global ||!other_load_status))
    7513         [ #  # ]:          0 :                                     && bnx2x_trylock_leader_lock(sc)
    7514         [ #  # ]:          0 :                                     && !bnx2x_leader_reset(sc)) {
    7515                 :          0 :                                         PMD_DRV_LOG(INFO, sc,
    7516                 :            :                                                     "Recovered during init");
    7517                 :          0 :                                         break;
    7518                 :            :                                 }
    7519                 :            : 
    7520                 :            :                                 /* recovery has failed... */
    7521                 :          0 :                                 bnx2x_set_power_state(sc, PCI_PM_D3hot);
    7522                 :            : 
    7523                 :          0 :                                 sc->recovery_state = BNX2X_RECOVERY_FAILED;
    7524                 :            : 
    7525                 :          0 :                                 PMD_DRV_LOG(NOTICE, sc,
    7526                 :            :                                             "Recovery flow hasn't properly "
    7527                 :            :                                             "completed yet, try again later. "
    7528                 :            :                                             "If you still see this message after a "
    7529                 :            :                                             "few retries then power cycle is required.");
    7530                 :            : 
    7531                 :            :                                 rc = -ENXIO;
    7532                 :          0 :                                 goto bnx2x_init_done;
    7533                 :            :                         } while (0);
    7534                 :            :                 }
    7535                 :            :         }
    7536                 :            : 
    7537                 :          0 :         sc->recovery_state = BNX2X_RECOVERY_DONE;
    7538                 :            : 
    7539                 :          0 :         rc = bnx2x_nic_load(sc);
    7540                 :            : 
    7541                 :            : bnx2x_init_done:
    7542                 :            : 
    7543         [ #  # ]:          0 :         if (rc) {
    7544                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Initialization failed, "
    7545                 :            :                             "stack notified driver is NOT running!");
    7546                 :            :         }
    7547                 :            : 
    7548                 :          0 :         return rc;
    7549                 :            : }
    7550                 :            : 
    7551                 :          0 : static void bnx2x_get_function_num(struct bnx2x_softc *sc)
    7552                 :            : {
    7553                 :            :         uint32_t val = 0;
    7554                 :            : 
    7555                 :            :         /*
    7556                 :            :          * Read the ME register to get the function number. The ME register
    7557                 :            :          * holds the relative-function number and absolute-function number. The
    7558                 :            :          * absolute-function number appears only in E2 and above. Before that
    7559                 :            :          * these bits always contained zero, therefore we cannot blindly use them.
    7560                 :            :          */
    7561                 :            : 
    7562                 :            :         val = REG_RD(sc, BAR_ME_REGISTER);
    7563                 :            : 
    7564                 :          0 :         sc->pfunc_rel =
    7565                 :          0 :             (uint8_t) ((val & ME_REG_PF_NUM) >> ME_REG_PF_NUM_SHIFT);
    7566                 :          0 :         sc->path_id =
    7567                 :          0 :             (uint8_t) ((val & ME_REG_ABS_PF_NUM) >> ME_REG_ABS_PF_NUM_SHIFT) &
    7568                 :            :             1;
    7569                 :            : 
    7570         [ #  # ]:          0 :         if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
    7571                 :          0 :                 sc->pfunc_abs = ((sc->pfunc_rel << 1) | sc->path_id);
    7572                 :            :         } else {
    7573                 :          0 :                 sc->pfunc_abs = (sc->pfunc_rel | sc->path_id);
    7574                 :            :         }
    7575                 :            : 
    7576                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
    7577                 :            :                     "Relative function %d, Absolute function %d, Path %d",
    7578                 :            :                     sc->pfunc_rel, sc->pfunc_abs, sc->path_id);
    7579                 :          0 : }
    7580                 :            : 
    7581                 :            : static uint32_t bnx2x_get_shmem_mf_cfg_base(struct bnx2x_softc *sc)
    7582                 :            : {
    7583                 :            :         uint32_t shmem2_size;
    7584                 :            :         uint32_t offset;
    7585                 :            :         uint32_t mf_cfg_offset_value;
    7586                 :            : 
    7587                 :            :         /* Non 57712 */
    7588                 :          0 :         offset = (SHMEM_ADDR(sc, func_mb) +
    7589                 :            :                   (MAX_FUNC_NUM * sizeof(struct drv_func_mb)));
    7590                 :            : 
    7591                 :            :         /* 57712 plus */
    7592         [ #  # ]:          0 :         if (sc->devinfo.shmem2_base != 0) {
    7593                 :          0 :                 shmem2_size = SHMEM2_RD(sc, size);
    7594         [ #  # ]:          0 :                 if (shmem2_size > offsetof(struct shmem2_region, mf_cfg_addr)) {
    7595                 :          0 :                         mf_cfg_offset_value = SHMEM2_RD(sc, mf_cfg_addr);
    7596         [ #  # ]:          0 :                         if (SHMEM_MF_CFG_ADDR_NONE != mf_cfg_offset_value) {
    7597                 :            :                                 offset = mf_cfg_offset_value;
    7598                 :            :                         }
    7599                 :            :                 }
    7600                 :            :         }
    7601                 :            : 
    7602                 :            :         return offset;
    7603                 :            : }
    7604                 :            : 
    7605                 :          0 : static uint32_t bnx2x_pcie_capability_read(struct bnx2x_softc *sc, int reg)
    7606                 :            : {
    7607                 :            :         uint32_t ret;
    7608                 :            :         struct bnx2x_pci_cap *caps;
    7609                 :            : 
    7610                 :            :         /* ensure PCIe capability is enabled */
    7611                 :            :         caps = pci_find_cap(sc, RTE_PCI_CAP_ID_EXP, BNX2X_PCI_CAP);
    7612         [ #  # ]:          0 :         if (NULL != caps) {
    7613                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Found PCIe capability: "
    7614                 :            :                             "id=0x%04X type=0x%04X addr=0x%08X",
    7615                 :            :                             caps->id, caps->type, caps->addr);
    7616                 :          0 :                 pci_read(sc, (caps->addr + reg), &ret, 2);
    7617                 :          0 :                 return ret;
    7618                 :            :         }
    7619                 :            : 
    7620                 :          0 :         PMD_DRV_LOG(WARNING, sc, "PCIe capability NOT FOUND!!!");
    7621                 :            : 
    7622                 :          0 :         return 0;
    7623                 :            : }
    7624                 :            : 
    7625                 :            : static uint8_t bnx2x_is_pcie_pending(struct bnx2x_softc *sc)
    7626                 :            : {
    7627                 :          0 :         return bnx2x_pcie_capability_read(sc, RTE_PCI_EXP_TYPE_RC_EC) &
    7628                 :            :                 RTE_PCI_EXP_DEVSTA_TRPND;
    7629                 :            : }
    7630                 :            : 
    7631                 :            : /*
    7632                 :            : * Walk the PCI capabilities list for the device to find what features are
    7633                 :            : * supported. These capabilities may be enabled/disabled by firmware so it's
    7634                 :            : * best to walk the list rather than make assumptions.
    7635                 :            : */
    7636                 :          0 : static void bnx2x_probe_pci_caps(struct bnx2x_softc *sc)
    7637                 :            : {
    7638                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    7639                 :            : 
    7640                 :            :         struct bnx2x_pci_cap *caps;
    7641                 :            :         uint16_t link_status;
    7642                 :            :         int reg = 0;
    7643                 :            : 
    7644                 :            :         /* check if PCI Power Management is enabled */
    7645                 :            :         caps = pci_find_cap(sc, RTE_PCI_CAP_ID_PM, BNX2X_PCI_CAP);
    7646         [ #  # ]:          0 :         if (NULL != caps) {
    7647                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Found PM capability: "
    7648                 :            :                             "id=0x%04X type=0x%04X addr=0x%08X",
    7649                 :            :                             caps->id, caps->type, caps->addr);
    7650                 :            : 
    7651                 :          0 :                 sc->devinfo.pcie_cap_flags |= BNX2X_PM_CAPABLE_FLAG;
    7652                 :          0 :                 sc->devinfo.pcie_pm_cap_reg = caps->addr;
    7653                 :            :         }
    7654                 :            : 
    7655                 :          0 :         link_status = bnx2x_pcie_capability_read(sc, RTE_PCI_EXP_LNKSTA);
    7656                 :            : 
    7657                 :          0 :         sc->devinfo.pcie_link_speed = (link_status & RTE_PCI_EXP_LNKSTA_CLS);
    7658                 :          0 :         sc->devinfo.pcie_link_width =
    7659                 :          0 :             ((link_status & RTE_PCI_EXP_LNKSTA_NLW) >> 4);
    7660                 :            : 
    7661                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "PCIe link speed=%d width=%d",
    7662                 :            :                     sc->devinfo.pcie_link_speed, sc->devinfo.pcie_link_width);
    7663                 :            : 
    7664                 :          0 :         sc->devinfo.pcie_cap_flags |= BNX2X_PCIE_CAPABLE_FLAG;
    7665                 :            : 
    7666                 :            :         /* check if MSI capability is enabled */
    7667                 :            :         caps = pci_find_cap(sc, RTE_PCI_CAP_ID_MSI, BNX2X_PCI_CAP);
    7668         [ #  # ]:          0 :         if (NULL != caps) {
    7669                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Found MSI capability at 0x%04x", reg);
    7670                 :            : 
    7671                 :          0 :                 sc->devinfo.pcie_cap_flags |= BNX2X_MSI_CAPABLE_FLAG;
    7672                 :          0 :                 sc->devinfo.pcie_msi_cap_reg = caps->addr;
    7673                 :            :         }
    7674                 :            : 
    7675                 :            :         /* check if MSI-X capability is enabled */
    7676                 :            :         caps = pci_find_cap(sc, RTE_PCI_CAP_ID_MSIX, BNX2X_PCI_CAP);
    7677         [ #  # ]:          0 :         if (NULL != caps) {
    7678                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Found MSI-X capability at 0x%04x", reg);
    7679                 :            : 
    7680                 :          0 :                 sc->devinfo.pcie_cap_flags |= BNX2X_MSIX_CAPABLE_FLAG;
    7681                 :          0 :                 sc->devinfo.pcie_msix_cap_reg = caps->addr;
    7682                 :            :         }
    7683                 :          0 : }
    7684                 :            : 
    7685                 :          0 : static int bnx2x_get_shmem_mf_cfg_info_sd(struct bnx2x_softc *sc)
    7686                 :            : {
    7687                 :            :         struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
    7688                 :            :         uint32_t val;
    7689                 :            : 
    7690                 :            :         /* get the outer vlan if we're in switch-dependent mode */
    7691                 :            : 
    7692                 :          0 :         val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
    7693                 :          0 :         mf_info->ext_id = (uint16_t) val;
    7694                 :            : 
    7695                 :          0 :         mf_info->multi_vnics_mode = 1;
    7696                 :            : 
    7697         [ #  # ]:          0 :         if (!VALID_OVLAN(mf_info->ext_id)) {
    7698                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid VLAN (%d)", mf_info->ext_id);
    7699                 :          0 :                 return 1;
    7700                 :            :         }
    7701                 :            : 
    7702                 :            :         /* get the capabilities */
    7703         [ #  # ]:          0 :         if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK) ==
    7704                 :            :             FUNC_MF_CFG_PROTOCOL_ISCSI) {
    7705                 :          0 :                 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ISCSI;
    7706         [ #  # ]:          0 :         } else if ((mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_PROTOCOL_MASK)
    7707                 :            :                    == FUNC_MF_CFG_PROTOCOL_FCOE) {
    7708                 :          0 :                 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_FCOE;
    7709                 :            :         } else {
    7710                 :          0 :                 mf_info->mf_protos_supported |= MF_PROTO_SUPPORT_ETHERNET;
    7711                 :            :         }
    7712                 :            : 
    7713                 :          0 :         mf_info->vnics_per_port =
    7714         [ #  # ]:          0 :             (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
    7715                 :            : 
    7716                 :          0 :         return 0;
    7717                 :            : }
    7718                 :            : 
    7719                 :          0 : static uint32_t bnx2x_get_shmem_ext_proto_support_flags(struct bnx2x_softc *sc)
    7720                 :            : {
    7721                 :            :         uint32_t retval = 0;
    7722                 :            :         uint32_t val;
    7723                 :            : 
    7724                 :          0 :         val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
    7725                 :            : 
    7726         [ #  # ]:          0 :         if (val & MACP_FUNC_CFG_FLAGS_ENABLED) {
    7727         [ #  # ]:          0 :                 if (val & MACP_FUNC_CFG_FLAGS_ETHERNET) {
    7728                 :            :                         retval |= MF_PROTO_SUPPORT_ETHERNET;
    7729                 :            :                 }
    7730         [ #  # ]:          0 :                 if (val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
    7731                 :          0 :                         retval |= MF_PROTO_SUPPORT_ISCSI;
    7732                 :            :                 }
    7733         [ #  # ]:          0 :                 if (val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
    7734                 :          0 :                         retval |= MF_PROTO_SUPPORT_FCOE;
    7735                 :            :                 }
    7736                 :            :         }
    7737                 :            : 
    7738                 :          0 :         return retval;
    7739                 :            : }
    7740                 :            : 
    7741                 :          0 : static int bnx2x_get_shmem_mf_cfg_info_si(struct bnx2x_softc *sc)
    7742                 :            : {
    7743                 :            :         struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
    7744                 :            :         uint32_t val;
    7745                 :            : 
    7746                 :            :         /*
    7747                 :            :          * There is no outer vlan if we're in switch-independent mode.
    7748                 :            :          * If the mac is valid then assume multi-function.
    7749                 :            :          */
    7750                 :            : 
    7751                 :          0 :         val = MFCFG_RD(sc, func_ext_config[SC_ABS_FUNC(sc)].func_cfg);
    7752                 :            : 
    7753                 :          0 :         mf_info->multi_vnics_mode = ((val & MACP_FUNC_CFG_FLAGS_MASK) != 0);
    7754                 :            : 
    7755                 :          0 :         mf_info->mf_protos_supported =
    7756                 :          0 :             bnx2x_get_shmem_ext_proto_support_flags(sc);
    7757                 :            : 
    7758                 :          0 :         mf_info->vnics_per_port =
    7759         [ #  # ]:          0 :             (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
    7760                 :            : 
    7761                 :          0 :         return 0;
    7762                 :            : }
    7763                 :            : 
    7764                 :          0 : static int bnx2x_get_shmem_mf_cfg_info_niv(struct bnx2x_softc *sc)
    7765                 :            : {
    7766                 :            :         struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
    7767                 :            :         uint32_t e1hov_tag;
    7768                 :            :         uint32_t func_config;
    7769                 :            :         uint32_t niv_config;
    7770                 :            : 
    7771                 :          0 :         mf_info->multi_vnics_mode = 1;
    7772                 :            : 
    7773                 :          0 :         e1hov_tag = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
    7774                 :          0 :         func_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
    7775                 :          0 :         niv_config = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].afex_config);
    7776                 :            : 
    7777                 :          0 :         mf_info->ext_id =
    7778                 :          0 :             (uint16_t) ((e1hov_tag & FUNC_MF_CFG_E1HOV_TAG_MASK) >>
    7779                 :            :                         FUNC_MF_CFG_E1HOV_TAG_SHIFT);
    7780                 :            : 
    7781                 :          0 :         mf_info->default_vlan =
    7782                 :          0 :             (uint16_t) ((e1hov_tag & FUNC_MF_CFG_AFEX_VLAN_MASK) >>
    7783                 :            :                         FUNC_MF_CFG_AFEX_VLAN_SHIFT);
    7784                 :            : 
    7785                 :          0 :         mf_info->niv_allowed_priorities =
    7786                 :          0 :             (uint8_t) ((niv_config & FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
    7787                 :            :                        FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT);
    7788                 :            : 
    7789                 :          0 :         mf_info->niv_default_cos =
    7790                 :          0 :             (uint8_t) ((func_config & FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
    7791                 :            :                        FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT);
    7792                 :            : 
    7793                 :          0 :         mf_info->afex_vlan_mode =
    7794                 :          0 :             ((niv_config & FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
    7795                 :            :              FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT);
    7796                 :            : 
    7797                 :          0 :         mf_info->niv_mba_enabled =
    7798                 :          0 :             ((niv_config & FUNC_MF_CFG_AFEX_MBA_ENABLED_MASK) >>
    7799                 :            :              FUNC_MF_CFG_AFEX_MBA_ENABLED_SHIFT);
    7800                 :            : 
    7801                 :          0 :         mf_info->mf_protos_supported =
    7802                 :          0 :             bnx2x_get_shmem_ext_proto_support_flags(sc);
    7803                 :            : 
    7804                 :          0 :         mf_info->vnics_per_port =
    7805         [ #  # ]:          0 :             (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) ? 2 : 4;
    7806                 :            : 
    7807                 :          0 :         return 0;
    7808                 :            : }
    7809                 :            : 
    7810                 :          0 : static int bnx2x_check_valid_mf_cfg(struct bnx2x_softc *sc)
    7811                 :            : {
    7812                 :            :         struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
    7813                 :            :         uint32_t mf_cfg1;
    7814                 :            :         uint32_t mf_cfg2;
    7815                 :            :         uint32_t ovlan1;
    7816                 :            :         uint32_t ovlan2;
    7817                 :            :         uint8_t i, j;
    7818                 :            : 
    7819                 :            :         /* various MF mode sanity checks... */
    7820                 :            : 
    7821         [ #  # ]:          0 :         if (mf_info->mf_config[SC_VN(sc)] & FUNC_MF_CFG_FUNC_HIDE) {
    7822                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    7823                 :            :                             "Enumerated function %d is marked as hidden",
    7824                 :            :                             SC_PORT(sc));
    7825                 :          0 :                 return 1;
    7826                 :            :         }
    7827                 :            : 
    7828   [ #  #  #  # ]:          0 :         if ((mf_info->vnics_per_port > 1) && !mf_info->multi_vnics_mode) {
    7829                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "vnics_per_port=%d multi_vnics_mode=%d",
    7830                 :            :                             mf_info->vnics_per_port, mf_info->multi_vnics_mode);
    7831                 :          0 :                 return 1;
    7832                 :            :         }
    7833                 :            : 
    7834         [ #  # ]:          0 :         if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
    7835                 :            : /* vnic id > 0 must have valid ovlan in switch-dependent mode */
    7836   [ #  #  #  # ]:          0 :                 if ((SC_VN(sc) > 0) && !VALID_OVLAN(OVLAN(sc))) {
    7837                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "mf_mode=SD vnic_id=%d ovlan=%d",
    7838                 :            :                                     SC_VN(sc), OVLAN(sc));
    7839                 :          0 :                         return 1;
    7840                 :            :                 }
    7841                 :            : 
    7842   [ #  #  #  # ]:          0 :                 if (!VALID_OVLAN(OVLAN(sc)) && mf_info->multi_vnics_mode) {
    7843                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    7844                 :            :                                     "mf_mode=SD multi_vnics_mode=%d ovlan=%d",
    7845                 :            :                                     mf_info->multi_vnics_mode, OVLAN(sc));
    7846                 :          0 :                         return 1;
    7847                 :            :                 }
    7848                 :            : 
    7849                 :            : /*
    7850                 :            :  * Verify all functions are either MF or SF mode. If MF, make sure
    7851                 :            :  * sure that all non-hidden functions have a valid ovlan. If SF,
    7852                 :            :  * make sure that all non-hidden functions have an invalid ovlan.
    7853                 :            :  */
    7854   [ #  #  #  #  :          0 :                 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
                   #  # ]
    7855                 :          0 :                         mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
    7856                 :          0 :                         ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
    7857         [ #  # ]:          0 :                         if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE) &&
    7858         [ #  # ]:          0 :                             (((mf_info->multi_vnics_mode)
    7859         [ #  # ]:          0 :                               && !VALID_OVLAN(ovlan1))
    7860         [ #  # ]:          0 :                              || ((!mf_info->multi_vnics_mode)
    7861         [ #  # ]:          0 :                                  && VALID_OVLAN(ovlan1)))) {
    7862                 :          0 :                                 PMD_DRV_LOG(NOTICE, sc,
    7863                 :            :                                             "mf_mode=SD function %d MF config "
    7864                 :            :                                             "mismatch, multi_vnics_mode=%d ovlan=%d",
    7865                 :            :                                             i, mf_info->multi_vnics_mode,
    7866                 :            :                                             ovlan1);
    7867                 :          0 :                                 return 1;
    7868                 :            :                         }
    7869                 :            :                 }
    7870                 :            : 
    7871                 :            : /* Verify all funcs on the same port each have a different ovlan. */
    7872   [ #  #  #  #  :          0 :                 FOREACH_ABS_FUNC_IN_PORT(sc, i) {
                   #  # ]
    7873                 :          0 :                         mf_cfg1 = MFCFG_RD(sc, func_mf_config[i].config);
    7874                 :          0 :                         ovlan1 = MFCFG_RD(sc, func_mf_config[i].e1hov_tag);
    7875                 :            :                         /* iterate from the next function on the port to the max func */
    7876         [ #  # ]:          0 :                         for (j = i + 2; j < MAX_FUNC_NUM; j += 2) {
    7877                 :            :                                 mf_cfg2 =
    7878                 :          0 :                                     MFCFG_RD(sc, func_mf_config[j].config);
    7879                 :            :                                 ovlan2 =
    7880                 :          0 :                                     MFCFG_RD(sc, func_mf_config[j].e1hov_tag);
    7881         [ #  # ]:          0 :                                 if (!(mf_cfg1 & FUNC_MF_CFG_FUNC_HIDE)
    7882         [ #  # ]:          0 :                                     && VALID_OVLAN(ovlan1)
    7883         [ #  # ]:          0 :                                     && !(mf_cfg2 & FUNC_MF_CFG_FUNC_HIDE)
    7884                 :          0 :                                     && VALID_OVLAN(ovlan2)
    7885         [ #  # ]:          0 :                                     && (ovlan1 == ovlan2)) {
    7886                 :          0 :                                         PMD_DRV_LOG(NOTICE, sc,
    7887                 :            :                                                     "mf_mode=SD functions %d and %d "
    7888                 :            :                                                     "have the same ovlan (%d)",
    7889                 :            :                                                     i, j, ovlan1);
    7890                 :          0 :                                         return 1;
    7891                 :            :                                 }
    7892                 :            :                         }
    7893                 :            :                 }
    7894                 :            :         }
    7895                 :            :         /* MULTI_FUNCTION_SD */
    7896                 :            :         return 0;
    7897                 :            : }
    7898                 :            : 
    7899                 :          0 : static int bnx2x_get_mf_cfg_info(struct bnx2x_softc *sc)
    7900                 :            : {
    7901                 :            :         struct bnx2x_mf_info *mf_info = &sc->devinfo.mf_info;
    7902                 :            :         uint32_t val, mac_upper;
    7903                 :            :         uint8_t i, vnic;
    7904                 :            : 
    7905                 :            :         /* initialize mf_info defaults */
    7906                 :          0 :         mf_info->vnics_per_port = 1;
    7907                 :          0 :         mf_info->multi_vnics_mode = FALSE;
    7908                 :          0 :         mf_info->path_has_ovlan = FALSE;
    7909                 :          0 :         mf_info->mf_mode = SINGLE_FUNCTION;
    7910                 :            : 
    7911   [ #  #  #  #  :          0 :         if (!CHIP_IS_MF_CAP(sc)) {
          #  #  #  #  #  
                #  #  # ]
    7912                 :            :                 return 0;
    7913                 :            :         }
    7914                 :            : 
    7915         [ #  # ]:          0 :         if (sc->devinfo.mf_cfg_base == SHMEM_MF_CFG_ADDR_NONE) {
    7916                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid mf_cfg_base!");
    7917                 :          0 :                 return 1;
    7918                 :            :         }
    7919                 :            : 
    7920                 :            :         /* get the MF mode (switch dependent / independent / single-function) */
    7921                 :            : 
    7922                 :          0 :         val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
    7923                 :            : 
    7924   [ #  #  #  #  :          0 :         switch (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) {
                      # ]
    7925                 :          0 :         case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
    7926                 :            : 
    7927                 :            :                 mac_upper =
    7928                 :          0 :                     MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
    7929                 :            : 
    7930                 :            :                 /* check for legal upper mac bytes */
    7931         [ #  # ]:          0 :                 if (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT) {
    7932                 :          0 :                         mf_info->mf_mode = MULTI_FUNCTION_SI;
    7933                 :            :                 } else {
    7934                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    7935                 :            :                                     "Invalid config for Switch Independent mode");
    7936                 :            :                 }
    7937                 :            : 
    7938                 :            :                 break;
    7939                 :            : 
    7940                 :          0 :         case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
    7941                 :            :         case SHARED_FEAT_CFG_FORCE_SF_MODE_SPIO4:
    7942                 :            : 
    7943                 :            :                 /* get outer vlan configuration */
    7944                 :          0 :                 val = MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].e1hov_tag);
    7945                 :            : 
    7946         [ #  # ]:          0 :                 if ((val & FUNC_MF_CFG_E1HOV_TAG_MASK) !=
    7947                 :            :                     FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
    7948                 :          0 :                         mf_info->mf_mode = MULTI_FUNCTION_SD;
    7949                 :            :                 } else {
    7950                 :          0 :                         PMD_DRV_LOG(NOTICE, sc,
    7951                 :            :                                     "Invalid config for Switch Dependent mode");
    7952                 :            :                 }
    7953                 :            : 
    7954                 :            :                 break;
    7955                 :            : 
    7956                 :            :         case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
    7957                 :            : 
    7958                 :            :                 /* not in MF mode, vnics_per_port=1 and multi_vnics_mode=FALSE */
    7959                 :            :                 return 0;
    7960                 :            : 
    7961                 :          0 :         case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
    7962                 :            : 
    7963                 :            :                 /*
    7964                 :            :                  * Mark MF mode as NIV if MCP version includes NPAR-SD support
    7965                 :            :                  * and the MAC address is valid.
    7966                 :            :                  */
    7967                 :            :                 mac_upper =
    7968                 :          0 :                     MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
    7969                 :            : 
    7970   [ #  #  #  #  :          0 :                 if ((SHMEM2_HAS(sc, afex_driver_support)) &&
                   #  # ]
    7971                 :            :                     (mac_upper != FUNC_MF_CFG_UPPERMAC_DEFAULT)) {
    7972                 :          0 :                         mf_info->mf_mode = MULTI_FUNCTION_AFEX;
    7973                 :            :                 } else {
    7974                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Invalid config for AFEX mode");
    7975                 :            :                 }
    7976                 :            : 
    7977                 :            :                 break;
    7978                 :            : 
    7979                 :          0 :         default:
    7980                 :            : 
    7981                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Unknown MF mode (0x%08x)",
    7982                 :            :                             (val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK));
    7983                 :            : 
    7984                 :          0 :                 return 1;
    7985                 :            :         }
    7986                 :            : 
    7987                 :            :         /* set path mf_mode (which could be different than function mf_mode) */
    7988         [ #  # ]:          0 :         if (mf_info->mf_mode == MULTI_FUNCTION_SD) {
    7989                 :          0 :                 mf_info->path_has_ovlan = TRUE;
    7990         [ #  # ]:          0 :         } else if (mf_info->mf_mode == SINGLE_FUNCTION) {
    7991                 :            : /*
    7992                 :            :  * Decide on path multi vnics mode. If we're not in MF mode and in
    7993                 :            :  * 4-port mode, this is good enough to check vnic-0 of the other port
    7994                 :            :  * on the same path
    7995                 :            :  */
    7996         [ #  # ]:          0 :                 if (CHIP_PORT_MODE(sc) == CHIP_4_PORT_MODE) {
    7997                 :          0 :                         uint8_t other_port = !(PORT_ID(sc) & 1);
    7998                 :          0 :                         uint8_t abs_func_other_port =
    7999                 :          0 :                             (SC_PATH(sc) + (2 * other_port));
    8000                 :            : 
    8001                 :            :                         val =
    8002                 :          0 :                             MFCFG_RD(sc,
    8003                 :            :                                      func_mf_config
    8004                 :            :                                      [abs_func_other_port].e1hov_tag);
    8005                 :            : 
    8006                 :          0 :                         mf_info->path_has_ovlan = VALID_OVLAN((uint16_t) val);
    8007                 :            :                 }
    8008                 :            :         }
    8009                 :            : 
    8010         [ #  # ]:          0 :         if (mf_info->mf_mode == SINGLE_FUNCTION) {
    8011                 :            : /* invalid MF config */
    8012         [ #  # ]:          0 :                 if (SC_VN(sc) >= 1) {
    8013                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "VNIC ID >= 1 in SF mode");
    8014                 :          0 :                         return 1;
    8015                 :            :                 }
    8016                 :            : 
    8017                 :            :                 return 0;
    8018                 :            :         }
    8019                 :            : 
    8020                 :            :         /* get the MF configuration */
    8021                 :          0 :         mf_info->mf_config[SC_VN(sc)] =
    8022                 :          0 :             MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].config);
    8023                 :            : 
    8024   [ #  #  #  # ]:          0 :         switch (mf_info->mf_mode) {
    8025                 :          0 :         case MULTI_FUNCTION_SD:
    8026                 :            : 
    8027                 :          0 :                 bnx2x_get_shmem_mf_cfg_info_sd(sc);
    8028                 :          0 :                 break;
    8029                 :            : 
    8030                 :          0 :         case MULTI_FUNCTION_SI:
    8031                 :            : 
    8032                 :          0 :                 bnx2x_get_shmem_mf_cfg_info_si(sc);
    8033                 :          0 :                 break;
    8034                 :            : 
    8035                 :          0 :         case MULTI_FUNCTION_AFEX:
    8036                 :            : 
    8037                 :          0 :                 bnx2x_get_shmem_mf_cfg_info_niv(sc);
    8038                 :          0 :                 break;
    8039                 :            : 
    8040                 :          0 :         default:
    8041                 :            : 
    8042                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Get MF config failed (mf_mode=0x%08x)",
    8043                 :            :                             mf_info->mf_mode);
    8044                 :          0 :                 return 1;
    8045                 :            :         }
    8046                 :            : 
    8047                 :            :         /* get the congestion management parameters */
    8048                 :            : 
    8049                 :            :         vnic = 0;
    8050   [ #  #  #  # ]:          0 :         FOREACH_ABS_FUNC_IN_PORT(sc, i) {
    8051                 :            : /* get min/max bw */
    8052                 :          0 :                 val = MFCFG_RD(sc, func_mf_config[i].config);
    8053                 :          0 :                 mf_info->min_bw[vnic] =
    8054                 :          0 :                     ((val & FUNC_MF_CFG_MIN_BW_MASK) >>
    8055                 :            :                      FUNC_MF_CFG_MIN_BW_SHIFT);
    8056                 :          0 :                 mf_info->max_bw[vnic] =
    8057                 :          0 :                     ((val & FUNC_MF_CFG_MAX_BW_MASK) >>
    8058                 :            :                      FUNC_MF_CFG_MAX_BW_SHIFT);
    8059         [ #  # ]:          0 :                 vnic++;
    8060                 :            :         }
    8061                 :            : 
    8062                 :          0 :         return bnx2x_check_valid_mf_cfg(sc);
    8063                 :            : }
    8064                 :            : 
    8065                 :          0 : static int bnx2x_get_shmem_info(struct bnx2x_softc *sc)
    8066                 :            : {
    8067                 :            :         int port;
    8068                 :            :         uint32_t mac_hi, mac_lo, val;
    8069                 :            : 
    8070                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    8071                 :            : 
    8072                 :          0 :         port = SC_PORT(sc);
    8073                 :            :         mac_hi = mac_lo = 0;
    8074                 :            : 
    8075                 :          0 :         sc->link_params.sc = sc;
    8076                 :          0 :         sc->link_params.port = port;
    8077                 :            : 
    8078                 :            :         /* get the hardware config info */
    8079                 :          0 :         sc->devinfo.hw_config = SHMEM_RD(sc, dev_info.shared_hw_config.config);
    8080                 :          0 :         sc->devinfo.hw_config2 =
    8081                 :          0 :             SHMEM_RD(sc, dev_info.shared_hw_config.config2);
    8082                 :            : 
    8083                 :          0 :         sc->link_params.hw_led_mode =
    8084                 :          0 :             ((sc->devinfo.hw_config & SHARED_HW_CFG_LED_MODE_MASK) >>
    8085                 :            :              SHARED_HW_CFG_LED_MODE_SHIFT);
    8086                 :            : 
    8087                 :            :         /* get the port feature config */
    8088                 :          0 :         sc->port.config =
    8089                 :          0 :             SHMEM_RD(sc, dev_info.port_feature_config[port].config);
    8090                 :            : 
    8091                 :            :         /* get the link params */
    8092                 :          0 :         sc->link_params.speed_cap_mask[ELINK_INT_PHY] =
    8093                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask)
    8094                 :          0 :             & PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
    8095                 :          0 :         sc->link_params.speed_cap_mask[ELINK_EXT_PHY1] =
    8096                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].speed_capability_mask2)
    8097                 :          0 :             & PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
    8098                 :            : 
    8099                 :            :         /* get the lane config */
    8100                 :          0 :         sc->link_params.lane_config =
    8101                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].lane_config);
    8102                 :            : 
    8103                 :            :         /* get the link config */
    8104                 :          0 :         val = SHMEM_RD(sc, dev_info.port_feature_config[port].link_config);
    8105                 :          0 :         sc->port.link_config[ELINK_INT_PHY] = val;
    8106                 :          0 :         sc->link_params.switch_cfg = (val & PORT_FEATURE_CONNECTED_SWITCH_MASK);
    8107                 :          0 :         sc->port.link_config[ELINK_EXT_PHY1] =
    8108                 :          0 :             SHMEM_RD(sc, dev_info.port_feature_config[port].link_config2);
    8109                 :            : 
    8110                 :            :         /* get the override preemphasis flag and enable it or turn it off */
    8111                 :          0 :         val = SHMEM_RD(sc, dev_info.shared_feature_config.config);
    8112         [ #  # ]:          0 :         if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED) {
    8113                 :          0 :                 sc->link_params.feature_config_flags |=
    8114                 :            :                     ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
    8115                 :            :         } else {
    8116                 :          0 :                 sc->link_params.feature_config_flags &=
    8117                 :            :                     ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
    8118                 :            :         }
    8119                 :            : 
    8120                 :          0 :         val = sc->devinfo.bc_ver >> 8;
    8121         [ #  # ]:          0 :         if (val < BNX2X_BC_VER) {
    8122                 :            :                 /* for now only warn later we might need to enforce this */
    8123                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "This driver needs bc_ver %X but found %X, please upgrade BC",
    8124                 :            :                             BNX2X_BC_VER, val);
    8125                 :            :         }
    8126                 :          0 :         sc->link_params.feature_config_flags |=
    8127                 :            :                                 (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
    8128         [ #  # ]:          0 :                                 ELINK_FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY :
    8129                 :            :                                 0;
    8130                 :            : 
    8131                 :          0 :         sc->link_params.feature_config_flags |=
    8132                 :            :                 (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
    8133         [ #  # ]:          0 :                 ELINK_FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
    8134                 :          0 :         sc->link_params.feature_config_flags |=
    8135                 :            :                 (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
    8136         [ #  # ]:          0 :                 ELINK_FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
    8137                 :          0 :         sc->link_params.feature_config_flags |=
    8138                 :            :                 (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
    8139         [ #  # ]:          0 :                 ELINK_FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
    8140                 :            : 
    8141                 :            :         /* get the initial value of the link params */
    8142                 :          0 :         sc->link_params.multi_phy_config =
    8143                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
    8144                 :            : 
    8145                 :            :         /* get external phy info */
    8146                 :          0 :         sc->port.ext_phy_config =
    8147                 :          0 :             SHMEM_RD(sc, dev_info.port_hw_config[port].external_phy_config);
    8148                 :            : 
    8149                 :            :         /* get the multifunction configuration */
    8150                 :          0 :         bnx2x_get_mf_cfg_info(sc);
    8151                 :            : 
    8152                 :            :         /* get the mac address */
    8153   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    8154                 :            :                 mac_hi =
    8155                 :          0 :                     MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_upper);
    8156                 :          0 :                 mac_lo =
    8157                 :          0 :                     MFCFG_RD(sc, func_mf_config[SC_ABS_FUNC(sc)].mac_lower);
    8158                 :            :         } else {
    8159                 :          0 :                 mac_hi = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_upper);
    8160                 :          0 :                 mac_lo = SHMEM_RD(sc, dev_info.port_hw_config[port].mac_lower);
    8161                 :            :         }
    8162                 :            : 
    8163         [ #  # ]:          0 :         if ((mac_lo == 0) && (mac_hi == 0)) {
    8164                 :          0 :                 *sc->mac_addr_str = 0;
    8165                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "No Ethernet address programmed!");
    8166                 :            :         } else {
    8167                 :          0 :                 sc->link_params.mac_addr[0] = (uint8_t) (mac_hi >> 8);
    8168                 :          0 :                 sc->link_params.mac_addr[1] = (uint8_t) (mac_hi);
    8169                 :          0 :                 sc->link_params.mac_addr[2] = (uint8_t) (mac_lo >> 24);
    8170                 :          0 :                 sc->link_params.mac_addr[3] = (uint8_t) (mac_lo >> 16);
    8171                 :          0 :                 sc->link_params.mac_addr[4] = (uint8_t) (mac_lo >> 8);
    8172                 :          0 :                 sc->link_params.mac_addr[5] = (uint8_t) (mac_lo);
    8173                 :          0 :                 snprintf(sc->mac_addr_str, sizeof(sc->mac_addr_str),
    8174                 :            :                          RTE_ETHER_ADDR_PRT_FMT,
    8175                 :            :                          sc->link_params.mac_addr[0],
    8176                 :            :                          sc->link_params.mac_addr[1],
    8177                 :            :                          sc->link_params.mac_addr[2],
    8178                 :            :                          sc->link_params.mac_addr[3],
    8179                 :            :                          sc->link_params.mac_addr[4],
    8180                 :            :                          sc->link_params.mac_addr[5]);
    8181                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
    8182                 :            :                             "Ethernet address: %s", sc->mac_addr_str);
    8183                 :            :         }
    8184                 :            : 
    8185                 :          0 :         return 0;
    8186                 :            : }
    8187                 :            : 
    8188                 :          0 : static void bnx2x_media_detect(struct bnx2x_softc *sc)
    8189                 :            : {
    8190                 :          0 :         uint32_t phy_idx = bnx2x_get_cur_phy_idx(sc);
    8191   [ #  #  #  #  :          0 :         switch (sc->link_params.phy[phy_idx].media_type) {
                      # ]
    8192                 :          0 :         case ELINK_ETH_PHY_SFPP_10G_FIBER:
    8193                 :            :         case ELINK_ETH_PHY_SFP_1G_FIBER:
    8194                 :            :         case ELINK_ETH_PHY_XFP_FIBER:
    8195                 :            :         case ELINK_ETH_PHY_KR:
    8196                 :            :         case ELINK_ETH_PHY_CX4:
    8197                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Found 10GBase-CX4 media.");
    8198                 :          0 :                 sc->media = IFM_10G_CX4;
    8199                 :          0 :                 break;
    8200                 :          0 :         case ELINK_ETH_PHY_DA_TWINAX:
    8201                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Found 10Gb Twinax media.");
    8202                 :          0 :                 sc->media = IFM_10G_TWINAX;
    8203                 :          0 :                 break;
    8204                 :          0 :         case ELINK_ETH_PHY_BASE_T:
    8205                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Found 10GBase-T media.");
    8206                 :          0 :                 sc->media = IFM_10G_T;
    8207                 :          0 :                 break;
    8208                 :          0 :         case ELINK_ETH_PHY_NOT_PRESENT:
    8209                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Media not present.");
    8210                 :          0 :                 sc->media = 0;
    8211                 :          0 :                 break;
    8212                 :          0 :         case ELINK_ETH_PHY_UNSPECIFIED:
    8213                 :            :         default:
    8214                 :          0 :                 PMD_DRV_LOG(INFO, sc, "Unknown media!");
    8215                 :          0 :                 sc->media = 0;
    8216                 :          0 :                 break;
    8217                 :            :         }
    8218                 :          0 : }
    8219                 :            : 
    8220                 :            : #define GET_FIELD(value, fname)                     \
    8221                 :            : (((value) & (fname##_MASK)) >> (fname##_SHIFT))
    8222                 :            : #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
    8223                 :            : #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
    8224                 :            : 
    8225                 :          0 : static int bnx2x_get_igu_cam_info(struct bnx2x_softc *sc)
    8226                 :            : {
    8227                 :          0 :         int pfid = SC_FUNC(sc);
    8228                 :            :         int igu_sb_id;
    8229                 :            :         uint32_t val;
    8230                 :            :         uint8_t fid, igu_sb_cnt = 0;
    8231                 :            : 
    8232                 :          0 :         sc->igu_base_sb = 0xff;
    8233                 :            : 
    8234   [ #  #  #  # ]:          0 :         if (CHIP_INT_MODE_IS_BC(sc)) {
    8235                 :          0 :                 int vn = SC_VN(sc);
    8236                 :            :                 igu_sb_cnt = sc->igu_sb_cnt;
    8237         [ #  # ]:          0 :                 sc->igu_base_sb = ((CHIP_IS_MODE_4_PORT(sc) ? pfid : vn) *
    8238                 :            :                                    FP_SB_MAX_E1x);
    8239         [ #  # ]:          0 :                 sc->igu_dsb_id = (E1HVN_MAX * FP_SB_MAX_E1x +
    8240                 :            :                                   (CHIP_IS_MODE_4_PORT(sc) ? pfid : vn));
    8241                 :          0 :                 return 0;
    8242                 :            :         }
    8243                 :            : 
    8244                 :            :         /* IGU in normal mode - read CAM */
    8245                 :            :         for (igu_sb_id = 0;
    8246         [ #  # ]:          0 :              igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE; igu_sb_id++) {
    8247                 :          0 :                 val = REG_RD(sc, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
    8248         [ #  # ]:          0 :                 if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) {
    8249                 :          0 :                         continue;
    8250                 :            :                 }
    8251                 :          0 :                 fid = IGU_FID(val);
    8252         [ #  # ]:          0 :                 if (fid & IGU_FID_ENCODE_IS_PF) {
    8253         [ #  # ]:          0 :                         if ((fid & IGU_FID_PF_NUM_MASK) != pfid) {
    8254                 :          0 :                                 continue;
    8255                 :            :                         }
    8256         [ #  # ]:          0 :                         if (IGU_VEC(val) == 0) {
    8257                 :            :                                 /* default status block */
    8258                 :          0 :                                 sc->igu_dsb_id = igu_sb_id;
    8259                 :            :                         } else {
    8260         [ #  # ]:          0 :                                 if (sc->igu_base_sb == 0xff) {
    8261                 :          0 :                                         sc->igu_base_sb = igu_sb_id;
    8262                 :            :                                 }
    8263                 :          0 :                                 igu_sb_cnt++;
    8264                 :            :                         }
    8265                 :            :                 }
    8266                 :            :         }
    8267                 :            : 
    8268                 :            :         /*
    8269                 :            :          * Due to new PF resource allocation by MFW T7.4 and above, it's optional
    8270                 :            :          * that number of CAM entries will not be equal to the value advertised in
    8271                 :            :          * PCI. Driver should use the minimal value of both as the actual status
    8272                 :            :          * block count
    8273                 :            :          */
    8274                 :          0 :         sc->igu_sb_cnt = min(sc->igu_sb_cnt, igu_sb_cnt);
    8275                 :            : 
    8276         [ #  # ]:          0 :         if (igu_sb_cnt == 0) {
    8277                 :          0 :                 PMD_DRV_LOG(ERR, sc, "CAM configuration error");
    8278                 :          0 :                 return -1;
    8279                 :            :         }
    8280                 :            : 
    8281                 :            :         return 0;
    8282                 :            : }
    8283                 :            : 
    8284                 :            : /*
    8285                 :            : * Gather various information from the device config space, the device itself,
    8286                 :            : * shmem, and the user input.
    8287                 :            : */
    8288                 :          0 : static int bnx2x_get_device_info(struct bnx2x_softc *sc)
    8289                 :            : {
    8290                 :            :         uint32_t val;
    8291                 :            :         int rc;
    8292                 :            : 
    8293                 :            :         /* get the chip revision (chip metal comes from pci config space) */
    8294                 :          0 :         sc->devinfo.chip_id = sc->link_params.chip_id =
    8295                 :          0 :             (((REG_RD(sc, MISC_REG_CHIP_NUM) & 0xffff) << 16) |
    8296                 :          0 :              ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12) |
    8297                 :          0 :              (((REG_RD(sc, PCICFG_OFFSET + PCI_ID_VAL3) >> 24) & 0xf) << 4) |
    8298                 :          0 :              ((REG_RD(sc, MISC_REG_BOND_ID) & 0xf) << 0));
    8299                 :            : 
    8300                 :            :         /* force 57811 according to MISC register */
    8301         [ #  # ]:          0 :         if (REG_RD(sc, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
    8302         [ #  # ]:          0 :                 if (CHIP_IS_57810(sc)) {
    8303                 :          0 :                         sc->devinfo.chip_id = ((CHIP_NUM_57811 << 16) |
    8304                 :            :                                                (sc->
    8305                 :          0 :                                                 devinfo.chip_id & 0x0000ffff));
    8306         [ #  # ]:          0 :                 } else if (CHIP_IS_57810_MF(sc)) {
    8307                 :          0 :                         sc->devinfo.chip_id = ((CHIP_NUM_57811_MF << 16) |
    8308                 :            :                                                (sc->
    8309                 :          0 :                                                 devinfo.chip_id & 0x0000ffff));
    8310                 :            :                 }
    8311                 :          0 :                 sc->devinfo.chip_id |= 0x1;
    8312                 :            :         }
    8313                 :            : 
    8314                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
    8315                 :            :                     "chip_id=0x%08x (num=0x%04x rev=0x%01x metal=0x%02x bond=0x%01x)",
    8316                 :            :                     sc->devinfo.chip_id,
    8317                 :            :                     ((sc->devinfo.chip_id >> 16) & 0xffff),
    8318                 :            :                     ((sc->devinfo.chip_id >> 12) & 0xf),
    8319                 :            :                     ((sc->devinfo.chip_id >> 4) & 0xff),
    8320                 :            :                     ((sc->devinfo.chip_id >> 0) & 0xf));
    8321                 :            : 
    8322                 :          0 :         val = (REG_RD(sc, 0x2874) & 0x55);
    8323   [ #  #  #  #  :          0 :         if ((sc->devinfo.chip_id & 0x1) || (CHIP_IS_E1H(sc) && (val == 0x55))) {
                   #  # ]
    8324                 :          0 :                 sc->flags |= BNX2X_ONE_PORT_FLAG;
    8325                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "single port device");
    8326                 :            :         }
    8327                 :            : 
    8328                 :            :         /* set the doorbell size */
    8329                 :          0 :         sc->doorbell_size = (1 << BNX2X_DB_SHIFT);
    8330                 :            : 
    8331                 :            :         /* determine whether the device is in 2 port or 4 port mode */
    8332                 :          0 :         sc->devinfo.chip_port_mode = CHIP_PORT_MODE_NONE;    /* E1h */
    8333   [ #  #  #  # ]:          0 :         if (CHIP_IS_E2E3(sc)) {
    8334                 :            : /*
    8335                 :            :  * Read port4mode_en_ovwr[0]:
    8336                 :            :  *   If 1, four port mode is in port4mode_en_ovwr[1].
    8337                 :            :  *   If 0, four port mode is in port4mode_en[0].
    8338                 :            :  */
    8339                 :            :                 val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
    8340         [ #  # ]:          0 :                 if (val & 1) {
    8341                 :          0 :                         val = ((val >> 1) & 1);
    8342                 :            :                 } else {
    8343                 :            :                         val = REG_RD(sc, MISC_REG_PORT4MODE_EN);
    8344                 :            :                 }
    8345                 :            : 
    8346                 :          0 :                 sc->devinfo.chip_port_mode =
    8347                 :          0 :                     (val) ? CHIP_4_PORT_MODE : CHIP_2_PORT_MODE;
    8348                 :            : 
    8349         [ #  # ]:          0 :                 PMD_DRV_LOG(DEBUG, sc, "Port mode = %s", (val) ? "4" : "2");
    8350                 :            :         }
    8351                 :            : 
    8352                 :            :         /* get the function and path info for the device */
    8353                 :          0 :         bnx2x_get_function_num(sc);
    8354                 :            : 
    8355                 :            :         /* get the shared memory base address */
    8356                 :          0 :         sc->devinfo.shmem_base =
    8357                 :          0 :             sc->link_params.shmem_base = REG_RD(sc, MISC_REG_SHARED_MEM_ADDR);
    8358                 :          0 :         sc->devinfo.shmem2_base =
    8359         [ #  # ]:          0 :             REG_RD(sc, (SC_PATH(sc) ? MISC_REG_GENERIC_CR_1 :
    8360                 :            :                         MISC_REG_GENERIC_CR_0));
    8361                 :            : 
    8362         [ #  # ]:          0 :         if (!sc->devinfo.shmem_base) {
    8363                 :            : /* this should ONLY prevent upcoming shmem reads */
    8364                 :          0 :                 PMD_DRV_LOG(INFO, sc, "MCP not active");
    8365                 :          0 :                 sc->flags |= BNX2X_NO_MCP_FLAG;
    8366                 :          0 :                 return 0;
    8367                 :            :         }
    8368                 :            : 
    8369                 :            :         /* make sure the shared memory contents are valid */
    8370                 :          0 :         val = SHMEM_RD(sc, validity_map[SC_PORT(sc)]);
    8371         [ #  # ]:          0 :         if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) !=
    8372                 :            :             (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) {
    8373                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Invalid SHMEM validity signature: 0x%08x",
    8374                 :            :                             val);
    8375                 :          0 :                 return 0;
    8376                 :            :         }
    8377                 :            : 
    8378                 :            :         /* get the bootcode version */
    8379                 :          0 :         sc->devinfo.bc_ver = SHMEM_RD(sc, dev_info.bc_rev);
    8380                 :          0 :         snprintf(sc->devinfo.bc_ver_str,
    8381                 :            :                  sizeof(sc->devinfo.bc_ver_str),
    8382                 :            :                  "%d.%d.%d",
    8383                 :            :                  ((sc->devinfo.bc_ver >> 24) & 0xff),
    8384                 :          0 :                  ((sc->devinfo.bc_ver >> 16) & 0xff),
    8385                 :          0 :                  ((sc->devinfo.bc_ver >> 8) & 0xff));
    8386                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Bootcode version: %s", sc->devinfo.bc_ver_str);
    8387                 :            : 
    8388                 :            :         /* get the bootcode shmem address */
    8389                 :          0 :         sc->devinfo.mf_cfg_base = bnx2x_get_shmem_mf_cfg_base(sc);
    8390                 :            : 
    8391                 :            :         /* clean indirect addresses as they're not used */
    8392                 :          0 :         pci_write_long(sc, PCICFG_GRC_ADDRESS, 0);
    8393         [ #  # ]:          0 :         if (IS_PF(sc)) {
    8394                 :            :                 REG_WR(sc, PXP2_REG_PGL_ADDR_88_F0, 0);
    8395                 :            :                 REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F0, 0);
    8396                 :            :                 REG_WR(sc, PXP2_REG_PGL_ADDR_90_F0, 0);
    8397                 :            :                 REG_WR(sc, PXP2_REG_PGL_ADDR_94_F0, 0);
    8398         [ #  # ]:          0 :                 if (CHIP_IS_E1x(sc)) {
    8399                 :            :                         REG_WR(sc, PXP2_REG_PGL_ADDR_88_F1, 0);
    8400                 :            :                         REG_WR(sc, PXP2_REG_PGL_ADDR_8C_F1, 0);
    8401                 :            :                         REG_WR(sc, PXP2_REG_PGL_ADDR_90_F1, 0);
    8402                 :            :                         REG_WR(sc, PXP2_REG_PGL_ADDR_94_F1, 0);
    8403                 :            :                 }
    8404                 :            :         }
    8405                 :            : 
    8406                 :            :         /* get the nvram size */
    8407                 :            :         val = REG_RD(sc, MCP_REG_MCPR_NVM_CFG4);
    8408                 :          0 :         sc->devinfo.flash_size =
    8409                 :          0 :             (NVRAM_1MB_SIZE << (val & MCPR_NVM_CFG4_FLASH_SIZE));
    8410                 :            : 
    8411                 :          0 :         bnx2x_set_power_state(sc, PCI_PM_D0);
    8412                 :            :         /* get various configuration parameters from shmem */
    8413                 :          0 :         bnx2x_get_shmem_info(sc);
    8414                 :            : 
    8415                 :            :         /* initialize IGU parameters */
    8416         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
    8417                 :          0 :                 sc->devinfo.int_block = INT_BLOCK_HC;
    8418                 :          0 :                 sc->igu_dsb_id = DEF_SB_IGU_ID;
    8419                 :          0 :                 sc->igu_base_sb = 0;
    8420                 :            :         } else {
    8421                 :          0 :                 sc->devinfo.int_block = INT_BLOCK_IGU;
    8422                 :            : 
    8423                 :            : /* do not allow device reset during IGU info processing */
    8424                 :          0 :                 bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
    8425                 :            : 
    8426                 :            :                 val = REG_RD(sc, IGU_REG_BLOCK_CONFIGURATION);
    8427                 :            : 
    8428         [ #  # ]:          0 :                 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
    8429                 :            :                         int tout = 5000;
    8430                 :            : 
    8431                 :          0 :                         val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
    8432                 :            :                         REG_WR(sc, IGU_REG_BLOCK_CONFIGURATION, val);
    8433                 :            :                         REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x7f);
    8434                 :            : 
    8435   [ #  #  #  # ]:          0 :                         while (tout && REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
    8436                 :          0 :                                 tout--;
    8437                 :          0 :                                 DELAY(1000);
    8438                 :            :                         }
    8439                 :            : 
    8440         [ #  # ]:          0 :                         if (REG_RD(sc, IGU_REG_RESET_MEMORIES)) {
    8441                 :          0 :                                 PMD_DRV_LOG(NOTICE, sc,
    8442                 :            :                                             "FORCING IGU Normal Mode failed!!!");
    8443                 :          0 :                                 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
    8444                 :          0 :                                 return -1;
    8445                 :            :                         }
    8446                 :            :                 }
    8447                 :            : 
    8448         [ #  # ]:          0 :                 if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
    8449                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "IGU Backward Compatible Mode");
    8450                 :          0 :                         sc->devinfo.int_block |= INT_BLOCK_MODE_BW_COMP;
    8451                 :            :                 } else {
    8452                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "IGU Normal Mode");
    8453                 :            :                 }
    8454                 :            : 
    8455                 :          0 :                 rc = bnx2x_get_igu_cam_info(sc);
    8456                 :            : 
    8457                 :          0 :                 bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
    8458                 :            : 
    8459         [ #  # ]:          0 :                 if (rc) {
    8460                 :            :                         return rc;
    8461                 :            :                 }
    8462                 :            :         }
    8463                 :            : 
    8464                 :            :         /*
    8465                 :            :          * Get base FW non-default (fast path) status block ID. This value is
    8466                 :            :          * used to initialize the fw_sb_id saved on the fp/queue structure to
    8467                 :            :          * determine the id used by the FW.
    8468                 :            :          */
    8469         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
    8470                 :          0 :                 sc->base_fw_ndsb =
    8471                 :          0 :                     ((SC_PORT(sc) * FP_SB_MAX_E1x) + SC_L_ID(sc));
    8472                 :            :         } else {
    8473                 :            : /*
    8474                 :            :  * 57712+ - We currently use one FW SB per IGU SB (Rx and Tx of
    8475                 :            :  * the same queue are indicated on the same IGU SB). So we prefer
    8476                 :            :  * FW and IGU SBs to be the same value.
    8477                 :            :  */
    8478                 :          0 :                 sc->base_fw_ndsb = sc->igu_base_sb;
    8479                 :            :         }
    8480                 :            : 
    8481                 :          0 :         elink_phy_probe(&sc->link_params);
    8482                 :            : 
    8483                 :          0 :         return 0;
    8484                 :            : }
    8485                 :            : 
    8486                 :            : static void
    8487                 :          0 : bnx2x_link_settings_supported(struct bnx2x_softc *sc, uint32_t switch_cfg)
    8488                 :            : {
    8489                 :            :         uint32_t cfg_size = 0;
    8490                 :            :         uint32_t idx;
    8491                 :          0 :         uint8_t port = SC_PORT(sc);
    8492                 :            : 
    8493                 :            :         /* aggregation of supported attributes of all external phys */
    8494                 :          0 :         sc->port.supported[0] = 0;
    8495                 :          0 :         sc->port.supported[1] = 0;
    8496                 :            : 
    8497   [ #  #  #  # ]:          0 :         switch (sc->link_params.num_phys) {
    8498                 :          0 :         case 1:
    8499                 :          0 :                 sc->port.supported[0] =
    8500                 :          0 :                     sc->link_params.phy[ELINK_INT_PHY].supported;
    8501                 :            :                 cfg_size = 1;
    8502                 :          0 :                 break;
    8503                 :          0 :         case 2:
    8504                 :          0 :                 sc->port.supported[0] =
    8505                 :          0 :                     sc->link_params.phy[ELINK_EXT_PHY1].supported;
    8506                 :            :                 cfg_size = 1;
    8507                 :          0 :                 break;
    8508                 :          0 :         case 3:
    8509         [ #  # ]:          0 :                 if (sc->link_params.multi_phy_config &
    8510                 :            :                     PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
    8511                 :          0 :                         sc->port.supported[1] =
    8512                 :          0 :                             sc->link_params.phy[ELINK_EXT_PHY1].supported;
    8513                 :          0 :                         sc->port.supported[0] =
    8514                 :          0 :                             sc->link_params.phy[ELINK_EXT_PHY2].supported;
    8515                 :            :                 } else {
    8516                 :          0 :                         sc->port.supported[0] =
    8517                 :          0 :                             sc->link_params.phy[ELINK_EXT_PHY1].supported;
    8518                 :          0 :                         sc->port.supported[1] =
    8519                 :          0 :                             sc->link_params.phy[ELINK_EXT_PHY2].supported;
    8520                 :            :                 }
    8521                 :            :                 cfg_size = 2;
    8522                 :            :                 break;
    8523                 :            :         }
    8524                 :            : 
    8525   [ #  #  #  # ]:          0 :         if (!(sc->port.supported[0] || sc->port.supported[1])) {
    8526                 :          0 :                 PMD_DRV_LOG(ERR, sc,
    8527                 :            :                             "Invalid phy config in NVRAM (PHY1=0x%08x PHY2=0x%08x)",
    8528                 :            :                             SHMEM_RD(sc,
    8529                 :            :                                      dev_info.port_hw_config
    8530                 :            :                                      [port].external_phy_config),
    8531                 :            :                             SHMEM_RD(sc,
    8532                 :            :                                      dev_info.port_hw_config
    8533                 :            :                                      [port].external_phy_config2));
    8534                 :          0 :                 return;
    8535                 :            :         }
    8536                 :            : 
    8537         [ #  # ]:          0 :         if (CHIP_IS_E3(sc))
    8538                 :          0 :                 sc->port.phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
    8539                 :            :         else {
    8540      [ #  #  # ]:          0 :                 switch (switch_cfg) {
    8541                 :          0 :                 case ELINK_SWITCH_CFG_1G:
    8542                 :          0 :                         sc->port.phy_addr =
    8543                 :          0 :                             REG_RD(sc,
    8544                 :            :                                    NIG_REG_SERDES0_CTRL_PHY_ADDR + port * 0x10);
    8545                 :          0 :                         break;
    8546                 :          0 :                 case ELINK_SWITCH_CFG_10G:
    8547                 :          0 :                         sc->port.phy_addr =
    8548                 :          0 :                             REG_RD(sc,
    8549                 :            :                                    NIG_REG_XGXS0_CTRL_PHY_ADDR + port * 0x18);
    8550                 :          0 :                         break;
    8551                 :          0 :                 default:
    8552                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    8553                 :            :                                     "Invalid switch config in"
    8554                 :            :                                     "link_config=0x%08x",
    8555                 :            :                                     sc->port.link_config[0]);
    8556                 :          0 :                         return;
    8557                 :            :                 }
    8558                 :            :         }
    8559                 :            : 
    8560                 :          0 :         PMD_DRV_LOG(INFO, sc, "PHY addr 0x%08x", sc->port.phy_addr);
    8561                 :            : 
    8562                 :            :         /* mask what we support according to speed_cap_mask per configuration */
    8563         [ #  # ]:          0 :         for (idx = 0; idx < cfg_size; idx++) {
    8564         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8565                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
    8566                 :          0 :                         sc->port.supported[idx] &=
    8567                 :            :                             ~ELINK_SUPPORTED_10baseT_Half;
    8568                 :            :                 }
    8569                 :            : 
    8570         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8571                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) {
    8572                 :          0 :                         sc->port.supported[idx] &=
    8573                 :            :                             ~ELINK_SUPPORTED_10baseT_Full;
    8574                 :            :                 }
    8575                 :            : 
    8576         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8577                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
    8578                 :          0 :                         sc->port.supported[idx] &=
    8579                 :            :                             ~ELINK_SUPPORTED_100baseT_Half;
    8580                 :            :                 }
    8581                 :            : 
    8582         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8583                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) {
    8584                 :          0 :                         sc->port.supported[idx] &=
    8585                 :            :                             ~ELINK_SUPPORTED_100baseT_Full;
    8586                 :            :                 }
    8587                 :            : 
    8588         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8589                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) {
    8590                 :          0 :                         sc->port.supported[idx] &=
    8591                 :            :                             ~ELINK_SUPPORTED_1000baseT_Full;
    8592                 :            :                 }
    8593                 :            : 
    8594         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8595                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) {
    8596                 :          0 :                         sc->port.supported[idx] &=
    8597                 :            :                             ~ELINK_SUPPORTED_2500baseX_Full;
    8598                 :            :                 }
    8599                 :            : 
    8600         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8601                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
    8602                 :          0 :                         sc->port.supported[idx] &=
    8603                 :            :                             ~ELINK_SUPPORTED_10000baseT_Full;
    8604                 :            :                 }
    8605                 :            : 
    8606         [ #  # ]:          0 :                 if (!(sc->link_params.speed_cap_mask[idx] &
    8607                 :            :                       PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) {
    8608                 :          0 :                         sc->port.supported[idx] &=
    8609                 :            :                             ~ELINK_SUPPORTED_20000baseKR2_Full;
    8610                 :            :                 }
    8611                 :            :         }
    8612                 :            : 
    8613                 :          0 :         PMD_DRV_LOG(INFO, sc, "PHY supported 0=0x%08x 1=0x%08x",
    8614                 :            :                     sc->port.supported[0], sc->port.supported[1]);
    8615                 :            : }
    8616                 :            : 
    8617                 :          0 : static void bnx2x_link_settings_requested(struct bnx2x_softc *sc)
    8618                 :            : {
    8619                 :            :         uint32_t link_config;
    8620                 :            :         uint32_t idx;
    8621                 :            :         uint32_t cfg_size = 0;
    8622                 :            : 
    8623                 :          0 :         sc->port.advertising[0] = 0;
    8624                 :          0 :         sc->port.advertising[1] = 0;
    8625                 :            : 
    8626      [ #  #  # ]:          0 :         switch (sc->link_params.num_phys) {
    8627                 :          0 :         case 1:
    8628                 :            :         case 2:
    8629                 :            :                 cfg_size = 1;
    8630                 :          0 :                 break;
    8631                 :          0 :         case 3:
    8632                 :            :                 cfg_size = 2;
    8633                 :          0 :                 break;
    8634                 :            :         }
    8635                 :            : 
    8636         [ #  # ]:          0 :         for (idx = 0; idx < cfg_size; idx++) {
    8637                 :          0 :                 sc->link_params.req_duplex[idx] = DUPLEX_FULL;
    8638                 :          0 :                 link_config = sc->port.link_config[idx];
    8639                 :            : 
    8640   [ #  #  #  #  :          0 :                 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
          #  #  #  #  #  
                      # ]
    8641                 :          0 :                 case PORT_FEATURE_LINK_SPEED_AUTO:
    8642         [ #  # ]:          0 :                         if (sc->port.supported[idx] & ELINK_SUPPORTED_Autoneg) {
    8643                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8644                 :            :                                     ELINK_SPEED_AUTO_NEG;
    8645                 :          0 :                                 sc->port.advertising[idx] |=
    8646                 :            :                                     sc->port.supported[idx];
    8647         [ #  # ]:          0 :                                 if (sc->link_params.phy[ELINK_EXT_PHY1].type ==
    8648                 :            :                                     PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833)
    8649                 :          0 :                                         sc->port.advertising[idx] |=
    8650                 :            :                                             (ELINK_SUPPORTED_100baseT_Half |
    8651                 :            :                                              ELINK_SUPPORTED_100baseT_Full);
    8652                 :            :                         } else {
    8653                 :            :                                 /* force 10G, no AN */
    8654                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8655                 :            :                                     ELINK_SPEED_10000;
    8656                 :          0 :                                 sc->port.advertising[idx] |=
    8657                 :            :                                     (ADVERTISED_10000baseT_Full |
    8658                 :            :                                      ADVERTISED_FIBRE);
    8659                 :          0 :                                 continue;
    8660                 :            :                         }
    8661                 :            :                         break;
    8662                 :            : 
    8663                 :          0 :                 case PORT_FEATURE_LINK_SPEED_10M_FULL:
    8664                 :          0 :                         if (sc->
    8665         [ #  # ]:          0 :                             port.supported[idx] & ELINK_SUPPORTED_10baseT_Full)
    8666                 :            :                         {
    8667                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8668                 :            :                                     ELINK_SPEED_10;
    8669                 :          0 :                                 sc->port.advertising[idx] |=
    8670                 :            :                                     (ADVERTISED_10baseT_Full | ADVERTISED_TP);
    8671                 :            :                         } else {
    8672                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8673                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8674                 :            :                                             "speed_cap_mask=0x%08x",
    8675                 :            :                                             link_config,
    8676                 :            :                                             sc->
    8677                 :            :                                             link_params.speed_cap_mask[idx]);
    8678                 :          0 :                                 return;
    8679                 :            :                         }
    8680                 :          0 :                         break;
    8681                 :            : 
    8682                 :          0 :                 case PORT_FEATURE_LINK_SPEED_10M_HALF:
    8683                 :          0 :                         if (sc->
    8684         [ #  # ]:          0 :                             port.supported[idx] & ELINK_SUPPORTED_10baseT_Half)
    8685                 :            :                         {
    8686                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8687                 :            :                                     ELINK_SPEED_10;
    8688                 :          0 :                                 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
    8689                 :          0 :                                 sc->port.advertising[idx] |=
    8690                 :            :                                     (ADVERTISED_10baseT_Half | ADVERTISED_TP);
    8691                 :            :                         } else {
    8692                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8693                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8694                 :            :                                             "speed_cap_mask=0x%08x",
    8695                 :            :                                             link_config,
    8696                 :            :                                             sc->
    8697                 :            :                                             link_params.speed_cap_mask[idx]);
    8698                 :          0 :                                 return;
    8699                 :            :                         }
    8700                 :          0 :                         break;
    8701                 :            : 
    8702                 :          0 :                 case PORT_FEATURE_LINK_SPEED_100M_FULL:
    8703                 :          0 :                         if (sc->
    8704         [ #  # ]:          0 :                             port.supported[idx] & ELINK_SUPPORTED_100baseT_Full)
    8705                 :            :                         {
    8706                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8707                 :            :                                     ELINK_SPEED_100;
    8708                 :          0 :                                 sc->port.advertising[idx] |=
    8709                 :            :                                     (ADVERTISED_100baseT_Full | ADVERTISED_TP);
    8710                 :            :                         } else {
    8711                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8712                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8713                 :            :                                             "speed_cap_mask=0x%08x",
    8714                 :            :                                             link_config,
    8715                 :            :                                             sc->
    8716                 :            :                                             link_params.speed_cap_mask[idx]);
    8717                 :          0 :                                 return;
    8718                 :            :                         }
    8719                 :          0 :                         break;
    8720                 :            : 
    8721                 :          0 :                 case PORT_FEATURE_LINK_SPEED_100M_HALF:
    8722                 :          0 :                         if (sc->
    8723         [ #  # ]:          0 :                             port.supported[idx] & ELINK_SUPPORTED_100baseT_Half)
    8724                 :            :                         {
    8725                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8726                 :            :                                     ELINK_SPEED_100;
    8727                 :          0 :                                 sc->link_params.req_duplex[idx] = DUPLEX_HALF;
    8728                 :          0 :                                 sc->port.advertising[idx] |=
    8729                 :            :                                     (ADVERTISED_100baseT_Half | ADVERTISED_TP);
    8730                 :            :                         } else {
    8731                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8732                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8733                 :            :                                             "speed_cap_mask=0x%08x",
    8734                 :            :                                             link_config,
    8735                 :            :                                             sc->
    8736                 :            :                                             link_params.speed_cap_mask[idx]);
    8737                 :          0 :                                 return;
    8738                 :            :                         }
    8739                 :          0 :                         break;
    8740                 :            : 
    8741                 :          0 :                 case PORT_FEATURE_LINK_SPEED_1G:
    8742         [ #  # ]:          0 :                         if (sc->port.supported[idx] &
    8743                 :            :                             ELINK_SUPPORTED_1000baseT_Full) {
    8744                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8745                 :            :                                     ELINK_SPEED_1000;
    8746                 :          0 :                                 sc->port.advertising[idx] |=
    8747                 :            :                                     (ADVERTISED_1000baseT_Full | ADVERTISED_TP);
    8748                 :            :                         } else {
    8749                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8750                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8751                 :            :                                             "speed_cap_mask=0x%08x",
    8752                 :            :                                             link_config,
    8753                 :            :                                             sc->
    8754                 :            :                                             link_params.speed_cap_mask[idx]);
    8755                 :          0 :                                 return;
    8756                 :            :                         }
    8757                 :          0 :                         break;
    8758                 :            : 
    8759                 :          0 :                 case PORT_FEATURE_LINK_SPEED_2_5G:
    8760         [ #  # ]:          0 :                         if (sc->port.supported[idx] &
    8761                 :            :                             ELINK_SUPPORTED_2500baseX_Full) {
    8762                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8763                 :            :                                     ELINK_SPEED_2500;
    8764                 :          0 :                                 sc->port.advertising[idx] |=
    8765                 :            :                                     (ADVERTISED_2500baseX_Full | ADVERTISED_TP);
    8766                 :            :                         } else {
    8767                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8768                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8769                 :            :                                             "speed_cap_mask=0x%08x",
    8770                 :            :                                             link_config,
    8771                 :            :                                             sc->
    8772                 :            :                                             link_params.speed_cap_mask[idx]);
    8773                 :          0 :                                 return;
    8774                 :            :                         }
    8775                 :          0 :                         break;
    8776                 :            : 
    8777                 :          0 :                 case PORT_FEATURE_LINK_SPEED_10G_CX4:
    8778         [ #  # ]:          0 :                         if (sc->port.supported[idx] &
    8779                 :            :                             ELINK_SUPPORTED_10000baseT_Full) {
    8780                 :          0 :                                 sc->link_params.req_line_speed[idx] =
    8781                 :            :                                     ELINK_SPEED_10000;
    8782                 :          0 :                                 sc->port.advertising[idx] |=
    8783                 :            :                                     (ADVERTISED_10000baseT_Full |
    8784                 :            :                                      ADVERTISED_FIBRE);
    8785                 :            :                         } else {
    8786                 :          0 :                                 PMD_DRV_LOG(ERR, sc,
    8787                 :            :                                             "Invalid NVRAM config link_config=0x%08x "
    8788                 :            :                                             "speed_cap_mask=0x%08x",
    8789                 :            :                                             link_config,
    8790                 :            :                                             sc->
    8791                 :            :                                             link_params.speed_cap_mask[idx]);
    8792                 :          0 :                                 return;
    8793                 :            :                         }
    8794                 :          0 :                         break;
    8795                 :            : 
    8796                 :          0 :                 case PORT_FEATURE_LINK_SPEED_20G:
    8797                 :          0 :                         sc->link_params.req_line_speed[idx] = ELINK_SPEED_20000;
    8798                 :          0 :                         break;
    8799                 :            : 
    8800                 :          0 :                 default:
    8801                 :          0 :                         PMD_DRV_LOG(ERR, sc,
    8802                 :            :                                     "Invalid NVRAM config link_config=0x%08x "
    8803                 :            :                                     "speed_cap_mask=0x%08x", link_config,
    8804                 :            :                                     sc->link_params.speed_cap_mask[idx]);
    8805                 :          0 :                         sc->link_params.req_line_speed[idx] =
    8806                 :            :                             ELINK_SPEED_AUTO_NEG;
    8807                 :          0 :                         sc->port.advertising[idx] = sc->port.supported[idx];
    8808                 :          0 :                         break;
    8809                 :            :                 }
    8810                 :            : 
    8811                 :          0 :                 sc->link_params.req_flow_ctrl[idx] =
    8812                 :          0 :                     (link_config & PORT_FEATURE_FLOW_CONTROL_MASK);
    8813                 :            : 
    8814         [ #  # ]:          0 :                 if (sc->link_params.req_flow_ctrl[idx] == ELINK_FLOW_CTRL_AUTO) {
    8815                 :          0 :                         if (!
    8816                 :            :                             (sc->
    8817         [ #  # ]:          0 :                              port.supported[idx] & ELINK_SUPPORTED_Autoneg)) {
    8818                 :          0 :                                 sc->link_params.req_flow_ctrl[idx] =
    8819                 :            :                                     ELINK_FLOW_CTRL_NONE;
    8820                 :            :                         } else {
    8821                 :            :                                 bnx2x_set_requested_fc(sc);
    8822                 :            :                         }
    8823                 :            :                 }
    8824                 :            :         }
    8825                 :            : }
    8826                 :            : 
    8827                 :          0 : static void bnx2x_get_phy_info(struct bnx2x_softc *sc)
    8828                 :            : {
    8829                 :          0 :         uint8_t port = SC_PORT(sc);
    8830                 :            :         uint32_t eee_mode;
    8831                 :            : 
    8832                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    8833                 :            : 
    8834                 :            :         /* shmem data already read in bnx2x_get_shmem_info() */
    8835                 :            : 
    8836                 :          0 :         bnx2x_link_settings_supported(sc, sc->link_params.switch_cfg);
    8837                 :          0 :         bnx2x_link_settings_requested(sc);
    8838                 :            : 
    8839                 :            :         /* configure link feature according to nvram value */
    8840                 :          0 :         eee_mode =
    8841                 :          0 :             (((SHMEM_RD(sc, dev_info.port_feature_config[port].eee_power_mode))
    8842                 :            :               & PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
    8843                 :            :              PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
    8844         [ #  # ]:          0 :         if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
    8845                 :          0 :                 sc->link_params.eee_mode = (ELINK_EEE_MODE_ADV_LPI |
    8846                 :            :                                             ELINK_EEE_MODE_ENABLE_LPI |
    8847                 :            :                                             ELINK_EEE_MODE_OUTPUT_TIME);
    8848                 :            :         } else {
    8849                 :          0 :                 sc->link_params.eee_mode = 0;
    8850                 :            :         }
    8851                 :            : 
    8852                 :            :         /* get the media type */
    8853                 :          0 :         bnx2x_media_detect(sc);
    8854                 :          0 : }
    8855                 :            : 
    8856                 :          0 : static void bnx2x_set_modes_bitmap(struct bnx2x_softc *sc)
    8857                 :            : {
    8858                 :            :         uint32_t flags = MODE_ASIC | MODE_PORT2;
    8859                 :            : 
    8860         [ #  # ]:          0 :         if (CHIP_IS_E2(sc)) {
    8861                 :            :                 flags |= MODE_E2;
    8862         [ #  # ]:          0 :         } else if (CHIP_IS_E3(sc)) {
    8863                 :            :                 flags |= MODE_E3;
    8864         [ #  # ]:          0 :                 if (CHIP_REV(sc) == CHIP_REV_Ax) {
    8865                 :            :                         flags |= MODE_E3_A0;
    8866                 :            :                 } else {        /*if (CHIP_REV(sc) == CHIP_REV_Bx) */
    8867                 :            : 
    8868                 :            :                         flags |= MODE_E3_B0 | MODE_COS3;
    8869                 :            :                 }
    8870                 :            :         }
    8871                 :            : 
    8872   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
    8873                 :          0 :                 flags |= MODE_MF;
    8874   [ #  #  #  # ]:          0 :                 switch (sc->devinfo.mf_info.mf_mode) {
    8875                 :          0 :                 case MULTI_FUNCTION_SD:
    8876                 :          0 :                         flags |= MODE_MF_SD;
    8877                 :          0 :                         break;
    8878                 :          0 :                 case MULTI_FUNCTION_SI:
    8879                 :          0 :                         flags |= MODE_MF_SI;
    8880                 :          0 :                         break;
    8881                 :          0 :                 case MULTI_FUNCTION_AFEX:
    8882                 :          0 :                         flags |= MODE_MF_AFEX;
    8883                 :          0 :                         break;
    8884                 :            :                 }
    8885                 :            :         } else {
    8886                 :          0 :                 flags |= MODE_SF;
    8887                 :            :         }
    8888                 :            : 
    8889                 :            : #if defined(__LITTLE_ENDIAN)
    8890                 :          0 :         flags |= MODE_LITTLE_ENDIAN;
    8891                 :            : #else /* __BIG_ENDIAN */
    8892                 :            :         flags |= MODE_BIG_ENDIAN;
    8893                 :            : #endif
    8894                 :            : 
    8895                 :          0 :         INIT_MODE_FLAGS(sc) = flags;
    8896                 :          0 : }
    8897                 :            : 
    8898                 :          0 : int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
    8899                 :            : {
    8900                 :            :         struct bnx2x_fastpath *fp;
    8901                 :            :         char buf[32];
    8902                 :            :         uint32_t i;
    8903                 :            : 
    8904         [ #  # ]:          0 :         if (IS_PF(sc)) {
    8905                 :            :                 /************************/
    8906                 :            :                 /* DEFAULT STATUS BLOCK */
    8907                 :            :                 /************************/
    8908                 :            : 
    8909         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, sizeof(struct host_sp_status_block),
    8910                 :            :                                   &sc->def_sb_dma, "def_sb",
    8911                 :            :                                   RTE_CACHE_LINE_SIZE) != 0) {
    8912                 :            :                         return -1;
    8913                 :            :                 }
    8914                 :            : 
    8915                 :          0 :                 sc->def_sb =
    8916                 :          0 :                     (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
    8917                 :            :                 /***************/
    8918                 :            :                 /* EVENT QUEUE */
    8919                 :            :                 /***************/
    8920                 :            : 
    8921         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
    8922                 :            :                                   &sc->eq_dma, "ev_queue",
    8923                 :            :                                   RTE_CACHE_LINE_SIZE) != 0) {
    8924                 :          0 :                         sc->def_sb = NULL;
    8925                 :          0 :                         return -1;
    8926                 :            :                 }
    8927                 :            : 
    8928                 :          0 :                 sc->eq = (union event_ring_elem *)sc->eq_dma.vaddr;
    8929                 :            : 
    8930                 :            :                 /*************/
    8931                 :            :                 /* SLOW PATH */
    8932                 :            :                 /*************/
    8933                 :            : 
    8934         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_slowpath),
    8935                 :            :                                   &sc->sp_dma, "sp",
    8936                 :            :                                   RTE_CACHE_LINE_SIZE) != 0) {
    8937                 :          0 :                         sc->eq = NULL;
    8938                 :          0 :                         sc->def_sb = NULL;
    8939                 :          0 :                         return -1;
    8940                 :            :                 }
    8941                 :            : 
    8942                 :          0 :                 sc->sp = (struct bnx2x_slowpath *)sc->sp_dma.vaddr;
    8943                 :            : 
    8944                 :            :                 /*******************/
    8945                 :            :                 /* SLOW PATH QUEUE */
    8946                 :            :                 /*******************/
    8947                 :            : 
    8948         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
    8949                 :            :                                   &sc->spq_dma, "sp_queue",
    8950                 :            :                                   RTE_CACHE_LINE_SIZE) != 0) {
    8951                 :          0 :                         sc->sp = NULL;
    8952                 :          0 :                         sc->eq = NULL;
    8953                 :          0 :                         sc->def_sb = NULL;
    8954                 :          0 :                         return -1;
    8955                 :            :                 }
    8956                 :            : 
    8957                 :          0 :                 sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
    8958                 :            : 
    8959                 :            :                 /***************************/
    8960                 :            :                 /* FW DECOMPRESSION BUFFER */
    8961                 :            :                 /***************************/
    8962                 :            : 
    8963         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
    8964                 :            :                                   "fw_buf", RTE_CACHE_LINE_SIZE) != 0) {
    8965                 :          0 :                         sc->spq = NULL;
    8966                 :          0 :                         sc->sp = NULL;
    8967                 :          0 :                         sc->eq = NULL;
    8968                 :          0 :                         sc->def_sb = NULL;
    8969                 :          0 :                         return -1;
    8970                 :            :                 }
    8971                 :            : 
    8972                 :          0 :                 sc->gz_buf = (void *)sc->gz_buf_dma.vaddr;
    8973                 :            :         }
    8974                 :            : 
    8975                 :            :         /*************/
    8976                 :            :         /* FASTPATHS */
    8977                 :            :         /*************/
    8978                 :            : 
    8979                 :            :         /* allocate DMA memory for each fastpath structure */
    8980         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    8981                 :            :                 fp = &sc->fp[i];
    8982                 :          0 :                 fp->sc = sc;
    8983                 :          0 :                 fp->index = i;
    8984                 :            : 
    8985                 :            :                 /*******************/
    8986                 :            :                 /* FP STATUS BLOCK */
    8987                 :            :                 /*******************/
    8988                 :            : 
    8989                 :            :                 snprintf(buf, sizeof(buf), "fp_%d_sb", i);
    8990         [ #  # ]:          0 :                 if (bnx2x_dma_alloc(sc, sizeof(union bnx2x_host_hc_status_block),
    8991                 :            :                                   &fp->sb_dma, buf, RTE_CACHE_LINE_SIZE) != 0) {
    8992                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Failed to alloc %s", buf);
    8993                 :          0 :                         return -1;
    8994                 :            :                 } else {
    8995   [ #  #  #  # ]:          0 :                         if (CHIP_IS_E2E3(sc)) {
    8996                 :          0 :                                 fp->status_block.e2_sb =
    8997                 :            :                                     (struct host_hc_status_block_e2 *)
    8998                 :          0 :                                     fp->sb_dma.vaddr;
    8999                 :            :                         } else {
    9000                 :          0 :                                 fp->status_block.e1x_sb =
    9001                 :            :                                     (struct host_hc_status_block_e1x *)
    9002                 :          0 :                                     fp->sb_dma.vaddr;
    9003                 :            :                         }
    9004                 :            :                 }
    9005                 :            :         }
    9006                 :            : 
    9007                 :            :         return 0;
    9008                 :            : }
    9009                 :            : 
    9010                 :          0 : void bnx2x_free_hsi_mem(struct bnx2x_softc *sc)
    9011                 :            : {
    9012                 :            :         struct bnx2x_fastpath *fp;
    9013                 :            :         int i;
    9014                 :            : 
    9015         [ #  # ]:          0 :         for (i = 0; i < sc->num_queues; i++) {
    9016                 :            :                 fp = &sc->fp[i];
    9017                 :            : 
    9018                 :            :                 /*******************/
    9019                 :            :                 /* FP STATUS BLOCK */
    9020                 :            :                 /*******************/
    9021                 :            : 
    9022                 :          0 :                 memset(&fp->status_block, 0, sizeof(fp->status_block));
    9023                 :          0 :                 bnx2x_dma_free(&fp->sb_dma);
    9024                 :            :         }
    9025                 :            : 
    9026         [ #  # ]:          0 :         if (IS_PF(sc)) {
    9027                 :            :                 /***************************/
    9028                 :            :                 /* FW DECOMPRESSION BUFFER */
    9029                 :            :                 /***************************/
    9030                 :            : 
    9031                 :          0 :                 bnx2x_dma_free(&sc->gz_buf_dma);
    9032                 :          0 :                 sc->gz_buf = NULL;
    9033                 :            : 
    9034                 :            :                 /*******************/
    9035                 :            :                 /* SLOW PATH QUEUE */
    9036                 :            :                 /*******************/
    9037                 :            : 
    9038                 :          0 :                 bnx2x_dma_free(&sc->spq_dma);
    9039                 :          0 :                 sc->spq = NULL;
    9040                 :            : 
    9041                 :            :                 /*************/
    9042                 :            :                 /* SLOW PATH */
    9043                 :            :                 /*************/
    9044                 :            : 
    9045                 :          0 :                 bnx2x_dma_free(&sc->sp_dma);
    9046                 :          0 :                 sc->sp = NULL;
    9047                 :            : 
    9048                 :            :                 /***************/
    9049                 :            :                 /* EVENT QUEUE */
    9050                 :            :                 /***************/
    9051                 :            : 
    9052                 :          0 :                 bnx2x_dma_free(&sc->eq_dma);
    9053                 :          0 :                 sc->eq = NULL;
    9054                 :            : 
    9055                 :            :                 /************************/
    9056                 :            :                 /* DEFAULT STATUS BLOCK */
    9057                 :            :                 /************************/
    9058                 :            : 
    9059                 :          0 :                 bnx2x_dma_free(&sc->def_sb_dma);
    9060                 :          0 :                 sc->def_sb = NULL;
    9061                 :            :         }
    9062                 :          0 : }
    9063                 :            : 
    9064                 :            : /*
    9065                 :            : * Previous driver DMAE transaction may have occurred when pre-boot stage
    9066                 :            : * ended and boot began. This would invalidate the addresses of the
    9067                 :            : * transaction, resulting in was-error bit set in the PCI causing all
    9068                 :            : * hw-to-host PCIe transactions to timeout. If this happened we want to clear
    9069                 :            : * the interrupt which detected this from the pglueb and the was-done bit
    9070                 :            : */
    9071                 :            : static void bnx2x_prev_interrupted_dmae(struct bnx2x_softc *sc)
    9072                 :            : {
    9073                 :            :         uint32_t val;
    9074                 :            : 
    9075         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    9076                 :            :                 val = REG_RD(sc, PGLUE_B_REG_PGLUE_B_INT_STS);
    9077         [ #  # ]:          0 :                 if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
    9078                 :          0 :                         REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
    9079                 :            :                                1 << SC_FUNC(sc));
    9080                 :            :                 }
    9081                 :            :         }
    9082                 :            : }
    9083                 :            : 
    9084                 :          0 : static int bnx2x_prev_mcp_done(struct bnx2x_softc *sc)
    9085                 :            : {
    9086                 :            :         uint32_t rc = bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_DONE,
    9087                 :            :                                      DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
    9088         [ #  # ]:          0 :         if (!rc) {
    9089                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
    9090                 :          0 :                 return -1;
    9091                 :            :         }
    9092                 :            : 
    9093                 :            :         return 0;
    9094                 :            : }
    9095                 :            : 
    9096                 :            : static struct bnx2x_prev_list_node *bnx2x_prev_path_get_entry(struct bnx2x_softc *sc)
    9097                 :            : {
    9098                 :            :         struct bnx2x_prev_list_node *tmp;
    9099                 :            : 
    9100   [ #  #  #  # ]:          0 :         LIST_FOREACH(tmp, &bnx2x_prev_list, node) {
    9101   [ #  #  #  # ]:          0 :                 if ((sc->pcie_bus == tmp->bus) &&
    9102   [ #  #  #  # ]:          0 :                     (sc->pcie_device == tmp->slot) &&
    9103   [ #  #  #  # ]:          0 :                     (SC_PATH(sc) == tmp->path)) {
    9104                 :            :                         return tmp;
    9105                 :            :                 }
    9106                 :            :         }
    9107                 :            : 
    9108                 :            :         return NULL;
    9109                 :            : }
    9110                 :            : 
    9111                 :          0 : static uint8_t bnx2x_prev_is_path_marked(struct bnx2x_softc *sc)
    9112                 :            : {
    9113                 :            :         struct bnx2x_prev_list_node *tmp;
    9114                 :            :         int rc = FALSE;
    9115                 :            : 
    9116                 :            :         rte_spinlock_lock(&bnx2x_prev_mtx);
    9117                 :            : 
    9118                 :            :         tmp = bnx2x_prev_path_get_entry(sc);
    9119         [ #  # ]:          0 :         if (tmp) {
    9120         [ #  # ]:          0 :                 if (tmp->aer) {
    9121                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    9122                 :            :                                     "Path %d/%d/%d was marked by AER",
    9123                 :            :                                     sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
    9124                 :            :                 } else {
    9125                 :            :                         rc = TRUE;
    9126                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    9127                 :            :                                     "Path %d/%d/%d was already cleaned from previous drivers",
    9128                 :            :                                     sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
    9129                 :            :                 }
    9130                 :            :         }
    9131                 :            : 
    9132                 :            :         rte_spinlock_unlock(&bnx2x_prev_mtx);
    9133                 :            : 
    9134                 :          0 :         return rc;
    9135                 :            : }
    9136                 :            : 
    9137                 :          0 : static int bnx2x_prev_mark_path(struct bnx2x_softc *sc, uint8_t after_undi)
    9138                 :            : {
    9139                 :            :         struct bnx2x_prev_list_node *tmp;
    9140                 :            : 
    9141                 :            :         rte_spinlock_lock(&bnx2x_prev_mtx);
    9142                 :            : 
    9143                 :            :         /* Check whether the entry for this path already exists */
    9144                 :            :         tmp = bnx2x_prev_path_get_entry(sc);
    9145         [ #  # ]:          0 :         if (tmp) {
    9146         [ #  # ]:          0 :                 if (!tmp->aer) {
    9147                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    9148                 :            :                                     "Re-marking AER in path %d/%d/%d",
    9149                 :            :                                     sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
    9150                 :            :                 } else {
    9151                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
    9152                 :            :                                     "Removing AER indication from path %d/%d/%d",
    9153                 :            :                                     sc->pcie_bus, sc->pcie_device, SC_PATH(sc));
    9154                 :          0 :                         tmp->aer = 0;
    9155                 :            :                 }
    9156                 :            : 
    9157                 :            :                 rte_spinlock_unlock(&bnx2x_prev_mtx);
    9158                 :          0 :                 return 0;
    9159                 :            :         }
    9160                 :            : 
    9161                 :            :         rte_spinlock_unlock(&bnx2x_prev_mtx);
    9162                 :            : 
    9163                 :            :         /* Create an entry for this path and add it */
    9164                 :          0 :         tmp = rte_malloc("", sizeof(struct bnx2x_prev_list_node),
    9165                 :            :                          RTE_CACHE_LINE_SIZE);
    9166         [ #  # ]:          0 :         if (!tmp) {
    9167                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Failed to allocate 'bnx2x_prev_list_node'");
    9168                 :          0 :                 return -1;
    9169                 :            :         }
    9170                 :            : 
    9171                 :          0 :         tmp->bus = sc->pcie_bus;
    9172                 :          0 :         tmp->slot = sc->pcie_device;
    9173                 :          0 :         tmp->path = SC_PATH(sc);
    9174                 :          0 :         tmp->aer = 0;
    9175         [ #  # ]:          0 :         tmp->undi = after_undi ? (1 << SC_PORT(sc)) : 0;
    9176                 :            : 
    9177                 :            :         rte_spinlock_lock(&bnx2x_prev_mtx);
    9178                 :            : 
    9179         [ #  # ]:          0 :         LIST_INSERT_HEAD(&bnx2x_prev_list, tmp, node);
    9180                 :            : 
    9181                 :            :         rte_spinlock_unlock(&bnx2x_prev_mtx);
    9182                 :            : 
    9183                 :          0 :         return 0;
    9184                 :            : }
    9185                 :            : 
    9186                 :          0 : static int bnx2x_do_flr(struct bnx2x_softc *sc)
    9187                 :            : {
    9188                 :            :         int i;
    9189                 :            : 
    9190                 :            :         /* only E2 and onwards support FLR */
    9191         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
    9192                 :          0 :                 PMD_DRV_LOG(WARNING, sc, "FLR not supported in E1H");
    9193                 :          0 :                 return -1;
    9194                 :            :         }
    9195                 :            : 
    9196                 :            :         /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
    9197         [ #  # ]:          0 :         if (sc->devinfo.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
    9198                 :          0 :                 PMD_DRV_LOG(WARNING, sc,
    9199                 :            :                             "FLR not supported by BC_VER: 0x%08x",
    9200                 :            :                             sc->devinfo.bc_ver);
    9201                 :          0 :                 return -1;
    9202                 :            :         }
    9203                 :            : 
    9204                 :            :         /* Wait for Transaction Pending bit clean */
    9205         [ #  # ]:          0 :         for (i = 0; i < 4; i++) {
    9206         [ #  # ]:          0 :                 if (i) {
    9207                 :          0 :                         DELAY(((1 << (i - 1)) * 100) * 1000);
    9208                 :            :                 }
    9209                 :            : 
    9210         [ #  # ]:          0 :                 if (!bnx2x_is_pcie_pending(sc)) {
    9211                 :          0 :                         goto clear;
    9212                 :            :                 }
    9213                 :            :         }
    9214                 :            : 
    9215                 :          0 :         PMD_DRV_LOG(NOTICE, sc, "PCIE transaction is not cleared, "
    9216                 :            :                     "proceeding with reset anyway");
    9217                 :            : 
    9218                 :          0 : clear:
    9219                 :            :         bnx2x_fw_command(sc, DRV_MSG_CODE_INITIATE_FLR, 0);
    9220                 :            : 
    9221                 :          0 :         return 0;
    9222                 :            : }
    9223                 :            : 
    9224                 :            : struct bnx2x_mac_vals {
    9225                 :            :         uint32_t xmac_addr;
    9226                 :            :         uint32_t xmac_val;
    9227                 :            :         uint32_t emac_addr;
    9228                 :            :         uint32_t emac_val;
    9229                 :            :         uint32_t umac_addr;
    9230                 :            :         uint32_t umac_val;
    9231                 :            :         uint32_t bmac_addr;
    9232                 :            :         uint32_t bmac_val[2];
    9233                 :            : };
    9234                 :            : 
    9235                 :            : static void
    9236                 :          0 : bnx2x_prev_unload_close_mac(struct bnx2x_softc *sc, struct bnx2x_mac_vals *vals)
    9237                 :            : {
    9238                 :            :         uint32_t val, base_addr, offset, mask, reset_reg;
    9239                 :            :         uint8_t mac_stopped = FALSE;
    9240                 :          0 :         uint8_t port = SC_PORT(sc);
    9241                 :            :         uint32_t wb_data[2];
    9242                 :            : 
    9243                 :            :         /* reset addresses as they also mark which values were changed */
    9244                 :          0 :         vals->bmac_addr = 0;
    9245                 :          0 :         vals->umac_addr = 0;
    9246                 :          0 :         vals->xmac_addr = 0;
    9247                 :          0 :         vals->emac_addr = 0;
    9248                 :            : 
    9249                 :            :         reset_reg = REG_RD(sc, MISC_REG_RESET_REG_2);
    9250                 :            : 
    9251   [ #  #  #  #  :          0 :         if (!CHIP_IS_E3(sc)) {
          #  #  #  #  #  
                      # ]
    9252                 :          0 :                 val = REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
    9253                 :          0 :                 mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
    9254   [ #  #  #  # ]:          0 :                 if ((mask & reset_reg) && val) {
    9255                 :          0 :                         base_addr = SC_PORT(sc) ? NIG_REG_INGRESS_BMAC1_MEM
    9256         [ #  # ]:          0 :                             : NIG_REG_INGRESS_BMAC0_MEM;
    9257                 :            :                         offset = CHIP_IS_E2(sc) ? BIGMAC2_REGISTER_BMAC_CONTROL
    9258                 :            :                             : BIGMAC_REGISTER_BMAC_CONTROL;
    9259                 :            : 
    9260                 :            :                         /*
    9261                 :            :                          * use rd/wr since we cannot use dmae. This is safe
    9262                 :            :                          * since MCP won't access the bus due to the request
    9263                 :            :                          * to unload, and no function on the path can be
    9264                 :            :                          * loaded at this time.
    9265                 :            :                          */
    9266                 :          0 :                         wb_data[0] = REG_RD(sc, base_addr + offset);
    9267                 :          0 :                         wb_data[1] = REG_RD(sc, base_addr + offset + 0x4);
    9268                 :          0 :                         vals->bmac_addr = base_addr + offset;
    9269                 :          0 :                         vals->bmac_val[0] = wb_data[0];
    9270                 :          0 :                         vals->bmac_val[1] = wb_data[1];
    9271                 :          0 :                         wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
    9272                 :            :                         REG_WR(sc, vals->bmac_addr, wb_data[0]);
    9273                 :          0 :                         REG_WR(sc, vals->bmac_addr + 0x4, wb_data[1]);
    9274                 :            :                 }
    9275                 :            : 
    9276                 :          0 :                 vals->emac_addr = NIG_REG_NIG_EMAC0_EN + SC_PORT(sc) * 4;
    9277                 :          0 :                 vals->emac_val = REG_RD(sc, vals->emac_addr);
    9278                 :          0 :                 REG_WR(sc, vals->emac_addr, 0);
    9279                 :            :                 mac_stopped = TRUE;
    9280                 :            :         } else {
    9281         [ #  # ]:          0 :                 if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
    9282         [ #  # ]:          0 :                         base_addr = SC_PORT(sc) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
    9283                 :          0 :                         val = REG_RD(sc, base_addr + XMAC_REG_PFC_CTRL_HI);
    9284                 :          0 :                         REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI,
    9285                 :            :                                val & ~(1 << 1));
    9286                 :          0 :                         REG_WR(sc, base_addr + XMAC_REG_PFC_CTRL_HI,
    9287                 :            :                                val | (1 << 1));
    9288                 :          0 :                         vals->xmac_addr = base_addr + XMAC_REG_CTRL;
    9289                 :          0 :                         vals->xmac_val = REG_RD(sc, vals->xmac_addr);
    9290                 :          0 :                         REG_WR(sc, vals->xmac_addr, 0);
    9291                 :            :                         mac_stopped = TRUE;
    9292                 :            :                 }
    9293                 :            : 
    9294                 :          0 :                 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
    9295         [ #  # ]:          0 :                 if (mask & reset_reg) {
    9296         [ #  # ]:          0 :                         base_addr = SC_PORT(sc) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
    9297                 :          0 :                         vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
    9298                 :          0 :                         vals->umac_val = REG_RD(sc, vals->umac_addr);
    9299                 :          0 :                         REG_WR(sc, vals->umac_addr, 0);
    9300                 :            :                         mac_stopped = TRUE;
    9301                 :            :                 }
    9302                 :            :         }
    9303                 :            : 
    9304         [ #  # ]:          0 :         if (mac_stopped) {
    9305                 :          0 :                 DELAY(20000);
    9306                 :            :         }
    9307                 :          0 : }
    9308                 :            : 
    9309                 :            : #define BNX2X_PREV_UNDI_PROD_ADDR(p)  (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
    9310                 :            : #define BNX2X_PREV_UNDI_RCQ(val)      ((val) & 0xffff)
    9311                 :            : #define BNX2X_PREV_UNDI_BD(val)       ((val) >> 16 & 0xffff)
    9312                 :            : #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
    9313                 :            : 
    9314                 :            : static void
    9315                 :            : bnx2x_prev_unload_undi_inc(struct bnx2x_softc *sc, uint8_t port, uint8_t inc)
    9316                 :            : {
    9317                 :            :         uint16_t rcq, bd;
    9318                 :          0 :         uint32_t tmp_reg = REG_RD(sc, BNX2X_PREV_UNDI_PROD_ADDR(port));
    9319                 :            : 
    9320                 :          0 :         rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
    9321                 :          0 :         bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
    9322                 :            : 
    9323                 :          0 :         tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
    9324                 :            :         REG_WR(sc, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
    9325                 :          0 : }
    9326                 :            : 
    9327                 :          0 : static int bnx2x_prev_unload_common(struct bnx2x_softc *sc)
    9328                 :            : {
    9329                 :            :         uint32_t reset_reg, tmp_reg = 0, rc;
    9330                 :            :         uint8_t prev_undi = FALSE;
    9331                 :            :         struct bnx2x_mac_vals mac_vals;
    9332                 :            :         uint32_t timer_count = 1000;
    9333                 :            :         uint32_t prev_brb;
    9334                 :            : 
    9335                 :            :         /*
    9336                 :            :          * It is possible a previous function received 'common' answer,
    9337                 :            :          * but hasn't loaded yet, therefore creating a scenario of
    9338                 :            :          * multiple functions receiving 'common' on the same path.
    9339                 :            :          */
    9340                 :            :         memset(&mac_vals, 0, sizeof(mac_vals));
    9341                 :            : 
    9342         [ #  # ]:          0 :         if (bnx2x_prev_is_path_marked(sc)) {
    9343                 :          0 :                 return bnx2x_prev_mcp_done(sc);
    9344                 :            :         }
    9345                 :            : 
    9346                 :            :         reset_reg = REG_RD(sc, MISC_REG_RESET_REG_1);
    9347                 :            : 
    9348                 :            :         /* Reset should be performed after BRB is emptied */
    9349         [ #  # ]:          0 :         if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
    9350                 :            :                 /* Close the MAC Rx to prevent BRB from filling up */
    9351                 :          0 :                 bnx2x_prev_unload_close_mac(sc, &mac_vals);
    9352                 :            : 
    9353                 :            :                 /* close LLH filters towards the BRB */
    9354                 :          0 :                 elink_set_rx_filter(&sc->link_params, 0);
    9355                 :            : 
    9356                 :            :                 /*
    9357                 :            :                  * Check if the UNDI driver was previously loaded.
    9358                 :            :                  * UNDI driver initializes CID offset for normal bell to 0x7
    9359                 :            :                  */
    9360         [ #  # ]:          0 :                 if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
    9361                 :            :                         tmp_reg = REG_RD(sc, DORQ_REG_NORM_CID_OFST);
    9362         [ #  # ]:          0 :                         if (tmp_reg == 0x7) {
    9363                 :          0 :                                 PMD_DRV_LOG(DEBUG, sc, "UNDI previously loaded");
    9364                 :            :                                 prev_undi = TRUE;
    9365                 :            :                                 /* clear the UNDI indication */
    9366                 :            :                                 REG_WR(sc, DORQ_REG_NORM_CID_OFST, 0);
    9367                 :            :                                 /* clear possible idle check errors */
    9368                 :            :                                 REG_RD(sc, NIG_REG_NIG_INT_STS_CLR_0);
    9369                 :            :                         }
    9370                 :            :                 }
    9371                 :            : 
    9372                 :            :                 /* wait until BRB is empty */
    9373                 :            :                 tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
    9374         [ #  # ]:          0 :                 while (timer_count) {
    9375                 :            :                         prev_brb = tmp_reg;
    9376                 :            : 
    9377                 :            :                         tmp_reg = REG_RD(sc, BRB1_REG_NUM_OF_FULL_BLOCKS);
    9378         [ #  # ]:          0 :                         if (!tmp_reg) {
    9379                 :            :                                 break;
    9380                 :            :                         }
    9381                 :            : 
    9382                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "BRB still has 0x%08x", tmp_reg);
    9383                 :            : 
    9384                 :            :                         /* reset timer as long as BRB actually gets emptied */
    9385         [ #  # ]:          0 :                         if (prev_brb > tmp_reg) {
    9386                 :            :                                 timer_count = 1000;
    9387                 :            :                         } else {
    9388                 :          0 :                                 timer_count--;
    9389                 :            :                         }
    9390                 :            : 
    9391                 :            :                         /* If UNDI resides in memory, manually increment it */
    9392         [ #  # ]:          0 :                         if (prev_undi) {
    9393                 :          0 :                                 bnx2x_prev_unload_undi_inc(sc, SC_PORT(sc), 1);
    9394                 :            :                         }
    9395                 :            : 
    9396                 :          0 :                         DELAY(10);
    9397                 :            :                 }
    9398                 :            : 
    9399         [ #  # ]:          0 :                 if (!timer_count) {
    9400                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Failed to empty BRB");
    9401                 :            :                 }
    9402                 :            :         }
    9403                 :            : 
    9404                 :            :         /* No packets are in the pipeline, path is ready for reset */
    9405                 :          0 :         bnx2x_reset_common(sc);
    9406                 :            : 
    9407         [ #  # ]:          0 :         if (mac_vals.xmac_addr) {
    9408                 :          0 :                 REG_WR(sc, mac_vals.xmac_addr, mac_vals.xmac_val);
    9409                 :            :         }
    9410         [ #  # ]:          0 :         if (mac_vals.umac_addr) {
    9411                 :          0 :                 REG_WR(sc, mac_vals.umac_addr, mac_vals.umac_val);
    9412                 :            :         }
    9413         [ #  # ]:          0 :         if (mac_vals.emac_addr) {
    9414                 :          0 :                 REG_WR(sc, mac_vals.emac_addr, mac_vals.emac_val);
    9415                 :            :         }
    9416         [ #  # ]:          0 :         if (mac_vals.bmac_addr) {
    9417                 :          0 :                 REG_WR(sc, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
    9418                 :          0 :                 REG_WR(sc, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
    9419                 :            :         }
    9420                 :            : 
    9421                 :          0 :         rc = bnx2x_prev_mark_path(sc, prev_undi);
    9422         [ #  # ]:          0 :         if (rc) {
    9423                 :          0 :                 bnx2x_prev_mcp_done(sc);
    9424                 :          0 :                 return rc;
    9425                 :            :         }
    9426                 :            : 
    9427                 :          0 :         return bnx2x_prev_mcp_done(sc);
    9428                 :            : }
    9429                 :            : 
    9430                 :          0 : static int bnx2x_prev_unload_uncommon(struct bnx2x_softc *sc)
    9431                 :            : {
    9432                 :            :         int rc;
    9433                 :            : 
    9434                 :            :         /* Test if previous unload process was already finished for this path */
    9435         [ #  # ]:          0 :         if (bnx2x_prev_is_path_marked(sc)) {
    9436                 :          0 :                 return bnx2x_prev_mcp_done(sc);
    9437                 :            :         }
    9438                 :            : 
    9439                 :            :         /*
    9440                 :            :          * If function has FLR capabilities, and existing FW version matches
    9441                 :            :          * the one required, then FLR will be sufficient to clean any residue
    9442                 :            :          * left by previous driver
    9443                 :            :          */
    9444                 :          0 :         rc = bnx2x_nic_load_analyze_req(sc, FW_MSG_CODE_DRV_LOAD_FUNCTION);
    9445         [ #  # ]:          0 :         if (!rc) {
    9446                 :            :                 /* fw version is good */
    9447                 :          0 :                 rc = bnx2x_do_flr(sc);
    9448                 :            :         }
    9449                 :            : 
    9450         [ #  # ]:          0 :         if (!rc) {
    9451                 :            :                 /* FLR was performed */
    9452                 :            :                 return 0;
    9453                 :            :         }
    9454                 :            : 
    9455                 :          0 :         PMD_DRV_LOG(INFO, sc, "Could not FLR");
    9456                 :            : 
    9457                 :            :         /* Close the MCP request, return failure */
    9458                 :          0 :         rc = bnx2x_prev_mcp_done(sc);
    9459         [ #  # ]:          0 :         if (!rc) {
    9460                 :            :                 rc = BNX2X_PREV_WAIT_NEEDED;
    9461                 :            :         }
    9462                 :            : 
    9463                 :            :         return rc;
    9464                 :            : }
    9465                 :            : 
    9466                 :          0 : static int bnx2x_prev_unload(struct bnx2x_softc *sc)
    9467                 :            : {
    9468                 :            :         int time_counter = 10;
    9469                 :            :         uint32_t fw, hw_lock_reg, hw_lock_val;
    9470                 :            :         uint32_t rc = 0;
    9471                 :            : 
    9472                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    9473                 :            : 
    9474                 :            :         /*
    9475                 :            :          * Clear HW from errors which may have resulted from an interrupted
    9476                 :            :          * DMAE transaction.
    9477                 :            :          */
    9478                 :            :         bnx2x_prev_interrupted_dmae(sc);
    9479                 :            : 
    9480                 :            :         /* Release previously held locks */
    9481                 :          0 :         hw_lock_reg = (SC_FUNC(sc) <= 5) ?
    9482         [ #  # ]:          0 :                         (MISC_REG_DRIVER_CONTROL_1 + SC_FUNC(sc) * 8) :
    9483                 :          0 :                         (MISC_REG_DRIVER_CONTROL_7 + (SC_FUNC(sc) - 6) * 8);
    9484                 :            : 
    9485                 :          0 :         hw_lock_val = (REG_RD(sc, hw_lock_reg));
    9486         [ #  # ]:          0 :         if (hw_lock_val) {
    9487         [ #  # ]:          0 :                 if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
    9488                 :          0 :                         PMD_DRV_LOG(DEBUG, sc, "Releasing previously held NVRAM lock");
    9489                 :          0 :                         REG_WR(sc, MCP_REG_MCPR_NVM_SW_ARB,
    9490                 :            :                                (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << SC_PORT(sc)));
    9491                 :            :                 }
    9492                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Releasing previously held HW lock");
    9493                 :            :                 REG_WR(sc, hw_lock_reg, 0xffffffff);
    9494                 :            :         }
    9495                 :            : 
    9496         [ #  # ]:          0 :         if (MCPR_ACCESS_LOCK_LOCK & REG_RD(sc, MCP_REG_MCPR_ACCESS_LOCK)) {
    9497                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "Releasing previously held ALR");
    9498                 :            :                 REG_WR(sc, MCP_REG_MCPR_ACCESS_LOCK, 0);
    9499                 :            :         }
    9500                 :            : 
    9501                 :            :         do {
    9502                 :            :                 /* Lock MCP using an unload request */
    9503                 :            :                 fw = bnx2x_fw_command(sc, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
    9504         [ #  # ]:          0 :                 if (!fw) {
    9505                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "MCP response failure, aborting");
    9506                 :            :                         rc = -1;
    9507                 :          0 :                         break;
    9508                 :            :                 }
    9509                 :            : 
    9510         [ #  # ]:          0 :                 if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
    9511                 :          0 :                         rc = bnx2x_prev_unload_common(sc);
    9512                 :          0 :                         break;
    9513                 :            :                 }
    9514                 :            : 
    9515                 :            :                 /* non-common reply from MCP might require looping */
    9516                 :          0 :                 rc = bnx2x_prev_unload_uncommon(sc);
    9517         [ #  # ]:          0 :                 if (rc != BNX2X_PREV_WAIT_NEEDED) {
    9518                 :            :                         break;
    9519                 :            :                 }
    9520                 :            : 
    9521                 :          0 :                 DELAY(20000);
    9522         [ #  # ]:          0 :         } while (--time_counter);
    9523                 :            : 
    9524         [ #  # ]:          0 :         if (!time_counter || rc) {
    9525                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Failed to unload previous driver!");
    9526                 :            :                 rc = -1;
    9527                 :            :         }
    9528                 :            : 
    9529                 :          0 :         return rc;
    9530                 :            : }
    9531                 :            : 
    9532                 :            : static void
    9533                 :          0 : bnx2x_dcbx_set_state(struct bnx2x_softc *sc, uint8_t dcb_on, uint32_t dcbx_enabled)
    9534                 :            : {
    9535         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    9536                 :          0 :                 sc->dcb_state = dcb_on;
    9537                 :          0 :                 sc->dcbx_enabled = dcbx_enabled;
    9538                 :            :         } else {
    9539                 :          0 :                 sc->dcb_state = FALSE;
    9540                 :          0 :                 sc->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
    9541                 :            :         }
    9542   [ #  #  #  #  :          0 :         PMD_DRV_LOG(DEBUG, sc,
             #  #  #  # ]
    9543                 :            :                     "DCB state [%s:%s]",
    9544                 :            :                     dcb_on ? "ON" : "OFF",
    9545                 :            :                     (dcbx_enabled == BNX2X_DCBX_ENABLED_OFF) ? "user-mode" :
    9546                 :            :                     (dcbx_enabled ==
    9547                 :            :                      BNX2X_DCBX_ENABLED_ON_NEG_OFF) ? "on-chip static"
    9548                 :            :                     : (dcbx_enabled ==
    9549                 :            :                        BNX2X_DCBX_ENABLED_ON_NEG_ON) ?
    9550                 :            :                     "on-chip with negotiation" : "invalid");
    9551                 :          0 : }
    9552                 :            : 
    9553                 :            : static int bnx2x_set_qm_cid_count(struct bnx2x_softc *sc)
    9554                 :            : {
    9555                 :          0 :         int cid_count = BNX2X_L2_MAX_CID(sc);
    9556                 :            : 
    9557                 :            :         if (CNIC_SUPPORT(sc)) {
    9558                 :            :                 cid_count += CNIC_CID_MAX;
    9559                 :            :         }
    9560                 :            : 
    9561                 :          0 :         return roundup(cid_count, QM_CID_ROUND);
    9562                 :            : }
    9563                 :            : 
    9564                 :          0 : static void bnx2x_init_multi_cos(struct bnx2x_softc *sc)
    9565                 :            : {
    9566                 :            :         int pri, cos;
    9567                 :            : 
    9568                 :            :         uint32_t pri_map = 0;
    9569                 :            : 
    9570         [ #  # ]:          0 :         for (pri = 0; pri < BNX2X_MAX_PRIORITY; pri++) {
    9571                 :            :                 cos = ((pri_map & (0xf << (pri * 4))) >> (pri * 4));
    9572         [ #  # ]:          0 :                 if (cos < sc->max_cos) {
    9573                 :          0 :                         sc->prio_to_cos[pri] = cos;
    9574                 :            :                 } else {
    9575                 :          0 :                         PMD_DRV_LOG(WARNING, sc,
    9576                 :            :                                     "Invalid COS %d for priority %d "
    9577                 :            :                                     "(max COS is %d), setting to 0", cos, pri,
    9578                 :            :                                     (sc->max_cos - 1));
    9579                 :          0 :                         sc->prio_to_cos[pri] = 0;
    9580                 :            :                 }
    9581                 :            :         }
    9582                 :          0 : }
    9583                 :            : 
    9584                 :            : static uint8_t bnx2x_pci_capabilities[] = {
    9585                 :            :         RTE_PCI_CAP_ID_EXP,
    9586                 :            :         RTE_PCI_CAP_ID_PM,
    9587                 :            :         RTE_PCI_CAP_ID_MSI,
    9588                 :            :         RTE_PCI_CAP_ID_MSIX,
    9589                 :            : };
    9590                 :            : 
    9591                 :          0 : static int bnx2x_pci_get_caps(struct bnx2x_softc *sc)
    9592                 :            : {
    9593                 :            :         struct bnx2x_pci_cap *cap;
    9594                 :            :         unsigned int i;
    9595                 :            : 
    9596                 :          0 :         cap = sc->pci_caps = rte_zmalloc("caps", sizeof(struct bnx2x_pci_cap),
    9597                 :            :                                          RTE_CACHE_LINE_SIZE);
    9598         [ #  # ]:          0 :         if (!cap) {
    9599                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Failed to allocate memory");
    9600                 :          0 :                 return -ENOMEM;
    9601                 :            :         }
    9602                 :            : 
    9603         [ #  # ]:          0 :         if (!rte_pci_has_capability_list(sc->pci_dev)) {
    9604                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PCIe capability reading failed");
    9605                 :          0 :                 return -1;
    9606                 :            :         }
    9607                 :            : 
    9608         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(bnx2x_pci_capabilities); i++) {
    9609                 :          0 :                 off_t pos = rte_pci_find_capability(sc->pci_dev,
    9610                 :          0 :                         bnx2x_pci_capabilities[i]);
    9611                 :            : 
    9612         [ #  # ]:          0 :                 if (pos <= 0)
    9613                 :          0 :                         continue;
    9614                 :            : 
    9615                 :          0 :                 cap->id = bnx2x_pci_capabilities[i];
    9616                 :          0 :                 cap->type = BNX2X_PCI_CAP;
    9617                 :          0 :                 cap->addr = pos;
    9618                 :          0 :                 cap->next = rte_zmalloc("pci_cap",
    9619                 :            :                                         sizeof(struct bnx2x_pci_cap),
    9620                 :            :                                         RTE_CACHE_LINE_SIZE);
    9621         [ #  # ]:          0 :                 if (!cap->next) {
    9622                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "Failed to allocate memory");
    9623                 :          0 :                         return -ENOMEM;
    9624                 :            :                 }
    9625                 :            :                 cap = cap->next;
    9626                 :            :         }
    9627                 :            : 
    9628                 :            :         return 0;
    9629                 :            : }
    9630                 :            : 
    9631                 :            : static void bnx2x_init_rte(struct bnx2x_softc *sc)
    9632                 :            : {
    9633         [ #  # ]:          0 :         if (IS_VF(sc)) {
    9634                 :          0 :                 sc->max_tx_queues = min(BNX2X_VF_MAX_QUEUES_PER_VF,
    9635                 :            :                                         sc->igu_sb_cnt);
    9636                 :          0 :                 sc->max_rx_queues = min(BNX2X_VF_MAX_QUEUES_PER_VF,
    9637                 :            :                                         sc->igu_sb_cnt);
    9638                 :            :         } else {
    9639                 :          0 :                 sc->max_rx_queues = BNX2X_MAX_RSS_COUNT(sc);
    9640                 :          0 :                 sc->max_tx_queues = sc->max_rx_queues;
    9641                 :            :         }
    9642                 :            : }
    9643                 :            : 
    9644                 :            : #define FW_HEADER_LEN 104
    9645                 :            : #define FW_NAME_57711 "/lib/firmware/bnx2x/bnx2x-e1h-7.13.11.0.fw"
    9646                 :            : #define FW_NAME_57810 "/lib/firmware/bnx2x/bnx2x-e2-7.13.11.0.fw"
    9647                 :            : 
    9648                 :          0 : void bnx2x_load_firmware(struct bnx2x_softc *sc)
    9649                 :            : {
    9650                 :            :         const char *fwname;
    9651                 :            :         void *buf;
    9652                 :            :         size_t bufsz;
    9653                 :            : 
    9654                 :          0 :         fwname = sc->devinfo.device_id == CHIP_NUM_57711
    9655         [ #  # ]:          0 :                 ? FW_NAME_57711 : FW_NAME_57810;
    9656         [ #  # ]:          0 :         if (rte_firmware_read(fwname, &buf, &bufsz) != 0) {
    9657                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Can't open firmware file");
    9658                 :          0 :                 return;
    9659                 :            :         }
    9660                 :            : 
    9661                 :          0 :         sc->firmware = rte_zmalloc("bnx2x_fw", bufsz, RTE_CACHE_LINE_SIZE);
    9662         [ #  # ]:          0 :         if (!sc->firmware) {
    9663                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "Can't allocate memory for firmware");
    9664                 :          0 :                 goto out;
    9665                 :            :         }
    9666                 :            : 
    9667                 :          0 :         sc->fw_len = bufsz;
    9668         [ #  # ]:          0 :         if (sc->fw_len < FW_HEADER_LEN) {
    9669                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
    9670                 :            :                             "Invalid fw size: %" PRIu64, sc->fw_len);
    9671                 :          0 :                 goto out;
    9672                 :            :         }
    9673                 :            : 
    9674                 :          0 :         memcpy(sc->firmware, buf, sc->fw_len);
    9675                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "fw_len = %" PRIu64, sc->fw_len);
    9676                 :          0 : out:
    9677                 :          0 :         free(buf);
    9678                 :            : }
    9679                 :            : 
    9680                 :            : static void
    9681                 :          0 : bnx2x_data_to_init_ops(uint8_t * data, struct raw_op *dst, uint32_t len)
    9682                 :            : {
    9683                 :            :         uint32_t *src = (uint32_t *) data;
    9684                 :            :         uint32_t i, j, tmp;
    9685                 :            : 
    9686         [ #  # ]:          0 :         for (i = 0, j = 0; i < len / 8; ++i, j += 2) {
    9687         [ #  # ]:          0 :                 tmp = rte_be_to_cpu_32(src[j]);
    9688                 :          0 :                 dst[i].op = (tmp >> 24) & 0xFF;
    9689                 :          0 :                 dst[i].offset = tmp & 0xFFFFFF;
    9690         [ #  # ]:          0 :                 dst[i].raw_data = rte_be_to_cpu_32(src[j + 1]);
    9691                 :            :         }
    9692                 :          0 : }
    9693                 :            : 
    9694                 :            : static void
    9695                 :            : bnx2x_data_to_init_offsets(uint8_t * data, uint16_t * dst, uint32_t len)
    9696                 :            : {
    9697                 :            :         uint16_t *src = (uint16_t *) data;
    9698                 :            :         uint32_t i;
    9699                 :            : 
    9700         [ #  # ]:          0 :         for (i = 0; i < len / 2; ++i)
    9701         [ #  # ]:          0 :                 dst[i] = rte_be_to_cpu_16(src[i]);
    9702                 :            : }
    9703                 :            : 
    9704                 :          0 : static void bnx2x_data_to_init_data(uint8_t * data, uint32_t * dst, uint32_t len)
    9705                 :            : {
    9706                 :            :         uint32_t *src = (uint32_t *) data;
    9707                 :            :         uint32_t i;
    9708                 :            : 
    9709         [ #  # ]:          0 :         for (i = 0; i < len / 4; ++i)
    9710         [ #  # ]:          0 :                 dst[i] = rte_be_to_cpu_32(src[i]);
    9711                 :          0 : }
    9712                 :            : 
    9713                 :          0 : static void bnx2x_data_to_iro_array(uint8_t * data, struct iro *dst, uint32_t len)
    9714                 :            : {
    9715                 :            :         uint32_t *src = (uint32_t *) data;
    9716                 :            :         uint32_t i, j, tmp;
    9717                 :            : 
    9718         [ #  # ]:          0 :         for (i = 0, j = 0; i < len / sizeof(struct iro); ++i, ++j) {
    9719                 :          0 :                 dst[i].base = rte_be_to_cpu_32(src[j++]);
    9720         [ #  # ]:          0 :                 tmp = rte_be_to_cpu_32(src[j]);
    9721                 :          0 :                 dst[i].m1 = (tmp >> 16) & 0xFFFF;
    9722                 :          0 :                 dst[i].m2 = tmp & 0xFFFF;
    9723                 :          0 :                 ++j;
    9724         [ #  # ]:          0 :                 tmp = rte_be_to_cpu_32(src[j]);
    9725                 :          0 :                 dst[i].m3 = (tmp >> 16) & 0xFFFF;
    9726                 :          0 :                 dst[i].size = tmp & 0xFFFF;
    9727                 :            :         }
    9728                 :          0 : }
    9729                 :            : 
    9730                 :            : /*
    9731                 :            : * Device attach function.
    9732                 :            : *
    9733                 :            : * Allocates device resources, performs secondary chip identification, and
    9734                 :            : * initializes driver instance variables. This function is called from driver
    9735                 :            : * load after a successful probe.
    9736                 :            : *
    9737                 :            : * Returns:
    9738                 :            : *   0 = Success, >0 = Failure
    9739                 :            : */
    9740                 :          0 : int bnx2x_attach(struct bnx2x_softc *sc)
    9741                 :            : {
    9742                 :            :         int rc;
    9743                 :            : 
    9744                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "Starting attach...");
    9745                 :            : 
    9746                 :          0 :         rc = bnx2x_pci_get_caps(sc);
    9747         [ #  # ]:          0 :         if (rc) {
    9748                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PCIe caps reading was failed");
    9749                 :          0 :                 return rc;
    9750                 :            :         }
    9751                 :            : 
    9752                 :          0 :         sc->state = BNX2X_STATE_CLOSED;
    9753                 :            : 
    9754                 :          0 :         pci_write_long(sc, PCICFG_GRC_ADDRESS, PCICFG_VENDOR_ID_OFFSET);
    9755                 :            : 
    9756         [ #  # ]:          0 :         sc->igu_base_addr = IS_VF(sc) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
    9757                 :            : 
    9758                 :            :         /* get PCI capabilities */
    9759                 :          0 :         bnx2x_probe_pci_caps(sc);
    9760                 :            : 
    9761         [ #  # ]:          0 :         if (sc->devinfo.pcie_msix_cap_reg != 0) {
    9762                 :            :                 uint32_t val;
    9763                 :          0 :                 pci_read(sc,
    9764                 :          0 :                          (sc->devinfo.pcie_msix_cap_reg + RTE_PCI_MSIX_FLAGS), &val,
    9765                 :            :                          2);
    9766                 :          0 :                 sc->igu_sb_cnt = (val & RTE_PCI_MSIX_FLAGS_QSIZE) + 1;
    9767                 :            :         } else {
    9768                 :          0 :                 sc->igu_sb_cnt = 1;
    9769                 :            :         }
    9770                 :            : 
    9771                 :            :         /* Init RTE stuff */
    9772                 :            :         bnx2x_init_rte(sc);
    9773                 :            : 
    9774         [ #  # ]:          0 :         if (IS_PF(sc)) {
    9775                 :            :                 /* Enable internal target-read (in case we are probed after PF
    9776                 :            :                  * FLR). Must be done prior to any BAR read access. Only for
    9777                 :            :                  * 57712 and up
    9778                 :            :                  */
    9779         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
    9780                 :            :                         REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ,
    9781                 :            :                                1);
    9782                 :          0 :                         DELAY(200000);
    9783                 :            :                 }
    9784                 :            : 
    9785                 :            :                 /* get device info and set params */
    9786         [ #  # ]:          0 :                 if (bnx2x_get_device_info(sc) != 0) {
    9787                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "getting device info");
    9788                 :          0 :                         return -ENXIO;
    9789                 :            :                 }
    9790                 :            : 
    9791                 :            : /* get phy settings from shmem and 'and' against admin settings */
    9792                 :          0 :                 bnx2x_get_phy_info(sc);
    9793                 :            :         } else {
    9794                 :            :                 /* Left mac of VF unfilled, PF should set it for VF */
    9795                 :          0 :                 memset(sc->link_params.mac_addr, 0, RTE_ETHER_ADDR_LEN);
    9796                 :            :         }
    9797                 :            : 
    9798                 :          0 :         sc->wol = 0;
    9799                 :            : 
    9800                 :            :         /* set the default MTU (changed via ifconfig) */
    9801                 :          0 :         sc->mtu = RTE_ETHER_MTU;
    9802                 :            : 
    9803                 :          0 :         bnx2x_set_modes_bitmap(sc);
    9804                 :            : 
    9805                 :            :         /* need to reset chip if UNDI was active */
    9806         [ #  # ]:          0 :         if (IS_PF(sc) && !BNX2X_NOMCP(sc)) {
    9807                 :            : /* init fw_seq */
    9808                 :          0 :                 sc->fw_seq =
    9809   [ #  #  #  # ]:          0 :                     (SHMEM_RD(sc, func_mb[SC_FW_MB_IDX(sc)].drv_mb_header) &
    9810                 :            :                      DRV_MSG_SEQ_NUMBER_MASK);
    9811                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "prev unload fw_seq 0x%04x",
    9812                 :            :                             sc->fw_seq);
    9813                 :          0 :                 bnx2x_prev_unload(sc);
    9814                 :            :         }
    9815                 :            : 
    9816                 :          0 :         bnx2x_dcbx_set_state(sc, FALSE, BNX2X_DCBX_ENABLED_OFF);
    9817                 :            : 
    9818                 :            :         /* calculate qm_cid_count */
    9819                 :          0 :         sc->qm_cid_count = bnx2x_set_qm_cid_count(sc);
    9820                 :            : 
    9821                 :          0 :         sc->max_cos = 1;
    9822                 :          0 :         bnx2x_init_multi_cos(sc);
    9823                 :            : 
    9824                 :          0 :         return 0;
    9825                 :            : }
    9826                 :            : 
    9827                 :            : static void
    9828                 :            : bnx2x_igu_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id, uint8_t segment,
    9829                 :            :                uint16_t index, uint8_t op, uint8_t update)
    9830                 :            : {
    9831                 :          0 :         uint32_t igu_addr = sc->igu_base_addr;
    9832                 :          0 :         igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id) * 8;
    9833                 :            :         bnx2x_igu_ack_sb_gen(sc, segment, index, op, update, igu_addr);
    9834                 :          0 : }
    9835                 :            : 
    9836                 :            : static void
    9837                 :          0 : bnx2x_ack_sb(struct bnx2x_softc *sc, uint8_t igu_sb_id, uint8_t storm,
    9838                 :            :            uint16_t index, uint8_t op, uint8_t update)
    9839                 :            : {
    9840         [ #  # ]:          0 :         if (unlikely(sc->devinfo.int_block == INT_BLOCK_HC))
    9841                 :          0 :                 bnx2x_hc_ack_sb(sc, igu_sb_id, storm, index, op, update);
    9842                 :            :         else {
    9843                 :            :                 uint8_t segment;
    9844   [ #  #  #  # ]:          0 :                 if (CHIP_INT_MODE_IS_BC(sc)) {
    9845                 :            :                         segment = storm;
    9846         [ #  # ]:          0 :                 } else if (igu_sb_id != sc->igu_dsb_id) {
    9847                 :            :                         segment = IGU_SEG_ACCESS_DEF;
    9848         [ #  # ]:          0 :                 } else if (storm == ATTENTION_ID) {
    9849                 :            :                         segment = IGU_SEG_ACCESS_ATTN;
    9850                 :            :                 } else {
    9851                 :            :                         segment = IGU_SEG_ACCESS_DEF;
    9852                 :            :                 }
    9853                 :          0 :                 bnx2x_igu_ack_sb(sc, igu_sb_id, segment, index, op, update);
    9854                 :            :         }
    9855                 :          0 : }
    9856                 :            : 
    9857                 :            : static void
    9858                 :          0 : bnx2x_igu_clear_sb_gen(struct bnx2x_softc *sc, uint8_t func, uint8_t idu_sb_id,
    9859                 :            :                      uint8_t is_pf)
    9860                 :            : {
    9861                 :            :         uint32_t data, ctl, cnt = 100;
    9862                 :            :         uint32_t igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
    9863                 :            :         uint32_t igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
    9864                 :          0 :         uint32_t igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP +
    9865                 :          0 :             (idu_sb_id / 32) * 4;
    9866                 :          0 :         uint32_t sb_bit = 1 << (idu_sb_id % 32);
    9867                 :          0 :         uint32_t func_encode = func |
    9868         [ #  # ]:          0 :             (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
    9869                 :          0 :         uint32_t addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
    9870                 :            : 
    9871                 :            :         /* Not supported in BC mode */
    9872   [ #  #  #  # ]:          0 :         if (CHIP_INT_MODE_IS_BC(sc)) {
    9873                 :            :                 return;
    9874                 :            :         }
    9875                 :            : 
    9876                 :            :         data = ((IGU_USE_REGISTER_cstorm_type_0_sb_cleanup <<
    9877                 :            :                  IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
    9878                 :            :                 IGU_REGULAR_CLEANUP_SET | IGU_REGULAR_BCLEANUP);
    9879                 :            : 
    9880                 :          0 :         ctl = ((addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT) |
    9881                 :          0 :                (func_encode << IGU_CTRL_REG_FID_SHIFT) |
    9882                 :            :                (IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT));
    9883                 :            : 
    9884                 :            :         REG_WR(sc, igu_addr_data, data);
    9885                 :            : 
    9886                 :            :         mb();
    9887                 :            : 
    9888                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "write 0x%08x to IGU(via GRC) addr 0x%x",
    9889                 :            :                     ctl, igu_addr_ctl);
    9890                 :            :         REG_WR(sc, igu_addr_ctl, ctl);
    9891                 :            : 
    9892                 :            :         mb();
    9893                 :            : 
    9894                 :            :         /* wait for clean up to finish */
    9895   [ #  #  #  # ]:          0 :         while (!(REG_RD(sc, igu_addr_ack) & sb_bit) && --cnt) {
    9896                 :          0 :                 DELAY(20000);
    9897                 :            :         }
    9898                 :            : 
    9899         [ #  # ]:          0 :         if (!(REG_RD(sc, igu_addr_ack) & sb_bit)) {
    9900                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
    9901                 :            :                             "Unable to finish IGU cleanup: "
    9902                 :            :                             "idu_sb_id %d offset %d bit %d (cnt %d)",
    9903                 :            :                             idu_sb_id, idu_sb_id / 32, idu_sb_id % 32, cnt);
    9904                 :            :         }
    9905                 :            : }
    9906                 :            : 
    9907                 :            : static void bnx2x_igu_clear_sb(struct bnx2x_softc *sc, uint8_t idu_sb_id)
    9908                 :            : {
    9909                 :          0 :         bnx2x_igu_clear_sb_gen(sc, SC_FUNC(sc), idu_sb_id, TRUE /*PF*/);
    9910                 :            : }
    9911                 :            : 
    9912                 :            : /*******************/
    9913                 :            : /* ECORE CALLBACKS */
    9914                 :            : /*******************/
    9915                 :            : 
    9916                 :          0 : static void bnx2x_reset_common(struct bnx2x_softc *sc)
    9917                 :            : {
    9918                 :            :         uint32_t val = 0x1400;
    9919                 :            : 
    9920                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
    9921                 :            : 
    9922                 :            :         /* reset_common */
    9923                 :            :         REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR),
    9924                 :            :                0xd3ffff7f);
    9925                 :            : 
    9926         [ #  # ]:          0 :         if (CHIP_IS_E3(sc)) {
    9927                 :            :                 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
    9928                 :            :                 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
    9929                 :            :         }
    9930                 :            : 
    9931                 :            :         REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR), val);
    9932                 :          0 : }
    9933                 :            : 
    9934                 :          0 : static void bnx2x_common_init_phy(struct bnx2x_softc *sc)
    9935                 :            : {
    9936                 :            :         uint32_t shmem_base[2];
    9937                 :            :         uint32_t shmem2_base[2];
    9938                 :            : 
    9939                 :            :         /* Avoid common init in case MFW supports LFA */
    9940                 :          0 :         if (SHMEM2_RD(sc, size) >
    9941         [ #  # ]:          0 :             (uint32_t) offsetof(struct shmem2_region,
    9942                 :            :                                 lfa_host_addr[SC_PORT(sc)])) {
    9943                 :          0 :                 return;
    9944                 :            :         }
    9945                 :            : 
    9946                 :          0 :         shmem_base[0] = sc->devinfo.shmem_base;
    9947                 :          0 :         shmem2_base[0] = sc->devinfo.shmem2_base;
    9948                 :            : 
    9949         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
    9950                 :          0 :                 shmem_base[1] = SHMEM2_RD(sc, other_shmem_base_addr);
    9951                 :          0 :                 shmem2_base[1] = SHMEM2_RD(sc, other_shmem2_base_addr);
    9952                 :            :         }
    9953                 :            : 
    9954                 :          0 :         bnx2x_acquire_phy_lock(sc);
    9955                 :          0 :         elink_common_init_phy(sc, shmem_base, shmem2_base,
    9956                 :            :                               sc->devinfo.chip_id, 0);
    9957                 :            :         bnx2x_release_phy_lock(sc);
    9958                 :            : }
    9959                 :            : 
    9960                 :            : static void bnx2x_pf_disable(struct bnx2x_softc *sc)
    9961                 :            : {
    9962                 :            :         uint32_t val = REG_RD(sc, IGU_REG_PF_CONFIGURATION);
    9963                 :            : 
    9964                 :          0 :         val &= ~IGU_PF_CONF_FUNC_EN;
    9965                 :            : 
    9966                 :            :         REG_WR(sc, IGU_REG_PF_CONFIGURATION, val);
    9967                 :            :         REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
    9968                 :            :         REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 0);
    9969                 :          0 : }
    9970                 :            : 
    9971                 :          0 : static void bnx2x_init_pxp(struct bnx2x_softc *sc)
    9972                 :            : {
    9973                 :            :         uint16_t devctl;
    9974                 :            :         int r_order, w_order;
    9975                 :            : 
    9976                 :          0 :         devctl = bnx2x_pcie_capability_read(sc, RTE_PCI_EXP_DEVCTL);
    9977                 :            : 
    9978                 :          0 :         w_order = ((devctl & RTE_PCI_EXP_DEVCTL_PAYLOAD) >> 5);
    9979                 :          0 :         r_order = ((devctl & RTE_PCI_EXP_DEVCTL_READRQ) >> 12);
    9980                 :            : 
    9981                 :          0 :         ecore_init_pxp_arb(sc, r_order, w_order);
    9982                 :          0 : }
    9983                 :            : 
    9984                 :            : static uint32_t bnx2x_get_pretend_reg(struct bnx2x_softc *sc)
    9985                 :            : {
    9986                 :            :         uint32_t base = PXP2_REG_PGL_PRETEND_FUNC_F0;
    9987                 :            :         uint32_t stride = (PXP2_REG_PGL_PRETEND_FUNC_F1 - base);
    9988                 :          0 :         return base + (SC_ABS_FUNC(sc)) * stride;
    9989                 :            : }
    9990                 :            : 
    9991                 :            : /*
    9992                 :            :  * Called only on E1H or E2.
    9993                 :            :  * When pretending to be PF, the pretend value is the function number 0..7.
    9994                 :            :  * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
    9995                 :            :  * combination.
    9996                 :            :  */
    9997                 :            : static int bnx2x_pretend_func(struct bnx2x_softc *sc, uint16_t pretend_func_val)
    9998                 :            : {
    9999                 :            :         uint32_t pretend_reg;
   10000                 :            : 
   10001   [ #  #  #  # ]:          0 :         if (CHIP_IS_E1H(sc) && (pretend_func_val > E1H_FUNC_MAX))
   10002                 :            :                 return -1;
   10003                 :            : 
   10004                 :            :         /* get my own pretend register */
   10005                 :            :         pretend_reg = bnx2x_get_pretend_reg(sc);
   10006                 :          0 :         REG_WR(sc, pretend_reg, pretend_func_val);
   10007                 :            :         REG_RD(sc, pretend_reg);
   10008                 :          0 :         return 0;
   10009                 :            : }
   10010                 :            : 
   10011                 :          0 : static void bnx2x_setup_fan_failure_detection(struct bnx2x_softc *sc)
   10012                 :            : {
   10013                 :            :         int is_required;
   10014                 :            :         uint32_t val;
   10015                 :            :         int port;
   10016                 :            : 
   10017                 :            :         is_required = 0;
   10018                 :          0 :         val = (SHMEM_RD(sc, dev_info.shared_hw_config.config2) &
   10019                 :            :                SHARED_HW_CFG_FAN_FAILURE_MASK);
   10020                 :            : 
   10021         [ #  # ]:          0 :         if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED) {
   10022                 :            :                 is_required = 1;
   10023                 :            :         }
   10024                 :            :         /*
   10025                 :            :          * The fan failure mechanism is usually related to the PHY type since
   10026                 :            :          * the power consumption of the board is affected by the PHY. Currently,
   10027                 :            :          * fan is required for most designs with SFX7101, BNX2X8727 and BNX2X8481.
   10028                 :            :          */
   10029         [ #  # ]:          0 :         else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE) {
   10030         [ #  # ]:          0 :                 for (port = PORT_0; port < PORT_MAX; port++) {
   10031                 :          0 :                         is_required |= elink_fan_failure_det_req(sc,
   10032                 :            :                                                                  sc->
   10033                 :            :                                                                  devinfo.shmem_base,
   10034                 :            :                                                                  sc->
   10035                 :            :                                                                  devinfo.shmem2_base,
   10036                 :            :                                                                  port);
   10037                 :            :                 }
   10038                 :            :         }
   10039                 :            : 
   10040         [ #  # ]:          0 :         if (is_required == 0) {
   10041                 :          0 :                 return;
   10042                 :            :         }
   10043                 :            : 
   10044                 :            :         /* Fan failure is indicated by SPIO 5 */
   10045                 :          0 :         bnx2x_set_spio(sc, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
   10046                 :            : 
   10047                 :            :         /* set to active low mode */
   10048                 :            :         val = REG_RD(sc, MISC_REG_SPIO_INT);
   10049                 :          0 :         val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
   10050                 :            :         REG_WR(sc, MISC_REG_SPIO_INT, val);
   10051                 :            : 
   10052                 :            :         /* enable interrupt to signal the IGU */
   10053                 :            :         val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
   10054                 :          0 :         val |= MISC_SPIO_SPIO5;
   10055                 :            :         REG_WR(sc, MISC_REG_SPIO_EVENT_EN, val);
   10056                 :            : }
   10057                 :            : 
   10058                 :          0 : static void bnx2x_enable_blocks_attention(struct bnx2x_softc *sc)
   10059                 :            : {
   10060                 :            :         uint32_t val;
   10061                 :            : 
   10062                 :            :         REG_WR(sc, PXP_REG_PXP_INT_MASK_0, 0);
   10063         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10064                 :            :                 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0x40);
   10065                 :            :         } else {
   10066                 :            :                 REG_WR(sc, PXP_REG_PXP_INT_MASK_1, 0);
   10067                 :            :         }
   10068                 :            :         REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
   10069                 :            :         REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
   10070                 :            :         /*
   10071                 :            :          * mask read length error interrupts in brb for parser
   10072                 :            :          * (parsing unit and 'checksum and crc' unit)
   10073                 :            :          * these errors are legal (PU reads fixed length and CAC can cause
   10074                 :            :          * read length error on truncated packets)
   10075                 :            :          */
   10076                 :            :         REG_WR(sc, BRB1_REG_BRB1_INT_MASK, 0xFC00);
   10077                 :            :         REG_WR(sc, QM_REG_QM_INT_MASK, 0);
   10078                 :            :         REG_WR(sc, TM_REG_TM_INT_MASK, 0);
   10079                 :            :         REG_WR(sc, XSDM_REG_XSDM_INT_MASK_0, 0);
   10080                 :            :         REG_WR(sc, XSDM_REG_XSDM_INT_MASK_1, 0);
   10081                 :            :         REG_WR(sc, XCM_REG_XCM_INT_MASK, 0);
   10082                 :            :         /*      REG_WR(sc, XSEM_REG_XSEM_INT_MASK_0, 0); */
   10083                 :            :         /*      REG_WR(sc, XSEM_REG_XSEM_INT_MASK_1, 0); */
   10084                 :            :         REG_WR(sc, USDM_REG_USDM_INT_MASK_0, 0);
   10085                 :            :         REG_WR(sc, USDM_REG_USDM_INT_MASK_1, 0);
   10086                 :            :         REG_WR(sc, UCM_REG_UCM_INT_MASK, 0);
   10087                 :            :         /*      REG_WR(sc, USEM_REG_USEM_INT_MASK_0, 0); */
   10088                 :            :         /*      REG_WR(sc, USEM_REG_USEM_INT_MASK_1, 0); */
   10089                 :            :         REG_WR(sc, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
   10090                 :            :         REG_WR(sc, CSDM_REG_CSDM_INT_MASK_0, 0);
   10091                 :            :         REG_WR(sc, CSDM_REG_CSDM_INT_MASK_1, 0);
   10092                 :            :         REG_WR(sc, CCM_REG_CCM_INT_MASK, 0);
   10093                 :            :         /*      REG_WR(sc, CSEM_REG_CSEM_INT_MASK_0, 0); */
   10094                 :            :         /*      REG_WR(sc, CSEM_REG_CSEM_INT_MASK_1, 0); */
   10095                 :            : 
   10096                 :            :         val = (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
   10097                 :            :                PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
   10098                 :            :                PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN);
   10099         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10100                 :            :                 val |= (PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
   10101                 :            :                         PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED);
   10102                 :            :         }
   10103                 :            :         REG_WR(sc, PXP2_REG_PXP2_INT_MASK_0, val);
   10104                 :            : 
   10105                 :            :         REG_WR(sc, TSDM_REG_TSDM_INT_MASK_0, 0);
   10106                 :            :         REG_WR(sc, TSDM_REG_TSDM_INT_MASK_1, 0);
   10107                 :            :         REG_WR(sc, TCM_REG_TCM_INT_MASK, 0);
   10108                 :            :         /*      REG_WR(sc, TSEM_REG_TSEM_INT_MASK_0, 0); */
   10109                 :            : 
   10110         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10111                 :            : /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
   10112                 :            :                 REG_WR(sc, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
   10113                 :            :         }
   10114                 :            : 
   10115                 :            :         REG_WR(sc, CDU_REG_CDU_INT_MASK, 0);
   10116                 :            :         REG_WR(sc, DMAE_REG_DMAE_INT_MASK, 0);
   10117                 :            :         /*      REG_WR(sc, MISC_REG_MISC_INT_MASK, 0); */
   10118                 :            :         REG_WR(sc, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
   10119                 :          0 : }
   10120                 :            : 
   10121                 :            : /**
   10122                 :            :  * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
   10123                 :            :  *
   10124                 :            :  * @sc:     driver handle
   10125                 :            :  */
   10126                 :          0 : static int bnx2x_init_hw_common(struct bnx2x_softc *sc)
   10127                 :            : {
   10128                 :            :         uint8_t abs_func_id;
   10129                 :            :         uint32_t val;
   10130                 :            : 
   10131                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
   10132                 :            :                     "starting common init for func %d", SC_ABS_FUNC(sc));
   10133                 :            : 
   10134                 :            :         /*
   10135                 :            :          * take the RESET lock to protect undi_unload flow from accessing
   10136                 :            :          * registers while we are resetting the chip
   10137                 :            :          */
   10138                 :          0 :         bnx2x_acquire_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
   10139                 :            : 
   10140                 :          0 :         bnx2x_reset_common(sc);
   10141                 :            : 
   10142                 :            :         REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET), 0xffffffff);
   10143                 :            : 
   10144                 :            :         val = 0xfffc;
   10145         [ #  # ]:          0 :         if (CHIP_IS_E3(sc)) {
   10146                 :            :                 val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
   10147                 :            :                 val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
   10148                 :            :         }
   10149                 :            : 
   10150                 :            :         REG_WR(sc, (GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET), val);
   10151                 :            : 
   10152                 :          0 :         bnx2x_release_hw_lock(sc, HW_LOCK_RESOURCE_RESET);
   10153                 :            : 
   10154                 :          0 :         ecore_init_block(sc, BLOCK_MISC, PHASE_COMMON);
   10155                 :            : 
   10156         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10157                 :            : /*
   10158                 :            :  * 4-port mode or 2-port mode we need to turn off master-enable for
   10159                 :            :  * everyone. After that we turn it back on for self. So, we disregard
   10160                 :            :  * multi-function, and always disable all functions on the given path,
   10161                 :            :  * this means 0,2,4,6 for path 0 and 1,3,5,7 for path 1
   10162                 :            :  */
   10163                 :          0 :                 for (abs_func_id = SC_PATH(sc);
   10164         [ #  # ]:          0 :                      abs_func_id < (E2_FUNC_MAX * 2); abs_func_id += 2) {
   10165         [ #  # ]:          0 :                         if (abs_func_id == SC_ABS_FUNC(sc)) {
   10166                 :            :                                 REG_WR(sc,
   10167                 :            :                                        PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
   10168                 :            :                                        1);
   10169                 :          0 :                                 continue;
   10170                 :            :                         }
   10171                 :            : 
   10172                 :            :                         bnx2x_pretend_func(sc, abs_func_id);
   10173                 :            : 
   10174                 :            :                         /* clear pf enable */
   10175                 :            :                         bnx2x_pf_disable(sc);
   10176                 :            : 
   10177         [ #  # ]:          0 :                         bnx2x_pretend_func(sc, SC_ABS_FUNC(sc));
   10178                 :            :                 }
   10179                 :            :         }
   10180                 :            : 
   10181                 :          0 :         ecore_init_block(sc, BLOCK_PXP, PHASE_COMMON);
   10182                 :            : 
   10183                 :          0 :         ecore_init_block(sc, BLOCK_PXP2, PHASE_COMMON);
   10184                 :          0 :         bnx2x_init_pxp(sc);
   10185                 :            : 
   10186                 :            : #ifdef __BIG_ENDIAN
   10187                 :            :         REG_WR(sc, PXP2_REG_RQ_QM_ENDIAN_M, 1);
   10188                 :            :         REG_WR(sc, PXP2_REG_RQ_TM_ENDIAN_M, 1);
   10189                 :            :         REG_WR(sc, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
   10190                 :            :         REG_WR(sc, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
   10191                 :            :         REG_WR(sc, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
   10192                 :            :         /* make sure this value is 0 */
   10193                 :            :         REG_WR(sc, PXP2_REG_RQ_HC_ENDIAN_M, 0);
   10194                 :            : 
   10195                 :            :         //REG_WR(sc, PXP2_REG_RD_PBF_SWAP_MODE, 1);
   10196                 :            :         REG_WR(sc, PXP2_REG_RD_QM_SWAP_MODE, 1);
   10197                 :            :         REG_WR(sc, PXP2_REG_RD_TM_SWAP_MODE, 1);
   10198                 :            :         REG_WR(sc, PXP2_REG_RD_SRC_SWAP_MODE, 1);
   10199                 :            :         REG_WR(sc, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
   10200                 :            : #endif
   10201                 :            : 
   10202                 :          0 :         ecore_ilt_init_page_size(sc, INITOP_SET);
   10203                 :            : 
   10204   [ #  #  #  #  :          0 :         if (CHIP_REV_IS_FPGA(sc) && CHIP_IS_E1H(sc)) {
                   #  # ]
   10205                 :            :                 REG_WR(sc, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
   10206                 :            :         }
   10207                 :            : 
   10208                 :            :         /* let the HW do it's magic... */
   10209                 :          0 :         DELAY(100000);
   10210                 :            : 
   10211                 :            :         /* finish PXP init */
   10212                 :            : 
   10213                 :            :         val = REG_RD(sc, PXP2_REG_RQ_CFG_DONE);
   10214         [ #  # ]:          0 :         if (val != 1) {
   10215                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PXP2 CFG failed");
   10216                 :          0 :                 return -1;
   10217                 :            :         }
   10218                 :            :         val = REG_RD(sc, PXP2_REG_RD_INIT_DONE);
   10219         [ #  # ]:          0 :         if (val != 1) {
   10220                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PXP2 RD_INIT failed");
   10221                 :          0 :                 return -1;
   10222                 :            :         }
   10223                 :            : 
   10224                 :            :         /*
   10225                 :            :          * Timer bug workaround for E2 only. We need to set the entire ILT to have
   10226                 :            :          * entries with value "0" and valid bit on. This needs to be done by the
   10227                 :            :          * first PF that is loaded in a path (i.e. common phase)
   10228                 :            :          */
   10229         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10230                 :            : /*
   10231                 :            :  * In E2 there is a bug in the timers block that can cause function 6 / 7
   10232                 :            :  * (i.e. vnic3) to start even if it is marked as "scan-off".
   10233                 :            :  * This occurs when a different function (func2,3) is being marked
   10234                 :            :  * as "scan-off". Real-life scenario for example: if a driver is being
   10235                 :            :  * load-unloaded while func6,7 are down. This will cause the timer to access
   10236                 :            :  * the ilt, translate to a logical address and send a request to read/write.
   10237                 :            :  * Since the ilt for the function that is down is not valid, this will cause
   10238                 :            :  * a translation error which is unrecoverable.
   10239                 :            :  * The Workaround is intended to make sure that when this happens nothing
   10240                 :            :  * fatal will occur. The workaround:
   10241                 :            :  *  1.  First PF driver which loads on a path will:
   10242                 :            :  *      a.  After taking the chip out of reset, by using pretend,
   10243                 :            :  *          it will write "0" to the following registers of
   10244                 :            :  *          the other vnics.
   10245                 :            :  *          REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
   10246                 :            :  *          REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
   10247                 :            :  *          REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
   10248                 :            :  *          And for itself it will write '1' to
   10249                 :            :  *          PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
   10250                 :            :  *          dmae-operations (writing to pram for example.)
   10251                 :            :  *          note: can be done for only function 6,7 but cleaner this
   10252                 :            :  *            way.
   10253                 :            :  *      b.  Write zero+valid to the entire ILT.
   10254                 :            :  *      c.  Init the first_timers_ilt_entry, last_timers_ilt_entry of
   10255                 :            :  *          VNIC3 (of that port). The range allocated will be the
   10256                 :            :  *          entire ILT. This is needed to prevent  ILT range error.
   10257                 :            :  *  2.  Any PF driver load flow:
   10258                 :            :  *      a.  ILT update with the physical addresses of the allocated
   10259                 :            :  *          logical pages.
   10260                 :            :  *      b.  Wait 20msec. - note that this timeout is needed to make
   10261                 :            :  *          sure there are no requests in one of the PXP internal
   10262                 :            :  *          queues with "old" ILT addresses.
   10263                 :            :  *      c.  PF enable in the PGLC.
   10264                 :            :  *      d.  Clear the was_error of the PF in the PGLC. (could have
   10265                 :            :  *          occurred while driver was down)
   10266                 :            :  *      e.  PF enable in the CFC (WEAK + STRONG)
   10267                 :            :  *      f.  Timers scan enable
   10268                 :            :  *  3.  PF driver unload flow:
   10269                 :            :  *      a.  Clear the Timers scan_en.
   10270                 :            :  *      b.  Polling for scan_on=0 for that PF.
   10271                 :            :  *      c.  Clear the PF enable bit in the PXP.
   10272                 :            :  *      d.  Clear the PF enable in the CFC (WEAK + STRONG)
   10273                 :            :  *      e.  Write zero+valid to all ILT entries (The valid bit must
   10274                 :            :  *          stay set)
   10275                 :            :  *      f.  If this is VNIC 3 of a port then also init
   10276                 :            :  *          first_timers_ilt_entry to zero and last_timers_ilt_entry
   10277                 :            :  *          to the last entry in the ILT.
   10278                 :            :  *
   10279                 :            :  *      Notes:
   10280                 :            :  *      Currently the PF error in the PGLC is non recoverable.
   10281                 :            :  *      In the future the there will be a recovery routine for this error.
   10282                 :            :  *      Currently attention is masked.
   10283                 :            :  *      Having an MCP lock on the load/unload process does not guarantee that
   10284                 :            :  *      there is no Timer disable during Func6/7 enable. This is because the
   10285                 :            :  *      Timers scan is currently being cleared by the MCP on FLR.
   10286                 :            :  *      Step 2.d can be done only for PF6/7 and the driver can also check if
   10287                 :            :  *      there is error before clearing it. But the flow above is simpler and
   10288                 :            :  *      more general.
   10289                 :            :  *      All ILT entries are written by zero+valid and not just PF6/7
   10290                 :            :  *      ILT entries since in the future the ILT entries allocation for
   10291                 :            :  *      PF-s might be dynamic.
   10292                 :            :  */
   10293                 :            :                 struct ilt_client_info ilt_cli;
   10294                 :            :                 struct ecore_ilt ilt;
   10295                 :            : 
   10296                 :            :                 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
   10297                 :            :                 memset(&ilt, 0, sizeof(struct ecore_ilt));
   10298                 :            : 
   10299                 :            : /* initialize dummy TM client */
   10300                 :            :                 ilt_cli.start = 0;
   10301                 :          0 :                 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
   10302                 :          0 :                 ilt_cli.client_num = ILT_CLIENT_TM;
   10303                 :            : 
   10304                 :            : /*
   10305                 :            :  * Step 1: set zeroes to all ilt page entries with valid bit on
   10306                 :            :  * Step 2: set the timers first/last ilt entry to point
   10307                 :            :  * to the entire range to prevent ILT range error for 3rd/4th
   10308                 :            :  * vnic (this code assumes existence of the vnic)
   10309                 :            :  *
   10310                 :            :  * both steps performed by call to ecore_ilt_client_init_op()
   10311                 :            :  * with dummy TM client
   10312                 :            :  *
   10313                 :            :  * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
   10314                 :            :  * and his brother are split registers
   10315                 :            :  */
   10316                 :            : 
   10317                 :          0 :                 bnx2x_pretend_func(sc, (SC_PATH(sc) + 6));
   10318                 :          0 :                 ecore_ilt_client_init_op_ilt(sc, &ilt, &ilt_cli, INITOP_CLEAR);
   10319         [ #  # ]:          0 :                 bnx2x_pretend_func(sc, SC_ABS_FUNC(sc));
   10320                 :            : 
   10321                 :            :                 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
   10322                 :            :                 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
   10323                 :            :                 REG_WR(sc, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
   10324                 :            :         }
   10325                 :            : 
   10326                 :            :         REG_WR(sc, PXP2_REG_RQ_DISABLE_INPUTS, 0);
   10327                 :            :         REG_WR(sc, PXP2_REG_RD_DISABLE_INPUTS, 0);
   10328                 :            : 
   10329         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10330   [ #  #  #  # ]:          0 :                 int factor = CHIP_REV_IS_EMUL(sc) ? 1000 :
   10331   [ #  #  #  # ]:          0 :                                 (CHIP_REV_IS_FPGA(sc) ? 400 : 0);
   10332                 :            : 
   10333                 :          0 :                 ecore_init_block(sc, BLOCK_PGLUE_B, PHASE_COMMON);
   10334                 :          0 :                 ecore_init_block(sc, BLOCK_ATC, PHASE_COMMON);
   10335                 :            : 
   10336                 :            :                 /* let the HW do it's magic... */
   10337                 :            :                 do {
   10338                 :          0 :                         DELAY(200000);
   10339                 :            :                         val = REG_RD(sc, ATC_REG_ATC_INIT_DONE);
   10340   [ #  #  #  # ]:          0 :                 } while (factor-- && (val != 1));
   10341                 :            : 
   10342         [ #  # ]:          0 :                 if (val != 1) {
   10343                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "ATC_INIT failed");
   10344                 :          0 :                         return -1;
   10345                 :            :                 }
   10346                 :            :         }
   10347                 :            : 
   10348                 :          0 :         ecore_init_block(sc, BLOCK_DMAE, PHASE_COMMON);
   10349                 :            : 
   10350                 :            :         /* clean the DMAE memory */
   10351                 :          0 :         sc->dmae_ready = 1;
   10352                 :          0 :         ecore_init_fill(sc, TSEM_REG_PRAM, 0, 8, 1);
   10353                 :            : 
   10354                 :          0 :         ecore_init_block(sc, BLOCK_TCM, PHASE_COMMON);
   10355                 :            : 
   10356                 :          0 :         ecore_init_block(sc, BLOCK_UCM, PHASE_COMMON);
   10357                 :            : 
   10358                 :          0 :         ecore_init_block(sc, BLOCK_CCM, PHASE_COMMON);
   10359                 :            : 
   10360                 :          0 :         ecore_init_block(sc, BLOCK_XCM, PHASE_COMMON);
   10361                 :            : 
   10362                 :          0 :         bnx2x_read_dmae(sc, XSEM_REG_PASSIVE_BUFFER, 3);
   10363                 :          0 :         bnx2x_read_dmae(sc, CSEM_REG_PASSIVE_BUFFER, 3);
   10364                 :          0 :         bnx2x_read_dmae(sc, TSEM_REG_PASSIVE_BUFFER, 3);
   10365                 :          0 :         bnx2x_read_dmae(sc, USEM_REG_PASSIVE_BUFFER, 3);
   10366                 :            : 
   10367                 :          0 :         ecore_init_block(sc, BLOCK_QM, PHASE_COMMON);
   10368                 :            : 
   10369                 :            :         /* QM queues pointers table */
   10370                 :          0 :         ecore_qm_init_ptr_table(sc, sc->qm_cid_count, INITOP_SET);
   10371                 :            : 
   10372                 :            :         /* soft reset pulse */
   10373                 :            :         REG_WR(sc, QM_REG_SOFT_RESET, 1);
   10374                 :            :         REG_WR(sc, QM_REG_SOFT_RESET, 0);
   10375                 :            : 
   10376                 :            :         if (CNIC_SUPPORT(sc))
   10377                 :            :                 ecore_init_block(sc, BLOCK_TM, PHASE_COMMON);
   10378                 :            : 
   10379                 :          0 :         ecore_init_block(sc, BLOCK_DORQ, PHASE_COMMON);
   10380                 :            : 
   10381         [ #  # ]:          0 :         if (!CHIP_REV_IS_SLOW(sc)) {
   10382                 :            : /* enable hw interrupt from doorbell Q */
   10383                 :            :                 REG_WR(sc, DORQ_REG_DORQ_INT_MASK, 0);
   10384                 :            :         }
   10385                 :            : 
   10386                 :          0 :         ecore_init_block(sc, BLOCK_BRB1, PHASE_COMMON);
   10387                 :            : 
   10388                 :          0 :         ecore_init_block(sc, BLOCK_PRS, PHASE_COMMON);
   10389                 :            :         REG_WR(sc, PRS_REG_A_PRSU_20, 0xf);
   10390                 :          0 :         REG_WR(sc, PRS_REG_E1HOV_MODE, sc->devinfo.mf_info.path_has_ovlan);
   10391                 :            : 
   10392   [ #  #  #  #  :          0 :         if (!CHIP_IS_E1x(sc) && !CHIP_IS_E3B0(sc)) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
   10393   [ #  #  #  # ]:          0 :                 if (IS_MF_AFEX(sc)) {
   10394                 :            :                         /*
   10395                 :            :                          * configure that AFEX and VLAN headers must be
   10396                 :            :                          * received in AFEX mode
   10397                 :            :                          */
   10398                 :            :                         REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC, 0xE);
   10399                 :            :                         REG_WR(sc, PRS_REG_MUST_HAVE_HDRS, 0xA);
   10400                 :            :                         REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
   10401                 :            :                         REG_WR(sc, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
   10402                 :            :                         REG_WR(sc, PRS_REG_TAG_LEN_0, 0x4);
   10403                 :            :                 } else {
   10404                 :            :                         /*
   10405                 :            :                          * Bit-map indicating which L2 hdrs may appear
   10406                 :            :                          * after the basic Ethernet header
   10407                 :            :                          */
   10408         [ #  # ]:          0 :                         REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC,
   10409                 :            :                                sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
   10410                 :            :                 }
   10411                 :            :         }
   10412                 :            : 
   10413                 :          0 :         ecore_init_block(sc, BLOCK_TSDM, PHASE_COMMON);
   10414                 :          0 :         ecore_init_block(sc, BLOCK_CSDM, PHASE_COMMON);
   10415                 :          0 :         ecore_init_block(sc, BLOCK_USDM, PHASE_COMMON);
   10416                 :          0 :         ecore_init_block(sc, BLOCK_XSDM, PHASE_COMMON);
   10417                 :            : 
   10418         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10419                 :            : /* reset VFC memories */
   10420                 :            :                 REG_WR(sc, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
   10421                 :            :                        VFC_MEMORIES_RST_REG_CAM_RST |
   10422                 :            :                        VFC_MEMORIES_RST_REG_RAM_RST);
   10423                 :            :                 REG_WR(sc, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
   10424                 :            :                        VFC_MEMORIES_RST_REG_CAM_RST |
   10425                 :            :                        VFC_MEMORIES_RST_REG_RAM_RST);
   10426                 :            : 
   10427                 :          0 :                 DELAY(20000);
   10428                 :            :         }
   10429                 :            : 
   10430                 :          0 :         ecore_init_block(sc, BLOCK_TSEM, PHASE_COMMON);
   10431                 :          0 :         ecore_init_block(sc, BLOCK_USEM, PHASE_COMMON);
   10432                 :          0 :         ecore_init_block(sc, BLOCK_CSEM, PHASE_COMMON);
   10433                 :          0 :         ecore_init_block(sc, BLOCK_XSEM, PHASE_COMMON);
   10434                 :            : 
   10435                 :            :         /* sync semi rtc */
   10436                 :            :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x80000000);
   10437                 :            :         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x80000000);
   10438                 :            : 
   10439                 :          0 :         ecore_init_block(sc, BLOCK_UPB, PHASE_COMMON);
   10440                 :          0 :         ecore_init_block(sc, BLOCK_XPB, PHASE_COMMON);
   10441                 :          0 :         ecore_init_block(sc, BLOCK_PBF, PHASE_COMMON);
   10442                 :            : 
   10443         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10444   [ #  #  #  # ]:          0 :                 if (IS_MF_AFEX(sc)) {
   10445                 :            :                         /*
   10446                 :            :                          * configure that AFEX and VLAN headers must be
   10447                 :            :                          * sent in AFEX mode
   10448                 :            :                          */
   10449                 :            :                         REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC, 0xE);
   10450                 :            :                         REG_WR(sc, PBF_REG_MUST_HAVE_HDRS, 0xA);
   10451                 :            :                         REG_WR(sc, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
   10452                 :            :                         REG_WR(sc, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
   10453                 :            :                         REG_WR(sc, PBF_REG_TAG_LEN_0, 0x4);
   10454                 :            :                 } else {
   10455         [ #  # ]:          0 :                         REG_WR(sc, PBF_REG_HDRS_AFTER_BASIC,
   10456                 :            :                                sc->devinfo.mf_info.path_has_ovlan ? 7 : 6);
   10457                 :            :                 }
   10458                 :            :         }
   10459                 :            : 
   10460                 :            :         REG_WR(sc, SRC_REG_SOFT_RST, 1);
   10461                 :            : 
   10462                 :          0 :         ecore_init_block(sc, BLOCK_SRC, PHASE_COMMON);
   10463                 :            : 
   10464                 :            :         if (CNIC_SUPPORT(sc)) {
   10465                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_0, 0x63285672);
   10466                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
   10467                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_2, 0x223aef9b);
   10468                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_3, 0x26001e3a);
   10469                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_4, 0x7ae91116);
   10470                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
   10471                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_6, 0x298d8adf);
   10472                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
   10473                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_8, 0x1830f82f);
   10474                 :            :                 REG_WR(sc, SRC_REG_KEYSEARCH_9, 0x01e46be7);
   10475                 :            :         }
   10476                 :            :         REG_WR(sc, SRC_REG_SOFT_RST, 0);
   10477                 :            : 
   10478                 :            :         if (sizeof(union cdu_context) != 1024) {
   10479                 :            : /* we currently assume that a context is 1024 bytes */
   10480                 :            :                 PMD_DRV_LOG(NOTICE, sc,
   10481                 :            :                             "please adjust the size of cdu_context(%ld)",
   10482                 :            :                             (long)sizeof(union cdu_context));
   10483                 :            :         }
   10484                 :            : 
   10485                 :          0 :         ecore_init_block(sc, BLOCK_CDU, PHASE_COMMON);
   10486                 :            :         val = (4 << 24) + (0 << 12) + 1024;
   10487                 :            :         REG_WR(sc, CDU_REG_CDU_GLOBAL_PARAMS, val);
   10488                 :            : 
   10489                 :          0 :         ecore_init_block(sc, BLOCK_CFC, PHASE_COMMON);
   10490                 :            : 
   10491                 :            :         REG_WR(sc, CFC_REG_INIT_REG, 0x7FF);
   10492                 :            :         /* enable context validation interrupt from CFC */
   10493                 :            :         REG_WR(sc, CFC_REG_CFC_INT_MASK, 0);
   10494                 :            : 
   10495                 :            :         /* set the thresholds to prevent CFC/CDU race */
   10496                 :            :         REG_WR(sc, CFC_REG_DEBUG0, 0x20020000);
   10497                 :          0 :         ecore_init_block(sc, BLOCK_HC, PHASE_COMMON);
   10498                 :            : 
   10499   [ #  #  #  # ]:          0 :         if (!CHIP_IS_E1x(sc) && BNX2X_NOMCP(sc)) {
   10500                 :            :                 REG_WR(sc, IGU_REG_RESET_MEMORIES, 0x36);
   10501                 :            :         }
   10502                 :            : 
   10503                 :          0 :         ecore_init_block(sc, BLOCK_IGU, PHASE_COMMON);
   10504                 :          0 :         ecore_init_block(sc, BLOCK_MISC_AEU, PHASE_COMMON);
   10505                 :            : 
   10506                 :            :         /* Reset PCIE errors for debug */
   10507                 :            :         REG_WR(sc, 0x2814, 0xffffffff);
   10508                 :            :         REG_WR(sc, 0x3820, 0xffffffff);
   10509                 :            : 
   10510         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10511                 :            :                 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
   10512                 :            :                        (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
   10513                 :            :                         PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
   10514                 :            :                 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
   10515                 :            :                        (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
   10516                 :            :                         PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
   10517                 :            :                         PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
   10518                 :            :                 REG_WR(sc, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
   10519                 :            :                        (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
   10520                 :            :                         PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
   10521                 :            :                         PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
   10522                 :            :         }
   10523                 :            : 
   10524                 :          0 :         ecore_init_block(sc, BLOCK_NIG, PHASE_COMMON);
   10525                 :            : 
   10526                 :            :         /* in E3 this done in per-port section */
   10527   [ #  #  #  #  :          0 :         if (!CHIP_IS_E3(sc))
          #  #  #  #  #  
                      # ]
   10528   [ #  #  #  # ]:          0 :                 REG_WR(sc, NIG_REG_LLH_MF_MODE, IS_MF(sc));
   10529                 :            : 
   10530         [ #  # ]:          0 :         if (CHIP_IS_E1H(sc)) {
   10531                 :            : /* not applicable for E2 (and above ...) */
   10532   [ #  #  #  # ]:          0 :                 REG_WR(sc, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(sc));
   10533                 :            :         }
   10534                 :            : 
   10535         [ #  # ]:          0 :         if (CHIP_REV_IS_SLOW(sc)) {
   10536                 :          0 :                 DELAY(200000);
   10537                 :            :         }
   10538                 :            : 
   10539                 :            :         /* finish CFC init */
   10540                 :            :         val = reg_poll(sc, CFC_REG_LL_INIT_DONE, 1, 100, 10);
   10541         [ #  # ]:          0 :         if (val != 1) {
   10542                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "CFC LL_INIT failed");
   10543                 :          0 :                 return -1;
   10544                 :            :         }
   10545                 :            :         val = reg_poll(sc, CFC_REG_AC_INIT_DONE, 1, 100, 10);
   10546         [ #  # ]:          0 :         if (val != 1) {
   10547                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "CFC AC_INIT failed");
   10548                 :          0 :                 return -1;
   10549                 :            :         }
   10550                 :            :         val = reg_poll(sc, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
   10551         [ #  # ]:          0 :         if (val != 1) {
   10552                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "CFC CAM_INIT failed");
   10553                 :          0 :                 return -1;
   10554                 :            :         }
   10555                 :            :         REG_WR(sc, CFC_REG_DEBUG0, 0);
   10556                 :            : 
   10557                 :          0 :         bnx2x_setup_fan_failure_detection(sc);
   10558                 :            : 
   10559                 :            :         /* clear PXP2 attentions */
   10560                 :            :         REG_RD(sc, PXP2_REG_PXP2_INT_STS_CLR_0);
   10561                 :            : 
   10562                 :          0 :         bnx2x_enable_blocks_attention(sc);
   10563                 :            : 
   10564         [ #  # ]:          0 :         if (!CHIP_REV_IS_SLOW(sc)) {
   10565                 :          0 :                 ecore_enable_blocks_parity(sc);
   10566                 :            :         }
   10567                 :            : 
   10568         [ #  # ]:          0 :         if (!BNX2X_NOMCP(sc)) {
   10569         [ #  # ]:          0 :                 if (CHIP_IS_E1x(sc)) {
   10570                 :          0 :                         bnx2x_common_init_phy(sc);
   10571                 :            :                 }
   10572                 :            :         }
   10573                 :            : 
   10574                 :            :         return 0;
   10575                 :            : }
   10576                 :            : 
   10577                 :            : /**
   10578                 :            :  * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
   10579                 :            :  *
   10580                 :            :  * @sc:     driver handle
   10581                 :            :  */
   10582                 :          0 : static int bnx2x_init_hw_common_chip(struct bnx2x_softc *sc)
   10583                 :            : {
   10584                 :          0 :         int rc = bnx2x_init_hw_common(sc);
   10585                 :            : 
   10586         [ #  # ]:          0 :         if (rc) {
   10587                 :            :                 return rc;
   10588                 :            :         }
   10589                 :            : 
   10590                 :            :         /* In E2 2-PORT mode, same ext phy is used for the two paths */
   10591         [ #  # ]:          0 :         if (!BNX2X_NOMCP(sc)) {
   10592                 :          0 :                 bnx2x_common_init_phy(sc);
   10593                 :            :         }
   10594                 :            : 
   10595                 :            :         return 0;
   10596                 :            : }
   10597                 :            : 
   10598                 :          0 : static int bnx2x_init_hw_port(struct bnx2x_softc *sc)
   10599                 :            : {
   10600                 :          0 :         int port = SC_PORT(sc);
   10601         [ #  # ]:          0 :         int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
   10602                 :            :         uint32_t low, high;
   10603                 :            :         uint32_t val;
   10604                 :            : 
   10605                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "starting port init for port %d", port);
   10606                 :            : 
   10607                 :          0 :         REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4, 0);
   10608                 :            : 
   10609                 :          0 :         ecore_init_block(sc, BLOCK_MISC, init_phase);
   10610                 :          0 :         ecore_init_block(sc, BLOCK_PXP, init_phase);
   10611                 :          0 :         ecore_init_block(sc, BLOCK_PXP2, init_phase);
   10612                 :            : 
   10613                 :            :         /*
   10614                 :            :          * Timers bug workaround: disables the pf_master bit in pglue at
   10615                 :            :          * common phase, we need to enable it here before any dmae access are
   10616                 :            :          * attempted. Therefore we manually added the enable-master to the
   10617                 :            :          * port phase (it also happens in the function phase)
   10618                 :            :          */
   10619         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10620                 :            :                 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
   10621                 :            :         }
   10622                 :            : 
   10623                 :          0 :         ecore_init_block(sc, BLOCK_ATC, init_phase);
   10624                 :          0 :         ecore_init_block(sc, BLOCK_DMAE, init_phase);
   10625                 :          0 :         ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
   10626                 :          0 :         ecore_init_block(sc, BLOCK_QM, init_phase);
   10627                 :            : 
   10628                 :          0 :         ecore_init_block(sc, BLOCK_TCM, init_phase);
   10629                 :          0 :         ecore_init_block(sc, BLOCK_UCM, init_phase);
   10630                 :          0 :         ecore_init_block(sc, BLOCK_CCM, init_phase);
   10631                 :          0 :         ecore_init_block(sc, BLOCK_XCM, init_phase);
   10632                 :            : 
   10633                 :            :         /* QM cid (connection) count */
   10634         [ #  # ]:          0 :         ecore_qm_init_cid_count(sc, sc->qm_cid_count, INITOP_SET);
   10635                 :            : 
   10636                 :            :         if (CNIC_SUPPORT(sc)) {
   10637                 :            :                 ecore_init_block(sc, BLOCK_TM, init_phase);
   10638                 :            :                 REG_WR(sc, TM_REG_LIN0_SCAN_TIME + port * 4, 20);
   10639                 :            :                 REG_WR(sc, TM_REG_LIN0_MAX_ACTIVE_CID + port * 4, 31);
   10640                 :            :         }
   10641                 :            : 
   10642                 :          0 :         ecore_init_block(sc, BLOCK_DORQ, init_phase);
   10643                 :            : 
   10644                 :          0 :         ecore_init_block(sc, BLOCK_BRB1, init_phase);
   10645                 :            : 
   10646         [ #  # ]:          0 :         if (CHIP_IS_E1H(sc)) {
   10647   [ #  #  #  # ]:          0 :                 if (IS_MF(sc)) {
   10648         [ #  # ]:          0 :                         low = (BNX2X_ONE_PORT(sc) ? 160 : 246);
   10649         [ #  # ]:          0 :                 } else if (sc->mtu > 4096) {
   10650         [ #  # ]:          0 :                         if (BNX2X_ONE_PORT(sc)) {
   10651                 :            :                                 low = 160;
   10652                 :            :                         } else {
   10653                 :          0 :                                 val = sc->mtu;
   10654                 :            :                                 /* (24*1024 + val*4)/256 */
   10655         [ #  # ]:          0 :                                 low = (96 + (val / 64) + ((val % 64) ? 1 : 0));
   10656                 :            :                         }
   10657                 :            :                 } else {
   10658         [ #  # ]:          0 :                         low = (BNX2X_ONE_PORT(sc) ? 80 : 160);
   10659                 :            :                 }
   10660                 :          0 :                 high = (low + 56);      /* 14*1024/256 */
   10661                 :          0 :                 REG_WR(sc, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port * 4, low);
   10662                 :          0 :                 REG_WR(sc, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port * 4, high);
   10663                 :            :         }
   10664                 :            : 
   10665         [ #  # ]:          0 :         if (CHIP_IS_MODE_4_PORT(sc)) {
   10666         [ #  # ]:          0 :                 REG_WR(sc, SC_PORT(sc) ?
   10667                 :            :                        BRB1_REG_MAC_GUARANTIED_1 :
   10668                 :            :                        BRB1_REG_MAC_GUARANTIED_0, 40);
   10669                 :            :         }
   10670                 :            : 
   10671                 :          0 :         ecore_init_block(sc, BLOCK_PRS, init_phase);
   10672   [ #  #  #  # ]:          0 :         if (CHIP_IS_E3B0(sc)) {
   10673   [ #  #  #  # ]:          0 :                 if (IS_MF_AFEX(sc)) {
   10674                 :            :                         /* configure headers for AFEX mode */
   10675         [ #  # ]:          0 :                         if (SC_PORT(sc)) {
   10676                 :            :                                 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC_PORT_1,
   10677                 :            :                                        0xE);
   10678                 :            :                                 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0_PORT_1,
   10679                 :            :                                        0x6);
   10680                 :            :                                 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS_PORT_1, 0xA);
   10681                 :            :                         } else {
   10682                 :            :                                 REG_WR(sc, PRS_REG_HDRS_AFTER_BASIC_PORT_0,
   10683                 :            :                                        0xE);
   10684                 :            :                                 REG_WR(sc, PRS_REG_HDRS_AFTER_TAG_0_PORT_0,
   10685                 :            :                                        0x6);
   10686                 :            :                                 REG_WR(sc, PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
   10687                 :            :                         }
   10688                 :            :                 } else {
   10689                 :            :                         /* Ovlan exists only if we are in multi-function +
   10690                 :            :                          * switch-dependent mode, in switch-independent there
   10691                 :            :                          * is no ovlan headers
   10692                 :            :                          */
   10693   [ #  #  #  # ]:          0 :                         REG_WR(sc, SC_PORT(sc) ?
   10694                 :            :                                PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
   10695                 :            :                                PRS_REG_HDRS_AFTER_BASIC_PORT_0,
   10696                 :            :                                (sc->devinfo.mf_info.path_has_ovlan ? 7 : 6));
   10697                 :            :                 }
   10698                 :            :         }
   10699                 :            : 
   10700                 :          0 :         ecore_init_block(sc, BLOCK_TSDM, init_phase);
   10701                 :          0 :         ecore_init_block(sc, BLOCK_CSDM, init_phase);
   10702                 :          0 :         ecore_init_block(sc, BLOCK_USDM, init_phase);
   10703                 :          0 :         ecore_init_block(sc, BLOCK_XSDM, init_phase);
   10704                 :            : 
   10705                 :          0 :         ecore_init_block(sc, BLOCK_TSEM, init_phase);
   10706                 :          0 :         ecore_init_block(sc, BLOCK_USEM, init_phase);
   10707                 :          0 :         ecore_init_block(sc, BLOCK_CSEM, init_phase);
   10708                 :          0 :         ecore_init_block(sc, BLOCK_XSEM, init_phase);
   10709                 :            : 
   10710                 :          0 :         ecore_init_block(sc, BLOCK_UPB, init_phase);
   10711                 :          0 :         ecore_init_block(sc, BLOCK_XPB, init_phase);
   10712                 :            : 
   10713                 :          0 :         ecore_init_block(sc, BLOCK_PBF, init_phase);
   10714                 :            : 
   10715         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
   10716                 :            : /* configure PBF to work without PAUSE mtu 9000 */
   10717                 :          0 :                 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port * 4, 0);
   10718                 :            : 
   10719                 :            : /* update threshold */
   10720                 :          0 :                 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port * 4, (9040 / 16));
   10721                 :            : /* update init credit */
   10722                 :          0 :                 REG_WR(sc, PBF_REG_P0_INIT_CRD + port * 4,
   10723                 :            :                        (9040 / 16) + 553 - 22);
   10724                 :            : 
   10725                 :            : /* probe changes */
   10726                 :          0 :                 REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 1);
   10727                 :          0 :                 DELAY(50);
   10728                 :            :                 REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 0);
   10729                 :            :         }
   10730                 :            : 
   10731                 :            :         if (CNIC_SUPPORT(sc)) {
   10732                 :            :                 ecore_init_block(sc, BLOCK_SRC, init_phase);
   10733                 :            :         }
   10734                 :            : 
   10735                 :          0 :         ecore_init_block(sc, BLOCK_CDU, init_phase);
   10736                 :          0 :         ecore_init_block(sc, BLOCK_CFC, init_phase);
   10737                 :          0 :         ecore_init_block(sc, BLOCK_HC, init_phase);
   10738                 :          0 :         ecore_init_block(sc, BLOCK_IGU, init_phase);
   10739                 :          0 :         ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
   10740                 :            :         /* init aeu_mask_attn_func_0/1:
   10741                 :            :          *  - SF mode: bits 3-7 are masked. only bits 0-2 are in use
   10742                 :            :          *  - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
   10743                 :            :          *             bits 4-7 are used for "per vn group attention" */
   10744   [ #  #  #  # ]:          0 :         val = IS_MF(sc) ? 0xF7 : 0x7;
   10745                 :          0 :         val |= 0x10;
   10746                 :          0 :         REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port * 4, val);
   10747                 :            : 
   10748                 :          0 :         ecore_init_block(sc, BLOCK_NIG, init_phase);
   10749                 :            : 
   10750         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10751                 :            : /* Bit-map indicating which L2 hdrs may appear after the
   10752                 :            :  * basic Ethernet header
   10753                 :            :  */
   10754   [ #  #  #  # ]:          0 :                 if (IS_MF_AFEX(sc)) {
   10755         [ #  # ]:          0 :                         REG_WR(sc, SC_PORT(sc) ?
   10756                 :            :                                NIG_REG_P1_HDRS_AFTER_BASIC :
   10757                 :            :                                NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
   10758                 :            :                 } else {
   10759   [ #  #  #  #  :          0 :                         REG_WR(sc, SC_PORT(sc) ?
                   #  # ]
   10760                 :            :                                NIG_REG_P1_HDRS_AFTER_BASIC :
   10761                 :            :                                NIG_REG_P0_HDRS_AFTER_BASIC,
   10762                 :            :                                IS_MF_SD(sc) ? 7 : 6);
   10763                 :            :                 }
   10764                 :            : 
   10765         [ #  # ]:          0 :                 if (CHIP_IS_E3(sc)) {
   10766   [ #  #  #  #  :          0 :                         REG_WR(sc, SC_PORT(sc) ?
                   #  # ]
   10767                 :            :                                NIG_REG_LLH1_MF_MODE :
   10768                 :            :                                NIG_REG_LLH_MF_MODE, IS_MF(sc));
   10769                 :            :                 }
   10770                 :            :         }
   10771   [ #  #  #  #  :          0 :         if (!CHIP_IS_E3(sc)) {
          #  #  #  #  #  
                      # ]
   10772                 :          0 :                 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 1);
   10773                 :            :         }
   10774                 :            : 
   10775                 :            :         /* 0x2 disable mf_ov, 0x1 enable */
   10776   [ #  #  #  # ]:          0 :         REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port * 4,
   10777                 :            :                (IS_MF_SD(sc) ? 0x1 : 0x2));
   10778                 :            : 
   10779         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   10780                 :            :                 val = 0;
   10781      [ #  #  # ]:          0 :                 switch (sc->devinfo.mf_info.mf_mode) {
   10782                 :          0 :                 case MULTI_FUNCTION_SD:
   10783                 :            :                         val = 1;
   10784                 :          0 :                         break;
   10785                 :          0 :                 case MULTI_FUNCTION_SI:
   10786                 :            :                 case MULTI_FUNCTION_AFEX:
   10787                 :            :                         val = 2;
   10788                 :          0 :                         break;
   10789                 :            :                 }
   10790                 :            : 
   10791         [ #  # ]:          0 :                 REG_WR(sc, (SC_PORT(sc) ? NIG_REG_LLH1_CLS_TYPE :
   10792                 :            :                             NIG_REG_LLH0_CLS_TYPE), val);
   10793                 :            :         }
   10794                 :          0 :         REG_WR(sc, NIG_REG_LLFC_ENABLE_0 + port * 4, 0);
   10795                 :          0 :         REG_WR(sc, NIG_REG_LLFC_OUT_EN_0 + port * 4, 0);
   10796                 :          0 :         REG_WR(sc, NIG_REG_PAUSE_ENABLE_0 + port * 4, 1);
   10797                 :            : 
   10798                 :            :         /* If SPIO5 is set to generate interrupts, enable it for this port */
   10799                 :            :         val = REG_RD(sc, MISC_REG_SPIO_EVENT_EN);
   10800         [ #  # ]:          0 :         if (val & MISC_SPIO_SPIO5) {
   10801         [ #  # ]:          0 :                 uint32_t reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
   10802                 :            :                                      MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
   10803                 :          0 :                 val = REG_RD(sc, reg_addr);
   10804                 :          0 :                 val |= AEU_INPUTS_ATTN_BITS_SPIO5;
   10805                 :            :                 REG_WR(sc, reg_addr, val);
   10806                 :            :         }
   10807                 :            : 
   10808                 :          0 :         return 0;
   10809                 :            : }
   10810                 :            : 
   10811                 :            : static uint32_t
   10812                 :            : bnx2x_flr_clnup_reg_poll(struct bnx2x_softc *sc, uint32_t reg,
   10813                 :            :                        uint32_t expected, uint32_t poll_count)
   10814                 :            : {
   10815                 :            :         uint32_t cur_cnt = poll_count;
   10816                 :            :         uint32_t val;
   10817                 :            : 
   10818   [ #  #  #  #  :          0 :         while ((val = REG_RD(sc, reg)) != expected && cur_cnt--) {
             #  #  #  # ]
   10819                 :          0 :                 DELAY(FLR_WAIT_INTERVAL);
   10820                 :            :         }
   10821                 :            : 
   10822                 :            :         return val;
   10823                 :            : }
   10824                 :            : 
   10825                 :            : static int
   10826                 :          0 : bnx2x_flr_clnup_poll_hw_counter(struct bnx2x_softc *sc, uint32_t reg,
   10827                 :            :                               __rte_unused const char *msg, uint32_t poll_cnt)
   10828                 :            : {
   10829                 :            :         uint32_t val = bnx2x_flr_clnup_reg_poll(sc, reg, 0, poll_cnt);
   10830                 :            : 
   10831         [ #  # ]:          0 :         if (val != 0) {
   10832                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "%s usage count=%d", msg, val);
   10833                 :          0 :                 return -1;
   10834                 :            :         }
   10835                 :            : 
   10836                 :            :         return 0;
   10837                 :            : }
   10838                 :            : 
   10839                 :            : /* Common routines with VF FLR cleanup */
   10840                 :            : static uint32_t bnx2x_flr_clnup_poll_count(struct bnx2x_softc *sc)
   10841                 :            : {
   10842                 :            :         /* adjust polling timeout */
   10843         [ #  # ]:          0 :         if (CHIP_REV_IS_EMUL(sc)) {
   10844                 :            :                 return FLR_POLL_CNT * 2000;
   10845                 :            :         }
   10846                 :            : 
   10847   [ #  #  #  # ]:          0 :         if (CHIP_REV_IS_FPGA(sc)) {
   10848                 :          0 :                 return FLR_POLL_CNT * 120;
   10849                 :            :         }
   10850                 :            : 
   10851                 :            :         return FLR_POLL_CNT;
   10852                 :            : }
   10853                 :            : 
   10854                 :          0 : static int bnx2x_poll_hw_usage_counters(struct bnx2x_softc *sc, uint32_t poll_cnt)
   10855                 :            : {
   10856                 :            :         /* wait for CFC PF usage-counter to zero (includes all the VFs) */
   10857         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10858                 :            :                                           CFC_REG_NUM_LCIDS_INSIDE_PF,
   10859                 :            :                                           "CFC PF usage counter timed out",
   10860                 :            :                                           poll_cnt)) {
   10861                 :            :                 return -1;
   10862                 :            :         }
   10863                 :            : 
   10864                 :            :         /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
   10865         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10866                 :            :                                           DORQ_REG_PF_USAGE_CNT,
   10867                 :            :                                           "DQ PF usage counter timed out",
   10868                 :            :                                           poll_cnt)) {
   10869                 :            :                 return -1;
   10870                 :            :         }
   10871                 :            : 
   10872                 :            :         /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
   10873         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10874                 :          0 :                                           QM_REG_PF_USG_CNT_0 + 4 * SC_FUNC(sc),
   10875                 :            :                                           "QM PF usage counter timed out",
   10876                 :            :                                           poll_cnt)) {
   10877                 :            :                 return -1;
   10878                 :            :         }
   10879                 :            : 
   10880                 :            :         /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
   10881         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10882                 :          0 :                                           TM_REG_LIN0_VNIC_UC + 4 * SC_PORT(sc),
   10883                 :            :                                           "Timers VNIC usage counter timed out",
   10884                 :            :                                           poll_cnt)) {
   10885                 :            :                 return -1;
   10886                 :            :         }
   10887                 :            : 
   10888         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10889                 :          0 :                                           TM_REG_LIN0_NUM_SCANS +
   10890                 :          0 :                                           4 * SC_PORT(sc),
   10891                 :            :                                           "Timers NUM_SCANS usage counter timed out",
   10892                 :            :                                           poll_cnt)) {
   10893                 :            :                 return -1;
   10894                 :            :         }
   10895                 :            : 
   10896                 :            :         /* Wait DMAE PF usage counter to zero */
   10897         [ #  # ]:          0 :         if (bnx2x_flr_clnup_poll_hw_counter(sc,
   10898                 :          0 :                                           dmae_reg_go_c[INIT_DMAE_C(sc)],
   10899                 :            :                                           "DMAE dommand register timed out",
   10900                 :            :                                           poll_cnt)) {
   10901                 :          0 :                 return -1;
   10902                 :            :         }
   10903                 :            : 
   10904                 :            :         return 0;
   10905                 :            : }
   10906                 :            : 
   10907                 :            : #define OP_GEN_PARAM(param)                                            \
   10908                 :            :         (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
   10909                 :            : #define OP_GEN_TYPE(type)                                           \
   10910                 :            :         (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
   10911                 :            : #define OP_GEN_AGG_VECT(index)                                             \
   10912                 :            :         (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
   10913                 :            : 
   10914                 :            : static int
   10915                 :          0 : bnx2x_send_final_clnup(struct bnx2x_softc *sc, uint8_t clnup_func,
   10916                 :            :                      uint32_t poll_cnt)
   10917                 :            : {
   10918                 :            :         uint32_t op_gen_command = 0;
   10919                 :          0 :         uint32_t comp_addr = (BAR_CSTRORM_INTMEM +
   10920                 :          0 :                               CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func));
   10921                 :            :         int ret = 0;
   10922                 :            : 
   10923         [ #  # ]:          0 :         if (REG_RD(sc, comp_addr)) {
   10924                 :          0 :                 PMD_DRV_LOG(NOTICE, sc,
   10925                 :            :                             "Cleanup complete was not 0 before sending");
   10926                 :          0 :                 return -1;
   10927                 :            :         }
   10928                 :            : 
   10929                 :          0 :         op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
   10930                 :          0 :         op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
   10931                 :          0 :         op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
   10932                 :          0 :         op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
   10933                 :            : 
   10934                 :            :         REG_WR(sc, XSDM_REG_OPERATION_GEN, op_gen_command);
   10935                 :            : 
   10936         [ #  # ]:          0 :         if (bnx2x_flr_clnup_reg_poll(sc, comp_addr, 1, poll_cnt) != 1) {
   10937                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "FW final cleanup did not succeed");
   10938                 :          0 :                 PMD_DRV_LOG(DEBUG, sc, "At timeout completion address contained %x",
   10939                 :            :                             (REG_RD(sc, comp_addr)));
   10940                 :          0 :                 rte_panic("FLR cleanup failed");
   10941                 :            :                 return -1;
   10942                 :            :         }
   10943                 :            : 
   10944                 :            :         /* Zero completion for nxt FLR */
   10945                 :            :         REG_WR(sc, comp_addr, 0);
   10946                 :            : 
   10947                 :          0 :         return ret;
   10948                 :            : }
   10949                 :            : 
   10950                 :            : static void
   10951                 :          0 : bnx2x_pbf_pN_buf_flushed(struct bnx2x_softc *sc, struct pbf_pN_buf_regs *regs,
   10952                 :            :                        uint32_t poll_count)
   10953                 :            : {
   10954                 :            :         uint32_t init_crd, crd, crd_start, crd_freed, crd_freed_start;
   10955                 :            :         uint32_t cur_cnt = poll_count;
   10956                 :            : 
   10957                 :          0 :         crd_freed = crd_freed_start = REG_RD(sc, regs->crd_freed);
   10958                 :          0 :         crd = crd_start = REG_RD(sc, regs->crd);
   10959                 :          0 :         init_crd = REG_RD(sc, regs->init_crd);
   10960                 :            : 
   10961         [ #  # ]:          0 :         while ((crd != init_crd) &&
   10962                 :          0 :                ((uint32_t) ((int32_t) crd_freed - (int32_t) crd_freed_start) <
   10963         [ #  # ]:          0 :                 (init_crd - crd_start))) {
   10964         [ #  # ]:          0 :                 if (cur_cnt--) {
   10965                 :          0 :                         DELAY(FLR_WAIT_INTERVAL);
   10966                 :          0 :                         crd = REG_RD(sc, regs->crd);
   10967                 :          0 :                         crd_freed = REG_RD(sc, regs->crd_freed);
   10968                 :            :                 } else {
   10969                 :            :                         break;
   10970                 :            :                 }
   10971                 :            :         }
   10972                 :          0 : }
   10973                 :            : 
   10974                 :            : static void
   10975                 :          0 : bnx2x_pbf_pN_cmd_flushed(struct bnx2x_softc *sc, struct pbf_pN_cmd_regs *regs,
   10976                 :            :                        uint32_t poll_count)
   10977                 :            : {
   10978                 :            :         uint32_t occup, to_free, freed, freed_start;
   10979                 :            :         uint32_t cur_cnt = poll_count;
   10980                 :            : 
   10981                 :          0 :         occup = to_free = REG_RD(sc, regs->lines_occup);
   10982                 :          0 :         freed = freed_start = REG_RD(sc, regs->lines_freed);
   10983                 :            : 
   10984         [ #  # ]:          0 :         while (occup &&
   10985         [ #  # ]:          0 :                ((uint32_t) ((int32_t) freed - (int32_t) freed_start) <
   10986                 :            :                 to_free)) {
   10987         [ #  # ]:          0 :                 if (cur_cnt--) {
   10988                 :          0 :                         DELAY(FLR_WAIT_INTERVAL);
   10989                 :          0 :                         occup = REG_RD(sc, regs->lines_occup);
   10990                 :          0 :                         freed = REG_RD(sc, regs->lines_freed);
   10991                 :            :                 } else {
   10992                 :            :                         break;
   10993                 :            :                 }
   10994                 :            :         }
   10995                 :          0 : }
   10996                 :            : 
   10997                 :          0 : static void bnx2x_tx_hw_flushed(struct bnx2x_softc *sc, uint32_t poll_count)
   10998                 :            : {
   10999                 :          0 :         struct pbf_pN_cmd_regs cmd_regs[] = {
   11000         [ #  # ]:          0 :                 {0, (CHIP_IS_E3B0(sc)) ?
   11001         [ #  # ]:          0 :                  PBF_REG_TQ_OCCUPANCY_Q0 : PBF_REG_P0_TQ_OCCUPANCY,
   11002         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11003         [ #  # ]:          0 :                  PBF_REG_TQ_LINES_FREED_CNT_Q0 : PBF_REG_P0_TQ_LINES_FREED_CNT},
   11004         [ #  # ]:          0 :                 {1, (CHIP_IS_E3B0(sc)) ?
   11005         [ #  # ]:          0 :                  PBF_REG_TQ_OCCUPANCY_Q1 : PBF_REG_P1_TQ_OCCUPANCY,
   11006         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11007         [ #  # ]:          0 :                  PBF_REG_TQ_LINES_FREED_CNT_Q1 : PBF_REG_P1_TQ_LINES_FREED_CNT},
   11008         [ #  # ]:          0 :                 {4, (CHIP_IS_E3B0(sc)) ?
   11009         [ #  # ]:          0 :                  PBF_REG_TQ_OCCUPANCY_LB_Q : PBF_REG_P4_TQ_OCCUPANCY,
   11010         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11011         [ #  # ]:          0 :                  PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
   11012                 :            :                  PBF_REG_P4_TQ_LINES_FREED_CNT}
   11013                 :            :         };
   11014                 :            : 
   11015                 :          0 :         struct pbf_pN_buf_regs buf_regs[] = {
   11016         [ #  # ]:          0 :                 {0, (CHIP_IS_E3B0(sc)) ?
   11017         [ #  # ]:          0 :                  PBF_REG_INIT_CRD_Q0 : PBF_REG_P0_INIT_CRD,
   11018   [ #  #  #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_Q0 : PBF_REG_P0_CREDIT,
   11019         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11020         [ #  # ]:          0 :                  PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
   11021                 :            :                  PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
   11022         [ #  # ]:          0 :                 {1, (CHIP_IS_E3B0(sc)) ?
   11023         [ #  # ]:          0 :                  PBF_REG_INIT_CRD_Q1 : PBF_REG_P1_INIT_CRD,
   11024   [ #  #  #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_Q1 : PBF_REG_P1_CREDIT,
   11025         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11026         [ #  # ]:          0 :                  PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
   11027                 :            :                  PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
   11028         [ #  # ]:          0 :                 {4, (CHIP_IS_E3B0(sc)) ?
   11029         [ #  # ]:          0 :                  PBF_REG_INIT_CRD_LB_Q : PBF_REG_P4_INIT_CRD,
   11030   [ #  #  #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ? PBF_REG_CREDIT_LB_Q : PBF_REG_P4_CREDIT,
   11031         [ #  # ]:          0 :                  (CHIP_IS_E3B0(sc)) ?
   11032         [ #  # ]:          0 :                  PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
   11033                 :            :                  PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
   11034                 :            :         };
   11035                 :            : 
   11036                 :            :         uint32_t i;
   11037                 :            : 
   11038                 :            :         /* Verify the command queues are flushed P0, P1, P4 */
   11039         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(cmd_regs); i++) {
   11040                 :          0 :                 bnx2x_pbf_pN_cmd_flushed(sc, &cmd_regs[i], poll_count);
   11041                 :            :         }
   11042                 :            : 
   11043                 :            :         /* Verify the transmission buffers are flushed P0, P1, P4 */
   11044         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(buf_regs); i++) {
   11045                 :          0 :                 bnx2x_pbf_pN_buf_flushed(sc, &buf_regs[i], poll_count);
   11046                 :            :         }
   11047                 :          0 : }
   11048                 :            : 
   11049                 :          0 : static void bnx2x_hw_enable_status(struct bnx2x_softc *sc)
   11050                 :            : {
   11051                 :            :         __rte_unused uint32_t val;
   11052                 :            : 
   11053                 :            :         val = REG_RD(sc, CFC_REG_WEAK_ENABLE_PF);
   11054                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "CFC_REG_WEAK_ENABLE_PF is 0x%x", val);
   11055                 :            : 
   11056                 :            :         val = REG_RD(sc, PBF_REG_DISABLE_PF);
   11057                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "PBF_REG_DISABLE_PF is 0x%x", val);
   11058                 :            : 
   11059                 :            :         val = REG_RD(sc, IGU_REG_PCI_PF_MSI_EN);
   11060                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSI_EN is 0x%x", val);
   11061                 :            : 
   11062                 :            :         val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_EN);
   11063                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSIX_EN is 0x%x", val);
   11064                 :            : 
   11065                 :            :         val = REG_RD(sc, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
   11066                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x", val);
   11067                 :            : 
   11068                 :            :         val = REG_RD(sc, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
   11069                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
   11070                 :            :                     "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x", val);
   11071                 :            : 
   11072                 :            :         val = REG_RD(sc, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
   11073                 :          0 :         PMD_DRV_LOG(DEBUG, sc,
   11074                 :            :                     "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x", val);
   11075                 :            : 
   11076                 :            :         val = REG_RD(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
   11077                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x",
   11078                 :            :                     val);
   11079                 :          0 : }
   11080                 :            : 
   11081                 :            : /**
   11082                 :            :  *      bnx2x_pf_flr_clnup
   11083                 :            :  *      a. re-enable target read on the PF
   11084                 :            :  *      b. poll cfc per function usage counter
   11085                 :            :  *      c. poll the qm perfunction usage counter
   11086                 :            :  *      d. poll the tm per function usage counter
   11087                 :            :  *      e. poll the tm per function scan-done indication
   11088                 :            :  *      f. clear the dmae channel associated wit hthe PF
   11089                 :            :  *      g. zero the igu 'trailing edge' and 'leading edge' regs (attentions)
   11090                 :            :  *      h. call the common flr cleanup code with -1 (pf indication)
   11091                 :            :  */
   11092         [ #  # ]:          0 : static int bnx2x_pf_flr_clnup(struct bnx2x_softc *sc)
   11093                 :            : {
   11094                 :            :         uint32_t poll_cnt = bnx2x_flr_clnup_poll_count(sc);
   11095                 :            : 
   11096                 :            :         /* Re-enable PF target read access */
   11097                 :            :         REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
   11098                 :            : 
   11099                 :            :         /* Poll HW usage counters */
   11100         [ #  # ]:          0 :         if (bnx2x_poll_hw_usage_counters(sc, poll_cnt)) {
   11101                 :            :                 return -1;
   11102                 :            :         }
   11103                 :            : 
   11104                 :            :         /* Zero the igu 'trailing edge' and 'leading edge' */
   11105                 :            : 
   11106                 :            :         /* Send the FW cleanup command */
   11107         [ #  # ]:          0 :         if (bnx2x_send_final_clnup(sc, (uint8_t) SC_FUNC(sc), poll_cnt)) {
   11108                 :            :                 return -1;
   11109                 :            :         }
   11110                 :            : 
   11111                 :            :         /* ATC cleanup */
   11112                 :            : 
   11113                 :            :         /* Verify TX hw is flushed */
   11114                 :          0 :         bnx2x_tx_hw_flushed(sc, poll_cnt);
   11115                 :            : 
   11116                 :            :         /* Wait 100ms (not adjusted according to platform) */
   11117                 :          0 :         DELAY(100000);
   11118                 :            : 
   11119                 :            :         /* Verify no pending pci transactions */
   11120         [ #  # ]:          0 :         if (bnx2x_is_pcie_pending(sc)) {
   11121                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "PCIE Transactions still pending");
   11122                 :            :         }
   11123                 :            : 
   11124                 :            :         /* Debug */
   11125                 :          0 :         bnx2x_hw_enable_status(sc);
   11126                 :            : 
   11127                 :            :         /*
   11128                 :            :          * Master enable - Due to WB DMAE writes performed before this
   11129                 :            :          * register is re-initialized as part of the regular function init
   11130                 :            :          */
   11131                 :            :         REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
   11132                 :            : 
   11133                 :          0 :         return 0;
   11134                 :            : }
   11135                 :            : 
   11136                 :          0 : static int bnx2x_init_hw_func(struct bnx2x_softc *sc)
   11137                 :            : {
   11138                 :          0 :         int port = SC_PORT(sc);
   11139                 :            :         int func = SC_FUNC(sc);
   11140                 :          0 :         int init_phase = PHASE_PF0 + func;
   11141                 :            :         struct ecore_ilt *ilt = sc->ilt;
   11142                 :            :         uint16_t cdu_ilt_start;
   11143                 :            :         uint32_t addr, val;
   11144                 :            :         uint32_t main_mem_base, main_mem_size, main_mem_prty_clr;
   11145                 :            :         int main_mem_width, rc;
   11146                 :            :         uint32_t i;
   11147                 :            : 
   11148                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "starting func init for func %d", func);
   11149                 :            : 
   11150                 :            :         /* FLR cleanup */
   11151         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   11152                 :          0 :                 rc = bnx2x_pf_flr_clnup(sc);
   11153         [ #  # ]:          0 :                 if (rc) {
   11154                 :          0 :                         PMD_DRV_LOG(NOTICE, sc, "FLR cleanup failed!");
   11155                 :          0 :                         return rc;
   11156                 :            :                 }
   11157                 :            :         }
   11158                 :            : 
   11159                 :            :         /* set MSI reconfigure capability */
   11160         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
   11161         [ #  # ]:          0 :                 addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
   11162                 :          0 :                 val = REG_RD(sc, addr);
   11163                 :          0 :                 val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
   11164                 :            :                 REG_WR(sc, addr, val);
   11165                 :            :         }
   11166                 :            : 
   11167                 :          0 :         ecore_init_block(sc, BLOCK_PXP, init_phase);
   11168                 :          0 :         ecore_init_block(sc, BLOCK_PXP2, init_phase);
   11169                 :            : 
   11170                 :          0 :         ilt = sc->ilt;
   11171                 :          0 :         cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
   11172                 :            : 
   11173         [ #  # ]:          0 :         for (i = 0; i < L2_ILT_LINES(sc); i++) {
   11174                 :          0 :                 ilt->lines[cdu_ilt_start + i].page = sc->context[i].vcxt;
   11175                 :          0 :                 ilt->lines[cdu_ilt_start + i].page_mapping =
   11176                 :          0 :                     (rte_iova_t)sc->context[i].vcxt_dma.paddr;
   11177                 :          0 :                 ilt->lines[cdu_ilt_start + i].size = sc->context[i].size;
   11178                 :            :         }
   11179                 :          0 :         ecore_ilt_init_op(sc, INITOP_SET);
   11180                 :            : 
   11181                 :            :         REG_WR(sc, PRS_REG_NIC_MODE, 1);
   11182                 :            : 
   11183         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   11184                 :            :                 uint32_t pf_conf = IGU_PF_CONF_FUNC_EN;
   11185                 :            : 
   11186                 :            : /* Turn on a single ISR mode in IGU if driver is going to use
   11187                 :            :  * INT#x or MSI
   11188                 :            :  */
   11189         [ #  # ]:          0 :                 if (sc->interrupt_mode == INTR_MODE_INTX ||
   11190                 :            :                     sc->interrupt_mode == INTR_MODE_MSI)
   11191                 :            :                         pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
   11192                 :            : /*
   11193                 :            :  * Timers workaround bug: function init part.
   11194                 :            :  * Need to wait 20msec after initializing ILT,
   11195                 :            :  * needed to make sure there are no requests in
   11196                 :            :  * one of the PXP internal queues with "old" ILT addresses
   11197                 :            :  */
   11198                 :          0 :                 DELAY(20000);
   11199                 :            : 
   11200                 :            : /*
   11201                 :            :  * Master enable - Due to WB DMAE writes performed before this
   11202                 :            :  * register is re-initialized as part of the regular function
   11203                 :            :  * init
   11204                 :            :  */
   11205                 :            :                 REG_WR(sc, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
   11206                 :            : /* Enable the function in IGU */
   11207                 :            :                 REG_WR(sc, IGU_REG_PF_CONFIGURATION, pf_conf);
   11208                 :            :         }
   11209                 :            : 
   11210                 :          0 :         sc->dmae_ready = 1;
   11211                 :            : 
   11212                 :          0 :         ecore_init_block(sc, BLOCK_PGLUE_B, init_phase);
   11213                 :            : 
   11214         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc))
   11215                 :          0 :                 REG_WR(sc, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
   11216                 :            : 
   11217                 :          0 :         ecore_init_block(sc, BLOCK_ATC, init_phase);
   11218                 :          0 :         ecore_init_block(sc, BLOCK_DMAE, init_phase);
   11219                 :          0 :         ecore_init_block(sc, BLOCK_NIG, init_phase);
   11220                 :          0 :         ecore_init_block(sc, BLOCK_SRC, init_phase);
   11221                 :          0 :         ecore_init_block(sc, BLOCK_MISC, init_phase);
   11222                 :          0 :         ecore_init_block(sc, BLOCK_TCM, init_phase);
   11223                 :          0 :         ecore_init_block(sc, BLOCK_UCM, init_phase);
   11224                 :          0 :         ecore_init_block(sc, BLOCK_CCM, init_phase);
   11225                 :          0 :         ecore_init_block(sc, BLOCK_XCM, init_phase);
   11226                 :          0 :         ecore_init_block(sc, BLOCK_TSEM, init_phase);
   11227                 :          0 :         ecore_init_block(sc, BLOCK_USEM, init_phase);
   11228                 :          0 :         ecore_init_block(sc, BLOCK_CSEM, init_phase);
   11229                 :          0 :         ecore_init_block(sc, BLOCK_XSEM, init_phase);
   11230                 :            : 
   11231         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc))
   11232                 :            :                 REG_WR(sc, QM_REG_PF_EN, 1);
   11233                 :            : 
   11234         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   11235                 :          0 :                 REG_WR(sc, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
   11236                 :            :                 REG_WR(sc, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
   11237                 :            :                 REG_WR(sc, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
   11238                 :            :                 REG_WR(sc, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
   11239                 :            :         }
   11240                 :          0 :         ecore_init_block(sc, BLOCK_QM, init_phase);
   11241                 :            : 
   11242                 :          0 :         ecore_init_block(sc, BLOCK_TM, init_phase);
   11243                 :          0 :         ecore_init_block(sc, BLOCK_DORQ, init_phase);
   11244                 :            : 
   11245                 :          0 :         ecore_init_block(sc, BLOCK_BRB1, init_phase);
   11246                 :          0 :         ecore_init_block(sc, BLOCK_PRS, init_phase);
   11247                 :          0 :         ecore_init_block(sc, BLOCK_TSDM, init_phase);
   11248                 :          0 :         ecore_init_block(sc, BLOCK_CSDM, init_phase);
   11249                 :          0 :         ecore_init_block(sc, BLOCK_USDM, init_phase);
   11250                 :          0 :         ecore_init_block(sc, BLOCK_XSDM, init_phase);
   11251                 :          0 :         ecore_init_block(sc, BLOCK_UPB, init_phase);
   11252                 :          0 :         ecore_init_block(sc, BLOCK_XPB, init_phase);
   11253                 :          0 :         ecore_init_block(sc, BLOCK_PBF, init_phase);
   11254         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc))
   11255                 :            :                 REG_WR(sc, PBF_REG_DISABLE_PF, 0);
   11256                 :            : 
   11257                 :          0 :         ecore_init_block(sc, BLOCK_CDU, init_phase);
   11258                 :            : 
   11259                 :          0 :         ecore_init_block(sc, BLOCK_CFC, init_phase);
   11260                 :            : 
   11261         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc))
   11262                 :            :                 REG_WR(sc, CFC_REG_WEAK_ENABLE_PF, 1);
   11263                 :            : 
   11264   [ #  #  #  # ]:          0 :         if (IS_MF(sc)) {
   11265                 :          0 :                 REG_WR(sc, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
   11266                 :          0 :                 REG_WR(sc, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8, OVLAN(sc));
   11267                 :            :         }
   11268                 :            : 
   11269                 :          0 :         ecore_init_block(sc, BLOCK_MISC_AEU, init_phase);
   11270                 :            : 
   11271                 :            :         /* HC init per function */
   11272         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
   11273         [ #  # ]:          0 :                 if (CHIP_IS_E1H(sc)) {
   11274                 :          0 :                         REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
   11275                 :            : 
   11276                 :          0 :                         REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, 0);
   11277                 :          0 :                         REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, 0);
   11278                 :            :                 }
   11279                 :          0 :                 ecore_init_block(sc, BLOCK_HC, init_phase);
   11280                 :            : 
   11281                 :            :         } else {
   11282                 :            :                 uint32_t num_segs, sb_idx, prod_offset;
   11283                 :            : 
   11284                 :          0 :                 REG_WR(sc, MISC_REG_AEU_GENERAL_ATTN_12 + func * 4, 0);
   11285                 :            : 
   11286         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
   11287                 :            :                         REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
   11288                 :            :                         REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
   11289                 :            :                 }
   11290                 :            : 
   11291                 :          0 :                 ecore_init_block(sc, BLOCK_IGU, init_phase);
   11292                 :            : 
   11293         [ #  # ]:          0 :                 if (!CHIP_IS_E1x(sc)) {
   11294                 :            :                         int dsb_idx = 0;
   11295                 :            :         /**
   11296                 :            :          * Producer memory:
   11297                 :            :          * E2 mode: address 0-135 match to the mapping memory;
   11298                 :            :          * 136 - PF0 default prod; 137 - PF1 default prod;
   11299                 :            :          * 138 - PF2 default prod; 139 - PF3 default prod;
   11300                 :            :          * 140 - PF0 attn prod;    141 - PF1 attn prod;
   11301                 :            :          * 142 - PF2 attn prod;    143 - PF3 attn prod;
   11302                 :            :          * 144-147 reserved.
   11303                 :            :          *
   11304                 :            :          * E1.5 mode - In backward compatible mode;
   11305                 :            :          * for non default SB; each even line in the memory
   11306                 :            :          * holds the U producer and each odd line hold
   11307                 :            :          * the C producer. The first 128 producers are for
   11308                 :            :          * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
   11309                 :            :          * producers are for the DSB for each PF.
   11310                 :            :          * Each PF has five segments: (the order inside each
   11311                 :            :          * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
   11312                 :            :          * 132-135 C prods; 136-139 X prods; 140-143 T prods;
   11313                 :            :          * 144-147 attn prods;
   11314                 :            :          */
   11315                 :            :                         /* non-default-status-blocks */
   11316         [ #  # ]:          0 :                         num_segs = CHIP_INT_MODE_IS_BC(sc) ?
   11317                 :            :                             IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
   11318         [ #  # ]:          0 :                         for (sb_idx = 0; sb_idx < sc->igu_sb_cnt; sb_idx++) {
   11319                 :          0 :                                 prod_offset = (sc->igu_base_sb + sb_idx) *
   11320                 :            :                                     num_segs;
   11321                 :            : 
   11322         [ #  # ]:          0 :                                 for (i = 0; i < num_segs; i++) {
   11323                 :          0 :                                         addr = IGU_REG_PROD_CONS_MEMORY +
   11324                 :          0 :                                             (prod_offset + i) * 4;
   11325                 :          0 :                                         REG_WR(sc, addr, 0);
   11326                 :            :                                 }
   11327                 :            :                                 /* send consumer update with value 0 */
   11328                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_base_sb + sb_idx,
   11329                 :            :                                            USTORM_ID, 0, IGU_INT_NOP, 1);
   11330                 :          0 :                                 bnx2x_igu_clear_sb(sc, sc->igu_base_sb + sb_idx);
   11331                 :            :                         }
   11332                 :            : 
   11333                 :            :                         /* default-status-blocks */
   11334         [ #  # ]:          0 :                         num_segs = CHIP_INT_MODE_IS_BC(sc) ?
   11335         [ #  # ]:          0 :                             IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
   11336                 :            : 
   11337         [ #  # ]:          0 :                         if (CHIP_IS_MODE_4_PORT(sc))
   11338                 :          0 :                                 dsb_idx = SC_FUNC(sc);
   11339                 :            :                         else
   11340                 :          0 :                                 dsb_idx = SC_VN(sc);
   11341                 :            : 
   11342         [ #  # ]:          0 :                         prod_offset = (CHIP_INT_MODE_IS_BC(sc) ?
   11343         [ #  # ]:          0 :                                        IGU_BC_BASE_DSB_PROD + dsb_idx :
   11344                 :          0 :                                        IGU_NORM_BASE_DSB_PROD + dsb_idx);
   11345                 :            : 
   11346                 :            :                         /*
   11347                 :            :                          * igu prods come in chunks of E1HVN_MAX (4) -
   11348                 :            :                          * does not matters what is the current chip mode
   11349                 :            :                          */
   11350         [ #  # ]:          0 :                         for (i = 0; i < (num_segs * E1HVN_MAX); i += E1HVN_MAX) {
   11351                 :          0 :                                 addr = IGU_REG_PROD_CONS_MEMORY +
   11352                 :          0 :                                     (prod_offset + i) * 4;
   11353                 :          0 :                                 REG_WR(sc, addr, 0);
   11354                 :            :                         }
   11355                 :            :                         /* send consumer update with 0 */
   11356   [ #  #  #  # ]:          0 :                         if (CHIP_INT_MODE_IS_BC(sc)) {
   11357                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11358                 :            :                                            USTORM_ID, 0, IGU_INT_NOP, 1);
   11359                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11360                 :            :                                            CSTORM_ID, 0, IGU_INT_NOP, 1);
   11361                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11362                 :            :                                            XSTORM_ID, 0, IGU_INT_NOP, 1);
   11363                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11364                 :            :                                            TSTORM_ID, 0, IGU_INT_NOP, 1);
   11365                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11366                 :            :                                            ATTENTION_ID, 0, IGU_INT_NOP, 1);
   11367                 :            :                         } else {
   11368                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11369                 :            :                                            USTORM_ID, 0, IGU_INT_NOP, 1);
   11370                 :          0 :                                 bnx2x_ack_sb(sc, sc->igu_dsb_id,
   11371                 :            :                                            ATTENTION_ID, 0, IGU_INT_NOP, 1);
   11372                 :            :                         }
   11373                 :          0 :                         bnx2x_igu_clear_sb(sc, sc->igu_dsb_id);
   11374                 :            : 
   11375                 :            :                         /* !!! these should become driver const once
   11376                 :            :                            rf-tool supports split-68 const */
   11377                 :            :                         REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
   11378                 :            :                         REG_WR(sc, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
   11379                 :            :                         REG_WR(sc, IGU_REG_SB_MASK_LSB, 0);
   11380                 :            :                         REG_WR(sc, IGU_REG_SB_MASK_MSB, 0);
   11381                 :            :                         REG_WR(sc, IGU_REG_PBA_STATUS_LSB, 0);
   11382                 :            :                         REG_WR(sc, IGU_REG_PBA_STATUS_MSB, 0);
   11383                 :            :                 }
   11384                 :            :         }
   11385                 :            : 
   11386                 :            :         /* Reset PCIE errors for debug */
   11387                 :            :         REG_WR(sc, 0x2114, 0xffffffff);
   11388                 :            :         REG_WR(sc, 0x2120, 0xffffffff);
   11389                 :            : 
   11390         [ #  # ]:          0 :         if (CHIP_IS_E1x(sc)) {
   11391                 :            :                 main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2;    /*dwords */
   11392                 :          0 :                 main_mem_base = HC_REG_MAIN_MEMORY +
   11393                 :          0 :                     SC_PORT(sc) * (main_mem_size * 4);
   11394                 :            :                 main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
   11395                 :            :                 main_mem_width = 8;
   11396                 :            : 
   11397                 :            :                 val = REG_RD(sc, main_mem_prty_clr);
   11398         [ #  # ]:          0 :                 if (val) {
   11399                 :          0 :                         PMD_DRV_LOG(DEBUG, sc,
   11400                 :            :                                     "Parity errors in HC block during function init (0x%x)!",
   11401                 :            :                                     val);
   11402                 :            :                 }
   11403                 :            : 
   11404                 :            : /* Clear "false" parity errors in MSI-X table */
   11405                 :            :                 for (i = main_mem_base;
   11406         [ #  # ]:          0 :                      i < main_mem_base + main_mem_size * 4;
   11407                 :          0 :                      i += main_mem_width) {
   11408                 :          0 :                         bnx2x_read_dmae(sc, i, main_mem_width / 4);
   11409                 :          0 :                         bnx2x_write_dmae(sc, BNX2X_SP_MAPPING(sc, wb_data),
   11410                 :            :                                        i, main_mem_width / 4);
   11411                 :            :                 }
   11412                 :            : /* Clear HC parity attention */
   11413                 :            :                 REG_RD(sc, main_mem_prty_clr);
   11414                 :            :         }
   11415                 :            : 
   11416                 :            :         /* Enable STORMs SP logging */
   11417                 :          0 :         REG_WR8(sc, BAR_USTRORM_INTMEM +
   11418                 :            :                 USTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
   11419                 :          0 :         REG_WR8(sc, BAR_TSTRORM_INTMEM +
   11420                 :            :                 TSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
   11421                 :          0 :         REG_WR8(sc, BAR_CSTRORM_INTMEM +
   11422                 :            :                 CSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
   11423                 :          0 :         REG_WR8(sc, BAR_XSTRORM_INTMEM +
   11424                 :            :                 XSTORM_RECORD_SLOW_PATH_OFFSET(SC_FUNC(sc)), 1);
   11425                 :            : 
   11426                 :          0 :         elink_phy_probe(&sc->link_params);
   11427                 :            : 
   11428                 :          0 :         return 0;
   11429                 :            : }
   11430                 :            : 
   11431                 :          0 : static void bnx2x_link_reset(struct bnx2x_softc *sc)
   11432                 :            : {
   11433         [ #  # ]:          0 :         if (!BNX2X_NOMCP(sc)) {
   11434                 :          0 :                 bnx2x_acquire_phy_lock(sc);
   11435                 :          0 :                 elink_lfa_reset(&sc->link_params, &sc->link_vars);
   11436                 :            :                 bnx2x_release_phy_lock(sc);
   11437                 :            :         } else {
   11438         [ #  # ]:          0 :                 if (!CHIP_REV_IS_SLOW(sc)) {
   11439                 :          0 :                         PMD_DRV_LOG(WARNING, sc,
   11440                 :            :                                     "Bootcode is missing - cannot reset link");
   11441                 :            :                 }
   11442                 :            :         }
   11443                 :          0 : }
   11444                 :            : 
   11445                 :          0 : static void bnx2x_reset_port(struct bnx2x_softc *sc)
   11446                 :            : {
   11447                 :          0 :         int port = SC_PORT(sc);
   11448                 :            :         uint32_t val;
   11449                 :            : 
   11450                 :            :         /* reset physical Link */
   11451                 :          0 :         bnx2x_link_reset(sc);
   11452                 :            : 
   11453                 :          0 :         REG_WR(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4, 0);
   11454                 :            : 
   11455                 :            :         /* Do not rcv packets to BRB */
   11456                 :          0 :         REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + port * 4, 0x0);
   11457                 :            :         /* Do not direct rcv packets that are not for MCP to the BRB */
   11458         [ #  # ]:          0 :         REG_WR(sc, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
   11459                 :            :                     NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
   11460                 :            : 
   11461                 :            :         /* Configure AEU */
   11462                 :          0 :         REG_WR(sc, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port * 4, 0);
   11463                 :            : 
   11464                 :          0 :         DELAY(100000);
   11465                 :            : 
   11466                 :            :         /* Check for BRB port occupancy */
   11467                 :          0 :         val = REG_RD(sc, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port * 4);
   11468         [ #  # ]:          0 :         if (val) {
   11469                 :          0 :                 PMD_DRV_LOG(DEBUG, sc,
   11470                 :            :                             "BRB1 is not empty, %d blocks are occupied", val);
   11471                 :            :         }
   11472                 :          0 : }
   11473                 :            : 
   11474                 :          0 : static void bnx2x_ilt_wr(struct bnx2x_softc *sc, uint32_t index, rte_iova_t addr)
   11475                 :            : {
   11476                 :            :         int reg;
   11477                 :            :         uint32_t wb_write[2];
   11478                 :            : 
   11479                 :          0 :         reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index * 8;
   11480                 :            : 
   11481                 :          0 :         wb_write[0] = ONCHIP_ADDR1(addr);
   11482                 :          0 :         wb_write[1] = ONCHIP_ADDR2(addr);
   11483         [ #  # ]:          0 :         REG_WR_DMAE(sc, reg, wb_write, 2);
   11484                 :          0 : }
   11485                 :            : 
   11486                 :            : static void bnx2x_clear_func_ilt(struct bnx2x_softc *sc, uint32_t func)
   11487                 :            : {
   11488                 :          0 :         uint32_t i, base = FUNC_ILT_BASE(func);
   11489         [ #  # ]:          0 :         for (i = base; i < base + ILT_PER_FUNC; i++) {
   11490                 :          0 :                 bnx2x_ilt_wr(sc, i, 0);
   11491                 :            :         }
   11492                 :            : }
   11493                 :            : 
   11494                 :          0 : static void bnx2x_reset_func(struct bnx2x_softc *sc)
   11495                 :            : {
   11496                 :            :         struct bnx2x_fastpath *fp;
   11497                 :          0 :         int port = SC_PORT(sc);
   11498                 :            :         int func = SC_FUNC(sc);
   11499                 :            :         int i;
   11500                 :            : 
   11501                 :            :         /* Disable the function in the FW */
   11502                 :          0 :         REG_WR8(sc, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
   11503                 :          0 :         REG_WR8(sc, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
   11504                 :          0 :         REG_WR8(sc, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
   11505                 :          0 :         REG_WR8(sc, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
   11506                 :            : 
   11507                 :            :         /* FP SBs */
   11508         [ #  # ]:          0 :         FOR_EACH_ETH_QUEUE(sc, i) {
   11509                 :            :                 fp = &sc->fp[i];
   11510                 :          0 :                 REG_WR8(sc, BAR_CSTRORM_INTMEM +
   11511                 :            :                         CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
   11512                 :            :                         SB_DISABLED);
   11513                 :            :         }
   11514                 :            : 
   11515                 :            :         /* SP SB */
   11516                 :          0 :         REG_WR8(sc, BAR_CSTRORM_INTMEM +
   11517                 :            :                 CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func), SB_DISABLED);
   11518                 :            : 
   11519         [ #  # ]:          0 :         for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++) {
   11520                 :          0 :                 REG_WR(sc, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
   11521                 :            :                        0);
   11522                 :            :         }
   11523                 :            : 
   11524                 :            :         /* Configure IGU */
   11525         [ #  # ]:          0 :         if (sc->devinfo.int_block == INT_BLOCK_HC) {
   11526                 :          0 :                 REG_WR(sc, HC_REG_LEADING_EDGE_0 + port * 8, 0);
   11527                 :          0 :                 REG_WR(sc, HC_REG_TRAILING_EDGE_0 + port * 8, 0);
   11528                 :            :         } else {
   11529                 :            :                 REG_WR(sc, IGU_REG_LEADING_EDGE_LATCH, 0);
   11530                 :            :                 REG_WR(sc, IGU_REG_TRAILING_EDGE_LATCH, 0);
   11531                 :            :         }
   11532                 :            : 
   11533                 :            :         if (CNIC_LOADED(sc)) {
   11534                 :            : /* Disable Timer scan */
   11535                 :            :                 REG_WR(sc, TM_REG_EN_LINEAR0_TIMER + port * 4, 0);
   11536                 :            : /*
   11537                 :            :  * Wait for at least 10ms and up to 2 second for the timers
   11538                 :            :  * scan to complete
   11539                 :            :  */
   11540                 :            :                 for (i = 0; i < 200; i++) {
   11541                 :            :                         DELAY(10000);
   11542                 :            :                         if (!REG_RD(sc, TM_REG_LIN0_SCAN_ON + port * 4))
   11543                 :            :                                 break;
   11544                 :            :                 }
   11545                 :            :         }
   11546                 :            : 
   11547                 :            :         /* Clear ILT */
   11548                 :          0 :         bnx2x_clear_func_ilt(sc, func);
   11549                 :            : 
   11550                 :            :         /*
   11551                 :            :          * Timers workaround bug for E2: if this is vnic-3,
   11552                 :            :          * we need to set the entire ilt range for this timers.
   11553                 :            :          */
   11554   [ #  #  #  # ]:          0 :         if (!CHIP_IS_E1x(sc) && SC_VN(sc) == 3) {
   11555                 :            :                 struct ilt_client_info ilt_cli;
   11556                 :            : /* use dummy TM client */
   11557                 :            :                 memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
   11558                 :            :                 ilt_cli.start = 0;
   11559                 :          0 :                 ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
   11560                 :          0 :                 ilt_cli.client_num = ILT_CLIENT_TM;
   11561                 :            : 
   11562                 :          0 :                 ecore_ilt_boundary_init_op(sc, &ilt_cli, 0, INITOP_CLEAR);
   11563                 :            :         }
   11564                 :            : 
   11565                 :            :         /* this assumes that reset_port() called before reset_func() */
   11566         [ #  # ]:          0 :         if (!CHIP_IS_E1x(sc)) {
   11567                 :            :                 bnx2x_pf_disable(sc);
   11568                 :            :         }
   11569                 :            : 
   11570                 :          0 :         sc->dmae_ready = 0;
   11571                 :          0 : }
   11572                 :            : 
   11573                 :          0 : static void bnx2x_release_firmware(struct bnx2x_softc *sc)
   11574                 :            : {
   11575                 :          0 :         rte_free(sc->init_ops);
   11576                 :          0 :         rte_free(sc->init_ops_offsets);
   11577                 :          0 :         rte_free(sc->init_data);
   11578                 :          0 :         rte_free(sc->iro_array);
   11579                 :          0 : }
   11580                 :            : 
   11581                 :          0 : static int bnx2x_init_firmware(struct bnx2x_softc *sc)
   11582                 :            : {
   11583                 :            :         uint32_t len, i;
   11584                 :          0 :         uint8_t *p = sc->firmware;
   11585                 :            :         uint32_t off[24];
   11586                 :            : 
   11587         [ #  # ]:          0 :         for (i = 0; i < 24; ++i)
   11588         [ #  # ]:          0 :                 off[i] = rte_be_to_cpu_32(*((uint32_t *) sc->firmware + i));
   11589                 :            : 
   11590                 :          0 :         len = off[0];
   11591                 :          0 :         sc->init_ops = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
   11592         [ #  # ]:          0 :         if (!sc->init_ops)
   11593                 :          0 :                 goto alloc_failed;
   11594                 :          0 :         bnx2x_data_to_init_ops(p + off[1], sc->init_ops, len);
   11595                 :            : 
   11596                 :          0 :         len = off[2];
   11597                 :          0 :         sc->init_ops_offsets = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
   11598         [ #  # ]:          0 :         if (!sc->init_ops_offsets)
   11599                 :          0 :                 goto alloc_failed;
   11600                 :          0 :         bnx2x_data_to_init_offsets(p + off[3], sc->init_ops_offsets, len);
   11601                 :            : 
   11602                 :          0 :         len = off[4];
   11603                 :          0 :         sc->init_data = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
   11604         [ #  # ]:          0 :         if (!sc->init_data)
   11605                 :          0 :                 goto alloc_failed;
   11606                 :          0 :         bnx2x_data_to_init_data(p + off[5], sc->init_data, len);
   11607                 :            : 
   11608                 :          0 :         sc->tsem_int_table_data = p + off[7];
   11609                 :          0 :         sc->tsem_pram_data = p + off[9];
   11610                 :          0 :         sc->usem_int_table_data = p + off[11];
   11611                 :          0 :         sc->usem_pram_data = p + off[13];
   11612                 :          0 :         sc->csem_int_table_data = p + off[15];
   11613                 :          0 :         sc->csem_pram_data = p + off[17];
   11614                 :          0 :         sc->xsem_int_table_data = p + off[19];
   11615                 :          0 :         sc->xsem_pram_data = p + off[21];
   11616                 :            : 
   11617                 :          0 :         len = off[22];
   11618                 :          0 :         sc->iro_array = rte_zmalloc("", len, RTE_CACHE_LINE_SIZE);
   11619         [ #  # ]:          0 :         if (!sc->iro_array)
   11620                 :          0 :                 goto alloc_failed;
   11621                 :          0 :         bnx2x_data_to_iro_array(p + off[23], sc->iro_array, len);
   11622                 :            : 
   11623                 :          0 :         return 0;
   11624                 :            : 
   11625                 :          0 : alloc_failed:
   11626                 :          0 :         bnx2x_release_firmware(sc);
   11627                 :          0 :         return -1;
   11628                 :            : }
   11629                 :            : 
   11630                 :          0 : static int cut_gzip_prefix(const uint8_t * zbuf, int len)
   11631                 :            : {
   11632                 :            : #define MIN_PREFIX_SIZE (10)
   11633                 :            : 
   11634                 :            :         int n = MIN_PREFIX_SIZE;
   11635                 :            :         uint16_t xlen;
   11636                 :            : 
   11637   [ #  #  #  #  :          0 :         if (!(zbuf[0] == 0x1f && zbuf[1] == 0x8b && zbuf[2] == Z_DEFLATED) ||
             #  #  #  # ]
   11638                 :            :             len <= MIN_PREFIX_SIZE) {
   11639                 :            :                 return -1;
   11640                 :            :         }
   11641                 :            : 
   11642                 :            :         /* optional extra fields are present */
   11643         [ #  # ]:          0 :         if (zbuf[3] & 0x4) {
   11644                 :          0 :                 xlen = zbuf[13];
   11645                 :          0 :                 xlen <<= 8;
   11646                 :          0 :                 xlen += zbuf[12];
   11647                 :            : 
   11648                 :          0 :                 n += xlen;
   11649                 :            :         }
   11650                 :            :         /* file name is present */
   11651         [ #  # ]:          0 :         if (zbuf[3] & 0x8) {
   11652   [ #  #  #  # ]:          0 :                 while ((zbuf[n++] != 0) && (n < len)) ;
   11653                 :            :         }
   11654                 :            : 
   11655                 :            :         return n;
   11656                 :            : }
   11657                 :            : 
   11658                 :          0 : static int ecore_gunzip(struct bnx2x_softc *sc, const uint8_t * zbuf, int len)
   11659                 :            : {
   11660                 :            :         int ret;
   11661                 :          0 :         int data_begin = cut_gzip_prefix(zbuf, len);
   11662                 :            : 
   11663                 :          0 :         PMD_DRV_LOG(DEBUG, sc, "ecore_gunzip %d", len);
   11664                 :            : 
   11665         [ #  # ]:          0 :         if (data_begin <= 0) {
   11666                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "bad gzip prefix");
   11667                 :          0 :                 return -1;
   11668                 :            :         }
   11669                 :            : 
   11670                 :            :         memset(&zlib_stream, 0, sizeof(zlib_stream));
   11671                 :          0 :         zlib_stream.next_in = zbuf + data_begin;
   11672                 :          0 :         zlib_stream.avail_in = len - data_begin;
   11673                 :          0 :         zlib_stream.next_out = sc->gz_buf;
   11674                 :          0 :         zlib_stream.avail_out = FW_BUF_SIZE;
   11675                 :            : 
   11676                 :          0 :         ret = inflateInit2(&zlib_stream, -MAX_WBITS);
   11677         [ #  # ]:          0 :         if (ret != Z_OK) {
   11678                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "zlib inflateInit2 error");
   11679                 :          0 :                 return ret;
   11680                 :            :         }
   11681                 :            : 
   11682                 :          0 :         ret = inflate(&zlib_stream, Z_FINISH);
   11683         [ #  # ]:          0 :         if ((ret != Z_STREAM_END) && (ret != Z_OK)) {
   11684                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "zlib inflate error: %d %s", ret,
   11685                 :            :                             zlib_stream.msg);
   11686                 :            :         }
   11687                 :            : 
   11688                 :          0 :         sc->gz_outlen = zlib_stream.total_out;
   11689         [ #  # ]:          0 :         if (sc->gz_outlen & 0x3) {
   11690                 :          0 :                 PMD_DRV_LOG(NOTICE, sc, "firmware is not aligned. gz_outlen == %d",
   11691                 :            :                             sc->gz_outlen);
   11692                 :            :         }
   11693                 :          0 :         sc->gz_outlen >>= 2;
   11694                 :            : 
   11695                 :          0 :         inflateEnd(&zlib_stream);
   11696                 :            : 
   11697         [ #  # ]:          0 :         if (ret == Z_STREAM_END)
   11698                 :          0 :                 return 0;
   11699                 :            : 
   11700                 :            :         return ret;
   11701                 :            : }
   11702                 :            : 
   11703                 :            : static void
   11704                 :            : ecore_write_dmae_phys_len(struct bnx2x_softc *sc, rte_iova_t phys_addr,
   11705                 :            :                           uint32_t addr, uint32_t len)
   11706                 :            : {
   11707                 :          0 :         bnx2x_write_dmae_phys_len(sc, phys_addr, addr, len);
   11708                 :          0 : }
   11709                 :            : 
   11710                 :            : void
   11711                 :          0 : ecore_storm_memset_struct(struct bnx2x_softc *sc, uint32_t addr, size_t size,
   11712                 :            :                           uint32_t * data)
   11713                 :            : {
   11714                 :            :         uint8_t i;
   11715         [ #  # ]:          0 :         for (i = 0; i < size / 4; i++) {
   11716                 :          0 :                 REG_WR(sc, addr + (i * 4), data[i]);
   11717                 :            :         }
   11718                 :          0 : }
   11719                 :            : 
   11720                 :            : static const char *get_ext_phy_type(uint32_t ext_phy_type)
   11721                 :            : {
   11722                 :          0 :         uint32_t phy_type_idx = ext_phy_type >> 8;
   11723                 :            :         static const char *types[] =
   11724                 :            :             { "DIRECT", "BNX2X-8071", "BNX2X-8072", "BNX2X-8073",
   11725                 :            :                 "BNX2X-8705", "BNX2X-8706", "BNX2X-8726", "BNX2X-8481", "SFX-7101",
   11726                 :            :                 "BNX2X-8727",
   11727                 :            :                 "BNX2X-8727-NOC", "BNX2X-84823", "NOT_CONN", "FAILURE"
   11728                 :            :         };
   11729                 :            : 
   11730         [ #  # ]:          0 :         if (phy_type_idx < 12)
   11731                 :          0 :                 return types[phy_type_idx];
   11732         [ #  # ]:          0 :         else if (PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN == ext_phy_type)
   11733                 :          0 :                 return types[12];
   11734                 :            :         else
   11735                 :          0 :                 return types[13];
   11736                 :            : }
   11737                 :            : 
   11738                 :            : static const char *get_state(uint32_t state)
   11739                 :            : {
   11740                 :          0 :         uint32_t state_idx = state >> 12;
   11741                 :            :         static const char *states[] = { "CLOSED", "OPENING_WAIT4_LOAD",
   11742                 :            :                 "OPENING_WAIT4_PORT", "OPEN", "CLOSING_WAIT4_HALT",
   11743                 :            :                 "CLOSING_WAIT4_DELETE", "CLOSING_WAIT4_UNLOAD",
   11744                 :            :                 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
   11745                 :            :                 "UNKNOWN", "DISABLED", "DIAG", "ERROR", "UNDEFINED"
   11746                 :            :         };
   11747                 :            : 
   11748                 :          0 :         if (state_idx <= 0xF)
   11749                 :          0 :                 return states[state_idx];
   11750                 :            :         else
   11751                 :          0 :                 return states[0x10];
   11752                 :            : }
   11753                 :            : 
   11754                 :            : static const char *get_recovery_state(uint32_t state)
   11755                 :            : {
   11756                 :            :         static const char *states[] = { "NONE", "DONE", "INIT",
   11757                 :            :                 "WAIT", "FAILED", "NIC_LOADING"
   11758                 :            :         };
   11759                 :          0 :         return states[state];
   11760                 :            : }
   11761                 :            : 
   11762                 :            : static const char *get_rx_mode(uint32_t mode)
   11763                 :            : {
   11764                 :            :         static const char *modes[] = { "NONE", "NORMAL", "ALLMULTI",
   11765                 :            :                 "PROMISC", "MAX_MULTICAST", "ERROR"
   11766                 :            :         };
   11767                 :            : 
   11768                 :          0 :         if (mode < 0x4)
   11769                 :          0 :                 return modes[mode];
   11770         [ #  # ]:          0 :         else if (BNX2X_MAX_MULTICAST == mode)
   11771                 :          0 :                 return modes[4];
   11772                 :            :         else
   11773                 :          0 :                 return modes[5];
   11774                 :            : }
   11775                 :            : 
   11776                 :            : #define BNX2X_INFO_STR_MAX 256
   11777                 :          0 : static const char *get_bnx2x_flags(uint32_t flags)
   11778                 :            : {
   11779                 :            :         int i;
   11780                 :            :         static const char *flag[] = { "ONE_PORT ", "NO_ISCSI ",
   11781                 :            :                 "NO_FCOE ", "NO_WOL ", "USING_DAC ", "USING_MSIX ",
   11782                 :            :                 "USING_MSI ", "DISABLE_MSI ", "UNKNOWN ", "NO_MCP ",
   11783                 :            :                 "SAFC_TX_FLAG ", "MF_FUNC_DIS ", "TX_SWITCHING "
   11784                 :            :         };
   11785                 :            :         static char flag_str[BNX2X_INFO_STR_MAX];
   11786                 :            :         memset(flag_str, 0, BNX2X_INFO_STR_MAX);
   11787                 :            : 
   11788         [ #  # ]:          0 :         for (i = 0; i < 5; i++)
   11789         [ #  # ]:          0 :                 if (flags & (1 << i)) {
   11790                 :          0 :                         strlcat(flag_str, flag[i], sizeof(flag_str));
   11791                 :          0 :                         flags ^= (1 << i);
   11792                 :            :                 }
   11793         [ #  # ]:          0 :         if (flags) {
   11794                 :            :                 static char unknown[BNX2X_INFO_STR_MAX];
   11795                 :            :                 snprintf(unknown, 32, "Unknown flag mask %x", flags);
   11796                 :          0 :                 strlcat(flag_str, unknown, sizeof(flag_str));
   11797                 :            :         }
   11798                 :          0 :         return flag_str;
   11799                 :            : }
   11800                 :            : 
   11801                 :            : /* Prints useful adapter info. */
   11802                 :          0 : void bnx2x_print_adapter_info(struct bnx2x_softc *sc)
   11803                 :            : {
   11804                 :            :         int i = 0;
   11805                 :            : 
   11806                 :          0 :         PMD_DRV_LOG(INFO, sc, "========================================");
   11807                 :            :         /* DPDK and Driver versions */
   11808                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "DPDK",
   11809                 :            :                         rte_version());
   11810                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "Driver",
   11811                 :            :                         bnx2x_pmd_version());
   11812                 :            :         /* Firmware versions. */
   11813                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %d.%d.%d",
   11814                 :            :                      "Firmware",
   11815                 :            :                      BNX2X_5710_FW_MAJOR_VERSION,
   11816                 :            :                      BNX2X_5710_FW_MINOR_VERSION,
   11817                 :            :                      BNX2X_5710_FW_REVISION_VERSION);
   11818                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s",
   11819                 :            :                      "Bootcode", sc->devinfo.bc_ver_str);
   11820                 :            :         /* Hardware chip info. */
   11821                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %#08x", "ASIC", sc->devinfo.chip_id);
   11822                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %c%d", "Rev", (CHIP_REV(sc) >> 12) + 'A',
   11823                 :            :                      (CHIP_METAL(sc) >> 4));
   11824                 :            :         /* Bus PCIe info. */
   11825                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : 0x%x", "Vendor Id",
   11826                 :            :                     sc->devinfo.vendor_id);
   11827                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : 0x%x", "Device Id",
   11828                 :            :                     sc->devinfo.device_id);
   11829                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : width x%d, ", "Bus PCIe",
   11830                 :            :                     sc->devinfo.pcie_link_width);
   11831   [ #  #  #  # ]:          0 :         switch (sc->devinfo.pcie_link_speed) {
   11832                 :            :         case 1:
   11833                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%23s", "2.5 Gbps");
   11834                 :          0 :                 break;
   11835                 :            :         case 2:
   11836                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%21s", "5 Gbps");
   11837                 :          0 :                 break;
   11838                 :            :         case 4:
   11839                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%21s", "8 Gbps");
   11840                 :          0 :                 break;
   11841                 :            :         default:
   11842                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%33s", "Unknown link speed");
   11843                 :            :         }
   11844                 :            :         /* Device features. */
   11845                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : ", "Flags");
   11846                 :            :         /* Miscellaneous flags. */
   11847         [ #  # ]:          0 :         if (sc->devinfo.pcie_cap_flags & BNX2X_MSI_CAPABLE_FLAG) {
   11848                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%18s", "MSI");
   11849                 :            :                 i++;
   11850                 :            :         }
   11851         [ #  # ]:          0 :         if (sc->devinfo.pcie_cap_flags & BNX2X_MSIX_CAPABLE_FLAG) {
   11852         [ #  # ]:          0 :                 if (i > 0)
   11853                 :          0 :                         PMD_DRV_LOG(INFO, sc, "|");
   11854                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%20s", "MSI-X");
   11855                 :            :                 i++;
   11856                 :            :         }
   11857         [ #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "OVLAN", (OVLAN(sc) ? "YES" : "NO"));
   11858   [ #  #  #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "MF", (IS_MF(sc) ? "YES" : "NO"));
   11859                 :          0 :         PMD_DRV_LOG(INFO, sc, "========================================");
   11860                 :          0 : }
   11861                 :            : 
   11862                 :            : /* Prints useful device info. */
   11863                 :          0 : void bnx2x_print_device_info(struct bnx2x_softc *sc)
   11864                 :            : {
   11865                 :            :         __rte_unused uint32_t ext_phy_type;
   11866                 :            :         uint32_t offset, reg_val;
   11867                 :            : 
   11868                 :          0 :         PMD_INIT_FUNC_TRACE(sc);
   11869                 :            :         offset = offsetof(struct shmem_region,
   11870                 :            :                           dev_info.port_hw_config[0].external_phy_config);
   11871                 :          0 :         reg_val = REG_RD(sc, sc->devinfo.shmem_base + offset);
   11872         [ #  # ]:          0 :         if (sc->link_vars.phy_flags & PHY_XGXS_FLAG)
   11873                 :          0 :                 ext_phy_type = ELINK_XGXS_EXT_PHY_TYPE(reg_val);
   11874                 :            :         else
   11875                 :          0 :                 ext_phy_type = ELINK_SERDES_EXT_PHY_TYPE(reg_val);
   11876                 :            : 
   11877                 :            :         /* Device features. */
   11878                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %u", "Bnx2x Func", sc->pcie_func);
   11879                 :          0 :         PMD_DRV_LOG(INFO, sc,
   11880                 :            :                     "%12s : %s", "Bnx2x Flags", get_bnx2x_flags(sc->flags));
   11881         [ #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "DMAE Is",
   11882                 :            :                      (sc->dmae_ready ? "Ready" : "Not Ready"));
   11883                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %u", "MTU", sc->mtu);
   11884                 :          0 :         PMD_DRV_LOG(INFO, sc,
   11885                 :            :                     "%12s : %s", "PHY Type", get_ext_phy_type(ext_phy_type));
   11886                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : " RTE_ETHER_ADDR_PRT_FMT, "MAC Addr",
   11887                 :            :                         sc->link_params.mac_addr[0],
   11888                 :            :                         sc->link_params.mac_addr[1],
   11889                 :            :                         sc->link_params.mac_addr[2],
   11890                 :            :                         sc->link_params.mac_addr[3],
   11891                 :            :                         sc->link_params.mac_addr[4],
   11892                 :            :                         sc->link_params.mac_addr[5]);
   11893         [ #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "RX Mode", get_rx_mode(sc->rx_mode));
   11894         [ #  # ]:          0 :         PMD_DRV_LOG(INFO, sc, "%12s : %s", "State", get_state(sc->state));
   11895         [ #  # ]:          0 :         if (sc->recovery_state)
   11896                 :          0 :                 PMD_DRV_LOG(INFO, sc, "%12s : %s", "Recovery",
   11897                 :            :                              get_recovery_state(sc->recovery_state));
   11898                 :            :         /* Queue info. */
   11899         [ #  # ]:          0 :         if (IS_PF(sc)) {
   11900      [ #  #  # ]:          0 :                 switch (sc->sp->rss_rdata.rss_mode) {
   11901                 :            :                 case ETH_RSS_MODE_DISABLED:
   11902                 :          0 :                         PMD_DRV_LOG(INFO, sc, "%12s : %s", "Queues", "RSS mode - None");
   11903                 :          0 :                         break;
   11904                 :            :                 case ETH_RSS_MODE_REGULAR:
   11905                 :          0 :                         PMD_DRV_LOG(INFO, sc, "%12s : %s,", "Queues", "RSS mode - Regular");
   11906                 :          0 :                         PMD_DRV_LOG(INFO, sc, "%16d", sc->num_queues);
   11907                 :          0 :                         break;
   11908                 :            :                 default:
   11909                 :          0 :                         PMD_DRV_LOG(INFO, sc, "%12s : %s", "Queues", "RSS mode - Unknown");
   11910                 :          0 :                         break;
   11911                 :            :                 }
   11912                 :            :         }
   11913                 :          0 :         PMD_DRV_LOG(INFO, sc, "%12s : CQ = %lx,  EQ = %lx", "SPQ Left",
   11914                 :            :                      sc->cq_spq_left, sc->eq_spq_left);
   11915                 :            : 
   11916                 :          0 :         PMD_DRV_LOG(INFO, sc,
   11917                 :            :                     "%12s : %x", "Switch", sc->link_params.switch_cfg);
   11918                 :          0 :         PMD_DRV_LOG(INFO, sc, "pcie_bus=%d, pcie_device=%d",
   11919                 :            :                         sc->pcie_bus, sc->pcie_device);
   11920                 :          0 :         PMD_DRV_LOG(INFO, sc, "bar0.addr=%p, bar1.addr=%p",
   11921                 :            :                         sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
   11922                 :          0 :         PMD_DRV_LOG(INFO, sc, "port=%d, path=%d, vnic=%d, func=%d",
   11923                 :            :                         PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
   11924                 :          0 : }

Generated by: LCOV version 1.14