]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* |
2 | * Copyright(c) 2012-2018 Intel Corporation | |
3 | * SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | */ | |
5 | ||
6 | #ifndef UTILS_RQ_H_ | |
7 | #define UTILS_RQ_H_ | |
8 | ||
9 | #include "../ocf_request.h" | |
10 | ||
11 | /** | |
12 | * @file utils_req.h | |
13 | * @brief OCF request allocation utilities | |
14 | */ | |
15 | ||
16 | struct ocf_req_allocator; | |
17 | ||
18 | /** | |
19 | * @brief Initialize OCF request allocation utility | |
20 | * | |
21 | * @param cache - OCF cache instance | |
22 | * @return Operation status 0 - successful, non-zero failure | |
23 | */ | |
24 | int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx); | |
25 | ||
26 | /** | |
27 | * @brief De-initialize OCF request allocation utility | |
28 | * | |
29 | * @param cache - OCF cache instance | |
30 | */ | |
31 | void ocf_req_allocator_deinit(struct ocf_ctx *ocf_ctx); | |
32 | ||
33 | /** | |
34 | * @brief Allocate new OCF request | |
35 | * | |
36 | * @param queue - I/O queue handle | |
37 | * @param core - OCF core instance | |
38 | * @param addr - LBA of request | |
39 | * @param bytes - number of bytes of request | |
40 | * @param rw - Read or Write | |
41 | * | |
42 | * @return new OCF request | |
43 | */ | |
44 | struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core, | |
45 | uint64_t addr, uint32_t bytes, int rw); | |
46 | ||
47 | /** | |
48 | * @brief Allocate OCF request map | |
49 | * | |
50 | * @param req OCF request | |
51 | * | |
52 | * @retval 0 Allocation succeed | |
53 | * @retval non-zero Allocation failed | |
54 | */ | |
55 | int ocf_req_alloc_map(struct ocf_request *req); | |
56 | ||
57 | /** | |
58 | * @brief Allocate new OCF request with NOIO map allocation for huge request | |
59 | * | |
60 | * @param queue - I/O queue handle | |
61 | * @param core - OCF core instance | |
62 | * @param addr - LBA of request | |
63 | * @param bytes - number of bytes of request | |
64 | * @param rw - Read or Write | |
65 | * | |
66 | * @return new OCF request | |
67 | */ | |
68 | ||
69 | struct ocf_request *ocf_req_new_extended(ocf_queue_t queue, ocf_core_t core, | |
70 | uint64_t addr, uint32_t bytes, int rw); | |
71 | ||
72 | /** | |
73 | * @brief Allocate new OCF request for DISCARD operation | |
74 | * | |
75 | * @param queue - I/O queue handle | |
76 | * @param core - OCF core instance | |
77 | * @param addr - LBA of request | |
78 | * @param bytes - number of bytes of request | |
79 | * @param rw - Read or Write | |
80 | * | |
81 | * @return new OCF request | |
82 | */ | |
83 | struct ocf_request *ocf_req_new_discard(ocf_queue_t queue, ocf_core_t core, | |
84 | uint64_t addr, uint32_t bytes, int rw); | |
85 | ||
86 | /** | |
87 | * @brief Get number of allocated requests | |
88 | * | |
89 | * @param cache OCF cache instance | |
90 | * | |
91 | * @return Number of allocated requests | |
92 | */ | |
93 | uint32_t ocf_req_get_allocated(struct ocf_cache *cache); | |
94 | ||
95 | /** | |
96 | * @brief Increment OCF request reference count | |
97 | * | |
98 | * @param req - OCF request | |
99 | */ | |
100 | void ocf_req_get(struct ocf_request *req); | |
101 | ||
102 | /** | |
103 | * @brief Decrement OCF request reference. If reference is 0 then request will | |
104 | * be deallocated | |
105 | * | |
106 | * @param req - OCF request | |
107 | */ | |
108 | void ocf_req_put(struct ocf_request *req); | |
109 | ||
110 | /** | |
111 | * @brief Clear OCF request info | |
112 | * | |
113 | * @param req - OCF request | |
114 | */ | |
115 | void ocf_req_clear_info(struct ocf_request *req); | |
116 | ||
117 | /** | |
118 | * @brief Clear OCF request map | |
119 | * | |
120 | * @param req - OCF request | |
121 | */ | |
122 | void ocf_req_clear_map(struct ocf_request *req); | |
123 | ||
124 | /** | |
125 | * @brief Clear OCF request | |
126 | * | |
127 | * @param req - OCF request | |
128 | */ | |
129 | static inline void ocf_req_clear(struct ocf_request *req) | |
130 | { | |
131 | ocf_req_clear_info(req); | |
132 | ocf_req_clear_map(req); | |
133 | ||
134 | env_atomic_set(&req->lock_remaining, 0); | |
135 | env_atomic_set(&req->req_remaining, 0); | |
136 | } | |
137 | ||
138 | /** | |
139 | * @brief Return OCF request reference count | |
140 | * | |
141 | * @param req - OCF request | |
142 | * @return OCF request reference count | |
143 | */ | |
144 | static inline int ocf_req_ref_count(struct ocf_request *req) | |
145 | { | |
146 | return env_atomic_read(&req->ref_count); | |
147 | } | |
148 | ||
149 | static inline bool ocf_req_is_4k(uint64_t addr, uint32_t bytes) | |
150 | { | |
151 | return !((addr % PAGE_SIZE) || (bytes % PAGE_SIZE)); | |
152 | } | |
153 | ||
154 | #endif /* UTILS_RQ_H_ */ |