blob: ef2c7d2e76c4829c36ff1cc2a3bb974bf405cd5a [file] [log] [blame]
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01001#ifndef NVM_H
2#define NVM_H
3
Jens Axboea7fd9a42016-01-13 13:04:11 -07004#include <linux/types.h>
5
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01006enum {
7 NVM_IO_OK = 0,
8 NVM_IO_REQUEUE = 1,
9 NVM_IO_DONE = 2,
10 NVM_IO_ERR = 3,
11
12 NVM_IOTYPE_NONE = 0,
13 NVM_IOTYPE_GC = 1,
14};
15
Jens Axboea7fd9a42016-01-13 13:04:11 -070016#define NVM_BLK_BITS (16)
17#define NVM_PG_BITS (16)
18#define NVM_SEC_BITS (8)
19#define NVM_PL_BITS (8)
20#define NVM_LUN_BITS (8)
Matias Bjørlingdf414b32016-05-06 20:03:19 +020021#define NVM_CH_BITS (7)
Jens Axboea7fd9a42016-01-13 13:04:11 -070022
23struct ppa_addr {
24 /* Generic structure for all addresses */
25 union {
26 struct {
27 u64 blk : NVM_BLK_BITS;
28 u64 pg : NVM_PG_BITS;
29 u64 sec : NVM_SEC_BITS;
30 u64 pl : NVM_PL_BITS;
31 u64 lun : NVM_LUN_BITS;
32 u64 ch : NVM_CH_BITS;
Matias Bjørlingdf414b32016-05-06 20:03:19 +020033 u64 reserved : 1;
Jens Axboea7fd9a42016-01-13 13:04:11 -070034 } g;
35
Matias Bjørlingdf414b32016-05-06 20:03:19 +020036 struct {
37 u64 line : 63;
38 u64 is_cached : 1;
39 } c;
40
Jens Axboea7fd9a42016-01-13 13:04:11 -070041 u64 ppa;
42 };
43};
44
45struct nvm_rq;
46struct nvm_id;
47struct nvm_dev;
48
49typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070050typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *);
51typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32,
52 nvm_l2p_update_fn *, void *);
Matias Bjørlinge11903f2016-05-06 20:03:05 +020053typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørling00ee6cc2016-05-06 20:03:09 +020054typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
Jens Axboea7fd9a42016-01-13 13:04:11 -070055typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
56typedef int (nvm_erase_blk_fn)(struct nvm_dev *, struct nvm_rq *);
57typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
58typedef void (nvm_destroy_dma_pool_fn)(void *);
59typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
60 dma_addr_t *);
61typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
62
63struct nvm_dev_ops {
64 nvm_id_fn *identity;
65 nvm_get_l2p_tbl_fn *get_l2p_tbl;
66 nvm_op_bb_tbl_fn *get_bb_tbl;
67 nvm_op_set_bb_fn *set_bb_tbl;
68
69 nvm_submit_io_fn *submit_io;
70 nvm_erase_blk_fn *erase_block;
71
72 nvm_create_dma_pool_fn *create_dma_pool;
73 nvm_destroy_dma_pool_fn *destroy_dma_pool;
74 nvm_dev_dma_alloc_fn *dev_dma_alloc;
75 nvm_dev_dma_free_fn *dev_dma_free;
76
77 unsigned int max_phys_sect;
78};
79
80
81
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010082#ifdef CONFIG_NVM
83
84#include <linux/blkdev.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010085#include <linux/file.h>
86#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010087#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010088
89enum {
90 /* HW Responsibilities */
91 NVM_RSP_L2P = 1 << 0,
92 NVM_RSP_ECC = 1 << 1,
93
94 /* Physical Adressing Mode */
95 NVM_ADDRMODE_LINEAR = 0,
96 NVM_ADDRMODE_CHANNEL = 1,
97
98 /* Plane programming mode for LUN */
Matias Bjørlingd5bdec82016-02-19 13:56:58 +010099 NVM_PLANE_SINGLE = 1,
100 NVM_PLANE_DOUBLE = 2,
101 NVM_PLANE_QUAD = 4,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100102
103 /* Status codes */
104 NVM_RSP_SUCCESS = 0x0,
105 NVM_RSP_NOT_CHANGEABLE = 0x1,
106 NVM_RSP_ERR_FAILWRITE = 0x40ff,
107 NVM_RSP_ERR_EMPTYPAGE = 0x42ff,
108
109 /* Device opcodes */
110 NVM_OP_HBREAD = 0x02,
111 NVM_OP_HBWRITE = 0x81,
112 NVM_OP_PWRITE = 0x91,
113 NVM_OP_PREAD = 0x92,
114 NVM_OP_ERASE = 0x90,
115
116 /* PPA Command Flags */
117 NVM_IO_SNGL_ACCESS = 0x0,
118 NVM_IO_DUAL_ACCESS = 0x1,
119 NVM_IO_QUAD_ACCESS = 0x2,
120
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100121 /* NAND Access Modes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100122 NVM_IO_SUSPEND = 0x80,
123 NVM_IO_SLC_MODE = 0x100,
124 NVM_IO_SCRAMBLE_DISABLE = 0x200,
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100125
126 /* Block Types */
127 NVM_BLK_T_FREE = 0x0,
128 NVM_BLK_T_BAD = 0x1,
Matias Bjørlingb5d4acd2016-01-12 07:49:32 +0100129 NVM_BLK_T_GRWN_BAD = 0x2,
130 NVM_BLK_T_DEV = 0x4,
131 NVM_BLK_T_HOST = 0x8,
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100132
133 /* Memory capabilities */
134 NVM_ID_CAP_SLC = 0x1,
135 NVM_ID_CAP_CMD_SUSPEND = 0x2,
136 NVM_ID_CAP_SCRAMBLE = 0x4,
137 NVM_ID_CAP_ENCRYPT = 0x8,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100138
139 /* Memory types */
140 NVM_ID_FMTYPE_SLC = 0,
141 NVM_ID_FMTYPE_MLC = 1,
Matias Bjørlingbf643182016-02-04 15:13:27 +0100142
143 /* Device capabilities */
144 NVM_ID_DCAP_BBLKMGMT = 0x1,
145 NVM_UD_DCAP_ECC = 0x2,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100146};
147
148struct nvm_id_lp_mlc {
149 u16 num_pairs;
150 u8 pairs[886];
151};
152
153struct nvm_id_lp_tbl {
154 __u8 id[8];
155 struct nvm_id_lp_mlc mlc;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100156};
157
158struct nvm_id_group {
159 u8 mtype;
160 u8 fmtype;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100161 u8 num_ch;
162 u8 num_lun;
163 u8 num_pln;
164 u16 num_blk;
165 u16 num_pg;
166 u16 fpg_sz;
167 u16 csecs;
168 u16 sos;
169 u32 trdt;
170 u32 trdm;
171 u32 tprt;
172 u32 tprm;
173 u32 tbet;
174 u32 tbem;
175 u32 mpos;
Matias Bjørling12be5ed2015-11-16 15:34:39 +0100176 u32 mccap;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100177 u16 cpar;
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100178
179 struct nvm_id_lp_tbl lptbl;
Matias Bjørling73387e72015-11-16 15:34:40 +0100180};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100181
182struct nvm_addr_format {
183 u8 ch_offset;
184 u8 ch_len;
185 u8 lun_offset;
186 u8 lun_len;
187 u8 pln_offset;
188 u8 pln_len;
189 u8 blk_offset;
190 u8 blk_len;
191 u8 pg_offset;
192 u8 pg_len;
193 u8 sect_offset;
194 u8 sect_len;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100195};
196
197struct nvm_id {
198 u8 ver_id;
199 u8 vmnt;
200 u8 cgrps;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100201 u32 cap;
202 u32 dom;
203 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100204 struct nvm_id_group groups[4];
205} __packed;
206
207struct nvm_target {
208 struct list_head list;
Matias Bjørling976bdfc2016-05-06 20:03:17 +0200209 struct nvm_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100210 struct nvm_tgt_type *type;
211 struct gendisk *disk;
212};
213
214struct nvm_tgt_instance {
215 struct nvm_tgt_type *tt;
216};
217
218#define ADDR_EMPTY (~0ULL)
219
220#define NVM_VERSION_MAJOR 1
221#define NVM_VERSION_MINOR 0
222#define NVM_VERSION_PATCH 0
223
Matias Bjørling912761622016-01-12 07:49:21 +0100224struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100225typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100226
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100227struct nvm_rq {
228 struct nvm_tgt_instance *ins;
229 struct nvm_dev *dev;
230
231 struct bio *bio;
232
233 union {
234 struct ppa_addr ppa_addr;
235 dma_addr_t dma_ppa_list;
236 };
237
238 struct ppa_addr *ppa_list;
239
Javier González003fad32016-05-06 20:03:12 +0200240 void *meta_list;
241 dma_addr_t dma_meta_list;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100242
Matias Bjørling912761622016-01-12 07:49:21 +0100243 struct completion *wait;
244 nvm_end_io_fn *end_io;
245
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100246 uint8_t opcode;
Javier González6d5be952016-05-06 20:03:20 +0200247 uint16_t nr_ppas;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100248 uint16_t flags;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100249
Matias Bjorling9f867262016-03-03 15:06:39 +0100250 u64 ppa_status; /* ppa media status */
Matias Bjørling72d256e2016-01-12 07:49:29 +0100251 int error;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100252};
253
254static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu)
255{
256 return pdu - sizeof(struct nvm_rq);
257}
258
259static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
260{
261 return rqdata + 1;
262}
263
264struct nvm_block;
265
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100266struct nvm_lun {
267 int id;
268
269 int lun_id;
270 int chnl_id;
271
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100272 /* It is up to the target to mark blocks as closed. If the target does
273 * not do it, all blocks are marked as open, and nr_open_blocks
274 * represents the number of blocks in use
275 */
276 unsigned int nr_open_blocks; /* Number of used, writable blocks */
277 unsigned int nr_closed_blocks; /* Number of used, read-only blocks */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100278 unsigned int nr_free_blocks; /* Number of unused blocks */
Javier Gonzalez0b597332015-11-20 13:47:56 +0100279 unsigned int nr_bad_blocks; /* Number of bad blocks */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100280
281 spinlock_t lock;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100282
283 struct nvm_block *blocks;
284};
285
286enum {
287 NVM_BLK_ST_FREE = 0x1, /* Free block */
288 NVM_BLK_ST_OPEN = 0x2, /* Open block - read-write */
289 NVM_BLK_ST_CLOSED = 0x4, /* Closed block - read-only */
290 NVM_BLK_ST_BAD = 0x8, /* Bad block */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100291};
292
293struct nvm_block {
294 struct list_head list;
295 struct nvm_lun *lun;
296 unsigned long id;
297
298 void *priv;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100299 int state;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100300};
301
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100302/* system block cpu representation */
303struct nvm_sb_info {
304 unsigned long seqnr;
305 unsigned long erase_cnt;
306 unsigned int version;
307 char mmtype[NVM_MMTYPE_LEN];
308 struct ppa_addr fs_ppa;
309};
310
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100311struct nvm_dev {
312 struct nvm_dev_ops *ops;
313
314 struct list_head devices;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100315
316 /* Media manager */
317 struct nvmm_type *mt;
318 void *mp;
319
Matias Bjørlingb7692072016-01-12 07:49:38 +0100320 /* System blocks */
321 struct nvm_sb_info sb;
322
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100323 /* Device information */
324 int nr_chnls;
325 int nr_planes;
326 int luns_per_chnl;
327 int sec_per_pg; /* only sectors for a single page */
328 int pgs_per_blk;
329 int blks_per_lun;
Matias Bjørling4891d122016-05-06 20:02:57 +0200330 int fpg_size;
331 int pfpg_size; /* size of buffer if all pages are to be read */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100332 int sec_size;
333 int oob_size;
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100334 int mccap;
Matias Bjørling7386af22015-11-16 15:34:44 +0100335 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100336
337 /* Calculated/Cached values. These do not reflect the actual usable
338 * blocks at run-time.
339 */
340 int max_rq_size;
341 int plane_mode; /* drive device in single, double or quad mode */
342
343 int sec_per_pl; /* all sectors across planes */
344 int sec_per_blk;
345 int sec_per_lun;
346
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100347 /* lower page table */
348 int lps_per_blk;
349 int *lptbl;
350
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100351 unsigned long total_blocks;
Matias Bjørling4ece44a2016-02-20 08:52:41 +0100352 unsigned long total_secs;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100353 int nr_luns;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100354
Wenwei Taoda1e2842016-03-03 15:06:38 +0100355 unsigned long *lun_map;
Javier González75b85642016-05-06 20:03:13 +0200356 void *dma_pool;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100357
358 struct nvm_id identity;
359
360 /* Backend device */
361 struct request_queue *q;
362 char name[DISK_NAME_LEN];
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100363
364 struct mutex mlock;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100365 spinlock_t lock;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100366};
367
Matias Bjørling7386af22015-11-16 15:34:44 +0100368static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev,
369 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100370{
371 struct ppa_addr l;
372
Matias Bjørling7386af22015-11-16 15:34:44 +0100373 l.ppa = ((u64)r.g.blk) << dev->ppaf.blk_offset;
374 l.ppa |= ((u64)r.g.pg) << dev->ppaf.pg_offset;
375 l.ppa |= ((u64)r.g.sec) << dev->ppaf.sect_offset;
376 l.ppa |= ((u64)r.g.pl) << dev->ppaf.pln_offset;
377 l.ppa |= ((u64)r.g.lun) << dev->ppaf.lun_offset;
378 l.ppa |= ((u64)r.g.ch) << dev->ppaf.ch_offset;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100379
380 return l;
381}
382
Matias Bjørling7386af22015-11-16 15:34:44 +0100383static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,
384 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100385{
386 struct ppa_addr l;
387
Matias Bjørling7386af22015-11-16 15:34:44 +0100388 /*
389 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
390 */
391 l.g.blk = (r.ppa >> dev->ppaf.blk_offset) &
392 (((1 << dev->ppaf.blk_len) - 1));
393 l.g.pg |= (r.ppa >> dev->ppaf.pg_offset) &
394 (((1 << dev->ppaf.pg_len) - 1));
395 l.g.sec |= (r.ppa >> dev->ppaf.sect_offset) &
396 (((1 << dev->ppaf.sect_len) - 1));
397 l.g.pl |= (r.ppa >> dev->ppaf.pln_offset) &
398 (((1 << dev->ppaf.pln_len) - 1));
399 l.g.lun |= (r.ppa >> dev->ppaf.lun_offset) &
400 (((1 << dev->ppaf.lun_len) - 1));
401 l.g.ch |= (r.ppa >> dev->ppaf.ch_offset) &
402 (((1 << dev->ppaf.ch_len) - 1));
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100403
404 return l;
405}
406
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100407static inline int ppa_empty(struct ppa_addr ppa_addr)
408{
409 return (ppa_addr.ppa == ADDR_EMPTY);
410}
411
412static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
413{
414 ppa_addr->ppa = ADDR_EMPTY;
415}
416
417static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev,
418 struct nvm_block *blk)
419{
420 struct ppa_addr ppa;
421 struct nvm_lun *lun = blk->lun;
422
423 ppa.ppa = 0;
424 ppa.g.blk = blk->id % dev->blks_per_lun;
425 ppa.g.lun = lun->lun_id;
426 ppa.g.ch = lun->chnl_id;
427
428 return ppa;
429}
430
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100431static inline int ppa_to_slc(struct nvm_dev *dev, int slc_pg)
432{
433 return dev->lptbl[slc_pg];
434}
435
Jens Axboedece1632015-11-05 10:41:16 -0700436typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100437typedef sector_t (nvm_tgt_capacity_fn)(void *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100438typedef void *(nvm_tgt_init_fn)(struct nvm_dev *, struct gendisk *, int, int);
439typedef void (nvm_tgt_exit_fn)(void *);
440
441struct nvm_tgt_type {
442 const char *name;
443 unsigned int version[3];
444
445 /* target entry points */
446 nvm_tgt_make_rq_fn *make_rq;
447 nvm_tgt_capacity_fn *capacity;
Matias Bjørling912761622016-01-12 07:49:21 +0100448 nvm_end_io_fn *end_io;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100449
450 /* module-specific init/teardown */
451 nvm_tgt_init_fn *init;
452 nvm_tgt_exit_fn *exit;
453
454 /* For internal use */
455 struct list_head list;
456};
457
Simon A. F. Lund6063fe32016-05-06 20:03:02 +0200458extern int nvm_register_tgt_type(struct nvm_tgt_type *);
459extern void nvm_unregister_tgt_type(struct nvm_tgt_type *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100460
461extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
462extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
463
464typedef int (nvmm_register_fn)(struct nvm_dev *);
465typedef void (nvmm_unregister_fn)(struct nvm_dev *);
466typedef struct nvm_block *(nvmm_get_blk_fn)(struct nvm_dev *,
467 struct nvm_lun *, unsigned long);
468typedef void (nvmm_put_blk_fn)(struct nvm_dev *, struct nvm_block *);
469typedef int (nvmm_open_blk_fn)(struct nvm_dev *, struct nvm_block *);
470typedef int (nvmm_close_blk_fn)(struct nvm_dev *, struct nvm_block *);
471typedef void (nvmm_flush_blk_fn)(struct nvm_dev *, struct nvm_block *);
472typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100473typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *,
474 unsigned long);
Matias Bjørling04a8aa12016-05-06 20:03:18 +0200475typedef void (nvmm_mark_blk_fn)(struct nvm_dev *, struct ppa_addr, int);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100476typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
Wenwei Taoda1e2842016-03-03 15:06:38 +0100477typedef int (nvmm_reserve_lun)(struct nvm_dev *, int);
478typedef void (nvmm_release_lun)(struct nvm_dev *, int);
Javier Gonzalez2fde0e42015-11-20 13:47:57 +0100479typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100480
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100481typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t);
482typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t);
483
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100484struct nvmm_type {
485 const char *name;
486 unsigned int version[3];
487
488 nvmm_register_fn *register_mgr;
489 nvmm_unregister_fn *unregister_mgr;
490
491 /* Block administration callbacks */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100492 nvmm_get_blk_fn *get_blk_unlocked;
493 nvmm_put_blk_fn *put_blk_unlocked;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100494 nvmm_get_blk_fn *get_blk;
495 nvmm_put_blk_fn *put_blk;
496 nvmm_open_blk_fn *open_blk;
497 nvmm_close_blk_fn *close_blk;
498 nvmm_flush_blk_fn *flush_blk;
499
500 nvmm_submit_io_fn *submit_io;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100501 nvmm_erase_blk_fn *erase_blk;
502
Matias Bjørling04a8aa12016-05-06 20:03:18 +0200503 /* Bad block mgmt */
504 nvmm_mark_blk_fn *mark_blk;
505
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100506 /* Configuration management */
507 nvmm_get_lun_fn *get_lun;
Wenwei Taoda1e2842016-03-03 15:06:38 +0100508 nvmm_reserve_lun *reserve_lun;
509 nvmm_release_lun *release_lun;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100510
511 /* Statistics */
Javier Gonzalez2fde0e42015-11-20 13:47:57 +0100512 nvmm_lun_info_print_fn *lun_info_print;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100513
514 nvmm_get_area_fn *get_area;
515 nvmm_put_area_fn *put_area;
516
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100517 struct list_head list;
518};
519
520extern int nvm_register_mgr(struct nvmm_type *);
521extern void nvm_unregister_mgr(struct nvmm_type *);
522
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100523extern struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *,
524 struct nvm_lun *, unsigned long);
525extern void nvm_put_blk_unlocked(struct nvm_dev *, struct nvm_block *);
526
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100527extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *,
528 unsigned long);
529extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *);
530
531extern int nvm_register(struct request_queue *, char *,
532 struct nvm_dev_ops *);
533extern void nvm_unregister(char *);
534
535extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling069368e2016-01-12 07:49:19 +0100536extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *);
537extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingabd805e2016-01-12 07:49:20 +0100538extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *,
Matias Bjørling5ebc7d92016-05-06 20:03:07 +0200539 struct ppa_addr *, int, int);
Matias Bjørlingabd805e2016-01-12 07:49:20 +0100540extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling81e681d2016-01-12 07:49:28 +0100541extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100542extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *);
Matias Bjørling912761622016-01-12 07:49:21 +0100543extern void nvm_end_io(struct nvm_rq *, int);
Matias Bjørling09719b62016-01-12 07:49:30 +0100544extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int,
545 void *, int);
Matias Bjørling1145e632016-05-06 20:02:56 +0200546extern int nvm_submit_ppa_list(struct nvm_dev *, struct ppa_addr *, int, int,
547 int, void *, int);
Matias Bjørling22e8c972016-05-06 20:02:58 +0200548extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int);
Matias Bjørlinge11903f2016-05-06 20:03:05 +0200549extern int nvm_get_bb_tbl(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100550
551/* sysblk.c */
552#define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */
553
554/* system block on disk representation */
555struct nvm_system_block {
556 __be32 magic; /* magic signature */
557 __be32 seqnr; /* sequence number */
558 __be32 erase_cnt; /* erase count */
559 __be16 version; /* version number */
560 u8 mmtype[NVM_MMTYPE_LEN]; /* media manager name */
561 __be64 fs_ppa; /* PPA for media manager
562 * superblock */
563};
564
565extern int nvm_get_sysblock(struct nvm_dev *, struct nvm_sb_info *);
566extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *);
567extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *);
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100568
569extern int nvm_dev_factory(struct nvm_dev *, int flags);
Matias Bjørling51360612016-05-06 20:03:04 +0200570
571#define nvm_for_each_lun_ppa(dev, ppa, chid, lunid) \
572 for ((chid) = 0, (ppa).ppa = 0; (chid) < (dev)->nr_chnls; \
573 (chid)++, (ppa).g.ch = (chid)) \
574 for ((lunid) = 0; (lunid) < (dev)->luns_per_chnl; \
575 (lunid)++, (ppa).g.lun = (lunid))
576
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100577#else /* CONFIG_NVM */
578struct nvm_dev_ops;
579
580static inline int nvm_register(struct request_queue *q, char *disk_name,
581 struct nvm_dev_ops *ops)
582{
583 return -EINVAL;
584}
585static inline void nvm_unregister(char *disk_name) {}
586#endif /* CONFIG_NVM */
587#endif /* LIGHTNVM.H */