1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2022-2024 Chelsio Communications, Inc.
5 * Written by: John Baldwin <jhb@FreeBSD.org>
6 */
7
8#ifndef __NVMF_H__
9#define __NVMF_H__
10
11#include <sys/ioccom.h>
12#ifndef _KERNEL
13#include <stdbool.h>
14#endif
15
16/*
17 * Default settings in Fabrics controllers. These match values used by the
18 * Linux target.
19 */
20#define NVMF_MAX_IO_ENTRIES (1024)
21#define NVMF_CC_EN_TIMEOUT (15) /* In 500ms units */
22
23/* Allows for a 16k data buffer + SQE */
24#define NVMF_IOCCSZ (sizeof(struct nvme_command) + 16 * 1024)
25#define NVMF_IORCSZ (sizeof(struct nvme_completion))
26
27#define NVMF_NN (1024)
28
29/*
30 * Default timeouts for Fabrics hosts. These match values used by
31 * Linux.
32 */
33#define NVMF_DEFAULT_RECONNECT_DELAY 10
34#define NVMF_DEFAULT_CONTROLLER_LOSS 600
35
36/*
37 * (data, size) is the userspace buffer for a packed nvlist.
38 *
39 * For requests that copyout an nvlist, len is the amount of data
40 * copied out to *data. If size is zero, no data is copied and len is
41 * set to the required buffer size.
42 */
43struct nvmf_ioc_nv {
44 void *data;
45 size_t len;
46 size_t size;
47};
48
49/*
50 * The fields in a qpair handoff nvlist are:
51 *
52 * Transport independent:
53 *
54 * bool admin
55 * bool sq_flow_control
56 * number qsize
57 * number sqhd
58 * number sqtail host only
59 *
60 * TCP transport:
61 *
62 * number fd
63 * number rxpda
64 * number txpda
65 * bool header_digests
66 * bool data_digests
67 * number maxr2t
68 * number maxh2cdata
69 * number max_icd
70 */
71
72/*
73 * The fields in the nvlist for NVMF_HANDOFF_HOST and
74 * NVMF_RECONNECT_HOST are:
75 *
76 * number trtype
77 * number kato (optional)
78 * number reconnect_delay (optional)
79 * number controller_loss_timeout (optional)
80 * qpair handoff nvlist admin
81 * qpair handoff nvlist array io
82 * binary cdata struct nvme_controller_data
83 * NVMF_RECONNECT_PARAMS nvlist rparams
84 */
85
86/*
87 * The fields in the nvlist for NVMF_RECONNECT_PARAMS are:
88 *
89 * binary dle struct nvme_discovery_log_entry
90 * string hostnqn
91 * number num_io_queues
92 * number kato (optional)
93 * number reconnect_delay (optional)
94 * number controller_loss_timeout (optional)
95 * number io_qsize
96 * bool sq_flow_control
97 *
98 * TCP transport:
99 *
100 * bool header_digests
101 * bool data_digests
102 */
103
104/*
105 * The fields in the nvlist for NVMF_CONNECTION_STATUS are:
106 *
107 * bool connected
108 * timespec nvlist last_disconnect
109 * number tv_sec
110 * number tv_nsec
111 */
112
113/*
114 * The fields in the nvlist for handing off a controller qpair are:
115 *
116 * number trtype
117 * qpair handoff nvlist params
118 * binary cmd struct nvmf_fabric_connect_cmd
119 * binary data struct nvmf_fabric_connect_data
120 */
121
122/* Operations on /dev/nvmf */
123#define NVMF_HANDOFF_HOST _IOW('n', 200, struct nvmf_ioc_nv)
124#define NVMF_DISCONNECT_HOST _IOW('n', 201, const char *)
125#define NVMF_DISCONNECT_ALL _IO('n', 202)
126
127/* Operations on /dev/nvmeX */
128#define NVMF_RECONNECT_PARAMS _IOWR('n', 203, struct nvmf_ioc_nv)
129#define NVMF_RECONNECT_HOST _IOW('n', 204, struct nvmf_ioc_nv)
130#define NVMF_CONNECTION_STATUS _IOWR('n', 205, struct nvmf_ioc_nv)
131
132#endif /* !__NVMF_H__ */