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 | |
Javier González | f1d4e81 | 2018-03-30 00:05:12 +0200 | [diff] [blame] | 26 | enum { |
| 27 | NVM_OCSSD_SPEC_12 = 12, |
| 28 | NVM_OCSSD_SPEC_20 = 20, |
| 29 | }; |
| 30 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 31 | struct ppa_addr { |
| 32 | /* Generic structure for all addresses */ |
| 33 | union { |
| 34 | struct { |
| 35 | u64 blk : NVM_BLK_BITS; |
| 36 | u64 pg : NVM_PG_BITS; |
| 37 | u64 sec : NVM_SEC_BITS; |
| 38 | u64 pl : NVM_PL_BITS; |
| 39 | u64 lun : NVM_LUN_BITS; |
| 40 | u64 ch : NVM_CH_BITS; |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 41 | u64 reserved : 1; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 42 | } g; |
| 43 | |
Matias Bjørling | df414b3 | 2016-05-06 20:03:19 +0200 | [diff] [blame] | 44 | struct { |
| 45 | u64 line : 63; |
| 46 | u64 is_cached : 1; |
| 47 | } c; |
| 48 | |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 49 | u64 ppa; |
| 50 | }; |
| 51 | }; |
| 52 | |
| 53 | struct nvm_rq; |
| 54 | struct nvm_id; |
| 55 | struct nvm_dev; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 56 | struct nvm_tgt_dev; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 57 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 58 | typedef int (nvm_id_fn)(struct nvm_dev *); |
Matias Bjørling | e11903f | 2016-05-06 20:03:05 +0200 | [diff] [blame] | 59 | 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] | 60 | 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] | 61 | 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] | 62 | 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] | 63 | typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *); |
| 64 | typedef void (nvm_destroy_dma_pool_fn)(void *); |
| 65 | typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t, |
| 66 | dma_addr_t *); |
| 67 | typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t); |
| 68 | |
| 69 | struct nvm_dev_ops { |
| 70 | nvm_id_fn *identity; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 71 | nvm_op_bb_tbl_fn *get_bb_tbl; |
| 72 | nvm_op_set_bb_fn *set_bb_tbl; |
| 73 | |
| 74 | nvm_submit_io_fn *submit_io; |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 75 | nvm_submit_io_sync_fn *submit_io_sync; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 76 | |
| 77 | nvm_create_dma_pool_fn *create_dma_pool; |
| 78 | nvm_destroy_dma_pool_fn *destroy_dma_pool; |
| 79 | nvm_dev_dma_alloc_fn *dev_dma_alloc; |
| 80 | nvm_dev_dma_free_fn *dev_dma_free; |
Jens Axboe | a7fd9a4 | 2016-01-13 13:04:11 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 83 | #ifdef CONFIG_NVM |
| 84 | |
| 85 | #include <linux/blkdev.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 86 | #include <linux/file.h> |
| 87 | #include <linux/dmapool.h> |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 88 | #include <uapi/linux/lightnvm.h> |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 89 | |
| 90 | enum { |
| 91 | /* HW Responsibilities */ |
| 92 | NVM_RSP_L2P = 1 << 0, |
| 93 | NVM_RSP_ECC = 1 << 1, |
| 94 | |
| 95 | /* Physical Adressing Mode */ |
| 96 | NVM_ADDRMODE_LINEAR = 0, |
| 97 | NVM_ADDRMODE_CHANNEL = 1, |
| 98 | |
| 99 | /* Plane programming mode for LUN */ |
Matias Bjørling | d5bdec8 | 2016-02-19 13:56:58 +0100 | [diff] [blame] | 100 | NVM_PLANE_SINGLE = 1, |
| 101 | NVM_PLANE_DOUBLE = 2, |
| 102 | NVM_PLANE_QUAD = 4, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 103 | |
| 104 | /* Status codes */ |
| 105 | NVM_RSP_SUCCESS = 0x0, |
| 106 | NVM_RSP_NOT_CHANGEABLE = 0x1, |
| 107 | NVM_RSP_ERR_FAILWRITE = 0x40ff, |
| 108 | NVM_RSP_ERR_EMPTYPAGE = 0x42ff, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 109 | NVM_RSP_ERR_FAILECC = 0x4281, |
Javier González | 38ea2f7 | 2017-01-31 13:17:18 +0100 | [diff] [blame] | 110 | NVM_RSP_ERR_FAILCRC = 0x4004, |
Javier González | 402ab9a | 2016-11-28 22:38:57 +0100 | [diff] [blame] | 111 | NVM_RSP_WARN_HIGHECC = 0x4700, |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 112 | |
| 113 | /* Device opcodes */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 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 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 160 | struct nvm_addrf_12 { |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 161 | u8 ch_len; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 162 | u8 lun_len; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 163 | u8 blk_len; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 164 | u8 pg_len; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 165 | u8 pln_len; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 166 | u8 sect_len; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 167 | |
| 168 | u8 ch_offset; |
| 169 | u8 lun_offset; |
| 170 | u8 blk_offset; |
| 171 | u8 pg_offset; |
| 172 | u8 pln_offset; |
| 173 | u8 sect_offset; |
| 174 | |
| 175 | u64 ch_mask; |
| 176 | u64 lun_mask; |
| 177 | u64 blk_mask; |
| 178 | u64 pg_mask; |
| 179 | u64 pln_mask; |
| 180 | u64 sec_mask; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 183 | struct nvm_addrf { |
| 184 | u8 ch_len; |
| 185 | u8 lun_len; |
| 186 | u8 chk_len; |
| 187 | u8 sec_len; |
| 188 | u8 rsv_len[2]; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 189 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 190 | u8 ch_offset; |
| 191 | u8 lun_offset; |
| 192 | u8 chk_offset; |
| 193 | u8 sec_offset; |
| 194 | u8 rsv_off[2]; |
Matias Bjørling | c6ac3f3 | 2018-03-30 00:05:01 +0200 | [diff] [blame] | 195 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 196 | u64 ch_mask; |
| 197 | u64 lun_mask; |
| 198 | u64 chk_mask; |
| 199 | u64 sec_mask; |
| 200 | u64 rsv_mask[2]; |
| 201 | }; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 202 | |
| 203 | struct nvm_target { |
| 204 | struct list_head list; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 205 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 206 | struct nvm_tgt_type *type; |
| 207 | struct gendisk *disk; |
| 208 | }; |
| 209 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 210 | #define ADDR_EMPTY (~0ULL) |
| 211 | |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 212 | #define NVM_TARGET_DEFAULT_OP (101) |
| 213 | #define NVM_TARGET_MIN_OP (3) |
| 214 | #define NVM_TARGET_MAX_OP (80) |
| 215 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 216 | #define NVM_VERSION_MAJOR 1 |
| 217 | #define NVM_VERSION_MINOR 0 |
| 218 | #define NVM_VERSION_PATCH 0 |
| 219 | |
Matias Bjørling | 89a09c5 | 2018-03-30 00:05:04 +0200 | [diff] [blame] | 220 | #define NVM_MAX_VLBA (64) /* max logical blocks in a vector command */ |
| 221 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 222 | struct nvm_rq; |
Matias Bjørling | 72d256e | 2016-01-12 07:49:29 +0100 | [diff] [blame] | 223 | typedef void (nvm_end_io_fn)(struct nvm_rq *); |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 224 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 225 | struct nvm_rq { |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 226 | struct nvm_tgt_dev *dev; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 227 | |
| 228 | struct bio *bio; |
| 229 | |
| 230 | union { |
| 231 | struct ppa_addr ppa_addr; |
| 232 | dma_addr_t dma_ppa_list; |
| 233 | }; |
| 234 | |
| 235 | struct ppa_addr *ppa_list; |
| 236 | |
Javier González | 003fad3 | 2016-05-06 20:03:12 +0200 | [diff] [blame] | 237 | void *meta_list; |
| 238 | dma_addr_t dma_meta_list; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 239 | |
Matias Bjørling | 91276162 | 2016-01-12 07:49:21 +0100 | [diff] [blame] | 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 | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 268 | /* Instance geometry */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 269 | struct nvm_geo { |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 270 | /* device reported version */ |
Javier González | 3cb98f8 | 2018-03-30 00:05:11 +0200 | [diff] [blame] | 271 | u8 major_ver_id; |
| 272 | u8 minor_ver_id; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 273 | |
Javier González | f1d4e81 | 2018-03-30 00:05:12 +0200 | [diff] [blame] | 274 | /* kernel short version */ |
| 275 | u8 version; |
| 276 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 277 | /* instance specific geometry */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 278 | int nr_chnls; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 279 | int nr_luns; /* per channel */ |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 280 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 281 | /* calculated values */ |
| 282 | int all_luns; /* across channels */ |
| 283 | int all_chunks; /* across channels */ |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 284 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 285 | int op; /* over-provision in instance */ |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 286 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 287 | sector_t total_secs; /* across channels */ |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 288 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 289 | /* chunk geometry */ |
| 290 | u32 nr_chks; /* chunks per lun */ |
| 291 | u32 clba; /* sectors per chunk */ |
| 292 | u16 csecs; /* sector size */ |
| 293 | u16 sos; /* out-of-band area size */ |
Javier González | e539273 | 2018-01-05 14:16:14 +0100 | [diff] [blame] | 294 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 295 | /* device write constrains */ |
| 296 | u32 ws_min; /* minimum write size */ |
| 297 | u32 ws_opt; /* optimal write size */ |
| 298 | u32 mw_cunits; /* distance required for successful read */ |
Javier González | 3f48021 | 2018-03-30 00:05:13 +0200 | [diff] [blame^] | 299 | u32 maxoc; /* maximum open chunks */ |
| 300 | u32 maxocpu; /* maximum open chunks per parallel unit */ |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 301 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 302 | /* device capabilities */ |
| 303 | u32 mccap; |
| 304 | |
| 305 | /* device timings */ |
| 306 | u32 trdt; /* Avg. Tread (ns) */ |
| 307 | u32 trdm; /* Max Tread (ns) */ |
| 308 | u32 tprt; /* Avg. Tprog (ns) */ |
| 309 | u32 tprm; /* Max Tprog (ns) */ |
| 310 | u32 tbet; /* Avg. Terase (ns) */ |
| 311 | u32 tbem; /* Max Terase (ns) */ |
| 312 | |
| 313 | /* generic address format */ |
| 314 | struct nvm_addrf addrf; |
| 315 | |
| 316 | /* 1.2 compatibility */ |
| 317 | u8 vmnt; |
| 318 | u32 cap; |
| 319 | u32 dom; |
| 320 | |
| 321 | u8 mtype; |
| 322 | u8 fmtype; |
| 323 | |
| 324 | u16 cpar; |
| 325 | u32 mpos; |
| 326 | |
| 327 | u8 num_pln; |
| 328 | u8 plane_mode; |
| 329 | u16 num_pg; |
| 330 | u16 fpg_sz; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 331 | }; |
| 332 | |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 333 | /* sub-device structure */ |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 334 | struct nvm_tgt_dev { |
| 335 | /* Device information */ |
| 336 | struct nvm_geo geo; |
| 337 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 338 | /* Base ppas for target LUNs */ |
| 339 | struct ppa_addr *luns; |
| 340 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 341 | struct request_queue *q; |
| 342 | |
Javier González | 959e911 | 2016-11-28 22:39:11 +0100 | [diff] [blame] | 343 | struct nvm_dev *parent; |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 344 | void *map; |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | struct nvm_dev { |
| 348 | struct nvm_dev_ops *ops; |
| 349 | |
| 350 | struct list_head devices; |
| 351 | |
Javier González | 8e79b5c | 2016-11-28 22:39:06 +0100 | [diff] [blame] | 352 | /* Device information */ |
| 353 | struct nvm_geo geo; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 354 | |
Wenwei Tao | da1e284 | 2016-03-03 15:06:38 +0100 | [diff] [blame] | 355 | unsigned long *lun_map; |
Javier González | 75b8564 | 2016-05-06 20:03:13 +0200 | [diff] [blame] | 356 | void *dma_pool; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 357 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 358 | /* Backend device */ |
| 359 | struct request_queue *q; |
| 360 | char name[DISK_NAME_LEN]; |
Simon A. F. Lund | 40267ef | 2016-09-16 14:25:08 +0200 | [diff] [blame] | 361 | void *private_data; |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 362 | |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 363 | void *rmap; |
| 364 | |
Matias Bjørling | e3eb379 | 2016-01-12 07:49:36 +0100 | [diff] [blame] | 365 | struct mutex mlock; |
Wenwei Tao | 4c9dacb | 2016-03-03 15:06:37 +0100 | [diff] [blame] | 366 | spinlock_t lock; |
Matias Bjørling | ade69e2 | 2017-01-31 13:17:09 +0100 | [diff] [blame] | 367 | |
| 368 | /* target management */ |
| 369 | struct list_head area_list; |
| 370 | struct list_head targets; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 371 | }; |
| 372 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 373 | static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev, |
| 374 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 375 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 376 | struct nvm_geo *geo = &tgt_dev->geo; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 377 | struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&geo->addrf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 378 | struct ppa_addr l; |
| 379 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 380 | l.ppa = ((u64)r.g.ch) << ppaf->ch_offset; |
| 381 | l.ppa |= ((u64)r.g.lun) << ppaf->lun_offset; |
| 382 | l.ppa |= ((u64)r.g.blk) << ppaf->blk_offset; |
| 383 | l.ppa |= ((u64)r.g.pg) << ppaf->pg_offset; |
| 384 | l.ppa |= ((u64)r.g.pl) << ppaf->pln_offset; |
| 385 | l.ppa |= ((u64)r.g.sec) << ppaf->sect_offset; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 386 | |
| 387 | return l; |
| 388 | } |
| 389 | |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 390 | static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev, |
| 391 | struct ppa_addr r) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 392 | { |
Matias Bjørling | dab8ee9 | 2017-01-31 13:17:14 +0100 | [diff] [blame] | 393 | struct nvm_geo *geo = &tgt_dev->geo; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 394 | struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&geo->addrf; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 395 | struct ppa_addr l; |
| 396 | |
Javier González | 5389a1d | 2016-07-07 09:54:09 +0200 | [diff] [blame] | 397 | l.ppa = 0; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 398 | |
| 399 | l.g.ch = (r.ppa & ppaf->ch_mask) >> ppaf->ch_offset; |
| 400 | l.g.lun = (r.ppa & ppaf->lun_mask) >> ppaf->lun_offset; |
| 401 | l.g.blk = (r.ppa & ppaf->blk_mask) >> ppaf->blk_offset; |
| 402 | l.g.pg = (r.ppa & ppaf->pg_mask) >> ppaf->pg_offset; |
| 403 | l.g.pl = (r.ppa & ppaf->pln_mask) >> ppaf->pln_offset; |
| 404 | l.g.sec = (r.ppa & ppaf->sec_mask) >> ppaf->sect_offset; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 405 | |
| 406 | return l; |
| 407 | } |
| 408 | |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 409 | 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] | 410 | typedef sector_t (nvm_tgt_capacity_fn)(void *); |
Javier González | 4af3f75 | 2017-04-15 20:55:45 +0200 | [diff] [blame] | 411 | typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *, |
| 412 | int flags); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 413 | typedef void (nvm_tgt_exit_fn)(void *); |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 414 | typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *); |
| 415 | typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 416 | |
| 417 | struct nvm_tgt_type { |
| 418 | const char *name; |
| 419 | unsigned int version[3]; |
| 420 | |
| 421 | /* target entry points */ |
| 422 | nvm_tgt_make_rq_fn *make_rq; |
| 423 | nvm_tgt_capacity_fn *capacity; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 424 | |
| 425 | /* module-specific init/teardown */ |
| 426 | nvm_tgt_init_fn *init; |
| 427 | nvm_tgt_exit_fn *exit; |
| 428 | |
Javier González | 9a69b0e | 2017-01-31 13:17:20 +0100 | [diff] [blame] | 429 | /* sysfs */ |
| 430 | nvm_tgt_sysfs_init_fn *sysfs_init; |
| 431 | nvm_tgt_sysfs_exit_fn *sysfs_exit; |
| 432 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 433 | /* For internal use */ |
| 434 | struct list_head list; |
Rakesh Pandit | 9001482 | 2017-10-13 14:45:50 +0200 | [diff] [blame] | 435 | struct module *owner; |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 436 | }; |
| 437 | |
Simon A. F. Lund | 6063fe3 | 2016-05-06 20:03:02 +0200 | [diff] [blame] | 438 | extern int nvm_register_tgt_type(struct nvm_tgt_type *); |
| 439 | extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 440 | |
| 441 | extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); |
| 442 | extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); |
| 443 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 444 | extern struct nvm_dev *nvm_alloc_dev(int); |
| 445 | extern int nvm_register(struct nvm_dev *); |
| 446 | extern void nvm_unregister(struct nvm_dev *); |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 447 | |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 448 | extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *, |
| 449 | int, int); |
Javier González | 8e53624 | 2016-11-28 22:39:10 +0100 | [diff] [blame] | 450 | 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] | 451 | 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] | 452 | extern void nvm_end_io(struct nvm_rq *); |
Matias Bjørling | 22e8c97 | 2016-05-06 20:02:58 +0200 | [diff] [blame] | 453 | extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int); |
Javier González | 333ba05 | 2016-11-28 22:39:14 +0100 | [diff] [blame] | 454 | 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] | 455 | |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 456 | #else /* CONFIG_NVM */ |
| 457 | struct nvm_dev_ops; |
| 458 | |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 459 | static inline struct nvm_dev *nvm_alloc_dev(int node) |
| 460 | { |
| 461 | return ERR_PTR(-EINVAL); |
| 462 | } |
| 463 | static inline int nvm_register(struct nvm_dev *dev) |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 464 | { |
| 465 | return -EINVAL; |
| 466 | } |
Matias Bjørling | b0b4e09 | 2016-09-16 14:25:07 +0200 | [diff] [blame] | 467 | static inline void nvm_unregister(struct nvm_dev *dev) {} |
Matias Bjørling | cd9e980 | 2015-10-28 19:54:55 +0100 | [diff] [blame] | 468 | #endif /* CONFIG_NVM */ |
| 469 | #endif /* LIGHTNVM.H */ |