Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
10#ifndef LIBISCSI_TCP_H
11#define LIBISCSI_TCP_H
12
13#include <scsi/libiscsi.h>
14
15struct iscsi_tcp_conn;
16struct iscsi_segment;
17struct sk_buff;
18
19typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
20 struct iscsi_segment *);
21
22struct iscsi_segment {
23 unsigned char *data;
24 unsigned int size;
25 unsigned int copied;
26 unsigned int total_size;
27 unsigned int total_copied;
28
29 u32 *crcp;
30 unsigned char padbuf[ISCSI_PAD_LEN];
31 unsigned char recv_digest[ISCSI_DIGEST_SIZE];
32 unsigned char digest[ISCSI_DIGEST_SIZE];
33 unsigned int digest_len;
34
35 struct scatterlist *sg;
36 void *sg_mapped;
37 unsigned int sg_offset;
38 bool atomic_mapped;
39
40 iscsi_segment_done_fn_t *done;
41};
42
43/* Socket connection receive helper */
44struct iscsi_tcp_recv {
45 struct iscsi_hdr *hdr;
46 struct iscsi_segment segment;
47
48 /* Allocate buffer for BHS + AHS */
49 uint32_t hdr_buf[64];
50
51 /* copied and flipped values */
52 int datalen;
53};
54
55struct 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 if they do not offload */
64 u32 *rx_crcp;
65};
66
67struct iscsi_tcp_task {
68 uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
69 int data_offset;
70 struct iscsi_r2t_info *r2t; /* in progress solict R2T */
71 struct iscsi_pool r2tpool;
72 struct kfifo r2tqueue;
73 void *dd_data;
74 spinlock_t pool2queue;
75 spinlock_t queue2pool;
76};
77
78enum {
79 ISCSI_TCP_SEGMENT_DONE, /* curr seg has been processed */
80 ISCSI_TCP_SKB_DONE, /* skb is out of data */
81 ISCSI_TCP_CONN_ERR, /* iscsi layer has fired a conn err */
82 ISCSI_TCP_SUSPENDED, /* conn is suspended */
83};
84
85extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
86extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
87 unsigned int offset, bool offloaded, int *status);
88extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
89extern int iscsi_tcp_task_init(struct iscsi_task *task);
90extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
91
92/* segment helpers */
93extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
94extern int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
95 struct iscsi_segment *segment, int recv,
96 unsigned copied);
97extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
98
99extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
100 void *data, size_t size,
101 iscsi_segment_done_fn_t *done, u32 *crcp);
102extern int
103iscsi_segment_seek_sg(struct iscsi_segment *segment,
104 struct scatterlist *sg_list, unsigned int sg_count,
105 unsigned int offset, size_t size,
106 iscsi_segment_done_fn_t *done, u32 *crcp);
107
108/* digest helpers */
109extern void iscsi_tcp_dgst_header(const void *hdr, size_t hdrlen,
110 unsigned char digest[ISCSI_DIGEST_SIZE]);
111extern struct iscsi_cls_conn *
112iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
113 uint32_t conn_idx);
114extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
115
116/* misc helpers */
117extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
118extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
119extern int iscsi_tcp_set_max_r2t(struct iscsi_conn *conn, char *buf);
120extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
121 struct iscsi_stats *stats);
122#endif /* LIBISCSI_TCP_H */