1
2
3
4
5
6#ifndef _NVME_H
7#define _NVME_H
8
9#include <linux/nvme.h>
10#include <linux/cdev.h>
11#include <linux/pci.h>
12#include <linux/kref.h>
13#include <linux/blk-mq.h>
14#include <linux/lightnvm.h>
15#include <linux/sed-opal.h>
16#include <linux/fault-inject.h>
17#include <linux/rcupdate.h>
18#include <linux/wait.h>
19#include <linux/t10-pi.h>
20
21#include <trace/events/block.h>
22
23extern unsigned int nvme_io_timeout;
24#define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
25
26extern unsigned int admin_timeout;
27#define NVME_ADMIN_TIMEOUT (admin_timeout * HZ)
28
29#define NVME_DEFAULT_KATO 5
30
31#ifdef CONFIG_ARCH_NO_SG_CHAIN
32#define NVME_INLINE_SG_CNT 0
33#define NVME_INLINE_METADATA_SG_CNT 0
34#else
35#define NVME_INLINE_SG_CNT 2
36#define NVME_INLINE_METADATA_SG_CNT 1
37#endif
38
39
40
41
42
43
44#define NVME_CTRL_PAGE_SHIFT 12
45#define NVME_CTRL_PAGE_SIZE (1 << NVME_CTRL_PAGE_SHIFT)
46
47extern struct workqueue_struct *nvme_wq;
48extern struct workqueue_struct *nvme_reset_wq;
49extern struct workqueue_struct *nvme_delete_wq;
50
51enum {
52 NVME_NS_LBA = 0,
53 NVME_NS_LIGHTNVM = 1,
54};
55
56
57
58
59
60enum nvme_quirks {
61
62
63
64
65 NVME_QUIRK_STRIPE_SIZE = (1 << 0),
66
67
68
69
70
71 NVME_QUIRK_IDENTIFY_CNS = (1 << 1),
72
73
74
75
76
77 NVME_QUIRK_DEALLOCATE_ZEROES = (1 << 2),
78
79
80
81
82
83 NVME_QUIRK_DELAY_BEFORE_CHK_RDY = (1 << 3),
84
85
86
87
88 NVME_QUIRK_NO_APST = (1 << 4),
89
90
91
92
93 NVME_QUIRK_NO_DEEPEST_PS = (1 << 5),
94
95
96
97
98 NVME_QUIRK_LIGHTNVM = (1 << 6),
99
100
101
102
103 NVME_QUIRK_MEDIUM_PRIO_SQ = (1 << 7),
104
105
106
107
108 NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8),
109
110
111
112
113 NVME_QUIRK_DISABLE_WRITE_ZEROES = (1 << 9),
114
115
116
117
118 NVME_QUIRK_SIMPLE_SUSPEND = (1 << 10),
119
120
121
122
123 NVME_QUIRK_SINGLE_VECTOR = (1 << 11),
124
125
126
127
128 NVME_QUIRK_128_BYTES_SQES = (1 << 12),
129
130
131
132
133 NVME_QUIRK_SHARED_TAGS = (1 << 13),
134
135
136
137
138 NVME_QUIRK_NO_TEMP_THRESH_CHANGE = (1 << 14),
139
140
141
142
143
144
145 NVME_QUIRK_NO_NS_DESC_LIST = (1 << 15),
146
147
148
149
150
151 NVME_QUIRK_DMA_ADDRESS_BITS_48 = (1 << 16),
152
153
154
155
156
157 NVME_QUIRK_SKIP_CID_GEN = (1 << 17),
158};
159
160
161
162
163
164struct nvme_request {
165 struct nvme_command *cmd;
166 union nvme_result result;
167 u8 genctr;
168 u8 retries;
169 u8 flags;
170 u16 status;
171 struct nvme_ctrl *ctrl;
172};
173
174
175
176
177#define REQ_NVME_MPATH REQ_DRV
178
179enum {
180 NVME_REQ_CANCELLED = (1 << 0),
181 NVME_REQ_USERCMD = (1 << 1),
182};
183
184static inline struct nvme_request *nvme_req(struct request *req)
185{
186 return blk_mq_rq_to_pdu(req);
187}
188
189static inline u16 nvme_req_qid(struct request *req)
190{
191 if (!req->q->queuedata)
192 return 0;
193
194 return req->mq_hctx->queue_num + 1;
195}
196
197
198
199
200
201
202#define NVME_QUIRK_DELAY_AMOUNT 2300
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223enum nvme_ctrl_state {
224 NVME_CTRL_NEW,
225 NVME_CTRL_LIVE,
226 NVME_CTRL_RESETTING,
227 NVME_CTRL_CONNECTING,
228 NVME_CTRL_DELETING,
229 NVME_CTRL_DELETING_NOIO,
230 NVME_CTRL_DEAD,
231};
232
233struct nvme_fault_inject {
234#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
235 struct fault_attr attr;
236 struct dentry *parent;
237 bool dont_retry;
238 u16 status;
239#endif
240};
241
242struct nvme_ctrl {
243 bool comp_seen;
244 enum nvme_ctrl_state state;
245 bool identified;
246 spinlock_t lock;
247 struct mutex scan_lock;
248 const struct nvme_ctrl_ops *ops;
249 struct request_queue *admin_q;
250 struct request_queue *connect_q;
251 struct request_queue *fabrics_q;
252 struct device *dev;
253 int instance;
254 int numa_node;
255 struct blk_mq_tag_set *tagset;
256 struct blk_mq_tag_set *admin_tagset;
257 struct list_head namespaces;
258 struct rw_semaphore namespaces_rwsem;
259 struct device ctrl_device;
260 struct device *device;
261#ifdef CONFIG_NVME_HWMON
262 struct device *hwmon_device;
263#endif
264 struct cdev cdev;
265 struct work_struct reset_work;
266 struct work_struct delete_work;
267 wait_queue_head_t state_wq;
268
269 struct nvme_subsystem *subsys;
270 struct list_head subsys_entry;
271
272 struct opal_dev *opal_dev;
273
274 char name[12];
275 u16 cntlid;
276
277 u32 ctrl_config;
278 u16 mtfa;
279 u32 queue_count;
280
281 u64 cap;
282 u32 max_hw_sectors;
283 u32 max_segments;
284 u32 max_integrity_segments;
285 u32 max_discard_sectors;
286 u32 max_discard_segments;
287 u32 max_zeroes_sectors;
288#ifdef CONFIG_BLK_DEV_ZONED
289 u32 max_zone_append;
290#endif
291 u16 crdt[3];
292 u16 oncs;
293 u16 oacs;
294 u16 nssa;
295 u16 nr_streams;
296 u16 sqsize;
297 u32 max_namespaces;
298 atomic_t abort_limit;
299 u8 vwc;
300 u32 vs;
301 u32 sgls;
302 u16 kas;
303 u8 npss;
304 u8 apsta;
305 u16 wctemp;
306 u16 cctemp;
307 u32 oaes;
308 u32 aen_result;
309 u32 ctratt;
310 unsigned int shutdown_timeout;
311 unsigned int kato;
312 bool subsystem;
313 unsigned long quirks;
314 struct nvme_id_power_state psd[32];
315 struct nvme_effects_log *effects;
316 struct xarray cels;
317 struct work_struct scan_work;
318 struct work_struct async_event_work;
319 struct delayed_work ka_work;
320 struct delayed_work failfast_work;
321 struct nvme_command ka_cmd;
322 struct work_struct fw_act_work;
323 unsigned long events;
324
325#ifdef CONFIG_NVME_MULTIPATH
326
327 u8 anacap;
328 u8 anatt;
329 u32 anagrpmax;
330 u32 nanagrpid;
331 struct mutex ana_lock;
332 struct nvme_ana_rsp_hdr *ana_log_buf;
333 size_t ana_log_size;
334 struct timer_list anatt_timer;
335 struct work_struct ana_work;
336#endif
337
338
339 u64 ps_max_latency_us;
340 bool apst_enabled;
341
342
343 u32 hmpre;
344 u32 hmmin;
345 u32 hmminds;
346 u16 hmmaxd;
347
348
349 u32 ioccsz;
350 u32 iorcsz;
351 u16 icdoff;
352 u16 maxcmd;
353 int nr_reconnects;
354 unsigned long flags;
355#define NVME_CTRL_FAILFAST_EXPIRED 0
356 struct nvmf_ctrl_options *opts;
357
358 struct page *discard_page;
359 unsigned long discard_page_busy;
360
361 struct nvme_fault_inject fault_inject;
362
363
364 u64 segment_boundary;
365};
366
367enum nvme_iopolicy {
368 NVME_IOPOLICY_NUMA,
369 NVME_IOPOLICY_RR,
370};
371
372struct nvme_subsystem {
373 int instance;
374 struct device dev;
375
376
377
378
379 struct kref ref;
380 struct list_head entry;
381 struct mutex lock;
382 struct list_head ctrls;
383 struct list_head nsheads;
384 char subnqn[NVMF_NQN_SIZE];
385 char serial[20];
386 char model[40];
387 char firmware_rev[8];
388 u8 cmic;
389 u16 vendor_id;
390 u16 awupf;
391 struct ida ns_ida;
392#ifdef CONFIG_NVME_MULTIPATH
393 enum nvme_iopolicy iopolicy;
394#endif
395};
396
397
398
399
400struct nvme_ns_ids {
401 u8 eui64[8];
402 u8 nguid[16];
403 uuid_t uuid;
404 u8 csi;
405};
406
407
408
409
410
411
412
413
414struct nvme_ns_head {
415 struct list_head list;
416 struct srcu_struct srcu;
417 struct nvme_subsystem *subsys;
418 unsigned ns_id;
419 struct nvme_ns_ids ids;
420 struct list_head entry;
421 struct kref ref;
422 bool shared;
423 int instance;
424 struct nvme_effects_log *effects;
425
426 struct cdev cdev;
427 struct device cdev_device;
428
429 struct gendisk *disk;
430#ifdef CONFIG_NVME_MULTIPATH
431 struct bio_list requeue_list;
432 spinlock_t requeue_lock;
433 struct work_struct requeue_work;
434 struct mutex lock;
435 unsigned long flags;
436#define NVME_NSHEAD_DISK_LIVE 0
437 struct nvme_ns __rcu *current_path[];
438#endif
439};
440
441static inline bool nvme_ns_head_multipath(struct nvme_ns_head *head)
442{
443 return IS_ENABLED(CONFIG_NVME_MULTIPATH) && head->disk;
444}
445
446enum nvme_ns_features {
447 NVME_NS_EXT_LBAS = 1 << 0,
448 NVME_NS_METADATA_SUPPORTED = 1 << 1,
449};
450
451struct nvme_ns {
452 struct list_head list;
453
454 struct nvme_ctrl *ctrl;
455 struct request_queue *queue;
456 struct gendisk *disk;
457#ifdef CONFIG_NVME_MULTIPATH
458 enum nvme_ana_state ana_state;
459 u32 ana_grpid;
460#endif
461 struct list_head siblings;
462 struct nvm_dev *ndev;
463 struct kref kref;
464 struct nvme_ns_head *head;
465
466 int lba_shift;
467 u16 ms;
468 u16 sgs;
469 u32 sws;
470 u8 pi_type;
471#ifdef CONFIG_BLK_DEV_ZONED
472 u64 zsze;
473#endif
474 unsigned long features;
475 unsigned long flags;
476#define NVME_NS_REMOVING 0
477#define NVME_NS_DEAD 1
478#define NVME_NS_ANA_PENDING 2
479#define NVME_NS_FORCE_RO 3
480
481 struct cdev cdev;
482 struct device cdev_device;
483
484 struct nvme_fault_inject fault_inject;
485
486};
487
488
489static inline bool nvme_ns_has_pi(struct nvme_ns *ns)
490{
491 return ns->pi_type && ns->ms == sizeof(struct t10_pi_tuple);
492}
493
494struct nvme_ctrl_ops {
495 const char *name;
496 struct module *module;
497 unsigned int flags;
498#define NVME_F_FABRICS (1 << 0)
499#define NVME_F_METADATA_SUPPORTED (1 << 1)
500#define NVME_F_PCI_P2PDMA (1 << 2)
501 int (*reg_read32)(struct nvme_ctrl *ctrl, u32 off, u32 *val);
502 int (*reg_write32)(struct nvme_ctrl *ctrl, u32 off, u32 val);
503 int (*reg_read64)(struct nvme_ctrl *ctrl, u32 off, u64 *val);
504 void (*free_ctrl)(struct nvme_ctrl *ctrl);
505 void (*submit_async_event)(struct nvme_ctrl *ctrl);
506 void (*delete_ctrl)(struct nvme_ctrl *ctrl);
507 int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size);
508};
509
510
511
512
513
514
515#define nvme_genctr_mask(gen) (gen & 0xf)
516#define nvme_cid_install_genctr(gen) (nvme_genctr_mask(gen) << 12)
517#define nvme_genctr_from_cid(cid) ((cid & 0xf000) >> 12)
518#define nvme_tag_from_cid(cid) (cid & 0xfff)
519
520static inline u16 nvme_cid(struct request *rq)
521{
522 return nvme_cid_install_genctr(nvme_req(rq)->genctr) | rq->tag;
523}
524
525static inline struct request *nvme_find_rq(struct blk_mq_tags *tags,
526 u16 command_id)
527{
528 u8 genctr = nvme_genctr_from_cid(command_id);
529 u16 tag = nvme_tag_from_cid(command_id);
530 struct request *rq;
531
532 rq = blk_mq_tag_to_rq(tags, tag);
533 if (unlikely(!rq)) {
534 pr_err("could not locate request for tag %#x\n",
535 tag);
536 return NULL;
537 }
538 if (unlikely(nvme_genctr_mask(nvme_req(rq)->genctr) != genctr)) {
539 dev_err(nvme_req(rq)->ctrl->device,
540 "request %#x genctr mismatch (got %#x expected %#x)\n",
541 tag, genctr, nvme_genctr_mask(nvme_req(rq)->genctr));
542 return NULL;
543 }
544 return rq;
545}
546
547static inline struct request *nvme_cid_to_rq(struct blk_mq_tags *tags,
548 u16 command_id)
549{
550 return blk_mq_tag_to_rq(tags, nvme_tag_from_cid(command_id));
551}
552
553#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
554void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
555 const char *dev_name);
556void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject);
557void nvme_should_fail(struct request *req);
558#else
559static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
560 const char *dev_name)
561{
562}
563static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj)
564{
565}
566static inline void nvme_should_fail(struct request *req) {}
567#endif
568
569static inline int nvme_reset_subsystem(struct nvme_ctrl *ctrl)
570{
571 if (!ctrl->subsystem)
572 return -ENOTTY;
573 return ctrl->ops->reg_write32(ctrl, NVME_REG_NSSR, 0x4E564D65);
574}
575
576
577
578
579static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector)
580{
581 return sector >> (ns->lba_shift - SECTOR_SHIFT);
582}
583
584static inline bool nvme_is_ana_error(u16 status)
585{
586 switch (status & 0x7ff) {
587 case NVME_SC_ANA_TRANSITION:
588 case NVME_SC_ANA_INACCESSIBLE:
589 case NVME_SC_ANA_PERSISTENT_LOSS:
590 return true;
591 default:
592 return false;
593 }
594}
595
596static inline bool nvme_is_path_error(u16 status)
597{
598
599 return (status & 0x700) == 0x300;
600}
601
602
603
604
605static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba)
606{
607 return lba << (ns->lba_shift - SECTOR_SHIFT);
608}
609
610
611
612
613static inline u32 nvme_bytes_to_numd(size_t len)
614{
615 return (len >> 2) - 1;
616}
617
618static inline bool nvme_end_request(struct request *req, __le16 status,
619 union nvme_result result)
620{
621 struct nvme_request *rq = nvme_req(req);
622 struct nvme_ctrl *ctrl = rq->ctrl;
623
624 if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
625 rq->genctr++;
626
627 rq->status = le16_to_cpu(status) >> 1;
628 rq->result = result;
629
630 nvme_should_fail(req);
631 if (unlikely(blk_should_fake_timeout(req->q)))
632 return true;
633 return blk_mq_complete_request_remote(req);
634}
635
636static inline void nvme_get_ctrl(struct nvme_ctrl *ctrl)
637{
638 get_device(ctrl->device);
639}
640
641static inline void nvme_put_ctrl(struct nvme_ctrl *ctrl)
642{
643 put_device(ctrl->device);
644}
645
646static inline bool nvme_is_aen_req(u16 qid, __u16 command_id)
647{
648 return !qid &&
649 nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH;
650}
651
652void nvme_complete_rq(struct request *req);
653blk_status_t nvme_host_path_error(struct request *req);
654bool nvme_cancel_request(struct request *req, void *data, bool reserved);
655void nvme_cancel_tagset(struct nvme_ctrl *ctrl);
656void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl);
657bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
658 enum nvme_ctrl_state new_state);
659bool nvme_wait_reset(struct nvme_ctrl *ctrl);
660int nvme_disable_ctrl(struct nvme_ctrl *ctrl);
661int nvme_enable_ctrl(struct nvme_ctrl *ctrl);
662int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
663int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
664 const struct nvme_ctrl_ops *ops, unsigned long quirks);
665void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
666void nvme_start_ctrl(struct nvme_ctrl *ctrl);
667void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
668int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl);
669
670void nvme_remove_namespaces(struct nvme_ctrl *ctrl);
671
672int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,
673 bool send);
674
675void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
676 volatile union nvme_result *res);
677
678void nvme_stop_queues(struct nvme_ctrl *ctrl);
679void nvme_start_queues(struct nvme_ctrl *ctrl);
680void nvme_kill_queues(struct nvme_ctrl *ctrl);
681void nvme_sync_queues(struct nvme_ctrl *ctrl);
682void nvme_sync_io_queues(struct nvme_ctrl *ctrl);
683void nvme_unfreeze(struct nvme_ctrl *ctrl);
684void nvme_wait_freeze(struct nvme_ctrl *ctrl);
685int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
686void nvme_start_freeze(struct nvme_ctrl *ctrl);
687
688#define NVME_QID_ANY -1
689struct request *nvme_alloc_request(struct request_queue *q,
690 struct nvme_command *cmd, blk_mq_req_flags_t flags);
691void nvme_cleanup_cmd(struct request *req);
692blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
693blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
694 struct request *req);
695bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
696 bool queue_live);
697
698static inline bool nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
699 bool queue_live)
700{
701 if (likely(ctrl->state == NVME_CTRL_LIVE))
702 return true;
703 if (ctrl->ops->flags & NVME_F_FABRICS &&
704 ctrl->state == NVME_CTRL_DELETING)
705 return true;
706 return __nvme_check_ready(ctrl, rq, queue_live);
707}
708int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
709 void *buf, unsigned bufflen);
710int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
711 union nvme_result *result, void *buffer, unsigned bufflen,
712 unsigned timeout, int qid, int at_head,
713 blk_mq_req_flags_t flags);
714int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
715 unsigned int dword11, void *buffer, size_t buflen,
716 u32 *result);
717int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid,
718 unsigned int dword11, void *buffer, size_t buflen,
719 u32 *result);
720int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
721void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
722int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
723int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
724int nvme_try_sched_reset(struct nvme_ctrl *ctrl);
725int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
726void nvme_queue_scan(struct nvme_ctrl *ctrl);
727int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
728 void *log, size_t size, u64 offset);
729bool nvme_tryget_ns_head(struct nvme_ns_head *head);
730void nvme_put_ns_head(struct nvme_ns_head *head);
731int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
732 const struct file_operations *fops, struct module *owner);
733void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device);
734int nvme_ioctl(struct block_device *bdev, fmode_t mode,
735 unsigned int cmd, unsigned long arg);
736long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
737int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
738 unsigned int cmd, unsigned long arg);
739long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
740 unsigned long arg);
741long nvme_dev_ioctl(struct file *file, unsigned int cmd,
742 unsigned long arg);
743int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo);
744
745extern const struct attribute_group *nvme_ns_id_attr_groups[];
746extern const struct pr_ops nvme_pr_ops;
747extern const struct block_device_operations nvme_ns_head_ops;
748
749struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
750#ifdef CONFIG_NVME_MULTIPATH
751static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
752{
753 return ctrl->ana_log_buf != NULL;
754}
755
756void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
757void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
758void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
759bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name, int *flags);
760void nvme_failover_req(struct request *req);
761void nvme_update_ana(struct request *req);
762void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
763int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
764void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id);
765void nvme_mpath_remove_disk(struct nvme_ns_head *head);
766int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id);
767void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl);
768void nvme_mpath_uninit(struct nvme_ctrl *ctrl);
769void nvme_mpath_stop(struct nvme_ctrl *ctrl);
770bool nvme_mpath_clear_current_path(struct nvme_ns *ns);
771void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl);
772void nvme_mpath_shutdown_disk(struct nvme_ns_head *head);
773
774static inline void nvme_trace_bio_complete(struct request *req)
775{
776 struct nvme_ns *ns = req->q->queuedata;
777
778 if (req->cmd_flags & REQ_NVME_MPATH)
779 trace_block_bio_complete(ns->head->disk->queue, req->bio);
780}
781
782extern struct device_attribute dev_attr_ana_grpid;
783extern struct device_attribute dev_attr_ana_state;
784extern struct device_attribute subsys_attr_iopolicy;
785
786#else
787static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
788{
789 return false;
790}
791static inline bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name,
792 int *flags)
793{
794 return false;
795}
796static inline void nvme_failover_req(struct request *req)
797{
798}
799static inline void nvme_update_ana(struct request *req)
800{
801}
802static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
803{
804}
805static inline int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,
806 struct nvme_ns_head *head)
807{
808 return 0;
809}
810static inline void nvme_mpath_add_disk(struct nvme_ns *ns,
811 struct nvme_id_ns *id)
812{
813}
814static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head)
815{
816}
817static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
818{
819 return false;
820}
821static inline void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
822{
823}
824static inline void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
825{
826}
827static inline void nvme_trace_bio_complete(struct request *req)
828{
829}
830static inline void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)
831{
832}
833static inline int nvme_mpath_init_identify(struct nvme_ctrl *ctrl,
834 struct nvme_id_ctrl *id)
835{
836 if (ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA)
837 dev_warn(ctrl->device,
838"Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.\n");
839 return 0;
840}
841static inline void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
842{
843}
844static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl)
845{
846}
847static inline void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
848{
849}
850static inline void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
851{
852}
853static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
854{
855}
856#endif
857
858int nvme_revalidate_zones(struct nvme_ns *ns);
859int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
860 unsigned int nr_zones, report_zones_cb cb, void *data);
861#ifdef CONFIG_BLK_DEV_ZONED
862int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf);
863blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
864 struct nvme_command *cmnd,
865 enum nvme_zone_mgmt_action action);
866#else
867static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns,
868 struct request *req, struct nvme_command *cmnd,
869 enum nvme_zone_mgmt_action action)
870{
871 return BLK_STS_NOTSUPP;
872}
873
874static inline int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf)
875{
876 dev_warn(ns->ctrl->device,
877 "Please enable CONFIG_BLK_DEV_ZONED to support ZNS devices\n");
878 return -EPROTONOSUPPORT;
879}
880#endif
881
882#ifdef CONFIG_NVM
883int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node);
884void nvme_nvm_unregister(struct nvme_ns *ns);
885extern const struct attribute_group nvme_nvm_attr_group;
886int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, void __user *argp);
887#else
888static inline int nvme_nvm_register(struct nvme_ns *ns, char *disk_name,
889 int node)
890{
891 return 0;
892}
893
894static inline void nvme_nvm_unregister(struct nvme_ns *ns) {};
895static inline int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd,
896 void __user *argp)
897{
898 return -ENOTTY;
899}
900#endif
901
902static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev)
903{
904 return dev_to_disk(dev)->private_data;
905}
906
907#ifdef CONFIG_NVME_HWMON
908int nvme_hwmon_init(struct nvme_ctrl *ctrl);
909void nvme_hwmon_exit(struct nvme_ctrl *ctrl);
910#else
911static inline int nvme_hwmon_init(struct nvme_ctrl *ctrl)
912{
913 return 0;
914}
915
916static inline void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
917{
918}
919#endif
920
921static inline bool nvme_ctrl_sgl_supported(struct nvme_ctrl *ctrl)
922{
923 return ctrl->sgls & ((1 << 0) | (1 << 1));
924}
925
926u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
927 u8 opcode);
928int nvme_execute_passthru_rq(struct request *rq);
929struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
930struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
931void nvme_put_ns(struct nvme_ns *ns);
932
933static inline bool nvme_multi_css(struct nvme_ctrl *ctrl)
934{
935 return (ctrl->ctrl_config & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI;
936}
937
938#endif
939