libiscsi_tcp.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * iSCSI over TCP/IP Data-Path lib
  4. *
  5. * Copyright (C) 2008 Mike Christie
  6. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  7. * maintained by open-iscsi@googlegroups.com
  8. */
  9. #ifndef LIBISCSI_TCP_H
  10. #define LIBISCSI_TCP_H
  11. #include <scsi/libiscsi.h>
  12. struct iscsi_tcp_conn;
  13. struct iscsi_segment;
  14. struct sk_buff;
  15. struct ahash_request;
  16. typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
  17. struct iscsi_segment *);
  18. struct iscsi_segment {
  19. unsigned char *data;
  20. unsigned int size;
  21. unsigned int copied;
  22. unsigned int total_size;
  23. unsigned int total_copied;
  24. struct ahash_request *hash;
  25. unsigned char padbuf[ISCSI_PAD_LEN];
  26. unsigned char recv_digest[ISCSI_DIGEST_SIZE];
  27. unsigned char digest[ISCSI_DIGEST_SIZE];
  28. unsigned int digest_len;
  29. struct scatterlist *sg;
  30. void *sg_mapped;
  31. unsigned int sg_offset;
  32. bool atomic_mapped;
  33. iscsi_segment_done_fn_t *done;
  34. };
  35. /* Socket connection receive helper */
  36. struct iscsi_tcp_recv {
  37. struct iscsi_hdr *hdr;
  38. struct iscsi_segment segment;
  39. /* Allocate buffer for BHS + AHS */
  40. uint32_t hdr_buf[64];
  41. /* copied and flipped values */
  42. int datalen;
  43. };
  44. struct iscsi_tcp_conn {
  45. struct iscsi_conn *iscsi_conn;
  46. void *dd_data;
  47. int stop_stage; /* conn_stop() flag: *
  48. * stop to recover, *
  49. * stop to terminate */
  50. /* control data */
  51. struct iscsi_tcp_recv in; /* TCP receive context */
  52. /* CRC32C (Rx) LLD should set this is they do not offload */
  53. struct ahash_request *rx_hash;
  54. };
  55. struct iscsi_tcp_task {
  56. uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
  57. int data_offset;
  58. struct iscsi_r2t_info *r2t; /* in progress solict R2T */
  59. struct iscsi_pool r2tpool;
  60. struct kfifo r2tqueue;
  61. void *dd_data;
  62. spinlock_t pool2queue;
  63. spinlock_t queue2pool;
  64. };
  65. enum {
  66. ISCSI_TCP_SEGMENT_DONE, /* curr seg has been processed */
  67. ISCSI_TCP_SKB_DONE, /* skb is out of data */
  68. ISCSI_TCP_CONN_ERR, /* iscsi layer has fired a conn err */
  69. ISCSI_TCP_SUSPENDED, /* conn is suspended */
  70. };
  71. extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
  72. extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
  73. unsigned int offset, bool offloaded, int *status);
  74. extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
  75. extern int iscsi_tcp_task_init(struct iscsi_task *task);
  76. extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
  77. /* segment helpers */
  78. extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
  79. extern int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
  80. struct iscsi_segment *segment, int recv,
  81. unsigned copied);
  82. extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
  83. extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
  84. void *data, size_t size,
  85. iscsi_segment_done_fn_t *done,
  86. struct ahash_request *hash);
  87. extern int
  88. iscsi_segment_seek_sg(struct iscsi_segment *segment,
  89. struct scatterlist *sg_list, unsigned int sg_count,
  90. unsigned int offset, size_t size,
  91. iscsi_segment_done_fn_t *done,
  92. struct ahash_request *hash);
  93. /* digest helpers */
  94. extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr,
  95. size_t hdrlen,
  96. unsigned char digest[ISCSI_DIGEST_SIZE]);
  97. extern struct iscsi_cls_conn *
  98. iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
  99. uint32_t conn_idx);
  100. extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
  101. /* misc helpers */
  102. extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
  103. extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
  104. extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf);
  105. extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  106. struct iscsi_stats *stats);
  107. #endif /* LIBISCSI_TCP_H */