From 01ecf332ff9f0c8f61e493cdca116f58d80bb5fb Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 27 Jun 2022 07:18:21 +1000 Subject: Generic wear-leveling algorithm (#16996) * Initial import of wear-leveling algorithm. * Alignment. * Docs tweaks. * Lock/unlock. * Update quantum/wear_leveling/wear_leveling_internal.h Co-authored-by: Stefan Kerkmann * More tests, fix issue with consolidation when unlocked. * More tests. * Review comments. * Add plumbing for FNV1a. * Another test checking that checksum mismatch clears the cache. * Check that the write log still gets played back. Co-authored-by: Stefan Kerkmann --- quantum/wear_leveling/wear_leveling.h | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 quantum/wear_leveling/wear_leveling.h (limited to 'quantum/wear_leveling/wear_leveling.h') diff --git a/quantum/wear_leveling/wear_leveling.h b/quantum/wear_leveling/wear_leveling.h new file mode 100644 index 0000000000..6641bc49b3 --- /dev/null +++ b/quantum/wear_leveling/wear_leveling.h @@ -0,0 +1,54 @@ +// Copyright 2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once +#include +#include + +/** + * @typedef Status returned from any wear-leveling API. + */ +typedef enum wear_leveling_status_t { + WEAR_LEVELING_FAILED, //< Invocation failed + WEAR_LEVELING_SUCCESS, //< Invocation succeeded + WEAR_LEVELING_CONSOLIDATED //< Invocation succeeded, consolidation occurred +} wear_leveling_status_t; + +/** + * Wear-leveling initialization + * + * @return Status of the request + */ +wear_leveling_status_t wear_leveling_init(void); + +/** + * Wear-leveling erasure. + * + * Clears the wear-leveling area, with the definition that the "reset state" of all data is zero. + * + * @return Status of the request + */ +wear_leveling_status_t wear_leveling_erase(void); + +/** + * Writes logical data into the backing store. + * + * Skips writes if there are no changes to written values. The entire written block is considered when attempting to + * determine if an overwrite should occur -- if there is any data mismatch the entire block will be written to the log, + * not just the changed bytes. + * + * @param address[in] the logical address to write data + * @param value[in] pointer to the source buffer + * @param length[in] length of the data + * @return Status of the request + */ +wear_leveling_status_t wear_leveling_write(uint32_t address, const void* value, size_t length); + +/** + * Reads logical data from the cache. + * + * @param address[in] the logical address to read data + * @param value[out] pointer to the destination buffer + * @param length[in] length of the data + * @return Status of the request + */ +wear_leveling_status_t wear_leveling_read(uint32_t address, void* value, size_t length); -- cgit v1.2.3