blob: ba78b830667435838e787055d0cb2012f1404d56 [file] [log] [blame]
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01001#ifndef NVM_H
2#define NVM_H
3
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02004#include <linux/blkdev.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07005#include <linux/types.h>
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02006#include <uapi/linux/lightnvm.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07007
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01008enum {
9 NVM_IO_OK = 0,
10 NVM_IO_REQUEUE = 1,
11 NVM_IO_DONE = 2,
12 NVM_IO_ERR = 3,
13
14 NVM_IOTYPE_NONE = 0,
15 NVM_IOTYPE_GC = 1,
16};
17
Jens Axboea7fd9a42016-01-13 13:04:11 -070018#define NVM_BLK_BITS (16)
19#define NVM_PG_BITS (16)
20#define NVM_SEC_BITS (8)
21#define NVM_PL_BITS (8)
22#define NVM_LUN_BITS (8)
Matias Bjørlingdf414b32016-05-06 20:03:19 +020023#define NVM_CH_BITS (7)
Jens Axboea7fd9a42016-01-13 13:04:11 -070024
25struct ppa_addr {
26 /* Generic structure for all addresses */
27 union {
28 struct {
29 u64 blk : NVM_BLK_BITS;
30 u64 pg : NVM_PG_BITS;
31 u64 sec : NVM_SEC_BITS;
32 u64 pl : NVM_PL_BITS;
33 u64 lun : NVM_LUN_BITS;
34 u64 ch : NVM_CH_BITS;
Matias Bjørlingdf414b32016-05-06 20:03:19 +020035 u64 reserved : 1;
Jens Axboea7fd9a42016-01-13 13:04:11 -070036 } g;
37
Matias Bjørlingdf414b32016-05-06 20:03:19 +020038 struct {
39 u64 line : 63;
40 u64 is_cached : 1;
41 } c;
42
Jens Axboea7fd9a42016-01-13 13:04:11 -070043 u64 ppa;
44 };
45};
46
47struct nvm_rq;
48struct nvm_id;
49struct nvm_dev;
50
51typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070052typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *);
53typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32,
54 nvm_l2p_update_fn *, void *);
Matias Bjørlinge11903f2016-05-06 20:03:05 +020055typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørling00ee6cc2016-05-06 20:03:09 +020056typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
Jens Axboea7fd9a42016-01-13 13:04:11 -070057typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
58typedef int (nvm_erase_blk_fn)(struct nvm_dev *, struct nvm_rq *);
59typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
60typedef void (nvm_destroy_dma_pool_fn)(void *);
61typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
62 dma_addr_t *);
63typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
64
65struct nvm_dev_ops {
66 nvm_id_fn *identity;
67 nvm_get_l2p_tbl_fn *get_l2p_tbl;
68 nvm_op_bb_tbl_fn *get_bb_tbl;
69 nvm_op_set_bb_fn *set_bb_tbl;
70
71 nvm_submit_io_fn *submit_io;
72 nvm_erase_blk_fn *erase_block;
73
74 nvm_create_dma_pool_fn *create_dma_pool;
75 nvm_destroy_dma_pool_fn *destroy_dma_pool;
76 nvm_dev_dma_alloc_fn *dev_dma_alloc;
77 nvm_dev_dma_free_fn *dev_dma_free;
78
79 unsigned int max_phys_sect;
80};
81
82
83
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010084#ifdef CONFIG_NVM
85
86#include <linux/blkdev.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010087#include <linux/file.h>
88#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010089#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010090
91enum {
92 /* HW Responsibilities */
93 NVM_RSP_L2P = 1 << 0,
94 NVM_RSP_ECC = 1 << 1,
95
96 /* Physical Adressing Mode */
97 NVM_ADDRMODE_LINEAR = 0,
98 NVM_ADDRMODE_CHANNEL = 1,
99
100 /* Plane programming mode for LUN */
Matias Bjørlingd5bdec82016-02-19 13:56:58 +0100101 NVM_PLANE_SINGLE = 1,
102 NVM_PLANE_DOUBLE = 2,
103 NVM_PLANE_QUAD = 4,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100104
105 /* Status codes */
106 NVM_RSP_SUCCESS = 0x0,
107 NVM_RSP_NOT_CHANGEABLE = 0x1,
108 NVM_RSP_ERR_FAILWRITE = 0x40ff,
109 NVM_RSP_ERR_EMPTYPAGE = 0x42ff,
110
111 /* Device opcodes */
112 NVM_OP_HBREAD = 0x02,
113 NVM_OP_HBWRITE = 0x81,
114 NVM_OP_PWRITE = 0x91,
115 NVM_OP_PREAD = 0x92,
116 NVM_OP_ERASE = 0x90,
117
118 /* PPA Command Flags */
119 NVM_IO_SNGL_ACCESS = 0x0,
120 NVM_IO_DUAL_ACCESS = 0x1,
121 NVM_IO_QUAD_ACCESS = 0x2,
122
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100123 /* NAND Access Modes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100124 NVM_IO_SUSPEND = 0x80,
125 NVM_IO_SLC_MODE = 0x100,
126 NVM_IO_SCRAMBLE_DISABLE = 0x200,
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100127
128 /* Block Types */
129 NVM_BLK_T_FREE = 0x0,
130 NVM_BLK_T_BAD = 0x1,
Matias Bjørlingb5d4acd2016-01-12 07:49:32 +0100131 NVM_BLK_T_GRWN_BAD = 0x2,
132 NVM_BLK_T_DEV = 0x4,
133 NVM_BLK_T_HOST = 0x8,
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100134
135 /* Memory capabilities */
136 NVM_ID_CAP_SLC = 0x1,
137 NVM_ID_CAP_CMD_SUSPEND = 0x2,
138 NVM_ID_CAP_SCRAMBLE = 0x4,
139 NVM_ID_CAP_ENCRYPT = 0x8,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100140
141 /* Memory types */
142 NVM_ID_FMTYPE_SLC = 0,
143 NVM_ID_FMTYPE_MLC = 1,
Matias Bjørlingbf643182016-02-04 15:13:27 +0100144
145 /* Device capabilities */
146 NVM_ID_DCAP_BBLKMGMT = 0x1,
147 NVM_UD_DCAP_ECC = 0x2,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100148};
149
150struct nvm_id_lp_mlc {
151 u16 num_pairs;
152 u8 pairs[886];
153};
154
155struct nvm_id_lp_tbl {
156 __u8 id[8];
157 struct nvm_id_lp_mlc mlc;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100158};
159
160struct nvm_id_group {
161 u8 mtype;
162 u8 fmtype;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100163 u8 num_ch;
164 u8 num_lun;
165 u8 num_pln;
166 u16 num_blk;
167 u16 num_pg;
168 u16 fpg_sz;
169 u16 csecs;
170 u16 sos;
171 u32 trdt;
172 u32 trdm;
173 u32 tprt;
174 u32 tprm;
175 u32 tbet;
176 u32 tbem;
177 u32 mpos;
Matias Bjørling12be5ed2015-11-16 15:34:39 +0100178 u32 mccap;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100179 u16 cpar;
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100180
181 struct nvm_id_lp_tbl lptbl;
Matias Bjørling73387e72015-11-16 15:34:40 +0100182};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100183
184struct nvm_addr_format {
185 u8 ch_offset;
186 u8 ch_len;
187 u8 lun_offset;
188 u8 lun_len;
189 u8 pln_offset;
190 u8 pln_len;
191 u8 blk_offset;
192 u8 blk_len;
193 u8 pg_offset;
194 u8 pg_len;
195 u8 sect_offset;
196 u8 sect_len;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100197};
198
199struct nvm_id {
200 u8 ver_id;
201 u8 vmnt;
202 u8 cgrps;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100203 u32 cap;
204 u32 dom;
205 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100206 struct nvm_id_group groups[4];
207} __packed;
208
209struct nvm_target {
210 struct list_head list;
Matias Bjørling976bdfc2016-05-06 20:03:17 +0200211 struct nvm_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100212 struct nvm_tgt_type *type;
213 struct gendisk *disk;
214};
215
216struct nvm_tgt_instance {
217 struct nvm_tgt_type *tt;
218};
219
220#define ADDR_EMPTY (~0ULL)
221
222#define NVM_VERSION_MAJOR 1
223#define NVM_VERSION_MINOR 0
224#define NVM_VERSION_PATCH 0
225
Matias Bjørling912761622016-01-12 07:49:21 +0100226struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100227typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100228
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100229struct nvm_rq {
230 struct nvm_tgt_instance *ins;
231 struct nvm_dev *dev;
232
233 struct bio *bio;
234
235 union {
236 struct ppa_addr ppa_addr;
237 dma_addr_t dma_ppa_list;
238 };
239
240 struct ppa_addr *ppa_list;
241
Javier González003fad32016-05-06 20:03:12 +0200242 void *meta_list;
243 dma_addr_t dma_meta_list;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100244
Matias Bjørling912761622016-01-12 07:49:21 +0100245 struct completion *wait;
246 nvm_end_io_fn *end_io;
247
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100248 uint8_t opcode;
Javier González6d5be952016-05-06 20:03:20 +0200249 uint16_t nr_ppas;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100250 uint16_t flags;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100251
Matias Bjorling9f867262016-03-03 15:06:39 +0100252 u64 ppa_status; /* ppa media status */
Matias Bjørling72d256e2016-01-12 07:49:29 +0100253 int error;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100254};
255
256static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu)
257{
258 return pdu - sizeof(struct nvm_rq);
259}
260
261static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
262{
263 return rqdata + 1;
264}
265
266struct nvm_block;
267
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100268struct nvm_lun {
269 int id;
270
271 int lun_id;
272 int chnl_id;
273
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100274 spinlock_t lock;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100275
Matias Bjørling077d2382016-07-07 09:54:14 +0200276 unsigned int nr_free_blocks; /* Number of unused blocks */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100277 struct nvm_block *blocks;
278};
279
280enum {
281 NVM_BLK_ST_FREE = 0x1, /* Free block */
Matias Bjørling077d2382016-07-07 09:54:14 +0200282 NVM_BLK_ST_TGT = 0x2, /* Block in use by target */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100283 NVM_BLK_ST_BAD = 0x8, /* Bad block */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100284};
285
286struct nvm_block {
287 struct list_head list;
288 struct nvm_lun *lun;
289 unsigned long id;
290
291 void *priv;
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100292 int state;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100293};
294
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100295/* system block cpu representation */
296struct nvm_sb_info {
297 unsigned long seqnr;
298 unsigned long erase_cnt;
299 unsigned int version;
300 char mmtype[NVM_MMTYPE_LEN];
301 struct ppa_addr fs_ppa;
302};
303
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100304struct nvm_dev {
305 struct nvm_dev_ops *ops;
306
307 struct list_head devices;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100308
309 /* Media manager */
310 struct nvmm_type *mt;
311 void *mp;
312
Matias Bjørlingb7692072016-01-12 07:49:38 +0100313 /* System blocks */
314 struct nvm_sb_info sb;
315
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100316 /* Device information */
317 int nr_chnls;
318 int nr_planes;
319 int luns_per_chnl;
320 int sec_per_pg; /* only sectors for a single page */
321 int pgs_per_blk;
322 int blks_per_lun;
Matias Bjørling4891d122016-05-06 20:02:57 +0200323 int fpg_size;
324 int pfpg_size; /* size of buffer if all pages are to be read */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100325 int sec_size;
326 int oob_size;
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100327 int mccap;
Matias Bjørling7386af22015-11-16 15:34:44 +0100328 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100329
330 /* Calculated/Cached values. These do not reflect the actual usable
331 * blocks at run-time.
332 */
333 int max_rq_size;
334 int plane_mode; /* drive device in single, double or quad mode */
335
336 int sec_per_pl; /* all sectors across planes */
337 int sec_per_blk;
338 int sec_per_lun;
339
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100340 /* lower page table */
341 int lps_per_blk;
342 int *lptbl;
343
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100344 unsigned long total_blocks;
Matias Bjørling4ece44a2016-02-20 08:52:41 +0100345 unsigned long total_secs;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100346 int nr_luns;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100347
Wenwei Taoda1e2842016-03-03 15:06:38 +0100348 unsigned long *lun_map;
Javier González75b85642016-05-06 20:03:13 +0200349 void *dma_pool;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100350
351 struct nvm_id identity;
352
353 /* Backend device */
354 struct request_queue *q;
355 char name[DISK_NAME_LEN];
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100356
357 struct mutex mlock;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100358 spinlock_t lock;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100359};
360
Matias Bjørling7386af22015-11-16 15:34:44 +0100361static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev,
362 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100363{
364 struct ppa_addr l;
365
Matias Bjørling7386af22015-11-16 15:34:44 +0100366 l.ppa = ((u64)r.g.blk) << dev->ppaf.blk_offset;
367 l.ppa |= ((u64)r.g.pg) << dev->ppaf.pg_offset;
368 l.ppa |= ((u64)r.g.sec) << dev->ppaf.sect_offset;
369 l.ppa |= ((u64)r.g.pl) << dev->ppaf.pln_offset;
370 l.ppa |= ((u64)r.g.lun) << dev->ppaf.lun_offset;
371 l.ppa |= ((u64)r.g.ch) << dev->ppaf.ch_offset;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100372
373 return l;
374}
375
Matias Bjørling7386af22015-11-16 15:34:44 +0100376static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev,
377 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100378{
379 struct ppa_addr l;
380
Javier González5389a1d2016-07-07 09:54:09 +0200381 l.ppa = 0;
Matias Bjørling7386af22015-11-16 15:34:44 +0100382 /*
383 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
384 */
385 l.g.blk = (r.ppa >> dev->ppaf.blk_offset) &
386 (((1 << dev->ppaf.blk_len) - 1));
387 l.g.pg |= (r.ppa >> dev->ppaf.pg_offset) &
388 (((1 << dev->ppaf.pg_len) - 1));
389 l.g.sec |= (r.ppa >> dev->ppaf.sect_offset) &
390 (((1 << dev->ppaf.sect_len) - 1));
391 l.g.pl |= (r.ppa >> dev->ppaf.pln_offset) &
392 (((1 << dev->ppaf.pln_len) - 1));
393 l.g.lun |= (r.ppa >> dev->ppaf.lun_offset) &
394 (((1 << dev->ppaf.lun_len) - 1));
395 l.g.ch |= (r.ppa >> dev->ppaf.ch_offset) &
396 (((1 << dev->ppaf.ch_len) - 1));
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100397
398 return l;
399}
400
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100401static inline int ppa_empty(struct ppa_addr ppa_addr)
402{
403 return (ppa_addr.ppa == ADDR_EMPTY);
404}
405
406static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
407{
408 ppa_addr->ppa = ADDR_EMPTY;
409}
410
411static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev,
412 struct nvm_block *blk)
413{
414 struct ppa_addr ppa;
415 struct nvm_lun *lun = blk->lun;
416
417 ppa.ppa = 0;
418 ppa.g.blk = blk->id % dev->blks_per_lun;
419 ppa.g.lun = lun->lun_id;
420 ppa.g.ch = lun->chnl_id;
421
422 return ppa;
423}
424
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100425static inline int ppa_to_slc(struct nvm_dev *dev, int slc_pg)
426{
427 return dev->lptbl[slc_pg];
428}
429
Jens Axboedece1632015-11-05 10:41:16 -0700430typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100431typedef sector_t (nvm_tgt_capacity_fn)(void *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100432typedef void *(nvm_tgt_init_fn)(struct nvm_dev *, struct gendisk *, int, int);
433typedef void (nvm_tgt_exit_fn)(void *);
434
435struct nvm_tgt_type {
436 const char *name;
437 unsigned int version[3];
438
439 /* target entry points */
440 nvm_tgt_make_rq_fn *make_rq;
441 nvm_tgt_capacity_fn *capacity;
Matias Bjørling912761622016-01-12 07:49:21 +0100442 nvm_end_io_fn *end_io;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100443
444 /* module-specific init/teardown */
445 nvm_tgt_init_fn *init;
446 nvm_tgt_exit_fn *exit;
447
448 /* For internal use */
449 struct list_head list;
450};
451
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +0200452extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);
453
Simon A. F. Lund6063fe32016-05-06 20:03:02 +0200454extern int nvm_register_tgt_type(struct nvm_tgt_type *);
455extern void nvm_unregister_tgt_type(struct nvm_tgt_type *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100456
457extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
458extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
459
460typedef int (nvmm_register_fn)(struct nvm_dev *);
461typedef void (nvmm_unregister_fn)(struct nvm_dev *);
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +0200462
463typedef int (nvmm_create_tgt_fn)(struct nvm_dev *, struct nvm_ioctl_create *);
464typedef int (nvmm_remove_tgt_fn)(struct nvm_dev *, struct nvm_ioctl_remove *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100465typedef struct nvm_block *(nvmm_get_blk_fn)(struct nvm_dev *,
466 struct nvm_lun *, unsigned long);
467typedef void (nvmm_put_blk_fn)(struct nvm_dev *, struct nvm_block *);
468typedef int (nvmm_open_blk_fn)(struct nvm_dev *, struct nvm_block *);
469typedef int (nvmm_close_blk_fn)(struct nvm_dev *, struct nvm_block *);
470typedef void (nvmm_flush_blk_fn)(struct nvm_dev *, struct nvm_block *);
471typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100472typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *,
473 unsigned long);
Matias Bjørling04a8aa12016-05-06 20:03:18 +0200474typedef void (nvmm_mark_blk_fn)(struct nvm_dev *, struct ppa_addr, int);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100475typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
Wenwei Taoda1e2842016-03-03 15:06:38 +0100476typedef int (nvmm_reserve_lun)(struct nvm_dev *, int);
477typedef void (nvmm_release_lun)(struct nvm_dev *, int);
Javier Gonzalez2fde0e42015-11-20 13:47:57 +0100478typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100479
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100480typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t);
481typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t);
482
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100483struct nvmm_type {
484 const char *name;
485 unsigned int version[3];
486
487 nvmm_register_fn *register_mgr;
488 nvmm_unregister_fn *unregister_mgr;
489
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +0200490 nvmm_create_tgt_fn *create_tgt;
491 nvmm_remove_tgt_fn *remove_tgt;
492
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100493 /* Block administration callbacks */
494 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
523extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *,
524 unsigned long);
525extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *);
526
527extern int nvm_register(struct request_queue *, char *,
528 struct nvm_dev_ops *);
529extern void nvm_unregister(char *);
530
Javier González529435e2016-07-07 09:54:08 +0200531void nvm_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type);
532
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100533extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling069368e2016-01-12 07:49:19 +0100534extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *);
535extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *);
Matias Bjørlingabd805e2016-01-12 07:49:20 +0100536extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *,
Matias Bjørling8680f162016-07-07 09:54:22 +0200537 const struct ppa_addr *, int, int);
Matias Bjørlingabd805e2016-01-12 07:49:20 +0100538extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *);
Matias Bjørling81e681d2016-01-12 07:49:28 +0100539extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100540extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *);
Matias Bjørling912761622016-01-12 07:49:21 +0100541extern void nvm_end_io(struct nvm_rq *, int);
Matias Bjørling09719b62016-01-12 07:49:30 +0100542extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int,
543 void *, int);
Matias Bjørling1145e632016-05-06 20:02:56 +0200544extern int nvm_submit_ppa_list(struct nvm_dev *, struct ppa_addr *, int, int,
545 int, void *, int);
Matias Bjørling22e8c972016-05-06 20:02:58 +0200546extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int);
Matias Bjørlinge11903f2016-05-06 20:03:05 +0200547extern int nvm_get_bb_tbl(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100548
549/* sysblk.c */
550#define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */
551
552/* system block on disk representation */
553struct nvm_system_block {
554 __be32 magic; /* magic signature */
555 __be32 seqnr; /* sequence number */
556 __be32 erase_cnt; /* erase count */
557 __be16 version; /* version number */
558 u8 mmtype[NVM_MMTYPE_LEN]; /* media manager name */
559 __be64 fs_ppa; /* PPA for media manager
560 * superblock */
561};
562
563extern int nvm_get_sysblock(struct nvm_dev *, struct nvm_sb_info *);
564extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *);
565extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *);
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100566
567extern int nvm_dev_factory(struct nvm_dev *, int flags);
Matias Bjørling51360612016-05-06 20:03:04 +0200568
569#define nvm_for_each_lun_ppa(dev, ppa, chid, lunid) \
570 for ((chid) = 0, (ppa).ppa = 0; (chid) < (dev)->nr_chnls; \
571 (chid)++, (ppa).g.ch = (chid)) \
572 for ((lunid) = 0; (lunid) < (dev)->luns_per_chnl; \
573 (lunid)++, (ppa).g.lun = (lunid))
574
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100575#else /* CONFIG_NVM */
576struct nvm_dev_ops;
577
578static inline int nvm_register(struct request_queue *q, char *disk_name,
579 struct nvm_dev_ops *ops)
580{
581 return -EINVAL;
582}
583static inline void nvm_unregister(char *disk_name) {}
584#endif /* CONFIG_NVM */
585#endif /* LIGHTNVM.H */