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 enum ftl_layout_region_type { 15 #ifdef SPDK_FTL_VSS_EMU 16 /** VSS region for NV cache VSS emulation */ 17 FTL_LAYOUT_REGION_TYPE_VSS, 18 #endif 19 /* Superblock describing the basic FTL information */ 20 FTL_LAYOUT_REGION_TYPE_SB, 21 /* Mirrored instance of the superblock on the base device */ 22 FTL_LAYOUT_REGION_TYPE_SB_BASE, 23 /* If using cached L2P, this region stores the serialized instance of it */ 24 FTL_LAYOUT_REGION_TYPE_L2P, 25 26 /* State of chunks */ 27 FTL_LAYOUT_REGION_TYPE_NVC_MD, 28 /* Mirrored instance of the state of chunks */ 29 FTL_LAYOUT_REGION_TYPE_NVC_MD_MIRROR, 30 31 /* User data region on the nv cache device */ 32 FTL_LAYOUT_REGION_TYPE_DATA_NVC, 33 34 /* User data region on the base device */ 35 FTL_LAYOUT_REGION_TYPE_DATA_BASE, 36 37 FTL_LAYOUT_REGION_TYPE_MAX, 38 }; 39 40 /* last nvc/base region in terms of lba address space */ 41 #define FTL_LAYOUT_REGION_LAST_NVC FTL_LAYOUT_REGION_TYPE_DATA_NVC 42 #define FTL_LAYOUT_REGION_LAST_BASE FTL_LAYOUT_REGION_TYPE_DATA_BASE 43 #define FTL_LAYOUT_REGION_TYPE_FREE_BASE (UINT32_MAX - 2) 44 #define FTL_LAYOUT_REGION_TYPE_FREE_NVC (UINT32_MAX - 1) 45 #define FTL_LAYOUT_REGION_TYPE_INVALID (UINT32_MAX) 46 47 struct ftl_layout_region_descriptor { 48 /* Current version of the region */ 49 uint64_t version; 50 51 /* Offset in FTL_BLOCK_SIZE unit where the region exists on the device */ 52 uint64_t offset; 53 54 /* Number of blocks in FTL_BLOCK_SIZE unit */ 55 uint64_t blocks; 56 }; 57 58 /* Data or metadata region on devices */ 59 struct ftl_layout_region { 60 /* Name of the region */ 61 const char *name; 62 63 /* Region type */ 64 enum ftl_layout_region_type type; 65 66 /* Mirror region type - a region may be mirrored for higher durability */ 67 enum ftl_layout_region_type mirror_type; 68 69 /* Latest region version */ 70 struct ftl_layout_region_descriptor current; 71 72 /* Previous region version, if found */ 73 struct ftl_layout_region_descriptor prev; 74 75 /* Number of blocks in FTL_BLOCK_SIZE unit of a single entry. 76 * A metadata region may be subdivided into multiple smaller entries. 77 * Eg. there's one region describing all bands, but you may be able to access 78 * metadata of a single one. 79 */ 80 uint64_t entry_size; 81 82 /* Number of entries */ 83 uint64_t num_entries; 84 85 /* VSS MD size or 0:disable VSS MD */ 86 uint64_t vss_blksz; 87 88 /* Device of region */ 89 struct spdk_bdev_desc *bdev_desc; 90 91 /* IO channel of region */ 92 struct spdk_io_channel *ioch; 93 }; 94 95 /* 96 * This structure describes the geometry (space organization) of FTL 97 */ 98 struct ftl_layout { 99 /* Organization for base device */ 100 struct { 101 uint64_t total_blocks; 102 } base; 103 104 /* Organization for NV cache */ 105 struct { 106 uint64_t total_blocks; 107 uint64_t chunk_data_blocks; 108 uint64_t chunk_meta_size; 109 uint64_t chunk_count; 110 uint64_t chunk_tail_md_num_blocks; 111 } nvc; 112 113 /* Information corresponding to L2P */ 114 struct { 115 /* Address length in bits */ 116 uint64_t addr_length; 117 /* Address size in bytes */ 118 uint64_t addr_size; 119 /* Number of LBAS in memory page */ 120 uint64_t lbas_in_page; 121 } l2p; 122 123 struct ftl_layout_region region[FTL_LAYOUT_REGION_TYPE_MAX]; 124 125 /* Metadata object corresponding to the regions */ 126 struct ftl_md *md[FTL_LAYOUT_REGION_TYPE_MAX]; 127 }; 128 129 /** 130 * @brief Setup FTL layout 131 */ 132 int ftl_layout_setup(struct spdk_ftl_dev *dev); 133 134 /** 135 * @brief Setup FTL layout of a superblock 136 */ 137 int ftl_layout_setup_superblock(struct spdk_ftl_dev *dev); 138 139 #ifdef SPDK_FTL_VSS_EMU 140 /** 141 * @brief Setup FTL layout of VSS emu 142 */ 143 void ftl_layout_setup_vss_emu(struct spdk_ftl_dev *dev); 144 #endif 145 146 void ftl_layout_dump(struct spdk_ftl_dev *dev); 147 int ftl_validate_regions(struct spdk_ftl_dev *dev, struct ftl_layout *layout); 148 149 #endif /* FTL_LAYOUT_H */ 150