Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 IT University of Copenhagen. All rights reserved. |
| 3 | * Initial release: Matias Bjorling <m@bjorling.me> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version |
| 7 | * 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; see the file COPYING. If not, write to |
| 16 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, |
| 17 | * USA. |
| 18 | * |
| 19 | */ |
| 20 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 21 | #include <linux/list.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/sem.h> |
| 24 | #include <linux/bitmap.h> |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 25 | #include <linux/module.h> |
Paul Gortmaker | 389b2a1 | 2016-10-29 16:38:41 -0400 | [diff] [blame] | 26 | #include <linux/moduleparam.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 27 | #include <linux/miscdevice.h> |
| 28 | #include <linux/lightnvm.h> |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 29 | #include <linux/sched/sysctl.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 30 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 31 | static LIST_HEAD(nvm_tgt_types); |
Matias Bjørling | 5cd9078 | 2016-07-07 09:54:17 +0200 | [diff] [blame] | 32 | static DECLARE_RWSEM(nvm_tgtt_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 33 | static LIST_HEAD(nvm_devices); |
| 34 | static DECLARE_RWSEM(nvm_lock); |
| 35 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 36 | /* Map between virtual and physical channel and lun */ |
| 37 | struct nvm_ch_map { |
| 38 | int ch_off; |
| 39 | int nr_luns; |
| 40 | int *lun_offs; |
| 41 | }; |
| 42 | |
| 43 | struct nvm_dev_map { |
| 44 | struct nvm_ch_map *chnls; |
| 45 | int nr_chnls; |
| 46 | }; |
| 47 | |
| 48 | struct nvm_area { |
| 49 | struct list_head list; |
| 50 | sector_t begin; |
| 51 | sector_t end; /* end is excluded */ |
| 52 | }; |
| 53 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 54 | static struct nvm_target *nvm_find_target(struct nvm_dev *dev, const char *name) |
| 55 | { |
| 56 | struct nvm_target *tgt; |
| 57 | |
| 58 | list_for_each_entry(tgt, &dev->targets, list) |
| 59 | if (!strcmp(name, tgt->disk->disk_name)) |
| 60 | return tgt; |
| 61 | |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | static int nvm_reserve_luns(struct nvm_dev *dev, int lun_begin, int lun_end) |
| 66 | { |
| 67 | int i; |
| 68 | |
| 69 | for (i = lun_begin; i <= lun_end; i++) { |
| 70 | if (test_and_set_bit(i, dev->lun_map)) { |
| 71 | pr_err("nvm: lun %d already allocated\n", i); |
| 72 | goto err; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | err: |
Javier González | 507f7d6 | 2017-05-03 11:19:05 +0200 | [diff] [blame] | 78 | while (--i >= lun_begin) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 79 | clear_bit(i, dev->lun_map); |
| 80 | |
| 81 | return -EBUSY; |
| 82 | } |
| 83 | |
| 84 | static void nvm_release_luns_err(struct nvm_dev *dev, int lun_begin, |
| 85 | int lun_end) |
| 86 | { |
| 87 | int i; |
| 88 | |
| 89 | for (i = lun_begin; i <= lun_end; i++) |
| 90 | WARN_ON(!test_and_clear_bit(i, dev->lun_map)); |
| 91 | } |
| 92 | |
Javier González | edee1bd | 2017-04-15 20:55:42 +0200 | [diff] [blame] | 93 | static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 94 | { |
| 95 | struct nvm_dev *dev = tgt_dev->parent; |
| 96 | struct nvm_dev_map *dev_map = tgt_dev->map; |
| 97 | int i, j; |
| 98 | |
| 99 | for (i = 0; i < dev_map->nr_chnls; i++) { |
| 100 | struct nvm_ch_map *ch_map = &dev_map->chnls[i]; |
| 101 | int *lun_offs = ch_map->lun_offs; |
| 102 | int ch = i + ch_map->ch_off; |
| 103 | |
Javier González | edee1bd | 2017-04-15 20:55:42 +0200 | [diff] [blame] | 104 | if (clear) { |
| 105 | for (j = 0; j < ch_map->nr_luns; j++) { |
| 106 | int lun = j + lun_offs[j]; |
| 107 | int lunid = (ch * dev->geo.luns_per_chnl) + lun; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 108 | |
Javier González | edee1bd | 2017-04-15 20:55:42 +0200 | [diff] [blame] | 109 | WARN_ON(!test_and_clear_bit(lunid, |
| 110 | dev->lun_map)); |
| 111 | } |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | kfree(ch_map->lun_offs); |
| 115 | } |
| 116 | |
| 117 | kfree(dev_map->chnls); |
| 118 | kfree(dev_map); |
| 119 | |
| 120 | kfree(tgt_dev->luns); |
| 121 | kfree(tgt_dev); |
| 122 | } |
| 123 | |
| 124 | static struct nvm_tgt_dev *nvm_create_tgt_dev(struct nvm_dev *dev, |
| 125 | int lun_begin, int lun_end) |
| 126 | { |
| 127 | struct nvm_tgt_dev *tgt_dev = NULL; |
| 128 | struct nvm_dev_map *dev_rmap = dev->rmap; |
| 129 | struct nvm_dev_map *dev_map; |
| 130 | struct ppa_addr *luns; |
| 131 | int nr_luns = lun_end - lun_begin + 1; |
| 132 | int luns_left = nr_luns; |
| 133 | int nr_chnls = nr_luns / dev->geo.luns_per_chnl; |
| 134 | int nr_chnls_mod = nr_luns % dev->geo.luns_per_chnl; |
| 135 | int bch = lun_begin / dev->geo.luns_per_chnl; |
| 136 | int blun = lun_begin % dev->geo.luns_per_chnl; |
| 137 | int lunid = 0; |
| 138 | int lun_balanced = 1; |
| 139 | int prev_nr_luns; |
| 140 | int i, j; |
| 141 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 142 | nr_chnls = (nr_chnls_mod == 0) ? nr_chnls : nr_chnls + 1; |
| 143 | |
| 144 | dev_map = kmalloc(sizeof(struct nvm_dev_map), GFP_KERNEL); |
| 145 | if (!dev_map) |
| 146 | goto err_dev; |
| 147 | |
| 148 | dev_map->chnls = kcalloc(nr_chnls, sizeof(struct nvm_ch_map), |
| 149 | GFP_KERNEL); |
| 150 | if (!dev_map->chnls) |
| 151 | goto err_chnls; |
| 152 | |
| 153 | luns = kcalloc(nr_luns, sizeof(struct ppa_addr), GFP_KERNEL); |
| 154 | if (!luns) |
| 155 | goto err_luns; |
| 156 | |
| 157 | prev_nr_luns = (luns_left > dev->geo.luns_per_chnl) ? |
| 158 | dev->geo.luns_per_chnl : luns_left; |
| 159 | for (i = 0; i < nr_chnls; i++) { |
| 160 | struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[i + bch]; |
| 161 | int *lun_roffs = ch_rmap->lun_offs; |
| 162 | struct nvm_ch_map *ch_map = &dev_map->chnls[i]; |
| 163 | int *lun_offs; |
| 164 | int luns_in_chnl = (luns_left > dev->geo.luns_per_chnl) ? |
| 165 | dev->geo.luns_per_chnl : luns_left; |
| 166 | |
| 167 | if (lun_balanced && prev_nr_luns != luns_in_chnl) |
| 168 | lun_balanced = 0; |
| 169 | |
| 170 | ch_map->ch_off = ch_rmap->ch_off = bch; |
| 171 | ch_map->nr_luns = luns_in_chnl; |
| 172 | |
| 173 | lun_offs = kcalloc(luns_in_chnl, sizeof(int), GFP_KERNEL); |
| 174 | if (!lun_offs) |
| 175 | goto err_ch; |
| 176 | |
| 177 | for (j = 0; j < luns_in_chnl; j++) { |
| 178 | luns[lunid].ppa = 0; |
| 179 | luns[lunid].g.ch = i; |
| 180 | luns[lunid++].g.lun = j; |
| 181 | |
| 182 | lun_offs[j] = blun; |
| 183 | lun_roffs[j + blun] = blun; |
| 184 | } |
| 185 | |
| 186 | ch_map->lun_offs = lun_offs; |
| 187 | |
| 188 | /* when starting a new channel, lun offset is reset */ |
| 189 | blun = 0; |
| 190 | luns_left -= luns_in_chnl; |
| 191 | } |
| 192 | |
| 193 | dev_map->nr_chnls = nr_chnls; |
| 194 | |
| 195 | tgt_dev = kmalloc(sizeof(struct nvm_tgt_dev), GFP_KERNEL); |
| 196 | if (!tgt_dev) |
| 197 | goto err_ch; |
| 198 | |
| 199 | memcpy(&tgt_dev->geo, &dev->geo, sizeof(struct nvm_geo)); |
| 200 | /* Target device only owns a portion of the physical device */ |
| 201 | tgt_dev->geo.nr_chnls = nr_chnls; |
| 202 | tgt_dev->geo.nr_luns = nr_luns; |
| 203 | tgt_dev->geo.luns_per_chnl = (lun_balanced) ? prev_nr_luns : -1; |
| 204 | tgt_dev->total_secs = nr_luns * tgt_dev->geo.sec_per_lun; |
| 205 | tgt_dev->q = dev->q; |
| 206 | tgt_dev->map = dev_map; |
| 207 | tgt_dev->luns = luns; |
| 208 | memcpy(&tgt_dev->identity, &dev->identity, sizeof(struct nvm_id)); |
| 209 | |
| 210 | tgt_dev->parent = dev; |
| 211 | |
| 212 | return tgt_dev; |
| 213 | err_ch: |
Javier González | 507f7d6 | 2017-05-03 11:19:05 +0200 | [diff] [blame] | 214 | while (--i >= 0) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 215 | kfree(dev_map->chnls[i].lun_offs); |
| 216 | kfree(luns); |
| 217 | err_luns: |
| 218 | kfree(dev_map->chnls); |
| 219 | err_chnls: |
| 220 | kfree(dev_map); |
| 221 | err_dev: |
| 222 | return tgt_dev; |
| 223 | } |
| 224 | |
| 225 | static const struct block_device_operations nvm_fops = { |
| 226 | .owner = THIS_MODULE, |
| 227 | }; |
| 228 | |
Rakesh Pandit | eb6f168 | 2017-10-13 14:46:31 +0200 | [diff] [blame^] | 229 | static struct nvm_tgt_type *nvm_find_target_type(const char *name, int lock) |
| 230 | { |
| 231 | struct nvm_tgt_type *tmp, *tt = NULL; |
| 232 | |
| 233 | if (lock) |
| 234 | down_write(&nvm_tgtt_lock); |
| 235 | |
| 236 | list_for_each_entry(tmp, &nvm_tgt_types, list) |
| 237 | if (!strcmp(name, tmp->name)) { |
| 238 | tt = tmp; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | if (lock) |
| 243 | up_write(&nvm_tgtt_lock); |
| 244 | return tt; |
| 245 | } |
| 246 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 247 | static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) |
| 248 | { |
| 249 | struct nvm_ioctl_create_simple *s = &create->conf.s; |
| 250 | struct request_queue *tqueue; |
| 251 | struct gendisk *tdisk; |
| 252 | struct nvm_tgt_type *tt; |
| 253 | struct nvm_target *t; |
| 254 | struct nvm_tgt_dev *tgt_dev; |
| 255 | void *targetdata; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 256 | int ret; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 257 | |
| 258 | tt = nvm_find_target_type(create->tgttype, 1); |
| 259 | if (!tt) { |
| 260 | pr_err("nvm: target type %s not found\n", create->tgttype); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
| 264 | mutex_lock(&dev->mlock); |
| 265 | t = nvm_find_target(dev, create->tgtname); |
| 266 | if (t) { |
| 267 | pr_err("nvm: target name already exists.\n"); |
| 268 | mutex_unlock(&dev->mlock); |
| 269 | return -EINVAL; |
| 270 | } |
| 271 | mutex_unlock(&dev->mlock); |
| 272 | |
Rakesh Pandit | 12e9a6d6 | 2017-06-27 14:55:33 +0300 | [diff] [blame] | 273 | ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end); |
| 274 | if (ret) |
| 275 | return ret; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 276 | |
| 277 | t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 278 | if (!t) { |
| 279 | ret = -ENOMEM; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 280 | goto err_reserve; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 281 | } |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 282 | |
| 283 | tgt_dev = nvm_create_tgt_dev(dev, s->lun_begin, s->lun_end); |
| 284 | if (!tgt_dev) { |
| 285 | pr_err("nvm: could not create target device\n"); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 286 | ret = -ENOMEM; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 287 | goto err_t; |
| 288 | } |
| 289 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 290 | tdisk = alloc_disk(0); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 291 | if (!tdisk) { |
| 292 | ret = -ENOMEM; |
Javier González | 7d1ef2f | 2017-04-15 20:55:43 +0200 | [diff] [blame] | 293 | goto err_dev; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 294 | } |
Javier González | 7d1ef2f | 2017-04-15 20:55:43 +0200 | [diff] [blame] | 295 | |
| 296 | tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 297 | if (!tqueue) { |
| 298 | ret = -ENOMEM; |
Javier González | 7d1ef2f | 2017-04-15 20:55:43 +0200 | [diff] [blame] | 299 | goto err_disk; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 300 | } |
Javier González | 7d1ef2f | 2017-04-15 20:55:43 +0200 | [diff] [blame] | 301 | blk_queue_make_request(tqueue, tt->make_rq); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 302 | |
Javier González | 6eb0824 | 2017-04-15 20:55:49 +0200 | [diff] [blame] | 303 | strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name)); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 304 | tdisk->flags = GENHD_FL_EXT_DEVT; |
| 305 | tdisk->major = 0; |
| 306 | tdisk->first_minor = 0; |
| 307 | tdisk->fops = &nvm_fops; |
| 308 | tdisk->queue = tqueue; |
| 309 | |
Javier González | 4af3f75 | 2017-04-15 20:55:45 +0200 | [diff] [blame] | 310 | targetdata = tt->init(tgt_dev, tdisk, create->flags); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 311 | if (IS_ERR(targetdata)) { |
| 312 | ret = PTR_ERR(targetdata); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 313 | goto err_init; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 314 | } |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 315 | |
| 316 | tdisk->private_data = targetdata; |
| 317 | tqueue->queuedata = targetdata; |
| 318 | |
| 319 | blk_queue_max_hw_sectors(tqueue, 8 * dev->ops->max_phys_sect); |
| 320 | |
| 321 | set_capacity(tdisk, tt->capacity(targetdata)); |
| 322 | add_disk(tdisk); |
| 323 | |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 324 | if (tt->sysfs_init && tt->sysfs_init(tdisk)) { |
| 325 | ret = -ENOMEM; |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 326 | goto err_sysfs; |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 327 | } |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 328 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 329 | t->type = tt; |
| 330 | t->disk = tdisk; |
| 331 | t->dev = tgt_dev; |
| 332 | |
| 333 | mutex_lock(&dev->mlock); |
| 334 | list_add_tail(&t->list, &dev->targets); |
| 335 | mutex_unlock(&dev->mlock); |
| 336 | |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 337 | __module_get(tt->owner); |
| 338 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 339 | return 0; |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 340 | err_sysfs: |
| 341 | if (tt->exit) |
| 342 | tt->exit(targetdata); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 343 | err_init: |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 344 | blk_cleanup_queue(tqueue); |
Rakesh Pandit | 75ba4ad | 2017-04-20 08:17:47 -0600 | [diff] [blame] | 345 | tdisk->queue = NULL; |
Javier González | 7d1ef2f | 2017-04-15 20:55:43 +0200 | [diff] [blame] | 346 | err_disk: |
| 347 | put_disk(tdisk); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 348 | err_dev: |
Javier González | edee1bd | 2017-04-15 20:55:42 +0200 | [diff] [blame] | 349 | nvm_remove_tgt_dev(tgt_dev, 0); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 350 | err_t: |
| 351 | kfree(t); |
| 352 | err_reserve: |
| 353 | nvm_release_luns_err(dev, s->lun_begin, s->lun_end); |
Rakesh Pandit | 8d77bb8 | 2017-04-20 21:23:56 +0300 | [diff] [blame] | 354 | return ret; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static void __nvm_remove_target(struct nvm_target *t) |
| 358 | { |
| 359 | struct nvm_tgt_type *tt = t->type; |
| 360 | struct gendisk *tdisk = t->disk; |
| 361 | struct request_queue *q = tdisk->queue; |
| 362 | |
| 363 | del_gendisk(tdisk); |
| 364 | blk_cleanup_queue(q); |
| 365 | |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 366 | if (tt->sysfs_exit) |
| 367 | tt->sysfs_exit(tdisk); |
| 368 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 369 | if (tt->exit) |
| 370 | tt->exit(tdisk->private_data); |
| 371 | |
Javier González | edee1bd | 2017-04-15 20:55:42 +0200 | [diff] [blame] | 372 | nvm_remove_tgt_dev(t->dev, 1); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 373 | put_disk(tdisk); |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 374 | module_put(t->type->owner); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 375 | |
| 376 | list_del(&t->list); |
| 377 | kfree(t); |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * nvm_remove_tgt - Removes a target from the media manager |
| 382 | * @dev: device |
| 383 | * @remove: ioctl structure with target name to remove. |
| 384 | * |
| 385 | * Returns: |
| 386 | * 0: on success |
| 387 | * 1: on not found |
| 388 | * <0: on error |
| 389 | */ |
| 390 | static int nvm_remove_tgt(struct nvm_dev *dev, struct nvm_ioctl_remove *remove) |
| 391 | { |
| 392 | struct nvm_target *t; |
Rakesh Pandit | bb6aa6f | 2017-10-13 14:45:51 +0200 | [diff] [blame] | 393 | struct block_device *bdev; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 394 | |
| 395 | mutex_lock(&dev->mlock); |
| 396 | t = nvm_find_target(dev, remove->tgtname); |
| 397 | if (!t) { |
| 398 | mutex_unlock(&dev->mlock); |
| 399 | return 1; |
| 400 | } |
Rakesh Pandit | bb6aa6f | 2017-10-13 14:45:51 +0200 | [diff] [blame] | 401 | bdev = bdget_disk(t->disk, 0); |
| 402 | if (!bdev) { |
| 403 | pr_err("nvm: removal failed, allocating bd failed\n"); |
| 404 | mutex_unlock(&dev->mlock); |
| 405 | return -ENOMEM; |
| 406 | } |
| 407 | if (bdev->bd_super || bdev->bd_part_count) { |
| 408 | pr_err("nvm: removal failed, block device busy\n"); |
| 409 | bdput(bdev); |
| 410 | mutex_unlock(&dev->mlock); |
| 411 | return -EBUSY; |
| 412 | } |
| 413 | bdput(bdev); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 414 | __nvm_remove_target(t); |
| 415 | mutex_unlock(&dev->mlock); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int nvm_register_map(struct nvm_dev *dev) |
| 421 | { |
| 422 | struct nvm_dev_map *rmap; |
| 423 | int i, j; |
| 424 | |
| 425 | rmap = kmalloc(sizeof(struct nvm_dev_map), GFP_KERNEL); |
| 426 | if (!rmap) |
| 427 | goto err_rmap; |
| 428 | |
| 429 | rmap->chnls = kcalloc(dev->geo.nr_chnls, sizeof(struct nvm_ch_map), |
| 430 | GFP_KERNEL); |
| 431 | if (!rmap->chnls) |
| 432 | goto err_chnls; |
| 433 | |
| 434 | for (i = 0; i < dev->geo.nr_chnls; i++) { |
| 435 | struct nvm_ch_map *ch_rmap; |
| 436 | int *lun_roffs; |
| 437 | int luns_in_chnl = dev->geo.luns_per_chnl; |
| 438 | |
| 439 | ch_rmap = &rmap->chnls[i]; |
| 440 | |
| 441 | ch_rmap->ch_off = -1; |
| 442 | ch_rmap->nr_luns = luns_in_chnl; |
| 443 | |
| 444 | lun_roffs = kcalloc(luns_in_chnl, sizeof(int), GFP_KERNEL); |
| 445 | if (!lun_roffs) |
| 446 | goto err_ch; |
| 447 | |
| 448 | for (j = 0; j < luns_in_chnl; j++) |
| 449 | lun_roffs[j] = -1; |
| 450 | |
| 451 | ch_rmap->lun_offs = lun_roffs; |
| 452 | } |
| 453 | |
| 454 | dev->rmap = rmap; |
| 455 | |
| 456 | return 0; |
| 457 | err_ch: |
| 458 | while (--i >= 0) |
| 459 | kfree(rmap->chnls[i].lun_offs); |
| 460 | err_chnls: |
| 461 | kfree(rmap); |
| 462 | err_rmap: |
| 463 | return -ENOMEM; |
| 464 | } |
| 465 | |
Javier González | 7a3de2b | 2017-04-15 20:55:39 +0200 | [diff] [blame] | 466 | static void nvm_unregister_map(struct nvm_dev *dev) |
| 467 | { |
| 468 | struct nvm_dev_map *rmap = dev->rmap; |
| 469 | int i; |
| 470 | |
| 471 | for (i = 0; i < dev->geo.nr_chnls; i++) |
| 472 | kfree(rmap->chnls[i].lun_offs); |
| 473 | |
| 474 | kfree(rmap->chnls); |
| 475 | kfree(rmap); |
| 476 | } |
| 477 | |
Matias Bjørling | 61a561d | 2017-01-31 13:17:13 +0100 | [diff] [blame] | 478 | static void nvm_map_to_dev(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *p) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 479 | { |
| 480 | struct nvm_dev_map *dev_map = tgt_dev->map; |
| 481 | struct nvm_ch_map *ch_map = &dev_map->chnls[p->g.ch]; |
| 482 | int lun_off = ch_map->lun_offs[p->g.lun]; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 483 | |
| 484 | p->g.ch += ch_map->ch_off; |
| 485 | p->g.lun += lun_off; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Matias Bjørling | 61a561d | 2017-01-31 13:17:13 +0100 | [diff] [blame] | 488 | static void nvm_map_to_tgt(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *p) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 489 | { |
| 490 | struct nvm_dev *dev = tgt_dev->parent; |
| 491 | struct nvm_dev_map *dev_rmap = dev->rmap; |
| 492 | struct nvm_ch_map *ch_rmap = &dev_rmap->chnls[p->g.ch]; |
| 493 | int lun_roff = ch_rmap->lun_offs[p->g.lun]; |
| 494 | |
| 495 | p->g.ch -= ch_rmap->ch_off; |
| 496 | p->g.lun -= lun_roff; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 499 | static void nvm_ppa_tgt_to_dev(struct nvm_tgt_dev *tgt_dev, |
| 500 | struct ppa_addr *ppa_list, int nr_ppas) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 501 | { |
| 502 | int i; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 503 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 504 | for (i = 0; i < nr_ppas; i++) { |
| 505 | nvm_map_to_dev(tgt_dev, &ppa_list[i]); |
| 506 | ppa_list[i] = generic_to_dev_addr(tgt_dev, ppa_list[i]); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 507 | } |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 510 | static void nvm_ppa_dev_to_tgt(struct nvm_tgt_dev *tgt_dev, |
| 511 | struct ppa_addr *ppa_list, int nr_ppas) |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 512 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 513 | int i; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 514 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 515 | for (i = 0; i < nr_ppas; i++) { |
| 516 | ppa_list[i] = dev_to_generic_addr(tgt_dev, ppa_list[i]); |
| 517 | nvm_map_to_tgt(tgt_dev, &ppa_list[i]); |
| 518 | } |
| 519 | } |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 520 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 521 | static void nvm_rq_tgt_to_dev(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd) |
| 522 | { |
| 523 | if (rqd->nr_ppas == 1) { |
| 524 | nvm_ppa_tgt_to_dev(tgt_dev, &rqd->ppa_addr, 1); |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | nvm_ppa_tgt_to_dev(tgt_dev, rqd->ppa_list, rqd->nr_ppas); |
| 529 | } |
| 530 | |
| 531 | static void nvm_rq_dev_to_tgt(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd) |
| 532 | { |
| 533 | if (rqd->nr_ppas == 1) { |
| 534 | nvm_ppa_dev_to_tgt(tgt_dev, &rqd->ppa_addr, 1); |
| 535 | return; |
| 536 | } |
| 537 | |
| 538 | nvm_ppa_dev_to_tgt(tgt_dev, rqd->ppa_list, rqd->nr_ppas); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void nvm_part_to_tgt(struct nvm_dev *dev, sector_t *entries, |
| 542 | int len) |
| 543 | { |
| 544 | struct nvm_geo *geo = &dev->geo; |
| 545 | struct nvm_dev_map *dev_rmap = dev->rmap; |
| 546 | u64 i; |
| 547 | |
| 548 | for (i = 0; i < len; i++) { |
| 549 | struct nvm_ch_map *ch_rmap; |
| 550 | int *lun_roffs; |
| 551 | struct ppa_addr gaddr; |
| 552 | u64 pba = le64_to_cpu(entries[i]); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 553 | u64 diff; |
| 554 | |
| 555 | if (!pba) |
| 556 | continue; |
| 557 | |
| 558 | gaddr = linear_to_generic_addr(geo, pba); |
| 559 | ch_rmap = &dev_rmap->chnls[gaddr.g.ch]; |
| 560 | lun_roffs = ch_rmap->lun_offs; |
| 561 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 562 | diff = ((ch_rmap->ch_off * geo->luns_per_chnl) + |
| 563 | (lun_roffs[gaddr.g.lun])) * geo->sec_per_lun; |
| 564 | |
| 565 | entries[i] -= cpu_to_le64(diff); |
| 566 | } |
| 567 | } |
| 568 | EXPORT_SYMBOL(nvm_part_to_tgt); |
| 569 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 570 | int nvm_register_tgt_type(struct nvm_tgt_type *tt) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 571 | { |
| 572 | int ret = 0; |
| 573 | |
Matias Bjørling | 5cd9078 | 2016-07-07 09:54:17 +0200 | [diff] [blame] | 574 | down_write(&nvm_tgtt_lock); |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 575 | if (nvm_find_target_type(tt->name, 0)) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 576 | ret = -EEXIST; |
| 577 | else |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 578 | list_add(&tt->list, &nvm_tgt_types); |
Matias Bjørling | 5cd9078 | 2016-07-07 09:54:17 +0200 | [diff] [blame] | 579 | up_write(&nvm_tgtt_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 580 | |
| 581 | return ret; |
| 582 | } |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 583 | EXPORT_SYMBOL(nvm_register_tgt_type); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 584 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 585 | void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 586 | { |
| 587 | if (!tt) |
| 588 | return; |
| 589 | |
Rakesh Pandit | 88d31ea | 2017-10-13 14:45:52 +0200 | [diff] [blame] | 590 | down_write(&nvm_tgtt_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 591 | list_del(&tt->list); |
Rakesh Pandit | 88d31ea | 2017-10-13 14:45:52 +0200 | [diff] [blame] | 592 | up_write(&nvm_tgtt_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 593 | } |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 594 | EXPORT_SYMBOL(nvm_unregister_tgt_type); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 595 | |
| 596 | void *nvm_dev_dma_alloc(struct nvm_dev *dev, gfp_t mem_flags, |
| 597 | dma_addr_t *dma_handler) |
| 598 | { |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 599 | return dev->ops->dev_dma_alloc(dev, dev->dma_pool, mem_flags, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 600 | dma_handler); |
| 601 | } |
| 602 | EXPORT_SYMBOL(nvm_dev_dma_alloc); |
| 603 | |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 604 | void nvm_dev_dma_free(struct nvm_dev *dev, void *addr, dma_addr_t dma_handler) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 605 | { |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 606 | dev->ops->dev_dma_free(dev->dma_pool, addr, dma_handler); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 607 | } |
| 608 | EXPORT_SYMBOL(nvm_dev_dma_free); |
| 609 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 610 | static struct nvm_dev *nvm_find_nvm_dev(const char *name) |
| 611 | { |
| 612 | struct nvm_dev *dev; |
| 613 | |
| 614 | list_for_each_entry(dev, &nvm_devices, devices) |
| 615 | if (!strcmp(name, dev->name)) |
| 616 | return dev; |
| 617 | |
| 618 | return NULL; |
| 619 | } |
| 620 | |
Rakesh Pandit | eb6f168 | 2017-10-13 14:46:31 +0200 | [diff] [blame^] | 621 | static int nvm_set_rqd_ppalist(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd, |
| 622 | const struct ppa_addr *ppas, int nr_ppas) |
| 623 | { |
| 624 | struct nvm_dev *dev = tgt_dev->parent; |
| 625 | struct nvm_geo *geo = &tgt_dev->geo; |
| 626 | int i, plane_cnt, pl_idx; |
| 627 | struct ppa_addr ppa; |
| 628 | |
| 629 | if (geo->plane_mode == NVM_PLANE_SINGLE && nr_ppas == 1) { |
| 630 | rqd->nr_ppas = nr_ppas; |
| 631 | rqd->ppa_addr = ppas[0]; |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | rqd->nr_ppas = nr_ppas; |
| 637 | rqd->ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, &rqd->dma_ppa_list); |
| 638 | if (!rqd->ppa_list) { |
| 639 | pr_err("nvm: failed to allocate dma memory\n"); |
| 640 | return -ENOMEM; |
| 641 | } |
| 642 | |
| 643 | plane_cnt = geo->plane_mode; |
| 644 | rqd->nr_ppas *= plane_cnt; |
| 645 | |
| 646 | for (i = 0; i < nr_ppas; i++) { |
| 647 | for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { |
| 648 | ppa = ppas[i]; |
| 649 | ppa.g.pl = pl_idx; |
| 650 | rqd->ppa_list[(pl_idx * nr_ppas) + i] = ppa; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static void nvm_free_rqd_ppalist(struct nvm_tgt_dev *tgt_dev, |
| 658 | struct nvm_rq *rqd) |
| 659 | { |
| 660 | if (!rqd->ppa_list) |
| 661 | return; |
| 662 | |
| 663 | nvm_dev_dma_free(tgt_dev->parent, rqd->ppa_list, rqd->dma_ppa_list); |
| 664 | } |
| 665 | |
| 666 | |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 667 | int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas, |
| 668 | int nr_ppas, int type) |
| 669 | { |
| 670 | struct nvm_dev *dev = tgt_dev->parent; |
| 671 | struct nvm_rq rqd; |
| 672 | int ret; |
| 673 | |
| 674 | if (nr_ppas > dev->ops->max_phys_sect) { |
| 675 | pr_err("nvm: unable to update all blocks atomically\n"); |
| 676 | return -EINVAL; |
| 677 | } |
| 678 | |
| 679 | memset(&rqd, 0, sizeof(struct nvm_rq)); |
| 680 | |
Rakesh Pandit | ef56b9c | 2017-10-13 14:46:30 +0200 | [diff] [blame] | 681 | nvm_set_rqd_ppalist(tgt_dev, &rqd, ppas, nr_ppas); |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 682 | nvm_rq_tgt_to_dev(tgt_dev, &rqd); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 683 | |
| 684 | ret = dev->ops->set_bb_tbl(dev, &rqd.ppa_addr, rqd.nr_ppas, type); |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 685 | nvm_free_rqd_ppalist(tgt_dev, &rqd); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 686 | if (ret) { |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 687 | pr_err("nvm: failed bb mark\n"); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 688 | return -EINVAL; |
| 689 | } |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | EXPORT_SYMBOL(nvm_set_tgt_bb_tbl); |
| 694 | |
Javier González | a279006 | 2016-11-28 22:39:12 +0100 | [diff] [blame] | 695 | int nvm_max_phys_sects(struct nvm_tgt_dev *tgt_dev) |
| 696 | { |
| 697 | struct nvm_dev *dev = tgt_dev->parent; |
| 698 | |
| 699 | return dev->ops->max_phys_sect; |
| 700 | } |
| 701 | EXPORT_SYMBOL(nvm_max_phys_sects); |
| 702 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 703 | int nvm_submit_io(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 704 | { |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 705 | struct nvm_dev *dev = tgt_dev->parent; |
Javier González | 3e505af | 2017-06-26 11:57:10 +0200 | [diff] [blame] | 706 | int ret; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 707 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 708 | if (!dev->ops->submit_io) |
| 709 | return -ENODEV; |
| 710 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 711 | nvm_rq_tgt_to_dev(tgt_dev, rqd); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 712 | |
| 713 | rqd->dev = tgt_dev; |
Javier González | 3e505af | 2017-06-26 11:57:10 +0200 | [diff] [blame] | 714 | |
| 715 | /* In case of error, fail with right address format */ |
| 716 | ret = dev->ops->submit_io(dev, rqd); |
| 717 | if (ret) |
| 718 | nvm_rq_dev_to_tgt(tgt_dev, rqd); |
| 719 | return ret; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 720 | } |
| 721 | EXPORT_SYMBOL(nvm_submit_io); |
| 722 | |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 723 | static void nvm_end_io_sync(struct nvm_rq *rqd) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 724 | { |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 725 | struct completion *waiting = rqd->private; |
| 726 | |
| 727 | complete(waiting); |
| 728 | } |
| 729 | |
| 730 | int nvm_erase_sync(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas, |
| 731 | int nr_ppas) |
| 732 | { |
| 733 | struct nvm_geo *geo = &tgt_dev->geo; |
Matias Bjørling | 10995c3 | 2017-01-31 13:17:10 +0100 | [diff] [blame] | 734 | struct nvm_rq rqd; |
| 735 | int ret; |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 736 | DECLARE_COMPLETION_ONSTACK(wait); |
Matias Bjørling | 10995c3 | 2017-01-31 13:17:10 +0100 | [diff] [blame] | 737 | |
| 738 | memset(&rqd, 0, sizeof(struct nvm_rq)); |
| 739 | |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 740 | rqd.opcode = NVM_OP_ERASE; |
| 741 | rqd.end_io = nvm_end_io_sync; |
| 742 | rqd.private = &wait; |
| 743 | rqd.flags = geo->plane_mode >> 1; |
| 744 | |
Rakesh Pandit | ef56b9c | 2017-10-13 14:46:30 +0200 | [diff] [blame] | 745 | ret = nvm_set_rqd_ppalist(tgt_dev, &rqd, ppas, nr_ppas); |
Matias Bjørling | 10995c3 | 2017-01-31 13:17:10 +0100 | [diff] [blame] | 746 | if (ret) |
| 747 | return ret; |
| 748 | |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 749 | ret = nvm_submit_io(tgt_dev, &rqd); |
| 750 | if (ret) { |
| 751 | pr_err("rrpr: erase I/O submission failed: %d\n", ret); |
| 752 | goto free_ppa_list; |
| 753 | } |
| 754 | wait_for_completion_io(&wait); |
Matias Bjørling | 10995c3 | 2017-01-31 13:17:10 +0100 | [diff] [blame] | 755 | |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 756 | free_ppa_list: |
| 757 | nvm_free_rqd_ppalist(tgt_dev, &rqd); |
Matias Bjørling | 10995c3 | 2017-01-31 13:17:10 +0100 | [diff] [blame] | 758 | |
| 759 | return ret; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 760 | } |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 761 | EXPORT_SYMBOL(nvm_erase_sync); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 762 | |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 763 | int nvm_get_l2p_tbl(struct nvm_tgt_dev *tgt_dev, u64 slba, u32 nlb, |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 764 | nvm_l2p_update_fn *update_l2p, void *priv) |
| 765 | { |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 766 | struct nvm_dev *dev = tgt_dev->parent; |
| 767 | |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 768 | if (!dev->ops->get_l2p_tbl) |
| 769 | return 0; |
| 770 | |
| 771 | return dev->ops->get_l2p_tbl(dev, slba, nlb, update_l2p, priv); |
| 772 | } |
| 773 | EXPORT_SYMBOL(nvm_get_l2p_tbl); |
| 774 | |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 775 | int nvm_get_area(struct nvm_tgt_dev *tgt_dev, sector_t *lba, sector_t len) |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 776 | { |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 777 | struct nvm_dev *dev = tgt_dev->parent; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 778 | struct nvm_geo *geo = &dev->geo; |
| 779 | struct nvm_area *area, *prev, *next; |
| 780 | sector_t begin = 0; |
| 781 | sector_t max_sectors = (geo->sec_size * dev->total_secs) >> 9; |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 782 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 783 | if (len > max_sectors) |
| 784 | return -EINVAL; |
| 785 | |
| 786 | area = kmalloc(sizeof(struct nvm_area), GFP_KERNEL); |
| 787 | if (!area) |
| 788 | return -ENOMEM; |
| 789 | |
| 790 | prev = NULL; |
| 791 | |
| 792 | spin_lock(&dev->lock); |
| 793 | list_for_each_entry(next, &dev->area_list, list) { |
| 794 | if (begin + len > next->begin) { |
| 795 | begin = next->end; |
| 796 | prev = next; |
| 797 | continue; |
| 798 | } |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | if ((begin + len) > max_sectors) { |
| 803 | spin_unlock(&dev->lock); |
| 804 | kfree(area); |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | area->begin = *lba = begin; |
| 809 | area->end = begin + len; |
| 810 | |
| 811 | if (prev) /* insert into sorted order */ |
| 812 | list_add(&area->list, &prev->list); |
| 813 | else |
| 814 | list_add(&area->list, &dev->area_list); |
| 815 | spin_unlock(&dev->lock); |
| 816 | |
| 817 | return 0; |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 818 | } |
| 819 | EXPORT_SYMBOL(nvm_get_area); |
| 820 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 821 | void nvm_put_area(struct nvm_tgt_dev *tgt_dev, sector_t begin) |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 822 | { |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 823 | struct nvm_dev *dev = tgt_dev->parent; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 824 | struct nvm_area *area; |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 825 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 826 | spin_lock(&dev->lock); |
| 827 | list_for_each_entry(area, &dev->area_list, list) { |
| 828 | if (area->begin != begin) |
| 829 | continue; |
| 830 | |
| 831 | list_del(&area->list); |
| 832 | spin_unlock(&dev->lock); |
| 833 | kfree(area); |
| 834 | return; |
| 835 | } |
| 836 | spin_unlock(&dev->lock); |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 837 | } |
| 838 | EXPORT_SYMBOL(nvm_put_area); |
| 839 | |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 840 | void nvm_end_io(struct nvm_rq *rqd) |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 841 | { |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 842 | struct nvm_tgt_dev *tgt_dev = rqd->dev; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 843 | |
| 844 | /* Convert address space */ |
| 845 | if (tgt_dev) |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 846 | nvm_rq_dev_to_tgt(tgt_dev, rqd); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 847 | |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 848 | if (rqd->end_io) |
| 849 | rqd->end_io(rqd); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 850 | } |
| 851 | EXPORT_SYMBOL(nvm_end_io); |
| 852 | |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 853 | /* |
| 854 | * folds a bad block list from its plane representation to its virtual |
| 855 | * block representation. The fold is done in place and reduced size is |
| 856 | * returned. |
| 857 | * |
| 858 | * If any of the planes status are bad or grown bad block, the virtual block |
| 859 | * is marked bad. If not bad, the first plane state acts as the block state. |
| 860 | */ |
| 861 | int nvm_bb_tbl_fold(struct nvm_dev *dev, u8 *blks, int nr_blks) |
| 862 | { |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 863 | struct nvm_geo *geo = &dev->geo; |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 864 | int blk, offset, pl, blktype; |
| 865 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 866 | if (nr_blks != geo->blks_per_lun * geo->plane_mode) |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 867 | return -EINVAL; |
| 868 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 869 | for (blk = 0; blk < geo->blks_per_lun; blk++) { |
| 870 | offset = blk * geo->plane_mode; |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 871 | blktype = blks[offset]; |
| 872 | |
| 873 | /* Bad blocks on any planes take precedence over other types */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 874 | for (pl = 0; pl < geo->plane_mode; pl++) { |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 875 | if (blks[offset + pl] & |
| 876 | (NVM_BLK_T_BAD|NVM_BLK_T_GRWN_BAD)) { |
| 877 | blktype = blks[offset + pl]; |
| 878 | break; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | blks[blk] = blktype; |
| 883 | } |
| 884 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 885 | return geo->blks_per_lun; |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 886 | } |
| 887 | EXPORT_SYMBOL(nvm_bb_tbl_fold); |
| 888 | |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 889 | int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, struct ppa_addr ppa, |
| 890 | u8 *blks) |
| 891 | { |
Matias Bjørling | 8f4fe00 | 2017-01-31 13:17:12 +0100 | [diff] [blame] | 892 | struct nvm_dev *dev = tgt_dev->parent; |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 893 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 894 | nvm_ppa_tgt_to_dev(tgt_dev, &ppa, 1); |
Matias Bjørling | 8f4fe00 | 2017-01-31 13:17:12 +0100 | [diff] [blame] | 895 | |
| 896 | return dev->ops->get_bb_tbl(dev, ppa, blks); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 897 | } |
| 898 | EXPORT_SYMBOL(nvm_get_tgt_bb_tbl); |
| 899 | |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 900 | static int nvm_init_slc_tbl(struct nvm_dev *dev, struct nvm_id_group *grp) |
| 901 | { |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 902 | struct nvm_geo *geo = &dev->geo; |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 903 | int i; |
| 904 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 905 | dev->lps_per_blk = geo->pgs_per_blk; |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 906 | dev->lptbl = kcalloc(dev->lps_per_blk, sizeof(int), GFP_KERNEL); |
| 907 | if (!dev->lptbl) |
| 908 | return -ENOMEM; |
| 909 | |
| 910 | /* Just a linear array */ |
| 911 | for (i = 0; i < dev->lps_per_blk; i++) |
| 912 | dev->lptbl[i] = i; |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static int nvm_init_mlc_tbl(struct nvm_dev *dev, struct nvm_id_group *grp) |
| 918 | { |
| 919 | int i, p; |
| 920 | struct nvm_id_lp_mlc *mlc = &grp->lptbl.mlc; |
| 921 | |
| 922 | if (!mlc->num_pairs) |
| 923 | return 0; |
| 924 | |
| 925 | dev->lps_per_blk = mlc->num_pairs; |
| 926 | dev->lptbl = kcalloc(dev->lps_per_blk, sizeof(int), GFP_KERNEL); |
| 927 | if (!dev->lptbl) |
| 928 | return -ENOMEM; |
| 929 | |
| 930 | /* The lower page table encoding consists of a list of bytes, where each |
| 931 | * has a lower and an upper half. The first half byte maintains the |
| 932 | * increment value and every value after is an offset added to the |
Matias Bjørling | 12624af | 2016-07-07 09:54:13 +0200 | [diff] [blame] | 933 | * previous incrementation value |
| 934 | */ |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 935 | dev->lptbl[0] = mlc->pairs[0] & 0xF; |
| 936 | for (i = 1; i < dev->lps_per_blk; i++) { |
| 937 | p = mlc->pairs[i >> 1]; |
| 938 | if (i & 0x1) /* upper */ |
| 939 | dev->lptbl[i] = dev->lptbl[i - 1] + ((p & 0xF0) >> 4); |
| 940 | else /* lower */ |
| 941 | dev->lptbl[i] = dev->lptbl[i - 1] + (p & 0xF); |
| 942 | } |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 947 | static int nvm_core_init(struct nvm_dev *dev) |
| 948 | { |
| 949 | struct nvm_id *id = &dev->identity; |
Matias Bjørling | 19bd6fe | 2017-01-31 13:17:15 +0100 | [diff] [blame] | 950 | struct nvm_id_group *grp = &id->grp; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 951 | struct nvm_geo *geo = &dev->geo; |
Matias Bjørling | 7f7c5d0 | 2016-05-06 20:02:59 +0200 | [diff] [blame] | 952 | int ret; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 953 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 954 | /* Whole device values */ |
| 955 | geo->nr_chnls = grp->num_ch; |
| 956 | geo->luns_per_chnl = grp->num_lun; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 957 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 958 | /* Generic device values */ |
| 959 | geo->pgs_per_blk = grp->num_pg; |
| 960 | geo->blks_per_lun = grp->num_blk; |
| 961 | geo->nr_planes = grp->num_pln; |
| 962 | geo->fpg_size = grp->fpg_sz; |
| 963 | geo->pfpg_size = grp->fpg_sz * grp->num_pln; |
| 964 | geo->sec_size = grp->csecs; |
| 965 | geo->oob_size = grp->sos; |
| 966 | geo->sec_per_pg = grp->fpg_sz / grp->csecs; |
| 967 | geo->mccap = grp->mccap; |
| 968 | memcpy(&geo->ppaf, &id->ppaf, sizeof(struct nvm_addr_format)); |
| 969 | |
| 970 | geo->plane_mode = NVM_PLANE_SINGLE; |
| 971 | geo->max_rq_size = dev->ops->max_phys_sect * geo->sec_size; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 972 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 973 | if (grp->mpos & 0x020202) |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 974 | geo->plane_mode = NVM_PLANE_DOUBLE; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 975 | if (grp->mpos & 0x040404) |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 976 | geo->plane_mode = NVM_PLANE_QUAD; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 977 | |
Matias Bjørling | 7f7c5d0 | 2016-05-06 20:02:59 +0200 | [diff] [blame] | 978 | if (grp->mtype != 0) { |
| 979 | pr_err("nvm: memory type not supported\n"); |
| 980 | return -EINVAL; |
| 981 | } |
| 982 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 983 | /* calculated values */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 984 | geo->sec_per_pl = geo->sec_per_pg * geo->nr_planes; |
| 985 | geo->sec_per_blk = geo->sec_per_pl * geo->pgs_per_blk; |
| 986 | geo->sec_per_lun = geo->sec_per_blk * geo->blks_per_lun; |
| 987 | geo->nr_luns = geo->luns_per_chnl * geo->nr_chnls; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 988 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 989 | dev->total_secs = geo->nr_luns * geo->sec_per_lun; |
| 990 | dev->lun_map = kcalloc(BITS_TO_LONGS(geo->nr_luns), |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 991 | sizeof(unsigned long), GFP_KERNEL); |
| 992 | if (!dev->lun_map) |
| 993 | return -ENOMEM; |
Matias Bjørling | 7f7c5d0 | 2016-05-06 20:02:59 +0200 | [diff] [blame] | 994 | |
| 995 | switch (grp->fmtype) { |
| 996 | case NVM_ID_FMTYPE_SLC: |
| 997 | if (nvm_init_slc_tbl(dev, grp)) { |
| 998 | ret = -ENOMEM; |
| 999 | goto err_fmtype; |
| 1000 | } |
| 1001 | break; |
| 1002 | case NVM_ID_FMTYPE_MLC: |
| 1003 | if (nvm_init_mlc_tbl(dev, grp)) { |
| 1004 | ret = -ENOMEM; |
| 1005 | goto err_fmtype; |
| 1006 | } |
| 1007 | break; |
| 1008 | default: |
| 1009 | pr_err("nvm: flash type not supported\n"); |
| 1010 | ret = -EINVAL; |
| 1011 | goto err_fmtype; |
| 1012 | } |
| 1013 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1014 | INIT_LIST_HEAD(&dev->area_list); |
| 1015 | INIT_LIST_HEAD(&dev->targets); |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 1016 | mutex_init(&dev->mlock); |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 1017 | spin_lock_init(&dev->lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1018 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1019 | ret = nvm_register_map(dev); |
| 1020 | if (ret) |
| 1021 | goto err_fmtype; |
Matias Bjørling | ac81bfa9 | 2016-09-16 14:25:04 +0200 | [diff] [blame] | 1022 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1023 | blk_queue_logical_block_size(dev->q, geo->sec_size); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1024 | return 0; |
Matias Bjørling | 7f7c5d0 | 2016-05-06 20:02:59 +0200 | [diff] [blame] | 1025 | err_fmtype: |
| 1026 | kfree(dev->lun_map); |
| 1027 | return ret; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Javier González | 46b160c | 2017-04-15 20:55:46 +0200 | [diff] [blame] | 1030 | static void nvm_free(struct nvm_dev *dev) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1031 | { |
| 1032 | if (!dev) |
| 1033 | return; |
| 1034 | |
Simon A. F. Lund | 40267ef | 2016-09-16 14:25:08 +0200 | [diff] [blame] | 1035 | if (dev->dma_pool) |
| 1036 | dev->ops->destroy_dma_pool(dev->dma_pool); |
| 1037 | |
Javier González | 7a3de2b | 2017-04-15 20:55:39 +0200 | [diff] [blame] | 1038 | nvm_unregister_map(dev); |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 1039 | kfree(dev->lptbl); |
Matias Bjørling | 7f7c5d0 | 2016-05-06 20:02:59 +0200 | [diff] [blame] | 1040 | kfree(dev->lun_map); |
Simon A. F. Lund | 40267ef | 2016-09-16 14:25:08 +0200 | [diff] [blame] | 1041 | kfree(dev); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | static int nvm_init(struct nvm_dev *dev) |
| 1045 | { |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 1046 | struct nvm_geo *geo = &dev->geo; |
Wenwei Tao | 480fc0d | 2015-11-20 13:47:53 +0100 | [diff] [blame] | 1047 | int ret = -EINVAL; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1048 | |
Matias Bjørling | 16f26c3 | 2015-12-06 11:25:48 +0100 | [diff] [blame] | 1049 | if (dev->ops->identity(dev, &dev->identity)) { |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1050 | pr_err("nvm: device could not be identified\n"); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1051 | goto err; |
| 1052 | } |
| 1053 | |
Matias Bjørling | 19bd6fe | 2017-01-31 13:17:15 +0100 | [diff] [blame] | 1054 | pr_debug("nvm: ver:%x nvm_vendor:%x\n", |
| 1055 | dev->identity.ver_id, dev->identity.vmnt); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1056 | |
| 1057 | if (dev->identity.ver_id != 1) { |
| 1058 | pr_err("nvm: device not supported by kernel."); |
| 1059 | goto err; |
| 1060 | } |
| 1061 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1062 | ret = nvm_core_init(dev); |
| 1063 | if (ret) { |
| 1064 | pr_err("nvm: could not initialize core structures.\n"); |
| 1065 | goto err; |
| 1066 | } |
| 1067 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1068 | pr_info("nvm: registered %s [%u/%u/%u/%u/%u/%u]\n", |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 1069 | dev->name, geo->sec_per_pg, geo->nr_planes, |
| 1070 | geo->pgs_per_blk, geo->blks_per_lun, |
| 1071 | geo->nr_luns, geo->nr_chnls); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1072 | return 0; |
| 1073 | err: |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1074 | pr_err("nvm: failed to initialize nvm\n"); |
| 1075 | return ret; |
| 1076 | } |
| 1077 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 1078 | struct nvm_dev *nvm_alloc_dev(int node) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1079 | { |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 1080 | return kzalloc_node(sizeof(struct nvm_dev), GFP_KERNEL, node); |
| 1081 | } |
| 1082 | EXPORT_SYMBOL(nvm_alloc_dev); |
| 1083 | |
| 1084 | int nvm_register(struct nvm_dev *dev) |
| 1085 | { |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1086 | int ret; |
| 1087 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1088 | if (!dev->q || !dev->ops) |
| 1089 | return -EINVAL; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1090 | |
Wenwei Tao | d160147 | 2015-11-28 16:49:25 +0100 | [diff] [blame] | 1091 | if (dev->ops->max_phys_sect > 256) { |
| 1092 | pr_info("nvm: max sectors supported is 256.\n"); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1093 | return -EINVAL; |
Wenwei Tao | d160147 | 2015-11-28 16:49:25 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1096 | if (dev->ops->max_phys_sect > 1) { |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 1097 | dev->dma_pool = dev->ops->create_dma_pool(dev, "ppalist"); |
| 1098 | if (!dev->dma_pool) { |
| 1099 | pr_err("nvm: could not create dma pool\n"); |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1100 | return -ENOMEM; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1101 | } |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1104 | ret = nvm_init(dev); |
| 1105 | if (ret) |
| 1106 | goto err_init; |
Matias Bjørling | b769207 | 2016-01-12 07:49:38 +0100 | [diff] [blame] | 1107 | |
Matias Bjørling | 762796b | 2015-12-06 11:25:49 +0100 | [diff] [blame] | 1108 | /* register device with a supported media manager */ |
Matias Bjørling | edad2e6 | 2015-11-16 15:34:42 +0100 | [diff] [blame] | 1109 | down_write(&nvm_lock); |
| 1110 | list_add(&dev->devices, &nvm_devices); |
| 1111 | up_write(&nvm_lock); |
| 1112 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1113 | return 0; |
| 1114 | err_init: |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1115 | dev->ops->destroy_dma_pool(dev->dma_pool); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1116 | return ret; |
| 1117 | } |
| 1118 | EXPORT_SYMBOL(nvm_register); |
| 1119 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 1120 | void nvm_unregister(struct nvm_dev *dev) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1121 | { |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1122 | struct nvm_target *t, *tmp; |
| 1123 | |
| 1124 | mutex_lock(&dev->mlock); |
| 1125 | list_for_each_entry_safe(t, tmp, &dev->targets, list) { |
| 1126 | if (t->dev->parent != dev) |
| 1127 | continue; |
| 1128 | __nvm_remove_target(t); |
| 1129 | } |
| 1130 | mutex_unlock(&dev->mlock); |
| 1131 | |
Wenwei Tao | d0a712c | 2015-11-28 16:49:28 +0100 | [diff] [blame] | 1132 | down_write(&nvm_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1133 | list_del(&dev->devices); |
| 1134 | up_write(&nvm_lock); |
Matias Bjørling | c1480ad | 2015-11-16 15:34:43 +0100 | [diff] [blame] | 1135 | |
Matias Bjørling | 3dc87dd | 2016-11-28 22:38:53 +0100 | [diff] [blame] | 1136 | nvm_free(dev); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1137 | } |
| 1138 | EXPORT_SYMBOL(nvm_unregister); |
| 1139 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1140 | static int __nvm_configure_create(struct nvm_ioctl_create *create) |
| 1141 | { |
| 1142 | struct nvm_dev *dev; |
| 1143 | struct nvm_ioctl_create_simple *s; |
| 1144 | |
Wenwei Tao | d0a712c | 2015-11-28 16:49:28 +0100 | [diff] [blame] | 1145 | down_write(&nvm_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1146 | dev = nvm_find_nvm_dev(create->dev); |
Wenwei Tao | d0a712c | 2015-11-28 16:49:28 +0100 | [diff] [blame] | 1147 | up_write(&nvm_lock); |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 1148 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1149 | if (!dev) { |
| 1150 | pr_err("nvm: device not found\n"); |
| 1151 | return -EINVAL; |
| 1152 | } |
| 1153 | |
| 1154 | if (create->conf.type != NVM_CONFIG_TYPE_SIMPLE) { |
| 1155 | pr_err("nvm: config type not valid\n"); |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | s = &create->conf.s; |
| 1159 | |
Matias Bjørling | 6732c74 | 2017-02-15 16:25:33 +0100 | [diff] [blame] | 1160 | if (s->lun_begin == -1 && s->lun_end == -1) { |
| 1161 | s->lun_begin = 0; |
| 1162 | s->lun_end = dev->geo.nr_luns - 1; |
| 1163 | } |
| 1164 | |
Matias Bjørling | 0e5ffd1 | 2017-02-15 16:25:32 +0100 | [diff] [blame] | 1165 | if (s->lun_begin > s->lun_end || s->lun_end >= dev->geo.nr_luns) { |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1166 | pr_err("nvm: lun out of bound (%u:%u > %u)\n", |
Matias Bjørling | 0e5ffd1 | 2017-02-15 16:25:32 +0100 | [diff] [blame] | 1167 | s->lun_begin, s->lun_end, dev->geo.nr_luns - 1); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1168 | return -EINVAL; |
| 1169 | } |
| 1170 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1171 | return nvm_create_tgt(dev, create); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1174 | static long nvm_ioctl_info(struct file *file, void __user *arg) |
| 1175 | { |
| 1176 | struct nvm_ioctl_info *info; |
| 1177 | struct nvm_tgt_type *tt; |
| 1178 | int tgt_iter = 0; |
| 1179 | |
| 1180 | if (!capable(CAP_SYS_ADMIN)) |
| 1181 | return -EPERM; |
| 1182 | |
| 1183 | info = memdup_user(arg, sizeof(struct nvm_ioctl_info)); |
| 1184 | if (IS_ERR(info)) |
| 1185 | return -EFAULT; |
| 1186 | |
| 1187 | info->version[0] = NVM_VERSION_MAJOR; |
| 1188 | info->version[1] = NVM_VERSION_MINOR; |
| 1189 | info->version[2] = NVM_VERSION_PATCH; |
| 1190 | |
Rakesh Pandit | 88d31ea | 2017-10-13 14:45:52 +0200 | [diff] [blame] | 1191 | down_write(&nvm_tgtt_lock); |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 1192 | list_for_each_entry(tt, &nvm_tgt_types, list) { |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1193 | struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; |
| 1194 | |
| 1195 | tgt->version[0] = tt->version[0]; |
| 1196 | tgt->version[1] = tt->version[1]; |
| 1197 | tgt->version[2] = tt->version[2]; |
| 1198 | strncpy(tgt->tgtname, tt->name, NVM_TTYPE_NAME_MAX); |
| 1199 | |
| 1200 | tgt_iter++; |
| 1201 | } |
| 1202 | |
| 1203 | info->tgtsize = tgt_iter; |
Rakesh Pandit | 88d31ea | 2017-10-13 14:45:52 +0200 | [diff] [blame] | 1204 | up_write(&nvm_tgtt_lock); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1205 | |
Sudip Mukherjee | 76e2508 | 2015-11-28 16:49:24 +0100 | [diff] [blame] | 1206 | if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) { |
| 1207 | kfree(info); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1208 | return -EFAULT; |
Sudip Mukherjee | 76e2508 | 2015-11-28 16:49:24 +0100 | [diff] [blame] | 1209 | } |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1210 | |
| 1211 | kfree(info); |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | static long nvm_ioctl_get_devices(struct file *file, void __user *arg) |
| 1216 | { |
| 1217 | struct nvm_ioctl_get_devices *devices; |
| 1218 | struct nvm_dev *dev; |
| 1219 | int i = 0; |
| 1220 | |
| 1221 | if (!capable(CAP_SYS_ADMIN)) |
| 1222 | return -EPERM; |
| 1223 | |
| 1224 | devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL); |
| 1225 | if (!devices) |
| 1226 | return -ENOMEM; |
| 1227 | |
| 1228 | down_write(&nvm_lock); |
| 1229 | list_for_each_entry(dev, &nvm_devices, devices) { |
| 1230 | struct nvm_ioctl_device_info *info = &devices->info[i]; |
| 1231 | |
Javier González | 6eb0824 | 2017-04-15 20:55:49 +0200 | [diff] [blame] | 1232 | strlcpy(info->devname, dev->name, sizeof(info->devname)); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1233 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1234 | /* kept for compatibility */ |
| 1235 | info->bmversion[0] = 1; |
| 1236 | info->bmversion[1] = 0; |
| 1237 | info->bmversion[2] = 0; |
Javier González | 6eb0824 | 2017-04-15 20:55:49 +0200 | [diff] [blame] | 1238 | strlcpy(info->bmname, "gennvm", sizeof(info->bmname)); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1239 | i++; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1240 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1241 | if (i > 31) { |
| 1242 | pr_err("nvm: max 31 devices can be reported.\n"); |
| 1243 | break; |
| 1244 | } |
| 1245 | } |
| 1246 | up_write(&nvm_lock); |
| 1247 | |
| 1248 | devices->nr_devices = i; |
| 1249 | |
Sudip Mukherjee | 76e2508 | 2015-11-28 16:49:24 +0100 | [diff] [blame] | 1250 | if (copy_to_user(arg, devices, |
| 1251 | sizeof(struct nvm_ioctl_get_devices))) { |
| 1252 | kfree(devices); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1253 | return -EFAULT; |
Sudip Mukherjee | 76e2508 | 2015-11-28 16:49:24 +0100 | [diff] [blame] | 1254 | } |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1255 | |
| 1256 | kfree(devices); |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | static long nvm_ioctl_dev_create(struct file *file, void __user *arg) |
| 1261 | { |
| 1262 | struct nvm_ioctl_create create; |
| 1263 | |
| 1264 | if (!capable(CAP_SYS_ADMIN)) |
| 1265 | return -EPERM; |
| 1266 | |
| 1267 | if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create))) |
| 1268 | return -EFAULT; |
| 1269 | |
| 1270 | create.dev[DISK_NAME_LEN - 1] = '\0'; |
| 1271 | create.tgttype[NVM_TTYPE_NAME_MAX - 1] = '\0'; |
| 1272 | create.tgtname[DISK_NAME_LEN - 1] = '\0'; |
| 1273 | |
| 1274 | if (create.flags != 0) { |
Javier González | 4af3f75 | 2017-04-15 20:55:45 +0200 | [diff] [blame] | 1275 | __u32 flags = create.flags; |
| 1276 | |
| 1277 | /* Check for valid flags */ |
| 1278 | if (flags & NVM_TARGET_FACTORY) |
| 1279 | flags &= ~NVM_TARGET_FACTORY; |
| 1280 | |
| 1281 | if (flags) { |
| 1282 | pr_err("nvm: flag not supported\n"); |
| 1283 | return -EINVAL; |
| 1284 | } |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | return __nvm_configure_create(&create); |
| 1288 | } |
| 1289 | |
| 1290 | static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) |
| 1291 | { |
| 1292 | struct nvm_ioctl_remove remove; |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 1293 | struct nvm_dev *dev; |
| 1294 | int ret = 0; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1295 | |
| 1296 | if (!capable(CAP_SYS_ADMIN)) |
| 1297 | return -EPERM; |
| 1298 | |
| 1299 | if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) |
| 1300 | return -EFAULT; |
| 1301 | |
| 1302 | remove.tgtname[DISK_NAME_LEN - 1] = '\0'; |
| 1303 | |
| 1304 | if (remove.flags != 0) { |
| 1305 | pr_err("nvm: no flags supported\n"); |
| 1306 | return -EINVAL; |
| 1307 | } |
| 1308 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 1309 | list_for_each_entry(dev, &nvm_devices, devices) { |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1310 | ret = nvm_remove_tgt(dev, &remove); |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 1311 | if (!ret) |
| 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | return ret; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1318 | /* kept for compatibility reasons */ |
Matias Bjørling | 5569615 | 2016-01-12 07:49:37 +0100 | [diff] [blame] | 1319 | static long nvm_ioctl_dev_init(struct file *file, void __user *arg) |
| 1320 | { |
| 1321 | struct nvm_ioctl_dev_init init; |
| 1322 | |
| 1323 | if (!capable(CAP_SYS_ADMIN)) |
| 1324 | return -EPERM; |
| 1325 | |
| 1326 | if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) |
| 1327 | return -EFAULT; |
| 1328 | |
| 1329 | if (init.flags != 0) { |
| 1330 | pr_err("nvm: no flags supported\n"); |
| 1331 | return -EINVAL; |
| 1332 | } |
| 1333 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1334 | return 0; |
Matias Bjørling | 5569615 | 2016-01-12 07:49:37 +0100 | [diff] [blame] | 1335 | } |
| 1336 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 1337 | /* Kept for compatibility reasons */ |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 1338 | static long nvm_ioctl_dev_factory(struct file *file, void __user *arg) |
| 1339 | { |
| 1340 | struct nvm_ioctl_dev_factory fact; |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 1341 | |
| 1342 | if (!capable(CAP_SYS_ADMIN)) |
| 1343 | return -EPERM; |
| 1344 | |
| 1345 | if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory))) |
| 1346 | return -EFAULT; |
| 1347 | |
| 1348 | fact.dev[DISK_NAME_LEN - 1] = '\0'; |
| 1349 | |
| 1350 | if (fact.flags & ~(NVM_FACTORY_NR_BITS - 1)) |
| 1351 | return -EINVAL; |
| 1352 | |
Matias Bjørling | bf64318 | 2016-02-04 15:13:27 +0100 | [diff] [blame] | 1353 | return 0; |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1356 | static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) |
| 1357 | { |
| 1358 | void __user *argp = (void __user *)arg; |
| 1359 | |
| 1360 | switch (cmd) { |
| 1361 | case NVM_INFO: |
| 1362 | return nvm_ioctl_info(file, argp); |
| 1363 | case NVM_GET_DEVICES: |
| 1364 | return nvm_ioctl_get_devices(file, argp); |
| 1365 | case NVM_DEV_CREATE: |
| 1366 | return nvm_ioctl_dev_create(file, argp); |
| 1367 | case NVM_DEV_REMOVE: |
| 1368 | return nvm_ioctl_dev_remove(file, argp); |
Matias Bjørling | 5569615 | 2016-01-12 07:49:37 +0100 | [diff] [blame] | 1369 | case NVM_DEV_INIT: |
| 1370 | return nvm_ioctl_dev_init(file, argp); |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 1371 | case NVM_DEV_FACTORY: |
| 1372 | return nvm_ioctl_dev_factory(file, argp); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1373 | } |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
| 1377 | static const struct file_operations _ctl_fops = { |
| 1378 | .open = nonseekable_open, |
| 1379 | .unlocked_ioctl = nvm_ctl_ioctl, |
| 1380 | .owner = THIS_MODULE, |
| 1381 | .llseek = noop_llseek, |
| 1382 | }; |
| 1383 | |
| 1384 | static struct miscdevice _nvm_misc = { |
| 1385 | .minor = MISC_DYNAMIC_MINOR, |
| 1386 | .name = "lightnvm", |
| 1387 | .nodename = "lightnvm/control", |
| 1388 | .fops = &_ctl_fops, |
| 1389 | }; |
Paul Gortmaker | 389b2a1 | 2016-10-29 16:38:41 -0400 | [diff] [blame] | 1390 | builtin_misc_device(_nvm_misc); |