iscsi_tcp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #define IN_PROGRESS_PAD_RECV 0x4
  30. /* xmit state machine */
  31. #define XMSTATE_IDLE 0x0
  32. #define XMSTATE_CMD_HDR_INIT 0x1
  33. #define XMSTATE_CMD_HDR_XMIT 0x2
  34. #define XMSTATE_IMM_HDR 0x4
  35. #define XMSTATE_IMM_DATA 0x8
  36. #define XMSTATE_UNS_INIT 0x10
  37. #define XMSTATE_UNS_HDR 0x20
  38. #define XMSTATE_UNS_DATA 0x40
  39. #define XMSTATE_SOL_HDR 0x80
  40. #define XMSTATE_SOL_DATA 0x100
  41. #define XMSTATE_W_PAD 0x200
  42. #define XMSTATE_W_RESEND_PAD 0x400
  43. #define XMSTATE_W_RESEND_DATA_DIGEST 0x800
  44. #define XMSTATE_IMM_HDR_INIT 0x1000
  45. #define XMSTATE_SOL_HDR_INIT 0x2000
  46. #define ISCSI_PAD_LEN 4
  47. #define ISCSI_SG_TABLESIZE SG_ALL
  48. #define ISCSI_TCP_MAX_CMD_LEN 16
  49. struct crypto_hash;
  50. struct socket;
  51. /* Socket connection recieve helper */
  52. struct iscsi_tcp_recv {
  53. struct iscsi_hdr *hdr;
  54. struct sk_buff *skb;
  55. int offset;
  56. int len;
  57. int hdr_offset;
  58. int copy;
  59. int copied;
  60. int padding;
  61. struct iscsi_cmd_task *ctask; /* current cmd in progress */
  62. /* copied and flipped values */
  63. int datalen;
  64. int datadgst;
  65. char zero_copy_hdr;
  66. };
  67. struct iscsi_tcp_conn {
  68. struct iscsi_conn *iscsi_conn;
  69. struct socket *sock;
  70. struct iscsi_hdr hdr; /* header placeholder */
  71. char hdrext[4*sizeof(__u16) +
  72. sizeof(__u32)];
  73. int data_copied;
  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. /* control data */
  80. struct iscsi_tcp_recv in; /* TCP receive context */
  81. int in_progress; /* connection state machine */
  82. /* old values for socket callbacks */
  83. void (*old_data_ready)(struct sock *, int);
  84. void (*old_state_change)(struct sock *);
  85. void (*old_write_space)(struct sock *);
  86. /* data and header digests */
  87. struct hash_desc tx_hash; /* CRC32C (Tx) */
  88. struct hash_desc rx_hash; /* CRC32C (Rx) */
  89. /* MIB custom statistics */
  90. uint32_t sendpage_failures_cnt;
  91. uint32_t discontiguous_hdr_cnt;
  92. ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
  93. };
  94. struct iscsi_buf {
  95. struct scatterlist sg;
  96. unsigned int sent;
  97. char use_sendmsg;
  98. };
  99. struct iscsi_data_task {
  100. struct iscsi_data hdr; /* PDU */
  101. char hdrext[sizeof(__u32)]; /* Header-Digest */
  102. struct iscsi_buf digestbuf; /* digest buffer */
  103. uint32_t digest; /* data digest */
  104. };
  105. struct iscsi_tcp_mgmt_task {
  106. struct iscsi_hdr hdr;
  107. char hdrext[sizeof(__u32)]; /* Header-Digest */
  108. int xmstate; /* mgmt xmit progress */
  109. struct iscsi_buf headbuf; /* header buffer */
  110. struct iscsi_buf sendbuf; /* in progress buffer */
  111. int sent;
  112. };
  113. struct iscsi_r2t_info {
  114. __be32 ttt; /* copied from R2T */
  115. __be32 exp_statsn; /* copied from R2T */
  116. uint32_t data_length; /* copied from R2T */
  117. uint32_t data_offset; /* copied from R2T */
  118. struct iscsi_buf headbuf; /* Data-Out Header Buffer */
  119. struct iscsi_buf sendbuf; /* Data-Out in progress buffer*/
  120. int sent; /* R2T sequence progress */
  121. int data_count; /* DATA-Out payload progress */
  122. struct scatterlist *sg; /* per-R2T SG list */
  123. int solicit_datasn;
  124. struct iscsi_data_task dtask; /* which data task */
  125. };
  126. struct iscsi_tcp_cmd_task {
  127. struct iscsi_cmd hdr;
  128. char hdrext[4*sizeof(__u16)+ /* AHS */
  129. sizeof(__u32)]; /* HeaderDigest */
  130. char pad[ISCSI_PAD_LEN];
  131. int pad_count; /* padded bytes */
  132. struct iscsi_buf headbuf; /* header buf (xmit) */
  133. struct iscsi_buf sendbuf; /* in progress buffer*/
  134. int xmstate; /* xmit xtate machine */
  135. int sent;
  136. struct scatterlist *sg; /* per-cmd SG list */
  137. struct scatterlist *bad_sg; /* assert statement */
  138. int sg_count; /* SG's to process */
  139. uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
  140. int data_offset;
  141. struct iscsi_r2t_info *r2t; /* in progress R2T */
  142. struct iscsi_queue r2tpool;
  143. struct kfifo *r2tqueue;
  144. struct iscsi_r2t_info **r2ts;
  145. int digest_count;
  146. uint32_t immdigest; /* for imm data */
  147. struct iscsi_buf immbuf; /* for imm data digest */
  148. struct iscsi_data_task unsol_dtask; /* unsol data task */
  149. };
  150. #endif /* ISCSI_H */