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> 29a07b4970SChristoph Hellwig 30a07b4970SChristoph Hellwig #define NVMET_ASYNC_EVENTS 4 31a07b4970SChristoph Hellwig #define NVMET_ERROR_LOG_SLOTS 128 32a07b4970SChristoph Hellwig 33c86b8f7bSChristoph Hellwig /* 34c86b8f7bSChristoph Hellwig * Supported optional AENs: 35c86b8f7bSChristoph Hellwig */ 36c86b8f7bSChristoph Hellwig #define NVMET_AEN_CFG_OPTIONAL \ 37*62ac0d32SChristoph Hellwig (NVME_AEN_CFG_NS_ATTR | NVME_AEN_CFG_ANA_CHANGE) 38c86b8f7bSChristoph Hellwig 39c86b8f7bSChristoph Hellwig /* 40c86b8f7bSChristoph Hellwig * Plus mandatory SMART AENs (we'll never send them, but allow enabling them): 41c86b8f7bSChristoph Hellwig */ 42c86b8f7bSChristoph Hellwig #define NVMET_AEN_CFG_ALL \ 43c86b8f7bSChristoph Hellwig (NVME_SMART_CRIT_SPARE | NVME_SMART_CRIT_TEMPERATURE | \ 44c86b8f7bSChristoph Hellwig NVME_SMART_CRIT_RELIABILITY | NVME_SMART_CRIT_MEDIA | \ 45c86b8f7bSChristoph Hellwig NVME_SMART_CRIT_VOLATILE_MEMORY | NVMET_AEN_CFG_OPTIONAL) 46c86b8f7bSChristoph Hellwig 47a07b4970SChristoph Hellwig /* Helper Macros when NVMe error is NVME_SC_CONNECT_INVALID_PARAM 48a07b4970SChristoph Hellwig * The 16 bit shift is to set IATTR bit to 1, which means offending 49a07b4970SChristoph Hellwig * offset starts in the data section of connect() 50a07b4970SChristoph Hellwig */ 51a07b4970SChristoph Hellwig #define IPO_IATTR_CONNECT_DATA(x) \ 52a07b4970SChristoph Hellwig (cpu_to_le32((1 << 16) | (offsetof(struct nvmf_connect_data, x)))) 53a07b4970SChristoph Hellwig #define IPO_IATTR_CONNECT_SQE(x) \ 54a07b4970SChristoph Hellwig (cpu_to_le32(offsetof(struct nvmf_connect_command, x))) 55a07b4970SChristoph Hellwig 56a07b4970SChristoph Hellwig struct nvmet_ns { 57a07b4970SChristoph Hellwig struct list_head dev_link; 58a07b4970SChristoph Hellwig struct percpu_ref ref; 59a07b4970SChristoph Hellwig struct block_device *bdev; 60d5eff33eSChaitanya Kulkarni struct file *file; 61a07b4970SChristoph Hellwig u32 nsid; 62a07b4970SChristoph Hellwig u32 blksize_shift; 63a07b4970SChristoph Hellwig loff_t size; 64a07b4970SChristoph Hellwig u8 nguid[16]; 65637dc0f3SJohannes Thumshirn uuid_t uuid; 6672efd25dSChristoph Hellwig u32 anagrpid; 67a07b4970SChristoph Hellwig 6855eb942eSChaitanya Kulkarni bool buffered_io; 69e4fcf07cSSolganik Alexander bool enabled; 70a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 71a07b4970SChristoph Hellwig const char *device_path; 72a07b4970SChristoph Hellwig 73a07b4970SChristoph Hellwig struct config_group device_group; 74a07b4970SChristoph Hellwig struct config_group group; 75a07b4970SChristoph Hellwig 76a07b4970SChristoph Hellwig struct completion disable_done; 77d5eff33eSChaitanya Kulkarni mempool_t *bvec_pool; 78d5eff33eSChaitanya Kulkarni struct kmem_cache *bvec_cache; 79a07b4970SChristoph Hellwig }; 80a07b4970SChristoph Hellwig 81a07b4970SChristoph Hellwig static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item) 82a07b4970SChristoph Hellwig { 83a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_ns, group); 84a07b4970SChristoph Hellwig } 85a07b4970SChristoph Hellwig 86a07b4970SChristoph Hellwig struct nvmet_cq { 87a07b4970SChristoph Hellwig u16 qid; 88a07b4970SChristoph Hellwig u16 size; 89a07b4970SChristoph Hellwig }; 90a07b4970SChristoph Hellwig 91a07b4970SChristoph Hellwig struct nvmet_sq { 92a07b4970SChristoph Hellwig struct nvmet_ctrl *ctrl; 93a07b4970SChristoph Hellwig struct percpu_ref ref; 94a07b4970SChristoph Hellwig u16 qid; 95a07b4970SChristoph Hellwig u16 size; 96f9cf2a64SJames Smart u32 sqhd; 97a07b4970SChristoph Hellwig struct completion free_done; 98427242ceSSagi Grimberg struct completion confirm_done; 99a07b4970SChristoph Hellwig }; 100a07b4970SChristoph Hellwig 101*62ac0d32SChristoph Hellwig struct nvmet_ana_group { 102*62ac0d32SChristoph Hellwig struct config_group group; 103*62ac0d32SChristoph Hellwig struct nvmet_port *port; 104*62ac0d32SChristoph Hellwig u32 grpid; 105*62ac0d32SChristoph Hellwig }; 106*62ac0d32SChristoph Hellwig 107*62ac0d32SChristoph Hellwig static inline struct nvmet_ana_group *to_ana_group(struct config_item *item) 108*62ac0d32SChristoph Hellwig { 109*62ac0d32SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_ana_group, 110*62ac0d32SChristoph Hellwig group); 111*62ac0d32SChristoph Hellwig } 112*62ac0d32SChristoph Hellwig 113a07b4970SChristoph Hellwig /** 114a07b4970SChristoph Hellwig * struct nvmet_port - Common structure to keep port 115a07b4970SChristoph Hellwig * information for the target. 116fe4a9791SChristoph Hellwig * @entry: Entry into referrals or transport list. 117a07b4970SChristoph Hellwig * @disc_addr: Address information is stored in a format defined 118a07b4970SChristoph Hellwig * for a discovery log page entry. 119a07b4970SChristoph Hellwig * @group: ConfigFS group for this element's folder. 120a07b4970SChristoph Hellwig * @priv: Private data for the transport. 121a07b4970SChristoph Hellwig */ 122a07b4970SChristoph Hellwig struct nvmet_port { 123a07b4970SChristoph Hellwig struct list_head entry; 124a07b4970SChristoph Hellwig struct nvmf_disc_rsp_page_entry disc_addr; 125a07b4970SChristoph Hellwig struct config_group group; 126a07b4970SChristoph Hellwig struct config_group subsys_group; 127a07b4970SChristoph Hellwig struct list_head subsystems; 128a07b4970SChristoph Hellwig struct config_group referrals_group; 129a07b4970SChristoph Hellwig struct list_head referrals; 130*62ac0d32SChristoph Hellwig struct config_group ana_groups_group; 131*62ac0d32SChristoph Hellwig struct nvmet_ana_group ana_default_group; 13272efd25dSChristoph Hellwig enum nvme_ana_state *ana_state; 133a07b4970SChristoph Hellwig void *priv; 134a07b4970SChristoph Hellwig bool enabled; 1350d5ee2b2SSteve Wise int inline_data_size; 136a07b4970SChristoph Hellwig }; 137a07b4970SChristoph Hellwig 138a07b4970SChristoph Hellwig static inline struct nvmet_port *to_nvmet_port(struct config_item *item) 139a07b4970SChristoph Hellwig { 140a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_port, 141a07b4970SChristoph Hellwig group); 142a07b4970SChristoph Hellwig } 143a07b4970SChristoph Hellwig 144*62ac0d32SChristoph Hellwig static inline struct nvmet_port *ana_groups_to_port( 145*62ac0d32SChristoph Hellwig struct config_item *item) 146*62ac0d32SChristoph Hellwig { 147*62ac0d32SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_port, 148*62ac0d32SChristoph Hellwig ana_groups_group); 149*62ac0d32SChristoph Hellwig } 150*62ac0d32SChristoph Hellwig 151a07b4970SChristoph Hellwig struct nvmet_ctrl { 152a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 153a07b4970SChristoph Hellwig struct nvmet_cq **cqs; 154a07b4970SChristoph Hellwig struct nvmet_sq **sqs; 155a07b4970SChristoph Hellwig 156a07b4970SChristoph Hellwig struct mutex lock; 157a07b4970SChristoph Hellwig u64 cap; 158a07b4970SChristoph Hellwig u32 cc; 159a07b4970SChristoph Hellwig u32 csts; 160a07b4970SChristoph Hellwig 16128dd5cf7SOmri Mann uuid_t hostid; 162a07b4970SChristoph Hellwig u16 cntlid; 163a07b4970SChristoph Hellwig u32 kato; 164a07b4970SChristoph Hellwig 1654ee43280SChristoph Hellwig struct nvmet_port *port; 1664ee43280SChristoph Hellwig 167c86b8f7bSChristoph Hellwig u32 aen_enabled; 16855fdd6b6SChristoph Hellwig unsigned long aen_masked; 169a07b4970SChristoph Hellwig struct nvmet_req *async_event_cmds[NVMET_ASYNC_EVENTS]; 170a07b4970SChristoph Hellwig unsigned int nr_async_event_cmds; 171a07b4970SChristoph Hellwig struct list_head async_events; 172a07b4970SChristoph Hellwig struct work_struct async_event_work; 173a07b4970SChristoph Hellwig 174a07b4970SChristoph Hellwig struct list_head subsys_entry; 175a07b4970SChristoph Hellwig struct kref ref; 176a07b4970SChristoph Hellwig struct delayed_work ka_work; 177a07b4970SChristoph Hellwig struct work_struct fatal_err_work; 178a07b4970SChristoph Hellwig 179e929f06dSChristoph Hellwig const struct nvmet_fabrics_ops *ops; 180a07b4970SChristoph Hellwig 181c16734eaSChristoph Hellwig __le32 *changed_ns_list; 182c16734eaSChristoph Hellwig u32 nr_changed_ns; 183c16734eaSChristoph Hellwig 184a07b4970SChristoph Hellwig char subsysnqn[NVMF_NQN_FIELD_LEN]; 185a07b4970SChristoph Hellwig char hostnqn[NVMF_NQN_FIELD_LEN]; 186a07b4970SChristoph Hellwig }; 187a07b4970SChristoph Hellwig 188a07b4970SChristoph Hellwig struct nvmet_subsys { 189a07b4970SChristoph Hellwig enum nvme_subsys_type type; 190a07b4970SChristoph Hellwig 191a07b4970SChristoph Hellwig struct mutex lock; 192a07b4970SChristoph Hellwig struct kref ref; 193a07b4970SChristoph Hellwig 194a07b4970SChristoph Hellwig struct list_head namespaces; 195793c7cfcSChristoph Hellwig unsigned int nr_namespaces; 196a07b4970SChristoph Hellwig unsigned int max_nsid; 197a07b4970SChristoph Hellwig 198a07b4970SChristoph Hellwig struct list_head ctrls; 199a07b4970SChristoph Hellwig 200a07b4970SChristoph Hellwig struct list_head hosts; 201a07b4970SChristoph Hellwig bool allow_any_host; 202a07b4970SChristoph Hellwig 203a07b4970SChristoph Hellwig u16 max_qid; 204a07b4970SChristoph Hellwig 205a07b4970SChristoph Hellwig u64 ver; 2062e7f5d2aSJohannes Thumshirn u64 serial; 207a07b4970SChristoph Hellwig char *subsysnqn; 208a07b4970SChristoph Hellwig 209a07b4970SChristoph Hellwig struct config_group group; 210a07b4970SChristoph Hellwig 211a07b4970SChristoph Hellwig struct config_group namespaces_group; 212a07b4970SChristoph Hellwig struct config_group allowed_hosts_group; 213a07b4970SChristoph Hellwig }; 214a07b4970SChristoph Hellwig 215a07b4970SChristoph Hellwig static inline struct nvmet_subsys *to_subsys(struct config_item *item) 216a07b4970SChristoph Hellwig { 217a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_subsys, group); 218a07b4970SChristoph Hellwig } 219a07b4970SChristoph Hellwig 220a07b4970SChristoph Hellwig static inline struct nvmet_subsys *namespaces_to_subsys( 221a07b4970SChristoph Hellwig struct config_item *item) 222a07b4970SChristoph Hellwig { 223a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_subsys, 224a07b4970SChristoph Hellwig namespaces_group); 225a07b4970SChristoph Hellwig } 226a07b4970SChristoph Hellwig 227a07b4970SChristoph Hellwig struct nvmet_host { 228a07b4970SChristoph Hellwig struct config_group group; 229a07b4970SChristoph Hellwig }; 230a07b4970SChristoph Hellwig 231a07b4970SChristoph Hellwig static inline struct nvmet_host *to_host(struct config_item *item) 232a07b4970SChristoph Hellwig { 233a07b4970SChristoph Hellwig return container_of(to_config_group(item), struct nvmet_host, group); 234a07b4970SChristoph Hellwig } 235a07b4970SChristoph Hellwig 236a07b4970SChristoph Hellwig static inline char *nvmet_host_name(struct nvmet_host *host) 237a07b4970SChristoph Hellwig { 238a07b4970SChristoph Hellwig return config_item_name(&host->group.cg_item); 239a07b4970SChristoph Hellwig } 240a07b4970SChristoph Hellwig 241a07b4970SChristoph Hellwig struct nvmet_host_link { 242a07b4970SChristoph Hellwig struct list_head entry; 243a07b4970SChristoph Hellwig struct nvmet_host *host; 244a07b4970SChristoph Hellwig }; 245a07b4970SChristoph Hellwig 246a07b4970SChristoph Hellwig struct nvmet_subsys_link { 247a07b4970SChristoph Hellwig struct list_head entry; 248a07b4970SChristoph Hellwig struct nvmet_subsys *subsys; 249a07b4970SChristoph Hellwig }; 250a07b4970SChristoph Hellwig 251a07b4970SChristoph Hellwig struct nvmet_req; 252a07b4970SChristoph Hellwig struct nvmet_fabrics_ops { 253a07b4970SChristoph Hellwig struct module *owner; 254a07b4970SChristoph Hellwig unsigned int type; 255a07b4970SChristoph Hellwig unsigned int msdbd; 256a07b4970SChristoph Hellwig bool has_keyed_sgls : 1; 257a07b4970SChristoph Hellwig void (*queue_response)(struct nvmet_req *req); 258a07b4970SChristoph Hellwig int (*add_port)(struct nvmet_port *port); 259a07b4970SChristoph Hellwig void (*remove_port)(struct nvmet_port *port); 260a07b4970SChristoph Hellwig void (*delete_ctrl)(struct nvmet_ctrl *ctrl); 2614c652685SSagi Grimberg void (*disc_traddr)(struct nvmet_req *req, 2624c652685SSagi Grimberg struct nvmet_port *port, char *traddr); 263a07b4970SChristoph Hellwig }; 264a07b4970SChristoph Hellwig 265a07b4970SChristoph Hellwig #define NVMET_MAX_INLINE_BIOVEC 8 266a07b4970SChristoph Hellwig 267a07b4970SChristoph Hellwig struct nvmet_req { 268a07b4970SChristoph Hellwig struct nvme_command *cmd; 269a07b4970SChristoph Hellwig struct nvme_completion *rsp; 270a07b4970SChristoph Hellwig struct nvmet_sq *sq; 271a07b4970SChristoph Hellwig struct nvmet_cq *cq; 272a07b4970SChristoph Hellwig struct nvmet_ns *ns; 273a07b4970SChristoph Hellwig struct scatterlist *sg; 274a07b4970SChristoph Hellwig struct bio_vec inline_bvec[NVMET_MAX_INLINE_BIOVEC]; 275d5eff33eSChaitanya Kulkarni union { 276d5eff33eSChaitanya Kulkarni struct { 277d5eff33eSChaitanya Kulkarni struct bio inline_bio; 278d5eff33eSChaitanya Kulkarni } b; 279d5eff33eSChaitanya Kulkarni struct { 280d5eff33eSChaitanya Kulkarni bool mpool_alloc; 281d5eff33eSChaitanya Kulkarni struct kiocb iocb; 282d5eff33eSChaitanya Kulkarni struct bio_vec *bvec; 283d5eff33eSChaitanya Kulkarni struct work_struct work; 284d5eff33eSChaitanya Kulkarni } f; 285d5eff33eSChaitanya Kulkarni }; 286a07b4970SChristoph Hellwig int sg_cnt; 2875e62d5c9SChristoph Hellwig /* data length as parsed from the command: */ 288a07b4970SChristoph Hellwig size_t data_len; 2895e62d5c9SChristoph Hellwig /* data length as parsed from the SGL descriptor: */ 2905e62d5c9SChristoph Hellwig size_t transfer_len; 291a07b4970SChristoph Hellwig 292a07b4970SChristoph Hellwig struct nvmet_port *port; 293a07b4970SChristoph Hellwig 294a07b4970SChristoph Hellwig void (*execute)(struct nvmet_req *req); 295e929f06dSChristoph Hellwig const struct nvmet_fabrics_ops *ops; 296a07b4970SChristoph Hellwig }; 297a07b4970SChristoph Hellwig 29855eb942eSChaitanya Kulkarni extern struct workqueue_struct *buffered_io_wq; 29955eb942eSChaitanya Kulkarni 300a07b4970SChristoph Hellwig static inline void nvmet_set_status(struct nvmet_req *req, u16 status) 301a07b4970SChristoph Hellwig { 302a07b4970SChristoph Hellwig req->rsp->status = cpu_to_le16(status << 1); 303a07b4970SChristoph Hellwig } 304a07b4970SChristoph Hellwig 305a07b4970SChristoph Hellwig static inline void nvmet_set_result(struct nvmet_req *req, u32 result) 306a07b4970SChristoph Hellwig { 307d49187e9SChristoph Hellwig req->rsp->result.u32 = cpu_to_le32(result); 308a07b4970SChristoph Hellwig } 309a07b4970SChristoph Hellwig 310a07b4970SChristoph Hellwig /* 311a07b4970SChristoph Hellwig * NVMe command writes actually are DMA reads for us on the target side. 312a07b4970SChristoph Hellwig */ 313a07b4970SChristoph Hellwig static inline enum dma_data_direction 314a07b4970SChristoph Hellwig nvmet_data_dir(struct nvmet_req *req) 315a07b4970SChristoph Hellwig { 316a07b4970SChristoph Hellwig return nvme_is_write(req->cmd) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 317a07b4970SChristoph Hellwig } 318a07b4970SChristoph Hellwig 319a07b4970SChristoph Hellwig struct nvmet_async_event { 320a07b4970SChristoph Hellwig struct list_head entry; 321a07b4970SChristoph Hellwig u8 event_type; 322a07b4970SChristoph Hellwig u8 event_info; 323a07b4970SChristoph Hellwig u8 log_page; 324a07b4970SChristoph Hellwig }; 325a07b4970SChristoph Hellwig 32664a0ca88SParav Pandit u16 nvmet_parse_connect_cmd(struct nvmet_req *req); 327d5eff33eSChaitanya Kulkarni u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req); 328d5eff33eSChaitanya Kulkarni u16 nvmet_file_parse_io_cmd(struct nvmet_req *req); 32964a0ca88SParav Pandit u16 nvmet_parse_admin_cmd(struct nvmet_req *req); 33064a0ca88SParav Pandit u16 nvmet_parse_discovery_cmd(struct nvmet_req *req); 33164a0ca88SParav Pandit u16 nvmet_parse_fabrics_cmd(struct nvmet_req *req); 332a07b4970SChristoph Hellwig 333a07b4970SChristoph Hellwig bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq, 334e929f06dSChristoph Hellwig struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops); 335549f01aeSVijay Immanuel void nvmet_req_uninit(struct nvmet_req *req); 3365e62d5c9SChristoph Hellwig void nvmet_req_execute(struct nvmet_req *req); 337a07b4970SChristoph Hellwig void nvmet_req_complete(struct nvmet_req *req, u16 status); 338a07b4970SChristoph Hellwig 339a07b4970SChristoph Hellwig void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, u16 qid, 340a07b4970SChristoph Hellwig u16 size); 341a07b4970SChristoph Hellwig void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, u16 qid, 342a07b4970SChristoph Hellwig u16 size); 343a07b4970SChristoph Hellwig void nvmet_sq_destroy(struct nvmet_sq *sq); 344a07b4970SChristoph Hellwig int nvmet_sq_init(struct nvmet_sq *sq); 345a07b4970SChristoph Hellwig 346a07b4970SChristoph Hellwig void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl); 347a07b4970SChristoph Hellwig 348a07b4970SChristoph Hellwig void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new); 349a07b4970SChristoph Hellwig u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, 350a07b4970SChristoph Hellwig struct nvmet_req *req, u32 kato, struct nvmet_ctrl **ctrlp); 351a07b4970SChristoph Hellwig u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid, 352a07b4970SChristoph Hellwig struct nvmet_req *req, struct nvmet_ctrl **ret); 353a07b4970SChristoph Hellwig void nvmet_ctrl_put(struct nvmet_ctrl *ctrl); 35464a0ca88SParav Pandit u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd); 355a07b4970SChristoph Hellwig 356a07b4970SChristoph Hellwig struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, 357a07b4970SChristoph Hellwig enum nvme_subsys_type type); 358a07b4970SChristoph Hellwig void nvmet_subsys_put(struct nvmet_subsys *subsys); 359344770b0SSagi Grimberg void nvmet_subsys_del_ctrls(struct nvmet_subsys *subsys); 360a07b4970SChristoph Hellwig 361a07b4970SChristoph Hellwig struct nvmet_ns *nvmet_find_namespace(struct nvmet_ctrl *ctrl, __le32 nsid); 362a07b4970SChristoph Hellwig void nvmet_put_namespace(struct nvmet_ns *ns); 363a07b4970SChristoph Hellwig int nvmet_ns_enable(struct nvmet_ns *ns); 364a07b4970SChristoph Hellwig void nvmet_ns_disable(struct nvmet_ns *ns); 365a07b4970SChristoph Hellwig struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid); 366a07b4970SChristoph Hellwig void nvmet_ns_free(struct nvmet_ns *ns); 367a07b4970SChristoph Hellwig 368*62ac0d32SChristoph Hellwig void nvmet_send_ana_event(struct nvmet_subsys *subsys, 369*62ac0d32SChristoph Hellwig struct nvmet_port *port); 370*62ac0d32SChristoph Hellwig void nvmet_port_send_ana_event(struct nvmet_port *port); 371*62ac0d32SChristoph Hellwig 372e929f06dSChristoph Hellwig int nvmet_register_transport(const struct nvmet_fabrics_ops *ops); 373e929f06dSChristoph Hellwig void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops); 374a07b4970SChristoph Hellwig 375a07b4970SChristoph Hellwig int nvmet_enable_port(struct nvmet_port *port); 376a07b4970SChristoph Hellwig void nvmet_disable_port(struct nvmet_port *port); 377a07b4970SChristoph Hellwig 378a07b4970SChristoph Hellwig void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port); 379a07b4970SChristoph Hellwig void nvmet_referral_disable(struct nvmet_port *port); 380a07b4970SChristoph Hellwig 381a07b4970SChristoph Hellwig u16 nvmet_copy_to_sgl(struct nvmet_req *req, off_t off, const void *buf, 382a07b4970SChristoph Hellwig size_t len); 383a07b4970SChristoph Hellwig u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf, 384a07b4970SChristoph Hellwig size_t len); 385c7759fffSChristoph Hellwig u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len); 386a07b4970SChristoph Hellwig 387a07b4970SChristoph Hellwig u32 nvmet_get_log_page_len(struct nvme_command *cmd); 388a07b4970SChristoph Hellwig 389a07b4970SChristoph Hellwig #define NVMET_QUEUE_SIZE 1024 3903375e29cSJames Smart #define NVMET_NR_QUEUES 128 391a07b4970SChristoph Hellwig #define NVMET_MAX_CMD NVMET_QUEUE_SIZE 392793c7cfcSChristoph Hellwig 393793c7cfcSChristoph Hellwig /* 394793c7cfcSChristoph Hellwig * Nice round number that makes a list of nsids fit into a page. 395793c7cfcSChristoph Hellwig * Should become tunable at some point in the future. 396793c7cfcSChristoph Hellwig */ 397793c7cfcSChristoph Hellwig #define NVMET_MAX_NAMESPACES 1024 398793c7cfcSChristoph Hellwig 39972efd25dSChristoph Hellwig /* 40072efd25dSChristoph Hellwig * 0 is not a valid ANA group ID, so we start numbering at 1. 40172efd25dSChristoph Hellwig * 40272efd25dSChristoph Hellwig * ANA Group 1 exists without manual intervention, has namespaces assigned to it 40372efd25dSChristoph Hellwig * by default, and is available in an optimized state through all ports. 40472efd25dSChristoph Hellwig */ 405*62ac0d32SChristoph Hellwig #define NVMET_MAX_ANAGRPS 128 40672efd25dSChristoph Hellwig #define NVMET_DEFAULT_ANA_GRPID 1 40772efd25dSChristoph Hellwig 408a07b4970SChristoph Hellwig #define NVMET_KAS 10 409a07b4970SChristoph Hellwig #define NVMET_DISC_KATO 120 410a07b4970SChristoph Hellwig 411a07b4970SChristoph Hellwig int __init nvmet_init_configfs(void); 412a07b4970SChristoph Hellwig void __exit nvmet_exit_configfs(void); 413a07b4970SChristoph Hellwig 414a07b4970SChristoph Hellwig int __init nvmet_init_discovery(void); 415a07b4970SChristoph Hellwig void nvmet_exit_discovery(void); 416a07b4970SChristoph Hellwig 417a07b4970SChristoph Hellwig extern struct nvmet_subsys *nvmet_disc_subsys; 418a07b4970SChristoph Hellwig extern u64 nvmet_genctr; 419a07b4970SChristoph Hellwig extern struct rw_semaphore nvmet_config_sem; 420a07b4970SChristoph Hellwig 42172efd25dSChristoph Hellwig extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1]; 42272efd25dSChristoph Hellwig extern u64 nvmet_ana_chgcnt; 42372efd25dSChristoph Hellwig extern struct rw_semaphore nvmet_ana_sem; 42472efd25dSChristoph Hellwig 425a07b4970SChristoph Hellwig bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys, 426a07b4970SChristoph Hellwig const char *hostnqn); 427a07b4970SChristoph Hellwig 428d5eff33eSChaitanya Kulkarni int nvmet_bdev_ns_enable(struct nvmet_ns *ns); 429d5eff33eSChaitanya Kulkarni int nvmet_file_ns_enable(struct nvmet_ns *ns); 430d5eff33eSChaitanya Kulkarni void nvmet_bdev_ns_disable(struct nvmet_ns *ns); 431d5eff33eSChaitanya Kulkarni void nvmet_file_ns_disable(struct nvmet_ns *ns); 432d5eff33eSChaitanya Kulkarni 433d5eff33eSChaitanya Kulkarni static inline u32 nvmet_rw_len(struct nvmet_req *req) 434d5eff33eSChaitanya Kulkarni { 435d5eff33eSChaitanya Kulkarni return ((u32)le16_to_cpu(req->cmd->rw.length) + 1) << 436d5eff33eSChaitanya Kulkarni req->ns->blksize_shift; 437d5eff33eSChaitanya Kulkarni } 438a07b4970SChristoph Hellwig #endif /* _NVMET_H */ 439