Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 1 | #ifndef NVM_H |
| 2 | #define NVM_H |
| 3 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 4 | #include <linux/blkdev.h> |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 5 | #include <linux/types.h> |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 6 | #include <uapi/linux/lightnvm.h> |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 7 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 8 | enum { |
| 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 Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 18 | #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ørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 23 | #define NVM_CH_BITS (7) |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 24 | |
| 25 | struct 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ørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 35 | u64 reserved : 1; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 36 | } g; |
| 37 | |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 38 | struct { |
| 39 | u64 line : 63; |
| 40 | u64 is_cached : 1; |
| 41 | } c; |
| 42 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 43 | u64 ppa; |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | struct nvm_rq; |
| 48 | struct nvm_id; |
| 49 | struct nvm_dev; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 50 | struct nvm_tgt_dev; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 51 | |
| 52 | typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *); |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 53 | typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *); |
| 54 | typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32, |
| 55 | nvm_l2p_update_fn *, void *); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 56 | typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *); |
Matias Bjørling | 00ee6cc | 2016-05-06 20:03:09 +0200 | [diff] [blame] | 57 | typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int); |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 58 | typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 59 | typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *); |
| 60 | typedef void (nvm_destroy_dma_pool_fn)(void *); |
| 61 | typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t, |
| 62 | dma_addr_t *); |
| 63 | typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t); |
| 64 | |
| 65 | struct 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; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 72 | |
| 73 | nvm_create_dma_pool_fn *create_dma_pool; |
| 74 | nvm_destroy_dma_pool_fn *destroy_dma_pool; |
| 75 | nvm_dev_dma_alloc_fn *dev_dma_alloc; |
| 76 | nvm_dev_dma_free_fn *dev_dma_free; |
| 77 | |
| 78 | unsigned int max_phys_sect; |
| 79 | }; |
| 80 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 81 | #ifdef CONFIG_NVM |
| 82 | |
| 83 | #include <linux/blkdev.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 84 | #include <linux/file.h> |
| 85 | #include <linux/dmapool.h> |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 86 | #include <uapi/linux/lightnvm.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 87 | |
| 88 | enum { |
| 89 | /* HW Responsibilities */ |
| 90 | NVM_RSP_L2P = 1 << 0, |
| 91 | NVM_RSP_ECC = 1 << 1, |
| 92 | |
| 93 | /* Physical Adressing Mode */ |
| 94 | NVM_ADDRMODE_LINEAR = 0, |
| 95 | NVM_ADDRMODE_CHANNEL = 1, |
| 96 | |
| 97 | /* Plane programming mode for LUN */ |
Matias Bjørling | d5bdec8 | 2016-02-19 13:56:58 +0100 | [diff] [blame] | 98 | NVM_PLANE_SINGLE = 1, |
| 99 | NVM_PLANE_DOUBLE = 2, |
| 100 | NVM_PLANE_QUAD = 4, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 101 | |
| 102 | /* Status codes */ |
| 103 | NVM_RSP_SUCCESS = 0x0, |
| 104 | NVM_RSP_NOT_CHANGEABLE = 0x1, |
| 105 | NVM_RSP_ERR_FAILWRITE = 0x40ff, |
| 106 | NVM_RSP_ERR_EMPTYPAGE = 0x42ff, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 107 | NVM_RSP_ERR_FAILECC = 0x4281, |
Javier González | 38ea2f7 | 2017-01-31 13:17:18 +0100 | [diff] [blame] | 108 | NVM_RSP_ERR_FAILCRC = 0x4004, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 109 | NVM_RSP_WARN_HIGHECC = 0x4700, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 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ørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 123 | /* NAND Access Modes */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 124 | NVM_IO_SUSPEND = 0x80, |
| 125 | NVM_IO_SLC_MODE = 0x100, |
Javier González | a7737f3 | 2017-04-15 20:55:38 +0200 | [diff] [blame] | 126 | NVM_IO_SCRAMBLE_ENABLE = 0x200, |
Matias Bjørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 127 | |
| 128 | /* Block Types */ |
| 129 | NVM_BLK_T_FREE = 0x0, |
| 130 | NVM_BLK_T_BAD = 0x1, |
Matias Bjørling | b5d4acd | 2016-01-12 07:49:32 +0100 | [diff] [blame] | 131 | NVM_BLK_T_GRWN_BAD = 0x2, |
| 132 | NVM_BLK_T_DEV = 0x4, |
| 133 | NVM_BLK_T_HOST = 0x8, |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 134 | |
| 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ørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 140 | |
| 141 | /* Memory types */ |
| 142 | NVM_ID_FMTYPE_SLC = 0, |
| 143 | NVM_ID_FMTYPE_MLC = 1, |
Matias Bjørling | bf64318 | 2016-02-04 15:13:27 +0100 | [diff] [blame] | 144 | |
| 145 | /* Device capabilities */ |
| 146 | NVM_ID_DCAP_BBLKMGMT = 0x1, |
| 147 | NVM_UD_DCAP_ECC = 0x2, |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | struct nvm_id_lp_mlc { |
| 151 | u16 num_pairs; |
| 152 | u8 pairs[886]; |
| 153 | }; |
| 154 | |
| 155 | struct nvm_id_lp_tbl { |
| 156 | __u8 id[8]; |
| 157 | struct nvm_id_lp_mlc mlc; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct nvm_id_group { |
| 161 | u8 mtype; |
| 162 | u8 fmtype; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 163 | 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ørling | 12be5ed | 2015-11-16 15:34:39 +0100 | [diff] [blame] | 178 | u32 mccap; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 179 | u16 cpar; |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 180 | |
| 181 | struct nvm_id_lp_tbl lptbl; |
Matias Bjørling | 73387e7 | 2015-11-16 15:34:40 +0100 | [diff] [blame] | 182 | }; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 183 | |
| 184 | struct 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ørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | struct nvm_id { |
| 200 | u8 ver_id; |
| 201 | u8 vmnt; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 202 | u32 cap; |
| 203 | u32 dom; |
| 204 | struct nvm_addr_format ppaf; |
Matias Bjørling | 19bd6fe | 2017-01-31 13:17:15 +0100 | [diff] [blame] | 205 | struct nvm_id_group grp; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 206 | } __packed; |
| 207 | |
| 208 | struct nvm_target { |
| 209 | struct list_head list; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 210 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 211 | struct nvm_tgt_type *type; |
| 212 | struct gendisk *disk; |
| 213 | }; |
| 214 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 215 | #define ADDR_EMPTY (~0ULL) |
| 216 | |
| 217 | #define NVM_VERSION_MAJOR 1 |
| 218 | #define NVM_VERSION_MINOR 0 |
| 219 | #define NVM_VERSION_PATCH 0 |
| 220 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 221 | struct nvm_rq; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 222 | typedef void (nvm_end_io_fn)(struct nvm_rq *); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 223 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 224 | struct nvm_rq { |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 225 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 226 | |
| 227 | struct bio *bio; |
| 228 | |
| 229 | union { |
| 230 | struct ppa_addr ppa_addr; |
| 231 | dma_addr_t dma_ppa_list; |
| 232 | }; |
| 233 | |
| 234 | struct ppa_addr *ppa_list; |
| 235 | |
Javier González | 003fad3 | 2016-05-06 20:03:12 +0200 | [diff] [blame] | 236 | void *meta_list; |
| 237 | dma_addr_t dma_meta_list; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 238 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 239 | struct completion *wait; |
| 240 | nvm_end_io_fn *end_io; |
| 241 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 242 | uint8_t opcode; |
Javier González | 6d5be95 | 2016-05-06 20:03:20 +0200 | [diff] [blame] | 243 | uint16_t nr_ppas; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 244 | uint16_t flags; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 245 | |
Matias Bjorling | 9f86726 | 2016-03-03 15:06:39 +0100 | [diff] [blame] | 246 | u64 ppa_status; /* ppa media status */ |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 247 | int error; |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 248 | |
| 249 | void *private; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu) |
| 253 | { |
| 254 | return pdu - sizeof(struct nvm_rq); |
| 255 | } |
| 256 | |
| 257 | static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata) |
| 258 | { |
| 259 | return rqdata + 1; |
| 260 | } |
| 261 | |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 262 | enum { |
| 263 | NVM_BLK_ST_FREE = 0x1, /* Free block */ |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 264 | NVM_BLK_ST_TGT = 0x2, /* Block in use by target */ |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 265 | NVM_BLK_ST_BAD = 0x8, /* Bad block */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 266 | }; |
| 267 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 268 | /* Device generic information */ |
| 269 | struct nvm_geo { |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 270 | int nr_chnls; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 271 | int nr_luns; |
| 272 | int luns_per_chnl; /* -1 if channels are not symmetric */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 273 | int nr_planes; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 274 | int sec_per_pg; /* only sectors for a single page */ |
| 275 | int pgs_per_blk; |
| 276 | int blks_per_lun; |
Matias Bjørling | 4891d12 | 2016-05-06 20:02:57 +0200 | [diff] [blame] | 277 | int fpg_size; |
| 278 | int pfpg_size; /* size of buffer if all pages are to be read */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 279 | int sec_size; |
| 280 | int oob_size; |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 281 | int mccap; |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 282 | struct nvm_addr_format ppaf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 283 | |
| 284 | /* Calculated/Cached values. These do not reflect the actual usable |
| 285 | * blocks at run-time. |
| 286 | */ |
| 287 | int max_rq_size; |
| 288 | int plane_mode; /* drive device in single, double or quad mode */ |
| 289 | |
| 290 | int sec_per_pl; /* all sectors across planes */ |
| 291 | int sec_per_blk; |
| 292 | int sec_per_lun; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 293 | }; |
| 294 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 295 | /* sub-device structure */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 296 | struct nvm_tgt_dev { |
| 297 | /* Device information */ |
| 298 | struct nvm_geo geo; |
| 299 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 300 | /* Base ppas for target LUNs */ |
| 301 | struct ppa_addr *luns; |
| 302 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 303 | sector_t total_secs; |
| 304 | |
| 305 | struct nvm_id identity; |
| 306 | struct request_queue *q; |
| 307 | |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 308 | struct nvm_dev *parent; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 309 | void *map; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | struct nvm_dev { |
| 313 | struct nvm_dev_ops *ops; |
| 314 | |
| 315 | struct list_head devices; |
| 316 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 317 | /* Device information */ |
| 318 | struct nvm_geo geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 319 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 320 | /* lower page table */ |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 321 | int lps_per_blk; |
| 322 | int *lptbl; |
| 323 | |
Matias Bjørling | 4ece44a | 2016-02-20 08:52:41 +0100 | [diff] [blame] | 324 | unsigned long total_secs; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 325 | |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 326 | unsigned long *lun_map; |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 327 | void *dma_pool; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 328 | |
| 329 | struct nvm_id identity; |
| 330 | |
| 331 | /* Backend device */ |
| 332 | struct request_queue *q; |
| 333 | char name[DISK_NAME_LEN]; |
Simon A. F. Lund | 40267ef | 2016-09-16 14:25:08 +0200 | [diff] [blame] | 334 | void *private_data; |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 335 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 336 | void *rmap; |
| 337 | |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 338 | struct mutex mlock; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 339 | spinlock_t lock; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 340 | |
| 341 | /* target management */ |
| 342 | struct list_head area_list; |
| 343 | struct list_head targets; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 344 | }; |
| 345 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 346 | static inline struct ppa_addr linear_to_generic_addr(struct nvm_geo *geo, |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 347 | u64 pba) |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 348 | { |
| 349 | struct ppa_addr l; |
| 350 | int secs, pgs, blks, luns; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 351 | sector_t ppa = pba; |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 352 | |
| 353 | l.ppa = 0; |
| 354 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 355 | div_u64_rem(ppa, geo->sec_per_pg, &secs); |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 356 | l.g.sec = secs; |
| 357 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 358 | sector_div(ppa, geo->sec_per_pg); |
| 359 | div_u64_rem(ppa, geo->pgs_per_blk, &pgs); |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 360 | l.g.pg = pgs; |
| 361 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 362 | sector_div(ppa, geo->pgs_per_blk); |
| 363 | div_u64_rem(ppa, geo->blks_per_lun, &blks); |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 364 | l.g.blk = blks; |
| 365 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 366 | sector_div(ppa, geo->blks_per_lun); |
| 367 | div_u64_rem(ppa, geo->luns_per_chnl, &luns); |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 368 | l.g.lun = luns; |
| 369 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 370 | sector_div(ppa, geo->luns_per_chnl); |
Javier González | 0e5c324 | 2016-11-28 22:39:01 +0100 | [diff] [blame] | 371 | l.g.ch = ppa; |
| 372 | |
| 373 | return l; |
| 374 | } |
| 375 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 376 | static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev, |
| 377 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 378 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 379 | struct nvm_geo *geo = &tgt_dev->geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 380 | struct ppa_addr l; |
| 381 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 382 | l.ppa = ((u64)r.g.blk) << geo->ppaf.blk_offset; |
| 383 | l.ppa |= ((u64)r.g.pg) << geo->ppaf.pg_offset; |
| 384 | l.ppa |= ((u64)r.g.sec) << geo->ppaf.sect_offset; |
| 385 | l.ppa |= ((u64)r.g.pl) << geo->ppaf.pln_offset; |
| 386 | l.ppa |= ((u64)r.g.lun) << geo->ppaf.lun_offset; |
| 387 | l.ppa |= ((u64)r.g.ch) << geo->ppaf.ch_offset; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 388 | |
| 389 | return l; |
| 390 | } |
| 391 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 392 | static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev, |
| 393 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 394 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 395 | struct nvm_geo *geo = &tgt_dev->geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 396 | struct ppa_addr l; |
| 397 | |
Javier González | 5389a1d | 2016-07-07 09:54:09 +0200 | [diff] [blame] | 398 | l.ppa = 0; |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 399 | /* |
| 400 | * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc. |
| 401 | */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 402 | l.g.blk = (r.ppa >> geo->ppaf.blk_offset) & |
| 403 | (((1 << geo->ppaf.blk_len) - 1)); |
| 404 | l.g.pg |= (r.ppa >> geo->ppaf.pg_offset) & |
| 405 | (((1 << geo->ppaf.pg_len) - 1)); |
| 406 | l.g.sec |= (r.ppa >> geo->ppaf.sect_offset) & |
| 407 | (((1 << geo->ppaf.sect_len) - 1)); |
| 408 | l.g.pl |= (r.ppa >> geo->ppaf.pln_offset) & |
| 409 | (((1 << geo->ppaf.pln_len) - 1)); |
| 410 | l.g.lun |= (r.ppa >> geo->ppaf.lun_offset) & |
| 411 | (((1 << geo->ppaf.lun_len) - 1)); |
| 412 | l.g.ch |= (r.ppa >> geo->ppaf.ch_offset) & |
| 413 | (((1 << geo->ppaf.ch_len) - 1)); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 414 | |
| 415 | return l; |
| 416 | } |
| 417 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 418 | static inline int ppa_empty(struct ppa_addr ppa_addr) |
| 419 | { |
| 420 | return (ppa_addr.ppa == ADDR_EMPTY); |
| 421 | } |
| 422 | |
| 423 | static inline void ppa_set_empty(struct ppa_addr *ppa_addr) |
| 424 | { |
| 425 | ppa_addr->ppa = ADDR_EMPTY; |
| 426 | } |
| 427 | |
Javier González | a24ba46 | 2016-11-28 22:38:56 +0100 | [diff] [blame] | 428 | static inline int ppa_cmp_blk(struct ppa_addr ppa1, struct ppa_addr ppa2) |
| 429 | { |
| 430 | if (ppa_empty(ppa1) || ppa_empty(ppa2)) |
| 431 | return 0; |
| 432 | |
| 433 | return ((ppa1.g.ch == ppa2.g.ch) && (ppa1.g.lun == ppa2.g.lun) && |
| 434 | (ppa1.g.blk == ppa2.g.blk)); |
| 435 | } |
| 436 | |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 437 | 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] | 438 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
Javier González | 4af3f75 | 2017-04-15 20:55:45 +0200 | [diff] [blame] | 439 | typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *, |
| 440 | int flags); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 441 | typedef void (nvm_tgt_exit_fn)(void *); |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 442 | typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *); |
| 443 | typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 444 | |
| 445 | struct nvm_tgt_type { |
| 446 | const char *name; |
| 447 | unsigned int version[3]; |
| 448 | |
| 449 | /* target entry points */ |
| 450 | nvm_tgt_make_rq_fn *make_rq; |
| 451 | nvm_tgt_capacity_fn *capacity; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 452 | |
| 453 | /* module-specific init/teardown */ |
| 454 | nvm_tgt_init_fn *init; |
| 455 | nvm_tgt_exit_fn *exit; |
| 456 | |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 457 | /* sysfs */ |
| 458 | nvm_tgt_sysfs_init_fn *sysfs_init; |
| 459 | nvm_tgt_sysfs_exit_fn *sysfs_exit; |
| 460 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 461 | /* For internal use */ |
| 462 | struct list_head list; |
| 463 | }; |
| 464 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 465 | extern struct nvm_tgt_type *nvm_find_target_type(const char *, int); |
| 466 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 467 | extern int nvm_register_tgt_type(struct nvm_tgt_type *); |
| 468 | extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 469 | |
| 470 | extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); |
| 471 | extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); |
| 472 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 473 | extern struct nvm_dev *nvm_alloc_dev(int); |
| 474 | extern int nvm_register(struct nvm_dev *); |
| 475 | extern void nvm_unregister(struct nvm_dev *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 476 | |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 477 | extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *, |
| 478 | int, int); |
Javier González | a279006 | 2016-11-28 22:39:12 +0100 | [diff] [blame] | 479 | extern int nvm_max_phys_sects(struct nvm_tgt_dev *); |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 480 | extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *); |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 481 | extern int nvm_erase_sync(struct nvm_tgt_dev *, struct ppa_addr *, int); |
| 482 | extern int nvm_set_rqd_ppalist(struct nvm_tgt_dev *, struct nvm_rq *, |
Matias Bjørling | 8680f16 | 2016-07-07 09:54:22 +0200 | [diff] [blame] | 483 | const struct ppa_addr *, int, int); |
Javier González | 17912c4 | 2017-04-15 20:55:37 +0200 | [diff] [blame] | 484 | extern void nvm_free_rqd_ppalist(struct nvm_tgt_dev *, struct nvm_rq *); |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 485 | extern int nvm_get_l2p_tbl(struct nvm_tgt_dev *, u64, u32, nvm_l2p_update_fn *, |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 486 | void *); |
Javier González | da2d7cb | 2016-11-28 22:39:13 +0100 | [diff] [blame] | 487 | extern int nvm_get_area(struct nvm_tgt_dev *, sector_t *, sector_t); |
| 488 | extern void nvm_put_area(struct nvm_tgt_dev *, sector_t); |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 489 | extern void nvm_end_io(struct nvm_rq *); |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 490 | extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 491 | extern int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr, u8 *); |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 492 | |
Matias Bjørling | 8b4970c | 2016-01-12 07:49:39 +0100 | [diff] [blame] | 493 | extern int nvm_dev_factory(struct nvm_dev *, int flags); |
Matias Bjørling | 5136061 | 2016-05-06 20:03:04 +0200 | [diff] [blame] | 494 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 495 | extern void nvm_part_to_tgt(struct nvm_dev *, sector_t *, int); |
Matias Bjørling | 5136061 | 2016-05-06 20:03:04 +0200 | [diff] [blame] | 496 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 497 | #else /* CONFIG_NVM */ |
| 498 | struct nvm_dev_ops; |
| 499 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 500 | static inline struct nvm_dev *nvm_alloc_dev(int node) |
| 501 | { |
| 502 | return ERR_PTR(-EINVAL); |
| 503 | } |
| 504 | static inline int nvm_register(struct nvm_dev *dev) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 505 | { |
| 506 | return -EINVAL; |
| 507 | } |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 508 | static inline void nvm_unregister(struct nvm_dev *dev) {} |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 509 | #endif /* CONFIG_NVM */ |
| 510 | #endif /* LIGHTNVM.H */ |