xref: /spdk/lib/ftl/nvc/ftl_nvc_dev.h (revision d4d015a572e1af7b2818e44218c1e661a61545ec)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright 2023 Solidigm All Rights Reserved
3   */
4 
5 #ifndef FTL_NV_CACHE_DEVICE_H
6 #define FTL_NV_CACHE_DEVICE_H
7 
8 #include "spdk/stdinc.h"
9 #include "spdk/bdev_module.h"
10 #include "ftl_layout.h"
11 
12 struct spdk_ftl_dev;
13 struct ftl_nv_cache_chunk;
14 struct ftl_io;
15 struct ftl_mngt_process;
16 
17 /**
18  * @brief NV Cache device features and capabilities
19  */
20 struct ftl_nv_cache_device_features {
21 	/*
22 	 * The placeholder for NV Cache device features. It will be filled in the future.
23 	 */
24 };
25 
26 /**
27  * @brief NV Cache device operations interface
28  */
29 struct ftl_nv_cache_device_ops {
30 	/**
31 	 * @brief Initialize NV Cache device
32 	 *
33 	 * @param dev ftl device
34 	 *
35 	 * @return Initialization result
36 	 */
37 	int (*init)(struct spdk_ftl_dev *dev);
38 
39 	/**
40 	 * @brief Deinitialize NV Cache device
41 	 *
42 	 * @param dev ftl device
43 	 */
44 	void (*deinit)(struct spdk_ftl_dev *dev);
45 
46 	/**
47 	 * @brief Inform NV cache device that chunk is being opened
48 	 *
49 	 * @param dev ftl device
50 	 * @param chunk chunk is being opened
51 	 */
52 	void (*on_chunk_open)(struct spdk_ftl_dev *dev, struct ftl_nv_cache_chunk *chunk);
53 
54 	/**
55 	 * @brief Inform NV cache device that chunk has been closed
56 	 *
57 	 * @param dev ftl device
58 	 * @param chunk chunk which has been closed
59 	 */
60 	void (*on_chunk_closed)(struct spdk_ftl_dev *dev, struct ftl_nv_cache_chunk *chunk);
61 
62 	/**
63 	 * @brief Check if block device is valid for NV Cache device
64 	 *
65 	 * @param dev ftl device
66 	 * @param bdev bdev to be checked
67 	 *
68 	 * @retval true if bdev is valid for NV Cache device
69 	 * @retval false if bdev is not valid for NV Cache device
70 	 */
71 	bool (*is_bdev_compatible)(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev);
72 
73 	/**
74 	 * @brief Check if chunk is active and can be used for NV Cache
75 	 *
76 	 * @param dev FTL device
77 	 * @param chunk_offset chunk start offset to be checked
78 	 *
79 	 * @retval true if chunk is active
80 	 * @retval false if chunk is not active
81 	 */
82 	bool (*is_chunk_active)(struct spdk_ftl_dev *dev, uint64_t chunk_offset);
83 
84 	/**
85 	 * @brief Write user IO to the NV cache device
86 	 *
87 	 * @param io FTL IO
88 	 *
89 	 */
90 	void (*write)(struct ftl_io *io);
91 
92 	/**
93 	 * @brief Process NV Cache device
94 	 *
95 	 * @param dev ftl device
96 	 */
97 	void (*process)(struct spdk_ftl_dev *dev);
98 
99 	/**
100 	 * @brief Recover open chunk
101 	 *
102 	 * @param dev ftl device
103 	 * @param mngt FTL management precess handler
104 	 * @param chunk NV cache chunk to be recovered
105 	 *
106 	 * @note When the recovery finished successfully then the procedure
107 	 * shall invoke ftl_mngt_next_step(mngt). If a failure occurred then
108 	 * the process shall call ftl_mngt_fail_step(mngt)
109 	 */
110 	void (*recover_open_chunk)(struct spdk_ftl_dev *dev, struct ftl_mngt_process *mngt,
111 				   struct ftl_nv_cache_chunk *chunk);
112 
113 	/**
114 	 * @brief Setup NV Cache device layout
115 	 *
116 	 * If the NV cache device requires to setup additional metadata regions,
117 	 * it can be done here.
118 	 *
119 	 * @param dev ftl device
120 	 *
121 	 * @retval 0 on success
122 	 * @retval non-zero on failure
123 	 */
124 	int (*setup_layout)(struct spdk_ftl_dev *dev);
125 
126 	struct ftl_md_layout_ops md_layout_ops;
127 };
128 
129 /**
130  * @brief NV Cache device type
131  */
132 struct ftl_nv_cache_device_type {
133 	/**
134 	 * The name of the NV cache device type
135 	 */
136 	const char *name;
137 
138 	/**
139 	 * The features list of the NV cache device type
140 	 *
141 	 */
142 	const struct ftl_nv_cache_device_features features;
143 
144 	/**
145 	 * The NV cache device operations
146 	 */
147 	const struct ftl_nv_cache_device_ops ops;
148 
149 	/** Internal fields */
150 	struct {
151 		/* The queue entry to put this description to a queue */
152 		TAILQ_ENTRY(ftl_nv_cache_device_type) entry;
153 	} internal;
154 };
155 
156 /**
157  * @brief Macro to register NV Cache device type when the module is loaded
158  *
159  * @param desc NV Cache device type
160  */
161 #define FTL_NV_CACHE_DEVICE_TYPE_REGISTER(desc) \
162 static void __attribute__((constructor)) ftl_nv_cache_device_register_##desc(void) \
163 { \
164 	ftl_nv_cache_device_register(&desc); \
165 }
166 
167 /**
168  * @brief Register NV Cache device type
169  *
170  * @param type NV Cache device type
171  */
172 void ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type);
173 
174 /**
175  * @brief Get NV Cache device type by bdev
176  *
177  * @param bdev bdev for which NV Cache device type is requested
178  *
179  * @return NV Cache device type
180  */
181 const struct ftl_nv_cache_device_type *ftl_nv_cache_device_get_type_by_bdev(
182 	struct spdk_ftl_dev *dev, struct spdk_bdev *bdev);
183 
184 #endif /* FTL_NV_CACHE_DEVICE_H */
185