2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
6 #ifndef __OCF_CTX_PRIV_H__
7 #define __OCF_CTX_PRIV_H__
10 #include "ocf/ocf_ctx.h"
11 #include "ocf_logger_priv.h"
12 #include "ocf_volume_priv.h"
14 #define OCF_VOLUME_TYPE_MAX 8
17 * @brief OCF main control structure
20 const struct ocf_ctx_ops
*ops
;
21 const struct ocf_ctx_config
*cfg
;
22 struct ocf_logger logger
;
23 struct ocf_volume_type
*volume_type
[OCF_VOLUME_TYPE_MAX
];
26 struct list_head caches
;
28 struct list_head core_pool_head
;
33 struct ocf_req_allocator
*req
;
37 #define ocf_log_prefix(ctx, lvl, prefix, fmt, ...) \
38 ocf_log_raw(&ctx->logger, lvl, prefix fmt, ##__VA_ARGS__)
40 #define ocf_log(ctx, lvl, fmt, ...) \
41 ocf_log_prefix(ctx, lvl, "", fmt, ##__VA_ARGS__)
43 #define ocf_log_rl(ctx) \
44 ocf_log_raw_rl(&ctx->logger, __func__)
46 #define ocf_log_stack_trace(ctx) \
47 ocf_log_stack_trace_raw(&ctx->logger)
49 int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx
, uint8_t type_id
,
50 const struct ocf_volume_properties
*properties
,
51 const struct ocf_volume_extended
*extended
);
54 * @name Environment data buffer operations wrappers
57 static inline void *ctx_data_alloc(ocf_ctx_t ctx
, uint32_t pages
)
59 return ctx
->ops
->data
.alloc(pages
);
62 static inline void ctx_data_free(ocf_ctx_t ctx
, ctx_data_t
*data
)
64 ctx
->ops
->data
.free(data
);
67 static inline int ctx_data_mlock(ocf_ctx_t ctx
, ctx_data_t
*data
)
69 return ctx
->ops
->data
.mlock(data
);
72 static inline void ctx_data_munlock(ocf_ctx_t ctx
, ctx_data_t
*data
)
74 ctx
->ops
->data
.munlock(data
);
77 static inline uint32_t ctx_data_rd(ocf_ctx_t ctx
, void *dst
,
78 ctx_data_t
*src
, uint32_t size
)
80 return ctx
->ops
->data
.read(dst
, src
, size
);
83 static inline uint32_t ctx_data_wr(ocf_ctx_t ctx
, ctx_data_t
*dst
,
84 const void *src
, uint32_t size
)
86 return ctx
->ops
->data
.write(dst
, src
, size
);
89 static inline void ctx_data_rd_check(ocf_ctx_t ctx
, void *dst
,
90 ctx_data_t
*src
, uint32_t size
)
92 uint32_t read
= ctx_data_rd(ctx
, dst
, src
, size
);
94 ENV_BUG_ON(read
!= size
);
97 static inline void ctx_data_wr_check(ocf_ctx_t ctx
, ctx_data_t
*dst
,
98 const void *src
, uint32_t size
)
100 uint32_t written
= ctx_data_wr(ctx
, dst
, src
, size
);
102 ENV_BUG_ON(written
!= size
);
105 static inline uint32_t ctx_data_zero(ocf_ctx_t ctx
, ctx_data_t
*dst
,
108 return ctx
->ops
->data
.zero(dst
, size
);
111 static inline void ctx_data_zero_check(ocf_ctx_t ctx
, ctx_data_t
*dst
,
114 uint32_t zerored
= ctx_data_zero(ctx
, dst
, size
);
116 ENV_BUG_ON(zerored
!= size
);
119 static inline uint32_t ctx_data_seek(ocf_ctx_t ctx
, ctx_data_t
*dst
,
120 ctx_data_seek_t seek
, uint32_t size
)
122 return ctx
->ops
->data
.seek(dst
, seek
, size
);
125 static inline void ctx_data_seek_check(ocf_ctx_t ctx
, ctx_data_t
*dst
,
126 ctx_data_seek_t seek
, uint32_t size
)
128 uint32_t bytes
= ctx_data_seek(ctx
, dst
, seek
, size
);
130 ENV_BUG_ON(bytes
!= size
);
133 static inline uint64_t ctx_data_cpy(ocf_ctx_t ctx
, ctx_data_t
*dst
, ctx_data_t
*src
,
134 uint64_t to
, uint64_t from
, uint64_t bytes
)
136 return ctx
->ops
->data
.copy(dst
, src
, to
, from
, bytes
);
139 static inline void ctx_data_secure_erase(ocf_ctx_t ctx
, ctx_data_t
*dst
)
141 return ctx
->ops
->data
.secure_erase(dst
);
144 static inline int ctx_cleaner_init(ocf_ctx_t ctx
, ocf_cleaner_t cleaner
)
146 return ctx
->ops
->cleaner
.init(cleaner
);
149 static inline void ctx_cleaner_stop(ocf_ctx_t ctx
, ocf_cleaner_t cleaner
)
151 ctx
->ops
->cleaner
.stop(cleaner
);
154 static inline void ctx_cleaner_kick(ocf_ctx_t ctx
, ocf_cleaner_t cleaner
)
156 ctx
->ops
->cleaner
.kick(cleaner
);
159 static inline int ctx_metadata_updater_init(ocf_ctx_t ctx
,
160 ocf_metadata_updater_t mu
)
162 return ctx
->ops
->metadata_updater
.init(mu
);
165 static inline void ctx_metadata_updater_kick(ocf_ctx_t ctx
,
166 ocf_metadata_updater_t mu
)
168 ctx
->ops
->metadata_updater
.kick(mu
);
171 static inline void ctx_metadata_updater_stop(ocf_ctx_t ctx
,
172 ocf_metadata_updater_t mu
)
174 ctx
->ops
->metadata_updater
.stop(mu
);
181 #endif /* __OCF_CTX_PRIV_H__ */