iscsi_tcp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * iSCSI Initiator TCP Transport
  3. * Copyright (C) 2004 Dmitry Yusupov
  4. * Copyright (C) 2004 Alex Aizman
  5. * Copyright (C) 2005 - 2006 Mike Christie
  6. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  7. * maintained by open-iscsi@googlegroups.com
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published
  11. * by the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * See the file COPYING included with this distribution for more details.
  20. */
  21. #ifndef ISCSI_TCP_H
  22. #define ISCSI_TCP_H
  23. #include <scsi/libiscsi.h>
  24. /* Socket's Receive state machine */
  25. #define IN_PROGRESS_WAIT_HEADER 0x0
  26. #define IN_PROGRESS_HEADER_GATHER 0x1
  27. #define IN_PROGRESS_DATA_RECV 0x2
  28. #define IN_PROGRESS_DDIGEST_RECV 0x3
  29. /* xmit state machine */
  30. #define XMSTATE_IDLE 0x0
  31. #define XMSTATE_R_HDR 0x1
  32. #define XMSTATE_W_HDR 0x2
  33. #define XMSTATE_IMM_HDR 0x4
  34. #define XMSTATE_IMM_DATA 0x8
  35. #define XMSTATE_UNS_INIT 0x10
  36. #define XMSTATE_UNS_HDR 0x20
  37. #define XMSTATE_UNS_DATA 0x40
  38. #define XMSTATE_SOL_HDR 0x80
  39. #define XMSTATE_SOL_DATA 0x100
  40. #define XMSTATE_W_PAD 0x200
  41. #define XMSTATE_DATA_DIGEST 0x400
  42. #define ISCSI_CONN_RCVBUF_MIN 262144
  43. #define ISCSI_CONN_SNDBUF_MIN 262144
  44. #define ISCSI_PAD_LEN 4
  45. #define ISCSI_R2T_MAX 16
  46. #define ISCSI_SG_TABLESIZE SG_ALL
  47. #define ISCSI_TCP_MAX_CMD_LEN 16
  48. struct socket;
  49. /* Socket connection recieve helper */
  50. struct iscsi_tcp_recv {
  51. struct iscsi_hdr *hdr;
  52. struct sk_buff *skb;
  53. int offset;
  54. int len;
  55. int hdr_offset;
  56. int copy;
  57. int copied;
  58. int padding;
  59. struct iscsi_cmd_task *ctask; /* current cmd in progress */
  60. /* copied and flipped values */
  61. int datalen;
  62. int datadgst;
  63. char zero_copy_hdr;
  64. };
  65. struct iscsi_tcp_conn {
  66. struct iscsi_conn *iscsi_conn;
  67. struct socket *sock;
  68. struct iscsi_hdr hdr; /* header placeholder */
  69. char hdrext[4*sizeof(__u16) +
  70. sizeof(__u32)];
  71. int data_copied;
  72. char *data; /* data placeholder */
  73. int data_size; /* actual recv_dlength */
  74. int stop_stage; /* conn_stop() flag: *
  75. * stop to recover, *
  76. * stop to terminate */
  77. /* iSCSI connection-wide sequencing */
  78. int hdr_size; /* PDU header size */
  79. struct crypto_tfm *rx_tfm; /* CRC32C (Rx) */
  80. struct crypto_tfm *data_rx_tfm; /* CRC32C (Rx) for data */
  81. /* control data */
  82. struct iscsi_tcp_recv in; /* TCP receive context */
  83. int in_progress; /* connection state machine */
  84. /* old values for socket callbacks */
  85. void (*old_data_ready)(struct sock *, int);
  86. void (*old_state_change)(struct sock *);
  87. void (*old_write_space)(struct sock *);
  88. /* xmit */
  89. struct crypto_tfm *tx_tfm; /* CRC32C (Tx) */
  90. struct crypto_tfm *data_tx_tfm; /* CRC32C (Tx) for data */
  91. /* MIB custom statistics */
  92. uint32_t sendpage_failures_cnt;
  93. uint32_t discontiguous_hdr_cnt;
  94. ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
  95. };
  96. struct iscsi_buf {
  97. struct scatterlist sg;
  98. unsigned int sent;
  99. char use_sendmsg;
  100. };
  101. struct iscsi_data_task {
  102. struct iscsi_data hdr; /* PDU */
  103. char hdrext[sizeof(__u32)]; /* Header-Digest */
  104. struct iscsi_buf digestbuf; /* digest buffer */
  105. uint32_t digest; /* data digest */
  106. };
  107. struct iscsi_tcp_mgmt_task {
  108. struct iscsi_hdr hdr;
  109. char hdrext[sizeof(__u32)]; /* Header-Digest */
  110. int xmstate; /* mgmt xmit progress */
  111. struct iscsi_buf headbuf; /* header buffer */
  112. struct iscsi_buf sendbuf; /* in progress buffer */
  113. int sent;
  114. };
  115. struct iscsi_r2t_info {
  116. __be32 ttt; /* copied from R2T */
  117. __be32 exp_statsn; /* copied from R2T */
  118. uint32_t data_length; /* copied from R2T */
  119. uint32_t data_offset; /* copied from R2T */
  120. struct iscsi_buf headbuf; /* Data-Out Header Buffer */
  121. struct iscsi_buf sendbuf; /* Data-Out in progress buffer*/
  122. int sent; /* R2T sequence progress */
  123. int data_count; /* DATA-Out payload progress */
  124. struct scatterlist *sg; /* per-R2T SG list */
  125. int solicit_datasn;
  126. struct iscsi_data_task dtask; /* which data task */
  127. };
  128. struct iscsi_tcp_cmd_task {
  129. struct iscsi_cmd hdr;
  130. char hdrext[4*sizeof(__u16)+ /* AHS */
  131. sizeof(__u32)]; /* HeaderDigest */
  132. char pad[ISCSI_PAD_LEN];
  133. int pad_count; /* padded bytes */
  134. struct iscsi_buf headbuf; /* header buf (xmit) */
  135. struct iscsi_buf sendbuf; /* in progress buffer*/
  136. int xmstate; /* xmit xtate machine */
  137. int sent;
  138. struct scatterlist *sg; /* per-cmd SG list */
  139. struct scatterlist *bad_sg; /* assert statement */
  140. int sg_count; /* SG's to process */
  141. uint32_t exp_r2tsn;
  142. int r2t_data_count; /* R2T Data-Out bytes */
  143. int data_offset;
  144. struct iscsi_r2t_info *r2t; /* in progress R2T */
  145. struct iscsi_queue r2tpool;
  146. struct kfifo *r2tqueue;
  147. struct iscsi_r2t_info **r2ts;
  148. uint32_t datadigest; /* for recover digest */
  149. int digest_count;
  150. uint32_t immdigest; /* for imm data */
  151. struct iscsi_buf immbuf; /* for imm data digest */
  152. struct iscsi_data_task *dtask; /* data task in progress*/
  153. struct iscsi_data_task unsol_dtask; /* unsol data task */
  154. int digest_offset; /* for partial buff digest */
  155. };
  156. #endif /* ISCSI_H */