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