]>
Commit | Line | Data |
---|---|---|
bc50ad75 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
f11bb3e2 CH |
2 | /* |
3 | * Copyright (c) 2011-2014, Intel Corporation. | |
f11bb3e2 CH |
4 | */ |
5 | ||
6 | #ifndef _NVME_H | |
7 | #define _NVME_H | |
8 | ||
9 | #include <linux/nvme.h> | |
a6a5149b | 10 | #include <linux/cdev.h> |
f11bb3e2 CH |
11 | #include <linux/pci.h> |
12 | #include <linux/kref.h> | |
13 | #include <linux/blk-mq.h> | |
b0b4e09c | 14 | #include <linux/lightnvm.h> |
a98e58e5 | 15 | #include <linux/sed-opal.h> |
b9e03857 | 16 | #include <linux/fault-inject.h> |
978628ec | 17 | #include <linux/rcupdate.h> |
c1ac9a4b | 18 | #include <linux/wait.h> |
4d2ce688 | 19 | #include <linux/t10-pi.h> |
f11bb3e2 | 20 | |
35fe0d12 HR |
21 | #include <trace/events/block.h> |
22 | ||
8ae4e447 | 23 | extern unsigned int nvme_io_timeout; |
f11bb3e2 CH |
24 | #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ) |
25 | ||
8ae4e447 | 26 | extern unsigned int admin_timeout; |
21d34711 CH |
27 | #define ADMIN_TIMEOUT (admin_timeout * HZ) |
28 | ||
038bd4cb SG |
29 | #define NVME_DEFAULT_KATO 5 |
30 | #define NVME_KATO_GRACE 10 | |
31 | ||
38e18002 IR |
32 | #ifdef CONFIG_ARCH_NO_SG_CHAIN |
33 | #define NVME_INLINE_SG_CNT 0 | |
ba7ca2ae | 34 | #define NVME_INLINE_METADATA_SG_CNT 0 |
38e18002 IR |
35 | #else |
36 | #define NVME_INLINE_SG_CNT 2 | |
ba7ca2ae | 37 | #define NVME_INLINE_METADATA_SG_CNT 1 |
38e18002 IR |
38 | #endif |
39 | ||
9a6327d2 | 40 | extern struct workqueue_struct *nvme_wq; |
b227c59b RS |
41 | extern struct workqueue_struct *nvme_reset_wq; |
42 | extern struct workqueue_struct *nvme_delete_wq; | |
9a6327d2 | 43 | |
ca064085 MB |
44 | enum { |
45 | NVME_NS_LBA = 0, | |
46 | NVME_NS_LIGHTNVM = 1, | |
47 | }; | |
48 | ||
f11bb3e2 | 49 | /* |
106198ed CH |
50 | * List of workarounds for devices that required behavior not specified in |
51 | * the standard. | |
f11bb3e2 | 52 | */ |
106198ed CH |
53 | enum nvme_quirks { |
54 | /* | |
55 | * Prefers I/O aligned to a stripe size specified in a vendor | |
56 | * specific Identify field. | |
57 | */ | |
58 | NVME_QUIRK_STRIPE_SIZE = (1 << 0), | |
540c801c KB |
59 | |
60 | /* | |
61 | * The controller doesn't handle Identify value others than 0 or 1 | |
62 | * correctly. | |
63 | */ | |
64 | NVME_QUIRK_IDENTIFY_CNS = (1 << 1), | |
08095e70 KB |
65 | |
66 | /* | |
e850fd16 CH |
67 | * The controller deterministically returns O's on reads to |
68 | * logical blocks that deallocate was called on. | |
08095e70 | 69 | */ |
e850fd16 | 70 | NVME_QUIRK_DEALLOCATE_ZEROES = (1 << 2), |
54adc010 GP |
71 | |
72 | /* | |
73 | * The controller needs a delay before starts checking the device | |
74 | * readiness, which is done by reading the NVME_CSTS_RDY bit. | |
75 | */ | |
76 | NVME_QUIRK_DELAY_BEFORE_CHK_RDY = (1 << 3), | |
c5552fde AL |
77 | |
78 | /* | |
79 | * APST should not be used. | |
80 | */ | |
81 | NVME_QUIRK_NO_APST = (1 << 4), | |
ff5350a8 AL |
82 | |
83 | /* | |
84 | * The deepest sleep state should not be used. | |
85 | */ | |
86 | NVME_QUIRK_NO_DEEPEST_PS = (1 << 5), | |
608cc4b1 CH |
87 | |
88 | /* | |
89 | * Supports the LighNVM command set if indicated in vs[1]. | |
90 | */ | |
91 | NVME_QUIRK_LIGHTNVM = (1 << 6), | |
9abd68ef JA |
92 | |
93 | /* | |
94 | * Set MEDIUM priority on SQ creation | |
95 | */ | |
96 | NVME_QUIRK_MEDIUM_PRIO_SQ = (1 << 7), | |
6299358d JD |
97 | |
98 | /* | |
99 | * Ignore device provided subnqn. | |
100 | */ | |
101 | NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8), | |
7b210e4e CH |
102 | |
103 | /* | |
104 | * Broken Write Zeroes. | |
105 | */ | |
106 | NVME_QUIRK_DISABLE_WRITE_ZEROES = (1 << 9), | |
cb32de1b ML |
107 | |
108 | /* | |
109 | * Force simple suspend/resume path. | |
110 | */ | |
111 | NVME_QUIRK_SIMPLE_SUSPEND = (1 << 10), | |
7ad67ca5 | 112 | |
66341331 BH |
113 | /* |
114 | * Use only one interrupt vector for all queues | |
115 | */ | |
7ad67ca5 | 116 | NVME_QUIRK_SINGLE_VECTOR = (1 << 11), |
66341331 BH |
117 | |
118 | /* | |
119 | * Use non-standard 128 bytes SQEs. | |
120 | */ | |
7ad67ca5 | 121 | NVME_QUIRK_128_BYTES_SQES = (1 << 12), |
d38e9f04 BH |
122 | |
123 | /* | |
124 | * Prevent tag overlap between queues | |
125 | */ | |
7ad67ca5 | 126 | NVME_QUIRK_SHARED_TAGS = (1 << 13), |
6c6aa2f2 AM |
127 | |
128 | /* | |
129 | * Don't change the value of the temperature threshold feature | |
130 | */ | |
131 | NVME_QUIRK_NO_TEMP_THRESH_CHANGE = (1 << 14), | |
106198ed CH |
132 | }; |
133 | ||
d49187e9 CH |
134 | /* |
135 | * Common request structure for NVMe passthrough. All drivers must have | |
136 | * this structure as the first member of their request-private data. | |
137 | */ | |
138 | struct nvme_request { | |
139 | struct nvme_command *cmd; | |
140 | union nvme_result result; | |
44e44b29 | 141 | u8 retries; |
27fa9bc5 CH |
142 | u8 flags; |
143 | u16 status; | |
59e29ce6 | 144 | struct nvme_ctrl *ctrl; |
27fa9bc5 CH |
145 | }; |
146 | ||
32acab31 CH |
147 | /* |
148 | * Mark a bio as coming in through the mpath node. | |
149 | */ | |
150 | #define REQ_NVME_MPATH REQ_DRV | |
151 | ||
27fa9bc5 CH |
152 | enum { |
153 | NVME_REQ_CANCELLED = (1 << 0), | |
bb06ec31 | 154 | NVME_REQ_USERCMD = (1 << 1), |
d49187e9 CH |
155 | }; |
156 | ||
157 | static inline struct nvme_request *nvme_req(struct request *req) | |
158 | { | |
159 | return blk_mq_rq_to_pdu(req); | |
160 | } | |
161 | ||
5d87eb94 KB |
162 | static inline u16 nvme_req_qid(struct request *req) |
163 | { | |
164 | if (!req->rq_disk) | |
165 | return 0; | |
166 | return blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(req)) + 1; | |
167 | } | |
168 | ||
54adc010 GP |
169 | /* The below value is the specific amount of delay needed before checking |
170 | * readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the | |
171 | * NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was | |
172 | * found empirically. | |
173 | */ | |
8c97eecc | 174 | #define NVME_QUIRK_DELAY_AMOUNT 2300 |
54adc010 | 175 | |
bb8d261e CH |
176 | enum nvme_ctrl_state { |
177 | NVME_CTRL_NEW, | |
178 | NVME_CTRL_LIVE, | |
179 | NVME_CTRL_RESETTING, | |
ad6a0a52 | 180 | NVME_CTRL_CONNECTING, |
bb8d261e | 181 | NVME_CTRL_DELETING, |
0ff9d4e1 | 182 | NVME_CTRL_DEAD, |
bb8d261e CH |
183 | }; |
184 | ||
a3646451 AM |
185 | struct nvme_fault_inject { |
186 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | |
187 | struct fault_attr attr; | |
188 | struct dentry *parent; | |
189 | bool dont_retry; /* DNR, do not retry */ | |
190 | u16 status; /* status code */ | |
191 | #endif | |
192 | }; | |
193 | ||
1c63dc66 | 194 | struct nvme_ctrl { |
6e3ca03e | 195 | bool comp_seen; |
bb8d261e | 196 | enum nvme_ctrl_state state; |
bd4da3ab | 197 | bool identified; |
bb8d261e | 198 | spinlock_t lock; |
e7ad43c3 | 199 | struct mutex scan_lock; |
1c63dc66 | 200 | const struct nvme_ctrl_ops *ops; |
f11bb3e2 | 201 | struct request_queue *admin_q; |
07bfcd09 | 202 | struct request_queue *connect_q; |
e7832cb4 | 203 | struct request_queue *fabrics_q; |
f11bb3e2 | 204 | struct device *dev; |
f11bb3e2 | 205 | int instance; |
103e515e | 206 | int numa_node; |
5bae7f73 | 207 | struct blk_mq_tag_set *tagset; |
34b6c231 | 208 | struct blk_mq_tag_set *admin_tagset; |
f11bb3e2 | 209 | struct list_head namespaces; |
765cc031 | 210 | struct rw_semaphore namespaces_rwsem; |
d22524a4 | 211 | struct device ctrl_device; |
5bae7f73 | 212 | struct device *device; /* char device */ |
a6a5149b | 213 | struct cdev cdev; |
d86c4d8e | 214 | struct work_struct reset_work; |
c5017e85 | 215 | struct work_struct delete_work; |
c1ac9a4b | 216 | wait_queue_head_t state_wq; |
1c63dc66 | 217 | |
ab9e00cc CH |
218 | struct nvme_subsystem *subsys; |
219 | struct list_head subsys_entry; | |
220 | ||
4f1244c8 | 221 | struct opal_dev *opal_dev; |
a98e58e5 | 222 | |
f11bb3e2 | 223 | char name[12]; |
76e3914a | 224 | u16 cntlid; |
5fd4ce1b CH |
225 | |
226 | u32 ctrl_config; | |
b6dccf7f | 227 | u16 mtfa; |
d858e5f0 | 228 | u32 queue_count; |
5fd4ce1b | 229 | |
20d0dfe6 | 230 | u64 cap; |
5fd4ce1b | 231 | u32 page_size; |
f11bb3e2 | 232 | u32 max_hw_sectors; |
943e942e | 233 | u32 max_segments; |
95093350 | 234 | u32 max_integrity_segments; |
49cd84b6 | 235 | u16 crdt[3]; |
f11bb3e2 | 236 | u16 oncs; |
8a9ae523 | 237 | u16 oacs; |
f5d11840 JA |
238 | u16 nssa; |
239 | u16 nr_streams; | |
f968688f | 240 | u16 sqsize; |
0d0b660f | 241 | u32 max_namespaces; |
6bf25d16 | 242 | atomic_t abort_limit; |
f11bb3e2 | 243 | u8 vwc; |
f3ca80fc | 244 | u32 vs; |
07bfcd09 | 245 | u32 sgls; |
038bd4cb | 246 | u16 kas; |
c5552fde AL |
247 | u8 npss; |
248 | u8 apsta; | |
400b6a7b GR |
249 | u16 wctemp; |
250 | u16 cctemp; | |
c0561f82 | 251 | u32 oaes; |
e3d7874d | 252 | u32 aen_result; |
3e53ba38 | 253 | u32 ctratt; |
07fbd32a | 254 | unsigned int shutdown_timeout; |
038bd4cb | 255 | unsigned int kato; |
f3ca80fc | 256 | bool subsystem; |
106198ed | 257 | unsigned long quirks; |
c5552fde | 258 | struct nvme_id_power_state psd[32]; |
84fef62d | 259 | struct nvme_effects_log *effects; |
5955be21 | 260 | struct work_struct scan_work; |
f866fc42 | 261 | struct work_struct async_event_work; |
038bd4cb | 262 | struct delayed_work ka_work; |
0a34e466 | 263 | struct nvme_command ka_cmd; |
b6dccf7f | 264 | struct work_struct fw_act_work; |
30d90964 | 265 | unsigned long events; |
ce151813 | 266 | bool created; |
07bfcd09 | 267 | |
0d0b660f CH |
268 | #ifdef CONFIG_NVME_MULTIPATH |
269 | /* asymmetric namespace access: */ | |
270 | u8 anacap; | |
271 | u8 anatt; | |
272 | u32 anagrpmax; | |
273 | u32 nanagrpid; | |
274 | struct mutex ana_lock; | |
275 | struct nvme_ana_rsp_hdr *ana_log_buf; | |
276 | size_t ana_log_size; | |
277 | struct timer_list anatt_timer; | |
278 | struct work_struct ana_work; | |
279 | #endif | |
280 | ||
c5552fde AL |
281 | /* Power saving configuration */ |
282 | u64 ps_max_latency_us; | |
76a5af84 | 283 | bool apst_enabled; |
c5552fde | 284 | |
044a9df1 | 285 | /* PCIe only: */ |
fe6d53c9 CH |
286 | u32 hmpre; |
287 | u32 hmmin; | |
044a9df1 CH |
288 | u32 hmminds; |
289 | u16 hmmaxd; | |
fe6d53c9 | 290 | |
07bfcd09 | 291 | /* Fabrics only */ |
07bfcd09 CH |
292 | u32 ioccsz; |
293 | u32 iorcsz; | |
294 | u16 icdoff; | |
295 | u16 maxcmd; | |
fdf9dfa8 | 296 | int nr_reconnects; |
07bfcd09 | 297 | struct nvmf_ctrl_options *opts; |
cb5b7262 JA |
298 | |
299 | struct page *discard_page; | |
300 | unsigned long discard_page_busy; | |
f79d5fda AM |
301 | |
302 | struct nvme_fault_inject fault_inject; | |
f11bb3e2 CH |
303 | }; |
304 | ||
75c10e73 HR |
305 | enum nvme_iopolicy { |
306 | NVME_IOPOLICY_NUMA, | |
307 | NVME_IOPOLICY_RR, | |
308 | }; | |
309 | ||
ab9e00cc CH |
310 | struct nvme_subsystem { |
311 | int instance; | |
312 | struct device dev; | |
313 | /* | |
314 | * Because we unregister the device on the last put we need | |
315 | * a separate refcount. | |
316 | */ | |
317 | struct kref ref; | |
318 | struct list_head entry; | |
319 | struct mutex lock; | |
320 | struct list_head ctrls; | |
ed754e5d | 321 | struct list_head nsheads; |
ab9e00cc CH |
322 | char subnqn[NVMF_NQN_SIZE]; |
323 | char serial[20]; | |
324 | char model[40]; | |
325 | char firmware_rev[8]; | |
326 | u8 cmic; | |
327 | u16 vendor_id; | |
81adb863 | 328 | u16 awupf; /* 0's based awupf value. */ |
ed754e5d | 329 | struct ida ns_ida; |
75c10e73 HR |
330 | #ifdef CONFIG_NVME_MULTIPATH |
331 | enum nvme_iopolicy iopolicy; | |
332 | #endif | |
ab9e00cc CH |
333 | }; |
334 | ||
002fab04 CH |
335 | /* |
336 | * Container structure for uniqueue namespace identifiers. | |
337 | */ | |
338 | struct nvme_ns_ids { | |
339 | u8 eui64[8]; | |
340 | u8 nguid[16]; | |
341 | uuid_t uuid; | |
71010c30 | 342 | u8 csi; |
002fab04 CH |
343 | }; |
344 | ||
ed754e5d CH |
345 | /* |
346 | * Anchor structure for namespaces. There is one for each namespace in a | |
347 | * NVMe subsystem that any of our controllers can see, and the namespace | |
348 | * structure for each controller is chained of it. For private namespaces | |
349 | * there is a 1:1 relation to our namespace structures, that is ->list | |
350 | * only ever has a single entry for private namespaces. | |
351 | */ | |
352 | struct nvme_ns_head { | |
353 | struct list_head list; | |
354 | struct srcu_struct srcu; | |
355 | struct nvme_subsystem *subsys; | |
356 | unsigned ns_id; | |
357 | struct nvme_ns_ids ids; | |
358 | struct list_head entry; | |
359 | struct kref ref; | |
0c284db7 | 360 | bool shared; |
ed754e5d | 361 | int instance; |
f3334447 CH |
362 | #ifdef CONFIG_NVME_MULTIPATH |
363 | struct gendisk *disk; | |
364 | struct bio_list requeue_list; | |
365 | spinlock_t requeue_lock; | |
366 | struct work_struct requeue_work; | |
367 | struct mutex lock; | |
d8a22f85 AE |
368 | unsigned long flags; |
369 | #define NVME_NSHEAD_DISK_LIVE 0 | |
f3334447 CH |
370 | struct nvme_ns __rcu *current_path[]; |
371 | #endif | |
ed754e5d CH |
372 | }; |
373 | ||
ffc89b1d MG |
374 | enum nvme_ns_features { |
375 | NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */ | |
b29f8485 | 376 | NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */ |
ffc89b1d MG |
377 | }; |
378 | ||
f11bb3e2 CH |
379 | struct nvme_ns { |
380 | struct list_head list; | |
381 | ||
1c63dc66 | 382 | struct nvme_ctrl *ctrl; |
f11bb3e2 CH |
383 | struct request_queue *queue; |
384 | struct gendisk *disk; | |
0d0b660f CH |
385 | #ifdef CONFIG_NVME_MULTIPATH |
386 | enum nvme_ana_state ana_state; | |
387 | u32 ana_grpid; | |
388 | #endif | |
ed754e5d | 389 | struct list_head siblings; |
b0b4e09c | 390 | struct nvm_dev *ndev; |
f11bb3e2 | 391 | struct kref kref; |
ed754e5d | 392 | struct nvme_ns_head *head; |
f11bb3e2 | 393 | |
f11bb3e2 CH |
394 | int lba_shift; |
395 | u16 ms; | |
f5d11840 JA |
396 | u16 sgs; |
397 | u32 sws; | |
f11bb3e2 | 398 | u8 pi_type; |
ffc89b1d | 399 | unsigned long features; |
646017a6 | 400 | unsigned long flags; |
0d0b660f CH |
401 | #define NVME_NS_REMOVING 0 |
402 | #define NVME_NS_DEAD 1 | |
403 | #define NVME_NS_ANA_PENDING 2 | |
b9e03857 | 404 | |
b9e03857 | 405 | struct nvme_fault_inject fault_inject; |
b9e03857 | 406 | |
f11bb3e2 CH |
407 | }; |
408 | ||
4d2ce688 JS |
409 | /* NVMe ns supports metadata actions by the controller (generate/strip) */ |
410 | static inline bool nvme_ns_has_pi(struct nvme_ns *ns) | |
411 | { | |
412 | return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple); | |
413 | } | |
414 | ||
1c63dc66 | 415 | struct nvme_ctrl_ops { |
1a353d85 | 416 | const char *name; |
e439bb12 | 417 | struct module *module; |
d3d5b87d CH |
418 | unsigned int flags; |
419 | #define NVME_F_FABRICS (1 << 0) | |
c81bfba9 | 420 | #define NVME_F_METADATA_SUPPORTED (1 << 1) |
e0596ab2 | 421 | #define NVME_F_PCI_P2PDMA (1 << 2) |
1c63dc66 | 422 | int (*reg_read32)(struct nvme_ctrl *ctrl, u32 off, u32 *val); |
5fd4ce1b | 423 | int (*reg_write32)(struct nvme_ctrl *ctrl, u32 off, u32 val); |
7fd8930f | 424 | int (*reg_read64)(struct nvme_ctrl *ctrl, u32 off, u64 *val); |
1673f1f0 | 425 | void (*free_ctrl)(struct nvme_ctrl *ctrl); |
ad22c355 | 426 | void (*submit_async_event)(struct nvme_ctrl *ctrl); |
c5017e85 | 427 | void (*delete_ctrl)(struct nvme_ctrl *ctrl); |
1a353d85 | 428 | int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size); |
f11bb3e2 CH |
429 | }; |
430 | ||
b9e03857 | 431 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
a3646451 AM |
432 | void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj, |
433 | const char *dev_name); | |
434 | void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject); | |
b9e03857 TT |
435 | void nvme_should_fail(struct request *req); |
436 | #else | |
a3646451 AM |
437 | static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj, |
438 | const char *dev_name) | |
439 | { | |
440 | } | |
441 | static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj) | |
442 | { | |
443 | } | |
b9e03857 TT |
444 | static inline void nvme_should_fail(struct request *req) {} |
445 | #endif | |
446 | ||
f3ca80fc CH |
447 | static inline int nvme_reset_subsystem(struct nvme_ctrl *ctrl) |
448 | { | |
449 | if (!ctrl->subsystem) | |
450 | return -ENOTTY; | |
451 | return ctrl->ops->reg_write32(ctrl, NVME_REG_NSSR, 0x4E564D65); | |
452 | } | |
453 | ||
314d48dd DLM |
454 | /* |
455 | * Convert a 512B sector number to a device logical block number. | |
456 | */ | |
457 | static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) | |
f11bb3e2 | 458 | { |
314d48dd | 459 | return sector >> (ns->lba_shift - SECTOR_SHIFT); |
f11bb3e2 CH |
460 | } |
461 | ||
e08f2ae8 DLM |
462 | /* |
463 | * Convert a device logical block number to a 512B sector number. | |
464 | */ | |
465 | static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba) | |
f11bb3e2 | 466 | { |
e08f2ae8 | 467 | return lba << (ns->lba_shift - SECTOR_SHIFT); |
f11bb3e2 CH |
468 | } |
469 | ||
71fb90eb KB |
470 | /* |
471 | * Convert byte length to nvme's 0-based num dwords | |
472 | */ | |
473 | static inline u32 nvme_bytes_to_numd(size_t len) | |
474 | { | |
475 | return (len >> 2) - 1; | |
476 | } | |
477 | ||
ff029451 | 478 | static inline bool nvme_end_request(struct request *req, __le16 status, |
27fa9bc5 | 479 | union nvme_result result) |
15a190f7 | 480 | { |
27fa9bc5 | 481 | struct nvme_request *rq = nvme_req(req); |
15a190f7 | 482 | |
27fa9bc5 CH |
483 | rq->status = le16_to_cpu(status) >> 1; |
484 | rq->result = result; | |
b9e03857 TT |
485 | /* inject error when permitted by fault injection framework */ |
486 | nvme_should_fail(req); | |
ff029451 CH |
487 | if (unlikely(blk_should_fake_timeout(req->q))) |
488 | return true; | |
489 | return blk_mq_complete_request_remote(req); | |
7688faa6 CH |
490 | } |
491 | ||
d22524a4 CH |
492 | static inline void nvme_get_ctrl(struct nvme_ctrl *ctrl) |
493 | { | |
494 | get_device(ctrl->device); | |
495 | } | |
496 | ||
497 | static inline void nvme_put_ctrl(struct nvme_ctrl *ctrl) | |
498 | { | |
499 | put_device(ctrl->device); | |
500 | } | |
501 | ||
58a8df67 IR |
502 | static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) |
503 | { | |
504 | return !qid && command_id >= NVME_AQ_BLK_MQ_DEPTH; | |
505 | } | |
506 | ||
77f02a7a | 507 | void nvme_complete_rq(struct request *req); |
7baa8572 | 508 | bool nvme_cancel_request(struct request *req, void *data, bool reserved); |
bb8d261e CH |
509 | bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, |
510 | enum nvme_ctrl_state new_state); | |
c1ac9a4b | 511 | bool nvme_wait_reset(struct nvme_ctrl *ctrl); |
b5b05048 | 512 | int nvme_disable_ctrl(struct nvme_ctrl *ctrl); |
c0f2f45b | 513 | int nvme_enable_ctrl(struct nvme_ctrl *ctrl); |
5fd4ce1b | 514 | int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl); |
f3ca80fc CH |
515 | int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, |
516 | const struct nvme_ctrl_ops *ops, unsigned long quirks); | |
53029b04 | 517 | void nvme_uninit_ctrl(struct nvme_ctrl *ctrl); |
d09f2b45 SG |
518 | void nvme_start_ctrl(struct nvme_ctrl *ctrl); |
519 | void nvme_stop_ctrl(struct nvme_ctrl *ctrl); | |
7fd8930f | 520 | int nvme_init_identify(struct nvme_ctrl *ctrl); |
5bae7f73 | 521 | |
5bae7f73 | 522 | void nvme_remove_namespaces(struct nvme_ctrl *ctrl); |
1673f1f0 | 523 | |
4f1244c8 CH |
524 | int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len, |
525 | bool send); | |
a98e58e5 | 526 | |
7bf58533 | 527 | void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, |
287a63eb | 528 | volatile union nvme_result *res); |
f866fc42 | 529 | |
25646264 KB |
530 | void nvme_stop_queues(struct nvme_ctrl *ctrl); |
531 | void nvme_start_queues(struct nvme_ctrl *ctrl); | |
69d9a99c | 532 | void nvme_kill_queues(struct nvme_ctrl *ctrl); |
d6135c3a | 533 | void nvme_sync_queues(struct nvme_ctrl *ctrl); |
302ad8cc KB |
534 | void nvme_unfreeze(struct nvme_ctrl *ctrl); |
535 | void nvme_wait_freeze(struct nvme_ctrl *ctrl); | |
536 | void nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout); | |
537 | void nvme_start_freeze(struct nvme_ctrl *ctrl); | |
363c9aac | 538 | |
eb71f435 | 539 | #define NVME_QID_ANY -1 |
4160982e | 540 | struct request *nvme_alloc_request(struct request_queue *q, |
9a95e4ef | 541 | struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid); |
f7f1fc36 | 542 | void nvme_cleanup_cmd(struct request *req); |
fc17b653 | 543 | blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req, |
8093f7ca | 544 | struct nvme_command *cmd); |
f11bb3e2 CH |
545 | int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, |
546 | void *buf, unsigned bufflen); | |
547 | int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, | |
d49187e9 | 548 | union nvme_result *result, void *buffer, unsigned bufflen, |
9a95e4ef | 549 | unsigned timeout, int qid, int at_head, |
6287b51c | 550 | blk_mq_req_flags_t flags, bool poll); |
1a87ee65 KB |
551 | int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid, |
552 | unsigned int dword11, void *buffer, size_t buflen, | |
553 | u32 *result); | |
554 | int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid, | |
555 | unsigned int dword11, void *buffer, size_t buflen, | |
556 | u32 *result); | |
9a0be7ab | 557 | int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count); |
038bd4cb | 558 | void nvme_stop_keep_alive(struct nvme_ctrl *ctrl); |
d86c4d8e | 559 | int nvme_reset_ctrl(struct nvme_ctrl *ctrl); |
79c48ccf | 560 | int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl); |
c1ac9a4b | 561 | int nvme_try_sched_reset(struct nvme_ctrl *ctrl); |
c5017e85 | 562 | int nvme_delete_ctrl(struct nvme_ctrl *ctrl); |
f11bb3e2 | 563 | |
0e98719b CH |
564 | int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, |
565 | void *log, size_t size, u64 offset); | |
d558fb51 | 566 | |
33b14f67 | 567 | extern const struct attribute_group *nvme_ns_id_attr_groups[]; |
32acab31 CH |
568 | extern const struct block_device_operations nvme_ns_head_ops; |
569 | ||
570 | #ifdef CONFIG_NVME_MULTIPATH | |
66b20ac0 MR |
571 | static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl) |
572 | { | |
573 | return ctrl->ana_log_buf != NULL; | |
574 | } | |
575 | ||
b9156dae SG |
576 | void nvme_mpath_unfreeze(struct nvme_subsystem *subsys); |
577 | void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys); | |
578 | void nvme_mpath_start_freeze(struct nvme_subsystem *subsys); | |
a785dbcc KB |
579 | void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, |
580 | struct nvme_ctrl *ctrl, int *flags); | |
764e9332 | 581 | bool nvme_failover_req(struct request *req); |
32acab31 CH |
582 | void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl); |
583 | int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head); | |
0d0b660f | 584 | void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id); |
32acab31 | 585 | void nvme_mpath_remove_disk(struct nvme_ns_head *head); |
0d0b660f CH |
586 | int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id); |
587 | void nvme_mpath_uninit(struct nvme_ctrl *ctrl); | |
588 | void nvme_mpath_stop(struct nvme_ctrl *ctrl); | |
0157ec8d SG |
589 | bool nvme_mpath_clear_current_path(struct nvme_ns *ns); |
590 | void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl); | |
32acab31 | 591 | struct nvme_ns *nvme_find_path(struct nvme_ns_head *head); |
c62b37d9 | 592 | blk_qc_t nvme_ns_head_submit_bio(struct bio *bio); |
479a322f SG |
593 | |
594 | static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) | |
595 | { | |
596 | struct nvme_ns_head *head = ns->head; | |
597 | ||
598 | if (head->disk && list_empty(&head->list)) | |
599 | kblockd_schedule_work(&head->requeue_work); | |
600 | } | |
601 | ||
35fe0d12 HR |
602 | static inline void nvme_trace_bio_complete(struct request *req, |
603 | blk_status_t status) | |
604 | { | |
605 | struct nvme_ns *ns = req->q->queuedata; | |
606 | ||
607 | if (req->cmd_flags & REQ_NVME_MPATH) | |
d24de76a | 608 | trace_block_bio_complete(ns->head->disk->queue, req->bio); |
35fe0d12 HR |
609 | } |
610 | ||
0d0b660f CH |
611 | extern struct device_attribute dev_attr_ana_grpid; |
612 | extern struct device_attribute dev_attr_ana_state; | |
75c10e73 | 613 | extern struct device_attribute subsys_attr_iopolicy; |
0d0b660f | 614 | |
32acab31 | 615 | #else |
0d0b660f CH |
616 | static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl) |
617 | { | |
618 | return false; | |
619 | } | |
a785dbcc KB |
620 | /* |
621 | * Without the multipath code enabled, multiple controller per subsystems are | |
622 | * visible as devices and thus we cannot use the subsystem instance. | |
623 | */ | |
624 | static inline void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns, | |
625 | struct nvme_ctrl *ctrl, int *flags) | |
626 | { | |
627 | sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->head->instance); | |
628 | } | |
629 | ||
764e9332 | 630 | static inline bool nvme_failover_req(struct request *req) |
32acab31 | 631 | { |
764e9332 | 632 | return false; |
32acab31 | 633 | } |
32acab31 CH |
634 | static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl) |
635 | { | |
636 | } | |
637 | static inline int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, | |
638 | struct nvme_ns_head *head) | |
639 | { | |
640 | return 0; | |
641 | } | |
0d0b660f CH |
642 | static inline void nvme_mpath_add_disk(struct nvme_ns *ns, |
643 | struct nvme_id_ns *id) | |
32acab31 CH |
644 | { |
645 | } | |
646 | static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head) | |
647 | { | |
648 | } | |
0157ec8d SG |
649 | static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns) |
650 | { | |
651 | return false; | |
652 | } | |
653 | static inline void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl) | |
479a322f SG |
654 | { |
655 | } | |
656 | static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) | |
32acab31 CH |
657 | { |
658 | } | |
35fe0d12 HR |
659 | static inline void nvme_trace_bio_complete(struct request *req, |
660 | blk_status_t status) | |
661 | { | |
662 | } | |
0d0b660f CH |
663 | static inline int nvme_mpath_init(struct nvme_ctrl *ctrl, |
664 | struct nvme_id_ctrl *id) | |
665 | { | |
14a1336e CH |
666 | if (ctrl->subsys->cmic & (1 << 3)) |
667 | dev_warn(ctrl->device, | |
668 | "Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.\n"); | |
0d0b660f CH |
669 | return 0; |
670 | } | |
671 | static inline void nvme_mpath_uninit(struct nvme_ctrl *ctrl) | |
672 | { | |
673 | } | |
674 | static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl) | |
675 | { | |
676 | } | |
b9156dae SG |
677 | static inline void nvme_mpath_unfreeze(struct nvme_subsystem *subsys) |
678 | { | |
679 | } | |
680 | static inline void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys) | |
681 | { | |
682 | } | |
683 | static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) | |
684 | { | |
685 | } | |
32acab31 CH |
686 | #endif /* CONFIG_NVME_MULTIPATH */ |
687 | ||
c4699e70 | 688 | #ifdef CONFIG_NVM |
3dc87dd0 | 689 | int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node); |
b0b4e09c | 690 | void nvme_nvm_unregister(struct nvme_ns *ns); |
33b14f67 | 691 | extern const struct attribute_group nvme_nvm_attr_group; |
84d4add7 | 692 | int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg); |
c4699e70 | 693 | #else |
b0b4e09c | 694 | static inline int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, |
3dc87dd0 | 695 | int node) |
c4699e70 KB |
696 | { |
697 | return 0; | |
698 | } | |
699 | ||
b0b4e09c | 700 | static inline void nvme_nvm_unregister(struct nvme_ns *ns) {}; |
84d4add7 MB |
701 | static inline int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, |
702 | unsigned long arg) | |
703 | { | |
704 | return -ENOTTY; | |
705 | } | |
3dc87dd0 MB |
706 | #endif /* CONFIG_NVM */ |
707 | ||
40267efd SL |
708 | static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev) |
709 | { | |
710 | return dev_to_disk(dev)->private_data; | |
711 | } | |
ca064085 | 712 | |
400b6a7b GR |
713 | #ifdef CONFIG_NVME_HWMON |
714 | void nvme_hwmon_init(struct nvme_ctrl *ctrl); | |
715 | #else | |
716 | static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { } | |
717 | #endif | |
718 | ||
f11bb3e2 | 719 | #endif /* _NVME_H */ |