Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 2 | #ifndef NVM_H |
| 3 | #define NVM_H |
| 4 | |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 5 | #include <linux/blkdev.h> |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 6 | #include <linux/types.h> |
Matias Bjørling | b76eb20b | 2016-07-07 09:54:16 +0200 | [diff] [blame] | 7 | #include <uapi/linux/lightnvm.h> |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 8 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 9 | enum { |
| 10 | NVM_IO_OK = 0, |
| 11 | NVM_IO_REQUEUE = 1, |
| 12 | NVM_IO_DONE = 2, |
| 13 | NVM_IO_ERR = 3, |
| 14 | |
| 15 | NVM_IOTYPE_NONE = 0, |
| 16 | NVM_IOTYPE_GC = 1, |
| 17 | }; |
| 18 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 19 | #define NVM_BLK_BITS (16) |
| 20 | #define NVM_PG_BITS (16) |
| 21 | #define NVM_SEC_BITS (8) |
| 22 | #define NVM_PL_BITS (8) |
| 23 | #define NVM_LUN_BITS (8) |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 24 | #define NVM_CH_BITS (7) |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 25 | |
| 26 | struct ppa_addr { |
| 27 | /* Generic structure for all addresses */ |
| 28 | union { |
| 29 | struct { |
| 30 | u64 blk : NVM_BLK_BITS; |
| 31 | u64 pg : NVM_PG_BITS; |
| 32 | u64 sec : NVM_SEC_BITS; |
| 33 | u64 pl : NVM_PL_BITS; |
| 34 | u64 lun : NVM_LUN_BITS; |
| 35 | u64 ch : NVM_CH_BITS; |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 36 | u64 reserved : 1; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 37 | } g; |
| 38 | |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 39 | struct { |
| 40 | u64 line : 63; |
| 41 | u64 is_cached : 1; |
| 42 | } c; |
| 43 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 44 | u64 ppa; |
| 45 | }; |
| 46 | }; |
| 47 | |
| 48 | struct nvm_rq; |
| 49 | struct nvm_id; |
| 50 | struct nvm_dev; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 51 | struct nvm_tgt_dev; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 52 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 53 | typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 54 | 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] | 55 | 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] | 56 | typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 57 | typedef int (nvm_submit_io_sync_fn)(struct nvm_dev *, struct nvm_rq *); |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 58 | typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *); |
| 59 | typedef void (nvm_destroy_dma_pool_fn)(void *); |
| 60 | typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t, |
| 61 | dma_addr_t *); |
| 62 | typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t); |
| 63 | |
| 64 | struct nvm_dev_ops { |
| 65 | nvm_id_fn *identity; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 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; |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 70 | nvm_submit_io_sync_fn *submit_io_sync; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 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 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_NVM |
| 81 | |
| 82 | #include <linux/blkdev.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 83 | #include <linux/file.h> |
| 84 | #include <linux/dmapool.h> |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 85 | #include <uapi/linux/lightnvm.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 86 | |
| 87 | enum { |
| 88 | /* HW Responsibilities */ |
| 89 | NVM_RSP_L2P = 1 << 0, |
| 90 | NVM_RSP_ECC = 1 << 1, |
| 91 | |
| 92 | /* Physical Adressing Mode */ |
| 93 | NVM_ADDRMODE_LINEAR = 0, |
| 94 | NVM_ADDRMODE_CHANNEL = 1, |
| 95 | |
| 96 | /* Plane programming mode for LUN */ |
Matias Bjørling | d5bdec8 | 2016-02-19 13:56:58 +0100 | [diff] [blame] | 97 | NVM_PLANE_SINGLE = 1, |
| 98 | NVM_PLANE_DOUBLE = 2, |
| 99 | NVM_PLANE_QUAD = 4, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 100 | |
| 101 | /* Status codes */ |
| 102 | NVM_RSP_SUCCESS = 0x0, |
| 103 | NVM_RSP_NOT_CHANGEABLE = 0x1, |
| 104 | NVM_RSP_ERR_FAILWRITE = 0x40ff, |
| 105 | NVM_RSP_ERR_EMPTYPAGE = 0x42ff, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 106 | NVM_RSP_ERR_FAILECC = 0x4281, |
Javier González | 38ea2f7 | 2017-01-31 13:17:18 +0100 | [diff] [blame] | 107 | NVM_RSP_ERR_FAILCRC = 0x4004, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 108 | NVM_RSP_WARN_HIGHECC = 0x4700, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 109 | |
| 110 | /* Device opcodes */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 111 | NVM_OP_PWRITE = 0x91, |
| 112 | NVM_OP_PREAD = 0x92, |
| 113 | NVM_OP_ERASE = 0x90, |
| 114 | |
| 115 | /* PPA Command Flags */ |
| 116 | NVM_IO_SNGL_ACCESS = 0x0, |
| 117 | NVM_IO_DUAL_ACCESS = 0x1, |
| 118 | NVM_IO_QUAD_ACCESS = 0x2, |
| 119 | |
Matias Bjørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 120 | /* NAND Access Modes */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 121 | NVM_IO_SUSPEND = 0x80, |
| 122 | NVM_IO_SLC_MODE = 0x100, |
Javier González | a7737f3 | 2017-04-15 20:55:38 +0200 | [diff] [blame] | 123 | NVM_IO_SCRAMBLE_ENABLE = 0x200, |
Matias Bjørling | 57b4bd0 | 2015-12-06 11:25:47 +0100 | [diff] [blame] | 124 | |
| 125 | /* Block Types */ |
| 126 | NVM_BLK_T_FREE = 0x0, |
| 127 | NVM_BLK_T_BAD = 0x1, |
Matias Bjørling | b5d4acd | 2016-01-12 07:49:32 +0100 | [diff] [blame] | 128 | NVM_BLK_T_GRWN_BAD = 0x2, |
| 129 | NVM_BLK_T_DEV = 0x4, |
| 130 | NVM_BLK_T_HOST = 0x8, |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 131 | |
| 132 | /* Memory capabilities */ |
| 133 | NVM_ID_CAP_SLC = 0x1, |
| 134 | NVM_ID_CAP_CMD_SUSPEND = 0x2, |
| 135 | NVM_ID_CAP_SCRAMBLE = 0x4, |
| 136 | NVM_ID_CAP_ENCRYPT = 0x8, |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 137 | |
| 138 | /* Memory types */ |
| 139 | NVM_ID_FMTYPE_SLC = 0, |
| 140 | NVM_ID_FMTYPE_MLC = 1, |
Matias Bjørling | bf64318 | 2016-02-04 15:13:27 +0100 | [diff] [blame] | 141 | |
| 142 | /* Device capabilities */ |
| 143 | NVM_ID_DCAP_BBLKMGMT = 0x1, |
| 144 | NVM_UD_DCAP_ECC = 0x2, |
Matias Bjørling | ca5927e | 2016-01-12 07:49:35 +0100 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | struct nvm_id_lp_mlc { |
| 148 | u16 num_pairs; |
| 149 | u8 pairs[886]; |
| 150 | }; |
| 151 | |
| 152 | struct nvm_id_lp_tbl { |
| 153 | __u8 id[8]; |
| 154 | struct nvm_id_lp_mlc mlc; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | struct nvm_id_group { |
| 158 | u8 mtype; |
| 159 | u8 fmtype; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 160 | u8 num_ch; |
| 161 | u8 num_lun; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 162 | u16 num_chk; |
| 163 | u16 clba; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 164 | u16 csecs; |
| 165 | u16 sos; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 166 | |
| 167 | u16 ws_min; |
| 168 | u16 ws_opt; |
| 169 | u16 ws_seq; |
| 170 | u16 ws_per_chk; |
| 171 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 172 | u32 trdt; |
| 173 | u32 trdm; |
| 174 | u32 tprt; |
| 175 | u32 tprm; |
| 176 | u32 tbet; |
| 177 | u32 tbem; |
| 178 | u32 mpos; |
Matias Bjørling | 12be5ed | 2015-11-16 15:34:39 +0100 | [diff] [blame] | 179 | u32 mccap; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 180 | u16 cpar; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 181 | |
| 182 | /* 1.2 compatibility */ |
| 183 | u8 num_pln; |
| 184 | u16 num_pg; |
| 185 | u16 fpg_sz; |
Matias Bjørling | 73387e7 | 2015-11-16 15:34:40 +0100 | [diff] [blame] | 186 | }; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 187 | |
| 188 | struct nvm_addr_format { |
| 189 | u8 ch_offset; |
| 190 | u8 ch_len; |
| 191 | u8 lun_offset; |
| 192 | u8 lun_len; |
| 193 | u8 pln_offset; |
| 194 | u8 pln_len; |
| 195 | u8 blk_offset; |
| 196 | u8 blk_len; |
| 197 | u8 pg_offset; |
| 198 | u8 pg_len; |
| 199 | u8 sect_offset; |
| 200 | u8 sect_len; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | struct nvm_id { |
| 204 | u8 ver_id; |
| 205 | u8 vmnt; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 206 | u32 cap; |
| 207 | u32 dom; |
| 208 | struct nvm_addr_format ppaf; |
Matias Bjørling | 19bd6fe | 2017-01-31 13:17:15 +0100 | [diff] [blame] | 209 | struct nvm_id_group grp; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 210 | } __packed; |
| 211 | |
| 212 | struct nvm_target { |
| 213 | struct list_head list; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 214 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 215 | struct nvm_tgt_type *type; |
| 216 | struct gendisk *disk; |
| 217 | }; |
| 218 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 219 | #define ADDR_EMPTY (~0ULL) |
| 220 | |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 221 | #define NVM_TARGET_DEFAULT_OP (101) |
| 222 | #define NVM_TARGET_MIN_OP (3) |
| 223 | #define NVM_TARGET_MAX_OP (80) |
| 224 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 225 | #define NVM_VERSION_MAJOR 1 |
| 226 | #define NVM_VERSION_MINOR 0 |
| 227 | #define NVM_VERSION_PATCH 0 |
| 228 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 229 | struct nvm_rq; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 230 | typedef void (nvm_end_io_fn)(struct nvm_rq *); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 231 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 232 | struct nvm_rq { |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 233 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 234 | |
| 235 | struct bio *bio; |
| 236 | |
| 237 | union { |
| 238 | struct ppa_addr ppa_addr; |
| 239 | dma_addr_t dma_ppa_list; |
| 240 | }; |
| 241 | |
| 242 | struct ppa_addr *ppa_list; |
| 243 | |
Javier González | 003fad3 | 2016-05-06 20:03:12 +0200 | [diff] [blame] | 244 | void *meta_list; |
| 245 | dma_addr_t dma_meta_list; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 246 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 247 | nvm_end_io_fn *end_io; |
| 248 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 249 | uint8_t opcode; |
Javier González | 6d5be95 | 2016-05-06 20:03:20 +0200 | [diff] [blame] | 250 | uint16_t nr_ppas; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 251 | uint16_t flags; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 252 | |
Matias Bjorling | 9f86726 | 2016-03-03 15:06:39 +0100 | [diff] [blame] | 253 | u64 ppa_status; /* ppa media status */ |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 254 | int error; |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 255 | |
| 256 | void *private; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu) |
| 260 | { |
| 261 | return pdu - sizeof(struct nvm_rq); |
| 262 | } |
| 263 | |
| 264 | static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata) |
| 265 | { |
| 266 | return rqdata + 1; |
| 267 | } |
| 268 | |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 269 | enum { |
| 270 | NVM_BLK_ST_FREE = 0x1, /* Free block */ |
Matias Bjørling | 077d238 | 2016-07-07 09:54:14 +0200 | [diff] [blame] | 271 | NVM_BLK_ST_TGT = 0x2, /* Block in use by target */ |
Javier González | ff0e498 | 2016-01-12 07:49:33 +0100 | [diff] [blame] | 272 | NVM_BLK_ST_BAD = 0x8, /* Bad block */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 273 | }; |
| 274 | |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 275 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 276 | /* Device generic information */ |
| 277 | struct nvm_geo { |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 278 | /* generic geometry */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 279 | int nr_chnls; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 280 | int all_luns; /* across channels */ |
| 281 | int nr_luns; /* per channel */ |
| 282 | int nr_chks; /* per lun */ |
| 283 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 284 | int sec_size; |
| 285 | int oob_size; |
Matias Bjørling | f9a9995 | 2016-01-12 07:49:34 +0100 | [diff] [blame] | 286 | int mccap; |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 287 | |
| 288 | int sec_per_chk; |
| 289 | int sec_per_lun; |
| 290 | |
| 291 | int ws_min; |
| 292 | int ws_opt; |
| 293 | int ws_seq; |
| 294 | int ws_per_chk; |
| 295 | |
| 296 | int max_rq_size; |
| 297 | |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 298 | int op; |
| 299 | |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 300 | struct nvm_addr_format ppaf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 301 | |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 302 | /* Legacy 1.2 specific geometry */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 303 | int plane_mode; /* drive device in single, double or quad mode */ |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 304 | int nr_planes; |
| 305 | int sec_per_pg; /* only sectors for a single page */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 306 | int sec_per_pl; /* all sectors across planes */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 307 | }; |
| 308 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 309 | /* sub-device structure */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 310 | struct nvm_tgt_dev { |
| 311 | /* Device information */ |
| 312 | struct nvm_geo geo; |
| 313 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 314 | /* Base ppas for target LUNs */ |
| 315 | struct ppa_addr *luns; |
| 316 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 317 | sector_t total_secs; |
| 318 | |
| 319 | struct nvm_id identity; |
| 320 | struct request_queue *q; |
| 321 | |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 322 | struct nvm_dev *parent; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 323 | void *map; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | struct nvm_dev { |
| 327 | struct nvm_dev_ops *ops; |
| 328 | |
| 329 | struct list_head devices; |
| 330 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 331 | /* Device information */ |
| 332 | struct nvm_geo geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 333 | |
Matias Bjørling | 4ece44a | 2016-02-20 08:52:41 +0100 | [diff] [blame] | 334 | unsigned long total_secs; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 335 | |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 336 | unsigned long *lun_map; |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 337 | void *dma_pool; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 338 | |
| 339 | struct nvm_id identity; |
| 340 | |
| 341 | /* Backend device */ |
| 342 | struct request_queue *q; |
| 343 | char name[DISK_NAME_LEN]; |
Simon A. F. Lund | 40267ef | 2016-09-16 14:25:08 +0200 | [diff] [blame] | 344 | void *private_data; |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 345 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 346 | void *rmap; |
| 347 | |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 348 | struct mutex mlock; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 349 | spinlock_t lock; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 350 | |
| 351 | /* target management */ |
| 352 | struct list_head area_list; |
| 353 | struct list_head targets; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 354 | }; |
| 355 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 356 | static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev, |
| 357 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 358 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 359 | struct nvm_geo *geo = &tgt_dev->geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 360 | struct ppa_addr l; |
| 361 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 362 | l.ppa = ((u64)r.g.blk) << geo->ppaf.blk_offset; |
| 363 | l.ppa |= ((u64)r.g.pg) << geo->ppaf.pg_offset; |
| 364 | l.ppa |= ((u64)r.g.sec) << geo->ppaf.sect_offset; |
| 365 | l.ppa |= ((u64)r.g.pl) << geo->ppaf.pln_offset; |
| 366 | l.ppa |= ((u64)r.g.lun) << geo->ppaf.lun_offset; |
| 367 | l.ppa |= ((u64)r.g.ch) << geo->ppaf.ch_offset; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 368 | |
| 369 | return l; |
| 370 | } |
| 371 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 372 | static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev, |
| 373 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 374 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 375 | struct nvm_geo *geo = &tgt_dev->geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 376 | struct ppa_addr l; |
| 377 | |
Javier González | 5389a1d | 2016-07-07 09:54:09 +0200 | [diff] [blame] | 378 | l.ppa = 0; |
Matias Bjørling | 7386af2 | 2015-11-16 15:34:44 +0100 | [diff] [blame] | 379 | /* |
| 380 | * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc. |
| 381 | */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 382 | l.g.blk = (r.ppa >> geo->ppaf.blk_offset) & |
| 383 | (((1 << geo->ppaf.blk_len) - 1)); |
| 384 | l.g.pg |= (r.ppa >> geo->ppaf.pg_offset) & |
| 385 | (((1 << geo->ppaf.pg_len) - 1)); |
| 386 | l.g.sec |= (r.ppa >> geo->ppaf.sect_offset) & |
| 387 | (((1 << geo->ppaf.sect_len) - 1)); |
| 388 | l.g.pl |= (r.ppa >> geo->ppaf.pln_offset) & |
| 389 | (((1 << geo->ppaf.pln_len) - 1)); |
| 390 | l.g.lun |= (r.ppa >> geo->ppaf.lun_offset) & |
| 391 | (((1 << geo->ppaf.lun_len) - 1)); |
| 392 | l.g.ch |= (r.ppa >> geo->ppaf.ch_offset) & |
| 393 | (((1 << geo->ppaf.ch_len) - 1)); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 394 | |
| 395 | return l; |
| 396 | } |
| 397 | |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 398 | 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] | 399 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
Javier González | 4af3f75 | 2017-04-15 20:55:45 +0200 | [diff] [blame] | 400 | typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *, |
| 401 | int flags); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 402 | typedef void (nvm_tgt_exit_fn)(void *); |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 403 | typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *); |
| 404 | typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 405 | |
| 406 | struct nvm_tgt_type { |
| 407 | const char *name; |
| 408 | unsigned int version[3]; |
| 409 | |
| 410 | /* target entry points */ |
| 411 | nvm_tgt_make_rq_fn *make_rq; |
| 412 | nvm_tgt_capacity_fn *capacity; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 413 | |
| 414 | /* module-specific init/teardown */ |
| 415 | nvm_tgt_init_fn *init; |
| 416 | nvm_tgt_exit_fn *exit; |
| 417 | |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 418 | /* sysfs */ |
| 419 | nvm_tgt_sysfs_init_fn *sysfs_init; |
| 420 | nvm_tgt_sysfs_exit_fn *sysfs_exit; |
| 421 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 422 | /* For internal use */ |
| 423 | struct list_head list; |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 424 | struct module *owner; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 425 | }; |
| 426 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 427 | extern int nvm_register_tgt_type(struct nvm_tgt_type *); |
| 428 | extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 429 | |
| 430 | extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); |
| 431 | extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); |
| 432 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 433 | extern struct nvm_dev *nvm_alloc_dev(int); |
| 434 | extern int nvm_register(struct nvm_dev *); |
| 435 | extern void nvm_unregister(struct nvm_dev *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 436 | |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 437 | extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *, |
| 438 | int, int); |
Javier González | a279006 | 2016-11-28 22:39:12 +0100 | [diff] [blame] | 439 | extern int nvm_max_phys_sects(struct nvm_tgt_dev *); |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 440 | extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *); |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 441 | extern int nvm_submit_io_sync(struct nvm_tgt_dev *, struct nvm_rq *); |
Matias Bjørling | 06894ef | 2017-01-31 13:17:17 +0100 | [diff] [blame] | 442 | extern void nvm_end_io(struct nvm_rq *); |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 443 | extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 444 | 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] | 445 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 446 | #else /* CONFIG_NVM */ |
| 447 | struct nvm_dev_ops; |
| 448 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 449 | static inline struct nvm_dev *nvm_alloc_dev(int node) |
| 450 | { |
| 451 | return ERR_PTR(-EINVAL); |
| 452 | } |
| 453 | static inline int nvm_register(struct nvm_dev *dev) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 454 | { |
| 455 | return -EINVAL; |
| 456 | } |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 457 | static inline void nvm_unregister(struct nvm_dev *dev) {} |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 458 | #endif /* CONFIG_NVM */ |
| 459 | #endif /* LIGHTNVM.H */ |