blob: 7dfa56ebbc6d0f1bd4e215c93d5e642b3231334b [file] [log] [blame]
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01001#ifndef NVM_H
2#define NVM_H
3
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02004#include <linux/blkdev.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07005#include <linux/types.h>
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02006#include <uapi/linux/lightnvm.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07007
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01008enum {
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 Axboea7fd9a42016-01-13 13:04:11 -070018#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ørlingdf414b32016-05-06 20:03:19 +020023#define NVM_CH_BITS (7)
Jens Axboea7fd9a42016-01-13 13:04:11 -070024
25struct 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ørlingdf414b32016-05-06 20:03:19 +020035 u64 reserved : 1;
Jens Axboea7fd9a42016-01-13 13:04:11 -070036 } g;
37
Matias Bjørlingdf414b32016-05-06 20:03:19 +020038 struct {
39 u64 line : 63;
40 u64 is_cached : 1;
41 } c;
42
Jens Axboea7fd9a42016-01-13 13:04:11 -070043 u64 ppa;
44 };
45};
46
47struct nvm_rq;
48struct nvm_id;
49struct nvm_dev;
Javier González8e536242016-11-28 22:39:10 +010050struct nvm_tgt_dev;
Jens Axboea7fd9a42016-01-13 13:04:11 -070051
52typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070053typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *);
54typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32,
55 nvm_l2p_update_fn *, void *);
Matias Bjørlinge11903f2016-05-06 20:03:05 +020056typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørling00ee6cc2016-05-06 20:03:09 +020057typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
Jens Axboea7fd9a42016-01-13 13:04:11 -070058typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070059typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
60typedef void (nvm_destroy_dma_pool_fn)(void *);
61typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
62 dma_addr_t *);
63typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
64
65struct 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 Axboea7fd9a42016-01-13 13:04:11 -070072
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ørlingcd9e9802015-10-28 19:54:55 +010081#ifdef CONFIG_NVM
82
83#include <linux/blkdev.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010084#include <linux/file.h>
85#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010086#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010087
88enum {
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ørlingd5bdec82016-02-19 13:56:58 +010098 NVM_PLANE_SINGLE = 1,
99 NVM_PLANE_DOUBLE = 2,
100 NVM_PLANE_QUAD = 4,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100101
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ález402ab9a2016-11-28 22:38:57 +0100107 NVM_RSP_ERR_FAILECC = 0x4281,
Javier González38ea2f72017-01-31 13:17:18 +0100108 NVM_RSP_ERR_FAILCRC = 0x4004,
Javier González402ab9a2016-11-28 22:38:57 +0100109 NVM_RSP_WARN_HIGHECC = 0x4700,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100110
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ørling57b4bd02015-12-06 11:25:47 +0100123 /* NAND Access Modes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100124 NVM_IO_SUSPEND = 0x80,
125 NVM_IO_SLC_MODE = 0x100,
Javier Gonzáleza7737f32017-04-15 20:55:38 +0200126 NVM_IO_SCRAMBLE_ENABLE = 0x200,
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100127
128 /* Block Types */
129 NVM_BLK_T_FREE = 0x0,
130 NVM_BLK_T_BAD = 0x1,
Matias Bjørlingb5d4acd2016-01-12 07:49:32 +0100131 NVM_BLK_T_GRWN_BAD = 0x2,
132 NVM_BLK_T_DEV = 0x4,
133 NVM_BLK_T_HOST = 0x8,
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100134
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ørlingca5927e2016-01-12 07:49:35 +0100140
141 /* Memory types */
142 NVM_ID_FMTYPE_SLC = 0,
143 NVM_ID_FMTYPE_MLC = 1,
Matias Bjørlingbf643182016-02-04 15:13:27 +0100144
145 /* Device capabilities */
146 NVM_ID_DCAP_BBLKMGMT = 0x1,
147 NVM_UD_DCAP_ECC = 0x2,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100148};
149
150struct nvm_id_lp_mlc {
151 u16 num_pairs;
152 u8 pairs[886];
153};
154
155struct nvm_id_lp_tbl {
156 __u8 id[8];
157 struct nvm_id_lp_mlc mlc;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100158};
159
160struct nvm_id_group {
161 u8 mtype;
162 u8 fmtype;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100163 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ørling12be5ed2015-11-16 15:34:39 +0100178 u32 mccap;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100179 u16 cpar;
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100180
181 struct nvm_id_lp_tbl lptbl;
Matias Bjørling73387e72015-11-16 15:34:40 +0100182};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100183
184struct 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ørlingcd9e9802015-10-28 19:54:55 +0100197};
198
199struct nvm_id {
200 u8 ver_id;
201 u8 vmnt;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100202 u32 cap;
203 u32 dom;
204 struct nvm_addr_format ppaf;
Matias Bjørling19bd6fe2017-01-31 13:17:15 +0100205 struct nvm_id_group grp;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100206} __packed;
207
208struct nvm_target {
209 struct list_head list;
Javier González8e79b5c2016-11-28 22:39:06 +0100210 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100211 struct nvm_tgt_type *type;
212 struct gendisk *disk;
213};
214
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100215#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ørling912761622016-01-12 07:49:21 +0100221struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100222typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100223
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100224struct nvm_rq {
Javier González8e536242016-11-28 22:39:10 +0100225 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100226
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ález003fad32016-05-06 20:03:12 +0200236 void *meta_list;
237 dma_addr_t dma_meta_list;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100238
Matias Bjørling912761622016-01-12 07:49:21 +0100239 struct completion *wait;
240 nvm_end_io_fn *end_io;
241
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100242 uint8_t opcode;
Javier González6d5be952016-05-06 20:03:20 +0200243 uint16_t nr_ppas;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100244 uint16_t flags;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100245
Matias Bjorling9f867262016-03-03 15:06:39 +0100246 u64 ppa_status; /* ppa media status */
Matias Bjørling72d256e2016-01-12 07:49:29 +0100247 int error;
Matias Bjørling06894ef2017-01-31 13:17:17 +0100248
249 void *private;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100250};
251
252static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu)
253{
254 return pdu - sizeof(struct nvm_rq);
255}
256
257static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
258{
259 return rqdata + 1;
260}
261
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100262enum {
263 NVM_BLK_ST_FREE = 0x1, /* Free block */
Matias Bjørling077d2382016-07-07 09:54:14 +0200264 NVM_BLK_ST_TGT = 0x2, /* Block in use by target */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100265 NVM_BLK_ST_BAD = 0x8, /* Bad block */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100266};
267
Javier González8e79b5c2016-11-28 22:39:06 +0100268/* Device generic information */
269struct nvm_geo {
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100270 int nr_chnls;
Javier González8e79b5c2016-11-28 22:39:06 +0100271 int nr_luns;
272 int luns_per_chnl; /* -1 if channels are not symmetric */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100273 int nr_planes;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100274 int sec_per_pg; /* only sectors for a single page */
275 int pgs_per_blk;
276 int blks_per_lun;
Matias Bjørling4891d122016-05-06 20:02:57 +0200277 int fpg_size;
278 int pfpg_size; /* size of buffer if all pages are to be read */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100279 int sec_size;
280 int oob_size;
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100281 int mccap;
Matias Bjørling7386af22015-11-16 15:34:44 +0100282 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100283
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ález8e79b5c2016-11-28 22:39:06 +0100293};
294
Matias Bjørlingade69e22017-01-31 13:17:09 +0100295/* sub-device structure */
Javier González8e79b5c2016-11-28 22:39:06 +0100296struct nvm_tgt_dev {
297 /* Device information */
298 struct nvm_geo geo;
299
Javier González8e536242016-11-28 22:39:10 +0100300 /* Base ppas for target LUNs */
301 struct ppa_addr *luns;
302
Javier González8e79b5c2016-11-28 22:39:06 +0100303 sector_t total_secs;
304
305 struct nvm_id identity;
306 struct request_queue *q;
307
Javier González959e9112016-11-28 22:39:11 +0100308 struct nvm_dev *parent;
Javier González8e536242016-11-28 22:39:10 +0100309 void *map;
Javier González8e79b5c2016-11-28 22:39:06 +0100310};
311
312struct nvm_dev {
313 struct nvm_dev_ops *ops;
314
315 struct list_head devices;
316
Javier González8e79b5c2016-11-28 22:39:06 +0100317 /* Device information */
318 struct nvm_geo geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100319
Matias Bjørlingade69e22017-01-31 13:17:09 +0100320 /* lower page table */
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100321 int lps_per_blk;
322 int *lptbl;
323
Matias Bjørling4ece44a2016-02-20 08:52:41 +0100324 unsigned long total_secs;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100325
Wenwei Taoda1e2842016-03-03 15:06:38 +0100326 unsigned long *lun_map;
Javier González75b85642016-05-06 20:03:13 +0200327 void *dma_pool;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100328
329 struct nvm_id identity;
330
331 /* Backend device */
332 struct request_queue *q;
333 char name[DISK_NAME_LEN];
Simon A. F. Lund40267ef2016-09-16 14:25:08 +0200334 void *private_data;
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100335
Javier González8e536242016-11-28 22:39:10 +0100336 void *rmap;
337
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100338 struct mutex mlock;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100339 spinlock_t lock;
Matias Bjørlingade69e22017-01-31 13:17:09 +0100340
341 /* target management */
342 struct list_head area_list;
343 struct list_head targets;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100344};
345
Javier González8e79b5c2016-11-28 22:39:06 +0100346static inline struct ppa_addr linear_to_generic_addr(struct nvm_geo *geo,
Javier González8e536242016-11-28 22:39:10 +0100347 u64 pba)
Javier González0e5c3242016-11-28 22:39:01 +0100348{
349 struct ppa_addr l;
350 int secs, pgs, blks, luns;
Javier González8e536242016-11-28 22:39:10 +0100351 sector_t ppa = pba;
Javier González0e5c3242016-11-28 22:39:01 +0100352
353 l.ppa = 0;
354
Javier González8e79b5c2016-11-28 22:39:06 +0100355 div_u64_rem(ppa, geo->sec_per_pg, &secs);
Javier González0e5c3242016-11-28 22:39:01 +0100356 l.g.sec = secs;
357
Javier González8e79b5c2016-11-28 22:39:06 +0100358 sector_div(ppa, geo->sec_per_pg);
359 div_u64_rem(ppa, geo->pgs_per_blk, &pgs);
Javier González0e5c3242016-11-28 22:39:01 +0100360 l.g.pg = pgs;
361
Javier González8e79b5c2016-11-28 22:39:06 +0100362 sector_div(ppa, geo->pgs_per_blk);
363 div_u64_rem(ppa, geo->blks_per_lun, &blks);
Javier González0e5c3242016-11-28 22:39:01 +0100364 l.g.blk = blks;
365
Javier González8e79b5c2016-11-28 22:39:06 +0100366 sector_div(ppa, geo->blks_per_lun);
367 div_u64_rem(ppa, geo->luns_per_chnl, &luns);
Javier González0e5c3242016-11-28 22:39:01 +0100368 l.g.lun = luns;
369
Javier González8e79b5c2016-11-28 22:39:06 +0100370 sector_div(ppa, geo->luns_per_chnl);
Javier González0e5c3242016-11-28 22:39:01 +0100371 l.g.ch = ppa;
372
373 return l;
374}
375
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100376static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev,
377 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100378{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100379 struct nvm_geo *geo = &tgt_dev->geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100380 struct ppa_addr l;
381
Javier González8e79b5c2016-11-28 22:39:06 +0100382 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ørlingcd9e9802015-10-28 19:54:55 +0100388
389 return l;
390}
391
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100392static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev,
393 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100394{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100395 struct nvm_geo *geo = &tgt_dev->geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100396 struct ppa_addr l;
397
Javier González5389a1d2016-07-07 09:54:09 +0200398 l.ppa = 0;
Matias Bjørling7386af22015-11-16 15:34:44 +0100399 /*
400 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
401 */
Javier González8e79b5c2016-11-28 22:39:06 +0100402 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ørlingcd9e9802015-10-28 19:54:55 +0100414
415 return l;
416}
417
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100418static inline int ppa_empty(struct ppa_addr ppa_addr)
419{
420 return (ppa_addr.ppa == ADDR_EMPTY);
421}
422
423static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
424{
425 ppa_addr->ppa = ADDR_EMPTY;
426}
427
Javier Gonzáleza24ba462016-11-28 22:38:56 +0100428static 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 Axboedece1632015-11-05 10:41:16 -0700437typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100438typedef sector_t (nvm_tgt_capacity_fn)(void *);
Javier González4af3f752017-04-15 20:55:45 +0200439typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *,
440 int flags);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100441typedef void (nvm_tgt_exit_fn)(void *);
Javier González9a69b0e2017-01-31 13:17:20 +0100442typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *);
443typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100444
445struct 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ørlingcd9e9802015-10-28 19:54:55 +0100452
453 /* module-specific init/teardown */
454 nvm_tgt_init_fn *init;
455 nvm_tgt_exit_fn *exit;
456
Javier González9a69b0e2017-01-31 13:17:20 +0100457 /* sysfs */
458 nvm_tgt_sysfs_init_fn *sysfs_init;
459 nvm_tgt_sysfs_exit_fn *sysfs_exit;
460
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100461 /* For internal use */
462 struct list_head list;
463};
464
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +0200465extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);
466
Simon A. F. Lund6063fe32016-05-06 20:03:02 +0200467extern int nvm_register_tgt_type(struct nvm_tgt_type *);
468extern void nvm_unregister_tgt_type(struct nvm_tgt_type *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100469
470extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
471extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
472
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200473extern struct nvm_dev *nvm_alloc_dev(int);
474extern int nvm_register(struct nvm_dev *);
475extern void nvm_unregister(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100476
Javier González333ba052016-11-28 22:39:14 +0100477extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *,
478 int, int);
Javier Gonzáleza2790062016-11-28 22:39:12 +0100479extern int nvm_max_phys_sects(struct nvm_tgt_dev *);
Javier González8e536242016-11-28 22:39:10 +0100480extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *);
Javier González17912c42017-04-15 20:55:37 +0200481extern int nvm_erase_sync(struct nvm_tgt_dev *, struct ppa_addr *, int);
482extern int nvm_set_rqd_ppalist(struct nvm_tgt_dev *, struct nvm_rq *,
Matias Bjørling8680f162016-07-07 09:54:22 +0200483 const struct ppa_addr *, int, int);
Javier González17912c42017-04-15 20:55:37 +0200484extern void nvm_free_rqd_ppalist(struct nvm_tgt_dev *, struct nvm_rq *);
Javier Gonzálezda2d7cb2016-11-28 22:39:13 +0100485extern int nvm_get_l2p_tbl(struct nvm_tgt_dev *, u64, u32, nvm_l2p_update_fn *,
Javier González8e536242016-11-28 22:39:10 +0100486 void *);
Javier Gonzálezda2d7cb2016-11-28 22:39:13 +0100487extern int nvm_get_area(struct nvm_tgt_dev *, sector_t *, sector_t);
488extern void nvm_put_area(struct nvm_tgt_dev *, sector_t);
Matias Bjørling06894ef2017-01-31 13:17:17 +0100489extern void nvm_end_io(struct nvm_rq *);
Matias Bjørling22e8c972016-05-06 20:02:58 +0200490extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int);
Javier González333ba052016-11-28 22:39:14 +0100491extern int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr, u8 *);
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100492
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100493extern int nvm_dev_factory(struct nvm_dev *, int flags);
Matias Bjørling51360612016-05-06 20:03:04 +0200494
Matias Bjørlingade69e22017-01-31 13:17:09 +0100495extern void nvm_part_to_tgt(struct nvm_dev *, sector_t *, int);
Matias Bjørling51360612016-05-06 20:03:04 +0200496
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100497#else /* CONFIG_NVM */
498struct nvm_dev_ops;
499
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200500static inline struct nvm_dev *nvm_alloc_dev(int node)
501{
502 return ERR_PTR(-EINVAL);
503}
504static inline int nvm_register(struct nvm_dev *dev)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100505{
506 return -EINVAL;
507}
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200508static inline void nvm_unregister(struct nvm_dev *dev) {}
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100509#endif /* CONFIG_NVM */
510#endif /* LIGHTNVM.H */