16 #include <linux/blkdev.h>
17 #include <linux/types.h>
18 #include <linux/file.h>
19 #include <linux/dmapool.h>
22 /* HW Responsibilities */
26 /* Physical Adressing Mode */
27 NVM_ADDRMODE_LINEAR
= 0,
28 NVM_ADDRMODE_CHANNEL
= 1,
30 /* Plane programming mode for LUN */
36 NVM_RSP_SUCCESS
= 0x0,
37 NVM_RSP_NOT_CHANGEABLE
= 0x1,
38 NVM_RSP_ERR_FAILWRITE
= 0x40ff,
39 NVM_RSP_ERR_EMPTYPAGE
= 0x42ff,
43 NVM_OP_HBWRITE
= 0x81,
48 /* PPA Command Flags */
49 NVM_IO_SNGL_ACCESS
= 0x0,
50 NVM_IO_DUAL_ACCESS
= 0x1,
51 NVM_IO_QUAD_ACCESS
= 0x2,
53 /* NAND Access Modes */
54 NVM_IO_SUSPEND
= 0x80,
55 NVM_IO_SLC_MODE
= 0x100,
56 NVM_IO_SCRAMBLE_DISABLE
= 0x200,
87 struct nvm_addr_format
{
108 struct nvm_addr_format ppaf
;
109 struct nvm_id_group groups
[4];
113 struct list_head list
;
114 struct nvm_tgt_type
*type
;
115 struct gendisk
*disk
;
118 struct nvm_tgt_instance
{
119 struct nvm_tgt_type
*tt
;
122 #define ADDR_EMPTY (~0ULL)
124 #define NVM_VERSION_MAJOR 1
125 #define NVM_VERSION_MINOR 0
126 #define NVM_VERSION_PATCH 0
128 #define NVM_BLK_BITS (16)
129 #define NVM_PG_BITS (16)
130 #define NVM_SEC_BITS (8)
131 #define NVM_PL_BITS (8)
132 #define NVM_LUN_BITS (8)
133 #define NVM_CH_BITS (8)
136 /* Generic structure for all addresses */
139 u64 blk
: NVM_BLK_BITS
;
140 u64 pg
: NVM_PG_BITS
;
141 u64 sec
: NVM_SEC_BITS
;
142 u64 pl
: NVM_PL_BITS
;
143 u64 lun
: NVM_LUN_BITS
;
144 u64 ch
: NVM_CH_BITS
;
152 typedef void (nvm_end_io_fn
)(struct nvm_rq
*);
155 struct nvm_tgt_instance
*ins
;
161 struct ppa_addr ppa_addr
;
162 dma_addr_t dma_ppa_list
;
165 struct ppa_addr
*ppa_list
;
168 dma_addr_t dma_metadata
;
170 struct completion
*wait
;
171 nvm_end_io_fn
*end_io
;
180 static inline struct nvm_rq
*nvm_rq_from_pdu(void *pdu
)
182 return pdu
- sizeof(struct nvm_rq
);
185 static inline void *nvm_rq_to_pdu(struct nvm_rq
*rqdata
)
192 typedef int (nvm_l2p_update_fn
)(u64
, u32
, __le64
*, void *);
193 typedef int (nvm_bb_update_fn
)(struct ppa_addr
, int, u8
*, void *);
194 typedef int (nvm_id_fn
)(struct nvm_dev
*, struct nvm_id
*);
195 typedef int (nvm_get_l2p_tbl_fn
)(struct nvm_dev
*, u64
, u32
,
196 nvm_l2p_update_fn
*, void *);
197 typedef int (nvm_op_bb_tbl_fn
)(struct nvm_dev
*, struct ppa_addr
, int,
198 nvm_bb_update_fn
*, void *);
199 typedef int (nvm_op_set_bb_fn
)(struct nvm_dev
*, struct nvm_rq
*, int);
200 typedef int (nvm_submit_io_fn
)(struct nvm_dev
*, struct nvm_rq
*);
201 typedef int (nvm_erase_blk_fn
)(struct nvm_dev
*, struct nvm_rq
*);
202 typedef void *(nvm_create_dma_pool_fn
)(struct nvm_dev
*, char *);
203 typedef void (nvm_destroy_dma_pool_fn
)(void *);
204 typedef void *(nvm_dev_dma_alloc_fn
)(struct nvm_dev
*, void *, gfp_t
,
206 typedef void (nvm_dev_dma_free_fn
)(void *, void*, dma_addr_t
);
210 nvm_get_l2p_tbl_fn
*get_l2p_tbl
;
211 nvm_op_bb_tbl_fn
*get_bb_tbl
;
212 nvm_op_set_bb_fn
*set_bb_tbl
;
214 nvm_submit_io_fn
*submit_io
;
215 nvm_erase_blk_fn
*erase_block
;
217 nvm_create_dma_pool_fn
*create_dma_pool
;
218 nvm_destroy_dma_pool_fn
*destroy_dma_pool
;
219 nvm_dev_dma_alloc_fn
*dev_dma_alloc
;
220 nvm_dev_dma_free_fn
*dev_dma_free
;
222 unsigned int max_phys_sect
;
231 unsigned int nr_inuse_blocks
; /* Number of used blocks */
232 unsigned int nr_free_blocks
; /* Number of unused blocks */
233 unsigned int nr_bad_blocks
; /* Number of bad blocks */
234 struct nvm_block
*blocks
;
240 struct list_head list
;
249 struct nvm_dev_ops
*ops
;
251 struct list_head devices
;
252 struct list_head online_targets
;
255 struct nvmm_type
*mt
;
258 /* Device information */
262 int sec_per_pg
; /* only sectors for a single page */
267 struct nvm_addr_format ppaf
;
269 /* Calculated/Cached values. These do not reflect the actual usable
270 * blocks at run-time.
273 int plane_mode
; /* drive device in single, double or quad mode */
275 int sec_per_pl
; /* all sectors across planes */
279 unsigned long total_pages
;
280 unsigned long total_blocks
;
282 unsigned max_pages_per_blk
;
286 struct nvm_id identity
;
289 struct request_queue
*q
;
290 char name
[DISK_NAME_LEN
];
293 static inline struct ppa_addr
generic_to_dev_addr(struct nvm_dev
*dev
,
298 l
.ppa
= ((u64
)r
.g
.blk
) << dev
->ppaf
.blk_offset
;
299 l
.ppa
|= ((u64
)r
.g
.pg
) << dev
->ppaf
.pg_offset
;
300 l
.ppa
|= ((u64
)r
.g
.sec
) << dev
->ppaf
.sect_offset
;
301 l
.ppa
|= ((u64
)r
.g
.pl
) << dev
->ppaf
.pln_offset
;
302 l
.ppa
|= ((u64
)r
.g
.lun
) << dev
->ppaf
.lun_offset
;
303 l
.ppa
|= ((u64
)r
.g
.ch
) << dev
->ppaf
.ch_offset
;
308 static inline struct ppa_addr
dev_to_generic_addr(struct nvm_dev
*dev
,
314 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
316 l
.g
.blk
= (r
.ppa
>> dev
->ppaf
.blk_offset
) &
317 (((1 << dev
->ppaf
.blk_len
) - 1));
318 l
.g
.pg
|= (r
.ppa
>> dev
->ppaf
.pg_offset
) &
319 (((1 << dev
->ppaf
.pg_len
) - 1));
320 l
.g
.sec
|= (r
.ppa
>> dev
->ppaf
.sect_offset
) &
321 (((1 << dev
->ppaf
.sect_len
) - 1));
322 l
.g
.pl
|= (r
.ppa
>> dev
->ppaf
.pln_offset
) &
323 (((1 << dev
->ppaf
.pln_len
) - 1));
324 l
.g
.lun
|= (r
.ppa
>> dev
->ppaf
.lun_offset
) &
325 (((1 << dev
->ppaf
.lun_len
) - 1));
326 l
.g
.ch
|= (r
.ppa
>> dev
->ppaf
.ch_offset
) &
327 (((1 << dev
->ppaf
.ch_len
) - 1));
332 static inline int ppa_empty(struct ppa_addr ppa_addr
)
334 return (ppa_addr
.ppa
== ADDR_EMPTY
);
337 static inline void ppa_set_empty(struct ppa_addr
*ppa_addr
)
339 ppa_addr
->ppa
= ADDR_EMPTY
;
342 static inline struct ppa_addr
block_to_ppa(struct nvm_dev
*dev
,
343 struct nvm_block
*blk
)
346 struct nvm_lun
*lun
= blk
->lun
;
349 ppa
.g
.blk
= blk
->id
% dev
->blks_per_lun
;
350 ppa
.g
.lun
= lun
->lun_id
;
351 ppa
.g
.ch
= lun
->chnl_id
;
356 typedef blk_qc_t (nvm_tgt_make_rq_fn
)(struct request_queue
*, struct bio
*);
357 typedef sector_t (nvm_tgt_capacity_fn
)(void *);
358 typedef void *(nvm_tgt_init_fn
)(struct nvm_dev
*, struct gendisk
*, int, int);
359 typedef void (nvm_tgt_exit_fn
)(void *);
361 struct nvm_tgt_type
{
363 unsigned int version
[3];
365 /* target entry points */
366 nvm_tgt_make_rq_fn
*make_rq
;
367 nvm_tgt_capacity_fn
*capacity
;
368 nvm_end_io_fn
*end_io
;
370 /* module-specific init/teardown */
371 nvm_tgt_init_fn
*init
;
372 nvm_tgt_exit_fn
*exit
;
374 /* For internal use */
375 struct list_head list
;
378 extern int nvm_register_target(struct nvm_tgt_type
*);
379 extern void nvm_unregister_target(struct nvm_tgt_type
*);
381 extern void *nvm_dev_dma_alloc(struct nvm_dev
*, gfp_t
, dma_addr_t
*);
382 extern void nvm_dev_dma_free(struct nvm_dev
*, void *, dma_addr_t
);
384 typedef int (nvmm_register_fn
)(struct nvm_dev
*);
385 typedef void (nvmm_unregister_fn
)(struct nvm_dev
*);
386 typedef struct nvm_block
*(nvmm_get_blk_fn
)(struct nvm_dev
*,
387 struct nvm_lun
*, unsigned long);
388 typedef void (nvmm_put_blk_fn
)(struct nvm_dev
*, struct nvm_block
*);
389 typedef int (nvmm_open_blk_fn
)(struct nvm_dev
*, struct nvm_block
*);
390 typedef int (nvmm_close_blk_fn
)(struct nvm_dev
*, struct nvm_block
*);
391 typedef void (nvmm_flush_blk_fn
)(struct nvm_dev
*, struct nvm_block
*);
392 typedef int (nvmm_submit_io_fn
)(struct nvm_dev
*, struct nvm_rq
*);
393 typedef int (nvmm_erase_blk_fn
)(struct nvm_dev
*, struct nvm_block
*,
395 typedef struct nvm_lun
*(nvmm_get_lun_fn
)(struct nvm_dev
*, int);
396 typedef void (nvmm_lun_info_print_fn
)(struct nvm_dev
*);
400 unsigned int version
[3];
402 nvmm_register_fn
*register_mgr
;
403 nvmm_unregister_fn
*unregister_mgr
;
405 /* Block administration callbacks */
406 nvmm_get_blk_fn
*get_blk
;
407 nvmm_put_blk_fn
*put_blk
;
408 nvmm_open_blk_fn
*open_blk
;
409 nvmm_close_blk_fn
*close_blk
;
410 nvmm_flush_blk_fn
*flush_blk
;
412 nvmm_submit_io_fn
*submit_io
;
413 nvmm_erase_blk_fn
*erase_blk
;
415 /* Configuration management */
416 nvmm_get_lun_fn
*get_lun
;
419 nvmm_lun_info_print_fn
*lun_info_print
;
420 struct list_head list
;
423 extern int nvm_register_mgr(struct nvmm_type
*);
424 extern void nvm_unregister_mgr(struct nvmm_type
*);
426 extern struct nvm_block
*nvm_get_blk(struct nvm_dev
*, struct nvm_lun
*,
428 extern void nvm_put_blk(struct nvm_dev
*, struct nvm_block
*);
430 extern int nvm_register(struct request_queue
*, char *,
431 struct nvm_dev_ops
*);
432 extern void nvm_unregister(char *);
434 extern int nvm_submit_io(struct nvm_dev
*, struct nvm_rq
*);
435 extern void nvm_generic_to_addr_mode(struct nvm_dev
*, struct nvm_rq
*);
436 extern void nvm_addr_to_generic_mode(struct nvm_dev
*, struct nvm_rq
*);
437 extern int nvm_set_rqd_ppalist(struct nvm_dev
*, struct nvm_rq
*,
438 struct ppa_addr
*, int);
439 extern void nvm_free_rqd_ppalist(struct nvm_dev
*, struct nvm_rq
*);
440 extern int nvm_erase_ppa(struct nvm_dev
*, struct ppa_addr
*, int);
441 extern int nvm_erase_blk(struct nvm_dev
*, struct nvm_block
*);
442 extern void nvm_end_io(struct nvm_rq
*, int);
443 #else /* CONFIG_NVM */
446 static inline int nvm_register(struct request_queue
*q
, char *disk_name
,
447 struct nvm_dev_ops
*ops
)
451 static inline void nvm_unregister(char *disk_name
) {}
452 #endif /* CONFIG_NVM */
453 #endif /* LIGHTNVM.H */
This page took 0.056843 seconds and 6 git commands to generate.