From b6eecb21e5194a6b977a22c2c1f68ca8617f3696 Mon Sep 17 00:00:00 2001 From: Artur Paszkiewicz Date: Mon, 27 Jun 2022 15:09:06 +0200 Subject: [PATCH] FTL: Add address store/load utils Signed-off-by: Kozlowski Mateusz Signed-off-by: Artur Paszkiewicz Change-Id: Ibac2fe36ba0f3038915075d7105e2d6119b8ed20 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13314 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/ftl/ftl_core.h | 26 +++++++++++++ lib/ftl/utils/ftl_addr_utils.h | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 lib/ftl/utils/ftl_addr_utils.h diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index 3fa11049e..cee95070b 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -176,4 +176,30 @@ ftl_check_core_thread(const struct spdk_ftl_dev *dev) return dev->core_thread == spdk_get_thread(); } +static inline int +ftl_addr_packed(const struct spdk_ftl_dev *dev) +{ + return dev->layout.l2p.addr_size < sizeof(ftl_addr); +} + +static inline int +ftl_addr_in_nvc(const struct spdk_ftl_dev *dev, ftl_addr addr) +{ + assert(addr != FTL_ADDR_INVALID); + return addr >= dev->layout.base.total_blocks; +} + +static inline uint64_t +ftl_addr_to_nvc_offset(const struct spdk_ftl_dev *dev, ftl_addr addr) +{ + assert(ftl_addr_in_nvc(dev, addr)); + return addr - dev->layout.base.total_blocks; +} + +static inline ftl_addr +ftl_addr_from_nvc_offset(const struct spdk_ftl_dev *dev, uint64_t cache_offset) +{ + return cache_offset + dev->layout.base.total_blocks; +} + #endif /* FTL_CORE_H */ diff --git a/lib/ftl/utils/ftl_addr_utils.h b/lib/ftl/utils/ftl_addr_utils.h new file mode 100644 index 000000000..7bbe18431 --- /dev/null +++ b/lib/ftl/utils/ftl_addr_utils.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#ifndef FTL_ADDR_UTILS_H +#define FTL_ADDR_UTILS_H + +#include "ftl_core.h" + +static inline ftl_addr +ftl_addr_load(struct spdk_ftl_dev *dev, void *buffer, uint64_t offset) +{ + if (ftl_addr_packed(dev)) { + uint32_t *b32 = buffer; + ftl_addr addr = b32[offset]; + + if (addr == (uint32_t)FTL_ADDR_INVALID) { + return FTL_ADDR_INVALID; + } else { + return addr; + } + } else { + uint64_t *b64 = buffer; + return b64[offset]; + } +} + +static inline void +ftl_addr_store(struct spdk_ftl_dev *dev, void *buffer, uint64_t offset, ftl_addr addr) +{ + if (ftl_addr_packed(dev)) { + uint32_t *b32 = buffer; + b32[offset] = addr; + } else { + uint64_t *b64 = buffer; + b64[offset] = addr; + } +} + +static inline uint64_t +ftl_lba_load(struct spdk_ftl_dev *dev, void *buffer, uint64_t offset) +{ + if (ftl_addr_packed(dev)) { + uint32_t *b32 = buffer; + uint32_t lba = b32[offset]; + + if (lba == (uint32_t)FTL_LBA_INVALID) { + return FTL_LBA_INVALID; + } else { + return lba; + } + } else { + uint64_t *b64 = buffer; + return b64[offset]; + } +} + +static inline void +ftl_lba_store(struct spdk_ftl_dev *dev, void *buffer, uint64_t offset, uint64_t lba) +{ + if (ftl_addr_packed(dev)) { + uint32_t *b32 = buffer; + b32[offset] = lba; + } else { + uint64_t *b64 = buffer; + b64[offset] = lba; + } +} + +#endif /* FTL_ADDR_UTILS_H */