1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2024 Broadcom 3 * All rights reserved. 4 */ 5 6 #include <stdio.h> 7 8 #include "tf_core.h" 9 #include "tf_util.h" 10 #include "tf_session.h" 11 #include "tf_tbl.h" 12 #include "tf_em.h" 13 #include "tf_rm.h" 14 #include "tf_global_cfg.h" 15 #include "tf_msg.h" 16 #include "tfp.h" 17 #include "bitalloc.h" 18 #include "bnxt.h" 19 #include "rand.h" 20 #include "tf_common.h" 21 #include "tf_ext_flow_handle.h" 22 23 int 24 tf_open_session(struct tf *tfp, 25 struct tf_open_session_parms *parms) 26 { 27 int rc; 28 unsigned int domain, bus, slot, device; 29 struct tf_session_open_session_parms oparms; 30 31 TF_CHECK_PARMS2(tfp, parms); 32 33 /* Filter out any non-supported device types on the Core 34 * side. It is assumed that the Firmware will be supported if 35 * firmware open session succeeds. 36 */ 37 if (parms->device_type != TF_DEVICE_TYPE_P4 && 38 parms->device_type != TF_DEVICE_TYPE_P5 && 39 parms->device_type != TF_DEVICE_TYPE_SR) { 40 TFP_DRV_LOG(ERR, 41 "Unsupported device type %d\n", 42 parms->device_type); 43 return -ENOTSUP; 44 } 45 46 /* Verify control channel and build the beginning of session_id */ 47 rc = sscanf(parms->ctrl_chan_name, 48 "%x:%x:%x.%u", 49 &domain, 50 &bus, 51 &slot, 52 &device); 53 if (rc != 4) { 54 /* PCI Domain not provided (optional in DPDK), thus we 55 * force domain to 0 and recheck. 56 */ 57 domain = 0; 58 59 /* Check parsing of bus/slot/device */ 60 rc = sscanf(parms->ctrl_chan_name, 61 "%x:%x.%u", 62 &bus, 63 &slot, 64 &device); 65 if (rc != 3) { 66 TFP_DRV_LOG(ERR, 67 "Failed to scan device ctrl_chan_name\n"); 68 return -EINVAL; 69 } 70 } 71 72 parms->session_id.internal.domain = domain; 73 parms->session_id.internal.bus = bus; 74 parms->session_id.internal.device = device; 75 oparms.open_cfg = parms; 76 77 /* Session vs session client is decided in 78 * tf_session_open_session() 79 */ 80 rc = tf_session_open_session(tfp, &oparms); 81 /* Logging handled by tf_session_open_session */ 82 if (rc) 83 return rc; 84 85 TFP_DRV_LOG(INFO, 86 "domain:%x, bus:%x, device:%u\n", 87 parms->session_id.internal.domain, 88 parms->session_id.internal.bus, 89 parms->session_id.internal.device); 90 91 return 0; 92 } 93 94 int 95 tf_attach_session(struct tf *tfp, 96 struct tf_attach_session_parms *parms) 97 { 98 int rc; 99 unsigned int domain, bus, slot, device; 100 struct tf_session_attach_session_parms aparms; 101 102 TF_CHECK_PARMS2(tfp, parms); 103 104 /* Verify control channel */ 105 rc = sscanf(parms->ctrl_chan_name, 106 "%x:%x:%x.%u", 107 &domain, 108 &bus, 109 &slot, 110 &device); 111 if (rc != 4) { 112 TFP_DRV_LOG(ERR, 113 "Failed to scan device ctrl_chan_name\n"); 114 return -EINVAL; 115 } 116 117 /* Verify 'attach' channel */ 118 rc = sscanf(parms->attach_chan_name, 119 "%x:%x:%x.%u", 120 &domain, 121 &bus, 122 &slot, 123 &device); 124 if (rc != 4) { 125 TFP_DRV_LOG(ERR, 126 "Failed to scan device attach_chan_name\n"); 127 return -EINVAL; 128 } 129 130 /* Prepare return value of session_id, using ctrl_chan_name 131 * device values as it becomes the session id. 132 */ 133 parms->session_id.internal.domain = domain; 134 parms->session_id.internal.bus = bus; 135 parms->session_id.internal.device = device; 136 aparms.attach_cfg = parms; 137 rc = tf_session_attach_session(tfp, 138 &aparms); 139 /* Logging handled by dev_bind */ 140 if (rc) 141 return rc; 142 143 TFP_DRV_LOG(INFO, 144 "Attached to session, session_id:%d\n", 145 parms->session_id.id); 146 147 TFP_DRV_LOG(INFO, 148 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n", 149 parms->session_id.internal.domain, 150 parms->session_id.internal.bus, 151 parms->session_id.internal.device, 152 parms->session_id.internal.fw_session_id); 153 154 return rc; 155 } 156 157 int 158 tf_close_session(struct tf *tfp) 159 { 160 int rc; 161 struct tf_session_close_session_parms cparms = { 0 }; 162 union tf_session_id session_id = { 0 }; 163 uint8_t ref_count; 164 165 TF_CHECK_PARMS1(tfp); 166 167 cparms.ref_count = &ref_count; 168 cparms.session_id = &session_id; 169 /* Session vs session client is decided in 170 * tf_session_close_session() 171 */ 172 rc = tf_session_close_session(tfp, 173 &cparms); 174 /* Logging handled by tf_session_close_session */ 175 if (rc) 176 return rc; 177 178 TFP_DRV_LOG(INFO, 179 "domain:%d, bus:%x, device:%d\n", 180 cparms.session_id->internal.domain, 181 cparms.session_id->internal.bus, 182 cparms.session_id->internal.device); 183 184 return rc; 185 } 186 187 /** insert EM hash entry API 188 * 189 * returns: 190 * 0 - Success 191 * -EINVAL - Error 192 */ 193 int tf_insert_em_entry(struct tf *tfp, 194 struct tf_insert_em_entry_parms *parms) 195 { 196 struct tf_session *tfs; 197 struct tf_dev_info *dev; 198 int rc; 199 200 TF_CHECK_PARMS2(tfp, parms); 201 202 /* Retrieve the session information */ 203 rc = tf_session_get_session(tfp, &tfs); 204 if (rc) { 205 TFP_DRV_LOG(ERR, 206 "%s: Failed to lookup session, rc:%s\n", 207 tf_dir_2_str(parms->dir), 208 strerror(-rc)); 209 return rc; 210 } 211 212 /* Retrieve the device information */ 213 rc = tf_session_get_device(tfs, &dev); 214 if (rc) { 215 TFP_DRV_LOG(ERR, 216 "%s: Failed to lookup device, rc:%s\n", 217 tf_dir_2_str(parms->dir), 218 strerror(-rc)); 219 return rc; 220 } 221 222 if (parms->mem == TF_MEM_EXTERNAL && 223 dev->ops->tf_dev_insert_ext_em_entry != NULL) 224 rc = dev->ops->tf_dev_insert_ext_em_entry(tfp, parms); 225 else if (parms->mem == TF_MEM_INTERNAL && 226 dev->ops->tf_dev_insert_int_em_entry != NULL) 227 rc = dev->ops->tf_dev_insert_int_em_entry(tfp, parms); 228 else 229 return -EINVAL; 230 231 if (rc) { 232 TFP_DRV_LOG(ERR, 233 "%s: EM insert failed, rc:%s\n", 234 tf_dir_2_str(parms->dir), 235 strerror(-rc)); 236 return rc; 237 } 238 239 return 0; 240 } 241 242 /** Delete EM hash entry API 243 * 244 * returns: 245 * 0 - Success 246 * -EINVAL - Error 247 */ 248 int tf_delete_em_entry(struct tf *tfp, 249 struct tf_delete_em_entry_parms *parms) 250 { 251 struct tf_session *tfs; 252 struct tf_dev_info *dev; 253 int rc; 254 unsigned int flag = 0; 255 256 TF_CHECK_PARMS2(tfp, parms); 257 258 /* Retrieve the session information */ 259 rc = tf_session_get_session(tfp, &tfs); 260 if (rc) { 261 TFP_DRV_LOG(ERR, 262 "%s: Failed to lookup session, rc:%s\n", 263 tf_dir_2_str(parms->dir), 264 strerror(-rc)); 265 return rc; 266 } 267 268 /* Retrieve the device information */ 269 rc = tf_session_get_device(tfs, &dev); 270 if (rc) { 271 TFP_DRV_LOG(ERR, 272 "%s: Failed to lookup device, rc:%s\n", 273 tf_dir_2_str(parms->dir), 274 strerror(-rc)); 275 return rc; 276 } 277 278 TF_GET_FLAG_FROM_FLOW_HANDLE(parms->flow_handle, flag); 279 if ((flag & TF_FLAGS_FLOW_HANDLE_INTERNAL)) 280 rc = dev->ops->tf_dev_delete_int_em_entry(tfp, parms); 281 else 282 rc = dev->ops->tf_dev_delete_ext_em_entry(tfp, parms); 283 284 if (rc) { 285 TFP_DRV_LOG(ERR, 286 "%s: EM delete failed, rc:%s\n", 287 tf_dir_2_str(parms->dir), 288 strerror(-rc)); 289 return rc; 290 } 291 292 return rc; 293 } 294 295 /** Get global configuration API 296 * 297 * returns: 298 * 0 - Success 299 * -EINVAL - Error 300 */ 301 int tf_get_global_cfg(struct tf *tfp, 302 struct tf_global_cfg_parms *parms) 303 { 304 int rc = 0; 305 struct tf_session *tfs; 306 struct tf_dev_info *dev; 307 308 TF_CHECK_PARMS2(tfp, parms); 309 310 /* Retrieve the session information */ 311 rc = tf_session_get_session(tfp, &tfs); 312 if (rc) { 313 TFP_DRV_LOG(ERR, 314 "%s: Failed to lookup session, rc:%s\n", 315 tf_dir_2_str(parms->dir), 316 strerror(-rc)); 317 return rc; 318 } 319 320 /* Retrieve the device information */ 321 rc = tf_session_get_device(tfs, &dev); 322 if (rc) { 323 TFP_DRV_LOG(ERR, 324 "%s: Failed to lookup device, rc:%s\n", 325 tf_dir_2_str(parms->dir), 326 strerror(-rc)); 327 return rc; 328 } 329 330 if (parms->config == NULL || 331 parms->config_sz_in_bytes == 0) { 332 TFP_DRV_LOG(ERR, "Invalid Argument(s)\n"); 333 return -EINVAL; 334 } 335 336 if (dev->ops->tf_dev_get_global_cfg == NULL) { 337 rc = -EOPNOTSUPP; 338 TFP_DRV_LOG(ERR, 339 "%s: Operation not supported, rc:%s\n", 340 tf_dir_2_str(parms->dir), 341 strerror(-rc)); 342 return -EOPNOTSUPP; 343 } 344 345 rc = dev->ops->tf_dev_get_global_cfg(tfp, parms); 346 if (rc) { 347 TFP_DRV_LOG(ERR, 348 "%s: Global Cfg get failed, rc:%s\n", 349 tf_dir_2_str(parms->dir), 350 strerror(-rc)); 351 return rc; 352 } 353 354 return rc; 355 } 356 357 /** Set global configuration API 358 * 359 * returns: 360 * 0 - Success 361 * -EINVAL - Error 362 */ 363 int tf_set_global_cfg(struct tf *tfp, 364 struct tf_global_cfg_parms *parms) 365 { 366 int rc = 0; 367 struct tf_session *tfs; 368 struct tf_dev_info *dev; 369 370 TF_CHECK_PARMS2(tfp, parms); 371 372 /* Retrieve the session information */ 373 rc = tf_session_get_session(tfp, &tfs); 374 if (rc) { 375 TFP_DRV_LOG(ERR, 376 "%s: Failed to lookup session, rc:%s\n", 377 tf_dir_2_str(parms->dir), 378 strerror(-rc)); 379 return rc; 380 } 381 382 /* Retrieve the device information */ 383 rc = tf_session_get_device(tfs, &dev); 384 if (rc) { 385 TFP_DRV_LOG(ERR, 386 "%s: Failed to lookup device, rc:%s\n", 387 tf_dir_2_str(parms->dir), 388 strerror(-rc)); 389 return rc; 390 } 391 392 if (parms->config == NULL || 393 parms->config_sz_in_bytes == 0) { 394 TFP_DRV_LOG(ERR, "Invalid Argument(s)\n"); 395 return -EINVAL; 396 } 397 398 if (dev->ops->tf_dev_set_global_cfg == NULL) { 399 rc = -EOPNOTSUPP; 400 TFP_DRV_LOG(ERR, 401 "%s: Operation not supported, rc:%s\n", 402 tf_dir_2_str(parms->dir), 403 strerror(-rc)); 404 return -EOPNOTSUPP; 405 } 406 407 rc = dev->ops->tf_dev_set_global_cfg(tfp, parms); 408 if (rc) { 409 TFP_DRV_LOG(ERR, 410 "%s: Global Cfg set failed, rc:%s\n", 411 tf_dir_2_str(parms->dir), 412 strerror(-rc)); 413 return rc; 414 } 415 416 return rc; 417 } 418 419 int 420 tf_alloc_identifier(struct tf *tfp, 421 struct tf_alloc_identifier_parms *parms) 422 { 423 int rc; 424 struct tf_session *tfs; 425 struct tf_dev_info *dev; 426 struct tf_ident_alloc_parms aparms; 427 uint16_t id; 428 429 TF_CHECK_PARMS2(tfp, parms); 430 431 /* Can't do static initialization due to UT enum check */ 432 memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms)); 433 434 /* Retrieve the session information */ 435 rc = tf_session_get_session(tfp, &tfs); 436 if (rc) { 437 TFP_DRV_LOG(ERR, 438 "%s: Failed to lookup session, rc:%s\n", 439 tf_dir_2_str(parms->dir), 440 strerror(-rc)); 441 return rc; 442 } 443 444 /* Retrieve the device information */ 445 rc = tf_session_get_device(tfs, &dev); 446 if (rc) { 447 TFP_DRV_LOG(ERR, 448 "%s: Failed to lookup device, rc:%s\n", 449 tf_dir_2_str(parms->dir), 450 strerror(-rc)); 451 return rc; 452 } 453 454 if (dev->ops->tf_dev_alloc_ident == NULL) { 455 rc = -EOPNOTSUPP; 456 TFP_DRV_LOG(ERR, 457 "%s: Operation not supported, rc:%s\n", 458 tf_dir_2_str(parms->dir), 459 strerror(-rc)); 460 return -EOPNOTSUPP; 461 } 462 463 aparms.dir = parms->dir; 464 aparms.type = parms->ident_type; 465 aparms.id = &id; 466 rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms); 467 if (rc) { 468 TFP_DRV_LOG(ERR, 469 "%s: Identifier allocation failed, rc:%s\n", 470 tf_dir_2_str(parms->dir), 471 strerror(-rc)); 472 return rc; 473 } 474 475 parms->id = id; 476 477 return 0; 478 } 479 480 int 481 tf_free_identifier(struct tf *tfp, 482 struct tf_free_identifier_parms *parms) 483 { 484 int rc; 485 struct tf_session *tfs; 486 struct tf_dev_info *dev; 487 struct tf_ident_free_parms fparms; 488 489 TF_CHECK_PARMS2(tfp, parms); 490 491 /* Can't do static initialization due to UT enum check */ 492 memset(&fparms, 0, sizeof(struct tf_ident_free_parms)); 493 494 /* Retrieve the session information */ 495 rc = tf_session_get_session(tfp, &tfs); 496 if (rc) { 497 TFP_DRV_LOG(ERR, 498 "%s: Failed to lookup session, rc:%s\n", 499 tf_dir_2_str(parms->dir), 500 strerror(-rc)); 501 return rc; 502 } 503 504 /* Retrieve the device information */ 505 rc = tf_session_get_device(tfs, &dev); 506 if (rc) { 507 TFP_DRV_LOG(ERR, 508 "%s: Failed to lookup device, rc:%s\n", 509 tf_dir_2_str(parms->dir), 510 strerror(-rc)); 511 return rc; 512 } 513 514 if (dev->ops->tf_dev_free_ident == NULL) { 515 rc = -EOPNOTSUPP; 516 TFP_DRV_LOG(ERR, 517 "%s: Operation not supported, rc:%s\n", 518 tf_dir_2_str(parms->dir), 519 strerror(-rc)); 520 return -EOPNOTSUPP; 521 } 522 523 fparms.dir = parms->dir; 524 fparms.type = parms->ident_type; 525 fparms.id = parms->id; 526 fparms.ref_cnt = &parms->ref_cnt; 527 rc = dev->ops->tf_dev_free_ident(tfp, &fparms); 528 if (rc) { 529 TFP_DRV_LOG(ERR, 530 "%s: Identifier free failed, rc:%s\n", 531 tf_dir_2_str(parms->dir), 532 strerror(-rc)); 533 return rc; 534 } 535 536 return 0; 537 } 538 539 int 540 tf_search_identifier(struct tf *tfp, 541 struct tf_search_identifier_parms *parms) 542 { 543 int rc; 544 struct tf_session *tfs; 545 struct tf_dev_info *dev; 546 struct tf_ident_search_parms sparms; 547 548 TF_CHECK_PARMS2(tfp, parms); 549 550 /* Can't do static initialization due to UT enum check */ 551 memset(&sparms, 0, sizeof(struct tf_ident_search_parms)); 552 553 /* Retrieve the session information */ 554 rc = tf_session_get_session(tfp, &tfs); 555 if (rc) { 556 TFP_DRV_LOG(ERR, 557 "%s: Failed to lookup session, rc:%s\n", 558 tf_dir_2_str(parms->dir), 559 strerror(-rc)); 560 return rc; 561 } 562 563 /* Retrieve the device information */ 564 rc = tf_session_get_device(tfs, &dev); 565 if (rc) { 566 TFP_DRV_LOG(ERR, 567 "%s: Failed to lookup device, rc:%s\n", 568 tf_dir_2_str(parms->dir), 569 strerror(-rc)); 570 return rc; 571 } 572 573 if (dev->ops->tf_dev_search_ident == NULL) { 574 rc = -EOPNOTSUPP; 575 TFP_DRV_LOG(ERR, 576 "%s: Operation not supported, rc:%s\n", 577 tf_dir_2_str(parms->dir), 578 strerror(-rc)); 579 return rc; 580 } 581 582 sparms.dir = parms->dir; 583 sparms.type = parms->ident_type; 584 sparms.search_id = parms->search_id; 585 sparms.hit = &parms->hit; 586 sparms.ref_cnt = &parms->ref_cnt; 587 rc = dev->ops->tf_dev_search_ident(tfp, &sparms); 588 if (rc) { 589 TFP_DRV_LOG(ERR, 590 "%s: Identifier search failed, rc:%s\n", 591 tf_dir_2_str(parms->dir), 592 strerror(-rc)); 593 return rc; 594 } 595 596 return 0; 597 } 598 599 int 600 tf_search_tcam_entry(struct tf *tfp, 601 struct tf_search_tcam_entry_parms *parms) 602 { 603 int rc; 604 struct tf_session *tfs; 605 struct tf_dev_info *dev; 606 struct tf_tcam_alloc_search_parms sparms; 607 608 TF_CHECK_PARMS2(tfp, parms); 609 610 memset(&sparms, 0, sizeof(struct tf_tcam_alloc_search_parms)); 611 612 /* Retrieve the session information */ 613 rc = tf_session_get_session(tfp, &tfs); 614 if (rc) { 615 TFP_DRV_LOG(ERR, 616 "%s: Failed to lookup session, rc:%s\n", 617 tf_dir_2_str(parms->dir), 618 strerror(-rc)); 619 return rc; 620 } 621 622 /* Retrieve the device information */ 623 rc = tf_session_get_device(tfs, &dev); 624 if (rc) { 625 TFP_DRV_LOG(ERR, 626 "%s: Failed to lookup device, rc:%s\n", 627 tf_dir_2_str(parms->dir), 628 strerror(-rc)); 629 return rc; 630 } 631 632 if (dev->ops->tf_dev_alloc_search_tcam == NULL) { 633 rc = -EOPNOTSUPP; 634 TFP_DRV_LOG(ERR, 635 "%s: Operation not supported, rc:%s\n", 636 tf_dir_2_str(parms->dir), 637 strerror(-rc)); 638 return rc; 639 } 640 641 sparms.dir = parms->dir; 642 sparms.type = parms->tcam_tbl_type; 643 sparms.key = parms->key; 644 sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits); 645 sparms.mask = parms->mask; 646 sparms.priority = parms->priority; 647 sparms.alloc = parms->alloc; 648 649 /* Result is an in/out and so no need to copy during outputs */ 650 sparms.result = parms->result; 651 sparms.result_size = 652 TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits); 653 654 rc = dev->ops->tf_dev_alloc_search_tcam(tfp, &sparms); 655 if (rc) { 656 TFP_DRV_LOG(ERR, 657 "%s: TCAM allocation failed, rc:%s\n", 658 tf_dir_2_str(parms->dir), 659 strerror(-rc)); 660 return rc; 661 } 662 663 /* Copy the outputs */ 664 parms->hit = sparms.hit; 665 parms->search_status = sparms.search_status; 666 parms->ref_cnt = sparms.ref_cnt; 667 parms->idx = sparms.idx; 668 669 return 0; 670 } 671 672 int 673 tf_alloc_tcam_entry(struct tf *tfp, 674 struct tf_alloc_tcam_entry_parms *parms) 675 { 676 int rc; 677 struct tf_session *tfs; 678 struct tf_dev_info *dev; 679 struct tf_tcam_alloc_parms aparms; 680 681 TF_CHECK_PARMS2(tfp, parms); 682 683 memset(&aparms, 0, sizeof(struct tf_tcam_alloc_parms)); 684 685 /* Retrieve the session information */ 686 rc = tf_session_get_session(tfp, &tfs); 687 if (rc) { 688 TFP_DRV_LOG(ERR, 689 "%s: Failed to lookup session, rc:%s\n", 690 tf_dir_2_str(parms->dir), 691 strerror(-rc)); 692 return rc; 693 } 694 695 /* Retrieve the device information */ 696 rc = tf_session_get_device(tfs, &dev); 697 if (rc) { 698 TFP_DRV_LOG(ERR, 699 "%s: Failed to lookup device, rc:%s\n", 700 tf_dir_2_str(parms->dir), 701 strerror(-rc)); 702 return rc; 703 } 704 705 if (dev->ops->tf_dev_alloc_tcam == NULL) { 706 rc = -EOPNOTSUPP; 707 TFP_DRV_LOG(ERR, 708 "%s: Operation not supported, rc:%s\n", 709 tf_dir_2_str(parms->dir), 710 strerror(-rc)); 711 return rc; 712 } 713 714 aparms.dir = parms->dir; 715 aparms.type = parms->tcam_tbl_type; 716 aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits); 717 aparms.priority = parms->priority; 718 rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms); 719 if (rc) { 720 TFP_DRV_LOG(ERR, 721 "%s: TCAM allocation failed, rc:%s\n", 722 tf_dir_2_str(parms->dir), 723 strerror(-rc)); 724 return rc; 725 } 726 727 parms->idx = aparms.idx; 728 729 return 0; 730 } 731 732 int 733 tf_set_tcam_entry(struct tf *tfp, 734 struct tf_set_tcam_entry_parms *parms) 735 { 736 int rc; 737 struct tf_session *tfs; 738 struct tf_dev_info *dev; 739 struct tf_tcam_set_parms sparms; 740 741 TF_CHECK_PARMS2(tfp, parms); 742 743 memset(&sparms, 0, sizeof(struct tf_tcam_set_parms)); 744 745 /* Retrieve the session information */ 746 rc = tf_session_get_session(tfp, &tfs); 747 if (rc) { 748 TFP_DRV_LOG(ERR, 749 "%s: Failed to lookup session, rc:%s\n", 750 tf_dir_2_str(parms->dir), 751 strerror(-rc)); 752 return rc; 753 } 754 755 /* Retrieve the device information */ 756 rc = tf_session_get_device(tfs, &dev); 757 if (rc) { 758 TFP_DRV_LOG(ERR, 759 "%s: Failed to lookup device, rc:%s\n", 760 tf_dir_2_str(parms->dir), 761 strerror(-rc)); 762 return rc; 763 } 764 765 if (dev->ops->tf_dev_set_tcam == NULL || 766 dev->ops->tf_dev_word_align == NULL) { 767 rc = -EOPNOTSUPP; 768 TFP_DRV_LOG(ERR, 769 "%s: Operation not supported, rc:%s\n", 770 tf_dir_2_str(parms->dir), 771 strerror(-rc)); 772 return rc; 773 } 774 775 sparms.dir = parms->dir; 776 sparms.type = parms->tcam_tbl_type; 777 sparms.idx = parms->idx; 778 sparms.key = parms->key; 779 sparms.mask = parms->mask; 780 sparms.key_size = dev->ops->tf_dev_word_align(parms->key_sz_in_bits); 781 sparms.result = parms->result; 782 sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits); 783 784 rc = dev->ops->tf_dev_set_tcam(tfp, &sparms); 785 if (rc) { 786 TFP_DRV_LOG(ERR, 787 "%s: TCAM set failed, rc:%s\n", 788 tf_dir_2_str(parms->dir), 789 strerror(-rc)); 790 return rc; 791 } 792 TFP_DRV_LOG(DEBUG, 793 "%s: TCAM type %d set idx:%d key size %d result size %d\n", 794 tf_dir_2_str(parms->dir), sparms.type, 795 sparms.idx, sparms.key_size, sparms.result_size); 796 797 return 0; 798 } 799 800 int 801 tf_get_tcam_entry(struct tf *tfp __rte_unused, 802 struct tf_get_tcam_entry_parms *parms) 803 { 804 int rc; 805 struct tf_session *tfs; 806 struct tf_dev_info *dev; 807 struct tf_tcam_get_parms gparms; 808 809 TF_CHECK_PARMS2(tfp, parms); 810 811 memset(&gparms, 0, sizeof(struct tf_tcam_get_parms)); 812 813 /* Retrieve the session information */ 814 rc = tf_session_get_session(tfp, &tfs); 815 if (rc) { 816 TFP_DRV_LOG(ERR, 817 "%s: Failed to lookup session, rc:%s\n", 818 tf_dir_2_str(parms->dir), 819 strerror(-rc)); 820 return rc; 821 } 822 823 /* Retrieve the device information */ 824 rc = tf_session_get_device(tfs, &dev); 825 if (rc) { 826 TFP_DRV_LOG(ERR, 827 "%s: Failed to lookup device, rc:%s\n", 828 tf_dir_2_str(parms->dir), 829 strerror(-rc)); 830 return rc; 831 } 832 833 if (dev->ops->tf_dev_get_tcam == NULL) { 834 rc = -EOPNOTSUPP; 835 TFP_DRV_LOG(ERR, 836 "%s: Operation not supported, rc:%s\n", 837 tf_dir_2_str(parms->dir), 838 strerror(-rc)); 839 return rc; 840 } 841 842 gparms.dir = parms->dir; 843 gparms.type = parms->tcam_tbl_type; 844 gparms.idx = parms->idx; 845 gparms.key = parms->key; 846 gparms.key_size = dev->ops->tf_dev_word_align(parms->key_sz_in_bits); 847 gparms.mask = parms->mask; 848 gparms.result = parms->result; 849 gparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits); 850 851 rc = dev->ops->tf_dev_get_tcam(tfp, &gparms); 852 if (rc) { 853 TFP_DRV_LOG(ERR, 854 "%s: TCAM get failed, rc:%s\n", 855 tf_dir_2_str(parms->dir), 856 strerror(-rc)); 857 return rc; 858 } 859 parms->key_sz_in_bits = gparms.key_size * 8; 860 parms->result_sz_in_bits = gparms.result_size * 8; 861 862 return 0; 863 } 864 865 int 866 tf_free_tcam_entry(struct tf *tfp, 867 struct tf_free_tcam_entry_parms *parms) 868 { 869 int rc; 870 struct tf_session *tfs; 871 struct tf_dev_info *dev; 872 struct tf_tcam_free_parms fparms; 873 874 TF_CHECK_PARMS2(tfp, parms); 875 876 memset(&fparms, 0, sizeof(struct tf_tcam_free_parms)); 877 878 /* Retrieve the session information */ 879 rc = tf_session_get_session(tfp, &tfs); 880 if (rc) { 881 TFP_DRV_LOG(ERR, 882 "%s: Failed to lookup session, rc:%s\n", 883 tf_dir_2_str(parms->dir), 884 strerror(-rc)); 885 return rc; 886 } 887 888 /* Retrieve the device information */ 889 rc = tf_session_get_device(tfs, &dev); 890 if (rc) { 891 TFP_DRV_LOG(ERR, 892 "%s: Failed to lookup device, rc:%s\n", 893 tf_dir_2_str(parms->dir), 894 strerror(-rc)); 895 return rc; 896 } 897 898 if (dev->ops->tf_dev_free_tcam == NULL) { 899 rc = -EOPNOTSUPP; 900 TFP_DRV_LOG(ERR, 901 "%s: Operation not supported, rc:%s\n", 902 tf_dir_2_str(parms->dir), 903 strerror(-rc)); 904 return rc; 905 } 906 907 fparms.dir = parms->dir; 908 fparms.type = parms->tcam_tbl_type; 909 fparms.idx = parms->idx; 910 rc = dev->ops->tf_dev_free_tcam(tfp, &fparms); 911 if (rc) { 912 TFP_DRV_LOG(ERR, 913 "%s: TCAM free failed, rc:%s\n", 914 tf_dir_2_str(parms->dir), 915 strerror(-rc)); 916 return rc; 917 } 918 919 return 0; 920 } 921 922 int 923 tf_move_tcam_shared_entries(struct tf *tfp, 924 struct tf_move_tcam_shared_entries_parms *parms) 925 { 926 int rc; 927 struct tf_session *tfs; 928 struct tf_dev_info *dev; 929 930 TF_CHECK_PARMS2(tfp, parms); 931 932 /* Retrieve the session information */ 933 rc = tf_session_get_session(tfp, &tfs); 934 if (rc) { 935 TFP_DRV_LOG(ERR, 936 "%s: Failed to lookup session, rc:%s\n", 937 tf_dir_2_str(parms->dir), 938 strerror(-rc)); 939 return rc; 940 } 941 942 /* Retrieve the device information */ 943 rc = tf_session_get_device(tfs, &dev); 944 if (rc) { 945 TFP_DRV_LOG(ERR, 946 "%s: Failed to lookup device, rc:%s\n", 947 tf_dir_2_str(parms->dir), 948 strerror(-rc)); 949 return rc; 950 } 951 952 if (dev->ops->tf_dev_move_tcam == NULL) { 953 rc = -EOPNOTSUPP; 954 TFP_DRV_LOG(ERR, 955 "%s: Operation not supported, rc:%s\n", 956 tf_dir_2_str(parms->dir), 957 strerror(-rc)); 958 return rc; 959 } 960 961 rc = dev->ops->tf_dev_move_tcam(tfp, parms); 962 if (rc) { 963 TFP_DRV_LOG(ERR, 964 "%s: TCAM shared entries move failed, rc:%s\n", 965 tf_dir_2_str(parms->dir), 966 strerror(-rc)); 967 return rc; 968 } 969 970 return 0; 971 } 972 973 int 974 tf_clear_tcam_shared_entries(struct tf *tfp, 975 struct tf_clear_tcam_shared_entries_parms *parms) 976 { 977 int rc; 978 struct tf_session *tfs; 979 struct tf_dev_info *dev; 980 981 TF_CHECK_PARMS2(tfp, parms); 982 983 /* Retrieve the session information */ 984 rc = tf_session_get_session(tfp, &tfs); 985 if (rc) { 986 TFP_DRV_LOG(ERR, 987 "%s: Failed to lookup session, rc:%s\n", 988 tf_dir_2_str(parms->dir), 989 strerror(-rc)); 990 return rc; 991 } 992 993 /* Retrieve the device information */ 994 rc = tf_session_get_device(tfs, &dev); 995 if (rc) { 996 TFP_DRV_LOG(ERR, 997 "%s: Failed to lookup device, rc:%s\n", 998 tf_dir_2_str(parms->dir), 999 strerror(-rc)); 1000 return rc; 1001 } 1002 1003 if (dev->ops->tf_dev_clear_tcam == NULL) { 1004 rc = -EOPNOTSUPP; 1005 TFP_DRV_LOG(ERR, 1006 "%s: Operation not supported, rc:%s\n", 1007 tf_dir_2_str(parms->dir), 1008 strerror(-rc)); 1009 return rc; 1010 } 1011 1012 rc = dev->ops->tf_dev_clear_tcam(tfp, parms); 1013 if (rc) { 1014 TFP_DRV_LOG(ERR, 1015 "%s: TCAM shared entries clear failed, rc:%s\n", 1016 tf_dir_2_str(parms->dir), 1017 strerror(-rc)); 1018 return rc; 1019 } 1020 1021 return 0; 1022 } 1023 1024 int 1025 tf_alloc_tbl_entry(struct tf *tfp, 1026 struct tf_alloc_tbl_entry_parms *parms) 1027 { 1028 int rc; 1029 struct tf_session *tfs; 1030 struct tf_dev_info *dev; 1031 struct tf_tbl_alloc_parms aparms; 1032 uint32_t idx; 1033 1034 TF_CHECK_PARMS2(tfp, parms); 1035 1036 /* Can't do static initialization due to UT enum check */ 1037 memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms)); 1038 1039 /* Retrieve the session information */ 1040 rc = tf_session_get_session(tfp, &tfs); 1041 if (rc) { 1042 TFP_DRV_LOG(ERR, 1043 "%s: Failed to lookup session, rc:%s\n", 1044 tf_dir_2_str(parms->dir), 1045 strerror(-rc)); 1046 return rc; 1047 } 1048 1049 /* Retrieve the device information */ 1050 rc = tf_session_get_device(tfs, &dev); 1051 if (rc) { 1052 TFP_DRV_LOG(ERR, 1053 "%s: Failed to lookup device, rc:%s\n", 1054 tf_dir_2_str(parms->dir), 1055 strerror(-rc)); 1056 return rc; 1057 } 1058 1059 aparms.dir = parms->dir; 1060 aparms.type = parms->type; 1061 aparms.idx = &idx; 1062 aparms.tbl_scope_id = parms->tbl_scope_id; 1063 1064 if (parms->type == TF_TBL_TYPE_EXT) { 1065 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) { 1066 rc = -EOPNOTSUPP; 1067 TFP_DRV_LOG(ERR, 1068 "%s: Operation not supported, rc:%s\n", 1069 tf_dir_2_str(parms->dir), 1070 strerror(-rc)); 1071 return -EOPNOTSUPP; 1072 } 1073 1074 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms); 1075 if (rc) { 1076 TFP_DRV_LOG(ERR, 1077 "%s: External table allocation failed, rc:%s\n", 1078 tf_dir_2_str(parms->dir), 1079 strerror(-rc)); 1080 return rc; 1081 } 1082 } else if (dev->ops->tf_dev_is_sram_managed(tfp, parms->type)) { 1083 rc = dev->ops->tf_dev_alloc_sram_tbl(tfp, &aparms); 1084 if (rc) { 1085 TFP_DRV_LOG(ERR, 1086 "%s: SRAM table allocation failed, rc:%s\n", 1087 tf_dir_2_str(parms->dir), 1088 strerror(-rc)); 1089 return rc; 1090 } 1091 } else { 1092 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms); 1093 if (rc) { 1094 TFP_DRV_LOG(ERR, 1095 "%s: Table allocation failed, rc:%s\n", 1096 tf_dir_2_str(parms->dir), 1097 strerror(-rc)); 1098 return rc; 1099 } 1100 } 1101 1102 parms->idx = idx; 1103 1104 #ifdef TF_FLOW_SCALE_QUERY 1105 /* Update resource usage buffer */ 1106 if (!rc && dev->ops->tf_dev_update_tbl_usage_buffer) { 1107 rc = dev->ops->tf_dev_update_tbl_usage_buffer(tfp, 1108 parms->dir, 1109 parms->type, 1110 TF_RESC_ALLOC); 1111 if (rc) { 1112 TFP_DRV_LOG(DEBUG, 1113 "%s: Table usage update failed!\n", 1114 tf_dir_2_str(parms->dir)); 1115 } 1116 } 1117 #endif /* TF_FLOW_SCALE_QUERY */ 1118 1119 return 0; 1120 } 1121 1122 int 1123 tf_free_tbl_entry(struct tf *tfp, 1124 struct tf_free_tbl_entry_parms *parms) 1125 { 1126 int rc; 1127 struct tf_session *tfs; 1128 struct tf_dev_info *dev; 1129 struct tf_tbl_free_parms fparms; 1130 1131 TF_CHECK_PARMS2(tfp, parms); 1132 1133 /* Can't do static initialization due to UT enum check */ 1134 memset(&fparms, 0, sizeof(struct tf_tbl_free_parms)); 1135 1136 /* Retrieve the session information */ 1137 rc = tf_session_get_session(tfp, &tfs); 1138 if (rc) { 1139 TFP_DRV_LOG(ERR, 1140 "%s: Failed to lookup session, rc:%s\n", 1141 tf_dir_2_str(parms->dir), 1142 strerror(-rc)); 1143 return rc; 1144 } 1145 1146 /* Retrieve the device information */ 1147 rc = tf_session_get_device(tfs, &dev); 1148 if (rc) { 1149 TFP_DRV_LOG(ERR, 1150 "%s: Failed to lookup device, rc:%s\n", 1151 tf_dir_2_str(parms->dir), 1152 strerror(-rc)); 1153 return rc; 1154 } 1155 1156 fparms.dir = parms->dir; 1157 fparms.type = parms->type; 1158 fparms.idx = parms->idx; 1159 fparms.tbl_scope_id = parms->tbl_scope_id; 1160 1161 if (parms->type == TF_TBL_TYPE_EXT) { 1162 if (dev->ops->tf_dev_free_ext_tbl == NULL) { 1163 rc = -EOPNOTSUPP; 1164 TFP_DRV_LOG(ERR, 1165 "%s: Operation not supported, rc:%s\n", 1166 tf_dir_2_str(parms->dir), 1167 strerror(-rc)); 1168 return -EOPNOTSUPP; 1169 } 1170 1171 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms); 1172 if (rc) { 1173 TFP_DRV_LOG(ERR, 1174 "%s: Table free failed, rc:%s\n", 1175 tf_dir_2_str(parms->dir), 1176 strerror(-rc)); 1177 return rc; 1178 } 1179 } else if (dev->ops->tf_dev_is_sram_managed(tfp, parms->type)) { 1180 rc = dev->ops->tf_dev_free_sram_tbl(tfp, &fparms); 1181 if (rc) { 1182 TFP_DRV_LOG(ERR, 1183 "%s: SRAM table free failed, rc:%s\n", 1184 tf_dir_2_str(parms->dir), 1185 strerror(-rc)); 1186 return rc; 1187 } 1188 } else { 1189 1190 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms); 1191 if (rc) { 1192 TFP_DRV_LOG(ERR, 1193 "%s: Table free failed, rc:%s\n", 1194 tf_dir_2_str(parms->dir), 1195 strerror(-rc)); 1196 return rc; 1197 } 1198 } 1199 1200 #ifdef TF_FLOW_SCALE_QUERY 1201 /* Update resource usage buffer */ 1202 if (!rc && dev->ops->tf_dev_update_tbl_usage_buffer) { 1203 rc = dev->ops->tf_dev_update_tbl_usage_buffer(tfp, 1204 parms->dir, 1205 parms->type, 1206 TF_RESC_FREE); 1207 if (rc) { 1208 TFP_DRV_LOG(DEBUG, 1209 "%s: Table usage update failed!\n", 1210 tf_dir_2_str(parms->dir)); 1211 } 1212 } 1213 #endif /* TF_FLOW_SCALE_QUERY */ 1214 1215 return 0; 1216 } 1217 1218 int 1219 tf_set_tbl_entry(struct tf *tfp, 1220 struct tf_set_tbl_entry_parms *parms) 1221 { 1222 int rc = 0; 1223 struct tf_session *tfs; 1224 struct tf_dev_info *dev; 1225 struct tf_tbl_set_parms sparms; 1226 1227 TF_CHECK_PARMS3(tfp, parms, parms->data); 1228 1229 /* Can't do static initialization due to UT enum check */ 1230 memset(&sparms, 0, sizeof(struct tf_tbl_set_parms)); 1231 1232 /* Retrieve the session information */ 1233 rc = tf_session_get_session(tfp, &tfs); 1234 if (rc) { 1235 TFP_DRV_LOG(ERR, 1236 "%s: Failed to lookup session, rc:%s\n", 1237 tf_dir_2_str(parms->dir), 1238 strerror(-rc)); 1239 return rc; 1240 } 1241 1242 /* Retrieve the device information */ 1243 rc = tf_session_get_device(tfs, &dev); 1244 if (rc) { 1245 TFP_DRV_LOG(ERR, 1246 "%s: Failed to lookup device, rc:%s\n", 1247 tf_dir_2_str(parms->dir), 1248 strerror(-rc)); 1249 return rc; 1250 } 1251 1252 sparms.dir = parms->dir; 1253 sparms.type = parms->type; 1254 sparms.data = parms->data; 1255 sparms.data_sz_in_bytes = parms->data_sz_in_bytes; 1256 sparms.idx = parms->idx; 1257 sparms.tbl_scope_id = parms->tbl_scope_id; 1258 1259 if (parms->type == TF_TBL_TYPE_EXT) { 1260 if (dev->ops->tf_dev_set_ext_tbl == NULL) { 1261 rc = -EOPNOTSUPP; 1262 TFP_DRV_LOG(ERR, 1263 "%s: Operation not supported, rc:%s\n", 1264 tf_dir_2_str(parms->dir), 1265 strerror(-rc)); 1266 return -EOPNOTSUPP; 1267 } 1268 1269 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms); 1270 if (rc) { 1271 TFP_DRV_LOG(ERR, 1272 "%s: Table set failed, rc:%s\n", 1273 tf_dir_2_str(parms->dir), 1274 strerror(-rc)); 1275 return rc; 1276 } 1277 } else if (dev->ops->tf_dev_is_sram_managed(tfp, parms->type)) { 1278 rc = dev->ops->tf_dev_set_sram_tbl(tfp, &sparms); 1279 if (rc) { 1280 TFP_DRV_LOG(ERR, 1281 "%s: SRAM table set failed, rc:%s\n", 1282 tf_dir_2_str(parms->dir), 1283 strerror(-rc)); 1284 return rc; 1285 } 1286 } else { 1287 if (dev->ops->tf_dev_set_tbl == NULL) { 1288 rc = -EOPNOTSUPP; 1289 TFP_DRV_LOG(ERR, 1290 "%s: Operation not supported, rc:%s\n", 1291 tf_dir_2_str(parms->dir), 1292 strerror(-rc)); 1293 return -EOPNOTSUPP; 1294 } 1295 1296 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms); 1297 if (rc) { 1298 TFP_DRV_LOG(ERR, 1299 "%s: Table set failed, rc:%s\n", 1300 tf_dir_2_str(parms->dir), 1301 strerror(-rc)); 1302 return rc; 1303 } 1304 } 1305 1306 return rc; 1307 } 1308 1309 int 1310 tf_get_tbl_entry(struct tf *tfp, 1311 struct tf_get_tbl_entry_parms *parms) 1312 { 1313 int rc = 0; 1314 struct tf_session *tfs; 1315 struct tf_dev_info *dev; 1316 struct tf_tbl_get_parms gparms; 1317 1318 TF_CHECK_PARMS3(tfp, parms, parms->data); 1319 1320 /* Can't do static initialization due to UT enum check */ 1321 memset(&gparms, 0, sizeof(struct tf_tbl_get_parms)); 1322 1323 /* Retrieve the session information */ 1324 rc = tf_session_get_session(tfp, &tfs); 1325 if (rc) { 1326 TFP_DRV_LOG(ERR, 1327 "%s: Failed to lookup session, rc:%s\n", 1328 tf_dir_2_str(parms->dir), 1329 strerror(-rc)); 1330 return rc; 1331 } 1332 1333 /* Retrieve the device information */ 1334 rc = tf_session_get_device(tfs, &dev); 1335 if (rc) { 1336 TFP_DRV_LOG(ERR, 1337 "%s: Failed to lookup device, rc:%s\n", 1338 tf_dir_2_str(parms->dir), 1339 strerror(-rc)); 1340 return rc; 1341 } 1342 gparms.dir = parms->dir; 1343 gparms.type = parms->type; 1344 gparms.data = parms->data; 1345 gparms.data_sz_in_bytes = parms->data_sz_in_bytes; 1346 gparms.idx = parms->idx; 1347 1348 if (dev->ops->tf_dev_is_sram_managed(tfp, parms->type)) { 1349 rc = dev->ops->tf_dev_get_sram_tbl(tfp, &gparms); 1350 if (rc) { 1351 TFP_DRV_LOG(ERR, 1352 "%s: SRAM table get failed, rc:%s\n", 1353 tf_dir_2_str(parms->dir), 1354 strerror(-rc)); 1355 return rc; 1356 } 1357 } else { 1358 if (dev->ops->tf_dev_get_tbl == NULL) { 1359 rc = -EOPNOTSUPP; 1360 TFP_DRV_LOG(ERR, 1361 "%s: Operation not supported, rc:%s\n", 1362 tf_dir_2_str(parms->dir), 1363 strerror(-rc)); 1364 return -EOPNOTSUPP; 1365 } 1366 1367 rc = dev->ops->tf_dev_get_tbl(tfp, &gparms); 1368 if (rc) { 1369 TFP_DRV_LOG(ERR, 1370 "%s: Table get failed, rc:%s\n", 1371 tf_dir_2_str(parms->dir), 1372 strerror(-rc)); 1373 return rc; 1374 } 1375 } 1376 1377 return rc; 1378 } 1379 1380 int 1381 tf_bulk_get_tbl_entry(struct tf *tfp, 1382 struct tf_bulk_get_tbl_entry_parms *parms) 1383 { 1384 int rc = 0; 1385 struct tf_session *tfs; 1386 struct tf_dev_info *dev; 1387 struct tf_tbl_get_bulk_parms bparms; 1388 1389 TF_CHECK_PARMS2(tfp, parms); 1390 1391 /* Can't do static initialization due to UT enum check */ 1392 memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms)); 1393 1394 /* Retrieve the session information */ 1395 rc = tf_session_get_session(tfp, &tfs); 1396 if (rc) { 1397 TFP_DRV_LOG(ERR, 1398 "%s: Failed to lookup session, rc:%s\n", 1399 tf_dir_2_str(parms->dir), 1400 strerror(-rc)); 1401 return rc; 1402 } 1403 1404 /* Retrieve the device information */ 1405 rc = tf_session_get_device(tfs, &dev); 1406 if (rc) { 1407 TFP_DRV_LOG(ERR, 1408 "%s: Failed to lookup device, rc:%s\n", 1409 tf_dir_2_str(parms->dir), 1410 strerror(-rc)); 1411 return rc; 1412 } 1413 1414 bparms.dir = parms->dir; 1415 bparms.type = parms->type; 1416 bparms.starting_idx = parms->starting_idx; 1417 bparms.num_entries = parms->num_entries; 1418 bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes; 1419 bparms.physical_mem_addr = parms->physical_mem_addr; 1420 1421 if (parms->type == TF_TBL_TYPE_EXT) { 1422 /* Not supported, yet */ 1423 rc = -EOPNOTSUPP; 1424 TFP_DRV_LOG(ERR, 1425 "%s, External table type not supported, rc:%s\n", 1426 tf_dir_2_str(parms->dir), 1427 strerror(-rc)); 1428 1429 return rc; 1430 } else if (dev->ops->tf_dev_is_sram_managed(tfp, parms->type)) { 1431 rc = dev->ops->tf_dev_get_bulk_sram_tbl(tfp, &bparms); 1432 if (rc) { 1433 TFP_DRV_LOG(ERR, 1434 "%s: SRAM table bulk get failed, rc:%s\n", 1435 tf_dir_2_str(parms->dir), 1436 strerror(-rc)); 1437 } 1438 return rc; 1439 } 1440 1441 if (dev->ops->tf_dev_get_bulk_tbl == NULL) { 1442 rc = -EOPNOTSUPP; 1443 TFP_DRV_LOG(ERR, 1444 "%s: Operation not supported, rc:%s\n", 1445 tf_dir_2_str(parms->dir), 1446 strerror(-rc)); 1447 return -EOPNOTSUPP; 1448 } 1449 1450 rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms); 1451 if (rc) { 1452 TFP_DRV_LOG(ERR, 1453 "%s: Table get bulk failed, rc:%s\n", 1454 tf_dir_2_str(parms->dir), 1455 strerror(-rc)); 1456 return rc; 1457 } 1458 return rc; 1459 } 1460 1461 int tf_get_shared_tbl_increment(struct tf *tfp, 1462 struct tf_get_shared_tbl_increment_parms *parms) 1463 { 1464 int rc = 0; 1465 struct tf_session *tfs; 1466 struct tf_dev_info *dev; 1467 1468 TF_CHECK_PARMS2(tfp, parms); 1469 1470 /* Retrieve the session information */ 1471 rc = tf_session_get_session(tfp, &tfs); 1472 if (rc) { 1473 TFP_DRV_LOG(ERR, 1474 "%s: Failed to lookup session, rc:%s\n", 1475 tf_dir_2_str(parms->dir), 1476 strerror(-rc)); 1477 return rc; 1478 } 1479 1480 /* Retrieve the device information */ 1481 rc = tf_session_get_device(tfs, &dev); 1482 if (rc) { 1483 TFP_DRV_LOG(ERR, 1484 "%s: Failed to lookup device, rc:%s\n", 1485 tf_dir_2_str(parms->dir), 1486 strerror(-rc)); 1487 return rc; 1488 } 1489 1490 /* Internal table type processing */ 1491 1492 if (dev->ops->tf_dev_get_shared_tbl_increment == NULL) { 1493 rc = -EOPNOTSUPP; 1494 TFP_DRV_LOG(ERR, 1495 "%s: Operation not supported, rc:%s\n", 1496 tf_dir_2_str(parms->dir), 1497 strerror(-rc)); 1498 return -EOPNOTSUPP; 1499 } 1500 1501 rc = dev->ops->tf_dev_get_shared_tbl_increment(tfp, parms); 1502 if (rc) { 1503 TFP_DRV_LOG(ERR, 1504 "%s: Get table increment not supported, rc:%s\n", 1505 tf_dir_2_str(parms->dir), 1506 strerror(-rc)); 1507 return rc; 1508 } 1509 1510 return rc; 1511 } 1512 1513 int 1514 tf_alloc_tbl_scope(struct tf *tfp, 1515 struct tf_alloc_tbl_scope_parms *parms) 1516 { 1517 struct tf_session *tfs; 1518 struct tf_dev_info *dev; 1519 int rc; 1520 1521 TF_CHECK_PARMS2(tfp, parms); 1522 1523 /* Retrieve the session information */ 1524 rc = tf_session_get_session(tfp, &tfs); 1525 if (rc) { 1526 TFP_DRV_LOG(ERR, 1527 "Failed to lookup session, rc:%s\n", 1528 strerror(-rc)); 1529 return rc; 1530 } 1531 1532 /* Retrieve the device information */ 1533 rc = tf_session_get_device(tfs, &dev); 1534 if (rc) { 1535 TFP_DRV_LOG(ERR, 1536 "Failed to lookup device, rc:%s\n", 1537 strerror(-rc)); 1538 return rc; 1539 } 1540 1541 if (dev->ops->tf_dev_alloc_tbl_scope != NULL) { 1542 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms); 1543 } else { 1544 TFP_DRV_LOG(ERR, 1545 "Alloc table scope not supported by device\n"); 1546 return -EINVAL; 1547 } 1548 1549 return rc; 1550 } 1551 int 1552 tf_map_tbl_scope(struct tf *tfp, 1553 struct tf_map_tbl_scope_parms *parms) 1554 { 1555 struct tf_session *tfs; 1556 struct tf_dev_info *dev; 1557 int rc; 1558 1559 TF_CHECK_PARMS2(tfp, parms); 1560 1561 /* Retrieve the session information */ 1562 rc = tf_session_get_session(tfp, &tfs); 1563 if (rc) { 1564 TFP_DRV_LOG(ERR, 1565 "Failed to lookup session, rc:%s\n", 1566 strerror(-rc)); 1567 return rc; 1568 } 1569 1570 /* Retrieve the device information */ 1571 rc = tf_session_get_device(tfs, &dev); 1572 if (rc) { 1573 TFP_DRV_LOG(ERR, 1574 "Failed to lookup device, rc:%s\n", 1575 strerror(-rc)); 1576 return rc; 1577 } 1578 1579 if (dev->ops->tf_dev_map_tbl_scope != NULL) { 1580 rc = dev->ops->tf_dev_map_tbl_scope(tfp, parms); 1581 } else { 1582 TFP_DRV_LOG(ERR, 1583 "Map table scope not supported by device\n"); 1584 return -EINVAL; 1585 } 1586 1587 return rc; 1588 } 1589 1590 int 1591 tf_free_tbl_scope(struct tf *tfp, 1592 struct tf_free_tbl_scope_parms *parms) 1593 { 1594 struct tf_session *tfs; 1595 struct tf_dev_info *dev; 1596 int rc; 1597 1598 TF_CHECK_PARMS2(tfp, parms); 1599 1600 /* Retrieve the session information */ 1601 rc = tf_session_get_session(tfp, &tfs); 1602 if (rc) { 1603 TFP_DRV_LOG(ERR, 1604 "Failed to lookup session, rc:%s\n", 1605 strerror(-rc)); 1606 return rc; 1607 } 1608 1609 /* Retrieve the device information */ 1610 rc = tf_session_get_device(tfs, &dev); 1611 if (rc) { 1612 TFP_DRV_LOG(ERR, 1613 "Failed to lookup device, rc:%s\n", 1614 strerror(-rc)); 1615 return rc; 1616 } 1617 1618 if (dev->ops->tf_dev_free_tbl_scope) { 1619 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms); 1620 } else { 1621 TFP_DRV_LOG(ERR, 1622 "Free table scope not supported by device\n"); 1623 return -EINVAL; 1624 } 1625 1626 return rc; 1627 } 1628 1629 int 1630 tf_set_if_tbl_entry(struct tf *tfp, 1631 struct tf_set_if_tbl_entry_parms *parms) 1632 { 1633 int rc; 1634 struct tf_session *tfs; 1635 struct tf_dev_info *dev; 1636 struct tf_if_tbl_set_parms sparms = { 0 }; 1637 1638 TF_CHECK_PARMS2(tfp, parms); 1639 1640 /* Retrieve the session information */ 1641 rc = tf_session_get_session(tfp, &tfs); 1642 if (rc) { 1643 TFP_DRV_LOG(ERR, 1644 "%s: Failed to lookup session, rc:%s\n", 1645 tf_dir_2_str(parms->dir), 1646 strerror(-rc)); 1647 return rc; 1648 } 1649 1650 /* Retrieve the device information */ 1651 rc = tf_session_get_device(tfs, &dev); 1652 if (rc) { 1653 TFP_DRV_LOG(ERR, 1654 "%s: Failed to lookup device, rc:%s\n", 1655 tf_dir_2_str(parms->dir), 1656 strerror(-rc)); 1657 return rc; 1658 } 1659 1660 if (dev->ops->tf_dev_set_if_tbl == NULL) { 1661 rc = -EOPNOTSUPP; 1662 TFP_DRV_LOG(ERR, 1663 "%s: Operation not supported, rc:%s\n", 1664 tf_dir_2_str(parms->dir), 1665 strerror(-rc)); 1666 return rc; 1667 } 1668 1669 sparms.dir = parms->dir; 1670 sparms.type = parms->type; 1671 sparms.idx = parms->idx; 1672 sparms.data_sz_in_bytes = parms->data_sz_in_bytes; 1673 sparms.data = parms->data; 1674 1675 rc = dev->ops->tf_dev_set_if_tbl(tfp, &sparms); 1676 if (rc) { 1677 TFP_DRV_LOG(ERR, 1678 "%s: If_tbl set failed, rc:%s\n", 1679 tf_dir_2_str(parms->dir), 1680 strerror(-rc)); 1681 return rc; 1682 } 1683 1684 return 0; 1685 } 1686 1687 int 1688 tf_get_if_tbl_entry(struct tf *tfp, 1689 struct tf_get_if_tbl_entry_parms *parms) 1690 { 1691 int rc; 1692 struct tf_session *tfs; 1693 struct tf_dev_info *dev; 1694 struct tf_if_tbl_get_parms gparms = { 0 }; 1695 1696 TF_CHECK_PARMS2(tfp, parms); 1697 1698 /* Retrieve the session information */ 1699 rc = tf_session_get_session(tfp, &tfs); 1700 if (rc) { 1701 TFP_DRV_LOG(ERR, 1702 "%s: Failed to lookup session, rc:%s\n", 1703 tf_dir_2_str(parms->dir), 1704 strerror(-rc)); 1705 return rc; 1706 } 1707 1708 /* Retrieve the device information */ 1709 rc = tf_session_get_device(tfs, &dev); 1710 if (rc) { 1711 TFP_DRV_LOG(ERR, 1712 "%s: Failed to lookup device, rc:%s\n", 1713 tf_dir_2_str(parms->dir), 1714 strerror(-rc)); 1715 return rc; 1716 } 1717 1718 if (dev->ops->tf_dev_get_if_tbl == NULL) { 1719 rc = -EOPNOTSUPP; 1720 TFP_DRV_LOG(ERR, 1721 "%s: Operation not supported, rc:%s\n", 1722 tf_dir_2_str(parms->dir), 1723 strerror(-rc)); 1724 return rc; 1725 } 1726 1727 gparms.dir = parms->dir; 1728 gparms.type = parms->type; 1729 gparms.idx = parms->idx; 1730 gparms.data_sz_in_bytes = parms->data_sz_in_bytes; 1731 gparms.data = parms->data; 1732 1733 rc = dev->ops->tf_dev_get_if_tbl(tfp, &gparms); 1734 if (rc) { 1735 TFP_DRV_LOG(ERR, 1736 "%s: If_tbl get failed, rc:%s\n", 1737 tf_dir_2_str(parms->dir), 1738 strerror(-rc)); 1739 return rc; 1740 } 1741 1742 return 0; 1743 } 1744 1745 int tf_get_session_info(struct tf *tfp, 1746 struct tf_get_session_info_parms *parms) 1747 { 1748 int rc; 1749 struct tf_session *tfs; 1750 struct tf_dev_info *dev; 1751 1752 TF_CHECK_PARMS2(tfp, parms); 1753 1754 /* Retrieve the session information */ 1755 rc = tf_session_get_session(tfp, &tfs); 1756 if (rc) { 1757 TFP_DRV_LOG(ERR, 1758 "Failed to lookup session, rc:%s\n", 1759 strerror(-rc)); 1760 return rc; 1761 } 1762 1763 /* Retrieve the device information */ 1764 rc = tf_session_get_device(tfs, &dev); 1765 if (rc) { 1766 TFP_DRV_LOG(ERR, 1767 "Failed to lookup device, rc:%s\n", 1768 strerror(-rc)); 1769 return rc; 1770 } 1771 1772 TF_CHECK_PARMS2(tfp, parms); 1773 1774 if (dev->ops->tf_dev_get_ident_resc_info == NULL) { 1775 rc = -EOPNOTSUPP; 1776 TFP_DRV_LOG(ERR, 1777 "Operation not supported, rc:%s\n", 1778 strerror(-rc)); 1779 return rc; 1780 } 1781 1782 rc = dev->ops->tf_dev_get_ident_resc_info(tfp, parms->session_info.ident); 1783 if (rc) { 1784 TFP_DRV_LOG(ERR, 1785 "Ident get resc info failed, rc:%s\n", 1786 strerror(-rc)); 1787 } 1788 1789 if (dev->ops->tf_dev_get_tbl_resc_info == NULL) { 1790 rc = -EOPNOTSUPP; 1791 TFP_DRV_LOG(ERR, 1792 "Operation not supported, rc:%s\n", 1793 strerror(-rc)); 1794 return rc; 1795 } 1796 1797 rc = dev->ops->tf_dev_get_tbl_resc_info(tfp, parms->session_info.tbl); 1798 if (rc) { 1799 TFP_DRV_LOG(ERR, 1800 "Tbl get resc info failed, rc:%s\n", 1801 strerror(-rc)); 1802 } 1803 1804 if (dev->ops->tf_dev_get_tcam_resc_info == NULL) { 1805 rc = -EOPNOTSUPP; 1806 TFP_DRV_LOG(ERR, 1807 "Operation not supported, rc:%s\n", 1808 strerror(-rc)); 1809 return rc; 1810 } 1811 1812 rc = dev->ops->tf_dev_get_tcam_resc_info(tfp, parms->session_info.tcam); 1813 if (rc) { 1814 TFP_DRV_LOG(ERR, 1815 "TCAM get resc info failed, rc:%s\n", 1816 strerror(-rc)); 1817 } 1818 1819 if (dev->ops->tf_dev_get_em_resc_info == NULL) { 1820 rc = -EOPNOTSUPP; 1821 TFP_DRV_LOG(ERR, 1822 "Operation not supported, rc:%s\n", 1823 strerror(-rc)); 1824 return rc; 1825 } 1826 1827 rc = dev->ops->tf_dev_get_em_resc_info(tfp, parms->session_info.em); 1828 if (rc) { 1829 TFP_DRV_LOG(ERR, 1830 "EM get resc info failed, rc:%s\n", 1831 strerror(-rc)); 1832 } 1833 1834 return 0; 1835 } 1836 1837 int tf_get_version(struct tf *tfp, 1838 struct tf_get_version_parms *parms) 1839 { 1840 int rc; 1841 struct tf_dev_info dev; 1842 1843 TF_CHECK_PARMS2(tfp, parms); 1844 1845 /* This function can be called before open session, filter 1846 * out any non-supported device types on the Core side. 1847 */ 1848 if (parms->device_type != TF_DEVICE_TYPE_P4 && 1849 parms->device_type != TF_DEVICE_TYPE_P5 && 1850 parms->device_type != TF_DEVICE_TYPE_SR) { 1851 TFP_DRV_LOG(ERR, 1852 "Unsupported device type %d\n", 1853 parms->device_type); 1854 return -ENOTSUP; 1855 } 1856 1857 tf_dev_bind_ops(parms->device_type, &dev); 1858 1859 rc = tf_msg_get_version(parms->bp, &dev, parms); 1860 if (rc) 1861 return rc; 1862 1863 return 0; 1864 } 1865 1866 int tf_query_sram_resources(struct tf *tfp, 1867 struct tf_query_sram_resources_parms *parms) 1868 { 1869 int rc; 1870 struct tf_dev_info dev; 1871 uint16_t max_types; 1872 struct tfp_calloc_parms cparms; 1873 struct tf_rm_resc_req_entry *query; 1874 enum tf_rm_resc_resv_strategy resv_strategy; 1875 1876 TF_CHECK_PARMS2(tfp, parms); 1877 1878 /* This function can be called before open session, filter 1879 * out any non-supported device types on the Core side. 1880 */ 1881 if (parms->device_type != TF_DEVICE_TYPE_P5) { 1882 TFP_DRV_LOG(ERR, 1883 "Unsupported device type %d\n", 1884 parms->device_type); 1885 return -ENOTSUP; 1886 } 1887 1888 tf_dev_bind_ops(parms->device_type, &dev); 1889 1890 if (dev.ops->tf_dev_get_max_types == NULL) { 1891 rc = -EOPNOTSUPP; 1892 TFP_DRV_LOG(ERR, 1893 "%s: Operation not supported, rc:%s\n", 1894 tf_dir_2_str(parms->dir), 1895 strerror(-rc)); 1896 return -EOPNOTSUPP; 1897 } 1898 1899 /* Need device max number of elements for the RM QCAPS */ 1900 rc = dev.ops->tf_dev_get_max_types(tfp, &max_types); 1901 if (rc) { 1902 TFP_DRV_LOG(ERR, 1903 "Get SRAM resc info failed, rc:%s\n", 1904 strerror(-rc)); 1905 return rc; 1906 } 1907 1908 /* Allocate memory for RM QCAPS request */ 1909 cparms.nitems = max_types; 1910 cparms.size = sizeof(struct tf_rm_resc_req_entry); 1911 cparms.alignment = 0; 1912 rc = tfp_calloc(&cparms); 1913 if (rc) 1914 return rc; 1915 1916 query = (struct tf_rm_resc_req_entry *)cparms.mem_va; 1917 tfp->bp = parms->bp; 1918 1919 /* Get Firmware Capabilities */ 1920 rc = tf_msg_session_resc_qcaps(tfp, 1921 &dev, 1922 parms->dir, 1923 max_types, 1924 query, 1925 &resv_strategy, 1926 &parms->sram_profile); 1927 if (rc) 1928 return rc; 1929 1930 if (dev.ops->tf_dev_get_sram_resources == NULL) { 1931 rc = -EOPNOTSUPP; 1932 TFP_DRV_LOG(ERR, 1933 "%s: Operation not supported, rc:%s\n", 1934 tf_dir_2_str(parms->dir), 1935 strerror(-rc)); 1936 return -EOPNOTSUPP; 1937 } 1938 1939 rc = dev.ops->tf_dev_get_sram_resources((void *)query, 1940 parms->bank_resc_count, 1941 &parms->dynamic_sram_capable); 1942 if (rc) { 1943 TFP_DRV_LOG(ERR, 1944 "Get SRAM resc info failed, rc:%s\n", 1945 strerror(-rc)); 1946 return rc; 1947 } 1948 1949 return 0; 1950 } 1951 1952 int tf_set_sram_policy(struct tf *tfp, 1953 struct tf_set_sram_policy_parms *parms) 1954 { 1955 int rc = 0; 1956 struct tf_dev_info dev; 1957 1958 TF_CHECK_PARMS2(tfp, parms); 1959 1960 /* This function can be called before open session, filter 1961 * out any non-supported device types on the Core side. 1962 */ 1963 if (parms->device_type != TF_DEVICE_TYPE_P5) { 1964 TFP_DRV_LOG(ERR, 1965 "Unsupported device type %d\n", 1966 parms->device_type); 1967 return -ENOTSUP; 1968 } 1969 1970 tf_dev_bind_ops(parms->device_type, &dev); 1971 1972 if (dev.ops->tf_dev_set_sram_policy == NULL) { 1973 rc = -EOPNOTSUPP; 1974 TFP_DRV_LOG(ERR, 1975 "%s: Operation not supported, rc:%s\n", 1976 tf_dir_2_str(parms->dir), 1977 strerror(-rc)); 1978 return rc; 1979 } 1980 1981 rc = dev.ops->tf_dev_set_sram_policy(parms->dir, parms->bank_id); 1982 if (rc) { 1983 TFP_DRV_LOG(ERR, 1984 "%s: SRAM policy set failed, rc:%s\n", 1985 tf_dir_2_str(parms->dir), 1986 strerror(-rc)); 1987 return rc; 1988 } 1989 1990 return rc; 1991 } 1992 1993 int tf_get_sram_policy(struct tf *tfp, 1994 struct tf_get_sram_policy_parms *parms) 1995 { 1996 int rc = 0; 1997 struct tf_dev_info dev; 1998 1999 TF_CHECK_PARMS2(tfp, parms); 2000 2001 /* This function can be called before open session, filter 2002 * out any non-supported device types on the Core side. 2003 */ 2004 if (parms->device_type != TF_DEVICE_TYPE_P5) { 2005 TFP_DRV_LOG(ERR, 2006 "Unsupported device type %d\n", 2007 parms->device_type); 2008 return -ENOTSUP; 2009 } 2010 2011 tf_dev_bind_ops(parms->device_type, &dev); 2012 2013 if (dev.ops->tf_dev_get_sram_policy == NULL) { 2014 rc = -EOPNOTSUPP; 2015 TFP_DRV_LOG(ERR, 2016 "%s: Operation not supported, rc:%s\n", 2017 tf_dir_2_str(parms->dir), 2018 strerror(-rc)); 2019 return rc; 2020 } 2021 2022 rc = dev.ops->tf_dev_get_sram_policy(parms->dir, parms->bank_id); 2023 if (rc) { 2024 TFP_DRV_LOG(ERR, 2025 "%s: SRAM policy get failed, rc:%s\n", 2026 tf_dir_2_str(parms->dir), 2027 strerror(-rc)); 2028 return rc; 2029 } 2030 2031 return rc; 2032 } 2033 2034 int tf_set_session_hotup_state(struct tf *tfp, 2035 struct tf_set_session_hotup_state_parms *parms) 2036 { 2037 int rc = 0; 2038 2039 TF_CHECK_PARMS1(tfp); 2040 2041 rc = tf_session_set_hotup_state(tfp, parms); 2042 if (rc) 2043 return rc; 2044 2045 return rc; 2046 } 2047 2048 int tf_get_session_hotup_state(struct tf *tfp, 2049 struct tf_get_session_hotup_state_parms *parms) 2050 { 2051 int rc = 0; 2052 2053 TF_CHECK_PARMS1(tfp); 2054 2055 rc = tf_session_get_hotup_state(tfp, parms); 2056 if (rc) 2057 return rc; 2058 2059 return rc; 2060 } 2061 2062 #ifdef TF_FLOW_SCALE_QUERY 2063 /* Update TF resource usage state with firmware */ 2064 int tf_update_resc_usage(struct tf *tfp, 2065 enum tf_dir dir, 2066 enum tf_flow_resc_type flow_resc_type) 2067 { 2068 int rc; 2069 struct tf_session *tfs; 2070 struct tf_dev_info *dev; 2071 TF_CHECK_PARMS1(tfp); 2072 2073 /* Retrieve the session information */ 2074 rc = tf_session_get_session(tfp, &tfs); 2075 if (rc) { 2076 TFP_DRV_LOG(ERR, 2077 "%s: Failed to lookup session, rc:%s\n", 2078 tf_dir_2_str(dir), 2079 strerror(-rc)); 2080 return rc; 2081 } 2082 2083 /* Retrieve the device information */ 2084 rc = tf_session_get_device(tfs, &dev); 2085 if (rc) { 2086 TFP_DRV_LOG(ERR, 2087 "%s: Failed to lookup device, rc:%s\n", 2088 tf_dir_2_str(dir), 2089 strerror(-rc)); 2090 return rc; 2091 } 2092 2093 /* Support Thor(P5) on the first session */ 2094 if (dev->type != TF_DEVICE_TYPE_P5 || tfs->session_id.internal.fw_session_id) 2095 return rc; 2096 2097 if (dev->ops->tf_dev_update_resc_usage == NULL) { 2098 rc = -EOPNOTSUPP; 2099 TFP_DRV_LOG(ERR, 2100 "%s: Operation not supported, rc:%s\n", 2101 tf_dir_2_str(dir), 2102 strerror(-rc)); 2103 return rc; 2104 } 2105 2106 rc = dev->ops->tf_dev_update_resc_usage(tfp, dir, flow_resc_type); 2107 if (rc) { 2108 TFP_DRV_LOG(ERR, 2109 "%s: Flow resource usage update failed, rc:%s\n", 2110 tf_dir_2_str(dir), 2111 strerror(-rc)); 2112 return rc; 2113 } 2114 2115 TFP_DRV_LOG(DEBUG, 2116 "%s: Flow resource usage updated: usage type %d\n", 2117 tf_dir_2_str(dir), flow_resc_type); 2118 2119 return 0; 2120 } 2121 2122 /* Get TF resource usage state from firmware*/ 2123 int tf_query_resc_usage(struct tf *tfp, 2124 struct tf_query_resc_usage_parms *parms) 2125 { 2126 int rc; 2127 struct tf_session *tfs; 2128 struct tf_dev_info *dev; 2129 2130 TF_CHECK_PARMS2(tfp, parms); 2131 2132 /* Retrieve the session information */ 2133 rc = tf_session_get_session(tfp, &tfs); 2134 if (rc) { 2135 TFP_DRV_LOG(ERR, 2136 "%s: Failed to lookup session, rc:%s\n", 2137 tf_dir_2_str(parms->dir), 2138 strerror(-rc)); 2139 return rc; 2140 } 2141 2142 /* Retrieve the device information */ 2143 rc = tf_session_get_device(tfs, &dev); 2144 if (rc) { 2145 TFP_DRV_LOG(ERR, 2146 "%s: Failed to lookup device, rc:%s\n", 2147 tf_dir_2_str(parms->dir), 2148 strerror(-rc)); 2149 return rc; 2150 } 2151 2152 /* Support Thor(P5) on the first session */ 2153 if (dev->type != TF_DEVICE_TYPE_P5 || tfs->session_id.internal.fw_session_id) 2154 return rc; 2155 2156 if (dev->ops->tf_dev_query_resc_usage == NULL) { 2157 rc = -EOPNOTSUPP; 2158 TFP_DRV_LOG(ERR, 2159 "%s: Operation not supported, rc:%s\n", 2160 tf_dir_2_str(parms->dir), 2161 strerror(-rc)); 2162 return rc; 2163 } 2164 2165 rc = dev->ops->tf_dev_query_resc_usage(tfp, parms); 2166 if (rc) { 2167 TFP_DRV_LOG(ERR, 2168 "%s: Flow resource usage query failed, rc:%s\n", 2169 tf_dir_2_str(parms->dir), 2170 strerror(-rc)); 2171 return rc; 2172 } 2173 2174 TFP_DRV_LOG(DEBUG, 2175 "%s: Flow resource usage query successfully: usage type %d\n", 2176 tf_dir_2_str(parms->dir), parms->flow_resc_type); 2177 return 0; 2178 } 2179 #endif /* TF_FLOW_SCALE_QUERY */ 2180