Skip to content

Commit

Permalink
[Silabs] Increase the max supported KVS entries (project-chip#35480)
Browse files Browse the repository at this point in the history
* Increase the maximum KVS entries our implementation can handle

* add gn argument to configure the nvm3 max object size
  • Loading branch information
jmartinez-silabs authored Sep 10, 2024
1 parent d1279a8 commit bd6ae09
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/platform/silabs/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ uint16_t KeyValueStoreManagerImpl::hashKvsKeyString(const char * key) const
CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint16_t hash, uint32_t & nvm3Key, bool isSlotNeeded) const
{
CHIP_ERROR err;
char * strPrefix = nullptr;
uint8_t firstEmptyKeySlot = kMaxEntries;
for (uint8_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
char * strPrefix = nullptr;
uint16_t firstEmptyKeySlot = kMaxEntries;
for (uint16_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
{
if (mKvsKeyMap[keyIndex] == hash)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
Commit the key map in nvm once it as stabilized.
*/
SystemLayer().StartTimer(
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)),
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SL_KVS_SAVE_DELAY_SECONDS)),
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
}

Expand Down Expand Up @@ -247,7 +247,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
void KeyValueStoreManagerImpl::ErasePartition(void)
{
// Iterate over all the Matter Kvs nvm3 records and delete each one...
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kMaxConfigKey_MatterKvs; nvm3Key++)
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kConfigKey_KvsLastKeySlot; nvm3Key++)
{
SilabsConfig::ClearConfigValue(nvm3Key);
}
Expand Down
16 changes: 11 additions & 5 deletions src/platform/silabs/SilabsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
#endif

// Delay before Key/Value is actually saved in NVM
#define SILABS_KVS_SAVE_DELAY_SECONDS 5
#ifndef SL_KVS_SAVE_DELAY_SECONDS
#define SL_KVS_SAVE_DELAY_SECONDS 2
#endif

static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
static_assert((KVS_MAX_ENTRIES <= 511), "Implementation supports up to 511 Kvs entries");
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");

namespace chip {
Expand Down Expand Up @@ -89,7 +91,8 @@ class SilabsConfig
// Persistent counter values set at runtime. Retained during factory reset.
static constexpr uint8_t kMatterCounter_KeyBase = 0x74;
// Persistent config values set at runtime. Cleared during factory reset.
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
static constexpr uint8_t kMatterKvs_ExtendedRange = 0x76;

// Key definitions for well-known configuration values.
// Factory config keys
Expand Down Expand Up @@ -167,7 +170,8 @@ class SilabsConfig
// Matter KVS storage Keys
static constexpr Key kConfigKey_KvsStringKeyMap = SilabsConfigKey(kMatterKvs_KeyBase, 0x00);
static constexpr Key kConfigKey_KvsFirstKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, 0x01);
static constexpr Key kConfigKey_KvsLastKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, KVS_MAX_ENTRIES);
static constexpr Key kConfigKey_KvsLastKeySlot =
SilabsConfigKey(kMatterKvs_KeyBase + (KVS_MAX_ENTRIES >> 8), KVS_MAX_ENTRIES & UINT8_MAX);

// Set key id limits for each group.
static constexpr Key kMinConfigKey_MatterFactory = SilabsConfigKey(kMatterFactory_KeyBase, 0x00);
Expand All @@ -180,7 +184,9 @@ class SilabsConfig
static constexpr Key kMaxConfigKey_MatterCounter = SilabsConfigKey(kMatterCounter_KeyBase, 0x1F);

static constexpr Key kMinConfigKey_MatterKvs = kConfigKey_KvsStringKeyMap;
static constexpr Key kMaxConfigKey_MatterKvs = kConfigKey_KvsLastKeySlot;
static constexpr Key kMaxConfigKey_MatterKvs = SilabsConfigKey(kMatterKvs_ExtendedRange, 0xFF);
static_assert(kConfigKey_KvsLastKeySlot <= kMaxConfigKey_MatterKvs,
"Configured KVS_MAX_ENTRIES overflows the reserved KVS Key range");

static CHIP_ERROR Init(void);
static void DeInit(void);
Expand Down
2 changes: 1 addition & 1 deletion third_party/silabs/SiWx917_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ template("siwx917_sdk") {
# 1->SOC and 0->NCP
"RSI_WLAN_API_ENABLE",
"NVM3_DEFAULT_NVM_SIZE=40960",
"NVM3_DEFAULT_MAX_OBJECT_SIZE=4092",
"NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}",
"KVS_MAX_ENTRIES=${kvs_max_entries}",
"${silabs_mcu}=1",
"${silabs_board}=1",
Expand Down
3 changes: 2 additions & 1 deletion third_party/silabs/efr32_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare_args() {
# enable by default for thread/non-wifi-ncp builds
enable_openthread_cli = !(use_rs9116 || use_wf200 || use_SiWx917)
kvs_max_entries = 255
sl_nvm3_max_object_size = 4092

# Use Silabs factory data provider example.
# Users can implement their own.
Expand Down Expand Up @@ -421,7 +422,7 @@ template("efr32_sdk") {
"HARD_FAULT_LOG_ENABLE",
"CORTEXM3_EFM32_MICRO",
"NVM3_DEFAULT_NVM_SIZE=40960",
"NVM3_DEFAULT_MAX_OBJECT_SIZE=4092",
"NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}",
"KVS_MAX_ENTRIES=${kvs_max_entries}",
"CORTEXM3=1",
"MICRO=EMBER_MICRO_CORTEXM3_EFR32",
Expand Down

0 comments on commit bd6ae09

Please sign in to comment.