1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * drivers/hyperhold/hp_iotab.h 4 * 5 * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd. 6 */ 7 8 #ifndef _HP_IOTAB_H_ 9 #define _HP_IOTAB_H_ 10 11 #include <linux/kernel.h> 12 #include <linux/kref.h> 13 #include <linux/completion.h> 14 #include <linux/workqueue.h> 15 16 enum hpio_state { 17 HPIO_INIT, 18 HPIO_SUBMIT, 19 HPIO_DONE, 20 HPIO_FAIL, 21 }; 22 23 struct hpio; 24 25 typedef void (*hp_endio)(struct hpio *); 26 27 struct hpio { 28 u32 eid; 29 struct page **pages; 30 u32 nr_page; 31 void *private; 32 33 unsigned int op; 34 void (*free_extent)(u32 eid); 35 36 atomic_t state; 37 struct kref refcnt; 38 struct completion wait; 39 hp_endio endio; 40 struct work_struct endio_work; 41 42 struct bio *bio; 43 struct list_head list; 44 }; 45 46 struct hpio *hpio_alloc(u32 nr_page, gfp_t gfp, unsigned int op, bool new_page); 47 void hpio_free(struct hpio *hpio); 48 49 struct hpio *hpio_get(u32 eid); 50 bool hpio_put(struct hpio *hpio); 51 struct hpio *hpio_get_alloc(u32 eid, u32 nr_page, gfp_t gfp, unsigned int op); 52 53 void hpio_complete(struct hpio *hpio); 54 void hpio_wait(struct hpio *hpio); 55 56 enum hpio_state hpio_get_state(struct hpio *hpio); 57 void hpio_set_state(struct hpio *hpio, enum hpio_state state); 58 bool hpio_change_state(struct hpio *hpio, enum hpio_state from, enum hpio_state to); 59 60 void wait_for_iotab_empty(void); 61 62 u64 hpio_memory(void); 63 #endif 64