1a07b4970SChristoph Hellwig /* 2a07b4970SChristoph Hellwig * Copyright (c) 2015-2016 HGST, a Western Digital Company. 3a07b4970SChristoph Hellwig * 4a07b4970SChristoph Hellwig * This program is free software; you can redistribute it and/or modify it 5a07b4970SChristoph Hellwig * under the terms and conditions of the GNU General Public License, 6a07b4970SChristoph Hellwig * version 2, as published by the Free Software Foundation. 7a07b4970SChristoph Hellwig * 8a07b4970SChristoph Hellwig * This program is distributed in the hope it will be useful, but WITHOUT 9a07b4970SChristoph Hellwig * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10a07b4970SChristoph Hellwig * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11a07b4970SChristoph Hellwig * more details. 12a07b4970SChristoph Hellwig */ 13a07b4970SChristoph Hellwig 14a07b4970SChristoph Hellwig #ifndef _NVMET_H 15a07b4970SChristoph Hellwig #define _NVMET_H 16a07b4970SChristoph Hellwig 17a07b4970SChristoph Hellwig #include <linux/dma-mapping.h> 18a07b4970SChristoph Hellwig #include <linux/types.h> 19a07b4970SChristoph Hellwig #include <linux/device.h> 20a07b4970SChristoph Hellwig #include <linux/kref.h> 21a07b4970SChristoph Hellwig #include <linux/percpu-refcount.h> 22a07b4970SChristoph Hellwig #include <linux/list.h> 23a07b4970SChristoph Hellwig #include <linux/mutex.h> 248e412263SChristoph Hellwig #include <linux/uuid.h> 25a07b4970SChristoph Hellwig #include <linux/nvme.h> 26a07b4970SChristoph Hellwig #include <linux/configfs.h> 27a07b4970SChristoph Hellwig #include <linux/rcupdate.h> 28a07b4970SChristoph Hellwig #include <linux/blkdev.h> 29*c6925093SLogan Gunthorpe #include <linux/radix-tree.h> 30a07b4970SChristoph Hellwig 31a07b4970SChristoph Hellwig #define NVMET_ASYNC_EVENTS 4 32a07b4970SChristoph Hellwig #define NVMET_ERROR_LOG_SLOTS 128 33a07b4970SChristoph Hellwig 34c86b8f7bSChristoph Hellwig /* 35c86b8f7bSChristoph Hellwig * Supported optional AENs: 36c86b8f7bSChristoph Hellwig */ 37c86b8f7bSChristoph Hellwig #define NVMET_AEN_CFG_OPTIONAL \ 3862ac0d32SChristoph Hellwig (NVME_AEN_CFG_NS_ATTR | NVME_AEN_CFG_ANA_CHANGE) 39c86b8f7bSChristoph Hellwig 40c86b8f7bSChristoph Hellwig /* 41c86b8f7bSChristoph Hellwig * Plus mandatory SMART AENs (we'll never send them, but allow enabling them): 42c86b8f7bSChristoph Hellwig */ 43c86b8f7bSChristoph Hellwig #define NVMET_AEN_CFG_ALL \ 44c86b8f7bSChristoph Hellwig (NVME_SMART_CRIT_SPARE | NVME_SMART_CRIT_TEMPERATURE | \ 45c86b8f7bSChristoph Hellwig NVME_SMART_CRIT_RELIABILITY | NVME_SMART_CRIT_MEDIA | \ 46c86b8f7bSChristoph Hellwig NVME_SMART_CRIT_VOLATILE_MEMORY | NVMET_AEN_CFG_OPTIONAL) 47c86b8f7bSChristoph Hellwig 48a07b4970SChristoph Hellwig /* Helper Macros when NVMe error is NVME_SC_CONNECT_INVALID_PARAM 49a07b4970SChristoph Hellwig * The 16 bit shift is to set IATTR bit to 1, which means offending 50a07b4970SChristoph Hellwig * offset starts in the data section of connect() 51a07b4970SChristoph Hellwig */ 52a07b4970SChristoph Hellwig #define IPO_IATTR_CONNECT_DATA(x) \ 53a07b4970SChristoph Hellwig (cpu_to_le32((1 << 16) | (offsetof(struct nvmf_connect_data, x)))) 54a07b4970SChristoph Hellwig #define IPO_IATTR_CONNECT_SQE(x) \ 55a07b4970SChristoph Hellwig (cpu_to_le32(offsetof(struct nvmf_connect_command, x))) 56a07b4970SChristoph Hellwig 57a07b4970SChristoph Hellwig struct nvmet_ns { 58a07b4970SChristoph Hellwig struct list_head dev_link; 59a07b4970SChristoph Hellwig struct percpu_ref ref; 60a07b4970SChristoph Hellwig struct block_device *bdev; 61d5eff33eSChaitanya Kulkarni struct file *file; 62dedf0be5SChaitanya Kulkarni bool readonly; 63a07b4970SChristoph Hellwig u32 nsid; 64a07b4970SChristoph Hellwig u32 blksize_shift; 65a07b4970SChristoph Hellwig loff_t size; 66a07b4970SChristoph Hellwig u8 nguid[16]; 67637dc0f3SJohannes Thumshirn uuid_t uuid; 6872efd25dSChristoph Hellwig u32 anagrpid; 69a07b4970SChristoph Hellwig 7055eb942eSChaitanya Kulkarni bool buffered_io; 71e4fcf07cSSolganik Alexander bool enabled; 72a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 73a07b4970SChristoph Hellwig const char *device_path; 74a07b4970SChristoph Hellwig 75a07b4970SChristoph Hellwig struct config_group device_group; 76a07b4970SChristoph Hellwig struct config_group group; 77a07b4970SChristoph Hellwig 78a07b4970SChristoph Hellwig struct completion disable_done; 79d5eff33eSChaitanya Kulkarni mempool_t *bvec_pool; 80d5eff33eSChaitanya Kulkarni struct kmem_cache *bvec_cache; 81*c6925093SLogan Gunthorpe 82*c6925093SLogan Gunthorpe int use_p2pmem; 83*c6925093SLogan Gunthorpe struct pci_dev *p2p_dev; 84a07b4970SChristoph Hellwig }; 85a07b4970SChristoph Hellwig 86a07b4970SChristoph Hellwig static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item) 87a07b4970SChristoph Hellwig { 88a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_ns, group); 89a07b4970SChristoph Hellwig } 90a07b4970SChristoph Hellwig 91*c6925093SLogan Gunthorpe static inline struct device *nvmet_ns_dev(struct nvmet_ns *ns) 92*c6925093SLogan Gunthorpe { 93*c6925093SLogan Gunthorpe return ns->bdev ? disk_to_dev(ns->bdev->bd_disk) : NULL; 94*c6925093SLogan Gunthorpe } 95*c6925093SLogan Gunthorpe 96a07b4970SChristoph Hellwig struct nvmet_cq { 97a07b4970SChristoph Hellwig u16 qid; 98a07b4970SChristoph Hellwig u16 size; 99a07b4970SChristoph Hellwig }; 100a07b4970SChristoph Hellwig 101a07b4970SChristoph Hellwig struct nvmet_sq { 102a07b4970SChristoph Hellwig struct nvmet_ctrl *ctrl; 103a07b4970SChristoph Hellwig struct percpu_ref ref; 104a07b4970SChristoph Hellwig u16 qid; 105a07b4970SChristoph Hellwig u16 size; 106f9cf2a64SJames Smart u32 sqhd; 107a07b4970SChristoph Hellwig struct completion free_done; 108427242ceSSagi Grimberg struct completion confirm_done; 109a07b4970SChristoph Hellwig }; 110a07b4970SChristoph Hellwig 11162ac0d32SChristoph Hellwig struct nvmet_ana_group { 11262ac0d32SChristoph Hellwig struct config_group group; 11362ac0d32SChristoph Hellwig struct nvmet_port *port; 11462ac0d32SChristoph Hellwig u32 grpid; 11562ac0d32SChristoph Hellwig }; 11662ac0d32SChristoph Hellwig 11762ac0d32SChristoph Hellwig static inline struct nvmet_ana_group *to_ana_group(struct config_item *item) 11862ac0d32SChristoph Hellwig { 11962ac0d32SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_ana_group, 12062ac0d32SChristoph Hellwig group); 12162ac0d32SChristoph Hellwig } 12262ac0d32SChristoph Hellwig 123a07b4970SChristoph Hellwig /** 124a07b4970SChristoph Hellwig * struct nvmet_port - Common structure to keep port 125a07b4970SChristoph Hellwig * information for the target. 126fe4a9791SChristoph Hellwig * @entry: Entry into referrals or transport list. 127a07b4970SChristoph Hellwig * @disc_addr: Address information is stored in a format defined 128a07b4970SChristoph Hellwig * for a discovery log page entry. 129a07b4970SChristoph Hellwig * @group: ConfigFS group for this element's folder. 130a07b4970SChristoph Hellwig * @priv: Private data for the transport. 131a07b4970SChristoph Hellwig */ 132a07b4970SChristoph Hellwig struct nvmet_port { 133a07b4970SChristoph Hellwig struct list_head entry; 134a07b4970SChristoph Hellwig struct nvmf_disc_rsp_page_entry disc_addr; 135a07b4970SChristoph Hellwig struct config_group group; 136a07b4970SChristoph Hellwig struct config_group subsys_group; 137a07b4970SChristoph Hellwig struct list_head subsystems; 138a07b4970SChristoph Hellwig struct config_group referrals_group; 139a07b4970SChristoph Hellwig struct list_head referrals; 14062ac0d32SChristoph Hellwig struct config_group ana_groups_group; 14162ac0d32SChristoph Hellwig struct nvmet_ana_group ana_default_group; 14272efd25dSChristoph Hellwig enum nvme_ana_state *ana_state; 143a07b4970SChristoph Hellwig void *priv; 144a07b4970SChristoph Hellwig bool enabled; 1450d5ee2b2SSteve Wise int inline_data_size; 146a07b4970SChristoph Hellwig }; 147a07b4970SChristoph Hellwig 148a07b4970SChristoph Hellwig static inline struct nvmet_port *to_nvmet_port(struct config_item *item) 149a07b4970SChristoph Hellwig { 150a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_port, 151a07b4970SChristoph Hellwig group); 152a07b4970SChristoph Hellwig } 153a07b4970SChristoph Hellwig 15462ac0d32SChristoph Hellwig static inline struct nvmet_port *ana_groups_to_port( 15562ac0d32SChristoph Hellwig struct config_item *item) 15662ac0d32SChristoph Hellwig { 15762ac0d32SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_port, 15862ac0d32SChristoph Hellwig ana_groups_group); 15962ac0d32SChristoph Hellwig } 16062ac0d32SChristoph Hellwig 161a07b4970SChristoph Hellwig struct nvmet_ctrl { 162a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 163a07b4970SChristoph Hellwig struct nvmet_cq **cqs; 164a07b4970SChristoph Hellwig struct nvmet_sq **sqs; 165a07b4970SChristoph Hellwig 166a07b4970SChristoph Hellwig struct mutex lock; 167a07b4970SChristoph Hellwig u64 cap; 168a07b4970SChristoph Hellwig u32 cc; 169a07b4970SChristoph Hellwig u32 csts; 170a07b4970SChristoph Hellwig 17128dd5cf7SOmri Mann uuid_t hostid; 172a07b4970SChristoph Hellwig u16 cntlid; 173a07b4970SChristoph Hellwig u32 kato; 174a07b4970SChristoph Hellwig 1754ee43280SChristoph Hellwig struct nvmet_port *port; 1764ee43280SChristoph Hellwig 177c86b8f7bSChristoph Hellwig u32 aen_enabled; 17855fdd6b6SChristoph Hellwig unsigned long aen_masked; 179a07b4970SChristoph Hellwig struct nvmet_req *async_event_cmds[NVMET_ASYNC_EVENTS]; 180a07b4970SChristoph Hellwig unsigned int nr_async_event_cmds; 181a07b4970SChristoph Hellwig struct list_head async_events; 182a07b4970SChristoph Hellwig struct work_struct async_event_work; 183a07b4970SChristoph Hellwig 184a07b4970SChristoph Hellwig struct list_head subsys_entry; 185a07b4970SChristoph Hellwig struct kref ref; 186a07b4970SChristoph Hellwig struct delayed_work ka_work; 187a07b4970SChristoph Hellwig struct work_struct fatal_err_work; 188a07b4970SChristoph Hellwig 189e929f06dSChristoph Hellwig const struct nvmet_fabrics_ops *ops; 190a07b4970SChristoph Hellwig 191c16734eaSChristoph Hellwig __le32 *changed_ns_list; 192c16734eaSChristoph Hellwig u32 nr_changed_ns; 193c16734eaSChristoph Hellwig 194a07b4970SChristoph Hellwig char subsysnqn[NVMF_NQN_FIELD_LEN]; 195a07b4970SChristoph Hellwig char hostnqn[NVMF_NQN_FIELD_LEN]; 196*c6925093SLogan Gunthorpe 197*c6925093SLogan Gunthorpe struct device *p2p_client; 198*c6925093SLogan Gunthorpe struct radix_tree_root p2p_ns_map; 199a07b4970SChristoph Hellwig }; 200a07b4970SChristoph Hellwig 201a07b4970SChristoph Hellwig struct nvmet_subsys { 202a07b4970SChristoph Hellwig enum nvme_subsys_type type; 203a07b4970SChristoph Hellwig 204a07b4970SChristoph Hellwig struct mutex lock; 205a07b4970SChristoph Hellwig struct kref ref; 206a07b4970SChristoph Hellwig 207a07b4970SChristoph Hellwig struct list_head namespaces; 208793c7cfcSChristoph Hellwig unsigned int nr_namespaces; 209a07b4970SChristoph Hellwig unsigned int max_nsid; 210a07b4970SChristoph Hellwig 211a07b4970SChristoph Hellwig struct list_head ctrls; 212a07b4970SChristoph Hellwig 213a07b4970SChristoph Hellwig struct list_head hosts; 214a07b4970SChristoph Hellwig bool allow_any_host; 215a07b4970SChristoph Hellwig 216a07b4970SChristoph Hellwig u16 max_qid; 217a07b4970SChristoph Hellwig 218a07b4970SChristoph Hellwig u64 ver; 2192e7f5d2aSJohannes Thumshirn u64 serial; 220a07b4970SChristoph Hellwig char *subsysnqn; 221a07b4970SChristoph Hellwig 222a07b4970SChristoph Hellwig struct config_group group; 223a07b4970SChristoph Hellwig 224a07b4970SChristoph Hellwig struct config_group namespaces_group; 225a07b4970SChristoph Hellwig struct config_group allowed_hosts_group; 226a07b4970SChristoph Hellwig }; 227a07b4970SChristoph Hellwig 228a07b4970SChristoph Hellwig static inline struct nvmet_subsys *to_subsys(struct config_item *item) 229a07b4970SChristoph Hellwig { 230a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_subsys, group); 231a07b4970SChristoph Hellwig } 232a07b4970SChristoph Hellwig 233a07b4970SChristoph Hellwig static inline struct nvmet_subsys *namespaces_to_subsys( 234a07b4970SChristoph Hellwig struct config_item *item) 235a07b4970SChristoph Hellwig { 236a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_subsys, 237a07b4970SChristoph Hellwig namespaces_group); 238a07b4970SChristoph Hellwig } 239a07b4970SChristoph Hellwig 240a07b4970SChristoph Hellwig struct nvmet_host { 241a07b4970SChristoph Hellwig struct config_group group; 242a07b4970SChristoph Hellwig }; 243a07b4970SChristoph Hellwig 244a07b4970SChristoph Hellwig static inline struct nvmet_host *to_host(struct config_item *item) 245a07b4970SChristoph Hellwig { 246a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_host, group); 247a07b4970SChristoph Hellwig } 248a07b4970SChristoph Hellwig 249a07b4970SChristoph Hellwig static inline char *nvmet_host_name(struct nvmet_host *host) 250a07b4970SChristoph Hellwig { 251a07b4970SChristoph Hellwig return config_item_name(&host->group.cg_item); 252a07b4970SChristoph Hellwig } 253a07b4970SChristoph Hellwig 254a07b4970SChristoph Hellwig struct nvmet_host_link { 255a07b4970SChristoph Hellwig struct list_head entry; 256a07b4970SChristoph Hellwig struct nvmet_host *host; 257a07b4970SChristoph Hellwig }; 258a07b4970SChristoph Hellwig 259a07b4970SChristoph Hellwig struct nvmet_subsys_link { 260a07b4970SChristoph Hellwig struct list_head entry; 261a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 262a07b4970SChristoph Hellwig }; 263a07b4970SChristoph Hellwig 264a07b4970SChristoph Hellwig struct nvmet_req; 265a07b4970SChristoph Hellwig struct nvmet_fabrics_ops { 266a07b4970SChristoph Hellwig struct module *owner; 267a07b4970SChristoph Hellwig unsigned int type; 268a07b4970SChristoph Hellwig unsigned int msdbd; 269a07b4970SChristoph Hellwig bool has_keyed_sgls : 1; 270a07b4970SChristoph Hellwig void (*queue_response)(struct nvmet_req *req); 271a07b4970SChristoph Hellwig int (*add_port)(struct nvmet_port *port); 272a07b4970SChristoph Hellwig void (*remove_port)(struct nvmet_port *port); 273a07b4970SChristoph Hellwig void (*delete_ctrl)(struct nvmet_ctrl *ctrl); 2744c652685SSagi Grimberg void (*disc_traddr)(struct nvmet_req *req, 2754c652685SSagi Grimberg struct nvmet_port *port, char *traddr); 276a07b4970SChristoph Hellwig }; 277a07b4970SChristoph Hellwig 278a07b4970SChristoph Hellwig #define NVMET_MAX_INLINE_BIOVEC 8 279a07b4970SChristoph Hellwig 280a07b4970SChristoph Hellwig struct nvmet_req { 281a07b4970SChristoph Hellwig struct nvme_command *cmd; 282a07b4970SChristoph Hellwig struct nvme_completion *rsp; 283a07b4970SChristoph Hellwig struct nvmet_sq *sq; 284a07b4970SChristoph Hellwig struct nvmet_cq *cq; 285a07b4970SChristoph Hellwig struct nvmet_ns *ns; 286a07b4970SChristoph Hellwig struct scatterlist *sg; 287a07b4970SChristoph Hellwig struct bio_vec inline_bvec[NVMET_MAX_INLINE_BIOVEC]; 288d5eff33eSChaitanya Kulkarni union { 289d5eff33eSChaitanya Kulkarni struct { 290d5eff33eSChaitanya Kulkarni struct bio inline_bio; 291d5eff33eSChaitanya Kulkarni } b; 292d5eff33eSChaitanya Kulkarni struct { 293d5eff33eSChaitanya Kulkarni bool mpool_alloc; 294d5eff33eSChaitanya Kulkarni struct kiocb iocb; 295d5eff33eSChaitanya Kulkarni struct bio_vec *bvec; 296d5eff33eSChaitanya Kulkarni struct work_struct work; 297d5eff33eSChaitanya Kulkarni } f; 298d5eff33eSChaitanya Kulkarni }; 299a07b4970SChristoph Hellwig int sg_cnt; 3005e62d5c9SChristoph Hellwig /* data length as parsed from the command: */ 301a07b4970SChristoph Hellwig size_t data_len; 3025e62d5c9SChristoph Hellwig /* data length as parsed from the SGL descriptor: */ 3035e62d5c9SChristoph Hellwig size_t transfer_len; 304a07b4970SChristoph Hellwig 305a07b4970SChristoph Hellwig struct nvmet_port *port; 306a07b4970SChristoph Hellwig 307a07b4970SChristoph Hellwig void (*execute)(struct nvmet_req *req); 308e929f06dSChristoph Hellwig const struct nvmet_fabrics_ops *ops; 309*c6925093SLogan Gunthorpe 310*c6925093SLogan Gunthorpe struct pci_dev *p2p_dev; 311*c6925093SLogan Gunthorpe struct device *p2p_client; 312a07b4970SChristoph Hellwig }; 313a07b4970SChristoph Hellwig 31455eb942eSChaitanya Kulkarni extern struct workqueue_struct *buffered_io_wq; 31555eb942eSChaitanya Kulkarni 316a07b4970SChristoph Hellwig static inline void nvmet_set_status(struct nvmet_req *req, u16 status) 317a07b4970SChristoph Hellwig { 318a07b4970SChristoph Hellwig req->rsp->status = cpu_to_le16(status << 1); 319a07b4970SChristoph Hellwig } 320a07b4970SChristoph Hellwig 321a07b4970SChristoph Hellwig static inline void nvmet_set_result(struct nvmet_req *req, u32 result) 322a07b4970SChristoph Hellwig { 323d49187e9SChristoph Hellwig req->rsp->result.u32 = cpu_to_le32(result); 324a07b4970SChristoph Hellwig } 325a07b4970SChristoph Hellwig 326a07b4970SChristoph Hellwig /* 327a07b4970SChristoph Hellwig * NVMe command writes actually are DMA reads for us on the target side. 328a07b4970SChristoph Hellwig */ 329a07b4970SChristoph Hellwig static inline enum dma_data_direction 330a07b4970SChristoph Hellwig nvmet_data_dir(struct nvmet_req *req) 331a07b4970SChristoph Hellwig { 332a07b4970SChristoph Hellwig return nvme_is_write(req->cmd) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 333a07b4970SChristoph Hellwig } 334a07b4970SChristoph Hellwig 335a07b4970SChristoph Hellwig struct nvmet_async_event { 336a07b4970SChristoph Hellwig struct list_head entry; 337a07b4970SChristoph Hellwig u8 event_type; 338a07b4970SChristoph Hellwig u8 event_info; 339a07b4970SChristoph Hellwig u8 log_page; 340a07b4970SChristoph Hellwig }; 341a07b4970SChristoph Hellwig 34264a0ca88SParav Pandit u16 nvmet_parse_connect_cmd(struct nvmet_req *req); 343d5eff33eSChaitanya Kulkarni u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req); 344d5eff33eSChaitanya Kulkarni u16 nvmet_file_parse_io_cmd(struct nvmet_req *req); 34564a0ca88SParav Pandit u16 nvmet_parse_admin_cmd(struct nvmet_req *req); 34664a0ca88SParav Pandit u16 nvmet_parse_discovery_cmd(struct nvmet_req *req); 34764a0ca88SParav Pandit u16 nvmet_parse_fabrics_cmd(struct nvmet_req *req); 348a07b4970SChristoph Hellwig 349a07b4970SChristoph Hellwig bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq, 350e929f06dSChristoph Hellwig struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops); 351549f01aeSVijay Immanuel void nvmet_req_uninit(struct nvmet_req *req); 3525e62d5c9SChristoph Hellwig void nvmet_req_execute(struct nvmet_req *req); 353a07b4970SChristoph Hellwig void nvmet_req_complete(struct nvmet_req *req, u16 status); 3545b2322e4SLogan Gunthorpe int nvmet_req_alloc_sgl(struct nvmet_req *req); 3555b2322e4SLogan Gunthorpe void nvmet_req_free_sgl(struct nvmet_req *req); 356a07b4970SChristoph Hellwig 357a07b4970SChristoph Hellwig void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, u16 qid, 358a07b4970SChristoph Hellwig u16 size); 359a07b4970SChristoph Hellwig void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, u16 qid, 360a07b4970SChristoph Hellwig u16 size); 361a07b4970SChristoph Hellwig void nvmet_sq_destroy(struct nvmet_sq *sq); 362a07b4970SChristoph Hellwig int nvmet_sq_init(struct nvmet_sq *sq); 363a07b4970SChristoph Hellwig 364a07b4970SChristoph Hellwig void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl); 365a07b4970SChristoph Hellwig 366a07b4970SChristoph Hellwig void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new); 367a07b4970SChristoph Hellwig u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, 368a07b4970SChristoph Hellwig struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp); 369a07b4970SChristoph Hellwig u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid, 370a07b4970SChristoph Hellwig struct nvmet_req *req, struct nvmet_ctrl **ret); 371a07b4970SChristoph Hellwig void nvmet_ctrl_put(struct nvmet_ctrl *ctrl); 37264a0ca88SParav Pandit u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd); 373a07b4970SChristoph Hellwig 374a07b4970SChristoph Hellwig struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, 375a07b4970SChristoph Hellwig enum nvme_subsys_type type); 376a07b4970SChristoph Hellwig void nvmet_subsys_put(struct nvmet_subsys *subsys); 377344770b0SSagi Grimberg void nvmet_subsys_del_ctrls(struct nvmet_subsys *subsys); 378a07b4970SChristoph Hellwig 379a07b4970SChristoph Hellwig struct nvmet_ns *nvmet_find_namespace(struct nvmet_ctrl *ctrl, __le32 nsid); 380a07b4970SChristoph Hellwig void nvmet_put_namespace(struct nvmet_ns *ns); 381a07b4970SChristoph Hellwig int nvmet_ns_enable(struct nvmet_ns *ns); 382a07b4970SChristoph Hellwig void nvmet_ns_disable(struct nvmet_ns *ns); 383a07b4970SChristoph Hellwig struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid); 384a07b4970SChristoph Hellwig void nvmet_ns_free(struct nvmet_ns *ns); 385a07b4970SChristoph Hellwig 38662ac0d32SChristoph Hellwig void nvmet_send_ana_event(struct nvmet_subsys *subsys, 38762ac0d32SChristoph Hellwig struct nvmet_port *port); 38862ac0d32SChristoph Hellwig void nvmet_port_send_ana_event(struct nvmet_port *port); 38962ac0d32SChristoph Hellwig 390e929f06dSChristoph Hellwig int nvmet_register_transport(const struct nvmet_fabrics_ops *ops); 391e929f06dSChristoph Hellwig void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops); 392a07b4970SChristoph Hellwig 393a07b4970SChristoph Hellwig int nvmet_enable_port(struct nvmet_port *port); 394a07b4970SChristoph Hellwig void nvmet_disable_port(struct nvmet_port *port); 395a07b4970SChristoph Hellwig 396a07b4970SChristoph Hellwig void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port); 397a07b4970SChristoph Hellwig void nvmet_referral_disable(struct nvmet_port *port); 398a07b4970SChristoph Hellwig 399a07b4970SChristoph Hellwig u16 nvmet_copy_to_sgl(struct nvmet_req *req, off_t off, const void *buf, 400a07b4970SChristoph Hellwig size_t len); 401a07b4970SChristoph Hellwig u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf, 402a07b4970SChristoph Hellwig size_t len); 403c7759fffSChristoph Hellwig u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len); 404a07b4970SChristoph Hellwig 405a07b4970SChristoph Hellwig u32 nvmet_get_log_page_len(struct nvme_command *cmd); 406a07b4970SChristoph Hellwig 407a07b4970SChristoph Hellwig #define NVMET_QUEUE_SIZE 1024 4083375e29cSJames Smart #define NVMET_NR_QUEUES 128 409a07b4970SChristoph Hellwig #define NVMET_MAX_CMD NVMET_QUEUE_SIZE 410793c7cfcSChristoph Hellwig 411793c7cfcSChristoph Hellwig /* 412793c7cfcSChristoph Hellwig * Nice round number that makes a list of nsids fit into a page. 413793c7cfcSChristoph Hellwig * Should become tunable at some point in the future. 414793c7cfcSChristoph Hellwig */ 415793c7cfcSChristoph Hellwig #define NVMET_MAX_NAMESPACES 1024 416793c7cfcSChristoph Hellwig 41772efd25dSChristoph Hellwig /* 41872efd25dSChristoph Hellwig * 0 is not a valid ANA group ID, so we start numbering at 1. 41972efd25dSChristoph Hellwig * 42072efd25dSChristoph Hellwig * ANA Group 1 exists without manual intervention, has namespaces assigned to it 42172efd25dSChristoph Hellwig * by default, and is available in an optimized state through all ports. 42272efd25dSChristoph Hellwig */ 42362ac0d32SChristoph Hellwig #define NVMET_MAX_ANAGRPS 128 42472efd25dSChristoph Hellwig #define NVMET_DEFAULT_ANA_GRPID 1 42572efd25dSChristoph Hellwig 426a07b4970SChristoph Hellwig #define NVMET_KAS 10 427a07b4970SChristoph Hellwig #define NVMET_DISC_KATO 120 428a07b4970SChristoph Hellwig 429a07b4970SChristoph Hellwig int __init nvmet_init_configfs(void); 430a07b4970SChristoph Hellwig void __exit nvmet_exit_configfs(void); 431a07b4970SChristoph Hellwig 432a07b4970SChristoph Hellwig int __init nvmet_init_discovery(void); 433a07b4970SChristoph Hellwig void nvmet_exit_discovery(void); 434a07b4970SChristoph Hellwig 435a07b4970SChristoph Hellwig extern struct nvmet_subsys *nvmet_disc_subsys; 436a07b4970SChristoph Hellwig extern u64 nvmet_genctr; 437a07b4970SChristoph Hellwig extern struct rw_semaphore nvmet_config_sem; 438a07b4970SChristoph Hellwig 43972efd25dSChristoph Hellwig extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1]; 44072efd25dSChristoph Hellwig extern u64 nvmet_ana_chgcnt; 44172efd25dSChristoph Hellwig extern struct rw_semaphore nvmet_ana_sem; 44272efd25dSChristoph Hellwig 443a07b4970SChristoph Hellwig bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys, 444a07b4970SChristoph Hellwig const char *hostnqn); 445a07b4970SChristoph Hellwig 446d5eff33eSChaitanya Kulkarni int nvmet_bdev_ns_enable(struct nvmet_ns *ns); 447d5eff33eSChaitanya Kulkarni int nvmet_file_ns_enable(struct nvmet_ns *ns); 448d5eff33eSChaitanya Kulkarni void nvmet_bdev_ns_disable(struct nvmet_ns *ns); 449d5eff33eSChaitanya Kulkarni void nvmet_file_ns_disable(struct nvmet_ns *ns); 450dedf0be5SChaitanya Kulkarni u16 nvmet_bdev_flush(struct nvmet_req *req); 451dedf0be5SChaitanya Kulkarni u16 nvmet_file_flush(struct nvmet_req *req); 452dedf0be5SChaitanya Kulkarni void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid); 453d5eff33eSChaitanya Kulkarni 454d5eff33eSChaitanya Kulkarni static inline u32 nvmet_rw_len(struct nvmet_req *req) 455d5eff33eSChaitanya Kulkarni { 456d5eff33eSChaitanya Kulkarni return ((u32)le16_to_cpu(req->cmd->rw.length) + 1) << 457d5eff33eSChaitanya Kulkarni req->ns->blksize_shift; 458d5eff33eSChaitanya Kulkarni } 459a07b4970SChristoph Hellwig #endif /* _NVMET_H */ 460