xref: /linux/include/linux/nvme-tcp.h (revision 745b7908ecdbec3a3077cd770264c59cdc0efdfd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * NVMe over Fabrics TCP protocol header.
4  * Copyright (c) 2018 Lightbits Labs. All rights reserved.
5  */
6 
7 #ifndef _LINUX_NVME_TCP_H
8 #define _LINUX_NVME_TCP_H
9 
10 #include <linux/nvme.h>
11 
12 #define NVME_TCP_DISC_PORT	8009
13 #define NVME_TCP_ADMIN_CCSZ	SZ_8K
14 #define NVME_TCP_DIGEST_LENGTH	4
15 #define NVME_TCP_MIN_MAXH2CDATA 4096
16 
17 enum nvme_tcp_pfv {
18 	NVME_TCP_PFV_1_0 = 0x0,
19 };
20 
21 enum nvme_tcp_fatal_error_status {
22 	NVME_TCP_FES_INVALID_PDU_HDR		= 0x01,
23 	NVME_TCP_FES_PDU_SEQ_ERR		= 0x02,
24 	NVME_TCP_FES_HDR_DIGEST_ERR		= 0x03,
25 	NVME_TCP_FES_DATA_OUT_OF_RANGE		= 0x04,
26 	NVME_TCP_FES_R2T_LIMIT_EXCEEDED		= 0x05,
27 	NVME_TCP_FES_DATA_LIMIT_EXCEEDED	= 0x05,
28 	NVME_TCP_FES_UNSUPPORTED_PARAM		= 0x06,
29 };
30 
31 enum nvme_tcp_digest_option {
32 	NVME_TCP_HDR_DIGEST_ENABLE	= (1 << 0),
33 	NVME_TCP_DATA_DIGEST_ENABLE	= (1 << 1),
34 };
35 
36 enum nvme_tcp_pdu_type {
37 	nvme_tcp_icreq		= 0x0,
38 	nvme_tcp_icresp		= 0x1,
39 	nvme_tcp_h2c_term	= 0x2,
40 	nvme_tcp_c2h_term	= 0x3,
41 	nvme_tcp_cmd		= 0x4,
42 	nvme_tcp_rsp		= 0x5,
43 	nvme_tcp_h2c_data	= 0x6,
44 	nvme_tcp_c2h_data	= 0x7,
45 	nvme_tcp_r2t		= 0x9,
46 };
47 
48 enum nvme_tcp_pdu_flags {
49 	NVME_TCP_F_HDGST		= (1 << 0),
50 	NVME_TCP_F_DDGST		= (1 << 1),
51 	NVME_TCP_F_DATA_LAST		= (1 << 2),
52 	NVME_TCP_F_DATA_SUCCESS		= (1 << 3),
53 };
54 
55 /**
56  * struct nvme_tcp_hdr - nvme tcp pdu common header
57  *
58  * @type:          pdu type
59  * @flags:         pdu specific flags
60  * @hlen:          pdu header length
61  * @pdo:           pdu data offset
62  * @plen:          pdu wire byte length
63  */
64 struct nvme_tcp_hdr {
65 	__u8	type;
66 	__u8	flags;
67 	__u8	hlen;
68 	__u8	pdo;
69 	__le32	plen;
70 };
71 
72 /**
73  * struct nvme_tcp_icreq_pdu - nvme tcp initialize connection request pdu
74  *
75  * @hdr:           pdu generic header
76  * @pfv:           pdu version format
77  * @hpda:          host pdu data alignment (dwords, 0's based)
78  * @digest:        digest types enabled
79  * @maxr2t:        maximum r2ts per request supported
80  */
81 struct nvme_tcp_icreq_pdu {
82 	struct nvme_tcp_hdr	hdr;
83 	__le16			pfv;
84 	__u8			hpda;
85 	__u8			digest;
86 	__le32			maxr2t;
87 	__u8			rsvd2[112];
88 };
89 
90 /**
91  * struct nvme_tcp_icresp_pdu - nvme tcp initialize connection response pdu
92  *
93  * @hdr:           pdu common header
94  * @pfv:           pdu version format
95  * @cpda:          controller pdu data alignment (dowrds, 0's based)
96  * @digest:        digest types enabled
97  * @maxdata:       maximum data capsules per r2t supported
98  */
99 struct nvme_tcp_icresp_pdu {
100 	struct nvme_tcp_hdr	hdr;
101 	__le16			pfv;
102 	__u8			cpda;
103 	__u8			digest;
104 	__le32			maxdata;
105 	__u8			rsvd[112];
106 };
107 
108 /**
109  * struct nvme_tcp_term_pdu - nvme tcp terminate connection pdu
110  *
111  * @hdr:           pdu common header
112  * @fes:           fatal error status
113  * @fei:           fatal error information
114  */
115 struct nvme_tcp_term_pdu {
116 	struct nvme_tcp_hdr	hdr;
117 	__le16			fes;
118 	__le16			feil;
119 	__le16			feiu;
120 	__u8			rsvd[10];
121 };
122 
123 /**
124  * struct nvme_tcp_cmd_pdu - nvme tcp command capsule pdu
125  *
126  * @hdr:           pdu common header
127  * @cmd:           nvme command
128  */
129 struct nvme_tcp_cmd_pdu {
130 	struct nvme_tcp_hdr	hdr;
131 	struct nvme_command	cmd;
132 };
133 
134 /**
135  * struct nvme_tcp_rsp_pdu - nvme tcp response capsule pdu
136  *
137  * @hdr:           pdu common header
138  * @hdr:           nvme-tcp generic header
139  * @cqe:           nvme completion queue entry
140  */
141 struct nvme_tcp_rsp_pdu {
142 	struct nvme_tcp_hdr	hdr;
143 	struct nvme_completion	cqe;
144 };
145 
146 /**
147  * struct nvme_tcp_r2t_pdu - nvme tcp ready-to-transfer pdu
148  *
149  * @hdr:           pdu common header
150  * @command_id:    nvme command identifier which this relates to
151  * @ttag:          transfer tag (controller generated)
152  * @r2t_offset:    offset from the start of the command data
153  * @r2t_length:    length the host is allowed to send
154  */
155 struct nvme_tcp_r2t_pdu {
156 	struct nvme_tcp_hdr	hdr;
157 	__u16			command_id;
158 	__u16			ttag;
159 	__le32			r2t_offset;
160 	__le32			r2t_length;
161 	__u8			rsvd[4];
162 };
163 
164 /**
165  * struct nvme_tcp_data_pdu - nvme tcp data pdu
166  *
167  * @hdr:           pdu common header
168  * @command_id:    nvme command identifier which this relates to
169  * @ttag:          transfer tag (controller generated)
170  * @data_offset:   offset from the start of the command data
171  * @data_length:   length of the data stream
172  */
173 struct nvme_tcp_data_pdu {
174 	struct nvme_tcp_hdr	hdr;
175 	__u16			command_id;
176 	__u16			ttag;
177 	__le32			data_offset;
178 	__le32			data_length;
179 	__u8			rsvd[4];
180 };
181 
182 union nvme_tcp_pdu {
183 	struct nvme_tcp_icreq_pdu	icreq;
184 	struct nvme_tcp_icresp_pdu	icresp;
185 	struct nvme_tcp_cmd_pdu		cmd;
186 	struct nvme_tcp_rsp_pdu		rsp;
187 	struct nvme_tcp_r2t_pdu		r2t;
188 	struct nvme_tcp_data_pdu	data;
189 };
190 
191 #endif /* _LINUX_NVME_TCP_H */
192