xref: /spdk/lib/ftl/ftl_layout.h (revision ea8f5b27612fa03698a9ce3ad4bd37765d9cdfa5)
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 	FTL_LAYOUT_REGION_TYPE_MAX,
61 };
62 
63 /* last nvc/base region in terms of lba address space */
64 #define FTL_LAYOUT_REGION_LAST_NVC FTL_LAYOUT_REGION_TYPE_DATA_NVC
65 #define FTL_LAYOUT_REGION_LAST_BASE FTL_LAYOUT_REGION_TYPE_VALID_MAP
66 #define FTL_LAYOUT_REGION_TYPE_FREE_BASE (UINT32_MAX - 2)
67 #define FTL_LAYOUT_REGION_TYPE_FREE_NVC (UINT32_MAX - 1)
68 #define FTL_LAYOUT_REGION_TYPE_INVALID (UINT32_MAX)
69 
70 struct ftl_layout_region_descriptor {
71 	/* Current version of the region */
72 	uint64_t version;
73 
74 	/* Offset in FTL_BLOCK_SIZE unit where the region exists on the device */
75 	uint64_t offset;
76 
77 	/* Number of blocks in FTL_BLOCK_SIZE unit */
78 	uint64_t blocks;
79 };
80 
81 /* Data or metadata region on devices */
82 struct ftl_layout_region {
83 	/* Name of the region */
84 	const char *name;
85 
86 	/* Region type */
87 	enum ftl_layout_region_type type;
88 
89 	/* Mirror region type - a region may be mirrored for higher durability */
90 	enum ftl_layout_region_type mirror_type;
91 
92 	/* Latest region version */
93 	struct ftl_layout_region_descriptor current;
94 
95 	/* Previous region version, if found */
96 	struct ftl_layout_region_descriptor prev;
97 
98 	/* Number of blocks in FTL_BLOCK_SIZE unit of a single entry.
99 	 * A metadata region may be subdivided into multiple smaller entries.
100 	 * Eg. there's one region describing all bands, but you may be able to access
101 	 * metadata of a single one.
102 	 */
103 	uint64_t entry_size;
104 
105 	/* Number of entries */
106 	uint64_t num_entries;
107 
108 	/* VSS MD size or 0:disable VSS MD */
109 	uint64_t vss_blksz;
110 
111 	/* Device of region */
112 	struct spdk_bdev_desc *bdev_desc;
113 
114 	/* IO channel of region */
115 	struct spdk_io_channel *ioch;
116 };
117 
118 /*
119  * This structure describes the geometry (space organization) of FTL
120  */
121 struct ftl_layout {
122 	/* Organization for base device */
123 	struct {
124 		uint64_t total_blocks;
125 		uint64_t num_usable_blocks;
126 		uint64_t user_blocks;
127 	} base;
128 
129 	/* Organization for NV cache */
130 	struct {
131 		uint64_t total_blocks;
132 		uint64_t chunk_data_blocks;
133 		uint64_t chunk_meta_size;
134 		uint64_t chunk_count;
135 		uint64_t chunk_tail_md_num_blocks;
136 	} nvc;
137 
138 	/* Information corresponding to L2P */
139 	struct {
140 		/* Address length in bits */
141 		uint64_t addr_length;
142 		/* Address size in bytes */
143 		uint64_t addr_size;
144 		/* Number of LBAS in memory page */
145 		uint64_t lbas_in_page;
146 	} l2p;
147 
148 	/* Organization of P2L checkpoints */
149 	struct {
150 		/* Number of P2L checkpoint pages */
151 		uint64_t ckpt_pages;
152 	} p2l;
153 
154 	struct ftl_layout_region region[FTL_LAYOUT_REGION_TYPE_MAX];
155 
156 	/* Metadata object corresponding to the regions */
157 	struct ftl_md *md[FTL_LAYOUT_REGION_TYPE_MAX];
158 };
159 
160 /**
161  * @brief Setup FTL layout
162  */
163 int ftl_layout_setup(struct spdk_ftl_dev *dev);
164 
165 /**
166  * @brief Setup FTL layout of a superblock
167  */
168 int ftl_layout_setup_superblock(struct spdk_ftl_dev *dev);
169 
170 #ifdef SPDK_FTL_VSS_EMU
171 /**
172  * @brief Setup FTL layout of VSS emu
173  */
174 void ftl_layout_setup_vss_emu(struct spdk_ftl_dev *dev);
175 #endif
176 
177 void ftl_layout_dump(struct spdk_ftl_dev *dev);
178 int ftl_validate_regions(struct spdk_ftl_dev *dev, struct ftl_layout *layout);
179 
180 #endif /* FTL_LAYOUT_H */
181