xref: /spdk/lib/nvmf/nvmf.c (revision d27b24c94b3e506868d5eaa7b93fddc8abfe250f)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <arpa/inet.h>
35 
36 #include "spdk/conf.h"
37 #include "spdk/nvmf.h"
38 #include "spdk/trace.h"
39 
40 #include "spdk_internal/log.h"
41 
42 #include "subsystem.h"
43 #include "transport.h"
44 
45 SPDK_LOG_REGISTER_TRACE_FLAG("nvmf", SPDK_TRACE_NVMF)
46 
47 #define MAX_SUBSYSTEMS 4
48 
49 struct spdk_nvmf_globals g_nvmf_tgt;
50 
51 int
52 spdk_nvmf_tgt_init(uint16_t max_queue_depth, uint16_t max_queues_per_sess,
53 		   uint32_t in_capsule_data_size, uint32_t max_io_size)
54 {
55 	int rc;
56 
57 	g_nvmf_tgt.max_queues_per_session = max_queues_per_sess;
58 	g_nvmf_tgt.max_queue_depth = max_queue_depth;
59 	g_nvmf_tgt.in_capsule_data_size = in_capsule_data_size;
60 	g_nvmf_tgt.max_io_size = max_io_size;
61 
62 	spdk_nvmf_transport_init();
63 
64 	SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max Queues Per Session: %d\n", max_queues_per_sess);
65 	SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max Queue Depth: %d\n", max_queue_depth);
66 	SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max In Capsule Data: %d bytes\n", in_capsule_data_size);
67 	SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max I/O Size: %d bytes\n", max_io_size);
68 
69 	rc = spdk_nvmf_transport_init();
70 	if (rc <= 0) {
71 		SPDK_ERRLOG("Transport initialization failed\n");
72 		return -1;
73 	}
74 
75 	return 0;
76 }
77 
78 int
79 spdk_nvmf_tgt_fini(void)
80 {
81 	spdk_nvmf_transport_fini();
82 
83 	return 0;
84 }
85 
86 SPDK_TRACE_REGISTER_FN(nvmf_trace)
87 {
88 	spdk_trace_register_object(OBJECT_NVMF_IO, 'r');
89 	spdk_trace_register_description("NVMF_IO_START", "", TRACE_NVMF_IO_START,
90 					OWNER_NONE, OBJECT_NVMF_IO, 1, 0, 0, "");
91 	spdk_trace_register_description("NVMF_RDMA_READ_START", "", TRACE_RDMA_READ_START,
92 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
93 	spdk_trace_register_description("NVMF_RDMA_WRITE_START", "", TRACE_RDMA_WRITE_START,
94 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
95 	spdk_trace_register_description("NVMF_RDMA_READ_COMPLETE", "", TRACE_RDMA_READ_COMPLETE,
96 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
97 	spdk_trace_register_description("NVMF_RDMA_WRITE_COMPLETE", "", TRACE_RDMA_WRITE_COMPLETE,
98 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
99 	spdk_trace_register_description("NVMF_LIB_READ_START", "", TRACE_NVMF_LIB_READ_START,
100 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
101 	spdk_trace_register_description("NVMF_LIB_WRITE_START", "", TRACE_NVMF_LIB_WRITE_START,
102 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
103 	spdk_trace_register_description("NVMF_LIB_COMPLETE", "", TRACE_NVMF_LIB_COMPLETE,
104 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
105 	spdk_trace_register_description("NVMF_IO_COMPLETION_DONE", "", TRACE_NVMF_IO_COMPLETE,
106 					OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
107 }
108