Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1 | #ifndef NVM_H |
| 2 | #define NVM_H |
| 3 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 4 | #include <linux/types.h> |
| 5 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 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 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 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) |
| 21 | #define NVM_CH_BITS (8) |
| 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; |
| 33 | } g; |
| 34 | |
| 35 | u64 ppa; |
| 36 | }; |
| 37 | }; |
| 38 | |
| 39 | struct nvm_rq; |
| 40 | struct nvm_id; |
| 41 | struct nvm_dev; |
| 42 | |
| 43 | typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *); |
| 44 | typedef int (nvm_bb_update_fn)(struct ppa_addr, int, u8 *, void *); |
| 45 | typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *); |
| 46 | typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32, |
| 47 | nvm_l2p_update_fn *, void *); |
| 48 | typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, int, |
| 49 | nvm_bb_update_fn *, void *); |
| 50 | typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct nvm_rq *, int); |
| 51 | typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); |
| 52 | typedef int (nvm_erase_blk_fn)(struct nvm_dev *, struct nvm_rq *); |
| 53 | typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *); |
| 54 | typedef void (nvm_destroy_dma_pool_fn)(void *); |
| 55 | typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t, |
| 56 | dma_addr_t *); |
| 57 | typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t); |
| 58 | |
| 59 | struct nvm_dev_ops { |
| 60 | nvm_id_fn *identity; |
| 61 | nvm_get_l2p_tbl_fn *get_l2p_tbl; |
| 62 | nvm_op_bb_tbl_fn *get_bb_tbl; |
| 63 | nvm_op_set_bb_fn *set_bb_tbl; |
| 64 | |
| 65 | nvm_submit_io_fn *submit_io; |
| 66 | nvm_erase_blk_fn *erase_block; |
| 67 | |
| 68 | nvm_create_dma_pool_fn *create_dma_pool; |
| 69 | nvm_destroy_dma_pool_fn *destroy_dma_pool; |
| 70 | nvm_dev_dma_alloc_fn *dev_dma_alloc; |
| 71 | nvm_dev_dma_free_fn *dev_dma_free; |
| 72 | |
| 73 | unsigned int max_phys_sect; |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 78 | #ifdef CONFIG_NVM |
| 79 | |
| 80 | #include <linux/blkdev.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 81 | #include <linux/file.h> |
| 82 | #include <linux/dmapool.h> |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 83 | #include <uapi/linux/lightnvm.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 84 | |
| 85 | enum { |
| 86 | /* HW Responsibilities */ |
| 87 | NVM_RSP_L2P = 1 << 0, |
| 88 | NVM_RSP_ECC = 1 << 1, |
| 89 | |
| 90 | /* Physical Adressing Mode */ |
| 91 | NVM_ADDRMODE_LINEAR = 0, |
| 92 | NVM_ADDRMODE_CHANNEL = 1, |
| 93 | |
| 94 | /* Plane programming mode for LUN */ |
| 95 | NVM_PLANE_SINGLE = 0, |
| 96 | NVM_PLANE_DOUBLE = 1, |
| 97 | NVM_PLANE_QUAD = 2, |
| 98 | |
| 99 | /* Status codes */ |
| 100 | NVM_RSP_SUCCESS = 0x0, |
| 101 | NVM_RSP_NOT_CHANGEABLE = 0x1, |
| 102 | NVM_RSP_ERR_FAILWRITE = 0x40ff, |
| 103 | NVM_RSP_ERR_EMPTYPAGE = 0x42ff, |
| 104 | |
| 105 | /* Device opcodes */ |
| 106 | NVM_OP_HBREAD = 0x02, |
| 107 | NVM_OP_HBWRITE = 0x81, |
| 108 | NVM_OP_PWRITE = 0x91, |
| 109 | NVM_OP_PREAD = 0x92, |
| 110 | NVM_OP_ERASE = 0x90, |
| 111 | |
| 112 | /* PPA Command Flags */ |
| 113 | NVM_IO_SNGL_ACCESS = 0x0, |
| 114 | NVM_IO_DUAL_ACCESS = 0x1, |
| 115 | NVM_IO_QUAD_ACCESS = 0x2, |
| 116 | |
Matias Bjørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 117 | /* NAND Access Modes */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 118 | NVM_IO_SUSPEND = 0x80, |
| 119 | NVM_IO_SLC_MODE = 0x100, |
| 120 | NVM_IO_SCRAMBLE_DISABLE = 0x200, |
Matias Bjørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 121 | |
| 122 | /* Block Types */ |
| 123 | NVM_BLK_T_FREE = 0x0, |
| 124 | NVM_BLK_T_BAD = 0x1, |
Matias Bjørling | b5d4acd | 2016-01-12 07:49:32 +0100 | [diff] [blame] | 125 | NVM_BLK_T_GRWN_BAD = 0x2, |
| 126 | NVM_BLK_T_DEV = 0x4, |
| 127 | NVM_BLK_T_HOST = 0x8, |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 128 | |
| 129 | /* Memory capabilities */ |
| 130 | NVM_ID_CAP_SLC = 0x1, |
| 131 | NVM_ID_CAP_CMD_SUSPEND = 0x2, |
| 132 | NVM_ID_CAP_SCRAMBLE = 0x4, |
| 133 | NVM_ID_CAP_ENCRYPT = 0x8, |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 134 | |
| 135 | /* Memory types */ |
| 136 | NVM_ID_FMTYPE_SLC = 0, |
| 137 | NVM_ID_FMTYPE_MLC = 1, |
| 138 | }; |
| 139 | |
| 140 | struct nvm_id_lp_mlc { |
| 141 | u16 num_pairs; |
| 142 | u8 pairs[886]; |
| 143 | }; |
| 144 | |
| 145 | struct nvm_id_lp_tbl { |
| 146 | __u8 id[8]; |
| 147 | struct nvm_id_lp_mlc mlc; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | struct nvm_id_group { |
| 151 | u8 mtype; |
| 152 | u8 fmtype; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 153 | u8 num_ch; |
| 154 | u8 num_lun; |
| 155 | u8 num_pln; |
| 156 | u16 num_blk; |
| 157 | u16 num_pg; |
| 158 | u16 fpg_sz; |
| 159 | u16 csecs; |
| 160 | u16 sos; |
| 161 | u32 trdt; |
| 162 | u32 trdm; |
| 163 | u32 tprt; |
| 164 | u32 tprm; |
| 165 | u32 tbet; |
| 166 | u32 tbem; |
| 167 | u32 mpos; |
Matias Bjørling | 12be5ed | 2015-11-16 15:34:39 +0100 | [diff] [blame] | 168 | u32 mccap; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 169 | u16 cpar; |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 170 | |
| 171 | struct nvm_id_lp_tbl lptbl; |
Matias Bjørling | 73387e7 | 2015-11-16 15:34:40 +0100 | [diff] [blame] | 172 | }; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 173 | |
| 174 | struct nvm_addr_format { |
| 175 | u8 ch_offset; |
| 176 | u8 ch_len; |
| 177 | u8 lun_offset; |
| 178 | u8 lun_len; |
| 179 | u8 pln_offset; |
| 180 | u8 pln_len; |
| 181 | u8 blk_offset; |
| 182 | u8 blk_len; |
| 183 | u8 pg_offset; |
| 184 | u8 pg_len; |
| 185 | u8 sect_offset; |
| 186 | u8 sect_len; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | struct nvm_id { |
| 190 | u8 ver_id; |
| 191 | u8 vmnt; |
| 192 | u8 cgrps; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 193 | u32 cap; |
| 194 | u32 dom; |
| 195 | struct nvm_addr_format ppaf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 196 | struct nvm_id_group groups[4]; |
| 197 | } __packed; |
| 198 | |
| 199 | struct nvm_target { |
| 200 | struct list_head list; |
| 201 | struct nvm_tgt_type *type; |
| 202 | struct gendisk *disk; |
| 203 | }; |
| 204 | |
| 205 | struct nvm_tgt_instance { |
| 206 | struct nvm_tgt_type *tt; |
| 207 | }; |
| 208 | |
| 209 | #define ADDR_EMPTY (~0ULL) |
| 210 | |
| 211 | #define NVM_VERSION_MAJOR 1 |
| 212 | #define NVM_VERSION_MINOR 0 |
| 213 | #define NVM_VERSION_PATCH 0 |
| 214 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 215 | struct nvm_rq; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 216 | typedef void (nvm_end_io_fn)(struct nvm_rq *); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 217 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 218 | struct nvm_rq { |
| 219 | struct nvm_tgt_instance *ins; |
| 220 | struct nvm_dev *dev; |
| 221 | |
| 222 | struct bio *bio; |
| 223 | |
| 224 | union { |
| 225 | struct ppa_addr ppa_addr; |
| 226 | dma_addr_t dma_ppa_list; |
| 227 | }; |
| 228 | |
| 229 | struct ppa_addr *ppa_list; |
| 230 | |
| 231 | void *metadata; |
| 232 | dma_addr_t dma_metadata; |
| 233 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 234 | struct completion *wait; |
| 235 | nvm_end_io_fn *end_io; |
| 236 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 237 | uint8_t opcode; |
| 238 | uint16_t nr_pages; |
| 239 | uint16_t flags; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 240 | |
| 241 | int error; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu) |
| 245 | { |
| 246 | return pdu - sizeof(struct nvm_rq); |
| 247 | } |
| 248 | |
| 249 | static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata) |
| 250 | { |
| 251 | return rqdata + 1; |
| 252 | } |
| 253 | |
| 254 | struct nvm_block; |
| 255 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 256 | struct nvm_lun { |
| 257 | int id; |
| 258 | |
| 259 | int lun_id; |
| 260 | int chnl_id; |
| 261 | |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 262 | /* It is up to the target to mark blocks as closed. If the target does |
| 263 | * not do it, all blocks are marked as open, and nr_open_blocks |
| 264 | * represents the number of blocks in use |
| 265 | */ |
| 266 | unsigned int nr_open_blocks; /* Number of used, writable blocks */ |
| 267 | unsigned int nr_closed_blocks; /* Number of used, read-only blocks */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 268 | unsigned int nr_free_blocks; /* Number of unused blocks */ |
Javier Gonzalez | 0b59733 | 2015-11-20 13:47:56 +0100 | [diff] [blame] | 269 | unsigned int nr_bad_blocks; /* Number of bad blocks */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 270 | |
| 271 | spinlock_t lock; |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 272 | |
| 273 | struct nvm_block *blocks; |
| 274 | }; |
| 275 | |
| 276 | enum { |
| 277 | NVM_BLK_ST_FREE = 0x1, /* Free block */ |
| 278 | NVM_BLK_ST_OPEN = 0x2, /* Open block - read-write */ |
| 279 | NVM_BLK_ST_CLOSED = 0x4, /* Closed block - read-only */ |
| 280 | NVM_BLK_ST_BAD = 0x8, /* Bad block */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | struct nvm_block { |
| 284 | struct list_head list; |
| 285 | struct nvm_lun *lun; |
| 286 | unsigned long id; |
| 287 | |
| 288 | void *priv; |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 289 | int state; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 290 | }; |
| 291 | |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 292 | /* system block cpu representation */ |
| 293 | struct nvm_sb_info { |
| 294 | unsigned long seqnr; |
| 295 | unsigned long erase_cnt; |
| 296 | unsigned int version; |
| 297 | char mmtype[NVM_MMTYPE_LEN]; |
| 298 | struct ppa_addr fs_ppa; |
| 299 | }; |
| 300 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 301 | struct nvm_dev { |
| 302 | struct nvm_dev_ops *ops; |
| 303 | |
| 304 | struct list_head devices; |
| 305 | struct list_head online_targets; |
| 306 | |
| 307 | /* Media manager */ |
| 308 | struct nvmm_type *mt; |
| 309 | void *mp; |
| 310 | |
Matias Bjørling | b769207 | 2016-01-12 07:49:38 +0100 | [diff] [blame] | 311 | /* System blocks */ |
| 312 | struct nvm_sb_info sb; |
| 313 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 314 | /* Device information */ |
| 315 | int nr_chnls; |
| 316 | int nr_planes; |
| 317 | int luns_per_chnl; |
| 318 | int sec_per_pg; /* only sectors for a single page */ |
| 319 | int pgs_per_blk; |
| 320 | int blks_per_lun; |
| 321 | int sec_size; |
| 322 | int oob_size; |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 323 | int mccap; |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 324 | struct nvm_addr_format ppaf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 325 | |
| 326 | /* Calculated/Cached values. These do not reflect the actual usable |
| 327 | * blocks at run-time. |
| 328 | */ |
| 329 | int max_rq_size; |
| 330 | int plane_mode; /* drive device in single, double or quad mode */ |
| 331 | |
| 332 | int sec_per_pl; /* all sectors across planes */ |
| 333 | int sec_per_blk; |
| 334 | int sec_per_lun; |
| 335 | |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 336 | /* lower page table */ |
| 337 | int lps_per_blk; |
| 338 | int *lptbl; |
| 339 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 340 | unsigned long total_pages; |
| 341 | unsigned long total_blocks; |
| 342 | int nr_luns; |
| 343 | unsigned max_pages_per_blk; |
| 344 | |
| 345 | void *ppalist_pool; |
| 346 | |
| 347 | struct nvm_id identity; |
| 348 | |
| 349 | /* Backend device */ |
| 350 | struct request_queue *q; |
| 351 | char name[DISK_NAME_LEN]; |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 352 | |
| 353 | struct mutex mlock; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 354 | }; |
| 355 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 356 | static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev, |
| 357 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 358 | { |
| 359 | struct ppa_addr l; |
| 360 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 361 | l.ppa = ((u64)r.g.blk) << dev->ppaf.blk_offset; |
| 362 | l.ppa |= ((u64)r.g.pg) << dev->ppaf.pg_offset; |
| 363 | l.ppa |= ((u64)r.g.sec) << dev->ppaf.sect_offset; |
| 364 | l.ppa |= ((u64)r.g.pl) << dev->ppaf.pln_offset; |
| 365 | l.ppa |= ((u64)r.g.lun) << dev->ppaf.lun_offset; |
| 366 | l.ppa |= ((u64)r.g.ch) << dev->ppaf.ch_offset; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 367 | |
| 368 | return l; |
| 369 | } |
| 370 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 371 | static inline struct ppa_addr dev_to_generic_addr(struct nvm_dev *dev, |
| 372 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 373 | { |
| 374 | struct ppa_addr l; |
| 375 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 376 | /* |
| 377 | * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc. |
| 378 | */ |
| 379 | l.g.blk = (r.ppa >> dev->ppaf.blk_offset) & |
| 380 | (((1 << dev->ppaf.blk_len) - 1)); |
| 381 | l.g.pg |= (r.ppa >> dev->ppaf.pg_offset) & |
| 382 | (((1 << dev->ppaf.pg_len) - 1)); |
| 383 | l.g.sec |= (r.ppa >> dev->ppaf.sect_offset) & |
| 384 | (((1 << dev->ppaf.sect_len) - 1)); |
| 385 | l.g.pl |= (r.ppa >> dev->ppaf.pln_offset) & |
| 386 | (((1 << dev->ppaf.pln_len) - 1)); |
| 387 | l.g.lun |= (r.ppa >> dev->ppaf.lun_offset) & |
| 388 | (((1 << dev->ppaf.lun_len) - 1)); |
| 389 | l.g.ch |= (r.ppa >> dev->ppaf.ch_offset) & |
| 390 | (((1 << dev->ppaf.ch_len) - 1)); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 391 | |
| 392 | return l; |
| 393 | } |
| 394 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 395 | static inline int ppa_empty(struct ppa_addr ppa_addr) |
| 396 | { |
| 397 | return (ppa_addr.ppa == ADDR_EMPTY); |
| 398 | } |
| 399 | |
| 400 | static inline void ppa_set_empty(struct ppa_addr *ppa_addr) |
| 401 | { |
| 402 | ppa_addr->ppa = ADDR_EMPTY; |
| 403 | } |
| 404 | |
| 405 | static inline struct ppa_addr block_to_ppa(struct nvm_dev *dev, |
| 406 | struct nvm_block *blk) |
| 407 | { |
| 408 | struct ppa_addr ppa; |
| 409 | struct nvm_lun *lun = blk->lun; |
| 410 | |
| 411 | ppa.ppa = 0; |
| 412 | ppa.g.blk = blk->id % dev->blks_per_lun; |
| 413 | ppa.g.lun = lun->lun_id; |
| 414 | ppa.g.ch = lun->chnl_id; |
| 415 | |
| 416 | return ppa; |
| 417 | } |
| 418 | |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 419 | static inline int ppa_to_slc(struct nvm_dev *dev, int slc_pg) |
| 420 | { |
| 421 | return dev->lptbl[slc_pg]; |
| 422 | } |
| 423 | |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 424 | typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 425 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 426 | typedef void *(nvm_tgt_init_fn)(struct nvm_dev *, struct gendisk *, int, int); |
| 427 | typedef void (nvm_tgt_exit_fn)(void *); |
| 428 | |
| 429 | struct nvm_tgt_type { |
| 430 | const char *name; |
| 431 | unsigned int version[3]; |
| 432 | |
| 433 | /* target entry points */ |
| 434 | nvm_tgt_make_rq_fn *make_rq; |
| 435 | nvm_tgt_capacity_fn *capacity; |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 436 | nvm_end_io_fn *end_io; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 437 | |
| 438 | /* module-specific init/teardown */ |
| 439 | nvm_tgt_init_fn *init; |
| 440 | nvm_tgt_exit_fn *exit; |
| 441 | |
| 442 | /* For internal use */ |
| 443 | struct list_head list; |
| 444 | }; |
| 445 | |
| 446 | extern int nvm_register_target(struct nvm_tgt_type *); |
| 447 | extern void nvm_unregister_target(struct nvm_tgt_type *); |
| 448 | |
| 449 | extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); |
| 450 | extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); |
| 451 | |
| 452 | typedef int (nvmm_register_fn)(struct nvm_dev *); |
| 453 | typedef void (nvmm_unregister_fn)(struct nvm_dev *); |
| 454 | typedef struct nvm_block *(nvmm_get_blk_fn)(struct nvm_dev *, |
| 455 | struct nvm_lun *, unsigned long); |
| 456 | typedef void (nvmm_put_blk_fn)(struct nvm_dev *, struct nvm_block *); |
| 457 | typedef int (nvmm_open_blk_fn)(struct nvm_dev *, struct nvm_block *); |
| 458 | typedef int (nvmm_close_blk_fn)(struct nvm_dev *, struct nvm_block *); |
| 459 | typedef void (nvmm_flush_blk_fn)(struct nvm_dev *, struct nvm_block *); |
| 460 | typedef int (nvmm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 461 | typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, |
| 462 | unsigned long); |
| 463 | typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int); |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 464 | typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 465 | |
| 466 | struct nvmm_type { |
| 467 | const char *name; |
| 468 | unsigned int version[3]; |
| 469 | |
| 470 | nvmm_register_fn *register_mgr; |
| 471 | nvmm_unregister_fn *unregister_mgr; |
| 472 | |
| 473 | /* Block administration callbacks */ |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 474 | nvmm_get_blk_fn *get_blk_unlocked; |
| 475 | nvmm_put_blk_fn *put_blk_unlocked; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 476 | nvmm_get_blk_fn *get_blk; |
| 477 | nvmm_put_blk_fn *put_blk; |
| 478 | nvmm_open_blk_fn *open_blk; |
| 479 | nvmm_close_blk_fn *close_blk; |
| 480 | nvmm_flush_blk_fn *flush_blk; |
| 481 | |
| 482 | nvmm_submit_io_fn *submit_io; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 483 | nvmm_erase_blk_fn *erase_blk; |
| 484 | |
| 485 | /* Configuration management */ |
| 486 | nvmm_get_lun_fn *get_lun; |
| 487 | |
| 488 | /* Statistics */ |
Javier Gonzalez | 2fde0e4 | 2015-11-20 13:47:57 +0100 | [diff] [blame] | 489 | nvmm_lun_info_print_fn *lun_info_print; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 490 | struct list_head list; |
| 491 | }; |
| 492 | |
| 493 | extern int nvm_register_mgr(struct nvmm_type *); |
| 494 | extern void nvm_unregister_mgr(struct nvmm_type *); |
| 495 | |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 496 | extern struct nvm_block *nvm_get_blk_unlocked(struct nvm_dev *, |
| 497 | struct nvm_lun *, unsigned long); |
| 498 | extern void nvm_put_blk_unlocked(struct nvm_dev *, struct nvm_block *); |
| 499 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 500 | extern struct nvm_block *nvm_get_blk(struct nvm_dev *, struct nvm_lun *, |
| 501 | unsigned long); |
| 502 | extern void nvm_put_blk(struct nvm_dev *, struct nvm_block *); |
| 503 | |
| 504 | extern int nvm_register(struct request_queue *, char *, |
| 505 | struct nvm_dev_ops *); |
| 506 | extern void nvm_unregister(char *); |
| 507 | |
| 508 | extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *); |
Matias Bjørling | 069368e | 2016-01-12 07:49:19 +0100 | [diff] [blame] | 509 | extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *); |
| 510 | extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *); |
Matias Bjørling | abd805e | 2016-01-12 07:49:20 +0100 | [diff] [blame] | 511 | extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *, |
| 512 | struct ppa_addr *, int); |
| 513 | extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *); |
Matias Bjørling | 81e681d | 2016-01-12 07:49:28 +0100 | [diff] [blame] | 514 | extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr *, int); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 515 | extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 516 | extern void nvm_end_io(struct nvm_rq *, int); |
Matias Bjørling | 09719b6 | 2016-01-12 07:49:30 +0100 | [diff] [blame] | 517 | extern int nvm_submit_ppa(struct nvm_dev *, struct ppa_addr *, int, int, int, |
| 518 | void *, int); |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 519 | |
| 520 | /* sysblk.c */ |
| 521 | #define NVM_SYSBLK_MAGIC 0x4E564D53 /* "NVMS" */ |
| 522 | |
| 523 | /* system block on disk representation */ |
| 524 | struct nvm_system_block { |
| 525 | __be32 magic; /* magic signature */ |
| 526 | __be32 seqnr; /* sequence number */ |
| 527 | __be32 erase_cnt; /* erase count */ |
| 528 | __be16 version; /* version number */ |
| 529 | u8 mmtype[NVM_MMTYPE_LEN]; /* media manager name */ |
| 530 | __be64 fs_ppa; /* PPA for media manager |
| 531 | * superblock */ |
| 532 | }; |
| 533 | |
| 534 | extern int nvm_get_sysblock(struct nvm_dev *, struct nvm_sb_info *); |
| 535 | extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *); |
| 536 | extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *); |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 537 | |
| 538 | extern int nvm_dev_factory(struct nvm_dev *, int flags); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 539 | #else /* CONFIG_NVM */ |
| 540 | struct nvm_dev_ops; |
| 541 | |
| 542 | static inline int nvm_register(struct request_queue *q, char *disk_name, |
| 543 | struct nvm_dev_ops *ops) |
| 544 | { |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | static inline void nvm_unregister(char *disk_name) {} |
| 548 | #endif /* CONFIG_NVM */ |
| 549 | #endif /* LIGHTNVM.H */ |