2 * Block Translation Table library
3 * Copyright (c) 2014-2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 #include <linux/types.h>
20 #define BTT_SIG_LEN 16
21 #define BTT_SIG "BTT_ARENA_INFO\0"
22 #define MAP_ENT_SIZE 4
23 #define MAP_TRIM_SHIFT 31
24 #define MAP_TRIM_MASK (1 << MAP_TRIM_SHIFT)
25 #define MAP_ERR_SHIFT 30
26 #define MAP_ERR_MASK (1 << MAP_ERR_SHIFT)
27 #define MAP_LBA_MASK (~((1 << MAP_TRIM_SHIFT) | (1 << MAP_ERR_SHIFT)))
28 #define MAP_ENT_NORMAL 0xC0000000
29 #define LOG_ENT_SIZE sizeof(struct log_entry)
30 #define ARENA_MIN_SIZE (1UL << 24) /* 16 MB */
31 #define ARENA_MAX_SIZE (1ULL << 39) /* 512 GB */
32 #define RTT_VALID (1UL << 31)
34 #define BTT_PG_SIZE 4096
35 #define BTT_DEFAULT_NFREE ND_MAX_LANES
36 #define LOG_SEQ_INIT 1
38 #define IB_FLAG_ERROR 0x00000001
39 #define IB_FLAG_ERROR_MASK 0x00000001
56 u8 signature
[BTT_SIG_LEN
];
62 __le32 external_lbasize
;
64 __le32 internal_lbasize
;
86 u8 cacheline_padding
[L1_CACHE_BYTES
];
91 * struct arena_info - handle for an arena
92 * @size: Size in bytes this arena occupies on the raw device.
93 * This includes arena metadata.
94 * @external_lba_start: The first external LBA in this arena.
95 * @internal_nlba: Number of internal blocks available in the arena
96 * including nfree reserved blocks
97 * @internal_lbasize: Internal and external lba sizes may be different as
98 * we can round up 'odd' external lbasizes such as 520B
100 * @external_nlba: Number of blocks contributed by the arena to the number
101 * reported to upper layers. (internal_nlba - nfree)
102 * @external_lbasize: LBA size as exposed to upper layers.
103 * @nfree: A reserve number of 'free' blocks that is used to
104 * handle incoming writes.
105 * @version_major: Metadata layout version major.
106 * @version_minor: Metadata layout version minor.
107 * @nextoff: Offset in bytes to the start of the next arena.
108 * @infooff: Offset in bytes to the info block of this arena.
109 * @dataoff: Offset in bytes to the data area of this arena.
110 * @mapoff: Offset in bytes to the map area of this arena.
111 * @logoff: Offset in bytes to the log area of this arena.
112 * @info2off: Offset in bytes to the backup info block of this arena.
113 * @freelist: Pointer to in-memory list of free blocks
114 * @rtt: Pointer to in-memory "Read Tracking Table"
115 * @map_locks: Spinlocks protecting concurrent map writes
116 * @nd_btt: Pointer to parent nd_btt structure.
117 * @list: List head for list of arenas
118 * @debugfs_dir: Debugfs dentry
119 * @flags: Arena flags - may signify error states.
121 * arena_info is a per-arena handle. Once an arena is narrowed down for an
122 * IO, this struct is passed around for the duration of the IO.
125 u64 size
; /* Total bytes for this arena */
126 u64 external_lba_start
;
128 u32 internal_lbasize
;
130 u32 external_lbasize
;
134 /* Byte offsets to the different on-media structures */
141 /* Pointers to other in-memory structures for this arena */
142 struct free_entry
*freelist
;
144 struct aligned_lock
*map_locks
;
145 struct nd_btt
*nd_btt
;
146 struct list_head list
;
147 struct dentry
*debugfs_dir
;
153 * struct btt - handle for a BTT instance
154 * @btt_disk: Pointer to the gendisk for BTT device
155 * @btt_queue: Pointer to the request queue for the BTT device
156 * @arena_list: Head of the list of arenas
157 * @debugfs_dir: Debugfs dentry
158 * @nd_btt: Parent nd_btt struct
159 * @nlba: Number of logical blocks exposed to the upper layers
160 * after removing the amount of space needed by metadata
161 * @rawsize: Total size in bytes of the available backing device
162 * @lbasize: LBA size as requested and presented to upper layers.
163 * This is sector_size + size of any metadata.
164 * @sector_size: The Linux sector size - 512 or 4096
165 * @lanes: Per-lane spinlocks
166 * @init_lock: Mutex used for the BTT initialization
167 * @init_state: Flag describing the initialization state for the BTT
168 * @num_arenas: Number of arenas in the BTT instance
171 struct gendisk
*btt_disk
;
172 struct request_queue
*btt_queue
;
173 struct list_head arena_list
;
174 struct dentry
*debugfs_dir
;
175 struct nd_btt
*nd_btt
;
177 unsigned long long rawsize
;
180 struct nd_region
*nd_region
;
181 struct mutex init_lock
;