Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 IT University of Copenhagen (rrpc.c) |
| 3 | * Copyright (C) 2016 CNEX Labs |
| 4 | * Initial release: Javier Gonzalez <javier@cnexlabs.com> |
| 5 | * Matias Bjorling <matias@cnexlabs.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License version |
| 9 | * 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * Implementation of a physical block-device target for Open-channel SSDs. |
| 17 | * |
| 18 | * pblk-init.c - pblk's initialization. |
| 19 | */ |
| 20 | |
| 21 | #include "pblk.h" |
| 22 | |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 23 | static struct kmem_cache *pblk_ws_cache, *pblk_rec_cache, *pblk_g_rq_cache, |
Javier González | e72ec1d | 2017-10-13 14:46:09 +0200 | [diff] [blame] | 24 | *pblk_w_rq_cache; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 25 | static DECLARE_RWSEM(pblk_lock); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 26 | struct bio_set pblk_bio_set; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 27 | |
| 28 | static int pblk_rw_io(struct request_queue *q, struct pblk *pblk, |
| 29 | struct bio *bio) |
| 30 | { |
| 31 | int ret; |
| 32 | |
| 33 | /* Read requests must be <= 256kb due to NVMe's 64 bit completion bitmap |
| 34 | * constraint. Writes can be of arbitrary size. |
| 35 | */ |
| 36 | if (bio_data_dir(bio) == READ) { |
NeilBrown | af67c31 | 2017-06-18 14:38:57 +1000 | [diff] [blame] | 37 | blk_queue_split(q, &bio); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 38 | ret = pblk_submit_read(pblk, bio); |
| 39 | if (ret == NVM_IO_DONE && bio_flagged(bio, BIO_CLONED)) |
| 40 | bio_put(bio); |
| 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | /* Prevent deadlock in the case of a modest LUN configuration and large |
| 46 | * user I/Os. Unless stalled, the rate limiter leaves at least 256KB |
| 47 | * available for user I/O. |
| 48 | */ |
Javier González | da67e68f | 2017-10-13 14:46:05 +0200 | [diff] [blame] | 49 | if (pblk_get_secs(bio) > pblk_rl_max_io(&pblk->rl)) |
NeilBrown | af67c31 | 2017-06-18 14:38:57 +1000 | [diff] [blame] | 50 | blk_queue_split(q, &bio); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 51 | |
| 52 | return pblk_write_to_cache(pblk, bio, PBLK_IOTYPE_USER); |
| 53 | } |
| 54 | |
| 55 | static blk_qc_t pblk_make_rq(struct request_queue *q, struct bio *bio) |
| 56 | { |
| 57 | struct pblk *pblk = q->queuedata; |
| 58 | |
| 59 | if (bio_op(bio) == REQ_OP_DISCARD) { |
| 60 | pblk_discard(pblk, bio); |
| 61 | if (!(bio->bi_opf & REQ_PREFLUSH)) { |
| 62 | bio_endio(bio); |
| 63 | return BLK_QC_T_NONE; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | switch (pblk_rw_io(q, pblk, bio)) { |
| 68 | case NVM_IO_ERR: |
| 69 | bio_io_error(bio); |
| 70 | break; |
| 71 | case NVM_IO_DONE: |
| 72 | bio_endio(bio); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | return BLK_QC_T_NONE; |
| 77 | } |
| 78 | |
Hans Holmberg | c558619 | 2017-10-13 14:46:40 +0200 | [diff] [blame] | 79 | static size_t pblk_trans_map_size(struct pblk *pblk) |
| 80 | { |
| 81 | int entry_size = 8; |
| 82 | |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 83 | if (pblk->addrf_len < 32) |
Hans Holmberg | c558619 | 2017-10-13 14:46:40 +0200 | [diff] [blame] | 84 | entry_size = 4; |
| 85 | |
| 86 | return entry_size * pblk->rl.nr_secs; |
| 87 | } |
| 88 | |
| 89 | #ifdef CONFIG_NVM_DEBUG |
| 90 | static u32 pblk_l2p_crc(struct pblk *pblk) |
| 91 | { |
| 92 | size_t map_size; |
| 93 | u32 crc = ~(u32)0; |
| 94 | |
| 95 | map_size = pblk_trans_map_size(pblk); |
| 96 | crc = crc32_le(crc, pblk->trans_map, map_size); |
| 97 | return crc; |
| 98 | } |
| 99 | #endif |
| 100 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 101 | static void pblk_l2p_free(struct pblk *pblk) |
| 102 | { |
| 103 | vfree(pblk->trans_map); |
| 104 | } |
| 105 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 106 | static int pblk_l2p_recover(struct pblk *pblk, bool factory_init) |
| 107 | { |
| 108 | struct pblk_line *line = NULL; |
| 109 | |
| 110 | if (factory_init) { |
| 111 | pblk_setup_uuid(pblk); |
| 112 | } else { |
| 113 | line = pblk_recov_l2p(pblk); |
| 114 | if (IS_ERR(line)) { |
| 115 | pr_err("pblk: could not recover l2p table\n"); |
| 116 | return -EFAULT; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | #ifdef CONFIG_NVM_DEBUG |
| 121 | pr_info("pblk init: L2P CRC: %x\n", pblk_l2p_crc(pblk)); |
| 122 | #endif |
| 123 | |
| 124 | /* Free full lines directly as GC has not been started yet */ |
| 125 | pblk_gc_free_full_lines(pblk); |
| 126 | |
| 127 | if (!line) { |
| 128 | /* Configure next line for user data */ |
| 129 | line = pblk_line_get_first_data(pblk); |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 130 | if (!line) |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 131 | return -EFAULT; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static int pblk_l2p_init(struct pblk *pblk, bool factory_init) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 138 | { |
| 139 | sector_t i; |
| 140 | struct ppa_addr ppa; |
Hans Holmberg | c558619 | 2017-10-13 14:46:40 +0200 | [diff] [blame] | 141 | size_t map_size; |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 142 | int ret = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 143 | |
Hans Holmberg | c558619 | 2017-10-13 14:46:40 +0200 | [diff] [blame] | 144 | map_size = pblk_trans_map_size(pblk); |
| 145 | pblk->trans_map = vmalloc(map_size); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 146 | if (!pblk->trans_map) |
| 147 | return -ENOMEM; |
| 148 | |
| 149 | pblk_ppa_set_empty(&ppa); |
| 150 | |
| 151 | for (i = 0; i < pblk->rl.nr_secs; i++) |
| 152 | pblk_trans_map_set(pblk, i, ppa); |
| 153 | |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 154 | ret = pblk_l2p_recover(pblk, factory_init); |
| 155 | if (ret) |
| 156 | vfree(pblk->trans_map); |
| 157 | |
| 158 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void pblk_rwb_free(struct pblk *pblk) |
| 162 | { |
| 163 | if (pblk_rb_tear_down_check(&pblk->rwb)) |
| 164 | pr_err("pblk: write buffer error on tear down\n"); |
| 165 | |
| 166 | pblk_rb_data_free(&pblk->rwb); |
| 167 | vfree(pblk_rb_entries_ref(&pblk->rwb)); |
| 168 | } |
| 169 | |
| 170 | static int pblk_rwb_init(struct pblk *pblk) |
| 171 | { |
| 172 | struct nvm_tgt_dev *dev = pblk->dev; |
| 173 | struct nvm_geo *geo = &dev->geo; |
| 174 | struct pblk_rb_entry *entries; |
| 175 | unsigned long nr_entries; |
| 176 | unsigned int power_size, power_seg_sz; |
| 177 | |
| 178 | nr_entries = pblk_rb_calculate_size(pblk->pgs_in_buffer); |
| 179 | |
| 180 | entries = vzalloc(nr_entries * sizeof(struct pblk_rb_entry)); |
| 181 | if (!entries) |
| 182 | return -ENOMEM; |
| 183 | |
| 184 | power_size = get_count_order(nr_entries); |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 185 | power_seg_sz = get_count_order(geo->csecs); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 186 | |
| 187 | return pblk_rb_init(&pblk->rwb, entries, power_size, power_seg_sz); |
| 188 | } |
| 189 | |
| 190 | /* Minimum pages needed within a lun */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 191 | #define ADDR_POOL_SIZE 64 |
| 192 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 193 | static int pblk_set_addrf_12(struct nvm_geo *geo, struct nvm_addrf_12 *dst) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 194 | { |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 195 | struct nvm_addrf_12 *src = (struct nvm_addrf_12 *)&geo->addrf; |
| 196 | int power_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 197 | |
| 198 | /* Re-calculate channel and lun format to adapt to configuration */ |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 199 | power_len = get_count_order(geo->num_ch); |
| 200 | if (1 << power_len != geo->num_ch) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 201 | pr_err("pblk: supports only power-of-two channel config.\n"); |
| 202 | return -EINVAL; |
| 203 | } |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 204 | dst->ch_len = power_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 205 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 206 | power_len = get_count_order(geo->num_lun); |
| 207 | if (1 << power_len != geo->num_lun) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 208 | pr_err("pblk: supports only power-of-two LUN config.\n"); |
| 209 | return -EINVAL; |
| 210 | } |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 211 | dst->lun_len = power_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 212 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 213 | dst->blk_len = src->blk_len; |
| 214 | dst->pg_len = src->pg_len; |
| 215 | dst->pln_len = src->pln_len; |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 216 | dst->sec_len = src->sec_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 217 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 218 | dst->sec_offset = 0; |
| 219 | dst->pln_offset = dst->sec_len; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 220 | dst->ch_offset = dst->pln_offset + dst->pln_len; |
| 221 | dst->lun_offset = dst->ch_offset + dst->ch_len; |
| 222 | dst->pg_offset = dst->lun_offset + dst->lun_len; |
| 223 | dst->blk_offset = dst->pg_offset + dst->pg_len; |
| 224 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 225 | dst->sec_mask = ((1ULL << dst->sec_len) - 1) << dst->sec_offset; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 226 | dst->pln_mask = ((1ULL << dst->pln_len) - 1) << dst->pln_offset; |
| 227 | dst->ch_mask = ((1ULL << dst->ch_len) - 1) << dst->ch_offset; |
| 228 | dst->lun_mask = ((1ULL << dst->lun_len) - 1) << dst->lun_offset; |
| 229 | dst->pg_mask = ((1ULL << dst->pg_len) - 1) << dst->pg_offset; |
| 230 | dst->blk_mask = ((1ULL << dst->blk_len) - 1) << dst->blk_offset; |
| 231 | |
| 232 | return dst->blk_offset + src->blk_len; |
| 233 | } |
| 234 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 235 | static int pblk_set_addrf_20(struct nvm_geo *geo, struct nvm_addrf *adst, |
| 236 | struct pblk_addrf *udst) |
| 237 | { |
| 238 | struct nvm_addrf *src = &geo->addrf; |
| 239 | |
| 240 | adst->ch_len = get_count_order(geo->num_ch); |
| 241 | adst->lun_len = get_count_order(geo->num_lun); |
| 242 | adst->chk_len = src->chk_len; |
| 243 | adst->sec_len = src->sec_len; |
| 244 | |
| 245 | adst->sec_offset = 0; |
| 246 | adst->ch_offset = adst->sec_len; |
| 247 | adst->lun_offset = adst->ch_offset + adst->ch_len; |
| 248 | adst->chk_offset = adst->lun_offset + adst->lun_len; |
| 249 | |
| 250 | adst->sec_mask = ((1ULL << adst->sec_len) - 1) << adst->sec_offset; |
| 251 | adst->chk_mask = ((1ULL << adst->chk_len) - 1) << adst->chk_offset; |
| 252 | adst->lun_mask = ((1ULL << adst->lun_len) - 1) << adst->lun_offset; |
| 253 | adst->ch_mask = ((1ULL << adst->ch_len) - 1) << adst->ch_offset; |
| 254 | |
| 255 | udst->sec_stripe = geo->ws_opt; |
| 256 | udst->ch_stripe = geo->num_ch; |
| 257 | udst->lun_stripe = geo->num_lun; |
| 258 | |
| 259 | udst->sec_lun_stripe = udst->sec_stripe * udst->ch_stripe; |
| 260 | udst->sec_ws_stripe = udst->sec_lun_stripe * udst->lun_stripe; |
| 261 | |
| 262 | return adst->chk_offset + adst->chk_len; |
| 263 | } |
| 264 | |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 265 | static int pblk_set_addrf(struct pblk *pblk) |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 266 | { |
| 267 | struct nvm_tgt_dev *dev = pblk->dev; |
| 268 | struct nvm_geo *geo = &dev->geo; |
| 269 | int mod; |
| 270 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 271 | switch (geo->version) { |
| 272 | case NVM_OCSSD_SPEC_12: |
| 273 | div_u64_rem(geo->clba, pblk->min_write_pgs, &mod); |
| 274 | if (mod) { |
| 275 | pr_err("pblk: bad configuration of sectors/pages\n"); |
| 276 | return -EINVAL; |
| 277 | } |
| 278 | |
| 279 | pblk->addrf_len = pblk_set_addrf_12(geo, (void *)&pblk->addrf); |
| 280 | break; |
| 281 | case NVM_OCSSD_SPEC_20: |
| 282 | pblk->addrf_len = pblk_set_addrf_20(geo, (void *)&pblk->addrf, |
| 283 | &pblk->uaddrf); |
| 284 | break; |
| 285 | default: |
| 286 | pr_err("pblk: OCSSD revision not supported (%d)\n", |
| 287 | geo->version); |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 288 | return -EINVAL; |
| 289 | } |
| 290 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int pblk_init_global_caches(struct pblk *pblk) |
| 295 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 296 | down_write(&pblk_lock); |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 297 | pblk_ws_cache = kmem_cache_create("pblk_blk_ws", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 298 | sizeof(struct pblk_line_ws), 0, 0, NULL); |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 299 | if (!pblk_ws_cache) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 300 | up_write(&pblk_lock); |
| 301 | return -ENOMEM; |
| 302 | } |
| 303 | |
| 304 | pblk_rec_cache = kmem_cache_create("pblk_rec", |
| 305 | sizeof(struct pblk_rec_ctx), 0, 0, NULL); |
| 306 | if (!pblk_rec_cache) { |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 307 | kmem_cache_destroy(pblk_ws_cache); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 308 | up_write(&pblk_lock); |
| 309 | return -ENOMEM; |
| 310 | } |
| 311 | |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 312 | pblk_g_rq_cache = kmem_cache_create("pblk_g_rq", pblk_g_rq_size, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 313 | 0, 0, NULL); |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 314 | if (!pblk_g_rq_cache) { |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 315 | kmem_cache_destroy(pblk_ws_cache); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 316 | kmem_cache_destroy(pblk_rec_cache); |
| 317 | up_write(&pblk_lock); |
| 318 | return -ENOMEM; |
| 319 | } |
| 320 | |
| 321 | pblk_w_rq_cache = kmem_cache_create("pblk_w_rq", pblk_w_rq_size, |
| 322 | 0, 0, NULL); |
| 323 | if (!pblk_w_rq_cache) { |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 324 | kmem_cache_destroy(pblk_ws_cache); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 325 | kmem_cache_destroy(pblk_rec_cache); |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 326 | kmem_cache_destroy(pblk_g_rq_cache); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 327 | up_write(&pblk_lock); |
| 328 | return -ENOMEM; |
| 329 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 330 | up_write(&pblk_lock); |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Rakesh Pandit | 22a4e06 | 2017-10-13 14:46:33 +0200 | [diff] [blame] | 335 | static void pblk_free_global_caches(struct pblk *pblk) |
| 336 | { |
| 337 | kmem_cache_destroy(pblk_ws_cache); |
| 338 | kmem_cache_destroy(pblk_rec_cache); |
| 339 | kmem_cache_destroy(pblk_g_rq_cache); |
| 340 | kmem_cache_destroy(pblk_w_rq_cache); |
| 341 | } |
| 342 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 343 | static int pblk_core_init(struct pblk *pblk) |
| 344 | { |
| 345 | struct nvm_tgt_dev *dev = pblk->dev; |
| 346 | struct nvm_geo *geo = &dev->geo; |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 347 | int ret, max_write_ppas; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 348 | |
| 349 | atomic64_set(&pblk->user_wa, 0); |
| 350 | atomic64_set(&pblk->pad_wa, 0); |
| 351 | atomic64_set(&pblk->gc_wa, 0); |
| 352 | pblk->user_rst_wa = 0; |
| 353 | pblk->pad_rst_wa = 0; |
| 354 | pblk->gc_rst_wa = 0; |
| 355 | |
| 356 | atomic64_set(&pblk->nr_flush, 0); |
| 357 | pblk->nr_flush_rst = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 358 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 359 | pblk->pgs_in_buffer = geo->mw_cunits * geo->all_luns; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 360 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 361 | pblk->min_write_pgs = geo->ws_opt * (geo->csecs / PAGE_SIZE); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 362 | max_write_ppas = pblk->min_write_pgs * geo->all_luns; |
| 363 | pblk->max_write_pgs = min_t(int, max_write_ppas, NVM_MAX_VLBA); |
| 364 | pblk_set_sec_per_write(pblk, pblk->min_write_pgs); |
| 365 | |
| 366 | if (pblk->max_write_pgs > PBLK_MAX_REQ_ADDRS) { |
| 367 | pr_err("pblk: vector list too big(%u > %u)\n", |
| 368 | pblk->max_write_pgs, PBLK_MAX_REQ_ADDRS); |
| 369 | return -EINVAL; |
| 370 | } |
| 371 | |
| 372 | pblk->pad_dist = kzalloc((pblk->min_write_pgs - 1) * sizeof(atomic64_t), |
| 373 | GFP_KERNEL); |
| 374 | if (!pblk->pad_dist) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 375 | return -ENOMEM; |
| 376 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 377 | if (pblk_init_global_caches(pblk)) |
| 378 | goto fail_free_pad_dist; |
| 379 | |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 380 | /* Internal bios can be at most the sectors signaled by the device. */ |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 381 | ret = mempool_init_page_pool(&pblk->page_bio_pool, NVM_MAX_VLBA, 0); |
| 382 | if (ret) |
Rakesh Pandit | 22a4e06 | 2017-10-13 14:46:33 +0200 | [diff] [blame] | 383 | goto free_global_caches; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 384 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 385 | ret = mempool_init_slab_pool(&pblk->gen_ws_pool, PBLK_GEN_WS_POOL_SIZE, |
| 386 | pblk_ws_cache); |
| 387 | if (ret) |
Javier González | bd43241 | 2017-10-13 14:46:06 +0200 | [diff] [blame] | 388 | goto free_page_bio_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 389 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 390 | ret = mempool_init_slab_pool(&pblk->rec_pool, geo->all_luns, |
| 391 | pblk_rec_cache); |
| 392 | if (ret) |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 393 | goto free_gen_ws_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 394 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 395 | ret = mempool_init_slab_pool(&pblk->r_rq_pool, geo->all_luns, |
| 396 | pblk_g_rq_cache); |
| 397 | if (ret) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 398 | goto free_rec_pool; |
| 399 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 400 | ret = mempool_init_slab_pool(&pblk->e_rq_pool, geo->all_luns, |
| 401 | pblk_g_rq_cache); |
| 402 | if (ret) |
Javier González | 0d88039 | 2017-10-13 14:46:08 +0200 | [diff] [blame] | 403 | goto free_r_rq_pool; |
| 404 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 405 | ret = mempool_init_slab_pool(&pblk->w_rq_pool, geo->all_luns, |
| 406 | pblk_w_rq_cache); |
| 407 | if (ret) |
Javier González | 0d88039 | 2017-10-13 14:46:08 +0200 | [diff] [blame] | 408 | goto free_e_rq_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 409 | |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 410 | pblk->close_wq = alloc_workqueue("pblk-close-wq", |
| 411 | WQ_MEM_RECLAIM | WQ_UNBOUND, PBLK_NR_CLOSE_JOBS); |
| 412 | if (!pblk->close_wq) |
Javier González | e72ec1d | 2017-10-13 14:46:09 +0200 | [diff] [blame] | 413 | goto free_w_rq_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 414 | |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 415 | pblk->bb_wq = alloc_workqueue("pblk-bb-wq", |
| 416 | WQ_MEM_RECLAIM | WQ_UNBOUND, 0); |
| 417 | if (!pblk->bb_wq) |
| 418 | goto free_close_wq; |
| 419 | |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 420 | pblk->r_end_wq = alloc_workqueue("pblk-read-end-wq", |
| 421 | WQ_MEM_RECLAIM | WQ_UNBOUND, 0); |
| 422 | if (!pblk->r_end_wq) |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 423 | goto free_bb_wq; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 424 | |
Javier González | bb845ae4 | 2018-03-30 00:05:19 +0200 | [diff] [blame] | 425 | if (pblk_set_addrf(pblk)) |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 426 | goto free_r_end_wq; |
| 427 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 428 | INIT_LIST_HEAD(&pblk->compl_list); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 429 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 430 | return 0; |
| 431 | |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 432 | free_r_end_wq: |
| 433 | destroy_workqueue(pblk->r_end_wq); |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 434 | free_bb_wq: |
| 435 | destroy_workqueue(pblk->bb_wq); |
| 436 | free_close_wq: |
| 437 | destroy_workqueue(pblk->close_wq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 438 | free_w_rq_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 439 | mempool_exit(&pblk->w_rq_pool); |
Javier González | 0d88039 | 2017-10-13 14:46:08 +0200 | [diff] [blame] | 440 | free_e_rq_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 441 | mempool_exit(&pblk->e_rq_pool); |
Javier González | 0d88039 | 2017-10-13 14:46:08 +0200 | [diff] [blame] | 442 | free_r_rq_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 443 | mempool_exit(&pblk->r_rq_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 444 | free_rec_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 445 | mempool_exit(&pblk->rec_pool); |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 446 | free_gen_ws_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 447 | mempool_exit(&pblk->gen_ws_pool); |
Javier González | bd43241 | 2017-10-13 14:46:06 +0200 | [diff] [blame] | 448 | free_page_bio_pool: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 449 | mempool_exit(&pblk->page_bio_pool); |
Rakesh Pandit | 22a4e06 | 2017-10-13 14:46:33 +0200 | [diff] [blame] | 450 | free_global_caches: |
| 451 | pblk_free_global_caches(pblk); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 452 | fail_free_pad_dist: |
| 453 | kfree(pblk->pad_dist); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 454 | return -ENOMEM; |
| 455 | } |
| 456 | |
| 457 | static void pblk_core_free(struct pblk *pblk) |
| 458 | { |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 459 | if (pblk->close_wq) |
| 460 | destroy_workqueue(pblk->close_wq); |
| 461 | |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 462 | if (pblk->r_end_wq) |
| 463 | destroy_workqueue(pblk->r_end_wq); |
| 464 | |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 465 | if (pblk->bb_wq) |
| 466 | destroy_workqueue(pblk->bb_wq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 467 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 468 | mempool_exit(&pblk->page_bio_pool); |
| 469 | mempool_exit(&pblk->gen_ws_pool); |
| 470 | mempool_exit(&pblk->rec_pool); |
| 471 | mempool_exit(&pblk->r_rq_pool); |
| 472 | mempool_exit(&pblk->e_rq_pool); |
| 473 | mempool_exit(&pblk->w_rq_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 474 | |
Rakesh Pandit | 22a4e06 | 2017-10-13 14:46:33 +0200 | [diff] [blame] | 475 | pblk_free_global_caches(pblk); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 476 | kfree(pblk->pad_dist); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 479 | static void pblk_line_mg_free(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 480 | { |
| 481 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 482 | int i; |
| 483 | |
| 484 | kfree(l_mg->bb_template); |
| 485 | kfree(l_mg->bb_aux); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 486 | kfree(l_mg->vsc_list); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 487 | |
| 488 | for (i = 0; i < PBLK_DATA_LINES; i++) { |
Javier González | f680f19 | 2017-06-26 11:57:21 +0200 | [diff] [blame] | 489 | kfree(l_mg->sline_meta[i]); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 490 | pblk_mfree(l_mg->eline_meta[i]->buf, l_mg->emeta_alloc_type); |
Javier González | f680f19 | 2017-06-26 11:57:21 +0200 | [diff] [blame] | 491 | kfree(l_mg->eline_meta[i]); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 492 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 495 | static void pblk_line_meta_free(struct pblk_line *line) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 496 | { |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 497 | kfree(line->blk_bitmap); |
| 498 | kfree(line->erase_bitmap); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 499 | kfree(line->chks); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 500 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 501 | |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 502 | static void pblk_lines_free(struct pblk *pblk) |
| 503 | { |
| 504 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 505 | struct pblk_line *line; |
| 506 | int i; |
| 507 | |
| 508 | spin_lock(&l_mg->free_lock); |
| 509 | for (i = 0; i < l_mg->nr_lines; i++) { |
| 510 | line = &pblk->lines[i]; |
| 511 | |
| 512 | pblk_line_free(pblk, line); |
| 513 | pblk_line_meta_free(line); |
| 514 | } |
| 515 | spin_unlock(&l_mg->free_lock); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 516 | |
| 517 | pblk_line_mg_free(pblk); |
| 518 | |
| 519 | kfree(pblk->luns); |
| 520 | kfree(pblk->lines); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static int pblk_bb_get_tbl(struct nvm_tgt_dev *dev, struct pblk_lun *rlun, |
| 524 | u8 *blks, int nr_blks) |
| 525 | { |
| 526 | struct ppa_addr ppa; |
| 527 | int ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 528 | |
| 529 | ppa.ppa = 0; |
| 530 | ppa.g.ch = rlun->bppa.g.ch; |
| 531 | ppa.g.lun = rlun->bppa.g.lun; |
| 532 | |
| 533 | ret = nvm_get_tgt_bb_tbl(dev, ppa, blks); |
| 534 | if (ret) |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 535 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 536 | |
| 537 | nr_blks = nvm_bb_tbl_fold(dev->parent, blks, nr_blks); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 538 | if (nr_blks < 0) |
| 539 | return -EIO; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 540 | |
Wei Yongjun | 5136a4f | 2017-04-25 16:15:30 +0000 | [diff] [blame] | 541 | return 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 544 | static void *pblk_bb_get_meta(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 545 | { |
Javier González | dffdd96 | 2017-06-26 11:57:22 +0200 | [diff] [blame] | 546 | struct nvm_tgt_dev *dev = pblk->dev; |
| 547 | struct nvm_geo *geo = &dev->geo; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 548 | u8 *meta; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 549 | int i, nr_blks, blk_per_lun; |
| 550 | int ret; |
| 551 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 552 | blk_per_lun = geo->num_chk * geo->pln_mode; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 553 | nr_blks = blk_per_lun * geo->all_luns; |
| 554 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 555 | meta = kmalloc(nr_blks, GFP_KERNEL); |
| 556 | if (!meta) |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 557 | return ERR_PTR(-ENOMEM); |
| 558 | |
| 559 | for (i = 0; i < geo->all_luns; i++) { |
| 560 | struct pblk_lun *rlun = &pblk->luns[i]; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 561 | u8 *meta_pos = meta + i * blk_per_lun; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 562 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 563 | ret = pblk_bb_get_tbl(dev, rlun, meta_pos, blk_per_lun); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 564 | if (ret) { |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 565 | kfree(meta); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 566 | return ERR_PTR(-EIO); |
| 567 | } |
| 568 | } |
| 569 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 570 | return meta; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 571 | } |
| 572 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 573 | static void *pblk_chunk_get_meta(struct pblk *pblk) |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 574 | { |
| 575 | struct nvm_tgt_dev *dev = pblk->dev; |
| 576 | struct nvm_geo *geo = &dev->geo; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 577 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 578 | if (geo->version == NVM_OCSSD_SPEC_12) |
| 579 | return pblk_bb_get_meta(pblk); |
| 580 | else |
| 581 | return pblk_chunk_get_info(pblk); |
Javier González | dffdd96 | 2017-06-26 11:57:22 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 584 | static int pblk_luns_init(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 585 | { |
| 586 | struct nvm_tgt_dev *dev = pblk->dev; |
| 587 | struct nvm_geo *geo = &dev->geo; |
| 588 | struct pblk_lun *rlun; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 589 | int i; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 590 | |
| 591 | /* TODO: Implement unbalanced LUN support */ |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 592 | if (geo->num_lun < 0) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 593 | pr_err("pblk: unbalanced LUN config.\n"); |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 597 | pblk->luns = kcalloc(geo->all_luns, sizeof(struct pblk_lun), |
| 598 | GFP_KERNEL); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 599 | if (!pblk->luns) |
| 600 | return -ENOMEM; |
| 601 | |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 602 | for (i = 0; i < geo->all_luns; i++) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 603 | /* Stripe across channels */ |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 604 | int ch = i % geo->num_ch; |
| 605 | int lun_raw = i / geo->num_ch; |
| 606 | int lunid = lun_raw + ch * geo->num_lun; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 607 | |
| 608 | rlun = &pblk->luns[i]; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 609 | rlun->bppa = dev->luns[lunid]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 610 | |
| 611 | sema_init(&rlun->wr_sem, 1); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 617 | /* See comment over struct line_emeta definition */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 618 | static unsigned int calc_emeta_len(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 619 | { |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 620 | struct pblk_line_meta *lm = &pblk->lm; |
| 621 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 622 | struct nvm_tgt_dev *dev = pblk->dev; |
| 623 | struct nvm_geo *geo = &dev->geo; |
| 624 | |
| 625 | /* Round to sector size so that lba_list starts on its own sector */ |
| 626 | lm->emeta_sec[1] = DIV_ROUND_UP( |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 627 | sizeof(struct line_emeta) + lm->blk_bitmap_len + |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 628 | sizeof(struct wa_counters), geo->csecs); |
| 629 | lm->emeta_len[1] = lm->emeta_sec[1] * geo->csecs; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 630 | |
| 631 | /* Round to sector size so that vsc_list starts on its own sector */ |
| 632 | lm->dsec_per_line = lm->sec_per_line - lm->emeta_sec[0]; |
| 633 | lm->emeta_sec[2] = DIV_ROUND_UP(lm->dsec_per_line * sizeof(u64), |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 634 | geo->csecs); |
| 635 | lm->emeta_len[2] = lm->emeta_sec[2] * geo->csecs; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 636 | |
| 637 | lm->emeta_sec[3] = DIV_ROUND_UP(l_mg->nr_lines * sizeof(u32), |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 638 | geo->csecs); |
| 639 | lm->emeta_len[3] = lm->emeta_sec[3] * geo->csecs; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 640 | |
| 641 | lm->vsc_list_len = l_mg->nr_lines * sizeof(u32); |
| 642 | |
| 643 | return (lm->emeta_len[1] + lm->emeta_len[2] + lm->emeta_len[3]); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static void pblk_set_provision(struct pblk *pblk, long nr_free_blks) |
| 647 | { |
| 648 | struct nvm_tgt_dev *dev = pblk->dev; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 649 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 650 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 651 | struct nvm_geo *geo = &dev->geo; |
| 652 | sector_t provisioned; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 653 | int sec_meta, blk_meta; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 654 | |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 655 | if (geo->op == NVM_TARGET_DEFAULT_OP) |
| 656 | pblk->op = PBLK_DEFAULT_OP; |
| 657 | else |
| 658 | pblk->op = geo->op; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 659 | |
| 660 | provisioned = nr_free_blks; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 661 | provisioned *= (100 - pblk->op); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 662 | sector_div(provisioned, 100); |
| 663 | |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 664 | pblk->op_blks = nr_free_blks - provisioned; |
| 665 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 666 | /* Internally pblk manages all free blocks, but all calculations based |
| 667 | * on user capacity consider only provisioned blocks |
| 668 | */ |
| 669 | pblk->rl.total_blocks = nr_free_blks; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 670 | pblk->rl.nr_secs = nr_free_blks * geo->clba; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 671 | |
| 672 | /* Consider sectors used for metadata */ |
| 673 | sec_meta = (lm->smeta_sec + lm->emeta_sec[0]) * l_mg->nr_free_lines; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 674 | blk_meta = DIV_ROUND_UP(sec_meta, geo->clba); |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 675 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 676 | pblk->capacity = (provisioned - blk_meta) * geo->clba; |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 677 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 678 | atomic_set(&pblk->rl.free_blocks, nr_free_blks); |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 679 | atomic_set(&pblk->rl.free_user_blocks, nr_free_blks); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 682 | static int pblk_setup_line_meta_12(struct pblk *pblk, struct pblk_line *line, |
| 683 | void *chunk_meta) |
| 684 | { |
| 685 | struct nvm_tgt_dev *dev = pblk->dev; |
| 686 | struct nvm_geo *geo = &dev->geo; |
| 687 | struct pblk_line_meta *lm = &pblk->lm; |
| 688 | int i, chk_per_lun, nr_bad_chks = 0; |
| 689 | |
| 690 | chk_per_lun = geo->num_chk * geo->pln_mode; |
| 691 | |
| 692 | for (i = 0; i < lm->blk_per_line; i++) { |
| 693 | struct pblk_lun *rlun = &pblk->luns[i]; |
| 694 | struct nvm_chk_meta *chunk; |
| 695 | int pos = pblk_ppa_to_pos(geo, rlun->bppa); |
| 696 | u8 *lun_bb_meta = chunk_meta + pos * chk_per_lun; |
| 697 | |
| 698 | chunk = &line->chks[pos]; |
| 699 | |
| 700 | /* |
| 701 | * In 1.2 spec. chunk state is not persisted by the device. Thus |
| 702 | * some of the values are reset each time pblk is instantiated. |
| 703 | */ |
| 704 | if (lun_bb_meta[line->id] == NVM_BLK_T_FREE) |
| 705 | chunk->state = NVM_CHK_ST_FREE; |
| 706 | else |
| 707 | chunk->state = NVM_CHK_ST_OFFLINE; |
| 708 | |
| 709 | chunk->type = NVM_CHK_TP_W_SEQ; |
| 710 | chunk->wi = 0; |
| 711 | chunk->slba = -1; |
| 712 | chunk->cnlb = geo->clba; |
| 713 | chunk->wp = 0; |
| 714 | |
| 715 | if (!(chunk->state & NVM_CHK_ST_OFFLINE)) |
| 716 | continue; |
| 717 | |
| 718 | set_bit(pos, line->blk_bitmap); |
| 719 | nr_bad_chks++; |
| 720 | } |
| 721 | |
| 722 | return nr_bad_chks; |
| 723 | } |
| 724 | |
| 725 | static int pblk_setup_line_meta_20(struct pblk *pblk, struct pblk_line *line, |
| 726 | struct nvm_chk_meta *meta) |
| 727 | { |
| 728 | struct nvm_tgt_dev *dev = pblk->dev; |
| 729 | struct nvm_geo *geo = &dev->geo; |
| 730 | struct pblk_line_meta *lm = &pblk->lm; |
| 731 | int i, nr_bad_chks = 0; |
| 732 | |
| 733 | for (i = 0; i < lm->blk_per_line; i++) { |
| 734 | struct pblk_lun *rlun = &pblk->luns[i]; |
| 735 | struct nvm_chk_meta *chunk; |
| 736 | struct nvm_chk_meta *chunk_meta; |
| 737 | struct ppa_addr ppa; |
| 738 | int pos; |
| 739 | |
| 740 | ppa = rlun->bppa; |
| 741 | pos = pblk_ppa_to_pos(geo, ppa); |
| 742 | chunk = &line->chks[pos]; |
| 743 | |
| 744 | ppa.m.chk = line->id; |
| 745 | chunk_meta = pblk_chunk_get_off(pblk, meta, ppa); |
| 746 | |
| 747 | chunk->state = chunk_meta->state; |
| 748 | chunk->type = chunk_meta->type; |
| 749 | chunk->wi = chunk_meta->wi; |
| 750 | chunk->slba = chunk_meta->slba; |
| 751 | chunk->cnlb = chunk_meta->cnlb; |
| 752 | chunk->wp = chunk_meta->wp; |
| 753 | |
| 754 | if (!(chunk->state & NVM_CHK_ST_OFFLINE)) |
| 755 | continue; |
| 756 | |
| 757 | if (chunk->type & NVM_CHK_TP_SZ_SPEC) { |
| 758 | WARN_ONCE(1, "pblk: custom-sized chunks unsupported\n"); |
| 759 | continue; |
| 760 | } |
| 761 | |
| 762 | set_bit(pos, line->blk_bitmap); |
| 763 | nr_bad_chks++; |
| 764 | } |
| 765 | |
| 766 | return nr_bad_chks; |
| 767 | } |
| 768 | |
| 769 | static long pblk_setup_line_meta(struct pblk *pblk, struct pblk_line *line, |
| 770 | void *chunk_meta, int line_id) |
| 771 | { |
| 772 | struct nvm_tgt_dev *dev = pblk->dev; |
| 773 | struct nvm_geo *geo = &dev->geo; |
| 774 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 775 | struct pblk_line_meta *lm = &pblk->lm; |
| 776 | long nr_bad_chks, chk_in_line; |
| 777 | |
| 778 | line->pblk = pblk; |
| 779 | line->id = line_id; |
| 780 | line->type = PBLK_LINETYPE_FREE; |
| 781 | line->state = PBLK_LINESTATE_NEW; |
| 782 | line->gc_group = PBLK_LINEGC_NONE; |
| 783 | line->vsc = &l_mg->vsc_list[line_id]; |
| 784 | spin_lock_init(&line->lock); |
| 785 | |
| 786 | if (geo->version == NVM_OCSSD_SPEC_12) |
| 787 | nr_bad_chks = pblk_setup_line_meta_12(pblk, line, chunk_meta); |
| 788 | else |
| 789 | nr_bad_chks = pblk_setup_line_meta_20(pblk, line, chunk_meta); |
| 790 | |
| 791 | chk_in_line = lm->blk_per_line - nr_bad_chks; |
| 792 | if (nr_bad_chks < 0 || nr_bad_chks > lm->blk_per_line || |
| 793 | chk_in_line < lm->min_blk_line) { |
| 794 | line->state = PBLK_LINESTATE_BAD; |
| 795 | list_add_tail(&line->list, &l_mg->bad_list); |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | atomic_set(&line->blk_in_line, chk_in_line); |
| 800 | list_add_tail(&line->list, &l_mg->free_list); |
| 801 | l_mg->nr_free_lines++; |
| 802 | |
| 803 | return chk_in_line; |
| 804 | } |
| 805 | |
| 806 | static int pblk_alloc_line_meta(struct pblk *pblk, struct pblk_line *line) |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 807 | { |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 808 | struct pblk_line_meta *lm = &pblk->lm; |
| 809 | |
| 810 | line->blk_bitmap = kzalloc(lm->blk_bitmap_len, GFP_KERNEL); |
| 811 | if (!line->blk_bitmap) |
| 812 | return -ENOMEM; |
| 813 | |
| 814 | line->erase_bitmap = kzalloc(lm->blk_bitmap_len, GFP_KERNEL); |
| 815 | if (!line->erase_bitmap) { |
| 816 | kfree(line->blk_bitmap); |
| 817 | return -ENOMEM; |
| 818 | } |
| 819 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 820 | line->chks = kmalloc(lm->blk_per_line * sizeof(struct nvm_chk_meta), |
| 821 | GFP_KERNEL); |
| 822 | if (!line->chks) { |
| 823 | kfree(line->erase_bitmap); |
| 824 | kfree(line->blk_bitmap); |
| 825 | return -ENOMEM; |
| 826 | } |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int pblk_line_mg_init(struct pblk *pblk) |
| 832 | { |
| 833 | struct nvm_tgt_dev *dev = pblk->dev; |
| 834 | struct nvm_geo *geo = &dev->geo; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 835 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 836 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 837 | int i, bb_distance; |
| 838 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 839 | l_mg->nr_lines = geo->num_chk; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 840 | l_mg->log_line = l_mg->data_line = NULL; |
| 841 | l_mg->l_seq_nr = l_mg->d_seq_nr = 0; |
| 842 | l_mg->nr_free_lines = 0; |
| 843 | bitmap_zero(&l_mg->meta_bitmap, PBLK_DATA_LINES); |
| 844 | |
| 845 | INIT_LIST_HEAD(&l_mg->free_list); |
| 846 | INIT_LIST_HEAD(&l_mg->corrupt_list); |
| 847 | INIT_LIST_HEAD(&l_mg->bad_list); |
| 848 | INIT_LIST_HEAD(&l_mg->gc_full_list); |
| 849 | INIT_LIST_HEAD(&l_mg->gc_high_list); |
| 850 | INIT_LIST_HEAD(&l_mg->gc_mid_list); |
| 851 | INIT_LIST_HEAD(&l_mg->gc_low_list); |
| 852 | INIT_LIST_HEAD(&l_mg->gc_empty_list); |
| 853 | |
| 854 | INIT_LIST_HEAD(&l_mg->emeta_list); |
| 855 | |
| 856 | l_mg->gc_lists[0] = &l_mg->gc_high_list; |
| 857 | l_mg->gc_lists[1] = &l_mg->gc_mid_list; |
| 858 | l_mg->gc_lists[2] = &l_mg->gc_low_list; |
| 859 | |
| 860 | spin_lock_init(&l_mg->free_lock); |
| 861 | spin_lock_init(&l_mg->close_lock); |
| 862 | spin_lock_init(&l_mg->gc_lock); |
| 863 | |
| 864 | l_mg->vsc_list = kcalloc(l_mg->nr_lines, sizeof(__le32), GFP_KERNEL); |
| 865 | if (!l_mg->vsc_list) |
| 866 | goto fail; |
| 867 | |
| 868 | l_mg->bb_template = kzalloc(lm->sec_bitmap_len, GFP_KERNEL); |
| 869 | if (!l_mg->bb_template) |
| 870 | goto fail_free_vsc_list; |
| 871 | |
| 872 | l_mg->bb_aux = kzalloc(lm->sec_bitmap_len, GFP_KERNEL); |
| 873 | if (!l_mg->bb_aux) |
| 874 | goto fail_free_bb_template; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 875 | |
| 876 | /* smeta is always small enough to fit on a kmalloc memory allocation, |
| 877 | * emeta depends on the number of LUNs allocated to the pblk instance |
| 878 | */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 879 | for (i = 0; i < PBLK_DATA_LINES; i++) { |
| 880 | l_mg->sline_meta[i] = kmalloc(lm->smeta_len, GFP_KERNEL); |
| 881 | if (!l_mg->sline_meta[i]) |
| 882 | goto fail_free_smeta; |
| 883 | } |
| 884 | |
| 885 | /* emeta allocates three different buffers for managing metadata with |
| 886 | * in-memory and in-media layouts |
| 887 | */ |
| 888 | for (i = 0; i < PBLK_DATA_LINES; i++) { |
| 889 | struct pblk_emeta *emeta; |
| 890 | |
| 891 | emeta = kmalloc(sizeof(struct pblk_emeta), GFP_KERNEL); |
| 892 | if (!emeta) |
| 893 | goto fail_free_emeta; |
| 894 | |
| 895 | if (lm->emeta_len[0] > KMALLOC_MAX_CACHE_SIZE) { |
| 896 | l_mg->emeta_alloc_type = PBLK_VMALLOC_META; |
| 897 | |
| 898 | emeta->buf = vmalloc(lm->emeta_len[0]); |
| 899 | if (!emeta->buf) { |
| 900 | kfree(emeta); |
| 901 | goto fail_free_emeta; |
| 902 | } |
| 903 | |
| 904 | emeta->nr_entries = lm->emeta_sec[0]; |
| 905 | l_mg->eline_meta[i] = emeta; |
| 906 | } else { |
| 907 | l_mg->emeta_alloc_type = PBLK_KMALLOC_META; |
| 908 | |
| 909 | emeta->buf = kmalloc(lm->emeta_len[0], GFP_KERNEL); |
| 910 | if (!emeta->buf) { |
| 911 | kfree(emeta); |
| 912 | goto fail_free_emeta; |
| 913 | } |
| 914 | |
| 915 | emeta->nr_entries = lm->emeta_sec[0]; |
| 916 | l_mg->eline_meta[i] = emeta; |
| 917 | } |
| 918 | } |
| 919 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 920 | for (i = 0; i < l_mg->nr_lines; i++) |
| 921 | l_mg->vsc_list[i] = cpu_to_le32(EMPTY_ENTRY); |
| 922 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 923 | bb_distance = (geo->all_luns) * geo->ws_opt; |
| 924 | for (i = 0; i < lm->sec_per_line; i += bb_distance) |
| 925 | bitmap_set(l_mg->bb_template, i, geo->ws_opt); |
| 926 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 927 | return 0; |
| 928 | |
| 929 | fail_free_emeta: |
| 930 | while (--i >= 0) { |
Rakesh Pandit | c9d84b3 | 2017-10-13 14:45:54 +0200 | [diff] [blame] | 931 | if (l_mg->emeta_alloc_type == PBLK_VMALLOC_META) |
| 932 | vfree(l_mg->eline_meta[i]->buf); |
| 933 | else |
| 934 | kfree(l_mg->eline_meta[i]->buf); |
Javier González | f680f19 | 2017-06-26 11:57:21 +0200 | [diff] [blame] | 935 | kfree(l_mg->eline_meta[i]); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 936 | } |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 937 | fail_free_smeta: |
| 938 | for (i = 0; i < PBLK_DATA_LINES; i++) |
Javier González | f680f19 | 2017-06-26 11:57:21 +0200 | [diff] [blame] | 939 | kfree(l_mg->sline_meta[i]); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 940 | kfree(l_mg->bb_aux); |
| 941 | fail_free_bb_template: |
| 942 | kfree(l_mg->bb_template); |
| 943 | fail_free_vsc_list: |
| 944 | kfree(l_mg->vsc_list); |
| 945 | fail: |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 946 | return -ENOMEM; |
| 947 | } |
| 948 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 949 | static int pblk_line_meta_init(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 950 | { |
| 951 | struct nvm_tgt_dev *dev = pblk->dev; |
| 952 | struct nvm_geo *geo = &dev->geo; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 953 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 954 | unsigned int smeta_len, emeta_len; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 955 | int i; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 956 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 957 | lm->sec_per_line = geo->clba * geo->all_luns; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 958 | lm->blk_per_line = geo->all_luns; |
| 959 | lm->blk_bitmap_len = BITS_TO_LONGS(geo->all_luns) * sizeof(long); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 960 | lm->sec_bitmap_len = BITS_TO_LONGS(lm->sec_per_line) * sizeof(long); |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 961 | lm->lun_bitmap_len = BITS_TO_LONGS(geo->all_luns) * sizeof(long); |
Rakesh Pandit | 27b9787 | 2017-10-13 14:46:28 +0200 | [diff] [blame] | 962 | lm->mid_thrs = lm->sec_per_line / 2; |
| 963 | lm->high_thrs = lm->sec_per_line / 4; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 964 | lm->meta_distance = (geo->all_luns / 2) * pblk->min_write_pgs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 965 | |
| 966 | /* Calculate necessary pages for smeta. See comment over struct |
| 967 | * line_smeta definition |
| 968 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 969 | i = 1; |
| 970 | add_smeta_page: |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 971 | lm->smeta_sec = i * geo->ws_opt; |
| 972 | lm->smeta_len = lm->smeta_sec * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 973 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 974 | smeta_len = sizeof(struct line_smeta) + lm->lun_bitmap_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 975 | if (smeta_len > lm->smeta_len) { |
| 976 | i++; |
| 977 | goto add_smeta_page; |
| 978 | } |
| 979 | |
| 980 | /* Calculate necessary pages for emeta. See comment over struct |
| 981 | * line_emeta definition |
| 982 | */ |
| 983 | i = 1; |
| 984 | add_emeta_page: |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 985 | lm->emeta_sec[0] = i * geo->ws_opt; |
| 986 | lm->emeta_len[0] = lm->emeta_sec[0] * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 987 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 988 | emeta_len = calc_emeta_len(pblk); |
| 989 | if (emeta_len > lm->emeta_len[0]) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 990 | i++; |
| 991 | goto add_emeta_page; |
| 992 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 993 | |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 994 | lm->emeta_bb = geo->all_luns > i ? geo->all_luns - i : 0; |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 995 | |
| 996 | lm->min_blk_line = 1; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 997 | if (geo->all_luns > 1) |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 998 | lm->min_blk_line += DIV_ROUND_UP(lm->smeta_sec + |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 999 | lm->emeta_sec[0], geo->clba); |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1000 | |
Javier González | b5e063a | 2017-06-30 17:56:41 +0200 | [diff] [blame] | 1001 | if (lm->min_blk_line > lm->blk_per_line) { |
| 1002 | pr_err("pblk: config. not supported. Min. LUN in line:%d\n", |
| 1003 | lm->blk_per_line); |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1004 | return -EINVAL; |
Javier González | b5e063a | 2017-06-30 17:56:41 +0200 | [diff] [blame] | 1005 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1006 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | static int pblk_lines_init(struct pblk *pblk) |
| 1011 | { |
| 1012 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1013 | struct pblk_line *line; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1014 | void *chunk_meta; |
| 1015 | long nr_free_chks = 0; |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1016 | int i, ret; |
| 1017 | |
| 1018 | ret = pblk_line_meta_init(pblk); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1019 | if (ret) |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1020 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1021 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1022 | ret = pblk_line_mg_init(pblk); |
| 1023 | if (ret) |
| 1024 | return ret; |
| 1025 | |
| 1026 | ret = pblk_luns_init(pblk); |
| 1027 | if (ret) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1028 | goto fail_free_meta; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1029 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1030 | chunk_meta = pblk_chunk_get_meta(pblk); |
| 1031 | if (IS_ERR(chunk_meta)) { |
| 1032 | ret = PTR_ERR(chunk_meta); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1033 | goto fail_free_luns; |
| 1034 | } |
| 1035 | |
| 1036 | pblk->lines = kcalloc(l_mg->nr_lines, sizeof(struct pblk_line), |
| 1037 | GFP_KERNEL); |
| 1038 | if (!pblk->lines) { |
| 1039 | ret = -ENOMEM; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1040 | goto fail_free_chunk_meta; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1043 | for (i = 0; i < l_mg->nr_lines; i++) { |
| 1044 | line = &pblk->lines[i]; |
| 1045 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1046 | ret = pblk_alloc_line_meta(pblk, line); |
Javier González | dffdd96 | 2017-06-26 11:57:22 +0200 | [diff] [blame] | 1047 | if (ret) |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1048 | goto fail_free_lines; |
Javier González | dffdd96 | 2017-06-26 11:57:22 +0200 | [diff] [blame] | 1049 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1050 | nr_free_chks += pblk_setup_line_meta(pblk, line, chunk_meta, i); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
Javier González | 2deeefc | 2018-06-01 15:04:15 +0200 | [diff] [blame] | 1053 | if (!nr_free_chks) { |
| 1054 | pr_err("pblk: too many bad blocks prevent for sane instance\n"); |
| 1055 | return -EINTR; |
| 1056 | } |
| 1057 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1058 | pblk_set_provision(pblk, nr_free_chks); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1059 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1060 | kfree(chunk_meta); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1061 | return 0; |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1062 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1063 | fail_free_lines: |
Javier González | dffdd96 | 2017-06-26 11:57:22 +0200 | [diff] [blame] | 1064 | while (--i >= 0) |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1065 | pblk_line_meta_free(&pblk->lines[i]); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1066 | kfree(pblk->lines); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1067 | fail_free_chunk_meta: |
| 1068 | kfree(chunk_meta); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1069 | fail_free_luns: |
| 1070 | kfree(pblk->luns); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1071 | fail_free_meta: |
Javier González | e411b33 | 2018-03-30 00:04:59 +0200 | [diff] [blame] | 1072 | pblk_line_mg_free(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1073 | |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | static int pblk_writer_init(struct pblk *pblk) |
| 1078 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1079 | pblk->writer_ts = kthread_create(pblk_write_ts, pblk, "pblk-writer-t"); |
| 1080 | if (IS_ERR(pblk->writer_ts)) { |
Javier González | cc4f5ba | 2018-01-05 14:16:17 +0100 | [diff] [blame] | 1081 | int err = PTR_ERR(pblk->writer_ts); |
| 1082 | |
| 1083 | if (err != -EINTR) |
| 1084 | pr_err("pblk: could not allocate writer kthread (%d)\n", |
| 1085 | err); |
| 1086 | return err; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1087 | } |
| 1088 | |
Javier González | cc4f5ba | 2018-01-05 14:16:17 +0100 | [diff] [blame] | 1089 | timer_setup(&pblk->wtimer, pblk_write_timer_fn, 0); |
| 1090 | mod_timer(&pblk->wtimer, jiffies + msecs_to_jiffies(100)); |
| 1091 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | static void pblk_writer_stop(struct pblk *pblk) |
| 1096 | { |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 1097 | /* The pipeline must be stopped and the write buffer emptied before the |
| 1098 | * write thread is stopped |
| 1099 | */ |
| 1100 | WARN(pblk_rb_read_count(&pblk->rwb), |
| 1101 | "Stopping not fully persisted write buffer\n"); |
| 1102 | |
| 1103 | WARN(pblk_rb_sync_count(&pblk->rwb), |
| 1104 | "Stopping not fully synced write buffer\n"); |
| 1105 | |
Hans Holmberg | 7be970b | 2018-03-30 00:04:56 +0200 | [diff] [blame] | 1106 | del_timer_sync(&pblk->wtimer); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1107 | if (pblk->writer_ts) |
| 1108 | kthread_stop(pblk->writer_ts); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | static void pblk_free(struct pblk *pblk) |
| 1112 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1113 | pblk_lines_free(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1114 | pblk_l2p_free(pblk); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1115 | pblk_rwb_free(pblk); |
| 1116 | pblk_core_free(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1117 | |
| 1118 | kfree(pblk); |
| 1119 | } |
| 1120 | |
| 1121 | static void pblk_tear_down(struct pblk *pblk) |
| 1122 | { |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1123 | pblk_pipeline_stop(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1124 | pblk_writer_stop(pblk); |
| 1125 | pblk_rb_sync_l2p(&pblk->rwb); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1126 | pblk_rl_free(&pblk->rl); |
| 1127 | |
| 1128 | pr_debug("pblk: consistent tear down\n"); |
| 1129 | } |
| 1130 | |
| 1131 | static void pblk_exit(void *private) |
| 1132 | { |
| 1133 | struct pblk *pblk = private; |
| 1134 | |
| 1135 | down_write(&pblk_lock); |
| 1136 | pblk_gc_exit(pblk); |
| 1137 | pblk_tear_down(pblk); |
Hans Holmberg | c558619 | 2017-10-13 14:46:40 +0200 | [diff] [blame] | 1138 | |
| 1139 | #ifdef CONFIG_NVM_DEBUG |
| 1140 | pr_info("pblk exit: L2P CRC: %x\n", pblk_l2p_crc(pblk)); |
| 1141 | #endif |
| 1142 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1143 | pblk_free(pblk); |
| 1144 | up_write(&pblk_lock); |
| 1145 | } |
| 1146 | |
| 1147 | static sector_t pblk_capacity(void *private) |
| 1148 | { |
| 1149 | struct pblk *pblk = private; |
| 1150 | |
| 1151 | return pblk->capacity * NR_PHY_IN_LOG; |
| 1152 | } |
| 1153 | |
| 1154 | static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, |
| 1155 | int flags) |
| 1156 | { |
| 1157 | struct nvm_geo *geo = &dev->geo; |
| 1158 | struct request_queue *bqueue = dev->q; |
| 1159 | struct request_queue *tqueue = tdisk->queue; |
| 1160 | struct pblk *pblk; |
| 1161 | int ret; |
| 1162 | |
Javier González | 3b2a3ad | 2018-03-30 00:05:21 +0200 | [diff] [blame] | 1163 | /* pblk supports 1.2 and 2.0 versions */ |
| 1164 | if (!(geo->version == NVM_OCSSD_SPEC_12 || |
| 1165 | geo->version == NVM_OCSSD_SPEC_20)) { |
Javier González | 7ad5039 | 2018-03-30 00:05:18 +0200 | [diff] [blame] | 1166 | pr_err("pblk: OCSSD version not supported (%u)\n", |
| 1167 | geo->version); |
| 1168 | return ERR_PTR(-EINVAL); |
| 1169 | } |
| 1170 | |
| 1171 | if (geo->version == NVM_OCSSD_SPEC_12 && geo->dom & NVM_RSP_L2P) { |
Rakesh Pandit | 4e76af5 | 2017-10-13 14:45:57 +0200 | [diff] [blame] | 1172 | pr_err("pblk: host-side L2P table not supported. (%x)\n", |
Javier González | 7ad5039 | 2018-03-30 00:05:18 +0200 | [diff] [blame] | 1173 | geo->dom); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1174 | return ERR_PTR(-EINVAL); |
| 1175 | } |
| 1176 | |
| 1177 | pblk = kzalloc(sizeof(struct pblk), GFP_KERNEL); |
| 1178 | if (!pblk) |
| 1179 | return ERR_PTR(-ENOMEM); |
| 1180 | |
| 1181 | pblk->dev = dev; |
| 1182 | pblk->disk = tdisk; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1183 | pblk->state = PBLK_STATE_RUNNING; |
Hans Holmberg | 3e3a5b8 | 2017-10-13 14:46:34 +0200 | [diff] [blame] | 1184 | pblk->gc.gc_enabled = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1185 | |
| 1186 | spin_lock_init(&pblk->trans_lock); |
| 1187 | spin_lock_init(&pblk->lock); |
| 1188 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1189 | #ifdef CONFIG_NVM_DEBUG |
| 1190 | atomic_long_set(&pblk->inflight_writes, 0); |
| 1191 | atomic_long_set(&pblk->padded_writes, 0); |
| 1192 | atomic_long_set(&pblk->padded_wb, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1193 | atomic_long_set(&pblk->req_writes, 0); |
| 1194 | atomic_long_set(&pblk->sub_writes, 0); |
| 1195 | atomic_long_set(&pblk->sync_writes, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1196 | atomic_long_set(&pblk->inflight_reads, 0); |
Javier González | db7ada3 | 2017-06-26 11:57:13 +0200 | [diff] [blame] | 1197 | atomic_long_set(&pblk->cache_reads, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1198 | atomic_long_set(&pblk->sync_reads, 0); |
| 1199 | atomic_long_set(&pblk->recov_writes, 0); |
| 1200 | atomic_long_set(&pblk->recov_writes, 0); |
| 1201 | atomic_long_set(&pblk->recov_gc_writes, 0); |
Javier González | a112117 | 2017-10-13 14:46:01 +0200 | [diff] [blame] | 1202 | atomic_long_set(&pblk->recov_gc_reads, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1203 | #endif |
| 1204 | |
| 1205 | atomic_long_set(&pblk->read_failed, 0); |
| 1206 | atomic_long_set(&pblk->read_empty, 0); |
| 1207 | atomic_long_set(&pblk->read_high_ecc, 0); |
| 1208 | atomic_long_set(&pblk->read_failed_gc, 0); |
| 1209 | atomic_long_set(&pblk->write_failed, 0); |
| 1210 | atomic_long_set(&pblk->erase_failed, 0); |
| 1211 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1212 | ret = pblk_core_init(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1213 | if (ret) { |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1214 | pr_err("pblk: could not initialize core\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1215 | goto fail; |
| 1216 | } |
| 1217 | |
| 1218 | ret = pblk_lines_init(pblk); |
| 1219 | if (ret) { |
| 1220 | pr_err("pblk: could not initialize lines\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1221 | goto fail_free_core; |
| 1222 | } |
| 1223 | |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1224 | ret = pblk_rwb_init(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1225 | if (ret) { |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1226 | pr_err("pblk: could not initialize write buffer\n"); |
| 1227 | goto fail_free_lines; |
| 1228 | } |
| 1229 | |
| 1230 | ret = pblk_l2p_init(pblk, flags & NVM_TARGET_FACTORY); |
| 1231 | if (ret) { |
| 1232 | pr_err("pblk: could not initialize maps\n"); |
| 1233 | goto fail_free_rwb; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | ret = pblk_writer_init(pblk); |
| 1237 | if (ret) { |
Javier González | cc4f5ba | 2018-01-05 14:16:17 +0100 | [diff] [blame] | 1238 | if (ret != -EINTR) |
| 1239 | pr_err("pblk: could not initialize write thread\n"); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1240 | goto fail_free_l2p; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | ret = pblk_gc_init(pblk); |
| 1244 | if (ret) { |
| 1245 | pr_err("pblk: could not initialize gc\n"); |
| 1246 | goto fail_stop_writer; |
| 1247 | } |
| 1248 | |
| 1249 | /* inherit the size from the underlying device */ |
| 1250 | blk_queue_logical_block_size(tqueue, queue_physical_block_size(bqueue)); |
| 1251 | blk_queue_max_hw_sectors(tqueue, queue_max_hw_sectors(bqueue)); |
| 1252 | |
| 1253 | blk_queue_write_cache(tqueue, true, false); |
| 1254 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1255 | tqueue->limits.discard_granularity = geo->clba * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1256 | tqueue->limits.discard_alignment = 0; |
| 1257 | blk_queue_max_discard_sectors(tqueue, UINT_MAX >> 9); |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 1258 | blk_queue_flag_set(QUEUE_FLAG_DISCARD, tqueue); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1259 | |
Javier González | 30d82a86 | 2018-01-05 14:16:19 +0100 | [diff] [blame] | 1260 | pr_info("pblk(%s): luns:%u, lines:%d, secs:%llu, buf entries:%u\n", |
| 1261 | tdisk->disk_name, |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 1262 | geo->all_luns, pblk->l_mg.nr_lines, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1263 | (unsigned long long)pblk->rl.nr_secs, |
| 1264 | pblk->rwb.nr_entries); |
| 1265 | |
| 1266 | wake_up_process(pblk->writer_ts); |
Hans Holmberg | 03661b5 | 2017-10-13 14:46:37 +0200 | [diff] [blame] | 1267 | |
| 1268 | /* Check if we need to start GC */ |
| 1269 | pblk_gc_should_kick(pblk); |
| 1270 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1271 | return pblk; |
| 1272 | |
| 1273 | fail_stop_writer: |
| 1274 | pblk_writer_stop(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1275 | fail_free_l2p: |
| 1276 | pblk_l2p_free(pblk); |
Javier González | 43d4712 | 2018-03-30 00:05:09 +0200 | [diff] [blame] | 1277 | fail_free_rwb: |
| 1278 | pblk_rwb_free(pblk); |
| 1279 | fail_free_lines: |
| 1280 | pblk_lines_free(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1281 | fail_free_core: |
| 1282 | pblk_core_free(pblk); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1283 | fail: |
| 1284 | kfree(pblk); |
| 1285 | return ERR_PTR(ret); |
| 1286 | } |
| 1287 | |
| 1288 | /* physical block device target */ |
| 1289 | static struct nvm_tgt_type tt_pblk = { |
| 1290 | .name = "pblk", |
| 1291 | .version = {1, 0, 0}, |
| 1292 | |
| 1293 | .make_rq = pblk_make_rq, |
| 1294 | .capacity = pblk_capacity, |
| 1295 | |
| 1296 | .init = pblk_init, |
| 1297 | .exit = pblk_exit, |
| 1298 | |
| 1299 | .sysfs_init = pblk_sysfs_init, |
| 1300 | .sysfs_exit = pblk_sysfs_exit, |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 1301 | .owner = THIS_MODULE, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1302 | }; |
| 1303 | |
| 1304 | static int __init pblk_module_init(void) |
| 1305 | { |
NeilBrown | b25d523 | 2017-06-18 14:38:58 +1000 | [diff] [blame] | 1306 | int ret; |
| 1307 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1308 | ret = bioset_init(&pblk_bio_set, BIO_POOL_SIZE, 0, 0); |
| 1309 | if (ret) |
| 1310 | return ret; |
NeilBrown | b25d523 | 2017-06-18 14:38:58 +1000 | [diff] [blame] | 1311 | ret = nvm_register_tgt_type(&tt_pblk); |
| 1312 | if (ret) |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1313 | bioset_exit(&pblk_bio_set); |
NeilBrown | b25d523 | 2017-06-18 14:38:58 +1000 | [diff] [blame] | 1314 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | static void pblk_module_exit(void) |
| 1318 | { |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1319 | bioset_exit(&pblk_bio_set); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1320 | nvm_unregister_tgt_type(&tt_pblk); |
| 1321 | } |
| 1322 | |
| 1323 | module_init(pblk_module_init); |
| 1324 | module_exit(pblk_module_exit); |
| 1325 | MODULE_AUTHOR("Javier Gonzalez <javier@cnexlabs.com>"); |
| 1326 | MODULE_AUTHOR("Matias Bjorling <matias@cnexlabs.com>"); |
| 1327 | MODULE_LICENSE("GPL v2"); |
| 1328 | MODULE_DESCRIPTION("Physical Block-Device for Open-Channel SSDs"); |