blob: 2d1d9de06728d619d98b9b718a8e9cdb432d56de [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01002#ifndef NVM_H
3#define NVM_H
4
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02005#include <linux/blkdev.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07006#include <linux/types.h>
Matias Bjørlingb76eb20b2016-07-07 09:54:16 +02007#include <uapi/linux/lightnvm.h>
Jens Axboea7fd9a42016-01-13 13:04:11 -07008
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01009enum {
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 Axboea7fd9a42016-01-13 13:04:11 -070019#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ørlingdf414b32016-05-06 20:03:19 +020024#define NVM_CH_BITS (7)
Jens Axboea7fd9a42016-01-13 13:04:11 -070025
26struct 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ørlingdf414b32016-05-06 20:03:19 +020036 u64 reserved : 1;
Jens Axboea7fd9a42016-01-13 13:04:11 -070037 } g;
38
Matias Bjørlingdf414b32016-05-06 20:03:19 +020039 struct {
40 u64 line : 63;
41 u64 is_cached : 1;
42 } c;
43
Jens Axboea7fd9a42016-01-13 13:04:11 -070044 u64 ppa;
45 };
46};
47
48struct nvm_rq;
49struct nvm_id;
50struct nvm_dev;
Javier González8e536242016-11-28 22:39:10 +010051struct nvm_tgt_dev;
Jens Axboea7fd9a42016-01-13 13:04:11 -070052
53typedef int (nvm_l2p_update_fn)(u64, u32, __le64 *, void *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070054typedef int (nvm_id_fn)(struct nvm_dev *, struct nvm_id *);
55typedef int (nvm_get_l2p_tbl_fn)(struct nvm_dev *, u64, u32,
56 nvm_l2p_update_fn *, void *);
Matias Bjørlinge11903f2016-05-06 20:03:05 +020057typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørling00ee6cc2016-05-06 20:03:09 +020058typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
Jens Axboea7fd9a42016-01-13 13:04:11 -070059typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Javier González1a94b2d2017-10-13 14:46:47 +020060typedef int (nvm_submit_io_sync_fn)(struct nvm_dev *, struct nvm_rq *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070061typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
62typedef void (nvm_destroy_dma_pool_fn)(void *);
63typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
64 dma_addr_t *);
65typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
66
67struct nvm_dev_ops {
68 nvm_id_fn *identity;
69 nvm_get_l2p_tbl_fn *get_l2p_tbl;
70 nvm_op_bb_tbl_fn *get_bb_tbl;
71 nvm_op_set_bb_fn *set_bb_tbl;
72
73 nvm_submit_io_fn *submit_io;
Javier González1a94b2d2017-10-13 14:46:47 +020074 nvm_submit_io_sync_fn *submit_io_sync;
Jens Axboea7fd9a42016-01-13 13:04:11 -070075
76 nvm_create_dma_pool_fn *create_dma_pool;
77 nvm_destroy_dma_pool_fn *destroy_dma_pool;
78 nvm_dev_dma_alloc_fn *dev_dma_alloc;
79 nvm_dev_dma_free_fn *dev_dma_free;
80
81 unsigned int max_phys_sect;
82};
83
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010084#ifdef CONFIG_NVM
85
86#include <linux/blkdev.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010087#include <linux/file.h>
88#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010089#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010090
91enum {
92 /* HW Responsibilities */
93 NVM_RSP_L2P = 1 << 0,
94 NVM_RSP_ECC = 1 << 1,
95
96 /* Physical Adressing Mode */
97 NVM_ADDRMODE_LINEAR = 0,
98 NVM_ADDRMODE_CHANNEL = 1,
99
100 /* Plane programming mode for LUN */
Matias Bjørlingd5bdec82016-02-19 13:56:58 +0100101 NVM_PLANE_SINGLE = 1,
102 NVM_PLANE_DOUBLE = 2,
103 NVM_PLANE_QUAD = 4,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100104
105 /* Status codes */
106 NVM_RSP_SUCCESS = 0x0,
107 NVM_RSP_NOT_CHANGEABLE = 0x1,
108 NVM_RSP_ERR_FAILWRITE = 0x40ff,
109 NVM_RSP_ERR_EMPTYPAGE = 0x42ff,
Javier González402ab9a2016-11-28 22:38:57 +0100110 NVM_RSP_ERR_FAILECC = 0x4281,
Javier González38ea2f72017-01-31 13:17:18 +0100111 NVM_RSP_ERR_FAILCRC = 0x4004,
Javier González402ab9a2016-11-28 22:38:57 +0100112 NVM_RSP_WARN_HIGHECC = 0x4700,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100113
114 /* Device opcodes */
115 NVM_OP_HBREAD = 0x02,
116 NVM_OP_HBWRITE = 0x81,
117 NVM_OP_PWRITE = 0x91,
118 NVM_OP_PREAD = 0x92,
119 NVM_OP_ERASE = 0x90,
120
121 /* PPA Command Flags */
122 NVM_IO_SNGL_ACCESS = 0x0,
123 NVM_IO_DUAL_ACCESS = 0x1,
124 NVM_IO_QUAD_ACCESS = 0x2,
125
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100126 /* NAND Access Modes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100127 NVM_IO_SUSPEND = 0x80,
128 NVM_IO_SLC_MODE = 0x100,
Javier Gonzáleza7737f32017-04-15 20:55:38 +0200129 NVM_IO_SCRAMBLE_ENABLE = 0x200,
Matias Bjørling57b4bd02015-12-06 11:25:47 +0100130
131 /* Block Types */
132 NVM_BLK_T_FREE = 0x0,
133 NVM_BLK_T_BAD = 0x1,
Matias Bjørlingb5d4acd2016-01-12 07:49:32 +0100134 NVM_BLK_T_GRWN_BAD = 0x2,
135 NVM_BLK_T_DEV = 0x4,
136 NVM_BLK_T_HOST = 0x8,
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100137
138 /* Memory capabilities */
139 NVM_ID_CAP_SLC = 0x1,
140 NVM_ID_CAP_CMD_SUSPEND = 0x2,
141 NVM_ID_CAP_SCRAMBLE = 0x4,
142 NVM_ID_CAP_ENCRYPT = 0x8,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100143
144 /* Memory types */
145 NVM_ID_FMTYPE_SLC = 0,
146 NVM_ID_FMTYPE_MLC = 1,
Matias Bjørlingbf643182016-02-04 15:13:27 +0100147
148 /* Device capabilities */
149 NVM_ID_DCAP_BBLKMGMT = 0x1,
150 NVM_UD_DCAP_ECC = 0x2,
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100151};
152
153struct nvm_id_lp_mlc {
154 u16 num_pairs;
155 u8 pairs[886];
156};
157
158struct nvm_id_lp_tbl {
159 __u8 id[8];
160 struct nvm_id_lp_mlc mlc;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100161};
162
163struct nvm_id_group {
164 u8 mtype;
165 u8 fmtype;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100166 u8 num_ch;
167 u8 num_lun;
168 u8 num_pln;
169 u16 num_blk;
170 u16 num_pg;
171 u16 fpg_sz;
172 u16 csecs;
173 u16 sos;
174 u32 trdt;
175 u32 trdm;
176 u32 tprt;
177 u32 tprm;
178 u32 tbet;
179 u32 tbem;
180 u32 mpos;
Matias Bjørling12be5ed2015-11-16 15:34:39 +0100181 u32 mccap;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100182 u16 cpar;
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100183
184 struct nvm_id_lp_tbl lptbl;
Matias Bjørling73387e72015-11-16 15:34:40 +0100185};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100186
187struct nvm_addr_format {
188 u8 ch_offset;
189 u8 ch_len;
190 u8 lun_offset;
191 u8 lun_len;
192 u8 pln_offset;
193 u8 pln_len;
194 u8 blk_offset;
195 u8 blk_len;
196 u8 pg_offset;
197 u8 pg_len;
198 u8 sect_offset;
199 u8 sect_len;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100200};
201
202struct nvm_id {
203 u8 ver_id;
204 u8 vmnt;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100205 u32 cap;
206 u32 dom;
207 struct nvm_addr_format ppaf;
Matias Bjørling19bd6fe2017-01-31 13:17:15 +0100208 struct nvm_id_group grp;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100209} __packed;
210
211struct nvm_target {
212 struct list_head list;
Javier González8e79b5c2016-11-28 22:39:06 +0100213 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100214 struct nvm_tgt_type *type;
215 struct gendisk *disk;
216};
217
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100218#define ADDR_EMPTY (~0ULL)
219
220#define NVM_VERSION_MAJOR 1
221#define NVM_VERSION_MINOR 0
222#define NVM_VERSION_PATCH 0
223
Matias Bjørling912761622016-01-12 07:49:21 +0100224struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100225typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100226
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100227struct nvm_rq {
Javier González8e536242016-11-28 22:39:10 +0100228 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100229
230 struct bio *bio;
231
232 union {
233 struct ppa_addr ppa_addr;
234 dma_addr_t dma_ppa_list;
235 };
236
237 struct ppa_addr *ppa_list;
238
Javier González003fad32016-05-06 20:03:12 +0200239 void *meta_list;
240 dma_addr_t dma_meta_list;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100241
Matias Bjørling912761622016-01-12 07:49:21 +0100242 struct completion *wait;
243 nvm_end_io_fn *end_io;
244
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100245 uint8_t opcode;
Javier González6d5be952016-05-06 20:03:20 +0200246 uint16_t nr_ppas;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100247 uint16_t flags;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100248
Matias Bjorling9f867262016-03-03 15:06:39 +0100249 u64 ppa_status; /* ppa media status */
Matias Bjørling72d256e2016-01-12 07:49:29 +0100250 int error;
Matias Bjørling06894ef2017-01-31 13:17:17 +0100251
252 void *private;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100253};
254
255static inline struct nvm_rq *nvm_rq_from_pdu(void *pdu)
256{
257 return pdu - sizeof(struct nvm_rq);
258}
259
260static inline void *nvm_rq_to_pdu(struct nvm_rq *rqdata)
261{
262 return rqdata + 1;
263}
264
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100265enum {
266 NVM_BLK_ST_FREE = 0x1, /* Free block */
Matias Bjørling077d2382016-07-07 09:54:14 +0200267 NVM_BLK_ST_TGT = 0x2, /* Block in use by target */
Javier Gonzálezff0e4982016-01-12 07:49:33 +0100268 NVM_BLK_ST_BAD = 0x8, /* Bad block */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100269};
270
Javier González8e79b5c2016-11-28 22:39:06 +0100271/* Device generic information */
272struct nvm_geo {
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100273 int nr_chnls;
Javier González8e79b5c2016-11-28 22:39:06 +0100274 int nr_luns;
275 int luns_per_chnl; /* -1 if channels are not symmetric */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100276 int nr_planes;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100277 int sec_per_pg; /* only sectors for a single page */
278 int pgs_per_blk;
279 int blks_per_lun;
Matias Bjørling4891d122016-05-06 20:02:57 +0200280 int fpg_size;
281 int pfpg_size; /* size of buffer if all pages are to be read */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100282 int sec_size;
283 int oob_size;
Matias Bjørlingf9a99952016-01-12 07:49:34 +0100284 int mccap;
Matias Bjørling7386af22015-11-16 15:34:44 +0100285 struct nvm_addr_format ppaf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100286
287 /* Calculated/Cached values. These do not reflect the actual usable
288 * blocks at run-time.
289 */
290 int max_rq_size;
291 int plane_mode; /* drive device in single, double or quad mode */
292
293 int sec_per_pl; /* all sectors across planes */
294 int sec_per_blk;
295 int sec_per_lun;
Javier González8e79b5c2016-11-28 22:39:06 +0100296};
297
Matias Bjørlingade69e22017-01-31 13:17:09 +0100298/* sub-device structure */
Javier González8e79b5c2016-11-28 22:39:06 +0100299struct nvm_tgt_dev {
300 /* Device information */
301 struct nvm_geo geo;
302
Javier González8e536242016-11-28 22:39:10 +0100303 /* Base ppas for target LUNs */
304 struct ppa_addr *luns;
305
Javier González8e79b5c2016-11-28 22:39:06 +0100306 sector_t total_secs;
307
308 struct nvm_id identity;
309 struct request_queue *q;
310
Javier González959e9112016-11-28 22:39:11 +0100311 struct nvm_dev *parent;
Javier González8e536242016-11-28 22:39:10 +0100312 void *map;
Javier González8e79b5c2016-11-28 22:39:06 +0100313};
314
315struct nvm_dev {
316 struct nvm_dev_ops *ops;
317
318 struct list_head devices;
319
Javier González8e79b5c2016-11-28 22:39:06 +0100320 /* Device information */
321 struct nvm_geo geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100322
Matias Bjørlingade69e22017-01-31 13:17:09 +0100323 /* lower page table */
Matias Bjørlingca5927e2016-01-12 07:49:35 +0100324 int lps_per_blk;
325 int *lptbl;
326
Matias Bjørling4ece44a2016-02-20 08:52:41 +0100327 unsigned long total_secs;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100328
Wenwei Taoda1e2842016-03-03 15:06:38 +0100329 unsigned long *lun_map;
Javier González75b85642016-05-06 20:03:13 +0200330 void *dma_pool;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100331
332 struct nvm_id identity;
333
334 /* Backend device */
335 struct request_queue *q;
336 char name[DISK_NAME_LEN];
Simon A. F. Lund40267ef2016-09-16 14:25:08 +0200337 void *private_data;
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100338
Javier González8e536242016-11-28 22:39:10 +0100339 void *rmap;
340
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100341 struct mutex mlock;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100342 spinlock_t lock;
Matias Bjørlingade69e22017-01-31 13:17:09 +0100343
344 /* target management */
345 struct list_head area_list;
346 struct list_head targets;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100347};
348
Javier González8e79b5c2016-11-28 22:39:06 +0100349static inline struct ppa_addr linear_to_generic_addr(struct nvm_geo *geo,
Javier González8e536242016-11-28 22:39:10 +0100350 u64 pba)
Javier González0e5c3242016-11-28 22:39:01 +0100351{
352 struct ppa_addr l;
353 int secs, pgs, blks, luns;
Javier González8e536242016-11-28 22:39:10 +0100354 sector_t ppa = pba;
Javier González0e5c3242016-11-28 22:39:01 +0100355
356 l.ppa = 0;
357
Javier González8e79b5c2016-11-28 22:39:06 +0100358 div_u64_rem(ppa, geo->sec_per_pg, &secs);
Javier González0e5c3242016-11-28 22:39:01 +0100359 l.g.sec = secs;
360
Javier González8e79b5c2016-11-28 22:39:06 +0100361 sector_div(ppa, geo->sec_per_pg);
362 div_u64_rem(ppa, geo->pgs_per_blk, &pgs);
Javier González0e5c3242016-11-28 22:39:01 +0100363 l.g.pg = pgs;
364
Javier González8e79b5c2016-11-28 22:39:06 +0100365 sector_div(ppa, geo->pgs_per_blk);
366 div_u64_rem(ppa, geo->blks_per_lun, &blks);
Javier González0e5c3242016-11-28 22:39:01 +0100367 l.g.blk = blks;
368
Javier González8e79b5c2016-11-28 22:39:06 +0100369 sector_div(ppa, geo->blks_per_lun);
370 div_u64_rem(ppa, geo->luns_per_chnl, &luns);
Javier González0e5c3242016-11-28 22:39:01 +0100371 l.g.lun = luns;
372
Javier González8e79b5c2016-11-28 22:39:06 +0100373 sector_div(ppa, geo->luns_per_chnl);
Javier González0e5c3242016-11-28 22:39:01 +0100374 l.g.ch = ppa;
375
376 return l;
377}
378
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100379static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev,
380 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100381{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100382 struct nvm_geo *geo = &tgt_dev->geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100383 struct ppa_addr l;
384
Javier González8e79b5c2016-11-28 22:39:06 +0100385 l.ppa = ((u64)r.g.blk) << geo->ppaf.blk_offset;
386 l.ppa |= ((u64)r.g.pg) << geo->ppaf.pg_offset;
387 l.ppa |= ((u64)r.g.sec) << geo->ppaf.sect_offset;
388 l.ppa |= ((u64)r.g.pl) << geo->ppaf.pln_offset;
389 l.ppa |= ((u64)r.g.lun) << geo->ppaf.lun_offset;
390 l.ppa |= ((u64)r.g.ch) << geo->ppaf.ch_offset;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100391
392 return l;
393}
394
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100395static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev,
396 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100397{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100398 struct nvm_geo *geo = &tgt_dev->geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100399 struct ppa_addr l;
400
Javier González5389a1d2016-07-07 09:54:09 +0200401 l.ppa = 0;
Matias Bjørling7386af22015-11-16 15:34:44 +0100402 /*
403 * (r.ppa << X offset) & X len bitmask. X eq. blk, pg, etc.
404 */
Javier González8e79b5c2016-11-28 22:39:06 +0100405 l.g.blk = (r.ppa >> geo->ppaf.blk_offset) &
406 (((1 << geo->ppaf.blk_len) - 1));
407 l.g.pg |= (r.ppa >> geo->ppaf.pg_offset) &
408 (((1 << geo->ppaf.pg_len) - 1));
409 l.g.sec |= (r.ppa >> geo->ppaf.sect_offset) &
410 (((1 << geo->ppaf.sect_len) - 1));
411 l.g.pl |= (r.ppa >> geo->ppaf.pln_offset) &
412 (((1 << geo->ppaf.pln_len) - 1));
413 l.g.lun |= (r.ppa >> geo->ppaf.lun_offset) &
414 (((1 << geo->ppaf.lun_len) - 1));
415 l.g.ch |= (r.ppa >> geo->ppaf.ch_offset) &
416 (((1 << geo->ppaf.ch_len) - 1));
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100417
418 return l;
419}
420
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100421static inline int ppa_empty(struct ppa_addr ppa_addr)
422{
423 return (ppa_addr.ppa == ADDR_EMPTY);
424}
425
426static inline void ppa_set_empty(struct ppa_addr *ppa_addr)
427{
428 ppa_addr->ppa = ADDR_EMPTY;
429}
430
Javier Gonzáleza24ba462016-11-28 22:38:56 +0100431static inline int ppa_cmp_blk(struct ppa_addr ppa1, struct ppa_addr ppa2)
432{
433 if (ppa_empty(ppa1) || ppa_empty(ppa2))
434 return 0;
435
436 return ((ppa1.g.ch == ppa2.g.ch) && (ppa1.g.lun == ppa2.g.lun) &&
437 (ppa1.g.blk == ppa2.g.blk));
438}
439
Jens Axboedece1632015-11-05 10:41:16 -0700440typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100441typedef sector_t (nvm_tgt_capacity_fn)(void *);
Javier González4af3f752017-04-15 20:55:45 +0200442typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *,
443 int flags);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100444typedef void (nvm_tgt_exit_fn)(void *);
Javier González9a69b0e2017-01-31 13:17:20 +0100445typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *);
446typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100447
448struct nvm_tgt_type {
449 const char *name;
450 unsigned int version[3];
451
452 /* target entry points */
453 nvm_tgt_make_rq_fn *make_rq;
454 nvm_tgt_capacity_fn *capacity;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100455
456 /* module-specific init/teardown */
457 nvm_tgt_init_fn *init;
458 nvm_tgt_exit_fn *exit;
459
Javier González9a69b0e2017-01-31 13:17:20 +0100460 /* sysfs */
461 nvm_tgt_sysfs_init_fn *sysfs_init;
462 nvm_tgt_sysfs_exit_fn *sysfs_exit;
463
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100464 /* For internal use */
465 struct list_head list;
Rakesh Pandit90014822017-10-13 14:45:50 +0200466 struct module *owner;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100467};
468
Simon A. F. Lund6063fe32016-05-06 20:03:02 +0200469extern int nvm_register_tgt_type(struct nvm_tgt_type *);
470extern void nvm_unregister_tgt_type(struct nvm_tgt_type *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100471
472extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
473extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
474
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200475extern struct nvm_dev *nvm_alloc_dev(int);
476extern int nvm_register(struct nvm_dev *);
477extern void nvm_unregister(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100478
Javier González333ba052016-11-28 22:39:14 +0100479extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *,
480 int, int);
Javier Gonzáleza2790062016-11-28 22:39:12 +0100481extern int nvm_max_phys_sects(struct nvm_tgt_dev *);
Javier González8e536242016-11-28 22:39:10 +0100482extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *);
Javier González1a94b2d2017-10-13 14:46:47 +0200483extern int nvm_submit_io_sync(struct nvm_tgt_dev *, struct nvm_rq *);
Javier González17912c42017-04-15 20:55:37 +0200484extern int nvm_erase_sync(struct nvm_tgt_dev *, struct ppa_addr *, int);
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ørlingade69e22017-01-31 13:17:09 +0100493extern void nvm_part_to_tgt(struct nvm_dev *, sector_t *, int);
Matias Bjørling51360612016-05-06 20:03:04 +0200494
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100495#else /* CONFIG_NVM */
496struct nvm_dev_ops;
497
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200498static inline struct nvm_dev *nvm_alloc_dev(int node)
499{
500 return ERR_PTR(-EINVAL);
501}
502static inline int nvm_register(struct nvm_dev *dev)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100503{
504 return -EINVAL;
505}
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200506static inline void nvm_unregister(struct nvm_dev *dev) {}
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100507#endif /* CONFIG_NVM */
508#endif /* LIGHTNVM.H */