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