iscsi_tcp.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. struct crypto_hash;
  25. struct socket;
  26. struct iscsi_tcp_conn;
  27. struct iscsi_segment;
  28. typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
  29. struct iscsi_segment *);
  30. struct iscsi_segment {
  31. unsigned char *data;
  32. unsigned int size;
  33. unsigned int copied;
  34. unsigned int total_size;
  35. unsigned int total_copied;
  36. struct hash_desc *hash;
  37. unsigned char recv_digest[ISCSI_DIGEST_SIZE];
  38. unsigned char digest[ISCSI_DIGEST_SIZE];
  39. unsigned int digest_len;
  40. struct scatterlist *sg;
  41. void *sg_mapped;
  42. unsigned int sg_offset;
  43. iscsi_segment_done_fn_t *done;
  44. };
  45. /* Socket connection recieve helper */
  46. struct iscsi_tcp_recv {
  47. struct iscsi_hdr *hdr;
  48. struct iscsi_segment segment;
  49. /* Allocate buffer for BHS + AHS */
  50. uint32_t hdr_buf[64];
  51. /* copied and flipped values */
  52. int datalen;
  53. };
  54. /* Socket connection send helper */
  55. struct iscsi_tcp_send {
  56. struct iscsi_hdr *hdr;
  57. struct iscsi_segment segment;
  58. struct iscsi_segment data_segment;
  59. };
  60. struct iscsi_tcp_conn {
  61. struct iscsi_conn *iscsi_conn;
  62. struct socket *sock;
  63. int stop_stage; /* conn_stop() flag: *
  64. * stop to recover, *
  65. * stop to terminate */
  66. /* control data */
  67. struct iscsi_tcp_recv in; /* TCP receive context */
  68. struct iscsi_tcp_send out; /* TCP send context */
  69. /* old values for socket callbacks */
  70. void (*old_data_ready)(struct sock *, int);
  71. void (*old_state_change)(struct sock *);
  72. void (*old_write_space)(struct sock *);
  73. /* data and header digests */
  74. struct hash_desc tx_hash; /* CRC32C (Tx) */
  75. struct hash_desc rx_hash; /* CRC32C (Rx) */
  76. /* MIB custom statistics */
  77. uint32_t sendpage_failures_cnt;
  78. uint32_t discontiguous_hdr_cnt;
  79. int error;
  80. ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
  81. };
  82. struct iscsi_data_task {
  83. struct iscsi_data hdr; /* PDU */
  84. char hdrext[ISCSI_DIGEST_SIZE];/* Header-Digest */
  85. };
  86. struct iscsi_r2t_info {
  87. __be32 ttt; /* copied from R2T */
  88. __be32 exp_statsn; /* copied from R2T */
  89. uint32_t data_length; /* copied from R2T */
  90. uint32_t data_offset; /* copied from R2T */
  91. int sent; /* R2T sequence progress */
  92. int data_count; /* DATA-Out payload progress */
  93. int solicit_datasn;
  94. struct iscsi_data_task dtask; /* Data-Out header buf */
  95. };
  96. struct iscsi_tcp_task {
  97. struct iscsi_hdr_buff {
  98. struct iscsi_cmd cmd_hdr;
  99. char hdrextbuf[ISCSI_MAX_AHS_SIZE +
  100. ISCSI_DIGEST_SIZE];
  101. } hdr;
  102. int sent;
  103. uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
  104. int data_offset;
  105. struct iscsi_r2t_info *r2t; /* in progress R2T */
  106. struct iscsi_pool r2tpool;
  107. struct kfifo *r2tqueue;
  108. struct iscsi_data_task unsol_dtask; /* Data-Out header buf */
  109. };
  110. #endif /* ISCSI_H */