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
16enum hpio_state {
17	HPIO_INIT,
18	HPIO_SUBMIT,
19	HPIO_DONE,
20	HPIO_FAIL,
21};
22
23struct hpio;
24
25typedef void (*hp_endio)(struct hpio *);
26
27struct 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
46struct hpio *hpio_alloc(u32 nr_page, gfp_t gfp, unsigned int op, bool new_page);
47void hpio_free(struct hpio *hpio);
48
49struct hpio *hpio_get(u32 eid);
50bool hpio_put(struct hpio *hpio);
51struct hpio *hpio_get_alloc(u32 eid, u32 nr_page, gfp_t gfp, unsigned int op);
52
53void hpio_complete(struct hpio *hpio);
54void hpio_wait(struct hpio *hpio);
55
56enum hpio_state hpio_get_state(struct hpio *hpio);
57void hpio_set_state(struct hpio *hpio, enum hpio_state state);
58bool hpio_change_state(struct hpio *hpio, enum hpio_state from, enum hpio_state to);
59
60void wait_for_iotab_empty(void);
61
62u64 hpio_memory(void);
63#endif
64