18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * drivers/hyperhold/hp_iotab.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _HP_IOTAB_H_
98c2ecf20Sopenharmony_ci#define _HP_IOTAB_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/kernel.h>
128c2ecf20Sopenharmony_ci#include <linux/kref.h>
138c2ecf20Sopenharmony_ci#include <linux/completion.h>
148c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cienum hpio_state {
178c2ecf20Sopenharmony_ci	HPIO_INIT,
188c2ecf20Sopenharmony_ci	HPIO_SUBMIT,
198c2ecf20Sopenharmony_ci	HPIO_DONE,
208c2ecf20Sopenharmony_ci	HPIO_FAIL,
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct hpio;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_citypedef void (*hp_endio)(struct hpio *);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct hpio {
288c2ecf20Sopenharmony_ci	u32 eid;
298c2ecf20Sopenharmony_ci	struct page **pages;
308c2ecf20Sopenharmony_ci	u32 nr_page;
318c2ecf20Sopenharmony_ci	void *private;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	unsigned int op;
348c2ecf20Sopenharmony_ci	void (*free_extent)(u32 eid);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	atomic_t state;
378c2ecf20Sopenharmony_ci	struct kref refcnt;
388c2ecf20Sopenharmony_ci	struct completion wait;
398c2ecf20Sopenharmony_ci	hp_endio endio;
408c2ecf20Sopenharmony_ci	struct work_struct endio_work;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	struct bio *bio;
438c2ecf20Sopenharmony_ci	struct list_head list;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct hpio *hpio_alloc(u32 nr_page, gfp_t gfp, unsigned int op, bool new_page);
478c2ecf20Sopenharmony_civoid hpio_free(struct hpio *hpio);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct hpio *hpio_get(u32 eid);
508c2ecf20Sopenharmony_cibool hpio_put(struct hpio *hpio);
518c2ecf20Sopenharmony_cistruct hpio *hpio_get_alloc(u32 eid, u32 nr_page, gfp_t gfp, unsigned int op);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_civoid hpio_complete(struct hpio *hpio);
548c2ecf20Sopenharmony_civoid hpio_wait(struct hpio *hpio);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cienum hpio_state hpio_get_state(struct hpio *hpio);
578c2ecf20Sopenharmony_civoid hpio_set_state(struct hpio *hpio, enum hpio_state state);
588c2ecf20Sopenharmony_cibool hpio_change_state(struct hpio *hpio, enum hpio_state from, enum hpio_state to);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_civoid wait_for_iotab_empty(void);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciu64 hpio_memory(void);
638c2ecf20Sopenharmony_ci#endif
64