blob: fc0e7c924967402c7c170683f13be0444b56ea13 [file] [log] [blame]
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01001#ifndef NVM_H
2#define NVM_H
3
4enum {
5 NVM_IO_OK = 0,
6 NVM_IO_REQUEUE = 1,
7 NVM_IO_DONE = 2,
8 NVM_IO_ERR = 3,
9
10 NVM_IOTYPE_NONE = 0,
11 NVM_IOTYPE_GC = 1,
12};
13
14#ifdef CONFIG_NVM
15
16#include <linux/blkdev.h>
17#include <linux/types.h>
18#include <linux/file.h>
19#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010020#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010021
22enum {
23 /* HW Responsibilities */
24 NVM_RSP_L2P = 1 << 0,
25 NVM_RSP_ECC = 1 << 1,
26
27 /* Physical Adressing Mode */
28 NVM_ADDRMODE_LINEAR = 0,
29 NVM_ADDRMODE_CHANNEL = 1,
30
31 /* Plane programming mode for LUN */
32 NVM_PLANE_SINGLE = 0,
33 NVM_PLANE_DOUBLE = 1,
34 NVM_PLANE_QUAD = 2,
35
36 /* Status codes */
37 NVM_RSP_SUCCESS = 0x0,
38 NVM_RSP_NOT_CHANGEABLE = 0x1,
39 NVM_RSP_ERR_FAILWRITE = 0x40ff,
40 NVM_RSP_ERR_EMPTYPAGE = 0x42ff,
41
42 /* Device opcodes */
43 NVM_OP_HBREAD = 0x02,
44 NVM_OP_HBWRITE = 0x81,
45 NVM_OP_PWRITE = 0x91,
46 NVM_OP_PREAD = 0x92,
47 NVM_OP_ERASE = 0x90,
48
49 /* PPA Command Flags */
50 NVM_IO_SNGL_ACCESS = 0x0,
51 NVM_IO_DUAL_ACCESS = 0x1,
52 NVM_IO_QUAD_ACCESS = 0x2,
53
Matias Bjørling57b4bd02015-12-06 11:25:47 +010054 /* NAND Access Modes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010055 NVM_IO_SUSPEND = 0x80,
56 NVM_IO_SLC_MODE = 0x100,
57 NVM_IO_SCRAMBLE_DISABLE = 0x200,
Matias Bjørling57b4bd02015-12-06 11:25:47 +010058
59 /* Block Types */
60 NVM_BLK_T_FREE = 0x0,
61 NVM_BLK_T_BAD = 0x1,
Matias Bjørlingb5d4acd2016-01-12 07:49:32 +010062 NVM_BLK_T_GRWN_BAD = 0x2,
63 NVM_BLK_T_DEV = 0x4,
64 NVM_BLK_T_HOST = 0x8,
Matias Bjørlingf9a99952016-01-12 07:49:34 +010065
66 /* Memory capabilities */
67 NVM_ID_CAP_SLC = 0x1,
68 NVM_ID_CAP_CMD_SUSPEND = 0x2,
69 NVM_ID_CAP_SCRAMBLE = 0x4,
70 NVM_ID_CAP_ENCRYPT = 0x8,
Matias Bjørlingca5927e2016-01-12 07:49:35 +010071
72 /* Memory types */
73 NVM_ID_FMTYPE_SLC = 0,
74 NVM_ID_FMTYPE_MLC = 1,
75};
76
77struct nvm_id_lp_mlc {
78 u16 num_pairs;
79 u8 pairs[886];
80};
81
82struct nvm_id_lp_tbl {
83 __u8 id[8];
84 struct nvm_id_lp_mlc mlc;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010085};
86
87struct nvm_id_group {
88 u8 mtype;
89 u8 fmtype;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010090 u8 num_ch;
91 u8 num_lun;
92 u8 num_pln;
93 u16 num_blk;
94 u16 num_pg;
95 u16 fpg_sz;
96 u16 csecs;
97 u16 sos;
98 u32 trdt;
99 u32 trdm;
100 u32 tprt;
101 u32 tprm;
102 u32 tbet;
103 u32 tbem;
104 u32 mpos;
Matias Bjørling12be5ed2015-11-16 15:34:39 +0100105 u32 mccap;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100106 u16 cpar;
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100107
108 struct nvm_id_lp_tbl lptbl;
Matias Bjørling73387e72015-11-16 15:34:40 +0100109};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100110
111struct nvm_addr_format {
112 u8 ch_offset;
113 u8 ch_len;
114 u8 lun_offset;
115 u8 lun_len;
116 u8 pln_offset;
117 u8 pln_len;
118 u8 blk_offset;
119 u8 blk_len;
120 u8 pg_offset;
121 u8 pg_len;
122 u8 sect_offset;
123 u8 sect_len;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100124};
125
126struct nvm_id {
127 u8 ver_id;
128 u8 vmnt;
129 u8 cgrps;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100130 u32 cap;
131 u32 dom;
132 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100133 struct nvm_id_group groups[4];
134} __packed;
135
136struct nvm_target {
137 struct list_head list;
138 struct nvm_tgt_type *type;
139 struct gendisk *disk;
140};
141
142struct nvm_tgt_instance {
143 struct nvm_tgt_type *tt;
144};
145
146#define ADDR_EMPTY (~0ULL)
147
148#define NVM_VERSION_MAJOR 1
149#define NVM_VERSION_MINOR 0
150#define NVM_VERSION_PATCH 0
151
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100152#define NVM_BLK_BITS (16)
Matias Bjørling7386af22015-11-16 15:34:44 +0100153#define NVM_PG_BITS (16)
154#define NVM_SEC_BITS (8)
155#define NVM_PL_BITS (8)
156#define NVM_LUN_BITS (8)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100157#define NVM_CH_BITS (8)
158
159struct ppa_addr {
Matias Bjørling7386af22015-11-16 15:34:44 +0100160 /* Generic structure for all addresses */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100161 union {
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100162 struct {
Matias Bjørling7386af22015-11-16 15:34:44 +0100163 u64 blk : NVM_BLK_BITS;
164 u64 pg : NVM_PG_BITS;
Matias Bjørlingb7ceb7d2015-11-02 17:12:27 +0100165 u64 sec : NVM_SEC_BITS;
166 u64 pl : NVM_PL_BITS;
Matias Bjørlingb7ceb7d2015-11-02 17:12:27 +0100167 u64 lun : NVM_LUN_BITS;
168 u64 ch : NVM_CH_BITS;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100169 } g;
170
Matias Bjørlingb7ceb7d2015-11-02 17:12:27 +0100171 u64 ppa;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100172 };
Matias Bjørling7386af22015-11-16 15:34:44 +0100173};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100174
Matias Bjørling912761622016-01-12 07:49:21 +0100175struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100176typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100177
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100178struct nvm_rq {
179 struct nvm_tgt_instance *ins;
180 struct nvm_dev *dev;
181
182 struct bio *bio;
183
184 union {
185 struct ppa_addr ppa_addr;
186 dma_addr_t dma_ppa_list;
187 };
188
189 struct ppa_addr *ppa_list;
190
191 void *metadata;
192 dma_addr_t dma_metadata;
193
Matias Bjørling912761622016-01-12 07:49:21 +0100194 struct completion *wait;
195 nvm_end_io_fn *end_io;
196
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100197 uint8_t opcode;
198 uint16_t nr_pages;
199 uint16_t flags;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100200
201 int error;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100202};
203
204static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu)
205{
206 return pdu - sizeof(struct nvm_rq);
207}
208
209static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
210{
211 return rqdata + 1;
212}
213
214struct nvm_block;
215
216typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *);
Matias Bjørling11450462015-11-16 15:34:37 +0100217typedef int (nvm_bb_update_fn)(struct ppa_addr, int, u8 *, void *);
Matias Bjørling16f26c32015-12-06 11:25:48 +0100218typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *);
219typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100220 nvm_l2p_update_fn *, void *);
Matias Bjørling08236c62015-11-28 16:49:27 +0100221typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, int,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100222 nvm_bb_update_fn *, void *);
Matias Bjørling16f26c32015-12-06 11:25:48 +0100223typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct nvm_rq *, int);
224typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
225typedef int (nvm_erase_blk_fn)(struct nvm_dev *, struct nvm_rq *);
226typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100227typedef void (nvm_destroy_dma_pool_fn)(void *);
Matias Bjørling16f26c32015-12-06 11:25:48 +0100228typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100229 dma_addr_t *);
230typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
231
232struct nvm_dev_ops {
233 nvm_id_fn *identity;
234 nvm_get_l2p_tbl_fn *get_l2p_tbl;
235 nvm_op_bb_tbl_fn *get_bb_tbl;
Matias Bjørling11450462015-11-16 15:34:37 +0100236 nvm_op_set_bb_fn *set_bb_tbl;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100237
238 nvm_submit_io_fn *submit_io;
239 nvm_erase_blk_fn *erase_block;
240
241 nvm_create_dma_pool_fn *create_dma_pool;
242 nvm_destroy_dma_pool_fn *destroy_dma_pool;
243 nvm_dev_dma_alloc_fn *dev_dma_alloc;
244 nvm_dev_dma_free_fn *dev_dma_free;
245
Matias Bjørlingaedf17f2015-11-16 15:34:36 +0100246 unsigned int max_phys_sect;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100247};
248
249struct nvm_lun {
250 int id;
251
252 int lun_id;
253 int chnl_id;
254
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100255 /* It is up to the target to mark blocks as closed. If the target does
256 * not do it, all blocks are marked as open, and nr_open_blocks
257 * represents the number of blocks in use
258 */
259 unsigned int nr_open_blocks; /* Number of used, writable blocks */
260 unsigned int nr_closed_blocks; /* Number of used, read-only blocks */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100261 unsigned int nr_free_blocks; /* Number of unused blocks */
Javier Gonzalez0b597332015-11-20 13:47:56 +0100262 unsigned int nr_bad_blocks; /* Number of bad blocks */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100263
264 spinlock_t lock;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100265
266 struct nvm_block *blocks;
267};
268
269enum {
270 NVM_BLK_ST_FREE = 0x1, /* Free block */
271 NVM_BLK_ST_OPEN = 0x2, /* Open block - read-write */
272 NVM_BLK_ST_CLOSED = 0x4, /* Closed block - read-only */
273 NVM_BLK_ST_BAD = 0x8, /* Bad block */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100274};
275
276struct nvm_block {
277 struct list_head list;
278 struct nvm_lun *lun;
279 unsigned long id;
280
281 void *priv;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100282 int state;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100283};
284
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100285/* system block cpu representation */
286struct nvm_sb_info {
287 unsigned long seqnr;
288 unsigned long erase_cnt;
289 unsigned int version;
290 char mmtype[NVM_MMTYPE_LEN];
291 struct ppa_addr fs_ppa;
292};
293
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100294struct nvm_dev {
295 struct nvm_dev_ops *ops;
296
297 struct list_head devices;
298 struct list_head online_targets;
299
300 /* Media manager */
301 struct nvmm_type *mt;
302 void *mp;
303
Matias Bjørlingb7692072016-01-12 07:49:38 +0100304 /* System blocks */
305 struct nvm_sb_info sb;
306
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100307 /* Device information */
308 int nr_chnls;
309 int nr_planes;
310 int luns_per_chnl;
311 int sec_per_pg; /* only sectors for a single page */
312 int pgs_per_blk;
313 int blks_per_lun;
314 int sec_size;
315 int oob_size;
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100316 int mccap;
Matias Bjørling7386af22015-11-16 15:34:44 +0100317 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100318
319 /* Calculated/Cached values. These do not reflect the actual usable
320 * blocks at run-time.
321 */
322 int max_rq_size;
323 int plane_mode; /* drive device in single, double or quad mode */
324
325 int sec_per_pl; /* all sectors across planes */
326 int sec_per_blk;
327 int sec_per_lun;
328
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100329 /* lower page table */
330 int lps_per_blk;
331 int *lptbl;
332
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100333 unsigned long total_pages;
334 unsigned long total_blocks;
335 int nr_luns;
336 unsigned max_pages_per_blk;
337
338 void *ppalist_pool;
339
340 struct nvm_id identity;
341
342 /* Backend device */
343 struct request_queue *q;
344 char name[DISK_NAME_LEN];
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100345
346 struct mutex mlock;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100347};
348
Matias Bjørling7386af22015-11-16 15:34:44 +0100349static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev,
350 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100351{
352 struct ppa_addr l;
353
Matias Bjørling7386af22015-11-16 15:34:44 +0100354 l.ppa = ((u64)r.g.blk) << dev->ppaf.blk_offset;
355 l.ppa |= ((u64)r.g.pg) << dev->ppaf.pg_offset;
356 l.ppa |= ((u64)r.g.sec) << dev->ppaf.sect_offset;
357 l.ppa |= ((u64)r.g.pl) << dev->ppaf.pln_offset;
358 l.ppa |= ((u64)r.g.lun) << dev->ppaf.lun_offset;
359 l.ppa |= ((u64)r.g.ch) << dev->ppaf.ch_offset;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100360
361 return l;
362}
363
Matias Bjørling7386af22015-11-16 15:34:44 +0100364static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,
365 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100366{
367 struct ppa_addr l;
368
Matias Bjørling7386af22015-11-16 15:34:44 +0100369 /*
370 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
371 */
372 l.g.blk = (r.ppa >> dev->ppaf.blk_offset) &
373 (((1 << dev->ppaf.blk_len) - 1));
374 l.g.pg |= (r.ppa >> dev->ppaf.pg_offset) &
375 (((1 << dev->ppaf.pg_len) - 1));
376 l.g.sec |= (r.ppa >> dev->ppaf.sect_offset) &
377 (((1 << dev->ppaf.sect_len) - 1));
378 l.g.pl |= (r.ppa >> dev->ppaf.pln_offset) &
379 (((1 << dev->ppaf.pln_len) - 1));
380 l.g.lun |= (r.ppa >> dev->ppaf.lun_offset) &
381 (((1 << dev->ppaf.lun_len) - 1));
382 l.g.ch |= (r.ppa >> dev->ppaf.ch_offset) &
383 (((1 << dev->ppaf.ch_len) - 1));
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100384
385 return l;
386}
387
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100388static inline int ppa_empty(struct ppa_addr ppa_addr)
389{
390 return (ppa_addr.ppa == ADDR_EMPTY);
391}
392
393static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
394{
395 ppa_addr->ppa = ADDR_EMPTY;
396}
397
398static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev,
399 struct nvm_block *blk)
400{
401 struct ppa_addr ppa;
402 struct nvm_lun *lun = blk->lun;
403
404 ppa.ppa = 0;
405 ppa.g.blk = blk->id % dev->blks_per_lun;
406 ppa.g.lun = lun->lun_id;
407 ppa.g.ch = lun->chnl_id;
408
409 return ppa;
410}
411
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100412static inline int ppa_to_slc(struct nvm_dev *dev, int slc_pg)
413{
414 return dev->lptbl[slc_pg];
415}
416
Jens Axboedece1632015-11-05 10:41:16 -0700417typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100418typedef sector_t (nvm_tgt_capacity_fn)(void *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100419typedef void *(nvm_tgt_init_fn)(struct nvm_dev *, struct gendisk *, int, int);
420typedef void (nvm_tgt_exit_fn)(void *);
421
422struct nvm_tgt_type {
423 const char *name;
424 unsigned int version[3];
425
426 /* target entry points */
427 nvm_tgt_make_rq_fn *make_rq;
428 nvm_tgt_capacity_fn *capacity;
Matias Bjørling912761622016-01-12 07:49:21 +0100429 nvm_end_io_fn *end_io;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100430
431 /* module-specific init/teardown */
432 nvm_tgt_init_fn *init;
433 nvm_tgt_exit_fn *exit;
434
435 /* For internal use */
436 struct list_head list;
437};
438
439extern int nvm_register_target(struct nvm_tgt_type *);
440extern void nvm_unregister_target(struct nvm_tgt_type *);
441
442extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
443extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
444
445typedef int (nvmm_register_fn)(struct nvm_dev *);
446typedef void (nvmm_unregister_fn)(struct nvm_dev *);
447typedef struct nvm_block *(nvmm_get_blk_fn)(struct nvm_dev *,
448 struct nvm_lun *, unsigned long);
449typedef void (nvmm_put_blk_fn)(struct nvm_dev *, struct nvm_block *);
450typedef int (nvmm_open_blk_fn)(struct nvm_dev *, struct nvm_block *);
451typedef int (nvmm_close_blk_fn)(struct nvm_dev *, struct nvm_block *);
452typedef void (nvmm_flush_blk_fn)(struct nvm_dev *, struct nvm_block *);
453typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100454typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *,
455 unsigned long);
456typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
Javier Gonzalez2fde0e42015-11-20 13:47:57 +0100457typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100458
459struct nvmm_type {
460 const char *name;
461 unsigned int version[3];
462
463 nvmm_register_fn *register_mgr;
464 nvmm_unregister_fn *unregister_mgr;
465
466 /* Block administration callbacks */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100467 nvmm_get_blk_fn *get_blk_unlocked;
468 nvmm_put_blk_fn *put_blk_unlocked;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100469 nvmm_get_blk_fn *get_blk;
470 nvmm_put_blk_fn *put_blk;
471 nvmm_open_blk_fn *open_blk;
472 nvmm_close_blk_fn *close_blk;
473 nvmm_flush_blk_fn *flush_blk;
474
475 nvmm_submit_io_fn *submit_io;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100476 nvmm_erase_blk_fn *erase_blk;
477
478 /* Configuration management */
479 nvmm_get_lun_fn *get_lun;
480
481 /* Statistics */
Javier Gonzalez2fde0e42015-11-20 13:47:57 +0100482 nvmm_lun_info_print_fn *lun_info_print;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100483 struct list_head list;
484};
485
486extern int nvm_register_mgr(struct nvmm_type *);
487extern void nvm_unregister_mgr(struct nvmm_type *);
488
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100489extern struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *,
490 struct nvm_lun *, unsigned long);
491extern void nvm_put_blk_unlocked(struct nvm_dev *, struct nvm_block *);
492
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100493extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *,
494 unsigned long);
495extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *);
496
497extern int nvm_register(struct request_queue *, char *,
498 struct nvm_dev_ops *);
499extern void nvm_unregister(char *);
500
501extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling069368e2016-01-12 07:49:19 +0100502extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *);
503extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingabd805e2016-01-12 07:49:20 +0100504extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *,
505 struct ppa_addr *, int);
506extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling81e681d2016-01-12 07:49:28 +0100507extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100508extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *);
Matias Bjørling912761622016-01-12 07:49:21 +0100509extern void nvm_end_io(struct nvm_rq *, int);
Matias Bjørling09719b62016-01-12 07:49:30 +0100510extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int,
511 void *, int);
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100512
513/* sysblk.c */
514#define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */
515
516/* system block on disk representation */
517struct nvm_system_block {
518 __be32 magic; /* magic signature */
519 __be32 seqnr; /* sequence number */
520 __be32 erase_cnt; /* erase count */
521 __be16 version; /* version number */
522 u8 mmtype[NVM_MMTYPE_LEN]; /* media manager name */
523 __be64 fs_ppa; /* PPA for media manager
524 * superblock */
525};
526
527extern int nvm_get_sysblock(struct nvm_dev *, struct nvm_sb_info *);
528extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *);
529extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *);
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100530
531extern int nvm_dev_factory(struct nvm_dev *, int flags);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100532#else /* CONFIG_NVM */
533struct nvm_dev_ops;
534
535static inline int nvm_register(struct request_queue *q, char *disk_name,
536 struct nvm_dev_ops *ops)
537{
538 return -EINVAL;
539}
540static inline void nvm_unregister(char *disk_name) {}
541#endif /* CONFIG_NVM */
542#endif /* LIGHTNVM.H */