xref: /spdk/lib/ftl/ftl_sb_common.h (revision f869197b76ff6981e901b6d9a05789e1b993494a)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (c) Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef FTL_SB_COMMON_H
7 #define FTL_SB_COMMON_H
8 
9 #include "spdk/stdinc.h"
10 #include "utils/ftl_defs.h"
11 
12 /* Size of superblock on NV cache, make it bigger for future fields */
13 #define FTL_SUPERBLOCK_SIZE (128ULL * KiB)
14 
15 #define FTL_MAGIC(a, b, c, d) \
16     ((UINT64_C(a) << 48) | (UINT64_C(b) << 32) | (UINT64_C(c) << 16) | \
17      UINT64_C(d))
18 
19 /**
20  * Magic number identifies FTL superblock
21  */
22 #define FTL_SUPERBLOCK_MAGIC FTL_MAGIC(0x1410, 0x1683, 0x1920, 0x1989)
23 
24 struct ftl_superblock_gc_info {
25 	/* High priority band; if there's no free bands after dirty shutdown, don't restart GC from same id, or phys_id -
26 	 * pick actual lowest validity band to avoid being stuck and try to write it to the open band.
27 	 */
28 	uint64_t band_id_high_prio;
29 	/* Currently relocated band (note it's just id, not seq_id ie. its actual location on disk) */
30 	uint64_t current_band_id;
31 	/* Bands are grouped together into larger reclaim units; this is the band id translated to those units */
32 	uint64_t band_phys_id;
33 	/* May be updating multiple fields at the same time, clearing/setting this marks the transaction */
34 	uint64_t is_valid;
35 };
36 
37 struct ftl_superblock_header {
38 	uint64_t magic;
39 	uint64_t crc;
40 	uint64_t version;
41 };
42 
43 struct ftl_superblock_md_region {
44 	uint32_t		type;
45 	uint32_t		version;
46 	uint64_t		blk_offs;
47 	uint64_t		blk_sz;
48 };
49 
50 struct ftl_superblock_shm {
51 	/* SHM initialization completed */
52 	bool				shm_ready;
53 
54 	/* SHM status - fast restart */
55 	bool				shm_clean;
56 
57 	/* Used to continue trim after SHM recovery */
58 	struct {
59 		bool			in_progress;
60 		uint64_t		start_lba;
61 		uint64_t		num_blocks;
62 		uint64_t		seq_id;
63 	} trim;
64 
65 	struct ftl_superblock_gc_info	gc_info;
66 };
67 
68 #endif /* FTL_SB_COMMON_H */
69