blob: f1c541151100d015484c29daa316459e4dbec4a9 [file] [log] [blame]
Alex Aizmanc213ca02005-08-04 19:30:31 -07001/*
2 * iSCSI Initiator TCP Transport
3 * Copyright (C) 2004 Dmitry Yusupov
4 * Copyright (C) 2004 Alex Aizman
Mike Christie5bb0b552006-04-06 21:26:46 -05005 * Copyright (C) 2005 - 2006 Mike Christie
6 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
Alex Aizmanc213ca02005-08-04 19:30:31 -07007 * maintained by open-iscsi@googlegroups.com
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * See the file COPYING included with this distribution for more details.
20 */
21
22#ifndef ISCSI_TCP_H
23#define ISCSI_TCP_H
24
Mike Christie5bb0b552006-04-06 21:26:46 -050025#include <scsi/libiscsi.h>
Alex Aizmanc213ca02005-08-04 19:30:31 -070026
Alex Aizmanc213ca02005-08-04 19:30:31 -070027/* xmit state machine */
Mike Christie843c0a82007-12-13 12:43:20 -060028#define XMSTATE_IDLE 0x0
29#define XMSTATE_CMD_HDR_INIT 0x1
30#define XMSTATE_CMD_HDR_XMIT 0x2
31#define XMSTATE_IMM_HDR 0x4
32#define XMSTATE_IMM_DATA 0x8
33#define XMSTATE_UNS_INIT 0x10
34#define XMSTATE_UNS_HDR 0x20
35#define XMSTATE_UNS_DATA 0x40
36#define XMSTATE_SOL_HDR 0x80
37#define XMSTATE_SOL_DATA 0x100
38#define XMSTATE_W_PAD 0x200
39#define XMSTATE_W_RESEND_PAD 0x400
40#define XMSTATE_W_RESEND_DATA_DIGEST 0x800
41#define XMSTATE_IMM_HDR_INIT 0x1000
42#define XMSTATE_SOL_HDR_INIT 0x2000
Alex Aizmanc213ca02005-08-04 19:30:31 -070043
Alex Aizmanc213ca02005-08-04 19:30:31 -070044#define ISCSI_PAD_LEN 4
Alex Aizmanc213ca02005-08-04 19:30:31 -070045#define ISCSI_SG_TABLESIZE SG_ALL
Alex Aizmanc213ca02005-08-04 19:30:31 -070046#define ISCSI_TCP_MAX_CMD_LEN 16
47
Herbert Xudc64ddf2006-08-24 18:45:50 +100048struct crypto_hash;
Mike Christie5bb0b552006-04-06 21:26:46 -050049struct socket;
Olaf Kirchda32dd62007-12-13 12:43:21 -060050struct iscsi_tcp_conn;
51struct iscsi_chunk;
52
53typedef int iscsi_chunk_done_fn_t(struct iscsi_tcp_conn *,
54 struct iscsi_chunk *);
55
56struct iscsi_chunk {
57 unsigned char *data;
58 unsigned int size;
59 unsigned int copied;
60 unsigned int total_size;
61 unsigned int total_copied;
62
63 struct hash_desc *hash;
64 unsigned char recv_digest[ISCSI_DIGEST_SIZE];
65 unsigned char digest[ISCSI_DIGEST_SIZE];
66 unsigned int digest_len;
67
68 struct scatterlist *sg;
69 void *sg_mapped;
70 unsigned int sg_offset;
71 unsigned int sg_index;
72 unsigned int sg_count;
73
74 iscsi_chunk_done_fn_t *done;
75};
Alex Aizmanc213ca02005-08-04 19:30:31 -070076
77/* Socket connection recieve helper */
78struct iscsi_tcp_recv {
79 struct iscsi_hdr *hdr;
Olaf Kirchda32dd62007-12-13 12:43:21 -060080 struct iscsi_chunk chunk;
81
82 /* Allocate buffer for BHS + AHS */
83 uint32_t hdr_buf[64];
Alex Aizmanc213ca02005-08-04 19:30:31 -070084
85 /* copied and flipped values */
Alex Aizmanc213ca02005-08-04 19:30:31 -070086 int datalen;
Olaf Kirchda32dd62007-12-13 12:43:21 -060087};
88
89/* Socket connection send helper */
90struct iscsi_tcp_send {
91 struct iscsi_hdr *hdr;
92 struct iscsi_chunk chunk;
93 struct iscsi_chunk data_chunk;
94
95 /* Allocate buffer for BHS + AHS */
96 uint32_t hdr_buf[64];
Alex Aizmanc213ca02005-08-04 19:30:31 -070097};
98
Mike Christie5bb0b552006-04-06 21:26:46 -050099struct iscsi_tcp_conn {
100 struct iscsi_conn *iscsi_conn;
101 struct socket *sock;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700102 int stop_stage; /* conn_stop() flag: *
103 * stop to recover, *
104 * stop to terminate */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700105 /* control data */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700106 struct iscsi_tcp_recv in; /* TCP receive context */
Olaf Kirchda32dd62007-12-13 12:43:21 -0600107 struct iscsi_tcp_send out; /* TCP send context */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700108
109 /* old values for socket callbacks */
110 void (*old_data_ready)(struct sock *, int);
111 void (*old_state_change)(struct sock *);
112 void (*old_write_space)(struct sock *);
113
Mike Christiedd8c0d92006-08-31 18:09:28 -0400114 /* data and header digests */
James Bottomleyc9802cd2006-09-23 15:33:43 -0500115 struct hash_desc tx_hash; /* CRC32C (Tx) */
116 struct hash_desc rx_hash; /* CRC32C (Rx) */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700117
Mike Christie5bb0b552006-04-06 21:26:46 -0500118 /* MIB custom statistics */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700119 uint32_t sendpage_failures_cnt;
120 uint32_t discontiguous_hdr_cnt;
FUJITA Tomonori56851692006-01-13 18:05:44 -0600121
122 ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int);
Alex Aizmanc213ca02005-08-04 19:30:31 -0700123};
124
Alex Aizmanc213ca02005-08-04 19:30:31 -0700125struct iscsi_buf {
126 struct scatterlist sg;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700127 unsigned int sent;
Mike Christie7cae5152006-01-13 18:05:47 -0600128 char use_sendmsg;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700129};
130
131struct iscsi_data_task {
132 struct iscsi_data hdr; /* PDU */
133 char hdrext[sizeof(__u32)]; /* Header-Digest */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700134 struct iscsi_buf digestbuf; /* digest buffer */
135 uint32_t digest; /* data digest */
136};
Alex Aizmanc213ca02005-08-04 19:30:31 -0700137
Mike Christie5bb0b552006-04-06 21:26:46 -0500138struct iscsi_tcp_mgmt_task {
139 struct iscsi_hdr hdr;
140 char hdrext[sizeof(__u32)]; /* Header-Digest */
Mike Christie843c0a82007-12-13 12:43:20 -0600141 int xmstate; /* mgmt xmit progress */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700142 struct iscsi_buf headbuf; /* header buffer */
143 struct iscsi_buf sendbuf; /* in progress buffer */
144 int sent;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700145};
146
147struct iscsi_r2t_info {
148 __be32 ttt; /* copied from R2T */
149 __be32 exp_statsn; /* copied from R2T */
150 uint32_t data_length; /* copied from R2T */
151 uint32_t data_offset; /* copied from R2T */
152 struct iscsi_buf headbuf; /* Data-Out Header Buffer */
153 struct iscsi_buf sendbuf; /* Data-Out in progress buffer*/
154 int sent; /* R2T sequence progress */
155 int data_count; /* DATA-Out payload progress */
156 struct scatterlist *sg; /* per-R2T SG list */
157 int solicit_datasn;
Mike Christieffbfe922006-05-18 20:31:36 -0500158 struct iscsi_data_task dtask; /* which data task */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700159};
160
Mike Christie5bb0b552006-04-06 21:26:46 -0500161struct iscsi_tcp_cmd_task {
162 struct iscsi_cmd hdr;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700163 char hdrext[4*sizeof(__u16)+ /* AHS */
164 sizeof(__u32)]; /* HeaderDigest */
165 char pad[ISCSI_PAD_LEN];
Mike Christie5bb0b552006-04-06 21:26:46 -0500166 int pad_count; /* padded bytes */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700167 struct iscsi_buf headbuf; /* header buf (xmit) */
168 struct iscsi_buf sendbuf; /* in progress buffer*/
Mike Christie843c0a82007-12-13 12:43:20 -0600169 int xmstate; /* xmit xtate machine */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700170 int sent;
171 struct scatterlist *sg; /* per-cmd SG list */
172 struct scatterlist *bad_sg; /* assert statement */
173 int sg_count; /* SG's to process */
Mike Christied473cc72007-05-30 12:57:14 -0500174 uint32_t exp_datasn; /* expected target's R2TSN/DataSN */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700175 int data_offset;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700176 struct iscsi_r2t_info *r2t; /* in progress R2T */
177 struct iscsi_queue r2tpool;
178 struct kfifo *r2tqueue;
179 struct iscsi_r2t_info **r2ts;
Alex Aizmanc213ca02005-08-04 19:30:31 -0700180 int digest_count;
181 uint32_t immdigest; /* for imm data */
182 struct iscsi_buf immbuf; /* for imm data digest */
Mike Christieffbfe922006-05-18 20:31:36 -0500183 struct iscsi_data_task unsol_dtask; /* unsol data task */
Alex Aizmanc213ca02005-08-04 19:30:31 -0700184};
185
186#endif /* ISCSI_H */