/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NAND_NFTL_H__
#define __NAND_NFTL_H__

#include "../nfd/nand_osal_for_linux.h"

#define NFTL_DBG_MESSAGE_ON

#ifdef NFTL_DBG_MESSAGE_ON
#define NFTL_DBG(...) nand_print_dbg(__VA_ARGS__)
#else
#define NFTL_DBG(...)
#endif

#define NFTL_ERR_MESSAGE_ON

#ifdef NFTL_ERR_MESSAGE_ON
#define NFTL_ERR(...) nand_print(__VA_ARGS__)
#else
#define NFTL_ERR(...)
#endif

#ifndef FACTORY_BAD_BLOCK_ERROR
#define FACTORY_BAD_BLOCK_ERROR 159
#endif
#ifndef BYTES_PER_SECTOR
#define BYTES_PER_SECTOR 512
#endif
#ifndef SHIFT_PER_SECTOR
#define SHIFT_PER_SECTOR 9
#endif
#ifndef BYTES_OF_USER_PER_PAGE
#define BYTES_OF_USER_PER_PAGE 16
#endif
#ifndef MIN_BYTES_OF_USER_PER_PAGE
#define MIN_BYTES_OF_USER_PER_PAGE 16
#endif

#define ZONE_RESERVED_BLOCK_RATIO 16
#define SYS_ZONE_RESERVED_BLOCK_RATIO 4
#define NORM_RESERVED_BLOCK_RATIO 10
#define SYS_RESERVED_BLOCK_RATIO 5

#define MIN_NAND_Free_BLOCK_NUM 20
#define MIN_NAND_Free_BLOCK 2
#define MAX_NAND_Free_BLOCK_NUM 120
#define MIN_NAND_Free_BLOCK_NUM_V2 25
#define MIN_NAND_Free_BLOCK_REMAIN 4
#define MIN_NAND_Free_BLOCK_NUM_RUNNING 15

typedef enum {
	NFTL_SUCCESS = 0,
	NFTL_FAILURE = 1,
	NFTL_INVALID_PARTITION = 2,
	NFTL_INVALID_ADDRESS = 3,
	NFTL_FLUSH_ERROR = 4,
	NFTL_PAGENOTFOUND = 5,
	NFTL_NO_NAND_Free_BLOCKS = 6,
	NFTL_NO_INVALID_BLOCKS = 7,
	NFTL_COMPLETE = 8,
	NFTL_YES = 1,
	NFTL_NO = 0,
} _nftl_error;

extern uint32 get_special_data_from_oob(uchar *buf);
extern uint32 get_erase_count_from_oob(uchar *buf);
extern uint32 get_block_used_count_from_oob(uchar *buf);
extern int is_nouse_page(u8 *buf);
extern void *nftl_malloc(uint32 size);
extern void nftl_free(const void *ptr);
extern int nftl_initialize(struct _nftl_blk *nftl_blk, int no);
extern int nftl_get_bad_block_cnt(struct _nftl_blk *nftl_blk);

#endif /*NAND_NFTL_H*/
