hclge_err.c 62.5 KB
Newer Older
1 2 3 4 5
// SPDX-License-Identifier: GPL-2.0+
/* Copyright (c) 2016-2017 Hisilicon Limited. */

#include "hclge_err.h"

6
static const struct hclge_hw_error hclge_imp_tcm_ecc_int[] = {
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
	{ .int_msk = BIT(1), .msg = "imp_itcm0_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(3), .msg = "imp_itcm1_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(5), .msg = "imp_itcm2_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(7), .msg = "imp_itcm3_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(9), .msg = "imp_dtcm0_mem0_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(11), .msg = "imp_dtcm0_mem1_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(13), .msg = "imp_dtcm1_mem0_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(15), .msg = "imp_dtcm1_mem1_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(17), .msg = "imp_itcm4_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
25 26 27 28
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_cmdq_nic_mem_ecc_int[] = {
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	{ .int_msk = BIT(1), .msg = "cmdq_nic_rx_depth_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(3), .msg = "cmdq_nic_tx_depth_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(5), .msg = "cmdq_nic_rx_tail_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(7), .msg = "cmdq_nic_tx_tail_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(9), .msg = "cmdq_nic_rx_head_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(11), .msg = "cmdq_nic_tx_head_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(13), .msg = "cmdq_nic_rx_addr_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(15), .msg = "cmdq_nic_tx_addr_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(17), .msg = "cmdq_rocee_rx_depth_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(19), .msg = "cmdq_rocee_tx_depth_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(21), .msg = "cmdq_rocee_rx_tail_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(23), .msg = "cmdq_rocee_tx_tail_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(25), .msg = "cmdq_rocee_rx_head_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(27), .msg = "cmdq_rocee_tx_head_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(29), .msg = "cmdq_rocee_rx_addr_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(31), .msg = "cmdq_rocee_tx_addr_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
61 62 63 64
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_tqp_int_ecc_int[] = {
65 66 67 68 69 70 71 72 73 74 75 76
	{ .int_msk = BIT(6), .msg = "tqp_int_cfg_even_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(7), .msg = "tqp_int_cfg_odd_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(8), .msg = "tqp_int_ctrl_even_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(9), .msg = "tqp_int_ctrl_odd_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(10), .msg = "tx_que_scan_int_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(11), .msg = "rx_que_scan_int_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
77 78 79
	{ /* sentinel */ }
};

80
static const struct hclge_hw_error hclge_msix_sram_ecc_int[] = {
81 82 83 84
	{ .int_msk = BIT(1), .msg = "msix_nic_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(3), .msg = "msix_rocee_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
85 86 87 88
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_igu_int[] = {
89
	{ .int_msk = BIT(0), .msg = "igu_rx_buf0_ecc_mbit_err",
90
	  .reset_level = HNAE3_GLOBAL_RESET },
91
	{ .int_msk = BIT(2), .msg = "igu_rx_buf1_ecc_mbit_err",
92
	  .reset_level = HNAE3_GLOBAL_RESET },
93 94 95
	{ /* sentinel */ }
};

96
static const struct hclge_hw_error hclge_igu_egu_tnl_int[] = {
97
	{ .int_msk = BIT(0), .msg = "rx_buf_overflow",
98
	  .reset_level = HNAE3_GLOBAL_RESET },
99
	{ .int_msk = BIT(1), .msg = "rx_stp_fifo_overflow",
100
	  .reset_level = HNAE3_GLOBAL_RESET },
101
	{ .int_msk = BIT(2), .msg = "rx_stp_fifo_undeflow",
102
	  .reset_level = HNAE3_GLOBAL_RESET },
103
	{ .int_msk = BIT(3), .msg = "tx_buf_overflow",
104
	  .reset_level = HNAE3_GLOBAL_RESET },
105
	{ .int_msk = BIT(4), .msg = "tx_buf_underrun",
106
	  .reset_level = HNAE3_GLOBAL_RESET },
107
	{ .int_msk = BIT(5), .msg = "rx_stp_buf_overflow",
108
	  .reset_level = HNAE3_GLOBAL_RESET },
109 110 111 112
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ncsi_err_int[] = {
113 114
	{ .int_msk = BIT(1), .msg = "ncsi_tx_ecc_mbit_err",
	  .reset_level = HNAE3_NONE_RESET },
115 116 117
	{ /* sentinel */ }
};

118
static const struct hclge_hw_error hclge_ppp_mpf_abnormal_int_st1[] = {
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	{ .int_msk = BIT(0), .msg = "vf_vlan_ad_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "umv_mcast_group_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "umv_key_mem0_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "umv_key_mem1_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "umv_key_mem2_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "umv_key_mem3_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "umv_ad_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "rss_tc_mode_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "rss_idt_mem0_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "rss_idt_mem1_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(10), .msg = "rss_idt_mem2_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "rss_idt_mem3_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "rss_idt_mem4_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "rss_idt_mem5_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "rss_idt_mem6_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "rss_idt_mem7_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(16), .msg = "rss_idt_mem8_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "rss_idt_mem9_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(18), .msg = "rss_idt_mem10_ecc_m1bit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(19), .msg = "rss_idt_mem11_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(20), .msg = "rss_idt_mem12_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(21), .msg = "rss_idt_mem13_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(22), .msg = "rss_idt_mem14_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(23), .msg = "rss_idt_mem15_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(24), .msg = "port_vlan_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(25), .msg = "mcast_linear_table_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(26), .msg = "mcast_result_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(27), .msg = "flow_director_ad_mem0_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(28), .msg = "flow_director_ad_mem1_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(29), .msg = "rx_vlan_tag_memory_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(30), .msg = "Tx_UP_mapping_config_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
181 182 183
	{ /* sentinel */ }
};

S
Shiju Jose 已提交
184
static const struct hclge_hw_error hclge_ppp_pf_abnormal_int[] = {
185 186 187 188
	{ .int_msk = BIT(0), .msg = "tx_vlan_tag_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(1), .msg = "rss_list_tc_unassigned_queue_err",
	  .reset_level = HNAE3_NONE_RESET },
189 190 191
	{ /* sentinel */ }
};

192
static const struct hclge_hw_error hclge_ppp_mpf_abnormal_int_st3[] = {
193 194 195 196 197 198 199 200 201 202 203 204
	{ .int_msk = BIT(0), .msg = "hfs_fifo_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "rslt_descr_fifo_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "tx_vlan_tag_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "FD_CN0_memory_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "FD_CN1_memory_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "GRO_AD_memory_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
205 206 207
	{ /* sentinel */ }
};

208
static const struct hclge_hw_error hclge_tm_sch_rint[] = {
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	{ .int_msk = BIT(1), .msg = "tm_sch_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "tm_sch_port_shap_sub_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "tm_sch_port_shap_sub_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "tm_sch_pg_pshap_sub_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "tm_sch_pg_pshap_sub_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "tm_sch_pg_cshap_sub_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "tm_sch_pg_cshap_sub_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "tm_sch_pri_pshap_sub_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "tm_sch_pri_pshap_sub_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(10), .msg = "tm_sch_pri_cshap_sub_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "tm_sch_pri_cshap_sub_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "tm_sch_port_shap_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "tm_sch_port_shap_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "tm_sch_pg_pshap_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "tm_sch_pg_pshap_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(16), .msg = "tm_sch_pg_cshap_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "tm_sch_pg_cshap_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(18), .msg = "tm_sch_pri_pshap_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(19), .msg = "tm_sch_pri_pshap_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(20), .msg = "tm_sch_pri_cshap_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(21), .msg = "tm_sch_pri_cshap_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(22), .msg = "tm_sch_rq_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(23), .msg = "tm_sch_rq_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(24), .msg = "tm_sch_nq_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(25), .msg = "tm_sch_nq_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(26), .msg = "tm_sch_roce_up_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(27), .msg = "tm_sch_roce_up_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(28), .msg = "tm_sch_rcb_byte_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(29), .msg = "tm_sch_rcb_byte_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(30), .msg = "tm_sch_ssu_byte_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(31), .msg = "tm_sch_ssu_byte_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
271 272 273 274
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_qcn_fifo_rint[] = {
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
	{ .int_msk = BIT(0), .msg = "qcn_shap_gp0_sch_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "qcn_shap_gp0_sch_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "qcn_shap_gp1_sch_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "qcn_shap_gp1_sch_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "qcn_shap_gp2_sch_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "qcn_shap_gp2_sch_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "qcn_shap_gp3_sch_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "qcn_shap_gp3_sch_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "qcn_shap_gp0_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "qcn_shap_gp0_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(10), .msg = "qcn_shap_gp1_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "qcn_shap_gp1_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "qcn_shap_gp2_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "qcn_shap_gp2_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "qcn_shap_gp3_offset_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "qcn_shap_gp3_offset_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(16), .msg = "qcn_byte_info_fifo_rd_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "qcn_byte_info_fifo_wr_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
311 312 313
	{ /* sentinel */ }
};

314
static const struct hclge_hw_error hclge_qcn_ecc_rint[] = {
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
	{ .int_msk = BIT(1), .msg = "qcn_byte_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "qcn_time_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "qcn_fb_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "qcn_link_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "qcn_rate_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "qcn_tmplt_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "qcn_shap_cfg_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "qcn_gp0_barrel_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "qcn_gp1_barrel_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(19), .msg = "qcn_gp2_barrel_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(21), .msg = "qcn_gp3_barral_mem_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
337 338 339
	{ /* sentinel */ }
};

340
static const struct hclge_hw_error hclge_mac_afifo_tnl_int[] = {
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	{ .int_msk = BIT(0), .msg = "egu_cge_afifo_ecc_1bit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(1), .msg = "egu_cge_afifo_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "egu_lge_afifo_ecc_1bit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(3), .msg = "egu_lge_afifo_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "cge_igu_afifo_ecc_1bit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(5), .msg = "cge_igu_afifo_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "lge_igu_afifo_ecc_1bit_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(7), .msg = "lge_igu_afifo_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "cge_igu_afifo_overflow_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "lge_igu_afifo_overflow_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(10), .msg = "egu_cge_afifo_underrun_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "egu_lge_afifo_underrun_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "egu_ge_afifo_underrun_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "ge_igu_afifo_overflow_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
369 370 371
	{ /* sentinel */ }
};

372
static const struct hclge_hw_error hclge_ppu_mpf_abnormal_int_st2[] = {
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	{ .int_msk = BIT(13), .msg = "rpu_rx_pkt_bit32_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "rpu_rx_pkt_bit33_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "rpu_rx_pkt_bit34_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(16), .msg = "rpu_rx_pkt_bit35_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "rcb_tx_ring_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(18), .msg = "rcb_rx_ring_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(19), .msg = "rcb_tx_fbd_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(20), .msg = "rcb_rx_ebd_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(21), .msg = "rcb_tso_info_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(22), .msg = "rcb_tx_int_info_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(23), .msg = "rcb_rx_int_info_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(24), .msg = "tpu_tx_pkt_0_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(25), .msg = "tpu_tx_pkt_1_ecc_mbit_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(26), .msg = "rd_bus_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(27), .msg = "wr_bus_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(28), .msg = "reg_search_miss",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(29), .msg = "rx_q_search_miss",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(30), .msg = "ooo_ecc_err_detect",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(31), .msg = "ooo_ecc_err_multpl",
	  .reset_level = HNAE3_GLOBAL_RESET },
411 412 413 414
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ppu_mpf_abnormal_int_st3[] = {
415
	{ .int_msk = BIT(4), .msg = "gro_bd_ecc_mbit_err",
416
	  .reset_level = HNAE3_GLOBAL_RESET },
417
	{ .int_msk = BIT(5), .msg = "gro_context_ecc_mbit_err",
418
	  .reset_level = HNAE3_GLOBAL_RESET },
419
	{ .int_msk = BIT(6), .msg = "rx_stash_cfg_ecc_mbit_err",
420
	  .reset_level = HNAE3_GLOBAL_RESET },
421
	{ .int_msk = BIT(7), .msg = "axi_rd_fbd_ecc_mbit_err",
422
	  .reset_level = HNAE3_GLOBAL_RESET },
423 424 425 426
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ppu_pf_abnormal_int[] = {
427 428 429 430 431 432 433 434 435 436 437 438
	{ .int_msk = BIT(0), .msg = "over_8bd_no_fe",
	  .reset_level = HNAE3_FUNC_RESET },
	{ .int_msk = BIT(1), .msg = "tso_mss_cmp_min_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(2), .msg = "tso_mss_cmp_max_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(3), .msg = "tx_rd_fbd_poison",
	  .reset_level = HNAE3_FUNC_RESET },
	{ .int_msk = BIT(4), .msg = "rx_rd_ebd_poison",
	  .reset_level = HNAE3_FUNC_RESET },
	{ .int_msk = BIT(5), .msg = "buf_wait_timeout",
	  .reset_level = HNAE3_NONE_RESET },
439 440 441
	{ /* sentinel */ }
};

S
Shiju Jose 已提交
442
static const struct hclge_hw_error hclge_ssu_com_err_int[] = {
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
	{ .int_msk = BIT(0), .msg = "buf_sum_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(1), .msg = "ppp_mb_num_err",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(2), .msg = "ppp_mbid_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "ppp_rlt_mac_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "ppp_rlt_host_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "cks_edit_position_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "cks_edit_condition_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "vlan_edit_condition_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "vlan_num_ot_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "vlan_num_in_err",
	  .reset_level = HNAE3_GLOBAL_RESET },
S
Shiju Jose 已提交
463 464 465
	{ /* sentinel */ }
};

466
#define HCLGE_SSU_MEM_ECC_ERR(x) \
467 468
	{ .int_msk = BIT(x), .msg = "ssu_mem" #x "_ecc_mbit_err", \
	  .reset_level = HNAE3_GLOBAL_RESET }
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

static const struct hclge_hw_error hclge_ssu_mem_ecc_err_int[] = {
	HCLGE_SSU_MEM_ECC_ERR(0),
	HCLGE_SSU_MEM_ECC_ERR(1),
	HCLGE_SSU_MEM_ECC_ERR(2),
	HCLGE_SSU_MEM_ECC_ERR(3),
	HCLGE_SSU_MEM_ECC_ERR(4),
	HCLGE_SSU_MEM_ECC_ERR(5),
	HCLGE_SSU_MEM_ECC_ERR(6),
	HCLGE_SSU_MEM_ECC_ERR(7),
	HCLGE_SSU_MEM_ECC_ERR(8),
	HCLGE_SSU_MEM_ECC_ERR(9),
	HCLGE_SSU_MEM_ECC_ERR(10),
	HCLGE_SSU_MEM_ECC_ERR(11),
	HCLGE_SSU_MEM_ECC_ERR(12),
	HCLGE_SSU_MEM_ECC_ERR(13),
	HCLGE_SSU_MEM_ECC_ERR(14),
	HCLGE_SSU_MEM_ECC_ERR(15),
	HCLGE_SSU_MEM_ECC_ERR(16),
	HCLGE_SSU_MEM_ECC_ERR(17),
	HCLGE_SSU_MEM_ECC_ERR(18),
	HCLGE_SSU_MEM_ECC_ERR(19),
	HCLGE_SSU_MEM_ECC_ERR(20),
	HCLGE_SSU_MEM_ECC_ERR(21),
	HCLGE_SSU_MEM_ECC_ERR(22),
	HCLGE_SSU_MEM_ECC_ERR(23),
	HCLGE_SSU_MEM_ECC_ERR(24),
	HCLGE_SSU_MEM_ECC_ERR(25),
	HCLGE_SSU_MEM_ECC_ERR(26),
	HCLGE_SSU_MEM_ECC_ERR(27),
	HCLGE_SSU_MEM_ECC_ERR(28),
	HCLGE_SSU_MEM_ECC_ERR(29),
	HCLGE_SSU_MEM_ECC_ERR(30),
	HCLGE_SSU_MEM_ECC_ERR(31),
	{ /* sentinel */ }
};

S
Shiju Jose 已提交
506
static const struct hclge_hw_error hclge_ssu_port_based_err_int[] = {
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
	{ .int_msk = BIT(0), .msg = "roc_pkt_without_key_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "tpu_pkt_without_key_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "igu_pkt_without_key_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "roc_eof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "tpu_eof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "igu_eof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "roc_sof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "tpu_sof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "igu_sof_mis_match_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "ets_rd_int_rx_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "ets_wr_int_rx_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "ets_rd_int_tx_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "ets_wr_int_tx_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
S
Shiju Jose 已提交
533 534 535 536
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ssu_fifo_overflow_int[] = {
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
	{ .int_msk = BIT(0), .msg = "ig_mac_inf_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "ig_host_inf_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "ig_roc_buf_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "ig_host_data_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(4), .msg = "ig_host_key_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(5), .msg = "tx_qcn_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(6), .msg = "rx_qcn_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(7), .msg = "tx_pf_rd_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(8), .msg = "rx_pf_rd_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "qm_eof_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(10), .msg = "mb_rlt_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(11), .msg = "dup_uncopy_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(12), .msg = "dup_cnt_rd_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(13), .msg = "dup_cnt_drop_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(14), .msg = "dup_cnt_wrb_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(15), .msg = "host_cmd_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(16), .msg = "mac_cmd_fifo_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(17), .msg = "host_cmd_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(18), .msg = "mac_cmd_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(19), .msg = "dup_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(20), .msg = "out_queue_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(21), .msg = "bank2_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(22), .msg = "bank1_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(23), .msg = "bank0_bitmap_empty_int",
	  .reset_level = HNAE3_GLOBAL_RESET },
S
Shiju Jose 已提交
585 586 587 588
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ssu_ets_tcg_int[] = {
589 590 591 592 593 594 595 596
	{ .int_msk = BIT(0), .msg = "ets_rd_int_rx_tcg",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(1), .msg = "ets_wr_int_rx_tcg",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(2), .msg = "ets_rd_int_tx_tcg",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(3), .msg = "ets_wr_int_tx_tcg",
	  .reset_level = HNAE3_GLOBAL_RESET },
S
Shiju Jose 已提交
597 598 599 600
	{ /* sentinel */ }
};

static const struct hclge_hw_error hclge_ssu_port_based_pf_int[] = {
601 602 603 604 605 606
	{ .int_msk = BIT(0), .msg = "roc_pkt_without_key_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
	{ .int_msk = BIT(9), .msg = "low_water_line_err_port",
	  .reset_level = HNAE3_NONE_RESET },
	{ .int_msk = BIT(10), .msg = "hi_water_line_err_port",
	  .reset_level = HNAE3_GLOBAL_RESET },
S
Shiju Jose 已提交
607 608 609
	{ /* sentinel */ }
};

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
static const struct hclge_hw_error hclge_rocee_qmm_ovf_err_int[] = {
	{ .int_msk = 0, .msg = "rocee qmm ovf: sgid invalid err" },
	{ .int_msk = 0x4, .msg = "rocee qmm ovf: sgid ovf err" },
	{ .int_msk = 0x8, .msg = "rocee qmm ovf: smac invalid err" },
	{ .int_msk = 0xC, .msg = "rocee qmm ovf: smac ovf err" },
	{ .int_msk = 0x10, .msg = "rocee qmm ovf: cqc invalid err" },
	{ .int_msk = 0x11, .msg = "rocee qmm ovf: cqc ovf err" },
	{ .int_msk = 0x12, .msg = "rocee qmm ovf: cqc hopnum err" },
	{ .int_msk = 0x13, .msg = "rocee qmm ovf: cqc ba0 err" },
	{ .int_msk = 0x14, .msg = "rocee qmm ovf: srqc invalid err" },
	{ .int_msk = 0x15, .msg = "rocee qmm ovf: srqc ovf err" },
	{ .int_msk = 0x16, .msg = "rocee qmm ovf: srqc hopnum err" },
	{ .int_msk = 0x17, .msg = "rocee qmm ovf: srqc ba0 err" },
	{ .int_msk = 0x18, .msg = "rocee qmm ovf: mpt invalid err" },
	{ .int_msk = 0x19, .msg = "rocee qmm ovf: mpt ovf err" },
	{ .int_msk = 0x1A, .msg = "rocee qmm ovf: mpt hopnum err" },
	{ .int_msk = 0x1B, .msg = "rocee qmm ovf: mpt ba0 err" },
	{ .int_msk = 0x1C, .msg = "rocee qmm ovf: qpc invalid err" },
	{ .int_msk = 0x1D, .msg = "rocee qmm ovf: qpc ovf err" },
	{ .int_msk = 0x1E, .msg = "rocee qmm ovf: qpc hopnum err" },
	{ .int_msk = 0x1F, .msg = "rocee qmm ovf: qpc ba0 err" },
	{ /* sentinel */ }
};

634 635 636
static enum hnae3_reset_type hclge_log_error(struct device *dev, char *reg,
					     const struct hclge_hw_error *err,
					     u32 err_sts)
637
{
638 639 640
	enum hnae3_reset_type reset_level = HNAE3_FUNC_RESET;
	bool need_reset = false;

641
	while (err->msg) {
642
		if (err->int_msk & err_sts) {
643 644
			dev_warn(dev, "%s %s found [error status=0x%x]\n",
				 reg, err->msg, err_sts);
645 646 647 648 649 650
			if (err->reset_level != HNAE3_NONE_RESET &&
			    err->reset_level >= reset_level) {
				reset_level = err->reset_level;
				need_reset = true;
			}
		}
651 652
		err++;
	}
653 654 655 656
	if (need_reset)
		return reset_level;
	else
		return HNAE3_NONE_RESET;
657 658
}

659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
/* hclge_cmd_query_error: read the error information
 * @hdev: pointer to struct hclge_dev
 * @desc: descriptor for describing the command
 * @cmd:  command opcode
 * @flag: flag for extended command structure
 * @w_num: offset for setting the read interrupt type.
 * @int_type: select which type of the interrupt for which the error
 * info will be read(RAS-CE/RAS-NFE/RAS-FE etc).
 *
 * This function query the error info from hw register/s using command
 */
static int hclge_cmd_query_error(struct hclge_dev *hdev,
				 struct hclge_desc *desc, u32 cmd,
				 u16 flag, u8 w_num,
				 enum hclge_err_int_type int_type)
{
	struct device *dev = &hdev->pdev->dev;
676
	int desc_num = 1;
677 678 679 680 681 682
	int ret;

	hclge_cmd_setup_basic_desc(&desc[0], cmd, true);
	if (flag) {
		desc[0].flag |= cpu_to_le16(flag);
		hclge_cmd_setup_basic_desc(&desc[1], cmd, true);
683
		desc_num = 2;
684 685 686 687
	}
	if (w_num)
		desc[0].data[w_num] = cpu_to_le32(int_type);

688
	ret = hclge_cmd_send(&hdev->hw, &desc[0], desc_num);
689 690 691 692 693 694
	if (ret)
		dev_err(dev, "query error cmd failed (%d)\n", ret);

	return ret;
}

695 696 697 698 699 700 701 702 703 704
static int hclge_clear_mac_tnl_int(struct hclge_dev *hdev)
{
	struct hclge_desc desc;

	hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CLEAR_MAC_TNL_INT, false);
	desc.data[0] = cpu_to_le32(HCLGE_MAC_TNL_INT_CLR);

	return hclge_cmd_send(&hdev->hw, &desc, 1);
}

705
static int hclge_config_common_hw_err_int(struct hclge_dev *hdev, bool en)
706 707 708 709 710
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	int ret;

711
	/* configure common error interrupts */
712 713 714 715 716 717 718 719 720
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_COMMON_ECC_INT_CFG, false);
	desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
	hclge_cmd_setup_basic_desc(&desc[1], HCLGE_COMMON_ECC_INT_CFG, false);

	if (en) {
		desc[0].data[0] = cpu_to_le32(HCLGE_IMP_TCM_ECC_ERR_INT_EN);
		desc[0].data[2] = cpu_to_le32(HCLGE_CMDQ_NIC_ECC_ERR_INT_EN |
					HCLGE_CMDQ_ROCEE_ECC_ERR_INT_EN);
		desc[0].data[3] = cpu_to_le32(HCLGE_IMP_RD_POISON_ERR_INT_EN);
721 722
		desc[0].data[4] = cpu_to_le32(HCLGE_TQP_ECC_ERR_INT_EN |
					      HCLGE_MSIX_SRAM_ECC_ERR_INT_EN);
723 724
		desc[0].data[5] = cpu_to_le32(HCLGE_IMP_ITCM4_ECC_ERR_INT_EN);
	}
725

726 727 728 729
	desc[1].data[0] = cpu_to_le32(HCLGE_IMP_TCM_ECC_ERR_INT_EN_MASK);
	desc[1].data[2] = cpu_to_le32(HCLGE_CMDQ_NIC_ECC_ERR_INT_EN_MASK |
				HCLGE_CMDQ_ROCEE_ECC_ERR_INT_EN_MASK);
	desc[1].data[3] = cpu_to_le32(HCLGE_IMP_RD_POISON_ERR_INT_EN_MASK);
730 731
	desc[1].data[4] = cpu_to_le32(HCLGE_TQP_ECC_ERR_INT_EN_MASK |
				      HCLGE_MSIX_SRAM_ECC_ERR_INT_EN_MASK);
732 733 734 735 736
	desc[1].data[5] = cpu_to_le32(HCLGE_IMP_ITCM4_ECC_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc[0], 2);
	if (ret)
		dev_err(dev,
737
			"fail(%d) to configure common err interrupts\n", ret);
738 739 740 741

	return ret;
}

742
static int hclge_config_ncsi_hw_err_int(struct hclge_dev *hdev, bool en)
743 744 745 746 747 748 749 750
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc;
	int ret;

	if (hdev->pdev->revision < 0x21)
		return 0;

751
	/* configure NCSI error interrupts */
752 753 754 755 756 757 758
	hclge_cmd_setup_basic_desc(&desc, HCLGE_NCSI_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_NCSI_ERR_INT_EN);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret)
		dev_err(dev,
759
			"fail(%d) to configure  NCSI error interrupts\n", ret);
760 761 762 763

	return ret;
}

764
static int hclge_config_igu_egu_hw_err_int(struct hclge_dev *hdev, bool en)
765 766 767 768 769
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc;
	int ret;

770
	/* configure IGU,EGU error interrupts */
771 772 773
	hclge_cmd_setup_basic_desc(&desc, HCLGE_IGU_COMMON_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_IGU_ERR_INT_EN);
774

775 776 777 778 779
	desc.data[1] = cpu_to_le32(HCLGE_IGU_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret) {
		dev_err(dev,
780
			"fail(%d) to configure IGU common interrupts\n", ret);
781 782 783 784 785 786
		return ret;
	}

	hclge_cmd_setup_basic_desc(&desc, HCLGE_IGU_EGU_TNL_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_IGU_TNL_ERR_INT_EN);
787

788 789 790 791 792
	desc.data[1] = cpu_to_le32(HCLGE_IGU_TNL_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret) {
		dev_err(dev,
793
			"fail(%d) to configure IGU-EGU TNL interrupts\n", ret);
794 795 796
		return ret;
	}

797
	ret = hclge_config_ncsi_hw_err_int(hdev, en);
798 799 800 801

	return ret;
}

802
static int hclge_config_ppp_error_interrupt(struct hclge_dev *hdev, u32 cmd,
803 804 805 806 807 808
					    bool en)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	int ret;

809
	/* configure PPP error interrupts */
810 811 812 813 814 815 816 817 818 819
	hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
	desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
	hclge_cmd_setup_basic_desc(&desc[1], cmd, false);

	if (cmd == HCLGE_PPP_CMD0_INT_CMD) {
		if (en) {
			desc[0].data[0] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN);
			desc[0].data[1] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN);
S
Shiju Jose 已提交
820
			desc[0].data[4] = cpu_to_le32(HCLGE_PPP_PF_ERR_INT_EN);
821
		}
822

823 824 825 826
		desc[1].data[0] =
			cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN_MASK);
		desc[1].data[1] =
			cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN_MASK);
S
Shiju Jose 已提交
827 828 829
		if (hdev->pdev->revision >= 0x21)
			desc[1].data[2] =
				cpu_to_le32(HCLGE_PPP_PF_ERR_INT_EN_MASK);
830 831 832 833 834 835 836
	} else if (cmd == HCLGE_PPP_CMD1_INT_CMD) {
		if (en) {
			desc[0].data[0] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT2_EN);
			desc[0].data[1] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT3_EN);
		}
837

838 839 840 841 842 843 844 845
		desc[1].data[0] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT2_EN_MASK);
		desc[1].data[1] =
				cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT3_EN_MASK);
	}

	ret = hclge_cmd_send(&hdev->hw, &desc[0], 2);
	if (ret)
846
		dev_err(dev, "fail(%d) to configure PPP error intr\n", ret);
847 848 849 850

	return ret;
}

851
static int hclge_config_ppp_hw_err_int(struct hclge_dev *hdev, bool en)
852 853 854
{
	int ret;

855
	ret = hclge_config_ppp_error_interrupt(hdev, HCLGE_PPP_CMD0_INT_CMD,
856
					       en);
857
	if (ret)
858 859
		return ret;

860
	ret = hclge_config_ppp_error_interrupt(hdev, HCLGE_PPP_CMD1_INT_CMD,
861 862 863 864 865
					       en);

	return ret;
}

866
static int hclge_config_tm_hw_err_int(struct hclge_dev *hdev, bool en)
867 868 869 870 871
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc;
	int ret;

872
	/* configure TM SCH hw errors */
873 874 875 876 877 878
	hclge_cmd_setup_basic_desc(&desc, HCLGE_TM_SCH_ECC_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_TM_SCH_ECC_ERR_INT_EN);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret) {
879
		dev_err(dev, "fail(%d) to configure TM SCH errors\n", ret);
880 881 882
		return ret;
	}

883
	/* configure TM QCN hw errors */
884 885 886
	ret = hclge_cmd_query_error(hdev, &desc, HCLGE_TM_QCN_MEM_INT_CFG,
				    0, 0, 0);
	if (ret) {
887
		dev_err(dev, "fail(%d) to read TM QCN CFG status\n", ret);
888 889 890 891 892 893 894 895 896 897
		return ret;
	}

	hclge_cmd_reuse_desc(&desc, false);
	if (en)
		desc.data[1] = cpu_to_le32(HCLGE_TM_QCN_MEM_ERR_INT_EN);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret)
		dev_err(dev,
898
			"fail(%d) to configure TM QCN mem errors\n", ret);
899 900 901 902

	return ret;
}

903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
static int hclge_config_mac_err_int(struct hclge_dev *hdev, bool en)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc;
	int ret;

	/* configure MAC common error interrupts */
	hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_COMMON_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_MAC_COMMON_ERR_INT_EN);

	desc.data[1] = cpu_to_le32(HCLGE_MAC_COMMON_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret)
		dev_err(dev,
			"fail(%d) to configure MAC COMMON error intr\n", ret);

	return ret;
}

924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
int hclge_config_mac_tnl_int(struct hclge_dev *hdev, bool en)
{
	struct hclge_desc desc;

	hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_TNL_INT_EN, false);
	if (en)
		desc.data[0] = cpu_to_le32(HCLGE_MAC_TNL_INT_EN);
	else
		desc.data[0] = 0;

	desc.data[1] = cpu_to_le32(HCLGE_MAC_TNL_INT_EN_MASK);

	return hclge_cmd_send(&hdev->hw, &desc, 1);
}

939 940 941 942 943
static int hclge_config_ppu_error_interrupts(struct hclge_dev *hdev, u32 cmd,
					     bool en)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
944
	int desc_num = 1;
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
	int ret;

	/* configure PPU error interrupts */
	if (cmd == HCLGE_PPU_MPF_ECC_INT_CMD) {
		hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
		desc[0].flag |= HCLGE_CMD_FLAG_NEXT;
		hclge_cmd_setup_basic_desc(&desc[1], cmd, false);
		if (en) {
			desc[0].data[0] = HCLGE_PPU_MPF_ABNORMAL_INT0_EN;
			desc[0].data[1] = HCLGE_PPU_MPF_ABNORMAL_INT1_EN;
			desc[1].data[3] = HCLGE_PPU_MPF_ABNORMAL_INT3_EN;
			desc[1].data[4] = HCLGE_PPU_MPF_ABNORMAL_INT2_EN;
		}

		desc[1].data[0] = HCLGE_PPU_MPF_ABNORMAL_INT0_EN_MASK;
		desc[1].data[1] = HCLGE_PPU_MPF_ABNORMAL_INT1_EN_MASK;
		desc[1].data[2] = HCLGE_PPU_MPF_ABNORMAL_INT2_EN_MASK;
		desc[1].data[3] |= HCLGE_PPU_MPF_ABNORMAL_INT3_EN_MASK;
963
		desc_num = 2;
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
	} else if (cmd == HCLGE_PPU_MPF_OTHER_INT_CMD) {
		hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
		if (en)
			desc[0].data[0] = HCLGE_PPU_MPF_ABNORMAL_INT2_EN2;

		desc[0].data[2] = HCLGE_PPU_MPF_ABNORMAL_INT2_EN2_MASK;
	} else if (cmd == HCLGE_PPU_PF_OTHER_INT_CMD) {
		hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
		if (en)
			desc[0].data[0] = HCLGE_PPU_PF_ABNORMAL_INT_EN;

		desc[0].data[2] = HCLGE_PPU_PF_ABNORMAL_INT_EN_MASK;
	} else {
		dev_err(dev, "Invalid cmd to configure PPU error interrupts\n");
		return -EINVAL;
	}

981
	ret = hclge_cmd_send(&hdev->hw, &desc[0], desc_num);
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014

	return ret;
}

static int hclge_config_ppu_hw_err_int(struct hclge_dev *hdev, bool en)
{
	struct device *dev = &hdev->pdev->dev;
	int ret;

	ret = hclge_config_ppu_error_interrupts(hdev, HCLGE_PPU_MPF_ECC_INT_CMD,
						en);
	if (ret) {
		dev_err(dev, "fail(%d) to configure PPU MPF ECC error intr\n",
			ret);
		return ret;
	}

	ret = hclge_config_ppu_error_interrupts(hdev,
						HCLGE_PPU_MPF_OTHER_INT_CMD,
						en);
	if (ret) {
		dev_err(dev, "fail(%d) to configure PPU MPF other intr\n", ret);
		return ret;
	}

	ret = hclge_config_ppu_error_interrupts(hdev,
						HCLGE_PPU_PF_OTHER_INT_CMD, en);
	if (ret)
		dev_err(dev, "fail(%d) to configure PPU PF error interrupts\n",
			ret);
	return ret;
}

S
Shiju Jose 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
static int hclge_config_ssu_hw_err_int(struct hclge_dev *hdev, bool en)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	int ret;

	/* configure SSU ecc error interrupts */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_SSU_ECC_INT_CMD, false);
	desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
	hclge_cmd_setup_basic_desc(&desc[1], HCLGE_SSU_ECC_INT_CMD, false);
	if (en) {
		desc[0].data[0] = cpu_to_le32(HCLGE_SSU_1BIT_ECC_ERR_INT_EN);
		desc[0].data[1] =
			cpu_to_le32(HCLGE_SSU_MULTI_BIT_ECC_ERR_INT_EN);
		desc[0].data[4] = cpu_to_le32(HCLGE_SSU_BIT32_ECC_ERR_INT_EN);
	}

	desc[1].data[0] = cpu_to_le32(HCLGE_SSU_1BIT_ECC_ERR_INT_EN_MASK);
	desc[1].data[1] = cpu_to_le32(HCLGE_SSU_MULTI_BIT_ECC_ERR_INT_EN_MASK);
	desc[1].data[2] = cpu_to_le32(HCLGE_SSU_BIT32_ECC_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc[0], 2);
	if (ret) {
		dev_err(dev,
			"fail(%d) to configure SSU ECC error interrupt\n", ret);
		return ret;
	}

	/* configure SSU common error interrupts */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_SSU_COMMON_INT_CMD, false);
	desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
	hclge_cmd_setup_basic_desc(&desc[1], HCLGE_SSU_COMMON_INT_CMD, false);

	if (en) {
		if (hdev->pdev->revision >= 0x21)
			desc[0].data[0] =
				cpu_to_le32(HCLGE_SSU_COMMON_INT_EN);
		else
			desc[0].data[0] =
				cpu_to_le32(HCLGE_SSU_COMMON_INT_EN & ~BIT(5));
		desc[0].data[1] = cpu_to_le32(HCLGE_SSU_PORT_BASED_ERR_INT_EN);
		desc[0].data[2] =
			cpu_to_le32(HCLGE_SSU_FIFO_OVERFLOW_ERR_INT_EN);
	}

	desc[1].data[0] = cpu_to_le32(HCLGE_SSU_COMMON_INT_EN_MASK |
				HCLGE_SSU_PORT_BASED_ERR_INT_EN_MASK);
	desc[1].data[1] = cpu_to_le32(HCLGE_SSU_FIFO_OVERFLOW_ERR_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc[0], 2);
	if (ret)
		dev_err(dev,
			"fail(%d) to configure SSU COMMON error intr\n", ret);

	return ret;
}

1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
#define HCLGE_SET_DEFAULT_RESET_REQUEST(reset_type) \
	do { \
		if (ae_dev->ops->set_default_reset_request) \
			ae_dev->ops->set_default_reset_request(ae_dev, \
							       reset_type); \
	} while (0)

/* hclge_handle_mpf_ras_error: handle all main PF RAS errors
 * @hdev: pointer to struct hclge_dev
 * @desc: descriptor for describing the command
 * @num:  number of extended command structures
 *
 * This function handles all the main PF RAS errors in the
 * hw register/s using command.
 */
static int hclge_handle_mpf_ras_error(struct hclge_dev *hdev,
				      struct hclge_desc *desc,
				      int num)
{
	struct hnae3_ae_dev *ae_dev = hdev->ae_dev;
1092
	enum hnae3_reset_type reset_level;
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
	struct device *dev = &hdev->pdev->dev;
	__le32 *desc_data;
	u32 status;
	int ret;

	/* query all main PF RAS errors */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_CLEAR_MPF_RAS_INT,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], num);
	if (ret) {
		dev_err(dev, "query all mpf ras int cmd failed (%d)\n", ret);
		return ret;
	}

	/* log HNS common errors */
	status = le32_to_cpu(desc[0].data[0]);
	if (status) {
1110 1111 1112 1113
		reset_level = hclge_log_error(dev, "IMP_TCM_ECC_INT_STS",
					      &hclge_imp_tcm_ecc_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1114 1115 1116 1117
	}

	status = le32_to_cpu(desc[0].data[1]);
	if (status) {
1118 1119 1120 1121
		reset_level = hclge_log_error(dev, "CMDQ_MEM_ECC_INT_STS",
					      &hclge_cmdq_nic_mem_ecc_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1122 1123 1124 1125
	}

	if ((le32_to_cpu(desc[0].data[2])) & BIT(0)) {
		dev_warn(dev, "imp_rd_data_poison_err found\n");
1126
		HCLGE_SET_DEFAULT_RESET_REQUEST(HNAE3_NONE_RESET);
1127 1128 1129 1130
	}

	status = le32_to_cpu(desc[0].data[3]);
	if (status) {
1131 1132 1133 1134
		reset_level = hclge_log_error(dev, "TQP_INT_ECC_INT_STS",
					      &hclge_tqp_int_ecc_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1135 1136 1137 1138
	}

	status = le32_to_cpu(desc[0].data[4]);
	if (status) {
1139 1140 1141 1142
		reset_level = hclge_log_error(dev, "MSIX_ECC_INT_STS",
					      &hclge_msix_sram_ecc_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1143 1144
	}

S
Shiju Jose 已提交
1145 1146 1147 1148
	/* log SSU(Storage Switch Unit) errors */
	desc_data = (__le32 *)&desc[2];
	status = le32_to_cpu(*(desc_data + 2));
	if (status) {
1149 1150 1151 1152
		reset_level = hclge_log_error(dev, "SSU_ECC_MULTI_BIT_INT_0",
					      &hclge_ssu_mem_ecc_err_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
S
Shiju Jose 已提交
1153 1154 1155 1156
	}

	status = le32_to_cpu(*(desc_data + 3)) & BIT(0);
	if (status) {
1157 1158
		dev_warn(dev, "SSU_ECC_MULTI_BIT_INT_1 ssu_mem32_ecc_mbit_err found [error status=0x%x]\n",
			 status);
1159
		HCLGE_SET_DEFAULT_RESET_REQUEST(HNAE3_GLOBAL_RESET);
S
Shiju Jose 已提交
1160 1161 1162 1163
	}

	status = le32_to_cpu(*(desc_data + 4)) & HCLGE_SSU_COMMON_ERR_INT_MASK;
	if (status) {
1164 1165 1166 1167
		reset_level = hclge_log_error(dev, "SSU_COMMON_ERR_INT",
					      &hclge_ssu_com_err_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
S
Shiju Jose 已提交
1168 1169
	}

1170 1171 1172
	/* log IGU(Ingress Unit) errors */
	desc_data = (__le32 *)&desc[3];
	status = le32_to_cpu(*desc_data) & HCLGE_IGU_INT_MASK;
1173 1174 1175 1176 1177
	if (status) {
		reset_level = hclge_log_error(dev, "IGU_INT_STS",
					      &hclge_igu_int[0], status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
	}
1178 1179 1180 1181

	/* log PPP(Programmable Packet Process) errors */
	desc_data = (__le32 *)&desc[4];
	status = le32_to_cpu(*(desc_data + 1));
1182 1183 1184 1185 1186 1187 1188
	if (status) {
		reset_level =
			hclge_log_error(dev, "PPP_MPF_ABNORMAL_INT_ST1",
					&hclge_ppp_mpf_abnormal_int_st1[0],
					status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
	}
1189 1190

	status = le32_to_cpu(*(desc_data + 3)) & HCLGE_PPP_MPF_INT_ST3_MASK;
1191 1192 1193 1194 1195 1196 1197
	if (status) {
		reset_level =
			hclge_log_error(dev, "PPP_MPF_ABNORMAL_INT_ST3",
					&hclge_ppp_mpf_abnormal_int_st3[0],
					status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
	}
1198

1199 1200 1201 1202 1203 1204
	/* log PPU(RCB) errors */
	desc_data = (__le32 *)&desc[5];
	status = le32_to_cpu(*(desc_data + 1));
	if (status) {
		dev_warn(dev, "PPU_MPF_ABNORMAL_INT_ST1 %s found\n",
			 "rpu_rx_pkt_ecc_mbit_err");
1205
		HCLGE_SET_DEFAULT_RESET_REQUEST(HNAE3_GLOBAL_RESET);
1206 1207 1208 1209
	}

	status = le32_to_cpu(*(desc_data + 2));
	if (status) {
1210 1211 1212 1213 1214
		reset_level =
			hclge_log_error(dev, "PPU_MPF_ABNORMAL_INT_ST2",
					&hclge_ppu_mpf_abnormal_int_st2[0],
					status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1215 1216 1217 1218
	}

	status = le32_to_cpu(*(desc_data + 3)) & HCLGE_PPU_MPF_INT_ST3_MASK;
	if (status) {
1219 1220 1221 1222 1223
		reset_level =
			hclge_log_error(dev, "PPU_MPF_ABNORMAL_INT_ST3",
					&hclge_ppu_mpf_abnormal_int_st3[0],
					status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1224 1225
	}

1226 1227 1228 1229
	/* log TM(Traffic Manager) errors */
	desc_data = (__le32 *)&desc[6];
	status = le32_to_cpu(*desc_data);
	if (status) {
1230 1231 1232
		reset_level = hclge_log_error(dev, "TM_SCH_RINT",
					      &hclge_tm_sch_rint[0], status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1233 1234 1235 1236 1237 1238
	}

	/* log QCN(Quantized Congestion Control) errors */
	desc_data = (__le32 *)&desc[7];
	status = le32_to_cpu(*desc_data) & HCLGE_QCN_FIFO_INT_MASK;
	if (status) {
1239 1240 1241
		reset_level = hclge_log_error(dev, "QCN_FIFO_RINT",
					      &hclge_qcn_fifo_rint[0], status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1242 1243 1244 1245
	}

	status = le32_to_cpu(*(desc_data + 1)) & HCLGE_QCN_ECC_INT_MASK;
	if (status) {
1246 1247 1248 1249
		reset_level = hclge_log_error(dev, "QCN_ECC_RINT",
					      &hclge_qcn_ecc_rint[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1250 1251 1252 1253 1254 1255
	}

	/* log NCSI errors */
	desc_data = (__le32 *)&desc[9];
	status = le32_to_cpu(*desc_data) & HCLGE_NCSI_ECC_INT_MASK;
	if (status) {
1256 1257 1258
		reset_level = hclge_log_error(dev, "NCSI_ECC_INT_RPT",
					      &hclge_ncsi_err_int[0], status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
	}

	/* clear all main PF RAS errors */
	hclge_cmd_reuse_desc(&desc[0], false);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], num);
	if (ret)
		dev_err(dev, "clear all mpf ras int cmd failed (%d)\n", ret);

	return ret;
}

/* hclge_handle_pf_ras_error: handle all PF RAS errors
 * @hdev: pointer to struct hclge_dev
 * @desc: descriptor for describing the command
 * @num:  number of extended command structures
 *
 * This function handles all the PF RAS errors in the
 * hw register/s using command.
 */
static int hclge_handle_pf_ras_error(struct hclge_dev *hdev,
				     struct hclge_desc *desc,
				     int num)
{
S
Shiju Jose 已提交
1282
	struct hnae3_ae_dev *ae_dev = hdev->ae_dev;
1283
	struct device *dev = &hdev->pdev->dev;
1284
	enum hnae3_reset_type reset_level;
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
	__le32 *desc_data;
	u32 status;
	int ret;

	/* query all PF RAS errors */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_CLEAR_PF_RAS_INT,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], num);
	if (ret) {
		dev_err(dev, "query all pf ras int cmd failed (%d)\n", ret);
		return ret;
	}

S
Shiju Jose 已提交
1298 1299 1300
	/* log SSU(Storage Switch Unit) errors */
	status = le32_to_cpu(desc[0].data[0]);
	if (status) {
1301 1302 1303 1304
		reset_level = hclge_log_error(dev, "SSU_PORT_BASED_ERR_INT",
					      &hclge_ssu_port_based_err_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
S
Shiju Jose 已提交
1305 1306 1307 1308
	}

	status = le32_to_cpu(desc[0].data[1]);
	if (status) {
1309 1310 1311 1312
		reset_level = hclge_log_error(dev, "SSU_FIFO_OVERFLOW_INT",
					      &hclge_ssu_fifo_overflow_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
S
Shiju Jose 已提交
1313 1314 1315 1316
	}

	status = le32_to_cpu(desc[0].data[2]);
	if (status) {
1317 1318 1319 1320
		reset_level = hclge_log_error(dev, "SSU_ETS_TCG_INT",
					      &hclge_ssu_ets_tcg_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
S
Shiju Jose 已提交
1321 1322
	}

1323 1324 1325
	/* log IGU(Ingress Unit) EGU(Egress Unit) TNL errors */
	desc_data = (__le32 *)&desc[1];
	status = le32_to_cpu(*desc_data) & HCLGE_IGU_EGU_TNL_INT_MASK;
1326 1327 1328 1329 1330 1331
	if (status) {
		reset_level = hclge_log_error(dev, "IGU_EGU_TNL_INT_STS",
					      &hclge_igu_egu_tnl_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
	}
1332

1333 1334 1335
	/* log PPU(RCB) errors */
	desc_data = (__le32 *)&desc[3];
	status = le32_to_cpu(*desc_data) & HCLGE_PPU_PF_INT_RAS_MASK;
1336 1337 1338 1339 1340 1341
	if (status) {
		reset_level = hclge_log_error(dev, "PPU_PF_ABNORMAL_INT_ST0",
					      &hclge_ppu_pf_abnormal_int[0],
					      status);
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_level);
	}
1342

1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
	/* clear all PF RAS errors */
	hclge_cmd_reuse_desc(&desc[0], false);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], num);
	if (ret)
		dev_err(dev, "clear all pf ras int cmd failed (%d)\n", ret);

	return ret;
}

static int hclge_handle_all_ras_errors(struct hclge_dev *hdev)
{
	struct device *dev = &hdev->pdev->dev;
	u32 mpf_bd_num, pf_bd_num, bd_num;
	struct hclge_desc desc_bd;
	struct hclge_desc *desc;
	int ret;

	/* query the number of registers in the RAS int status */
	hclge_cmd_setup_basic_desc(&desc_bd, HCLGE_QUERY_RAS_INT_STS_BD_NUM,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc_bd, 1);
	if (ret) {
		dev_err(dev, "fail(%d) to query ras int status bd num\n", ret);
		return ret;
	}
	mpf_bd_num = le32_to_cpu(desc_bd.data[0]);
	pf_bd_num = le32_to_cpu(desc_bd.data[1]);
	bd_num = max_t(u32, mpf_bd_num, pf_bd_num);

	desc = kcalloc(bd_num, sizeof(struct hclge_desc), GFP_KERNEL);
	if (!desc)
		return -ENOMEM;

	/* handle all main PF RAS errors */
	ret = hclge_handle_mpf_ras_error(hdev, desc, mpf_bd_num);
	if (ret) {
		kfree(desc);
		return ret;
	}
	memset(desc, 0, bd_num * sizeof(struct hclge_desc));

	/* handle all PF RAS errors */
	ret = hclge_handle_pf_ras_error(hdev, desc, pf_bd_num);
	kfree(desc);

	return ret;
}

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
static int hclge_log_rocee_axi_error(struct hclge_dev *hdev)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[3];
	int ret;

	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_ROCEE_AXI_RAS_INFO_CMD,
				   true);
	hclge_cmd_setup_basic_desc(&desc[1], HCLGE_QUERY_ROCEE_AXI_RAS_INFO_CMD,
				   true);
	hclge_cmd_setup_basic_desc(&desc[2], HCLGE_QUERY_ROCEE_AXI_RAS_INFO_CMD,
				   true);
	desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
	desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);

	ret = hclge_cmd_send(&hdev->hw, &desc[0], 3);
	if (ret) {
		dev_err(dev, "failed(%d) to query ROCEE AXI error sts\n", ret);
		return ret;
	}

	dev_info(dev, "AXI1: %08X %08X %08X %08X %08X %08X\n",
		 le32_to_cpu(desc[0].data[0]), le32_to_cpu(desc[0].data[1]),
		 le32_to_cpu(desc[0].data[2]), le32_to_cpu(desc[0].data[3]),
		 le32_to_cpu(desc[0].data[4]), le32_to_cpu(desc[0].data[5]));
	dev_info(dev, "AXI2: %08X %08X %08X %08X %08X %08X\n",
		 le32_to_cpu(desc[1].data[0]), le32_to_cpu(desc[1].data[1]),
		 le32_to_cpu(desc[1].data[2]), le32_to_cpu(desc[1].data[3]),
		 le32_to_cpu(desc[1].data[4]), le32_to_cpu(desc[1].data[5]));
	dev_info(dev, "AXI3: %08X %08X %08X %08X\n",
		 le32_to_cpu(desc[2].data[0]), le32_to_cpu(desc[2].data[1]),
		 le32_to_cpu(desc[2].data[2]), le32_to_cpu(desc[2].data[3]));

	return 0;
}

static int hclge_log_rocee_ecc_error(struct hclge_dev *hdev)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	int ret;

	ret = hclge_cmd_query_error(hdev, &desc[0],
				    HCLGE_QUERY_ROCEE_ECC_RAS_INFO_CMD,
				    HCLGE_CMD_FLAG_NEXT, 0, 0);
	if (ret) {
		dev_err(dev, "failed(%d) to query ROCEE ECC error sts\n", ret);
		return ret;
	}

	dev_info(dev, "ECC1: %08X %08X %08X %08X %08X %08X\n",
		 le32_to_cpu(desc[0].data[0]), le32_to_cpu(desc[0].data[1]),
		 le32_to_cpu(desc[0].data[2]), le32_to_cpu(desc[0].data[3]),
		 le32_to_cpu(desc[0].data[4]), le32_to_cpu(desc[0].data[5]));
	dev_info(dev, "ECC2: %08X %08X %08X\n", le32_to_cpu(desc[1].data[0]),
		 le32_to_cpu(desc[1].data[1]), le32_to_cpu(desc[1].data[2]));

	return 0;
}

1451 1452 1453 1454 1455 1456 1457
static int hclge_log_rocee_ovf_error(struct hclge_dev *hdev)
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	int ret;

	/* read overflow error status */
1458
	ret = hclge_cmd_query_error(hdev, &desc[0], HCLGE_ROCEE_PF_RAS_INT_CMD,
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
				    0, 0, 0);
	if (ret) {
		dev_err(dev, "failed(%d) to query ROCEE OVF error sts\n", ret);
		return ret;
	}

	/* log overflow error */
	if (le32_to_cpu(desc[0].data[0]) & HCLGE_ROCEE_OVF_ERR_INT_MASK) {
		const struct hclge_hw_error *err;
		u32 err_sts;

		err = &hclge_rocee_qmm_ovf_err_int[0];
		err_sts = HCLGE_ROCEE_OVF_ERR_TYPE_MASK &
			  le32_to_cpu(desc[0].data[0]);
		while (err->msg) {
			if (err->int_msk == err_sts) {
				dev_warn(dev, "%s [error status=0x%x] found\n",
					 err->msg,
					 le32_to_cpu(desc[0].data[0]));
				break;
			}
			err++;
		}
	}

	if (le32_to_cpu(desc[0].data[1]) & HCLGE_ROCEE_OVF_ERR_INT_MASK) {
		dev_warn(dev, "ROCEE TSP OVF [error status=0x%x] found\n",
			 le32_to_cpu(desc[0].data[1]));
	}

	if (le32_to_cpu(desc[0].data[2]) & HCLGE_ROCEE_OVF_ERR_INT_MASK) {
		dev_warn(dev, "ROCEE SCC OVF [error status=0x%x] found\n",
			 le32_to_cpu(desc[0].data[2]));
	}

	return 0;
}

1497 1498
static enum hnae3_reset_type
hclge_log_and_clear_rocee_ras_error(struct hclge_dev *hdev)
1499
{
1500
	enum hnae3_reset_type reset_type = HNAE3_NONE_RESET;
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc[2];
	unsigned int status;
	int ret;

	/* read RAS error interrupt status */
	ret = hclge_cmd_query_error(hdev, &desc[0],
				    HCLGE_QUERY_CLEAR_ROCEE_RAS_INT,
				    0, 0, 0);
	if (ret) {
		dev_err(dev, "failed(%d) to query ROCEE RAS INT SRC\n", ret);
		/* reset everything for now */
1513
		return HNAE3_GLOBAL_RESET;
1514 1515 1516 1517
	}

	status = le32_to_cpu(desc[0].data[0]);

1518 1519 1520 1521 1522 1523
	if (status & HCLGE_ROCEE_AXI_ERR_INT_MASK) {
		if (status & HCLGE_ROCEE_RERR_INT_MASK)
			dev_warn(dev, "ROCEE RAS AXI rresp error\n");

		if (status & HCLGE_ROCEE_BERR_INT_MASK)
			dev_warn(dev, "ROCEE RAS AXI bresp error\n");
1524

1525
		reset_type = HNAE3_FUNC_RESET;
1526 1527 1528 1529

		ret = hclge_log_rocee_axi_error(hdev);
		if (ret)
			return HNAE3_GLOBAL_RESET;
1530
	}
1531 1532 1533 1534

	if (status & HCLGE_ROCEE_ECC_INT_MASK) {
		dev_warn(dev, "ROCEE RAS 2bit ECC error\n");
		reset_type = HNAE3_GLOBAL_RESET;
1535 1536 1537 1538

		ret = hclge_log_rocee_ecc_error(hdev);
		if (ret)
			return HNAE3_GLOBAL_RESET;
1539 1540 1541 1542 1543 1544 1545
	}

	if (status & HCLGE_ROCEE_OVF_INT_MASK) {
		ret = hclge_log_rocee_ovf_error(hdev);
		if (ret) {
			dev_err(dev, "failed(%d) to process ovf error\n", ret);
			/* reset everything for now */
1546
			return HNAE3_GLOBAL_RESET;
1547 1548 1549 1550 1551 1552 1553 1554 1555
		}
	}

	/* clear error status */
	hclge_cmd_reuse_desc(&desc[0], false);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], 1);
	if (ret) {
		dev_err(dev, "failed(%d) to clear ROCEE RAS error\n", ret);
		/* reset everything for now */
1556
		return HNAE3_GLOBAL_RESET;
1557 1558
	}

1559
	return reset_type;
1560 1561
}

1562
int hclge_config_rocee_ras_interrupt(struct hclge_dev *hdev, bool en)
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
{
	struct device *dev = &hdev->pdev->dev;
	struct hclge_desc desc;
	int ret;

	if (hdev->pdev->revision < 0x21 || !hnae3_dev_roce_supported(hdev))
		return 0;

	hclge_cmd_setup_basic_desc(&desc, HCLGE_CONFIG_ROCEE_RAS_INT_EN, false);
	if (en) {
		/* enable ROCEE hw error interrupts */
		desc.data[0] = cpu_to_le32(HCLGE_ROCEE_RAS_NFE_INT_EN);
		desc.data[1] = cpu_to_le32(HCLGE_ROCEE_RAS_CE_INT_EN);

		hclge_log_and_clear_rocee_ras_error(hdev);
	}
	desc.data[2] = cpu_to_le32(HCLGE_ROCEE_RAS_NFE_INT_EN_MASK);
	desc.data[3] = cpu_to_le32(HCLGE_ROCEE_RAS_CE_INT_EN_MASK);

	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret)
		dev_err(dev, "failed(%d) to config ROCEE RAS interrupt\n", ret);

	return ret;
}

1589
static void hclge_handle_rocee_ras_error(struct hnae3_ae_dev *ae_dev)
1590
{
1591
	enum hnae3_reset_type reset_type = HNAE3_NONE_RESET;
1592 1593 1594 1595
	struct hclge_dev *hdev = ae_dev->priv;

	if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) ||
	    hdev->pdev->revision < 0x21)
1596
		return;
1597

1598 1599 1600
	reset_type = hclge_log_and_clear_rocee_ras_error(hdev);
	if (reset_type != HNAE3_NONE_RESET)
		HCLGE_SET_DEFAULT_RESET_REQUEST(reset_type);
1601 1602
}

1603
static const struct hclge_hw_blk hw_blk[] = {
1604 1605
	{
	  .msk = BIT(0), .name = "IGU_EGU",
1606
	  .config_err_int = hclge_config_igu_egu_hw_err_int,
1607 1608 1609
	},
	{
	  .msk = BIT(1), .name = "PPP",
1610
	  .config_err_int = hclge_config_ppp_hw_err_int,
1611
	},
S
Shiju Jose 已提交
1612 1613 1614 1615
	{
	  .msk = BIT(2), .name = "SSU",
	  .config_err_int = hclge_config_ssu_hw_err_int,
	},
1616 1617 1618 1619
	{
	  .msk = BIT(3), .name = "PPU",
	  .config_err_int = hclge_config_ppu_hw_err_int,
	},
1620 1621
	{
	  .msk = BIT(4), .name = "TM",
1622
	  .config_err_int = hclge_config_tm_hw_err_int,
1623 1624 1625
	},
	{
	  .msk = BIT(5), .name = "COMMON",
1626
	  .config_err_int = hclge_config_common_hw_err_int,
1627
	},
1628 1629 1630 1631
	{
	  .msk = BIT(8), .name = "MAC",
	  .config_err_int = hclge_config_mac_err_int,
	},
1632 1633 1634
	{ /* sentinel */ }
};

1635
int hclge_config_nic_hw_error(struct hclge_dev *hdev, bool state)
1636
{
1637
	const struct hclge_hw_blk *module = hw_blk;
1638 1639
	int ret = 0;

1640 1641 1642 1643 1644
	while (module->name) {
		if (module->config_err_int) {
			ret = module->config_err_int(hdev, state);
			if (ret)
				return ret;
1645
		}
1646
		module++;
1647 1648 1649 1650 1651
	}

	return ret;
}

1652
pci_ers_result_t hclge_handle_hw_ras_error(struct hnae3_ae_dev *ae_dev)
1653 1654 1655
{
	struct hclge_dev *hdev = ae_dev->priv;
	struct device *dev = &hdev->pdev->dev;
1656
	u32 status;
1657

1658
	status = hclge_read_dev(&hdev->hw, HCLGE_RAS_PF_OTHER_INT_STS_REG);
1659

1660 1661 1662 1663 1664 1665
	/* Handling Non-fatal HNS RAS errors */
	if (status & HCLGE_RAS_REG_NFE_MASK) {
		dev_warn(dev,
			 "HNS Non-Fatal RAS error(status=0x%x) identified\n",
			 status);
		hclge_handle_all_ras_errors(hdev);
1666 1667
	} else {
		if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) ||
1668 1669
		    hdev->pdev->revision < 0x21) {
			ae_dev->override_pci_need_reset = 1;
1670
			return PCI_ERS_RESULT_RECOVERED;
1671
		}
1672 1673 1674 1675 1676
	}

	if (status & HCLGE_RAS_REG_ROCEE_ERR_MASK) {
		dev_warn(dev, "ROCEE uncorrected RAS error identified\n");
		hclge_handle_rocee_ras_error(ae_dev);
1677
	}
1678

1679
	if (status & HCLGE_RAS_REG_NFE_MASK ||
1680 1681
	    status & HCLGE_RAS_REG_ROCEE_ERR_MASK) {
		ae_dev->override_pci_need_reset = 0;
1682
		return PCI_ERS_RESULT_NEED_RESET;
1683 1684
	}
	ae_dev->override_pci_need_reset = 1;
1685

1686
	return PCI_ERS_RESULT_RECOVERED;
1687
}
1688

1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
/* hclge_query_8bd_info: query information about over_8bd_nfe_err
 * @hdev: pointer to struct hclge_dev
 * @vf_id: Index of the virtual function with error
 * @q_id: Physical index of the queue with error
 *
 * This function get specific index of queue and function which causes
 * over_8bd_nfe_err by using command. If vf_id is 0, it means error is
 * caused by PF instead of VF.
 */
static int hclge_query_over_8bd_err_info(struct hclge_dev *hdev, u16 *vf_id,
					 u16 *q_id)
{
	struct hclge_query_ppu_pf_other_int_dfx_cmd *req;
	struct hclge_desc desc;
	int ret;

	hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_PPU_PF_OTHER_INT_DFX, true);
	ret = hclge_cmd_send(&hdev->hw, &desc, 1);
	if (ret)
		return ret;

	req = (struct hclge_query_ppu_pf_other_int_dfx_cmd *)desc.data;
	*vf_id = le16_to_cpu(req->over_8bd_no_fe_vf_id);
	*q_id = le16_to_cpu(req->over_8bd_no_fe_qid);

	return 0;
}

/* hclge_handle_over_8bd_err: handle MSI-X error named over_8bd_nfe_err
 * @hdev: pointer to struct hclge_dev
 * @reset_requests: reset level that we need to trigger later
 *
 * over_8bd_nfe_err is a special MSI-X because it may caused by a VF, in
 * that case, we need to trigger VF reset. Otherwise, a PF reset is needed.
 */
static void hclge_handle_over_8bd_err(struct hclge_dev *hdev,
				      unsigned long *reset_requests)
{
	struct device *dev = &hdev->pdev->dev;
	u16 vf_id;
	u16 q_id;
	int ret;

	ret = hclge_query_over_8bd_err_info(hdev, &vf_id, &q_id);
	if (ret) {
		dev_err(dev, "fail(%d) to query over_8bd_no_fe info\n",
			ret);
		return;
	}

	dev_warn(dev, "PPU_PF_ABNORMAL_INT_ST over_8bd_no_fe found, vf_id(%d), queue_id(%d)\n",
		 vf_id, q_id);

	if (vf_id) {
		if (vf_id >= hdev->num_alloc_vport) {
			dev_err(dev, "invalid vf id(%d)\n", vf_id);
			return;
		}

		/* If we need to trigger other reset whose level is higher
		 * than HNAE3_VF_FUNC_RESET, no need to trigger a VF reset
		 * here.
		 */
		if (*reset_requests != 0)
			return;

		ret = hclge_inform_reset_assert_to_vf(&hdev->vport[vf_id]);
		if (ret)
			dev_warn(dev, "inform reset to vf(%d) failed %d!\n",
				 hdev->vport->vport_id, ret);
	} else {
		set_bit(HNAE3_FUNC_RESET, reset_requests);
	}
}

1764 1765 1766
int hclge_handle_hw_msix_error(struct hclge_dev *hdev,
			       unsigned long *reset_requests)
{
1767
	struct hclge_mac_tnl_stats mac_tnl_stats;
1768 1769
	struct device *dev = &hdev->pdev->dev;
	u32 mpf_bd_num, pf_bd_num, bd_num;
1770
	enum hnae3_reset_type reset_level;
1771 1772
	struct hclge_desc desc_bd;
	struct hclge_desc *desc;
1773 1774
	__le32 *desc_data;
	u32 status;
1775
	int ret;
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804

	/* query the number of bds for the MSIx int status */
	hclge_cmd_setup_basic_desc(&desc_bd, HCLGE_QUERY_MSIX_INT_STS_BD_NUM,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc_bd, 1);
	if (ret) {
		dev_err(dev, "fail(%d) to query msix int status bd num\n",
			ret);
		return ret;
	}

	mpf_bd_num = le32_to_cpu(desc_bd.data[0]);
	pf_bd_num = le32_to_cpu(desc_bd.data[1]);
	bd_num = max_t(u32, mpf_bd_num, pf_bd_num);

	desc = kcalloc(bd_num, sizeof(struct hclge_desc), GFP_KERNEL);
	if (!desc)
		goto out;

	/* query all main PF MSIx errors */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_CLEAR_ALL_MPF_MSIX_INT,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], mpf_bd_num);
	if (ret) {
		dev_err(dev, "query all mpf msix int cmd failed (%d)\n",
			ret);
		goto msi_error;
	}

1805 1806 1807 1808
	/* log MAC errors */
	desc_data = (__le32 *)&desc[1];
	status = le32_to_cpu(*desc_data);
	if (status) {
1809 1810 1811 1812
		reset_level = hclge_log_error(dev, "MAC_AFIFO_TNL_INT_R",
					      &hclge_mac_afifo_tnl_int[0],
					      status);
		set_bit(reset_level, reset_requests);
1813 1814
	}

1815
	/* log PPU(RCB) MPF errors */
1816 1817 1818 1819
	desc_data = (__le32 *)&desc[5];
	status = le32_to_cpu(*(desc_data + 2)) &
			HCLGE_PPU_MPF_INT_ST2_MSIX_MASK;
	if (status) {
1820 1821 1822 1823 1824
		reset_level =
			hclge_log_error(dev, "PPU_MPF_ABNORMAL_INT_ST2",
					&hclge_ppu_mpf_abnormal_int_st2[0],
					status);
		set_bit(reset_level, reset_requests);
1825 1826
	}

1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
	/* clear all main PF MSIx errors */
	hclge_cmd_reuse_desc(&desc[0], false);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], mpf_bd_num);
	if (ret) {
		dev_err(dev, "clear all mpf msix int cmd failed (%d)\n",
			ret);
		goto msi_error;
	}

	/* query all PF MSIx errors */
	memset(desc, 0, bd_num * sizeof(struct hclge_desc));
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_CLEAR_ALL_PF_MSIX_INT,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], pf_bd_num);
	if (ret) {
		dev_err(dev, "query all pf msix int cmd failed (%d)\n",
			ret);
		goto msi_error;
	}

S
Shiju Jose 已提交
1847 1848 1849
	/* log SSU PF errors */
	status = le32_to_cpu(desc[0].data[0]) & HCLGE_SSU_PORT_INT_MSIX_MASK;
	if (status) {
1850 1851 1852 1853
		reset_level = hclge_log_error(dev, "SSU_PORT_BASED_ERR_INT",
					      &hclge_ssu_port_based_pf_int[0],
					      status);
		set_bit(reset_level, reset_requests);
S
Shiju Jose 已提交
1854 1855
	}

S
Shiju Jose 已提交
1856 1857 1858
	/* read and log PPP PF errors */
	desc_data = (__le32 *)&desc[2];
	status = le32_to_cpu(*desc_data);
1859 1860 1861 1862 1863 1864
	if (status) {
		reset_level = hclge_log_error(dev, "PPP_PF_ABNORMAL_INT_ST0",
					      &hclge_ppp_pf_abnormal_int[0],
					      status);
		set_bit(reset_level, reset_requests);
	}
S
Shiju Jose 已提交
1865

1866
	/* log PPU(RCB) PF errors */
1867 1868
	desc_data = (__le32 *)&desc[3];
	status = le32_to_cpu(*desc_data) & HCLGE_PPU_PF_INT_MSIX_MASK;
1869 1870 1871 1872 1873 1874
	if (status) {
		reset_level = hclge_log_error(dev, "PPU_PF_ABNORMAL_INT_ST",
					      &hclge_ppu_pf_abnormal_int[0],
					      status);
		set_bit(reset_level, reset_requests);
	}
1875

1876 1877 1878 1879
	status = le32_to_cpu(*desc_data) & HCLGE_PPU_PF_OVER_8BD_ERR_MASK;
	if (status)
		hclge_handle_over_8bd_err(hdev, reset_requests);

1880 1881 1882 1883 1884 1885 1886 1887
	/* clear all PF MSIx errors */
	hclge_cmd_reuse_desc(&desc[0], false);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], pf_bd_num);
	if (ret) {
		dev_err(dev, "clear all pf msix int cmd failed (%d)\n",
			ret);
	}

1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
	/* query and clear mac tnl interruptions */
	hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_QUERY_MAC_TNL_INT,
				   true);
	ret = hclge_cmd_send(&hdev->hw, &desc[0], 1);
	if (ret) {
		dev_err(dev, "query mac tnl int cmd failed (%d)\n", ret);
		goto msi_error;
	}

	status = le32_to_cpu(desc->data[0]);
	if (status) {
		/* When mac tnl interrupt occurs, we record current time and
		 * register status here in a fifo, then clear the status. So
		 * that if link status changes suddenly at some time, we can
		 * query them by debugfs.
		 */
		mac_tnl_stats.time = local_clock();
		mac_tnl_stats.status = status;
		kfifo_put(&hdev->mac_tnl_log, mac_tnl_stats);
		ret = hclge_clear_mac_tnl_int(hdev);
		if (ret)
			dev_err(dev, "clear mac tnl int failed (%d)\n", ret);
	}

1912 1913 1914 1915 1916
msi_error:
	kfree(desc);
out:
	return ret;
}