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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2020 Marvell Semiconductor Inc.
       3                 :            :  * All rights reserved.
       4                 :            :  * www.marvell.com
       5                 :            :  */
       6                 :            : 
       7                 :            : #include <assert.h>
       8                 :            : #include <rte_common.h>
       9                 :            : #include "base/bcm_osal.h"
      10                 :            : #include "base/ecore.h"
      11                 :            : #include "base/ecore_cxt.h"
      12                 :            : #include "base/ecore_hsi_common.h"
      13                 :            : #include "base/ecore_hw.h"
      14                 :            : #include "base/ecore_mcp.h"
      15                 :            : #include "base/reg_addr.h"
      16                 :            : #include "qede_debug.h"
      17                 :            : 
      18                 :            : /* Memory groups enum */
      19                 :            : enum mem_groups {
      20                 :            :         MEM_GROUP_PXP_MEM,
      21                 :            :         MEM_GROUP_DMAE_MEM,
      22                 :            :         MEM_GROUP_CM_MEM,
      23                 :            :         MEM_GROUP_QM_MEM,
      24                 :            :         MEM_GROUP_DORQ_MEM,
      25                 :            :         MEM_GROUP_BRB_RAM,
      26                 :            :         MEM_GROUP_BRB_MEM,
      27                 :            :         MEM_GROUP_PRS_MEM,
      28                 :            :         MEM_GROUP_SDM_MEM,
      29                 :            :         MEM_GROUP_PBUF,
      30                 :            :         MEM_GROUP_IOR,
      31                 :            :         MEM_GROUP_RAM,
      32                 :            :         MEM_GROUP_BTB_RAM,
      33                 :            :         MEM_GROUP_RDIF_CTX,
      34                 :            :         MEM_GROUP_TDIF_CTX,
      35                 :            :         MEM_GROUP_CFC_MEM,
      36                 :            :         MEM_GROUP_CONN_CFC_MEM,
      37                 :            :         MEM_GROUP_CAU_PI,
      38                 :            :         MEM_GROUP_CAU_MEM,
      39                 :            :         MEM_GROUP_CAU_MEM_EXT,
      40                 :            :         MEM_GROUP_PXP_ILT,
      41                 :            :         MEM_GROUP_MULD_MEM,
      42                 :            :         MEM_GROUP_BTB_MEM,
      43                 :            :         MEM_GROUP_IGU_MEM,
      44                 :            :         MEM_GROUP_IGU_MSIX,
      45                 :            :         MEM_GROUP_CAU_SB,
      46                 :            :         MEM_GROUP_BMB_RAM,
      47                 :            :         MEM_GROUP_BMB_MEM,
      48                 :            :         MEM_GROUP_TM_MEM,
      49                 :            :         MEM_GROUP_TASK_CFC_MEM,
      50                 :            :         MEM_GROUPS_NUM
      51                 :            : };
      52                 :            : 
      53                 :            : /* Memory groups names */
      54                 :            : static const char * const s_mem_group_names[] = {
      55                 :            :         "PXP_MEM",
      56                 :            :         "DMAE_MEM",
      57                 :            :         "CM_MEM",
      58                 :            :         "QM_MEM",
      59                 :            :         "DORQ_MEM",
      60                 :            :         "BRB_RAM",
      61                 :            :         "BRB_MEM",
      62                 :            :         "PRS_MEM",
      63                 :            :         "SDM_MEM",
      64                 :            :         "PBUF",
      65                 :            :         "IOR",
      66                 :            :         "RAM",
      67                 :            :         "BTB_RAM",
      68                 :            :         "RDIF_CTX",
      69                 :            :         "TDIF_CTX",
      70                 :            :         "CFC_MEM",
      71                 :            :         "CONN_CFC_MEM",
      72                 :            :         "CAU_PI",
      73                 :            :         "CAU_MEM",
      74                 :            :         "CAU_MEM_EXT",
      75                 :            :         "PXP_ILT",
      76                 :            :         "MULD_MEM",
      77                 :            :         "BTB_MEM",
      78                 :            :         "IGU_MEM",
      79                 :            :         "IGU_MSIX",
      80                 :            :         "CAU_SB",
      81                 :            :         "BMB_RAM",
      82                 :            :         "BMB_MEM",
      83                 :            :         "TM_MEM",
      84                 :            :         "TASK_CFC_MEM",
      85                 :            : };
      86                 :            : static_assert(RTE_DIM(s_mem_group_names) == MEM_GROUPS_NUM, "memory group string mismatch");
      87                 :            : 
      88                 :            : /* Idle check conditions */
      89                 :            : 
      90                 :          0 : static u32 cond5(const u32 *r, const u32 *imm)
      91                 :            : {
      92   [ #  #  #  # ]:          0 :         return ((r[0] & imm[0]) != imm[1]) && ((r[1] & imm[2]) != imm[3]);
      93                 :            : }
      94                 :            : 
      95                 :          0 : static u32 cond7(const u32 *r, const u32 *imm)
      96                 :            : {
      97                 :          0 :         return ((r[0] >> imm[0]) & imm[1]) != imm[2];
      98                 :            : }
      99                 :            : 
     100                 :          0 : static u32 cond6(const u32 *r, const u32 *imm)
     101                 :            : {
     102                 :          0 :         return (r[0] & imm[0]) != imm[1];
     103                 :            : }
     104                 :            : 
     105                 :          0 : static u32 cond9(const u32 *r, const u32 *imm)
     106                 :            : {
     107                 :          0 :         return ((r[0] & imm[0]) >> imm[1]) !=
     108                 :          0 :                 (((r[0] & imm[2]) >> imm[3]) | ((r[1] & imm[4]) << imm[5]));
     109                 :            : }
     110                 :            : 
     111                 :          0 : static u32 cond10(const u32 *r, const u32 *imm)
     112                 :            : {
     113                 :          0 :         return ((r[0] & imm[0]) >> imm[1]) != (r[0] & imm[2]);
     114                 :            : }
     115                 :            : 
     116                 :          0 : static u32 cond4(const u32 *r, const u32 *imm)
     117                 :            : {
     118                 :          0 :         return (r[0] & ~imm[0]) != imm[1];
     119                 :            : }
     120                 :            : 
     121                 :          0 : static u32 cond0(const u32 *r, const u32 *imm)
     122                 :            : {
     123                 :          0 :         return (r[0] & ~r[1]) != imm[0];
     124                 :            : }
     125                 :            : 
     126                 :          0 : static u32 cond1(const u32 *r, const u32 *imm)
     127                 :            : {
     128                 :          0 :         return r[0] != imm[0];
     129                 :            : }
     130                 :            : 
     131                 :          0 : static u32 cond11(const u32 *r, const u32 *imm)
     132                 :            : {
     133   [ #  #  #  # ]:          0 :         return r[0] != r[1] && r[2] == imm[0];
     134                 :            : }
     135                 :            : 
     136                 :          0 : static u32 cond12(const u32 *r, const u32 *imm)
     137                 :            : {
     138   [ #  #  #  # ]:          0 :         return r[0] != r[1] && r[2] > imm[0];
     139                 :            : }
     140                 :            : 
     141                 :          0 : static u32 cond3(const u32 *r, const __rte_unused u32 *imm)
     142                 :            : {
     143                 :          0 :         return r[0] != r[1];
     144                 :            : }
     145                 :            : 
     146                 :          0 : static u32 cond13(const u32 *r, const u32 *imm)
     147                 :            : {
     148                 :          0 :         return r[0] & imm[0];
     149                 :            : }
     150                 :            : 
     151                 :          0 : static u32 cond8(const u32 *r, const u32 *imm)
     152                 :            : {
     153                 :          0 :         return r[0] < (r[1] - imm[0]);
     154                 :            : }
     155                 :            : 
     156                 :          0 : static u32 cond2(const u32 *r, const u32 *imm)
     157                 :            : {
     158                 :          0 :         return r[0] > imm[0];
     159                 :            : }
     160                 :            : 
     161                 :            : /* Array of Idle Check conditions */
     162                 :            : static u32(*cond_arr[]) (const u32 *r, const u32 *imm) = {
     163                 :            :         cond0,
     164                 :            :         cond1,
     165                 :            :         cond2,
     166                 :            :         cond3,
     167                 :            :         cond4,
     168                 :            :         cond5,
     169                 :            :         cond6,
     170                 :            :         cond7,
     171                 :            :         cond8,
     172                 :            :         cond9,
     173                 :            :         cond10,
     174                 :            :         cond11,
     175                 :            :         cond12,
     176                 :            :         cond13,
     177                 :            : };
     178                 :            : 
     179                 :            : #define NUM_PHYS_BLOCKS 84
     180                 :            : 
     181                 :            : #define NUM_DBG_RESET_REGS 8
     182                 :            : 
     183                 :            : /******************************* Data Types **********************************/
     184                 :            : 
     185                 :            : enum hw_types {
     186                 :            :         HW_TYPE_ASIC,
     187                 :            :         PLATFORM_RESERVED,
     188                 :            :         PLATFORM_RESERVED2,
     189                 :            :         PLATFORM_RESERVED3,
     190                 :            :         PLATFORM_RESERVED4,
     191                 :            :         MAX_HW_TYPES
     192                 :            : };
     193                 :            : 
     194                 :            : /* CM context types */
     195                 :            : enum cm_ctx_types {
     196                 :            :         CM_CTX_CONN_AG,
     197                 :            :         CM_CTX_CONN_ST,
     198                 :            :         CM_CTX_TASK_AG,
     199                 :            :         CM_CTX_TASK_ST,
     200                 :            :         NUM_CM_CTX_TYPES
     201                 :            : };
     202                 :            : 
     203                 :            : /* Debug bus frame modes */
     204                 :            : enum dbg_bus_frame_modes {
     205                 :            :         DBG_BUS_FRAME_MODE_4ST = 0,     /* 4 Storm dwords (no HW) */
     206                 :            :         DBG_BUS_FRAME_MODE_2ST_2HW = 1, /* 2 Storm dwords, 2 HW dwords */
     207                 :            :         DBG_BUS_FRAME_MODE_1ST_3HW = 2, /* 1 Storm dwords, 3 HW dwords */
     208                 :            :         DBG_BUS_FRAME_MODE_4HW = 3,     /* 4 HW dwords (no Storms) */
     209                 :            :         DBG_BUS_FRAME_MODE_8HW = 4,     /* 8 HW dwords (no Storms) */
     210                 :            :         DBG_BUS_NUM_FRAME_MODES
     211                 :            : };
     212                 :            : 
     213                 :            : /* Chip constant definitions */
     214                 :            : struct chip_defs {
     215                 :            :         const char *name;
     216                 :            :         u32 num_ilt_pages;
     217                 :            : };
     218                 :            : 
     219                 :            : /* HW type constant definitions */
     220                 :            : struct hw_type_defs {
     221                 :            :         const char *name;
     222                 :            :         u32 delay_factor;
     223                 :            :         u32 dmae_thresh;
     224                 :            :         u32 log_thresh;
     225                 :            : };
     226                 :            : 
     227                 :            : /* RBC reset definitions */
     228                 :            : struct rbc_reset_defs {
     229                 :            :         u32 reset_reg_addr;
     230                 :            :         u32 reset_val[MAX_CHIP_IDS];
     231                 :            : };
     232                 :            : 
     233                 :            : /* Storm constant definitions.
     234                 :            :  * Addresses are in bytes, sizes are in quad-regs.
     235                 :            :  */
     236                 :            : struct storm_defs {
     237                 :            :         char letter;
     238                 :            :         enum block_id sem_block_id;
     239                 :            :         enum dbg_bus_clients dbg_client_id[MAX_CHIP_IDS];
     240                 :            :         bool has_vfc;
     241                 :            :         u32 sem_fast_mem_addr;
     242                 :            :         u32 sem_frame_mode_addr;
     243                 :            :         u32 sem_slow_enable_addr;
     244                 :            :         u32 sem_slow_mode_addr;
     245                 :            :         u32 sem_slow_mode1_conf_addr;
     246                 :            :         u32 sem_sync_dbg_empty_addr;
     247                 :            :         u32 sem_gpre_vect_addr;
     248                 :            :         u32 cm_ctx_wr_addr;
     249                 :            :         u32 cm_ctx_rd_addr[NUM_CM_CTX_TYPES];
     250                 :            :         u32 cm_ctx_lid_sizes[MAX_CHIP_IDS][NUM_CM_CTX_TYPES];
     251                 :            : };
     252                 :            : 
     253                 :            : /* Debug Bus Constraint operation constant definitions */
     254                 :            : struct dbg_bus_constraint_op_defs {
     255                 :            :         u8 hw_op_val;
     256                 :            :         bool is_cyclic;
     257                 :            : };
     258                 :            : 
     259                 :            : /* Storm Mode definitions */
     260                 :            : struct storm_mode_defs {
     261                 :            :         const char *name;
     262                 :            :         bool is_fast_dbg;
     263                 :            :         u8 id_in_hw;
     264                 :            :         u32 src_disable_reg_addr;
     265                 :            :         u32 src_enable_val;
     266                 :            :         bool exists[MAX_CHIP_IDS];
     267                 :            : };
     268                 :            : 
     269                 :            : struct grc_param_defs {
     270                 :            :         u32 default_val[MAX_CHIP_IDS];
     271                 :            :         u32 min;
     272                 :            :         u32 max;
     273                 :            :         bool is_preset;
     274                 :            :         bool is_persistent;
     275                 :            :         u32 exclude_all_preset_val;
     276                 :            :         u32 crash_preset_val[MAX_CHIP_IDS];
     277                 :            : };
     278                 :            : 
     279                 :            : /* Address is in 128b units. Width is in bits. */
     280                 :            : struct rss_mem_defs {
     281                 :            :         const char *mem_name;
     282                 :            :         const char *type_name;
     283                 :            :         u32 addr;
     284                 :            :         u32 entry_width;
     285                 :            :         u32 num_entries[MAX_CHIP_IDS];
     286                 :            : };
     287                 :            : 
     288                 :            : struct vfc_ram_defs {
     289                 :            :         const char *mem_name;
     290                 :            :         const char *type_name;
     291                 :            :         u32 base_row;
     292                 :            :         u32 num_rows;
     293                 :            : };
     294                 :            : 
     295                 :            : struct big_ram_defs {
     296                 :            :         const char *instance_name;
     297                 :            :         enum mem_groups mem_group_id;
     298                 :            :         enum mem_groups ram_mem_group_id;
     299                 :            :         enum dbg_grc_params grc_param;
     300                 :            :         u32 addr_reg_addr;
     301                 :            :         u32 data_reg_addr;
     302                 :            :         u32 is_256b_reg_addr;
     303                 :            :         u32 is_256b_bit_offset[MAX_CHIP_IDS];
     304                 :            :         u32 ram_size[MAX_CHIP_IDS]; /* In dwords */
     305                 :            : };
     306                 :            : 
     307                 :            : struct phy_defs {
     308                 :            :         const char *phy_name;
     309                 :            : 
     310                 :            :         /* PHY base GRC address */
     311                 :            :         u32 base_addr;
     312                 :            : 
     313                 :            :         /* Relative address of indirect TBUS address register (bits 0..7) */
     314                 :            :         u32 tbus_addr_lo_addr;
     315                 :            : 
     316                 :            :         /* Relative address of indirect TBUS address register (bits 8..10) */
     317                 :            :         u32 tbus_addr_hi_addr;
     318                 :            : 
     319                 :            :         /* Relative address of indirect TBUS data register (bits 0..7) */
     320                 :            :         u32 tbus_data_lo_addr;
     321                 :            : 
     322                 :            :         /* Relative address of indirect TBUS data register (bits 8..11) */
     323                 :            :         u32 tbus_data_hi_addr;
     324                 :            : };
     325                 :            : 
     326                 :            : /* Split type definitions */
     327                 :            : struct split_type_defs {
     328                 :            :         const char *name;
     329                 :            : };
     330                 :            : 
     331                 :            : /******************************** Constants **********************************/
     332                 :            : 
     333                 :            : #define BYTES_IN_DWORD                  sizeof(u32)
     334                 :            : /* In the macros below, size and offset are specified in bits */
     335                 :            : #define CEIL_DWORDS(size)               DIV_ROUND_UP(size, 32)
     336                 :            : #define FIELD_BIT_OFFSET(type, field)   type ## _ ## field ## _ ## OFFSET
     337                 :            : #define FIELD_BIT_SIZE(type, field)     type ## _ ## field ## _ ## SIZE
     338                 :            : #define FIELD_DWORD_OFFSET(type, field) \
     339                 :            :          (int)(FIELD_BIT_OFFSET(type, field) / 32)
     340                 :            : #define FIELD_DWORD_SHIFT(type, field)  (FIELD_BIT_OFFSET(type, field) % 32)
     341                 :            : #define FIELD_BIT_MASK(type, field) \
     342                 :            :         (((1 << FIELD_BIT_SIZE(type, field)) - 1) << \
     343                 :            :          FIELD_DWORD_SHIFT(type, field))
     344                 :            : 
     345                 :            : #define SET_VAR_FIELD(var, type, field, val) \
     346                 :            :         do { \
     347                 :            :                 var[FIELD_DWORD_OFFSET(type, field)] &=     \
     348                 :            :                 (~FIELD_BIT_MASK(type, field)); \
     349                 :            :                 var[FIELD_DWORD_OFFSET(type, field)] |= \
     350                 :            :                 (val) << FIELD_DWORD_SHIFT(type, field); \
     351                 :            :         } while (0)
     352                 :            : 
     353                 :            : #define ARR_REG_WR(dev, ptt, addr, arr, arr_size) \
     354                 :            :         do { \
     355                 :            :                 for (i = 0; i < (arr_size); i++) \
     356                 :            :                         ecore_wr(dev, ptt, addr,        (arr)[i]); \
     357                 :            :         } while (0)
     358                 :            : 
     359                 :            : #define DWORDS_TO_BYTES(dwords)         ((dwords) * BYTES_IN_DWORD)
     360                 :            : #define BYTES_TO_DWORDS(bytes)          ((bytes) / BYTES_IN_DWORD)
     361                 :            : 
     362                 :            : /* extra lines include a signature line + optional latency events line */
     363                 :            : #define NUM_EXTRA_DBG_LINES(block) \
     364                 :            :         (GET_FIELD((block)->flags, DBG_BLOCK_CHIP_HAS_LATENCY_EVENTS) ? 2 : 1)
     365                 :            : #define NUM_DBG_LINES(block) \
     366                 :            :         ((block)->num_of_dbg_bus_lines + NUM_EXTRA_DBG_LINES(block))
     367                 :            : 
     368                 :            : #define USE_DMAE                        true
     369                 :            : #define PROTECT_WIDE_BUS                true
     370                 :            : 
     371                 :            : #define RAM_LINES_TO_DWORDS(lines)      ((lines) * 2)
     372                 :            : #define RAM_LINES_TO_BYTES(lines) \
     373                 :            :         DWORDS_TO_BYTES(RAM_LINES_TO_DWORDS(lines))
     374                 :            : 
     375                 :            : #define REG_DUMP_LEN_SHIFT              24
     376                 :            : #define MEM_DUMP_ENTRY_SIZE_DWORDS \
     377                 :            :         BYTES_TO_DWORDS(sizeof(struct dbg_dump_mem))
     378                 :            : 
     379                 :            : #define IDLE_CHK_RULE_SIZE_DWORDS \
     380                 :            :         BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_rule))
     381                 :            : 
     382                 :            : #define IDLE_CHK_RESULT_HDR_DWORDS \
     383                 :            :         BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_hdr))
     384                 :            : 
     385                 :            : #define IDLE_CHK_RESULT_REG_HDR_DWORDS \
     386                 :            :         BYTES_TO_DWORDS(sizeof(struct dbg_idle_chk_result_reg_hdr))
     387                 :            : 
     388                 :            : #define PAGE_MEM_DESC_SIZE_DWORDS \
     389                 :            :         BYTES_TO_DWORDS(sizeof(struct phys_mem_desc))
     390                 :            : 
     391                 :            : #define IDLE_CHK_MAX_ENTRIES_SIZE       32
     392                 :            : 
     393                 :            : /* The sizes and offsets below are specified in bits */
     394                 :            : #define VFC_CAM_CMD_STRUCT_SIZE         64
     395                 :            : #define VFC_CAM_CMD_ROW_OFFSET          48
     396                 :            : #define VFC_CAM_CMD_ROW_SIZE            9
     397                 :            : #define VFC_CAM_ADDR_STRUCT_SIZE        16
     398                 :            : #define VFC_CAM_ADDR_OP_OFFSET          0
     399                 :            : #define VFC_CAM_ADDR_OP_SIZE            4
     400                 :            : #define VFC_CAM_RESP_STRUCT_SIZE        256
     401                 :            : #define VFC_RAM_ADDR_STRUCT_SIZE        16
     402                 :            : #define VFC_RAM_ADDR_OP_OFFSET          0
     403                 :            : #define VFC_RAM_ADDR_OP_SIZE            2
     404                 :            : #define VFC_RAM_ADDR_ROW_OFFSET         2
     405                 :            : #define VFC_RAM_ADDR_ROW_SIZE           10
     406                 :            : #define VFC_RAM_RESP_STRUCT_SIZE        256
     407                 :            : 
     408                 :            : #define VFC_CAM_CMD_DWORDS              CEIL_DWORDS(VFC_CAM_CMD_STRUCT_SIZE)
     409                 :            : #define VFC_CAM_ADDR_DWORDS             CEIL_DWORDS(VFC_CAM_ADDR_STRUCT_SIZE)
     410                 :            : #define VFC_CAM_RESP_DWORDS             CEIL_DWORDS(VFC_CAM_RESP_STRUCT_SIZE)
     411                 :            : #define VFC_RAM_CMD_DWORDS              VFC_CAM_CMD_DWORDS
     412                 :            : #define VFC_RAM_ADDR_DWORDS             CEIL_DWORDS(VFC_RAM_ADDR_STRUCT_SIZE)
     413                 :            : #define VFC_RAM_RESP_DWORDS             CEIL_DWORDS(VFC_RAM_RESP_STRUCT_SIZE)
     414                 :            : 
     415                 :            : #define NUM_VFC_RAM_TYPES               4
     416                 :            : 
     417                 :            : #define VFC_CAM_NUM_ROWS                512
     418                 :            : 
     419                 :            : #define VFC_OPCODE_CAM_RD               14
     420                 :            : #define VFC_OPCODE_RAM_RD               0
     421                 :            : 
     422                 :            : #define NUM_RSS_MEM_TYPES               5
     423                 :            : 
     424                 :            : #define NUM_BIG_RAM_TYPES               3
     425                 :            : #define BIG_RAM_NAME_LEN                3
     426                 :            : 
     427                 :            : #define NUM_PHY_TBUS_ADDRESSES          2048
     428                 :            : #define PHY_DUMP_SIZE_DWORDS            (NUM_PHY_TBUS_ADDRESSES / 2)
     429                 :            : 
     430                 :            : #define RESET_REG_UNRESET_OFFSET        4
     431                 :            : 
     432                 :            : #define STALL_DELAY_MS                  500
     433                 :            : 
     434                 :            : #define STATIC_DEBUG_LINE_DWORDS        9
     435                 :            : 
     436                 :            : #define NUM_COMMON_GLOBAL_PARAMS        11
     437                 :            : 
     438                 :            : #define MAX_RECURSION_DEPTH             10
     439                 :            : 
     440                 :            : #define FW_IMG_MAIN                     1
     441                 :            : 
     442                 :            : #define REG_FIFO_ELEMENT_DWORDS         2
     443                 :            : #define REG_FIFO_DEPTH_ELEMENTS         32
     444                 :            : #define REG_FIFO_DEPTH_DWORDS \
     445                 :            :         (REG_FIFO_ELEMENT_DWORDS * REG_FIFO_DEPTH_ELEMENTS)
     446                 :            : 
     447                 :            : #define IGU_FIFO_ELEMENT_DWORDS         4
     448                 :            : #define IGU_FIFO_DEPTH_ELEMENTS         64
     449                 :            : #define IGU_FIFO_DEPTH_DWORDS \
     450                 :            :         (IGU_FIFO_ELEMENT_DWORDS * IGU_FIFO_DEPTH_ELEMENTS)
     451                 :            : 
     452                 :            : #define PROTECTION_OVERRIDE_ELEMENT_DWORDS      2
     453                 :            : #define PROTECTION_OVERRIDE_DEPTH_ELEMENTS      20
     454                 :            : #define PROTECTION_OVERRIDE_DEPTH_DWORDS \
     455                 :            :         (PROTECTION_OVERRIDE_DEPTH_ELEMENTS * \
     456                 :            :          PROTECTION_OVERRIDE_ELEMENT_DWORDS)
     457                 :            : 
     458                 :            : #define MCP_SPAD_TRACE_OFFSIZE_ADDR \
     459                 :            :         (MCP_REG_SCRATCH + \
     460                 :            :          offsetof(struct static_init, sections[SPAD_SECTION_TRACE]))
     461                 :            : 
     462                 :            : #define MAX_SW_PLTAFORM_STR_SIZE        64
     463                 :            : 
     464                 :            : #define EMPTY_FW_VERSION_STR            "???_???_???_???"
     465                 :            : #define EMPTY_FW_IMAGE_STR              "???????????????"
     466                 :            : 
     467                 :            : /***************************** Constant Arrays *******************************/
     468                 :            : 
     469                 :            : /* Chip constant definitions array */
     470                 :            : static struct chip_defs s_chip_defs[MAX_CHIP_IDS] = {
     471                 :            :         {"bb", PSWRQ2_REG_ILT_MEMORY_SIZE_BB / 2},
     472                 :            :         {"ah", PSWRQ2_REG_ILT_MEMORY_SIZE_K2 / 2}
     473                 :            : };
     474                 :            : 
     475                 :            : /* Storm constant definitions array */
     476                 :            : static struct storm_defs s_storm_defs[] = {
     477                 :            :         /* Tstorm */
     478                 :            :         {'T', BLOCK_TSEM,
     479                 :            :                 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCT},
     480                 :            :                 true,
     481                 :            :                 TSEM_REG_FAST_MEMORY,
     482                 :            :                 TSEM_REG_DBG_FRAME_MODE, TSEM_REG_SLOW_DBG_ACTIVE,
     483                 :            :                 TSEM_REG_SLOW_DBG_MODE, TSEM_REG_DBG_MODE1_CFG,
     484                 :            :                 TSEM_REG_SYNC_DBG_EMPTY, TSEM_REG_DBG_GPRE_VECT,
     485                 :            :                 TCM_REG_CTX_RBC_ACCS,
     486                 :            :                 {TCM_REG_AGG_CON_CTX, TCM_REG_SM_CON_CTX, TCM_REG_AGG_TASK_CTX,
     487                 :            :                  TCM_REG_SM_TASK_CTX},
     488                 :            :                 {{4, 16, 2, 4}, {4, 16, 2, 4} } /* {bb} {k2} */
     489                 :            :         },
     490                 :            : 
     491                 :            :         /* Mstorm */
     492                 :            :         {'M', BLOCK_MSEM,
     493                 :            :                 {DBG_BUS_CLIENT_RBCT, DBG_BUS_CLIENT_RBCM},
     494                 :            :                 false,
     495                 :            :                 MSEM_REG_FAST_MEMORY,
     496                 :            :                 MSEM_REG_DBG_FRAME_MODE,
     497                 :            :                 MSEM_REG_SLOW_DBG_ACTIVE,
     498                 :            :                 MSEM_REG_SLOW_DBG_MODE,
     499                 :            :                 MSEM_REG_DBG_MODE1_CFG,
     500                 :            :                 MSEM_REG_SYNC_DBG_EMPTY,
     501                 :            :                 MSEM_REG_DBG_GPRE_VECT,
     502                 :            :                 MCM_REG_CTX_RBC_ACCS,
     503                 :            :                 {MCM_REG_AGG_CON_CTX, MCM_REG_SM_CON_CTX, MCM_REG_AGG_TASK_CTX,
     504                 :            :                  MCM_REG_SM_TASK_CTX },
     505                 :            :                 {{1, 10, 2, 7}, {1, 10, 2, 7} } /* {bb} {k2}*/
     506                 :            :         },
     507                 :            : 
     508                 :            :         /* Ustorm */
     509                 :            :         {'U', BLOCK_USEM,
     510                 :            :                 {DBG_BUS_CLIENT_RBCU, DBG_BUS_CLIENT_RBCU},
     511                 :            :                 false,
     512                 :            :                 USEM_REG_FAST_MEMORY,
     513                 :            :                 USEM_REG_DBG_FRAME_MODE,
     514                 :            :                 USEM_REG_SLOW_DBG_ACTIVE,
     515                 :            :                 USEM_REG_SLOW_DBG_MODE,
     516                 :            :                 USEM_REG_DBG_MODE1_CFG,
     517                 :            :                 USEM_REG_SYNC_DBG_EMPTY,
     518                 :            :                 USEM_REG_DBG_GPRE_VECT,
     519                 :            :                 UCM_REG_CTX_RBC_ACCS,
     520                 :            :                 {UCM_REG_AGG_CON_CTX, UCM_REG_SM_CON_CTX, UCM_REG_AGG_TASK_CTX,
     521                 :            :                  UCM_REG_SM_TASK_CTX},
     522                 :            :                 {{2, 13, 3, 3}, {2, 13, 3, 3} } /* {bb} {k2} */
     523                 :            :         },
     524                 :            : 
     525                 :            :         /* Xstorm */
     526                 :            :         {'X', BLOCK_XSEM,
     527                 :            :                 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCX},
     528                 :            :                 false,
     529                 :            :                 XSEM_REG_FAST_MEMORY,
     530                 :            :                 XSEM_REG_DBG_FRAME_MODE,
     531                 :            :                 XSEM_REG_SLOW_DBG_ACTIVE,
     532                 :            :                 XSEM_REG_SLOW_DBG_MODE,
     533                 :            :                 XSEM_REG_DBG_MODE1_CFG,
     534                 :            :                 XSEM_REG_SYNC_DBG_EMPTY,
     535                 :            :                 XSEM_REG_DBG_GPRE_VECT,
     536                 :            :                 XCM_REG_CTX_RBC_ACCS,
     537                 :            :                 {XCM_REG_AGG_CON_CTX, XCM_REG_SM_CON_CTX, 0, 0},
     538                 :            :                 {{9, 15, 0, 0}, {9, 15, 0, 0} } /* {bb} {k2} */
     539                 :            :         },
     540                 :            : 
     541                 :            :         /* Ystorm */
     542                 :            :         {'Y', BLOCK_YSEM,
     543                 :            :                 {DBG_BUS_CLIENT_RBCX, DBG_BUS_CLIENT_RBCY},
     544                 :            :                 false,
     545                 :            :                 YSEM_REG_FAST_MEMORY,
     546                 :            :                 YSEM_REG_DBG_FRAME_MODE,
     547                 :            :                 YSEM_REG_SLOW_DBG_ACTIVE,
     548                 :            :                 YSEM_REG_SLOW_DBG_MODE,
     549                 :            :                 YSEM_REG_DBG_MODE1_CFG,
     550                 :            :                 YSEM_REG_SYNC_DBG_EMPTY,
     551                 :            :                 YSEM_REG_DBG_GPRE_VECT,
     552                 :            :                 YCM_REG_CTX_RBC_ACCS,
     553                 :            :                 {YCM_REG_AGG_CON_CTX, YCM_REG_SM_CON_CTX, YCM_REG_AGG_TASK_CTX,
     554                 :            :                  YCM_REG_SM_TASK_CTX},
     555                 :            :                 {{2, 3, 2, 12}, {2, 3, 2, 12} } /* {bb} {k2} */
     556                 :            :         },
     557                 :            : 
     558                 :            :         /* Pstorm */
     559                 :            :         {'P', BLOCK_PSEM,
     560                 :            :                 {DBG_BUS_CLIENT_RBCS, DBG_BUS_CLIENT_RBCS},
     561                 :            :                 true,
     562                 :            :                 PSEM_REG_FAST_MEMORY,
     563                 :            :                 PSEM_REG_DBG_FRAME_MODE,
     564                 :            :                 PSEM_REG_SLOW_DBG_ACTIVE,
     565                 :            :                 PSEM_REG_SLOW_DBG_MODE,
     566                 :            :                 PSEM_REG_DBG_MODE1_CFG,
     567                 :            :                 PSEM_REG_SYNC_DBG_EMPTY,
     568                 :            :                 PSEM_REG_DBG_GPRE_VECT,
     569                 :            :                 PCM_REG_CTX_RBC_ACCS,
     570                 :            :                 {0, PCM_REG_SM_CON_CTX, 0, 0},
     571                 :            :                 {{0, 10, 0, 0}, {0, 10, 0, 0} } /* {bb} {k2} */
     572                 :            :         },
     573                 :            : };
     574                 :            : 
     575                 :            : static struct hw_type_defs s_hw_type_defs[] = {
     576                 :            :         /* HW_TYPE_ASIC */
     577                 :            :         {"asic", 1, 256, 32768},
     578                 :            :         {"reserved", 0, 0, 0},
     579                 :            :         {"reserved2", 0, 0, 0},
     580                 :            :         {"reserved3", 0, 0, 0}
     581                 :            : };
     582                 :            : 
     583                 :            : static struct grc_param_defs s_grc_param_defs[] = {
     584                 :            :         /* DBG_GRC_PARAM_DUMP_TSTORM */
     585                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     586                 :            : 
     587                 :            :         /* DBG_GRC_PARAM_DUMP_MSTORM */
     588                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     589                 :            : 
     590                 :            :         /* DBG_GRC_PARAM_DUMP_USTORM */
     591                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     592                 :            : 
     593                 :            :         /* DBG_GRC_PARAM_DUMP_XSTORM */
     594                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     595                 :            : 
     596                 :            :         /* DBG_GRC_PARAM_DUMP_YSTORM */
     597                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     598                 :            : 
     599                 :            :         /* DBG_GRC_PARAM_DUMP_PSTORM */
     600                 :            :         {{1, 1}, 0, 1, false, false, 1, {1, 1} },
     601                 :            : 
     602                 :            :         /* DBG_GRC_PARAM_DUMP_REGS */
     603                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     604                 :            : 
     605                 :            :         /* DBG_GRC_PARAM_DUMP_RAM */
     606                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     607                 :            : 
     608                 :            :         /* DBG_GRC_PARAM_DUMP_PBUF */
     609                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     610                 :            : 
     611                 :            :         /* DBG_GRC_PARAM_DUMP_IOR */
     612                 :            :         {{0, 0}, 0, 1, false, false, 0, {1, 1} },
     613                 :            : 
     614                 :            :         /* DBG_GRC_PARAM_DUMP_VFC */
     615                 :            :         {{0, 0}, 0, 1, false, false, 0, {1, 1} },
     616                 :            : 
     617                 :            :         /* DBG_GRC_PARAM_DUMP_CM_CTX */
     618                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     619                 :            : 
     620                 :            :         /* DBG_GRC_PARAM_DUMP_ILT */
     621                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     622                 :            : 
     623                 :            :         /* DBG_GRC_PARAM_DUMP_RSS */
     624                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     625                 :            : 
     626                 :            :         /* DBG_GRC_PARAM_DUMP_CAU */
     627                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     628                 :            : 
     629                 :            :         /* DBG_GRC_PARAM_DUMP_QM */
     630                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     631                 :            : 
     632                 :            :         /* DBG_GRC_PARAM_DUMP_MCP */
     633                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     634                 :            : 
     635                 :            :         /* DBG_GRC_PARAM_DUMP_DORQ */
     636                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     637                 :            : 
     638                 :            :         /* DBG_GRC_PARAM_DUMP_CFC */
     639                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     640                 :            : 
     641                 :            :         /* DBG_GRC_PARAM_DUMP_IGU */
     642                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     643                 :            : 
     644                 :            :         /* DBG_GRC_PARAM_DUMP_BRB */
     645                 :            :         {{0, 0}, 0, 1, false, false, 0, {1, 1} },
     646                 :            : 
     647                 :            :         /* DBG_GRC_PARAM_DUMP_BTB */
     648                 :            :         {{0, 0}, 0, 1, false, false, 0, {1, 1} },
     649                 :            : 
     650                 :            :         /* DBG_GRC_PARAM_DUMP_BMB */
     651                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     652                 :            : 
     653                 :            :         /* DBG_GRC_PARAM_RESERVED1 */
     654                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     655                 :            : 
     656                 :            :         /* DBG_GRC_PARAM_DUMP_MULD */
     657                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     658                 :            : 
     659                 :            :         /* DBG_GRC_PARAM_DUMP_PRS */
     660                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     661                 :            : 
     662                 :            :         /* DBG_GRC_PARAM_DUMP_DMAE */
     663                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     664                 :            : 
     665                 :            :         /* DBG_GRC_PARAM_DUMP_TM */
     666                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     667                 :            : 
     668                 :            :         /* DBG_GRC_PARAM_DUMP_SDM */
     669                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     670                 :            : 
     671                 :            :         /* DBG_GRC_PARAM_DUMP_DIF */
     672                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     673                 :            : 
     674                 :            :         /* DBG_GRC_PARAM_DUMP_STATIC */
     675                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     676                 :            : 
     677                 :            :         /* DBG_GRC_PARAM_UNSTALL */
     678                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     679                 :            : 
     680                 :            :         /* DBG_GRC_PARAM_RESERVED2 */
     681                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     682                 :            : 
     683                 :            :         /* DBG_GRC_PARAM_MCP_TRACE_META_SIZE */
     684                 :            :         {{0, 0}, 1, 0xffffffff, false, true, 0, {0, 0} },
     685                 :            : 
     686                 :            :         /* DBG_GRC_PARAM_EXCLUDE_ALL */
     687                 :            :         {{0, 0}, 0, 1, true, false, 0, {0, 0} },
     688                 :            : 
     689                 :            :         /* DBG_GRC_PARAM_CRASH */
     690                 :            :         {{0, 0}, 0, 1, true, false, 0, {0, 0} },
     691                 :            : 
     692                 :            :         /* DBG_GRC_PARAM_PARITY_SAFE */
     693                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     694                 :            : 
     695                 :            :         /* DBG_GRC_PARAM_DUMP_CM */
     696                 :            :         {{1, 1}, 0, 1, false, false, 0, {1, 1} },
     697                 :            : 
     698                 :            :         /* DBG_GRC_PARAM_DUMP_PHY */
     699                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     700                 :            : 
     701                 :            :         /* DBG_GRC_PARAM_NO_MCP */
     702                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     703                 :            : 
     704                 :            :         /* DBG_GRC_PARAM_NO_FW_VER */
     705                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     706                 :            : 
     707                 :            :         /* DBG_GRC_PARAM_RESERVED3 */
     708                 :            :         {{0, 0}, 0, 1, false, false, 0, {0, 0} },
     709                 :            : 
     710                 :            :         /* DBG_GRC_PARAM_DUMP_MCP_HW_DUMP */
     711                 :            :         {{0, 1}, 0, 1, false, false, 0, {0, 1} },
     712                 :            : 
     713                 :            :         /* DBG_GRC_PARAM_DUMP_ILT_CDUC */
     714                 :            :         {{1, 1}, 0, 1, false, false, 0, {0, 0} },
     715                 :            : 
     716                 :            :         /* DBG_GRC_PARAM_DUMP_ILT_CDUT */
     717                 :            :         {{1, 1}, 0, 1, false, false, 0, {0, 0} },
     718                 :            : 
     719                 :            :         /* DBG_GRC_PARAM_DUMP_CAU_EXT */
     720                 :            :         {{0, 0}, 0, 1, false, false, 0, {1, 1} }
     721                 :            : };
     722                 :            : 
     723                 :            : static struct rss_mem_defs s_rss_mem_defs[] = {
     724                 :            :         {"rss_mem_cid", "rss_cid", 0, 32,
     725                 :            :          {256, 320} },
     726                 :            : 
     727                 :            :         {"rss_mem_key_msb", "rss_key", 1024, 256,
     728                 :            :          {128, 208} },
     729                 :            : 
     730                 :            :         {"rss_mem_key_lsb", "rss_key", 2048, 64,
     731                 :            :          {128, 208} },
     732                 :            : 
     733                 :            :         {"rss_mem_info", "rss_info", 3072, 16,
     734                 :            :          {128, 208} },
     735                 :            : 
     736                 :            :         {"rss_mem_ind", "rss_ind", 4096, 16,
     737                 :            :          {16384, 26624} }
     738                 :            : };
     739                 :            : 
     740                 :            : static struct vfc_ram_defs s_vfc_ram_defs[] = {
     741                 :            :         {"vfc_ram_tt1", "vfc_ram", 0, 512},
     742                 :            :         {"vfc_ram_mtt2", "vfc_ram", 512, 128},
     743                 :            :         {"vfc_ram_stt2", "vfc_ram", 640, 32},
     744                 :            :         {"vfc_ram_ro_vect", "vfc_ram", 672, 32}
     745                 :            : };
     746                 :            : 
     747                 :            : static struct big_ram_defs s_big_ram_defs[] = {
     748                 :            :         {"BRB", MEM_GROUP_BRB_MEM, MEM_GROUP_BRB_RAM, DBG_GRC_PARAM_DUMP_BRB,
     749                 :            :          BRB_REG_BIG_RAM_ADDRESS, BRB_REG_BIG_RAM_DATA,
     750                 :            :          MISC_REG_BLOCK_256B_EN, {0, 0},
     751                 :            :          {153600, 180224} },
     752                 :            : 
     753                 :            :         {"BTB", MEM_GROUP_BTB_MEM, MEM_GROUP_BTB_RAM, DBG_GRC_PARAM_DUMP_BTB,
     754                 :            :          BTB_REG_BIG_RAM_ADDRESS, BTB_REG_BIG_RAM_DATA,
     755                 :            :          MISC_REG_BLOCK_256B_EN, {0, 1},
     756                 :            :          {92160, 117760} },
     757                 :            : 
     758                 :            :         {"BMB", MEM_GROUP_BMB_MEM, MEM_GROUP_BMB_RAM, DBG_GRC_PARAM_DUMP_BMB,
     759                 :            :          BMB_REG_BIG_RAM_ADDRESS, BMB_REG_BIG_RAM_DATA,
     760                 :            :          MISCS_REG_BLOCK_256B_EN, {0, 0},
     761                 :            :          {36864, 36864} }
     762                 :            : };
     763                 :            : 
     764                 :            : static struct rbc_reset_defs s_rbc_reset_defs[] = {
     765                 :            :         {MISCS_REG_RESET_PL_HV,
     766                 :            :          {0x0, 0x400} },
     767                 :            :         {MISC_REG_RESET_PL_PDA_VMAIN_1,
     768                 :            :          {0x4404040, 0x4404040} },
     769                 :            :         {MISC_REG_RESET_PL_PDA_VMAIN_2,
     770                 :            :          {0x7, 0x7c00007} },
     771                 :            :         {MISC_REG_RESET_PL_PDA_VAUX,
     772                 :            :          {0x2, 0x2} },
     773                 :            : };
     774                 :            : 
     775                 :            : static struct phy_defs s_phy_defs[] = {
     776                 :            :         {"nw_phy", NWS_REG_NWS_CMU_K2,
     777                 :            :          PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_7_0_K2,
     778                 :            :          PHY_NW_IP_REG_PHY0_TOP_TBUS_ADDR_15_8_K2,
     779                 :            :          PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_7_0_K2,
     780                 :            :          PHY_NW_IP_REG_PHY0_TOP_TBUS_DATA_11_8_K2},
     781                 :            :         {"sgmii_phy", MS_REG_MS_CMU_K2,
     782                 :            :          PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X132_K2,
     783                 :            :          PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X133_K2,
     784                 :            :          PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X130_K2,
     785                 :            :          PHY_SGMII_IP_REG_AHB_CMU_CSR_0_X131_K2},
     786                 :            :         {"pcie_phy0", PHY_PCIE_REG_PHY0_K2,
     787                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2,
     788                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2,
     789                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2,
     790                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2},
     791                 :            :         {"pcie_phy1", PHY_PCIE_REG_PHY1_K2,
     792                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X132_K2,
     793                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X133_K2,
     794                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X130_K2,
     795                 :            :          PHY_PCIE_IP_REG_AHB_CMU_CSR_0_X131_K2},
     796                 :            : };
     797                 :            : 
     798                 :            : static struct split_type_defs s_split_type_defs[] = {
     799                 :            :         /* SPLIT_TYPE_NONE */
     800                 :            :         {"eng"},
     801                 :            : 
     802                 :            :         /* SPLIT_TYPE_PORT */
     803                 :            :         {"port"},
     804                 :            : 
     805                 :            :         /* SPLIT_TYPE_PF */
     806                 :            :         {"pf"},
     807                 :            : 
     808                 :            :         /* SPLIT_TYPE_PORT_PF */
     809                 :            :         {"port"},
     810                 :            : 
     811                 :            :         /* SPLIT_TYPE_VF */
     812                 :            :         {"vf"}
     813                 :            : };
     814                 :            : 
     815                 :            : /******************************** Variables *********************************/
     816                 :            : 
     817                 :            : /**
     818                 :            :  * The version of the calling app
     819                 :            :  */
     820                 :            : static u32 s_app_ver;
     821                 :            : 
     822                 :            : /**************************** Private Functions ******************************/
     823                 :            : 
     824                 :            : /* Reads and returns a single dword from the specified unaligned buffer */
     825                 :            : static u32 qed_read_unaligned_dword(u8 *buf)
     826                 :            : {
     827                 :            :         u32 dword;
     828                 :            : 
     829                 :            :         memcpy((u8 *)&dword, buf, sizeof(dword));
     830                 :            :         return dword;
     831                 :            : }
     832                 :            : 
     833                 :            : /* Sets the value of the specified GRC param */
     834                 :            : static void qed_grc_set_param(struct ecore_hwfn *p_hwfn,
     835                 :            :                               enum dbg_grc_params grc_param, u32 val)
     836                 :            : {
     837                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     838                 :            : 
     839                 :          0 :         dev_data->grc.param_val[grc_param] = val;
     840                 :          0 : }
     841                 :            : 
     842                 :            : /* Returns the value of the specified GRC param */
     843                 :            : static u32 qed_grc_get_param(struct ecore_hwfn *p_hwfn,
     844                 :            :                              enum dbg_grc_params grc_param)
     845                 :            : {
     846                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     847                 :            : 
     848                 :          0 :         return dev_data->grc.param_val[grc_param];
     849                 :            : }
     850                 :            : 
     851                 :            : /* Initializes the GRC parameters */
     852                 :            : static void qed_dbg_grc_init_params(struct ecore_hwfn *p_hwfn)
     853                 :            : {
     854                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     855                 :            : 
     856         [ #  # ]:          0 :         if (!dev_data->grc.params_initialized) {
     857                 :          0 :                 qed_dbg_grc_set_params_default(p_hwfn);
     858                 :          0 :                 dev_data->grc.params_initialized = 1;
     859                 :            :         }
     860                 :            : }
     861                 :            : 
     862                 :            : /* Sets pointer and size for the specified binary buffer type */
     863                 :            : static void qed_set_dbg_bin_buf(struct ecore_hwfn *p_hwfn,
     864                 :            :                                 enum bin_dbg_buffer_type buf_type,
     865                 :            :                                 const u32 *ptr, u32 size)
     866                 :            : {
     867                 :            :         struct virt_mem_desc *buf = &p_hwfn->dbg_arrays[buf_type];
     868                 :            : 
     869                 :          0 :         buf->ptr = (void *)(osal_uintptr_t)ptr;
     870                 :          0 :         buf->size = size;
     871                 :            : }
     872                 :            : 
     873                 :            : /* Initializes debug data for the specified device */
     874                 :          0 : static enum dbg_status qed_dbg_dev_init(struct ecore_hwfn *p_hwfn)
     875                 :            : {
     876                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     877                 :            :         u8 num_pfs = 0, max_pfs_per_port = 0;
     878                 :            : 
     879         [ #  # ]:          0 :         if (dev_data->initialized)
     880                 :            :                 return DBG_STATUS_OK;
     881                 :            : 
     882                 :            :         /* Set chip */
     883         [ #  # ]:          0 :         if (ECORE_IS_K2(p_hwfn->p_dev)) {
     884                 :          0 :                 dev_data->chip_id = CHIP_K2;
     885                 :          0 :                 dev_data->mode_enable[MODE_K2] = 1;
     886                 :          0 :                 dev_data->num_vfs = MAX_NUM_VFS_K2;
     887                 :            :                 num_pfs = MAX_NUM_PFS_K2;
     888                 :            :                 max_pfs_per_port = MAX_NUM_PFS_K2 / 2;
     889   [ #  #  #  #  :          0 :         } else if (ECORE_IS_BB_B0(p_hwfn->p_dev)) {
             #  #  #  # ]
     890                 :          0 :                 dev_data->chip_id = CHIP_BB;
     891                 :          0 :                 dev_data->mode_enable[MODE_BB] = 1;
     892                 :          0 :                 dev_data->num_vfs = MAX_NUM_VFS_BB;
     893                 :            :                 num_pfs = MAX_NUM_PFS_BB;
     894                 :          0 :                 max_pfs_per_port = MAX_NUM_PFS_BB;
     895                 :            :         } else {
     896                 :            :                 return DBG_STATUS_UNKNOWN_CHIP;
     897                 :            :         }
     898                 :            : 
     899                 :            :         /* Set HW type */
     900                 :          0 :         dev_data->hw_type = HW_TYPE_ASIC;
     901                 :          0 :         dev_data->mode_enable[MODE_ASIC] = 1;
     902                 :            : 
     903                 :            :         /* Set port mode */
     904   [ #  #  #  # ]:          0 :         switch (p_hwfn->p_dev->num_ports_in_engine) {
     905                 :          0 :         case 1:
     906                 :          0 :                 dev_data->mode_enable[MODE_PORTS_PER_ENG_1] = 1;
     907                 :          0 :                 break;
     908                 :          0 :         case 2:
     909                 :          0 :                 dev_data->mode_enable[MODE_PORTS_PER_ENG_2] = 1;
     910                 :          0 :                 break;
     911                 :          0 :         case 4:
     912                 :          0 :                 dev_data->mode_enable[MODE_PORTS_PER_ENG_4] = 1;
     913                 :          0 :                 break;
     914                 :            :         }
     915                 :            : 
     916                 :            :         /* Set 100G mode */
     917         [ #  # ]:          0 :         if (ECORE_IS_CMT(p_hwfn->p_dev))
     918                 :          0 :                 dev_data->mode_enable[MODE_100G] = 1;
     919                 :            : 
     920                 :            :         /* Set number of ports */
     921         [ #  # ]:          0 :         if (dev_data->mode_enable[MODE_PORTS_PER_ENG_1] ||
     922         [ #  # ]:          0 :             dev_data->mode_enable[MODE_100G])
     923                 :          0 :                 dev_data->num_ports = 1;
     924         [ #  # ]:          0 :         else if (dev_data->mode_enable[MODE_PORTS_PER_ENG_2])
     925                 :          0 :                 dev_data->num_ports = 2;
     926         [ #  # ]:          0 :         else if (dev_data->mode_enable[MODE_PORTS_PER_ENG_4])
     927                 :          0 :                 dev_data->num_ports = 4;
     928                 :            : 
     929                 :            :         /* Set number of PFs per port */
     930         [ #  # ]:          0 :         dev_data->num_pfs_per_port = OSAL_MIN_T(u32,
     931                 :            :                                                 num_pfs / dev_data->num_ports,
     932                 :            :                                                 max_pfs_per_port);
     933                 :            : 
     934                 :            :         /* Initializes the GRC parameters */
     935                 :            :         qed_dbg_grc_init_params(p_hwfn);
     936                 :            : 
     937                 :          0 :         dev_data->use_dmae = true;
     938                 :          0 :         dev_data->initialized = 1;
     939                 :            : 
     940                 :          0 :         return DBG_STATUS_OK;
     941                 :            : }
     942                 :            : 
     943                 :            : static const struct dbg_block *get_dbg_block(struct ecore_hwfn *p_hwfn,
     944                 :            :                                              enum block_id block_id)
     945                 :            : {
     946                 :            :         const struct dbg_block *dbg_block;
     947                 :            : 
     948                 :          0 :         dbg_block = p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS].ptr;
     949                 :          0 :         return dbg_block + block_id;
     950                 :            : }
     951                 :            : 
     952                 :            : static const struct dbg_block_chip *qed_get_dbg_block_per_chip(struct ecore_hwfn
     953                 :            :                                                                *p_hwfn,
     954                 :            :                                                                enum block_id
     955                 :            :                                                                block_id)
     956                 :            : {
     957                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     958                 :            : 
     959                 :            :         return (const struct dbg_block_chip *)
     960                 :          0 :             p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS_CHIP_DATA].ptr +
     961                 :          0 :             block_id * MAX_CHIP_IDS + dev_data->chip_id;
     962                 :            : }
     963                 :            : 
     964                 :            : static const struct dbg_reset_reg *qed_get_dbg_reset_reg(struct ecore_hwfn
     965                 :            :                                                          *p_hwfn,
     966                 :            :                                                          u8 reset_reg_id)
     967                 :            : {
     968                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
     969                 :            : 
     970                 :            :         return (const struct dbg_reset_reg *)
     971                 :          0 :             p_hwfn->dbg_arrays[BIN_BUF_DBG_RESET_REGS].ptr +
     972                 :          0 :             reset_reg_id * MAX_CHIP_IDS + dev_data->chip_id;
     973                 :            : }
     974                 :            : 
     975                 :            : /* Reads the FW info structure for the specified Storm from the chip,
     976                 :            :  * and writes it to the specified fw_info pointer.
     977                 :            :  */
     978                 :          0 : static void qed_read_storm_fw_info(struct ecore_hwfn *p_hwfn,
     979                 :            :                                    struct ecore_ptt *p_ptt,
     980                 :            :                                    u8 storm_id, struct fw_info *fw_info)
     981                 :            : {
     982                 :          0 :         struct storm_defs *storm = &s_storm_defs[storm_id];
     983                 :            :         struct fw_info_location fw_info_location;
     984                 :            :         u32 addr, i, *dest;
     985                 :            : 
     986                 :            :         memset(&fw_info_location, 0, sizeof(fw_info_location));
     987                 :            :         memset(fw_info, 0, sizeof(*fw_info));
     988                 :            : 
     989                 :            :         /* Read first the address that points to fw_info location.
     990                 :            :          * The address is located in the last line of the Storm RAM.
     991                 :            :          */
     992                 :          0 :         addr = storm->sem_fast_mem_addr + SEM_FAST_REG_INT_RAM +
     993                 :            :             DWORDS_TO_BYTES(SEM_FAST_REG_INT_RAM_SIZE) -
     994                 :            :             sizeof(fw_info_location);
     995                 :            : 
     996                 :            :         dest = (u32 *)&fw_info_location;
     997                 :            : 
     998         [ #  # ]:          0 :         for (i = 0; i < BYTES_TO_DWORDS(sizeof(fw_info_location));
     999                 :          0 :              i++, addr += BYTES_IN_DWORD)
    1000                 :          0 :                 dest[i] = ecore_rd(p_hwfn, p_ptt, addr);
    1001                 :            : 
    1002                 :            :         /* Read FW version info from Storm RAM */
    1003         [ #  # ]:          0 :         if (fw_info_location.size > 0 && fw_info_location.size <=
    1004                 :            :             sizeof(*fw_info)) {
    1005                 :          0 :                 addr = fw_info_location.grc_addr;
    1006                 :            :                 dest = (u32 *)fw_info;
    1007         [ #  # ]:          0 :                 for (i = 0; i < BYTES_TO_DWORDS(fw_info_location.size);
    1008                 :          0 :                      i++, addr += BYTES_IN_DWORD)
    1009                 :          0 :                         dest[i] = ecore_rd(p_hwfn, p_ptt, addr);
    1010                 :            :         }
    1011                 :          0 : }
    1012                 :            : 
    1013                 :            : /* Dumps the specified string to the specified buffer.
    1014                 :            :  * Returns the dumped size in bytes.
    1015                 :            :  */
    1016                 :          0 : static u32 qed_dump_str(char *dump_buf, bool dump, const char *str)
    1017                 :            : {
    1018         [ #  # ]:          0 :         if (dump)
    1019                 :            :                 strcpy(dump_buf, str);
    1020                 :            : 
    1021                 :          0 :         return (u32)strlen(str) + 1;
    1022                 :            : }
    1023                 :            : 
    1024                 :            : /* Dumps zeros to align the specified buffer to dwords.
    1025                 :            :  * Returns the dumped size in bytes.
    1026                 :            :  */
    1027                 :          0 : static u32 qed_dump_align(char *dump_buf, bool dump, u32 byte_offset)
    1028                 :            : {
    1029                 :            :         u8 offset_in_dword, align_size;
    1030                 :            : 
    1031                 :          0 :         offset_in_dword = (u8)(byte_offset & 0x3);
    1032         [ #  # ]:          0 :         align_size = offset_in_dword ? BYTES_IN_DWORD - offset_in_dword : 0;
    1033                 :            : 
    1034         [ #  # ]:          0 :         if (dump && align_size)
    1035                 :          0 :                 memset(dump_buf, 0, align_size);
    1036                 :            : 
    1037                 :          0 :         return align_size;
    1038                 :            : }
    1039                 :            : 
    1040                 :            : /* Writes the specified string param to the specified buffer.
    1041                 :            :  * Returns the dumped size in dwords.
    1042                 :            :  */
    1043                 :          0 : static u32 qed_dump_str_param(u32 *dump_buf,
    1044                 :            :                               bool dump,
    1045                 :            :                               const char *param_name, const char *param_val)
    1046                 :            : {
    1047                 :            :         char *char_buf = (char *)dump_buf;
    1048                 :            :         u32 offset = 0;
    1049                 :            : 
    1050                 :            :         /* Dump param name */
    1051                 :          0 :         offset += qed_dump_str(char_buf + offset, dump, param_name);
    1052                 :            : 
    1053                 :            :         /* Indicate a string param value */
    1054         [ #  # ]:          0 :         if (dump)
    1055                 :          0 :                 *(char_buf + offset) = 1;
    1056                 :          0 :         offset++;
    1057                 :            : 
    1058                 :            :         /* Dump param value */
    1059                 :          0 :         offset += qed_dump_str(char_buf + offset, dump, param_val);
    1060                 :            : 
    1061                 :            :         /* Align buffer to next dword */
    1062                 :          0 :         offset += qed_dump_align(char_buf + offset, dump, offset);
    1063                 :            : 
    1064                 :          0 :         return BYTES_TO_DWORDS(offset);
    1065                 :            : }
    1066                 :            : 
    1067                 :            : /* Writes the specified numeric param to the specified buffer.
    1068                 :            :  * Returns the dumped size in dwords.
    1069                 :            :  */
    1070                 :          0 : static u32 qed_dump_num_param(u32 *dump_buf,
    1071                 :            :                               bool dump, const char *param_name, u32 param_val)
    1072                 :            : {
    1073                 :            :         char *char_buf = (char *)dump_buf;
    1074                 :            :         u32 offset = 0;
    1075                 :            : 
    1076                 :            :         /* Dump param name */
    1077                 :          0 :         offset += qed_dump_str(char_buf + offset, dump, param_name);
    1078                 :            : 
    1079                 :            :         /* Indicate a numeric param value */
    1080         [ #  # ]:          0 :         if (dump)
    1081                 :          0 :                 *(char_buf + offset) = 0;
    1082                 :          0 :         offset++;
    1083                 :            : 
    1084                 :            :         /* Align buffer to next dword */
    1085                 :          0 :         offset += qed_dump_align(char_buf + offset, dump, offset);
    1086                 :            : 
    1087                 :            :         /* Dump param value (and change offset from bytes to dwords) */
    1088                 :          0 :         offset = BYTES_TO_DWORDS(offset);
    1089         [ #  # ]:          0 :         if (dump)
    1090                 :          0 :                 *(dump_buf + offset) = param_val;
    1091                 :          0 :         offset++;
    1092                 :            : 
    1093                 :          0 :         return offset;
    1094                 :            : }
    1095                 :            : 
    1096                 :            : /* Reads the FW version and writes it as a param to the specified buffer.
    1097                 :            :  * Returns the dumped size in dwords.
    1098                 :            :  */
    1099                 :          0 : static u32 qed_dump_fw_ver_param(struct ecore_hwfn *p_hwfn,
    1100                 :            :                                  struct ecore_ptt *p_ptt,
    1101                 :            :                                  u32 *dump_buf, bool dump)
    1102                 :            : {
    1103                 :          0 :         char fw_ver_str[16] = EMPTY_FW_VERSION_STR;
    1104                 :          0 :         char fw_img_str[16] = EMPTY_FW_IMAGE_STR;
    1105                 :          0 :         struct fw_info fw_info = { {0}, {0} };
    1106                 :            :         u32 offset = 0;
    1107                 :            : 
    1108   [ #  #  #  # ]:          0 :         if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
    1109                 :            :                 /* Read FW info from chip */
    1110                 :          0 :                 qed_read_fw_info(p_hwfn, p_ptt, &fw_info);
    1111                 :            : 
    1112                 :            :                 /* Create FW version/image strings */
    1113                 :          0 :                 if (snprintf(fw_ver_str, sizeof(fw_ver_str),
    1114                 :          0 :                              "%d_%d_%d_%d", fw_info.ver.num.major,
    1115                 :          0 :                              fw_info.ver.num.minor, fw_info.ver.num.rev,
    1116         [ #  # ]:          0 :                              fw_info.ver.num.eng) < 0)
    1117                 :          0 :                         DP_NOTICE(p_hwfn, false,
    1118                 :            :                                   "Unexpected debug error: invalid FW version string\n");
    1119         [ #  # ]:          0 :                 switch (fw_info.ver.image_id) {
    1120                 :            :                 case FW_IMG_MAIN:
    1121                 :            :                         strcpy(fw_img_str, "main");
    1122                 :            :                         break;
    1123                 :            :                 default:
    1124                 :            :                         strcpy(fw_img_str, "unknown");
    1125                 :            :                         break;
    1126                 :            :                 }
    1127                 :            :         }
    1128                 :            : 
    1129                 :            :         /* Dump FW version, image and timestamp */
    1130                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1131                 :            :                                      dump, "fw-version", fw_ver_str);
    1132                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1133                 :            :                                      dump, "fw-image", fw_img_str);
    1134                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    1135                 :            :                                      dump,
    1136                 :            :                                      "fw-timestamp", fw_info.ver.timestamp);
    1137                 :            : 
    1138                 :          0 :         return offset;
    1139                 :            : }
    1140                 :            : 
    1141                 :            : /* Reads the MFW version and writes it as a param to the specified buffer.
    1142                 :            :  * Returns the dumped size in dwords.
    1143                 :            :  */
    1144                 :          0 : static u32 qed_dump_mfw_ver_param(struct ecore_hwfn *p_hwfn,
    1145                 :            :                                   struct ecore_ptt *p_ptt,
    1146                 :            :                                   u32 *dump_buf, bool dump)
    1147                 :            : {
    1148                 :          0 :         char mfw_ver_str[16] = EMPTY_FW_VERSION_STR;
    1149                 :            : 
    1150   [ #  #  #  # ]:          0 :         if (dump &&
    1151                 :            :             !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_FW_VER)) {
    1152                 :            :                 u32 global_section_offsize, global_section_addr, mfw_ver;
    1153                 :            :                 u32 public_data_addr, global_section_offsize_addr;
    1154                 :            : 
    1155                 :            :                 /* Find MCP public data GRC address. Needs to be ORed with
    1156                 :            :                  * MCP_REG_SCRATCH due to a HW bug.
    1157                 :            :                  */
    1158                 :          0 :                 public_data_addr = ecore_rd(p_hwfn,
    1159                 :            :                                           p_ptt,
    1160                 :            :                                           MISC_REG_SHARED_MEM_ADDR) |
    1161                 :            :                                    MCP_REG_SCRATCH;
    1162                 :            : 
    1163                 :            :                 /* Find MCP public global section offset */
    1164                 :          0 :                 global_section_offsize_addr = public_data_addr +
    1165                 :            :                                               offsetof(struct mcp_public_data,
    1166                 :            :                                                        sections) +
    1167                 :            :                                               sizeof(offsize_t) * PUBLIC_GLOBAL;
    1168                 :          0 :                 global_section_offsize = ecore_rd(p_hwfn, p_ptt,
    1169                 :            :                                                 global_section_offsize_addr);
    1170                 :          0 :                 global_section_addr =
    1171                 :          0 :                         MCP_REG_SCRATCH +
    1172                 :          0 :                         (global_section_offsize & OFFSIZE_OFFSET_MASK) * 4;
    1173                 :            : 
    1174                 :            :                 /* Read MFW version from MCP public global section */
    1175                 :          0 :                 mfw_ver = ecore_rd(p_hwfn, p_ptt,
    1176                 :            :                                  global_section_addr +
    1177                 :            :                                  offsetof(struct public_global, mfw_ver));
    1178                 :            : 
    1179                 :            :                 /* Dump MFW version param */
    1180                 :          0 :                 if (snprintf(mfw_ver_str, sizeof(mfw_ver_str), "%d_%d_%d_%d",
    1181                 :          0 :                              (u8)(mfw_ver >> 24), (u8)(mfw_ver >> 16),
    1182         [ #  # ]:          0 :                              (u8)(mfw_ver >> 8), (u8)mfw_ver) < 0)
    1183                 :          0 :                         DP_NOTICE(p_hwfn, false,
    1184                 :            :                                   "Unexpected debug error: invalid MFW version string\n");
    1185                 :            :         }
    1186                 :            : 
    1187                 :          0 :         return qed_dump_str_param(dump_buf, dump, "mfw-version", mfw_ver_str);
    1188                 :            : }
    1189                 :            : 
    1190                 :            : /* Reads the chip revision from the chip and writes it as a param to the
    1191                 :            :  * specified buffer. Returns the dumped size in dwords.
    1192                 :            :  */
    1193                 :          0 : static u32 qed_dump_chip_revision_param(struct ecore_hwfn *p_hwfn,
    1194                 :            :                                         struct ecore_ptt *p_ptt,
    1195                 :            :                                         u32 *dump_buf, bool dump)
    1196                 :            : {
    1197                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1198                 :          0 :         char param_str[3] = "??";
    1199                 :            : 
    1200         [ #  # ]:          0 :         if (dev_data->hw_type == HW_TYPE_ASIC) {
    1201                 :            :                 u32 chip_rev, chip_metal;
    1202                 :            : 
    1203                 :          0 :                 chip_rev = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
    1204                 :          0 :                 chip_metal = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
    1205                 :            : 
    1206                 :          0 :                 param_str[0] = 'a' + (u8)chip_rev;
    1207                 :          0 :                 param_str[1] = '0' + (u8)chip_metal;
    1208                 :            :         }
    1209                 :            : 
    1210                 :          0 :         return qed_dump_str_param(dump_buf, dump, "chip-revision", param_str);
    1211                 :            : }
    1212                 :            : 
    1213                 :            : /* Writes a section header to the specified buffer.
    1214                 :            :  * Returns the dumped size in dwords.
    1215                 :            :  */
    1216                 :            : static u32 qed_dump_section_hdr(u32 *dump_buf,
    1217                 :            :                                 bool dump, const char *name, u32 num_params)
    1218                 :            : {
    1219                 :          0 :         return qed_dump_num_param(dump_buf, dump, name, num_params);
    1220                 :            : }
    1221                 :            : 
    1222                 :            : /* Writes the common global params to the specified buffer.
    1223                 :            :  * Returns the dumped size in dwords.
    1224                 :            :  */
    1225                 :          0 : static u32 qed_dump_common_global_params(struct ecore_hwfn *p_hwfn,
    1226                 :            :                                          struct ecore_ptt *p_ptt,
    1227                 :            :                                          u32 *dump_buf,
    1228                 :            :                                          bool dump,
    1229                 :            :                                          u8 num_specific_global_params)
    1230                 :            : {
    1231                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1232                 :            :         char sw_platform_str[MAX_SW_PLTAFORM_STR_SIZE];
    1233                 :            :         u32 offset = 0;
    1234                 :            :         u8 num_params;
    1235                 :            : 
    1236                 :            :         /* Fill platform string */
    1237                 :          0 :         ecore_set_platform_str(p_hwfn, sw_platform_str,
    1238                 :            :                                MAX_SW_PLTAFORM_STR_SIZE);
    1239                 :            : 
    1240                 :            :         /* Dump global params section header */
    1241                 :          0 :         num_params = NUM_COMMON_GLOBAL_PARAMS + num_specific_global_params +
    1242                 :          0 :                 (dev_data->chip_id == CHIP_BB ? 1 : 0);
    1243                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    1244                 :            :                                        dump, "global_params", num_params);
    1245                 :            : 
    1246                 :            :         /* Store params */
    1247                 :          0 :         offset += qed_dump_fw_ver_param(p_hwfn, p_ptt, dump_buf + offset, dump);
    1248                 :          0 :         offset += qed_dump_mfw_ver_param(p_hwfn,
    1249                 :          0 :                                          p_ptt, dump_buf + offset, dump);
    1250                 :          0 :         offset += qed_dump_chip_revision_param(p_hwfn,
    1251                 :          0 :                                                p_ptt, dump_buf + offset, dump);
    1252                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    1253                 :            :                                      dump, "tools-version", TOOLS_VERSION);
    1254                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1255                 :            :                                      dump,
    1256                 :            :                                      "chip",
    1257                 :          0 :                                      s_chip_defs[dev_data->chip_id].name);
    1258                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1259                 :            :                                      dump,
    1260                 :            :                                      "platform",
    1261                 :          0 :                                      s_hw_type_defs[dev_data->hw_type].name);
    1262                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1263                 :            :                                      dump, "sw-platform", sw_platform_str);
    1264                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    1265                 :          0 :                                      dump, "pci-func", p_hwfn->abs_pf_id);
    1266                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    1267                 :          0 :                                      dump, "epoch", OSAL_GET_EPOCH(p_hwfn));
    1268         [ #  # ]:          0 :         if (dev_data->chip_id == CHIP_BB)
    1269                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    1270                 :            :                                              dump, "path",
    1271         [ #  # ]:          0 :                                              ECORE_PATH_ID(p_hwfn));
    1272                 :            : 
    1273                 :          0 :         return offset;
    1274                 :            : }
    1275                 :            : 
    1276                 :            : /* Writes the "last" section (including CRC) to the specified buffer at the
    1277                 :            :  * given offset. Returns the dumped size in dwords.
    1278                 :            :  */
    1279                 :          0 : static u32 qed_dump_last_section(u32 *dump_buf, u32 offset, bool dump)
    1280                 :            : {
    1281                 :            :         u32 start_offset = offset;
    1282                 :            : 
    1283                 :            :         /* Dump CRC section header */
    1284                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset, dump, "last", 0);
    1285                 :            : 
    1286                 :            :         /* Calculate CRC32 and add it to the dword after the "last" section */
    1287         [ #  # ]:          0 :         if (dump)
    1288                 :          0 :                 *(dump_buf + offset) = ~OSAL_CRC32(0xffffffff,
    1289                 :            :                                               (u8 *)dump_buf,
    1290                 :            :                                               DWORDS_TO_BYTES(offset));
    1291                 :            : 
    1292                 :          0 :         offset++;
    1293                 :            : 
    1294                 :          0 :         return offset - start_offset;
    1295                 :            : }
    1296                 :            : 
    1297                 :            : /* Update blocks reset state  */
    1298                 :          0 : static void qed_update_blocks_reset_state(struct ecore_hwfn *p_hwfn,
    1299                 :            :                                           struct ecore_ptt *p_ptt)
    1300                 :            : {
    1301                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1302                 :          0 :         u32 reg_val[NUM_DBG_RESET_REGS] = { 0 };
    1303                 :            :         u8 rst_reg_id;
    1304                 :            :         u32 blk_id;
    1305                 :            : 
    1306                 :            :         /* Read reset registers */
    1307         [ #  # ]:          0 :         for (rst_reg_id = 0; rst_reg_id < NUM_DBG_RESET_REGS; rst_reg_id++) {
    1308                 :            :                 const struct dbg_reset_reg *rst_reg;
    1309                 :            :                 bool rst_reg_removed;
    1310                 :            :                 u32 rst_reg_addr;
    1311                 :            : 
    1312                 :          0 :                 rst_reg = qed_get_dbg_reset_reg(p_hwfn, rst_reg_id);
    1313                 :          0 :                 rst_reg_removed = GET_FIELD(rst_reg->data,
    1314                 :            :                                             DBG_RESET_REG_IS_REMOVED);
    1315                 :          0 :                 rst_reg_addr = DWORDS_TO_BYTES(GET_FIELD(rst_reg->data,
    1316                 :            :                                                          DBG_RESET_REG_ADDR));
    1317                 :            : 
    1318         [ #  # ]:          0 :                 if (!rst_reg_removed)
    1319                 :          0 :                         reg_val[rst_reg_id] = ecore_rd(p_hwfn, p_ptt,
    1320                 :            :                                                      rst_reg_addr);
    1321                 :            :         }
    1322                 :            : 
    1323                 :            :         /* Check if blocks are in reset */
    1324         [ #  # ]:          0 :         for (blk_id = 0; blk_id < NUM_PHYS_BLOCKS; blk_id++) {
    1325                 :            :                 const struct dbg_block_chip *blk;
    1326                 :            :                 bool has_rst_reg;
    1327                 :            :                 bool is_removed;
    1328                 :            : 
    1329                 :            :                 blk = qed_get_dbg_block_per_chip(p_hwfn, (enum block_id)blk_id);
    1330                 :          0 :                 is_removed = GET_FIELD(blk->flags, DBG_BLOCK_CHIP_IS_REMOVED);
    1331                 :          0 :                 has_rst_reg = GET_FIELD(blk->flags,
    1332                 :            :                                         DBG_BLOCK_CHIP_HAS_RESET_REG);
    1333                 :            : 
    1334         [ #  # ]:          0 :                 if (!is_removed && has_rst_reg)
    1335                 :          0 :                         dev_data->block_in_reset[blk_id] =
    1336                 :          0 :                             !(reg_val[blk->reset_reg_id] &
    1337                 :          0 :                               OSAL_BIT(blk->reset_reg_bit_offset));
    1338                 :            :         }
    1339                 :          0 : }
    1340                 :            : 
    1341                 :            : /* is_mode_match recursive function */
    1342                 :          0 : static bool qed_is_mode_match_rec(struct ecore_hwfn *p_hwfn,
    1343                 :            :                                   u16 *modes_buf_offset, u8 rec_depth)
    1344                 :            : {
    1345                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1346                 :            :         const u8 *dbg_array;
    1347                 :            :         bool arg1, arg2;
    1348                 :            :         u8 tree_val;
    1349                 :            : 
    1350         [ #  # ]:          0 :         if (rec_depth > MAX_RECURSION_DEPTH) {
    1351                 :          0 :                 DP_NOTICE(p_hwfn, false,
    1352                 :            :                           "Unexpected error: is_mode_match_rec exceeded the max recursion depth. This is probably due to a corrupt init/debug buffer.\n");
    1353                 :          0 :                 return false;
    1354                 :            :         }
    1355                 :            : 
    1356                 :            :         /* Get next element from modes tree buffer */
    1357                 :          0 :         dbg_array = p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr;
    1358                 :          0 :         tree_val = dbg_array[(*modes_buf_offset)++];
    1359                 :            : 
    1360      [ #  #  # ]:          0 :         switch (tree_val) {
    1361                 :          0 :         case INIT_MODE_OP_NOT:
    1362                 :          0 :                 return !qed_is_mode_match_rec(p_hwfn,
    1363                 :          0 :                                               modes_buf_offset, rec_depth + 1);
    1364                 :          0 :         case INIT_MODE_OP_OR:
    1365                 :            :         case INIT_MODE_OP_AND:
    1366                 :          0 :                 arg1 = qed_is_mode_match_rec(p_hwfn,
    1367                 :          0 :                                              modes_buf_offset, rec_depth + 1);
    1368                 :          0 :                 arg2 = qed_is_mode_match_rec(p_hwfn,
    1369                 :            :                                              modes_buf_offset, rec_depth + 1);
    1370                 :            :                 return (tree_val == INIT_MODE_OP_OR) ? (arg1 ||
    1371         [ #  # ]:          0 :                                                         arg2) : (arg1 && arg2);
    1372                 :          0 :         default:
    1373                 :          0 :                 return dev_data->mode_enable[tree_val - MAX_INIT_MODE_OPS] > 0;
    1374                 :            :         }
    1375                 :            : }
    1376                 :            : 
    1377                 :            : /* Returns true if the mode (specified using modes_buf_offset) is enabled */
    1378                 :            : static bool qed_is_mode_match(struct ecore_hwfn *p_hwfn, u16 *modes_buf_offset)
    1379                 :            : {
    1380                 :          0 :         return qed_is_mode_match_rec(p_hwfn, modes_buf_offset, 0);
    1381                 :            : }
    1382                 :            : 
    1383                 :            : /* Enable / disable the Debug block */
    1384                 :            : static void qed_bus_enable_dbg_block(struct ecore_hwfn *p_hwfn,
    1385                 :            :                                      struct ecore_ptt *p_ptt, bool enable)
    1386                 :            : {
    1387                 :          0 :         ecore_wr(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON, enable ? 1 : 0);
    1388                 :          0 : }
    1389                 :            : 
    1390                 :            : /* Resets the Debug block */
    1391                 :          0 : static void qed_bus_reset_dbg_block(struct ecore_hwfn *p_hwfn,
    1392                 :            :                                     struct ecore_ptt *p_ptt)
    1393                 :            : {
    1394                 :            :         u32 reset_reg_addr, old_reset_reg_val, new_reset_reg_val;
    1395                 :            :         const struct dbg_reset_reg *reset_reg;
    1396                 :            :         const struct dbg_block_chip *block;
    1397                 :            : 
    1398                 :            :         block = qed_get_dbg_block_per_chip(p_hwfn, BLOCK_DBG);
    1399                 :          0 :         reset_reg = qed_get_dbg_reset_reg(p_hwfn, block->reset_reg_id);
    1400                 :          0 :         reset_reg_addr =
    1401                 :          0 :             DWORDS_TO_BYTES(GET_FIELD(reset_reg->data, DBG_RESET_REG_ADDR));
    1402                 :            : 
    1403                 :          0 :         old_reset_reg_val = ecore_rd(p_hwfn, p_ptt, reset_reg_addr);
    1404                 :          0 :         new_reset_reg_val =
    1405                 :          0 :             old_reset_reg_val & ~OSAL_BIT(block->reset_reg_bit_offset);
    1406                 :            : 
    1407                 :          0 :         ecore_wr(p_hwfn, p_ptt, reset_reg_addr, new_reset_reg_val);
    1408                 :          0 :         ecore_wr(p_hwfn, p_ptt, reset_reg_addr, old_reset_reg_val);
    1409                 :          0 : }
    1410                 :            : 
    1411                 :            : /* Enable / disable Debug Bus clients according to the specified mask
    1412                 :            :  * (1 = enable, 0 = disable).
    1413                 :            :  */
    1414                 :            : static void qed_bus_enable_clients(struct ecore_hwfn *p_hwfn,
    1415                 :            :                                    struct ecore_ptt *p_ptt, u32 client_mask)
    1416                 :            : {
    1417                 :          0 :         ecore_wr(p_hwfn, p_ptt, DBG_REG_CLIENT_ENABLE, client_mask);
    1418                 :          0 : }
    1419                 :            : 
    1420                 :          0 : static void qed_bus_config_dbg_line(struct ecore_hwfn *p_hwfn,
    1421                 :            :                                     struct ecore_ptt *p_ptt,
    1422                 :            :                                     enum block_id block_id,
    1423                 :            :                                     u8 line_id,
    1424                 :            :                                     u8 enable_mask,
    1425                 :            :                                     u8 right_shift,
    1426                 :            :                                     u8 force_valid_mask, u8 force_frame_mask)
    1427                 :            : {
    1428                 :            :         const struct dbg_block_chip *block =
    1429                 :            :                 qed_get_dbg_block_per_chip(p_hwfn, block_id);
    1430                 :            : 
    1431                 :          0 :         ecore_wr(p_hwfn, p_ptt,
    1432                 :          0 :                  DWORDS_TO_BYTES(block->dbg_select_reg_addr),
    1433                 :            :                  line_id);
    1434                 :          0 :         ecore_wr(p_hwfn, p_ptt,
    1435                 :          0 :                  DWORDS_TO_BYTES(block->dbg_dword_enable_reg_addr),
    1436                 :            :                  enable_mask);
    1437                 :          0 :         ecore_wr(p_hwfn, p_ptt,
    1438                 :          0 :                  DWORDS_TO_BYTES(block->dbg_shift_reg_addr),
    1439                 :            :                  right_shift);
    1440                 :          0 :         ecore_wr(p_hwfn, p_ptt,
    1441                 :          0 :                  DWORDS_TO_BYTES(block->dbg_force_valid_reg_addr),
    1442                 :            :                  force_valid_mask);
    1443                 :          0 :         ecore_wr(p_hwfn, p_ptt,
    1444                 :          0 :                  DWORDS_TO_BYTES(block->dbg_force_frame_reg_addr),
    1445                 :            :                  force_frame_mask);
    1446                 :          0 : }
    1447                 :            : 
    1448                 :            : /* Disable debug bus in all blocks */
    1449                 :          0 : static void qed_bus_disable_blocks(struct ecore_hwfn *p_hwfn,
    1450                 :            :                                    struct ecore_ptt *p_ptt)
    1451                 :            : {
    1452                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1453                 :            :         u32 block_id;
    1454                 :            : 
    1455                 :            :         /* Disable all blocks */
    1456         [ #  # ]:          0 :         for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
    1457                 :            :                 const struct dbg_block_chip *block_per_chip =
    1458                 :            :                     qed_get_dbg_block_per_chip(p_hwfn,
    1459                 :            :                                                (enum block_id)block_id);
    1460                 :            : 
    1461         [ #  # ]:          0 :                 if (GET_FIELD(block_per_chip->flags,
    1462                 :          0 :                               DBG_BLOCK_CHIP_IS_REMOVED) ||
    1463         [ #  # ]:          0 :                     dev_data->block_in_reset[block_id])
    1464                 :          0 :                         continue;
    1465                 :            : 
    1466                 :            :                 /* Disable debug bus */
    1467         [ #  # ]:          0 :                 if (GET_FIELD(block_per_chip->flags,
    1468                 :            :                               DBG_BLOCK_CHIP_HAS_DBG_BUS)) {
    1469                 :          0 :                         u32 dbg_en_addr =
    1470                 :            :                                 block_per_chip->dbg_dword_enable_reg_addr;
    1471                 :          0 :                         u16 modes_buf_offset =
    1472                 :          0 :                             GET_FIELD(block_per_chip->dbg_bus_mode.data,
    1473                 :            :                                       DBG_MODE_HDR_MODES_BUF_OFFSET);
    1474                 :            :                         bool eval_mode =
    1475                 :            :                             GET_FIELD(block_per_chip->dbg_bus_mode.data,
    1476                 :            :                                       DBG_MODE_HDR_EVAL_MODE) > 0;
    1477                 :            : 
    1478   [ #  #  #  # ]:          0 :                         if (!eval_mode ||
    1479                 :            :                             qed_is_mode_match(p_hwfn, &modes_buf_offset))
    1480                 :          0 :                                 ecore_wr(p_hwfn, p_ptt,
    1481                 :            :                                        DWORDS_TO_BYTES(dbg_en_addr),
    1482                 :            :                                        0);
    1483                 :            :                 }
    1484                 :            :         }
    1485                 :          0 : }
    1486                 :            : 
    1487                 :            : /* Returns true if the specified entity (indicated by GRC param) should be
    1488                 :            :  * included in the dump, false otherwise.
    1489                 :            :  */
    1490                 :            : static bool qed_grc_is_included(struct ecore_hwfn *p_hwfn,
    1491                 :            :                                 enum dbg_grc_params grc_param)
    1492                 :            : {
    1493                 :          0 :         return qed_grc_get_param(p_hwfn, grc_param) > 0;
    1494                 :            : }
    1495                 :            : 
    1496                 :            : /* Returns the storm_id that matches the specified Storm letter,
    1497                 :            :  * or MAX_DBG_STORMS if invalid storm letter.
    1498                 :            :  */
    1499                 :            : static enum dbg_storms qed_get_id_from_letter(char storm_letter)
    1500                 :            : {
    1501                 :            :         u8 storm_id;
    1502                 :            : 
    1503         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++)
    1504         [ #  # ]:          0 :                 if (s_storm_defs[storm_id].letter == storm_letter)
    1505                 :          0 :                         return (enum dbg_storms)storm_id;
    1506                 :            : 
    1507                 :            :         return MAX_DBG_STORMS;
    1508                 :            : }
    1509                 :            : 
    1510                 :            : /* Returns true of the specified Storm should be included in the dump, false
    1511                 :            :  * otherwise.
    1512                 :            :  */
    1513                 :            : static bool qed_grc_is_storm_included(struct ecore_hwfn *p_hwfn,
    1514                 :            :                                       enum dbg_storms storm)
    1515                 :            : {
    1516                 :            :         return qed_grc_get_param(p_hwfn, (enum dbg_grc_params)storm) > 0;
    1517                 :            : }
    1518                 :            : 
    1519                 :            : /* Returns true if the specified memory should be included in the dump, false
    1520                 :            :  * otherwise.
    1521                 :            :  */
    1522                 :          0 : static bool qed_grc_is_mem_included(struct ecore_hwfn *p_hwfn,
    1523                 :            :                                     enum block_id block_id, u8 mem_group_id)
    1524                 :            : {
    1525                 :            :         const struct dbg_block *block;
    1526                 :            :         u8 i;
    1527                 :            : 
    1528                 :            :         block = get_dbg_block(p_hwfn, block_id);
    1529                 :            : 
    1530                 :            :         /* If the block is associated with a Storm, check Storm match */
    1531         [ #  # ]:          0 :         if (block->associated_storm_letter) {
    1532                 :            :                 enum dbg_storms associated_storm_id =
    1533                 :          0 :                     qed_get_id_from_letter(block->associated_storm_letter);
    1534                 :            : 
    1535   [ #  #  #  # ]:          0 :                 if (associated_storm_id == MAX_DBG_STORMS ||
    1536                 :            :                     !qed_grc_is_storm_included(p_hwfn, associated_storm_id))
    1537                 :            :                         return false;
    1538                 :            :         }
    1539                 :            : 
    1540         [ #  # ]:          0 :         for (i = 0; i < NUM_BIG_RAM_TYPES; i++) {
    1541                 :          0 :                 struct big_ram_defs *big_ram = &s_big_ram_defs[i];
    1542                 :            : 
    1543         [ #  # ]:          0 :                 if (mem_group_id == big_ram->mem_group_id ||
    1544         [ #  # ]:          0 :                     mem_group_id == big_ram->ram_mem_group_id)
    1545                 :          0 :                         return qed_grc_is_included(p_hwfn, big_ram->grc_param);
    1546                 :            :         }
    1547                 :            : 
    1548   [ #  #  #  #  :          0 :         switch (mem_group_id) {
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    1549                 :            :         case MEM_GROUP_PXP_ILT:
    1550                 :            :         case MEM_GROUP_PXP_MEM:
    1551                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PXP);
    1552                 :            :         case MEM_GROUP_RAM:
    1553                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RAM);
    1554                 :            :         case MEM_GROUP_PBUF:
    1555                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PBUF);
    1556                 :            :         case MEM_GROUP_CAU_MEM:
    1557                 :            :         case MEM_GROUP_CAU_SB:
    1558                 :            :         case MEM_GROUP_CAU_PI:
    1559                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CAU);
    1560                 :            :         case MEM_GROUP_CAU_MEM_EXT:
    1561                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CAU_EXT);
    1562                 :            :         case MEM_GROUP_QM_MEM:
    1563                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_QM);
    1564                 :            :         case MEM_GROUP_CFC_MEM:
    1565                 :            :         case MEM_GROUP_CONN_CFC_MEM:
    1566                 :            :         case MEM_GROUP_TASK_CFC_MEM:
    1567   [ #  #  #  # ]:          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CFC) ||
    1568                 :            :                        qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX);
    1569                 :            :         case MEM_GROUP_DORQ_MEM:
    1570                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DORQ);
    1571                 :            :         case MEM_GROUP_IGU_MEM:
    1572                 :            :         case MEM_GROUP_IGU_MSIX:
    1573                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IGU);
    1574                 :            :         case MEM_GROUP_MULD_MEM:
    1575                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MULD);
    1576                 :            :         case MEM_GROUP_PRS_MEM:
    1577                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_PRS);
    1578                 :            :         case MEM_GROUP_DMAE_MEM:
    1579                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DMAE);
    1580                 :            :         case MEM_GROUP_TM_MEM:
    1581                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_TM);
    1582                 :            :         case MEM_GROUP_SDM_MEM:
    1583                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_SDM);
    1584                 :            :         case MEM_GROUP_TDIF_CTX:
    1585                 :            :         case MEM_GROUP_RDIF_CTX:
    1586                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_DIF);
    1587                 :            :         case MEM_GROUP_CM_MEM:
    1588                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM);
    1589                 :            :         case MEM_GROUP_IOR:
    1590                 :          0 :                 return qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_IOR);
    1591                 :            :         default:
    1592                 :            :                 return true;
    1593                 :            :         }
    1594                 :            : }
    1595                 :            : 
    1596                 :            : /* Stalls all Storms */
    1597                 :          0 : static void qed_grc_stall_storms(struct ecore_hwfn *p_hwfn,
    1598                 :            :                                  struct ecore_ptt *p_ptt, bool stall)
    1599                 :            : {
    1600                 :            :         u32 reg_addr;
    1601                 :            :         u8 storm_id;
    1602                 :            : 
    1603         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
    1604         [ #  # ]:          0 :                 if (!qed_grc_is_storm_included(p_hwfn,
    1605                 :            :                                                (enum dbg_storms)storm_id))
    1606                 :          0 :                         continue;
    1607                 :            : 
    1608                 :          0 :                 reg_addr = s_storm_defs[storm_id].sem_fast_mem_addr +
    1609                 :            :                     SEM_FAST_REG_STALL_0;
    1610                 :          0 :                 ecore_wr(p_hwfn, p_ptt, reg_addr, stall ? 1 : 0);
    1611                 :            :         }
    1612                 :            : 
    1613                 :          0 :         OSAL_MSLEEP(STALL_DELAY_MS);
    1614                 :          0 : }
    1615                 :            : 
    1616                 :            : /* Takes all blocks out of reset. If rbc_only is true, only RBC clients are
    1617                 :            :  * taken out of reset.
    1618                 :            :  */
    1619                 :          0 : static void qed_grc_unreset_blocks(struct ecore_hwfn *p_hwfn,
    1620                 :            :                                    struct ecore_ptt *p_ptt, bool rbc_only)
    1621                 :            : {
    1622                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1623                 :          0 :         u8 chip_id = dev_data->chip_id;
    1624                 :            :         u32 i;
    1625                 :            : 
    1626                 :            :         /* Take RBCs out of reset */
    1627         [ #  # ]:          0 :         for (i = 0; i < OSAL_ARRAY_SIZE(s_rbc_reset_defs); i++)
    1628         [ #  # ]:          0 :                 if (s_rbc_reset_defs[i].reset_val[dev_data->chip_id])
    1629                 :          0 :                         ecore_wr(p_hwfn,
    1630                 :            :                                p_ptt,
    1631                 :          0 :                                s_rbc_reset_defs[i].reset_reg_addr +
    1632                 :            :                                RESET_REG_UNRESET_OFFSET,
    1633                 :            :                                s_rbc_reset_defs[i].reset_val[chip_id]);
    1634                 :            : 
    1635         [ #  # ]:          0 :         if (!rbc_only) {
    1636                 :          0 :                 u32 reg_val[NUM_DBG_RESET_REGS] = { 0 };
    1637                 :            :                 u8 reset_reg_id;
    1638                 :            :                 u32 block_id;
    1639                 :            : 
    1640                 :            :                 /* Fill reset regs values */
    1641         [ #  # ]:          0 :                 for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
    1642                 :            :                         bool is_removed, has_reset_reg, unreset_before_dump;
    1643                 :            :                         const struct dbg_block_chip *block;
    1644                 :            : 
    1645                 :            :                         block = qed_get_dbg_block_per_chip(p_hwfn,
    1646                 :            :                                                            (enum block_id)
    1647                 :            :                                                            block_id);
    1648                 :            :                         is_removed =
    1649                 :          0 :                             GET_FIELD(block->flags, DBG_BLOCK_CHIP_IS_REMOVED);
    1650                 :          0 :                         has_reset_reg =
    1651                 :          0 :                             GET_FIELD(block->flags,
    1652                 :            :                                       DBG_BLOCK_CHIP_HAS_RESET_REG);
    1653                 :            :                         unreset_before_dump =
    1654                 :          0 :                             GET_FIELD(block->flags,
    1655                 :            :                                       DBG_BLOCK_CHIP_UNRESET_BEFORE_DUMP);
    1656                 :            : 
    1657   [ #  #  #  # ]:          0 :                         if (!is_removed && has_reset_reg && unreset_before_dump)
    1658                 :          0 :                                 reg_val[block->reset_reg_id] |=
    1659                 :          0 :                                     OSAL_BIT(block->reset_reg_bit_offset);
    1660                 :            :                 }
    1661                 :            : 
    1662                 :            :                 /* Write reset registers */
    1663         [ #  # ]:          0 :                 for (reset_reg_id = 0; reset_reg_id < NUM_DBG_RESET_REGS;
    1664                 :          0 :                      reset_reg_id++) {
    1665                 :            :                         const struct dbg_reset_reg *reset_reg;
    1666                 :            :                         u32 reset_reg_addr;
    1667                 :            : 
    1668                 :          0 :                         reset_reg = qed_get_dbg_reset_reg(p_hwfn, reset_reg_id);
    1669                 :            : 
    1670         [ #  # ]:          0 :                         if (GET_FIELD
    1671                 :            :                             (reset_reg->data, DBG_RESET_REG_IS_REMOVED))
    1672                 :          0 :                                 continue;
    1673                 :            : 
    1674         [ #  # ]:          0 :                         if (reg_val[reset_reg_id]) {
    1675                 :          0 :                                 reset_reg_addr =
    1676                 :            :                                     GET_FIELD(reset_reg->data,
    1677                 :            :                                               DBG_RESET_REG_ADDR);
    1678                 :          0 :                                 ecore_wr(p_hwfn,
    1679                 :            :                                        p_ptt,
    1680                 :            :                                        DWORDS_TO_BYTES(reset_reg_addr) +
    1681                 :            :                                        RESET_REG_UNRESET_OFFSET,
    1682                 :            :                                        reg_val[reset_reg_id]);
    1683                 :            :                         }
    1684                 :            :                 }
    1685                 :            :         }
    1686                 :          0 : }
    1687                 :            : 
    1688                 :            : /* Returns the attention block data of the specified block */
    1689                 :            : static const struct dbg_attn_block_type_data *
    1690                 :            : qed_get_block_attn_data(struct ecore_hwfn *p_hwfn,
    1691                 :            :                         enum block_id block_id, enum dbg_attn_type attn_type)
    1692                 :            : {
    1693                 :          0 :         const struct dbg_attn_block *base_attn_block_arr =
    1694                 :            :             (const struct dbg_attn_block *)
    1695                 :            :             p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr;
    1696                 :            : 
    1697                 :          0 :         return &base_attn_block_arr[block_id].per_type_data[attn_type];
    1698                 :            : }
    1699                 :            : 
    1700                 :            : /* Returns the attention registers of the specified block */
    1701                 :            : static const struct dbg_attn_reg *
    1702                 :            : qed_get_block_attn_regs(struct ecore_hwfn *p_hwfn,
    1703                 :            :                         enum block_id block_id, enum dbg_attn_type attn_type,
    1704                 :            :                         u8 *num_attn_regs)
    1705                 :            : {
    1706                 :            :         const struct dbg_attn_block_type_data *block_type_data =
    1707                 :            :             qed_get_block_attn_data(p_hwfn, block_id, attn_type);
    1708                 :            : 
    1709                 :          0 :         *num_attn_regs = block_type_data->num_regs;
    1710                 :            : 
    1711                 :            :         return (const struct dbg_attn_reg *)
    1712                 :          0 :                 p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr +
    1713                 :          0 :                 block_type_data->regs_offset;
    1714                 :            : }
    1715                 :            : 
    1716                 :            : /* For each block, clear the status of all parities */
    1717                 :          0 : static void qed_grc_clear_all_prty(struct ecore_hwfn *p_hwfn,
    1718                 :            :                                    struct ecore_ptt *p_ptt)
    1719                 :            : {
    1720                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1721                 :            :         const struct dbg_attn_reg *attn_reg_arr;
    1722                 :            :         u8 reg_idx, num_attn_regs;
    1723                 :            :         u32 block_id;
    1724                 :            : 
    1725         [ #  # ]:          0 :         for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
    1726         [ #  # ]:          0 :                 if (dev_data->block_in_reset[block_id])
    1727                 :          0 :                         continue;
    1728                 :            : 
    1729                 :            :                 attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
    1730                 :            :                                                        (enum block_id)block_id,
    1731                 :            :                                                        ATTN_TYPE_PARITY,
    1732                 :            :                                                        &num_attn_regs);
    1733                 :            : 
    1734         [ #  # ]:          0 :                 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
    1735                 :          0 :                         const struct dbg_attn_reg *reg_data =
    1736                 :          0 :                                 &attn_reg_arr[reg_idx];
    1737                 :            :                         u16 modes_buf_offset;
    1738                 :            :                         bool eval_mode;
    1739                 :            : 
    1740                 :            :                         /* Check mode */
    1741                 :          0 :                         eval_mode = GET_FIELD(reg_data->mode.data,
    1742                 :            :                                               DBG_MODE_HDR_EVAL_MODE) > 0;
    1743                 :          0 :                         modes_buf_offset =
    1744                 :            :                                 GET_FIELD(reg_data->mode.data,
    1745                 :            :                                           DBG_MODE_HDR_MODES_BUF_OFFSET);
    1746                 :            : 
    1747                 :            :                         /* If Mode match: clear parity status */
    1748   [ #  #  #  # ]:          0 :                         if (!eval_mode ||
    1749                 :            :                             qed_is_mode_match(p_hwfn, &modes_buf_offset))
    1750                 :          0 :                                 ecore_rd(p_hwfn, p_ptt,
    1751                 :          0 :                                     DWORDS_TO_BYTES(reg_data->sts_clr_address));
    1752                 :            :                 }
    1753                 :            :         }
    1754                 :          0 : }
    1755                 :            : 
    1756                 :            : /* Dumps GRC registers section header. Returns the dumped size in dwords.
    1757                 :            :  * the following parameters are dumped:
    1758                 :            :  * - count: no. of dumped entries
    1759                 :            :  * - split_type: split type
    1760                 :            :  * - split_id: split ID (dumped only if split_id != SPLIT_TYPE_NONE)
    1761                 :            :  * - reg_type_name: register type name (dumped only if reg_type_name != NULL)
    1762                 :            :  */
    1763                 :          0 : static u32 qed_grc_dump_regs_hdr(u32 *dump_buf,
    1764                 :            :                                  bool dump,
    1765                 :            :                                  u32 num_reg_entries,
    1766                 :            :                                  enum init_split_types split_type,
    1767                 :            :                                  u8 split_id, const char *reg_type_name)
    1768                 :            : {
    1769                 :          0 :         u8 num_params = 2 +
    1770         [ #  # ]:          0 :             (split_type != SPLIT_TYPE_NONE ? 1 : 0) + (reg_type_name ? 1 : 0);
    1771                 :            :         u32 offset = 0;
    1772                 :            : 
    1773                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    1774                 :            :                                        dump, "grc_regs", num_params);
    1775                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    1776                 :            :                                      dump, "count", num_reg_entries);
    1777                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    1778                 :            :                                      dump, "split",
    1779                 :            :                                      s_split_type_defs[split_type].name);
    1780         [ #  # ]:          0 :         if (split_type != SPLIT_TYPE_NONE)
    1781                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    1782                 :            :                                              dump, "id", split_id);
    1783         [ #  # ]:          0 :         if (reg_type_name)
    1784                 :          0 :                 offset += qed_dump_str_param(dump_buf + offset,
    1785                 :            :                                              dump, "type", reg_type_name);
    1786                 :            : 
    1787                 :          0 :         return offset;
    1788                 :            : }
    1789                 :            : 
    1790                 :            : /* Reads the specified registers into the specified buffer.
    1791                 :            :  * The addr and len arguments are specified in dwords.
    1792                 :            :  */
    1793                 :          0 : void qed_read_regs(struct ecore_hwfn *p_hwfn,
    1794                 :            :                    struct ecore_ptt *p_ptt, u32 *buf, u32 addr, u32 len)
    1795                 :            : {
    1796                 :            :         u32 i;
    1797                 :            : 
    1798         [ #  # ]:          0 :         for (i = 0; i < len; i++)
    1799                 :          0 :                 buf[i] = ecore_rd(p_hwfn, p_ptt, DWORDS_TO_BYTES(addr + i));
    1800                 :          0 : }
    1801                 :            : 
    1802                 :            : /* Dumps the GRC registers in the specified address range.
    1803                 :            :  * Returns the dumped size in dwords.
    1804                 :            :  * The addr and len arguments are specified in dwords.
    1805                 :            :  */
    1806                 :          0 : static u32 qed_grc_dump_addr_range(struct ecore_hwfn *p_hwfn,
    1807                 :            :                                    struct ecore_ptt *p_ptt,
    1808                 :            :                                    u32 *dump_buf,
    1809                 :            :                                    bool dump, u32 addr, u32 len, bool wide_bus,
    1810                 :            :                                    enum init_split_types split_type,
    1811                 :            :                                    u8 split_id)
    1812                 :            : {
    1813                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    1814                 :            :         u8 port_id = 0, pf_id = 0;
    1815                 :            :         u16 vf_id = 0, fid = 0;
    1816                 :            :         bool read_using_dmae = false;
    1817                 :            :         u32 thresh;
    1818                 :            : 
    1819         [ #  # ]:          0 :         if (!dump)
    1820                 :            :                 return len;
    1821                 :            : 
    1822   [ #  #  #  #  :          0 :         switch (split_type) {
                      # ]
    1823                 :          0 :         case SPLIT_TYPE_PORT:
    1824                 :            :                 port_id = split_id;
    1825                 :          0 :                 break;
    1826                 :          0 :         case SPLIT_TYPE_PF:
    1827                 :            :                 pf_id = split_id;
    1828                 :          0 :                 break;
    1829                 :          0 :         case SPLIT_TYPE_PORT_PF:
    1830                 :          0 :                 port_id = split_id / dev_data->num_pfs_per_port;
    1831                 :          0 :                 pf_id = port_id + dev_data->num_ports *
    1832                 :            :                     (split_id % dev_data->num_pfs_per_port);
    1833                 :          0 :                 break;
    1834                 :          0 :         case SPLIT_TYPE_VF:
    1835                 :          0 :                 vf_id = split_id;
    1836                 :          0 :                 break;
    1837                 :            :         default:
    1838                 :            :                 break;
    1839                 :            :         }
    1840                 :            : 
    1841                 :            :         /* Try reading using DMAE */
    1842   [ #  #  #  # ]:          0 :         if (dev_data->use_dmae && split_type != SPLIT_TYPE_VF &&
    1843   [ #  #  #  # ]:          0 :             (len >= s_hw_type_defs[dev_data->hw_type].dmae_thresh ||
    1844                 :            :              (PROTECT_WIDE_BUS && wide_bus))) {
    1845                 :            :                 struct dmae_params dmae_params;
    1846                 :            : 
    1847                 :            :                 /* Set DMAE params */
    1848                 :            :                 memset(&dmae_params, 0, sizeof(dmae_params));
    1849                 :          0 :                 SET_FIELD(dmae_params.flags, DMAE_PARAMS_COMPLETION_DST, 1);
    1850   [ #  #  #  # ]:          0 :                 switch (split_type) {
    1851                 :          0 :                 case SPLIT_TYPE_PORT:
    1852                 :          0 :                         SET_FIELD(dmae_params.flags, DMAE_PARAMS_PORT_VALID,
    1853                 :            :                                   1);
    1854                 :          0 :                         dmae_params.port_id = port_id;
    1855                 :          0 :                         break;
    1856                 :          0 :                 case SPLIT_TYPE_PF:
    1857                 :          0 :                         SET_FIELD(dmae_params.flags,
    1858                 :            :                                   DMAE_PARAMS_SRC_PF_VALID, 1);
    1859                 :          0 :                         dmae_params.src_pf_id = pf_id;
    1860                 :          0 :                         break;
    1861                 :          0 :                 case SPLIT_TYPE_PORT_PF:
    1862                 :            :                         SET_FIELD(dmae_params.flags, DMAE_PARAMS_PORT_VALID,
    1863                 :            :                                   1);
    1864                 :          0 :                         SET_FIELD(dmae_params.flags,
    1865                 :            :                                   DMAE_PARAMS_SRC_PF_VALID, 1);
    1866                 :          0 :                         dmae_params.port_id = port_id;
    1867                 :          0 :                         dmae_params.src_pf_id = pf_id;
    1868                 :          0 :                         break;
    1869                 :            :                 default:
    1870                 :            :                         break;
    1871                 :            :                 }
    1872                 :            : 
    1873                 :            :                 /* Execute DMAE command */
    1874                 :          0 :                 read_using_dmae = !ecore_dmae_grc2host(p_hwfn,
    1875                 :            :                                                      p_ptt,
    1876                 :            :                                                      DWORDS_TO_BYTES(addr),
    1877                 :            :                                                      (u64)(uintptr_t)(dump_buf),
    1878                 :            :                                                      len, &dmae_params);
    1879         [ #  # ]:          0 :                 if (!read_using_dmae) {
    1880                 :          0 :                         dev_data->use_dmae = 0;
    1881         [ #  # ]:          0 :                         DP_VERBOSE(p_hwfn->p_dev,
    1882                 :            :                                    ECORE_MSG_DEBUG,
    1883                 :            :                                    "Failed reading from chip using DMAE, using GRC instead\n");
    1884                 :            :                 }
    1885                 :            :         }
    1886                 :            : 
    1887         [ #  # ]:          0 :         if (read_using_dmae)
    1888                 :          0 :                 goto print_log;
    1889                 :            : 
    1890                 :            :         /* If not read using DMAE, read using GRC */
    1891                 :            : 
    1892                 :            :         /* Set pretend */
    1893         [ #  # ]:          0 :         if (split_type != dev_data->pretend.split_type ||
    1894         [ #  # ]:          0 :             split_id != dev_data->pretend.split_id) {
    1895   [ #  #  #  #  :          0 :                 switch (split_type) {
                      # ]
    1896                 :          0 :                 case SPLIT_TYPE_PORT:
    1897                 :          0 :                         ecore_port_pretend(p_hwfn, p_ptt, port_id);
    1898                 :          0 :                         break;
    1899                 :          0 :                 case SPLIT_TYPE_PF:
    1900                 :            :                         fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
    1901                 :            :                                           pf_id);
    1902                 :          0 :                         ecore_fid_pretend(p_hwfn, p_ptt, fid);
    1903                 :          0 :                         break;
    1904                 :          0 :                 case SPLIT_TYPE_PORT_PF:
    1905                 :            :                         fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
    1906                 :            :                                           pf_id);
    1907                 :          0 :                         ecore_port_fid_pretend(p_hwfn, p_ptt, port_id, fid);
    1908                 :          0 :                         break;
    1909                 :          0 :                 case SPLIT_TYPE_VF:
    1910                 :          0 :                         fid = FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_VFVALID, 1)
    1911                 :          0 :                               | FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_VFID,
    1912                 :            :                                           vf_id);
    1913                 :          0 :                         ecore_fid_pretend(p_hwfn, p_ptt, fid);
    1914                 :          0 :                         break;
    1915                 :            :                 default:
    1916                 :            :                         break;
    1917                 :            :                 }
    1918                 :            : 
    1919                 :          0 :                 dev_data->pretend.split_type = (u8)split_type;
    1920                 :          0 :                 dev_data->pretend.split_id = split_id;
    1921                 :            :         }
    1922                 :            : 
    1923                 :            :         /* Read registers using GRC */
    1924                 :          0 :         qed_read_regs(p_hwfn, p_ptt, dump_buf, addr, len);
    1925                 :            : 
    1926                 :          0 : print_log:
    1927                 :            :         /* Print log */
    1928                 :          0 :         dev_data->num_regs_read += len;
    1929                 :          0 :         thresh = s_hw_type_defs[dev_data->hw_type].log_thresh;
    1930                 :          0 :         if ((dev_data->num_regs_read / thresh) >
    1931         [ #  # ]:          0 :             ((dev_data->num_regs_read - len) / thresh))
    1932         [ #  # ]:          0 :                 DP_VERBOSE(p_hwfn->p_dev,
    1933                 :            :                            ECORE_MSG_DEBUG,
    1934                 :            :                            "Dumped %d registers...\n", dev_data->num_regs_read);
    1935                 :            : 
    1936                 :            :         return len;
    1937                 :            : }
    1938                 :            : 
    1939                 :            : /* Dumps GRC registers sequence header. Returns the dumped size in dwords.
    1940                 :            :  * The addr and len arguments are specified in dwords.
    1941                 :            :  */
    1942                 :            : static u32 qed_grc_dump_reg_entry_hdr(u32 *dump_buf,
    1943                 :            :                                       bool dump, u32 addr, u32 len)
    1944                 :            : {
    1945                 :          0 :         if (dump)
    1946                 :          0 :                 *dump_buf = addr | (len << REG_DUMP_LEN_SHIFT);
    1947                 :            : 
    1948                 :            :         return 1;
    1949                 :            : }
    1950                 :            : 
    1951                 :            : /* Dumps GRC registers sequence. Returns the dumped size in dwords.
    1952                 :            :  * The addr and len arguments are specified in dwords.
    1953                 :            :  */
    1954                 :            : static u32 qed_grc_dump_reg_entry(struct ecore_hwfn *p_hwfn,
    1955                 :            :                                   struct ecore_ptt *p_ptt,
    1956                 :            :                                   u32 *dump_buf,
    1957                 :            :                                   bool dump, u32 addr, u32 len, bool wide_bus,
    1958                 :            :                                   enum init_split_types split_type, u8 split_id)
    1959                 :            : {
    1960                 :            :         u32 offset = 0;
    1961                 :            : 
    1962                 :            :         offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, len);
    1963                 :          0 :         offset += qed_grc_dump_addr_range(p_hwfn,
    1964                 :            :                                           p_ptt,
    1965                 :            :                                           dump_buf + offset,
    1966                 :            :                                           dump, addr, len, wide_bus,
    1967                 :            :                                           split_type, split_id);
    1968                 :            : 
    1969                 :            :         return offset;
    1970                 :            : }
    1971                 :            : 
    1972                 :            : /* Dumps GRC registers sequence with skip cycle.
    1973                 :            :  * Returns the dumped size in dwords.
    1974                 :            :  * - addr:      start GRC address in dwords
    1975                 :            :  * - total_len: total no. of dwords to dump
    1976                 :            :  * - read_len:  no. consecutive dwords to read
    1977                 :            :  * - skip_len:  no. of dwords to skip (and fill with zeros)
    1978                 :            :  */
    1979         [ #  # ]:          0 : static u32 qed_grc_dump_reg_entry_skip(struct ecore_hwfn *p_hwfn,
    1980                 :            :                                        struct ecore_ptt *p_ptt,
    1981                 :            :                                        u32 *dump_buf,
    1982                 :            :                                        bool dump,
    1983                 :            :                                        u32 addr,
    1984                 :            :                                        u32 total_len,
    1985                 :            :                                        u32 read_len, u32 skip_len)
    1986                 :            : {
    1987                 :            :         u32 offset = 0, reg_offset = 0;
    1988                 :            : 
    1989                 :            :         offset += qed_grc_dump_reg_entry_hdr(dump_buf, dump, addr, total_len);
    1990                 :            : 
    1991         [ #  # ]:          0 :         if (!dump)
    1992                 :          0 :                 return offset + total_len;
    1993                 :            : 
    1994         [ #  # ]:          0 :         while (reg_offset < total_len) {
    1995                 :          0 :                 u32 curr_len = OSAL_MIN_T(u32, read_len,
    1996                 :            :                                           total_len - reg_offset);
    1997                 :            : 
    1998                 :          0 :                 offset += qed_grc_dump_addr_range(p_hwfn,
    1999                 :            :                                                   p_ptt,
    2000                 :          0 :                                                   dump_buf + offset,
    2001                 :            :                                                   dump,  addr, curr_len, false,
    2002                 :            :                                                   SPLIT_TYPE_NONE, 0);
    2003                 :          0 :                 reg_offset += curr_len;
    2004                 :          0 :                 addr += curr_len;
    2005                 :            : 
    2006         [ #  # ]:          0 :                 if (reg_offset < total_len) {
    2007                 :          0 :                         curr_len = OSAL_MIN_T(u32, skip_len,
    2008                 :            :                                               total_len - skip_len);
    2009                 :          0 :                         memset(dump_buf + offset, 0, DWORDS_TO_BYTES(curr_len));
    2010                 :          0 :                         offset += curr_len;
    2011                 :          0 :                         reg_offset += curr_len;
    2012                 :          0 :                         addr += curr_len;
    2013                 :            :                 }
    2014                 :            :         }
    2015                 :            : 
    2016                 :            :         return offset;
    2017                 :            : }
    2018                 :            : 
    2019                 :            : /* Dumps GRC registers entries. Returns the dumped size in dwords. */
    2020                 :          0 : static u32 qed_grc_dump_regs_entries(struct ecore_hwfn *p_hwfn,
    2021                 :            :                                      struct ecore_ptt *p_ptt,
    2022                 :            :                                      struct virt_mem_desc input_regs_arr,
    2023                 :            :                                      u32 *dump_buf,
    2024                 :            :                                      bool dump,
    2025                 :            :                                      enum init_split_types split_type,
    2026                 :            :                                      u8 split_id,
    2027                 :            :                                      bool block_enable[MAX_BLOCK_ID],
    2028                 :            :                                      u32 *num_dumped_reg_entries)
    2029                 :            : {
    2030                 :            :         u32 i, offset = 0, input_offset = 0;
    2031                 :            :         bool mode_match = true;
    2032                 :            : 
    2033                 :          0 :         *num_dumped_reg_entries = 0;
    2034                 :            : 
    2035         [ #  # ]:          0 :         while (input_offset < BYTES_TO_DWORDS(input_regs_arr.size)) {
    2036                 :          0 :                 const struct dbg_dump_cond_hdr *cond_hdr =
    2037                 :            :                     (const struct dbg_dump_cond_hdr *)
    2038                 :          0 :                     input_regs_arr.ptr + input_offset++;
    2039                 :            :                 u16 modes_buf_offset;
    2040                 :            :                 bool eval_mode;
    2041                 :            : 
    2042                 :            :                 /* Check mode/block */
    2043                 :          0 :                 eval_mode = GET_FIELD(cond_hdr->mode.data,
    2044                 :            :                                       DBG_MODE_HDR_EVAL_MODE) > 0;
    2045         [ #  # ]:          0 :                 if (eval_mode) {
    2046                 :          0 :                         modes_buf_offset =
    2047                 :            :                                 GET_FIELD(cond_hdr->mode.data,
    2048                 :            :                                           DBG_MODE_HDR_MODES_BUF_OFFSET);
    2049                 :            :                         mode_match = qed_is_mode_match(p_hwfn,
    2050                 :            :                                                        &modes_buf_offset);
    2051                 :            :                 }
    2052                 :            : 
    2053   [ #  #  #  # ]:          0 :                 if (!mode_match || !block_enable[cond_hdr->block_id]) {
    2054                 :          0 :                         input_offset += cond_hdr->data_size;
    2055                 :          0 :                         continue;
    2056                 :            :                 }
    2057                 :            : 
    2058         [ #  # ]:          0 :                 for (i = 0; i < cond_hdr->data_size; i++, input_offset++) {
    2059                 :          0 :                         const struct dbg_dump_reg *reg =
    2060                 :            :                             (const struct dbg_dump_reg *)
    2061                 :          0 :                             input_regs_arr.ptr + input_offset;
    2062                 :            :                         u32 addr, len;
    2063                 :            :                         bool wide_bus;
    2064                 :            : 
    2065                 :          0 :                         addr = GET_FIELD(reg->data, DBG_DUMP_REG_ADDRESS);
    2066                 :          0 :                         len = GET_FIELD(reg->data, DBG_DUMP_REG_LENGTH);
    2067                 :          0 :                         wide_bus = GET_FIELD(reg->data, DBG_DUMP_REG_WIDE_BUS);
    2068                 :          0 :                         offset += qed_grc_dump_reg_entry(p_hwfn,
    2069                 :            :                                                          p_ptt,
    2070         [ #  # ]:          0 :                                                          dump_buf + offset,
    2071                 :            :                                                          dump,
    2072                 :            :                                                          addr,
    2073                 :            :                                                          len,
    2074                 :            :                                                          wide_bus,
    2075                 :            :                                                          split_type, split_id);
    2076                 :          0 :                         (*num_dumped_reg_entries)++;
    2077                 :            :                 }
    2078                 :            :         }
    2079                 :            : 
    2080                 :          0 :         return offset;
    2081                 :            : }
    2082                 :            : 
    2083                 :            : /* Dumps GRC registers entries. Returns the dumped size in dwords. */
    2084                 :          0 : static u32 qed_grc_dump_split_data(struct ecore_hwfn *p_hwfn,
    2085                 :            :                                    struct ecore_ptt *p_ptt,
    2086                 :            :                                    struct virt_mem_desc input_regs_arr,
    2087                 :            :                                    u32 *dump_buf,
    2088                 :            :                                    bool dump,
    2089                 :            :                                    bool block_enable[MAX_BLOCK_ID],
    2090                 :            :                                    enum init_split_types split_type,
    2091                 :            :                                    u8 split_id, const char *reg_type_name)
    2092                 :            : {
    2093                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2094                 :            :         enum init_split_types hdr_split_type = split_type;
    2095                 :            :         u32 num_dumped_reg_entries, offset;
    2096                 :            :         u8 hdr_split_id = split_id;
    2097                 :            : 
    2098                 :            :         /* In PORT_PF split type, print a port split header */
    2099         [ #  # ]:          0 :         if (split_type == SPLIT_TYPE_PORT_PF) {
    2100                 :            :                 hdr_split_type = SPLIT_TYPE_PORT;
    2101                 :          0 :                 hdr_split_id = split_id / dev_data->num_pfs_per_port;
    2102                 :            :         }
    2103                 :            : 
    2104                 :            :         /* Calculate register dump header size (and skip it for now) */
    2105                 :          0 :         offset = qed_grc_dump_regs_hdr(dump_buf,
    2106                 :            :                                        false,
    2107                 :            :                                        0,
    2108                 :            :                                        hdr_split_type,
    2109                 :            :                                        hdr_split_id, reg_type_name);
    2110                 :            : 
    2111                 :            :         /* Dump registers */
    2112                 :          0 :         offset += qed_grc_dump_regs_entries(p_hwfn,
    2113                 :            :                                             p_ptt,
    2114                 :            :                                             input_regs_arr,
    2115                 :          0 :                                             dump_buf + offset,
    2116                 :            :                                             dump,
    2117                 :            :                                             split_type,
    2118                 :            :                                             split_id,
    2119                 :            :                                             block_enable,
    2120                 :            :                                             &num_dumped_reg_entries);
    2121                 :            : 
    2122                 :            :         /* Write register dump header */
    2123   [ #  #  #  # ]:          0 :         if (dump && num_dumped_reg_entries > 0)
    2124                 :          0 :                 qed_grc_dump_regs_hdr(dump_buf,
    2125                 :            :                                       dump,
    2126                 :            :                                       num_dumped_reg_entries,
    2127                 :            :                                       hdr_split_type,
    2128                 :            :                                       hdr_split_id, reg_type_name);
    2129                 :            : 
    2130         [ #  # ]:          0 :         return num_dumped_reg_entries > 0 ? offset : 0;
    2131                 :            : }
    2132                 :            : 
    2133                 :            : /* Dumps registers according to the input registers array. Returns the dumped
    2134                 :            :  * size in dwords.
    2135                 :            :  */
    2136                 :          0 : static u32 qed_grc_dump_registers(struct ecore_hwfn *p_hwfn,
    2137                 :            :                                   struct ecore_ptt *p_ptt,
    2138                 :            :                                   u32 *dump_buf,
    2139                 :            :                                   bool dump,
    2140                 :            :                                   bool block_enable[MAX_BLOCK_ID],
    2141                 :            :                                   const char *reg_type_name)
    2142                 :            : {
    2143                 :            :         struct virt_mem_desc *dbg_buf =
    2144                 :            :             &p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG];
    2145                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2146                 :            :         u32 offset = 0, input_offset = 0;
    2147                 :            : 
    2148         [ #  # ]:          0 :         while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
    2149                 :            :                 const struct dbg_dump_split_hdr *split_hdr;
    2150                 :            :                 struct virt_mem_desc curr_input_regs_arr;
    2151                 :            :                 enum init_split_types split_type;
    2152                 :            :                 u16 split_count = 0;
    2153                 :            :                 u32 split_data_size;
    2154                 :            :                 u8 split_id;
    2155                 :            : 
    2156                 :          0 :                 split_hdr =
    2157                 :            :                     (const struct dbg_dump_split_hdr *)
    2158                 :          0 :                     dbg_buf->ptr + input_offset++;
    2159                 :          0 :                 split_type =
    2160                 :          0 :                     GET_FIELD(split_hdr->hdr,
    2161                 :            :                               DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
    2162                 :          0 :                 split_data_size = GET_FIELD(split_hdr->hdr,
    2163                 :            :                                             DBG_DUMP_SPLIT_HDR_DATA_SIZE);
    2164                 :          0 :                 curr_input_regs_arr.ptr =
    2165                 :          0 :                     (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr +
    2166                 :            :                     input_offset;
    2167                 :          0 :                 curr_input_regs_arr.size = DWORDS_TO_BYTES(split_data_size);
    2168                 :            : 
    2169   [ #  #  #  #  :          0 :                 switch (split_type) {
                      # ]
    2170                 :            :                 case SPLIT_TYPE_NONE:
    2171                 :            :                         split_count = 1;
    2172                 :            :                         break;
    2173                 :          0 :                 case SPLIT_TYPE_PORT:
    2174                 :          0 :                         split_count = dev_data->num_ports;
    2175                 :          0 :                         break;
    2176                 :          0 :                 case SPLIT_TYPE_PF:
    2177                 :            :                 case SPLIT_TYPE_PORT_PF:
    2178                 :          0 :                         split_count = dev_data->num_ports *
    2179                 :          0 :                             dev_data->num_pfs_per_port;
    2180                 :          0 :                         break;
    2181                 :          0 :                 case SPLIT_TYPE_VF:
    2182                 :          0 :                         split_count = dev_data->num_vfs;
    2183                 :          0 :                         break;
    2184                 :          0 :                 default:
    2185                 :          0 :                         return 0;
    2186                 :            :                 }
    2187                 :            : 
    2188         [ #  # ]:          0 :                 for (split_id = 0; split_id < split_count; split_id++)
    2189                 :          0 :                         offset += qed_grc_dump_split_data(p_hwfn, p_ptt,
    2190                 :            :                                                           curr_input_regs_arr,
    2191                 :          0 :                                                           dump_buf + offset,
    2192                 :            :                                                           dump, block_enable,
    2193                 :            :                                                           split_type,
    2194                 :            :                                                           split_id,
    2195                 :            :                                                           reg_type_name);
    2196                 :            : 
    2197                 :          0 :                 input_offset += split_data_size;
    2198                 :            :         }
    2199                 :            : 
    2200                 :            :         /* Cancel pretends (pretend to original PF) */
    2201         [ #  # ]:          0 :         if (dump) {
    2202                 :          0 :                 ecore_fid_pretend(p_hwfn, p_ptt,
    2203                 :          0 :                                 FIELD_VALUE(PXP_PRETEND_CONCRETE_FID_PFID,
    2204                 :            :                                             p_hwfn->rel_pf_id));
    2205                 :          0 :                 dev_data->pretend.split_type = SPLIT_TYPE_NONE;
    2206                 :          0 :                 dev_data->pretend.split_id = 0;
    2207                 :            :         }
    2208                 :            : 
    2209                 :            :         return offset;
    2210                 :            : }
    2211                 :            : 
    2212                 :            : /* Dump reset registers. Returns the dumped size in dwords. */
    2213                 :          0 : static u32 qed_grc_dump_reset_regs(struct ecore_hwfn *p_hwfn,
    2214                 :            :                                    struct ecore_ptt *p_ptt,
    2215                 :            :                                    u32 *dump_buf, bool dump)
    2216                 :            : {
    2217                 :            :         u32 offset = 0, num_regs = 0;
    2218                 :            :         u8 reset_reg_id;
    2219                 :            : 
    2220                 :            :         /* Calculate header size */
    2221                 :          0 :         offset += qed_grc_dump_regs_hdr(dump_buf,
    2222                 :            :                                         false,
    2223                 :            :                                         0, SPLIT_TYPE_NONE, 0, "RESET_REGS");
    2224                 :            : 
    2225                 :            :         /* Write reset registers */
    2226         [ #  # ]:          0 :         for (reset_reg_id = 0; reset_reg_id < NUM_DBG_RESET_REGS;
    2227                 :          0 :              reset_reg_id++) {
    2228                 :            :                 const struct dbg_reset_reg *reset_reg;
    2229                 :            :                 u32 reset_reg_addr;
    2230                 :            : 
    2231                 :          0 :                 reset_reg = qed_get_dbg_reset_reg(p_hwfn, reset_reg_id);
    2232                 :            : 
    2233         [ #  # ]:          0 :                 if (GET_FIELD(reset_reg->data, DBG_RESET_REG_IS_REMOVED))
    2234                 :          0 :                         continue;
    2235                 :            : 
    2236                 :          0 :                 reset_reg_addr = GET_FIELD(reset_reg->data, DBG_RESET_REG_ADDR);
    2237                 :          0 :                 offset += qed_grc_dump_reg_entry(p_hwfn,
    2238                 :            :                                                  p_ptt,
    2239         [ #  # ]:          0 :                                                  dump_buf + offset,
    2240                 :            :                                                  dump,
    2241                 :            :                                                  reset_reg_addr,
    2242                 :            :                                                  1, false, SPLIT_TYPE_NONE, 0);
    2243                 :          0 :                 num_regs++;
    2244                 :            :         }
    2245                 :            : 
    2246                 :            :         /* Write header */
    2247         [ #  # ]:          0 :         if (dump)
    2248                 :          0 :                 qed_grc_dump_regs_hdr(dump_buf,
    2249                 :            :                                       true, num_regs, SPLIT_TYPE_NONE,
    2250                 :            :                                       0, "RESET_REGS");
    2251                 :            : 
    2252                 :          0 :         return offset;
    2253                 :            : }
    2254                 :            : 
    2255                 :            : /* Dump registers that are modified during GRC Dump and therefore must be
    2256                 :            :  * dumped first. Returns the dumped size in dwords.
    2257                 :            :  */
    2258                 :          0 : static u32 qed_grc_dump_modified_regs(struct ecore_hwfn *p_hwfn,
    2259                 :            :                                       struct ecore_ptt *p_ptt,
    2260                 :            :                                       u32 *dump_buf, bool dump)
    2261                 :            : {
    2262                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2263                 :            :         u32 block_id, offset = 0, stall_regs_offset;
    2264                 :            :         const struct dbg_attn_reg *attn_reg_arr;
    2265                 :            :         u8 storm_id, reg_idx, num_attn_regs;
    2266                 :            :         u32 num_reg_entries = 0;
    2267                 :            : 
    2268                 :            :         /* Write empty header for attention registers */
    2269                 :          0 :         offset += qed_grc_dump_regs_hdr(dump_buf,
    2270                 :            :                                         false,
    2271                 :            :                                         0, SPLIT_TYPE_NONE, 0, "ATTN_REGS");
    2272                 :            : 
    2273                 :            :         /* Write parity registers */
    2274         [ #  # ]:          0 :         for (block_id = 0; block_id < NUM_PHYS_BLOCKS; block_id++) {
    2275   [ #  #  #  # ]:          0 :                 if (dev_data->block_in_reset[block_id] && dump)
    2276                 :          0 :                         continue;
    2277                 :            : 
    2278                 :            :                 attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
    2279                 :            :                                                        (enum block_id)block_id,
    2280                 :            :                                                        ATTN_TYPE_PARITY,
    2281                 :            :                                                        &num_attn_regs);
    2282                 :            : 
    2283         [ #  # ]:          0 :                 for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
    2284                 :          0 :                         const struct dbg_attn_reg *reg_data =
    2285                 :          0 :                                 &attn_reg_arr[reg_idx];
    2286                 :            :                         u16 modes_buf_offset;
    2287                 :            :                         bool eval_mode;
    2288                 :            :                         u32 addr;
    2289                 :            : 
    2290                 :            :                         /* Check mode */
    2291                 :          0 :                         eval_mode = GET_FIELD(reg_data->mode.data,
    2292                 :            :                                               DBG_MODE_HDR_EVAL_MODE) > 0;
    2293                 :          0 :                         modes_buf_offset =
    2294                 :            :                                 GET_FIELD(reg_data->mode.data,
    2295                 :            :                                           DBG_MODE_HDR_MODES_BUF_OFFSET);
    2296   [ #  #  #  # ]:          0 :                         if (eval_mode &&
    2297                 :            :                             !qed_is_mode_match(p_hwfn, &modes_buf_offset))
    2298                 :          0 :                                 continue;
    2299                 :            : 
    2300                 :            :                         /* Mode match: read & dump registers */
    2301                 :          0 :                         addr = reg_data->mask_address;
    2302                 :          0 :                         offset += qed_grc_dump_reg_entry(p_hwfn,
    2303                 :            :                                                          p_ptt,
    2304         [ #  # ]:          0 :                                                          dump_buf + offset,
    2305                 :            :                                                          dump,
    2306                 :            :                                                          addr,
    2307                 :            :                                                          1, false,
    2308                 :            :                                                          SPLIT_TYPE_NONE, 0);
    2309                 :          0 :                         addr = GET_FIELD(reg_data->data,
    2310                 :            :                                          DBG_ATTN_REG_STS_ADDRESS);
    2311                 :          0 :                         offset += qed_grc_dump_reg_entry(p_hwfn,
    2312                 :            :                                                          p_ptt,
    2313         [ #  # ]:          0 :                                                          dump_buf + offset,
    2314                 :            :                                                          dump,
    2315                 :            :                                                          addr,
    2316                 :            :                                                          1, false,
    2317                 :            :                                                          SPLIT_TYPE_NONE, 0);
    2318                 :          0 :                         num_reg_entries += 2;
    2319                 :            :                 }
    2320                 :            :         }
    2321                 :            : 
    2322                 :            :         /* Overwrite header for attention registers */
    2323         [ #  # ]:          0 :         if (dump)
    2324                 :          0 :                 qed_grc_dump_regs_hdr(dump_buf,
    2325                 :            :                                       true,
    2326                 :            :                                       num_reg_entries,
    2327                 :            :                                       SPLIT_TYPE_NONE, 0, "ATTN_REGS");
    2328                 :            : 
    2329                 :            :         /* Write empty header for stall registers */
    2330                 :            :         stall_regs_offset = offset;
    2331                 :          0 :         offset += qed_grc_dump_regs_hdr(dump_buf,
    2332                 :            :                                         false, 0, SPLIT_TYPE_NONE, 0, "REGS");
    2333                 :            : 
    2334                 :            :         /* Write Storm stall status registers */
    2335         [ #  # ]:          0 :         for (storm_id = 0, num_reg_entries = 0; storm_id < MAX_DBG_STORMS;
    2336                 :          0 :              storm_id++) {
    2337                 :          0 :                 struct storm_defs *storm = &s_storm_defs[storm_id];
    2338                 :            :                 u32 addr;
    2339                 :            : 
    2340   [ #  #  #  # ]:          0 :                 if (dev_data->block_in_reset[storm->sem_block_id] && dump)
    2341                 :          0 :                         continue;
    2342                 :            : 
    2343                 :          0 :                 addr =
    2344                 :          0 :                     BYTES_TO_DWORDS(storm->sem_fast_mem_addr +
    2345                 :            :                                     SEM_FAST_REG_STALLED);
    2346                 :          0 :                 offset += qed_grc_dump_reg_entry(p_hwfn,
    2347                 :            :                                                  p_ptt,
    2348         [ #  # ]:          0 :                                                  dump_buf + offset,
    2349                 :            :                                                  dump,
    2350                 :            :                                                  addr,
    2351                 :            :                                                  1,
    2352                 :            :                                                  false, SPLIT_TYPE_NONE, 0);
    2353                 :          0 :                 num_reg_entries++;
    2354                 :            :         }
    2355                 :            : 
    2356                 :            :         /* Overwrite header for stall registers */
    2357         [ #  # ]:          0 :         if (dump)
    2358                 :          0 :                 qed_grc_dump_regs_hdr(dump_buf + stall_regs_offset,
    2359                 :            :                                       true,
    2360                 :            :                                       num_reg_entries,
    2361                 :            :                                       SPLIT_TYPE_NONE, 0, "REGS");
    2362                 :            : 
    2363                 :          0 :         return offset;
    2364                 :            : }
    2365                 :            : 
    2366                 :            : /* Dumps registers that can't be represented in the debug arrays */
    2367                 :          0 : static u32 qed_grc_dump_special_regs(struct ecore_hwfn *p_hwfn,
    2368                 :            :                                      struct ecore_ptt *p_ptt,
    2369                 :            :                                      u32 *dump_buf, bool dump)
    2370                 :            : {
    2371                 :            :         u32 offset = 0, addr;
    2372                 :            : 
    2373                 :          0 :         offset += qed_grc_dump_regs_hdr(dump_buf,
    2374                 :            :                                         dump, 2, SPLIT_TYPE_NONE, 0, "REGS");
    2375                 :            : 
    2376                 :            :         /* Dump R/TDIF_REG_DEBUG_ERROR_INFO_SIZE (every 8'th register should be
    2377                 :            :          * skipped).
    2378                 :            :          */
    2379                 :            :         addr = BYTES_TO_DWORDS(RDIF_REG_DEBUG_ERROR_INFO);
    2380                 :          0 :         offset += qed_grc_dump_reg_entry_skip(p_hwfn,
    2381                 :            :                                               p_ptt,
    2382                 :          0 :                                               dump_buf + offset,
    2383                 :            :                                               dump,
    2384                 :            :                                               addr,
    2385                 :            :                                               RDIF_REG_DEBUG_ERROR_INFO_SIZE,
    2386                 :            :                                               7,
    2387                 :            :                                               1);
    2388                 :            :         addr = BYTES_TO_DWORDS(TDIF_REG_DEBUG_ERROR_INFO);
    2389                 :          0 :         offset +=
    2390                 :          0 :             qed_grc_dump_reg_entry_skip(p_hwfn,
    2391                 :            :                                         p_ptt,
    2392                 :          0 :                                         dump_buf + offset,
    2393                 :            :                                         dump,
    2394                 :            :                                         addr,
    2395                 :            :                                         TDIF_REG_DEBUG_ERROR_INFO_SIZE,
    2396                 :            :                                         7,
    2397                 :            :                                         1);
    2398                 :            : 
    2399                 :          0 :         return offset;
    2400                 :            : }
    2401                 :            : 
    2402                 :            : /* Dumps a GRC memory header (section and params). Returns the dumped size in
    2403                 :            :  * dwords. The following parameters are dumped:
    2404                 :            :  * - name:         dumped only if it's not NULL.
    2405                 :            :  * - addr:         in dwords, dumped only if name is NULL.
    2406                 :            :  * - len:          in dwords, always dumped.
    2407                 :            :  * - width:        dumped if it's not zero.
    2408                 :            :  * - packed:       dumped only if it's not false.
    2409                 :            :  * - mem_group:    always dumped.
    2410                 :            :  * - is_storm:     true only if the memory is related to a Storm.
    2411                 :            :  * - storm_letter: valid only if is_storm is true.
    2412                 :            :  *
    2413                 :            :  */
    2414                 :          0 : static u32 qed_grc_dump_mem_hdr(struct ecore_hwfn *p_hwfn,
    2415                 :            :                                 u32 *dump_buf,
    2416                 :            :                                 bool dump,
    2417                 :            :                                 const char *name,
    2418                 :            :                                 u32 addr,
    2419                 :            :                                 u32 len,
    2420                 :            :                                 u32 bit_width,
    2421                 :            :                                 bool packed,
    2422                 :            :                                 const char *mem_group, char storm_letter)
    2423                 :            : {
    2424                 :            :         u8 num_params = 3;
    2425                 :            :         u32 offset = 0;
    2426                 :            :         char buf[64];
    2427                 :            : 
    2428         [ #  # ]:          0 :         if (!len)
    2429                 :          0 :                 DP_NOTICE(p_hwfn, false,
    2430                 :            :                           "Unexpected GRC Dump error: dumped memory size must be non-zero\n");
    2431                 :            : 
    2432         [ #  # ]:          0 :         if (bit_width)
    2433                 :            :                 num_params++;
    2434         [ #  # ]:          0 :         if (packed)
    2435                 :          0 :                 num_params++;
    2436                 :            : 
    2437                 :            :         /* Dump section header */
    2438                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    2439                 :            :                                        dump, "grc_mem", num_params);
    2440                 :            : 
    2441         [ #  # ]:          0 :         if (name) {
    2442                 :            :                 /* Dump name */
    2443         [ #  # ]:          0 :                 if (storm_letter) {
    2444                 :            :                         strcpy(buf, "?STORM_");
    2445                 :          0 :                         buf[0] = storm_letter;
    2446                 :          0 :                         strcpy(buf + strlen(buf), name);
    2447                 :            :                 } else {
    2448                 :            :                         strcpy(buf, name);
    2449                 :            :                 }
    2450                 :            : 
    2451                 :          0 :                 offset += qed_dump_str_param(dump_buf + offset,
    2452                 :            :                                              dump, "name", buf);
    2453                 :            :         } else {
    2454                 :            :                 /* Dump address */
    2455                 :          0 :                 u32 addr_in_bytes = DWORDS_TO_BYTES(addr);
    2456                 :            : 
    2457                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    2458                 :            :                                              dump, "addr", addr_in_bytes);
    2459                 :            :         }
    2460                 :            : 
    2461                 :            :         /* Dump len */
    2462                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "len", len);
    2463                 :            : 
    2464                 :            :         /* Dump bit width */
    2465         [ #  # ]:          0 :         if (bit_width)
    2466                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    2467                 :            :                                              dump, "width", bit_width);
    2468                 :            : 
    2469                 :            :         /* Dump packed */
    2470         [ #  # ]:          0 :         if (packed)
    2471                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    2472                 :            :                                              dump, "packed", 1);
    2473                 :            : 
    2474                 :            :         /* Dump reg type */
    2475         [ #  # ]:          0 :         if (storm_letter) {
    2476                 :            :                 strcpy(buf, "?STORM_");
    2477                 :          0 :                 buf[0] = storm_letter;
    2478                 :          0 :                 strcpy(buf + strlen(buf), mem_group);
    2479                 :            :         } else {
    2480                 :            :                 strcpy(buf, mem_group);
    2481                 :            :         }
    2482                 :            : 
    2483                 :          0 :         offset += qed_dump_str_param(dump_buf + offset, dump, "type", buf);
    2484                 :            : 
    2485                 :          0 :         return offset;
    2486                 :            : }
    2487                 :            : 
    2488                 :            : /* Dumps a single GRC memory. If name is NULL, the memory is stored by address.
    2489                 :            :  * Returns the dumped size in dwords.
    2490                 :            :  * The addr and len arguments are specified in dwords.
    2491                 :            :  */
    2492                 :          0 : static u32 qed_grc_dump_mem(struct ecore_hwfn *p_hwfn,
    2493                 :            :                             struct ecore_ptt *p_ptt,
    2494                 :            :                             u32 *dump_buf,
    2495                 :            :                             bool dump,
    2496                 :            :                             const char *name,
    2497                 :            :                             u32 addr,
    2498                 :            :                             u32 len,
    2499                 :            :                             bool wide_bus,
    2500                 :            :                             u32 bit_width,
    2501                 :            :                             bool packed,
    2502                 :            :                             const char *mem_group, char storm_letter)
    2503                 :            : {
    2504                 :            :         u32 offset = 0;
    2505                 :            : 
    2506                 :          0 :         offset += qed_grc_dump_mem_hdr(p_hwfn,
    2507                 :            :                                        dump_buf + offset,
    2508                 :            :                                        dump,
    2509                 :            :                                        name,
    2510                 :            :                                        addr,
    2511                 :            :                                        len,
    2512                 :            :                                        bit_width,
    2513                 :            :                                        packed, mem_group, storm_letter);
    2514                 :          0 :         offset += qed_grc_dump_addr_range(p_hwfn,
    2515                 :            :                                           p_ptt,
    2516                 :          0 :                                           dump_buf + offset,
    2517                 :            :                                           dump, addr, len, wide_bus,
    2518                 :            :                                           SPLIT_TYPE_NONE, 0);
    2519                 :            : 
    2520                 :          0 :         return offset;
    2521                 :            : }
    2522                 :            : 
    2523                 :            : /* Dumps GRC memories entries. Returns the dumped size in dwords. */
    2524                 :          0 : static u32 qed_grc_dump_mem_entries(struct ecore_hwfn *p_hwfn,
    2525                 :            :                                     struct ecore_ptt *p_ptt,
    2526                 :            :                                     struct virt_mem_desc input_mems_arr,
    2527                 :            :                                     u32 *dump_buf, bool dump)
    2528                 :            : {
    2529                 :            :         u32 i, offset = 0, input_offset = 0;
    2530                 :            :         bool mode_match = true;
    2531                 :            : 
    2532         [ #  # ]:          0 :         while (input_offset < BYTES_TO_DWORDS(input_mems_arr.size)) {
    2533                 :            :                 const struct dbg_dump_cond_hdr *cond_hdr;
    2534                 :            :                 u16 modes_buf_offset;
    2535                 :            :                 u32 num_entries;
    2536                 :            :                 bool eval_mode;
    2537                 :            : 
    2538                 :          0 :                 cond_hdr =
    2539                 :          0 :                     (const struct dbg_dump_cond_hdr *)input_mems_arr.ptr +
    2540                 :          0 :                     input_offset++;
    2541                 :          0 :                 num_entries = cond_hdr->data_size / MEM_DUMP_ENTRY_SIZE_DWORDS;
    2542                 :            : 
    2543                 :            :                 /* Check required mode */
    2544                 :          0 :                 eval_mode = GET_FIELD(cond_hdr->mode.data,
    2545                 :            :                                       DBG_MODE_HDR_EVAL_MODE) > 0;
    2546         [ #  # ]:          0 :                 if (eval_mode) {
    2547                 :          0 :                         modes_buf_offset =
    2548                 :            :                                 GET_FIELD(cond_hdr->mode.data,
    2549                 :            :                                           DBG_MODE_HDR_MODES_BUF_OFFSET);
    2550                 :            :                         mode_match = qed_is_mode_match(p_hwfn,
    2551                 :            :                                                        &modes_buf_offset);
    2552                 :            :                 }
    2553                 :            : 
    2554         [ #  # ]:          0 :                 if (!mode_match) {
    2555                 :          0 :                         input_offset += cond_hdr->data_size;
    2556                 :          0 :                         continue;
    2557                 :            :                 }
    2558                 :            : 
    2559         [ #  # ]:          0 :                 for (i = 0; i < num_entries;
    2560                 :          0 :                      i++, input_offset += MEM_DUMP_ENTRY_SIZE_DWORDS) {
    2561                 :          0 :                         const struct dbg_dump_mem *mem =
    2562                 :            :                             (const struct dbg_dump_mem *)((u32 *)
    2563                 :            :                                                           input_mems_arr.ptr
    2564                 :          0 :                                                           + input_offset);
    2565                 :            :                         const struct dbg_block *block;
    2566                 :            :                         char storm_letter = 0;
    2567                 :            :                         u32 mem_addr, mem_len;
    2568                 :            :                         bool mem_wide_bus;
    2569                 :            :                         u8 mem_group_id;
    2570                 :            : 
    2571                 :          0 :                         mem_group_id = GET_FIELD(mem->dword0,
    2572                 :            :                                                  DBG_DUMP_MEM_MEM_GROUP_ID);
    2573         [ #  # ]:          0 :                         if (mem_group_id >= MEM_GROUPS_NUM) {
    2574                 :          0 :                                 DP_NOTICE(p_hwfn, false, "Invalid mem_group_id\n");
    2575                 :          0 :                                 return 0;
    2576                 :            :                         }
    2577                 :            : 
    2578                 :          0 :                         if (!qed_grc_is_mem_included(p_hwfn,
    2579                 :            :                                                      (enum block_id)
    2580         [ #  # ]:          0 :                                                      cond_hdr->block_id,
    2581                 :            :                                                      mem_group_id))
    2582                 :          0 :                                 continue;
    2583                 :            : 
    2584                 :          0 :                         mem_addr = GET_FIELD(mem->dword0, DBG_DUMP_MEM_ADDRESS);
    2585                 :          0 :                         mem_len = GET_FIELD(mem->dword1, DBG_DUMP_MEM_LENGTH);
    2586                 :          0 :                         mem_wide_bus = GET_FIELD(mem->dword1,
    2587                 :            :                                                  DBG_DUMP_MEM_WIDE_BUS);
    2588                 :            : 
    2589                 :            :                         block = get_dbg_block(p_hwfn,
    2590                 :            :                                               cond_hdr->block_id);
    2591                 :            : 
    2592                 :            :                         /* If memory is associated with Storm,
    2593                 :            :                          * update storm details
    2594                 :            :                          */
    2595                 :          0 :                         if (block->associated_storm_letter)
    2596                 :            :                                 storm_letter = block->associated_storm_letter;
    2597                 :            : 
    2598                 :            :                         /* Dump memory */
    2599                 :          0 :                         offset += qed_grc_dump_mem(p_hwfn,
    2600                 :            :                                                 p_ptt,
    2601                 :          0 :                                                 dump_buf + offset,
    2602                 :            :                                                 dump,
    2603                 :            :                                                 NULL,
    2604                 :            :                                                 mem_addr,
    2605                 :            :                                                 mem_len,
    2606                 :            :                                                 mem_wide_bus,
    2607                 :            :                                                 0,
    2608                 :            :                                                 false,
    2609                 :          0 :                                                 s_mem_group_names[mem_group_id],
    2610                 :            :                                                 storm_letter);
    2611                 :            :                 }
    2612                 :            :         }
    2613                 :            : 
    2614                 :            :         return offset;
    2615                 :            : }
    2616                 :            : 
    2617                 :            : /* Dumps GRC memories according to the input array dump_mem.
    2618                 :            :  * Returns the dumped size in dwords.
    2619                 :            :  */
    2620                 :          0 : static u32 qed_grc_dump_memories(struct ecore_hwfn *p_hwfn,
    2621                 :            :                                  struct ecore_ptt *p_ptt,
    2622                 :            :                                  u32 *dump_buf, bool dump)
    2623                 :            : {
    2624                 :            :         struct virt_mem_desc *dbg_buf =
    2625                 :            :             &p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_MEM];
    2626                 :            :         u32 offset = 0, input_offset = 0;
    2627                 :            : 
    2628         [ #  # ]:          0 :         while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
    2629                 :            :                 const struct dbg_dump_split_hdr *split_hdr;
    2630                 :            :                 struct virt_mem_desc curr_input_mems_arr;
    2631                 :            :                 enum init_split_types split_type;
    2632                 :            :                 u32 split_data_size;
    2633                 :            : 
    2634                 :          0 :                 split_hdr =
    2635                 :          0 :                     (const struct dbg_dump_split_hdr *)dbg_buf->ptr +
    2636                 :          0 :                     input_offset++;
    2637                 :          0 :                 split_type = GET_FIELD(split_hdr->hdr,
    2638                 :            :                                        DBG_DUMP_SPLIT_HDR_SPLIT_TYPE_ID);
    2639                 :          0 :                 split_data_size = GET_FIELD(split_hdr->hdr,
    2640                 :            :                                             DBG_DUMP_SPLIT_HDR_DATA_SIZE);
    2641                 :          0 :                 curr_input_mems_arr.ptr = (u32 *)dbg_buf->ptr + input_offset;
    2642                 :          0 :                 curr_input_mems_arr.size = DWORDS_TO_BYTES(split_data_size);
    2643                 :            : 
    2644         [ #  # ]:          0 :                 if (split_type == SPLIT_TYPE_NONE)
    2645                 :          0 :                         offset += qed_grc_dump_mem_entries(p_hwfn,
    2646                 :            :                                                            p_ptt,
    2647                 :            :                                                            curr_input_mems_arr,
    2648                 :          0 :                                                            dump_buf + offset,
    2649                 :            :                                                            dump);
    2650                 :            :                 else
    2651                 :          0 :                         DP_NOTICE(p_hwfn, false,
    2652                 :            :                                   "Dumping split memories is currently not supported\n");
    2653                 :            : 
    2654                 :          0 :                 input_offset += split_data_size;
    2655                 :            :         }
    2656                 :            : 
    2657                 :          0 :         return offset;
    2658                 :            : }
    2659                 :            : 
    2660                 :            : /* Dumps GRC context data for the specified Storm.
    2661                 :            :  * Returns the dumped size in dwords.
    2662                 :            :  * The lid_size argument is specified in quad-regs.
    2663                 :            :  */
    2664                 :          0 : static u32 qed_grc_dump_ctx_data(struct ecore_hwfn *p_hwfn,
    2665                 :            :                                  struct ecore_ptt *p_ptt,
    2666                 :            :                                  u32 *dump_buf,
    2667                 :            :                                  bool dump,
    2668                 :            :                                  const char *name,
    2669                 :            :                                  u32 num_lids,
    2670                 :            :                                  enum cm_ctx_types ctx_type, u8 storm_id)
    2671                 :            : {
    2672                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2673                 :          0 :         struct storm_defs *storm = &s_storm_defs[storm_id];
    2674                 :            :         u32 i, lid, lid_size, total_size;
    2675                 :            :         u32 rd_reg_addr, offset = 0;
    2676                 :            : 
    2677                 :            :         /* Convert quad-regs to dwords */
    2678                 :          0 :         lid_size = storm->cm_ctx_lid_sizes[dev_data->chip_id][ctx_type] * 4;
    2679                 :            : 
    2680         [ #  # ]:          0 :         if (!lid_size)
    2681                 :            :                 return 0;
    2682                 :            : 
    2683                 :          0 :         total_size = num_lids * lid_size;
    2684                 :            : 
    2685                 :          0 :         offset += qed_grc_dump_mem_hdr(p_hwfn,
    2686                 :            :                                        dump_buf + offset,
    2687                 :            :                                        dump,
    2688                 :            :                                        name,
    2689                 :            :                                        0,
    2690                 :            :                                        total_size,
    2691                 :            :                                        lid_size * 32,
    2692                 :          0 :                                        false, name, storm->letter);
    2693                 :            : 
    2694         [ #  # ]:          0 :         if (!dump)
    2695                 :          0 :                 return offset + total_size;
    2696                 :            : 
    2697                 :          0 :         rd_reg_addr = BYTES_TO_DWORDS(storm->cm_ctx_rd_addr[ctx_type]);
    2698                 :            : 
    2699                 :            :         /* Dump context data */
    2700         [ #  # ]:          0 :         for (lid = 0; lid < num_lids; lid++) {
    2701         [ #  # ]:          0 :                 for (i = 0; i < lid_size; i++) {
    2702                 :          0 :                         ecore_wr(p_hwfn,
    2703                 :          0 :                                p_ptt, storm->cm_ctx_wr_addr, (i << 9) | lid);
    2704                 :          0 :                         offset += qed_grc_dump_addr_range(p_hwfn,
    2705                 :            :                                                           p_ptt,
    2706                 :          0 :                                                           dump_buf + offset,
    2707                 :            :                                                           dump,
    2708                 :            :                                                           rd_reg_addr,
    2709                 :            :                                                           1,
    2710                 :            :                                                           false,
    2711                 :            :                                                           SPLIT_TYPE_NONE, 0);
    2712                 :            :                 }
    2713                 :            :         }
    2714                 :            : 
    2715                 :            :         return offset;
    2716                 :            : }
    2717                 :            : 
    2718                 :            : /* Dumps GRC contexts. Returns the dumped size in dwords. */
    2719                 :          0 : static u32 qed_grc_dump_ctx(struct ecore_hwfn *p_hwfn,
    2720                 :            :                             struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    2721                 :            : {
    2722                 :            :         u32 offset = 0;
    2723                 :            :         u8 storm_id;
    2724                 :            : 
    2725         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
    2726         [ #  # ]:          0 :                 if (!qed_grc_is_storm_included(p_hwfn,
    2727                 :            :                                                (enum dbg_storms)storm_id))
    2728                 :          0 :                         continue;
    2729                 :            : 
    2730                 :            :                 /* Dump Conn AG context size */
    2731                 :          0 :                 offset += qed_grc_dump_ctx_data(p_hwfn,
    2732                 :            :                                                 p_ptt,
    2733                 :          0 :                                                 dump_buf + offset,
    2734                 :            :                                                 dump,
    2735                 :            :                                                 "CONN_AG_CTX",
    2736                 :            :                                                 NUM_OF_LCIDS,
    2737                 :            :                                                 CM_CTX_CONN_AG, storm_id);
    2738                 :            : 
    2739                 :            :                 /* Dump Conn ST context size */
    2740                 :          0 :                 offset += qed_grc_dump_ctx_data(p_hwfn,
    2741                 :            :                                                 p_ptt,
    2742                 :          0 :                                                 dump_buf + offset,
    2743                 :            :                                                 dump,
    2744                 :            :                                                 "CONN_ST_CTX",
    2745                 :            :                                                 NUM_OF_LCIDS,
    2746                 :            :                                                 CM_CTX_CONN_ST, storm_id);
    2747                 :            : 
    2748                 :            :                 /* Dump Task AG context size */
    2749                 :          0 :                 offset += qed_grc_dump_ctx_data(p_hwfn,
    2750                 :            :                                                 p_ptt,
    2751                 :          0 :                                                 dump_buf + offset,
    2752                 :            :                                                 dump,
    2753                 :            :                                                 "TASK_AG_CTX",
    2754                 :            :                                                 NUM_OF_LTIDS,
    2755                 :            :                                                 CM_CTX_TASK_AG, storm_id);
    2756                 :            : 
    2757                 :            :                 /* Dump Task ST context size */
    2758                 :          0 :                 offset += qed_grc_dump_ctx_data(p_hwfn,
    2759                 :            :                                                 p_ptt,
    2760                 :          0 :                                                 dump_buf + offset,
    2761                 :            :                                                 dump,
    2762                 :            :                                                 "TASK_ST_CTX",
    2763                 :            :                                                 NUM_OF_LTIDS,
    2764                 :            :                                                 CM_CTX_TASK_ST, storm_id);
    2765                 :            :         }
    2766                 :            : 
    2767                 :          0 :         return offset;
    2768                 :            : }
    2769                 :            : 
    2770                 :            : #define VFC_STATUS_RESP_READY_BIT       0
    2771                 :            : #define VFC_STATUS_BUSY_BIT             1
    2772                 :            : #define VFC_STATUS_SENDING_CMD_BIT      2
    2773                 :            : 
    2774                 :            : #define VFC_POLLING_DELAY_MS    1
    2775                 :            : #define VFC_POLLING_COUNT               20
    2776                 :            : 
    2777                 :            : /* Reads data from VFC. Returns the number of dwords read (0 on error).
    2778                 :            :  * Sizes are specified in dwords.
    2779                 :            :  */
    2780                 :          0 : static u32 qed_grc_dump_read_from_vfc(struct ecore_hwfn *p_hwfn,
    2781                 :            :                                       struct ecore_ptt *p_ptt,
    2782                 :            :                                       struct storm_defs *storm,
    2783                 :            :                                       u32 *cmd_data,
    2784                 :            :                                       u32 cmd_size,
    2785                 :            :                                       u32 *addr_data,
    2786                 :            :                                       u32 addr_size,
    2787                 :            :                                       u32 resp_size, u32 *dump_buf)
    2788                 :            : {
    2789                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2790                 :            :         u32 vfc_status, polling_ms, polling_count = 0, i;
    2791                 :            :         u32 reg_addr, sem_base;
    2792                 :            :         bool is_ready = false;
    2793                 :            : 
    2794                 :          0 :         sem_base = storm->sem_fast_mem_addr;
    2795                 :          0 :         polling_ms = VFC_POLLING_DELAY_MS *
    2796                 :          0 :             s_hw_type_defs[dev_data->hw_type].delay_factor;
    2797                 :            : 
    2798                 :            :         /* Write VFC command */
    2799         [ #  # ]:          0 :         ARR_REG_WR(p_hwfn,
    2800                 :            :                    p_ptt,
    2801                 :            :                    sem_base + SEM_FAST_REG_VFC_DATA_WR,
    2802                 :            :                    cmd_data, cmd_size);
    2803                 :            : 
    2804                 :            :         /* Write VFC address */
    2805         [ #  # ]:          0 :         ARR_REG_WR(p_hwfn,
    2806                 :            :                    p_ptt,
    2807                 :            :                    sem_base + SEM_FAST_REG_VFC_ADDR,
    2808                 :            :                    addr_data, addr_size);
    2809                 :            : 
    2810                 :            :         /* Read response */
    2811         [ #  # ]:          0 :         for (i = 0; i < resp_size; i++) {
    2812                 :            :                 /* Poll until ready */
    2813                 :            :                 do {
    2814                 :          0 :                         reg_addr = sem_base + SEM_FAST_REG_VFC_STATUS;
    2815                 :          0 :                         qed_grc_dump_addr_range(p_hwfn,
    2816                 :            :                                                 p_ptt,
    2817                 :            :                                                 &vfc_status,
    2818                 :            :                                                 true,
    2819                 :            :                                                 BYTES_TO_DWORDS(reg_addr),
    2820                 :            :                                                 1,
    2821                 :            :                                                 false, SPLIT_TYPE_NONE, 0);
    2822                 :          0 :                         is_ready = vfc_status &
    2823                 :            :                                    OSAL_BIT(VFC_STATUS_RESP_READY_BIT);
    2824                 :            : 
    2825         [ #  # ]:          0 :                         if (!is_ready) {
    2826         [ #  # ]:          0 :                                 if (polling_count++ == VFC_POLLING_COUNT)
    2827                 :            :                                         return 0;
    2828                 :            : 
    2829                 :          0 :                                 OSAL_MSLEEP(polling_ms);
    2830                 :            :                         }
    2831         [ #  # ]:          0 :                 } while (!is_ready);
    2832                 :            : 
    2833                 :          0 :                 reg_addr = sem_base + SEM_FAST_REG_VFC_DATA_RD;
    2834                 :          0 :                 qed_grc_dump_addr_range(p_hwfn,
    2835                 :            :                                         p_ptt,
    2836                 :          0 :                                         dump_buf + i,
    2837                 :            :                                         true,
    2838                 :            :                                         BYTES_TO_DWORDS(reg_addr),
    2839                 :            :                                         1, false, SPLIT_TYPE_NONE, 0);
    2840                 :            :         }
    2841                 :            : 
    2842                 :            :         return resp_size;
    2843                 :            : }
    2844                 :            : 
    2845                 :            : /* Dump VFC CAM. Returns the dumped size in dwords. */
    2846                 :          0 : static u32 qed_grc_dump_vfc_cam(struct ecore_hwfn *p_hwfn,
    2847                 :            :                                 struct ecore_ptt *p_ptt,
    2848                 :            :                                 u32 *dump_buf, bool dump, u8 storm_id)
    2849                 :            : {
    2850                 :            :         u32 total_size = VFC_CAM_NUM_ROWS * VFC_CAM_RESP_DWORDS;
    2851                 :          0 :         struct storm_defs *storm = &s_storm_defs[storm_id];
    2852                 :            :         u32 cam_addr[VFC_CAM_ADDR_DWORDS] = { 0 };
    2853                 :          0 :         u32 cam_cmd[VFC_CAM_CMD_DWORDS] = { 0 };
    2854                 :            :         u32 row, offset = 0;
    2855                 :            : 
    2856                 :          0 :         offset += qed_grc_dump_mem_hdr(p_hwfn,
    2857                 :            :                                        dump_buf + offset,
    2858                 :            :                                        dump,
    2859                 :            :                                        "vfc_cam",
    2860                 :            :                                        0,
    2861                 :            :                                        total_size,
    2862                 :            :                                        256,
    2863                 :          0 :                                        false, "vfc_cam", storm->letter);
    2864                 :            : 
    2865         [ #  # ]:          0 :         if (!dump)
    2866                 :          0 :                 return offset + total_size;
    2867                 :            : 
    2868                 :            :         /* Prepare CAM address */
    2869                 :          0 :         SET_VAR_FIELD(cam_addr, VFC_CAM_ADDR, OP, VFC_OPCODE_CAM_RD);
    2870                 :            : 
    2871                 :            :         /* Read VFC CAM data */
    2872         [ #  # ]:          0 :         for (row = 0; row < VFC_CAM_NUM_ROWS; row++) {
    2873                 :          0 :                 SET_VAR_FIELD(cam_cmd, VFC_CAM_CMD, ROW, row);
    2874                 :          0 :                 offset += qed_grc_dump_read_from_vfc(p_hwfn,
    2875                 :            :                                                      p_ptt,
    2876                 :            :                                                      storm,
    2877                 :            :                                                      cam_cmd,
    2878                 :            :                                                      VFC_CAM_CMD_DWORDS,
    2879                 :            :                                                      cam_addr,
    2880                 :            :                                                      VFC_CAM_ADDR_DWORDS,
    2881                 :            :                                                      VFC_CAM_RESP_DWORDS,
    2882                 :          0 :                                                      dump_buf + offset);
    2883                 :            :         }
    2884                 :            : 
    2885                 :            :         return offset;
    2886                 :            : }
    2887                 :            : 
    2888                 :            : /* Dump VFC RAM. Returns the dumped size in dwords. */
    2889                 :          0 : static u32 qed_grc_dump_vfc_ram(struct ecore_hwfn *p_hwfn,
    2890                 :            :                                 struct ecore_ptt *p_ptt,
    2891                 :            :                                 u32 *dump_buf,
    2892                 :            :                                 bool dump,
    2893                 :            :                                 u8 storm_id, struct vfc_ram_defs *ram_defs)
    2894                 :            : {
    2895                 :          0 :         u32 total_size = ram_defs->num_rows * VFC_RAM_RESP_DWORDS;
    2896                 :          0 :         struct storm_defs *storm = &s_storm_defs[storm_id];
    2897                 :          0 :         u32 ram_addr[VFC_RAM_ADDR_DWORDS] = { 0 };
    2898                 :          0 :         u32 ram_cmd[VFC_RAM_CMD_DWORDS] = { 0 };
    2899                 :            :         u32 row, offset = 0;
    2900                 :            : 
    2901                 :          0 :         offset += qed_grc_dump_mem_hdr(p_hwfn,
    2902                 :            :                                        dump_buf + offset,
    2903                 :            :                                        dump,
    2904                 :            :                                        ram_defs->mem_name,
    2905                 :            :                                        0,
    2906                 :            :                                        total_size,
    2907                 :            :                                        256,
    2908                 :            :                                        false,
    2909                 :            :                                        ram_defs->type_name,
    2910                 :          0 :                                        storm->letter);
    2911                 :            : 
    2912         [ #  # ]:          0 :         if (!dump)
    2913                 :          0 :                 return offset + total_size;
    2914                 :            : 
    2915                 :            :         /* Prepare RAM address */
    2916                 :            :         SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, OP, VFC_OPCODE_RAM_RD);
    2917                 :            : 
    2918                 :            :         /* Read VFC RAM data */
    2919                 :          0 :         for (row = ram_defs->base_row;
    2920         [ #  # ]:          0 :              row < ram_defs->base_row + ram_defs->num_rows; row++) {
    2921                 :          0 :                 SET_VAR_FIELD(ram_addr, VFC_RAM_ADDR, ROW, row);
    2922                 :          0 :                 offset += qed_grc_dump_read_from_vfc(p_hwfn,
    2923                 :            :                                                      p_ptt,
    2924                 :            :                                                      storm,
    2925                 :            :                                                      ram_cmd,
    2926                 :            :                                                      VFC_RAM_CMD_DWORDS,
    2927                 :            :                                                      ram_addr,
    2928                 :            :                                                      VFC_RAM_ADDR_DWORDS,
    2929                 :            :                                                      VFC_RAM_RESP_DWORDS,
    2930                 :          0 :                                                      dump_buf + offset);
    2931                 :            :         }
    2932                 :            : 
    2933                 :            :         return offset;
    2934                 :            : }
    2935                 :            : 
    2936                 :            : /* Dumps GRC VFC data. Returns the dumped size in dwords. */
    2937                 :          0 : static u32 qed_grc_dump_vfc(struct ecore_hwfn *p_hwfn,
    2938                 :            :                             struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    2939                 :            : {
    2940                 :            :         u8 storm_id, i;
    2941                 :            :         u32 offset = 0;
    2942                 :            : 
    2943         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
    2944         [ #  # ]:          0 :                 if (!qed_grc_is_storm_included(p_hwfn,
    2945                 :          0 :                                                (enum dbg_storms)storm_id) ||
    2946         [ #  # ]:          0 :                     !s_storm_defs[storm_id].has_vfc)
    2947                 :          0 :                         continue;
    2948                 :            : 
    2949                 :            :                 /* Read CAM */
    2950                 :          0 :                 offset += qed_grc_dump_vfc_cam(p_hwfn,
    2951                 :            :                                                p_ptt,
    2952                 :          0 :                                                dump_buf + offset,
    2953                 :            :                                                dump, storm_id);
    2954                 :            : 
    2955                 :            :                 /* Read RAM */
    2956         [ #  # ]:          0 :                 for (i = 0; i < NUM_VFC_RAM_TYPES; i++)
    2957                 :          0 :                         offset += qed_grc_dump_vfc_ram(p_hwfn,
    2958                 :            :                                                        p_ptt,
    2959                 :          0 :                                                        dump_buf + offset,
    2960                 :            :                                                        dump,
    2961                 :            :                                                        storm_id,
    2962                 :          0 :                                                        &s_vfc_ram_defs[i]);
    2963                 :            :         }
    2964                 :            : 
    2965                 :          0 :         return offset;
    2966                 :            : }
    2967                 :            : 
    2968                 :            : /* Dumps GRC RSS data. Returns the dumped size in dwords. */
    2969                 :          0 : static u32 qed_grc_dump_rss(struct ecore_hwfn *p_hwfn,
    2970                 :            :                             struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    2971                 :            : {
    2972                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    2973                 :            :         u32 offset = 0;
    2974                 :            :         u8 rss_mem_id;
    2975                 :            : 
    2976         [ #  # ]:          0 :         for (rss_mem_id = 0; rss_mem_id < NUM_RSS_MEM_TYPES; rss_mem_id++) {
    2977                 :            :                 u32 rss_addr, num_entries, total_dwords;
    2978                 :            :                 struct rss_mem_defs *rss_defs;
    2979                 :            :                 u32 addr, num_dwords_to_read;
    2980                 :            :                 bool packed;
    2981                 :            : 
    2982                 :          0 :                 rss_defs = &s_rss_mem_defs[rss_mem_id];
    2983                 :          0 :                 rss_addr = rss_defs->addr;
    2984                 :          0 :                 num_entries = rss_defs->num_entries[dev_data->chip_id];
    2985                 :          0 :                 total_dwords = (num_entries * rss_defs->entry_width) / 32;
    2986                 :          0 :                 packed = (rss_defs->entry_width == 16);
    2987                 :            : 
    2988                 :          0 :                 offset += qed_grc_dump_mem_hdr(p_hwfn,
    2989                 :          0 :                                                dump_buf + offset,
    2990                 :            :                                                dump,
    2991                 :            :                                                rss_defs->mem_name,
    2992                 :            :                                                0,
    2993                 :            :                                                total_dwords,
    2994                 :            :                                                rss_defs->entry_width,
    2995                 :            :                                                packed,
    2996                 :            :                                                rss_defs->type_name, 0);
    2997                 :            : 
    2998                 :            :                 /* Dump RSS data */
    2999         [ #  # ]:          0 :                 if (!dump) {
    3000                 :          0 :                         offset += total_dwords;
    3001                 :          0 :                         continue;
    3002                 :            :                 }
    3003                 :            : 
    3004                 :            :                 addr = BYTES_TO_DWORDS(RSS_REG_RSS_RAM_DATA);
    3005         [ #  # ]:          0 :                 while (total_dwords) {
    3006                 :          0 :                         num_dwords_to_read = OSAL_MIN_T(u32,
    3007                 :            :                                                       RSS_REG_RSS_RAM_DATA_SIZE,
    3008                 :            :                                                       total_dwords);
    3009                 :          0 :                         ecore_wr(p_hwfn, p_ptt, RSS_REG_RSS_RAM_ADDR, rss_addr);
    3010                 :          0 :                         offset += qed_grc_dump_addr_range(p_hwfn,
    3011                 :            :                                                           p_ptt,
    3012                 :          0 :                                                           dump_buf + offset,
    3013                 :            :                                                           dump,
    3014                 :            :                                                           addr,
    3015                 :            :                                                           num_dwords_to_read,
    3016                 :            :                                                           false,
    3017                 :            :                                                           SPLIT_TYPE_NONE, 0);
    3018                 :          0 :                         total_dwords -= num_dwords_to_read;
    3019                 :          0 :                         rss_addr++;
    3020                 :            :                 }
    3021                 :            :         }
    3022                 :            : 
    3023                 :          0 :         return offset;
    3024                 :            : }
    3025                 :            : 
    3026                 :            : /* Dumps GRC Big RAM. Returns the dumped size in dwords. */
    3027                 :          0 : static u32 qed_grc_dump_big_ram(struct ecore_hwfn *p_hwfn,
    3028                 :            :                                 struct ecore_ptt *p_ptt,
    3029                 :            :                                 u32 *dump_buf, bool dump, u8 big_ram_id)
    3030                 :            : {
    3031                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    3032                 :            :         u32 block_size, ram_size, offset = 0, reg_val, i;
    3033                 :          0 :         char mem_name[12] = "???_BIG_RAM";
    3034                 :          0 :         char type_name[8] = "???_RAM";
    3035                 :            :         struct big_ram_defs *big_ram;
    3036                 :            : 
    3037                 :          0 :         big_ram = &s_big_ram_defs[big_ram_id];
    3038                 :          0 :         ram_size = big_ram->ram_size[dev_data->chip_id];
    3039                 :            : 
    3040                 :          0 :         reg_val = ecore_rd(p_hwfn, p_ptt, big_ram->is_256b_reg_addr);
    3041                 :            :         block_size = reg_val &
    3042                 :          0 :                      OSAL_BIT(big_ram->is_256b_bit_offset[dev_data->chip_id]) ?
    3043         [ #  # ]:          0 :                                                                      256 : 128;
    3044                 :            : 
    3045                 :          0 :         strncpy(type_name, big_ram->instance_name, BIG_RAM_NAME_LEN);
    3046                 :            :         strncpy(mem_name, big_ram->instance_name, BIG_RAM_NAME_LEN);
    3047                 :            : 
    3048                 :            :         /* Dump memory header */
    3049                 :          0 :         offset += qed_grc_dump_mem_hdr(p_hwfn,
    3050                 :            :                                        dump_buf + offset,
    3051                 :            :                                        dump,
    3052                 :            :                                        mem_name,
    3053                 :            :                                        0,
    3054                 :            :                                        ram_size,
    3055                 :            :                                        block_size * 8,
    3056                 :            :                                        false, type_name, 0);
    3057                 :            : 
    3058                 :            :         /* Read and dump Big RAM data */
    3059         [ #  # ]:          0 :         if (!dump)
    3060                 :          0 :                 return offset + ram_size;
    3061                 :            : 
    3062                 :            :         /* Dump Big RAM */
    3063         [ #  # ]:          0 :         for (i = 0; i < DIV_ROUND_UP(ram_size, BRB_REG_BIG_RAM_DATA_SIZE);
    3064                 :          0 :              i++) {
    3065                 :            :                 u32 addr, len;
    3066                 :            : 
    3067                 :          0 :                 ecore_wr(p_hwfn, p_ptt, big_ram->addr_reg_addr, i);
    3068                 :          0 :                 addr = BYTES_TO_DWORDS(big_ram->data_reg_addr);
    3069                 :            :                 len = BRB_REG_BIG_RAM_DATA_SIZE;
    3070                 :          0 :                 offset += qed_grc_dump_addr_range(p_hwfn,
    3071                 :            :                                                   p_ptt,
    3072                 :          0 :                                                   dump_buf + offset,
    3073                 :            :                                                   dump,
    3074                 :            :                                                   addr,
    3075                 :            :                                                   len,
    3076                 :            :                                                   false, SPLIT_TYPE_NONE, 0);
    3077                 :            :         }
    3078                 :            : 
    3079                 :            :         return offset;
    3080                 :            : }
    3081                 :            : 
    3082                 :            : /* Dumps MCP scratchpad. Returns the dumped size in dwords. */
    3083                 :          0 : static u32 qed_grc_dump_mcp(struct ecore_hwfn *p_hwfn,
    3084                 :            :                             struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    3085                 :            : {
    3086                 :          0 :         bool block_enable[MAX_BLOCK_ID] = { 0 };
    3087                 :            :         u32 offset = 0, addr;
    3088                 :            :         bool halted = false;
    3089                 :            : 
    3090                 :            :         /* Halt MCP */
    3091   [ #  #  #  # ]:          0 :         if (dump && !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
    3092                 :          0 :                 halted = !ecore_mcp_halt(p_hwfn, p_ptt);
    3093         [ #  # ]:          0 :                 if (!halted)
    3094                 :          0 :                         DP_NOTICE(p_hwfn, false, "MCP halt failed!\n");
    3095                 :            :         }
    3096                 :            : 
    3097                 :            :         /* Dump MCP scratchpad */
    3098                 :          0 :         offset += qed_grc_dump_mem(p_hwfn,
    3099                 :            :                                    p_ptt,
    3100                 :            :                                    dump_buf + offset,
    3101                 :            :                                    dump,
    3102                 :            :                                    NULL,
    3103                 :            :                                    BYTES_TO_DWORDS(MCP_REG_SCRATCH),
    3104                 :            :                                    MCP_REG_SCRATCH_SIZE,
    3105                 :            :                                    false, 0, false, "MCP", 0);
    3106                 :            : 
    3107                 :            :         /* Dump MCP cpu_reg_file */
    3108                 :          0 :         offset += qed_grc_dump_mem(p_hwfn,
    3109                 :            :                                    p_ptt,
    3110                 :          0 :                                    dump_buf + offset,
    3111                 :            :                                    dump,
    3112                 :            :                                    NULL,
    3113                 :            :                                    BYTES_TO_DWORDS(MCP_REG_CPU_REG_FILE),
    3114                 :            :                                    MCP_REG_CPU_REG_FILE_SIZE,
    3115                 :            :                                    false, 0, false, "MCP", 0);
    3116                 :            : 
    3117                 :            :         /* Dump MCP registers */
    3118                 :          0 :         block_enable[BLOCK_MCP] = true;
    3119                 :          0 :         offset += qed_grc_dump_registers(p_hwfn,
    3120                 :            :                                          p_ptt,
    3121                 :          0 :                                          dump_buf + offset,
    3122                 :            :                                          dump, block_enable, "MCP");
    3123                 :            : 
    3124                 :            :         /* Dump required non-MCP registers */
    3125                 :          0 :         offset += qed_grc_dump_regs_hdr(dump_buf + offset,
    3126                 :            :                                         dump, 1, SPLIT_TYPE_NONE, 0,
    3127                 :            :                                         "MCP");
    3128                 :            :         addr = BYTES_TO_DWORDS(MISC_REG_SHARED_MEM_ADDR);
    3129                 :          0 :         offset += qed_grc_dump_reg_entry(p_hwfn,
    3130                 :            :                                          p_ptt,
    3131         [ #  # ]:          0 :                                          dump_buf + offset,
    3132                 :            :                                          dump,
    3133                 :            :                                          addr,
    3134                 :            :                                          1,
    3135                 :            :                                          false, SPLIT_TYPE_NONE, 0);
    3136                 :            : 
    3137                 :            :         /* Release MCP */
    3138   [ #  #  #  # ]:          0 :         if (halted && ecore_mcp_resume(p_hwfn, p_ptt))
    3139                 :          0 :                 DP_NOTICE(p_hwfn, false, "Failed to resume MCP after halt!\n");
    3140                 :            : 
    3141                 :          0 :         return offset;
    3142                 :            : }
    3143                 :            : 
    3144                 :            : /* Dumps the tbus indirect memory for all PHYs.
    3145                 :            :  * Returns the dumped size in dwords.
    3146                 :            :  */
    3147                 :          0 : static u32 qed_grc_dump_phy(struct ecore_hwfn *p_hwfn,
    3148                 :            :                             struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    3149                 :            : {
    3150                 :            :         u32 offset = 0, tbus_lo_offset, tbus_hi_offset;
    3151                 :            :         char mem_name[32];
    3152                 :            :         u8 phy_id;
    3153                 :            : 
    3154         [ #  # ]:          0 :         for (phy_id = 0; phy_id < OSAL_ARRAY_SIZE(s_phy_defs); phy_id++) {
    3155                 :            :                 u32 addr_lo_addr, addr_hi_addr, data_lo_addr, data_hi_addr;
    3156                 :            :                 struct phy_defs *phy_defs;
    3157                 :            :                 u8 *bytes_buf;
    3158                 :            : 
    3159                 :          0 :                 phy_defs = &s_phy_defs[phy_id];
    3160                 :          0 :                 addr_lo_addr = phy_defs->base_addr +
    3161                 :          0 :                                phy_defs->tbus_addr_lo_addr;
    3162                 :          0 :                 addr_hi_addr = phy_defs->base_addr +
    3163                 :          0 :                                phy_defs->tbus_addr_hi_addr;
    3164                 :          0 :                 data_lo_addr = phy_defs->base_addr +
    3165                 :          0 :                                phy_defs->tbus_data_lo_addr;
    3166                 :          0 :                 data_hi_addr = phy_defs->base_addr +
    3167                 :          0 :                                phy_defs->tbus_data_hi_addr;
    3168                 :            : 
    3169         [ #  # ]:          0 :                 if (snprintf(mem_name, sizeof(mem_name), "tbus_%s",
    3170                 :            :                              phy_defs->phy_name) < 0)
    3171                 :          0 :                         DP_NOTICE(p_hwfn, false,
    3172                 :            :                                   "Unexpected debug error: invalid PHY memory name\n");
    3173                 :            : 
    3174                 :          0 :                 offset += qed_grc_dump_mem_hdr(p_hwfn,
    3175                 :          0 :                                                dump_buf + offset,
    3176                 :            :                                                dump,
    3177                 :            :                                                mem_name,
    3178                 :            :                                                0,
    3179                 :            :                                                PHY_DUMP_SIZE_DWORDS,
    3180                 :            :                                                16, true, mem_name, 0);
    3181                 :            : 
    3182         [ #  # ]:          0 :                 if (!dump) {
    3183                 :          0 :                         offset += PHY_DUMP_SIZE_DWORDS;
    3184                 :          0 :                         continue;
    3185                 :            :                 }
    3186                 :            : 
    3187                 :          0 :                 bytes_buf = (u8 *)(dump_buf + offset);
    3188                 :          0 :                 for (tbus_hi_offset = 0;
    3189         [ #  # ]:          0 :                      tbus_hi_offset < (NUM_PHY_TBUS_ADDRESSES >> 8);
    3190                 :          0 :                      tbus_hi_offset++) {
    3191                 :          0 :                         ecore_wr(p_hwfn, p_ptt, addr_hi_addr, tbus_hi_offset);
    3192         [ #  # ]:          0 :                         for (tbus_lo_offset = 0; tbus_lo_offset < 256;
    3193                 :          0 :                              tbus_lo_offset++) {
    3194                 :          0 :                                 ecore_wr(p_hwfn,
    3195                 :            :                                        p_ptt, addr_lo_addr, tbus_lo_offset);
    3196                 :          0 :                                 *(bytes_buf++) = (u8)ecore_rd(p_hwfn,
    3197                 :            :                                                             p_ptt,
    3198                 :            :                                                             data_lo_addr);
    3199                 :          0 :                                 *(bytes_buf++) = (u8)ecore_rd(p_hwfn,
    3200                 :            :                                                             p_ptt,
    3201                 :            :                                                             data_hi_addr);
    3202                 :            :                         }
    3203                 :            :                 }
    3204                 :            : 
    3205                 :          0 :                 offset += PHY_DUMP_SIZE_DWORDS;
    3206                 :            :         }
    3207                 :            : 
    3208                 :          0 :         return offset;
    3209                 :            : }
    3210                 :            : 
    3211                 :            : static enum dbg_status qed_find_nvram_image(struct ecore_hwfn *p_hwfn,
    3212                 :            :                                             struct ecore_ptt *p_ptt,
    3213                 :            :                                             u32 image_type,
    3214                 :            :                                             u32 *nvram_offset_bytes,
    3215                 :            :                                             u32 *nvram_size_bytes);
    3216                 :            : 
    3217                 :            : static enum dbg_status qed_nvram_read(struct ecore_hwfn *p_hwfn,
    3218                 :            :                                       struct ecore_ptt *p_ptt,
    3219                 :            :                                       u32 nvram_offset_bytes,
    3220                 :            :                                       u32 nvram_size_bytes, u32 *ret_buf);
    3221                 :            : 
    3222                 :            : /* Dumps the MCP HW dump from NVRAM. Returns the dumped size in dwords. */
    3223                 :          0 : static u32 qed_grc_dump_mcp_hw_dump(struct ecore_hwfn *p_hwfn,
    3224                 :            :                                     struct ecore_ptt *p_ptt,
    3225                 :            :                                     u32 *dump_buf, bool dump)
    3226                 :            : {
    3227                 :          0 :         u32 hw_dump_offset_bytes = 0, hw_dump_size_bytes = 0;
    3228                 :            :         u32 hw_dump_size_dwords = 0, offset = 0;
    3229                 :            :         enum dbg_status status;
    3230                 :            : 
    3231                 :            :         /* Read HW dump image from NVRAM */
    3232                 :          0 :         status = qed_find_nvram_image(p_hwfn,
    3233                 :            :                                       p_ptt,
    3234                 :            :                                       NVM_TYPE_HW_DUMP_OUT,
    3235                 :            :                                       &hw_dump_offset_bytes,
    3236                 :            :                                       &hw_dump_size_bytes);
    3237         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    3238                 :            :                 return 0;
    3239                 :            : 
    3240                 :          0 :         hw_dump_size_dwords = BYTES_TO_DWORDS(hw_dump_size_bytes);
    3241                 :            : 
    3242                 :            :         /* Dump HW dump image section */
    3243                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    3244                 :            :                                        dump, "mcp_hw_dump", 1);
    3245                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    3246                 :            :                                      dump, "size", hw_dump_size_dwords);
    3247                 :            : 
    3248                 :            :         /* Read MCP HW dump image into dump buffer */
    3249         [ #  # ]:          0 :         if (dump && hw_dump_size_dwords) {
    3250                 :          0 :                 status = qed_nvram_read(p_hwfn,
    3251                 :            :                                         p_ptt,
    3252                 :            :                                         hw_dump_offset_bytes,
    3253                 :          0 :                                         hw_dump_size_bytes, dump_buf + offset);
    3254         [ #  # ]:          0 :                 if (status != DBG_STATUS_OK) {
    3255                 :          0 :                         DP_NOTICE(p_hwfn, false,
    3256                 :            :                                   "Failed to read MCP HW Dump image from NVRAM\n");
    3257                 :          0 :                         return 0;
    3258                 :            :                 }
    3259                 :            :         }
    3260                 :          0 :         offset += hw_dump_size_dwords;
    3261                 :            : 
    3262                 :          0 :         return offset;
    3263                 :            : }
    3264                 :            : 
    3265                 :            : /* Dumps Static Debug data. Returns the dumped size in dwords. */
    3266                 :          0 : static u32 qed_grc_dump_static_debug(struct ecore_hwfn *p_hwfn,
    3267                 :            :                                      struct ecore_ptt *p_ptt,
    3268                 :            :                                      u32 *dump_buf, bool dump)
    3269                 :            : {
    3270                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    3271                 :            :         u32 block_id, line_id, offset = 0, addr, len;
    3272                 :            : 
    3273                 :            :         /* Don't dump static debug if a debug bus recording is in progress */
    3274   [ #  #  #  # ]:          0 :         if (dump && ecore_rd(p_hwfn, p_ptt, DBG_REG_DBG_BLOCK_ON))
    3275                 :            :                 return 0;
    3276                 :            : 
    3277         [ #  # ]:          0 :         if (dump) {
    3278                 :            :                 /* Disable debug bus in all blocks */
    3279                 :          0 :                 qed_bus_disable_blocks(p_hwfn, p_ptt);
    3280                 :            : 
    3281                 :          0 :                 qed_bus_reset_dbg_block(p_hwfn, p_ptt);
    3282                 :          0 :                 ecore_wr(p_hwfn,
    3283                 :            :                        p_ptt, DBG_REG_FRAMING_MODE, DBG_BUS_FRAME_MODE_8HW);
    3284                 :          0 :                 ecore_wr(p_hwfn,
    3285                 :            :                        p_ptt, DBG_REG_DEBUG_TARGET, DBG_BUS_TARGET_ID_INT_BUF);
    3286                 :          0 :                 ecore_wr(p_hwfn, p_ptt, DBG_REG_FULL_MODE, 1);
    3287                 :            :                 qed_bus_enable_dbg_block(p_hwfn, p_ptt, true);
    3288                 :            :         }
    3289                 :            : 
    3290                 :            :         /* Dump all static debug lines for each relevant block */
    3291         [ #  # ]:          0 :         for (block_id = 0; block_id < MAX_BLOCK_ID; block_id++) {
    3292                 :            :                 const struct dbg_block_chip *block_per_chip;
    3293                 :            :                 const struct dbg_block *block;
    3294                 :            :                 bool is_removed, has_dbg_bus;
    3295                 :            :                 u16 modes_buf_offset;
    3296                 :            :                 u32 block_dwords;
    3297                 :            : 
    3298                 :            :                 block_per_chip =
    3299                 :            :                     qed_get_dbg_block_per_chip(p_hwfn, (enum block_id)block_id);
    3300                 :          0 :                 is_removed = GET_FIELD(block_per_chip->flags,
    3301                 :            :                                        DBG_BLOCK_CHIP_IS_REMOVED);
    3302                 :          0 :                 has_dbg_bus = GET_FIELD(block_per_chip->flags,
    3303                 :            :                                         DBG_BLOCK_CHIP_HAS_DBG_BUS);
    3304                 :            : 
    3305                 :            :                 /* read+clear for NWS parity is not working, skip NWS block */
    3306         [ #  # ]:          0 :                 if (block_id == BLOCK_NWS)
    3307                 :          0 :                         continue;
    3308                 :            : 
    3309         [ #  # ]:          0 :                 if (!is_removed && has_dbg_bus &&
    3310         [ #  # ]:          0 :                     GET_FIELD(block_per_chip->dbg_bus_mode.data,
    3311                 :            :                               DBG_MODE_HDR_EVAL_MODE) > 0) {
    3312                 :          0 :                         modes_buf_offset =
    3313                 :            :                             GET_FIELD(block_per_chip->dbg_bus_mode.data,
    3314                 :            :                                       DBG_MODE_HDR_MODES_BUF_OFFSET);
    3315         [ #  # ]:          0 :                         if (!qed_is_mode_match(p_hwfn, &modes_buf_offset))
    3316                 :            :                                 has_dbg_bus = false;
    3317                 :            :                 }
    3318                 :            : 
    3319         [ #  # ]:          0 :                 if (is_removed || !has_dbg_bus)
    3320                 :          0 :                         continue;
    3321                 :            : 
    3322         [ #  # ]:          0 :                 block_dwords = NUM_DBG_LINES(block_per_chip) *
    3323                 :            :                                STATIC_DEBUG_LINE_DWORDS;
    3324                 :            : 
    3325                 :            :                 /* Dump static section params */
    3326                 :            :                 block = get_dbg_block(p_hwfn, (enum block_id)block_id);
    3327                 :          0 :                 offset += qed_grc_dump_mem_hdr(p_hwfn,
    3328                 :          0 :                                                dump_buf + offset,
    3329                 :            :                                                dump,
    3330                 :          0 :                                                (const char *)block->name,
    3331                 :            :                                                0,
    3332                 :            :                                                block_dwords,
    3333                 :            :                                                32, false, "STATIC", 0);
    3334                 :            : 
    3335         [ #  # ]:          0 :                 if (!dump) {
    3336                 :          0 :                         offset += block_dwords;
    3337                 :          0 :                         continue;
    3338                 :            :                 }
    3339                 :            : 
    3340                 :            :                 /* If all lines are invalid - dump zeros */
    3341         [ #  # ]:          0 :                 if (dev_data->block_in_reset[block_id]) {
    3342                 :          0 :                         memset(dump_buf + offset, 0,
    3343                 :            :                                DWORDS_TO_BYTES(block_dwords));
    3344                 :          0 :                         offset += block_dwords;
    3345                 :          0 :                         continue;
    3346                 :            :                 }
    3347                 :            : 
    3348                 :            :                 /* Enable block's client */
    3349                 :          0 :                 qed_bus_enable_clients(p_hwfn,
    3350                 :            :                                        p_ptt,
    3351                 :          0 :                                        OSAL_BIT(block_per_chip->dbg_client_id));
    3352                 :            : 
    3353                 :            :                 addr = BYTES_TO_DWORDS(DBG_REG_CALENDAR_OUT_DATA);
    3354                 :            :                 len = STATIC_DEBUG_LINE_DWORDS;
    3355   [ #  #  #  # ]:          0 :                 for (line_id = 0; line_id < (u32)NUM_DBG_LINES(block_per_chip);
    3356                 :          0 :                      line_id++) {
    3357                 :            :                         /* Configure debug line ID */
    3358                 :          0 :                         qed_bus_config_dbg_line(p_hwfn,
    3359                 :            :                                                 p_ptt,
    3360                 :            :                                                 (enum block_id)block_id,
    3361                 :            :                                                 (u8)line_id, 0xf, 0, 0, 0);
    3362                 :            : 
    3363                 :            :                         /* Read debug line info */
    3364                 :          0 :                         offset += qed_grc_dump_addr_range(p_hwfn,
    3365                 :            :                                                           p_ptt,
    3366                 :          0 :                                                           dump_buf + offset,
    3367                 :            :                                                           dump,
    3368                 :            :                                                           addr,
    3369                 :            :                                                           len,
    3370                 :            :                                                           true, SPLIT_TYPE_NONE,
    3371                 :            :                                                           0);
    3372                 :            :                 }
    3373                 :            : 
    3374                 :            :                 /* Disable block's client and debug output */
    3375                 :            :                 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
    3376                 :          0 :                 qed_bus_config_dbg_line(p_hwfn, p_ptt,
    3377                 :            :                                         (enum block_id)block_id, 0, 0, 0, 0, 0);
    3378                 :            :         }
    3379                 :            : 
    3380         [ #  # ]:          0 :         if (dump) {
    3381                 :            :                 qed_bus_enable_dbg_block(p_hwfn, p_ptt, false);
    3382                 :            :                 qed_bus_enable_clients(p_hwfn, p_ptt, 0);
    3383                 :            :         }
    3384                 :            : 
    3385                 :            :         return offset;
    3386                 :            : }
    3387                 :            : 
    3388                 :            : /* Performs GRC Dump to the specified buffer.
    3389                 :            :  * Returns the dumped size in dwords.
    3390                 :            :  */
    3391                 :          0 : static enum dbg_status qed_grc_dump(struct ecore_hwfn *p_hwfn,
    3392                 :            :                                     struct ecore_ptt *p_ptt,
    3393                 :            :                                     u32 *dump_buf,
    3394                 :            :                                     bool dump, u32 *num_dumped_dwords)
    3395                 :            : {
    3396                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    3397                 :            :         u32 dwords_read, offset = 0;
    3398                 :            :         bool parities_masked = false;
    3399                 :            :         u8 i;
    3400                 :            : 
    3401                 :          0 :         *num_dumped_dwords = 0;
    3402                 :          0 :         dev_data->num_regs_read = 0;
    3403                 :            : 
    3404                 :            :         /* Update reset state */
    3405         [ #  # ]:          0 :         if (dump)
    3406                 :          0 :                 qed_update_blocks_reset_state(p_hwfn, p_ptt);
    3407                 :            : 
    3408                 :            :         /* Dump global params */
    3409                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    3410                 :            :                                                 p_ptt,
    3411                 :            :                                                 dump_buf + offset, dump, 4);
    3412                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    3413                 :            :                                      dump, "dump-type", "grc-dump");
    3414                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    3415                 :            :                                      dump,
    3416                 :            :                                      "num-lcids",
    3417                 :            :                                      NUM_OF_LCIDS);
    3418                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    3419                 :            :                                      dump,
    3420                 :            :                                      "num-ltids",
    3421                 :            :                                      NUM_OF_LTIDS);
    3422                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    3423                 :          0 :                                      dump, "num-ports", dev_data->num_ports);
    3424                 :            : 
    3425                 :            :         /* Dump reset registers (dumped before taking blocks out of reset ) */
    3426         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
    3427                 :          0 :                 offset += qed_grc_dump_reset_regs(p_hwfn,
    3428                 :            :                                                   p_ptt,
    3429                 :          0 :                                                   dump_buf + offset, dump);
    3430                 :            : 
    3431                 :            :         /* Take all blocks out of reset (using reset registers) */
    3432         [ #  # ]:          0 :         if (dump) {
    3433                 :          0 :                 qed_grc_unreset_blocks(p_hwfn, p_ptt, false);
    3434                 :          0 :                 qed_update_blocks_reset_state(p_hwfn, p_ptt);
    3435                 :            :         }
    3436                 :            : 
    3437                 :            :         /* Disable all parities using MFW command */
    3438   [ #  #  #  # ]:          0 :         if (dump &&
    3439                 :            :             !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP)) {
    3440                 :          0 :                 parities_masked = !ecore_mcp_mask_parities(p_hwfn, p_ptt, 1);
    3441         [ #  # ]:          0 :                 if (!parities_masked) {
    3442                 :          0 :                         DP_NOTICE(p_hwfn, false,
    3443                 :            :                                   "Failed to mask parities using MFW\n");
    3444         [ #  # ]:          0 :                         if (qed_grc_get_param
    3445                 :            :                             (p_hwfn, DBG_GRC_PARAM_PARITY_SAFE))
    3446                 :            :                                 return DBG_STATUS_MCP_COULD_NOT_MASK_PRTY;
    3447                 :            :                 }
    3448                 :            :         }
    3449                 :            : 
    3450                 :            :         /* Dump modified registers (dumped before modifying them) */
    3451         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS))
    3452                 :          0 :                 offset += qed_grc_dump_modified_regs(p_hwfn,
    3453                 :            :                                                      p_ptt,
    3454                 :          0 :                                                      dump_buf + offset, dump);
    3455                 :            : 
    3456                 :            :         /* Stall storms */
    3457   [ #  #  #  # ]:          0 :         if (dump &&
    3458                 :            :             (qed_grc_is_included(p_hwfn,
    3459         [ #  # ]:          0 :                                  DBG_GRC_PARAM_DUMP_IOR) ||
    3460                 :            :              qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC)))
    3461                 :          0 :                 qed_grc_stall_storms(p_hwfn, p_ptt, true);
    3462                 :            : 
    3463                 :            :         /* Dump all regs  */
    3464         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_REGS)) {
    3465                 :            :                 bool block_enable[MAX_BLOCK_ID];
    3466                 :            : 
    3467                 :            :                 /* Dump all blocks except MCP */
    3468         [ #  # ]:          0 :                 for (i = 0; i < MAX_BLOCK_ID; i++)
    3469                 :          0 :                         block_enable[i] = true;
    3470                 :          0 :                 block_enable[BLOCK_MCP] = false;
    3471                 :          0 :                 offset += qed_grc_dump_registers(p_hwfn,
    3472                 :            :                                                  p_ptt,
    3473                 :          0 :                                                  dump_buf +
    3474                 :            :                                                  offset,
    3475                 :            :                                                  dump,
    3476                 :            :                                                  block_enable, NULL);
    3477                 :            : 
    3478                 :            :                 /* Dump special registers */
    3479                 :          0 :                 offset += qed_grc_dump_special_regs(p_hwfn,
    3480                 :            :                                                     p_ptt,
    3481                 :          0 :                                                     dump_buf + offset, dump);
    3482                 :            :         }
    3483                 :            : 
    3484                 :            :         /* Dump memories */
    3485                 :          0 :         offset += qed_grc_dump_memories(p_hwfn, p_ptt, dump_buf + offset, dump);
    3486                 :            : 
    3487                 :            :         /* Dump MCP */
    3488         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MCP))
    3489                 :          0 :                 offset += qed_grc_dump_mcp(p_hwfn,
    3490                 :          0 :                                            p_ptt, dump_buf + offset, dump);
    3491                 :            : 
    3492                 :            :         /* Dump context */
    3493         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_CM_CTX))
    3494                 :          0 :                 offset += qed_grc_dump_ctx(p_hwfn,
    3495                 :          0 :                                            p_ptt, dump_buf + offset, dump);
    3496                 :            : 
    3497                 :            :         /* Dump RSS memories */
    3498         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_RSS))
    3499                 :          0 :                 offset += qed_grc_dump_rss(p_hwfn,
    3500                 :          0 :                                            p_ptt, dump_buf + offset, dump);
    3501                 :            : 
    3502                 :            :         /* Dump Big RAM */
    3503         [ #  # ]:          0 :         for (i = 0; i < NUM_BIG_RAM_TYPES; i++)
    3504         [ #  # ]:          0 :                 if (qed_grc_is_included(p_hwfn, s_big_ram_defs[i].grc_param))
    3505                 :          0 :                         offset += qed_grc_dump_big_ram(p_hwfn,
    3506                 :            :                                                        p_ptt,
    3507                 :          0 :                                                        dump_buf + offset,
    3508                 :            :                                                        dump, i);
    3509                 :            : 
    3510                 :            :         /* Dump VFC */
    3511         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_VFC)) {
    3512                 :          0 :                 dwords_read = qed_grc_dump_vfc(p_hwfn,
    3513                 :          0 :                                                p_ptt, dump_buf + offset, dump);
    3514                 :          0 :                 offset += dwords_read;
    3515         [ #  # ]:          0 :                 if (!dwords_read)
    3516                 :            :                         return DBG_STATUS_VFC_READ_ERROR;
    3517                 :            :         }
    3518                 :            : 
    3519                 :            :         /* Dump PHY tbus */
    3520         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn,
    3521                 :            :                                 DBG_GRC_PARAM_DUMP_PHY) && dev_data->chip_id ==
    3522         [ #  # ]:          0 :             CHIP_K2 && dev_data->hw_type == HW_TYPE_ASIC)
    3523                 :          0 :                 offset += qed_grc_dump_phy(p_hwfn,
    3524                 :          0 :                                            p_ptt, dump_buf + offset, dump);
    3525                 :            : 
    3526                 :            :         /* Dump MCP HW Dump */
    3527   [ #  #  #  # ]:          0 :         if (qed_grc_is_included(p_hwfn, DBG_GRC_PARAM_DUMP_MCP_HW_DUMP) &&
    3528                 :            :             !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP))
    3529                 :          0 :                 offset += qed_grc_dump_mcp_hw_dump(p_hwfn,
    3530                 :            :                                                    p_ptt,
    3531                 :          0 :                                                    dump_buf + offset, dump);
    3532                 :            : 
    3533                 :            :         /* Dump static debug data (only if not during debug bus recording) */
    3534         [ #  # ]:          0 :         if (qed_grc_is_included(p_hwfn,
    3535         [ #  # ]:          0 :                                 DBG_GRC_PARAM_DUMP_STATIC) &&
    3536         [ #  # ]:          0 :             (!dump || dev_data->bus.state == DBG_BUS_STATE_IDLE))
    3537                 :          0 :                 offset += qed_grc_dump_static_debug(p_hwfn,
    3538                 :            :                                                     p_ptt,
    3539                 :          0 :                                                     dump_buf + offset, dump);
    3540                 :            : 
    3541                 :            :         /* Dump last section */
    3542                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    3543                 :            : 
    3544         [ #  # ]:          0 :         if (dump) {
    3545                 :            :                 /* Unstall storms */
    3546         [ #  # ]:          0 :                 if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_UNSTALL))
    3547                 :          0 :                         qed_grc_stall_storms(p_hwfn, p_ptt, false);
    3548                 :            : 
    3549                 :            :                 /* Clear parity status */
    3550                 :          0 :                 qed_grc_clear_all_prty(p_hwfn, p_ptt);
    3551                 :            : 
    3552                 :            :                 /* Enable all parities using MFW command */
    3553         [ #  # ]:          0 :                 if (parities_masked)
    3554                 :          0 :                         ecore_mcp_mask_parities(p_hwfn, p_ptt, 0);
    3555                 :            :         }
    3556                 :            : 
    3557                 :          0 :         *num_dumped_dwords = offset;
    3558                 :            : 
    3559                 :          0 :         return DBG_STATUS_OK;
    3560                 :            : }
    3561                 :            : 
    3562                 :            : /* Writes the specified failing Idle Check rule to the specified buffer.
    3563                 :            :  * Returns the dumped size in dwords.
    3564                 :            :  */
    3565                 :          0 : static u32 qed_idle_chk_dump_failure(struct ecore_hwfn *p_hwfn,
    3566                 :            :                                      struct ecore_ptt *p_ptt,
    3567                 :            :                                      u32 *
    3568                 :            :                                      dump_buf,
    3569                 :            :                                      bool dump,
    3570                 :            :                                      u16 rule_id,
    3571                 :            :                                      const struct dbg_idle_chk_rule *rule,
    3572                 :            :                                      u16 fail_entry_id, u32 *cond_reg_values)
    3573                 :            : {
    3574                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    3575                 :            :         const struct dbg_idle_chk_cond_reg *cond_regs;
    3576                 :            :         const struct dbg_idle_chk_info_reg *info_regs;
    3577                 :            :         u32 i, next_reg_offset = 0, offset = 0;
    3578                 :            :         struct dbg_idle_chk_result_hdr *hdr;
    3579                 :            :         const union dbg_idle_chk_reg *regs;
    3580                 :            :         u8 reg_id;
    3581                 :            : 
    3582                 :            :         hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
    3583                 :          0 :         regs = (const union dbg_idle_chk_reg *)
    3584                 :          0 :                 p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr +
    3585                 :          0 :                 rule->reg_offset;
    3586                 :          0 :         cond_regs = &regs[0].cond_reg;
    3587                 :          0 :         info_regs = &regs[rule->num_cond_regs].info_reg;
    3588                 :            : 
    3589                 :            :         /* Dump rule data */
    3590         [ #  # ]:          0 :         if (dump) {
    3591                 :            :                 memset(hdr, 0, sizeof(*hdr));
    3592                 :          0 :                 hdr->rule_id = rule_id;
    3593                 :          0 :                 hdr->mem_entry_id = fail_entry_id;
    3594                 :          0 :                 hdr->severity = rule->severity;
    3595                 :          0 :                 hdr->num_dumped_cond_regs = rule->num_cond_regs;
    3596                 :            :         }
    3597                 :            : 
    3598                 :            :         offset += IDLE_CHK_RESULT_HDR_DWORDS;
    3599                 :            : 
    3600                 :            :         /* Dump condition register values */
    3601         [ #  # ]:          0 :         for (reg_id = 0; reg_id < rule->num_cond_regs; reg_id++) {
    3602                 :          0 :                 const struct dbg_idle_chk_cond_reg *reg = &cond_regs[reg_id];
    3603                 :            :                 struct dbg_idle_chk_result_reg_hdr *reg_hdr;
    3604                 :            : 
    3605                 :          0 :                 reg_hdr =
    3606                 :          0 :                     (struct dbg_idle_chk_result_reg_hdr *)(dump_buf + offset);
    3607                 :            : 
    3608                 :            :                 /* Write register header */
    3609         [ #  # ]:          0 :                 if (!dump) {
    3610                 :          0 :                         offset += IDLE_CHK_RESULT_REG_HDR_DWORDS +
    3611                 :          0 :                             reg->entry_size;
    3612                 :          0 :                         continue;
    3613                 :            :                 }
    3614                 :            : 
    3615         [ #  # ]:          0 :                 offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
    3616                 :            :                 memset(reg_hdr, 0, sizeof(*reg_hdr));
    3617                 :          0 :                 reg_hdr->start_entry = reg->start_entry;
    3618                 :          0 :                 reg_hdr->size = reg->entry_size;
    3619   [ #  #  #  # ]:          0 :                 SET_FIELD(reg_hdr->data,
    3620                 :            :                           DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM,
    3621                 :            :                           reg->num_entries > 1 || reg->start_entry > 0 ? 1 : 0);
    3622                 :          0 :                 SET_FIELD(reg_hdr->data,
    3623                 :            :                           DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID, reg_id);
    3624                 :            : 
    3625                 :            :                 /* Write register values */
    3626         [ #  # ]:          0 :                 for (i = 0; i < reg_hdr->size; i++, next_reg_offset++, offset++)
    3627                 :          0 :                         dump_buf[offset] = cond_reg_values[next_reg_offset];
    3628                 :            :         }
    3629                 :            : 
    3630                 :            :         /* Dump info register values */
    3631         [ #  # ]:          0 :         for (reg_id = 0; reg_id < rule->num_info_regs; reg_id++) {
    3632                 :          0 :                 const struct dbg_idle_chk_info_reg *reg = &info_regs[reg_id];
    3633                 :            :                 u32 block_id;
    3634                 :            : 
    3635                 :            :                 /* Check if register's block is in reset */
    3636         [ #  # ]:          0 :                 if (!dump) {
    3637                 :          0 :                         offset += IDLE_CHK_RESULT_REG_HDR_DWORDS + reg->size;
    3638                 :          0 :                         continue;
    3639                 :            :                 }
    3640                 :            : 
    3641                 :          0 :                 block_id = GET_FIELD(reg->data, DBG_IDLE_CHK_INFO_REG_BLOCK_ID);
    3642         [ #  # ]:          0 :                 if (block_id >= MAX_BLOCK_ID) {
    3643                 :          0 :                         DP_NOTICE(p_hwfn, false, "Invalid block_id\n");
    3644                 :          0 :                         return 0;
    3645                 :            :                 }
    3646                 :            : 
    3647         [ #  # ]:          0 :                 if (!dev_data->block_in_reset[block_id]) {
    3648                 :            :                         struct dbg_idle_chk_result_reg_hdr *reg_hdr;
    3649                 :            :                         bool wide_bus, eval_mode, mode_match = true;
    3650                 :            :                         u16 modes_buf_offset;
    3651                 :            :                         u32 addr;
    3652                 :            : 
    3653                 :          0 :                         reg_hdr = (struct dbg_idle_chk_result_reg_hdr *)
    3654                 :          0 :                                   (dump_buf + offset);
    3655                 :            : 
    3656                 :            :                         /* Check mode */
    3657                 :          0 :                         eval_mode = GET_FIELD(reg->mode.data,
    3658                 :            :                                               DBG_MODE_HDR_EVAL_MODE) > 0;
    3659         [ #  # ]:          0 :                         if (eval_mode) {
    3660                 :          0 :                                 modes_buf_offset =
    3661                 :            :                                     GET_FIELD(reg->mode.data,
    3662                 :            :                                               DBG_MODE_HDR_MODES_BUF_OFFSET);
    3663                 :            :                                 mode_match =
    3664                 :            :                                         qed_is_mode_match(p_hwfn,
    3665                 :            :                                                           &modes_buf_offset);
    3666                 :            :                         }
    3667                 :            : 
    3668         [ #  # ]:          0 :                         if (!mode_match)
    3669                 :          0 :                                 continue;
    3670                 :            : 
    3671                 :          0 :                         addr = GET_FIELD(reg->data,
    3672                 :            :                                          DBG_IDLE_CHK_INFO_REG_ADDRESS);
    3673                 :          0 :                         wide_bus = GET_FIELD(reg->data,
    3674                 :            :                                              DBG_IDLE_CHK_INFO_REG_WIDE_BUS);
    3675                 :            : 
    3676                 :            :                         /* Write register header */
    3677                 :          0 :                         offset += IDLE_CHK_RESULT_REG_HDR_DWORDS;
    3678                 :          0 :                         hdr->num_dumped_info_regs++;
    3679                 :            :                         memset(reg_hdr, 0, sizeof(*reg_hdr));
    3680                 :          0 :                         reg_hdr->size = reg->size;
    3681                 :          0 :                         SET_FIELD(reg_hdr->data,
    3682                 :            :                                   DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID,
    3683                 :            :                                   rule->num_cond_regs + reg_id);
    3684                 :            : 
    3685                 :            :                         /* Write register values */
    3686                 :          0 :                         offset += qed_grc_dump_addr_range(p_hwfn,
    3687                 :            :                                                           p_ptt,
    3688                 :          0 :                                                           dump_buf + offset,
    3689                 :            :                                                           dump,
    3690                 :            :                                                           addr,
    3691                 :            :                                                           reg->size, wide_bus,
    3692                 :            :                                                           SPLIT_TYPE_NONE, 0);
    3693                 :            :                 }
    3694                 :            :         }
    3695                 :            : 
    3696                 :            :         return offset;
    3697                 :            : }
    3698                 :            : 
    3699                 :            : /* Dumps idle check rule entries. Returns the dumped size in dwords. */
    3700                 :            : static u32
    3701                 :          0 : qed_idle_chk_dump_rule_entries(struct ecore_hwfn *p_hwfn,
    3702                 :            :                                struct ecore_ptt *p_ptt,
    3703                 :            :                                u32 *dump_buf, bool dump,
    3704                 :            :                                const struct dbg_idle_chk_rule *input_rules,
    3705                 :            :                                u32 num_input_rules, u32 *num_failing_rules)
    3706                 :            : {
    3707                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    3708                 :            :         u32 cond_reg_values[IDLE_CHK_MAX_ENTRIES_SIZE];
    3709                 :            :         u32 i, offset = 0;
    3710                 :            :         u16 entry_id;
    3711                 :            :         u8 reg_id;
    3712                 :            : 
    3713                 :          0 :         *num_failing_rules = 0;
    3714                 :            : 
    3715         [ #  # ]:          0 :         for (i = 0; i < num_input_rules; i++) {
    3716                 :            :                 const struct dbg_idle_chk_cond_reg *cond_regs;
    3717                 :            :                 const struct dbg_idle_chk_rule *rule;
    3718                 :            :                 const union dbg_idle_chk_reg *regs;
    3719                 :            :                 u16 num_reg_entries = 1;
    3720                 :            :                 bool check_rule = true;
    3721                 :            :                 const u32 *imm_values;
    3722                 :            : 
    3723                 :          0 :                 rule = &input_rules[i];
    3724                 :          0 :                 regs = (const union dbg_idle_chk_reg *)
    3725                 :          0 :                         p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr +
    3726                 :          0 :                         rule->reg_offset;
    3727                 :          0 :                 cond_regs = &regs[0].cond_reg;
    3728                 :          0 :                 imm_values =
    3729                 :          0 :                     (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr +
    3730                 :          0 :                     rule->imm_offset;
    3731                 :            : 
    3732                 :            :                 /* Check if all condition register blocks are out of reset, and
    3733                 :            :                  * find maximal number of entries (all condition registers that
    3734                 :            :                  * are memories must have the same size, which is > 1).
    3735                 :            :                  */
    3736   [ #  #  #  # ]:          0 :                 for (reg_id = 0; reg_id < rule->num_cond_regs && check_rule;
    3737                 :          0 :                      reg_id++) {
    3738                 :          0 :                         u32 block_id =
    3739                 :          0 :                                 GET_FIELD(cond_regs[reg_id].data,
    3740                 :            :                                           DBG_IDLE_CHK_COND_REG_BLOCK_ID);
    3741                 :            : 
    3742         [ #  # ]:          0 :                         if (block_id >= MAX_BLOCK_ID) {
    3743                 :          0 :                                 DP_NOTICE(p_hwfn, false, "Invalid block_id\n");
    3744                 :          0 :                                 return 0;
    3745                 :            :                         }
    3746                 :            : 
    3747                 :          0 :                         check_rule = !dev_data->block_in_reset[block_id];
    3748                 :          0 :                         if (cond_regs[reg_id].num_entries > num_reg_entries)
    3749                 :            :                                 num_reg_entries = cond_regs[reg_id].num_entries;
    3750                 :            :                 }
    3751                 :            : 
    3752         [ #  # ]:          0 :                 if (!check_rule && dump)
    3753                 :          0 :                         continue;
    3754                 :            : 
    3755         [ #  # ]:          0 :                 if (!dump) {
    3756                 :            :                         u32 entry_dump_size =
    3757                 :          0 :                                 qed_idle_chk_dump_failure(p_hwfn,
    3758                 :            :                                                           p_ptt,
    3759                 :          0 :                                                           dump_buf + offset,
    3760                 :            :                                                           false,
    3761                 :          0 :                                                           rule->rule_id,
    3762                 :            :                                                           rule,
    3763                 :            :                                                           0,
    3764                 :            :                                                           NULL);
    3765                 :            : 
    3766                 :          0 :                         offset += num_reg_entries * entry_dump_size;
    3767                 :          0 :                         (*num_failing_rules) += num_reg_entries;
    3768                 :          0 :                         continue;
    3769                 :            :                 }
    3770                 :            : 
    3771                 :            :                 /* Go over all register entries (number of entries is the same
    3772                 :            :                  * for all condition registers).
    3773                 :            :                  */
    3774         [ #  # ]:          0 :                 for (entry_id = 0; entry_id < num_reg_entries; entry_id++) {
    3775                 :            :                         u32 next_reg_offset = 0;
    3776                 :            : 
    3777                 :            :                         /* Read current entry of all condition registers */
    3778         [ #  # ]:          0 :                         for (reg_id = 0; reg_id < rule->num_cond_regs;
    3779                 :          0 :                              reg_id++) {
    3780                 :          0 :                                 const struct dbg_idle_chk_cond_reg *reg =
    3781                 :          0 :                                         &cond_regs[reg_id];
    3782                 :            :                                 u32 padded_entry_size, addr;
    3783                 :            :                                 bool wide_bus;
    3784                 :            : 
    3785                 :            :                                 /* Find GRC address (if it's a memory, the
    3786                 :            :                                  * address of the specific entry is calculated).
    3787                 :            :                                  */
    3788                 :          0 :                                 addr = GET_FIELD(reg->data,
    3789                 :            :                                                  DBG_IDLE_CHK_COND_REG_ADDRESS);
    3790                 :          0 :                                 wide_bus =
    3791                 :          0 :                                     GET_FIELD(reg->data,
    3792                 :            :                                               DBG_IDLE_CHK_COND_REG_WIDE_BUS);
    3793         [ #  # ]:          0 :                                 if (reg->num_entries > 1 ||
    3794         [ #  # ]:          0 :                                     reg->start_entry > 0) {
    3795                 :          0 :                                         padded_entry_size =
    3796         [ #  # ]:          0 :                                            reg->entry_size > 1 ?
    3797                 :          0 :                                            OSAL_ROUNDUP_POW_OF_TWO(reg->entry_size) :
    3798                 :            :                                            1;
    3799                 :          0 :                                         addr += (reg->start_entry + entry_id) *
    3800                 :            :                                                 padded_entry_size;
    3801                 :            :                                 }
    3802                 :            : 
    3803                 :            :                                 /* Read registers */
    3804         [ #  # ]:          0 :                                 if (next_reg_offset + reg->entry_size >=
    3805                 :            :                                     IDLE_CHK_MAX_ENTRIES_SIZE) {
    3806                 :          0 :                                         DP_NOTICE(p_hwfn, false,
    3807                 :            :                                                   "idle check registers entry is too large\n");
    3808                 :          0 :                                         return 0;
    3809                 :            :                                 }
    3810                 :            : 
    3811                 :          0 :                                 next_reg_offset +=
    3812                 :          0 :                                     qed_grc_dump_addr_range(p_hwfn, p_ptt,
    3813                 :          0 :                                                             cond_reg_values +
    3814                 :            :                                                             next_reg_offset,
    3815                 :            :                                                             dump, addr,
    3816                 :            :                                                             reg->entry_size,
    3817                 :            :                                                             wide_bus,
    3818                 :            :                                                             SPLIT_TYPE_NONE, 0);
    3819                 :            :                         }
    3820                 :            : 
    3821                 :            :                         /* Call rule condition function.
    3822                 :            :                          * If returns true, it's a failure.
    3823                 :            :                          */
    3824         [ #  # ]:          0 :                         if ((*cond_arr[rule->cond_id]) (cond_reg_values,
    3825                 :            :                                                         imm_values)) {
    3826                 :          0 :                                 offset += qed_idle_chk_dump_failure(p_hwfn,
    3827                 :            :                                                         p_ptt,
    3828                 :          0 :                                                         dump_buf + offset,
    3829                 :            :                                                         dump,
    3830                 :          0 :                                                         rule->rule_id,
    3831                 :            :                                                         rule,
    3832                 :            :                                                         entry_id,
    3833                 :            :                                                         cond_reg_values);
    3834                 :          0 :                                 (*num_failing_rules)++;
    3835                 :            :                         }
    3836                 :            :                 }
    3837                 :            :         }
    3838                 :            : 
    3839                 :            :         return offset;
    3840                 :            : }
    3841                 :            : 
    3842                 :            : /* Performs Idle Check Dump to the specified buffer.
    3843                 :            :  * Returns the dumped size in dwords.
    3844                 :            :  */
    3845                 :          0 : static u32 qed_idle_chk_dump(struct ecore_hwfn *p_hwfn,
    3846                 :            :                              struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    3847                 :            : {
    3848                 :            :         struct virt_mem_desc *dbg_buf =
    3849                 :            :             &p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES];
    3850                 :            :         u32 num_failing_rules_offset, offset = 0,
    3851                 :            :             input_offset = 0, num_failing_rules = 0;
    3852                 :            : 
    3853                 :            :         /* Dump global params  - 1 must match below amount of params */
    3854                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    3855                 :            :                                                 p_ptt,
    3856                 :            :                                                 dump_buf + offset, dump, 1);
    3857                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    3858                 :            :                                      dump, "dump-type", "idle-chk");
    3859                 :            : 
    3860                 :            :         /* Dump idle check section header with a single parameter */
    3861                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset, dump, "idle_chk", 1);
    3862                 :            :         num_failing_rules_offset = offset;
    3863                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "num_rules", 0);
    3864                 :            : 
    3865         [ #  # ]:          0 :         while (input_offset < BYTES_TO_DWORDS(dbg_buf->size)) {
    3866                 :          0 :                 const struct dbg_idle_chk_cond_hdr *cond_hdr =
    3867                 :          0 :                     (const struct dbg_idle_chk_cond_hdr *)dbg_buf->ptr +
    3868                 :          0 :                     input_offset++;
    3869                 :            :                 bool eval_mode, mode_match = true;
    3870                 :            :                 u32 curr_failing_rules;
    3871                 :            :                 u16 modes_buf_offset;
    3872                 :            : 
    3873                 :            :                 /* Check mode */
    3874                 :          0 :                 eval_mode = GET_FIELD(cond_hdr->mode.data,
    3875                 :            :                                       DBG_MODE_HDR_EVAL_MODE) > 0;
    3876         [ #  # ]:          0 :                 if (eval_mode) {
    3877                 :          0 :                         modes_buf_offset =
    3878                 :            :                                 GET_FIELD(cond_hdr->mode.data,
    3879                 :            :                                           DBG_MODE_HDR_MODES_BUF_OFFSET);
    3880                 :            :                         mode_match = qed_is_mode_match(p_hwfn,
    3881                 :            :                                                        &modes_buf_offset);
    3882                 :            :                 }
    3883                 :            : 
    3884         [ #  # ]:          0 :                 if (mode_match) {
    3885                 :          0 :                         const struct dbg_idle_chk_rule *rule =
    3886                 :            :                             (const struct dbg_idle_chk_rule *)((u32 *)
    3887                 :          0 :                                                                dbg_buf->ptr
    3888                 :          0 :                                                                + input_offset);
    3889                 :          0 :                         u32 num_input_rules =
    3890                 :          0 :                                 cond_hdr->data_size / IDLE_CHK_RULE_SIZE_DWORDS;
    3891                 :          0 :                         offset +=
    3892                 :          0 :                             qed_idle_chk_dump_rule_entries(p_hwfn,
    3893                 :            :                                                            p_ptt,
    3894                 :          0 :                                                            dump_buf +
    3895                 :            :                                                            offset,
    3896                 :            :                                                            dump,
    3897                 :            :                                                            rule,
    3898                 :            :                                                            num_input_rules,
    3899                 :            :                                                            &curr_failing_rules);
    3900                 :          0 :                         num_failing_rules += curr_failing_rules;
    3901                 :            :                 }
    3902                 :            : 
    3903                 :          0 :                 input_offset += cond_hdr->data_size;
    3904                 :            :         }
    3905                 :            : 
    3906                 :            :         /* Overwrite num_rules parameter */
    3907         [ #  # ]:          0 :         if (dump)
    3908                 :          0 :                 qed_dump_num_param(dump_buf + num_failing_rules_offset,
    3909                 :            :                                    dump, "num_rules", num_failing_rules);
    3910                 :            : 
    3911                 :            :         /* Dump last section */
    3912                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    3913                 :            : 
    3914                 :          0 :         return offset;
    3915                 :            : }
    3916                 :            : 
    3917                 :            : /* Finds the meta data image in NVRAM */
    3918                 :          0 : static enum dbg_status qed_find_nvram_image(struct ecore_hwfn *p_hwfn,
    3919                 :            :                                             struct ecore_ptt *p_ptt,
    3920                 :            :                                             u32 image_type,
    3921                 :            :                                             u32 *nvram_offset_bytes,
    3922                 :            :                                             u32 *nvram_size_bytes)
    3923                 :            : {
    3924                 :            :         u32 ret_mcp_resp, ret_mcp_param, ret_txn_size;
    3925                 :            :         struct mcp_file_att file_att;
    3926                 :            :         int nvm_result;
    3927                 :            : 
    3928                 :            :         /* Call NVRAM get file command */
    3929                 :          0 :         nvm_result = ecore_mcp_nvm_rd_cmd(p_hwfn,
    3930                 :            :                                         p_ptt,
    3931                 :            :                                         DRV_MSG_CODE_NVM_GET_FILE_ATT,
    3932                 :            :                                         image_type,
    3933                 :            :                                         &ret_mcp_resp,
    3934                 :            :                                         &ret_mcp_param,
    3935                 :            :                                         &ret_txn_size, (u32 *)&file_att);
    3936                 :            : 
    3937                 :            :         /* Check response */
    3938         [ #  # ]:          0 :         if (nvm_result ||
    3939         [ #  # ]:          0 :             (ret_mcp_resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
    3940                 :            :                 return DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
    3941                 :            : 
    3942                 :            :         /* Update return values */
    3943                 :          0 :         *nvram_offset_bytes = file_att.nvm_start_addr;
    3944                 :          0 :         *nvram_size_bytes = file_att.len;
    3945                 :            : 
    3946         [ #  # ]:          0 :         DP_VERBOSE(p_hwfn->p_dev,
    3947                 :            :                    ECORE_MSG_DEBUG,
    3948                 :            :                    "find_nvram_image: found NVRAM image of type %d in NVRAM offset %d bytes with size %d bytes\n",
    3949                 :            :                    image_type, *nvram_offset_bytes, *nvram_size_bytes);
    3950                 :            : 
    3951                 :            :         /* Check alignment */
    3952         [ #  # ]:          0 :         if (*nvram_size_bytes & 0x3)
    3953                 :          0 :                 return DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE;
    3954                 :            : 
    3955                 :            :         return DBG_STATUS_OK;
    3956                 :            : }
    3957                 :            : 
    3958                 :            : /* Reads data from NVRAM */
    3959                 :          0 : static enum dbg_status qed_nvram_read(struct ecore_hwfn *p_hwfn,
    3960                 :            :                                       struct ecore_ptt *p_ptt,
    3961                 :            :                                       u32 nvram_offset_bytes,
    3962                 :            :                                       u32 nvram_size_bytes, u32 *ret_buf)
    3963                 :            : {
    3964                 :            :         u32 ret_mcp_resp, ret_mcp_param, ret_read_size, bytes_to_copy;
    3965                 :          0 :         s32 bytes_left = nvram_size_bytes;
    3966                 :            :         u32 read_offset = 0, param = 0;
    3967                 :            : 
    3968                 :          0 :         DP_NOTICE(p_hwfn->p_dev, false,
    3969                 :            :                    "nvram_read: reading image of size %d bytes from NVRAM\n",
    3970                 :            :                    nvram_size_bytes);
    3971                 :            : 
    3972                 :            :         do {
    3973                 :          0 :                 bytes_to_copy =
    3974                 :            :                     (bytes_left >
    3975                 :          0 :                      MCP_DRV_NVM_BUF_LEN) ? MCP_DRV_NVM_BUF_LEN : bytes_left;
    3976                 :            : 
    3977                 :            :                 /* Call NVRAM read command */
    3978                 :          0 :                 SET_MFW_FIELD(param,
    3979                 :            :                               DRV_MB_PARAM_NVM_OFFSET,
    3980                 :            :                               nvram_offset_bytes + read_offset);
    3981                 :          0 :                 SET_MFW_FIELD(param, DRV_MB_PARAM_NVM_LEN, bytes_to_copy);
    3982         [ #  # ]:          0 :                 if (ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
    3983                 :            :                                          DRV_MSG_CODE_NVM_READ_NVRAM, param,
    3984                 :            :                                          &ret_mcp_resp,
    3985                 :            :                                          &ret_mcp_param, &ret_read_size,
    3986                 :            :                                          (u32 *)((u8 *)ret_buf +
    3987                 :            :                                                  read_offset))) {
    3988                 :          0 :                         DP_NOTICE(p_hwfn->p_dev, false, "rc = DBG_STATUS_NVRAM_READ_FAILED\n");
    3989                 :          0 :                         return DBG_STATUS_NVRAM_READ_FAILED;
    3990                 :            :                 }
    3991                 :            : 
    3992                 :            :                 /* Check response */
    3993         [ #  # ]:          0 :                 if ((ret_mcp_resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK) {
    3994                 :          0 :                         DP_NOTICE(p_hwfn->p_dev, false, "rc = DBG_STATUS_NVRAM_READ_FAILED\n");
    3995                 :          0 :                         return DBG_STATUS_NVRAM_READ_FAILED;
    3996                 :            :                 }
    3997                 :            : 
    3998                 :            :                 /* Update read offset */
    3999                 :          0 :                 read_offset += ret_read_size;
    4000                 :          0 :                 bytes_left -= ret_read_size;
    4001         [ #  # ]:          0 :         } while (bytes_left > 0);
    4002                 :            : 
    4003                 :            :         return DBG_STATUS_OK;
    4004                 :            : }
    4005                 :            : 
    4006                 :            : /* Get info on the MCP Trace data in the scratchpad:
    4007                 :            :  * - trace_data_grc_addr (OUT): trace data GRC address in bytes
    4008                 :            :  * - trace_data_size (OUT): trace data size in bytes (without the header)
    4009                 :            :  */
    4010                 :          0 : static enum dbg_status qed_mcp_trace_get_data_info(struct ecore_hwfn *p_hwfn,
    4011                 :            :                                                    struct ecore_ptt *p_ptt,
    4012                 :            :                                                    u32 *trace_data_grc_addr,
    4013                 :            :                                                    u32 *trace_data_size)
    4014                 :            : {
    4015                 :            :         u32 spad_trace_offsize, signature;
    4016                 :            : 
    4017                 :            :         /* Read trace section offsize structure from MCP scratchpad */
    4018                 :          0 :         spad_trace_offsize = ecore_rd(p_hwfn, p_ptt,
    4019                 :            :                                       MCP_SPAD_TRACE_OFFSIZE_ADDR);
    4020                 :            : 
    4021                 :            :         /* Extract trace section address from offsize (in scratchpad) */
    4022                 :          0 :         *trace_data_grc_addr =
    4023                 :          0 :                 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize);
    4024                 :            : 
    4025                 :            :         /* Read signature from MCP trace section */
    4026                 :          0 :         signature = ecore_rd(p_hwfn, p_ptt,
    4027                 :            :                            *trace_data_grc_addr +
    4028                 :            :                            offsetof(struct mcp_trace, signature));
    4029                 :            : 
    4030         [ #  # ]:          0 :         if (signature != MFW_TRACE_SIGNATURE)
    4031                 :            :                 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
    4032                 :            : 
    4033                 :            :         /* Read trace size from MCP trace section */
    4034                 :          0 :         *trace_data_size = ecore_rd(p_hwfn,
    4035                 :            :                                   p_ptt,
    4036                 :          0 :                                   *trace_data_grc_addr +
    4037                 :            :                                   offsetof(struct mcp_trace, size));
    4038                 :            : 
    4039                 :          0 :         return DBG_STATUS_OK;
    4040                 :            : }
    4041                 :            : 
    4042                 :            : /* Reads MCP trace meta data image from NVRAM
    4043                 :            :  * - running_bundle_id (OUT): running bundle ID (invalid when loaded from file)
    4044                 :            :  * - trace_meta_offset (OUT): trace meta offset in NVRAM in bytes (invalid when
    4045                 :            :  *                            loaded from file).
    4046                 :            :  * - trace_meta_size (OUT):   size in bytes of the trace meta data.
    4047                 :            :  */
    4048                 :          0 : static enum dbg_status qed_mcp_trace_get_meta_info(struct ecore_hwfn *p_hwfn,
    4049                 :            :                                                    struct ecore_ptt *p_ptt,
    4050                 :            :                                                    u32 trace_data_size_bytes,
    4051                 :            :                                                    u32 *running_bundle_id,
    4052                 :            :                                                    u32 *trace_meta_offset,
    4053                 :            :                                                    u32 *trace_meta_size)
    4054                 :            : {
    4055                 :            :         u32 spad_trace_offsize, nvram_image_type, running_mfw_addr;
    4056                 :            : 
    4057                 :            :         /* Read MCP trace section offsize structure from MCP scratchpad */
    4058                 :          0 :         spad_trace_offsize = ecore_rd(p_hwfn, p_ptt,
    4059                 :            :                                       MCP_SPAD_TRACE_OFFSIZE_ADDR);
    4060                 :            : 
    4061                 :            :         /* Find running bundle ID */
    4062                 :          0 :         running_mfw_addr =
    4063                 :          0 :                 MCP_REG_SCRATCH + SECTION_OFFSET(spad_trace_offsize) +
    4064                 :          0 :                 SECTION_SIZE(spad_trace_offsize) + trace_data_size_bytes;
    4065                 :          0 :         *running_bundle_id = ecore_rd(p_hwfn, p_ptt, running_mfw_addr);
    4066         [ #  # ]:          0 :         if (*running_bundle_id > 1)
    4067                 :            :                 return DBG_STATUS_INVALID_NVRAM_BUNDLE;
    4068                 :            : 
    4069                 :            :         /* Find image in NVRAM */
    4070                 :            :         nvram_image_type =
    4071                 :            :             (*running_bundle_id ==
    4072         [ #  # ]:          0 :              DIR_ID_1) ? NVM_TYPE_MFW_TRACE1 : NVM_TYPE_MFW_TRACE2;
    4073                 :          0 :         return qed_find_nvram_image(p_hwfn,
    4074                 :            :                                     p_ptt,
    4075                 :            :                                     nvram_image_type,
    4076                 :            :                                     trace_meta_offset, trace_meta_size);
    4077                 :            : }
    4078                 :            : 
    4079                 :            : /* Reads the MCP Trace meta data from NVRAM into the specified buffer */
    4080                 :          0 : static enum dbg_status qed_mcp_trace_read_meta(struct ecore_hwfn *p_hwfn,
    4081                 :            :                                                struct ecore_ptt *p_ptt,
    4082                 :            :                                                u32 nvram_offset_in_bytes,
    4083                 :            :                                                u32 size_in_bytes, u32 *buf)
    4084                 :            : {
    4085                 :            :         u8 modules_num, module_len, i, *byte_buf = (u8 *)buf;
    4086                 :            :         enum dbg_status status;
    4087                 :            :         u32 signature;
    4088                 :            : 
    4089                 :            :         /* Read meta data from NVRAM */
    4090                 :          0 :         status = qed_nvram_read(p_hwfn,
    4091                 :            :                                 p_ptt,
    4092                 :            :                                 nvram_offset_in_bytes, size_in_bytes, buf);
    4093         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    4094                 :            :                 return status;
    4095                 :            : 
    4096                 :            :         /* Extract and check first signature */
    4097                 :            :         signature = qed_read_unaligned_dword(byte_buf);
    4098                 :            :         byte_buf += sizeof(signature);
    4099         [ #  # ]:          0 :         if (signature != NVM_MAGIC_VALUE)
    4100                 :            :                 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
    4101                 :            : 
    4102                 :            :         /* Extract number of modules */
    4103                 :          0 :         modules_num = *(byte_buf++);
    4104                 :            : 
    4105                 :            :         /* Skip all modules */
    4106         [ #  # ]:          0 :         for (i = 0; i < modules_num; i++) {
    4107                 :          0 :                 module_len = *(byte_buf++);
    4108                 :          0 :                 byte_buf += module_len;
    4109                 :            :         }
    4110                 :            : 
    4111                 :            :         /* Extract and check second signature */
    4112                 :            :         signature = qed_read_unaligned_dword(byte_buf);
    4113                 :            :         byte_buf += sizeof(signature);
    4114         [ #  # ]:          0 :         if (signature != NVM_MAGIC_VALUE)
    4115                 :          0 :                 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
    4116                 :            : 
    4117                 :            :         return DBG_STATUS_OK;
    4118                 :            : }
    4119                 :            : 
    4120                 :            : /* Dump MCP Trace */
    4121                 :          0 : static enum dbg_status qed_mcp_trace_dump(struct ecore_hwfn *p_hwfn,
    4122                 :            :                                           struct ecore_ptt *p_ptt,
    4123                 :            :                                           u32 *dump_buf,
    4124                 :            :                                           bool dump, u32 *num_dumped_dwords)
    4125                 :            : {
    4126                 :            :         u32 trace_data_grc_addr, trace_data_size_bytes, trace_data_size_dwords;
    4127                 :            :         u32 trace_meta_size_dwords = 0, running_bundle_id, offset = 0;
    4128                 :          0 :         u32 trace_meta_offset_bytes = 0, trace_meta_size_bytes = 0;
    4129                 :            :         enum dbg_status status;
    4130                 :            :         int halted = 0;
    4131                 :            :         bool use_mfw;
    4132                 :            : 
    4133                 :          0 :         *num_dumped_dwords = 0;
    4134                 :            : 
    4135                 :          0 :         use_mfw = !qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_NO_MCP);
    4136                 :            : 
    4137                 :            :         /* Get trace data info */
    4138                 :          0 :         status = qed_mcp_trace_get_data_info(p_hwfn,
    4139                 :            :                                              p_ptt,
    4140                 :            :                                              &trace_data_grc_addr,
    4141                 :            :                                              &trace_data_size_bytes);
    4142         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    4143                 :            :                 return status;
    4144                 :            : 
    4145                 :            :         /* Dump global params */
    4146                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    4147                 :            :                                                 p_ptt,
    4148                 :            :                                                 dump_buf + offset, dump, 1);
    4149                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4150                 :            :                                      dump, "dump-type", "mcp-trace");
    4151                 :            : 
    4152                 :            :         /* Halt MCP while reading from scratchpad so the read data will be
    4153                 :            :          * consistent. if halt fails, MCP trace is taken anyway, with a small
    4154                 :            :          * risk that it may be corrupt.
    4155                 :            :          */
    4156         [ #  # ]:          0 :         if (dump && use_mfw) {
    4157                 :          0 :                 halted = !ecore_mcp_halt(p_hwfn, p_ptt);
    4158         [ #  # ]:          0 :                 if (!halted)
    4159                 :          0 :                         DP_NOTICE(p_hwfn, false, "MCP halt failed!\n");
    4160                 :            :         }
    4161                 :            : 
    4162                 :            :         /* Find trace data size */
    4163                 :          0 :         trace_data_size_dwords =
    4164                 :          0 :             DIV_ROUND_UP(trace_data_size_bytes + sizeof(struct mcp_trace),
    4165                 :            :                          BYTES_IN_DWORD);
    4166                 :            : 
    4167                 :            :         /* Dump trace data section header and param */
    4168                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4169                 :            :                                        dump, "mcp_trace_data", 1);
    4170                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4171                 :            :                                      dump, "size", trace_data_size_dwords);
    4172                 :            : 
    4173                 :            :         /* Read trace data from scratchpad into dump buffer */
    4174                 :          0 :         offset += qed_grc_dump_addr_range(p_hwfn,
    4175                 :            :                                           p_ptt,
    4176                 :          0 :                                           dump_buf + offset,
    4177                 :            :                                           dump,
    4178                 :            :                                           BYTES_TO_DWORDS(trace_data_grc_addr),
    4179                 :            :                                           trace_data_size_dwords, false,
    4180                 :            :                                           SPLIT_TYPE_NONE, 0);
    4181                 :            : 
    4182                 :            :         /* Resume MCP (only if halt succeeded) */
    4183   [ #  #  #  # ]:          0 :         if (halted && ecore_mcp_resume(p_hwfn, p_ptt))
    4184                 :          0 :                 DP_NOTICE(p_hwfn, false, "Failed to resume MCP after halt!\n");
    4185                 :            : 
    4186                 :            :         /* Dump trace meta section header */
    4187                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4188                 :            :                                        dump, "mcp_trace_meta", 1);
    4189                 :            : 
    4190                 :            :         /* If MCP Trace meta size parameter was set, use it.
    4191                 :            :          * Otherwise, read trace meta.
    4192                 :            :          * trace_meta_size_bytes is dword-aligned.
    4193                 :            :          */
    4194                 :          0 :         trace_meta_size_bytes =
    4195                 :            :                 qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_MCP_TRACE_META_SIZE);
    4196   [ #  #  #  # ]:          0 :         if ((!trace_meta_size_bytes || dump) && use_mfw)
    4197                 :          0 :                 status = qed_mcp_trace_get_meta_info(p_hwfn,
    4198                 :            :                                                      p_ptt,
    4199                 :            :                                                      trace_data_size_bytes,
    4200                 :            :                                                      &running_bundle_id,
    4201                 :            :                                                      &trace_meta_offset_bytes,
    4202                 :            :                                                      &trace_meta_size_bytes);
    4203         [ #  # ]:          0 :         if (status == DBG_STATUS_OK)
    4204                 :          0 :                 trace_meta_size_dwords = BYTES_TO_DWORDS(trace_meta_size_bytes);
    4205                 :            : 
    4206                 :            :         /* Dump trace meta size param */
    4207                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4208                 :            :                                      dump, "size", trace_meta_size_dwords);
    4209                 :            : 
    4210                 :            :         /* Read trace meta image into dump buffer */
    4211         [ #  # ]:          0 :         if (dump && trace_meta_size_dwords)
    4212                 :          0 :                 status = qed_mcp_trace_read_meta(p_hwfn,
    4213                 :            :                                                  p_ptt,
    4214                 :            :                                                  trace_meta_offset_bytes,
    4215                 :            :                                                  trace_meta_size_bytes,
    4216                 :          0 :                                                  dump_buf + offset);
    4217         [ #  # ]:          0 :         if (status == DBG_STATUS_OK)
    4218                 :          0 :                 offset += trace_meta_size_dwords;
    4219                 :            : 
    4220                 :            :         /* Dump last section */
    4221                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4222                 :            : 
    4223                 :          0 :         *num_dumped_dwords = offset;
    4224                 :            : 
    4225                 :            :         /* If no mcp access, indicate that the dump doesn't contain the meta
    4226                 :            :          * data from NVRAM.
    4227                 :            :          */
    4228         [ #  # ]:          0 :         return use_mfw ? status : DBG_STATUS_NVRAM_GET_IMAGE_FAILED;
    4229                 :            : }
    4230                 :            : 
    4231                 :            : /* Dump GRC FIFO */
    4232                 :          0 : static enum dbg_status qed_reg_fifo_dump(struct ecore_hwfn *p_hwfn,
    4233                 :            :                                          struct ecore_ptt *p_ptt,
    4234                 :            :                                          u32 *dump_buf,
    4235                 :            :                                          bool dump, u32 *num_dumped_dwords)
    4236                 :            : {
    4237                 :            :         u32 dwords_read, size_param_offset, offset = 0, addr, len;
    4238                 :            :         bool fifo_has_data;
    4239                 :            : 
    4240                 :          0 :         *num_dumped_dwords = 0;
    4241                 :            : 
    4242                 :            :         /* Dump global params */
    4243                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    4244                 :            :                                                 p_ptt,
    4245                 :            :                                                 dump_buf + offset, dump, 1);
    4246                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4247                 :            :                                      dump, "dump-type", "reg-fifo");
    4248                 :            : 
    4249                 :            :         /* Dump fifo data section header and param. The size param is 0 for
    4250                 :            :          * now, and is overwritten after reading the FIFO.
    4251                 :            :          */
    4252                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4253                 :            :                                        dump, "reg_fifo_data", 1);
    4254                 :            :         size_param_offset = offset;
    4255                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
    4256                 :            : 
    4257         [ #  # ]:          0 :         if (!dump) {
    4258                 :            :                 /* FIFO max size is REG_FIFO_DEPTH_DWORDS. There is no way to
    4259                 :            :                  * test how much data is available, except for reading it.
    4260                 :            :                  */
    4261                 :          0 :                 offset += REG_FIFO_DEPTH_DWORDS;
    4262                 :          0 :                 goto out;
    4263                 :            :         }
    4264                 :            : 
    4265                 :          0 :         fifo_has_data = ecore_rd(p_hwfn, p_ptt,
    4266                 :            :                                GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
    4267                 :            : 
    4268                 :            :         /* Pull available data from fifo. Use DMAE since this is widebus memory
    4269                 :            :          * and must be accessed atomically. Test for dwords_read not passing
    4270                 :            :          * buffer size since more entries could be added to the buffer as we are
    4271                 :            :          * emptying it.
    4272                 :            :          */
    4273                 :            :         addr = BYTES_TO_DWORDS(GRC_REG_TRACE_FIFO);
    4274                 :            :         len = REG_FIFO_ELEMENT_DWORDS;
    4275                 :          0 :         for (dwords_read = 0;
    4276         [ #  # ]:          0 :              fifo_has_data && dwords_read < REG_FIFO_DEPTH_DWORDS;
    4277                 :          0 :              dwords_read += REG_FIFO_ELEMENT_DWORDS) {
    4278                 :          0 :                 offset += qed_grc_dump_addr_range(p_hwfn,
    4279                 :            :                                                   p_ptt,
    4280                 :          0 :                                                   dump_buf + offset,
    4281                 :            :                                                   true,
    4282                 :            :                                                   addr,
    4283                 :            :                                                   len,
    4284                 :            :                                                   true, SPLIT_TYPE_NONE,
    4285                 :            :                                                   0);
    4286                 :          0 :                 fifo_has_data = ecore_rd(p_hwfn, p_ptt,
    4287                 :            :                                        GRC_REG_TRACE_FIFO_VALID_DATA) > 0;
    4288                 :            :         }
    4289                 :            : 
    4290                 :          0 :         qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
    4291                 :            :                            dwords_read);
    4292                 :          0 : out:
    4293                 :            :         /* Dump last section */
    4294                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4295                 :            : 
    4296                 :          0 :         *num_dumped_dwords = offset;
    4297                 :            : 
    4298                 :          0 :         return DBG_STATUS_OK;
    4299                 :            : }
    4300                 :            : 
    4301                 :            : /* Dump IGU FIFO */
    4302                 :          0 : static enum dbg_status qed_igu_fifo_dump(struct ecore_hwfn *p_hwfn,
    4303                 :            :                                          struct ecore_ptt *p_ptt,
    4304                 :            :                                          u32 *dump_buf,
    4305                 :            :                                          bool dump, u32 *num_dumped_dwords)
    4306                 :            : {
    4307                 :            :         u32 dwords_read, size_param_offset, offset = 0, addr, len;
    4308                 :            :         bool fifo_has_data;
    4309                 :            : 
    4310                 :          0 :         *num_dumped_dwords = 0;
    4311                 :            : 
    4312                 :            :         /* Dump global params */
    4313                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    4314                 :            :                                                 p_ptt,
    4315                 :            :                                                 dump_buf + offset, dump, 1);
    4316                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4317                 :            :                                      dump, "dump-type", "igu-fifo");
    4318                 :            : 
    4319                 :            :         /* Dump fifo data section header and param. The size param is 0 for
    4320                 :            :          * now, and is overwritten after reading the FIFO.
    4321                 :            :          */
    4322                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4323                 :            :                                        dump, "igu_fifo_data", 1);
    4324                 :            :         size_param_offset = offset;
    4325                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
    4326                 :            : 
    4327         [ #  # ]:          0 :         if (!dump) {
    4328                 :            :                 /* FIFO max size is IGU_FIFO_DEPTH_DWORDS. There is no way to
    4329                 :            :                  * test how much data is available, except for reading it.
    4330                 :            :                  */
    4331                 :          0 :                 offset += IGU_FIFO_DEPTH_DWORDS;
    4332                 :          0 :                 goto out;
    4333                 :            :         }
    4334                 :            : 
    4335                 :          0 :         fifo_has_data = ecore_rd(p_hwfn, p_ptt,
    4336                 :            :                                IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
    4337                 :            : 
    4338                 :            :         /* Pull available data from fifo. Use DMAE since this is widebus memory
    4339                 :            :          * and must be accessed atomically. Test for dwords_read not passing
    4340                 :            :          * buffer size since more entries could be added to the buffer as we are
    4341                 :            :          * emptying it.
    4342                 :            :          */
    4343                 :            :         addr = BYTES_TO_DWORDS(IGU_REG_ERROR_HANDLING_MEMORY);
    4344                 :            :         len = IGU_FIFO_ELEMENT_DWORDS;
    4345                 :          0 :         for (dwords_read = 0;
    4346         [ #  # ]:          0 :              fifo_has_data && dwords_read < IGU_FIFO_DEPTH_DWORDS;
    4347                 :          0 :              dwords_read += IGU_FIFO_ELEMENT_DWORDS) {
    4348                 :          0 :                 offset += qed_grc_dump_addr_range(p_hwfn,
    4349                 :            :                                                   p_ptt,
    4350                 :          0 :                                                   dump_buf + offset,
    4351                 :            :                                                   true,
    4352                 :            :                                                   addr,
    4353                 :            :                                                   len,
    4354                 :            :                                                   true, SPLIT_TYPE_NONE,
    4355                 :            :                                                   0);
    4356                 :          0 :                 fifo_has_data = ecore_rd(p_hwfn, p_ptt,
    4357                 :            :                                        IGU_REG_ERROR_HANDLING_DATA_VALID) > 0;
    4358                 :            :         }
    4359                 :            : 
    4360                 :          0 :         qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
    4361                 :            :                            dwords_read);
    4362                 :          0 : out:
    4363                 :            :         /* Dump last section */
    4364                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4365                 :            : 
    4366                 :          0 :         *num_dumped_dwords = offset;
    4367                 :            : 
    4368                 :          0 :         return DBG_STATUS_OK;
    4369                 :            : }
    4370                 :            : 
    4371                 :            : /* Protection Override dump */
    4372                 :          0 : static enum dbg_status qed_protection_override_dump(struct ecore_hwfn *p_hwfn,
    4373                 :            :                                                     struct ecore_ptt *p_ptt,
    4374                 :            :                                                     u32 *dump_buf,
    4375                 :            :                                                     bool dump,
    4376                 :            :                                                     u32 *num_dumped_dwords)
    4377                 :            : {
    4378                 :            :         u32 size_param_offset, override_window_dwords, offset = 0, addr;
    4379                 :            : 
    4380                 :          0 :         *num_dumped_dwords = 0;
    4381                 :            : 
    4382                 :            :         /* Dump global params */
    4383                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    4384                 :            :                                                 p_ptt,
    4385                 :            :                                                 dump_buf + offset, dump, 1);
    4386                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4387                 :            :                                      dump, "dump-type", "protection-override");
    4388                 :            : 
    4389                 :            :         /* Dump data section header and param. The size param is 0 for now,
    4390                 :            :          * and is overwritten after reading the data.
    4391                 :            :          */
    4392                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4393                 :            :                                        dump, "protection_override_data", 1);
    4394                 :            :         size_param_offset = offset;
    4395                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
    4396                 :            : 
    4397         [ #  # ]:          0 :         if (!dump) {
    4398                 :          0 :                 offset += PROTECTION_OVERRIDE_DEPTH_DWORDS;
    4399                 :          0 :                 goto out;
    4400                 :            :         }
    4401                 :            : 
    4402                 :            :         /* Add override window info to buffer */
    4403                 :          0 :         override_window_dwords =
    4404                 :          0 :                 ecore_rd(p_hwfn, p_ptt, GRC_REG_NUMBER_VALID_OVERRIDE_WINDOW) *
    4405                 :            :                 PROTECTION_OVERRIDE_ELEMENT_DWORDS;
    4406         [ #  # ]:          0 :         if (override_window_dwords) {
    4407                 :            :                 addr = BYTES_TO_DWORDS(GRC_REG_PROTECTION_OVERRIDE_WINDOW);
    4408                 :          0 :                 offset += qed_grc_dump_addr_range(p_hwfn,
    4409                 :            :                                                   p_ptt,
    4410                 :          0 :                                                   dump_buf + offset,
    4411                 :            :                                                   true,
    4412                 :            :                                                   addr,
    4413                 :            :                                                   override_window_dwords,
    4414                 :            :                                                   true, SPLIT_TYPE_NONE, 0);
    4415                 :          0 :                 qed_dump_num_param(dump_buf + size_param_offset, dump, "size",
    4416                 :            :                                    override_window_dwords);
    4417                 :            :         }
    4418                 :          0 : out:
    4419                 :            :         /* Dump last section */
    4420                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4421                 :            : 
    4422                 :          0 :         *num_dumped_dwords = offset;
    4423                 :            : 
    4424                 :          0 :         return DBG_STATUS_OK;
    4425                 :            : }
    4426                 :            : 
    4427                 :            : /* Performs FW Asserts Dump to the specified buffer.
    4428                 :            :  * Returns the dumped size in dwords.
    4429                 :            :  */
    4430                 :          0 : static u32 qed_fw_asserts_dump(struct ecore_hwfn *p_hwfn,
    4431                 :            :                                struct ecore_ptt *p_ptt, u32 *dump_buf,
    4432                 :            :                                bool dump)
    4433                 :            : {
    4434                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    4435                 :            :         struct fw_asserts_ram_section *asserts;
    4436                 :          0 :         char storm_letter_str[2] = "?";
    4437                 :            :         struct fw_info fw_info;
    4438                 :            :         u32 offset = 0;
    4439                 :            :         u8 storm_id;
    4440                 :            : 
    4441                 :            :         /* Dump global params */
    4442                 :          0 :         offset += qed_dump_common_global_params(p_hwfn,
    4443                 :            :                                                 p_ptt,
    4444                 :            :                                                 dump_buf + offset, dump, 1);
    4445                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4446                 :            :                                      dump, "dump-type", "fw-asserts");
    4447                 :            : 
    4448                 :            :         /* Find Storm dump size */
    4449         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
    4450                 :            :                 u32 fw_asserts_section_addr, next_list_idx_addr, next_list_idx;
    4451                 :          0 :                 struct storm_defs *storm = &s_storm_defs[storm_id];
    4452                 :            :                 u32 last_list_idx, addr;
    4453                 :            : 
    4454         [ #  # ]:          0 :                 if (dev_data->block_in_reset[storm->sem_block_id])
    4455                 :          0 :                         continue;
    4456                 :            : 
    4457                 :            :                 /* Read FW info for the current Storm */
    4458                 :          0 :                 qed_read_storm_fw_info(p_hwfn, p_ptt, storm_id, &fw_info);
    4459                 :            : 
    4460                 :            :                 asserts = &fw_info.fw_asserts_section;
    4461                 :            : 
    4462                 :            :                 /* Dump FW Asserts section header and params */
    4463                 :          0 :                 storm_letter_str[0] = storm->letter;
    4464                 :          0 :                 offset += qed_dump_section_hdr(dump_buf + offset,
    4465                 :            :                                                dump, "fw_asserts", 2);
    4466                 :          0 :                 offset += qed_dump_str_param(dump_buf + offset,
    4467                 :            :                                              dump, "storm", storm_letter_str);
    4468                 :          0 :                 offset += qed_dump_num_param(dump_buf + offset,
    4469                 :            :                                              dump,
    4470                 :            :                                              "size",
    4471                 :          0 :                                              asserts->list_element_dword_size);
    4472                 :            : 
    4473                 :            :                 /* Read and dump FW Asserts data */
    4474         [ #  # ]:          0 :                 if (!dump) {
    4475                 :          0 :                         offset += asserts->list_element_dword_size;
    4476                 :          0 :                         continue;
    4477                 :            :                 }
    4478                 :            : 
    4479                 :          0 :                 fw_asserts_section_addr = storm->sem_fast_mem_addr +
    4480                 :          0 :                         SEM_FAST_REG_INT_RAM +
    4481                 :          0 :                         RAM_LINES_TO_BYTES(asserts->section_ram_line_offset);
    4482                 :          0 :                 next_list_idx_addr = fw_asserts_section_addr +
    4483                 :          0 :                         DWORDS_TO_BYTES(asserts->list_next_index_dword_offset);
    4484                 :          0 :                 next_list_idx = ecore_rd(p_hwfn, p_ptt, next_list_idx_addr);
    4485                 :            :                 last_list_idx = (next_list_idx > 0 ?
    4486                 :            :                                  next_list_idx :
    4487         [ #  # ]:          0 :                                  asserts->list_num_elements) - 1;
    4488                 :          0 :                 addr = BYTES_TO_DWORDS(fw_asserts_section_addr) +
    4489                 :          0 :                        asserts->list_dword_offset +
    4490                 :          0 :                        last_list_idx * asserts->list_element_dword_size;
    4491                 :          0 :                 offset +=
    4492                 :          0 :                     qed_grc_dump_addr_range(p_hwfn, p_ptt,
    4493                 :          0 :                                             dump_buf + offset,
    4494                 :            :                                             dump, addr,
    4495                 :            :                                             asserts->list_element_dword_size,
    4496                 :            :                                                   false, SPLIT_TYPE_NONE, 0);
    4497                 :            :         }
    4498                 :            : 
    4499                 :            :         /* Dump last section */
    4500                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4501                 :            : 
    4502                 :          0 :         return offset;
    4503                 :            : }
    4504                 :            : 
    4505                 :            : /* Dumps the specified ILT pages to the specified buffer.
    4506                 :            :  * Returns the dumped size in dwords.
    4507                 :            :  */
    4508                 :          0 : static u32 qed_ilt_dump_pages_range(u32 *dump_buf,
    4509                 :            :                                     bool dump,
    4510                 :            :                                     u32 start_page_id,
    4511                 :            :                                     u32 num_pages,
    4512                 :            :                                     struct phys_mem_desc *ilt_pages,
    4513                 :            :                                     bool dump_page_ids)
    4514                 :            : {
    4515                 :            :         u32 page_id, end_page_id, offset = 0;
    4516                 :            : 
    4517         [ #  # ]:          0 :         if (num_pages == 0)
    4518                 :            :                 return offset;
    4519                 :            : 
    4520                 :          0 :         end_page_id = start_page_id + num_pages - 1;
    4521                 :            : 
    4522         [ #  # ]:          0 :         for (page_id = start_page_id; page_id <= end_page_id; page_id++) {
    4523                 :          0 :                 struct phys_mem_desc *mem_desc = &ilt_pages[page_id];
    4524                 :            : 
    4525                 :            :                 /**
    4526                 :            :                  *
    4527                 :            :                  * if (page_id >= ->p_cxt_mngr->ilt_shadow_size)
    4528                 :            :                  *     break;
    4529                 :            :                  */
    4530                 :            : 
    4531         [ #  # ]:          0 :                 if (!ilt_pages[page_id].virt_addr)
    4532                 :          0 :                         continue;
    4533                 :            : 
    4534         [ #  # ]:          0 :                 if (dump_page_ids) {
    4535                 :            :                         /* Copy page ID to dump buffer */
    4536         [ #  # ]:          0 :                         if (dump)
    4537                 :          0 :                                 *(dump_buf + offset) = page_id;
    4538                 :          0 :                         offset++;
    4539                 :            :                 } else {
    4540                 :            :                         /* Copy page memory to dump buffer */
    4541         [ #  # ]:          0 :                         if (dump)
    4542                 :          0 :                                 memcpy(dump_buf + offset,
    4543                 :          0 :                                        mem_desc->virt_addr, mem_desc->size);
    4544                 :          0 :                         offset += BYTES_TO_DWORDS(mem_desc->size);
    4545                 :            :                 }
    4546                 :            :         }
    4547                 :            : 
    4548                 :            :         return offset;
    4549                 :            : }
    4550                 :            : 
    4551                 :            : /* Dumps a section containing the dumped ILT pages.
    4552                 :            :  * Returns the dumped size in dwords.
    4553                 :            :  */
    4554                 :          0 : static u32 qed_ilt_dump_pages_section(struct ecore_hwfn *p_hwfn,
    4555                 :            :                                       u32 *dump_buf,
    4556                 :            :                                       bool dump,
    4557                 :            :                                       u32 valid_conn_pf_pages,
    4558                 :            :                                       u32 valid_conn_vf_pages,
    4559                 :            :                                       struct phys_mem_desc *ilt_pages,
    4560                 :            :                                       bool dump_page_ids)
    4561                 :            : {
    4562                 :          0 :         struct ecore_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients;
    4563                 :            :         u32 pf_start_line, start_page_id, offset = 0;
    4564                 :            :         u32 cdut_pf_init_pages, cdut_vf_init_pages;
    4565                 :            :         u32 cdut_pf_work_pages, cdut_vf_work_pages;
    4566                 :            :         u32 base_data_offset, size_param_offset;
    4567                 :            :         u32 cdut_pf_pages, cdut_vf_pages;
    4568                 :            :         const char *section_name;
    4569                 :            :         u8 i;
    4570                 :            : 
    4571         [ #  # ]:          0 :         section_name = dump_page_ids ? "ilt_page_ids" : "ilt_page_mem";
    4572                 :          0 :         cdut_pf_init_pages = ecore_get_cdut_num_pf_init_pages(p_hwfn);
    4573                 :          0 :         cdut_vf_init_pages = ecore_get_cdut_num_vf_init_pages(p_hwfn);
    4574                 :          0 :         cdut_pf_work_pages = ecore_get_cdut_num_pf_work_pages(p_hwfn);
    4575                 :          0 :         cdut_vf_work_pages = ecore_get_cdut_num_vf_work_pages(p_hwfn);
    4576                 :          0 :         cdut_pf_pages = cdut_pf_init_pages + cdut_pf_work_pages;
    4577                 :          0 :         cdut_vf_pages = cdut_vf_init_pages + cdut_vf_work_pages;
    4578                 :          0 :         pf_start_line = p_hwfn->p_cxt_mngr->pf_start_line;
    4579                 :            : 
    4580                 :            :         offset +=
    4581                 :          0 :             qed_dump_section_hdr(dump_buf + offset, dump, section_name, 1);
    4582                 :            : 
    4583                 :            :         /* Dump size parameter (0 for now, overwritten with real size later) */
    4584                 :            :         size_param_offset = offset;
    4585                 :          0 :         offset += qed_dump_num_param(dump_buf + offset, dump, "size", 0);
    4586                 :            :         base_data_offset = offset;
    4587                 :            : 
    4588                 :            :         /* CDUC pages are ordered as follows:
    4589                 :            :          * - PF pages - valid section (included in PF connection type mapping)
    4590                 :            :          * - PF pages - invalid section (not dumped)
    4591                 :            :          * - For each VF in the PF:
    4592                 :            :          *   - VF pages - valid section (included in VF connection type mapping)
    4593                 :            :          *   - VF pages - invalid section (not dumped)
    4594                 :            :          */
    4595         [ #  # ]:          0 :         if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_DUMP_ILT_CDUC)) {
    4596                 :            :                 /* Dump connection PF pages */
    4597                 :          0 :                 start_page_id = clients[ILT_CLI_CDUC].first.val - pf_start_line;
    4598                 :          0 :                 offset += qed_ilt_dump_pages_range(dump_buf + offset,
    4599                 :            :                                                    dump,
    4600                 :            :                                                    start_page_id,
    4601                 :            :                                                    valid_conn_pf_pages,
    4602                 :            :                                                    ilt_pages, dump_page_ids);
    4603                 :            : 
    4604                 :            :                 /* Dump connection VF pages */
    4605                 :          0 :                 start_page_id += clients[ILT_CLI_CDUC].pf_total_lines;
    4606         [ #  # ]:          0 :                 for (i = 0; i < p_hwfn->p_cxt_mngr->vf_count;
    4607                 :          0 :                      i++, start_page_id += clients[ILT_CLI_CDUC].vf_total_lines)
    4608                 :          0 :                         offset += qed_ilt_dump_pages_range(dump_buf + offset,
    4609                 :            :                                                            dump,
    4610                 :            :                                                            start_page_id,
    4611                 :            :                                                            valid_conn_vf_pages,
    4612                 :            :                                                            ilt_pages,
    4613                 :            :                                                            dump_page_ids);
    4614                 :            :         }
    4615                 :            : 
    4616                 :            :         /* CDUT pages are ordered as follows:
    4617                 :            :          * - PF init pages (not dumped)
    4618                 :            :          * - PF work pages
    4619                 :            :          * - For each VF in the PF:
    4620                 :            :          *   - VF init pages (not dumped)
    4621                 :            :          *   - VF work pages
    4622                 :            :          */
    4623         [ #  # ]:          0 :         if (qed_grc_get_param(p_hwfn, DBG_GRC_PARAM_DUMP_ILT_CDUT)) {
    4624                 :            :                 /* Dump task PF pages */
    4625                 :          0 :                 start_page_id = clients[ILT_CLI_CDUT].first.val +
    4626                 :            :                     cdut_pf_init_pages - pf_start_line;
    4627                 :          0 :                 offset += qed_ilt_dump_pages_range(dump_buf + offset,
    4628                 :            :                                                    dump,
    4629                 :            :                                                    start_page_id,
    4630                 :            :                                                    cdut_pf_work_pages,
    4631                 :            :                                                    ilt_pages, dump_page_ids);
    4632                 :            : 
    4633                 :            :                 /* Dump task VF pages */
    4634                 :          0 :                 start_page_id = clients[ILT_CLI_CDUT].first.val +
    4635                 :          0 :                     cdut_pf_pages + cdut_vf_init_pages - pf_start_line;
    4636         [ #  # ]:          0 :                 for (i = 0; i < p_hwfn->p_cxt_mngr->vf_count;
    4637                 :          0 :                      i++, start_page_id += cdut_vf_pages)
    4638                 :          0 :                         offset += qed_ilt_dump_pages_range(dump_buf + offset,
    4639                 :            :                                                            dump,
    4640                 :            :                                                            start_page_id,
    4641                 :            :                                                            cdut_vf_work_pages,
    4642                 :            :                                                            ilt_pages,
    4643                 :            :                                                            dump_page_ids);
    4644                 :            :         }
    4645                 :            : 
    4646                 :            :         /* Overwrite size param */
    4647         [ #  # ]:          0 :         if (dump)
    4648                 :          0 :                 qed_dump_num_param(dump_buf + size_param_offset,
    4649                 :            :                                    dump, "size", offset - base_data_offset);
    4650                 :            : 
    4651                 :          0 :         return offset;
    4652                 :            : }
    4653                 :            : 
    4654                 :            : /* Performs ILT Dump to the specified buffer.
    4655                 :            :  * Returns the dumped size in dwords.
    4656                 :            :  */
    4657                 :          0 : static u32 qed_ilt_dump(struct ecore_hwfn *p_hwfn,
    4658                 :            :                         struct ecore_ptt *p_ptt, u32 *dump_buf, bool dump)
    4659                 :            : {
    4660                 :          0 :         struct ecore_ilt_client_cfg *clients = p_hwfn->p_cxt_mngr->clients;
    4661                 :            :         u32 valid_conn_vf_cids, valid_conn_vf_pages, offset = 0;
    4662                 :            :         u32 valid_conn_pf_cids, valid_conn_pf_pages, num_pages;
    4663                 :            :         u32 num_cids_per_page, conn_ctx_size;
    4664                 :            :         u32 cduc_page_size, cdut_page_size;
    4665                 :            :         struct phys_mem_desc *ilt_pages;
    4666                 :            :         u8 conn_type;
    4667                 :            : 
    4668                 :          0 :         cduc_page_size = 1 <<
    4669                 :          0 :             (clients[ILT_CLI_CDUC].p_size.val + PXP_ILT_PAGE_SIZE_NUM_BITS_MIN);
    4670                 :          0 :         cdut_page_size = 1 <<
    4671                 :          0 :             (clients[ILT_CLI_CDUT].p_size.val + PXP_ILT_PAGE_SIZE_NUM_BITS_MIN);
    4672                 :          0 :         conn_ctx_size = p_hwfn->p_cxt_mngr->conn_ctx_size;
    4673                 :          0 :         num_cids_per_page = (int)(cduc_page_size / conn_ctx_size);
    4674                 :          0 :         ilt_pages = p_hwfn->p_cxt_mngr->ilt_shadow;
    4675                 :            : 
    4676                 :            :         /* Dump global params - 22 must match number of params below */
    4677                 :          0 :         offset += qed_dump_common_global_params(p_hwfn, p_ptt,
    4678                 :            :                                                 dump_buf + offset, dump, 22);
    4679                 :          0 :         offset += qed_dump_str_param(dump_buf + offset,
    4680                 :            :                                      dump, "dump-type", "ilt-dump");
    4681                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4682                 :            :                                      dump,
    4683                 :            :                                      "cduc-page-size", cduc_page_size);
    4684                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4685                 :            :                                      dump,
    4686                 :            :                                      "cduc-first-page-id",
    4687                 :            :                                      clients[ILT_CLI_CDUC].first.val);
    4688                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4689                 :            :                                      dump,
    4690                 :            :                                      "cduc-last-page-id",
    4691                 :            :                                      clients[ILT_CLI_CDUC].last.val);
    4692                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4693                 :            :                                      dump,
    4694                 :            :                                      "cduc-num-pf-pages",
    4695                 :            :                                      clients
    4696                 :            :                                      [ILT_CLI_CDUC].pf_total_lines);
    4697                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4698                 :            :                                      dump,
    4699                 :            :                                      "cduc-num-vf-pages",
    4700                 :            :                                      clients
    4701                 :            :                                      [ILT_CLI_CDUC].vf_total_lines);
    4702                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4703                 :            :                                      dump,
    4704                 :            :                                      "max-conn-ctx-size",
    4705                 :            :                                      conn_ctx_size);
    4706                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4707                 :            :                                      dump,
    4708                 :            :                                      "cdut-page-size", cdut_page_size);
    4709                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4710                 :            :                                      dump,
    4711                 :            :                                      "cdut-first-page-id",
    4712                 :            :                                      clients[ILT_CLI_CDUT].first.val);
    4713                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4714                 :            :                                      dump,
    4715                 :            :                                      "cdut-last-page-id",
    4716                 :            :                                      clients[ILT_CLI_CDUT].last.val);
    4717                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4718                 :            :                                      dump,
    4719                 :            :                                      "cdut-num-pf-init-pages",
    4720                 :          0 :                                      ecore_get_cdut_num_pf_init_pages(p_hwfn));
    4721                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4722                 :            :                                      dump,
    4723                 :            :                                      "cdut-num-vf-init-pages",
    4724                 :          0 :                                      ecore_get_cdut_num_vf_init_pages(p_hwfn));
    4725                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4726                 :            :                                      dump,
    4727                 :            :                                      "cdut-num-pf-work-pages",
    4728                 :          0 :                                      ecore_get_cdut_num_pf_work_pages(p_hwfn));
    4729                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4730                 :            :                                      dump,
    4731                 :            :                                      "cdut-num-vf-work-pages",
    4732                 :          0 :                                      ecore_get_cdut_num_vf_work_pages(p_hwfn));
    4733                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4734                 :            :                                      dump,
    4735                 :            :                                      "max-task-ctx-size",
    4736                 :          0 :                                      p_hwfn->p_cxt_mngr->task_ctx_size);
    4737                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4738                 :            :                                      dump,
    4739                 :            :                                      "task-type-id",
    4740                 :          0 :                                      p_hwfn->p_cxt_mngr->task_type_id);
    4741                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4742                 :            :                                      dump,
    4743                 :            :                                      "first-vf-id-in-pf",
    4744                 :          0 :                                      p_hwfn->p_cxt_mngr->first_vf_in_pf);
    4745                 :          0 :         offset += /* 18 */ qed_dump_num_param(dump_buf + offset,
    4746                 :            :                                               dump,
    4747                 :            :                                               "num-vfs-in-pf",
    4748                 :          0 :                                               p_hwfn->p_cxt_mngr->vf_count);
    4749                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4750                 :            :                                      dump,
    4751                 :            :                                      "ptr-size-bytes", sizeof(void *));
    4752                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4753                 :            :                                      dump,
    4754                 :            :                                      "pf-start-line",
    4755                 :          0 :                                      p_hwfn->p_cxt_mngr->pf_start_line);
    4756                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4757                 :            :                                      dump,
    4758                 :            :                                      "page-mem-desc-size-dwords",
    4759                 :            :                                      PAGE_MEM_DESC_SIZE_DWORDS);
    4760                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4761                 :            :                                      dump,
    4762                 :            :                                      "ilt-shadow-size",
    4763                 :          0 :                                      p_hwfn->p_cxt_mngr->ilt_shadow_size);
    4764                 :            :         /* Additional/Less parameters require matching of number in call to
    4765                 :            :          * dump_common_global_params()
    4766                 :            :          */
    4767                 :            : 
    4768                 :            :         /* Dump section containing number of PF CIDs per connection type */
    4769                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4770                 :            :                                        dump, "num_pf_cids_per_conn_type", 1);
    4771                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4772                 :            :                                      dump, "size", NUM_OF_CONNECTION_TYPES);
    4773                 :          0 :         for (conn_type = 0, valid_conn_pf_cids = 0;
    4774         [ #  # ]:          0 :              conn_type < NUM_OF_CONNECTION_TYPES; conn_type++, offset++) {
    4775                 :          0 :                 u32 num_pf_cids =
    4776                 :          0 :                     p_hwfn->p_cxt_mngr->conn_cfg[conn_type].cid_count;
    4777                 :            : 
    4778         [ #  # ]:          0 :                 if (dump)
    4779                 :          0 :                         *(dump_buf + offset) = num_pf_cids;
    4780                 :          0 :                 valid_conn_pf_cids += num_pf_cids;
    4781                 :            :         }
    4782                 :            : 
    4783                 :            :         /* Dump section containing number of VF CIDs per connection type */
    4784                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4785                 :            :                                        dump, "num_vf_cids_per_conn_type", 1);
    4786                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4787                 :            :                                      dump, "size", NUM_OF_CONNECTION_TYPES);
    4788                 :          0 :         for (conn_type = 0, valid_conn_vf_cids = 0;
    4789         [ #  # ]:          0 :              conn_type < NUM_OF_CONNECTION_TYPES; conn_type++, offset++) {
    4790                 :          0 :                 u32 num_vf_cids =
    4791                 :          0 :                     p_hwfn->p_cxt_mngr->conn_cfg[conn_type].cids_per_vf;
    4792                 :            : 
    4793         [ #  # ]:          0 :                 if (dump)
    4794                 :          0 :                         *(dump_buf + offset) = num_vf_cids;
    4795                 :          0 :                 valid_conn_vf_cids += num_vf_cids;
    4796                 :            :         }
    4797                 :            : 
    4798                 :            :         /* Dump section containing physical memory descs for each ILT page */
    4799                 :          0 :         num_pages = p_hwfn->p_cxt_mngr->ilt_shadow_size;
    4800                 :          0 :         offset += qed_dump_section_hdr(dump_buf + offset,
    4801                 :            :                                        dump, "ilt_page_desc", 1);
    4802                 :          0 :         offset += qed_dump_num_param(dump_buf + offset,
    4803                 :            :                                      dump,
    4804                 :            :                                      "size",
    4805                 :            :                                      num_pages * PAGE_MEM_DESC_SIZE_DWORDS);
    4806                 :            : 
    4807                 :            :         /* Copy memory descriptors to dump buffer */
    4808         [ #  # ]:          0 :         if (dump) {
    4809                 :            :                 u32 page_id;
    4810                 :            : 
    4811         [ #  # ]:          0 :                 for (page_id = 0; page_id < num_pages;
    4812                 :          0 :                      page_id++, offset += PAGE_MEM_DESC_SIZE_DWORDS)
    4813                 :          0 :                         memcpy(dump_buf + offset,
    4814                 :          0 :                                &ilt_pages[page_id],
    4815                 :            :                                DWORDS_TO_BYTES(PAGE_MEM_DESC_SIZE_DWORDS));
    4816                 :            :         } else {
    4817                 :          0 :                 offset += num_pages * PAGE_MEM_DESC_SIZE_DWORDS;
    4818                 :            :         }
    4819                 :            : 
    4820                 :          0 :         valid_conn_pf_pages = DIV_ROUND_UP(valid_conn_pf_cids,
    4821                 :            :                                            num_cids_per_page);
    4822                 :          0 :         valid_conn_vf_pages = DIV_ROUND_UP(valid_conn_vf_cids,
    4823                 :            :                                            num_cids_per_page);
    4824                 :            : 
    4825                 :            :         /* Dump ILT pages IDs */
    4826                 :          0 :         offset += qed_ilt_dump_pages_section(p_hwfn,
    4827                 :          0 :                                              dump_buf + offset,
    4828                 :            :                                              dump,
    4829                 :            :                                              valid_conn_pf_pages,
    4830                 :            :                                              valid_conn_vf_pages,
    4831                 :            :                                              ilt_pages, true);
    4832                 :            : 
    4833                 :            :         /* Dump ILT pages memory */
    4834                 :          0 :         offset += qed_ilt_dump_pages_section(p_hwfn,
    4835                 :          0 :                                              dump_buf + offset,
    4836                 :            :                                              dump,
    4837                 :            :                                              valid_conn_pf_pages,
    4838                 :            :                                              valid_conn_vf_pages,
    4839                 :            :                                              ilt_pages, false);
    4840                 :            : 
    4841                 :            :         /* Dump last section */
    4842                 :          0 :         offset += qed_dump_last_section(dump_buf, offset, dump);
    4843                 :            : 
    4844                 :          0 :         return offset;
    4845                 :            : }
    4846                 :            : 
    4847                 :            : /***************************** Public Functions *******************************/
    4848                 :            : 
    4849                 :          0 : enum dbg_status qed_dbg_set_bin_ptr(struct ecore_hwfn *p_hwfn,
    4850                 :            :                                     const u8 * const bin_ptr)
    4851                 :            : {
    4852                 :            :         struct bin_buffer_hdr *buf_hdrs =
    4853                 :            :                         (struct bin_buffer_hdr *)(osal_uintptr_t)bin_ptr;
    4854                 :            :         u8 buf_id;
    4855                 :            : 
    4856                 :            :         /* Convert binary data to debug arrays */
    4857         [ #  # ]:          0 :         for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++)
    4858                 :          0 :                 qed_set_dbg_bin_buf(p_hwfn,
    4859                 :            :                                     buf_id,
    4860                 :            :                                     (const u32 *)(bin_ptr +
    4861                 :          0 :                                                   buf_hdrs[buf_id].offset),
    4862                 :          0 :                                                   buf_hdrs[buf_id].length);
    4863                 :            : 
    4864                 :          0 :         return DBG_STATUS_OK;
    4865                 :            : }
    4866                 :            : 
    4867                 :          0 : enum dbg_status qed_dbg_set_app_ver(u32 ver)
    4868                 :            : {
    4869         [ #  # ]:          0 :         if (ver < TOOLS_VERSION)
    4870                 :            :                 return DBG_STATUS_UNSUPPORTED_APP_VERSION;
    4871                 :            : 
    4872                 :          0 :         s_app_ver = ver;
    4873                 :            : 
    4874                 :          0 :         return DBG_STATUS_OK;
    4875                 :            : }
    4876                 :            : 
    4877                 :          0 : bool qed_read_fw_info(struct ecore_hwfn *p_hwfn,
    4878                 :            :                       struct ecore_ptt *p_ptt, struct fw_info *fw_info)
    4879                 :            : {
    4880                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    4881                 :            :         u8 storm_id;
    4882                 :            : 
    4883         [ #  # ]:          0 :         for (storm_id = 0; storm_id < MAX_DBG_STORMS; storm_id++) {
    4884                 :          0 :                 struct storm_defs *storm = &s_storm_defs[storm_id];
    4885                 :            : 
    4886                 :            :                 /* Skip Storm if it's in reset */
    4887         [ #  # ]:          0 :                 if (dev_data->block_in_reset[storm->sem_block_id])
    4888                 :            :                         continue;
    4889                 :            : 
    4890                 :            :                 /* Read FW info for the current Storm */
    4891                 :          0 :                 qed_read_storm_fw_info(p_hwfn, p_ptt, storm_id, fw_info);
    4892                 :            : 
    4893                 :          0 :                 return true;
    4894                 :            :         }
    4895                 :            : 
    4896                 :            :         return false;
    4897                 :            : }
    4898                 :            : 
    4899                 :          0 : enum dbg_status qed_dbg_grc_config(struct ecore_hwfn *p_hwfn,
    4900                 :            :                                    enum dbg_grc_params grc_param, u32 val)
    4901                 :            : {
    4902                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    4903                 :            :         enum dbg_status status;
    4904                 :            :         int i;
    4905                 :            : 
    4906         [ #  # ]:          0 :         DP_VERBOSE(p_hwfn->p_dev,
    4907                 :            :                    ECORE_MSG_DEBUG,
    4908                 :            :                    "dbg_grc_config: paramId = %d, val = %d\n", grc_param, val);
    4909                 :            : 
    4910                 :          0 :         status = qed_dbg_dev_init(p_hwfn);
    4911         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    4912                 :            :                 return status;
    4913                 :            : 
    4914                 :            :         /* Initializes the GRC parameters (if not initialized). Needed in order
    4915                 :            :          * to set the default parameter values for the first time.
    4916                 :            :          */
    4917                 :            :         qed_dbg_grc_init_params(p_hwfn);
    4918                 :            : 
    4919         [ #  # ]:          0 :         if (grc_param >= MAX_DBG_GRC_PARAMS)
    4920                 :            :                 return DBG_STATUS_INVALID_ARGS;
    4921         [ #  # ]:          0 :         if (val < s_grc_param_defs[grc_param].min ||
    4922         [ #  # ]:          0 :             val > s_grc_param_defs[grc_param].max)
    4923                 :            :                 return DBG_STATUS_INVALID_ARGS;
    4924                 :            : 
    4925         [ #  # ]:          0 :         if (s_grc_param_defs[grc_param].is_preset) {
    4926                 :            :                 /* Preset param */
    4927                 :            : 
    4928                 :            :                 /* Disabling a preset is not allowed. Call
    4929                 :            :                  * dbg_grc_set_params_default instead.
    4930                 :            :                  */
    4931         [ #  # ]:          0 :                 if (!val)
    4932                 :            :                         return DBG_STATUS_INVALID_ARGS;
    4933                 :            : 
    4934                 :            :                 /* Update all params with the preset values */
    4935         [ #  # ]:          0 :                 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++) {
    4936                 :            :                         struct grc_param_defs *defs = &s_grc_param_defs[i];
    4937                 :            :                         u32 preset_val;
    4938                 :            :                         /* Skip persistent params */
    4939         [ #  # ]:          0 :                         if (defs->is_persistent)
    4940                 :          0 :                                 continue;
    4941                 :            : 
    4942                 :            :                         /* Find preset value */
    4943         [ #  # ]:          0 :                         if (grc_param == DBG_GRC_PARAM_EXCLUDE_ALL)
    4944                 :          0 :                                 preset_val =
    4945                 :            :                                     defs->exclude_all_preset_val;
    4946         [ #  # ]:          0 :                         else if (grc_param == DBG_GRC_PARAM_CRASH)
    4947                 :          0 :                                 preset_val =
    4948                 :          0 :                                     defs->crash_preset_val[dev_data->chip_id];
    4949                 :            :                         else
    4950                 :            :                                 return DBG_STATUS_INVALID_ARGS;
    4951                 :            : 
    4952                 :          0 :                         qed_grc_set_param(p_hwfn, i, preset_val);
    4953                 :            :                 }
    4954                 :            :         } else {
    4955                 :            :                 /* Regular param - set its value */
    4956                 :            :                 qed_grc_set_param(p_hwfn, grc_param, val);
    4957                 :            :         }
    4958                 :            : 
    4959                 :            :         return DBG_STATUS_OK;
    4960                 :            : }
    4961                 :            : 
    4962                 :            : /* Assign default GRC param values */
    4963                 :          0 : void qed_dbg_grc_set_params_default(struct ecore_hwfn *p_hwfn)
    4964                 :            : {
    4965                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    4966                 :            :         u32 i;
    4967                 :            : 
    4968         [ #  # ]:          0 :         for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
    4969         [ #  # ]:          0 :                 if (!s_grc_param_defs[i].is_persistent)
    4970                 :          0 :                         dev_data->grc.param_val[i] =
    4971                 :          0 :                             s_grc_param_defs[i].default_val[dev_data->chip_id];
    4972                 :          0 : }
    4973                 :            : 
    4974                 :          0 : enum dbg_status qed_dbg_grc_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    4975                 :            :                                               struct ecore_ptt *p_ptt,
    4976                 :            :                                               u32 *buf_size)
    4977                 :            : {
    4978                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    4979                 :            : 
    4980                 :          0 :         *buf_size = 0;
    4981                 :            : 
    4982         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    4983                 :            :                 return status;
    4984                 :            : 
    4985         [ #  # ]:          0 :         if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
    4986         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_REG].ptr ||
    4987         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_DUMP_MEM].ptr ||
    4988         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
    4989         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
    4990                 :            :                 return DBG_STATUS_DBG_ARRAY_NOT_SET;
    4991                 :            : 
    4992                 :          0 :         return qed_grc_dump(p_hwfn, p_ptt, NULL, false, buf_size);
    4993                 :            : }
    4994                 :            : 
    4995                 :          0 : enum dbg_status qed_dbg_grc_dump(struct ecore_hwfn *p_hwfn,
    4996                 :            :                                  struct ecore_ptt *p_ptt,
    4997                 :            :                                  u32 *dump_buf,
    4998                 :            :                                  u32 buf_size_in_dwords,
    4999                 :            :                                  u32 *num_dumped_dwords)
    5000                 :            : {
    5001                 :            :         u32 needed_buf_size_in_dwords;
    5002                 :            :         enum dbg_status status;
    5003                 :            : 
    5004                 :          0 :         *num_dumped_dwords = 0;
    5005                 :            : 
    5006                 :          0 :         status = qed_dbg_grc_get_dump_buf_size(p_hwfn,
    5007                 :            :                                                p_ptt,
    5008                 :            :                                                &needed_buf_size_in_dwords);
    5009         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5010                 :            :                 return status;
    5011                 :            : 
    5012         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5013                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5014                 :            : 
    5015                 :            :         /* GRC Dump */
    5016                 :          0 :         status = qed_grc_dump(p_hwfn, p_ptt, dump_buf, true, num_dumped_dwords);
    5017                 :            : 
    5018                 :            :         /* Revert GRC params to their default */
    5019                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5020                 :            : 
    5021                 :          0 :         return status;
    5022                 :            : }
    5023                 :            : 
    5024                 :          0 : enum dbg_status qed_dbg_idle_chk_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5025                 :            :                                                    struct ecore_ptt *p_ptt,
    5026                 :            :                                                    u32 *buf_size)
    5027                 :            : {
    5028                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    5029                 :            :         struct idle_chk_data *idle_chk = &dev_data->idle_chk;
    5030                 :            :         enum dbg_status status;
    5031                 :            : 
    5032                 :          0 :         *buf_size = 0;
    5033                 :            : 
    5034                 :          0 :         status = qed_dbg_dev_init(p_hwfn);
    5035         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5036                 :            :                 return status;
    5037                 :            : 
    5038         [ #  # ]:          0 :         if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
    5039         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_REGS].ptr ||
    5040         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_IMMS].ptr ||
    5041         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_RULES].ptr)
    5042                 :            :                 return DBG_STATUS_DBG_ARRAY_NOT_SET;
    5043                 :            : 
    5044         [ #  # ]:          0 :         if (!idle_chk->buf_size_set) {
    5045                 :          0 :                 idle_chk->buf_size = qed_idle_chk_dump(p_hwfn,
    5046                 :            :                                                        p_ptt, NULL, false);
    5047                 :          0 :                 idle_chk->buf_size_set = true;
    5048                 :            :         }
    5049                 :            : 
    5050                 :          0 :         *buf_size = idle_chk->buf_size;
    5051                 :            : 
    5052                 :          0 :         return DBG_STATUS_OK;
    5053                 :            : }
    5054                 :            : 
    5055                 :          0 : enum dbg_status qed_dbg_idle_chk_dump(struct ecore_hwfn *p_hwfn,
    5056                 :            :                                       struct ecore_ptt *p_ptt,
    5057                 :            :                                       u32 *dump_buf,
    5058                 :            :                                       u32 buf_size_in_dwords,
    5059                 :            :                                       u32 *num_dumped_dwords)
    5060                 :            : {
    5061                 :            :         u32 needed_buf_size_in_dwords;
    5062                 :            :         enum dbg_status status;
    5063                 :            : 
    5064                 :          0 :         *num_dumped_dwords = 0;
    5065                 :            : 
    5066                 :          0 :         status = qed_dbg_idle_chk_get_dump_buf_size(p_hwfn,
    5067                 :            :                                                     p_ptt,
    5068                 :            :                                                     &needed_buf_size_in_dwords);
    5069         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5070                 :            :                 return status;
    5071                 :            : 
    5072         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5073                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5074                 :            : 
    5075                 :            :         /* Update reset state */
    5076                 :          0 :         qed_grc_unreset_blocks(p_hwfn, p_ptt, true);
    5077                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5078                 :            : 
    5079                 :            :         /* Idle Check Dump */
    5080                 :          0 :         *num_dumped_dwords = qed_idle_chk_dump(p_hwfn, p_ptt, dump_buf, true);
    5081                 :            : 
    5082                 :            :         /* Revert GRC params to their default */
    5083                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5084                 :            : 
    5085                 :          0 :         return DBG_STATUS_OK;
    5086                 :            : }
    5087                 :            : 
    5088                 :          0 : enum dbg_status qed_dbg_mcp_trace_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5089                 :            :                                                     struct ecore_ptt *p_ptt,
    5090                 :            :                                                     u32 *buf_size)
    5091                 :            : {
    5092                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5093                 :            : 
    5094                 :          0 :         *buf_size = 0;
    5095                 :            : 
    5096         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5097                 :            :                 return status;
    5098                 :            : 
    5099                 :          0 :         return qed_mcp_trace_dump(p_hwfn, p_ptt, NULL, false, buf_size);
    5100                 :            : }
    5101                 :            : 
    5102                 :          0 : enum dbg_status qed_dbg_mcp_trace_dump(struct ecore_hwfn *p_hwfn,
    5103                 :            :                                        struct ecore_ptt *p_ptt,
    5104                 :            :                                        u32 *dump_buf,
    5105                 :            :                                        u32 buf_size_in_dwords,
    5106                 :            :                                        u32 *num_dumped_dwords)
    5107                 :            : {
    5108                 :            :         u32 needed_buf_size_in_dwords;
    5109                 :            :         enum dbg_status status;
    5110                 :            : 
    5111                 :            :         status =
    5112                 :          0 :                 qed_dbg_mcp_trace_get_dump_buf_size(p_hwfn,
    5113                 :            :                                                     p_ptt,
    5114                 :            :                                                     &needed_buf_size_in_dwords);
    5115         [ #  # ]:          0 :         if (status != DBG_STATUS_OK && status !=
    5116                 :            :             DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
    5117                 :            :                 return status;
    5118         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5119                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5120                 :            : 
    5121                 :            :         /* Update reset state */
    5122                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5123                 :            : 
    5124                 :            :         /* Perform dump */
    5125                 :          0 :         status = qed_mcp_trace_dump(p_hwfn,
    5126                 :            :                                     p_ptt, dump_buf, true, num_dumped_dwords);
    5127                 :            : 
    5128                 :            :         /* Revert GRC params to their default */
    5129                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5130                 :            : 
    5131                 :          0 :         return status;
    5132                 :            : }
    5133                 :            : 
    5134                 :          0 : enum dbg_status qed_dbg_reg_fifo_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5135                 :            :                                                    struct ecore_ptt *p_ptt,
    5136                 :            :                                                    u32 *buf_size)
    5137                 :            : {
    5138                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5139                 :            : 
    5140                 :          0 :         *buf_size = 0;
    5141                 :            : 
    5142         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5143                 :            :                 return status;
    5144                 :            : 
    5145                 :          0 :         return qed_reg_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
    5146                 :            : }
    5147                 :            : 
    5148                 :          0 : enum dbg_status qed_dbg_reg_fifo_dump(struct ecore_hwfn *p_hwfn,
    5149                 :            :                                       struct ecore_ptt *p_ptt,
    5150                 :            :                                       u32 *dump_buf,
    5151                 :            :                                       u32 buf_size_in_dwords,
    5152                 :            :                                       u32 *num_dumped_dwords)
    5153                 :            : {
    5154                 :            :         u32 needed_buf_size_in_dwords;
    5155                 :            :         enum dbg_status status;
    5156                 :            : 
    5157                 :          0 :         *num_dumped_dwords = 0;
    5158                 :            : 
    5159                 :          0 :         status = qed_dbg_reg_fifo_get_dump_buf_size(p_hwfn,
    5160                 :            :                                                     p_ptt,
    5161                 :            :                                                     &needed_buf_size_in_dwords);
    5162         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5163                 :            :                 return status;
    5164                 :            : 
    5165         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5166                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5167                 :            : 
    5168                 :            :         /* Update reset state */
    5169                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5170                 :            : 
    5171                 :          0 :         status = qed_reg_fifo_dump(p_hwfn,
    5172                 :            :                                    p_ptt, dump_buf, true, num_dumped_dwords);
    5173                 :            : 
    5174                 :            :         /* Revert GRC params to their default */
    5175                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5176                 :            : 
    5177                 :          0 :         return status;
    5178                 :            : }
    5179                 :            : 
    5180                 :          0 : enum dbg_status qed_dbg_igu_fifo_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5181                 :            :                                                    struct ecore_ptt *p_ptt,
    5182                 :            :                                                    u32 *buf_size)
    5183                 :            : {
    5184                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5185                 :            : 
    5186                 :          0 :         *buf_size = 0;
    5187                 :            : 
    5188         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5189                 :            :                 return status;
    5190                 :            : 
    5191                 :          0 :         return qed_igu_fifo_dump(p_hwfn, p_ptt, NULL, false, buf_size);
    5192                 :            : }
    5193                 :            : 
    5194                 :          0 : enum dbg_status qed_dbg_igu_fifo_dump(struct ecore_hwfn *p_hwfn,
    5195                 :            :                                       struct ecore_ptt *p_ptt,
    5196                 :            :                                       u32 *dump_buf,
    5197                 :            :                                       u32 buf_size_in_dwords,
    5198                 :            :                                       u32 *num_dumped_dwords)
    5199                 :            : {
    5200                 :            :         u32 needed_buf_size_in_dwords;
    5201                 :            :         enum dbg_status status;
    5202                 :            : 
    5203                 :          0 :         *num_dumped_dwords = 0;
    5204                 :            : 
    5205                 :          0 :         status = qed_dbg_igu_fifo_get_dump_buf_size(p_hwfn,
    5206                 :            :                                                     p_ptt,
    5207                 :            :                                                     &needed_buf_size_in_dwords);
    5208         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5209                 :            :                 return status;
    5210                 :            : 
    5211         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5212                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5213                 :            : 
    5214                 :            :         /* Update reset state */
    5215                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5216                 :            : 
    5217                 :          0 :         status = qed_igu_fifo_dump(p_hwfn,
    5218                 :            :                                    p_ptt, dump_buf, true, num_dumped_dwords);
    5219                 :            :         /* Revert GRC params to their default */
    5220                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5221                 :            : 
    5222                 :          0 :         return status;
    5223                 :            : }
    5224                 :            : 
    5225                 :            : enum dbg_status
    5226                 :          0 : qed_dbg_protection_override_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5227                 :            :                                               struct ecore_ptt *p_ptt,
    5228                 :            :                                               u32 *buf_size)
    5229                 :            : {
    5230                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5231                 :            : 
    5232                 :          0 :         *buf_size = 0;
    5233                 :            : 
    5234         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5235                 :            :                 return status;
    5236                 :            : 
    5237                 :          0 :         return qed_protection_override_dump(p_hwfn,
    5238                 :            :                                             p_ptt, NULL, false, buf_size);
    5239                 :            : }
    5240                 :            : 
    5241                 :          0 : enum dbg_status qed_dbg_protection_override_dump(struct ecore_hwfn *p_hwfn,
    5242                 :            :                                                  struct ecore_ptt *p_ptt,
    5243                 :            :                                                  u32 *dump_buf,
    5244                 :            :                                                  u32 buf_size_in_dwords,
    5245                 :            :                                                  u32 *num_dumped_dwords)
    5246                 :            : {
    5247                 :            :         u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
    5248                 :            :         enum dbg_status status;
    5249                 :            : 
    5250                 :          0 :         *num_dumped_dwords = 0;
    5251                 :            : 
    5252                 :            :         status =
    5253                 :          0 :                 qed_dbg_protection_override_get_dump_buf_size(p_hwfn,
    5254                 :            :                                                               p_ptt,
    5255                 :            :                                                               p_size);
    5256         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5257                 :            :                 return status;
    5258                 :            : 
    5259         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5260                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5261                 :            : 
    5262                 :            :         /* Update reset state */
    5263                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5264                 :            : 
    5265                 :          0 :         status = qed_protection_override_dump(p_hwfn,
    5266                 :            :                                               p_ptt,
    5267                 :            :                                               dump_buf,
    5268                 :            :                                               true, num_dumped_dwords);
    5269                 :            : 
    5270                 :            :         /* Revert GRC params to their default */
    5271                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5272                 :            : 
    5273                 :          0 :         return status;
    5274                 :            : }
    5275                 :            : 
    5276                 :          0 : enum dbg_status qed_dbg_fw_asserts_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5277                 :            :                                                      struct ecore_ptt *p_ptt,
    5278                 :            :                                                      u32 *buf_size)
    5279                 :            : {
    5280                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5281                 :            : 
    5282                 :          0 :         *buf_size = 0;
    5283                 :            : 
    5284         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5285                 :            :                 return status;
    5286                 :            : 
    5287                 :            :         /* Update reset state */
    5288                 :          0 :         qed_update_blocks_reset_state(p_hwfn, p_ptt);
    5289                 :            : 
    5290                 :          0 :         *buf_size = qed_fw_asserts_dump(p_hwfn, p_ptt, NULL, false);
    5291                 :            : 
    5292                 :          0 :         return DBG_STATUS_OK;
    5293                 :            : }
    5294                 :            : 
    5295                 :          0 : enum dbg_status qed_dbg_fw_asserts_dump(struct ecore_hwfn *p_hwfn,
    5296                 :            :                                         struct ecore_ptt *p_ptt,
    5297                 :            :                                         u32 *dump_buf,
    5298                 :            :                                         u32 buf_size_in_dwords,
    5299                 :            :                                         u32 *num_dumped_dwords)
    5300                 :            : {
    5301                 :            :         u32 needed_buf_size_in_dwords, *p_size = &needed_buf_size_in_dwords;
    5302                 :            :         enum dbg_status status;
    5303                 :            : 
    5304                 :          0 :         *num_dumped_dwords = 0;
    5305                 :            : 
    5306                 :            :         status =
    5307                 :          0 :                 qed_dbg_fw_asserts_get_dump_buf_size(p_hwfn,
    5308                 :            :                                                      p_ptt,
    5309                 :            :                                                      p_size);
    5310         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5311                 :            :                 return status;
    5312                 :            : 
    5313         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5314                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5315                 :            : 
    5316                 :          0 :         *num_dumped_dwords = qed_fw_asserts_dump(p_hwfn, p_ptt, dump_buf, true);
    5317                 :            : 
    5318                 :            :         /* Revert GRC params to their default */
    5319                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5320                 :            : 
    5321                 :          0 :         return DBG_STATUS_OK;
    5322                 :            : }
    5323                 :            : 
    5324                 :          0 : static enum dbg_status qed_dbg_ilt_get_dump_buf_size(struct ecore_hwfn *p_hwfn,
    5325                 :            :                                                      struct ecore_ptt *p_ptt,
    5326                 :            :                                                      u32 *buf_size)
    5327                 :            : {
    5328                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5329                 :            : 
    5330                 :          0 :         *buf_size = 0;
    5331                 :            : 
    5332         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5333                 :            :                 return status;
    5334                 :            : 
    5335                 :          0 :         *buf_size = qed_ilt_dump(p_hwfn, p_ptt, NULL, false);
    5336                 :            : 
    5337                 :          0 :         return DBG_STATUS_OK;
    5338                 :            : }
    5339                 :            : 
    5340                 :          0 : static enum dbg_status qed_dbg_ilt_dump(struct ecore_hwfn *p_hwfn,
    5341                 :            :                                         struct ecore_ptt *p_ptt,
    5342                 :            :                                         u32 *dump_buf,
    5343                 :            :                                         u32 buf_size_in_dwords,
    5344                 :            :                                         u32 *num_dumped_dwords)
    5345                 :            : {
    5346                 :            :         u32 needed_buf_size_in_dwords;
    5347                 :            :         enum dbg_status status;
    5348                 :            : 
    5349                 :          0 :         *num_dumped_dwords = 0;
    5350                 :            : 
    5351                 :          0 :         status = qed_dbg_ilt_get_dump_buf_size(p_hwfn,
    5352                 :            :                                                p_ptt,
    5353                 :            :                                                &needed_buf_size_in_dwords);
    5354         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5355                 :            :                 return status;
    5356                 :            : 
    5357         [ #  # ]:          0 :         if (buf_size_in_dwords < needed_buf_size_in_dwords)
    5358                 :            :                 return DBG_STATUS_DUMP_BUF_TOO_SMALL;
    5359                 :            : 
    5360                 :          0 :         *num_dumped_dwords = qed_ilt_dump(p_hwfn, p_ptt, dump_buf, true);
    5361                 :            : 
    5362                 :            :         /* Revert GRC params to their default */
    5363                 :          0 :         qed_dbg_grc_set_params_default(p_hwfn);
    5364                 :            : 
    5365                 :          0 :         return DBG_STATUS_OK;
    5366                 :            : }
    5367                 :            : 
    5368                 :          0 : enum dbg_status qed_dbg_read_attn(struct ecore_hwfn *p_hwfn,
    5369                 :            :                                   struct ecore_ptt *p_ptt,
    5370                 :            :                                   enum block_id block_id,
    5371                 :            :                                   enum dbg_attn_type attn_type,
    5372                 :            :                                   bool clear_status,
    5373                 :            :                                   struct dbg_attn_block_result *results)
    5374                 :            : {
    5375                 :          0 :         enum dbg_status status = qed_dbg_dev_init(p_hwfn);
    5376                 :            :         u8 reg_idx, num_attn_regs, num_result_regs = 0;
    5377                 :            :         const struct dbg_attn_reg *attn_reg_arr;
    5378                 :            : 
    5379         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    5380                 :            :                 return status;
    5381                 :            : 
    5382         [ #  # ]:          0 :         if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_MODE_TREE].ptr ||
    5383         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_BLOCKS].ptr ||
    5384         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_REGS].ptr)
    5385                 :            :                 return DBG_STATUS_DBG_ARRAY_NOT_SET;
    5386                 :            : 
    5387                 :            :         attn_reg_arr = qed_get_block_attn_regs(p_hwfn,
    5388                 :            :                                                block_id,
    5389                 :            :                                                attn_type, &num_attn_regs);
    5390                 :            : 
    5391         [ #  # ]:          0 :         for (reg_idx = 0; reg_idx < num_attn_regs; reg_idx++) {
    5392                 :          0 :                 const struct dbg_attn_reg *reg_data = &attn_reg_arr[reg_idx];
    5393                 :            :                 struct dbg_attn_reg_result *reg_result;
    5394                 :            :                 u32 sts_addr, sts_val;
    5395                 :            :                 u16 modes_buf_offset;
    5396                 :            :                 bool eval_mode;
    5397                 :            : 
    5398                 :            :                 /* Check mode */
    5399                 :          0 :                 eval_mode = GET_FIELD(reg_data->mode.data,
    5400                 :            :                                       DBG_MODE_HDR_EVAL_MODE) > 0;
    5401                 :          0 :                 modes_buf_offset = GET_FIELD(reg_data->mode.data,
    5402                 :            :                                              DBG_MODE_HDR_MODES_BUF_OFFSET);
    5403   [ #  #  #  # ]:          0 :                 if (eval_mode && !qed_is_mode_match(p_hwfn, &modes_buf_offset))
    5404                 :          0 :                         continue;
    5405                 :            : 
    5406                 :            :                 /* Mode match - read attention status register */
    5407         [ #  # ]:          0 :                 sts_addr = DWORDS_TO_BYTES(clear_status ?
    5408                 :            :                                            reg_data->sts_clr_address :
    5409                 :            :                                            GET_FIELD(reg_data->data,
    5410                 :            :                                                      DBG_ATTN_REG_STS_ADDRESS));
    5411                 :          0 :                 sts_val = ecore_rd(p_hwfn, p_ptt, sts_addr);
    5412         [ #  # ]:          0 :                 if (!sts_val)
    5413                 :          0 :                         continue;
    5414                 :            : 
    5415                 :            :                 /* Non-zero attention status - add to results */
    5416                 :          0 :                 reg_result = &results->reg_results[num_result_regs];
    5417                 :          0 :                 SET_FIELD(reg_result->data,
    5418                 :            :                           DBG_ATTN_REG_RESULT_STS_ADDRESS, sts_addr);
    5419                 :          0 :                 SET_FIELD(reg_result->data,
    5420                 :            :                           DBG_ATTN_REG_RESULT_NUM_REG_ATTN,
    5421                 :            :                           GET_FIELD(reg_data->data, DBG_ATTN_REG_NUM_REG_ATTN));
    5422                 :          0 :                 reg_result->block_attn_offset = reg_data->block_attn_offset;
    5423                 :          0 :                 reg_result->sts_val = sts_val;
    5424                 :          0 :                 reg_result->mask_val = ecore_rd(p_hwfn,
    5425                 :            :                                               p_ptt,
    5426                 :          0 :                                               DWORDS_TO_BYTES
    5427                 :            :                                               (reg_data->mask_address));
    5428                 :          0 :                 num_result_regs++;
    5429                 :            :         }
    5430                 :            : 
    5431                 :          0 :         results->block_id = (u8)block_id;
    5432                 :          0 :         results->names_offset =
    5433                 :          0 :             qed_get_block_attn_data(p_hwfn, block_id, attn_type)->names_offset;
    5434                 :          0 :         SET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_ATTN_TYPE, attn_type);
    5435                 :          0 :         SET_FIELD(results->data,
    5436                 :            :                   DBG_ATTN_BLOCK_RESULT_NUM_REGS, num_result_regs);
    5437                 :            : 
    5438                 :          0 :         return DBG_STATUS_OK;
    5439                 :            : }
    5440                 :            : 
    5441                 :            : /******************************* Data Types **********************************/
    5442                 :            : 
    5443                 :            : /* REG fifo element */
    5444                 :            : struct reg_fifo_element {
    5445                 :            :         u64 data;
    5446                 :            : #define REG_FIFO_ELEMENT_ADDRESS_SHIFT          0
    5447                 :            : #define REG_FIFO_ELEMENT_ADDRESS_MASK           0x7fffff
    5448                 :            : #define REG_FIFO_ELEMENT_ACCESS_SHIFT           23
    5449                 :            : #define REG_FIFO_ELEMENT_ACCESS_MASK            0x1
    5450                 :            : #define REG_FIFO_ELEMENT_PF_SHIFT               24
    5451                 :            : #define REG_FIFO_ELEMENT_PF_MASK                0xf
    5452                 :            : #define REG_FIFO_ELEMENT_VF_SHIFT               28
    5453                 :            : #define REG_FIFO_ELEMENT_VF_MASK                0xff
    5454                 :            : #define REG_FIFO_ELEMENT_PORT_SHIFT             36
    5455                 :            : #define REG_FIFO_ELEMENT_PORT_MASK              0x3
    5456                 :            : #define REG_FIFO_ELEMENT_PRIVILEGE_SHIFT        38
    5457                 :            : #define REG_FIFO_ELEMENT_PRIVILEGE_MASK         0x3
    5458                 :            : #define REG_FIFO_ELEMENT_PROTECTION_SHIFT       40
    5459                 :            : #define REG_FIFO_ELEMENT_PROTECTION_MASK        0x7
    5460                 :            : #define REG_FIFO_ELEMENT_MASTER_SHIFT           43
    5461                 :            : #define REG_FIFO_ELEMENT_MASTER_MASK            0xf
    5462                 :            : #define REG_FIFO_ELEMENT_ERROR_SHIFT            47
    5463                 :            : #define REG_FIFO_ELEMENT_ERROR_MASK             0x1f
    5464                 :            : };
    5465                 :            : 
    5466                 :            : /* REG fifo error element */
    5467                 :            : struct reg_fifo_err {
    5468                 :            :         u32 err_code;
    5469                 :            :         const char *err_msg;
    5470                 :            : };
    5471                 :            : 
    5472                 :            : /* IGU fifo element */
    5473                 :            : struct igu_fifo_element {
    5474                 :            :         u32 dword0;
    5475                 :            : #define IGU_FIFO_ELEMENT_DWORD0_FID_SHIFT               0
    5476                 :            : #define IGU_FIFO_ELEMENT_DWORD0_FID_MASK                0xff
    5477                 :            : #define IGU_FIFO_ELEMENT_DWORD0_IS_PF_SHIFT             8
    5478                 :            : #define IGU_FIFO_ELEMENT_DWORD0_IS_PF_MASK              0x1
    5479                 :            : #define IGU_FIFO_ELEMENT_DWORD0_SOURCE_SHIFT            9
    5480                 :            : #define IGU_FIFO_ELEMENT_DWORD0_SOURCE_MASK             0xf
    5481                 :            : #define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_SHIFT          13
    5482                 :            : #define IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE_MASK           0xf
    5483                 :            : #define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_SHIFT          17
    5484                 :            : #define IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR_MASK           0x7fff
    5485                 :            :         u32 dword1;
    5486                 :            :         u32 dword2;
    5487                 :            : #define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_SHIFT        0
    5488                 :            : #define IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD_MASK         0x1
    5489                 :            : #define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_SHIFT          1
    5490                 :            : #define IGU_FIFO_ELEMENT_DWORD12_WR_DATA_MASK           0xffffffff
    5491                 :            :         u32 reserved;
    5492                 :            : };
    5493                 :            : 
    5494                 :            : struct igu_fifo_wr_data {
    5495                 :            :         u32 data;
    5496                 :            : #define IGU_FIFO_WR_DATA_PROD_CONS_SHIFT                0
    5497                 :            : #define IGU_FIFO_WR_DATA_PROD_CONS_MASK                 0xffffff
    5498                 :            : #define IGU_FIFO_WR_DATA_UPDATE_FLAG_SHIFT              24
    5499                 :            : #define IGU_FIFO_WR_DATA_UPDATE_FLAG_MASK               0x1
    5500                 :            : #define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_SHIFT        25
    5501                 :            : #define IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB_MASK         0x3
    5502                 :            : #define IGU_FIFO_WR_DATA_SEGMENT_SHIFT                  27
    5503                 :            : #define IGU_FIFO_WR_DATA_SEGMENT_MASK                   0x1
    5504                 :            : #define IGU_FIFO_WR_DATA_TIMER_MASK_SHIFT               28
    5505                 :            : #define IGU_FIFO_WR_DATA_TIMER_MASK_MASK                0x1
    5506                 :            : #define IGU_FIFO_WR_DATA_CMD_TYPE_SHIFT                 31
    5507                 :            : #define IGU_FIFO_WR_DATA_CMD_TYPE_MASK                  0x1
    5508                 :            : };
    5509                 :            : 
    5510                 :            : struct igu_fifo_cleanup_wr_data {
    5511                 :            :         u32 data;
    5512                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_SHIFT         0
    5513                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_RESERVED_MASK          0x7ffffff
    5514                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_SHIFT      27
    5515                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL_MASK       0x1
    5516                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_SHIFT     28
    5517                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE_MASK      0x7
    5518                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_SHIFT         31
    5519                 :            : #define IGU_FIFO_CLEANUP_WR_DATA_CMD_TYPE_MASK          0x1
    5520                 :            : };
    5521                 :            : 
    5522                 :            : /* Protection override element */
    5523                 :            : struct protection_override_element {
    5524                 :            :         u64 data;
    5525                 :            : #define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_SHIFT               0
    5526                 :            : #define PROTECTION_OVERRIDE_ELEMENT_ADDRESS_MASK                0x7fffff
    5527                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_SHIFT           23
    5528                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE_MASK            0xffffff
    5529                 :            : #define PROTECTION_OVERRIDE_ELEMENT_READ_SHIFT                  47
    5530                 :            : #define PROTECTION_OVERRIDE_ELEMENT_READ_MASK                   0x1
    5531                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WRITE_SHIFT                 48
    5532                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WRITE_MASK                  0x1
    5533                 :            : #define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_SHIFT       49
    5534                 :            : #define PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION_MASK        0x7
    5535                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_SHIFT      52
    5536                 :            : #define PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION_MASK       0x7
    5537                 :            : };
    5538                 :            : 
    5539                 :            : enum igu_fifo_sources {
    5540                 :            :         IGU_SRC_PXP0,
    5541                 :            :         IGU_SRC_PXP1,
    5542                 :            :         IGU_SRC_PXP2,
    5543                 :            :         IGU_SRC_PXP3,
    5544                 :            :         IGU_SRC_PXP4,
    5545                 :            :         IGU_SRC_PXP5,
    5546                 :            :         IGU_SRC_PXP6,
    5547                 :            :         IGU_SRC_PXP7,
    5548                 :            :         IGU_SRC_CAU,
    5549                 :            :         IGU_SRC_ATTN,
    5550                 :            :         IGU_SRC_GRC
    5551                 :            : };
    5552                 :            : 
    5553                 :            : enum igu_fifo_addr_types {
    5554                 :            :         IGU_ADDR_TYPE_MSIX_MEM,
    5555                 :            :         IGU_ADDR_TYPE_WRITE_PBA,
    5556                 :            :         IGU_ADDR_TYPE_WRITE_INT_ACK,
    5557                 :            :         IGU_ADDR_TYPE_WRITE_ATTN_BITS,
    5558                 :            :         IGU_ADDR_TYPE_READ_INT,
    5559                 :            :         IGU_ADDR_TYPE_WRITE_PROD_UPDATE,
    5560                 :            :         IGU_ADDR_TYPE_RESERVED
    5561                 :            : };
    5562                 :            : 
    5563                 :            : struct igu_fifo_addr_data {
    5564                 :            :         u16 start_addr;
    5565                 :            :         u16 end_addr;
    5566                 :            :         const char *desc;
    5567                 :            :         const char *vf_desc;
    5568                 :            :         enum igu_fifo_addr_types type;
    5569                 :            : };
    5570                 :            : 
    5571                 :            : /******************************** Constants **********************************/
    5572                 :            : 
    5573                 :            : #define MAX_MSG_LEN                             1024
    5574                 :            : 
    5575                 :            : #define MCP_TRACE_MAX_MODULE_LEN                8
    5576                 :            : #define MCP_TRACE_FORMAT_MAX_PARAMS             3
    5577                 :            : #define MCP_TRACE_FORMAT_PARAM_WIDTH \
    5578                 :            :         (MCP_TRACE_FORMAT_P2_SIZE_OFFSET - MCP_TRACE_FORMAT_P1_SIZE_OFFSET)
    5579                 :            : 
    5580                 :            : #define REG_FIFO_ELEMENT_ADDR_FACTOR            4
    5581                 :            : #define REG_FIFO_ELEMENT_IS_PF_VF_VAL           127
    5582                 :            : 
    5583                 :            : #define PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR 4
    5584                 :            : 
    5585                 :            : /***************************** Constant Arrays *******************************/
    5586                 :            : 
    5587                 :            : /* Status string array */
    5588                 :            : static const char * const s_status_str[] = {
    5589                 :            :         /* DBG_STATUS_OK */
    5590                 :            :         "Operation completed successfully",
    5591                 :            : 
    5592                 :            :         /* DBG_STATUS_APP_VERSION_NOT_SET */
    5593                 :            :         "Debug application version wasn't set",
    5594                 :            : 
    5595                 :            :         /* DBG_STATUS_UNSUPPORTED_APP_VERSION */
    5596                 :            :         "Unsupported debug application version",
    5597                 :            : 
    5598                 :            :         /* DBG_STATUS_DBG_BLOCK_NOT_RESET */
    5599                 :            :         "The debug block wasn't reset since the last recording",
    5600                 :            : 
    5601                 :            :         /* DBG_STATUS_INVALID_ARGS */
    5602                 :            :         "Invalid arguments",
    5603                 :            : 
    5604                 :            :         /* DBG_STATUS_OUTPUT_ALREADY_SET */
    5605                 :            :         "The debug output was already set",
    5606                 :            : 
    5607                 :            :         /* DBG_STATUS_INVALID_PCI_BUF_SIZE */
    5608                 :            :         "Invalid PCI buffer size",
    5609                 :            : 
    5610                 :            :         /* DBG_STATUS_PCI_BUF_ALLOC_FAILED */
    5611                 :            :         "PCI buffer allocation failed",
    5612                 :            : 
    5613                 :            :         /* DBG_STATUS_PCI_BUF_NOT_ALLOCATED */
    5614                 :            :         "A PCI buffer wasn't allocated",
    5615                 :            : 
    5616                 :            :         /* DBG_STATUS_INVALID_FILTER_TRIGGER_DWORDS */
    5617                 :            :         "The filter/trigger constraint dword offsets are not enabled for recording",
    5618                 :            : 
    5619                 :            :         /* DBG_STATUS_NO_MATCHING_FRAMING_MODE */
    5620                 :            :         "No matching frame mode",
    5621                 :            : 
    5622                 :            :         /* DBG_STATUS_VFC_READ_ERROR */
    5623                 :            :         "Error reading from VFC",
    5624                 :            : 
    5625                 :            :         /* DBG_STATUS_STORM_ALREADY_ENABLED */
    5626                 :            :         "The Storm was already enabled",
    5627                 :            : 
    5628                 :            :         /* DBG_STATUS_STORM_NOT_ENABLED */
    5629                 :            :         "The specified Storm wasn't enabled",
    5630                 :            : 
    5631                 :            :         /* DBG_STATUS_BLOCK_ALREADY_ENABLED */
    5632                 :            :         "The block was already enabled",
    5633                 :            : 
    5634                 :            :         /* DBG_STATUS_BLOCK_NOT_ENABLED */
    5635                 :            :         "The specified block wasn't enabled",
    5636                 :            : 
    5637                 :            :         /* DBG_STATUS_NO_INPUT_ENABLED */
    5638                 :            :         "No input was enabled for recording",
    5639                 :            : 
    5640                 :            :         /* DBG_STATUS_NO_FILTER_TRIGGER_256B */
    5641                 :            :         "Filters and triggers are not allowed in E4 256-bit mode",
    5642                 :            : 
    5643                 :            :         /* DBG_STATUS_FILTER_ALREADY_ENABLED */
    5644                 :            :         "The filter was already enabled",
    5645                 :            : 
    5646                 :            :         /* DBG_STATUS_TRIGGER_ALREADY_ENABLED */
    5647                 :            :         "The trigger was already enabled",
    5648                 :            : 
    5649                 :            :         /* DBG_STATUS_TRIGGER_NOT_ENABLED */
    5650                 :            :         "The trigger wasn't enabled",
    5651                 :            : 
    5652                 :            :         /* DBG_STATUS_CANT_ADD_CONSTRAINT */
    5653                 :            :         "A constraint can be added only after a filter was enabled or a trigger state was added",
    5654                 :            : 
    5655                 :            :         /* DBG_STATUS_TOO_MANY_TRIGGER_STATES */
    5656                 :            :         "Cannot add more than 3 trigger states",
    5657                 :            : 
    5658                 :            :         /* DBG_STATUS_TOO_MANY_CONSTRAINTS */
    5659                 :            :         "Cannot add more than 4 constraints per filter or trigger state",
    5660                 :            : 
    5661                 :            :         /* DBG_STATUS_RECORDING_NOT_STARTED */
    5662                 :            :         "The recording wasn't started",
    5663                 :            : 
    5664                 :            :         /* DBG_STATUS_DATA_DID_NOT_TRIGGER */
    5665                 :            :         "A trigger was configured, but it didn't trigger",
    5666                 :            : 
    5667                 :            :         /* DBG_STATUS_NO_DATA_RECORDED */
    5668                 :            :         "No data was recorded",
    5669                 :            : 
    5670                 :            :         /* DBG_STATUS_DUMP_BUF_TOO_SMALL */
    5671                 :            :         "Dump buffer is too small",
    5672                 :            : 
    5673                 :            :         /* DBG_STATUS_DUMP_NOT_CHUNK_ALIGNED */
    5674                 :            :         "Dumped data is not aligned to chunks",
    5675                 :            : 
    5676                 :            :         /* DBG_STATUS_UNKNOWN_CHIP */
    5677                 :            :         "Unknown chip",
    5678                 :            : 
    5679                 :            :         /* DBG_STATUS_VIRT_MEM_ALLOC_FAILED */
    5680                 :            :         "Failed allocating virtual memory",
    5681                 :            : 
    5682                 :            :         /* DBG_STATUS_BLOCK_IN_RESET */
    5683                 :            :         "The input block is in reset",
    5684                 :            : 
    5685                 :            :         /* DBG_STATUS_INVALID_TRACE_SIGNATURE */
    5686                 :            :         "Invalid MCP trace signature found in NVRAM",
    5687                 :            : 
    5688                 :            :         /* DBG_STATUS_INVALID_NVRAM_BUNDLE */
    5689                 :            :         "Invalid bundle ID found in NVRAM",
    5690                 :            : 
    5691                 :            :         /* DBG_STATUS_NVRAM_GET_IMAGE_FAILED */
    5692                 :            :         "Failed getting NVRAM image",
    5693                 :            : 
    5694                 :            :         /* DBG_STATUS_NON_ALIGNED_NVRAM_IMAGE */
    5695                 :            :         "NVRAM image is not dword-aligned",
    5696                 :            : 
    5697                 :            :         /* DBG_STATUS_NVRAM_READ_FAILED */
    5698                 :            :         "Failed reading from NVRAM",
    5699                 :            : 
    5700                 :            :         /* DBG_STATUS_IDLE_CHK_PARSE_FAILED */
    5701                 :            :         "Idle check parsing failed",
    5702                 :            : 
    5703                 :            :         /* DBG_STATUS_MCP_TRACE_BAD_DATA */
    5704                 :            :         "MCP Trace data is corrupt",
    5705                 :            : 
    5706                 :            :         /* DBG_STATUS_MCP_TRACE_NO_META */
    5707                 :            :         "Dump doesn't contain meta data - it must be provided in image file",
    5708                 :            : 
    5709                 :            :         /* DBG_STATUS_MCP_COULD_NOT_HALT */
    5710                 :            :         "Failed to halt MCP",
    5711                 :            : 
    5712                 :            :         /* DBG_STATUS_MCP_COULD_NOT_RESUME */
    5713                 :            :         "Failed to resume MCP after halt",
    5714                 :            : 
    5715                 :            :         /* DBG_STATUS_RESERVED0 */
    5716                 :            :         "",
    5717                 :            : 
    5718                 :            :         /* DBG_STATUS_SEMI_FIFO_NOT_EMPTY */
    5719                 :            :         "Failed to empty SEMI sync FIFO",
    5720                 :            : 
    5721                 :            :         /* DBG_STATUS_IGU_FIFO_BAD_DATA */
    5722                 :            :         "IGU FIFO data is corrupt",
    5723                 :            : 
    5724                 :            :         /* DBG_STATUS_MCP_COULD_NOT_MASK_PRTY */
    5725                 :            :         "MCP failed to mask parities",
    5726                 :            : 
    5727                 :            :         /* DBG_STATUS_FW_ASSERTS_PARSE_FAILED */
    5728                 :            :         "FW Asserts parsing failed",
    5729                 :            : 
    5730                 :            :         /* DBG_STATUS_REG_FIFO_BAD_DATA */
    5731                 :            :         "GRC FIFO data is corrupt",
    5732                 :            : 
    5733                 :            :         /* DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA */
    5734                 :            :         "Protection Override data is corrupt",
    5735                 :            : 
    5736                 :            :         /* DBG_STATUS_DBG_ARRAY_NOT_SET */
    5737                 :            :         "Debug arrays were not set (when using binary files, dbg_set_bin_ptr must be called)",
    5738                 :            : 
    5739                 :            :         /* DBG_STATUS_RESERVED1 */
    5740                 :            :         "",
    5741                 :            : 
    5742                 :            :         /* DBG_STATUS_NON_MATCHING_LINES */
    5743                 :            :         "Non-matching debug lines - in E4, all lines must be of the same type (either 128b or 256b)",
    5744                 :            : 
    5745                 :            :         /* DBG_STATUS_INSUFFICIENT_HW_IDS */
    5746                 :            :         "Insufficient HW IDs. Try to record less Storms/blocks",
    5747                 :            : 
    5748                 :            :         /* DBG_STATUS_DBG_BUS_IN_USE */
    5749                 :            :         "The debug bus is in use",
    5750                 :            : 
    5751                 :            :         /* DBG_STATUS_INVALID_STORM_DBG_MODE */
    5752                 :            :         "The storm debug mode is not supported in the current chip",
    5753                 :            : 
    5754                 :            :         /* DBG_STATUS_OTHER_ENGINE_BB_ONLY */
    5755                 :            :         "Other engine is supported only in BB",
    5756                 :            : 
    5757                 :            :         /* DBG_STATUS_FILTER_SINGLE_HW_ID */
    5758                 :            :         "The configured filter mode requires a single Storm/block input",
    5759                 :            : 
    5760                 :            :         /* DBG_STATUS_TRIGGER_SINGLE_HW_ID */
    5761                 :            :         "The configured filter mode requires that all the constraints of a single trigger state will be defined on a single Storm/block input",
    5762                 :            : 
    5763                 :            :         /* DBG_STATUS_MISSING_TRIGGER_STATE_STORM */
    5764                 :            :         "When triggering on Storm data, the Storm to trigger on must be specified"
    5765                 :            : };
    5766                 :            : static_assert(RTE_DIM(s_status_str) == MAX_DBG_STATUS, "status string table mismatch");
    5767                 :            : 
    5768                 :            : /* Idle check severity names array */
    5769                 :            : static const char * const s_idle_chk_severity_str[] = {
    5770                 :            :         "Error",
    5771                 :            :         "Error if no traffic",
    5772                 :            :         "Warning"
    5773                 :            : };
    5774                 :            : 
    5775                 :            : /* MCP Trace level names array */
    5776                 :            : static const char * const s_mcp_trace_level_str[] = {
    5777                 :            :         "ERROR",
    5778                 :            :         "TRACE",
    5779                 :            :         "DEBUG"
    5780                 :            : };
    5781                 :            : 
    5782                 :            : /* Access type names array */
    5783                 :            : static const char * const s_access_strs[] = {
    5784                 :            :         "read",
    5785                 :            :         "write"
    5786                 :            : };
    5787                 :            : 
    5788                 :            : /* Privilege type names array */
    5789                 :            : static const char * const s_privilege_strs[] = {
    5790                 :            :         "VF",
    5791                 :            :         "PDA",
    5792                 :            :         "HV",
    5793                 :            :         "UA"
    5794                 :            : };
    5795                 :            : 
    5796                 :            : /* Protection type names array */
    5797                 :            : static const char * const s_protection_strs[] = {
    5798                 :            :         "(default)",
    5799                 :            :         "(default)",
    5800                 :            :         "(default)",
    5801                 :            :         "(default)",
    5802                 :            :         "override VF",
    5803                 :            :         "override PDA",
    5804                 :            :         "override HV",
    5805                 :            :         "override UA"
    5806                 :            : };
    5807                 :            : 
    5808                 :            : /* Master type names array */
    5809                 :            : static const char * const s_master_strs[] = {
    5810                 :            :         "???",
    5811                 :            :         "pxp",
    5812                 :            :         "mcp",
    5813                 :            :         "msdm",
    5814                 :            :         "psdm",
    5815                 :            :         "ysdm",
    5816                 :            :         "usdm",
    5817                 :            :         "tsdm",
    5818                 :            :         "xsdm",
    5819                 :            :         "dbu",
    5820                 :            :         "dmae",
    5821                 :            :         "jdap",
    5822                 :            :         "???",
    5823                 :            :         "???",
    5824                 :            :         "???",
    5825                 :            :         "???"
    5826                 :            : };
    5827                 :            : 
    5828                 :            : /* REG FIFO error messages array */
    5829                 :            : static struct reg_fifo_err s_reg_fifo_errors[] = {
    5830                 :            :         {1, "grc timeout"},
    5831                 :            :         {2, "address doesn't belong to any block"},
    5832                 :            :         {4, "reserved address in block or write to read-only address"},
    5833                 :            :         {8, "privilege/protection mismatch"},
    5834                 :            :         {16, "path isolation error"},
    5835                 :            :         {17, "RSL error"}
    5836                 :            : };
    5837                 :            : 
    5838                 :            : /* IGU FIFO sources array */
    5839                 :            : static const char * const s_igu_fifo_source_strs[] = {
    5840                 :            :         "TSTORM",
    5841                 :            :         "MSTORM",
    5842                 :            :         "USTORM",
    5843                 :            :         "XSTORM",
    5844                 :            :         "YSTORM",
    5845                 :            :         "PSTORM",
    5846                 :            :         "PCIE",
    5847                 :            :         "NIG_QM_PBF",
    5848                 :            :         "CAU",
    5849                 :            :         "ATTN",
    5850                 :            :         "GRC",
    5851                 :            : };
    5852                 :            : 
    5853                 :            : /* IGU FIFO error messages */
    5854                 :            : static const char * const s_igu_fifo_error_strs[] = {
    5855                 :            :         "no error",
    5856                 :            :         "length error",
    5857                 :            :         "function disabled",
    5858                 :            :         "VF sent command to attention address",
    5859                 :            :         "host sent prod update command",
    5860                 :            :         "read of during interrupt register while in MIMD mode",
    5861                 :            :         "access to PXP BAR reserved address",
    5862                 :            :         "producer update command to attention index",
    5863                 :            :         "unknown error",
    5864                 :            :         "SB index not valid",
    5865                 :            :         "SB relative index and FID not found",
    5866                 :            :         "FID not match",
    5867                 :            :         "command with error flag asserted (PCI error or CAU discard)",
    5868                 :            :         "VF sent cleanup and RF cleanup is disabled",
    5869                 :            :         "cleanup command on type bigger than 4"
    5870                 :            : };
    5871                 :            : 
    5872                 :            : /* IGU FIFO address data */
    5873                 :            : static const struct igu_fifo_addr_data s_igu_fifo_addr_data[] = {
    5874                 :            :         {0x0, 0x101, "MSI-X Memory", NULL,
    5875                 :            :          IGU_ADDR_TYPE_MSIX_MEM},
    5876                 :            :         {0x102, 0x1ff, "reserved", NULL,
    5877                 :            :          IGU_ADDR_TYPE_RESERVED},
    5878                 :            :         {0x200, 0x200, "Write PBA[0:63]", NULL,
    5879                 :            :          IGU_ADDR_TYPE_WRITE_PBA},
    5880                 :            :         {0x201, 0x201, "Write PBA[64:127]", "reserved",
    5881                 :            :          IGU_ADDR_TYPE_WRITE_PBA},
    5882                 :            :         {0x202, 0x202, "Write PBA[128]", "reserved",
    5883                 :            :          IGU_ADDR_TYPE_WRITE_PBA},
    5884                 :            :         {0x203, 0x3ff, "reserved", NULL,
    5885                 :            :          IGU_ADDR_TYPE_RESERVED},
    5886                 :            :         {0x400, 0x5ef, "Write interrupt acknowledgment", NULL,
    5887                 :            :          IGU_ADDR_TYPE_WRITE_INT_ACK},
    5888                 :            :         {0x5f0, 0x5f0, "Attention bits update", NULL,
    5889                 :            :          IGU_ADDR_TYPE_WRITE_ATTN_BITS},
    5890                 :            :         {0x5f1, 0x5f1, "Attention bits set", NULL,
    5891                 :            :          IGU_ADDR_TYPE_WRITE_ATTN_BITS},
    5892                 :            :         {0x5f2, 0x5f2, "Attention bits clear", NULL,
    5893                 :            :          IGU_ADDR_TYPE_WRITE_ATTN_BITS},
    5894                 :            :         {0x5f3, 0x5f3, "Read interrupt 0:63 with mask", NULL,
    5895                 :            :          IGU_ADDR_TYPE_READ_INT},
    5896                 :            :         {0x5f4, 0x5f4, "Read interrupt 0:31 with mask", NULL,
    5897                 :            :          IGU_ADDR_TYPE_READ_INT},
    5898                 :            :         {0x5f5, 0x5f5, "Read interrupt 32:63 with mask", NULL,
    5899                 :            :          IGU_ADDR_TYPE_READ_INT},
    5900                 :            :         {0x5f6, 0x5f6, "Read interrupt 0:63 without mask", NULL,
    5901                 :            :          IGU_ADDR_TYPE_READ_INT},
    5902                 :            :         {0x5f7, 0x5ff, "reserved", NULL,
    5903                 :            :          IGU_ADDR_TYPE_RESERVED},
    5904                 :            :         {0x600, 0x7ff, "Producer update", NULL,
    5905                 :            :          IGU_ADDR_TYPE_WRITE_PROD_UPDATE}
    5906                 :            : };
    5907                 :            : 
    5908                 :            : /******************************** Variables **********************************/
    5909                 :            : 
    5910                 :            : /* Temporary buffer, used for print size calculations */
    5911                 :            : static char s_temp_buf[MAX_MSG_LEN];
    5912                 :            : 
    5913                 :            : /**************************** Private Functions ******************************/
    5914                 :            : 
    5915                 :            : static u32 qed_cyclic_add(u32 a, u32 b, u32 size)
    5916                 :            : {
    5917                 :          0 :         return (a + b) % size;
    5918                 :            : }
    5919                 :            : 
    5920                 :            : static u32 qed_cyclic_sub(u32 a, u32 b, u32 size)
    5921                 :            : {
    5922                 :          0 :         return (size + a - b) % size;
    5923                 :            : }
    5924                 :            : 
    5925                 :            : /* Reads the specified number of bytes from the specified cyclic buffer (up to 4
    5926                 :            :  * bytes) and returns them as a dword value. the specified buffer offset is
    5927                 :            :  * updated.
    5928                 :            :  */
    5929                 :            : static u32 qed_read_from_cyclic_buf(void *buf,
    5930                 :            :                                     u32 *offset,
    5931                 :            :                                     u32 buf_size, u8 num_bytes_to_read)
    5932                 :            : {
    5933                 :            :         u8 i, *val_ptr, *bytes_buf = (u8 *)buf;
    5934                 :          0 :         u32 val = 0;
    5935                 :            : 
    5936                 :            :         val_ptr = (u8 *)&val;
    5937                 :            : 
    5938                 :            :         /* Assume running on a LITTLE ENDIAN and the buffer is network order
    5939                 :            :          * (BIG ENDIAN), as high order bytes are placed in lower memory address.
    5940                 :            :          */
    5941   [ #  #  #  # ]:          0 :         for (i = 0; i < num_bytes_to_read; i++) {
    5942                 :          0 :                 val_ptr[i] = bytes_buf[*offset];
    5943                 :            :                 *offset = qed_cyclic_add(*offset, 1, buf_size);
    5944                 :            :         }
    5945                 :            : 
    5946                 :          0 :         return val;
    5947                 :            : }
    5948                 :            : 
    5949                 :            : /* Reads and returns the next byte from the specified buffer.
    5950                 :            :  * The specified buffer offset is updated.
    5951                 :            :  */
    5952                 :            : static u8 qed_read_byte_from_buf(void *buf, u32 *offset)
    5953                 :            : {
    5954                 :          0 :         return ((u8 *)buf)[(*offset)++];
    5955                 :            : }
    5956                 :            : 
    5957                 :            : /* Reads and returns the next dword from the specified buffer.
    5958                 :            :  * The specified buffer offset is updated.
    5959                 :            :  */
    5960                 :            : static u32 qed_read_dword_from_buf(void *buf, u32 *offset)
    5961                 :            : {
    5962                 :          0 :         u32 dword_val = *(u32 *)&((u8 *)buf)[*offset];
    5963                 :            : 
    5964                 :          0 :         *offset += 4;
    5965                 :            : 
    5966                 :            :         return dword_val;
    5967                 :            : }
    5968                 :            : 
    5969                 :            : /* Reads the next string from the specified buffer, and copies it to the
    5970                 :            :  * specified pointer. The specified buffer offset is updated.
    5971                 :            :  */
    5972                 :            : static void qed_read_str_from_buf(void *buf, u32 *offset, u32 size, char *dest)
    5973                 :            : {
    5974                 :          0 :         const char *source_str = &((const char *)buf)[*offset];
    5975                 :            : 
    5976                 :          0 :         OSAL_STRNCPY(dest, source_str, size);
    5977                 :          0 :         dest[size - 1] = '\0';
    5978                 :          0 :         *offset += size;
    5979                 :            : }
    5980                 :            : 
    5981                 :            : /* Returns a pointer to the specified offset (in bytes) of the specified buffer.
    5982                 :            :  * If the specified buffer in NULL, a temporary buffer pointer is returned.
    5983                 :            :  */
    5984                 :            : static char *qed_get_buf_ptr(void *buf, u32 offset)
    5985                 :            : {
    5986   [ #  #  #  #  :          0 :         return buf ? (char *)buf + offset : s_temp_buf;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    5987                 :            : }
    5988                 :            : 
    5989                 :            : /* Reads a param from the specified buffer. Returns the number of dwords read.
    5990                 :            :  * If the returned str_param is NULL, the param is numeric and its value is
    5991                 :            :  * returned in num_param.
    5992                 :            :  * Otherwise, the param is a string and its pointer is returned in str_param.
    5993                 :            :  */
    5994                 :          0 : static u32 qed_read_param(u32 *dump_buf,
    5995                 :            :                           const char **param_name,
    5996                 :            :                           const char **param_str_val, u32 *param_num_val)
    5997                 :            : {
    5998                 :            :         char *char_buf = (char *)dump_buf;
    5999                 :            :         size_t offset = 0;
    6000                 :            : 
    6001                 :            :         /* Extract param name */
    6002                 :          0 :         *param_name = char_buf;
    6003                 :          0 :         offset += strlen(*param_name) + 1;
    6004                 :            : 
    6005                 :            :         /* Check param type */
    6006         [ #  # ]:          0 :         if (*(char_buf + offset++)) {
    6007                 :            :                 /* String param */
    6008                 :          0 :                 *param_str_val = char_buf + offset;
    6009                 :          0 :                 *param_num_val = 0;
    6010                 :          0 :                 offset += strlen(*param_str_val) + 1;
    6011         [ #  # ]:          0 :                 if (offset & 0x3)
    6012                 :          0 :                         offset += (4 - (offset & 0x3));
    6013                 :            :         } else {
    6014                 :            :                 /* Numeric param */
    6015                 :          0 :                 *param_str_val = NULL;
    6016         [ #  # ]:          0 :                 if (offset & 0x3)
    6017                 :          0 :                         offset += (4 - (offset & 0x3));
    6018                 :          0 :                 *param_num_val = *(u32 *)(char_buf + offset);
    6019                 :          0 :                 offset += 4;
    6020                 :            :         }
    6021                 :            : 
    6022                 :          0 :         return (u32)offset / 4;
    6023                 :            : }
    6024                 :            : 
    6025                 :            : /* Reads a section header from the specified buffer.
    6026                 :            :  * Returns the number of dwords read.
    6027                 :            :  */
    6028                 :            : static u32 qed_read_section_hdr(u32 *dump_buf,
    6029                 :            :                                 const char **section_name,
    6030                 :            :                                 u32 *num_section_params)
    6031                 :            : {
    6032                 :            :         const char *param_str_val;
    6033                 :            : 
    6034                 :          0 :         return qed_read_param(dump_buf,
    6035                 :            :                               section_name, &param_str_val, num_section_params);
    6036                 :            : }
    6037                 :            : 
    6038                 :            : /* Reads section params from the specified buffer and prints them to the results
    6039                 :            :  * buffer. Returns the number of dwords read.
    6040                 :            :  */
    6041                 :          0 : static u32 qed_print_section_params(u32 *dump_buf,
    6042                 :            :                                     u32 num_section_params,
    6043                 :            :                                     char *results_buf, u32 *num_chars_printed)
    6044                 :            : {
    6045                 :            :         u32 i, dump_offset = 0, results_offset = 0;
    6046                 :            : 
    6047         [ #  # ]:          0 :         for (i = 0; i < num_section_params; i++) {
    6048                 :            :                 const char *param_name, *param_str_val;
    6049                 :          0 :                 u32 param_num_val = 0;
    6050                 :            : 
    6051                 :          0 :                 dump_offset += qed_read_param(dump_buf + dump_offset,
    6052                 :            :                                               &param_name,
    6053                 :            :                                               &param_str_val, &param_num_val);
    6054                 :            : 
    6055         [ #  # ]:          0 :                 if (param_str_val) {
    6056                 :          0 :                         results_offset +=
    6057         [ #  # ]:          0 :                                 sprintf(qed_get_buf_ptr(results_buf,
    6058                 :            :                                                         results_offset),
    6059                 :            :                                         "%s: %s\n", param_name, param_str_val);
    6060         [ #  # ]:          0 :                 } else if (strcmp(param_name, "fw-timestamp")) {
    6061                 :          0 :                         results_offset +=
    6062         [ #  # ]:          0 :                                 sprintf(qed_get_buf_ptr(results_buf,
    6063                 :            :                                                         results_offset),
    6064                 :            :                                         "%s: %d\n", param_name, param_num_val);
    6065                 :            :                 }
    6066                 :            :         }
    6067                 :            : 
    6068                 :          0 :         results_offset += sprintf(qed_get_buf_ptr(results_buf, results_offset),
    6069                 :            :                                   "\n");
    6070                 :            : 
    6071                 :          0 :         *num_chars_printed = results_offset;
    6072                 :            : 
    6073                 :          0 :         return dump_offset;
    6074                 :            : }
    6075                 :            : 
    6076                 :            : /* Returns the block name that matches the specified block ID,
    6077                 :            :  * or NULL if not found.
    6078                 :            :  */
    6079                 :            : static const char *qed_dbg_get_block_name(struct ecore_hwfn *p_hwfn,
    6080                 :            :                                           enum block_id block_id)
    6081                 :            : {
    6082                 :          0 :         const struct dbg_block_user *block =
    6083                 :            :             (const struct dbg_block_user *)
    6084                 :          0 :             p_hwfn->dbg_arrays[BIN_BUF_DBG_BLOCKS_USER_DATA].ptr + block_id;
    6085                 :            : 
    6086                 :          0 :         return (const char *)block->name;
    6087                 :            : }
    6088                 :            : 
    6089                 :            : static struct dbg_tools_user_data *qed_dbg_get_user_data(struct ecore_hwfn
    6090                 :            :                                                          *p_hwfn)
    6091                 :            : {
    6092                 :          0 :         return (struct dbg_tools_user_data *)p_hwfn->dbg_user_info;
    6093                 :            : }
    6094                 :            : 
    6095                 :            : /* Parses the idle check rules and returns the number of characters printed.
    6096                 :            :  * In case of parsing error, returns 0.
    6097                 :            :  */
    6098                 :          0 : static u32 qed_parse_idle_chk_dump_rules(struct ecore_hwfn *p_hwfn,
    6099                 :            :                                          u32 *dump_buf,
    6100                 :            :                                          u32 *dump_buf_end,
    6101                 :            :                                          u32 num_rules,
    6102                 :            :                                          bool print_fw_idle_chk,
    6103                 :            :                                          char *results_buf,
    6104                 :            :                                          u32 *num_errors, u32 *num_warnings)
    6105                 :            : {
    6106                 :            :         /* Offset in results_buf in bytes */
    6107                 :            :         u32 results_offset = 0;
    6108                 :            : 
    6109                 :            :         u32 rule_idx;
    6110                 :            :         u16 i, j;
    6111                 :            : 
    6112                 :          0 :         *num_errors = 0;
    6113                 :          0 :         *num_warnings = 0;
    6114                 :            : 
    6115                 :            :         /* Go over dumped results */
    6116         [ #  # ]:          0 :         for (rule_idx = 0; rule_idx < num_rules && dump_buf < dump_buf_end;
    6117                 :          0 :              rule_idx++) {
    6118                 :            :                 const struct dbg_idle_chk_rule_parsing_data *rule_parsing_data;
    6119                 :            :                 struct dbg_idle_chk_result_hdr *hdr;
    6120                 :            :                 const char *parsing_str, *lsi_msg;
    6121                 :            :                 u32 parsing_str_offset;
    6122                 :            :                 bool has_fw_msg;
    6123                 :            :                 u8 curr_reg_id;
    6124                 :            : 
    6125                 :            :                 hdr = (struct dbg_idle_chk_result_hdr *)dump_buf;
    6126                 :          0 :                 rule_parsing_data =
    6127                 :            :                     (const struct dbg_idle_chk_rule_parsing_data *)
    6128                 :          0 :                     p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].ptr +
    6129                 :          0 :                     hdr->rule_id;
    6130                 :          0 :                 parsing_str_offset =
    6131                 :          0 :                     GET_FIELD(rule_parsing_data->data,
    6132                 :            :                               DBG_IDLE_CHK_RULE_PARSING_DATA_STR_OFFSET);
    6133                 :          0 :                 has_fw_msg =
    6134                 :          0 :                     GET_FIELD(rule_parsing_data->data,
    6135                 :            :                               DBG_IDLE_CHK_RULE_PARSING_DATA_HAS_FW_MSG) > 0;
    6136                 :          0 :                 parsing_str = (const char *)
    6137                 :          0 :                     p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr +
    6138                 :            :                     parsing_str_offset;
    6139                 :            :                 lsi_msg = parsing_str;
    6140                 :            :                 curr_reg_id = 0;
    6141                 :            : 
    6142         [ #  # ]:          0 :                 if (hdr->severity >= MAX_DBG_IDLE_CHK_SEVERITY_TYPES)
    6143                 :            :                         return 0;
    6144                 :            : 
    6145                 :            :                 /* Skip rule header */
    6146                 :          0 :                 dump_buf += BYTES_TO_DWORDS(sizeof(*hdr));
    6147                 :            : 
    6148                 :            :                 /* Update errors/warnings count */
    6149         [ #  # ]:          0 :                 if (hdr->severity == IDLE_CHK_SEVERITY_ERROR ||
    6150                 :            :                     hdr->severity == IDLE_CHK_SEVERITY_ERROR_NO_TRAFFIC)
    6151                 :          0 :                         (*num_errors)++;
    6152                 :            :                 else
    6153                 :          0 :                         (*num_warnings)++;
    6154                 :            : 
    6155                 :            :                 /* Print rule severity */
    6156                 :          0 :                 results_offset +=
    6157                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6158                 :            :                                             results_offset), "%s: ",
    6159         [ #  # ]:          0 :                             s_idle_chk_severity_str[hdr->severity]);
    6160                 :            : 
    6161                 :            :                 /* Print rule message */
    6162         [ #  # ]:          0 :                 if (has_fw_msg)
    6163                 :          0 :                         parsing_str += strlen(parsing_str) + 1;
    6164                 :          0 :                 results_offset +=
    6165                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6166                 :            :                                             results_offset), "%s.",
    6167         [ #  # ]:          0 :                             has_fw_msg &&
    6168                 :            :                             print_fw_idle_chk ? parsing_str : lsi_msg);
    6169         [ #  # ]:          0 :                 parsing_str += strlen(parsing_str) + 1;
    6170                 :            : 
    6171                 :            :                 /* Print register values */
    6172                 :          0 :                 results_offset +=
    6173                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6174                 :            :                                             results_offset), " Registers:");
    6175                 :          0 :                 for (i = 0;
    6176         [ #  # ]:          0 :                      i < hdr->num_dumped_cond_regs + hdr->num_dumped_info_regs;
    6177                 :          0 :                      i++) {
    6178                 :            :                         struct dbg_idle_chk_result_reg_hdr *reg_hdr;
    6179                 :            :                         bool is_mem;
    6180                 :            :                         u8 reg_id;
    6181                 :            : 
    6182                 :            :                         reg_hdr =
    6183                 :            :                                 (struct dbg_idle_chk_result_reg_hdr *)dump_buf;
    6184                 :          0 :                         is_mem = GET_FIELD(reg_hdr->data,
    6185                 :            :                                            DBG_IDLE_CHK_RESULT_REG_HDR_IS_MEM);
    6186                 :          0 :                         reg_id = GET_FIELD(reg_hdr->data,
    6187                 :            :                                            DBG_IDLE_CHK_RESULT_REG_HDR_REG_ID);
    6188                 :            : 
    6189                 :            :                         /* Skip reg header */
    6190                 :          0 :                         dump_buf += BYTES_TO_DWORDS(sizeof(*reg_hdr));
    6191                 :            : 
    6192                 :            :                         /* Skip register names until the required reg_id is
    6193                 :            :                          * reached.
    6194                 :            :                          */
    6195         [ #  # ]:          0 :                         while (reg_id > curr_reg_id) {
    6196                 :          0 :                                 curr_reg_id++;
    6197                 :          0 :                                 parsing_str += strlen(parsing_str) + 1;
    6198                 :            :                         }
    6199                 :            : 
    6200                 :          0 :                         results_offset +=
    6201                 :          0 :                             sprintf(qed_get_buf_ptr(results_buf,
    6202                 :            :                                                     results_offset), " %s",
    6203                 :            :                                     parsing_str);
    6204   [ #  #  #  # ]:          0 :                         if (i < hdr->num_dumped_cond_regs && is_mem)
    6205                 :          0 :                                 results_offset +=
    6206                 :          0 :                                     sprintf(qed_get_buf_ptr(results_buf,
    6207                 :            :                                                             results_offset),
    6208                 :          0 :                                             "[%d]", hdr->mem_entry_id +
    6209         [ #  # ]:          0 :                                             reg_hdr->start_entry);
    6210                 :          0 :                         results_offset +=
    6211                 :          0 :                             sprintf(qed_get_buf_ptr(results_buf,
    6212                 :            :                                                     results_offset), "=");
    6213         [ #  # ]:          0 :                         for (j = 0; j < reg_hdr->size; j++, dump_buf++) {
    6214                 :          0 :                                 results_offset +=
    6215         [ #  # ]:          0 :                                     sprintf(qed_get_buf_ptr(results_buf,
    6216                 :            :                                                             results_offset),
    6217                 :            :                                             "0x%x", *dump_buf);
    6218         [ #  # ]:          0 :                                 if (j < reg_hdr->size - 1)
    6219                 :          0 :                                         results_offset +=
    6220                 :          0 :                                             sprintf(qed_get_buf_ptr
    6221                 :            :                                                     (results_buf,
    6222                 :            :                                                      results_offset), ",");
    6223                 :            :                         }
    6224                 :            :                 }
    6225                 :            : 
    6226                 :          0 :                 results_offset +=
    6227                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf, results_offset), "\n");
    6228                 :            :         }
    6229                 :            : 
    6230                 :            :         /* Check if end of dump buffer was exceeded */
    6231         [ #  # ]:          0 :         if (dump_buf > dump_buf_end)
    6232                 :          0 :                 return 0;
    6233                 :            : 
    6234                 :            :         return results_offset;
    6235                 :            : }
    6236                 :            : 
    6237                 :            : /* Parses an idle check dump buffer.
    6238                 :            :  * If result_buf is not NULL, the idle check results are printed to it.
    6239                 :            :  * In any case, the required results buffer size is assigned to
    6240                 :            :  * parsed_results_bytes.
    6241                 :            :  * The parsing status is returned.
    6242                 :            :  */
    6243                 :          0 : static enum dbg_status qed_parse_idle_chk_dump(struct ecore_hwfn *p_hwfn,
    6244                 :            :                                                u32 *dump_buf,
    6245                 :            :                                                u32 num_dumped_dwords,
    6246                 :            :                                                char *results_buf,
    6247                 :            :                                                u32 *parsed_results_bytes,
    6248                 :            :                                                u32 *num_errors,
    6249                 :            :                                                u32 *num_warnings)
    6250                 :            : {
    6251                 :            :         const char *section_name, *param_name, *param_str_val;
    6252                 :          0 :         u32 *dump_buf_end = dump_buf + num_dumped_dwords;
    6253                 :          0 :         u32 num_section_params = 0, num_rules;
    6254                 :            : 
    6255                 :            :         /* Offset in results_buf in bytes */
    6256                 :          0 :         u32 results_offset = 0;
    6257                 :            : 
    6258                 :          0 :         *parsed_results_bytes = 0;
    6259                 :          0 :         *num_errors = 0;
    6260                 :          0 :         *num_warnings = 0;
    6261                 :            : 
    6262         [ #  # ]:          0 :         if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr ||
    6263         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_IDLE_CHK_PARSING_DATA].ptr)
    6264                 :            :                 return DBG_STATUS_DBG_ARRAY_NOT_SET;
    6265                 :            : 
    6266                 :            :         /* Read global_params section */
    6267                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6268                 :            :                                          &section_name, &num_section_params);
    6269         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    6270                 :            :                 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
    6271                 :            : 
    6272                 :            :         /* Print global params */
    6273                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    6274                 :            :                                              num_section_params,
    6275                 :            :                                              results_buf, &results_offset);
    6276                 :            : 
    6277                 :            :         /* Read idle_chk section */
    6278                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6279                 :            :                                          &section_name, &num_section_params);
    6280   [ #  #  #  # ]:          0 :         if (strcmp(section_name, "idle_chk") || num_section_params != 1)
    6281                 :            :                 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
    6282                 :          0 :         dump_buf += qed_read_param(dump_buf,
    6283                 :            :                                    &param_name, &param_str_val, &num_rules);
    6284         [ #  # ]:          0 :         if (strcmp(param_name, "num_rules"))
    6285                 :            :                 return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
    6286                 :            : 
    6287         [ #  # ]:          0 :         if (num_rules) {
    6288                 :            :                 u32 rules_print_size;
    6289                 :            : 
    6290                 :            :                 /* Print FW output */
    6291                 :          0 :                 results_offset +=
    6292         [ #  # ]:          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6293                 :            :                                             results_offset),
    6294                 :            :                             "FW_IDLE_CHECK:\n");
    6295                 :            :                 rules_print_size =
    6296         [ #  # ]:          0 :                         qed_parse_idle_chk_dump_rules(p_hwfn,
    6297                 :            :                                                       dump_buf,
    6298                 :            :                                                       dump_buf_end,
    6299                 :            :                                                       num_rules,
    6300                 :            :                                                       true,
    6301                 :            :                                                       results_buf ?
    6302                 :          0 :                                                       results_buf +
    6303                 :            :                                                       results_offset :
    6304                 :            :                                                       NULL,
    6305                 :            :                                                       num_errors,
    6306                 :            :                                                       num_warnings);
    6307                 :          0 :                 results_offset += rules_print_size;
    6308         [ #  # ]:          0 :                 if (!rules_print_size)
    6309                 :            :                         return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
    6310                 :            : 
    6311                 :            :                 /* Print LSI output */
    6312                 :          0 :                 results_offset +=
    6313                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6314                 :            :                                             results_offset),
    6315                 :            :                             "\nLSI_IDLE_CHECK:\n");
    6316                 :            :                 rules_print_size =
    6317         [ #  # ]:          0 :                         qed_parse_idle_chk_dump_rules(p_hwfn,
    6318                 :            :                                                       dump_buf,
    6319                 :            :                                                       dump_buf_end,
    6320                 :            :                                                       num_rules,
    6321                 :            :                                                       false,
    6322                 :            :                                                       results_buf ?
    6323                 :          0 :                                                       results_buf +
    6324                 :            :                                                       results_offset :
    6325                 :            :                                                       NULL,
    6326                 :            :                                                       num_errors,
    6327                 :            :                                                       num_warnings);
    6328                 :          0 :                 results_offset += rules_print_size;
    6329         [ #  # ]:          0 :                 if (!rules_print_size)
    6330                 :            :                         return DBG_STATUS_IDLE_CHK_PARSE_FAILED;
    6331                 :            :         }
    6332                 :            : 
    6333                 :            :         /* Print errors/warnings count */
    6334         [ #  # ]:          0 :         if (*num_errors)
    6335                 :          0 :                 results_offset +=
    6336         [ #  # ]:          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6337                 :            :                                             results_offset),
    6338                 :            :                             "\nIdle Check failed!!! (with %d errors and %d warnings)\n",
    6339                 :            :                             *num_errors, *num_warnings);
    6340         [ #  # ]:          0 :         else if (*num_warnings)
    6341                 :          0 :                 results_offset +=
    6342         [ #  # ]:          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6343                 :            :                                             results_offset),
    6344                 :            :                             "\nIdle Check completed successfully (with %d warnings)\n",
    6345                 :            :                             *num_warnings);
    6346                 :            :         else
    6347                 :          0 :                 results_offset +=
    6348         [ #  # ]:          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6349                 :            :                                             results_offset),
    6350                 :            :                             "\nIdle Check completed successfully\n");
    6351                 :            : 
    6352                 :            :         /* Add 1 for string NULL termination */
    6353                 :          0 :         *parsed_results_bytes = results_offset + 1;
    6354                 :            : 
    6355                 :          0 :         return DBG_STATUS_OK;
    6356                 :            : }
    6357                 :            : 
    6358                 :            : /* Allocates and fills MCP Trace meta data based on the specified meta data
    6359                 :            :  * dump buffer.
    6360                 :            :  * Returns debug status code.
    6361                 :            :  */
    6362                 :            : static enum dbg_status
    6363                 :          0 : qed_mcp_trace_alloc_meta_data(struct ecore_hwfn *p_hwfn,
    6364                 :            :                               const u32 *meta_buf)
    6365                 :            : {
    6366                 :            :         struct dbg_tools_user_data *dev_user_data;
    6367                 :            :         u32 offset = 0, signature, i;
    6368                 :            :         struct mcp_trace_meta *meta;
    6369                 :            :         u8 *meta_buf_bytes = (u8 *)(osal_uintptr_t)meta_buf;
    6370                 :            : 
    6371                 :            :         dev_user_data = qed_dbg_get_user_data(p_hwfn);
    6372                 :          0 :         meta = &dev_user_data->mcp_trace_meta;
    6373                 :            : 
    6374                 :            :         /* Free the previous meta before loading a new one. */
    6375         [ #  # ]:          0 :         if (meta->is_allocated)
    6376                 :          0 :                 qed_mcp_trace_free_meta_data(p_hwfn);
    6377                 :            : 
    6378                 :            :         OSAL_MEMSET(meta, 0, sizeof(*meta));
    6379                 :            : 
    6380                 :            :         /* Read first signature */
    6381                 :            :         signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
    6382         [ #  # ]:          0 :         if (signature != NVM_MAGIC_VALUE)
    6383                 :            :                 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
    6384                 :            : 
    6385                 :            :         /* Read no. of modules and allocate memory for their pointers */
    6386                 :          0 :         meta->modules_num = qed_read_byte_from_buf(meta_buf_bytes, &offset);
    6387                 :          0 :         meta->modules = (char **)OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
    6388                 :            :                                     meta->modules_num * sizeof(char *));
    6389         [ #  # ]:          0 :         if (!meta->modules)
    6390                 :            :                 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    6391                 :            : 
    6392                 :            :         /* Allocate and read all module strings */
    6393         [ #  # ]:          0 :         for (i = 0; i < meta->modules_num; i++) {
    6394                 :            :                 u8 module_len = qed_read_byte_from_buf(meta_buf_bytes, &offset);
    6395                 :            : 
    6396                 :          0 :                 *(meta->modules + i) = (char *)OSAL_ZALLOC(p_hwfn->p_dev,
    6397                 :            :                                                            GFP_KERNEL,
    6398                 :            :                                                            module_len);
    6399         [ #  # ]:          0 :                 if (!(*(meta->modules + i))) {
    6400                 :            :                         /* Update number of modules to be released */
    6401         [ #  # ]:          0 :                         meta->modules_num = i ? i - 1 : 0;
    6402                 :          0 :                         return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    6403                 :            :                 }
    6404                 :            : 
    6405         [ #  # ]:          0 :                 qed_read_str_from_buf(meta_buf_bytes, &offset, module_len,
    6406                 :            :                                       *(meta->modules + i));
    6407         [ #  # ]:          0 :                 if (module_len > MCP_TRACE_MAX_MODULE_LEN)
    6408                 :          0 :                         (*(meta->modules + i))[MCP_TRACE_MAX_MODULE_LEN] = '\0';
    6409                 :            :         }
    6410                 :            : 
    6411                 :            :         /* Read second signature */
    6412                 :            :         signature = qed_read_dword_from_buf(meta_buf_bytes, &offset);
    6413         [ #  # ]:          0 :         if (signature != NVM_MAGIC_VALUE)
    6414                 :            :                 return DBG_STATUS_INVALID_TRACE_SIGNATURE;
    6415                 :            : 
    6416                 :            :         /* Read number of formats and allocate memory for all formats */
    6417                 :          0 :         meta->formats_num = qed_read_dword_from_buf(meta_buf_bytes, &offset);
    6418                 :          0 :         meta->formats =
    6419                 :          0 :                 (struct mcp_trace_format *)OSAL_ZALLOC(p_hwfn->p_dev,
    6420                 :            :                                                        GFP_KERNEL,
    6421                 :            :                                                        meta->formats_num *
    6422                 :            :                                                sizeof(struct mcp_trace_format));
    6423         [ #  # ]:          0 :         if (!meta->formats)
    6424                 :            :                 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    6425                 :            : 
    6426                 :            :         /* Allocate and read all strings */
    6427         [ #  # ]:          0 :         for (i = 0; i < meta->formats_num; i++) {
    6428                 :          0 :                 struct mcp_trace_format *format_ptr = &meta->formats[i];
    6429                 :            :                 u8 format_len;
    6430                 :            : 
    6431                 :          0 :                 format_ptr->data = qed_read_dword_from_buf(meta_buf_bytes,
    6432                 :            :                                                            &offset);
    6433                 :          0 :                 format_len = GET_MFW_FIELD(format_ptr->data,
    6434                 :            :                                            MCP_TRACE_FORMAT_LEN);
    6435                 :          0 :                 format_ptr->format_str = (char *)OSAL_ZALLOC(p_hwfn->p_dev,
    6436                 :            :                                                              GFP_KERNEL,
    6437                 :            :                                                              format_len);
    6438         [ #  # ]:          0 :                 if (!format_ptr->format_str) {
    6439                 :            :                         /* Update number of modules to be released */
    6440         [ #  # ]:          0 :                         meta->formats_num = i ? i - 1 : 0;
    6441                 :          0 :                         return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    6442                 :            :                 }
    6443                 :            : 
    6444                 :            :                 qed_read_str_from_buf(meta_buf_bytes,
    6445                 :            :                                       &offset,
    6446                 :            :                                       format_len, format_ptr->format_str);
    6447                 :            :         }
    6448                 :            : 
    6449                 :          0 :         meta->is_allocated = true;
    6450                 :          0 :         return DBG_STATUS_OK;
    6451                 :            : }
    6452                 :            : 
    6453                 :            : /* Parses an MCP trace buffer. If result_buf is not NULL, the MCP Trace results
    6454                 :            :  * are printed to it. The parsing status is returned.
    6455                 :            :  * Arguments:
    6456                 :            :  * trace_buf - MCP trace cyclic buffer
    6457                 :            :  * trace_buf_size - MCP trace cyclic buffer size in bytes
    6458                 :            :  * data_offset - offset in bytes of the data to parse in the MCP trace cyclic
    6459                 :            :  *               buffer.
    6460                 :            :  * data_size - size in bytes of data to parse.
    6461                 :            :  * parsed_buf - destination buffer for parsed data.
    6462                 :            :  * parsed_results_bytes - size of parsed data in bytes.
    6463                 :            :  */
    6464                 :          0 : static enum dbg_status qed_parse_mcp_trace_buf(struct ecore_hwfn *p_hwfn,
    6465                 :            :                                                u8 *trace_buf,
    6466                 :            :                                                u32 trace_buf_size,
    6467                 :            :                                                u32 data_offset,
    6468                 :            :                                                u32 data_size,
    6469                 :            :                                                char *parsed_buf,
    6470                 :            :                                                u32 *parsed_results_bytes)
    6471                 :            : {
    6472                 :            :         struct dbg_tools_user_data *dev_user_data;
    6473                 :            :         struct mcp_trace_meta *meta;
    6474                 :            :         u32 param_mask, param_shift;
    6475                 :            :         enum dbg_status status;
    6476                 :            : 
    6477                 :            :         dev_user_data = qed_dbg_get_user_data(p_hwfn);
    6478                 :            :         meta = &dev_user_data->mcp_trace_meta;
    6479                 :          0 :         *parsed_results_bytes = 0;
    6480                 :            : 
    6481         [ #  # ]:          0 :         if (!meta->is_allocated)
    6482                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6483                 :            : 
    6484                 :            :         status = DBG_STATUS_OK;
    6485                 :            : 
    6486         [ #  # ]:          0 :         while (data_size) {
    6487                 :            :                 struct mcp_trace_format *format_ptr;
    6488                 :            :                 u8 format_level, format_module;
    6489                 :          0 :                 u32 params[3] = { 0, 0, 0 };
    6490                 :            :                 u32 header, format_idx, i;
    6491                 :            : 
    6492         [ #  # ]:          0 :                 if (data_size < MFW_TRACE_ENTRY_SIZE)
    6493                 :          0 :                         return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6494                 :            : 
    6495                 :            :                 header = qed_read_from_cyclic_buf(trace_buf,
    6496                 :            :                                                   &data_offset,
    6497                 :            :                                                   trace_buf_size,
    6498                 :            :                                                   MFW_TRACE_ENTRY_SIZE);
    6499                 :          0 :                 data_size -= MFW_TRACE_ENTRY_SIZE;
    6500                 :          0 :                 format_idx = header & MFW_TRACE_EVENTID_MASK;
    6501                 :            : 
    6502                 :            :                 /* Skip message if its index doesn't exist in the meta data */
    6503         [ #  # ]:          0 :                 if (format_idx >= meta->formats_num) {
    6504                 :          0 :                         u8 format_size = (u8)GET_MFW_FIELD(header,
    6505                 :            :                                                            MFW_TRACE_PRM_SIZE);
    6506                 :            : 
    6507         [ #  # ]:          0 :                         if (data_size < format_size)
    6508                 :            :                                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6509                 :            : 
    6510                 :            :                         data_offset = qed_cyclic_add(data_offset,
    6511                 :            :                                                      format_size,
    6512                 :            :                                                      trace_buf_size);
    6513                 :          0 :                         data_size -= format_size;
    6514                 :          0 :                         continue;
    6515                 :            :                 }
    6516                 :            : 
    6517                 :          0 :                 format_ptr =
    6518                 :          0 :                         (struct mcp_trace_format *)&meta->formats[format_idx];
    6519                 :            : 
    6520                 :          0 :                 for (i = 0,
    6521                 :            :                      param_mask = MCP_TRACE_FORMAT_P1_SIZE_MASK, param_shift =
    6522                 :            :                      MCP_TRACE_FORMAT_P1_SIZE_OFFSET;
    6523         [ #  # ]:          0 :                      i < MCP_TRACE_FORMAT_MAX_PARAMS;
    6524                 :          0 :                      i++, param_mask <<= MCP_TRACE_FORMAT_PARAM_WIDTH,
    6525                 :          0 :                      param_shift += MCP_TRACE_FORMAT_PARAM_WIDTH) {
    6526                 :            :                         /* Extract param size (0..3) */
    6527                 :          0 :                         u8 param_size = (u8)((format_ptr->data & param_mask) >>
    6528                 :            :                                              param_shift);
    6529                 :            : 
    6530                 :            :                         /* If the param size is zero, there are no other
    6531                 :            :                          * parameters.
    6532                 :            :                          */
    6533         [ #  # ]:          0 :                         if (!param_size)
    6534                 :            :                                 break;
    6535                 :            : 
    6536                 :            :                         /* Size is encoded using 2 bits, where 3 is used to
    6537                 :            :                          * encode 4.
    6538                 :            :                          */
    6539         [ #  # ]:          0 :                         if (param_size == 3)
    6540                 :            :                                 param_size = 4;
    6541                 :            : 
    6542         [ #  # ]:          0 :                         if (data_size < param_size)
    6543                 :            :                                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6544                 :            : 
    6545                 :          0 :                         params[i] = qed_read_from_cyclic_buf(trace_buf,
    6546                 :            :                                                              &data_offset,
    6547                 :            :                                                              trace_buf_size,
    6548                 :            :                                                              param_size);
    6549                 :          0 :                         data_size -= param_size;
    6550                 :            :                 }
    6551                 :            : 
    6552                 :          0 :                 format_level = (u8)GET_MFW_FIELD(format_ptr->data,
    6553                 :            :                                                  MCP_TRACE_FORMAT_LEVEL);
    6554                 :          0 :                 format_module = (u8)GET_MFW_FIELD(format_ptr->data,
    6555                 :            :                                                   MCP_TRACE_FORMAT_MODULE);
    6556         [ #  # ]:          0 :                 if (format_level >= OSAL_ARRAY_SIZE(s_mcp_trace_level_str))
    6557                 :            :                         return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6558                 :            : 
    6559                 :            :                 /* Print current message to results buffer */
    6560                 :          0 :                 *parsed_results_bytes +=
    6561         [ #  # ]:          0 :                         OSAL_SPRINTF(qed_get_buf_ptr(parsed_buf,
    6562                 :            :                                                 *parsed_results_bytes),
    6563                 :            :                                 "%s %-8s: ",
    6564                 :            :                                 s_mcp_trace_level_str[format_level],
    6565                 :            :                                 meta->modules[format_module]);
    6566                 :          0 :                 *parsed_results_bytes +=
    6567                 :          0 :                     sprintf(qed_get_buf_ptr(parsed_buf, *parsed_results_bytes),
    6568         [ #  # ]:          0 :                             format_ptr->format_str,
    6569                 :            :                             params[0], params[1], params[2]);
    6570                 :            :         }
    6571                 :            : 
    6572                 :            :         /* Add string NULL terminator */
    6573                 :          0 :         (*parsed_results_bytes)++;
    6574                 :            : 
    6575                 :          0 :         return status;
    6576                 :            : }
    6577                 :            : 
    6578                 :            : /* Parses an MCP Trace dump buffer.
    6579                 :            :  * If result_buf is not NULL, the MCP Trace results are printed to it.
    6580                 :            :  * In any case, the required results buffer size is assigned to
    6581                 :            :  * parsed_results_bytes.
    6582                 :            :  * The parsing status is returned.
    6583                 :            :  */
    6584                 :          0 : static enum dbg_status qed_parse_mcp_trace_dump(struct ecore_hwfn *p_hwfn,
    6585                 :            :                                                 u32 *dump_buf,
    6586                 :            :                                                 char *results_buf,
    6587                 :            :                                                 u32 *parsed_results_bytes,
    6588                 :            :                                                 bool free_meta_data)
    6589                 :            : {
    6590                 :            :         const char *section_name, *param_name, *param_str_val;
    6591                 :            :         u32 data_size, trace_data_dwords, trace_meta_dwords;
    6592                 :            :         u32 offset, results_offset, results_buf_bytes;
    6593                 :            :         u32 param_num_val, num_section_params;
    6594                 :            :         struct mcp_trace *trace;
    6595                 :            :         enum dbg_status status;
    6596                 :            :         const u32 *meta_buf;
    6597                 :            :         u8 *trace_buf;
    6598                 :            : 
    6599                 :          0 :         *parsed_results_bytes = 0;
    6600                 :            : 
    6601                 :            :         /* Read global_params section */
    6602                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6603                 :            :                                          &section_name, &num_section_params);
    6604         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    6605                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6606                 :            : 
    6607                 :            :         /* Print global params */
    6608                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    6609                 :            :                                              num_section_params,
    6610                 :            :                                              results_buf, &results_offset);
    6611                 :            : 
    6612                 :            :         /* Read trace_data section */
    6613                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6614                 :            :                                          &section_name, &num_section_params);
    6615   [ #  #  #  # ]:          0 :         if (strcmp(section_name, "mcp_trace_data") || num_section_params != 1)
    6616                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6617                 :          0 :         dump_buf += qed_read_param(dump_buf,
    6618                 :            :                                    &param_name, &param_str_val, &param_num_val);
    6619         [ #  # ]:          0 :         if (strcmp(param_name, "size"))
    6620                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6621                 :          0 :         trace_data_dwords = param_num_val;
    6622                 :            : 
    6623                 :            :         /* Prepare trace info */
    6624                 :            :         trace = (struct mcp_trace *)dump_buf;
    6625   [ #  #  #  # ]:          0 :         if (trace->signature != MFW_TRACE_SIGNATURE || !trace->size)
    6626                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6627                 :            : 
    6628                 :          0 :         trace_buf = (u8 *)dump_buf + sizeof(*trace);
    6629                 :          0 :         offset = trace->trace_oldest;
    6630                 :          0 :         data_size = qed_cyclic_sub(trace->trace_prod, offset, trace->size);
    6631                 :          0 :         dump_buf += trace_data_dwords;
    6632                 :            : 
    6633                 :            :         /* Read meta_data section */
    6634                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6635                 :            :                                          &section_name, &num_section_params);
    6636         [ #  # ]:          0 :         if (strcmp(section_name, "mcp_trace_meta"))
    6637                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6638                 :          0 :         dump_buf += qed_read_param(dump_buf,
    6639                 :            :                                    &param_name, &param_str_val, &param_num_val);
    6640         [ #  # ]:          0 :         if (strcmp(param_name, "size"))
    6641                 :            :                 return DBG_STATUS_MCP_TRACE_BAD_DATA;
    6642                 :          0 :         trace_meta_dwords = param_num_val;
    6643                 :            : 
    6644                 :            :         /* Choose meta data buffer */
    6645         [ #  # ]:          0 :         if (!trace_meta_dwords) {
    6646                 :            :                 /* Dump doesn't include meta data */
    6647                 :            :                 struct dbg_tools_user_data *dev_user_data =
    6648                 :            :                         qed_dbg_get_user_data(p_hwfn);
    6649                 :            : 
    6650         [ #  # ]:          0 :                 if (!dev_user_data->mcp_trace_user_meta_buf)
    6651                 :            :                         return DBG_STATUS_MCP_TRACE_NO_META;
    6652                 :            : 
    6653                 :            :                 meta_buf = dev_user_data->mcp_trace_user_meta_buf;
    6654                 :            :         } else {
    6655                 :            :                 /* Dump includes meta data */
    6656                 :            :                 meta_buf = dump_buf;
    6657                 :            :         }
    6658                 :            : 
    6659                 :            :         /* Allocate meta data memory */
    6660                 :          0 :         status = qed_mcp_trace_alloc_meta_data(p_hwfn, meta_buf);
    6661         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    6662                 :            :                 return status;
    6663                 :            : 
    6664         [ #  # ]:          0 :         status = qed_parse_mcp_trace_buf(p_hwfn,
    6665                 :            :                                          trace_buf,
    6666                 :            :                                          trace->size,
    6667                 :            :                                          offset,
    6668                 :            :                                          data_size,
    6669                 :            :                                          results_buf ?
    6670                 :          0 :                                          results_buf + results_offset :
    6671                 :            :                                          NULL,
    6672                 :            :                                          &results_buf_bytes);
    6673         [ #  # ]:          0 :         if (status != DBG_STATUS_OK)
    6674                 :            :                 return status;
    6675                 :            : 
    6676         [ #  # ]:          0 :         if (free_meta_data)
    6677                 :          0 :                 qed_mcp_trace_free_meta_data(p_hwfn);
    6678                 :            : 
    6679                 :          0 :         *parsed_results_bytes = results_offset + results_buf_bytes;
    6680                 :            : 
    6681                 :          0 :         return DBG_STATUS_OK;
    6682                 :            : }
    6683                 :            : 
    6684                 :            : /* Parses a Reg FIFO dump buffer.
    6685                 :            :  * If result_buf is not NULL, the Reg FIFO results are printed to it.
    6686                 :            :  * In any case, the required results buffer size is assigned to
    6687                 :            :  * parsed_results_bytes.
    6688                 :            :  * The parsing status is returned.
    6689                 :            :  */
    6690                 :          0 : static enum dbg_status qed_parse_reg_fifo_dump(u32 *dump_buf,
    6691                 :            :                                                char *results_buf,
    6692                 :            :                                                u32 *parsed_results_bytes)
    6693                 :            : {
    6694                 :            :         const char *section_name, *param_name, *param_str_val;
    6695                 :            :         u32 param_num_val, num_section_params, num_elements;
    6696                 :            :         struct reg_fifo_element *elements;
    6697                 :            :         u8 i, j, err_code, vf_val;
    6698                 :          0 :         u32 results_offset = 0;
    6699                 :            :         char vf_str[4];
    6700                 :            : 
    6701                 :            :         /* Read global_params section */
    6702                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6703                 :            :                                          &section_name, &num_section_params);
    6704         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    6705                 :            :                 return DBG_STATUS_REG_FIFO_BAD_DATA;
    6706                 :            : 
    6707                 :            :         /* Print global params */
    6708                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    6709                 :            :                                              num_section_params,
    6710                 :            :                                              results_buf, &results_offset);
    6711                 :            : 
    6712                 :            :         /* Read reg_fifo_data section */
    6713                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6714                 :            :                                          &section_name, &num_section_params);
    6715         [ #  # ]:          0 :         if (strcmp(section_name, "reg_fifo_data"))
    6716                 :            :                 return DBG_STATUS_REG_FIFO_BAD_DATA;
    6717                 :          0 :         dump_buf += qed_read_param(dump_buf,
    6718                 :            :                                    &param_name, &param_str_val, &param_num_val);
    6719         [ #  # ]:          0 :         if (strcmp(param_name, "size"))
    6720                 :            :                 return DBG_STATUS_REG_FIFO_BAD_DATA;
    6721         [ #  # ]:          0 :         if (param_num_val % REG_FIFO_ELEMENT_DWORDS)
    6722                 :            :                 return DBG_STATUS_REG_FIFO_BAD_DATA;
    6723                 :          0 :         num_elements = param_num_val / REG_FIFO_ELEMENT_DWORDS;
    6724                 :            :         elements = (struct reg_fifo_element *)dump_buf;
    6725                 :            : 
    6726                 :            :         /* Decode elements */
    6727         [ #  # ]:          0 :         for (i = 0; i < num_elements; i++) {
    6728                 :            :                 const char *err_msg = NULL;
    6729                 :            : 
    6730                 :            :                 /* Discover if element belongs to a VF or a PF */
    6731                 :          0 :                 vf_val = GET_FIELD(elements[i].data, REG_FIFO_ELEMENT_VF);
    6732         [ #  # ]:          0 :                 if (vf_val == REG_FIFO_ELEMENT_IS_PF_VF_VAL)
    6733                 :            :                         sprintf(vf_str, "%s", "N/A");
    6734                 :            :                 else
    6735                 :          0 :                         sprintf(vf_str, "%d", vf_val);
    6736                 :            : 
    6737                 :            :                 /* Find error message */
    6738                 :          0 :                 err_code = GET_FIELD(elements[i].data, REG_FIFO_ELEMENT_ERROR);
    6739         [ #  # ]:          0 :                 for (j = 0; j < OSAL_ARRAY_SIZE(s_reg_fifo_errors) && !err_msg;
    6740                 :          0 :                      j++)
    6741         [ #  # ]:          0 :                         if (err_code == s_reg_fifo_errors[j].err_code)
    6742                 :          0 :                                 err_msg = s_reg_fifo_errors[j].err_msg;
    6743                 :            : 
    6744                 :            :                 /* Add parsed element to parsed buffer */
    6745                 :          0 :                 results_offset +=
    6746         [ #  # ]:          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    6747                 :            :                                             results_offset),
    6748                 :            :                             "raw: 0x%016"PRIx64", address: 0x%07x, access: %-5s, pf: %2d, vf: %s, "
    6749                 :            :                             "port: %d, privilege: %-3s, protection: %-12s, master: %-4s, error: %s\n",
    6750                 :            :                             elements[i].data,
    6751                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    6752                 :            :                                            REG_FIFO_ELEMENT_ADDRESS) *
    6753                 :            :                             REG_FIFO_ELEMENT_ADDR_FACTOR,
    6754                 :          0 :                             s_access_strs[GET_FIELD(elements[i].data,
    6755                 :            :                                                     REG_FIFO_ELEMENT_ACCESS)],
    6756                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    6757                 :            :                                            REG_FIFO_ELEMENT_PF),
    6758                 :            :                             vf_str,
    6759                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    6760                 :            :                                            REG_FIFO_ELEMENT_PORT),
    6761                 :          0 :                             s_privilege_strs[GET_FIELD(elements[i].data,
    6762                 :            :                                                 REG_FIFO_ELEMENT_PRIVILEGE)],
    6763                 :          0 :                             s_protection_strs[GET_FIELD(elements[i].data,
    6764                 :            :                                                 REG_FIFO_ELEMENT_PROTECTION)],
    6765         [ #  # ]:          0 :                             s_master_strs[GET_FIELD(elements[i].data,
    6766                 :            :                                                     REG_FIFO_ELEMENT_MASTER)],
    6767                 :            :                             err_msg ? err_msg : "unknown error code");
    6768                 :            :         }
    6769                 :            : 
    6770         [ #  # ]:          0 :         results_offset += sprintf(qed_get_buf_ptr(results_buf,
    6771                 :            :                                                   results_offset),
    6772                 :            :                                   "fifo contained %d elements", num_elements);
    6773                 :            : 
    6774                 :            :         /* Add 1 for string NULL termination */
    6775                 :          0 :         *parsed_results_bytes = results_offset + 1;
    6776                 :            : 
    6777                 :          0 :         return DBG_STATUS_OK;
    6778                 :            : }
    6779                 :            : 
    6780                 :          0 : static enum dbg_status qed_parse_igu_fifo_element(struct igu_fifo_element
    6781                 :            :                                                   *element, char
    6782                 :            :                                                   *results_buf,
    6783                 :            :                                                   u32 *results_offset)
    6784                 :            : {
    6785                 :            :         const struct igu_fifo_addr_data *found_addr = NULL;
    6786                 :            :         u8 source, err_type, i, is_cleanup;
    6787                 :            :         char parsed_addr_data[32];
    6788                 :            :         char parsed_wr_data[256];
    6789                 :            :         u32 wr_data, prod_cons;
    6790                 :            :         bool is_wr_cmd, is_pf;
    6791                 :            :         u16 cmd_addr;
    6792                 :            :         u64 dword12;
    6793                 :            : 
    6794                 :            :         /* Dword12 (dword index 1 and 2) contains bits 32..95 of the
    6795                 :            :          * FIFO element.
    6796                 :            :          */
    6797                 :          0 :         dword12 = ((u64)element->dword2 << 32) | element->dword1;
    6798                 :          0 :         is_wr_cmd = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_IS_WR_CMD);
    6799                 :          0 :         is_pf = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_IS_PF);
    6800                 :          0 :         cmd_addr = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_CMD_ADDR);
    6801                 :          0 :         source = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_SOURCE);
    6802                 :          0 :         err_type = GET_FIELD(element->dword0, IGU_FIFO_ELEMENT_DWORD0_ERR_TYPE);
    6803                 :            : 
    6804         [ #  # ]:          0 :         if (source >= OSAL_ARRAY_SIZE(s_igu_fifo_source_strs))
    6805                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6806         [ #  # ]:          0 :         if (err_type >= OSAL_ARRAY_SIZE(s_igu_fifo_error_strs))
    6807                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6808                 :            : 
    6809                 :            :         /* Find address data */
    6810         [ #  # ]:          0 :         for (i = 0; i < OSAL_ARRAY_SIZE(s_igu_fifo_addr_data) && !found_addr;
    6811                 :          0 :              i++) {
    6812                 :          0 :                 const struct igu_fifo_addr_data *curr_addr =
    6813                 :          0 :                         &s_igu_fifo_addr_data[i];
    6814                 :            : 
    6815         [ #  # ]:          0 :                 if (cmd_addr >= curr_addr->start_addr && cmd_addr <=
    6816         [ #  # ]:          0 :                     curr_addr->end_addr)
    6817                 :            :                         found_addr = curr_addr;
    6818                 :            :         }
    6819                 :            : 
    6820         [ #  # ]:          0 :         if (!found_addr)
    6821                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6822                 :            : 
    6823                 :            :         /* Prepare parsed address data */
    6824      [ #  #  # ]:          0 :         switch (found_addr->type) {
    6825                 :          0 :         case IGU_ADDR_TYPE_MSIX_MEM:
    6826                 :          0 :                 sprintf(parsed_addr_data, " vector_num = 0x%x", cmd_addr / 2);
    6827                 :            :                 break;
    6828                 :          0 :         case IGU_ADDR_TYPE_WRITE_INT_ACK:
    6829                 :            :         case IGU_ADDR_TYPE_WRITE_PROD_UPDATE:
    6830                 :          0 :                 sprintf(parsed_addr_data,
    6831                 :          0 :                         " SB = 0x%x", cmd_addr - found_addr->start_addr);
    6832                 :            :                 break;
    6833                 :          0 :         default:
    6834                 :          0 :                 parsed_addr_data[0] = '\0';
    6835                 :            :         }
    6836                 :            : 
    6837         [ #  # ]:          0 :         if (!is_wr_cmd) {
    6838                 :          0 :                 parsed_wr_data[0] = '\0';
    6839                 :          0 :                 goto out;
    6840                 :            :         }
    6841                 :            : 
    6842                 :            :         /* Prepare parsed write data */
    6843                 :          0 :         wr_data = GET_FIELD(dword12, IGU_FIFO_ELEMENT_DWORD12_WR_DATA);
    6844                 :          0 :         prod_cons = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_PROD_CONS);
    6845                 :          0 :         is_cleanup = GET_FIELD(wr_data, IGU_FIFO_WR_DATA_CMD_TYPE);
    6846                 :            : 
    6847         [ #  # ]:          0 :         if (source == IGU_SRC_ATTN) {
    6848                 :            :                 sprintf(parsed_wr_data, "prod: 0x%x, ", prod_cons);
    6849                 :            :         } else {
    6850         [ #  # ]:          0 :                 if (is_cleanup) {
    6851                 :            :                         u8 cleanup_val, cleanup_type;
    6852                 :            : 
    6853                 :          0 :                         cleanup_val =
    6854                 :          0 :                                 GET_FIELD(wr_data,
    6855                 :            :                                           IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_VAL);
    6856                 :          0 :                         cleanup_type =
    6857                 :          0 :                             GET_FIELD(wr_data,
    6858                 :            :                                       IGU_FIFO_CLEANUP_WR_DATA_CLEANUP_TYPE);
    6859                 :            : 
    6860         [ #  # ]:          0 :                         sprintf(parsed_wr_data,
    6861                 :            :                                 "cmd_type: cleanup, cleanup_val: %s, cleanup_type : %d, ",
    6862                 :            :                                 cleanup_val ? "set" : "clear",
    6863                 :            :                                 cleanup_type);
    6864                 :            :                 } else {
    6865                 :            :                         u8 update_flag, en_dis_int_for_sb, segment;
    6866                 :            :                         u8 timer_mask;
    6867                 :            : 
    6868                 :          0 :                         update_flag = GET_FIELD(wr_data,
    6869                 :            :                                                 IGU_FIFO_WR_DATA_UPDATE_FLAG);
    6870                 :          0 :                         en_dis_int_for_sb =
    6871                 :          0 :                                 GET_FIELD(wr_data,
    6872                 :            :                                           IGU_FIFO_WR_DATA_EN_DIS_INT_FOR_SB);
    6873                 :          0 :                         segment = GET_FIELD(wr_data,
    6874                 :            :                                             IGU_FIFO_WR_DATA_SEGMENT);
    6875                 :          0 :                         timer_mask = GET_FIELD(wr_data,
    6876                 :            :                                                IGU_FIFO_WR_DATA_TIMER_MASK);
    6877                 :            : 
    6878   [ #  #  #  #  :          0 :                         sprintf(parsed_wr_data,
                   #  # ]
    6879                 :            :                                 "cmd_type: prod/cons update, prod/cons: 0x%x, update_flag: %s, en_dis_int_for_sb : %s, segment : %s, timer_mask = %d, ",
    6880                 :            :                                 prod_cons,
    6881                 :            :                                 update_flag ? "update" : "nop",
    6882                 :            :                                 en_dis_int_for_sb ?
    6883         [ #  # ]:          0 :                                 (en_dis_int_for_sb == 1 ? "disable" : "nop") :
    6884                 :            :                                 "enable",
    6885                 :            :                                 segment ? "attn" : "regular",
    6886                 :            :                                 timer_mask);
    6887                 :            :                 }
    6888                 :            :         }
    6889                 :          0 : out:
    6890                 :            :         /* Add parsed element to parsed buffer */
    6891   [ #  #  #  # ]:          0 :         *results_offset += sprintf(qed_get_buf_ptr(results_buf,
    6892                 :            :                                                    *results_offset),
    6893                 :            :                                    "raw: 0x%01x%08x%08x, %s: %d, source : %s, type : %s, cmd_addr : 0x%x(%s%s), %serror: %s\n",
    6894                 :            :                                    element->dword2, element->dword1,
    6895                 :            :                                    element->dword0,
    6896                 :            :                                    is_pf ? "pf" : "vf",
    6897                 :          0 :                                    GET_FIELD(element->dword0,
    6898                 :            :                                              IGU_FIFO_ELEMENT_DWORD0_FID),
    6899         [ #  # ]:          0 :                                    s_igu_fifo_source_strs[source],
    6900                 :            :                                    is_wr_cmd ? "wr" : "rd",
    6901                 :            :                                    cmd_addr,
    6902         [ #  # ]:          0 :                                    (!is_pf && found_addr->vf_desc)
    6903                 :            :                                    ? found_addr->vf_desc
    6904                 :            :                                    : found_addr->desc,
    6905                 :            :                                    parsed_addr_data,
    6906                 :            :                                    parsed_wr_data,
    6907         [ #  # ]:          0 :                                    s_igu_fifo_error_strs[err_type]);
    6908                 :            : 
    6909                 :          0 :         return DBG_STATUS_OK;
    6910                 :            : }
    6911                 :            : 
    6912                 :            : /* Parses an IGU FIFO dump buffer.
    6913                 :            :  * If result_buf is not NULL, the IGU FIFO results are printed to it.
    6914                 :            :  * In any case, the required results buffer size is assigned to
    6915                 :            :  * parsed_results_bytes.
    6916                 :            :  * The parsing status is returned.
    6917                 :            :  */
    6918                 :          0 : static enum dbg_status qed_parse_igu_fifo_dump(u32 *dump_buf,
    6919                 :            :                                                char *results_buf,
    6920                 :            :                                                u32 *parsed_results_bytes)
    6921                 :            : {
    6922                 :            :         const char *section_name, *param_name, *param_str_val;
    6923                 :            :         u32 param_num_val, num_section_params, num_elements;
    6924                 :            :         struct igu_fifo_element *elements;
    6925                 :            :         enum dbg_status status;
    6926                 :          0 :         u32 results_offset = 0;
    6927                 :            :         u8 i;
    6928                 :            : 
    6929                 :            :         /* Read global_params section */
    6930                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6931                 :            :                                          &section_name, &num_section_params);
    6932         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    6933                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6934                 :            : 
    6935                 :            :         /* Print global params */
    6936                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    6937                 :            :                                              num_section_params,
    6938                 :            :                                              results_buf, &results_offset);
    6939                 :            : 
    6940                 :            :         /* Read igu_fifo_data section */
    6941                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6942                 :            :                                          &section_name, &num_section_params);
    6943         [ #  # ]:          0 :         if (strcmp(section_name, "igu_fifo_data"))
    6944                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6945                 :          0 :         dump_buf += qed_read_param(dump_buf,
    6946                 :            :                                    &param_name, &param_str_val, &param_num_val);
    6947         [ #  # ]:          0 :         if (strcmp(param_name, "size"))
    6948                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6949         [ #  # ]:          0 :         if (param_num_val % IGU_FIFO_ELEMENT_DWORDS)
    6950                 :            :                 return DBG_STATUS_IGU_FIFO_BAD_DATA;
    6951                 :          0 :         num_elements = param_num_val / IGU_FIFO_ELEMENT_DWORDS;
    6952                 :            :         elements = (struct igu_fifo_element *)dump_buf;
    6953                 :            : 
    6954                 :            :         /* Decode elements */
    6955         [ #  # ]:          0 :         for (i = 0; i < num_elements; i++) {
    6956                 :          0 :                 status = qed_parse_igu_fifo_element(&elements[i],
    6957                 :            :                                                     results_buf,
    6958                 :            :                                                     &results_offset);
    6959         [ #  # ]:          0 :                 if (status != DBG_STATUS_OK)
    6960                 :          0 :                         return status;
    6961                 :            :         }
    6962                 :            : 
    6963         [ #  # ]:          0 :         results_offset += sprintf(qed_get_buf_ptr(results_buf,
    6964                 :            :                                                   results_offset),
    6965                 :            :                                   "fifo contained %d elements", num_elements);
    6966                 :            : 
    6967                 :            :         /* Add 1 for string NULL termination */
    6968                 :          0 :         *parsed_results_bytes = results_offset + 1;
    6969                 :            : 
    6970                 :          0 :         return DBG_STATUS_OK;
    6971                 :            : }
    6972                 :            : 
    6973                 :            : static enum dbg_status
    6974                 :          0 : qed_parse_protection_override_dump(u32 *dump_buf,
    6975                 :            :                                    char *results_buf,
    6976                 :            :                                    u32 *parsed_results_bytes)
    6977                 :            : {
    6978                 :            :         const char *section_name, *param_name, *param_str_val;
    6979                 :            :         u32 param_num_val, num_section_params, num_elements;
    6980                 :            :         struct protection_override_element *elements;
    6981                 :          0 :         u32 results_offset = 0;
    6982                 :            :         u8 i;
    6983                 :            : 
    6984                 :            :         /* Read global_params section */
    6985                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6986                 :            :                                          &section_name, &num_section_params);
    6987         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    6988                 :            :                 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
    6989                 :            : 
    6990                 :            :         /* Print global params */
    6991                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    6992                 :            :                                              num_section_params,
    6993                 :            :                                              results_buf, &results_offset);
    6994                 :            : 
    6995                 :            :         /* Read protection_override_data section */
    6996                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    6997                 :            :                                          &section_name, &num_section_params);
    6998         [ #  # ]:          0 :         if (strcmp(section_name, "protection_override_data"))
    6999                 :            :                 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
    7000                 :          0 :         dump_buf += qed_read_param(dump_buf,
    7001                 :            :                                    &param_name, &param_str_val, &param_num_val);
    7002         [ #  # ]:          0 :         if (strcmp(param_name, "size"))
    7003                 :            :                 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
    7004         [ #  # ]:          0 :         if (param_num_val % PROTECTION_OVERRIDE_ELEMENT_DWORDS)
    7005                 :            :                 return DBG_STATUS_PROTECTION_OVERRIDE_BAD_DATA;
    7006                 :          0 :         num_elements = param_num_val / PROTECTION_OVERRIDE_ELEMENT_DWORDS;
    7007                 :            :         elements = (struct protection_override_element *)dump_buf;
    7008                 :            : 
    7009                 :            :         /* Decode elements */
    7010         [ #  # ]:          0 :         for (i = 0; i < num_elements; i++) {
    7011                 :          0 :                 u32 address = GET_FIELD(elements[i].data,
    7012                 :            :                                         PROTECTION_OVERRIDE_ELEMENT_ADDRESS) *
    7013                 :            :                               PROTECTION_OVERRIDE_ELEMENT_ADDR_FACTOR;
    7014                 :            : 
    7015                 :          0 :                 results_offset +=
    7016                 :          0 :                     sprintf(qed_get_buf_ptr(results_buf,
    7017                 :            :                                             results_offset),
    7018                 :            :                             "window %2d, address: 0x%07x, size: %7d regs, read: %d, write: %d, read protection: %-12s, write protection: %-12s\n",
    7019                 :            :                             i, address,
    7020                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    7021                 :            :                                       PROTECTION_OVERRIDE_ELEMENT_WINDOW_SIZE),
    7022                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    7023                 :            :                                       PROTECTION_OVERRIDE_ELEMENT_READ),
    7024                 :          0 :                             (u32)GET_FIELD(elements[i].data,
    7025                 :            :                                       PROTECTION_OVERRIDE_ELEMENT_WRITE),
    7026                 :          0 :                             s_protection_strs[GET_FIELD(elements[i].data,
    7027                 :            :                                 PROTECTION_OVERRIDE_ELEMENT_READ_PROTECTION)],
    7028         [ #  # ]:          0 :                             s_protection_strs[GET_FIELD(elements[i].data,
    7029                 :            :                                 PROTECTION_OVERRIDE_ELEMENT_WRITE_PROTECTION)]);
    7030                 :            :         }
    7031                 :            : 
    7032         [ #  # ]:          0 :         results_offset += sprintf(qed_get_buf_ptr(results_buf,
    7033                 :            :                                                   results_offset),
    7034                 :            :                                   "protection override contained %d elements",
    7035                 :            :                                   num_elements);
    7036                 :            : 
    7037                 :            :         /* Add 1 for string NULL termination */
    7038                 :          0 :         *parsed_results_bytes = results_offset + 1;
    7039                 :            : 
    7040                 :          0 :         return DBG_STATUS_OK;
    7041                 :            : }
    7042                 :            : 
    7043                 :            : /* Parses a FW Asserts dump buffer.
    7044                 :            :  * If result_buf is not NULL, the FW Asserts results are printed to it.
    7045                 :            :  * In any case, the required results buffer size is assigned to
    7046                 :            :  * parsed_results_bytes.
    7047                 :            :  * The parsing status is returned.
    7048                 :            :  */
    7049                 :          0 : static enum dbg_status qed_parse_fw_asserts_dump(u32 *dump_buf,
    7050                 :            :                                                  char *results_buf,
    7051                 :            :                                                  u32 *parsed_results_bytes)
    7052                 :            : {
    7053                 :          0 :         u32 num_section_params, param_num_val, i, results_offset = 0;
    7054                 :            :         const char *param_name, *param_str_val, *section_name;
    7055                 :            :         bool last_section_found = false;
    7056                 :            : 
    7057                 :          0 :         *parsed_results_bytes = 0;
    7058                 :            : 
    7059                 :            :         /* Read global_params section */
    7060                 :          0 :         dump_buf += qed_read_section_hdr(dump_buf,
    7061                 :            :                                          &section_name, &num_section_params);
    7062         [ #  # ]:          0 :         if (strcmp(section_name, "global_params"))
    7063                 :            :                 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
    7064                 :            : 
    7065                 :            :         /* Print global params */
    7066                 :          0 :         dump_buf += qed_print_section_params(dump_buf,
    7067                 :            :                                              num_section_params,
    7068                 :            :                                              results_buf, &results_offset);
    7069                 :            : 
    7070         [ #  # ]:          0 :         while (!last_section_found) {
    7071                 :          0 :                 dump_buf += qed_read_section_hdr(dump_buf,
    7072                 :            :                                                  &section_name,
    7073                 :            :                                                  &num_section_params);
    7074         [ #  # ]:          0 :                 if (!strcmp(section_name, "fw_asserts")) {
    7075                 :            :                         /* Extract params */
    7076                 :            :                         const char *storm_letter = NULL;
    7077                 :            :                         u32 storm_dump_size = 0;
    7078                 :            : 
    7079         [ #  # ]:          0 :                         for (i = 0; i < num_section_params; i++) {
    7080                 :          0 :                                 dump_buf += qed_read_param(dump_buf,
    7081                 :            :                                                            &param_name,
    7082                 :            :                                                            &param_str_val,
    7083                 :            :                                                            &param_num_val);
    7084         [ #  # ]:          0 :                                 if (!strcmp(param_name, "storm"))
    7085                 :          0 :                                         storm_letter = param_str_val;
    7086         [ #  # ]:          0 :                                 else if (!strcmp(param_name, "size"))
    7087                 :          0 :                                         storm_dump_size = param_num_val;
    7088                 :            :                                 else
    7089                 :            :                                         return
    7090                 :            :                                             DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
    7091                 :            :                         }
    7092                 :            : 
    7093         [ #  # ]:          0 :                         if (!storm_letter || !storm_dump_size)
    7094                 :            :                                 return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
    7095                 :            : 
    7096                 :            :                         /* Print data */
    7097                 :          0 :                         results_offset +=
    7098         [ #  # ]:          0 :                             sprintf(qed_get_buf_ptr(results_buf,
    7099                 :            :                                                     results_offset),
    7100                 :            :                                     "\n%sSTORM_ASSERT: size=%d\n",
    7101                 :            :                                     storm_letter, storm_dump_size);
    7102         [ #  # ]:          0 :                         for (i = 0; i < storm_dump_size; i++, dump_buf++)
    7103                 :          0 :                                 results_offset +=
    7104         [ #  # ]:          0 :                                     sprintf(qed_get_buf_ptr(results_buf,
    7105                 :            :                                                             results_offset),
    7106                 :            :                                             "%08x\n", *dump_buf);
    7107         [ #  # ]:          0 :                 } else if (!strcmp(section_name, "last")) {
    7108                 :            :                         last_section_found = true;
    7109                 :            :                 } else {
    7110                 :            :                         return DBG_STATUS_FW_ASSERTS_PARSE_FAILED;
    7111                 :            :                 }
    7112                 :            :         }
    7113                 :            : 
    7114                 :            :         /* Add 1 for string NULL termination */
    7115                 :          0 :         *parsed_results_bytes = results_offset + 1;
    7116                 :            : 
    7117                 :          0 :         return DBG_STATUS_OK;
    7118                 :            : }
    7119                 :            : 
    7120                 :            : /***************************** Public Functions *******************************/
    7121                 :            : 
    7122                 :          0 : enum dbg_status qed_dbg_user_set_bin_ptr(struct ecore_hwfn *p_hwfn,
    7123                 :            :                                          const u8 * const bin_ptr)
    7124                 :            : {
    7125                 :            :         struct bin_buffer_hdr *buf_hdrs =
    7126                 :            :                         (struct bin_buffer_hdr *)(osal_uintptr_t)bin_ptr;
    7127                 :            :         u8 buf_id;
    7128                 :            : 
    7129                 :            :         /* Convert binary data to debug arrays */
    7130         [ #  # ]:          0 :         for (buf_id = 0; buf_id < MAX_BIN_DBG_BUFFER_TYPE; buf_id++)
    7131                 :          0 :                 qed_set_dbg_bin_buf(p_hwfn,
    7132                 :            :                                     (enum bin_dbg_buffer_type)buf_id,
    7133                 :            :                                     (const u32 *)(bin_ptr +
    7134                 :          0 :                                                   buf_hdrs[buf_id].offset),
    7135                 :          0 :                                                   buf_hdrs[buf_id].length);
    7136                 :            : 
    7137                 :          0 :         return DBG_STATUS_OK;
    7138                 :            : }
    7139                 :            : 
    7140                 :          0 : enum dbg_status qed_dbg_alloc_user_data(__rte_unused struct ecore_hwfn *p_hwfn,
    7141                 :            :                                         void **user_data_ptr)
    7142                 :            : {
    7143                 :          0 :         *user_data_ptr = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
    7144                 :            :                                      sizeof(struct dbg_tools_user_data));
    7145         [ #  # ]:          0 :         if (!(*user_data_ptr))
    7146                 :          0 :                 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    7147                 :            : 
    7148                 :            :         return DBG_STATUS_OK;
    7149                 :            : }
    7150                 :            : 
    7151                 :          0 : const char *qed_dbg_get_status_str(enum dbg_status status)
    7152                 :            : {
    7153                 :            :         return (status <
    7154         [ #  # ]:          0 :                 MAX_DBG_STATUS) ? s_status_str[status] : "Invalid debug status";
    7155                 :            : }
    7156                 :            : 
    7157                 :          0 : enum dbg_status qed_get_idle_chk_results_buf_size(struct ecore_hwfn *p_hwfn,
    7158                 :            :                                                   u32 *dump_buf,
    7159                 :            :                                                   u32 num_dumped_dwords,
    7160                 :            :                                                   u32 *results_buf_size)
    7161                 :            : {
    7162                 :            :         u32 num_errors, num_warnings;
    7163                 :            : 
    7164                 :          0 :         return qed_parse_idle_chk_dump(p_hwfn,
    7165                 :            :                                        dump_buf,
    7166                 :            :                                        num_dumped_dwords,
    7167                 :            :                                        NULL,
    7168                 :            :                                        results_buf_size,
    7169                 :            :                                        &num_errors, &num_warnings);
    7170                 :            : }
    7171                 :            : 
    7172                 :          0 : enum dbg_status qed_print_idle_chk_results(struct ecore_hwfn *p_hwfn,
    7173                 :            :                                            u32 *dump_buf,
    7174                 :            :                                            u32 num_dumped_dwords,
    7175                 :            :                                            char *results_buf,
    7176                 :            :                                            u32 *num_errors,
    7177                 :            :                                            u32 *num_warnings)
    7178                 :            : {
    7179                 :            :         u32 parsed_buf_size;
    7180                 :            : 
    7181                 :          0 :         return qed_parse_idle_chk_dump(p_hwfn,
    7182                 :            :                                        dump_buf,
    7183                 :            :                                        num_dumped_dwords,
    7184                 :            :                                        results_buf,
    7185                 :            :                                        &parsed_buf_size,
    7186                 :            :                                        num_errors, num_warnings);
    7187                 :            : }
    7188                 :            : 
    7189                 :          0 : void qed_dbg_mcp_trace_set_meta_data(struct ecore_hwfn *p_hwfn,
    7190                 :            :                                      const u32 *meta_buf)
    7191                 :            : {
    7192                 :            :         struct dbg_tools_user_data *dev_user_data =
    7193                 :            :                 qed_dbg_get_user_data(p_hwfn);
    7194                 :            : 
    7195                 :          0 :         dev_user_data->mcp_trace_user_meta_buf = meta_buf;
    7196                 :          0 : }
    7197                 :            : 
    7198                 :            : enum dbg_status
    7199                 :          0 : qed_get_mcp_trace_results_buf_size(struct ecore_hwfn *p_hwfn,
    7200                 :            :                                    u32 *dump_buf,
    7201                 :            :                                    __rte_unused u32 num_dumped_dwords,
    7202                 :            :                                    u32 *results_buf_size)
    7203                 :            : {
    7204                 :          0 :         return qed_parse_mcp_trace_dump(p_hwfn,
    7205                 :            :                                         dump_buf, NULL, results_buf_size, true);
    7206                 :            : }
    7207                 :            : 
    7208                 :          0 : enum dbg_status qed_print_mcp_trace_results(struct ecore_hwfn *p_hwfn,
    7209                 :            :                                             u32 *dump_buf,
    7210                 :            :                                             __rte_unused u32 num_dumped_dwords,
    7211                 :            :                                             char *results_buf)
    7212                 :            : {
    7213                 :            :         u32 parsed_buf_size;
    7214                 :            : 
    7215                 :          0 :         return qed_parse_mcp_trace_dump(p_hwfn,
    7216                 :            :                                         dump_buf,
    7217                 :            :                                         results_buf, &parsed_buf_size, true);
    7218                 :            : }
    7219                 :            : 
    7220                 :          0 : enum dbg_status qed_print_mcp_trace_results_cont(struct ecore_hwfn *p_hwfn,
    7221                 :            :                                                  u32 *dump_buf,
    7222                 :            :                                                  char *results_buf)
    7223                 :            : {
    7224                 :            :         u32 parsed_buf_size;
    7225                 :            : 
    7226                 :          0 :         return qed_parse_mcp_trace_dump(p_hwfn, dump_buf, results_buf,
    7227                 :            :                                         &parsed_buf_size, false);
    7228                 :            : }
    7229                 :            : 
    7230                 :          0 : enum dbg_status qed_print_mcp_trace_line(struct ecore_hwfn *p_hwfn,
    7231                 :            :                                          u8 *dump_buf,
    7232                 :            :                                          u32 num_dumped_bytes,
    7233                 :            :                                          char *results_buf)
    7234                 :            : {
    7235                 :            :         u32 parsed_results_bytes;
    7236                 :            : 
    7237                 :          0 :         return qed_parse_mcp_trace_buf(p_hwfn,
    7238                 :            :                                        dump_buf,
    7239                 :            :                                        num_dumped_bytes,
    7240                 :            :                                        0,
    7241                 :            :                                        num_dumped_bytes,
    7242                 :            :                                        results_buf, &parsed_results_bytes);
    7243                 :            : }
    7244                 :            : 
    7245                 :            : /* Frees the specified MCP Trace meta data */
    7246                 :          0 : void qed_mcp_trace_free_meta_data(struct ecore_hwfn *p_hwfn)
    7247                 :            : {
    7248                 :            :         struct dbg_tools_user_data *dev_user_data;
    7249                 :            :         struct mcp_trace_meta *meta;
    7250                 :            :         u32 i;
    7251                 :            : 
    7252                 :            :         dev_user_data = qed_dbg_get_user_data(p_hwfn);
    7253                 :            :         meta = &dev_user_data->mcp_trace_meta;
    7254         [ #  # ]:          0 :         if (!meta->is_allocated)
    7255                 :            :                 return;
    7256                 :            : 
    7257                 :            :         /* Release modules */
    7258         [ #  # ]:          0 :         if (meta->modules) {
    7259         [ #  # ]:          0 :                 for (i = 0; i < meta->modules_num; i++)
    7260                 :          0 :                         OSAL_FREE(p_hwfn, meta->modules[i]);
    7261                 :          0 :                 OSAL_FREE(p_hwfn, meta->modules);
    7262                 :            :         }
    7263                 :            : 
    7264                 :            :         /* Release formats */
    7265         [ #  # ]:          0 :         if (meta->formats) {
    7266         [ #  # ]:          0 :                 for (i = 0; i < meta->formats_num; i++)
    7267                 :          0 :                         OSAL_FREE(p_hwfn, meta->formats[i].format_str);
    7268                 :          0 :                 OSAL_FREE(p_hwfn, meta->formats);
    7269                 :            :         }
    7270                 :            : 
    7271                 :          0 :         meta->is_allocated = false;
    7272                 :            : }
    7273                 :            : 
    7274                 :            : enum dbg_status
    7275                 :          0 : qed_get_reg_fifo_results_buf_size(__rte_unused struct ecore_hwfn *p_hwfn,
    7276                 :            :                                   u32 *dump_buf,
    7277                 :            :                                   __rte_unused u32 num_dumped_dwords,
    7278                 :            :                                   u32 *results_buf_size)
    7279                 :            : {
    7280                 :          0 :         return qed_parse_reg_fifo_dump(dump_buf, NULL, results_buf_size);
    7281                 :            : }
    7282                 :            : 
    7283                 :            : enum dbg_status
    7284                 :          0 : qed_print_reg_fifo_results(__rte_unused struct ecore_hwfn *p_hwfn,
    7285                 :            :                            u32 *dump_buf,
    7286                 :            :                            __rte_unused u32 num_dumped_dwords,
    7287                 :            :                            char *results_buf)
    7288                 :            : {
    7289                 :            :         u32 parsed_buf_size;
    7290                 :            : 
    7291                 :          0 :         return qed_parse_reg_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
    7292                 :            : }
    7293                 :            : 
    7294                 :            : enum dbg_status
    7295                 :          0 : qed_get_igu_fifo_results_buf_size(__rte_unused struct ecore_hwfn *p_hwfn,
    7296                 :            :                                   u32 *dump_buf,
    7297                 :            :                                   __rte_unused u32 num_dumped_dwords,
    7298                 :            :                                   u32 *results_buf_size)
    7299                 :            : {
    7300                 :          0 :         return qed_parse_igu_fifo_dump(dump_buf, NULL, results_buf_size);
    7301                 :            : }
    7302                 :            : 
    7303                 :            : enum dbg_status
    7304                 :          0 : qed_print_igu_fifo_results(__rte_unused struct ecore_hwfn *p_hwfn,
    7305                 :            :                            u32 *dump_buf,
    7306                 :            :                            __rte_unused u32 num_dumped_dwords,
    7307                 :            :                            char *results_buf)
    7308                 :            : {
    7309                 :            :         u32 parsed_buf_size;
    7310                 :            : 
    7311                 :          0 :         return qed_parse_igu_fifo_dump(dump_buf, results_buf, &parsed_buf_size);
    7312                 :            : }
    7313                 :            : 
    7314                 :            : enum dbg_status
    7315                 :          0 : qed_get_protection_override_results_buf_size(__rte_unused
    7316                 :            :                                              struct ecore_hwfn *p_hwfn,
    7317                 :            :                                              u32 *dump_buf,
    7318                 :            :                                              __rte_unused u32 num_dumped_dwords,
    7319                 :            :                                              u32 *results_buf_size)
    7320                 :            : {
    7321                 :          0 :         return qed_parse_protection_override_dump(dump_buf,
    7322                 :            :                                                   NULL, results_buf_size);
    7323                 :            : }
    7324                 :            : 
    7325                 :            : enum dbg_status
    7326                 :          0 : qed_print_protection_override_results(__rte_unused struct ecore_hwfn *p_hwfn,
    7327                 :            :                                       u32 *dump_buf,
    7328                 :            :                                       __rte_unused u32 num_dumped_dwords,
    7329                 :            :                                       char *results_buf)
    7330                 :            : {
    7331                 :            :         u32 parsed_buf_size;
    7332                 :            : 
    7333                 :          0 :         return qed_parse_protection_override_dump(dump_buf,
    7334                 :            :                                                   results_buf,
    7335                 :            :                                                   &parsed_buf_size);
    7336                 :            : }
    7337                 :            : 
    7338                 :            : enum dbg_status
    7339                 :          0 : qed_get_fw_asserts_results_buf_size(__rte_unused struct ecore_hwfn *p_hwfn,
    7340                 :            :                                     u32 *dump_buf,
    7341                 :            :                                     __rte_unused u32 num_dumped_dwords,
    7342                 :            :                                     u32 *results_buf_size)
    7343                 :            : {
    7344                 :          0 :         return qed_parse_fw_asserts_dump(dump_buf, NULL, results_buf_size);
    7345                 :            : }
    7346                 :            : 
    7347                 :            : enum dbg_status
    7348                 :          0 : qed_print_fw_asserts_results(__rte_unused struct ecore_hwfn *p_hwfn,
    7349                 :            :                              u32 *dump_buf,
    7350                 :            :                              __rte_unused u32 num_dumped_dwords,
    7351                 :            :                              char *results_buf)
    7352                 :            : {
    7353                 :            :         u32 parsed_buf_size;
    7354                 :            : 
    7355                 :          0 :         return qed_parse_fw_asserts_dump(dump_buf,
    7356                 :            :                                          results_buf, &parsed_buf_size);
    7357                 :            : }
    7358                 :            : 
    7359                 :          0 : enum dbg_status qed_dbg_parse_attn(struct ecore_hwfn *p_hwfn,
    7360                 :            :                                    struct dbg_attn_block_result *results)
    7361                 :            : {
    7362                 :            :         const u32 *block_attn_name_offsets;
    7363                 :            :         const char *attn_name_base;
    7364                 :            :         const char *block_name;
    7365                 :            :         enum dbg_attn_type attn_type;
    7366                 :            :         u8 num_regs, i, j;
    7367                 :            : 
    7368                 :          0 :         num_regs = GET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_NUM_REGS);
    7369                 :            :         attn_type = GET_FIELD(results->data, DBG_ATTN_BLOCK_RESULT_ATTN_TYPE);
    7370                 :          0 :         block_name = qed_dbg_get_block_name(p_hwfn, results->block_id);
    7371         [ #  # ]:          0 :         if (!block_name)
    7372                 :            :                 return DBG_STATUS_INVALID_ARGS;
    7373                 :            : 
    7374         [ #  # ]:          0 :         if (!p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES].ptr ||
    7375         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS].ptr ||
    7376         [ #  # ]:          0 :             !p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr)
    7377                 :            :                 return DBG_STATUS_DBG_ARRAY_NOT_SET;
    7378                 :            : 
    7379                 :            :         block_attn_name_offsets =
    7380                 :            :             (u32 *)p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_NAME_OFFSETS].ptr +
    7381                 :          0 :             results->names_offset;
    7382                 :            : 
    7383                 :            :         attn_name_base = p_hwfn->dbg_arrays[BIN_BUF_DBG_PARSING_STRINGS].ptr;
    7384                 :            : 
    7385                 :            :         /* Go over registers with a non-zero attention status */
    7386         [ #  # ]:          0 :         for (i = 0; i < num_regs; i++) {
    7387                 :            :                 struct dbg_attn_bit_mapping *bit_mapping;
    7388                 :            :                 struct dbg_attn_reg_result *reg_result;
    7389                 :            :                 u8 num_reg_attn, bit_idx = 0;
    7390                 :            : 
    7391                 :          0 :                 reg_result = &results->reg_results[i];
    7392                 :          0 :                 num_reg_attn = GET_FIELD(reg_result->data,
    7393                 :            :                                          DBG_ATTN_REG_RESULT_NUM_REG_ATTN);
    7394                 :          0 :                 bit_mapping = (struct dbg_attn_bit_mapping *)
    7395                 :          0 :                     p_hwfn->dbg_arrays[BIN_BUF_DBG_ATTN_INDEXES].ptr +
    7396                 :          0 :                     reg_result->block_attn_offset;
    7397                 :            : 
    7398                 :            :                 /* Go over attention status bits */
    7399         [ #  # ]:          0 :                 for (j = 0; j < num_reg_attn; j++, bit_idx++) {
    7400                 :          0 :                         u16 attn_idx_val = GET_FIELD(bit_mapping[j].data,
    7401                 :            :                                                      DBG_ATTN_BIT_MAPPING_VAL);
    7402                 :            :                         const char *attn_name, *attn_type_str, *masked_str;
    7403                 :            :                         u32 attn_name_offset;
    7404                 :            :                         u32 sts_addr;
    7405                 :            : 
    7406                 :            :                         /* Check if bit mask should be advanced (due to unused
    7407                 :            :                          * bits).
    7408                 :            :                          */
    7409         [ #  # ]:          0 :                         if (GET_FIELD(bit_mapping[j].data,
    7410                 :            :                                       DBG_ATTN_BIT_MAPPING_IS_UNUSED_BIT_CNT)) {
    7411                 :          0 :                                 bit_idx += (u8)attn_idx_val;
    7412                 :          0 :                                 continue;
    7413                 :            :                         }
    7414                 :            : 
    7415                 :            :                         /* Check current bit index */
    7416         [ #  # ]:          0 :                         if (!(reg_result->sts_val & OSAL_BIT(bit_idx)))
    7417                 :          0 :                                 continue;
    7418                 :            : 
    7419                 :            :                         /* An attention bit with value=1 was found
    7420                 :            :                          * Find attention name
    7421                 :            :                          */
    7422                 :          0 :                         attn_name_offset =
    7423                 :          0 :                                 block_attn_name_offsets[attn_idx_val];
    7424                 :          0 :                         attn_name = attn_name_base + attn_name_offset;
    7425                 :            :                         attn_type_str =
    7426                 :            :                                 (attn_type ==
    7427         [ #  # ]:          0 :                                  ATTN_TYPE_INTERRUPT ? "Interrupt" :
    7428                 :            :                                  "Parity");
    7429                 :          0 :                         masked_str = reg_result->mask_val & OSAL_BIT(bit_idx) ?
    7430         [ #  # ]:          0 :                                      " [masked]" : "";
    7431                 :          0 :                         sts_addr = GET_FIELD(reg_result->data,
    7432                 :            :                                              DBG_ATTN_REG_RESULT_STS_ADDRESS);
    7433                 :          0 :                         DP_NOTICE(p_hwfn, false,
    7434                 :            :                                   "%s (%s) : %s [address 0x%08x, bit %d]%s\n",
    7435                 :            :                                   block_name, attn_type_str, attn_name,
    7436                 :            :                                   sts_addr * 4, bit_idx, masked_str);
    7437                 :            :                 }
    7438                 :            :         }
    7439                 :            : 
    7440                 :            :         return DBG_STATUS_OK;
    7441                 :            : }
    7442                 :            : 
    7443                 :            : /* Wrapper for unifying the idle_chk and mcp_trace api */
    7444                 :            : static enum dbg_status
    7445                 :          0 : qed_print_idle_chk_results_wrapper(struct ecore_hwfn *p_hwfn,
    7446                 :            :                                    u32 *dump_buf,
    7447                 :            :                                    u32 num_dumped_dwords,
    7448                 :            :                                    char *results_buf)
    7449                 :            : {
    7450                 :            :         u32 num_errors, num_warnnings;
    7451                 :            : 
    7452                 :          0 :         return qed_print_idle_chk_results(p_hwfn, dump_buf, num_dumped_dwords,
    7453                 :            :                                           results_buf, &num_errors,
    7454                 :            :                                           &num_warnnings);
    7455                 :            : }
    7456                 :            : 
    7457                 :            : /* Feature meta data lookup table */
    7458                 :            : static struct {
    7459                 :            :         const char *name;
    7460                 :            :         enum dbg_status (*get_size)(struct ecore_hwfn *p_hwfn,
    7461                 :            :                                     struct ecore_ptt *p_ptt, u32 *size);
    7462                 :            :         enum dbg_status (*perform_dump)(struct ecore_hwfn *p_hwfn,
    7463                 :            :                                         struct ecore_ptt *p_ptt, u32 *dump_buf,
    7464                 :            :                                         u32 buf_size, u32 *dumped_dwords);
    7465                 :            :         enum dbg_status (*print_results)(struct ecore_hwfn *p_hwfn,
    7466                 :            :                                          u32 *dump_buf, u32 num_dumped_dwords,
    7467                 :            :                                          char *results_buf);
    7468                 :            :         enum dbg_status (*results_buf_size)(struct ecore_hwfn *p_hwfn,
    7469                 :            :                                             u32 *dump_buf,
    7470                 :            :                                             u32 num_dumped_dwords,
    7471                 :            :                                             u32 *results_buf_size);
    7472                 :            : } qed_features_lookup[] = {
    7473                 :            :         {
    7474                 :            :         "grc", qed_dbg_grc_get_dump_buf_size,
    7475                 :            :                     qed_dbg_grc_dump, NULL, NULL}, {
    7476                 :            :         "idle_chk",
    7477                 :            :                     qed_dbg_idle_chk_get_dump_buf_size,
    7478                 :            :                     qed_dbg_idle_chk_dump,
    7479                 :            :                     qed_print_idle_chk_results_wrapper,
    7480                 :            :                     qed_get_idle_chk_results_buf_size}, {
    7481                 :            :         "mcp_trace",
    7482                 :            :                     qed_dbg_mcp_trace_get_dump_buf_size,
    7483                 :            :                     qed_dbg_mcp_trace_dump, qed_print_mcp_trace_results,
    7484                 :            :                     qed_get_mcp_trace_results_buf_size}, {
    7485                 :            :         "reg_fifo",
    7486                 :            :                     qed_dbg_reg_fifo_get_dump_buf_size,
    7487                 :            :                     qed_dbg_reg_fifo_dump, qed_print_reg_fifo_results,
    7488                 :            :                     qed_get_reg_fifo_results_buf_size}, {
    7489                 :            :         "igu_fifo",
    7490                 :            :                     qed_dbg_igu_fifo_get_dump_buf_size,
    7491                 :            :                     qed_dbg_igu_fifo_dump, qed_print_igu_fifo_results,
    7492                 :            :                     qed_get_igu_fifo_results_buf_size}, {
    7493                 :            :         "protection_override",
    7494                 :            :                     qed_dbg_protection_override_get_dump_buf_size,
    7495                 :            :                     qed_dbg_protection_override_dump,
    7496                 :            :                     qed_print_protection_override_results,
    7497                 :            :                     qed_get_protection_override_results_buf_size}, {
    7498                 :            :         "fw_asserts",
    7499                 :            :                     qed_dbg_fw_asserts_get_dump_buf_size,
    7500                 :            :                     qed_dbg_fw_asserts_dump,
    7501                 :            :                     qed_print_fw_asserts_results,
    7502                 :            :                     qed_get_fw_asserts_results_buf_size}, {
    7503                 :            :         "ilt",
    7504                 :            :                     qed_dbg_ilt_get_dump_buf_size,
    7505                 :            :                     qed_dbg_ilt_dump, NULL, NULL},};
    7506                 :            : 
    7507                 :            : #define QED_RESULTS_BUF_MIN_SIZE 16
    7508                 :            : /* Generic function for decoding debug feature info */
    7509                 :          0 : static enum dbg_status format_feature(struct ecore_hwfn *p_hwfn,
    7510                 :            :                                       enum ecore_dbg_features feature_idx)
    7511                 :            : {
    7512                 :            :         struct ecore_dbg_feature *feature =
    7513                 :          0 :             &p_hwfn->p_dev->dbg_params.features[feature_idx];
    7514                 :            :         u32 text_size_bytes, null_char_pos, i;
    7515                 :            :         enum dbg_status rc;
    7516                 :            :         char *text_buf;
    7517                 :            : 
    7518                 :            :         /* Check if feature supports formatting capability */
    7519         [ #  # ]:          0 :         if (!qed_features_lookup[feature_idx].results_buf_size)
    7520                 :            :                 return DBG_STATUS_OK;
    7521                 :            : 
    7522                 :            :         /* Obtain size of formatted output */
    7523                 :          0 :         rc = qed_features_lookup[feature_idx].results_buf_size(p_hwfn,
    7524                 :          0 :                                                 (u32 *)feature->dump_buf,
    7525                 :            :                                                 feature->dumped_dwords,
    7526                 :            :                                                 &text_size_bytes);
    7527         [ #  # ]:          0 :         if (rc != DBG_STATUS_OK)
    7528                 :            :                 return rc;
    7529                 :            : 
    7530                 :            :         /* Make sure that the allocated size is a multiple of dword (4 bytes) */
    7531                 :          0 :         null_char_pos = text_size_bytes - 1;
    7532                 :          0 :         text_size_bytes = (text_size_bytes + 3) & ~0x3;
    7533                 :            : 
    7534         [ #  # ]:          0 :         if (text_size_bytes < QED_RESULTS_BUF_MIN_SIZE) {
    7535                 :          0 :                 DP_NOTICE(p_hwfn->p_dev, false,
    7536                 :            :                           "formatted size of feature was too small %d. Aborting\n",
    7537                 :            :                           text_size_bytes);
    7538                 :          0 :                 return DBG_STATUS_INVALID_ARGS;
    7539                 :            :         }
    7540                 :            : 
    7541                 :            :         /* Allocate temp text buf */
    7542                 :          0 :         text_buf = OSAL_VZALLOC(p_hwfn, text_size_bytes);
    7543         [ #  # ]:          0 :         if (!text_buf) {
    7544                 :          0 :                 DP_NOTICE(p_hwfn->p_dev, false,
    7545                 :            :                           "failed to allocate text buffer. Aborting\n");
    7546                 :          0 :                 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    7547                 :            :         }
    7548                 :            : 
    7549                 :            :         /* Decode feature opcodes to string on temp buf */
    7550                 :          0 :         rc = qed_features_lookup[feature_idx].print_results(p_hwfn,
    7551                 :          0 :                                                 (u32 *)feature->dump_buf,
    7552                 :            :                                                 feature->dumped_dwords,
    7553                 :            :                                                 text_buf);
    7554         [ #  # ]:          0 :         if (rc != DBG_STATUS_OK) {
    7555                 :          0 :                 OSAL_VFREE(p_hwfn, text_buf);
    7556                 :          0 :                 return rc;
    7557                 :            :         }
    7558                 :            : 
    7559                 :            :         /* Replace the original null character with a '\n' character.
    7560                 :            :          * The bytes that were added as a result of the dword alignment are also
    7561                 :            :          * padded with '\n' characters.
    7562                 :            :          */
    7563         [ #  # ]:          0 :         for (i = null_char_pos; i < text_size_bytes; i++)
    7564                 :          0 :                 text_buf[i] = '\n';
    7565                 :            : 
    7566                 :            : 
    7567                 :            :         /* Free the old dump_buf and point the dump_buf to the newly allocated
    7568                 :            :          * and formatted text buffer.
    7569                 :            :          */
    7570                 :          0 :         OSAL_VFREE(p_hwfn, feature->dump_buf);
    7571                 :          0 :         feature->dump_buf = (u8 *)text_buf;
    7572                 :          0 :         feature->buf_size = text_size_bytes;
    7573                 :          0 :         feature->dumped_dwords = text_size_bytes / 4;
    7574                 :          0 :         return rc;
    7575                 :            : }
    7576                 :            : 
    7577                 :            : #define MAX_DBG_FEATURE_SIZE_DWORDS     0x3FFFFFFF
    7578                 :            : 
    7579                 :            : /* Generic function for performing the dump of a debug feature. */
    7580                 :          0 : static enum dbg_status qed_dbg_dump(struct ecore_hwfn *p_hwfn,
    7581                 :            :                                     struct ecore_ptt *p_ptt,
    7582                 :            :                                     enum ecore_dbg_features feature_idx)
    7583                 :            : {
    7584                 :            :         struct ecore_dbg_feature *feature =
    7585                 :          0 :             &p_hwfn->p_dev->dbg_params.features[feature_idx];
    7586                 :            :         u32 buf_size_dwords;
    7587                 :            :         enum dbg_status rc;
    7588                 :            : 
    7589                 :          0 :         DP_NOTICE(p_hwfn->p_dev, false, "Collecting a debug feature [\"%s\"]\n",
    7590                 :            :                   qed_features_lookup[feature_idx].name);
    7591                 :            : 
    7592                 :            :         /* Dump_buf was already allocated need to free (this can happen if dump
    7593                 :            :          * was called but file was never read).
    7594                 :            :          * We can't use the buffer as is since size may have changed.
    7595                 :            :          */
    7596         [ #  # ]:          0 :         if (feature->dump_buf) {
    7597                 :          0 :                 OSAL_VFREE(p_hwfn, feature->dump_buf);
    7598                 :            :                 feature->dump_buf = NULL;
    7599                 :            :         }
    7600                 :            : 
    7601                 :            :         /* Get buffer size from hsi, allocate accordingly, and perform the
    7602                 :            :          * dump.
    7603                 :            :          */
    7604                 :          0 :         rc = qed_features_lookup[feature_idx].get_size(p_hwfn, p_ptt,
    7605                 :            :                                                        &buf_size_dwords);
    7606         [ #  # ]:          0 :         if (rc != DBG_STATUS_OK && rc != DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
    7607                 :            :                 return rc;
    7608                 :            : 
    7609         [ #  # ]:          0 :         if (buf_size_dwords > MAX_DBG_FEATURE_SIZE_DWORDS) {
    7610                 :          0 :                 feature->buf_size = 0;
    7611                 :          0 :                 DP_NOTICE(p_hwfn->p_dev, false,
    7612                 :            :                           "Debug feature [\"%s\"] size (0x%x dwords) exceeds maximum size (0x%x dwords)\n",
    7613                 :            :                           qed_features_lookup[feature_idx].name,
    7614                 :            :                           buf_size_dwords, MAX_DBG_FEATURE_SIZE_DWORDS);
    7615                 :            : 
    7616                 :          0 :                 return DBG_STATUS_OK;
    7617                 :            :         }
    7618                 :            : 
    7619                 :          0 :         feature->buf_size = buf_size_dwords * sizeof(u32);
    7620                 :          0 :         feature->dump_buf = OSAL_ZALLOC(p_hwfn, GFP_KERNEL, feature->buf_size);
    7621         [ #  # ]:          0 :         if (!feature->dump_buf)
    7622                 :            :                 return DBG_STATUS_VIRT_MEM_ALLOC_FAILED;
    7623                 :            : 
    7624                 :          0 :         rc = qed_features_lookup[feature_idx].perform_dump(p_hwfn, p_ptt,
    7625                 :            :                                         (u32 *)feature->dump_buf,
    7626                 :          0 :                                         feature->buf_size / sizeof(u32),
    7627                 :            :                                         &feature->dumped_dwords);
    7628                 :            : 
    7629                 :            :         /* If mcp is stuck we get DBG_STATUS_NVRAM_GET_IMAGE_FAILED error.
    7630                 :            :          * In this case the buffer holds valid binary data, but we won't able
    7631                 :            :          * to parse it (since parsing relies on data in NVRAM which is only
    7632                 :            :          * accessible when MFW is responsive). skip the formatting but return
    7633                 :            :          * success so that binary data is provided.
    7634                 :            :          */
    7635         [ #  # ]:          0 :         if (rc == DBG_STATUS_NVRAM_GET_IMAGE_FAILED)
    7636                 :            :                 return DBG_STATUS_OK;
    7637                 :            : 
    7638         [ #  # ]:          0 :         if (rc != DBG_STATUS_OK)
    7639                 :            :                 return rc;
    7640                 :            : 
    7641                 :            :         /* Format output */
    7642                 :          0 :         rc = format_feature(p_hwfn, feature_idx);
    7643                 :          0 :         return rc;
    7644                 :            : }
    7645                 :            : 
    7646                 :          0 : int qed_dbg_grc(struct ecore_dev *edev, void *buffer, u32 *num_dumped_bytes)
    7647                 :            : {
    7648                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_GRC, num_dumped_bytes);
    7649                 :            : }
    7650                 :            : 
    7651                 :          0 : int qed_dbg_grc_size(struct ecore_dev *edev)
    7652                 :            : {
    7653                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_GRC);
    7654                 :            : }
    7655                 :            : 
    7656                 :            : int
    7657                 :          0 : qed_dbg_idle_chk(struct ecore_dev *edev, void *buffer, u32 *num_dumped_bytes)
    7658                 :            : {
    7659                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_IDLE_CHK,
    7660                 :            :                                num_dumped_bytes);
    7661                 :            : }
    7662                 :            : 
    7663                 :          0 : int qed_dbg_idle_chk_size(struct ecore_dev *edev)
    7664                 :            : {
    7665                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_IDLE_CHK);
    7666                 :            : }
    7667                 :            : 
    7668                 :            : int
    7669                 :          0 : qed_dbg_reg_fifo(struct ecore_dev *edev, void *buffer, u32 *num_dumped_bytes)
    7670                 :            : {
    7671                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_REG_FIFO,
    7672                 :            :                                num_dumped_bytes);
    7673                 :            : }
    7674                 :            : 
    7675                 :          0 : int qed_dbg_reg_fifo_size(struct ecore_dev *edev)
    7676                 :            : {
    7677                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_REG_FIFO);
    7678                 :            : }
    7679                 :            : 
    7680                 :            : int
    7681                 :          0 : qed_dbg_igu_fifo(struct ecore_dev *edev, void *buffer, u32 *num_dumped_bytes)
    7682                 :            : {
    7683                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_IGU_FIFO,
    7684                 :            :                                num_dumped_bytes);
    7685                 :            : }
    7686                 :            : 
    7687                 :          0 : int qed_dbg_igu_fifo_size(struct ecore_dev *edev)
    7688                 :            : {
    7689                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_IGU_FIFO);
    7690                 :            : }
    7691                 :            : 
    7692                 :            : static int qed_dbg_nvm_image_length(struct ecore_hwfn *p_hwfn,
    7693                 :            :                                     enum ecore_nvm_images image_id, u32 *length)
    7694                 :            : {
    7695                 :            :         struct ecore_nvm_image_att image_att;
    7696                 :            :         int rc;
    7697                 :            : 
    7698                 :            :         *length = 0;
    7699                 :          0 :         rc = ecore_mcp_get_nvm_image_att(p_hwfn, image_id, &image_att);
    7700   [ #  #  #  #  :          0 :         if (rc)
             #  #  #  # ]
    7701                 :            :                 return rc;
    7702                 :            : 
    7703                 :          0 :         *length = image_att.length;
    7704                 :            : 
    7705                 :            :         return rc;
    7706                 :            : }
    7707                 :            : 
    7708                 :          0 : int qed_dbg_protection_override(struct ecore_dev *edev, void *buffer,
    7709                 :            :                                 u32 *num_dumped_bytes)
    7710                 :            : {
    7711                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_PROTECTION_OVERRIDE,
    7712                 :            :                                num_dumped_bytes);
    7713                 :            : }
    7714                 :            : 
    7715                 :          0 : int qed_dbg_protection_override_size(struct ecore_dev *edev)
    7716                 :            : {
    7717                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_PROTECTION_OVERRIDE);
    7718                 :            : }
    7719                 :            : 
    7720                 :          0 : int qed_dbg_fw_asserts(struct ecore_dev *edev, void *buffer,
    7721                 :            :                        u32 *num_dumped_bytes)
    7722                 :            : {
    7723                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_FW_ASSERTS,
    7724                 :            :                                num_dumped_bytes);
    7725                 :            : }
    7726                 :            : 
    7727                 :          0 : int qed_dbg_fw_asserts_size(struct ecore_dev *edev)
    7728                 :            : {
    7729                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_FW_ASSERTS);
    7730                 :            : }
    7731                 :            : 
    7732                 :          0 : int qed_dbg_ilt(struct ecore_dev *edev, void *buffer, u32 *num_dumped_bytes)
    7733                 :            : {
    7734                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_ILT, num_dumped_bytes);
    7735                 :            : }
    7736                 :            : 
    7737                 :          0 : int qed_dbg_ilt_size(struct ecore_dev *edev)
    7738                 :            : {
    7739                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_ILT);
    7740                 :            : }
    7741                 :            : 
    7742                 :          0 : int qed_dbg_mcp_trace(struct ecore_dev *edev, void *buffer,
    7743                 :            :                       u32 *num_dumped_bytes)
    7744                 :            : {
    7745                 :          0 :         return qed_dbg_feature(edev, buffer, DBG_FEATURE_MCP_TRACE,
    7746                 :            :                                num_dumped_bytes);
    7747                 :            : }
    7748                 :            : 
    7749                 :          0 : int qed_dbg_mcp_trace_size(struct ecore_dev *edev)
    7750                 :            : {
    7751                 :          0 :         return qed_dbg_feature_size(edev, DBG_FEATURE_MCP_TRACE);
    7752                 :            : }
    7753                 :            : 
    7754                 :            : /* Defines the amount of bytes allocated for recording the length of debug
    7755                 :            :  * feature buffer.
    7756                 :            :  */
    7757                 :            : #define REGDUMP_HEADER_SIZE                     sizeof(u32)
    7758                 :            : #define REGDUMP_HEADER_SIZE_SHIFT               0
    7759                 :            : #define REGDUMP_HEADER_SIZE_MASK                0xffffff
    7760                 :            : #define REGDUMP_HEADER_FEATURE_SHIFT            24
    7761                 :            : #define REGDUMP_HEADER_FEATURE_MASK             0x3f
    7762                 :            : #define REGDUMP_HEADER_OMIT_ENGINE_SHIFT        30
    7763                 :            : #define REGDUMP_HEADER_OMIT_ENGINE_MASK         0x1
    7764                 :            : #define REGDUMP_HEADER_ENGINE_SHIFT             31
    7765                 :            : #define REGDUMP_HEADER_ENGINE_MASK              0x1
    7766                 :            : #define REGDUMP_MAX_SIZE                        0x1000000
    7767                 :            : #define ILT_DUMP_MAX_SIZE                       (1024 * 1024 * 15)
    7768                 :            : 
    7769                 :            : enum debug_print_features {
    7770                 :            :         OLD_MODE = 0,
    7771                 :            :         IDLE_CHK = 1,
    7772                 :            :         GRC_DUMP = 2,
    7773                 :            :         MCP_TRACE = 3,
    7774                 :            :         REG_FIFO = 4,
    7775                 :            :         PROTECTION_OVERRIDE = 5,
    7776                 :            :         IGU_FIFO = 6,
    7777                 :            :         PHY = 7,
    7778                 :            :         FW_ASSERTS = 8,
    7779                 :            :         NVM_CFG1 = 9,
    7780                 :            :         DEFAULT_CFG = 10,
    7781                 :            :         NVM_META = 11,
    7782                 :            :         MDUMP = 12,
    7783                 :            :         ILT_DUMP = 13,
    7784                 :            : };
    7785                 :            : 
    7786                 :          0 : static u32 qed_calc_regdump_header(struct ecore_dev *edev,
    7787                 :            :                                    enum debug_print_features feature,
    7788                 :            :                                    int engine, u32 feature_size, u8 omit_engine)
    7789                 :            : {
    7790                 :            :         u32 res = 0;
    7791                 :            : 
    7792                 :          0 :         SET_FIELD(res, REGDUMP_HEADER_SIZE, feature_size);
    7793         [ #  # ]:          0 :         if (res != feature_size)
    7794                 :          0 :                 DP_NOTICE(edev, false,
    7795                 :            :                           "Feature %d is too large (size 0x%x) and will corrupt the dump\n",
    7796                 :            :                           feature, feature_size);
    7797                 :            : 
    7798                 :          0 :         SET_FIELD(res, REGDUMP_HEADER_FEATURE, feature);
    7799                 :          0 :         SET_FIELD(res, REGDUMP_HEADER_OMIT_ENGINE, omit_engine);
    7800                 :          0 :         SET_FIELD(res, REGDUMP_HEADER_ENGINE, engine);
    7801                 :            : 
    7802                 :          0 :         return res;
    7803                 :            : }
    7804                 :            : 
    7805                 :          0 : int qed_dbg_all_data(struct ecore_dev *edev, void *buffer)
    7806                 :            : {
    7807                 :            :         u8 cur_engine, omit_engine = 0, org_engine;
    7808                 :            :         struct ecore_hwfn *p_hwfn =
    7809                 :          0 :                 &edev->hwfns[edev->dbg_params.engine_for_debug];
    7810                 :            :         struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
    7811                 :            :         int grc_params[MAX_DBG_GRC_PARAMS], i;
    7812                 :            :         u32 offset = 0, feature_size;
    7813                 :            :         int rc;
    7814                 :            : 
    7815         [ #  # ]:          0 :         for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
    7816                 :          0 :                 grc_params[i] = dev_data->grc.param_val[i];
    7817                 :            : 
    7818         [ #  # ]:          0 :         if (!ECORE_IS_CMT(edev))
    7819                 :            :                 omit_engine = 1;
    7820                 :            : 
    7821                 :          0 :         OSAL_MUTEX_ACQUIRE(&edev->dbg_lock);
    7822                 :            : 
    7823                 :          0 :         org_engine = qed_get_debug_engine(edev);
    7824         [ #  # ]:          0 :         for (cur_engine = 0; cur_engine < edev->num_hwfns; cur_engine++) {
    7825                 :            :                 /* Collect idle_chks and grcDump for each hw function */
    7826         [ #  # ]:          0 :                 DP_VERBOSE(edev, ECORE_MSG_DEBUG,
    7827                 :            :                            "obtaining idle_chk and grcdump for current engine\n");
    7828                 :          0 :                 qed_set_debug_engine(edev, cur_engine);
    7829                 :            : 
    7830                 :            :                 /* First idle_chk */
    7831                 :          0 :                 rc = qed_dbg_idle_chk(edev, (u8 *)buffer + offset +
    7832                 :            :                                       REGDUMP_HEADER_SIZE, &feature_size);
    7833         [ #  # ]:          0 :                 if (!rc) {
    7834                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7835                 :          0 :                             qed_calc_regdump_header(edev, IDLE_CHK, cur_engine,
    7836                 :            :                                                     feature_size, omit_engine);
    7837                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7838                 :            :                 } else {
    7839                 :          0 :                         DP_ERR(edev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
    7840                 :            :                 }
    7841                 :            : 
    7842                 :            :                 /* Second idle_chk */
    7843                 :          0 :                 rc = qed_dbg_idle_chk(edev, (u8 *)buffer + offset +
    7844                 :            :                                       REGDUMP_HEADER_SIZE, &feature_size);
    7845         [ #  # ]:          0 :                 if (!rc) {
    7846                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7847                 :          0 :                             qed_calc_regdump_header(edev, IDLE_CHK, cur_engine,
    7848                 :            :                                                     feature_size, omit_engine);
    7849                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7850                 :            :                 } else {
    7851                 :          0 :                         DP_ERR(edev, "qed_dbg_idle_chk failed. rc = %d\n", rc);
    7852                 :            :                 }
    7853                 :            : 
    7854                 :            :                 /* reg_fifo dump */
    7855                 :          0 :                 rc = qed_dbg_reg_fifo(edev, (u8 *)buffer + offset +
    7856                 :            :                                       REGDUMP_HEADER_SIZE, &feature_size);
    7857         [ #  # ]:          0 :                 if (!rc) {
    7858                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7859                 :          0 :                             qed_calc_regdump_header(edev, REG_FIFO, cur_engine,
    7860                 :            :                                                     feature_size, omit_engine);
    7861                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7862                 :            :                 } else {
    7863                 :          0 :                         DP_ERR(edev, "qed_dbg_reg_fifo failed. rc = %d\n", rc);
    7864                 :            :                 }
    7865                 :            : 
    7866                 :            :                 /* igu_fifo dump */
    7867                 :          0 :                 rc = qed_dbg_igu_fifo(edev, (u8 *)buffer + offset +
    7868                 :            :                                       REGDUMP_HEADER_SIZE, &feature_size);
    7869         [ #  # ]:          0 :                 if (!rc) {
    7870                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7871                 :          0 :                             qed_calc_regdump_header(edev, IGU_FIFO, cur_engine,
    7872                 :            :                                                     feature_size, omit_engine);
    7873                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7874                 :            :                 } else {
    7875                 :          0 :                         DP_ERR(edev, "qed_dbg_igu_fifo failed. rc = %d", rc);
    7876                 :            :                 }
    7877                 :            : 
    7878                 :            :                 /* protection_override dump */
    7879                 :          0 :                 rc = qed_dbg_protection_override(edev, (u8 *)buffer + offset +
    7880                 :            :                                                  REGDUMP_HEADER_SIZE,
    7881                 :            :                                                  &feature_size);
    7882         [ #  # ]:          0 :                 if (!rc) {
    7883                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7884                 :          0 :                             qed_calc_regdump_header(edev, PROTECTION_OVERRIDE,
    7885                 :            :                                                     cur_engine,
    7886                 :            :                                                     feature_size, omit_engine);
    7887                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7888                 :            :                 } else {
    7889                 :          0 :                         DP_ERR(edev,
    7890                 :            :                                "qed_dbg_protection_override failed. rc = %d\n",
    7891                 :            :                                rc);
    7892                 :            :                 }
    7893                 :            : 
    7894                 :            :                 /* fw_asserts dump */
    7895                 :          0 :                 rc = qed_dbg_fw_asserts(edev, (u8 *)buffer + offset +
    7896                 :            :                                         REGDUMP_HEADER_SIZE, &feature_size);
    7897         [ #  # ]:          0 :                 if (!rc) {
    7898                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7899                 :          0 :                             qed_calc_regdump_header(edev, FW_ASSERTS,
    7900                 :            :                                                     cur_engine, feature_size,
    7901                 :            :                                                     omit_engine);
    7902                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7903                 :            :                 } else {
    7904                 :          0 :                         DP_ERR(edev, "qed_dbg_fw_asserts failed. rc = %d\n",
    7905                 :            :                                rc);
    7906                 :            :                 }
    7907                 :            : 
    7908                 :            :                 /* GRC dump - must be last because when mcp stuck it will
    7909                 :            :                  * clutter idle_chk, reg_fifo, ...
    7910                 :            :                  */
    7911         [ #  # ]:          0 :                 for (i = 0; i < MAX_DBG_GRC_PARAMS; i++)
    7912                 :          0 :                         dev_data->grc.param_val[i] = grc_params[i];
    7913                 :            : 
    7914                 :          0 :                 rc = qed_dbg_grc(edev, (u8 *)buffer + offset +
    7915                 :            :                                  REGDUMP_HEADER_SIZE, &feature_size);
    7916         [ #  # ]:          0 :                 if (!rc) {
    7917                 :          0 :                         *(u32 *)((u8 *)buffer + offset) =
    7918                 :          0 :                             qed_calc_regdump_header(edev, GRC_DUMP,
    7919                 :            :                                                     cur_engine,
    7920                 :            :                                                     feature_size, omit_engine);
    7921                 :          0 :                         offset += (feature_size + REGDUMP_HEADER_SIZE);
    7922                 :            :                 } else {
    7923                 :          0 :                         DP_ERR(edev, "qed_dbg_grc failed. rc = %d", rc);
    7924                 :            :                 }
    7925                 :            :         }
    7926                 :            : 
    7927                 :          0 :         qed_set_debug_engine(edev, org_engine);
    7928                 :            : 
    7929                 :            :         /* mcp_trace */
    7930                 :          0 :         rc = qed_dbg_mcp_trace(edev, (u8 *)buffer + offset +
    7931                 :            :                                REGDUMP_HEADER_SIZE, &feature_size);
    7932         [ #  # ]:          0 :         if (!rc) {
    7933                 :          0 :                 *(u32 *)((u8 *)buffer + offset) =
    7934                 :          0 :                     qed_calc_regdump_header(edev, MCP_TRACE, cur_engine,
    7935                 :            :                                             feature_size, omit_engine);
    7936                 :            :                 offset += (feature_size + REGDUMP_HEADER_SIZE);
    7937                 :            :         } else {
    7938                 :          0 :                 DP_ERR(edev, "qed_dbg_mcp_trace failed. rc = %d\n", rc);
    7939                 :            :         }
    7940                 :            : 
    7941                 :          0 :         OSAL_MUTEX_RELEASE(&edev->dbg_lock);
    7942                 :            : 
    7943                 :          0 :         return 0;
    7944                 :            : }
    7945                 :            : 
    7946                 :          0 : int qed_dbg_all_data_size(struct ecore_dev *edev)
    7947                 :            : {
    7948                 :          0 :         struct ecore_hwfn *p_hwfn =
    7949                 :          0 :                 &edev->hwfns[edev->dbg_params.engine_for_debug];
    7950                 :            :         u32 regs_len = 0, image_len = 0, ilt_len = 0, total_ilt_len = 0;
    7951                 :            :         u8 cur_engine, org_engine;
    7952                 :            : 
    7953                 :          0 :         edev->disable_ilt_dump = false;
    7954                 :          0 :         org_engine = qed_get_debug_engine(edev);
    7955         [ #  # ]:          0 :         for (cur_engine = 0; cur_engine < edev->num_hwfns; cur_engine++) {
    7956                 :            :                 /* Engine specific */
    7957         [ #  # ]:          0 :                 DP_VERBOSE(edev, ECORE_MSG_DEBUG,
    7958                 :            :                            "calculating idle_chk and grcdump register length for current engine\n");
    7959                 :          0 :                 qed_set_debug_engine(edev, cur_engine);
    7960                 :          0 :                 regs_len += REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(edev) +
    7961                 :          0 :                             REGDUMP_HEADER_SIZE + qed_dbg_idle_chk_size(edev) +
    7962                 :          0 :                             REGDUMP_HEADER_SIZE + qed_dbg_grc_size(edev) +
    7963                 :          0 :                             REGDUMP_HEADER_SIZE + qed_dbg_reg_fifo_size(edev) +
    7964                 :          0 :                             REGDUMP_HEADER_SIZE + qed_dbg_igu_fifo_size(edev) +
    7965                 :          0 :                             REGDUMP_HEADER_SIZE +
    7966                 :          0 :                             qed_dbg_protection_override_size(edev) +
    7967                 :          0 :                             REGDUMP_HEADER_SIZE + qed_dbg_fw_asserts_size(edev);
    7968                 :            : 
    7969                 :          0 :                 ilt_len = REGDUMP_HEADER_SIZE + qed_dbg_ilt_size(edev);
    7970         [ #  # ]:          0 :                 if (ilt_len < ILT_DUMP_MAX_SIZE) {
    7971                 :          0 :                         total_ilt_len += ilt_len;
    7972                 :          0 :                         regs_len += ilt_len;
    7973                 :            :                 }
    7974                 :            :         }
    7975                 :            : 
    7976                 :          0 :         qed_set_debug_engine(edev, org_engine);
    7977                 :            : 
    7978                 :            :         /* Engine common */
    7979                 :          0 :         regs_len += REGDUMP_HEADER_SIZE + qed_dbg_mcp_trace_size(edev);
    7980                 :            :         qed_dbg_nvm_image_length(p_hwfn, ECORE_NVM_IMAGE_NVM_CFG1, &image_len);
    7981         [ #  # ]:          0 :         if (image_len)
    7982                 :          0 :                 regs_len += REGDUMP_HEADER_SIZE + image_len;
    7983                 :            :         qed_dbg_nvm_image_length(p_hwfn, ECORE_NVM_IMAGE_DEFAULT_CFG,
    7984                 :            :                                  &image_len);
    7985         [ #  # ]:          0 :         if (image_len)
    7986                 :          0 :                 regs_len += REGDUMP_HEADER_SIZE + image_len;
    7987                 :            :         qed_dbg_nvm_image_length(p_hwfn, ECORE_NVM_IMAGE_NVM_META, &image_len);
    7988         [ #  # ]:          0 :         if (image_len)
    7989                 :          0 :                 regs_len += REGDUMP_HEADER_SIZE + image_len;
    7990                 :            :         qed_dbg_nvm_image_length(p_hwfn, ECORE_NVM_IMAGE_MDUMP, &image_len);
    7991         [ #  # ]:          0 :         if (image_len)
    7992                 :          0 :                 regs_len += REGDUMP_HEADER_SIZE + image_len;
    7993                 :            : 
    7994         [ #  # ]:          0 :         if (regs_len > REGDUMP_MAX_SIZE) {
    7995         [ #  # ]:          0 :                 DP_VERBOSE(edev, ECORE_MSG_DEBUG,
    7996                 :            :                            "Dump exceeds max size 0x%x, disable ILT dump\n",
    7997                 :            :                            REGDUMP_MAX_SIZE);
    7998                 :          0 :                 edev->disable_ilt_dump = true;
    7999                 :          0 :                 regs_len -= total_ilt_len;
    8000                 :            :         }
    8001                 :            : 
    8002                 :          0 :         return regs_len;
    8003                 :            : }
    8004                 :            : 
    8005                 :          0 : int qed_dbg_feature(struct ecore_dev *edev, void *buffer,
    8006                 :            :                     enum ecore_dbg_features feature, u32 *num_dumped_bytes)
    8007                 :            : {
    8008                 :          0 :         struct ecore_hwfn *p_hwfn =
    8009                 :          0 :                 &edev->hwfns[edev->dbg_params.engine_for_debug];
    8010                 :            :         struct ecore_dbg_feature *qed_feature =
    8011                 :            :                 &edev->dbg_params.features[feature];
    8012                 :            :         enum dbg_status dbg_rc;
    8013                 :            :         struct ecore_ptt *p_ptt;
    8014                 :            :         int rc = 0;
    8015                 :            : 
    8016                 :            :         /* Acquire ptt */
    8017                 :          0 :         p_ptt = ecore_ptt_acquire(p_hwfn);
    8018         [ #  # ]:          0 :         if (!p_ptt)
    8019                 :            :                 return -EINVAL;
    8020                 :            : 
    8021                 :            :         /* Get dump */
    8022                 :          0 :         dbg_rc = qed_dbg_dump(p_hwfn, p_ptt, feature);
    8023         [ #  # ]:          0 :         if (dbg_rc != DBG_STATUS_OK) {
    8024         [ #  # ]:          0 :                 DP_VERBOSE(edev, ECORE_MSG_DEBUG, "%s\n",
    8025                 :            :                            qed_dbg_get_status_str(dbg_rc));
    8026                 :          0 :                 *num_dumped_bytes = 0;
    8027                 :            :                 rc = -EINVAL;
    8028                 :          0 :                 goto out;
    8029                 :            :         }
    8030                 :            : 
    8031         [ #  # ]:          0 :         DP_VERBOSE(edev, ECORE_MSG_DEBUG,
    8032                 :            :                    "copying debug feature to external buffer\n");
    8033                 :          0 :         memcpy(buffer, qed_feature->dump_buf, qed_feature->buf_size);
    8034                 :          0 :         *num_dumped_bytes = edev->dbg_params.features[feature].dumped_dwords *
    8035                 :            :                             4;
    8036                 :            : 
    8037                 :          0 : out:
    8038                 :          0 :         ecore_ptt_release(p_hwfn, p_ptt);
    8039                 :          0 :         return rc;
    8040                 :            : }
    8041                 :            : 
    8042                 :            : int
    8043                 :          0 : qed_dbg_feature_size(struct ecore_dev *edev, enum ecore_dbg_features feature)
    8044                 :            : {
    8045                 :          0 :         struct ecore_hwfn *p_hwfn =
    8046                 :          0 :                 &edev->hwfns[edev->dbg_params.engine_for_debug];
    8047                 :            :         struct ecore_dbg_feature *qed_feature = &edev->dbg_features[feature];
    8048                 :          0 :         struct ecore_ptt *p_ptt = ecore_ptt_acquire(p_hwfn);
    8049                 :            :         u32 buf_size_dwords;
    8050                 :            :         enum dbg_status rc;
    8051                 :            : 
    8052         [ #  # ]:          0 :         if (!p_ptt)
    8053                 :            :                 return -EINVAL;
    8054                 :            : 
    8055                 :          0 :         rc = qed_features_lookup[feature].get_size(p_hwfn, p_ptt,
    8056                 :            :                                                    &buf_size_dwords);
    8057         [ #  # ]:          0 :         if (rc != DBG_STATUS_OK)
    8058                 :          0 :                 buf_size_dwords = 0;
    8059                 :            : 
    8060                 :            :         /* Feature will not be dumped if it exceeds maximum size */
    8061         [ #  # ]:          0 :         if (buf_size_dwords > MAX_DBG_FEATURE_SIZE_DWORDS)
    8062                 :          0 :                 buf_size_dwords = 0;
    8063                 :            : 
    8064                 :          0 :         ecore_ptt_release(p_hwfn, p_ptt);
    8065                 :          0 :         qed_feature->buf_size = buf_size_dwords * sizeof(u32);
    8066                 :          0 :         return qed_feature->buf_size;
    8067                 :            : }
    8068                 :            : 
    8069                 :          0 : u8 qed_get_debug_engine(struct ecore_dev *edev)
    8070                 :            : {
    8071                 :          0 :         return edev->dbg_params.engine_for_debug;
    8072                 :            : }
    8073                 :            : 
    8074                 :          0 : void qed_set_debug_engine(struct ecore_dev *edev, int engine_number)
    8075                 :            : {
    8076         [ #  # ]:          0 :         DP_VERBOSE(edev, ECORE_MSG_DEBUG, "set debug engine to %d\n",
    8077                 :            :                    engine_number);
    8078                 :          0 :         edev->dbg_params.engine_for_debug = engine_number;
    8079                 :          0 : }
    8080                 :            : 
    8081                 :          0 : void qed_dbg_pf_init(struct ecore_dev *edev)
    8082                 :            : {
    8083                 :            :         const u8 *dbg_values = NULL;
    8084                 :            :         int i;
    8085                 :            : 
    8086                 :          0 :         PMD_INIT_FUNC_TRACE(edev);
    8087                 :            : 
    8088                 :          0 :         OSAL_MUTEX_INIT(&edev->dbg_lock);
    8089                 :            : 
    8090                 :            :         /* Sync ver with debugbus qed code */
    8091                 :          0 :         qed_dbg_set_app_ver(TOOLS_VERSION);
    8092                 :            : 
    8093                 :            :         /* Debug values are after init values.
    8094                 :            :          * The offset is the first dword of the file.
    8095                 :            :          */
    8096                 :            :         /* TBD: change hardcoded value to offset from FW file */
    8097                 :          0 :         dbg_values = (const u8 *)edev->firmware + 1337296;
    8098                 :            : 
    8099         [ #  # ]:          0 :         for_each_hwfn(edev, i) {
    8100                 :          0 :                 qed_dbg_set_bin_ptr(&edev->hwfns[i], dbg_values);
    8101                 :          0 :                 qed_dbg_user_set_bin_ptr(&edev->hwfns[i], dbg_values);
    8102                 :            :         }
    8103                 :            : 
    8104                 :            :         /* Set the hwfn to be 0 as default */
    8105                 :          0 :         edev->dbg_params.engine_for_debug = 0;
    8106                 :          0 : }
    8107                 :            : 
    8108                 :          0 : void qed_dbg_pf_exit(struct ecore_dev *edev)
    8109                 :            : {
    8110                 :            :         struct ecore_dbg_feature *feature = NULL;
    8111                 :            :         enum ecore_dbg_features feature_idx;
    8112                 :            : 
    8113                 :          0 :         PMD_INIT_FUNC_TRACE(edev);
    8114                 :            : 
    8115                 :            :         /* debug features' buffers may be allocated if debug feature was used
    8116                 :            :          * but dump wasn't called
    8117                 :            :          */
    8118         [ #  # ]:          0 :         for (feature_idx = 0; feature_idx < DBG_FEATURE_NUM; feature_idx++) {
    8119                 :            :                 feature = &edev->dbg_features[feature_idx];
    8120         [ #  # ]:          0 :                 if (feature->dump_buf) {
    8121                 :          0 :                         OSAL_VFREE(edev, feature->dump_buf);
    8122                 :            :                         feature->dump_buf = NULL;
    8123                 :            :                 }
    8124                 :            :         }
    8125                 :            : 
    8126                 :            :         OSAL_MUTEX_DEALLOC(&edev->dbg_lock);
    8127                 :          0 : }

Generated by: LCOV version 1.14