blob: 870959a58fefa091d270fb24f2e76a203972da71 [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
Javier Gonzálezf1d4e812018-03-30 00:05:12 +020026enum {
27 NVM_OCSSD_SPEC_12 = 12,
28 NVM_OCSSD_SPEC_20 = 20,
29};
30
Jens Axboea7fd9a42016-01-13 13:04:11 -070031struct 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ørlingdf414b32016-05-06 20:03:19 +020041 u64 reserved : 1;
Jens Axboea7fd9a42016-01-13 13:04:11 -070042 } g;
43
Matias Bjørlingdf414b32016-05-06 20:03:19 +020044 struct {
45 u64 line : 63;
46 u64 is_cached : 1;
47 } c;
48
Jens Axboea7fd9a42016-01-13 13:04:11 -070049 u64 ppa;
50 };
51};
52
53struct nvm_rq;
54struct nvm_id;
55struct nvm_dev;
Javier González8e536242016-11-28 22:39:10 +010056struct nvm_tgt_dev;
Jens Axboea7fd9a42016-01-13 13:04:11 -070057
Javier Gonzáleze46f4e42018-03-30 00:05:10 +020058typedef int (nvm_id_fn)(struct nvm_dev *);
Matias Bjørlinge11903f2016-05-06 20:03:05 +020059typedef int (nvm_op_bb_tbl_fn)(struct nvm_dev *, struct ppa_addr, u8 *);
Matias Bjørling00ee6cc2016-05-06 20:03:09 +020060typedef int (nvm_op_set_bb_fn)(struct nvm_dev *, struct ppa_addr *, int, int);
Jens Axboea7fd9a42016-01-13 13:04:11 -070061typedef int (nvm_submit_io_fn)(struct nvm_dev *, struct nvm_rq *);
Javier González1a94b2d2017-10-13 14:46:47 +020062typedef int (nvm_submit_io_sync_fn)(struct nvm_dev *, struct nvm_rq *);
Jens Axboea7fd9a42016-01-13 13:04:11 -070063typedef void *(nvm_create_dma_pool_fn)(struct nvm_dev *, char *);
64typedef void (nvm_destroy_dma_pool_fn)(void *);
65typedef void *(nvm_dev_dma_alloc_fn)(struct nvm_dev *, void *, gfp_t,
66 dma_addr_t *);
67typedef void (nvm_dev_dma_free_fn)(void *, void*, dma_addr_t);
68
69struct nvm_dev_ops {
70 nvm_id_fn *identity;
Jens Axboea7fd9a42016-01-13 13:04:11 -070071 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ález1a94b2d2017-10-13 14:46:47 +020075 nvm_submit_io_sync_fn *submit_io_sync;
Jens Axboea7fd9a42016-01-13 13:04:11 -070076
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 Axboea7fd9a42016-01-13 13:04:11 -070081};
82
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010083#ifdef CONFIG_NVM
84
85#include <linux/blkdev.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010086#include <linux/file.h>
87#include <linux/dmapool.h>
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010088#include <uapi/linux/lightnvm.h>
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010089
90enum {
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ørlingd5bdec82016-02-19 13:56:58 +0100100 NVM_PLANE_SINGLE = 1,
101 NVM_PLANE_DOUBLE = 2,
102 NVM_PLANE_QUAD = 4,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100103
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ález402ab9a2016-11-28 22:38:57 +0100109 NVM_RSP_ERR_FAILECC = 0x4281,
Javier González38ea2f72017-01-31 13:17:18 +0100110 NVM_RSP_ERR_FAILCRC = 0x4004,
Javier González402ab9a2016-11-28 22:38:57 +0100111 NVM_RSP_WARN_HIGHECC = 0x4700,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100112
113 /* Device opcodes */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100114 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
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200160struct nvm_addrf_12 {
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200161 u8 ch_len;
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200162 u8 lun_len;
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200163 u8 blk_len;
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200164 u8 pg_len;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200165 u8 pln_len;
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200166 u8 sect_len;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200167
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ørlingc6ac3f32018-03-30 00:05:01 +0200181};
182
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200183struct 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ørlingc6ac3f32018-03-30 00:05:01 +0200189
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200190 u8 ch_offset;
191 u8 lun_offset;
192 u8 chk_offset;
193 u8 sec_offset;
194 u8 rsv_off[2];
Matias Bjørlingc6ac3f32018-03-30 00:05:01 +0200195
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200196 u64 ch_mask;
197 u64 lun_mask;
198 u64 chk_mask;
199 u64 sec_mask;
200 u64 rsv_mask[2];
201};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100202
203struct nvm_target {
204 struct list_head list;
Javier González8e79b5c2016-11-28 22:39:06 +0100205 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100206 struct nvm_tgt_type *type;
207 struct gendisk *disk;
208};
209
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100210#define ADDR_EMPTY (~0ULL)
211
Javier Gonzáleze5392732018-01-05 14:16:14 +0100212#define NVM_TARGET_DEFAULT_OP (101)
213#define NVM_TARGET_MIN_OP (3)
214#define NVM_TARGET_MAX_OP (80)
215
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100216#define NVM_VERSION_MAJOR 1
217#define NVM_VERSION_MINOR 0
218#define NVM_VERSION_PATCH 0
219
Matias Bjørling89a09c52018-03-30 00:05:04 +0200220#define NVM_MAX_VLBA (64) /* max logical blocks in a vector command */
221
Matias Bjørling912761622016-01-12 07:49:21 +0100222struct nvm_rq;
Matias Bjørling72d256e2016-01-12 07:49:29 +0100223typedef void (nvm_end_io_fn)(struct nvm_rq *);
Matias Bjørling912761622016-01-12 07:49:21 +0100224
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100225struct nvm_rq {
Javier González8e536242016-11-28 22:39:10 +0100226 struct nvm_tgt_dev *dev;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100227
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ález003fad32016-05-06 20:03:12 +0200237 void *meta_list;
238 dma_addr_t dma_meta_list;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100239
Matias Bjørling912761622016-01-12 07:49:21 +0100240 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áleze46f4e42018-03-30 00:05:10 +0200268/* Instance geometry */
Javier González8e79b5c2016-11-28 22:39:06 +0100269struct nvm_geo {
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200270 /* device reported version */
Javier González3cb98f82018-03-30 00:05:11 +0200271 u8 major_ver_id;
272 u8 minor_ver_id;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200273
Javier Gonzálezf1d4e812018-03-30 00:05:12 +0200274 /* kernel short version */
275 u8 version;
276
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200277 /* instance specific geometry */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100278 int nr_chnls;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200279 int nr_luns; /* per channel */
Matias Bjørlingfae7fae2018-01-05 14:16:03 +0100280
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200281 /* calculated values */
282 int all_luns; /* across channels */
283 int all_chunks; /* across channels */
Matias Bjørlingfae7fae2018-01-05 14:16:03 +0100284
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200285 int op; /* over-provision in instance */
Matias Bjørlingfae7fae2018-01-05 14:16:03 +0100286
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200287 sector_t total_secs; /* across channels */
Matias Bjørlingfae7fae2018-01-05 14:16:03 +0100288
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200289 /* 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áleze5392732018-01-05 14:16:14 +0100294
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200295 /* 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ález3f480212018-03-30 00:05:13 +0200299 u32 maxoc; /* maximum open chunks */
300 u32 maxocpu; /* maximum open chunks per parallel unit */
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100301
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200302 /* 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ález8e79b5c2016-11-28 22:39:06 +0100331};
332
Matias Bjørlingade69e22017-01-31 13:17:09 +0100333/* sub-device structure */
Javier González8e79b5c2016-11-28 22:39:06 +0100334struct nvm_tgt_dev {
335 /* Device information */
336 struct nvm_geo geo;
337
Javier González8e536242016-11-28 22:39:10 +0100338 /* Base ppas for target LUNs */
339 struct ppa_addr *luns;
340
Javier González8e79b5c2016-11-28 22:39:06 +0100341 struct request_queue *q;
342
Javier González959e9112016-11-28 22:39:11 +0100343 struct nvm_dev *parent;
Javier González8e536242016-11-28 22:39:10 +0100344 void *map;
Javier González8e79b5c2016-11-28 22:39:06 +0100345};
346
347struct nvm_dev {
348 struct nvm_dev_ops *ops;
349
350 struct list_head devices;
351
Javier González8e79b5c2016-11-28 22:39:06 +0100352 /* Device information */
353 struct nvm_geo geo;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100354
Wenwei Taoda1e2842016-03-03 15:06:38 +0100355 unsigned long *lun_map;
Javier González75b85642016-05-06 20:03:13 +0200356 void *dma_pool;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100357
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100358 /* Backend device */
359 struct request_queue *q;
360 char name[DISK_NAME_LEN];
Simon A. F. Lund40267ef2016-09-16 14:25:08 +0200361 void *private_data;
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100362
Javier González8e536242016-11-28 22:39:10 +0100363 void *rmap;
364
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100365 struct mutex mlock;
Wenwei Tao4c9dacb2016-03-03 15:06:37 +0100366 spinlock_t lock;
Matias Bjørlingade69e22017-01-31 13:17:09 +0100367
368 /* target management */
369 struct list_head area_list;
370 struct list_head targets;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100371};
372
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100373static inline struct ppa_addr generic_to_dev_addr(struct nvm_tgt_dev *tgt_dev,
374 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100375{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100376 struct nvm_geo *geo = &tgt_dev->geo;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200377 struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&geo->addrf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100378 struct ppa_addr l;
379
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200380 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ørlingcd9e9802015-10-28 19:54:55 +0100386
387 return l;
388}
389
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100390static inline struct ppa_addr dev_to_generic_addr(struct nvm_tgt_dev *tgt_dev,
391 struct ppa_addr r)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100392{
Matias Bjørlingdab8ee92017-01-31 13:17:14 +0100393 struct nvm_geo *geo = &tgt_dev->geo;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200394 struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&geo->addrf;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100395 struct ppa_addr l;
396
Javier González5389a1d2016-07-07 09:54:09 +0200397 l.ppa = 0;
Javier Gonzáleze46f4e42018-03-30 00:05:10 +0200398
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ørlingcd9e9802015-10-28 19:54:55 +0100405
406 return l;
407}
408
Jens Axboedece1632015-11-05 10:41:16 -0700409typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100410typedef sector_t (nvm_tgt_capacity_fn)(void *);
Javier González4af3f752017-04-15 20:55:45 +0200411typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *,
412 int flags);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100413typedef void (nvm_tgt_exit_fn)(void *);
Javier González9a69b0e2017-01-31 13:17:20 +0100414typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *);
415typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100416
417struct 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ørlingcd9e9802015-10-28 19:54:55 +0100424
425 /* module-specific init/teardown */
426 nvm_tgt_init_fn *init;
427 nvm_tgt_exit_fn *exit;
428
Javier González9a69b0e2017-01-31 13:17:20 +0100429 /* sysfs */
430 nvm_tgt_sysfs_init_fn *sysfs_init;
431 nvm_tgt_sysfs_exit_fn *sysfs_exit;
432
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100433 /* For internal use */
434 struct list_head list;
Rakesh Pandit90014822017-10-13 14:45:50 +0200435 struct module *owner;
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100436};
437
Simon A. F. Lund6063fe32016-05-06 20:03:02 +0200438extern int nvm_register_tgt_type(struct nvm_tgt_type *);
439extern void nvm_unregister_tgt_type(struct nvm_tgt_type *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100440
441extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *);
442extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t);
443
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200444extern struct nvm_dev *nvm_alloc_dev(int);
445extern int nvm_register(struct nvm_dev *);
446extern void nvm_unregister(struct nvm_dev *);
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100447
Javier González333ba052016-11-28 22:39:14 +0100448extern int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr *,
449 int, int);
Javier González8e536242016-11-28 22:39:10 +0100450extern int nvm_submit_io(struct nvm_tgt_dev *, struct nvm_rq *);
Javier González1a94b2d2017-10-13 14:46:47 +0200451extern int nvm_submit_io_sync(struct nvm_tgt_dev *, struct nvm_rq *);
Matias Bjørling06894ef2017-01-31 13:17:17 +0100452extern void nvm_end_io(struct nvm_rq *);
Matias Bjørling22e8c972016-05-06 20:02:58 +0200453extern int nvm_bb_tbl_fold(struct nvm_dev *, u8 *, int);
Javier González333ba052016-11-28 22:39:14 +0100454extern int nvm_get_tgt_bb_tbl(struct nvm_tgt_dev *, struct ppa_addr, u8 *);
Matias Bjørlinge3eb3792016-01-12 07:49:36 +0100455
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100456#else /* CONFIG_NVM */
457struct nvm_dev_ops;
458
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200459static inline struct nvm_dev *nvm_alloc_dev(int node)
460{
461 return ERR_PTR(-EINVAL);
462}
463static inline int nvm_register(struct nvm_dev *dev)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100464{
465 return -EINVAL;
466}
Matias Bjørlingb0b4e092016-09-16 14:25:07 +0200467static inline void nvm_unregister(struct nvm_dev *dev) {}
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100468#endif /* CONFIG_NVM */
469#endif /* LIGHTNVM.H */