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