1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef FTL_WRITER_H 7 #define FTL_WRITER_H 8 9 #include "spdk/stdinc.h" 10 #include "spdk/queue.h" 11 12 #include "ftl_io.h" 13 14 struct ftl_writer { 15 struct spdk_ftl_dev *dev; 16 17 TAILQ_HEAD(, ftl_rq) rq_queue; 18 19 /* Band currently being written to */ 20 struct ftl_band *band; 21 22 /* Number of bands associated with writer */ 23 uint64_t num_bands; 24 25 /* Band next being written to */ 26 struct ftl_band *next_band; 27 28 /* List of full bands */ 29 TAILQ_HEAD(, ftl_band) full_bands; 30 31 /* FTL band limit which blocks writes */ 32 int limit; 33 34 /* Flag indicating halt has been requested */ 35 bool halt; 36 37 /* Which type of band the writer uses */ 38 enum ftl_band_type writer_type; 39 40 uint64_t last_seq_id; 41 }; 42 43 bool ftl_writer_is_halted(struct ftl_writer *writer); 44 45 void ftl_writer_init(struct spdk_ftl_dev *dev, struct ftl_writer *writer, 46 uint64_t limit, enum ftl_band_type type); 47 48 void ftl_writer_run(struct ftl_writer *writer); 49 50 void ftl_writer_band_state_change(struct ftl_band *band); 51 52 static inline void 53 ftl_writer_halt(struct ftl_writer *writer) 54 { 55 writer->halt = true; 56 } 57 58 static inline void 59 ftl_writer_resume(struct ftl_writer *writer) 60 { 61 writer->halt = false; 62 } 63 64 bool ftl_writer_is_halted(struct ftl_writer *writer); 65 66 void ftl_writer_run(struct ftl_writer *writer); 67 68 static inline void 69 ftl_writer_queue_rq(struct ftl_writer *writer, struct ftl_rq *rq) 70 { 71 TAILQ_INSERT_TAIL(&writer->rq_queue, rq, qentry); 72 } 73 74 /** 75 * @brief Returns free space in currently processing band 76 */ 77 uint64_t ftl_writer_get_free_blocks(struct ftl_writer *writer); 78 79 #endif /* FTL_WRITER_H */ 80