Javier González | 02a1520 | 2018-10-09 13:12:06 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 IT University of Copenhagen (rrpc.h) |
| 4 | * Copyright (C) 2016 CNEX Labs |
| 5 | * Initial release: Matias Bjorling <matias@cnexlabs.com> |
| 6 | * Write buffering: Javier Gonzalez <javier@cnexlabs.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License version |
| 10 | * 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * Implementation of a Physical Block-device target for Open-channel SSDs. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef PBLK_H_ |
| 22 | #define PBLK_H_ |
| 23 | |
| 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/blk-mq.h> |
| 26 | #include <linux/bio.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kthread.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | #include <linux/crc32.h> |
| 31 | #include <linux/uuid.h> |
| 32 | |
| 33 | #include <linux/lightnvm.h> |
| 34 | |
| 35 | /* Run only GC if less than 1/X blocks are free */ |
| 36 | #define GC_LIMIT_INVERSE 5 |
| 37 | #define GC_TIME_MSECS 1000 |
| 38 | |
| 39 | #define PBLK_SECTOR (512) |
| 40 | #define PBLK_EXPOSED_PAGE_SIZE (4096) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 41 | |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 42 | #define PBLK_NR_CLOSE_JOBS (4) |
| 43 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 44 | #define PBLK_CACHE_NAME_LEN (DISK_NAME_LEN + 16) |
| 45 | |
| 46 | #define PBLK_COMMAND_TIMEOUT_MS 30000 |
| 47 | |
| 48 | /* Max 512 LUNs per device */ |
| 49 | #define PBLK_MAX_LUNS_BITMAP (4) |
| 50 | |
| 51 | #define NR_PHY_IN_LOG (PBLK_EXPOSED_PAGE_SIZE / PBLK_SECTOR) |
| 52 | |
Javier González | 0d88039 | 2017-10-13 14:46:08 +0200 | [diff] [blame] | 53 | /* Static pool sizes */ |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 54 | #define PBLK_GEN_WS_POOL_SIZE (2) |
| 55 | |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 56 | #define PBLK_DEFAULT_OP (11) |
| 57 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 58 | enum { |
Javier González | e2cddf2 | 2017-10-13 14:46:19 +0200 | [diff] [blame] | 59 | PBLK_READ = READ, |
| 60 | PBLK_WRITE = WRITE,/* Write from write buffer */ |
| 61 | PBLK_WRITE_INT, /* Internal write - no write buffer */ |
Javier González | 8f55459 | 2018-01-05 14:16:16 +0100 | [diff] [blame] | 62 | PBLK_READ_RECOV, /* Recovery read - errors allowed */ |
Javier González | e2cddf2 | 2017-10-13 14:46:19 +0200 | [diff] [blame] | 63 | PBLK_ERASE, |
| 64 | }; |
| 65 | |
| 66 | enum { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 67 | /* IO Types */ |
| 68 | PBLK_IOTYPE_USER = 1 << 0, |
| 69 | PBLK_IOTYPE_GC = 1 << 1, |
| 70 | |
| 71 | /* Write buffer flags */ |
| 72 | PBLK_FLUSH_ENTRY = 1 << 2, |
| 73 | PBLK_WRITTEN_DATA = 1 << 3, |
| 74 | PBLK_SUBMITTED_ENTRY = 1 << 4, |
| 75 | PBLK_WRITABLE_ENTRY = 1 << 5, |
| 76 | }; |
| 77 | |
| 78 | enum { |
| 79 | PBLK_BLK_ST_OPEN = 0x1, |
| 80 | PBLK_BLK_ST_CLOSED = 0x2, |
| 81 | }; |
| 82 | |
Hans Holmberg | 4209c31 | 2018-10-09 13:11:55 +0200 | [diff] [blame] | 83 | enum { |
| 84 | PBLK_CHUNK_RESET_START, |
| 85 | PBLK_CHUNK_RESET_DONE, |
| 86 | PBLK_CHUNK_RESET_FAILED, |
| 87 | }; |
| 88 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 89 | struct pblk_sec_meta { |
| 90 | u64 reserved; |
| 91 | __le64 lba; |
| 92 | }; |
| 93 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 94 | /* The number of GC lists and the rate-limiter states go together. This way the |
| 95 | * rate-limiter can dictate how much GC is needed based on resource utilization. |
| 96 | */ |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 97 | #define PBLK_GC_NR_LISTS 4 |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 98 | |
| 99 | enum { |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 100 | PBLK_RL_OFF = 0, |
| 101 | PBLK_RL_WERR = 1, |
| 102 | PBLK_RL_HIGH = 2, |
| 103 | PBLK_RL_MID = 3, |
| 104 | PBLK_RL_LOW = 4 |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Matias Bjørling | afdc23c | 2018-10-09 13:11:37 +0200 | [diff] [blame] | 107 | #define pblk_dma_ppa_size (sizeof(u64) * NVM_MAX_VLBA) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 108 | |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 109 | /* write buffer completion context */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 110 | struct pblk_c_ctx { |
| 111 | struct list_head list; /* Head for out-of-order completion */ |
| 112 | |
| 113 | unsigned long *lun_bitmap; /* Luns used on current request */ |
| 114 | unsigned int sentry; |
| 115 | unsigned int nr_valid; |
| 116 | unsigned int nr_padded; |
| 117 | }; |
| 118 | |
Javier González | a4809fe | 2017-10-13 14:46:22 +0200 | [diff] [blame] | 119 | /* read context */ |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 120 | struct pblk_g_ctx { |
| 121 | void *private; |
Javier González | 998ba62 | 2018-01-05 14:16:20 +0100 | [diff] [blame] | 122 | unsigned long start_time; |
Javier González | a4809fe | 2017-10-13 14:46:22 +0200 | [diff] [blame] | 123 | u64 lba; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Heiner Litz | 11f6ad6 | 2018-07-13 10:48:44 +0200 | [diff] [blame] | 126 | /* partial read context */ |
| 127 | struct pblk_pr_ctx { |
| 128 | struct bio *orig_bio; |
| 129 | DECLARE_BITMAP(bitmap, NVM_MAX_VLBA); |
| 130 | unsigned int orig_nr_secs; |
| 131 | unsigned int bio_init_idx; |
| 132 | void *ppa_ptr; |
| 133 | dma_addr_t dma_ppa_list; |
Igor Konopko | dd43949 | 2018-12-11 20:16:22 +0100 | [diff] [blame] | 134 | __le64 lba_list_mem[NVM_MAX_VLBA]; |
| 135 | __le64 lba_list_media[NVM_MAX_VLBA]; |
Heiner Litz | 11f6ad6 | 2018-07-13 10:48:44 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 138 | /* Pad context */ |
| 139 | struct pblk_pad_rq { |
| 140 | struct pblk *pblk; |
| 141 | struct completion wait; |
| 142 | struct kref ref; |
| 143 | }; |
| 144 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 145 | /* Recovery context */ |
| 146 | struct pblk_rec_ctx { |
| 147 | struct pblk *pblk; |
| 148 | struct nvm_rq *rqd; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 149 | struct work_struct ws_rec; |
| 150 | }; |
| 151 | |
| 152 | /* Write context */ |
| 153 | struct pblk_w_ctx { |
| 154 | struct bio_list bios; /* Original bios - used for completion |
| 155 | * in REQ_FUA, REQ_FLUSH case |
| 156 | */ |
Arnd Bergmann | ef69790 | 2017-04-19 19:39:13 +0200 | [diff] [blame] | 157 | u64 lba; /* Logic addr. associated with entry */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 158 | struct ppa_addr ppa; /* Physic addr. associated with entry */ |
| 159 | int flags; /* Write context flags */ |
| 160 | }; |
| 161 | |
| 162 | struct pblk_rb_entry { |
| 163 | struct ppa_addr cacheline; /* Cacheline for this entry */ |
| 164 | void *data; /* Pointer to data on this entry */ |
| 165 | struct pblk_w_ctx w_ctx; /* Context for this entry */ |
| 166 | struct list_head index; /* List head to enable indexes */ |
| 167 | }; |
| 168 | |
| 169 | #define EMPTY_ENTRY (~0U) |
| 170 | |
| 171 | struct pblk_rb_pages { |
| 172 | struct page *pages; |
| 173 | int order; |
| 174 | struct list_head list; |
| 175 | }; |
| 176 | |
| 177 | struct pblk_rb { |
| 178 | struct pblk_rb_entry *entries; /* Ring buffer entries */ |
| 179 | unsigned int mem; /* Write offset - points to next |
| 180 | * writable entry in memory |
| 181 | */ |
| 182 | unsigned int subm; /* Read offset - points to last entry |
| 183 | * that has been submitted to the media |
| 184 | * to be persisted |
| 185 | */ |
| 186 | unsigned int sync; /* Synced - backpointer that signals |
| 187 | * the last submitted entry that has |
| 188 | * been successfully persisted to media |
| 189 | */ |
Hans Holmberg | 8154d29 | 2018-01-05 14:16:09 +0100 | [diff] [blame] | 190 | unsigned int flush_point; /* Sync point - last entry that must be |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 191 | * flushed to the media. Used with |
| 192 | * REQ_FLUSH and REQ_FUA |
| 193 | */ |
| 194 | unsigned int l2p_update; /* l2p update point - next entry for |
| 195 | * which l2p mapping will be updated to |
| 196 | * contain a device ppa address (instead |
| 197 | * of a cacheline |
| 198 | */ |
| 199 | unsigned int nr_entries; /* Number of entries in write buffer - |
| 200 | * must be a power of two |
| 201 | */ |
| 202 | unsigned int seg_size; /* Size of the data segments being |
| 203 | * stored on each entry. Typically this |
| 204 | * will be 4KB |
| 205 | */ |
| 206 | |
Javier González | 766c8ce | 2018-10-09 13:12:15 +0200 | [diff] [blame] | 207 | unsigned int back_thres; /* Threshold that shall be maintained by |
| 208 | * the backpointer in order to respect |
| 209 | * geo->mw_cunits on a per chunk basis |
| 210 | */ |
| 211 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 212 | struct list_head pages; /* List of data pages */ |
| 213 | |
| 214 | spinlock_t w_lock; /* Write lock */ |
| 215 | spinlock_t s_lock; /* Sync lock */ |
| 216 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 217 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Hans Holmberg | 8154d29 | 2018-01-05 14:16:09 +0100 | [diff] [blame] | 218 | atomic_t inflight_flush_point; /* Not served REQ_FLUSH | REQ_FUA */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 219 | #endif |
| 220 | }; |
| 221 | |
| 222 | #define PBLK_RECOVERY_SECTORS 16 |
| 223 | |
| 224 | struct pblk_lun { |
| 225 | struct ppa_addr bppa; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 226 | struct semaphore wr_sem; |
| 227 | }; |
| 228 | |
| 229 | struct pblk_gc_rq { |
| 230 | struct pblk_line *line; |
| 231 | void *data; |
Matias Bjørling | afdc23c | 2018-10-09 13:11:37 +0200 | [diff] [blame] | 232 | u64 paddr_list[NVM_MAX_VLBA]; |
| 233 | u64 lba_list[NVM_MAX_VLBA]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 234 | int nr_secs; |
| 235 | int secs_to_gc; |
| 236 | struct list_head list; |
| 237 | }; |
| 238 | |
| 239 | struct pblk_gc { |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 240 | /* These states are not protected by a lock since (i) they are in the |
| 241 | * fast path, and (ii) they are not critical. |
| 242 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 243 | int gc_active; |
| 244 | int gc_enabled; |
| 245 | int gc_forced; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 246 | |
| 247 | struct task_struct *gc_ts; |
| 248 | struct task_struct *gc_writer_ts; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 249 | struct task_struct *gc_reader_ts; |
| 250 | |
| 251 | struct workqueue_struct *gc_line_reader_wq; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 252 | struct workqueue_struct *gc_reader_wq; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 253 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 254 | struct timer_list gc_timer; |
| 255 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 256 | struct semaphore gc_sem; |
Hans Holmberg | d6b992f | 2017-10-13 14:46:41 +0200 | [diff] [blame] | 257 | atomic_t read_inflight_gc; /* Number of lines with inflight GC reads */ |
| 258 | atomic_t pipeline_gc; /* Number of lines in the GC pipeline - |
| 259 | * started reads to finished writes |
| 260 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 261 | int w_entries; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 262 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 263 | struct list_head w_list; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 264 | struct list_head r_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 265 | |
| 266 | spinlock_t lock; |
| 267 | spinlock_t w_lock; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 268 | spinlock_t r_lock; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | struct pblk_rl { |
| 272 | unsigned int high; /* Upper threshold for rate limiter (free run - |
| 273 | * user I/O rate limiter |
| 274 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 275 | unsigned int high_pw; /* High rounded up as a power of 2 */ |
| 276 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 277 | #define PBLK_USER_HIGH_THRS 8 /* Begin write limit at 12% available blks */ |
| 278 | #define PBLK_USER_LOW_THRS 10 /* Aggressive GC at 10% available blocks */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 279 | |
| 280 | int rb_windows_pw; /* Number of rate windows in the write buffer |
| 281 | * given as a power-of-2. This guarantees that |
| 282 | * when user I/O is being rate limited, there |
| 283 | * will be reserved enough space for the GC to |
| 284 | * place its payload. A window is of |
| 285 | * pblk->max_write_pgs size, which in NVMe is |
| 286 | * 64, i.e., 256kb. |
| 287 | */ |
| 288 | int rb_budget; /* Total number of entries available for I/O */ |
| 289 | int rb_user_max; /* Max buffer entries available for user I/O */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 290 | int rb_gc_max; /* Max buffer entries available for GC I/O */ |
| 291 | int rb_gc_rsv; /* Reserved buffer entries for GC I/O */ |
| 292 | int rb_state; /* Rate-limiter current state */ |
Javier González | da67e68f | 2017-10-13 14:46:05 +0200 | [diff] [blame] | 293 | int rb_max_io; /* Maximum size for an I/O giving the config */ |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 294 | |
| 295 | atomic_t rb_user_cnt; /* User I/O buffer counter */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 296 | atomic_t rb_gc_cnt; /* GC I/O buffer counter */ |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 297 | atomic_t rb_space; /* Space limit in case of reaching capacity */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 298 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 299 | int rsv_blocks; /* Reserved blocks for GC */ |
| 300 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 301 | int rb_user_active; |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 302 | int rb_gc_active; |
| 303 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 304 | atomic_t werr_lines; /* Number of write error lines that needs gc */ |
| 305 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 306 | struct timer_list u_timer; |
| 307 | |
| 308 | unsigned long long nr_secs; |
| 309 | unsigned long total_blocks; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 310 | |
| 311 | atomic_t free_blocks; /* Total number of free blocks (+ OP) */ |
| 312 | atomic_t free_user_blocks; /* Number of user free blocks (no OP) */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 313 | }; |
| 314 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 315 | #define PBLK_LINE_EMPTY (~0U) |
| 316 | |
| 317 | enum { |
| 318 | /* Line Types */ |
| 319 | PBLK_LINETYPE_FREE = 0, |
| 320 | PBLK_LINETYPE_LOG = 1, |
| 321 | PBLK_LINETYPE_DATA = 2, |
| 322 | |
| 323 | /* Line state */ |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 324 | PBLK_LINESTATE_NEW = 9, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 325 | PBLK_LINESTATE_FREE = 10, |
| 326 | PBLK_LINESTATE_OPEN = 11, |
| 327 | PBLK_LINESTATE_CLOSED = 12, |
| 328 | PBLK_LINESTATE_GC = 13, |
| 329 | PBLK_LINESTATE_BAD = 14, |
| 330 | PBLK_LINESTATE_CORRUPT = 15, |
| 331 | |
| 332 | /* GC group */ |
| 333 | PBLK_LINEGC_NONE = 20, |
| 334 | PBLK_LINEGC_EMPTY = 21, |
| 335 | PBLK_LINEGC_LOW = 22, |
| 336 | PBLK_LINEGC_MID = 23, |
| 337 | PBLK_LINEGC_HIGH = 24, |
| 338 | PBLK_LINEGC_FULL = 25, |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 339 | PBLK_LINEGC_WERR = 26 |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | #define PBLK_MAGIC 0x70626c6b /*pblk*/ |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 343 | |
| 344 | /* emeta/smeta persistent storage format versions: |
| 345 | * Changes in major version requires offline migration. |
| 346 | * Changes in minor version are handled automatically during |
| 347 | * recovery. |
| 348 | */ |
| 349 | |
| 350 | #define SMETA_VERSION_MAJOR (0) |
| 351 | #define SMETA_VERSION_MINOR (1) |
| 352 | |
| 353 | #define EMETA_VERSION_MAJOR (0) |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 354 | #define EMETA_VERSION_MINOR (2) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 355 | |
| 356 | struct line_header { |
| 357 | __le32 crc; |
| 358 | __le32 identifier; /* pblk identifier */ |
| 359 | __u8 uuid[16]; /* instance uuid */ |
| 360 | __le16 type; /* line type */ |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 361 | __u8 version_major; /* version major */ |
| 362 | __u8 version_minor; /* version minor */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 363 | __le32 id; /* line id for current line */ |
| 364 | }; |
| 365 | |
| 366 | struct line_smeta { |
| 367 | struct line_header header; |
| 368 | |
| 369 | __le32 crc; /* Full structure including struct crc */ |
| 370 | /* Previous line metadata */ |
| 371 | __le32 prev_id; /* Line id for previous line */ |
| 372 | |
| 373 | /* Current line metadata */ |
| 374 | __le64 seq_nr; /* Sequence number for current line */ |
| 375 | |
| 376 | /* Active writers */ |
| 377 | __le32 window_wr_lun; /* Number of parallel LUNs to write */ |
| 378 | |
| 379 | __le32 rsvd[2]; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 380 | |
| 381 | __le64 lun_bitmap[]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 382 | }; |
| 383 | |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 384 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 385 | /* |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 386 | * Metadata layout in media: |
| 387 | * First sector: |
| 388 | * 1. struct line_emeta |
| 389 | * 2. bad block bitmap (u64 * window_wr_lun) |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 390 | * 3. write amplification counters |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 391 | * Mid sectors (start at lbas_sector): |
| 392 | * 3. nr_lbas (u64) forming lba list |
| 393 | * Last sectors (start at vsc_sector): |
| 394 | * 4. u32 valid sector count (vsc) for all lines (~0U: free line) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 395 | */ |
| 396 | struct line_emeta { |
| 397 | struct line_header header; |
| 398 | |
| 399 | __le32 crc; /* Full structure including struct crc */ |
| 400 | |
| 401 | /* Previous line metadata */ |
| 402 | __le32 prev_id; /* Line id for prev line */ |
| 403 | |
| 404 | /* Current line metadata */ |
| 405 | __le64 seq_nr; /* Sequence number for current line */ |
| 406 | |
| 407 | /* Active writers */ |
| 408 | __le32 window_wr_lun; /* Number of parallel LUNs to write */ |
| 409 | |
| 410 | /* Bookkeeping for recovery */ |
| 411 | __le32 next_id; /* Line id for next line */ |
| 412 | __le64 nr_lbas; /* Number of lbas mapped in line */ |
| 413 | __le64 nr_valid_lbas; /* Number of valid lbas mapped in line */ |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 414 | __le64 bb_bitmap[]; /* Updated bad block bitmap for line */ |
| 415 | }; |
| 416 | |
| 417 | |
| 418 | /* Write amplification counters stored on media */ |
| 419 | struct wa_counters { |
| 420 | __le64 user; /* Number of user written sectors */ |
| 421 | __le64 gc; /* Number of sectors written by GC*/ |
| 422 | __le64 pad; /* Number of padded sectors */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | struct pblk_emeta { |
| 426 | struct line_emeta *buf; /* emeta buffer in media format */ |
| 427 | int mem; /* Write offset - points to next |
| 428 | * writable entry in memory |
| 429 | */ |
| 430 | atomic_t sync; /* Synced - backpointer that signals the |
| 431 | * last entry that has been successfully |
| 432 | * persisted to media |
| 433 | */ |
| 434 | unsigned int nr_entries; /* Number of emeta entries */ |
| 435 | }; |
| 436 | |
| 437 | struct pblk_smeta { |
| 438 | struct line_smeta *buf; /* smeta buffer in persistent format */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 439 | }; |
| 440 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 441 | struct pblk_w_err_gc { |
| 442 | int has_write_err; |
| 443 | __le64 *lba_list; |
| 444 | }; |
| 445 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 446 | struct pblk_line { |
| 447 | struct pblk *pblk; |
| 448 | unsigned int id; /* Line number corresponds to the |
| 449 | * block line |
| 450 | */ |
| 451 | unsigned int seq_nr; /* Unique line sequence number */ |
| 452 | |
| 453 | int state; /* PBLK_LINESTATE_X */ |
| 454 | int type; /* PBLK_LINETYPE_X */ |
| 455 | int gc_group; /* PBLK_LINEGC_X */ |
| 456 | struct list_head list; /* Free, GC lists */ |
| 457 | |
| 458 | unsigned long *lun_bitmap; /* Bitmap for LUNs mapped in line */ |
| 459 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 460 | struct nvm_chk_meta *chks; /* Chunks forming line */ |
| 461 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 462 | struct pblk_smeta *smeta; /* Start metadata */ |
| 463 | struct pblk_emeta *emeta; /* End medatada */ |
| 464 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 465 | int meta_line; /* Metadata line id */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 466 | int meta_distance; /* Distance between data and metadata */ |
| 467 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 468 | u64 smeta_ssec; /* Sector where smeta starts */ |
| 469 | u64 emeta_ssec; /* Sector where emeta starts */ |
| 470 | |
| 471 | unsigned int sec_in_line; /* Number of usable secs in line */ |
| 472 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 473 | atomic_t blk_in_line; /* Number of good blocks in line */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 474 | unsigned long *blk_bitmap; /* Bitmap for valid/invalid blocks */ |
| 475 | unsigned long *erase_bitmap; /* Bitmap for erased blocks */ |
| 476 | |
| 477 | unsigned long *map_bitmap; /* Bitmap for mapped sectors in line */ |
| 478 | unsigned long *invalid_bitmap; /* Bitmap for invalid sectors in line */ |
| 479 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 480 | atomic_t left_eblks; /* Blocks left for erasing */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 481 | atomic_t left_seblks; /* Blocks left for sync erasing */ |
| 482 | |
| 483 | int left_msecs; /* Sectors left for mapping */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 484 | unsigned int cur_sec; /* Sector map pointer */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 485 | unsigned int nr_valid_lbas; /* Number of valid lbas in line */ |
| 486 | |
| 487 | __le32 *vsc; /* Valid sector count in line */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 488 | |
| 489 | struct kref ref; /* Write buffer L2P references */ |
| 490 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 491 | struct pblk_w_err_gc *w_err_gc; /* Write error gc recovery metadata */ |
| 492 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 493 | spinlock_t lock; /* Necessary for invalid_bitmap only */ |
| 494 | }; |
| 495 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 496 | #define PBLK_DATA_LINES 4 |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 497 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 498 | enum { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 499 | PBLK_KMALLOC_META = 1, |
| 500 | PBLK_VMALLOC_META = 2, |
| 501 | }; |
| 502 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 503 | enum { |
| 504 | PBLK_EMETA_TYPE_HEADER = 1, /* struct line_emeta first sector */ |
| 505 | PBLK_EMETA_TYPE_LLBA = 2, /* lba list - type: __le64 */ |
| 506 | PBLK_EMETA_TYPE_VSC = 3, /* vsc list - type: __le32 */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | struct pblk_line_mgmt { |
| 510 | int nr_lines; /* Total number of full lines */ |
| 511 | int nr_free_lines; /* Number of full lines in free list */ |
| 512 | |
| 513 | /* Free lists - use free_lock */ |
| 514 | struct list_head free_list; /* Full lines ready to use */ |
| 515 | struct list_head corrupt_list; /* Full lines corrupted */ |
| 516 | struct list_head bad_list; /* Full lines bad */ |
| 517 | |
| 518 | /* GC lists - use gc_lock */ |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 519 | struct list_head *gc_lists[PBLK_GC_NR_LISTS]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 520 | struct list_head gc_high_list; /* Full lines ready to GC, high isc */ |
| 521 | struct list_head gc_mid_list; /* Full lines ready to GC, mid isc */ |
| 522 | struct list_head gc_low_list; /* Full lines ready to GC, low isc */ |
| 523 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 524 | struct list_head gc_werr_list; /* Write err recovery list */ |
| 525 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 526 | struct list_head gc_full_list; /* Full lines ready to GC, no valid */ |
| 527 | struct list_head gc_empty_list; /* Full lines close, all valid */ |
| 528 | |
| 529 | struct pblk_line *log_line; /* Current FTL log line */ |
| 530 | struct pblk_line *data_line; /* Current data line */ |
| 531 | struct pblk_line *log_next; /* Next FTL log line */ |
| 532 | struct pblk_line *data_next; /* Next data line */ |
| 533 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 534 | struct list_head emeta_list; /* Lines queued to schedule emeta */ |
| 535 | |
| 536 | __le32 *vsc_list; /* Valid sector counts for all lines */ |
| 537 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 538 | /* Metadata allocation type: VMALLOC | KMALLOC */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 539 | int emeta_alloc_type; |
| 540 | |
| 541 | /* Pre-allocated metadata for data lines */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 542 | struct pblk_smeta *sline_meta[PBLK_DATA_LINES]; |
| 543 | struct pblk_emeta *eline_meta[PBLK_DATA_LINES]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 544 | unsigned long meta_bitmap; |
| 545 | |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 546 | /* Cache and mempool for map/invalid bitmaps */ |
| 547 | struct kmem_cache *bitmap_cache; |
| 548 | mempool_t *bitmap_pool; |
| 549 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 550 | /* Helpers for fast bitmap calculations */ |
| 551 | unsigned long *bb_template; |
| 552 | unsigned long *bb_aux; |
| 553 | |
| 554 | unsigned long d_seq_nr; /* Data line unique sequence number */ |
| 555 | unsigned long l_seq_nr; /* Log line unique sequence number */ |
| 556 | |
| 557 | spinlock_t free_lock; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 558 | spinlock_t close_lock; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 559 | spinlock_t gc_lock; |
| 560 | }; |
| 561 | |
| 562 | struct pblk_line_meta { |
| 563 | unsigned int smeta_len; /* Total length for smeta */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 564 | unsigned int smeta_sec; /* Sectors needed for smeta */ |
| 565 | |
| 566 | unsigned int emeta_len[4]; /* Lengths for emeta: |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 567 | * [0]: Total |
| 568 | * [1]: struct line_emeta + |
| 569 | * bb_bitmap + struct wa_counters |
| 570 | * [2]: L2P portion |
| 571 | * [3]: vsc |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 572 | */ |
| 573 | unsigned int emeta_sec[4]; /* Sectors needed for emeta. Same layout |
| 574 | * as emeta_len |
| 575 | */ |
| 576 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 577 | unsigned int emeta_bb; /* Boundary for bb that affects emeta */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 578 | |
| 579 | unsigned int vsc_list_len; /* Length for vsc list */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 580 | unsigned int sec_bitmap_len; /* Length for sector bitmap in line */ |
| 581 | unsigned int blk_bitmap_len; /* Length for block bitmap in line */ |
| 582 | unsigned int lun_bitmap_len; /* Length for lun bitmap in line */ |
| 583 | |
| 584 | unsigned int blk_per_line; /* Number of blocks in a full line */ |
| 585 | unsigned int sec_per_line; /* Number of sectors in a line */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 586 | unsigned int dsec_per_line; /* Number of data sectors in a line */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 587 | unsigned int min_blk_line; /* Min. number of good blocks in line */ |
| 588 | |
| 589 | unsigned int mid_thrs; /* Threshold for GC mid list */ |
| 590 | unsigned int high_thrs; /* Threshold for GC high list */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 591 | |
| 592 | unsigned int meta_distance; /* Distance between data and metadata */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 593 | }; |
| 594 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 595 | enum { |
| 596 | PBLK_STATE_RUNNING = 0, |
| 597 | PBLK_STATE_STOPPING = 1, |
| 598 | PBLK_STATE_RECOVERING = 2, |
| 599 | PBLK_STATE_STOPPED = 3, |
| 600 | }; |
| 601 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 602 | /* Internal format to support not power-of-2 device formats */ |
| 603 | struct pblk_addrf { |
| 604 | /* gen to dev */ |
| 605 | int sec_stripe; |
| 606 | int ch_stripe; |
| 607 | int lun_stripe; |
| 608 | |
| 609 | /* dev to gen */ |
| 610 | int sec_lun_stripe; |
| 611 | int sec_ws_stripe; |
| 612 | }; |
| 613 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 614 | struct pblk { |
| 615 | struct nvm_tgt_dev *dev; |
| 616 | struct gendisk *disk; |
| 617 | |
| 618 | struct kobject kobj; |
| 619 | |
| 620 | struct pblk_lun *luns; |
| 621 | |
| 622 | struct pblk_line *lines; /* Line array */ |
| 623 | struct pblk_line_mgmt l_mg; /* Line management */ |
| 624 | struct pblk_line_meta lm; /* Line metadata */ |
| 625 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 626 | struct nvm_addrf addrf; /* Aligned address format */ |
| 627 | struct pblk_addrf uaddrf; /* Unaligned address format */ |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 628 | int addrf_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 629 | |
| 630 | struct pblk_rb rwb; |
| 631 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 632 | int state; /* pblk line state */ |
| 633 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 634 | int min_write_pgs; /* Minimum amount of pages required by controller */ |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 635 | int min_write_pgs_data; /* Minimum amount of payload pages */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 636 | int max_write_pgs; /* Maximum amount of pages supported by controller */ |
Igor Konopko | faa79f2 | 2018-12-11 20:16:23 +0100 | [diff] [blame] | 637 | int oob_meta_size; /* Size of OOB sector metadata */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 638 | |
| 639 | sector_t capacity; /* Device capacity when bad blocks are subtracted */ |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 640 | |
| 641 | int op; /* Percentage of device used for over-provisioning */ |
| 642 | int op_blks; /* Number of blocks used for over-provisioning */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 643 | |
| 644 | /* pblk provisioning values. Used by rate limiter */ |
| 645 | struct pblk_rl rl; |
| 646 | |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 647 | int sec_per_write; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 648 | |
| 649 | unsigned char instance_uuid[16]; |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 650 | |
| 651 | /* Persistent write amplification counters, 4kb sector I/Os */ |
| 652 | atomic64_t user_wa; /* Sectors written by user */ |
| 653 | atomic64_t gc_wa; /* Sectors written by GC */ |
| 654 | atomic64_t pad_wa; /* Padded sectors written */ |
| 655 | |
| 656 | /* Reset values for delta write amplification measurements */ |
| 657 | u64 user_rst_wa; |
| 658 | u64 gc_rst_wa; |
| 659 | u64 pad_rst_wa; |
| 660 | |
Hans Holmberg | 5d149bf | 2018-03-30 00:04:55 +0200 | [diff] [blame] | 661 | /* Counters used for calculating padding distribution */ |
| 662 | atomic64_t *pad_dist; /* Padding distribution buckets */ |
| 663 | u64 nr_flush_rst; /* Flushes reset value for pad dist.*/ |
| 664 | atomic64_t nr_flush; /* Number of flush/fua I/O */ |
| 665 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 666 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 667 | /* Non-persistent debug counters, 4kb sector I/Os */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 668 | atomic_long_t inflight_writes; /* Inflight writes (user and gc) */ |
| 669 | atomic_long_t padded_writes; /* Sectors padded due to flush/fua */ |
| 670 | atomic_long_t padded_wb; /* Sectors padded in write buffer */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 671 | atomic_long_t req_writes; /* Sectors stored on write buffer */ |
| 672 | atomic_long_t sub_writes; /* Sectors submitted from buffer */ |
| 673 | atomic_long_t sync_writes; /* Sectors synced to media */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 674 | atomic_long_t inflight_reads; /* Inflight sector read requests */ |
Javier González | db7ada3 | 2017-06-26 11:57:13 +0200 | [diff] [blame] | 675 | atomic_long_t cache_reads; /* Read requests that hit the cache */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 676 | atomic_long_t sync_reads; /* Completed sector read requests */ |
| 677 | atomic_long_t recov_writes; /* Sectors submitted from recovery */ |
| 678 | atomic_long_t recov_gc_writes; /* Sectors submitted from write GC */ |
| 679 | atomic_long_t recov_gc_reads; /* Sectors submitted from read GC */ |
| 680 | #endif |
| 681 | |
| 682 | spinlock_t lock; |
| 683 | |
| 684 | atomic_long_t read_failed; |
| 685 | atomic_long_t read_empty; |
| 686 | atomic_long_t read_high_ecc; |
| 687 | atomic_long_t read_failed_gc; |
| 688 | atomic_long_t write_failed; |
| 689 | atomic_long_t erase_failed; |
| 690 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 691 | atomic_t inflight_io; /* General inflight I/O counter */ |
| 692 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 693 | struct task_struct *writer_ts; |
| 694 | |
| 695 | /* Simple translation map of logical addresses to physical addresses. |
| 696 | * The logical addresses is known by the host system, while the physical |
| 697 | * addresses are used when writing to the disk block device. |
| 698 | */ |
| 699 | unsigned char *trans_map; |
| 700 | spinlock_t trans_lock; |
| 701 | |
| 702 | struct list_head compl_list; |
| 703 | |
Hans Holmberg | 6a3abf5 | 2018-06-01 16:41:05 +0200 | [diff] [blame] | 704 | spinlock_t resubmit_lock; /* Resubmit list lock */ |
| 705 | struct list_head resubmit_list; /* Resubmit list for failed writes*/ |
| 706 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 707 | mempool_t page_bio_pool; |
| 708 | mempool_t gen_ws_pool; |
| 709 | mempool_t rec_pool; |
| 710 | mempool_t r_rq_pool; |
| 711 | mempool_t w_rq_pool; |
| 712 | mempool_t e_rq_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 713 | |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 714 | struct workqueue_struct *close_wq; |
| 715 | struct workqueue_struct *bb_wq; |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 716 | struct workqueue_struct *r_end_wq; |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 717 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 718 | struct timer_list wtimer; |
| 719 | |
| 720 | struct pblk_gc gc; |
| 721 | }; |
| 722 | |
| 723 | struct pblk_line_ws { |
| 724 | struct pblk *pblk; |
| 725 | struct pblk_line *line; |
| 726 | void *priv; |
| 727 | struct work_struct ws; |
| 728 | }; |
| 729 | |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 730 | #define pblk_g_rq_size (sizeof(struct nvm_rq) + sizeof(struct pblk_g_ctx)) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 731 | #define pblk_w_rq_size (sizeof(struct nvm_rq) + sizeof(struct pblk_c_ctx)) |
| 732 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 733 | #define pblk_err(pblk, fmt, ...) \ |
| 734 | pr_err("pblk %s: " fmt, pblk->disk->disk_name, ##__VA_ARGS__) |
| 735 | #define pblk_info(pblk, fmt, ...) \ |
| 736 | pr_info("pblk %s: " fmt, pblk->disk->disk_name, ##__VA_ARGS__) |
| 737 | #define pblk_warn(pblk, fmt, ...) \ |
| 738 | pr_warn("pblk %s: " fmt, pblk->disk->disk_name, ##__VA_ARGS__) |
| 739 | #define pblk_debug(pblk, fmt, ...) \ |
| 740 | pr_debug("pblk %s: " fmt, pblk->disk->disk_name, ##__VA_ARGS__) |
| 741 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 742 | /* |
| 743 | * pblk ring buffer operations |
| 744 | */ |
Javier González | 766c8ce | 2018-10-09 13:12:15 +0200 | [diff] [blame] | 745 | int pblk_rb_init(struct pblk_rb *rb, unsigned int size, unsigned int threshold, |
| 746 | unsigned int seg_sz); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 747 | int pblk_rb_may_write_user(struct pblk_rb *rb, struct bio *bio, |
| 748 | unsigned int nr_entries, unsigned int *pos); |
| 749 | int pblk_rb_may_write_gc(struct pblk_rb *rb, unsigned int nr_entries, |
| 750 | unsigned int *pos); |
| 751 | void pblk_rb_write_entry_user(struct pblk_rb *rb, void *data, |
| 752 | struct pblk_w_ctx w_ctx, unsigned int pos); |
| 753 | void pblk_rb_write_entry_gc(struct pblk_rb *rb, void *data, |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 754 | struct pblk_w_ctx w_ctx, struct pblk_line *line, |
| 755 | u64 paddr, unsigned int pos); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 756 | struct pblk_w_ctx *pblk_rb_w_ctx(struct pblk_rb *rb, unsigned int pos); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 757 | void pblk_rb_flush(struct pblk_rb *rb); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 758 | |
| 759 | void pblk_rb_sync_l2p(struct pblk_rb *rb); |
Javier González | d624f37 | 2017-06-26 11:57:15 +0200 | [diff] [blame] | 760 | unsigned int pblk_rb_read_to_bio(struct pblk_rb *rb, struct nvm_rq *rqd, |
Javier González | 875d94f | 2017-10-13 14:46:18 +0200 | [diff] [blame] | 761 | unsigned int pos, unsigned int nr_entries, |
| 762 | unsigned int count); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 763 | int pblk_rb_copy_to_bio(struct pblk_rb *rb, struct bio *bio, sector_t lba, |
Javier González | 75cb8e9 | 2017-07-28 15:13:16 +0200 | [diff] [blame] | 764 | struct ppa_addr ppa, int bio_iter, bool advanced_bio); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 765 | unsigned int pblk_rb_read_commit(struct pblk_rb *rb, unsigned int entries); |
| 766 | |
| 767 | unsigned int pblk_rb_sync_init(struct pblk_rb *rb, unsigned long *flags); |
| 768 | unsigned int pblk_rb_sync_advance(struct pblk_rb *rb, unsigned int nr_entries); |
Javier González | 40b8657 | 2018-10-09 13:12:09 +0200 | [diff] [blame] | 769 | unsigned int pblk_rb_ptr_wrap(struct pblk_rb *rb, unsigned int p, |
| 770 | unsigned int nr_entries); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 771 | void pblk_rb_sync_end(struct pblk_rb *rb, unsigned long *flags); |
Hans Holmberg | 8154d29 | 2018-01-05 14:16:09 +0100 | [diff] [blame] | 772 | unsigned int pblk_rb_flush_point_count(struct pblk_rb *rb); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 773 | |
| 774 | unsigned int pblk_rb_read_count(struct pblk_rb *rb); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 775 | unsigned int pblk_rb_sync_count(struct pblk_rb *rb); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 776 | unsigned int pblk_rb_wrap_pos(struct pblk_rb *rb, unsigned int pos); |
| 777 | |
| 778 | int pblk_rb_tear_down_check(struct pblk_rb *rb); |
| 779 | int pblk_rb_pos_oob(struct pblk_rb *rb, u64 pos); |
Javier González | 9bd1f87 | 2018-10-09 13:12:10 +0200 | [diff] [blame] | 780 | void pblk_rb_free(struct pblk_rb *rb); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 781 | ssize_t pblk_rb_sysfs(struct pblk_rb *rb, char *buf); |
| 782 | |
| 783 | /* |
| 784 | * pblk core |
| 785 | */ |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 786 | struct nvm_rq *pblk_alloc_rqd(struct pblk *pblk, int type); |
| 787 | void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type); |
Javier González | 45dcf29 | 2018-10-09 13:12:02 +0200 | [diff] [blame] | 788 | int pblk_alloc_rqd_meta(struct pblk *pblk, struct nvm_rq *rqd); |
| 789 | void pblk_free_rqd_meta(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 790 | void pblk_set_sec_per_write(struct pblk *pblk, int sec_per_write); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 791 | int pblk_setup_w_rec_rq(struct pblk *pblk, struct nvm_rq *rqd, |
| 792 | struct pblk_c_ctx *c_ctx); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 793 | void pblk_discard(struct pblk *pblk, struct bio *bio); |
Matias Bjørling | aff3fb1 | 2018-10-09 13:11:36 +0200 | [diff] [blame] | 794 | struct nvm_chk_meta *pblk_get_chunk_meta(struct pblk *pblk); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 795 | struct nvm_chk_meta *pblk_chunk_get_off(struct pblk *pblk, |
| 796 | struct nvm_chk_meta *lp, |
| 797 | struct ppa_addr ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 798 | void pblk_log_write_err(struct pblk *pblk, struct nvm_rq *rqd); |
| 799 | void pblk_log_read_err(struct pblk *pblk, struct nvm_rq *rqd); |
| 800 | int pblk_submit_io(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 801 | int pblk_submit_io_sync(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | 253babc | 2018-10-09 13:12:04 +0200 | [diff] [blame] | 802 | int pblk_submit_io_sync_sem(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 803 | int pblk_submit_meta_io(struct pblk *pblk, struct pblk_line *meta_line); |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 804 | void pblk_check_chunk_state_update(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 805 | struct bio *pblk_bio_map_addr(struct pblk *pblk, void *data, |
| 806 | unsigned int nr_secs, unsigned int len, |
Javier González | de54e70 | 2017-06-30 17:56:39 +0200 | [diff] [blame] | 807 | int alloc_type, gfp_t gfp_mask); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 808 | struct pblk_line *pblk_line_get(struct pblk *pblk); |
| 809 | struct pblk_line *pblk_line_get_first_data(struct pblk *pblk); |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 810 | struct pblk_line *pblk_line_replace_data(struct pblk *pblk); |
Matias Bjørling | ae14cc0 | 2018-10-09 13:11:40 +0200 | [diff] [blame] | 811 | void pblk_ppa_to_line_put(struct pblk *pblk, struct ppa_addr ppa); |
| 812 | void pblk_rq_to_line_put(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 813 | int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line); |
| 814 | void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line); |
| 815 | struct pblk_line *pblk_line_get_data(struct pblk *pblk); |
Javier González | d624f37 | 2017-06-26 11:57:15 +0200 | [diff] [blame] | 816 | struct pblk_line *pblk_line_get_erase(struct pblk *pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 817 | int pblk_line_erase(struct pblk *pblk, struct pblk_line *line); |
| 818 | int pblk_line_is_full(struct pblk_line *line); |
Javier González | 8e55c07 | 2018-06-01 15:04:22 +0200 | [diff] [blame] | 819 | void pblk_line_free(struct pblk_line *line); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 820 | void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 821 | void pblk_line_close(struct pblk *pblk, struct pblk_line *line); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 822 | void pblk_line_close_ws(struct work_struct *work); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 823 | void pblk_pipeline_stop(struct pblk *pblk); |
Javier González | a7c9e91 | 2018-06-01 15:04:24 +0200 | [diff] [blame] | 824 | void __pblk_pipeline_stop(struct pblk *pblk); |
| 825 | void __pblk_pipeline_flush(struct pblk *pblk); |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 826 | void pblk_gen_run_ws(struct pblk *pblk, struct pblk_line *line, void *priv, |
| 827 | void (*work)(struct work_struct *), gfp_t gfp_mask, |
| 828 | struct workqueue_struct *wq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 829 | u64 pblk_line_smeta_start(struct pblk *pblk, struct pblk_line *line); |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 830 | int pblk_line_smeta_read(struct pblk *pblk, struct pblk_line *line); |
| 831 | int pblk_line_emeta_read(struct pblk *pblk, struct pblk_line *line, |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 832 | void *emeta_buf); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 833 | int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr erase_ppa); |
| 834 | void pblk_line_put(struct kref *ref); |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 835 | void pblk_line_put_wq(struct kref *ref); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 836 | struct list_head *pblk_line_gc_list(struct pblk *pblk, struct pblk_line *line); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 837 | u64 pblk_lookup_page(struct pblk *pblk, struct pblk_line *line); |
| 838 | void pblk_dealloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 839 | u64 pblk_alloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 840 | u64 __pblk_alloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 841 | int pblk_calc_secs(struct pblk *pblk, unsigned long secs_avail, |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 842 | unsigned long secs_to_flush, bool skip_meta); |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 843 | void pblk_down_rq(struct pblk *pblk, struct ppa_addr ppa, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 844 | unsigned long *lun_bitmap); |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 845 | void pblk_down_chunk(struct pblk *pblk, struct ppa_addr ppa); |
| 846 | void pblk_up_chunk(struct pblk *pblk, struct ppa_addr ppa); |
Hans Holmberg | e99e802 | 2018-10-09 13:11:48 +0200 | [diff] [blame] | 847 | void pblk_up_rq(struct pblk *pblk, unsigned long *lun_bitmap); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 848 | int pblk_bio_add_pages(struct pblk *pblk, struct bio *bio, gfp_t flags, |
| 849 | int nr_pages); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 850 | void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off, |
| 851 | int nr_pages); |
| 852 | void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa); |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 853 | void __pblk_map_invalidate(struct pblk *pblk, struct pblk_line *line, |
| 854 | u64 paddr); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 855 | void pblk_update_map(struct pblk *pblk, sector_t lba, struct ppa_addr ppa); |
| 856 | void pblk_update_map_cache(struct pblk *pblk, sector_t lba, |
| 857 | struct ppa_addr ppa); |
| 858 | void pblk_update_map_dev(struct pblk *pblk, sector_t lba, |
| 859 | struct ppa_addr ppa, struct ppa_addr entry_line); |
| 860 | int pblk_update_map_gc(struct pblk *pblk, sector_t lba, struct ppa_addr ppa, |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 861 | struct pblk_line *gc_line, u64 paddr); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 862 | void pblk_lookup_l2p_rand(struct pblk *pblk, struct ppa_addr *ppas, |
| 863 | u64 *lba_list, int nr_secs); |
| 864 | void pblk_lookup_l2p_seq(struct pblk *pblk, struct ppa_addr *ppas, |
| 865 | sector_t blba, int nr_secs); |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 866 | void *pblk_get_meta_for_writes(struct pblk *pblk, struct nvm_rq *rqd); |
| 867 | void pblk_get_packed_meta(struct pblk *pblk, struct nvm_rq *rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 868 | |
| 869 | /* |
| 870 | * pblk user I/O write path |
| 871 | */ |
| 872 | int pblk_write_to_cache(struct pblk *pblk, struct bio *bio, |
| 873 | unsigned long flags); |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 874 | int pblk_write_gc_to_cache(struct pblk *pblk, struct pblk_gc_rq *gc_rq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * pblk map |
| 878 | */ |
Hans Holmberg | 525f7bb | 2018-12-11 20:16:12 +0100 | [diff] [blame] | 879 | int pblk_map_erase_rq(struct pblk *pblk, struct nvm_rq *rqd, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 880 | unsigned int sentry, unsigned long *lun_bitmap, |
| 881 | unsigned int valid_secs, struct ppa_addr *erase_ppa); |
Hans Holmberg | 525f7bb | 2018-12-11 20:16:12 +0100 | [diff] [blame] | 882 | int pblk_map_rq(struct pblk *pblk, struct nvm_rq *rqd, unsigned int sentry, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 883 | unsigned long *lun_bitmap, unsigned int valid_secs, |
| 884 | unsigned int off); |
| 885 | |
| 886 | /* |
| 887 | * pblk write thread |
| 888 | */ |
| 889 | int pblk_write_ts(void *data); |
Kees Cook | 87c1d2d | 2017-10-17 21:10:19 -0700 | [diff] [blame] | 890 | void pblk_write_timer_fn(struct timer_list *t); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 891 | void pblk_write_should_kick(struct pblk *pblk); |
Hans Holmberg | cc9c9a0 | 2018-06-01 16:41:13 +0200 | [diff] [blame] | 892 | void pblk_write_kick(struct pblk *pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * pblk read path |
| 896 | */ |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 897 | extern struct bio_set pblk_bio_set; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 898 | int pblk_submit_read(struct pblk *pblk, struct bio *bio); |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 899 | int pblk_submit_read_gc(struct pblk *pblk, struct pblk_gc_rq *gc_rq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 900 | /* |
| 901 | * pblk recovery |
| 902 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 903 | struct pblk_line *pblk_recov_l2p(struct pblk *pblk); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 904 | int pblk_recov_pad(struct pblk *pblk); |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 905 | int pblk_recov_check_emeta(struct pblk *pblk, struct line_emeta *emeta); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 906 | |
| 907 | /* |
| 908 | * pblk gc |
| 909 | */ |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 910 | #define PBLK_GC_MAX_READERS 8 /* Max number of outstanding GC reader jobs */ |
Javier González | 3627896 | 2017-10-13 14:46:11 +0200 | [diff] [blame] | 911 | #define PBLK_GC_RQ_QD 128 /* Queue depth for inflight GC requests */ |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 912 | #define PBLK_GC_L_QD 4 /* Queue depth for inflight GC lines */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 913 | |
| 914 | int pblk_gc_init(struct pblk *pblk); |
Javier González | a7c9e91 | 2018-06-01 15:04:24 +0200 | [diff] [blame] | 915 | void pblk_gc_exit(struct pblk *pblk, bool graceful); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 916 | void pblk_gc_should_start(struct pblk *pblk); |
| 917 | void pblk_gc_should_stop(struct pblk *pblk); |
Hans Holmberg | 03661b5 | 2017-10-13 14:46:37 +0200 | [diff] [blame] | 918 | void pblk_gc_should_kick(struct pblk *pblk); |
Hans Holmberg | 37ce33d | 2017-10-13 14:46:36 +0200 | [diff] [blame] | 919 | void pblk_gc_free_full_lines(struct pblk *pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 920 | void pblk_gc_sysfs_state_show(struct pblk *pblk, int *gc_enabled, |
| 921 | int *gc_active); |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 922 | int pblk_gc_sysfs_force(struct pblk *pblk, int force); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 923 | |
| 924 | /* |
| 925 | * pblk rate limiter |
| 926 | */ |
| 927 | void pblk_rl_init(struct pblk_rl *rl, int budget); |
| 928 | void pblk_rl_free(struct pblk_rl *rl); |
Hans Holmberg | 03661b5 | 2017-10-13 14:46:37 +0200 | [diff] [blame] | 929 | void pblk_rl_update_rates(struct pblk_rl *rl); |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 930 | int pblk_rl_high_thrs(struct pblk_rl *rl); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 931 | unsigned long pblk_rl_nr_free_blks(struct pblk_rl *rl); |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 932 | unsigned long pblk_rl_nr_user_free_blks(struct pblk_rl *rl); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 933 | int pblk_rl_user_may_insert(struct pblk_rl *rl, int nr_entries); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 934 | void pblk_rl_inserted(struct pblk_rl *rl, int nr_entries); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 935 | void pblk_rl_user_in(struct pblk_rl *rl, int nr_entries); |
| 936 | int pblk_rl_gc_may_insert(struct pblk_rl *rl, int nr_entries); |
| 937 | void pblk_rl_gc_in(struct pblk_rl *rl, int nr_entries); |
| 938 | void pblk_rl_out(struct pblk_rl *rl, int nr_user, int nr_gc); |
Javier González | da67e68f | 2017-10-13 14:46:05 +0200 | [diff] [blame] | 939 | int pblk_rl_max_io(struct pblk_rl *rl); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 940 | void pblk_rl_free_lines_inc(struct pblk_rl *rl, struct pblk_line *line); |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 941 | void pblk_rl_free_lines_dec(struct pblk_rl *rl, struct pblk_line *line, |
| 942 | bool used); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 943 | int pblk_rl_is_limit(struct pblk_rl *rl); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 944 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 945 | void pblk_rl_werr_line_in(struct pblk_rl *rl); |
| 946 | void pblk_rl_werr_line_out(struct pblk_rl *rl); |
| 947 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 948 | /* |
| 949 | * pblk sysfs |
| 950 | */ |
| 951 | int pblk_sysfs_init(struct gendisk *tdisk); |
| 952 | void pblk_sysfs_exit(struct gendisk *tdisk); |
| 953 | |
| 954 | static inline void *pblk_malloc(size_t size, int type, gfp_t flags) |
| 955 | { |
| 956 | if (type == PBLK_KMALLOC_META) |
| 957 | return kmalloc(size, flags); |
| 958 | return vmalloc(size); |
| 959 | } |
| 960 | |
| 961 | static inline void pblk_mfree(void *ptr, int type) |
| 962 | { |
| 963 | if (type == PBLK_KMALLOC_META) |
| 964 | kfree(ptr); |
| 965 | else |
| 966 | vfree(ptr); |
| 967 | } |
| 968 | |
| 969 | static inline struct nvm_rq *nvm_rq_from_c_ctx(void *c_ctx) |
| 970 | { |
| 971 | return c_ctx - sizeof(struct nvm_rq); |
| 972 | } |
| 973 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 974 | static inline void *emeta_to_bb(struct line_emeta *emeta) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 975 | { |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 976 | return emeta->bb_bitmap; |
| 977 | } |
| 978 | |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 979 | static inline void *emeta_to_wa(struct pblk_line_meta *lm, |
| 980 | struct line_emeta *emeta) |
| 981 | { |
| 982 | return emeta->bb_bitmap + lm->blk_bitmap_len; |
| 983 | } |
| 984 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 985 | static inline void *emeta_to_lbas(struct pblk *pblk, struct line_emeta *emeta) |
| 986 | { |
| 987 | return ((void *)emeta + pblk->lm.emeta_len[1]); |
| 988 | } |
| 989 | |
| 990 | static inline void *emeta_to_vsc(struct pblk *pblk, struct line_emeta *emeta) |
| 991 | { |
| 992 | return (emeta_to_lbas(pblk, emeta) + pblk->lm.emeta_len[2]); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 993 | } |
| 994 | |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 995 | static inline int pblk_line_vsc(struct pblk_line *line) |
| 996 | { |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 997 | return le32_to_cpu(*line->vsc); |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 998 | } |
| 999 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1000 | static inline int pblk_ppa_to_line_id(struct ppa_addr p) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1001 | { |
Javier González | 6947151 | 2018-03-30 00:05:15 +0200 | [diff] [blame] | 1002 | return p.a.blk; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1005 | static inline struct pblk_line *pblk_ppa_to_line(struct pblk *pblk, |
| 1006 | struct ppa_addr p) |
| 1007 | { |
| 1008 | return &pblk->lines[pblk_ppa_to_line_id(p)]; |
| 1009 | } |
| 1010 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1011 | static inline int pblk_ppa_to_pos(struct nvm_geo *geo, struct ppa_addr p) |
| 1012 | { |
Javier González | 6947151 | 2018-03-30 00:05:15 +0200 | [diff] [blame] | 1013 | return p.a.lun * geo->num_ch + p.a.ch; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1016 | static inline struct ppa_addr addr_to_gen_ppa(struct pblk *pblk, u64 paddr, |
| 1017 | u64 line_id) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1018 | { |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1019 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1020 | struct nvm_geo *geo = &dev->geo; |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1021 | struct ppa_addr ppa; |
| 1022 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1023 | if (geo->version == NVM_OCSSD_SPEC_12) { |
| 1024 | struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf; |
| 1025 | |
| 1026 | ppa.ppa = 0; |
| 1027 | ppa.g.blk = line_id; |
| 1028 | ppa.g.pg = (paddr & ppaf->pg_mask) >> ppaf->pg_offset; |
| 1029 | ppa.g.lun = (paddr & ppaf->lun_mask) >> ppaf->lun_offset; |
| 1030 | ppa.g.ch = (paddr & ppaf->ch_mask) >> ppaf->ch_offset; |
| 1031 | ppa.g.pl = (paddr & ppaf->pln_mask) >> ppaf->pln_offset; |
| 1032 | ppa.g.sec = (paddr & ppaf->sec_mask) >> ppaf->sec_offset; |
| 1033 | } else { |
| 1034 | struct pblk_addrf *uaddrf = &pblk->uaddrf; |
| 1035 | int secs, chnls, luns; |
| 1036 | |
| 1037 | ppa.ppa = 0; |
| 1038 | |
| 1039 | ppa.m.chk = line_id; |
| 1040 | |
| 1041 | paddr = div_u64_rem(paddr, uaddrf->sec_stripe, &secs); |
| 1042 | ppa.m.sec = secs; |
| 1043 | |
| 1044 | paddr = div_u64_rem(paddr, uaddrf->ch_stripe, &chnls); |
| 1045 | ppa.m.grp = chnls; |
| 1046 | |
| 1047 | paddr = div_u64_rem(paddr, uaddrf->lun_stripe, &luns); |
| 1048 | ppa.m.pu = luns; |
| 1049 | |
| 1050 | ppa.m.sec += uaddrf->sec_stripe * paddr; |
| 1051 | } |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1052 | |
| 1053 | return ppa; |
| 1054 | } |
| 1055 | |
Javier González | 2cf99bb | 2018-10-09 13:11:41 +0200 | [diff] [blame] | 1056 | static inline struct nvm_chk_meta *pblk_dev_ppa_to_chunk(struct pblk *pblk, |
| 1057 | struct ppa_addr p) |
| 1058 | { |
| 1059 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1060 | struct nvm_geo *geo = &dev->geo; |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1061 | struct pblk_line *line = pblk_ppa_to_line(pblk, p); |
Javier González | 2cf99bb | 2018-10-09 13:11:41 +0200 | [diff] [blame] | 1062 | int pos = pblk_ppa_to_pos(geo, p); |
| 1063 | |
| 1064 | return &line->chks[pos]; |
| 1065 | } |
| 1066 | |
| 1067 | static inline u64 pblk_dev_ppa_to_chunk_addr(struct pblk *pblk, |
| 1068 | struct ppa_addr p) |
| 1069 | { |
| 1070 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1071 | |
| 1072 | return dev_to_chunk_addr(dev->parent, &pblk->addrf, p); |
| 1073 | } |
| 1074 | |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1075 | static inline u64 pblk_dev_ppa_to_line_addr(struct pblk *pblk, |
| 1076 | struct ppa_addr p) |
| 1077 | { |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1078 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1079 | struct nvm_geo *geo = &dev->geo; |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1080 | u64 paddr; |
| 1081 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1082 | if (geo->version == NVM_OCSSD_SPEC_12) { |
| 1083 | struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf; |
| 1084 | |
| 1085 | paddr = (u64)p.g.ch << ppaf->ch_offset; |
| 1086 | paddr |= (u64)p.g.lun << ppaf->lun_offset; |
| 1087 | paddr |= (u64)p.g.pg << ppaf->pg_offset; |
| 1088 | paddr |= (u64)p.g.pl << ppaf->pln_offset; |
| 1089 | paddr |= (u64)p.g.sec << ppaf->sec_offset; |
| 1090 | } else { |
| 1091 | struct pblk_addrf *uaddrf = &pblk->uaddrf; |
| 1092 | u64 secs = p.m.sec; |
| 1093 | int sec_stripe; |
| 1094 | |
| 1095 | paddr = (u64)p.m.grp * uaddrf->sec_stripe; |
| 1096 | paddr += (u64)p.m.pu * uaddrf->sec_lun_stripe; |
| 1097 | |
| 1098 | secs = div_u64_rem(secs, uaddrf->sec_stripe, &sec_stripe); |
| 1099 | paddr += secs * uaddrf->sec_ws_stripe; |
| 1100 | paddr += sec_stripe; |
| 1101 | } |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1102 | |
| 1103 | return paddr; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | static inline struct ppa_addr pblk_ppa32_to_ppa64(struct pblk *pblk, u32 ppa32) |
| 1107 | { |
Javier González | 7f985f9 | 2018-10-09 13:11:56 +0200 | [diff] [blame] | 1108 | struct nvm_tgt_dev *dev = pblk->dev; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1109 | |
Javier González | 7f985f9 | 2018-10-09 13:11:56 +0200 | [diff] [blame] | 1110 | return nvm_ppa32_to_ppa64(dev->parent, &pblk->addrf, ppa32); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1113 | static inline u32 pblk_ppa64_to_ppa32(struct pblk *pblk, struct ppa_addr ppa64) |
| 1114 | { |
Javier González | 7f985f9 | 2018-10-09 13:11:56 +0200 | [diff] [blame] | 1115 | struct nvm_tgt_dev *dev = pblk->dev; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1116 | |
Javier González | 7f985f9 | 2018-10-09 13:11:56 +0200 | [diff] [blame] | 1117 | return nvm_ppa64_to_ppa32(dev->parent, &pblk->addrf, ppa64); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1120 | static inline struct ppa_addr pblk_trans_map_get(struct pblk *pblk, |
| 1121 | sector_t lba) |
| 1122 | { |
| 1123 | struct ppa_addr ppa; |
| 1124 | |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 1125 | if (pblk->addrf_len < 32) { |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1126 | u32 *map = (u32 *)pblk->trans_map; |
| 1127 | |
| 1128 | ppa = pblk_ppa32_to_ppa64(pblk, map[lba]); |
| 1129 | } else { |
| 1130 | struct ppa_addr *map = (struct ppa_addr *)pblk->trans_map; |
| 1131 | |
| 1132 | ppa = map[lba]; |
| 1133 | } |
| 1134 | |
| 1135 | return ppa; |
| 1136 | } |
| 1137 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1138 | static inline void pblk_trans_map_set(struct pblk *pblk, sector_t lba, |
| 1139 | struct ppa_addr ppa) |
| 1140 | { |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 1141 | if (pblk->addrf_len < 32) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1142 | u32 *map = (u32 *)pblk->trans_map; |
| 1143 | |
| 1144 | map[lba] = pblk_ppa64_to_ppa32(pblk, ppa); |
| 1145 | } else { |
| 1146 | u64 *map = (u64 *)pblk->trans_map; |
| 1147 | |
| 1148 | map[lba] = ppa.ppa; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1152 | static inline int pblk_ppa_empty(struct ppa_addr ppa_addr) |
| 1153 | { |
| 1154 | return (ppa_addr.ppa == ADDR_EMPTY); |
| 1155 | } |
| 1156 | |
| 1157 | static inline void pblk_ppa_set_empty(struct ppa_addr *ppa_addr) |
| 1158 | { |
| 1159 | ppa_addr->ppa = ADDR_EMPTY; |
| 1160 | } |
| 1161 | |
Javier González | 07698466 | 2017-06-30 17:56:42 +0200 | [diff] [blame] | 1162 | static inline bool pblk_ppa_comp(struct ppa_addr lppa, struct ppa_addr rppa) |
| 1163 | { |
Matias Bjørling | 8b7bc84 | 2018-01-05 14:16:21 +0100 | [diff] [blame] | 1164 | return (lppa.ppa == rppa.ppa); |
Javier González | 07698466 | 2017-06-30 17:56:42 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1167 | static inline int pblk_addr_in_cache(struct ppa_addr ppa) |
| 1168 | { |
| 1169 | return (ppa.ppa != ADDR_EMPTY && ppa.c.is_cached); |
| 1170 | } |
| 1171 | |
| 1172 | static inline int pblk_addr_to_cacheline(struct ppa_addr ppa) |
| 1173 | { |
| 1174 | return ppa.c.line; |
| 1175 | } |
| 1176 | |
| 1177 | static inline struct ppa_addr pblk_cacheline_to_addr(int addr) |
| 1178 | { |
| 1179 | struct ppa_addr p; |
| 1180 | |
| 1181 | p.c.line = addr; |
| 1182 | p.c.is_cached = 1; |
| 1183 | |
| 1184 | return p; |
| 1185 | } |
| 1186 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1187 | static inline u32 pblk_calc_meta_header_crc(struct pblk *pblk, |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1188 | struct line_header *header) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1189 | { |
| 1190 | u32 crc = ~(u32)0; |
| 1191 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1192 | crc = crc32_le(crc, (unsigned char *)header + sizeof(crc), |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1193 | sizeof(struct line_header) - sizeof(crc)); |
| 1194 | |
| 1195 | return crc; |
| 1196 | } |
| 1197 | |
| 1198 | static inline u32 pblk_calc_smeta_crc(struct pblk *pblk, |
| 1199 | struct line_smeta *smeta) |
| 1200 | { |
| 1201 | struct pblk_line_meta *lm = &pblk->lm; |
| 1202 | u32 crc = ~(u32)0; |
| 1203 | |
| 1204 | crc = crc32_le(crc, (unsigned char *)smeta + |
| 1205 | sizeof(struct line_header) + sizeof(crc), |
| 1206 | lm->smeta_len - |
| 1207 | sizeof(struct line_header) - sizeof(crc)); |
| 1208 | |
| 1209 | return crc; |
| 1210 | } |
| 1211 | |
| 1212 | static inline u32 pblk_calc_emeta_crc(struct pblk *pblk, |
| 1213 | struct line_emeta *emeta) |
| 1214 | { |
| 1215 | struct pblk_line_meta *lm = &pblk->lm; |
| 1216 | u32 crc = ~(u32)0; |
| 1217 | |
| 1218 | crc = crc32_le(crc, (unsigned char *)emeta + |
| 1219 | sizeof(struct line_header) + sizeof(crc), |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1220 | lm->emeta_len[0] - |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1221 | sizeof(struct line_header) - sizeof(crc)); |
| 1222 | |
| 1223 | return crc; |
| 1224 | } |
| 1225 | |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 1226 | static inline int pblk_io_aligned(struct pblk *pblk, int nr_secs) |
| 1227 | { |
| 1228 | return !(nr_secs % pblk->min_write_pgs); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 1231 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1232 | static inline void print_ppa(struct pblk *pblk, struct ppa_addr *p, |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1233 | char *msg, int error) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1234 | { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1235 | struct nvm_geo *geo = &pblk->dev->geo; |
| 1236 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1237 | if (p->c.is_cached) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1238 | pblk_err(pblk, "ppa: (%s: %x) cache line: %llu\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1239 | msg, error, (u64)p->c.line); |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1240 | } else if (geo->version == NVM_OCSSD_SPEC_12) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1241 | pblk_err(pblk, "ppa: (%s: %x):ch:%d,lun:%d,blk:%d,pg:%d,pl:%d,sec:%d\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1242 | msg, error, |
| 1243 | p->g.ch, p->g.lun, p->g.blk, |
| 1244 | p->g.pg, p->g.pl, p->g.sec); |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1245 | } else { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1246 | pblk_err(pblk, "ppa: (%s: %x):ch:%d,lun:%d,chk:%d,sec:%d\n", |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1247 | msg, error, |
| 1248 | p->m.grp, p->m.pu, p->m.chk, p->m.sec); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | static inline void pblk_print_failed_rqd(struct pblk *pblk, struct nvm_rq *rqd, |
| 1253 | int error) |
| 1254 | { |
| 1255 | int bit = -1; |
| 1256 | |
| 1257 | if (rqd->nr_ppas == 1) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1258 | print_ppa(pblk, &rqd->ppa_addr, "rqd", error); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | while ((bit = find_next_bit((void *)&rqd->ppa_status, rqd->nr_ppas, |
| 1263 | bit + 1)) < rqd->nr_ppas) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1264 | print_ppa(pblk, &rqd->ppa_list[bit], "rqd", error); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1265 | } |
| 1266 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1267 | pblk_err(pblk, "error:%d, ppa_status:%llx\n", error, rqd->ppa_status); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1268 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1269 | |
| 1270 | static inline int pblk_boundary_ppa_checks(struct nvm_tgt_dev *tgt_dev, |
| 1271 | struct ppa_addr *ppas, int nr_ppas) |
| 1272 | { |
| 1273 | struct nvm_geo *geo = &tgt_dev->geo; |
| 1274 | struct ppa_addr *ppa; |
| 1275 | int i; |
| 1276 | |
| 1277 | for (i = 0; i < nr_ppas; i++) { |
| 1278 | ppa = &ppas[i]; |
| 1279 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1280 | if (geo->version == NVM_OCSSD_SPEC_12) { |
| 1281 | if (!ppa->c.is_cached && |
| 1282 | ppa->g.ch < geo->num_ch && |
| 1283 | ppa->g.lun < geo->num_lun && |
| 1284 | ppa->g.pl < geo->num_pln && |
| 1285 | ppa->g.blk < geo->num_chk && |
| 1286 | ppa->g.pg < geo->num_pg && |
| 1287 | ppa->g.sec < geo->ws_min) |
| 1288 | continue; |
| 1289 | } else { |
| 1290 | if (!ppa->c.is_cached && |
| 1291 | ppa->m.grp < geo->num_ch && |
| 1292 | ppa->m.pu < geo->num_lun && |
| 1293 | ppa->m.chk < geo->num_chk && |
| 1294 | ppa->m.sec < geo->clba) |
| 1295 | continue; |
| 1296 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1297 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1298 | print_ppa(tgt_dev->q->queuedata, ppa, "boundary", i); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1299 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1300 | return 1; |
| 1301 | } |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1305 | static inline int pblk_check_io(struct pblk *pblk, struct nvm_rq *rqd) |
| 1306 | { |
| 1307 | struct nvm_tgt_dev *dev = pblk->dev; |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame] | 1308 | struct ppa_addr *ppa_list = nvm_rq_to_ppa_list(rqd); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1309 | |
| 1310 | if (pblk_boundary_ppa_checks(dev, ppa_list, rqd->nr_ppas)) { |
| 1311 | WARN_ON(1); |
| 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
| 1315 | if (rqd->opcode == NVM_OP_PWRITE) { |
| 1316 | struct pblk_line *line; |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1317 | int i; |
| 1318 | |
| 1319 | for (i = 0; i < rqd->nr_ppas; i++) { |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1320 | line = pblk_ppa_to_line(pblk, ppa_list[i]); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1321 | |
| 1322 | spin_lock(&line->lock); |
| 1323 | if (line->state != PBLK_LINESTATE_OPEN) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1324 | pblk_err(pblk, "bad ppa: line:%d,state:%d\n", |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 1325 | line->id, line->state); |
| 1326 | WARN_ON(1); |
| 1327 | spin_unlock(&line->lock); |
| 1328 | return -EINVAL; |
| 1329 | } |
| 1330 | spin_unlock(&line->lock); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | #endif |
| 1337 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1338 | static inline int pblk_boundary_paddr_checks(struct pblk *pblk, u64 paddr) |
| 1339 | { |
| 1340 | struct pblk_line_meta *lm = &pblk->lm; |
| 1341 | |
| 1342 | if (paddr > lm->sec_per_line) |
| 1343 | return 1; |
| 1344 | |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | static inline unsigned int pblk_get_bi_idx(struct bio *bio) |
| 1349 | { |
| 1350 | return bio->bi_iter.bi_idx; |
| 1351 | } |
| 1352 | |
| 1353 | static inline sector_t pblk_get_lba(struct bio *bio) |
| 1354 | { |
| 1355 | return bio->bi_iter.bi_sector / NR_PHY_IN_LOG; |
| 1356 | } |
| 1357 | |
| 1358 | static inline unsigned int pblk_get_secs(struct bio *bio) |
| 1359 | { |
| 1360 | return bio->bi_iter.bi_size / PBLK_EXPOSED_PAGE_SIZE; |
| 1361 | } |
| 1362 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1363 | static inline void pblk_setup_uuid(struct pblk *pblk) |
| 1364 | { |
| 1365 | uuid_le uuid; |
| 1366 | |
| 1367 | uuid_le_gen(&uuid); |
| 1368 | memcpy(pblk->instance_uuid, uuid.b, 16); |
| 1369 | } |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 1370 | |
| 1371 | static inline char *pblk_disk_name(struct pblk *pblk) |
| 1372 | { |
| 1373 | struct gendisk *disk = pblk->disk; |
| 1374 | |
| 1375 | return disk->disk_name; |
| 1376 | } |
Hans Holmberg | 3bcebc5 | 2018-12-11 20:16:13 +0100 | [diff] [blame] | 1377 | |
| 1378 | static inline unsigned int pblk_get_min_chks(struct pblk *pblk) |
| 1379 | { |
| 1380 | struct pblk_line_meta *lm = &pblk->lm; |
| 1381 | /* In a worst-case scenario every line will have OP invalid sectors. |
| 1382 | * We will then need a minimum of 1/OP lines to free up a single line |
| 1383 | */ |
| 1384 | |
| 1385 | return DIV_ROUND_UP(100, pblk->op) * lm->blk_per_line; |
Igor Konopko | faa79f2 | 2018-12-11 20:16:23 +0100 | [diff] [blame] | 1386 | } |
Hans Holmberg | 3bcebc5 | 2018-12-11 20:16:13 +0100 | [diff] [blame] | 1387 | |
Igor Konopko | faa79f2 | 2018-12-11 20:16:23 +0100 | [diff] [blame] | 1388 | static inline struct pblk_sec_meta *pblk_get_meta(struct pblk *pblk, |
| 1389 | void *meta, int index) |
| 1390 | { |
Igor Konopko | 2c4d535 | 2018-12-11 20:16:27 +0100 | [diff] [blame^] | 1391 | return meta + |
| 1392 | max_t(int, sizeof(struct pblk_sec_meta), pblk->oob_meta_size) |
| 1393 | * index; |
Hans Holmberg | 3bcebc5 | 2018-12-11 20:16:13 +0100 | [diff] [blame] | 1394 | } |
Igor Konopko | 24828d0 | 2018-12-11 20:16:24 +0100 | [diff] [blame] | 1395 | |
| 1396 | static inline int pblk_dma_meta_size(struct pblk *pblk) |
| 1397 | { |
Igor Konopko | 2c4d535 | 2018-12-11 20:16:27 +0100 | [diff] [blame^] | 1398 | return max_t(int, sizeof(struct pblk_sec_meta), pblk->oob_meta_size) |
| 1399 | * NVM_MAX_VLBA; |
Igor Konopko | 24828d0 | 2018-12-11 20:16:24 +0100 | [diff] [blame] | 1400 | } |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 1401 | |
| 1402 | static inline int pblk_is_oob_meta_supported(struct pblk *pblk) |
| 1403 | { |
| 1404 | return pblk->oob_meta_size >= sizeof(struct pblk_sec_meta); |
| 1405 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1406 | #endif /* PBLK_H_ */ |