iscsi_tcp.h 4.9 KB

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