nvme-tcp.h 4.5 KB

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