18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci#ifndef _BCACHE_FEATURES_H
38c2ecf20Sopenharmony_ci#define _BCACHE_FEATURES_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/bcache.h>
68c2ecf20Sopenharmony_ci#include <linux/kernel.h>
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define BCH_FEATURE_COMPAT		0
108c2ecf20Sopenharmony_ci#define BCH_FEATURE_RO_COMPAT		1
118c2ecf20Sopenharmony_ci#define BCH_FEATURE_INCOMPAT		2
128c2ecf20Sopenharmony_ci#define BCH_FEATURE_TYPE_MASK		0x03
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* Feature set definition */
158c2ecf20Sopenharmony_ci/* Incompat feature set */
168c2ecf20Sopenharmony_ci/* 32bit bucket size, obsoleted */
178c2ecf20Sopenharmony_ci#define BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET		0x0001
188c2ecf20Sopenharmony_ci/* real bucket size is (1 << bucket_size) */
198c2ecf20Sopenharmony_ci#define BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE	0x0002
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define BCH_FEATURE_COMPAT_SUPP		0
228c2ecf20Sopenharmony_ci#define BCH_FEATURE_RO_COMPAT_SUPP	0
238c2ecf20Sopenharmony_ci#define BCH_FEATURE_INCOMPAT_SUPP	(BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET| \
248c2ecf20Sopenharmony_ci					 BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define BCH_HAS_COMPAT_FEATURE(sb, mask) \
278c2ecf20Sopenharmony_ci		((sb)->feature_compat & (mask))
288c2ecf20Sopenharmony_ci#define BCH_HAS_RO_COMPAT_FEATURE(sb, mask) \
298c2ecf20Sopenharmony_ci		((sb)->feature_ro_compat & (mask))
308c2ecf20Sopenharmony_ci#define BCH_HAS_INCOMPAT_FEATURE(sb, mask) \
318c2ecf20Sopenharmony_ci		((sb)->feature_incompat & (mask))
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define BCH_FEATURE_COMPAT_FUNCS(name, flagname) \
348c2ecf20Sopenharmony_cistatic inline int bch_has_feature_##name(struct cache_sb *sb) \
358c2ecf20Sopenharmony_ci{ \
368c2ecf20Sopenharmony_ci	if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
378c2ecf20Sopenharmony_ci		return 0; \
388c2ecf20Sopenharmony_ci	return (((sb)->feature_compat & \
398c2ecf20Sopenharmony_ci		BCH##_FEATURE_COMPAT_##flagname) != 0); \
408c2ecf20Sopenharmony_ci} \
418c2ecf20Sopenharmony_cistatic inline void bch_set_feature_##name(struct cache_sb *sb) \
428c2ecf20Sopenharmony_ci{ \
438c2ecf20Sopenharmony_ci	(sb)->feature_compat |= \
448c2ecf20Sopenharmony_ci		BCH##_FEATURE_COMPAT_##flagname; \
458c2ecf20Sopenharmony_ci} \
468c2ecf20Sopenharmony_cistatic inline void bch_clear_feature_##name(struct cache_sb *sb) \
478c2ecf20Sopenharmony_ci{ \
488c2ecf20Sopenharmony_ci	(sb)->feature_compat &= \
498c2ecf20Sopenharmony_ci		~BCH##_FEATURE_COMPAT_##flagname; \
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define BCH_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
538c2ecf20Sopenharmony_cistatic inline int bch_has_feature_##name(struct cache_sb *sb) \
548c2ecf20Sopenharmony_ci{ \
558c2ecf20Sopenharmony_ci	if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
568c2ecf20Sopenharmony_ci		return 0; \
578c2ecf20Sopenharmony_ci	return (((sb)->feature_ro_compat & \
588c2ecf20Sopenharmony_ci		BCH##_FEATURE_RO_COMPAT_##flagname) != 0); \
598c2ecf20Sopenharmony_ci} \
608c2ecf20Sopenharmony_cistatic inline void bch_set_feature_##name(struct cache_sb *sb) \
618c2ecf20Sopenharmony_ci{ \
628c2ecf20Sopenharmony_ci	(sb)->feature_ro_compat |= \
638c2ecf20Sopenharmony_ci		BCH##_FEATURE_RO_COMPAT_##flagname; \
648c2ecf20Sopenharmony_ci} \
658c2ecf20Sopenharmony_cistatic inline void bch_clear_feature_##name(struct cache_sb *sb) \
668c2ecf20Sopenharmony_ci{ \
678c2ecf20Sopenharmony_ci	(sb)->feature_ro_compat &= \
688c2ecf20Sopenharmony_ci		~BCH##_FEATURE_RO_COMPAT_##flagname; \
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define BCH_FEATURE_INCOMPAT_FUNCS(name, flagname) \
728c2ecf20Sopenharmony_cistatic inline int bch_has_feature_##name(struct cache_sb *sb) \
738c2ecf20Sopenharmony_ci{ \
748c2ecf20Sopenharmony_ci	if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
758c2ecf20Sopenharmony_ci		return 0; \
768c2ecf20Sopenharmony_ci	return (((sb)->feature_incompat & \
778c2ecf20Sopenharmony_ci		BCH##_FEATURE_INCOMPAT_##flagname) != 0); \
788c2ecf20Sopenharmony_ci} \
798c2ecf20Sopenharmony_cistatic inline void bch_set_feature_##name(struct cache_sb *sb) \
808c2ecf20Sopenharmony_ci{ \
818c2ecf20Sopenharmony_ci	(sb)->feature_incompat |= \
828c2ecf20Sopenharmony_ci		BCH##_FEATURE_INCOMPAT_##flagname; \
838c2ecf20Sopenharmony_ci} \
848c2ecf20Sopenharmony_cistatic inline void bch_clear_feature_##name(struct cache_sb *sb) \
858c2ecf20Sopenharmony_ci{ \
868c2ecf20Sopenharmony_ci	(sb)->feature_incompat &= \
878c2ecf20Sopenharmony_ci		~BCH##_FEATURE_INCOMPAT_##flagname; \
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciBCH_FEATURE_INCOMPAT_FUNCS(obso_large_bucket, OBSO_LARGE_BUCKET);
918c2ecf20Sopenharmony_ciBCH_FEATURE_INCOMPAT_FUNCS(large_bucket, LOG_LARGE_BUCKET_SIZE);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic inline bool bch_has_unknown_compat_features(struct cache_sb *sb)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	return ((sb->feature_compat & ~BCH_FEATURE_COMPAT_SUPP) != 0);
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline bool bch_has_unknown_ro_compat_features(struct cache_sb *sb)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	return ((sb->feature_ro_compat & ~BCH_FEATURE_RO_COMPAT_SUPP) != 0);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline bool bch_has_unknown_incompat_features(struct cache_sb *sb)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	return ((sb->feature_incompat & ~BCH_FEATURE_INCOMPAT_SUPP) != 0);
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciint bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size);
1098c2ecf20Sopenharmony_ciint bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size);
1108c2ecf20Sopenharmony_ciint bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#endif
113