1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 4 #include <linux/debugfs.h> 5 #include <linux/kernel.h> 6 #include <linux/seq_file.h> 7 #include "dr_types.h" 8 9 #define DR_DBG_PTR_TO_ID(p) ((u64)(uintptr_t)(p) & 0xFFFFFFFFULL) 10 11 enum dr_dump_rec_type { 12 DR_DUMP_REC_TYPE_DOMAIN = 3000, 13 DR_DUMP_REC_TYPE_DOMAIN_INFO_FLEX_PARSER = 3001, 14 DR_DUMP_REC_TYPE_DOMAIN_INFO_DEV_ATTR = 3002, 15 DR_DUMP_REC_TYPE_DOMAIN_INFO_VPORT = 3003, 16 DR_DUMP_REC_TYPE_DOMAIN_INFO_CAPS = 3004, 17 DR_DUMP_REC_TYPE_DOMAIN_SEND_RING = 3005, 18 19 DR_DUMP_REC_TYPE_TABLE = 3100, 20 DR_DUMP_REC_TYPE_TABLE_RX = 3101, 21 DR_DUMP_REC_TYPE_TABLE_TX = 3102, 22 23 DR_DUMP_REC_TYPE_MATCHER = 3200, 24 DR_DUMP_REC_TYPE_MATCHER_MASK_DEPRECATED = 3201, 25 DR_DUMP_REC_TYPE_MATCHER_RX = 3202, 26 DR_DUMP_REC_TYPE_MATCHER_TX = 3203, 27 DR_DUMP_REC_TYPE_MATCHER_BUILDER = 3204, 28 DR_DUMP_REC_TYPE_MATCHER_MASK = 3205, 29 30 DR_DUMP_REC_TYPE_RULE = 3300, 31 DR_DUMP_REC_TYPE_RULE_RX_ENTRY_V0 = 3301, 32 DR_DUMP_REC_TYPE_RULE_TX_ENTRY_V0 = 3302, 33 DR_DUMP_REC_TYPE_RULE_RX_ENTRY_V1 = 3303, 34 DR_DUMP_REC_TYPE_RULE_TX_ENTRY_V1 = 3304, 35 36 DR_DUMP_REC_TYPE_ACTION_ENCAP_L2 = 3400, 37 DR_DUMP_REC_TYPE_ACTION_ENCAP_L3 = 3401, 38 DR_DUMP_REC_TYPE_ACTION_MODIFY_HDR = 3402, 39 DR_DUMP_REC_TYPE_ACTION_DROP = 3403, 40 DR_DUMP_REC_TYPE_ACTION_QP = 3404, 41 DR_DUMP_REC_TYPE_ACTION_FT = 3405, 42 DR_DUMP_REC_TYPE_ACTION_CTR = 3406, 43 DR_DUMP_REC_TYPE_ACTION_TAG = 3407, 44 DR_DUMP_REC_TYPE_ACTION_VPORT = 3408, 45 DR_DUMP_REC_TYPE_ACTION_DECAP_L2 = 3409, 46 DR_DUMP_REC_TYPE_ACTION_DECAP_L3 = 3410, 47 DR_DUMP_REC_TYPE_ACTION_DEVX_TIR = 3411, 48 DR_DUMP_REC_TYPE_ACTION_PUSH_VLAN = 3412, 49 DR_DUMP_REC_TYPE_ACTION_POP_VLAN = 3413, 50 DR_DUMP_REC_TYPE_ACTION_SAMPLER = 3415, 51 DR_DUMP_REC_TYPE_ACTION_INSERT_HDR = 3420, 52 DR_DUMP_REC_TYPE_ACTION_REMOVE_HDR = 3421, 53 DR_DUMP_REC_TYPE_ACTION_MATCH_RANGE = 3425, 54 }; 55 56 void mlx5dr_dbg_tbl_add(struct mlx5dr_table *tbl) 57 { 58 mutex_lock(&tbl->dmn->dump_info.dbg_mutex); 59 list_add_tail(&tbl->dbg_node, &tbl->dmn->dbg_tbl_list); 60 mutex_unlock(&tbl->dmn->dump_info.dbg_mutex); 61 } 62 63 void mlx5dr_dbg_tbl_del(struct mlx5dr_table *tbl) 64 { 65 mutex_lock(&tbl->dmn->dump_info.dbg_mutex); 66 list_del(&tbl->dbg_node); 67 mutex_unlock(&tbl->dmn->dump_info.dbg_mutex); 68 } 69 70 void mlx5dr_dbg_rule_add(struct mlx5dr_rule *rule) 71 { 72 struct mlx5dr_domain *dmn = rule->matcher->tbl->dmn; 73 74 mutex_lock(&dmn->dump_info.dbg_mutex); 75 list_add_tail(&rule->dbg_node, &rule->matcher->dbg_rule_list); 76 mutex_unlock(&dmn->dump_info.dbg_mutex); 77 } 78 79 void mlx5dr_dbg_rule_del(struct mlx5dr_rule *rule) 80 { 81 struct mlx5dr_domain *dmn = rule->matcher->tbl->dmn; 82 83 mutex_lock(&dmn->dump_info.dbg_mutex); 84 list_del(&rule->dbg_node); 85 mutex_unlock(&dmn->dump_info.dbg_mutex); 86 } 87 88 static u64 dr_dump_icm_to_idx(u64 icm_addr) 89 { 90 return (icm_addr >> 6) & 0xffffffff; 91 } 92 93 #define DR_HEX_SIZE 256 94 95 static void 96 dr_dump_hex_print(char hex[DR_HEX_SIZE], char *src, u32 size) 97 { 98 if (WARN_ON_ONCE(DR_HEX_SIZE < 2 * size + 1)) 99 size = DR_HEX_SIZE / 2 - 1; /* truncate */ 100 101 bin2hex(hex, src, size); 102 hex[2 * size] = 0; /* NULL-terminate */ 103 } 104 105 static int 106 dr_dump_rule_action_mem(struct seq_file *file, const u64 rule_id, 107 struct mlx5dr_rule_action_member *action_mem) 108 { 109 struct mlx5dr_action *action = action_mem->action; 110 const u64 action_id = DR_DBG_PTR_TO_ID(action); 111 u64 hit_tbl_ptr, miss_tbl_ptr; 112 u32 hit_tbl_id, miss_tbl_id; 113 114 switch (action->action_type) { 115 case DR_ACTION_TYP_DROP: 116 seq_printf(file, "%d,0x%llx,0x%llx\n", 117 DR_DUMP_REC_TYPE_ACTION_DROP, action_id, rule_id); 118 break; 119 case DR_ACTION_TYP_FT: 120 if (action->dest_tbl->is_fw_tbl) 121 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%x\n", 122 DR_DUMP_REC_TYPE_ACTION_FT, action_id, 123 rule_id, action->dest_tbl->fw_tbl.id, 124 -1); 125 else 126 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%llx\n", 127 DR_DUMP_REC_TYPE_ACTION_FT, action_id, 128 rule_id, action->dest_tbl->tbl->table_id, 129 DR_DBG_PTR_TO_ID(action->dest_tbl->tbl)); 130 131 break; 132 case DR_ACTION_TYP_CTR: 133 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 134 DR_DUMP_REC_TYPE_ACTION_CTR, action_id, rule_id, 135 action->ctr->ctr_id + action->ctr->offset); 136 break; 137 case DR_ACTION_TYP_TAG: 138 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 139 DR_DUMP_REC_TYPE_ACTION_TAG, action_id, rule_id, 140 action->flow_tag->flow_tag); 141 break; 142 case DR_ACTION_TYP_MODIFY_HDR: 143 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 144 DR_DUMP_REC_TYPE_ACTION_MODIFY_HDR, action_id, 145 rule_id, action->rewrite->index); 146 break; 147 case DR_ACTION_TYP_VPORT: 148 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 149 DR_DUMP_REC_TYPE_ACTION_VPORT, action_id, rule_id, 150 action->vport->caps->num); 151 break; 152 case DR_ACTION_TYP_TNL_L2_TO_L2: 153 seq_printf(file, "%d,0x%llx,0x%llx\n", 154 DR_DUMP_REC_TYPE_ACTION_DECAP_L2, action_id, 155 rule_id); 156 break; 157 case DR_ACTION_TYP_TNL_L3_TO_L2: 158 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 159 DR_DUMP_REC_TYPE_ACTION_DECAP_L3, action_id, 160 rule_id, action->rewrite->index); 161 break; 162 case DR_ACTION_TYP_L2_TO_TNL_L2: 163 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 164 DR_DUMP_REC_TYPE_ACTION_ENCAP_L2, action_id, 165 rule_id, action->reformat->id); 166 break; 167 case DR_ACTION_TYP_L2_TO_TNL_L3: 168 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 169 DR_DUMP_REC_TYPE_ACTION_ENCAP_L3, action_id, 170 rule_id, action->reformat->id); 171 break; 172 case DR_ACTION_TYP_POP_VLAN: 173 seq_printf(file, "%d,0x%llx,0x%llx\n", 174 DR_DUMP_REC_TYPE_ACTION_POP_VLAN, action_id, 175 rule_id); 176 break; 177 case DR_ACTION_TYP_PUSH_VLAN: 178 seq_printf(file, "%d,0x%llx,0x%llx,0x%x\n", 179 DR_DUMP_REC_TYPE_ACTION_PUSH_VLAN, action_id, 180 rule_id, action->push_vlan->vlan_hdr); 181 break; 182 case DR_ACTION_TYP_INSERT_HDR: 183 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%x,0x%x\n", 184 DR_DUMP_REC_TYPE_ACTION_INSERT_HDR, action_id, 185 rule_id, action->reformat->id, 186 action->reformat->param_0, 187 action->reformat->param_1); 188 break; 189 case DR_ACTION_TYP_REMOVE_HDR: 190 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%x,0x%x\n", 191 DR_DUMP_REC_TYPE_ACTION_REMOVE_HDR, action_id, 192 rule_id, action->reformat->id, 193 action->reformat->param_0, 194 action->reformat->param_1); 195 break; 196 case DR_ACTION_TYP_SAMPLER: 197 seq_printf(file, 198 "%d,0x%llx,0x%llx,0x%x,0x%x,0x%x,0x%llx,0x%llx\n", 199 DR_DUMP_REC_TYPE_ACTION_SAMPLER, action_id, rule_id, 200 0, 0, action->sampler->sampler_id, 201 action->sampler->rx_icm_addr, 202 action->sampler->tx_icm_addr); 203 break; 204 case DR_ACTION_TYP_RANGE: 205 if (action->range->hit_tbl_action->dest_tbl->is_fw_tbl) { 206 hit_tbl_id = action->range->hit_tbl_action->dest_tbl->fw_tbl.id; 207 hit_tbl_ptr = 0; 208 } else { 209 hit_tbl_id = action->range->hit_tbl_action->dest_tbl->tbl->table_id; 210 hit_tbl_ptr = 211 DR_DBG_PTR_TO_ID(action->range->hit_tbl_action->dest_tbl->tbl); 212 } 213 214 if (action->range->miss_tbl_action->dest_tbl->is_fw_tbl) { 215 miss_tbl_id = action->range->miss_tbl_action->dest_tbl->fw_tbl.id; 216 miss_tbl_ptr = 0; 217 } else { 218 miss_tbl_id = action->range->miss_tbl_action->dest_tbl->tbl->table_id; 219 miss_tbl_ptr = 220 DR_DBG_PTR_TO_ID(action->range->miss_tbl_action->dest_tbl->tbl); 221 } 222 223 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%llx,0x%x,0x%llx,0x%x\n", 224 DR_DUMP_REC_TYPE_ACTION_MATCH_RANGE, action_id, rule_id, 225 hit_tbl_id, hit_tbl_ptr, miss_tbl_id, miss_tbl_ptr, 226 action->range->definer_id); 227 break; 228 default: 229 return 0; 230 } 231 232 return 0; 233 } 234 235 static int 236 dr_dump_rule_mem(struct seq_file *file, struct mlx5dr_ste *ste, 237 bool is_rx, const u64 rule_id, u8 format_ver) 238 { 239 char hw_ste_dump[DR_HEX_SIZE]; 240 u32 mem_rec_type; 241 242 if (format_ver == MLX5_STEERING_FORMAT_CONNECTX_5) { 243 mem_rec_type = is_rx ? DR_DUMP_REC_TYPE_RULE_RX_ENTRY_V0 : 244 DR_DUMP_REC_TYPE_RULE_TX_ENTRY_V0; 245 } else { 246 mem_rec_type = is_rx ? DR_DUMP_REC_TYPE_RULE_RX_ENTRY_V1 : 247 DR_DUMP_REC_TYPE_RULE_TX_ENTRY_V1; 248 } 249 250 dr_dump_hex_print(hw_ste_dump, (char *)mlx5dr_ste_get_hw_ste(ste), 251 DR_STE_SIZE_REDUCED); 252 253 seq_printf(file, "%d,0x%llx,0x%llx,%s\n", mem_rec_type, 254 dr_dump_icm_to_idx(mlx5dr_ste_get_icm_addr(ste)), rule_id, 255 hw_ste_dump); 256 257 return 0; 258 } 259 260 static int 261 dr_dump_rule_rx_tx(struct seq_file *file, struct mlx5dr_rule_rx_tx *rule_rx_tx, 262 bool is_rx, const u64 rule_id, u8 format_ver) 263 { 264 struct mlx5dr_ste *ste_arr[DR_RULE_MAX_STES + DR_ACTION_MAX_STES]; 265 struct mlx5dr_ste *curr_ste = rule_rx_tx->last_rule_ste; 266 int ret, i; 267 268 if (mlx5dr_rule_get_reverse_rule_members(ste_arr, curr_ste, &i)) 269 return 0; 270 271 while (i--) { 272 ret = dr_dump_rule_mem(file, ste_arr[i], is_rx, rule_id, 273 format_ver); 274 if (ret < 0) 275 return ret; 276 } 277 278 return 0; 279 } 280 281 static int dr_dump_rule(struct seq_file *file, struct mlx5dr_rule *rule) 282 { 283 struct mlx5dr_rule_action_member *action_mem; 284 const u64 rule_id = DR_DBG_PTR_TO_ID(rule); 285 struct mlx5dr_rule_rx_tx *rx = &rule->rx; 286 struct mlx5dr_rule_rx_tx *tx = &rule->tx; 287 u8 format_ver; 288 int ret; 289 290 format_ver = rule->matcher->tbl->dmn->info.caps.sw_format_ver; 291 292 seq_printf(file, "%d,0x%llx,0x%llx\n", DR_DUMP_REC_TYPE_RULE, rule_id, 293 DR_DBG_PTR_TO_ID(rule->matcher)); 294 295 if (rx->nic_matcher) { 296 ret = dr_dump_rule_rx_tx(file, rx, true, rule_id, format_ver); 297 if (ret < 0) 298 return ret; 299 } 300 301 if (tx->nic_matcher) { 302 ret = dr_dump_rule_rx_tx(file, tx, false, rule_id, format_ver); 303 if (ret < 0) 304 return ret; 305 } 306 307 list_for_each_entry(action_mem, &rule->rule_actions_list, list) { 308 ret = dr_dump_rule_action_mem(file, rule_id, action_mem); 309 if (ret < 0) 310 return ret; 311 } 312 313 return 0; 314 } 315 316 static int 317 dr_dump_matcher_mask(struct seq_file *file, struct mlx5dr_match_param *mask, 318 u8 criteria, const u64 matcher_id) 319 { 320 char dump[DR_HEX_SIZE]; 321 322 seq_printf(file, "%d,0x%llx,", DR_DUMP_REC_TYPE_MATCHER_MASK, 323 matcher_id); 324 325 if (criteria & DR_MATCHER_CRITERIA_OUTER) { 326 dr_dump_hex_print(dump, (char *)&mask->outer, sizeof(mask->outer)); 327 seq_printf(file, "%s,", dump); 328 } else { 329 seq_puts(file, ","); 330 } 331 332 if (criteria & DR_MATCHER_CRITERIA_INNER) { 333 dr_dump_hex_print(dump, (char *)&mask->inner, sizeof(mask->inner)); 334 seq_printf(file, "%s,", dump); 335 } else { 336 seq_puts(file, ","); 337 } 338 339 if (criteria & DR_MATCHER_CRITERIA_MISC) { 340 dr_dump_hex_print(dump, (char *)&mask->misc, sizeof(mask->misc)); 341 seq_printf(file, "%s,", dump); 342 } else { 343 seq_puts(file, ","); 344 } 345 346 if (criteria & DR_MATCHER_CRITERIA_MISC2) { 347 dr_dump_hex_print(dump, (char *)&mask->misc2, sizeof(mask->misc2)); 348 seq_printf(file, "%s,", dump); 349 } else { 350 seq_puts(file, ","); 351 } 352 353 if (criteria & DR_MATCHER_CRITERIA_MISC3) { 354 dr_dump_hex_print(dump, (char *)&mask->misc3, sizeof(mask->misc3)); 355 seq_printf(file, "%s\n", dump); 356 } else { 357 seq_puts(file, ",\n"); 358 } 359 360 return 0; 361 } 362 363 static int 364 dr_dump_matcher_builder(struct seq_file *file, struct mlx5dr_ste_build *builder, 365 u32 index, bool is_rx, const u64 matcher_id) 366 { 367 seq_printf(file, "%d,0x%llx,%d,%d,0x%x\n", 368 DR_DUMP_REC_TYPE_MATCHER_BUILDER, matcher_id, index, is_rx, 369 builder->lu_type); 370 371 return 0; 372 } 373 374 static int 375 dr_dump_matcher_rx_tx(struct seq_file *file, bool is_rx, 376 struct mlx5dr_matcher_rx_tx *matcher_rx_tx, 377 const u64 matcher_id) 378 { 379 enum dr_dump_rec_type rec_type; 380 u64 s_icm_addr, e_icm_addr; 381 int i, ret; 382 383 rec_type = is_rx ? DR_DUMP_REC_TYPE_MATCHER_RX : 384 DR_DUMP_REC_TYPE_MATCHER_TX; 385 386 s_icm_addr = mlx5dr_icm_pool_get_chunk_icm_addr(matcher_rx_tx->s_htbl->chunk); 387 e_icm_addr = mlx5dr_icm_pool_get_chunk_icm_addr(matcher_rx_tx->e_anchor->chunk); 388 seq_printf(file, "%d,0x%llx,0x%llx,%d,0x%llx,0x%llx\n", 389 rec_type, DR_DBG_PTR_TO_ID(matcher_rx_tx), 390 matcher_id, matcher_rx_tx->num_of_builders, 391 dr_dump_icm_to_idx(s_icm_addr), 392 dr_dump_icm_to_idx(e_icm_addr)); 393 394 for (i = 0; i < matcher_rx_tx->num_of_builders; i++) { 395 ret = dr_dump_matcher_builder(file, 396 &matcher_rx_tx->ste_builder[i], 397 i, is_rx, matcher_id); 398 if (ret < 0) 399 return ret; 400 } 401 402 return 0; 403 } 404 405 static int 406 dr_dump_matcher(struct seq_file *file, struct mlx5dr_matcher *matcher) 407 { 408 struct mlx5dr_matcher_rx_tx *rx = &matcher->rx; 409 struct mlx5dr_matcher_rx_tx *tx = &matcher->tx; 410 u64 matcher_id; 411 int ret; 412 413 matcher_id = DR_DBG_PTR_TO_ID(matcher); 414 415 seq_printf(file, "%d,0x%llx,0x%llx,%d\n", DR_DUMP_REC_TYPE_MATCHER, 416 matcher_id, DR_DBG_PTR_TO_ID(matcher->tbl), matcher->prio); 417 418 ret = dr_dump_matcher_mask(file, &matcher->mask, 419 matcher->match_criteria, matcher_id); 420 if (ret < 0) 421 return ret; 422 423 if (rx->nic_tbl) { 424 ret = dr_dump_matcher_rx_tx(file, true, rx, matcher_id); 425 if (ret < 0) 426 return ret; 427 } 428 429 if (tx->nic_tbl) { 430 ret = dr_dump_matcher_rx_tx(file, false, tx, matcher_id); 431 if (ret < 0) 432 return ret; 433 } 434 435 return 0; 436 } 437 438 static int 439 dr_dump_matcher_all(struct seq_file *file, struct mlx5dr_matcher *matcher) 440 { 441 struct mlx5dr_rule *rule; 442 int ret; 443 444 ret = dr_dump_matcher(file, matcher); 445 if (ret < 0) 446 return ret; 447 448 list_for_each_entry(rule, &matcher->dbg_rule_list, dbg_node) { 449 ret = dr_dump_rule(file, rule); 450 if (ret < 0) 451 return ret; 452 } 453 454 return 0; 455 } 456 457 static int 458 dr_dump_table_rx_tx(struct seq_file *file, bool is_rx, 459 struct mlx5dr_table_rx_tx *table_rx_tx, 460 const u64 table_id) 461 { 462 enum dr_dump_rec_type rec_type; 463 u64 s_icm_addr; 464 465 rec_type = is_rx ? DR_DUMP_REC_TYPE_TABLE_RX : 466 DR_DUMP_REC_TYPE_TABLE_TX; 467 468 s_icm_addr = mlx5dr_icm_pool_get_chunk_icm_addr(table_rx_tx->s_anchor->chunk); 469 seq_printf(file, "%d,0x%llx,0x%llx\n", rec_type, table_id, 470 dr_dump_icm_to_idx(s_icm_addr)); 471 472 return 0; 473 } 474 475 static int dr_dump_table(struct seq_file *file, struct mlx5dr_table *table) 476 { 477 struct mlx5dr_table_rx_tx *rx = &table->rx; 478 struct mlx5dr_table_rx_tx *tx = &table->tx; 479 int ret; 480 481 seq_printf(file, "%d,0x%llx,0x%llx,%d,%d\n", DR_DUMP_REC_TYPE_TABLE, 482 DR_DBG_PTR_TO_ID(table), DR_DBG_PTR_TO_ID(table->dmn), 483 table->table_type, table->level); 484 485 if (rx->nic_dmn) { 486 ret = dr_dump_table_rx_tx(file, true, rx, 487 DR_DBG_PTR_TO_ID(table)); 488 if (ret < 0) 489 return ret; 490 } 491 492 if (tx->nic_dmn) { 493 ret = dr_dump_table_rx_tx(file, false, tx, 494 DR_DBG_PTR_TO_ID(table)); 495 if (ret < 0) 496 return ret; 497 } 498 return 0; 499 } 500 501 static int dr_dump_table_all(struct seq_file *file, struct mlx5dr_table *tbl) 502 { 503 struct mlx5dr_matcher *matcher; 504 int ret; 505 506 ret = dr_dump_table(file, tbl); 507 if (ret < 0) 508 return ret; 509 510 list_for_each_entry(matcher, &tbl->matcher_list, list_node) { 511 ret = dr_dump_matcher_all(file, matcher); 512 if (ret < 0) 513 return ret; 514 } 515 return 0; 516 } 517 518 static int 519 dr_dump_send_ring(struct seq_file *file, struct mlx5dr_send_ring *ring, 520 const u64 domain_id) 521 { 522 seq_printf(file, "%d,0x%llx,0x%llx,0x%x,0x%x\n", 523 DR_DUMP_REC_TYPE_DOMAIN_SEND_RING, DR_DBG_PTR_TO_ID(ring), 524 domain_id, ring->cq->mcq.cqn, ring->qp->qpn); 525 return 0; 526 } 527 528 static int 529 dr_dump_domain_info_flex_parser(struct seq_file *file, 530 const char *flex_parser_name, 531 const u8 flex_parser_value, 532 const u64 domain_id) 533 { 534 seq_printf(file, "%d,0x%llx,%s,0x%x\n", 535 DR_DUMP_REC_TYPE_DOMAIN_INFO_FLEX_PARSER, domain_id, 536 flex_parser_name, flex_parser_value); 537 return 0; 538 } 539 540 static int 541 dr_dump_domain_info_caps(struct seq_file *file, struct mlx5dr_cmd_caps *caps, 542 const u64 domain_id) 543 { 544 struct mlx5dr_cmd_vport_cap *vport_caps; 545 unsigned long i, vports_num; 546 547 xa_for_each(&caps->vports.vports_caps_xa, vports_num, vport_caps) 548 ; /* count the number of vports in xarray */ 549 550 seq_printf(file, "%d,0x%llx,0x%x,0x%llx,0x%llx,0x%x,%lu,%d\n", 551 DR_DUMP_REC_TYPE_DOMAIN_INFO_CAPS, domain_id, caps->gvmi, 552 caps->nic_rx_drop_address, caps->nic_tx_drop_address, 553 caps->flex_protocols, vports_num, caps->eswitch_manager); 554 555 xa_for_each(&caps->vports.vports_caps_xa, i, vport_caps) { 556 vport_caps = xa_load(&caps->vports.vports_caps_xa, i); 557 558 seq_printf(file, "%d,0x%llx,%lu,0x%x,0x%llx,0x%llx\n", 559 DR_DUMP_REC_TYPE_DOMAIN_INFO_VPORT, domain_id, i, 560 vport_caps->vport_gvmi, vport_caps->icm_address_rx, 561 vport_caps->icm_address_tx); 562 } 563 return 0; 564 } 565 566 static int 567 dr_dump_domain_info(struct seq_file *file, struct mlx5dr_domain_info *info, 568 const u64 domain_id) 569 { 570 int ret; 571 572 ret = dr_dump_domain_info_caps(file, &info->caps, domain_id); 573 if (ret < 0) 574 return ret; 575 576 ret = dr_dump_domain_info_flex_parser(file, "icmp_dw0", 577 info->caps.flex_parser_id_icmp_dw0, 578 domain_id); 579 if (ret < 0) 580 return ret; 581 582 ret = dr_dump_domain_info_flex_parser(file, "icmp_dw1", 583 info->caps.flex_parser_id_icmp_dw1, 584 domain_id); 585 if (ret < 0) 586 return ret; 587 588 ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw0", 589 info->caps.flex_parser_id_icmpv6_dw0, 590 domain_id); 591 if (ret < 0) 592 return ret; 593 594 ret = dr_dump_domain_info_flex_parser(file, "icmpv6_dw1", 595 info->caps.flex_parser_id_icmpv6_dw1, 596 domain_id); 597 if (ret < 0) 598 return ret; 599 600 return 0; 601 } 602 603 static int 604 dr_dump_domain(struct seq_file *file, struct mlx5dr_domain *dmn) 605 { 606 u64 domain_id = DR_DBG_PTR_TO_ID(dmn); 607 int ret; 608 609 seq_printf(file, "%d,0x%llx,%d,0%x,%d,%s\n", DR_DUMP_REC_TYPE_DOMAIN, 610 domain_id, dmn->type, dmn->info.caps.gvmi, 611 dmn->info.supp_sw_steering, pci_name(dmn->mdev->pdev)); 612 613 ret = dr_dump_domain_info(file, &dmn->info, domain_id); 614 if (ret < 0) 615 return ret; 616 617 if (dmn->info.supp_sw_steering) { 618 ret = dr_dump_send_ring(file, dmn->send_ring, domain_id); 619 if (ret < 0) 620 return ret; 621 } 622 623 return 0; 624 } 625 626 static int dr_dump_domain_all(struct seq_file *file, struct mlx5dr_domain *dmn) 627 { 628 struct mlx5dr_table *tbl; 629 int ret; 630 631 mutex_lock(&dmn->dump_info.dbg_mutex); 632 mlx5dr_domain_lock(dmn); 633 634 ret = dr_dump_domain(file, dmn); 635 if (ret < 0) 636 goto unlock_mutex; 637 638 list_for_each_entry(tbl, &dmn->dbg_tbl_list, dbg_node) { 639 ret = dr_dump_table_all(file, tbl); 640 if (ret < 0) 641 break; 642 } 643 644 unlock_mutex: 645 mlx5dr_domain_unlock(dmn); 646 mutex_unlock(&dmn->dump_info.dbg_mutex); 647 return ret; 648 } 649 650 static int dr_dump_show(struct seq_file *file, void *priv) 651 { 652 return dr_dump_domain_all(file, file->private); 653 } 654 DEFINE_SHOW_ATTRIBUTE(dr_dump); 655 656 void mlx5dr_dbg_init_dump(struct mlx5dr_domain *dmn) 657 { 658 struct mlx5_core_dev *dev = dmn->mdev; 659 char file_name[128]; 660 661 if (dmn->type != MLX5DR_DOMAIN_TYPE_FDB) { 662 mlx5_core_warn(dev, 663 "Steering dump is not supported for NIC RX/TX domains\n"); 664 return; 665 } 666 667 dmn->dump_info.steering_debugfs = 668 debugfs_create_dir("steering", mlx5_debugfs_get_dev_root(dev)); 669 dmn->dump_info.fdb_debugfs = 670 debugfs_create_dir("fdb", dmn->dump_info.steering_debugfs); 671 672 sprintf(file_name, "dmn_%p", dmn); 673 debugfs_create_file(file_name, 0444, dmn->dump_info.fdb_debugfs, 674 dmn, &dr_dump_fops); 675 676 INIT_LIST_HEAD(&dmn->dbg_tbl_list); 677 mutex_init(&dmn->dump_info.dbg_mutex); 678 } 679 680 void mlx5dr_dbg_uninit_dump(struct mlx5dr_domain *dmn) 681 { 682 debugfs_remove_recursive(dmn->dump_info.steering_debugfs); 683 mutex_destroy(&dmn->dump_info.dbg_mutex); 684 } 685