iscsi_tcp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 crypto_hash;
  49. struct socket;
  50. /* Socket connection recieve helper */
  51. struct iscsi_tcp_recv {
  52. struct iscsi_hdr *hdr;
  53. struct sk_buff *skb;
  54. int offset;
  55. int len;
  56. int hdr_offset;
  57. int copy;
  58. int copied;
  59. int padding;
  60. struct iscsi_cmd_task *ctask; /* current cmd in progress */
  61. /* copied and flipped values */
  62. int datalen;
  63. int datadgst;
  64. char zero_copy_hdr;
  65. };
  66. struct iscsi_tcp_conn {
  67. struct iscsi_conn *iscsi_conn;
  68. struct socket *sock;
  69. struct iscsi_hdr hdr; /* header placeholder */
  70. char hdrext[4*sizeof(__u16) +
  71. sizeof(__u32)];
  72. int data_copied;
  73. int stop_stage; /* conn_stop() flag: *
  74. * stop to recover, *
  75. * stop to terminate */
  76. /* iSCSI connection-wide sequencing */
  77. int hdr_size; /* PDU header size */
  78. struct crypto_hash *rx_tfm; /* CRC32C (Rx) */
  79. struct hash_desc data_rx_hash; /* CRC32C (Rx) for data */
  80. /* control data */
  81. struct iscsi_tcp_recv in; /* TCP receive context */
  82. int in_progress; /* connection state machine */
  83. /* old values for socket callbacks */
  84. void (*old_data_ready)(struct sock *, int);
  85. void (*old_state_change)(struct sock *);
  86. void (*old_write_space)(struct sock *);
  87. /* xmit */
  88. struct crypto_hash *tx_tfm; /* CRC32C (Tx) */
  89. struct hash_desc data_tx_hash; /* CRC32C (Tx) for data */
  90. /* MIB custom statistics */
  91. uint32_t sendpage_failures_cnt;
  92. uint32_t discontiguous_hdr_cnt;
  93. ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
  94. };
  95. struct iscsi_buf {
  96. struct scatterlist sg;
  97. unsigned int sent;
  98. char use_sendmsg;
  99. };
  100. struct iscsi_data_task {
  101. struct iscsi_data hdr; /* PDU */
  102. char hdrext[sizeof(__u32)]; /* Header-Digest */
  103. struct iscsi_buf digestbuf; /* digest buffer */
  104. uint32_t digest; /* data digest */
  105. };
  106. struct iscsi_tcp_mgmt_task {
  107. struct iscsi_hdr hdr;
  108. char hdrext[sizeof(__u32)]; /* Header-Digest */
  109. int xmstate; /* mgmt xmit progress */
  110. struct iscsi_buf headbuf; /* header buffer */
  111. struct iscsi_buf sendbuf; /* in progress buffer */
  112. int sent;
  113. };
  114. struct iscsi_r2t_info {
  115. __be32 ttt; /* copied from R2T */
  116. __be32 exp_statsn; /* copied from R2T */
  117. uint32_t data_length; /* copied from R2T */
  118. uint32_t data_offset; /* copied from R2T */
  119. struct iscsi_buf headbuf; /* Data-Out Header Buffer */
  120. struct iscsi_buf sendbuf; /* Data-Out in progress buffer*/
  121. int sent; /* R2T sequence progress */
  122. int data_count; /* DATA-Out payload progress */
  123. struct scatterlist *sg; /* per-R2T SG list */
  124. int solicit_datasn;
  125. struct iscsi_data_task dtask; /* which data task */
  126. };
  127. struct iscsi_tcp_cmd_task {
  128. struct iscsi_cmd hdr;
  129. char hdrext[4*sizeof(__u16)+ /* AHS */
  130. sizeof(__u32)]; /* HeaderDigest */
  131. char pad[ISCSI_PAD_LEN];
  132. int pad_count; /* padded bytes */
  133. struct iscsi_buf headbuf; /* header buf (xmit) */
  134. struct iscsi_buf sendbuf; /* in progress buffer*/
  135. int xmstate; /* xmit xtate machine */
  136. int sent;
  137. struct scatterlist *sg; /* per-cmd SG list */
  138. struct scatterlist *bad_sg; /* assert statement */
  139. int sg_count; /* SG's to process */
  140. uint32_t exp_r2tsn;
  141. int r2t_data_count; /* R2T Data-Out bytes */
  142. int data_offset;
  143. struct iscsi_r2t_info *r2t; /* in progress R2T */
  144. struct iscsi_queue r2tpool;
  145. struct kfifo *r2tqueue;
  146. struct iscsi_r2t_info **r2ts;
  147. uint32_t datadigest; /* for recover digest */
  148. int digest_count;
  149. uint32_t immdigest; /* for imm data */
  150. struct iscsi_buf immbuf; /* for imm data digest */
  151. struct iscsi_data_task *dtask; /* data task in progress*/
  152. struct iscsi_data_task unsol_dtask; /* unsol data task */
  153. int digest_offset; /* for partial buff digest */
  154. };
  155. #endif /* ISCSI_H */