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 Check if block device is valid for NV Cache device 48 * 49 * @param dev ftl device 50 * @param bdev bdev to be checked 51 * 52 * @retval true if bdev is valid for NV Cache device 53 * @retval false if bdev is not valid for NV Cache device 54 */ 55 bool (*is_bdev_compatible)(struct spdk_ftl_dev *dev, struct spdk_bdev *bdev); 56 57 /** 58 * @brief Check if chunk is active and can be used for NV Cache 59 * 60 * @param dev FTL device 61 * @param chunk_offset chunk start offset to be checked 62 * 63 * @retval true if chunk is active 64 * @retval false if chunk is not active 65 */ 66 bool (*is_chunk_active)(struct spdk_ftl_dev *dev, uint64_t chunk_offset); 67 68 /** 69 * @brief Write user IO to the NV cache device 70 * 71 * @param io FTL IO 72 * 73 */ 74 void (*write)(struct ftl_io *io); 75 76 /** 77 * @brief Recover open chunk 78 * 79 * @param dev ftl device 80 * @param mngt FTL management precess handler 81 * @param chunk NV cache chunk to be recovered 82 * 83 * @note When the recovery finished successfully then the procedure 84 * shall invoke ftl_mngt_next_step(mngt). If a failure occurred then 85 * the process shall call ftl_mngt_fail_step(mngt) 86 */ 87 void (*recover_open_chunk)(struct spdk_ftl_dev *dev, struct ftl_mngt_process *mngt, 88 struct ftl_nv_cache_chunk *chunk); 89 90 /** 91 * @brief Setup NV Cache device layout 92 * 93 * If the NV cache device requires to setup additional metadata regions, 94 * it can be done here. 95 * 96 * @param dev ftl device 97 * 98 * @retval 0 on success 99 * @retval non-zero on failure 100 */ 101 int (*setup_layout)(struct spdk_ftl_dev *dev); 102 103 struct ftl_md_layout_ops md_layout_ops; 104 }; 105 106 /** 107 * @brief NV Cache device type 108 */ 109 struct ftl_nv_cache_device_type { 110 /** 111 * The name of the NV cache device type 112 */ 113 const char *name; 114 115 /** 116 * The features list of the NV cache device type 117 * 118 */ 119 const struct ftl_nv_cache_device_features features; 120 121 /** 122 * The NV cache device operations 123 */ 124 const struct ftl_nv_cache_device_ops ops; 125 126 /** Internal fields */ 127 struct { 128 /* The queue entry to put this description to a queue */ 129 TAILQ_ENTRY(ftl_nv_cache_device_type) entry; 130 } internal; 131 }; 132 133 /** 134 * @brief Macro to register NV Cache device type when the module is loaded 135 * 136 * @param desc NV Cache device type 137 */ 138 #define FTL_NV_CACHE_DEVICE_TYPE_REGISTER(desc) \ 139 static void __attribute__((constructor)) ftl_nv_cache_device_register_##desc(void) \ 140 { \ 141 ftl_nv_cache_device_register(&desc); \ 142 } 143 144 /** 145 * @brief Register NV Cache device type 146 * 147 * @param type NV Cache device type 148 */ 149 void ftl_nv_cache_device_register(struct ftl_nv_cache_device_type *type); 150 151 /** 152 * @brief Get NV Cache device type by bdev 153 * 154 * @param bdev bdev for which NV Cache device type is requested 155 * 156 * @return NV Cache device type 157 */ 158 const struct ftl_nv_cache_device_type *ftl_nv_cache_device_get_type_by_bdev( 159 struct spdk_ftl_dev *dev, struct spdk_bdev *bdev); 160 161 #endif /* FTL_NV_CACHE_DEVICE_H */ 162