iscsi_tcp.h 4.8 KB

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