]>
Commit | Line | Data |
---|---|---|
cd9e9808 MB |
1 | #ifndef NVM_H |
2 | #define NVM_H | |
3 | ||
a7fd9a4f JA |
4 | #include <linux/types.h> |
5 | ||
cd9e9808 MB |
6 | enum { |
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 | ||
a7fd9a4f JA |
16 | #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) | |
df414b33 | 21 | #define NVM_CH_BITS (7) |
a7fd9a4f JA |
22 | |
23 | struct 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; | |
df414b33 | 33 | u64 reserved : 1; |
a7fd9a4f JA |
34 | } g; |
35 | ||
df414b33 MB |
36 | struct { |
37 | u64 line : 63; | |
38 | u64 is_cached : 1; | |
39 | } c; | |
40 | ||
a7fd9a4f JA |
41 | u64 ppa; |
42 | }; | |
43 | }; | |
44 | ||
45 | struct nvm_rq; | |
46 | struct nvm_id; | |
47 | struct nvm_dev; | |
48 | ||
49 | typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *); | |
a7fd9a4f JA |
50 | typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *); |
51 | typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32, | |
52 | nvm_l2p_update_fn *, void *); | |
e11903f5 | 53 | typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *); |
00ee6cc3 | 54 | typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int); |
a7fd9a4f JA |
55 | typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); |
56 | typedef int (nvm_erase_blk_fn)(struct nvm_dev *, struct nvm_rq *); | |
57 | typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *); | |
58 | typedef void (nvm_destroy_dma_pool_fn)(void *); | |
59 | typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t, | |
60 | dma_addr_t *); | |
61 | typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t); | |
62 | ||
63 | struct 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 | ||
cd9e9808 MB |
82 | #ifdef CONFIG_NVM |
83 | ||
84 | #include <linux/blkdev.h> | |
cd9e9808 MB |
85 | #include <linux/file.h> |
86 | #include <linux/dmapool.h> | |
e3eb3799 | 87 | #include <uapi/linux/lightnvm.h> |
cd9e9808 MB |
88 | |
89 | enum { | |
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 */ | |
d5bdec8d MB |
99 | NVM_PLANE_SINGLE = 1, |
100 | NVM_PLANE_DOUBLE = 2, | |
101 | NVM_PLANE_QUAD = 4, | |
cd9e9808 MB |
102 | |
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 | ||
57b4bd06 | 121 | /* NAND Access Modes */ |
cd9e9808 MB |
122 | NVM_IO_SUSPEND = 0x80, |
123 | NVM_IO_SLC_MODE = 0x100, | |
124 | NVM_IO_SCRAMBLE_DISABLE = 0x200, | |
57b4bd06 MB |
125 | |
126 | /* Block Types */ | |
127 | NVM_BLK_T_FREE = 0x0, | |
128 | NVM_BLK_T_BAD = 0x1, | |
b5d4acd4 MB |
129 | NVM_BLK_T_GRWN_BAD = 0x2, |
130 | NVM_BLK_T_DEV = 0x4, | |
131 | NVM_BLK_T_HOST = 0x8, | |
f9a99950 MB |
132 | |
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, | |
ca5927e7 MB |
138 | |
139 | /* Memory types */ | |
140 | NVM_ID_FMTYPE_SLC = 0, | |
141 | NVM_ID_FMTYPE_MLC = 1, | |
bf643185 MB |
142 | |
143 | /* Device capabilities */ | |
144 | NVM_ID_DCAP_BBLKMGMT = 0x1, | |
145 | NVM_UD_DCAP_ECC = 0x2, | |
ca5927e7 MB |
146 | }; |
147 | ||
148 | struct nvm_id_lp_mlc { | |
149 | u16 num_pairs; | |
150 | u8 pairs[886]; | |
151 | }; | |
152 | ||
153 | struct nvm_id_lp_tbl { | |
154 | __u8 id[8]; | |
155 | struct nvm_id_lp_mlc mlc; | |
cd9e9808 MB |
156 | }; |
157 | ||
158 | struct nvm_id_group { | |
159 | u8 mtype; | |
160 | u8 fmtype; | |
cd9e9808 MB |
161 | 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; | |
12be5edf | 176 | u32 mccap; |
cd9e9808 | 177 | u16 cpar; |
ca5927e7 MB |
178 | |
179 | struct nvm_id_lp_tbl lptbl; | |
73387e7b | 180 | }; |
cd9e9808 MB |
181 | |
182 | struct 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; | |
cd9e9808 MB |
195 | }; |
196 | ||
197 | struct nvm_id { | |
198 | u8 ver_id; | |
199 | u8 vmnt; | |
200 | u8 cgrps; | |
cd9e9808 MB |
201 | u32 cap; |
202 | u32 dom; | |
203 | struct nvm_addr_format ppaf; | |
cd9e9808 MB |
204 | struct nvm_id_group groups[4]; |
205 | } __packed; | |
206 | ||
207 | struct nvm_target { | |
208 | struct list_head list; | |
976bdfca | 209 | struct nvm_dev *dev; |
cd9e9808 MB |
210 | struct nvm_tgt_type *type; |
211 | struct gendisk *disk; | |
212 | }; | |
213 | ||
214 | struct 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 | ||
91276162 | 224 | struct nvm_rq; |
72d256ec | 225 | typedef void (nvm_end_io_fn)(struct nvm_rq *); |
91276162 | 226 | |
cd9e9808 MB |
227 | struct 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 | ||
003fad37 JG |
240 | void *meta_list; |
241 | dma_addr_t dma_meta_list; | |
cd9e9808 | 242 | |
91276162 MB |
243 | struct completion *wait; |
244 | nvm_end_io_fn *end_io; | |
245 | ||
cd9e9808 | 246 | uint8_t opcode; |
6d5be959 | 247 | uint16_t nr_ppas; |
cd9e9808 | 248 | uint16_t flags; |
72d256ec | 249 | |
9f867268 | 250 | u64 ppa_status; /* ppa media status */ |
72d256ec | 251 | int error; |
cd9e9808 MB |
252 | }; |
253 | ||
254 | static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu) | |
255 | { | |
256 | return pdu - sizeof(struct nvm_rq); | |
257 | } | |
258 | ||
259 | static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata) | |
260 | { | |
261 | return rqdata + 1; | |
262 | } | |
263 | ||
264 | struct nvm_block; | |
265 | ||
cd9e9808 MB |
266 | struct nvm_lun { |
267 | int id; | |
268 | ||
269 | int lun_id; | |
270 | int chnl_id; | |
271 | ||
ff0e498b JG |
272 | /* 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 */ | |
cd9e9808 | 278 | unsigned int nr_free_blocks; /* Number of unused blocks */ |
0b59733b | 279 | unsigned int nr_bad_blocks; /* Number of bad blocks */ |
cd9e9808 MB |
280 | |
281 | spinlock_t lock; | |
ff0e498b JG |
282 | |
283 | struct nvm_block *blocks; | |
284 | }; | |
285 | ||
286 | enum { | |
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 */ | |
cd9e9808 MB |
291 | }; |
292 | ||
293 | struct nvm_block { | |
294 | struct list_head list; | |
295 | struct nvm_lun *lun; | |
296 | unsigned long id; | |
297 | ||
298 | void *priv; | |
ff0e498b | 299 | int state; |
cd9e9808 MB |
300 | }; |
301 | ||
e3eb3799 MB |
302 | /* system block cpu representation */ |
303 | struct 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 | ||
cd9e9808 MB |
311 | struct nvm_dev { |
312 | struct nvm_dev_ops *ops; | |
313 | ||
314 | struct list_head devices; | |
cd9e9808 MB |
315 | |
316 | /* Media manager */ | |
317 | struct nvmm_type *mt; | |
318 | void *mp; | |
319 | ||
b7692076 MB |
320 | /* System blocks */ |
321 | struct nvm_sb_info sb; | |
322 | ||
cd9e9808 MB |
323 | /* 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; | |
4891d120 MB |
330 | int fpg_size; |
331 | int pfpg_size; /* size of buffer if all pages are to be read */ | |
cd9e9808 MB |
332 | int sec_size; |
333 | int oob_size; | |
f9a99950 | 334 | int mccap; |
7386af27 | 335 | struct nvm_addr_format ppaf; |
cd9e9808 MB |
336 | |
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 | ||
ca5927e7 MB |
347 | /* lower page table */ |
348 | int lps_per_blk; | |
349 | int *lptbl; | |
350 | ||
cd9e9808 | 351 | unsigned long total_blocks; |
4ece44af | 352 | unsigned long total_secs; |
cd9e9808 | 353 | int nr_luns; |
cd9e9808 | 354 | |
da1e2849 | 355 | unsigned long *lun_map; |
75b85649 | 356 | void *dma_pool; |
cd9e9808 MB |
357 | |
358 | struct nvm_id identity; | |
359 | ||
360 | /* Backend device */ | |
361 | struct request_queue *q; | |
362 | char name[DISK_NAME_LEN]; | |
e3eb3799 MB |
363 | |
364 | struct mutex mlock; | |
4c9dacb8 | 365 | spinlock_t lock; |
cd9e9808 MB |
366 | }; |
367 | ||
7386af27 MB |
368 | static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev, |
369 | struct ppa_addr r) | |
cd9e9808 MB |
370 | { |
371 | struct ppa_addr l; | |
372 | ||
7386af27 MB |
373 | 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; | |
cd9e9808 MB |
379 | |
380 | return l; | |
381 | } | |
382 | ||
7386af27 MB |
383 | static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev, |
384 | struct ppa_addr r) | |
cd9e9808 MB |
385 | { |
386 | struct ppa_addr l; | |
387 | ||
5389a1df | 388 | l.ppa = 0; |
7386af27 MB |
389 | /* |
390 | * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc. | |
391 | */ | |
392 | l.g.blk = (r.ppa >> dev->ppaf.blk_offset) & | |
393 | (((1 << dev->ppaf.blk_len) - 1)); | |
394 | l.g.pg |= (r.ppa >> dev->ppaf.pg_offset) & | |
395 | (((1 << dev->ppaf.pg_len) - 1)); | |
396 | l.g.sec |= (r.ppa >> dev->ppaf.sect_offset) & | |
397 | (((1 << dev->ppaf.sect_len) - 1)); | |
398 | l.g.pl |= (r.ppa >> dev->ppaf.pln_offset) & | |
399 | (((1 << dev->ppaf.pln_len) - 1)); | |
400 | l.g.lun |= (r.ppa >> dev->ppaf.lun_offset) & | |
401 | (((1 << dev->ppaf.lun_len) - 1)); | |
402 | l.g.ch |= (r.ppa >> dev->ppaf.ch_offset) & | |
403 | (((1 << dev->ppaf.ch_len) - 1)); | |
cd9e9808 MB |
404 | |
405 | return l; | |
406 | } | |
407 | ||
cd9e9808 MB |
408 | static inline int ppa_empty(struct ppa_addr ppa_addr) |
409 | { | |
410 | return (ppa_addr.ppa == ADDR_EMPTY); | |
411 | } | |
412 | ||
413 | static inline void ppa_set_empty(struct ppa_addr *ppa_addr) | |
414 | { | |
415 | ppa_addr->ppa = ADDR_EMPTY; | |
416 | } | |
417 | ||
418 | static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev, | |
419 | struct nvm_block *blk) | |
420 | { | |
421 | struct ppa_addr ppa; | |
422 | struct nvm_lun *lun = blk->lun; | |
423 | ||
424 | ppa.ppa = 0; | |
425 | ppa.g.blk = blk->id % dev->blks_per_lun; | |
426 | ppa.g.lun = lun->lun_id; | |
427 | ppa.g.ch = lun->chnl_id; | |
428 | ||
429 | return ppa; | |
430 | } | |
431 | ||
e3eb3799 MB |
432 | static inline int ppa_to_slc(struct nvm_dev *dev, int slc_pg) |
433 | { | |
434 | return dev->lptbl[slc_pg]; | |
435 | } | |
436 | ||
dece1635 | 437 | typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *); |
cd9e9808 | 438 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
cd9e9808 MB |
439 | typedef void *(nvm_tgt_init_fn)(struct nvm_dev *, struct gendisk *, int, int); |
440 | typedef void (nvm_tgt_exit_fn)(void *); | |
441 | ||
442 | struct nvm_tgt_type { | |
443 | const char *name; | |
444 | unsigned int version[3]; | |
445 | ||
446 | /* target entry points */ | |
447 | nvm_tgt_make_rq_fn *make_rq; | |
448 | nvm_tgt_capacity_fn *capacity; | |
91276162 | 449 | nvm_end_io_fn *end_io; |
cd9e9808 MB |
450 | |
451 | /* module-specific init/teardown */ | |
452 | nvm_tgt_init_fn *init; | |
453 | nvm_tgt_exit_fn *exit; | |
454 | ||
455 | /* For internal use */ | |
456 | struct list_head list; | |
457 | }; | |
458 | ||
6063fe39 SL |
459 | extern int nvm_register_tgt_type(struct nvm_tgt_type *); |
460 | extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); | |
cd9e9808 MB |
461 | |
462 | extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); | |
463 | extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); | |
464 | ||
465 | typedef int (nvmm_register_fn)(struct nvm_dev *); | |
466 | typedef void (nvmm_unregister_fn)(struct nvm_dev *); | |
467 | typedef struct nvm_block *(nvmm_get_blk_fn)(struct nvm_dev *, | |
468 | struct nvm_lun *, unsigned long); | |
469 | typedef void (nvmm_put_blk_fn)(struct nvm_dev *, struct nvm_block *); | |
470 | typedef int (nvmm_open_blk_fn)(struct nvm_dev *, struct nvm_block *); | |
471 | typedef int (nvmm_close_blk_fn)(struct nvm_dev *, struct nvm_block *); | |
472 | typedef void (nvmm_flush_blk_fn)(struct nvm_dev *, struct nvm_block *); | |
473 | typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); | |
cd9e9808 MB |
474 | typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, |
475 | unsigned long); | |
04a8aa17 | 476 | typedef void (nvmm_mark_blk_fn)(struct nvm_dev *, struct ppa_addr, int); |
cd9e9808 | 477 | typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int); |
da1e2849 WT |
478 | typedef int (nvmm_reserve_lun)(struct nvm_dev *, int); |
479 | typedef void (nvmm_release_lun)(struct nvm_dev *, int); | |
2fde0e48 | 480 | typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *); |
cd9e9808 | 481 | |
4c9dacb8 WT |
482 | typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t); |
483 | typedef void (nvmm_put_area_fn)(struct nvm_dev *, sector_t); | |
484 | ||
cd9e9808 MB |
485 | struct nvmm_type { |
486 | const char *name; | |
487 | unsigned int version[3]; | |
488 | ||
489 | nvmm_register_fn *register_mgr; | |
490 | nvmm_unregister_fn *unregister_mgr; | |
491 | ||
492 | /* Block administration callbacks */ | |
ff0e498b JG |
493 | nvmm_get_blk_fn *get_blk_unlocked; |
494 | nvmm_put_blk_fn *put_blk_unlocked; | |
cd9e9808 MB |
495 | nvmm_get_blk_fn *get_blk; |
496 | nvmm_put_blk_fn *put_blk; | |
497 | nvmm_open_blk_fn *open_blk; | |
498 | nvmm_close_blk_fn *close_blk; | |
499 | nvmm_flush_blk_fn *flush_blk; | |
500 | ||
501 | nvmm_submit_io_fn *submit_io; | |
cd9e9808 MB |
502 | nvmm_erase_blk_fn *erase_blk; |
503 | ||
04a8aa17 MB |
504 | /* Bad block mgmt */ |
505 | nvmm_mark_blk_fn *mark_blk; | |
506 | ||
cd9e9808 MB |
507 | /* Configuration management */ |
508 | nvmm_get_lun_fn *get_lun; | |
da1e2849 WT |
509 | nvmm_reserve_lun *reserve_lun; |
510 | nvmm_release_lun *release_lun; | |
cd9e9808 MB |
511 | |
512 | /* Statistics */ | |
2fde0e48 | 513 | nvmm_lun_info_print_fn *lun_info_print; |
4c9dacb8 WT |
514 | |
515 | nvmm_get_area_fn *get_area; | |
516 | nvmm_put_area_fn *put_area; | |
517 | ||
cd9e9808 MB |
518 | struct list_head list; |
519 | }; | |
520 | ||
521 | extern int nvm_register_mgr(struct nvmm_type *); | |
522 | extern void nvm_unregister_mgr(struct nvmm_type *); | |
523 | ||
ff0e498b JG |
524 | extern struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *, |
525 | struct nvm_lun *, unsigned long); | |
526 | extern void nvm_put_blk_unlocked(struct nvm_dev *, struct nvm_block *); | |
527 | ||
cd9e9808 MB |
528 | extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *, |
529 | unsigned long); | |
530 | extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *); | |
531 | ||
532 | extern int nvm_register(struct request_queue *, char *, | |
533 | struct nvm_dev_ops *); | |
534 | extern void nvm_unregister(char *); | |
535 | ||
529435e8 JG |
536 | void nvm_mark_blk(struct nvm_dev *dev, struct ppa_addr ppa, int type); |
537 | ||
cd9e9808 | 538 | extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *); |
069368e9 MB |
539 | extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *); |
540 | extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *); | |
abd805ec | 541 | extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *, |
5ebc7d9f | 542 | struct ppa_addr *, int, int); |
abd805ec | 543 | extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *); |
81e681d3 | 544 | extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int); |
cd9e9808 | 545 | extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *); |
91276162 | 546 | extern void nvm_end_io(struct nvm_rq *, int); |
09719b62 MB |
547 | extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int, |
548 | void *, int); | |
1145e635 MB |
549 | extern int nvm_submit_ppa_list(struct nvm_dev *, struct ppa_addr *, int, int, |
550 | int, void *, int); | |
22e8c976 | 551 | extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int); |
e11903f5 | 552 | extern int nvm_get_bb_tbl(struct nvm_dev *, struct ppa_addr, u8 *); |
e3eb3799 MB |
553 | |
554 | /* sysblk.c */ | |
555 | #define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */ | |
556 | ||
557 | /* system block on disk representation */ | |
558 | struct nvm_system_block { | |
559 | __be32 magic; /* magic signature */ | |
560 | __be32 seqnr; /* sequence number */ | |
561 | __be32 erase_cnt; /* erase count */ | |
562 | __be16 version; /* version number */ | |
563 | u8 mmtype[NVM_MMTYPE_LEN]; /* media manager name */ | |
564 | __be64 fs_ppa; /* PPA for media manager | |
565 | * superblock */ | |
566 | }; | |
567 | ||
568 | extern int nvm_get_sysblock(struct nvm_dev *, struct nvm_sb_info *); | |
569 | extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *); | |
570 | extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *); | |
8b4970c4 MB |
571 | |
572 | extern int nvm_dev_factory(struct nvm_dev *, int flags); | |
5136061c MB |
573 | |
574 | #define nvm_for_each_lun_ppa(dev, ppa, chid, lunid) \ | |
575 | for ((chid) = 0, (ppa).ppa = 0; (chid) < (dev)->nr_chnls; \ | |
576 | (chid)++, (ppa).g.ch = (chid)) \ | |
577 | for ((lunid) = 0; (lunid) < (dev)->luns_per_chnl; \ | |
578 | (lunid)++, (ppa).g.lun = (lunid)) | |
579 | ||
cd9e9808 MB |
580 | #else /* CONFIG_NVM */ |
581 | struct nvm_dev_ops; | |
582 | ||
583 | static inline int nvm_register(struct request_queue *q, char *disk_name, | |
584 | struct nvm_dev_ops *ops) | |
585 | { | |
586 | return -EINVAL; | |
587 | } | |
588 | static inline void nvm_unregister(char *disk_name) {} | |
589 | #endif /* CONFIG_NVM */ | |
590 | #endif /* LIGHTNVM.H */ |