1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2022 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef FTL_SB_COMMON_H 7 #define FTL_SB_COMMON_H 8 9 #include "spdk/stdinc.h" 10 #include "utils/ftl_defs.h" 11 #include "utils/ftl_df.h" 12 13 /* Size of superblock on NV cache, make it bigger for future fields */ 14 #define FTL_SUPERBLOCK_SIZE (128ULL * KiB) 15 16 #define FTL_MAGIC(a, b, c, d) \ 17 ((UINT64_C(a) << 48) | (UINT64_C(b) << 32) | (UINT64_C(c) << 16) | \ 18 UINT64_C(d)) 19 20 /** 21 * Magic number identifies FTL superblock 22 */ 23 #define FTL_SUPERBLOCK_MAGIC FTL_MAGIC(0x1410, 0x1683, 0x1920, 0x1989) 24 25 struct ftl_superblock_gc_info { 26 /* High priority band; if there's no free bands after dirty shutdown, don't restart GC from same id, or phys_id - 27 * pick actual lowest validity band to avoid being stuck and try to write it to the open band. 28 */ 29 uint64_t band_id_high_prio; 30 /* Currently relocated band (note it's just id, not seq_id ie. its actual location on disk) */ 31 uint64_t current_band_id; 32 /* Bands are grouped together into larger reclaim units; this is the band id translated to those units */ 33 uint64_t band_phys_id; 34 /* May be updating multiple fields at the same time, clearing/setting this marks the transaction */ 35 uint64_t is_valid; 36 } __attribute__((packed)); 37 SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_gc_info) == 32, 38 "ftl_superblock_gc_info incorrect size"); 39 40 struct ftl_superblock_header { 41 uint64_t magic; 42 uint64_t crc; 43 uint64_t version; 44 } __attribute__((packed)); 45 SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_header) == 24, 46 "ftl_superblock_header incorrect size"); 47 48 struct ftl_superblock_v3_md_region { 49 uint32_t type; 50 uint32_t version; 51 uint64_t blk_offs; 52 uint64_t blk_sz; 53 ftl_df_obj_id df_next; 54 } __attribute__((packed)); 55 SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_v3_md_region) == 32, 56 "ftl_superblock_v3_md_region incorrect size"); 57 58 struct ftl_superblock_v5_md_blob_hdr { 59 /* Blob size in bytes */ 60 uint16_t blob_sz; 61 /* Reserved */ 62 uint16_t reserved1; 63 uint32_t reserved2; 64 /* DF pointer to the blob in a SB buf */ 65 ftl_df_obj_id df_id; 66 } __attribute__((packed)); 67 SPDK_STATIC_ASSERT(sizeof(struct ftl_superblock_v5_md_blob_hdr) == 16, 68 "ftl_superblock_v5_md_blob_hdr incorrect size"); 69 70 struct ftl_superblock_shm { 71 /* SHM initialization completed */ 72 bool shm_ready; 73 74 /* SHM status - fast restart */ 75 bool shm_clean; 76 77 /* Used to continue trim after SHM recovery */ 78 struct { 79 bool in_progress; 80 uint64_t start_lba; 81 uint64_t num_blocks; 82 uint64_t seq_id; 83 } trim; 84 85 struct ftl_superblock_gc_info gc_info; 86 }; 87 88 #endif /* FTL_SB_COMMON_H */ 89