Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Matias Bjorling <m@bjorling.me> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License version |
| 6 | * 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; see the file COPYING. If not, write to |
| 15 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, |
| 16 | * USA. |
| 17 | * |
| 18 | * Implementation of a generic nvm manager for Open-Channel SSDs. |
| 19 | */ |
| 20 | |
| 21 | #include "gennvm.h" |
| 22 | |
| 23 | static void gennvm_blocks_free(struct nvm_dev *dev) |
| 24 | { |
| 25 | struct gen_nvm *gn = dev->mp; |
| 26 | struct gen_lun *lun; |
| 27 | int i; |
| 28 | |
| 29 | gennvm_for_each_lun(gn, lun, i) { |
| 30 | if (!lun->vlun.blocks) |
| 31 | break; |
| 32 | vfree(lun->vlun.blocks); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static void gennvm_luns_free(struct nvm_dev *dev) |
| 37 | { |
| 38 | struct gen_nvm *gn = dev->mp; |
| 39 | |
| 40 | kfree(gn->luns); |
| 41 | } |
| 42 | |
| 43 | static int gennvm_luns_init(struct nvm_dev *dev, struct gen_nvm *gn) |
| 44 | { |
| 45 | struct gen_lun *lun; |
| 46 | int i; |
| 47 | |
| 48 | gn->luns = kcalloc(dev->nr_luns, sizeof(struct gen_lun), GFP_KERNEL); |
| 49 | if (!gn->luns) |
| 50 | return -ENOMEM; |
| 51 | |
| 52 | gennvm_for_each_lun(gn, lun, i) { |
| 53 | spin_lock_init(&lun->vlun.lock); |
| 54 | INIT_LIST_HEAD(&lun->free_list); |
| 55 | INIT_LIST_HEAD(&lun->used_list); |
| 56 | INIT_LIST_HEAD(&lun->bb_list); |
| 57 | |
| 58 | lun->reserved_blocks = 2; /* for GC only */ |
| 59 | lun->vlun.id = i; |
| 60 | lun->vlun.lun_id = i % dev->luns_per_chnl; |
| 61 | lun->vlun.chnl_id = i / dev->luns_per_chnl; |
| 62 | lun->vlun.nr_free_blocks = dev->blks_per_lun; |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 63 | lun->vlun.nr_inuse_blocks = 0; |
| 64 | lun->vlun.nr_bad_blocks = 0; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 69 | static int gennvm_block_bb(struct ppa_addr ppa, int nr_blocks, u8 *blks, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 70 | void *private) |
| 71 | { |
| 72 | struct gen_nvm *gn = private; |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 73 | struct nvm_dev *dev = gn->dev; |
| 74 | struct gen_lun *lun; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 75 | struct nvm_block *blk; |
| 76 | int i; |
| 77 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 78 | ppa = dev_to_generic_addr(gn->dev, ppa); |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 79 | lun = &gn->luns[(dev->nr_luns * ppa.g.ch) + ppa.g.lun]; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 80 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 81 | for (i = 0; i < nr_blocks; i++) { |
| 82 | if (blks[i] == 0) |
| 83 | continue; |
| 84 | |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 85 | blk = &lun->vlun.blocks[i]; |
| 86 | if (!blk) { |
| 87 | pr_err("gennvm: BB data is out of bounds.\n"); |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | list_move_tail(&blk->list, &lun->bb_list); |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 92 | lun->vlun.nr_bad_blocks++; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int gennvm_block_map(u64 slba, u32 nlb, __le64 *entries, void *private) |
| 99 | { |
| 100 | struct nvm_dev *dev = private; |
| 101 | struct gen_nvm *gn = dev->mp; |
| 102 | sector_t max_pages = dev->total_pages * (dev->sec_size >> 9); |
| 103 | u64 elba = slba + nlb; |
| 104 | struct gen_lun *lun; |
| 105 | struct nvm_block *blk; |
| 106 | u64 i; |
| 107 | int lun_id; |
| 108 | |
| 109 | if (unlikely(elba > dev->total_pages)) { |
| 110 | pr_err("gennvm: L2P data from device is out of bounds!\n"); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | |
| 114 | for (i = 0; i < nlb; i++) { |
| 115 | u64 pba = le64_to_cpu(entries[i]); |
| 116 | |
| 117 | if (unlikely(pba >= max_pages && pba != U64_MAX)) { |
| 118 | pr_err("gennvm: L2P data entry is out of bounds!\n"); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | |
| 122 | /* Address zero is a special one. The first page on a disk is |
| 123 | * protected. It often holds internal device boot |
| 124 | * information. |
| 125 | */ |
| 126 | if (!pba) |
| 127 | continue; |
| 128 | |
| 129 | /* resolve block from physical address */ |
| 130 | lun_id = div_u64(pba, dev->sec_per_lun); |
| 131 | lun = &gn->luns[lun_id]; |
| 132 | |
| 133 | /* Calculate block offset into lun */ |
| 134 | pba = pba - (dev->sec_per_lun * lun_id); |
| 135 | blk = &lun->vlun.blocks[div_u64(pba, dev->sec_per_blk)]; |
| 136 | |
| 137 | if (!blk->type) { |
| 138 | /* at this point, we don't know anything about the |
| 139 | * block. It's up to the FTL on top to re-etablish the |
| 140 | * block state |
| 141 | */ |
| 142 | list_move_tail(&blk->list, &lun->used_list); |
| 143 | blk->type = 1; |
| 144 | lun->vlun.nr_free_blocks--; |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 145 | lun->vlun.nr_inuse_blocks++; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn) |
| 153 | { |
| 154 | struct gen_lun *lun; |
| 155 | struct nvm_block *block; |
| 156 | sector_t lun_iter, blk_iter, cur_block_id = 0; |
| 157 | int ret; |
| 158 | |
| 159 | gennvm_for_each_lun(gn, lun, lun_iter) { |
| 160 | lun->vlun.blocks = vzalloc(sizeof(struct nvm_block) * |
| 161 | dev->blks_per_lun); |
| 162 | if (!lun->vlun.blocks) |
| 163 | return -ENOMEM; |
| 164 | |
| 165 | for (blk_iter = 0; blk_iter < dev->blks_per_lun; blk_iter++) { |
| 166 | block = &lun->vlun.blocks[blk_iter]; |
| 167 | |
| 168 | INIT_LIST_HEAD(&block->list); |
| 169 | |
| 170 | block->lun = &lun->vlun; |
| 171 | block->id = cur_block_id++; |
| 172 | |
| 173 | /* First block is reserved for device */ |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 174 | if (unlikely(lun_iter == 0 && blk_iter == 0)) { |
| 175 | lun->vlun.nr_free_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 176 | continue; |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 177 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 178 | |
| 179 | list_add_tail(&block->list, &lun->free_list); |
| 180 | } |
| 181 | |
| 182 | if (dev->ops->get_bb_tbl) { |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 183 | struct ppa_addr ppa; |
| 184 | |
| 185 | ppa.ppa = 0; |
| 186 | ppa.g.ch = lun->vlun.chnl_id; |
| 187 | ppa.g.lun = lun->vlun.id; |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 188 | ppa = generic_to_dev_addr(dev, ppa); |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 189 | |
| 190 | ret = dev->ops->get_bb_tbl(dev->q, ppa, |
| 191 | dev->blks_per_lun, |
| 192 | gennvm_block_bb, gn); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 193 | if (ret) |
| 194 | pr_err("gennvm: could not read BB table\n"); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | if (dev->ops->get_l2p_tbl) { |
| 199 | ret = dev->ops->get_l2p_tbl(dev->q, 0, dev->total_pages, |
| 200 | gennvm_block_map, dev); |
| 201 | if (ret) { |
| 202 | pr_err("gennvm: could not read L2P table.\n"); |
| 203 | pr_warn("gennvm: default block initialization"); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int gennvm_register(struct nvm_dev *dev) |
| 211 | { |
| 212 | struct gen_nvm *gn; |
| 213 | int ret; |
| 214 | |
| 215 | gn = kzalloc(sizeof(struct gen_nvm), GFP_KERNEL); |
| 216 | if (!gn) |
| 217 | return -ENOMEM; |
| 218 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 219 | gn->dev = dev; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 220 | gn->nr_luns = dev->nr_luns; |
| 221 | dev->mp = gn; |
| 222 | |
| 223 | ret = gennvm_luns_init(dev, gn); |
| 224 | if (ret) { |
| 225 | pr_err("gennvm: could not initialize luns\n"); |
| 226 | goto err; |
| 227 | } |
| 228 | |
| 229 | ret = gennvm_blocks_init(dev, gn); |
| 230 | if (ret) { |
| 231 | pr_err("gennvm: could not initialize blocks\n"); |
| 232 | goto err; |
| 233 | } |
| 234 | |
| 235 | return 1; |
| 236 | err: |
| 237 | kfree(gn); |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | static void gennvm_unregister(struct nvm_dev *dev) |
| 242 | { |
| 243 | gennvm_blocks_free(dev); |
| 244 | gennvm_luns_free(dev); |
| 245 | kfree(dev->mp); |
| 246 | dev->mp = NULL; |
| 247 | } |
| 248 | |
| 249 | static struct nvm_block *gennvm_get_blk(struct nvm_dev *dev, |
| 250 | struct nvm_lun *vlun, unsigned long flags) |
| 251 | { |
| 252 | struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun); |
| 253 | struct nvm_block *blk = NULL; |
| 254 | int is_gc = flags & NVM_IOTYPE_GC; |
| 255 | |
| 256 | spin_lock(&vlun->lock); |
| 257 | |
| 258 | if (list_empty(&lun->free_list)) { |
| 259 | pr_err_ratelimited("gennvm: lun %u have no free pages available", |
| 260 | lun->vlun.id); |
| 261 | spin_unlock(&vlun->lock); |
| 262 | goto out; |
| 263 | } |
| 264 | |
| 265 | while (!is_gc && lun->vlun.nr_free_blocks < lun->reserved_blocks) { |
| 266 | spin_unlock(&vlun->lock); |
| 267 | goto out; |
| 268 | } |
| 269 | |
| 270 | blk = list_first_entry(&lun->free_list, struct nvm_block, list); |
| 271 | list_move_tail(&blk->list, &lun->used_list); |
| 272 | blk->type = 1; |
| 273 | |
| 274 | lun->vlun.nr_free_blocks--; |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 275 | lun->vlun.nr_inuse_blocks++; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 276 | |
| 277 | spin_unlock(&vlun->lock); |
| 278 | out: |
| 279 | return blk; |
| 280 | } |
| 281 | |
| 282 | static void gennvm_put_blk(struct nvm_dev *dev, struct nvm_block *blk) |
| 283 | { |
| 284 | struct nvm_lun *vlun = blk->lun; |
| 285 | struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun); |
| 286 | |
| 287 | spin_lock(&vlun->lock); |
| 288 | |
| 289 | switch (blk->type) { |
| 290 | case 1: |
| 291 | list_move_tail(&blk->list, &lun->free_list); |
| 292 | lun->vlun.nr_free_blocks++; |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 293 | lun->vlun.nr_inuse_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 294 | blk->type = 0; |
| 295 | break; |
| 296 | case 2: |
| 297 | list_move_tail(&blk->list, &lun->bb_list); |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 298 | lun->vlun.nr_bad_blocks++; |
| 299 | lun->vlun.nr_inuse_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 300 | break; |
| 301 | default: |
| 302 | WARN_ON_ONCE(1); |
| 303 | pr_err("gennvm: erroneous block type (%lu -> %u)\n", |
| 304 | blk->id, blk->type); |
| 305 | list_move_tail(&blk->list, &lun->bb_list); |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 306 | lun->vlun.nr_bad_blocks++; |
| 307 | lun->vlun.nr_inuse_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | spin_unlock(&vlun->lock); |
| 311 | } |
| 312 | |
| 313 | static void gennvm_addr_to_generic_mode(struct nvm_dev *dev, struct nvm_rq *rqd) |
| 314 | { |
| 315 | int i; |
| 316 | |
| 317 | if (rqd->nr_pages > 1) { |
| 318 | for (i = 0; i < rqd->nr_pages; i++) |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 319 | rqd->ppa_list[i] = dev_to_generic_addr(dev, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 320 | rqd->ppa_list[i]); |
| 321 | } else { |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 322 | rqd->ppa_addr = dev_to_generic_addr(dev, rqd->ppa_addr); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | static void gennvm_generic_to_addr_mode(struct nvm_dev *dev, struct nvm_rq *rqd) |
| 327 | { |
| 328 | int i; |
| 329 | |
| 330 | if (rqd->nr_pages > 1) { |
| 331 | for (i = 0; i < rqd->nr_pages; i++) |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 332 | rqd->ppa_list[i] = generic_to_dev_addr(dev, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 333 | rqd->ppa_list[i]); |
| 334 | } else { |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 335 | rqd->ppa_addr = generic_to_dev_addr(dev, rqd->ppa_addr); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | static int gennvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd) |
| 340 | { |
| 341 | if (!dev->ops->submit_io) |
| 342 | return 0; |
| 343 | |
| 344 | /* Convert address space */ |
| 345 | gennvm_generic_to_addr_mode(dev, rqd); |
| 346 | |
| 347 | rqd->dev = dev; |
| 348 | return dev->ops->submit_io(dev->q, rqd); |
| 349 | } |
| 350 | |
| 351 | static void gennvm_blk_set_type(struct nvm_dev *dev, struct ppa_addr *ppa, |
| 352 | int type) |
| 353 | { |
| 354 | struct gen_nvm *gn = dev->mp; |
| 355 | struct gen_lun *lun; |
| 356 | struct nvm_block *blk; |
| 357 | |
| 358 | if (unlikely(ppa->g.ch > dev->nr_chnls || |
| 359 | ppa->g.lun > dev->luns_per_chnl || |
| 360 | ppa->g.blk > dev->blks_per_lun)) { |
| 361 | WARN_ON_ONCE(1); |
| 362 | pr_err("gennvm: ppa broken (ch: %u > %u lun: %u > %u blk: %u > %u", |
| 363 | ppa->g.ch, dev->nr_chnls, |
| 364 | ppa->g.lun, dev->luns_per_chnl, |
| 365 | ppa->g.blk, dev->blks_per_lun); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | lun = &gn->luns[ppa->g.lun * ppa->g.ch]; |
| 370 | blk = &lun->vlun.blocks[ppa->g.blk]; |
| 371 | |
| 372 | /* will be moved to bb list on put_blk from target */ |
| 373 | blk->type = type; |
| 374 | } |
| 375 | |
| 376 | /* mark block bad. It is expected the target recover from the error. */ |
| 377 | static void gennvm_mark_blk_bad(struct nvm_dev *dev, struct nvm_rq *rqd) |
| 378 | { |
| 379 | int i; |
| 380 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 381 | if (!dev->ops->set_bb_tbl) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 382 | return; |
| 383 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 384 | if (dev->ops->set_bb_tbl(dev->q, rqd, 1)) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 385 | return; |
| 386 | |
| 387 | gennvm_addr_to_generic_mode(dev, rqd); |
| 388 | |
| 389 | /* look up blocks and mark them as bad */ |
| 390 | if (rqd->nr_pages > 1) |
| 391 | for (i = 0; i < rqd->nr_pages; i++) |
| 392 | gennvm_blk_set_type(dev, &rqd->ppa_list[i], 2); |
| 393 | else |
| 394 | gennvm_blk_set_type(dev, &rqd->ppa_addr, 2); |
| 395 | } |
| 396 | |
| 397 | static int gennvm_end_io(struct nvm_rq *rqd, int error) |
| 398 | { |
| 399 | struct nvm_tgt_instance *ins = rqd->ins; |
| 400 | int ret = 0; |
| 401 | |
| 402 | switch (error) { |
| 403 | case NVM_RSP_SUCCESS: |
| 404 | break; |
| 405 | case NVM_RSP_ERR_EMPTYPAGE: |
| 406 | break; |
| 407 | case NVM_RSP_ERR_FAILWRITE: |
| 408 | gennvm_mark_blk_bad(rqd->dev, rqd); |
| 409 | default: |
| 410 | ret++; |
| 411 | } |
| 412 | |
| 413 | ret += ins->tt->end_io(rqd, error); |
| 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | static int gennvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blk, |
| 419 | unsigned long flags) |
| 420 | { |
| 421 | int plane_cnt = 0, pl_idx, ret; |
| 422 | struct ppa_addr addr; |
| 423 | struct nvm_rq rqd; |
| 424 | |
| 425 | if (!dev->ops->erase_block) |
| 426 | return 0; |
| 427 | |
| 428 | addr = block_to_ppa(dev, blk); |
| 429 | |
| 430 | if (dev->plane_mode == NVM_PLANE_SINGLE) { |
| 431 | rqd.nr_pages = 1; |
| 432 | rqd.ppa_addr = addr; |
| 433 | } else { |
| 434 | plane_cnt = (1 << dev->plane_mode); |
| 435 | rqd.nr_pages = plane_cnt; |
| 436 | |
| 437 | rqd.ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, |
| 438 | &rqd.dma_ppa_list); |
| 439 | if (!rqd.ppa_list) { |
| 440 | pr_err("gennvm: failed to allocate dma memory\n"); |
| 441 | return -ENOMEM; |
| 442 | } |
| 443 | |
| 444 | for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { |
| 445 | addr.g.pl = pl_idx; |
| 446 | rqd.ppa_list[pl_idx] = addr; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | gennvm_generic_to_addr_mode(dev, &rqd); |
| 451 | |
| 452 | ret = dev->ops->erase_block(dev->q, &rqd); |
| 453 | |
| 454 | if (plane_cnt) |
| 455 | nvm_dev_dma_free(dev, rqd.ppa_list, rqd.dma_ppa_list); |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid) |
| 461 | { |
| 462 | struct gen_nvm *gn = dev->mp; |
| 463 | |
| 464 | return &gn->luns[lunid].vlun; |
| 465 | } |
| 466 | |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 467 | static void gennvm_lun_info_print(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 468 | { |
| 469 | struct gen_nvm *gn = dev->mp; |
| 470 | struct gen_lun *lun; |
| 471 | unsigned int i; |
| 472 | |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 473 | |
| 474 | gennvm_for_each_lun(gn, lun, i) { |
| 475 | spin_lock(&lun->vlun.lock); |
| 476 | |
| 477 | pr_info("%s: lun%8u\t%u\t%u\t%u\n", |
| 478 | dev->name, i, |
| 479 | lun->vlun.nr_free_blocks, |
| 480 | lun->vlun.nr_inuse_blocks, |
| 481 | lun->vlun.nr_bad_blocks); |
| 482 | |
| 483 | spin_unlock(&lun->vlun.lock); |
| 484 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static struct nvmm_type gennvm = { |
| 488 | .name = "gennvm", |
| 489 | .version = {0, 1, 0}, |
| 490 | |
| 491 | .register_mgr = gennvm_register, |
| 492 | .unregister_mgr = gennvm_unregister, |
| 493 | |
| 494 | .get_blk = gennvm_get_blk, |
| 495 | .put_blk = gennvm_put_blk, |
| 496 | |
| 497 | .submit_io = gennvm_submit_io, |
| 498 | .end_io = gennvm_end_io, |
| 499 | .erase_blk = gennvm_erase_blk, |
| 500 | |
| 501 | .get_lun = gennvm_get_lun, |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 502 | .lun_info_print = gennvm_lun_info_print, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 503 | }; |
| 504 | |
| 505 | static int __init gennvm_module_init(void) |
| 506 | { |
| 507 | return nvm_register_mgr(&gennvm); |
| 508 | } |
| 509 | |
| 510 | static void gennvm_module_exit(void) |
| 511 | { |
| 512 | nvm_unregister_mgr(&gennvm); |
| 513 | } |
| 514 | |
| 515 | module_init(gennvm_module_init); |
| 516 | module_exit(gennvm_module_exit); |
| 517 | MODULE_LICENSE("GPL v2"); |
| 518 | MODULE_DESCRIPTION("Generic media manager for Open-Channel SSDs"); |