dm vdo: rename struct geometry to index_geometry
[linux-2.6-block.git] / drivers / md / dm-vdo / hash-utils.h
CommitLineData
024512e7
MS
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright 2023 Red Hat
4 */
5
6#ifndef UDS_HASH_UTILS_H
7#define UDS_HASH_UTILS_H
8
9#include "geometry.h"
10#include "numeric.h"
11#include "uds.h"
12
13/* Utilities for extracting portions of a request name for various uses. */
14
15/* How various portions of a record name are apportioned. */
16enum {
17 VOLUME_INDEX_BYTES_OFFSET = 0,
18 VOLUME_INDEX_BYTES_COUNT = 8,
19 CHAPTER_INDEX_BYTES_OFFSET = 8,
20 CHAPTER_INDEX_BYTES_COUNT = 6,
21 SAMPLE_BYTES_OFFSET = 14,
22 SAMPLE_BYTES_COUNT = 2,
23};
24
25static inline u64 uds_extract_chapter_index_bytes(const struct uds_record_name *name)
26{
27 const u8 *chapter_bits = &name->name[CHAPTER_INDEX_BYTES_OFFSET];
28 u64 bytes = (u64) get_unaligned_be16(chapter_bits) << 32;
29
30 bytes |= get_unaligned_be32(chapter_bits + 2);
31 return bytes;
32}
33
34static inline u64 uds_extract_volume_index_bytes(const struct uds_record_name *name)
35{
36 return get_unaligned_be64(&name->name[VOLUME_INDEX_BYTES_OFFSET]);
37}
38
39static inline u32 uds_extract_sampling_bytes(const struct uds_record_name *name)
40{
41 return get_unaligned_be16(&name->name[SAMPLE_BYTES_OFFSET]);
42}
43
44/* Compute the chapter delta list for a given name. */
45static inline u32 uds_hash_to_chapter_delta_list(const struct uds_record_name *name,
7f67d0f1 46 const struct index_geometry *geometry)
024512e7
MS
47{
48 return ((uds_extract_chapter_index_bytes(name) >> geometry->chapter_address_bits) &
49 ((1 << geometry->chapter_delta_list_bits) - 1));
50}
51
52/* Compute the chapter delta address for a given name. */
53static inline u32 uds_hash_to_chapter_delta_address(const struct uds_record_name *name,
7f67d0f1 54 const struct index_geometry *geometry)
024512e7
MS
55{
56 return uds_extract_chapter_index_bytes(name) & ((1 << geometry->chapter_address_bits) - 1);
57}
58
59static inline unsigned int uds_name_to_hash_slot(const struct uds_record_name *name,
60 unsigned int slot_count)
61{
62 return (unsigned int) (uds_extract_chapter_index_bytes(name) % slot_count);
63}
64
65#endif /* UDS_HASH_UTILS_H */