nvme.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2011-2014, Intel Corporation.
  4. */
  5. #ifndef _NVME_H
  6. #define _NVME_H
  7. #include <linux/nvme.h>
  8. #include <linux/cdev.h>
  9. #include <linux/pci.h>
  10. #include <linux/kref.h>
  11. #include <linux/blk-mq.h>
  12. #include <linux/sed-opal.h>
  13. #include <linux/fault-inject.h>
  14. #include <linux/rcupdate.h>
  15. #include <linux/wait.h>
  16. #include <linux/t10-pi.h>
  17. #include <linux/ratelimit_types.h>
  18. #include <trace/events/block.h>
  19. extern const struct pr_ops nvme_pr_ops;
  20. extern unsigned int nvme_io_timeout;
  21. #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
  22. extern unsigned int admin_timeout;
  23. #define NVME_ADMIN_TIMEOUT (admin_timeout * HZ)
  24. #define NVME_DEFAULT_KATO 5
  25. #ifdef CONFIG_ARCH_NO_SG_CHAIN
  26. #define NVME_INLINE_SG_CNT 0
  27. #define NVME_INLINE_METADATA_SG_CNT 0
  28. #else
  29. #define NVME_INLINE_SG_CNT 2
  30. #define NVME_INLINE_METADATA_SG_CNT 1
  31. #endif
  32. /*
  33. * Default to a 4K page size, with the intention to update this
  34. * path in the future to accommodate architectures with differing
  35. * kernel and IO page sizes.
  36. */
  37. #define NVME_CTRL_PAGE_SHIFT 12
  38. #define NVME_CTRL_PAGE_SIZE (1 << NVME_CTRL_PAGE_SHIFT)
  39. extern struct workqueue_struct *nvme_wq;
  40. extern struct workqueue_struct *nvme_reset_wq;
  41. extern struct workqueue_struct *nvme_delete_wq;
  42. extern struct mutex nvme_subsystems_lock;
  43. /*
  44. * List of workarounds for devices that required behavior not specified in
  45. * the standard.
  46. */
  47. enum nvme_quirks {
  48. /*
  49. * Prefers I/O aligned to a stripe size specified in a vendor
  50. * specific Identify field.
  51. */
  52. NVME_QUIRK_STRIPE_SIZE = (1 << 0),
  53. /*
  54. * The controller doesn't handle Identify value others than 0 or 1
  55. * correctly.
  56. */
  57. NVME_QUIRK_IDENTIFY_CNS = (1 << 1),
  58. /*
  59. * The controller deterministically returns O's on reads to
  60. * logical blocks that deallocate was called on.
  61. */
  62. NVME_QUIRK_DEALLOCATE_ZEROES = (1 << 2),
  63. /*
  64. * The controller needs a delay before starts checking the device
  65. * readiness, which is done by reading the NVME_CSTS_RDY bit.
  66. */
  67. NVME_QUIRK_DELAY_BEFORE_CHK_RDY = (1 << 3),
  68. /*
  69. * APST should not be used.
  70. */
  71. NVME_QUIRK_NO_APST = (1 << 4),
  72. /*
  73. * The deepest sleep state should not be used.
  74. */
  75. NVME_QUIRK_NO_DEEPEST_PS = (1 << 5),
  76. /*
  77. * Problems seen with concurrent commands
  78. */
  79. NVME_QUIRK_QDEPTH_ONE = (1 << 6),
  80. /*
  81. * Set MEDIUM priority on SQ creation
  82. */
  83. NVME_QUIRK_MEDIUM_PRIO_SQ = (1 << 7),
  84. /*
  85. * Ignore device provided subnqn.
  86. */
  87. NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8),
  88. /*
  89. * Broken Write Zeroes.
  90. */
  91. NVME_QUIRK_DISABLE_WRITE_ZEROES = (1 << 9),
  92. /*
  93. * Force simple suspend/resume path.
  94. */
  95. NVME_QUIRK_SIMPLE_SUSPEND = (1 << 10),
  96. /*
  97. * Use only one interrupt vector for all queues
  98. */
  99. NVME_QUIRK_SINGLE_VECTOR = (1 << 11),
  100. /*
  101. * Use non-standard 128 bytes SQEs.
  102. */
  103. NVME_QUIRK_128_BYTES_SQES = (1 << 12),
  104. /*
  105. * Prevent tag overlap between queues
  106. */
  107. NVME_QUIRK_SHARED_TAGS = (1 << 13),
  108. /*
  109. * Don't change the value of the temperature threshold feature
  110. */
  111. NVME_QUIRK_NO_TEMP_THRESH_CHANGE = (1 << 14),
  112. /*
  113. * The controller doesn't handle the Identify Namespace
  114. * Identification Descriptor list subcommand despite claiming
  115. * NVMe 1.3 compliance.
  116. */
  117. NVME_QUIRK_NO_NS_DESC_LIST = (1 << 15),
  118. /*
  119. * The controller does not properly handle DMA addresses over
  120. * 48 bits.
  121. */
  122. NVME_QUIRK_DMA_ADDRESS_BITS_48 = (1 << 16),
  123. /*
  124. * The controller requires the command_id value be limited, so skip
  125. * encoding the generation sequence number.
  126. */
  127. NVME_QUIRK_SKIP_CID_GEN = (1 << 17),
  128. /*
  129. * Reports garbage in the namespace identifiers (eui64, nguid, uuid).
  130. */
  131. NVME_QUIRK_BOGUS_NID = (1 << 18),
  132. /*
  133. * No temperature thresholds for channels other than 0 (Composite).
  134. */
  135. NVME_QUIRK_NO_SECONDARY_TEMP_THRESH = (1 << 19),
  136. /*
  137. * Disables simple suspend/resume path.
  138. */
  139. NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND = (1 << 20),
  140. /*
  141. * MSI (but not MSI-X) interrupts are broken and never fire.
  142. */
  143. NVME_QUIRK_BROKEN_MSI = (1 << 21),
  144. /*
  145. * Align dma pool segment size to 512 bytes
  146. */
  147. NVME_QUIRK_DMAPOOL_ALIGN_512 = (1 << 22),
  148. };
  149. /*
  150. * Common request structure for NVMe passthrough. All drivers must have
  151. * this structure as the first member of their request-private data.
  152. */
  153. struct nvme_request {
  154. struct nvme_command *cmd;
  155. union nvme_result result;
  156. u8 genctr;
  157. u8 retries;
  158. u8 flags;
  159. u16 status;
  160. #ifdef CONFIG_NVME_MULTIPATH
  161. unsigned long start_time;
  162. #endif
  163. struct nvme_ctrl *ctrl;
  164. };
  165. /*
  166. * Mark a bio as coming in through the mpath node.
  167. */
  168. #define REQ_NVME_MPATH REQ_DRV
  169. enum {
  170. NVME_REQ_CANCELLED = (1 << 0),
  171. NVME_REQ_USERCMD = (1 << 1),
  172. NVME_MPATH_IO_STATS = (1 << 2),
  173. NVME_MPATH_CNT_ACTIVE = (1 << 3),
  174. };
  175. static inline struct nvme_request *nvme_req(struct request *req)
  176. {
  177. return blk_mq_rq_to_pdu(req);
  178. }
  179. static inline u16 nvme_req_qid(struct request *req)
  180. {
  181. if (!req->q->queuedata)
  182. return 0;
  183. return req->mq_hctx->queue_num + 1;
  184. }
  185. /* The below value is the specific amount of delay needed before checking
  186. * readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the
  187. * NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
  188. * found empirically.
  189. */
  190. #define NVME_QUIRK_DELAY_AMOUNT 2300
  191. /*
  192. * enum nvme_ctrl_state: Controller state
  193. *
  194. * @NVME_CTRL_NEW: New controller just allocated, initial state
  195. * @NVME_CTRL_LIVE: Controller is connected and I/O capable
  196. * @NVME_CTRL_RESETTING: Controller is resetting (or scheduled reset)
  197. * @NVME_CTRL_CONNECTING: Controller is disconnected, now connecting the
  198. * transport
  199. * @NVME_CTRL_DELETING: Controller is deleting (or scheduled deletion)
  200. * @NVME_CTRL_DELETING_NOIO: Controller is deleting and I/O is not
  201. * disabled/failed immediately. This state comes
  202. * after all async event processing took place and
  203. * before ns removal and the controller deletion
  204. * progress
  205. * @NVME_CTRL_DEAD: Controller is non-present/unresponsive during
  206. * shutdown or removal. In this case we forcibly
  207. * kill all inflight I/O as they have no chance to
  208. * complete
  209. */
  210. enum nvme_ctrl_state {
  211. NVME_CTRL_NEW,
  212. NVME_CTRL_LIVE,
  213. NVME_CTRL_RESETTING,
  214. NVME_CTRL_CONNECTING,
  215. NVME_CTRL_DELETING,
  216. NVME_CTRL_DELETING_NOIO,
  217. NVME_CTRL_DEAD,
  218. };
  219. struct nvme_fault_inject {
  220. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  221. struct fault_attr attr;
  222. struct dentry *parent;
  223. bool dont_retry; /* DNR, do not retry */
  224. u16 status; /* status code */
  225. #endif
  226. };
  227. enum nvme_ctrl_flags {
  228. NVME_CTRL_FAILFAST_EXPIRED = 0,
  229. NVME_CTRL_ADMIN_Q_STOPPED = 1,
  230. NVME_CTRL_STARTED_ONCE = 2,
  231. NVME_CTRL_STOPPED = 3,
  232. NVME_CTRL_SKIP_ID_CNS_CS = 4,
  233. NVME_CTRL_DIRTY_CAPABILITY = 5,
  234. NVME_CTRL_FROZEN = 6,
  235. };
  236. struct nvme_ctrl {
  237. bool comp_seen;
  238. bool identified;
  239. bool passthru_err_log_enabled;
  240. enum nvme_ctrl_state state;
  241. spinlock_t lock;
  242. struct mutex scan_lock;
  243. const struct nvme_ctrl_ops *ops;
  244. struct request_queue *admin_q;
  245. struct request_queue *connect_q;
  246. struct request_queue *fabrics_q;
  247. struct device *dev;
  248. int instance;
  249. int numa_node;
  250. struct blk_mq_tag_set *tagset;
  251. struct blk_mq_tag_set *admin_tagset;
  252. struct list_head namespaces;
  253. struct mutex namespaces_lock;
  254. struct srcu_struct srcu;
  255. struct device ctrl_device;
  256. struct device *device; /* char device */
  257. #ifdef CONFIG_NVME_HWMON
  258. struct device *hwmon_device;
  259. #endif
  260. struct cdev cdev;
  261. struct work_struct reset_work;
  262. struct work_struct delete_work;
  263. wait_queue_head_t state_wq;
  264. struct nvme_subsystem *subsys;
  265. struct list_head subsys_entry;
  266. struct opal_dev *opal_dev;
  267. u16 cntlid;
  268. u16 mtfa;
  269. u32 ctrl_config;
  270. u32 queue_count;
  271. u64 cap;
  272. u32 max_hw_sectors;
  273. u32 max_segments;
  274. u32 max_integrity_segments;
  275. u32 max_zeroes_sectors;
  276. #ifdef CONFIG_BLK_DEV_ZONED
  277. u32 max_zone_append;
  278. #endif
  279. u16 crdt[3];
  280. u16 oncs;
  281. u8 dmrl;
  282. u32 dmrsl;
  283. u16 oacs;
  284. u16 sqsize;
  285. u32 max_namespaces;
  286. atomic_t abort_limit;
  287. u8 vwc;
  288. u32 vs;
  289. u32 sgls;
  290. u16 kas;
  291. u8 npss;
  292. u8 apsta;
  293. u16 wctemp;
  294. u16 cctemp;
  295. u32 oaes;
  296. u32 aen_result;
  297. u32 ctratt;
  298. unsigned int shutdown_timeout;
  299. unsigned int kato;
  300. bool subsystem;
  301. unsigned long quirks;
  302. struct nvme_id_power_state psd[32];
  303. struct nvme_effects_log *effects;
  304. struct xarray cels;
  305. struct work_struct scan_work;
  306. struct work_struct async_event_work;
  307. struct delayed_work ka_work;
  308. struct delayed_work failfast_work;
  309. struct nvme_command ka_cmd;
  310. unsigned long ka_last_check_time;
  311. struct work_struct fw_act_work;
  312. unsigned long events;
  313. #ifdef CONFIG_NVME_MULTIPATH
  314. /* asymmetric namespace access: */
  315. u8 anacap;
  316. u8 anatt;
  317. u32 anagrpmax;
  318. u32 nanagrpid;
  319. struct mutex ana_lock;
  320. struct nvme_ana_rsp_hdr *ana_log_buf;
  321. size_t ana_log_size;
  322. struct timer_list anatt_timer;
  323. struct work_struct ana_work;
  324. atomic_t nr_active;
  325. #endif
  326. #ifdef CONFIG_NVME_HOST_AUTH
  327. struct work_struct dhchap_auth_work;
  328. struct mutex dhchap_auth_mutex;
  329. struct nvme_dhchap_queue_context *dhchap_ctxs;
  330. struct nvme_dhchap_key *host_key;
  331. struct nvme_dhchap_key *ctrl_key;
  332. u16 transaction;
  333. #endif
  334. key_serial_t tls_pskid;
  335. /* Power saving configuration */
  336. u64 ps_max_latency_us;
  337. bool apst_enabled;
  338. /* PCIe only: */
  339. u16 hmmaxd;
  340. u32 hmpre;
  341. u32 hmmin;
  342. u32 hmminds;
  343. /* Fabrics only */
  344. u32 ioccsz;
  345. u32 iorcsz;
  346. u16 icdoff;
  347. u16 maxcmd;
  348. int nr_reconnects;
  349. unsigned long flags;
  350. struct nvmf_ctrl_options *opts;
  351. struct page *discard_page;
  352. unsigned long discard_page_busy;
  353. struct nvme_fault_inject fault_inject;
  354. enum nvme_ctrl_type cntrltype;
  355. enum nvme_dctype dctype;
  356. };
  357. static inline enum nvme_ctrl_state nvme_ctrl_state(struct nvme_ctrl *ctrl)
  358. {
  359. return READ_ONCE(ctrl->state);
  360. }
  361. enum nvme_iopolicy {
  362. NVME_IOPOLICY_NUMA,
  363. NVME_IOPOLICY_RR,
  364. NVME_IOPOLICY_QD,
  365. };
  366. struct nvme_subsystem {
  367. int instance;
  368. struct device dev;
  369. /*
  370. * Because we unregister the device on the last put we need
  371. * a separate refcount.
  372. */
  373. struct kref ref;
  374. struct list_head entry;
  375. struct mutex lock;
  376. struct list_head ctrls;
  377. struct list_head nsheads;
  378. char subnqn[NVMF_NQN_SIZE];
  379. char serial[20];
  380. char model[40];
  381. char firmware_rev[8];
  382. u8 cmic;
  383. enum nvme_subsys_type subtype;
  384. u16 vendor_id;
  385. u16 awupf; /* 0's based awupf value. */
  386. struct ida ns_ida;
  387. #ifdef CONFIG_NVME_MULTIPATH
  388. enum nvme_iopolicy iopolicy;
  389. #endif
  390. };
  391. /*
  392. * Container structure for uniqueue namespace identifiers.
  393. */
  394. struct nvme_ns_ids {
  395. u8 eui64[8];
  396. u8 nguid[16];
  397. uuid_t uuid;
  398. u8 csi;
  399. };
  400. /*
  401. * Anchor structure for namespaces. There is one for each namespace in a
  402. * NVMe subsystem that any of our controllers can see, and the namespace
  403. * structure for each controller is chained of it. For private namespaces
  404. * there is a 1:1 relation to our namespace structures, that is ->list
  405. * only ever has a single entry for private namespaces.
  406. */
  407. struct nvme_ns_head {
  408. struct list_head list;
  409. struct srcu_struct srcu;
  410. struct nvme_subsystem *subsys;
  411. struct nvme_ns_ids ids;
  412. u8 lba_shift;
  413. u16 ms;
  414. u16 pi_size;
  415. u8 pi_type;
  416. u8 guard_type;
  417. struct list_head entry;
  418. struct kref ref;
  419. bool shared;
  420. bool passthru_err_log_enabled;
  421. struct nvme_effects_log *effects;
  422. u64 nuse;
  423. unsigned ns_id;
  424. int instance;
  425. #ifdef CONFIG_BLK_DEV_ZONED
  426. u64 zsze;
  427. #endif
  428. unsigned long features;
  429. struct ratelimit_state rs_nuse;
  430. struct cdev cdev;
  431. struct device cdev_device;
  432. struct gendisk *disk;
  433. #ifdef CONFIG_NVME_MULTIPATH
  434. struct bio_list requeue_list;
  435. spinlock_t requeue_lock;
  436. struct work_struct requeue_work;
  437. struct work_struct partition_scan_work;
  438. struct mutex lock;
  439. unsigned long flags;
  440. #define NVME_NSHEAD_DISK_LIVE 0
  441. struct nvme_ns __rcu *current_path[];
  442. #endif
  443. };
  444. static inline bool nvme_ns_head_multipath(struct nvme_ns_head *head)
  445. {
  446. return IS_ENABLED(CONFIG_NVME_MULTIPATH) && head->disk;
  447. }
  448. enum nvme_ns_features {
  449. NVME_NS_EXT_LBAS = 1 << 0, /* support extended LBA format */
  450. NVME_NS_METADATA_SUPPORTED = 1 << 1, /* support getting generated md */
  451. NVME_NS_DEAC = 1 << 2, /* DEAC bit in Write Zeores supported */
  452. };
  453. struct nvme_ns {
  454. struct list_head list;
  455. struct nvme_ctrl *ctrl;
  456. struct request_queue *queue;
  457. struct gendisk *disk;
  458. #ifdef CONFIG_NVME_MULTIPATH
  459. enum nvme_ana_state ana_state;
  460. u32 ana_grpid;
  461. #endif
  462. struct list_head siblings;
  463. struct kref kref;
  464. struct nvme_ns_head *head;
  465. unsigned long flags;
  466. #define NVME_NS_REMOVING 0
  467. #define NVME_NS_ANA_PENDING 2
  468. #define NVME_NS_FORCE_RO 3
  469. #define NVME_NS_READY 4
  470. struct cdev cdev;
  471. struct device cdev_device;
  472. struct nvme_fault_inject fault_inject;
  473. };
  474. /* NVMe ns supports metadata actions by the controller (generate/strip) */
  475. static inline bool nvme_ns_has_pi(struct nvme_ns_head *head)
  476. {
  477. return head->pi_type && head->ms == head->pi_size;
  478. }
  479. struct nvme_ctrl_ops {
  480. const char *name;
  481. struct module *module;
  482. unsigned int flags;
  483. #define NVME_F_FABRICS (1 << 0)
  484. #define NVME_F_METADATA_SUPPORTED (1 << 1)
  485. #define NVME_F_BLOCKING (1 << 2)
  486. const struct attribute_group **dev_attr_groups;
  487. int (*reg_read32)(struct nvme_ctrl *ctrl, u32 off, u32 *val);
  488. int (*reg_write32)(struct nvme_ctrl *ctrl, u32 off, u32 val);
  489. int (*reg_read64)(struct nvme_ctrl *ctrl, u32 off, u64 *val);
  490. void (*free_ctrl)(struct nvme_ctrl *ctrl);
  491. void (*submit_async_event)(struct nvme_ctrl *ctrl);
  492. int (*subsystem_reset)(struct nvme_ctrl *ctrl);
  493. void (*delete_ctrl)(struct nvme_ctrl *ctrl);
  494. void (*stop_ctrl)(struct nvme_ctrl *ctrl);
  495. int (*get_address)(struct nvme_ctrl *ctrl, char *buf, int size);
  496. void (*print_device_info)(struct nvme_ctrl *ctrl);
  497. bool (*supports_pci_p2pdma)(struct nvme_ctrl *ctrl);
  498. };
  499. /*
  500. * nvme command_id is constructed as such:
  501. * | xxxx | xxxxxxxxxxxx |
  502. * gen request tag
  503. */
  504. #define nvme_genctr_mask(gen) (gen & 0xf)
  505. #define nvme_cid_install_genctr(gen) (nvme_genctr_mask(gen) << 12)
  506. #define nvme_genctr_from_cid(cid) ((cid & 0xf000) >> 12)
  507. #define nvme_tag_from_cid(cid) (cid & 0xfff)
  508. static inline u16 nvme_cid(struct request *rq)
  509. {
  510. return nvme_cid_install_genctr(nvme_req(rq)->genctr) | rq->tag;
  511. }
  512. static inline struct request *nvme_find_rq(struct blk_mq_tags *tags,
  513. u16 command_id)
  514. {
  515. u8 genctr = nvme_genctr_from_cid(command_id);
  516. u16 tag = nvme_tag_from_cid(command_id);
  517. struct request *rq;
  518. rq = blk_mq_tag_to_rq(tags, tag);
  519. if (unlikely(!rq)) {
  520. pr_err("could not locate request for tag %#x\n",
  521. tag);
  522. return NULL;
  523. }
  524. if (unlikely(nvme_genctr_mask(nvme_req(rq)->genctr) != genctr)) {
  525. dev_err(nvme_req(rq)->ctrl->device,
  526. "request %#x genctr mismatch (got %#x expected %#x)\n",
  527. tag, genctr, nvme_genctr_mask(nvme_req(rq)->genctr));
  528. return NULL;
  529. }
  530. return rq;
  531. }
  532. static inline struct request *nvme_cid_to_rq(struct blk_mq_tags *tags,
  533. u16 command_id)
  534. {
  535. return blk_mq_tag_to_rq(tags, nvme_tag_from_cid(command_id));
  536. }
  537. /*
  538. * Return the length of the string without the space padding
  539. */
  540. static inline int nvme_strlen(char *s, int len)
  541. {
  542. while (s[len - 1] == ' ')
  543. len--;
  544. return len;
  545. }
  546. static inline void nvme_print_device_info(struct nvme_ctrl *ctrl)
  547. {
  548. struct nvme_subsystem *subsys = ctrl->subsys;
  549. if (ctrl->ops->print_device_info) {
  550. ctrl->ops->print_device_info(ctrl);
  551. return;
  552. }
  553. dev_err(ctrl->device,
  554. "VID:%04x model:%.*s firmware:%.*s\n", subsys->vendor_id,
  555. nvme_strlen(subsys->model, sizeof(subsys->model)),
  556. subsys->model, nvme_strlen(subsys->firmware_rev,
  557. sizeof(subsys->firmware_rev)),
  558. subsys->firmware_rev);
  559. }
  560. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  561. void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
  562. const char *dev_name);
  563. void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject);
  564. void nvme_should_fail(struct request *req);
  565. #else
  566. static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
  567. const char *dev_name)
  568. {
  569. }
  570. static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj)
  571. {
  572. }
  573. static inline void nvme_should_fail(struct request *req) {}
  574. #endif
  575. bool nvme_wait_reset(struct nvme_ctrl *ctrl);
  576. int nvme_try_sched_reset(struct nvme_ctrl *ctrl);
  577. static inline int nvme_reset_subsystem(struct nvme_ctrl *ctrl)
  578. {
  579. if (!ctrl->subsystem || !ctrl->ops->subsystem_reset)
  580. return -ENOTTY;
  581. return ctrl->ops->subsystem_reset(ctrl);
  582. }
  583. /*
  584. * Convert a 512B sector number to a device logical block number.
  585. */
  586. static inline u64 nvme_sect_to_lba(struct nvme_ns_head *head, sector_t sector)
  587. {
  588. return sector >> (head->lba_shift - SECTOR_SHIFT);
  589. }
  590. /*
  591. * Convert a device logical block number to a 512B sector number.
  592. */
  593. static inline sector_t nvme_lba_to_sect(struct nvme_ns_head *head, u64 lba)
  594. {
  595. return lba << (head->lba_shift - SECTOR_SHIFT);
  596. }
  597. /*
  598. * Convert byte length to nvme's 0-based num dwords
  599. */
  600. static inline u32 nvme_bytes_to_numd(size_t len)
  601. {
  602. return (len >> 2) - 1;
  603. }
  604. static inline bool nvme_is_ana_error(u16 status)
  605. {
  606. switch (status & NVME_SCT_SC_MASK) {
  607. case NVME_SC_ANA_TRANSITION:
  608. case NVME_SC_ANA_INACCESSIBLE:
  609. case NVME_SC_ANA_PERSISTENT_LOSS:
  610. return true;
  611. default:
  612. return false;
  613. }
  614. }
  615. static inline bool nvme_is_path_error(u16 status)
  616. {
  617. /* check for a status code type of 'path related status' */
  618. return (status & NVME_SCT_MASK) == NVME_SCT_PATH;
  619. }
  620. /*
  621. * Fill in the status and result information from the CQE, and then figure out
  622. * if blk-mq will need to use IPI magic to complete the request, and if yes do
  623. * so. If not let the caller complete the request without an indirect function
  624. * call.
  625. */
  626. static inline bool nvme_try_complete_req(struct request *req, __le16 status,
  627. union nvme_result result)
  628. {
  629. struct nvme_request *rq = nvme_req(req);
  630. struct nvme_ctrl *ctrl = rq->ctrl;
  631. if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN))
  632. rq->genctr++;
  633. rq->status = le16_to_cpu(status) >> 1;
  634. rq->result = result;
  635. /* inject error when permitted by fault injection framework */
  636. nvme_should_fail(req);
  637. if (unlikely(blk_should_fake_timeout(req->q)))
  638. return true;
  639. return blk_mq_complete_request_remote(req);
  640. }
  641. static inline void nvme_get_ctrl(struct nvme_ctrl *ctrl)
  642. {
  643. get_device(ctrl->device);
  644. }
  645. static inline void nvme_put_ctrl(struct nvme_ctrl *ctrl)
  646. {
  647. put_device(ctrl->device);
  648. }
  649. static inline bool nvme_is_aen_req(u16 qid, __u16 command_id)
  650. {
  651. return !qid &&
  652. nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH;
  653. }
  654. /*
  655. * Returns true for sink states that can't ever transition back to live.
  656. */
  657. static inline bool nvme_state_terminal(struct nvme_ctrl *ctrl)
  658. {
  659. switch (nvme_ctrl_state(ctrl)) {
  660. case NVME_CTRL_NEW:
  661. case NVME_CTRL_LIVE:
  662. case NVME_CTRL_RESETTING:
  663. case NVME_CTRL_CONNECTING:
  664. return false;
  665. case NVME_CTRL_DELETING:
  666. case NVME_CTRL_DELETING_NOIO:
  667. case NVME_CTRL_DEAD:
  668. return true;
  669. default:
  670. WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
  671. return true;
  672. }
  673. }
  674. void nvme_end_req(struct request *req);
  675. void nvme_complete_rq(struct request *req);
  676. void nvme_complete_batch_req(struct request *req);
  677. static __always_inline void nvme_complete_batch(struct io_comp_batch *iob,
  678. void (*fn)(struct request *rq))
  679. {
  680. struct request *req;
  681. rq_list_for_each(&iob->req_list, req) {
  682. fn(req);
  683. nvme_complete_batch_req(req);
  684. }
  685. blk_mq_end_request_batch(iob);
  686. }
  687. blk_status_t nvme_host_path_error(struct request *req);
  688. bool nvme_cancel_request(struct request *req, void *data);
  689. void nvme_cancel_tagset(struct nvme_ctrl *ctrl);
  690. void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl);
  691. bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
  692. enum nvme_ctrl_state new_state);
  693. int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown);
  694. int nvme_enable_ctrl(struct nvme_ctrl *ctrl);
  695. int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
  696. const struct nvme_ctrl_ops *ops, unsigned long quirks);
  697. int nvme_add_ctrl(struct nvme_ctrl *ctrl);
  698. void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
  699. void nvme_start_ctrl(struct nvme_ctrl *ctrl);
  700. void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
  701. int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended);
  702. int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
  703. const struct blk_mq_ops *ops, unsigned int cmd_size);
  704. void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl);
  705. int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
  706. const struct blk_mq_ops *ops, unsigned int nr_maps,
  707. unsigned int cmd_size);
  708. void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl);
  709. void nvme_remove_namespaces(struct nvme_ctrl *ctrl);
  710. void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
  711. volatile union nvme_result *res);
  712. void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl);
  713. void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl);
  714. void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl);
  715. void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl);
  716. void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl);
  717. void nvme_sync_queues(struct nvme_ctrl *ctrl);
  718. void nvme_sync_io_queues(struct nvme_ctrl *ctrl);
  719. void nvme_unfreeze(struct nvme_ctrl *ctrl);
  720. void nvme_wait_freeze(struct nvme_ctrl *ctrl);
  721. int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
  722. void nvme_start_freeze(struct nvme_ctrl *ctrl);
  723. static inline enum req_op nvme_req_op(struct nvme_command *cmd)
  724. {
  725. return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
  726. }
  727. #define NVME_QID_ANY -1
  728. void nvme_init_request(struct request *req, struct nvme_command *cmd);
  729. void nvme_cleanup_cmd(struct request *req);
  730. blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
  731. blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
  732. struct request *req);
  733. bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
  734. bool queue_live, enum nvme_ctrl_state state);
  735. static inline bool nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
  736. bool queue_live)
  737. {
  738. enum nvme_ctrl_state state = nvme_ctrl_state(ctrl);
  739. if (likely(state == NVME_CTRL_LIVE))
  740. return true;
  741. if (ctrl->ops->flags & NVME_F_FABRICS && state == NVME_CTRL_DELETING)
  742. return queue_live;
  743. return __nvme_check_ready(ctrl, rq, queue_live, state);
  744. }
  745. /*
  746. * NSID shall be unique for all shared namespaces, or if at least one of the
  747. * following conditions is met:
  748. * 1. Namespace Management is supported by the controller
  749. * 2. ANA is supported by the controller
  750. * 3. NVM Set are supported by the controller
  751. *
  752. * In other case, private namespace are not required to report a unique NSID.
  753. */
  754. static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl,
  755. struct nvme_ns_head *head)
  756. {
  757. return head->shared ||
  758. (ctrl->oacs & NVME_CTRL_OACS_NS_MNGT_SUPP) ||
  759. (ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA) ||
  760. (ctrl->ctratt & NVME_CTRL_CTRATT_NVM_SETS);
  761. }
  762. /*
  763. * Flags for __nvme_submit_sync_cmd()
  764. */
  765. typedef __u32 __bitwise nvme_submit_flags_t;
  766. enum {
  767. /* Insert request at the head of the queue */
  768. NVME_SUBMIT_AT_HEAD = (__force nvme_submit_flags_t)(1 << 0),
  769. /* Set BLK_MQ_REQ_NOWAIT when allocating request */
  770. NVME_SUBMIT_NOWAIT = (__force nvme_submit_flags_t)(1 << 1),
  771. /* Set BLK_MQ_REQ_RESERVED when allocating request */
  772. NVME_SUBMIT_RESERVED = (__force nvme_submit_flags_t)(1 << 2),
  773. /* Retry command when NVME_STATUS_DNR is not set in the result */
  774. NVME_SUBMIT_RETRY = (__force nvme_submit_flags_t)(1 << 3),
  775. };
  776. int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  777. void *buf, unsigned bufflen);
  778. int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  779. union nvme_result *result, void *buffer, unsigned bufflen,
  780. int qid, nvme_submit_flags_t flags);
  781. int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
  782. unsigned int dword11, void *buffer, size_t buflen,
  783. u32 *result);
  784. int nvme_get_features(struct nvme_ctrl *dev, unsigned int fid,
  785. unsigned int dword11, void *buffer, size_t buflen,
  786. u32 *result);
  787. int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count);
  788. void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
  789. int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
  790. int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
  791. int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
  792. void nvme_queue_scan(struct nvme_ctrl *ctrl);
  793. int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
  794. void *log, size_t size, u64 offset);
  795. bool nvme_tryget_ns_head(struct nvme_ns_head *head);
  796. void nvme_put_ns_head(struct nvme_ns_head *head);
  797. int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
  798. const struct file_operations *fops, struct module *owner);
  799. void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device);
  800. int nvme_ioctl(struct block_device *bdev, blk_mode_t mode,
  801. unsigned int cmd, unsigned long arg);
  802. long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  803. int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode,
  804. unsigned int cmd, unsigned long arg);
  805. long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
  806. unsigned long arg);
  807. long nvme_dev_ioctl(struct file *file, unsigned int cmd,
  808. unsigned long arg);
  809. int nvme_ns_chr_uring_cmd_iopoll(struct io_uring_cmd *ioucmd,
  810. struct io_comp_batch *iob, unsigned int poll_flags);
  811. int nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd,
  812. unsigned int issue_flags);
  813. int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
  814. unsigned int issue_flags);
  815. int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
  816. struct nvme_id_ns **id);
  817. int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo);
  818. int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
  819. extern const struct attribute_group *nvme_ns_attr_groups[];
  820. extern const struct pr_ops nvme_pr_ops;
  821. extern const struct block_device_operations nvme_ns_head_ops;
  822. extern const struct attribute_group nvme_dev_attrs_group;
  823. extern const struct attribute_group *nvme_subsys_attrs_groups[];
  824. extern const struct attribute_group *nvme_dev_attr_groups[];
  825. extern const struct block_device_operations nvme_bdev_ops;
  826. void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
  827. struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
  828. #ifdef CONFIG_NVME_MULTIPATH
  829. static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
  830. {
  831. return ctrl->ana_log_buf != NULL;
  832. }
  833. void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
  834. void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
  835. void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
  836. void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys);
  837. void nvme_failover_req(struct request *req);
  838. void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
  839. int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
  840. void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid);
  841. void nvme_mpath_remove_disk(struct nvme_ns_head *head);
  842. int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id);
  843. void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl);
  844. void nvme_mpath_update(struct nvme_ctrl *ctrl);
  845. void nvme_mpath_uninit(struct nvme_ctrl *ctrl);
  846. void nvme_mpath_stop(struct nvme_ctrl *ctrl);
  847. bool nvme_mpath_clear_current_path(struct nvme_ns *ns);
  848. void nvme_mpath_revalidate_paths(struct nvme_ns *ns);
  849. void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl);
  850. void nvme_mpath_shutdown_disk(struct nvme_ns_head *head);
  851. void nvme_mpath_start_request(struct request *rq);
  852. void nvme_mpath_end_request(struct request *rq);
  853. static inline void nvme_trace_bio_complete(struct request *req)
  854. {
  855. struct nvme_ns *ns = req->q->queuedata;
  856. if ((req->cmd_flags & REQ_NVME_MPATH) && req->bio)
  857. trace_block_bio_complete(ns->head->disk->queue, req->bio);
  858. }
  859. extern bool multipath;
  860. extern struct device_attribute dev_attr_ana_grpid;
  861. extern struct device_attribute dev_attr_ana_state;
  862. extern struct device_attribute subsys_attr_iopolicy;
  863. static inline bool nvme_disk_is_ns_head(struct gendisk *disk)
  864. {
  865. return disk->fops == &nvme_ns_head_ops;
  866. }
  867. #else
  868. #define multipath false
  869. static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
  870. {
  871. return false;
  872. }
  873. static inline void nvme_failover_req(struct request *req)
  874. {
  875. }
  876. static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
  877. {
  878. }
  879. static inline int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,
  880. struct nvme_ns_head *head)
  881. {
  882. return 0;
  883. }
  884. static inline void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
  885. {
  886. }
  887. static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head)
  888. {
  889. }
  890. static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
  891. {
  892. return false;
  893. }
  894. static inline void nvme_mpath_revalidate_paths(struct nvme_ns *ns)
  895. {
  896. }
  897. static inline void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
  898. {
  899. }
  900. static inline void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
  901. {
  902. }
  903. static inline void nvme_trace_bio_complete(struct request *req)
  904. {
  905. }
  906. static inline void nvme_mpath_init_ctrl(struct nvme_ctrl *ctrl)
  907. {
  908. }
  909. static inline int nvme_mpath_init_identify(struct nvme_ctrl *ctrl,
  910. struct nvme_id_ctrl *id)
  911. {
  912. if (ctrl->subsys->cmic & NVME_CTRL_CMIC_ANA)
  913. dev_warn(ctrl->device,
  914. "Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.\n");
  915. return 0;
  916. }
  917. static inline void nvme_mpath_update(struct nvme_ctrl *ctrl)
  918. {
  919. }
  920. static inline void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
  921. {
  922. }
  923. static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl)
  924. {
  925. }
  926. static inline void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
  927. {
  928. }
  929. static inline void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
  930. {
  931. }
  932. static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
  933. {
  934. }
  935. static inline void nvme_mpath_default_iopolicy(struct nvme_subsystem *subsys)
  936. {
  937. }
  938. static inline void nvme_mpath_start_request(struct request *rq)
  939. {
  940. }
  941. static inline void nvme_mpath_end_request(struct request *rq)
  942. {
  943. }
  944. static inline bool nvme_disk_is_ns_head(struct gendisk *disk)
  945. {
  946. return false;
  947. }
  948. #endif /* CONFIG_NVME_MULTIPATH */
  949. int nvme_ns_get_unique_id(struct nvme_ns *ns, u8 id[16],
  950. enum blk_unique_id type);
  951. struct nvme_zone_info {
  952. u64 zone_size;
  953. unsigned int max_open_zones;
  954. unsigned int max_active_zones;
  955. };
  956. int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
  957. unsigned int nr_zones, report_zones_cb cb, void *data);
  958. int nvme_query_zone_info(struct nvme_ns *ns, unsigned lbaf,
  959. struct nvme_zone_info *zi);
  960. void nvme_update_zone_info(struct nvme_ns *ns, struct queue_limits *lim,
  961. struct nvme_zone_info *zi);
  962. #ifdef CONFIG_BLK_DEV_ZONED
  963. blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
  964. struct nvme_command *cmnd,
  965. enum nvme_zone_mgmt_action action);
  966. #else
  967. static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns,
  968. struct request *req, struct nvme_command *cmnd,
  969. enum nvme_zone_mgmt_action action)
  970. {
  971. return BLK_STS_NOTSUPP;
  972. }
  973. #endif
  974. static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev)
  975. {
  976. struct gendisk *disk = dev_to_disk(dev);
  977. WARN_ON(nvme_disk_is_ns_head(disk));
  978. return disk->private_data;
  979. }
  980. #ifdef CONFIG_NVME_HWMON
  981. int nvme_hwmon_init(struct nvme_ctrl *ctrl);
  982. void nvme_hwmon_exit(struct nvme_ctrl *ctrl);
  983. #else
  984. static inline int nvme_hwmon_init(struct nvme_ctrl *ctrl)
  985. {
  986. return 0;
  987. }
  988. static inline void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
  989. {
  990. }
  991. #endif
  992. static inline void nvme_start_request(struct request *rq)
  993. {
  994. if (rq->cmd_flags & REQ_NVME_MPATH)
  995. nvme_mpath_start_request(rq);
  996. blk_mq_start_request(rq);
  997. }
  998. static inline bool nvme_ctrl_sgl_supported(struct nvme_ctrl *ctrl)
  999. {
  1000. return ctrl->sgls & ((1 << 0) | (1 << 1));
  1001. }
  1002. static inline bool nvme_ctrl_meta_sgl_supported(struct nvme_ctrl *ctrl)
  1003. {
  1004. if (ctrl->ops->flags & NVME_F_FABRICS)
  1005. return true;
  1006. return ctrl->sgls & NVME_CTRL_SGLS_MSDS;
  1007. }
  1008. #ifdef CONFIG_NVME_HOST_AUTH
  1009. int __init nvme_init_auth(void);
  1010. void __exit nvme_exit_auth(void);
  1011. int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl);
  1012. void nvme_auth_stop(struct nvme_ctrl *ctrl);
  1013. int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid);
  1014. int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid);
  1015. void nvme_auth_free(struct nvme_ctrl *ctrl);
  1016. #else
  1017. static inline int nvme_auth_init_ctrl(struct nvme_ctrl *ctrl)
  1018. {
  1019. return 0;
  1020. }
  1021. static inline int __init nvme_init_auth(void)
  1022. {
  1023. return 0;
  1024. }
  1025. static inline void __exit nvme_exit_auth(void)
  1026. {
  1027. }
  1028. static inline void nvme_auth_stop(struct nvme_ctrl *ctrl) {};
  1029. static inline int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid)
  1030. {
  1031. return -EPROTONOSUPPORT;
  1032. }
  1033. static inline int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid)
  1034. {
  1035. return -EPROTONOSUPPORT;
  1036. }
  1037. static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {};
  1038. #endif
  1039. u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
  1040. u8 opcode);
  1041. u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode);
  1042. int nvme_execute_rq(struct request *rq, bool at_head);
  1043. void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects,
  1044. struct nvme_command *cmd, int status);
  1045. struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
  1046. struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
  1047. bool nvme_get_ns(struct nvme_ns *ns);
  1048. void nvme_put_ns(struct nvme_ns *ns);
  1049. static inline bool nvme_multi_css(struct nvme_ctrl *ctrl)
  1050. {
  1051. return (ctrl->ctrl_config & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI;
  1052. }
  1053. #ifdef CONFIG_NVME_VERBOSE_ERRORS
  1054. const char *nvme_get_error_status_str(u16 status);
  1055. const char *nvme_get_opcode_str(u8 opcode);
  1056. const char *nvme_get_admin_opcode_str(u8 opcode);
  1057. const char *nvme_get_fabrics_opcode_str(u8 opcode);
  1058. #else /* CONFIG_NVME_VERBOSE_ERRORS */
  1059. static inline const char *nvme_get_error_status_str(u16 status)
  1060. {
  1061. return "I/O Error";
  1062. }
  1063. static inline const char *nvme_get_opcode_str(u8 opcode)
  1064. {
  1065. return "I/O Cmd";
  1066. }
  1067. static inline const char *nvme_get_admin_opcode_str(u8 opcode)
  1068. {
  1069. return "Admin Cmd";
  1070. }
  1071. static inline const char *nvme_get_fabrics_opcode_str(u8 opcode)
  1072. {
  1073. return "Fabrics Cmd";
  1074. }
  1075. #endif /* CONFIG_NVME_VERBOSE_ERRORS */
  1076. static inline const char *nvme_opcode_str(int qid, u8 opcode)
  1077. {
  1078. return qid ? nvme_get_opcode_str(opcode) :
  1079. nvme_get_admin_opcode_str(opcode);
  1080. }
  1081. static inline const char *nvme_fabrics_opcode_str(
  1082. int qid, const struct nvme_command *cmd)
  1083. {
  1084. if (nvme_is_fabrics(cmd))
  1085. return nvme_get_fabrics_opcode_str(cmd->fabrics.fctype);
  1086. return nvme_opcode_str(qid, cmd->common.opcode);
  1087. }
  1088. #endif /* _NVME_H */