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