1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * iSCSI over TCP/IP Data-Path lib
5 * Copyright (C) 2008 Mike Christie
6 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
7 * maintained by open-iscsi@googlegroups.com
9 * See the file COPYING included with this distribution for more details.
12 #ifndef LIBISCSI_TCP_H
13 #define LIBISCSI_TCP_H
15 #include <scsi/libiscsi.h>
17 struct iscsi_tcp_conn;
22 typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
23 struct iscsi_segment *);
25 struct iscsi_segment {
29 unsigned int total_size;
30 unsigned int total_copied;
32 struct ahash_request *hash;
33 unsigned char padbuf[ISCSI_PAD_LEN];
34 unsigned char recv_digest[ISCSI_DIGEST_SIZE];
35 unsigned char digest[ISCSI_DIGEST_SIZE];
36 unsigned int digest_len;
38 struct scatterlist *sg;
40 unsigned int sg_offset;
43 iscsi_segment_done_fn_t *done;
46 /* Socket connection receive helper */
47 struct iscsi_tcp_recv {
48 struct iscsi_hdr *hdr;
49 struct iscsi_segment segment;
51 /* Allocate buffer for BHS + AHS */
54 /* copied and flipped values */
58 struct iscsi_tcp_conn {
59 struct iscsi_conn *iscsi_conn;
61 int stop_stage; /* conn_stop() flag: *
63 * stop to terminate */
65 struct iscsi_tcp_recv in; /* TCP receive context */
66 /* CRC32C (Rx) LLD should set this is they do not offload */
67 struct ahash_request *rx_hash;
70 struct iscsi_tcp_task {
71 uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
73 struct iscsi_r2t_info *r2t; /* in progress solict R2T */
74 struct iscsi_pool r2tpool;
75 struct kfifo r2tqueue;
77 spinlock_t pool2queue;
78 spinlock_t queue2pool;
82 ISCSI_TCP_SEGMENT_DONE, /* curr seg has been processed */
83 ISCSI_TCP_SKB_DONE, /* skb is out of data */
84 ISCSI_TCP_CONN_ERR, /* iscsi layer has fired a conn err */
85 ISCSI_TCP_SUSPENDED, /* conn is suspended */
88 extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
89 extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
90 unsigned int offset, bool offloaded, int *status);
91 extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
92 extern int iscsi_tcp_task_init(struct iscsi_task *task);
93 extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
96 extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
97 extern int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
98 struct iscsi_segment *segment, int recv,
100 extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
102 extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
103 void *data, size_t size,
104 iscsi_segment_done_fn_t *done,
105 struct ahash_request *hash);
107 iscsi_segment_seek_sg(struct iscsi_segment *segment,
108 struct scatterlist *sg_list, unsigned int sg_count,
109 unsigned int offset, size_t size,
110 iscsi_segment_done_fn_t *done,
111 struct ahash_request *hash);
114 extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr,
116 unsigned char digest[ISCSI_DIGEST_SIZE]);
117 extern struct iscsi_cls_conn *
118 iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
120 extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
123 extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
124 extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
125 extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf);
126 extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
127 struct iscsi_stats *stats);
128 #endif /* LIBISCSI_TCP_H */