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 | * |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 18 | * Implementation of a general nvm manager for Open-Channel SSDs. |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "gennvm.h" |
| 22 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 23 | static struct nvm_target *gen_find_target(struct gen_dev *gn, const char *name) |
| 24 | { |
| 25 | struct nvm_target *tgt; |
| 26 | |
| 27 | list_for_each_entry(tgt, &gn->targets, list) |
| 28 | if (!strcmp(name, tgt->disk->disk_name)) |
| 29 | return tgt; |
| 30 | |
| 31 | return NULL; |
| 32 | } |
| 33 | |
| 34 | static const struct block_device_operations gen_fops = { |
| 35 | .owner = THIS_MODULE, |
| 36 | }; |
| 37 | |
| 38 | static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) |
| 39 | { |
| 40 | struct gen_dev *gn = dev->mp; |
| 41 | struct nvm_ioctl_create_simple *s = &create->conf.s; |
| 42 | struct request_queue *tqueue; |
| 43 | struct gendisk *tdisk; |
| 44 | struct nvm_tgt_type *tt; |
| 45 | struct nvm_target *t; |
| 46 | void *targetdata; |
| 47 | |
| 48 | tt = nvm_find_target_type(create->tgttype, 1); |
| 49 | if (!tt) { |
| 50 | pr_err("nvm: target type %s not found\n", create->tgttype); |
| 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | mutex_lock(&gn->lock); |
| 55 | t = gen_find_target(gn, create->tgtname); |
| 56 | if (t) { |
| 57 | pr_err("nvm: target name already exists.\n"); |
| 58 | mutex_unlock(&gn->lock); |
| 59 | return -EINVAL; |
| 60 | } |
| 61 | mutex_unlock(&gn->lock); |
| 62 | |
| 63 | t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL); |
| 64 | if (!t) |
| 65 | return -ENOMEM; |
| 66 | |
| 67 | tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node); |
| 68 | if (!tqueue) |
| 69 | goto err_t; |
| 70 | blk_queue_make_request(tqueue, tt->make_rq); |
| 71 | |
| 72 | tdisk = alloc_disk(0); |
| 73 | if (!tdisk) |
| 74 | goto err_queue; |
| 75 | |
| 76 | sprintf(tdisk->disk_name, "%s", create->tgtname); |
| 77 | tdisk->flags = GENHD_FL_EXT_DEVT; |
| 78 | tdisk->major = 0; |
| 79 | tdisk->first_minor = 0; |
| 80 | tdisk->fops = &gen_fops; |
| 81 | tdisk->queue = tqueue; |
| 82 | |
| 83 | targetdata = tt->init(dev, tdisk, s->lun_begin, s->lun_end); |
| 84 | if (IS_ERR(targetdata)) |
| 85 | goto err_init; |
| 86 | |
| 87 | tdisk->private_data = targetdata; |
| 88 | tqueue->queuedata = targetdata; |
| 89 | |
| 90 | blk_queue_max_hw_sectors(tqueue, 8 * dev->ops->max_phys_sect); |
| 91 | |
| 92 | set_capacity(tdisk, tt->capacity(targetdata)); |
| 93 | add_disk(tdisk); |
| 94 | |
| 95 | t->type = tt; |
| 96 | t->disk = tdisk; |
| 97 | t->dev = dev; |
| 98 | |
| 99 | mutex_lock(&gn->lock); |
| 100 | list_add_tail(&t->list, &gn->targets); |
| 101 | mutex_unlock(&gn->lock); |
| 102 | |
| 103 | return 0; |
| 104 | err_init: |
| 105 | put_disk(tdisk); |
| 106 | err_queue: |
| 107 | blk_cleanup_queue(tqueue); |
| 108 | err_t: |
| 109 | kfree(t); |
| 110 | return -ENOMEM; |
| 111 | } |
| 112 | |
| 113 | static void __gen_remove_target(struct nvm_target *t) |
| 114 | { |
| 115 | struct nvm_tgt_type *tt = t->type; |
| 116 | struct gendisk *tdisk = t->disk; |
| 117 | struct request_queue *q = tdisk->queue; |
| 118 | |
| 119 | del_gendisk(tdisk); |
| 120 | blk_cleanup_queue(q); |
| 121 | |
| 122 | if (tt->exit) |
| 123 | tt->exit(tdisk->private_data); |
| 124 | |
| 125 | put_disk(tdisk); |
| 126 | |
| 127 | list_del(&t->list); |
| 128 | kfree(t); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * gen_remove_tgt - Removes a target from the media manager |
| 133 | * @dev: device |
| 134 | * @remove: ioctl structure with target name to remove. |
| 135 | * |
| 136 | * Returns: |
| 137 | * 0: on success |
| 138 | * 1: on not found |
| 139 | * <0: on error |
| 140 | */ |
| 141 | static int gen_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove) |
| 142 | { |
| 143 | struct gen_dev *gn = dev->mp; |
| 144 | struct nvm_target *t; |
| 145 | |
| 146 | if (!gn) |
| 147 | return 1; |
| 148 | |
| 149 | mutex_lock(&gn->lock); |
| 150 | t = gen_find_target(gn, remove->tgtname); |
| 151 | if (!t) { |
| 152 | mutex_unlock(&gn->lock); |
| 153 | return 1; |
| 154 | } |
| 155 | __gen_remove_target(t); |
| 156 | mutex_unlock(&gn->lock); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 161 | static int gen_get_area(struct nvm_dev *dev, sector_t *lba, sector_t len) |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 162 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 163 | struct gen_dev *gn = dev->mp; |
| 164 | struct gen_area *area, *prev, *next; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 165 | sector_t begin = 0; |
| 166 | sector_t max_sectors = (dev->sec_size * dev->total_secs) >> 9; |
| 167 | |
| 168 | if (len > max_sectors) |
| 169 | return -EINVAL; |
| 170 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 171 | area = kmalloc(sizeof(struct gen_area), GFP_KERNEL); |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 172 | if (!area) |
| 173 | return -ENOMEM; |
| 174 | |
| 175 | prev = NULL; |
| 176 | |
| 177 | spin_lock(&dev->lock); |
| 178 | list_for_each_entry(next, &gn->area_list, list) { |
| 179 | if (begin + len > next->begin) { |
| 180 | begin = next->end; |
| 181 | prev = next; |
| 182 | continue; |
| 183 | } |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | if ((begin + len) > max_sectors) { |
| 188 | spin_unlock(&dev->lock); |
| 189 | kfree(area); |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | area->begin = *lba = begin; |
| 194 | area->end = begin + len; |
| 195 | |
| 196 | if (prev) /* insert into sorted order */ |
| 197 | list_add(&area->list, &prev->list); |
| 198 | else |
| 199 | list_add(&area->list, &gn->area_list); |
| 200 | spin_unlock(&dev->lock); |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 205 | static void gen_put_area(struct nvm_dev *dev, sector_t begin) |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 206 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 207 | struct gen_dev *gn = dev->mp; |
| 208 | struct gen_area *area; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 209 | |
| 210 | spin_lock(&dev->lock); |
| 211 | list_for_each_entry(area, &gn->area_list, list) { |
| 212 | if (area->begin != begin) |
| 213 | continue; |
| 214 | |
| 215 | list_del(&area->list); |
| 216 | spin_unlock(&dev->lock); |
| 217 | kfree(area); |
| 218 | return; |
| 219 | } |
| 220 | spin_unlock(&dev->lock); |
| 221 | } |
| 222 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 223 | static void gen_blocks_free(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 224 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 225 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 226 | struct gen_lun *lun; |
| 227 | int i; |
| 228 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 229 | gen_for_each_lun(gn, lun, i) { |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 230 | if (!lun->vlun.blocks) |
| 231 | break; |
| 232 | vfree(lun->vlun.blocks); |
| 233 | } |
| 234 | } |
| 235 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 236 | static void gen_luns_free(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 237 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 238 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 239 | |
| 240 | kfree(gn->luns); |
| 241 | } |
| 242 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 243 | static int gen_luns_init(struct nvm_dev *dev, struct gen_dev *gn) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 244 | { |
| 245 | struct gen_lun *lun; |
| 246 | int i; |
| 247 | |
| 248 | gn->luns = kcalloc(dev->nr_luns, sizeof(struct gen_lun), GFP_KERNEL); |
| 249 | if (!gn->luns) |
| 250 | return -ENOMEM; |
| 251 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 252 | gen_for_each_lun(gn, lun, i) { |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 253 | spin_lock_init(&lun->vlun.lock); |
| 254 | INIT_LIST_HEAD(&lun->free_list); |
| 255 | INIT_LIST_HEAD(&lun->used_list); |
| 256 | INIT_LIST_HEAD(&lun->bb_list); |
| 257 | |
| 258 | lun->reserved_blocks = 2; /* for GC only */ |
| 259 | lun->vlun.id = i; |
| 260 | lun->vlun.lun_id = i % dev->luns_per_chnl; |
| 261 | lun->vlun.chnl_id = i / dev->luns_per_chnl; |
| 262 | lun->vlun.nr_free_blocks = dev->blks_per_lun; |
| 263 | } |
| 264 | return 0; |
| 265 | } |
| 266 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 267 | static int gen_block_bb(struct gen_dev *gn, struct ppa_addr ppa, |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 268 | u8 *blks, int nr_blks) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 269 | { |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 270 | struct nvm_dev *dev = gn->dev; |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 271 | struct gen_lun *lun; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 272 | struct nvm_block *blk; |
| 273 | int i; |
| 274 | |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 275 | nr_blks = nvm_bb_tbl_fold(dev, blks, nr_blks); |
| 276 | if (nr_blks < 0) |
| 277 | return nr_blks; |
| 278 | |
Matias Bjørling | c3293a9 | 2015-12-29 14:37:56 +0100 | [diff] [blame] | 279 | lun = &gn->luns[(dev->luns_per_chnl * ppa.g.ch) + ppa.g.lun]; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 280 | |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 281 | for (i = 0; i < nr_blks; i++) { |
Javier González | 98379a1 | 2016-11-28 22:39:03 +0100 | [diff] [blame^] | 282 | if (blks[i] == NVM_BLK_T_FREE) |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 283 | continue; |
| 284 | |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 285 | blk = &lun->vlun.blocks[i]; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 286 | list_move_tail(&blk->list, &lun->bb_list); |
Chao Yu | bdded15 | 2016-01-12 07:49:16 +0100 | [diff] [blame] | 287 | lun->vlun.nr_free_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 293 | static int gen_block_map(u64 slba, u32 nlb, __le64 *entries, void *private) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 294 | { |
| 295 | struct nvm_dev *dev = private; |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 296 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 297 | u64 elba = slba + nlb; |
| 298 | struct gen_lun *lun; |
| 299 | struct nvm_block *blk; |
| 300 | u64 i; |
| 301 | int lun_id; |
| 302 | |
Matias Bjørling | 4ece44a | 2016-02-20 08:52:41 +0100 | [diff] [blame] | 303 | if (unlikely(elba > dev->total_secs)) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 304 | pr_err("gen: L2P data from device is out of bounds!\n"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | } |
| 307 | |
| 308 | for (i = 0; i < nlb; i++) { |
| 309 | u64 pba = le64_to_cpu(entries[i]); |
| 310 | |
Matias Bjørling | 4ece44a | 2016-02-20 08:52:41 +0100 | [diff] [blame] | 311 | if (unlikely(pba >= dev->total_secs && pba != U64_MAX)) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 312 | pr_err("gen: L2P data entry is out of bounds!\n"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 313 | return -EINVAL; |
| 314 | } |
| 315 | |
| 316 | /* Address zero is a special one. The first page on a disk is |
| 317 | * protected. It often holds internal device boot |
| 318 | * information. |
| 319 | */ |
| 320 | if (!pba) |
| 321 | continue; |
| 322 | |
| 323 | /* resolve block from physical address */ |
| 324 | lun_id = div_u64(pba, dev->sec_per_lun); |
| 325 | lun = &gn->luns[lun_id]; |
| 326 | |
| 327 | /* Calculate block offset into lun */ |
| 328 | pba = pba - (dev->sec_per_lun * lun_id); |
| 329 | blk = &lun->vlun.blocks[div_u64(pba, dev->sec_per_blk)]; |
| 330 | |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 331 | if (!blk->state) { |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 332 | /* at this point, we don't know anything about the |
| 333 | * block. It's up to the FTL on top to re-etablish the |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 334 | * block state. The block is assumed to be open. |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 335 | */ |
| 336 | list_move_tail(&blk->list, &lun->used_list); |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 337 | blk->state = NVM_BLK_ST_TGT; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 338 | lun->vlun.nr_free_blocks--; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 345 | static int gen_blocks_init(struct nvm_dev *dev, struct gen_dev *gn) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 346 | { |
| 347 | struct gen_lun *lun; |
| 348 | struct nvm_block *block; |
| 349 | sector_t lun_iter, blk_iter, cur_block_id = 0; |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 350 | int ret, nr_blks; |
| 351 | u8 *blks; |
| 352 | |
| 353 | nr_blks = dev->blks_per_lun * dev->plane_mode; |
| 354 | blks = kmalloc(nr_blks, GFP_KERNEL); |
| 355 | if (!blks) |
| 356 | return -ENOMEM; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 357 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 358 | gen_for_each_lun(gn, lun, lun_iter) { |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 359 | lun->vlun.blocks = vzalloc(sizeof(struct nvm_block) * |
| 360 | dev->blks_per_lun); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 361 | if (!lun->vlun.blocks) { |
| 362 | kfree(blks); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 363 | return -ENOMEM; |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 364 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 365 | |
| 366 | for (blk_iter = 0; blk_iter < dev->blks_per_lun; blk_iter++) { |
| 367 | block = &lun->vlun.blocks[blk_iter]; |
| 368 | |
| 369 | INIT_LIST_HEAD(&block->list); |
| 370 | |
| 371 | block->lun = &lun->vlun; |
| 372 | block->id = cur_block_id++; |
| 373 | |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 374 | list_add_tail(&block->list, &lun->free_list); |
| 375 | } |
| 376 | |
| 377 | if (dev->ops->get_bb_tbl) { |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 378 | struct ppa_addr ppa; |
| 379 | |
| 380 | ppa.ppa = 0; |
| 381 | ppa.g.ch = lun->vlun.chnl_id; |
Matias Bjørling | 293a6e8 | 2016-05-06 20:03:10 +0200 | [diff] [blame] | 382 | ppa.g.lun = lun->vlun.lun_id; |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 383 | |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 384 | ret = nvm_get_bb_tbl(dev, ppa, blks); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 385 | if (ret) |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 386 | pr_err("gen: could not get BB table\n"); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 387 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 388 | ret = gen_block_bb(gn, ppa, blks, nr_blks); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 389 | if (ret) |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 390 | pr_err("gen: BB table map failed\n"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Javier González | 29fd20b | 2016-03-03 15:06:41 +0100 | [diff] [blame] | 394 | if ((dev->identity.dom & NVM_RSP_L2P) && dev->ops->get_l2p_tbl) { |
Matias Bjørling | 4ece44a | 2016-02-20 08:52:41 +0100 | [diff] [blame] | 395 | ret = dev->ops->get_l2p_tbl(dev, 0, dev->total_secs, |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 396 | gen_block_map, dev); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 397 | if (ret) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 398 | pr_err("gen: could not read L2P table.\n"); |
| 399 | pr_warn("gen: default block initialization"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 403 | kfree(blks); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 407 | static void gen_free(struct nvm_dev *dev) |
Wenwei Tao | 8261bd48 | 2015-11-28 16:49:23 +0100 | [diff] [blame] | 408 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 409 | gen_blocks_free(dev); |
| 410 | gen_luns_free(dev); |
Wenwei Tao | 8261bd48 | 2015-11-28 16:49:23 +0100 | [diff] [blame] | 411 | kfree(dev->mp); |
| 412 | dev->mp = NULL; |
| 413 | } |
| 414 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 415 | static int gen_register(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 416 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 417 | struct gen_dev *gn; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 418 | int ret; |
| 419 | |
Matias Bjørling | 008b744 | 2015-12-06 11:25:50 +0100 | [diff] [blame] | 420 | if (!try_module_get(THIS_MODULE)) |
| 421 | return -ENODEV; |
| 422 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 423 | gn = kzalloc(sizeof(struct gen_dev), GFP_KERNEL); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 424 | if (!gn) |
| 425 | return -ENOMEM; |
| 426 | |
Matias Bjørling | 1145046 | 2015-11-16 15:34:37 +0100 | [diff] [blame] | 427 | gn->dev = dev; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 428 | gn->nr_luns = dev->nr_luns; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 429 | INIT_LIST_HEAD(&gn->area_list); |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 430 | mutex_init(&gn->lock); |
| 431 | INIT_LIST_HEAD(&gn->targets); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 432 | dev->mp = gn; |
| 433 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 434 | ret = gen_luns_init(dev, gn); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 435 | if (ret) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 436 | pr_err("gen: could not initialize luns\n"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 437 | goto err; |
| 438 | } |
| 439 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 440 | ret = gen_blocks_init(dev, gn); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 441 | if (ret) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 442 | pr_err("gen: could not initialize blocks\n"); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 443 | goto err; |
| 444 | } |
| 445 | |
| 446 | return 1; |
| 447 | err: |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 448 | gen_free(dev); |
Matias Bjørling | 008b744 | 2015-12-06 11:25:50 +0100 | [diff] [blame] | 449 | module_put(THIS_MODULE); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 450 | return ret; |
| 451 | } |
| 452 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 453 | static void gen_unregister(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 454 | { |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 455 | struct gen_dev *gn = dev->mp; |
| 456 | struct nvm_target *t, *tmp; |
| 457 | |
| 458 | mutex_lock(&gn->lock); |
| 459 | list_for_each_entry_safe(t, tmp, &gn->targets, list) { |
| 460 | if (t->dev != dev) |
| 461 | continue; |
| 462 | __gen_remove_target(t); |
| 463 | } |
| 464 | mutex_unlock(&gn->lock); |
| 465 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 466 | gen_free(dev); |
Matias Bjørling | 008b744 | 2015-12-06 11:25:50 +0100 | [diff] [blame] | 467 | module_put(THIS_MODULE); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Matias Bjørling | 41285fa | 2016-07-07 09:54:19 +0200 | [diff] [blame] | 470 | static struct nvm_block *gen_get_blk(struct nvm_dev *dev, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 471 | struct nvm_lun *vlun, unsigned long flags) |
| 472 | { |
| 473 | struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun); |
| 474 | struct nvm_block *blk = NULL; |
| 475 | int is_gc = flags & NVM_IOTYPE_GC; |
| 476 | |
Matias Bjørling | 41285fa | 2016-07-07 09:54:19 +0200 | [diff] [blame] | 477 | spin_lock(&vlun->lock); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 478 | if (list_empty(&lun->free_list)) { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 479 | pr_err_ratelimited("gen: lun %u have no free pages available", |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 480 | lun->vlun.id); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 481 | goto out; |
| 482 | } |
| 483 | |
Wenwei Tao | e9b76a8 | 2015-12-06 11:25:45 +0100 | [diff] [blame] | 484 | if (!is_gc && lun->vlun.nr_free_blocks < lun->reserved_blocks) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 485 | goto out; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 486 | |
| 487 | blk = list_first_entry(&lun->free_list, struct nvm_block, list); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 488 | |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 489 | list_move_tail(&blk->list, &lun->used_list); |
| 490 | blk->state = NVM_BLK_ST_TGT; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 491 | lun->vlun.nr_free_blocks--; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 492 | out: |
Wenwei Tao | e9b76a8 | 2015-12-06 11:25:45 +0100 | [diff] [blame] | 493 | spin_unlock(&vlun->lock); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 494 | return blk; |
| 495 | } |
| 496 | |
Matias Bjørling | 41285fa | 2016-07-07 09:54:19 +0200 | [diff] [blame] | 497 | static void gen_put_blk(struct nvm_dev *dev, struct nvm_block *blk) |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 498 | { |
| 499 | struct nvm_lun *vlun = blk->lun; |
| 500 | struct gen_lun *lun = container_of(vlun, struct gen_lun, vlun); |
| 501 | |
Matias Bjørling | 41285fa | 2016-07-07 09:54:19 +0200 | [diff] [blame] | 502 | spin_lock(&vlun->lock); |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 503 | if (blk->state & NVM_BLK_ST_TGT) { |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 504 | list_move_tail(&blk->list, &lun->free_list); |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 505 | lun->vlun.nr_free_blocks++; |
| 506 | blk->state = NVM_BLK_ST_FREE; |
| 507 | } else if (blk->state & NVM_BLK_ST_BAD) { |
| 508 | list_move_tail(&blk->list, &lun->bb_list); |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 509 | blk->state = NVM_BLK_ST_BAD; |
| 510 | } else { |
| 511 | WARN_ON_ONCE(1); |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 512 | pr_err("gen: erroneous block type (%lu -> %u)\n", |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 513 | blk->id, blk->state); |
| 514 | list_move_tail(&blk->list, &lun->bb_list); |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 515 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 516 | spin_unlock(&vlun->lock); |
| 517 | } |
| 518 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 519 | static void gen_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 520 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 521 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 522 | struct gen_lun *lun; |
| 523 | struct nvm_block *blk; |
| 524 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 525 | pr_debug("gen: ppa (ch: %u lun: %u blk: %u pg: %u) -> %u\n", |
Matias Bjørling | 04a8aa1 | 2016-05-06 20:03:18 +0200 | [diff] [blame] | 526 | ppa.g.ch, ppa.g.lun, ppa.g.blk, ppa.g.pg, type); |
Matias Bjørling | a63d5cf | 2016-05-06 20:03:08 +0200 | [diff] [blame] | 527 | |
Matias Bjørling | 04a8aa1 | 2016-05-06 20:03:18 +0200 | [diff] [blame] | 528 | if (unlikely(ppa.g.ch > dev->nr_chnls || |
| 529 | ppa.g.lun > dev->luns_per_chnl || |
| 530 | ppa.g.blk > dev->blks_per_lun)) { |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 531 | WARN_ON_ONCE(1); |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 532 | pr_err("gen: ppa broken (ch: %u > %u lun: %u > %u blk: %u > %u", |
Matias Bjørling | 04a8aa1 | 2016-05-06 20:03:18 +0200 | [diff] [blame] | 533 | ppa.g.ch, dev->nr_chnls, |
| 534 | ppa.g.lun, dev->luns_per_chnl, |
| 535 | ppa.g.blk, dev->blks_per_lun); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 536 | return; |
| 537 | } |
| 538 | |
Matias Bjørling | 24d4a7d | 2016-07-07 09:54:21 +0200 | [diff] [blame] | 539 | lun = &gn->luns[(dev->luns_per_chnl * ppa.g.ch) + ppa.g.lun]; |
Matias Bjørling | 04a8aa1 | 2016-05-06 20:03:18 +0200 | [diff] [blame] | 540 | blk = &lun->vlun.blocks[ppa.g.blk]; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 541 | |
| 542 | /* will be moved to bb list on put_blk from target */ |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 543 | blk->state = type; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 546 | static void gen_end_io(struct nvm_rq *rqd) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 547 | { |
| 548 | struct nvm_tgt_instance *ins = rqd->ins; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 549 | |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 550 | ins->tt->end_io(rqd); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 551 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 552 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 553 | static int gen_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd) |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 554 | { |
| 555 | if (!dev->ops->submit_io) |
| 556 | return -ENODEV; |
| 557 | |
| 558 | /* Convert address space */ |
| 559 | nvm_generic_to_addr_mode(dev, rqd); |
| 560 | |
| 561 | rqd->dev = dev; |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 562 | rqd->end_io = gen_end_io; |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 563 | return dev->ops->submit_io(dev, rqd); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Javier González | bb31497 | 2016-11-28 22:38:54 +0100 | [diff] [blame] | 566 | static int gen_erase_blk(struct nvm_dev *dev, struct nvm_block *blk, int flags) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 567 | { |
Matias Bjørling | 069368e | 2016-01-12 07:49:19 +0100 | [diff] [blame] | 568 | struct ppa_addr addr = block_to_ppa(dev, blk); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 569 | |
Javier González | bb31497 | 2016-11-28 22:38:54 +0100 | [diff] [blame] | 570 | return nvm_erase_ppa(dev, &addr, 1, flags); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 571 | } |
| 572 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 573 | static int gen_reserve_lun(struct nvm_dev *dev, int lunid) |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 574 | { |
| 575 | return test_and_set_bit(lunid, dev->lun_map); |
| 576 | } |
| 577 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 578 | static void gen_release_lun(struct nvm_dev *dev, int lunid) |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 579 | { |
| 580 | WARN_ON(!test_and_clear_bit(lunid, dev->lun_map)); |
| 581 | } |
| 582 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 583 | static struct nvm_lun *gen_get_lun(struct nvm_dev *dev, int lunid) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 584 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 585 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 586 | |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 587 | if (unlikely(lunid >= dev->nr_luns)) |
| 588 | return NULL; |
| 589 | |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 590 | return &gn->luns[lunid].vlun; |
| 591 | } |
| 592 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 593 | static void gen_lun_info_print(struct nvm_dev *dev) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 594 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 595 | struct gen_dev *gn = dev->mp; |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 596 | struct gen_lun *lun; |
| 597 | unsigned int i; |
| 598 | |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 599 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 600 | gen_for_each_lun(gn, lun, i) { |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 601 | spin_lock(&lun->vlun.lock); |
| 602 | |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 603 | pr_info("%s: lun%8u\t%u\n", dev->name, i, |
| 604 | lun->vlun.nr_free_blocks); |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 605 | |
| 606 | spin_unlock(&lun->vlun.lock); |
| 607 | } |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 608 | } |
| 609 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 610 | static struct nvmm_type gen = { |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 611 | .name = "gennvm", |
| 612 | .version = {0, 1, 0}, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 613 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 614 | .register_mgr = gen_register, |
| 615 | .unregister_mgr = gen_unregister, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 616 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 617 | .create_tgt = gen_create_tgt, |
| 618 | .remove_tgt = gen_remove_tgt, |
| 619 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 620 | .get_blk = gen_get_blk, |
| 621 | .put_blk = gen_put_blk, |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 622 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 623 | .submit_io = gen_submit_io, |
| 624 | .erase_blk = gen_erase_blk, |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 625 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 626 | .mark_blk = gen_mark_blk, |
Matias Bjørling | 04a8aa1 | 2016-05-06 20:03:18 +0200 | [diff] [blame] | 627 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 628 | .get_lun = gen_get_lun, |
| 629 | .reserve_lun = gen_reserve_lun, |
| 630 | .release_lun = gen_release_lun, |
| 631 | .lun_info_print = gen_lun_info_print, |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 632 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 633 | .get_area = gen_get_area, |
| 634 | .put_area = gen_put_area, |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 635 | |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 636 | }; |
| 637 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 638 | static int __init gen_module_init(void) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 639 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 640 | return nvm_register_mgr(&gen); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 641 | } |
| 642 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 643 | static void gen_module_exit(void) |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 644 | { |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 645 | nvm_unregister_mgr(&gen); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 648 | module_init(gen_module_init); |
| 649 | module_exit(gen_module_exit); |
Matias Bjørling | 48add0f | 2015-10-28 19:54:56 +0100 | [diff] [blame] | 650 | MODULE_LICENSE("GPL v2"); |
Matias Bjørling | 5e60edb | 2016-07-07 09:54:15 +0200 | [diff] [blame] | 651 | MODULE_DESCRIPTION("General media manager for Open-Channel SSDs"); |