1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef FTL_INTERNAL_H 7 #define FTL_INTERNAL_H 8 9 #include "spdk/stdinc.h" 10 #include "spdk/crc32.h" 11 #include "spdk/util.h" 12 #include "spdk/uuid.h" 13 14 #include "utils/ftl_bitmap.h" 15 16 /* Marks address as invalid */ 17 #define FTL_ADDR_INVALID ((ftl_addr)-1) 18 /* Marks LBA as invalid */ 19 #define FTL_LBA_INVALID ((uint64_t)-1) 20 /* Smallest data unit size */ 21 #define FTL_BLOCK_SIZE 4096ULL 22 23 /* 24 * This type represents address in the ftl address space. Values from 0 to based bdev size are 25 * mapped directly to base device lbas. Values above that represent nv cache lbas. 26 */ 27 typedef uint64_t ftl_addr; 28 29 struct spdk_ftl_dev; 30 31 enum ftl_md_type { 32 FTL_MD_TYPE_BAND, 33 FTL_MD_TYPE_CHUNK 34 }; 35 36 enum ftl_band_type { 37 FTL_BAND_TYPE_GC = 1, 38 FTL_BAND_TYPE_COMPACTION 39 }; 40 41 enum ftl_md_status { 42 FTL_MD_SUCCESS, 43 /* Metadata read failure */ 44 FTL_MD_IO_FAILURE, 45 /* Invalid version */ 46 FTL_MD_INVALID_VER, 47 /* UUID doesn't match */ 48 FTL_MD_NO_MD, 49 /* UUID and version matches but CRC doesn't */ 50 FTL_MD_INVALID_CRC, 51 /* Vld or p2l map size doesn't match */ 52 FTL_MD_INVALID_SIZE 53 }; 54 55 /* Number of LBAs that could be stored in a single block */ 56 #define FTL_NUM_LBA_IN_BLOCK (FTL_BLOCK_SIZE / sizeof(uint64_t)) 57 58 /* 59 * Mapping of physical (actual location on disk) to logical (user's POV) addresses. Used in two main scenarios: 60 * - during relocation FTL needs to pin L2P pages (this allows to check which pages to pin) and move still valid blocks 61 * (valid map allows for preliminary elimination of invalid physical blocks, but user data could invalidate a location 62 * during read/write operation, so actual comparision against L2P needs to be done) 63 * - After dirty shutdown the state of the L2P is unknown and needs to be rebuilt - it is done by applying all P2L, taking 64 * into account ordering of user writes 65 */ 66 struct ftl_p2l_map { 67 /* Number of valid LBAs */ 68 size_t num_valid; 69 70 /* P2L map's reference count, prevents premature release of resources during dirty shutdown recovery for open bands */ 71 size_t ref_cnt; 72 73 /* Bitmap of valid LBAs */ 74 struct ftl_bitmap *valid; 75 76 /* P2L map (only valid for open/relocating bands) */ 77 union { 78 uint64_t *band_map; 79 void *chunk_map; 80 }; 81 82 /* DMA buffer for region's metadata entry */ 83 union { 84 struct ftl_band_md *band_dma_md; 85 86 struct ftl_nv_cache_chunk_md *chunk_dma_md; 87 }; 88 }; 89 90 struct spdk_ftl_dev; 91 92 struct ftl_reloc *ftl_reloc_init(struct spdk_ftl_dev *dev); 93 94 void ftl_reloc_free(struct ftl_reloc *reloc); 95 96 void ftl_reloc(struct ftl_reloc *reloc); 97 98 void ftl_reloc_halt(struct ftl_reloc *reloc); 99 100 void ftl_reloc_resume(struct ftl_reloc *reloc); 101 102 bool ftl_reloc_is_halted(const struct ftl_reloc *reloc); 103 104 #endif /* FTL_INTERNAL_H */ 105