xref: /spdk/lib/ftl/base/ftl_base_dev.h (revision b02581a89058ebaebe03bd0e16e3b58adfe406c1)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright 2023 Solidigm All Rights Reserved
3   */
4 
5 #ifndef FTL_BASE_DEVICE_H
6 #define FTL_BASE_DEVICE_H
7 
8 #include "spdk/stdinc.h"
9 #include "spdk/bdev_module.h"
10 #include "spdk/queue.h"
11 #include "ftl_layout.h"
12 
13 struct spdk_ftl_dev;
14 struct ftl_mngt_process;
15 
16 /**
17  * @brief Base device operations interface
18  */
19 struct ftl_base_device_ops {
20 	/**
21 	 * @brief Check if block device is valid for base device
22 	 *
23 	 * @param dev ftl device
24 	 * @param bdev bdev to be checked
25 	 *
26 	 * @retval true if bdev is valid for base device
27 	 * @retval false if bdev is not valid for base device
28 	 */
29 	bool (*is_bdev_compatible)(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev);
30 
31 	struct ftl_md_layout_ops md_layout_ops;
32 };
33 
34 /**
35  * @brief Base device type
36  */
37 struct ftl_base_device_type {
38 	/**
39 	 * The name of the base device type
40 	 */
41 	const char *name;
42 
43 	/**
44 	 * The base device operations
45 	 */
46 	const struct ftl_base_device_ops ops;
47 
48 	/**
49 	 * Queue entry for FTL base devices
50 	 */
51 	TAILQ_ENTRY(ftl_base_device_type) base_devs_entry;
52 };
53 
54 /**
55  * @brief Macro to register base device type when the module is loaded
56  *
57  * @param desc Base device type descriptor
58  */
59 #define FTL_BASE_DEVICE_TYPE_REGISTER(desc) \
60 static void __attribute__((constructor)) ftl_base_device_register_##desc(void) \
61 { \
62 	ftl_base_device_register(&desc); \
63 }
64 
65 /**
66  * @brief Register base device type
67  *
68  * @param desc Base device type type
69  */
70 void ftl_base_device_register(struct ftl_base_device_type *desc);
71 
72 /**
73  * @brief Get base device type by bdev
74  *
75  * @param bdev bdev for which base device type is requested
76  *
77  * @return Base device type descriptor
78  */
79 const struct ftl_base_device_type *ftl_base_device_get_type_by_bdev(
80 	struct spdk_ftl_dev *dev, struct spdk_bdev *bdev);
81 
82 #endif /* FTL_BASE_DEVICE_H */
83