xref: /spdk/lib/nvme/nvme_io_msg.h (revision a6dbe3721eb3b5990707fc3e378c95e505dd8ab5)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2019 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 /** \file
7  * SPDK cuse
8  */
9 
10 
11 #ifndef SPDK_NVME_IO_MSG_H_
12 #define SPDK_NVME_IO_MSG_H_
13 
14 typedef void (*spdk_nvme_io_msg_fn)(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid,
15 				    void *arg);
16 
17 struct spdk_nvme_io_msg {
18 	struct spdk_nvme_ctrlr	*ctrlr;
19 	uint32_t		nsid;
20 
21 	spdk_nvme_io_msg_fn	fn;
22 	void			*arg;
23 };
24 
25 struct nvme_io_msg_producer {
26 	const char *name;
27 	void (*update)(struct spdk_nvme_ctrlr *ctrlr);
28 	void (*stop)(struct spdk_nvme_ctrlr *ctrlr);
29 	STAILQ_ENTRY(nvme_io_msg_producer) link;
30 };
31 
32 int nvme_io_msg_send(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, spdk_nvme_io_msg_fn fn,
33 		     void *arg);
34 
35 /**
36  * Process IO message sent to controller from external module.
37  *
38  * This call process requests from the ring, send IO to an allocated qpair or
39  * admin commands in its context. This call is non-blocking and intended to be
40  * polled by SPDK thread to provide safe environment for NVMe request
41  * completion sent by external module to controller.
42  *
43  * The caller must ensure that each controller is polled by only one thread at
44  * a time.
45  *
46  * This function may be called at any point while the controller is attached to
47  * the SPDK NVMe driver.
48  *
49  * \param ctrlr Opaque handle to NVMe controller.
50  *
51  * \return number of processed external IO messages.
52  */
53 int nvme_io_msg_process(struct spdk_nvme_ctrlr *ctrlr);
54 
55 int nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
56 			       struct nvme_io_msg_producer *io_msg_producer);
57 void nvme_io_msg_ctrlr_unregister(struct spdk_nvme_ctrlr *ctrlr,
58 				  struct nvme_io_msg_producer *io_msg_producer);
59 void nvme_io_msg_ctrlr_detach(struct spdk_nvme_ctrlr *ctrlr);
60 void nvme_io_msg_ctrlr_update(struct spdk_nvme_ctrlr *ctrlr);
61 
62 #endif /* SPDK_NVME_IO_MSG_H_ */
63