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_mngt_process; 14 struct ftl_nv_cache_chunk; 15 16 /** 17 * @brief NV Cache device features and capabilities 18 */ 19 struct ftl_nv_cache_device_features { 20 /* 21 * The placeholder for NV Cache device features. It will be filled in the future. 22 */ 23 }; 24 25 /** 26 * @brief NV Cache device operations interface 27 */ 28 struct ftl_nv_cache_device_ops { 29 /** 30 * @brief Check if block device is valid for NV Cache device 31 * 32 * @param dev ftl device 33 * @param bdev bdev to be checked 34 * 35 * @retval true if bdev is valid for NV Cache device 36 * @retval false if bdev is not valid for NV Cache device 37 */ 38 bool (*is_bdev_compatible)(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev); 39 40 /** 41 * @brief Check if chunk is active and can be used for NV Cache 42 * 43 * @param dev FTL device 44 * @param chunk_offset chunk start offset to be checked 45 * 46 * @retval true if chunk is active 47 * @retval false if chunk is not active 48 */ 49 bool (*is_chunk_active)(struct spdk_ftl_dev *dev, uint64_t chunk_offset); 50 51 struct ftl_md_layout_ops md_layout_ops; 52 }; 53 54 /** 55 * @brief NV Cache device type 56 */ 57 struct ftl_nv_cache_device_type { 58 /** 59 * The name of the NV cache device type 60 */ 61 const char *name; 62 63 /** 64 * The features list of the NV cache device type 65 * 66 */ 67 const struct ftl_nv_cache_device_features features; 68 69 /** 70 * The NV cache device operations 71 */ 72 const struct ftl_nv_cache_device_ops ops; 73 74 /** Internal fields */ 75 struct { 76 /* The queue entry to put this description to a queue */ 77 TAILQ_ENTRY(ftl_nv_cache_device_type) entry; 78 } internal; 79 }; 80 81 /** 82 * @brief Macro to register NV Cache device type when the module is loaded 83 * 84 * @param desc NV Cache device type 85 */ 86 #define FTL_NV_CACHE_DEVICE_TYPE_REGISTER(desc) \ 87 static void __attribute__((constructor)) ftl_nv_cache_device_register_##desc(void) \ 88 { \ 89 ftl_nv_cache_device_register(&desc); \ 90 } 91 92 /** 93 * @brief Register NV Cache device type 94 * 95 * @param type NV Cache device type 96 */ 97 void ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type); 98 99 /** 100 * @brief Get NV Cache device type by bdev 101 * 102 * @param bdev bdev for which NV Cache device type is requested 103 * 104 * @return NV Cache device type 105 */ 106 const struct ftl_nv_cache_device_type *ftl_nv_cache_device_get_type_by_bdev( 107 struct spdk_ftl_dev *dev, struct spdk_bdev *bdev); 108 109 #endif /* FTL_NV_CACHE_DEVICE_H */ 110