iscsi_tcp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. /* xmit state machine */
  25. #define XMSTATE_IDLE 0x0
  26. #define XMSTATE_CMD_HDR_INIT 0x1
  27. #define XMSTATE_CMD_HDR_XMIT 0x2
  28. #define XMSTATE_IMM_HDR 0x4
  29. #define XMSTATE_IMM_DATA 0x8
  30. #define XMSTATE_UNS_INIT 0x10
  31. #define XMSTATE_UNS_HDR 0x20
  32. #define XMSTATE_UNS_DATA 0x40
  33. #define XMSTATE_SOL_HDR 0x80
  34. #define XMSTATE_SOL_DATA 0x100
  35. #define XMSTATE_W_PAD 0x200
  36. #define XMSTATE_W_RESEND_PAD 0x400
  37. #define XMSTATE_W_RESEND_DATA_DIGEST 0x800
  38. #define XMSTATE_IMM_HDR_INIT 0x1000
  39. #define XMSTATE_SOL_HDR_INIT 0x2000
  40. #define ISCSI_SG_TABLESIZE SG_ALL
  41. #define ISCSI_TCP_MAX_CMD_LEN 16
  42. struct crypto_hash;
  43. struct socket;
  44. struct iscsi_tcp_conn;
  45. struct iscsi_chunk;
  46. typedef int iscsi_chunk_done_fn_t(struct iscsi_tcp_conn *,
  47. struct iscsi_chunk *);
  48. struct iscsi_chunk {
  49. unsigned char *data;
  50. unsigned int size;
  51. unsigned int copied;
  52. unsigned int total_size;
  53. unsigned int total_copied;
  54. struct hash_desc *hash;
  55. unsigned char recv_digest[ISCSI_DIGEST_SIZE];
  56. unsigned char digest[ISCSI_DIGEST_SIZE];
  57. unsigned int digest_len;
  58. struct scatterlist *sg;
  59. void *sg_mapped;
  60. unsigned int sg_offset;
  61. unsigned int sg_index;
  62. unsigned int sg_count;
  63. iscsi_chunk_done_fn_t *done;
  64. };
  65. /* Socket connection recieve helper */
  66. struct iscsi_tcp_recv {
  67. struct iscsi_hdr *hdr;
  68. struct iscsi_chunk chunk;
  69. /* Allocate buffer for BHS + AHS */
  70. uint32_t hdr_buf[64];
  71. /* copied and flipped values */
  72. int datalen;
  73. };
  74. /* Socket connection send helper */
  75. struct iscsi_tcp_send {
  76. struct iscsi_hdr *hdr;
  77. struct iscsi_chunk chunk;
  78. struct iscsi_chunk data_chunk;
  79. /* Allocate buffer for BHS + AHS */
  80. uint32_t hdr_buf[64];
  81. };
  82. struct iscsi_tcp_conn {
  83. struct iscsi_conn *iscsi_conn;
  84. struct socket *sock;
  85. int stop_stage; /* conn_stop() flag: *
  86. * stop to recover, *
  87. * stop to terminate */
  88. /* control data */
  89. struct iscsi_tcp_recv in; /* TCP receive context */
  90. struct iscsi_tcp_send out; /* TCP send context */
  91. /* old values for socket callbacks */
  92. void (*old_data_ready)(struct sock *, int);
  93. void (*old_state_change)(struct sock *);
  94. void (*old_write_space)(struct sock *);
  95. /* data and header digests */
  96. struct hash_desc tx_hash; /* CRC32C (Tx) */
  97. struct hash_desc rx_hash; /* CRC32C (Rx) */
  98. /* MIB custom statistics */
  99. uint32_t sendpage_failures_cnt;
  100. uint32_t discontiguous_hdr_cnt;
  101. ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
  102. };
  103. struct iscsi_buf {
  104. struct scatterlist sg;
  105. unsigned int sent;
  106. char use_sendmsg;
  107. };
  108. struct iscsi_data_task {
  109. struct iscsi_data hdr; /* PDU */
  110. char hdrext[ISCSI_DIGEST_SIZE];/* Header-Digest */
  111. struct iscsi_buf digestbuf; /* digest buffer */
  112. uint32_t digest; /* data digest */
  113. };
  114. struct iscsi_tcp_mgmt_task {
  115. struct iscsi_hdr hdr;
  116. char hdrext[ISCSI_DIGEST_SIZE]; /* Header-Digest */
  117. int xmstate; /* mgmt xmit progress */
  118. struct iscsi_buf headbuf; /* header buffer */
  119. struct iscsi_buf sendbuf; /* in progress buffer */
  120. int sent;
  121. };
  122. struct iscsi_r2t_info {
  123. __be32 ttt; /* copied from R2T */
  124. __be32 exp_statsn; /* copied from R2T */
  125. uint32_t data_length; /* copied from R2T */
  126. uint32_t data_offset; /* copied from R2T */
  127. struct iscsi_buf headbuf; /* Data-Out Header Buffer */
  128. struct iscsi_buf sendbuf; /* Data-Out in progress buffer*/
  129. int sent; /* R2T sequence progress */
  130. int data_count; /* DATA-Out payload progress */
  131. struct scatterlist *sg; /* per-R2T SG list */
  132. int solicit_datasn;
  133. struct iscsi_data_task dtask; /* which data task */
  134. };
  135. struct iscsi_tcp_cmd_task {
  136. struct iscsi_hdr_buff {
  137. struct iscsi_cmd cmd_hdr;
  138. char hdrextbuf[ISCSI_MAX_AHS_SIZE +
  139. ISCSI_DIGEST_SIZE];
  140. } hdr;
  141. char pad[ISCSI_PAD_LEN];
  142. int pad_count; /* padded bytes */
  143. struct iscsi_buf headbuf; /* header buf (xmit) */
  144. struct iscsi_buf sendbuf; /* in progress buffer*/
  145. int xmstate; /* xmit xtate machine */
  146. int sent;
  147. struct scatterlist *sg; /* per-cmd SG list */
  148. struct scatterlist *bad_sg; /* assert statement */
  149. int sg_count; /* SG's to process */
  150. uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
  151. int data_offset;
  152. struct iscsi_r2t_info *r2t; /* in progress R2T */
  153. struct iscsi_pool r2tpool;
  154. struct kfifo *r2tqueue;
  155. int digest_count;
  156. uint32_t immdigest; /* for imm data */
  157. struct iscsi_buf immbuf; /* for imm data digest */
  158. struct iscsi_data_task unsol_dtask; /* unsol data task */
  159. };
  160. #endif /* ISCSI_H */