]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/nvdimm/btt.h
libnvdimm, btt: add a couple of missing kernel-doc lines
[mirror_ubuntu-bionic-kernel.git] / drivers / nvdimm / btt.h
CommitLineData
8c2f7e86
DW
1/*
2 * Block Translation Table library
3 * Copyright (c) 2014-2015, Intel Corporation.
4 *
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.
8 *
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
12 * more details.
13 */
14
15#ifndef _LINUX_BTT_H
16#define _LINUX_BTT_H
17
d9b83c75 18#include <linux/badblocks.h>
8c2f7e86
DW
19#include <linux/types.h>
20
21#define BTT_SIG_LEN 16
22#define BTT_SIG "BTT_ARENA_INFO\0"
5212e11f
VV
23#define MAP_ENT_SIZE 4
24#define MAP_TRIM_SHIFT 31
25#define MAP_TRIM_MASK (1 << MAP_TRIM_SHIFT)
26#define MAP_ERR_SHIFT 30
27#define MAP_ERR_MASK (1 << MAP_ERR_SHIFT)
28#define MAP_LBA_MASK (~((1 << MAP_TRIM_SHIFT) | (1 << MAP_ERR_SHIFT)))
29#define MAP_ENT_NORMAL 0xC0000000
30#define LOG_ENT_SIZE sizeof(struct log_entry)
31#define ARENA_MIN_SIZE (1UL << 24) /* 16 MB */
32#define ARENA_MAX_SIZE (1ULL << 39) /* 512 GB */
33#define RTT_VALID (1UL << 31)
34#define RTT_INVALID 0
5212e11f
VV
35#define BTT_PG_SIZE 4096
36#define BTT_DEFAULT_NFREE ND_MAX_LANES
37#define LOG_SEQ_INIT 1
38
39#define IB_FLAG_ERROR 0x00000001
40#define IB_FLAG_ERROR_MASK 0x00000001
41
0595d539
VV
42#define ent_lba(ent) (ent & MAP_LBA_MASK)
43#define ent_e_flag(ent) (!!(ent & MAP_ERR_MASK))
44#define ent_z_flag(ent) (!!(ent & MAP_TRIM_MASK))
d9b83c75 45#define set_e_flag(ent) (ent |= MAP_ERR_MASK)
0595d539 46
5212e11f
VV
47enum btt_init_state {
48 INIT_UNCHECKED = 0,
49 INIT_NOTFOUND,
50 INIT_READY
51};
52
53struct log_entry {
54 __le32 lba;
55 __le32 old_map;
56 __le32 new_map;
57 __le32 seq;
58 __le64 padding[2];
59};
8c2f7e86
DW
60
61struct btt_sb {
62 u8 signature[BTT_SIG_LEN];
63 u8 uuid[16];
64 u8 parent_uuid[16];
65 __le32 flags;
66 __le16 version_major;
67 __le16 version_minor;
68 __le32 external_lbasize;
69 __le32 external_nlba;
70 __le32 internal_lbasize;
71 __le32 internal_nlba;
72 __le32 nfree;
73 __le32 infosize;
74 __le64 nextoff;
75 __le64 dataoff;
76 __le64 mapoff;
77 __le64 logoff;
78 __le64 info2off;
79 u8 padding[3968];
80 __le64 checksum;
81};
82
5212e11f
VV
83struct free_entry {
84 u32 block;
85 u8 sub;
86 u8 seq;
d9b83c75 87 u8 has_err;
5212e11f
VV
88};
89
90struct aligned_lock {
91 union {
92 spinlock_t lock;
93 u8 cacheline_padding[L1_CACHE_BYTES];
94 };
95};
96
97/**
98 * struct arena_info - handle for an arena
99 * @size: Size in bytes this arena occupies on the raw device.
100 * This includes arena metadata.
101 * @external_lba_start: The first external LBA in this arena.
102 * @internal_nlba: Number of internal blocks available in the arena
103 * including nfree reserved blocks
104 * @internal_lbasize: Internal and external lba sizes may be different as
105 * we can round up 'odd' external lbasizes such as 520B
106 * to be aligned.
107 * @external_nlba: Number of blocks contributed by the arena to the number
108 * reported to upper layers. (internal_nlba - nfree)
109 * @external_lbasize: LBA size as exposed to upper layers.
110 * @nfree: A reserve number of 'free' blocks that is used to
111 * handle incoming writes.
112 * @version_major: Metadata layout version major.
113 * @version_minor: Metadata layout version minor.
75892004 114 * @sector_size: The Linux sector size - 512 or 4096
5212e11f
VV
115 * @nextoff: Offset in bytes to the start of the next arena.
116 * @infooff: Offset in bytes to the info block of this arena.
117 * @dataoff: Offset in bytes to the data area of this arena.
118 * @mapoff: Offset in bytes to the map area of this arena.
119 * @logoff: Offset in bytes to the log area of this arena.
120 * @info2off: Offset in bytes to the backup info block of this arena.
121 * @freelist: Pointer to in-memory list of free blocks
122 * @rtt: Pointer to in-memory "Read Tracking Table"
123 * @map_locks: Spinlocks protecting concurrent map writes
124 * @nd_btt: Pointer to parent nd_btt structure.
125 * @list: List head for list of arenas
126 * @debugfs_dir: Debugfs dentry
127 * @flags: Arena flags - may signify error states.
13b7954c 128 * @err_lock: Mutex for synchronizing error clearing.
5212e11f
VV
129 *
130 * arena_info is a per-arena handle. Once an arena is narrowed down for an
131 * IO, this struct is passed around for the duration of the IO.
132 */
133struct arena_info {
134 u64 size; /* Total bytes for this arena */
135 u64 external_lba_start;
136 u32 internal_nlba;
137 u32 internal_lbasize;
138 u32 external_nlba;
139 u32 external_lbasize;
140 u32 nfree;
141 u16 version_major;
142 u16 version_minor;
75892004 143 u32 sector_size;
5212e11f
VV
144 /* Byte offsets to the different on-media structures */
145 u64 nextoff;
146 u64 infooff;
147 u64 dataoff;
148 u64 mapoff;
149 u64 logoff;
150 u64 info2off;
151 /* Pointers to other in-memory structures for this arena */
152 struct free_entry *freelist;
153 u32 *rtt;
154 struct aligned_lock *map_locks;
155 struct nd_btt *nd_btt;
156 struct list_head list;
157 struct dentry *debugfs_dir;
158 /* Arena flags */
159 u32 flags;
d9b83c75 160 struct mutex err_lock;
5212e11f
VV
161};
162
163/**
164 * struct btt - handle for a BTT instance
165 * @btt_disk: Pointer to the gendisk for BTT device
166 * @btt_queue: Pointer to the request queue for the BTT device
167 * @arena_list: Head of the list of arenas
168 * @debugfs_dir: Debugfs dentry
169 * @nd_btt: Parent nd_btt struct
170 * @nlba: Number of logical blocks exposed to the upper layers
171 * after removing the amount of space needed by metadata
172 * @rawsize: Total size in bytes of the available backing device
173 * @lbasize: LBA size as requested and presented to upper layers.
174 * This is sector_size + size of any metadata.
175 * @sector_size: The Linux sector size - 512 or 4096
176 * @lanes: Per-lane spinlocks
177 * @init_lock: Mutex used for the BTT initialization
178 * @init_state: Flag describing the initialization state for the BTT
179 * @num_arenas: Number of arenas in the BTT instance
13b7954c 180 * @phys_bb: Pointer to the namespace's badblocks structure
5212e11f
VV
181 */
182struct btt {
183 struct gendisk *btt_disk;
184 struct request_queue *btt_queue;
185 struct list_head arena_list;
186 struct dentry *debugfs_dir;
187 struct nd_btt *nd_btt;
188 u64 nlba;
189 unsigned long long rawsize;
190 u32 lbasize;
191 u32 sector_size;
192 struct nd_region *nd_region;
193 struct mutex init_lock;
194 int init_state;
195 int num_arenas;
d9b83c75 196 struct badblocks *phys_bb;
5212e11f 197};
ab45e763
VV
198
199bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super);
14e49454
VV
200int nd_btt_version(struct nd_btt *nd_btt, struct nd_namespace_common *ndns,
201 struct btt_sb *btt_sb);
ab45e763 202
8c2f7e86 203#endif