libiscsi_tcp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * iSCSI over TCP/IP Data-Path lib
  3. *
  4. * Copyright (C) 2008 Mike Christie
  5. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  6. * maintained by open-iscsi@googlegroups.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * See the file COPYING included with this distribution for more details.
  19. */
  20. #ifndef LIBISCSI_TCP_H
  21. #define LIBISCSI_TCP_H
  22. #include <scsi/libiscsi.h>
  23. struct iscsi_tcp_conn;
  24. struct iscsi_segment;
  25. struct sk_buff;
  26. struct ahash_request;
  27. typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
  28. struct iscsi_segment *);
  29. struct iscsi_segment {
  30. unsigned char *data;
  31. unsigned int size;
  32. unsigned int copied;
  33. unsigned int total_size;
  34. unsigned int total_copied;
  35. struct ahash_request *hash;
  36. unsigned char padbuf[ISCSI_PAD_LEN];
  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. bool atomic_mapped;
  44. iscsi_segment_done_fn_t *done;
  45. };
  46. /* Socket connection receive helper */
  47. struct iscsi_tcp_recv {
  48. struct iscsi_hdr *hdr;
  49. struct iscsi_segment segment;
  50. /* Allocate buffer for BHS + AHS */
  51. uint32_t hdr_buf[64];
  52. /* copied and flipped values */
  53. int datalen;
  54. };
  55. struct iscsi_tcp_conn {
  56. struct iscsi_conn *iscsi_conn;
  57. void *dd_data;
  58. int stop_stage; /* conn_stop() flag: *
  59. * stop to recover, *
  60. * stop to terminate */
  61. /* control data */
  62. struct iscsi_tcp_recv in; /* TCP receive context */
  63. /* CRC32C (Rx) LLD should set this is they do not offload */
  64. struct ahash_request *rx_hash;
  65. };
  66. struct iscsi_tcp_task {
  67. uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
  68. int data_offset;
  69. struct iscsi_r2t_info *r2t; /* in progress solict R2T */
  70. struct iscsi_pool r2tpool;
  71. struct kfifo r2tqueue;
  72. void *dd_data;
  73. spinlock_t pool2queue;
  74. spinlock_t queue2pool;
  75. };
  76. enum {
  77. ISCSI_TCP_SEGMENT_DONE, /* curr seg has been processed */
  78. ISCSI_TCP_SKB_DONE, /* skb is out of data */
  79. ISCSI_TCP_CONN_ERR, /* iscsi layer has fired a conn err */
  80. ISCSI_TCP_SUSPENDED, /* conn is suspended */
  81. };
  82. extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
  83. extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
  84. unsigned int offset, bool offloaded, int *status);
  85. extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
  86. extern int iscsi_tcp_task_init(struct iscsi_task *task);
  87. extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
  88. /* segment helpers */
  89. extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
  90. extern int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
  91. struct iscsi_segment *segment, int recv,
  92. unsigned copied);
  93. extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
  94. extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
  95. void *data, size_t size,
  96. iscsi_segment_done_fn_t *done,
  97. struct ahash_request *hash);
  98. extern int
  99. iscsi_segment_seek_sg(struct iscsi_segment *segment,
  100. struct scatterlist *sg_list, unsigned int sg_count,
  101. unsigned int offset, size_t size,
  102. iscsi_segment_done_fn_t *done,
  103. struct ahash_request *hash);
  104. /* digest helpers */
  105. extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr,
  106. size_t hdrlen,
  107. unsigned char digest[ISCSI_DIGEST_SIZE]);
  108. extern struct iscsi_cls_conn *
  109. iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
  110. uint32_t conn_idx);
  111. extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
  112. /* misc helpers */
  113. extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
  114. extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
  115. extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf);
  116. extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  117. struct iscsi_stats *stats);
  118. #endif /* LIBISCSI_TCP_H */