[SCSI] libiscsi: allow drivers to modify the itt sent to the target
[safe/jmp/linux-2.6] / include / scsi / libiscsi_tcp.h
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
21 #ifndef LIBISCSI_TCP_H
22 #define LIBISCSI_TCP_H
23
24 #include <scsi/libiscsi.h>
25
26 struct iscsi_tcp_conn;
27 struct iscsi_segment;
28 struct sk_buff;
29 struct hash_desc;
30
31 typedef int iscsi_segment_done_fn_t(struct iscsi_tcp_conn *,
32                                     struct iscsi_segment *);
33
34 struct iscsi_segment {
35         unsigned char           *data;
36         unsigned int            size;
37         unsigned int            copied;
38         unsigned int            total_size;
39         unsigned int            total_copied;
40
41         struct hash_desc        *hash;
42         unsigned char           recv_digest[ISCSI_DIGEST_SIZE];
43         unsigned char           digest[ISCSI_DIGEST_SIZE];
44         unsigned int            digest_len;
45
46         struct scatterlist      *sg;
47         void                    *sg_mapped;
48         unsigned int            sg_offset;
49
50         iscsi_segment_done_fn_t *done;
51 };
52
53 /* Socket connection recieve helper */
54 struct iscsi_tcp_recv {
55         struct iscsi_hdr        *hdr;
56         struct iscsi_segment    segment;
57
58         /* Allocate buffer for BHS + AHS */
59         uint32_t                hdr_buf[64];
60
61         /* copied and flipped values */
62         int                     datalen;
63 };
64
65 struct iscsi_tcp_conn {
66         struct iscsi_conn       *iscsi_conn;
67         void                    *dd_data;
68         int                     stop_stage;     /* conn_stop() flag: *
69                                                  * stop to recover,  *
70                                                  * stop to terminate */
71         /* control data */
72         struct iscsi_tcp_recv   in;             /* TCP receive context */
73         /* CRC32C (Rx) LLD should set this is they do not offload */
74         struct hash_desc        *rx_hash;
75 };
76
77 struct iscsi_tcp_task {
78         uint32_t                exp_datasn;     /* expected target's R2TSN/DataSN */
79         int                     data_offset;
80         struct iscsi_r2t_info   *r2t;           /* in progress solict R2T */
81         struct iscsi_pool       r2tpool;
82         struct kfifo            *r2tqueue;
83         void                    *dd_data;
84 };
85
86 enum {
87         ISCSI_TCP_SEGMENT_DONE,         /* curr seg has been processed */
88         ISCSI_TCP_SKB_DONE,             /* skb is out of data */
89         ISCSI_TCP_CONN_ERR,             /* iscsi layer has fired a conn err */
90         ISCSI_TCP_SUSPENDED,            /* conn is suspended */
91 };
92
93 extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
94 extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
95                               unsigned int offset, bool offloaded, int *status);
96 extern void iscsi_tcp_cleanup_task(struct iscsi_task *task);
97 extern int iscsi_tcp_task_init(struct iscsi_task *task);
98 extern int iscsi_tcp_task_xmit(struct iscsi_task *task);
99
100 /* segment helpers */
101 extern int iscsi_tcp_recv_segment_is_hdr(struct iscsi_tcp_conn *tcp_conn);
102 extern int iscsi_tcp_segment_done(struct iscsi_segment *segment, int recv,
103                                   unsigned copied);
104 extern void iscsi_tcp_segment_unmap(struct iscsi_segment *segment);
105
106 extern void iscsi_segment_init_linear(struct iscsi_segment *segment,
107                                       void *data, size_t size,
108                                       iscsi_segment_done_fn_t *done,
109                                       struct hash_desc *hash);
110 extern int
111 iscsi_segment_seek_sg(struct iscsi_segment *segment,
112                       struct scatterlist *sg_list, unsigned int sg_count,
113                       unsigned int offset, size_t size,
114                       iscsi_segment_done_fn_t *done, struct hash_desc *hash);
115
116 /* digest helpers */
117 extern void iscsi_tcp_dgst_header(struct hash_desc *hash, const void *hdr,
118                                   size_t hdrlen,
119                                   unsigned char digest[ISCSI_DIGEST_SIZE]);
120 extern struct iscsi_cls_conn *
121 iscsi_tcp_conn_setup(struct iscsi_cls_session *cls_session, int dd_data_size,
122                      uint32_t conn_idx);
123 extern void iscsi_tcp_conn_teardown(struct iscsi_cls_conn *cls_conn);
124
125 /* misc helpers */
126 extern int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session);
127 extern void iscsi_tcp_r2tpool_free(struct iscsi_session *session);
128
129 extern void iscsi_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn,
130                                      struct iscsi_stats *stats);
131 #endif /* LIBISCSI_TCP_H */