diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index d39bc90a6b..7c050b2f57 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -163,6 +163,26 @@ sai_status_t VendorSai::apiInitialize( } } +#ifdef HAVE_SAI_QUERY_STATS_ST_CAPABILITY + // BROADCOM_LEGACY_SAI_COMPAT: Allow platforms to disable sai_query_stats_st_capability at runtime + // via sai.profile key SAI_STATS_ST_CAPABILITY_SUPPORTED=0. + // Needed for legacy ASICs (e.g. Tomahawk-1/BCM56960) where the SAI function + // pointer is non-null but the internal ST platform driver is uninitialized, + // causing a SIGSEGV in brcm_sai_st_pd_ctr_cap_list_get. + if (m_globalApis.query_stats_st_capability != nullptr && + m_service_method_table.profile_get_value != nullptr) + { + const char *stCapVal = m_service_method_table.profile_get_value( + 0, "SAI_STATS_ST_CAPABILITY_SUPPORTED"); + if (stCapVal != nullptr && std::string(stCapVal) == "0") + { + SWSS_LOG_NOTICE("SAI_STATS_ST_CAPABILITY_SUPPORTED=0 in sai.profile," + " disabling query_stats_st_capability for this platform"); + m_globalApis.query_stats_st_capability = nullptr; + } + } +#endif + m_apiInitialized = true; return status; diff --git a/tests/aspell.en.pws b/tests/aspell.en.pws index 62db532aa9..4216682c4e 100644 --- a/tests/aspell.en.pws +++ b/tests/aspell.en.pws @@ -490,3 +490,4 @@ IPFix ipfix SNR tparam +SIGSEGV diff --git a/unittest/syncd/TestVendorSai.cpp b/unittest/syncd/TestVendorSai.cpp index 65f93918fe..9616f60649 100644 --- a/unittest/syncd/TestVendorSai.cpp +++ b/unittest/syncd/TestVendorSai.cpp @@ -1847,3 +1847,31 @@ TEST(VendorSai, isSwitchStatsExtDisabledViaProfile) sai.apiInitialize(0, &test_services_no_switch_stats_ext); EXPECT_FALSE(sai.isSwitchStatsExtSupported()); } + +static const char* profile_get_value_no_st_capability( + _In_ sai_switch_profile_id_t profile_id, + _In_ const char* variable) +{ + SWSS_LOG_ENTER(); + + if (variable == NULL) + return NULL; + + if (std::string(variable) == "SAI_STATS_ST_CAPABILITY_SUPPORTED") + return "0"; + + return nullptr; +} + +static sai_service_method_table_t test_services_no_st_capability = { + profile_get_value_no_st_capability, + profile_get_next_value +}; + +TEST(VendorSai, statsStCapabilityProfileKeyProcessed) +{ + // BROADCOM_LEGACY_SAI_COMPAT: SAI_STATS_ST_CAPABILITY_SUPPORTED=0 in sai.profile + // should be processed during apiInitialize without breaking initialization + VendorSai sai; + EXPECT_EQ(SAI_STATUS_SUCCESS, sai.apiInitialize(0, &test_services_no_st_capability)); +}