]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/nvdimm/btt.h
libnvdimm, btt: add support for blk integrity
[mirror_ubuntu-artful-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
18#include <linux/types.h>
19
20#define BTT_SIG_LEN 16
21#define BTT_SIG "BTT_ARENA_INFO\0"
5212e11f
VV
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)
33#define RTT_INVALID 0
41cd8b70 34#define INT_LBASIZE_ALIGNMENT 64
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
42enum btt_init_state {
43 INIT_UNCHECKED = 0,
44 INIT_NOTFOUND,
45 INIT_READY
46};
47
48struct log_entry {
49 __le32 lba;
50 __le32 old_map;
51 __le32 new_map;
52 __le32 seq;
53 __le64 padding[2];
54};
8c2f7e86
DW
55
56struct btt_sb {
57 u8 signature[BTT_SIG_LEN];
58 u8 uuid[16];
59 u8 parent_uuid[16];
60 __le32 flags;
61 __le16 version_major;
62 __le16 version_minor;
63 __le32 external_lbasize;
64 __le32 external_nlba;
65 __le32 internal_lbasize;
66 __le32 internal_nlba;
67 __le32 nfree;
68 __le32 infosize;
69 __le64 nextoff;
70 __le64 dataoff;
71 __le64 mapoff;
72 __le64 logoff;
73 __le64 info2off;
74 u8 padding[3968];
75 __le64 checksum;
76};
77
5212e11f
VV
78struct free_entry {
79 u32 block;
80 u8 sub;
81 u8 seq;
82};
83
84struct aligned_lock {
85 union {
86 spinlock_t lock;
87 u8 cacheline_padding[L1_CACHE_BYTES];
88 };
89};
90
91/**
92 * struct arena_info - handle for an arena
93 * @size: Size in bytes this arena occupies on the raw device.
94 * This includes arena metadata.
95 * @external_lba_start: The first external LBA in this arena.
96 * @internal_nlba: Number of internal blocks available in the arena
97 * including nfree reserved blocks
98 * @internal_lbasize: Internal and external lba sizes may be different as
99 * we can round up 'odd' external lbasizes such as 520B
100 * to be aligned.
101 * @external_nlba: Number of blocks contributed by the arena to the number
102 * reported to upper layers. (internal_nlba - nfree)
103 * @external_lbasize: LBA size as exposed to upper layers.
104 * @nfree: A reserve number of 'free' blocks that is used to
105 * handle incoming writes.
106 * @version_major: Metadata layout version major.
107 * @version_minor: Metadata layout version minor.
108 * @nextoff: Offset in bytes to the start of the next arena.
109 * @infooff: Offset in bytes to the info block of this arena.
110 * @dataoff: Offset in bytes to the data area of this arena.
111 * @mapoff: Offset in bytes to the map area of this arena.
112 * @logoff: Offset in bytes to the log area of this arena.
113 * @info2off: Offset in bytes to the backup info block of this arena.
114 * @freelist: Pointer to in-memory list of free blocks
115 * @rtt: Pointer to in-memory "Read Tracking Table"
116 * @map_locks: Spinlocks protecting concurrent map writes
117 * @nd_btt: Pointer to parent nd_btt structure.
118 * @list: List head for list of arenas
119 * @debugfs_dir: Debugfs dentry
120 * @flags: Arena flags - may signify error states.
121 *
122 * arena_info is a per-arena handle. Once an arena is narrowed down for an
123 * IO, this struct is passed around for the duration of the IO.
124 */
125struct arena_info {
126 u64 size; /* Total bytes for this arena */
127 u64 external_lba_start;
128 u32 internal_nlba;
129 u32 internal_lbasize;
130 u32 external_nlba;
131 u32 external_lbasize;
132 u32 nfree;
133 u16 version_major;
134 u16 version_minor;
135 /* Byte offsets to the different on-media structures */
136 u64 nextoff;
137 u64 infooff;
138 u64 dataoff;
139 u64 mapoff;
140 u64 logoff;
141 u64 info2off;
142 /* Pointers to other in-memory structures for this arena */
143 struct free_entry *freelist;
144 u32 *rtt;
145 struct aligned_lock *map_locks;
146 struct nd_btt *nd_btt;
147 struct list_head list;
148 struct dentry *debugfs_dir;
149 /* Arena flags */
150 u32 flags;
151};
152
153/**
154 * struct btt - handle for a BTT instance
155 * @btt_disk: Pointer to the gendisk for BTT device
156 * @btt_queue: Pointer to the request queue for the BTT device
157 * @arena_list: Head of the list of arenas
158 * @debugfs_dir: Debugfs dentry
159 * @nd_btt: Parent nd_btt struct
160 * @nlba: Number of logical blocks exposed to the upper layers
161 * after removing the amount of space needed by metadata
162 * @rawsize: Total size in bytes of the available backing device
163 * @lbasize: LBA size as requested and presented to upper layers.
164 * This is sector_size + size of any metadata.
165 * @sector_size: The Linux sector size - 512 or 4096
166 * @lanes: Per-lane spinlocks
167 * @init_lock: Mutex used for the BTT initialization
168 * @init_state: Flag describing the initialization state for the BTT
169 * @num_arenas: Number of arenas in the BTT instance
170 */
171struct btt {
172 struct gendisk *btt_disk;
173 struct request_queue *btt_queue;
174 struct list_head arena_list;
175 struct dentry *debugfs_dir;
176 struct nd_btt *nd_btt;
177 u64 nlba;
178 unsigned long long rawsize;
179 u32 lbasize;
180 u32 sector_size;
181 struct nd_region *nd_region;
182 struct mutex init_lock;
183 int init_state;
184 int num_arenas;
185};
8c2f7e86 186#endif