1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2022 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef FTL_LAYOUT_H 7 #define FTL_LAYOUT_H 8 9 #include "spdk/stdinc.h" 10 11 struct spdk_ftl_dev; 12 struct ftl_md; 13 14 #define FTL_LAYOUT_REGION_TYPE_P2L_COUNT \ 15 (FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MAX - FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MIN + 1) 16 17 enum ftl_layout_region_type { 18 /* Superblock describing the basic FTL information */ 19 FTL_LAYOUT_REGION_TYPE_SB = 0, 20 /* Mirrored instance of the superblock on the base device */ 21 FTL_LAYOUT_REGION_TYPE_SB_BASE = 1, 22 /* If using cached L2P, this region stores the serialized instance of it */ 23 FTL_LAYOUT_REGION_TYPE_L2P = 2, 24 25 /* State of bands */ 26 FTL_LAYOUT_REGION_TYPE_BAND_MD = 3, 27 /* Mirrored instance of bands state */ 28 FTL_LAYOUT_REGION_TYPE_BAND_MD_MIRROR = 4, 29 30 /* Map of valid physical addresses, used for more efficient garbage collection */ 31 FTL_LAYOUT_REGION_TYPE_VALID_MAP = 5, 32 33 /* State of chunks */ 34 FTL_LAYOUT_REGION_TYPE_NVC_MD = 6, 35 /* Mirrored instance of the state of chunks */ 36 FTL_LAYOUT_REGION_TYPE_NVC_MD_MIRROR = 7, 37 38 /* User data region on the nv cache device */ 39 FTL_LAYOUT_REGION_TYPE_DATA_NVC = 8, 40 41 /* User data region on the base device */ 42 FTL_LAYOUT_REGION_TYPE_DATA_BASE = 9, 43 44 /* P2L checkpointing allows for emulation of VSS on base device. 45 * 4 entries are needed - 2 for each writer */ 46 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC = 10, 47 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MIN = FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC, 48 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_GC_NEXT = 11, 49 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP = 12, 50 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP_NEXT = 13, 51 FTL_LAYOUT_REGION_TYPE_P2L_CKPT_MAX = FTL_LAYOUT_REGION_TYPE_P2L_CKPT_COMP_NEXT, 52 53 /* Information about trimmed space in FTL */ 54 FTL_LAYOUT_REGION_TYPE_TRIM_MD = 14, 55 /* Mirrored information about trim */ 56 FTL_LAYOUT_REGION_TYPE_TRIM_MD_MIRROR = 15, 57 58 #ifndef SPDK_FTL_VSS_EMU 59 FTL_LAYOUT_REGION_TYPE_MAX = 16 60 #else 61 /* VSS region for NV cache VSS emulation */ 62 FTL_LAYOUT_REGION_TYPE_VSS = 16, 63 FTL_LAYOUT_REGION_TYPE_MAX = 17, 64 #endif 65 }; 66 67 /* last nvc/base region in terms of lba address space */ 68 #define FTL_LAYOUT_REGION_LAST_NVC FTL_LAYOUT_REGION_TYPE_DATA_NVC 69 #define FTL_LAYOUT_REGION_LAST_BASE FTL_LAYOUT_REGION_TYPE_VALID_MAP 70 #define FTL_LAYOUT_REGION_TYPE_FREE_BASE (UINT32_MAX - 2) 71 #define FTL_LAYOUT_REGION_TYPE_FREE_NVC (UINT32_MAX - 1) 72 #define FTL_LAYOUT_REGION_TYPE_INVALID (UINT32_MAX) 73 74 struct ftl_layout_region_descriptor { 75 /* Current version of the region */ 76 uint64_t version; 77 78 /* Offset in FTL_BLOCK_SIZE unit where the region exists on the device */ 79 uint64_t offset; 80 81 /* Number of blocks in FTL_BLOCK_SIZE unit */ 82 uint64_t blocks; 83 84 struct ftl_superblock_md_region *sb_md_reg; 85 }; 86 87 /* Data or metadata region on devices */ 88 struct ftl_layout_region { 89 /* Name of the region */ 90 const char *name; 91 92 /* Region type */ 93 enum ftl_layout_region_type type; 94 95 /* Mirror region type - a region may be mirrored for higher durability */ 96 enum ftl_layout_region_type mirror_type; 97 98 /* Latest region version */ 99 struct ftl_layout_region_descriptor current; 100 101 /* Previous region version, if found */ 102 struct ftl_layout_region_descriptor prev; 103 104 /* Number of blocks in FTL_BLOCK_SIZE unit of a single entry. 105 * A metadata region may be subdivided into multiple smaller entries. 106 * Eg. there's one region describing all bands, but you may be able to access 107 * metadata of a single one. 108 */ 109 uint64_t entry_size; 110 111 /* Number of entries */ 112 uint64_t num_entries; 113 114 /* VSS MD size or 0:disable VSS MD */ 115 uint64_t vss_blksz; 116 117 /* Device of region */ 118 struct spdk_bdev_desc *bdev_desc; 119 120 /* IO channel of region */ 121 struct spdk_io_channel *ioch; 122 }; 123 124 /* 125 * This structure describes the geometry (space organization) of FTL 126 */ 127 struct ftl_layout { 128 /* Organization for base device */ 129 struct { 130 uint64_t total_blocks; 131 uint64_t num_usable_blocks; 132 uint64_t user_blocks; 133 } base; 134 135 /* Organization for NV cache */ 136 struct { 137 uint64_t total_blocks; 138 uint64_t chunk_data_blocks; 139 uint64_t chunk_meta_size; 140 uint64_t chunk_count; 141 uint64_t chunk_tail_md_num_blocks; 142 } nvc; 143 144 /* Information corresponding to L2P */ 145 struct { 146 /* Address length in bits */ 147 uint64_t addr_length; 148 /* Address size in bytes */ 149 uint64_t addr_size; 150 /* Number of LBAS in memory page */ 151 uint64_t lbas_in_page; 152 } l2p; 153 154 /* Organization of P2L checkpoints */ 155 struct { 156 /* Number of P2L checkpoint pages */ 157 uint64_t ckpt_pages; 158 } p2l; 159 160 struct ftl_layout_region region[FTL_LAYOUT_REGION_TYPE_MAX]; 161 162 /* Metadata object corresponding to the regions */ 163 struct ftl_md *md[FTL_LAYOUT_REGION_TYPE_MAX]; 164 }; 165 166 /** 167 * @brief Setup FTL layout 168 */ 169 int ftl_layout_setup(struct spdk_ftl_dev *dev); 170 171 /** 172 * @brief Setup FTL layout of a superblock 173 */ 174 int ftl_layout_setup_superblock(struct spdk_ftl_dev *dev); 175 176 #ifdef SPDK_FTL_VSS_EMU 177 /** 178 * @brief Setup FTL layout of VSS emu 179 */ 180 void ftl_layout_setup_vss_emu(struct spdk_ftl_dev *dev); 181 #endif 182 183 void ftl_layout_dump(struct spdk_ftl_dev *dev); 184 int ftl_validate_regions(struct spdk_ftl_dev *dev, struct ftl_layout *layout); 185 186 #endif /* FTL_LAYOUT_H */ 187