1e48354ceSNicholas Bellinger /*******************************************************************************
2e48354ceSNicholas Bellinger  * This file contains error recovery level one used by the iSCSI Target driver.
3e48354ceSNicholas Bellinger  *
44c76251eSNicholas Bellinger  * (c) Copyright 2007-2013 Datera, Inc.
5e48354ceSNicholas Bellinger  *
6e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
7e48354ceSNicholas Bellinger  *
8e48354ceSNicholas Bellinger  * This program is free software; you can redistribute it and/or modify
9e48354ceSNicholas Bellinger  * it under the terms of the GNU General Public License as published by
10e48354ceSNicholas Bellinger  * the Free Software Foundation; either version 2 of the License, or
11e48354ceSNicholas Bellinger  * (at your option) any later version.
12e48354ceSNicholas Bellinger  *
13e48354ceSNicholas Bellinger  * This program is distributed in the hope that it will be useful,
14e48354ceSNicholas Bellinger  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15e48354ceSNicholas Bellinger  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e48354ceSNicholas Bellinger  * GNU General Public License for more details.
17e48354ceSNicholas Bellinger  ******************************************************************************/
18e48354ceSNicholas Bellinger 
19e48354ceSNicholas Bellinger #include <linux/list.h>
20e48354ceSNicholas Bellinger #include <scsi/iscsi_proto.h>
21e48354ceSNicholas Bellinger #include <target/target_core_base.h>
22c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
233e1c81a9SNicholas Bellinger #include <target/iscsi/iscsi_transport.h>
24e48354ceSNicholas Bellinger 
2567f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
26e48354ceSNicholas Bellinger #include "iscsi_target_seq_pdu_list.h"
27e48354ceSNicholas Bellinger #include "iscsi_target_datain_values.h"
28e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
29e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
30e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
31e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h"
32e48354ceSNicholas Bellinger #include "iscsi_target_erl1.h"
33e48354ceSNicholas Bellinger #include "iscsi_target_erl2.h"
34e48354ceSNicholas Bellinger #include "iscsi_target.h"
35e48354ceSNicholas Bellinger 
36e48354ceSNicholas Bellinger #define OFFLOAD_BUF_SIZE	32768
37e48354ceSNicholas Bellinger 
38e48354ceSNicholas Bellinger /*
39e48354ceSNicholas Bellinger  *	Used to dump excess datain payload for certain error recovery
40e48354ceSNicholas Bellinger  *	situations.  Receive in OFFLOAD_BUF_SIZE max of datain per rx_data().
41e48354ceSNicholas Bellinger  *
42e48354ceSNicholas Bellinger  *	dump_padding_digest denotes if padding and data digests need
43e48354ceSNicholas Bellinger  *	to be dumped.
44e48354ceSNicholas Bellinger  */
45e48354ceSNicholas Bellinger int iscsit_dump_data_payload(
46e48354ceSNicholas Bellinger 	struct iscsi_conn *conn,
47e48354ceSNicholas Bellinger 	u32 buf_len,
48e48354ceSNicholas Bellinger 	int dump_padding_digest)
49e48354ceSNicholas Bellinger {
50e48354ceSNicholas Bellinger 	char *buf, pad_bytes[4];
51e48354ceSNicholas Bellinger 	int ret = DATAOUT_WITHIN_COMMAND_RECOVERY, rx_got;
52e48354ceSNicholas Bellinger 	u32 length, padding, offset = 0, size;
53e48354ceSNicholas Bellinger 	struct kvec iov;
54e48354ceSNicholas Bellinger 
553e1c81a9SNicholas Bellinger 	if (conn->sess->sess_ops->RDMAExtensions)
563e1c81a9SNicholas Bellinger 		return 0;
573e1c81a9SNicholas Bellinger 
58e48354ceSNicholas Bellinger 	length = (buf_len > OFFLOAD_BUF_SIZE) ? OFFLOAD_BUF_SIZE : buf_len;
59e48354ceSNicholas Bellinger 
60e48354ceSNicholas Bellinger 	buf = kzalloc(length, GFP_ATOMIC);
61e48354ceSNicholas Bellinger 	if (!buf) {
62e48354ceSNicholas Bellinger 		pr_err("Unable to allocate %u bytes for offload"
63e48354ceSNicholas Bellinger 				" buffer.\n", length);
64e48354ceSNicholas Bellinger 		return -1;
65e48354ceSNicholas Bellinger 	}
66e48354ceSNicholas Bellinger 	memset(&iov, 0, sizeof(struct kvec));
67e48354ceSNicholas Bellinger 
68e48354ceSNicholas Bellinger 	while (offset < buf_len) {
69e48354ceSNicholas Bellinger 		size = ((offset + length) > buf_len) ?
70e48354ceSNicholas Bellinger 			(buf_len - offset) : length;
71e48354ceSNicholas Bellinger 
72e48354ceSNicholas Bellinger 		iov.iov_len = size;
73e48354ceSNicholas Bellinger 		iov.iov_base = buf;
74e48354ceSNicholas Bellinger 
75e48354ceSNicholas Bellinger 		rx_got = rx_data(conn, &iov, 1, size);
76e48354ceSNicholas Bellinger 		if (rx_got != size) {
77e48354ceSNicholas Bellinger 			ret = DATAOUT_CANNOT_RECOVER;
78e48354ceSNicholas Bellinger 			goto out;
79e48354ceSNicholas Bellinger 		}
80e48354ceSNicholas Bellinger 
81e48354ceSNicholas Bellinger 		offset += size;
82e48354ceSNicholas Bellinger 	}
83e48354ceSNicholas Bellinger 
84e48354ceSNicholas Bellinger 	if (!dump_padding_digest)
85e48354ceSNicholas Bellinger 		goto out;
86e48354ceSNicholas Bellinger 
87e48354ceSNicholas Bellinger 	padding = ((-buf_len) & 3);
88e48354ceSNicholas Bellinger 	if (padding != 0) {
89e48354ceSNicholas Bellinger 		iov.iov_len = padding;
90e48354ceSNicholas Bellinger 		iov.iov_base = pad_bytes;
91e48354ceSNicholas Bellinger 
92e48354ceSNicholas Bellinger 		rx_got = rx_data(conn, &iov, 1, padding);
93e48354ceSNicholas Bellinger 		if (rx_got != padding) {
94e48354ceSNicholas Bellinger 			ret = DATAOUT_CANNOT_RECOVER;
95e48354ceSNicholas Bellinger 			goto out;
96e48354ceSNicholas Bellinger 		}
97e48354ceSNicholas Bellinger 	}
98e48354ceSNicholas Bellinger 
99e48354ceSNicholas Bellinger 	if (conn->conn_ops->DataDigest) {
100e48354ceSNicholas Bellinger 		u32 data_crc;
101e48354ceSNicholas Bellinger 
102e48354ceSNicholas Bellinger 		iov.iov_len = ISCSI_CRC_LEN;
103e48354ceSNicholas Bellinger 		iov.iov_base = &data_crc;
104e48354ceSNicholas Bellinger 
105e48354ceSNicholas Bellinger 		rx_got = rx_data(conn, &iov, 1, ISCSI_CRC_LEN);
106e48354ceSNicholas Bellinger 		if (rx_got != ISCSI_CRC_LEN) {
107e48354ceSNicholas Bellinger 			ret = DATAOUT_CANNOT_RECOVER;
108e48354ceSNicholas Bellinger 			goto out;
109e48354ceSNicholas Bellinger 		}
110e48354ceSNicholas Bellinger 	}
111e48354ceSNicholas Bellinger 
112e48354ceSNicholas Bellinger out:
113e48354ceSNicholas Bellinger 	kfree(buf);
114e48354ceSNicholas Bellinger 	return ret;
115e48354ceSNicholas Bellinger }
116e48354ceSNicholas Bellinger 
117e48354ceSNicholas Bellinger /*
118e48354ceSNicholas Bellinger  *	Used for retransmitting R2Ts from a R2T SNACK request.
119e48354ceSNicholas Bellinger  */
120e48354ceSNicholas Bellinger static int iscsit_send_recovery_r2t_for_snack(
121e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
122e48354ceSNicholas Bellinger 	struct iscsi_r2t *r2t)
123e48354ceSNicholas Bellinger {
124e48354ceSNicholas Bellinger 	/*
125e48354ceSNicholas Bellinger 	 * If the struct iscsi_r2t has not been sent yet, we can safely
126e48354ceSNicholas Bellinger 	 * ignore retransmission
127e48354ceSNicholas Bellinger 	 * of the R2TSN in question.
128e48354ceSNicholas Bellinger 	 */
129e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->r2t_lock);
130e48354ceSNicholas Bellinger 	if (!r2t->sent_r2t) {
131e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->r2t_lock);
132e48354ceSNicholas Bellinger 		return 0;
133e48354ceSNicholas Bellinger 	}
134e48354ceSNicholas Bellinger 	r2t->sent_r2t = 0;
135e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->r2t_lock);
136e48354ceSNicholas Bellinger 
137e48354ceSNicholas Bellinger 	iscsit_add_cmd_to_immediate_queue(cmd, cmd->conn, ISTATE_SEND_R2T);
138e48354ceSNicholas Bellinger 
139e48354ceSNicholas Bellinger 	return 0;
140e48354ceSNicholas Bellinger }
141e48354ceSNicholas Bellinger 
142e48354ceSNicholas Bellinger static int iscsit_handle_r2t_snack(
143e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
144e48354ceSNicholas Bellinger 	unsigned char *buf,
145e48354ceSNicholas Bellinger 	u32 begrun,
146e48354ceSNicholas Bellinger 	u32 runlength)
147e48354ceSNicholas Bellinger {
148e48354ceSNicholas Bellinger 	u32 last_r2tsn;
149e48354ceSNicholas Bellinger 	struct iscsi_r2t *r2t;
150e48354ceSNicholas Bellinger 
151e48354ceSNicholas Bellinger 	/*
152e48354ceSNicholas Bellinger 	 * Make sure the initiator is not requesting retransmission
153e48354ceSNicholas Bellinger 	 * of R2TSNs already acknowledged by a TMR TASK_REASSIGN.
154e48354ceSNicholas Bellinger 	 */
155e48354ceSNicholas Bellinger 	if ((cmd->cmd_flags & ICF_GOT_DATACK_SNACK) &&
156e48354ceSNicholas Bellinger 	    (begrun <= cmd->acked_data_sn)) {
157e48354ceSNicholas Bellinger 		pr_err("ITT: 0x%08x, R2T SNACK requesting"
158e48354ceSNicholas Bellinger 			" retransmission of R2TSN: 0x%08x to 0x%08x but already"
159e48354ceSNicholas Bellinger 			" acked to  R2TSN: 0x%08x by TMR TASK_REASSIGN,"
160e48354ceSNicholas Bellinger 			" protocol error.\n", cmd->init_task_tag, begrun,
161e48354ceSNicholas Bellinger 			(begrun + runlength), cmd->acked_data_sn);
162e48354ceSNicholas Bellinger 
1635a342521SBart Van Assche 		return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
164e48354ceSNicholas Bellinger 	}
165e48354ceSNicholas Bellinger 
166e48354ceSNicholas Bellinger 	if (runlength) {
167e48354ceSNicholas Bellinger 		if ((begrun + runlength) > cmd->r2t_sn) {
168e48354ceSNicholas Bellinger 			pr_err("Command ITT: 0x%08x received R2T SNACK"
169e48354ceSNicholas Bellinger 			" with BegRun: 0x%08x, RunLength: 0x%08x, exceeds"
170e48354ceSNicholas Bellinger 			" current R2TSN: 0x%08x, protocol error.\n",
171e48354ceSNicholas Bellinger 			cmd->init_task_tag, begrun, runlength, cmd->r2t_sn);
172ba159914SNicholas Bellinger 			return iscsit_reject_cmd(cmd,
173ba159914SNicholas Bellinger 					ISCSI_REASON_BOOKMARK_INVALID, buf);
174e48354ceSNicholas Bellinger 		}
175e48354ceSNicholas Bellinger 		last_r2tsn = (begrun + runlength);
176e48354ceSNicholas Bellinger 	} else
177e48354ceSNicholas Bellinger 		last_r2tsn = cmd->r2t_sn;
178e48354ceSNicholas Bellinger 
179e48354ceSNicholas Bellinger 	while (begrun < last_r2tsn) {
180e48354ceSNicholas Bellinger 		r2t = iscsit_get_holder_for_r2tsn(cmd, begrun);
181e48354ceSNicholas Bellinger 		if (!r2t)
182e48354ceSNicholas Bellinger 			return -1;
183e48354ceSNicholas Bellinger 		if (iscsit_send_recovery_r2t_for_snack(cmd, r2t) < 0)
184e48354ceSNicholas Bellinger 			return -1;
185e48354ceSNicholas Bellinger 
186e48354ceSNicholas Bellinger 		begrun++;
187e48354ceSNicholas Bellinger 	}
188e48354ceSNicholas Bellinger 
189e48354ceSNicholas Bellinger 	return 0;
190e48354ceSNicholas Bellinger }
191e48354ceSNicholas Bellinger 
192e48354ceSNicholas Bellinger /*
193e48354ceSNicholas Bellinger  *	Generates Offsets and NextBurstLength based on Begrun and Runlength
194e48354ceSNicholas Bellinger  *	carried in a Data SNACK or ExpDataSN in TMR TASK_REASSIGN.
195e48354ceSNicholas Bellinger  *
196e48354ceSNicholas Bellinger  *	For DataSequenceInOrder=Yes and DataPDUInOrder=[Yes,No] only.
197e48354ceSNicholas Bellinger  *
198e48354ceSNicholas Bellinger  *	FIXME: How is this handled for a RData SNACK?
199e48354ceSNicholas Bellinger  */
200e48354ceSNicholas Bellinger int iscsit_create_recovery_datain_values_datasequenceinorder_yes(
201e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
202e48354ceSNicholas Bellinger 	struct iscsi_datain_req *dr)
203e48354ceSNicholas Bellinger {
204e48354ceSNicholas Bellinger 	u32 data_sn = 0, data_sn_count = 0;
205e48354ceSNicholas Bellinger 	u32 pdu_start = 0, seq_no = 0;
206e48354ceSNicholas Bellinger 	u32 begrun = dr->begrun;
207e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
208e48354ceSNicholas Bellinger 
209e48354ceSNicholas Bellinger 	while (begrun > data_sn++) {
210e48354ceSNicholas Bellinger 		data_sn_count++;
211e48354ceSNicholas Bellinger 		if ((dr->next_burst_len +
212e48354ceSNicholas Bellinger 		     conn->conn_ops->MaxRecvDataSegmentLength) <
213e48354ceSNicholas Bellinger 		     conn->sess->sess_ops->MaxBurstLength) {
214e48354ceSNicholas Bellinger 			dr->read_data_done +=
215e48354ceSNicholas Bellinger 				conn->conn_ops->MaxRecvDataSegmentLength;
216e48354ceSNicholas Bellinger 			dr->next_burst_len +=
217e48354ceSNicholas Bellinger 				conn->conn_ops->MaxRecvDataSegmentLength;
218e48354ceSNicholas Bellinger 		} else {
219e48354ceSNicholas Bellinger 			dr->read_data_done +=
220e48354ceSNicholas Bellinger 				(conn->sess->sess_ops->MaxBurstLength -
221e48354ceSNicholas Bellinger 				 dr->next_burst_len);
222e48354ceSNicholas Bellinger 			dr->next_burst_len = 0;
223e48354ceSNicholas Bellinger 			pdu_start += data_sn_count;
224e48354ceSNicholas Bellinger 			data_sn_count = 0;
225e48354ceSNicholas Bellinger 			seq_no++;
226e48354ceSNicholas Bellinger 		}
227e48354ceSNicholas Bellinger 	}
228e48354ceSNicholas Bellinger 
229e48354ceSNicholas Bellinger 	if (!conn->sess->sess_ops->DataPDUInOrder) {
230e48354ceSNicholas Bellinger 		cmd->seq_no = seq_no;
231e48354ceSNicholas Bellinger 		cmd->pdu_start = pdu_start;
232e48354ceSNicholas Bellinger 		cmd->pdu_send_order = data_sn_count;
233e48354ceSNicholas Bellinger 	}
234e48354ceSNicholas Bellinger 
235e48354ceSNicholas Bellinger 	return 0;
236e48354ceSNicholas Bellinger }
237e48354ceSNicholas Bellinger 
238e48354ceSNicholas Bellinger /*
239e48354ceSNicholas Bellinger  *	Generates Offsets and NextBurstLength based on Begrun and Runlength
240e48354ceSNicholas Bellinger  *	carried in a Data SNACK or ExpDataSN in TMR TASK_REASSIGN.
241e48354ceSNicholas Bellinger  *
242e48354ceSNicholas Bellinger  *	For DataSequenceInOrder=No and DataPDUInOrder=[Yes,No] only.
243e48354ceSNicholas Bellinger  *
244e48354ceSNicholas Bellinger  *	FIXME: How is this handled for a RData SNACK?
245e48354ceSNicholas Bellinger  */
246e48354ceSNicholas Bellinger int iscsit_create_recovery_datain_values_datasequenceinorder_no(
247e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
248e48354ceSNicholas Bellinger 	struct iscsi_datain_req *dr)
249e48354ceSNicholas Bellinger {
250e48354ceSNicholas Bellinger 	int found_seq = 0, i;
251e48354ceSNicholas Bellinger 	u32 data_sn, read_data_done = 0, seq_send_order = 0;
252e48354ceSNicholas Bellinger 	u32 begrun = dr->begrun;
253e48354ceSNicholas Bellinger 	u32 runlength = dr->runlength;
254e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
255e48354ceSNicholas Bellinger 	struct iscsi_seq *first_seq = NULL, *seq = NULL;
256e48354ceSNicholas Bellinger 
257e48354ceSNicholas Bellinger 	if (!cmd->seq_list) {
258e48354ceSNicholas Bellinger 		pr_err("struct iscsi_cmd->seq_list is NULL!\n");
259e48354ceSNicholas Bellinger 		return -1;
260e48354ceSNicholas Bellinger 	}
261e48354ceSNicholas Bellinger 
262e48354ceSNicholas Bellinger 	/*
263e48354ceSNicholas Bellinger 	 * Calculate read_data_done for all sequences containing a
264e48354ceSNicholas Bellinger 	 * first_datasn and last_datasn less than the BegRun.
265e48354ceSNicholas Bellinger 	 *
266e48354ceSNicholas Bellinger 	 * Locate the struct iscsi_seq the BegRun lies within and calculate
267e48354ceSNicholas Bellinger 	 * NextBurstLenghth up to the DataSN based on MaxRecvDataSegmentLength.
268e48354ceSNicholas Bellinger 	 *
269e48354ceSNicholas Bellinger 	 * Also use struct iscsi_seq->seq_send_order to determine where to start.
270e48354ceSNicholas Bellinger 	 */
271e48354ceSNicholas Bellinger 	for (i = 0; i < cmd->seq_count; i++) {
272e48354ceSNicholas Bellinger 		seq = &cmd->seq_list[i];
273e48354ceSNicholas Bellinger 
274e48354ceSNicholas Bellinger 		if (!seq->seq_send_order)
275e48354ceSNicholas Bellinger 			first_seq = seq;
276e48354ceSNicholas Bellinger 
277e48354ceSNicholas Bellinger 		/*
278e48354ceSNicholas Bellinger 		 * No data has been transferred for this DataIN sequence, so the
279e48354ceSNicholas Bellinger 		 * seq->first_datasn and seq->last_datasn have not been set.
280e48354ceSNicholas Bellinger 		 */
281e48354ceSNicholas Bellinger 		if (!seq->sent) {
282e48354ceSNicholas Bellinger 			pr_err("Ignoring non-sent sequence 0x%08x ->"
283e48354ceSNicholas Bellinger 				" 0x%08x\n\n", seq->first_datasn,
284e48354ceSNicholas Bellinger 				seq->last_datasn);
285e48354ceSNicholas Bellinger 			continue;
286e48354ceSNicholas Bellinger 		}
287e48354ceSNicholas Bellinger 
288e48354ceSNicholas Bellinger 		/*
289e48354ceSNicholas Bellinger 		 * This DataIN sequence is precedes the received BegRun, add the
290e48354ceSNicholas Bellinger 		 * total xfer_len of the sequence to read_data_done and reset
291e48354ceSNicholas Bellinger 		 * seq->pdu_send_order.
292e48354ceSNicholas Bellinger 		 */
293e48354ceSNicholas Bellinger 		if ((seq->first_datasn < begrun) &&
294e48354ceSNicholas Bellinger 				(seq->last_datasn < begrun)) {
295e48354ceSNicholas Bellinger 			pr_err("Pre BegRun sequence 0x%08x ->"
296e48354ceSNicholas Bellinger 				" 0x%08x\n", seq->first_datasn,
297e48354ceSNicholas Bellinger 				seq->last_datasn);
2988b1e1244SAndy Grover 
299e48354ceSNicholas Bellinger 			read_data_done += cmd->seq_list[i].xfer_len;
300e48354ceSNicholas Bellinger 			seq->next_burst_len = seq->pdu_send_order = 0;
301e48354ceSNicholas Bellinger 			continue;
302e48354ceSNicholas Bellinger 		}
303e48354ceSNicholas Bellinger 
304e48354ceSNicholas Bellinger 		/*
305e48354ceSNicholas Bellinger 		 * The BegRun lies within this DataIN sequence.
306e48354ceSNicholas Bellinger 		 */
307e48354ceSNicholas Bellinger 		if ((seq->first_datasn <= begrun) &&
308e48354ceSNicholas Bellinger 				(seq->last_datasn >= begrun)) {
309e48354ceSNicholas Bellinger 			pr_err("Found sequence begrun: 0x%08x in"
310e48354ceSNicholas Bellinger 				" 0x%08x -> 0x%08x\n", begrun,
311e48354ceSNicholas Bellinger 				seq->first_datasn, seq->last_datasn);
3128b1e1244SAndy Grover 
313e48354ceSNicholas Bellinger 			seq_send_order = seq->seq_send_order;
314e48354ceSNicholas Bellinger 			data_sn = seq->first_datasn;
315e48354ceSNicholas Bellinger 			seq->next_burst_len = seq->pdu_send_order = 0;
316e48354ceSNicholas Bellinger 			found_seq = 1;
317e48354ceSNicholas Bellinger 
318e48354ceSNicholas Bellinger 			/*
319e48354ceSNicholas Bellinger 			 * For DataPDUInOrder=Yes, while the first DataSN of
320e48354ceSNicholas Bellinger 			 * the sequence is less than the received BegRun, add
321e48354ceSNicholas Bellinger 			 * the MaxRecvDataSegmentLength to read_data_done and
322e48354ceSNicholas Bellinger 			 * to the sequence's next_burst_len;
323e48354ceSNicholas Bellinger 			 *
324e48354ceSNicholas Bellinger 			 * For DataPDUInOrder=No, while the first DataSN of the
325e48354ceSNicholas Bellinger 			 * sequence is less than the received BegRun, find the
326e48354ceSNicholas Bellinger 			 * struct iscsi_pdu of the DataSN in question and add the
327e48354ceSNicholas Bellinger 			 * MaxRecvDataSegmentLength to read_data_done and to the
328e48354ceSNicholas Bellinger 			 * sequence's next_burst_len;
329e48354ceSNicholas Bellinger 			 */
330e48354ceSNicholas Bellinger 			if (conn->sess->sess_ops->DataPDUInOrder) {
331e48354ceSNicholas Bellinger 				while (data_sn < begrun) {
332e48354ceSNicholas Bellinger 					seq->pdu_send_order++;
333e48354ceSNicholas Bellinger 					read_data_done +=
334e48354ceSNicholas Bellinger 						conn->conn_ops->MaxRecvDataSegmentLength;
335e48354ceSNicholas Bellinger 					seq->next_burst_len +=
336e48354ceSNicholas Bellinger 						conn->conn_ops->MaxRecvDataSegmentLength;
337e48354ceSNicholas Bellinger 					data_sn++;
338e48354ceSNicholas Bellinger 				}
339e48354ceSNicholas Bellinger 			} else {
340e48354ceSNicholas Bellinger 				int j;
341e48354ceSNicholas Bellinger 				struct iscsi_pdu *pdu;
342e48354ceSNicholas Bellinger 
343e48354ceSNicholas Bellinger 				while (data_sn < begrun) {
344e48354ceSNicholas Bellinger 					seq->pdu_send_order++;
345e48354ceSNicholas Bellinger 
346e48354ceSNicholas Bellinger 					for (j = 0; j < seq->pdu_count; j++) {
347e48354ceSNicholas Bellinger 						pdu = &cmd->pdu_list[
348e48354ceSNicholas Bellinger 							seq->pdu_start + j];
349e48354ceSNicholas Bellinger 						if (pdu->data_sn == data_sn) {
350e48354ceSNicholas Bellinger 							read_data_done +=
351e48354ceSNicholas Bellinger 								pdu->length;
352e48354ceSNicholas Bellinger 							seq->next_burst_len +=
353e48354ceSNicholas Bellinger 								pdu->length;
354e48354ceSNicholas Bellinger 						}
355e48354ceSNicholas Bellinger 					}
356e48354ceSNicholas Bellinger 					data_sn++;
357e48354ceSNicholas Bellinger 				}
358e48354ceSNicholas Bellinger 			}
359e48354ceSNicholas Bellinger 			continue;
360e48354ceSNicholas Bellinger 		}
361e48354ceSNicholas Bellinger 
362e48354ceSNicholas Bellinger 		/*
363e48354ceSNicholas Bellinger 		 * This DataIN sequence is larger than the received BegRun,
364e48354ceSNicholas Bellinger 		 * reset seq->pdu_send_order and continue.
365e48354ceSNicholas Bellinger 		 */
366e48354ceSNicholas Bellinger 		if ((seq->first_datasn > begrun) ||
367e48354ceSNicholas Bellinger 				(seq->last_datasn > begrun)) {
368e48354ceSNicholas Bellinger 			pr_err("Post BegRun sequence 0x%08x -> 0x%08x\n",
369e48354ceSNicholas Bellinger 					seq->first_datasn, seq->last_datasn);
3708b1e1244SAndy Grover 
371e48354ceSNicholas Bellinger 			seq->next_burst_len = seq->pdu_send_order = 0;
372e48354ceSNicholas Bellinger 			continue;
373e48354ceSNicholas Bellinger 		}
374e48354ceSNicholas Bellinger 	}
375e48354ceSNicholas Bellinger 
376e48354ceSNicholas Bellinger 	if (!found_seq) {
377e48354ceSNicholas Bellinger 		if (!begrun) {
378e48354ceSNicholas Bellinger 			if (!first_seq) {
379e48354ceSNicholas Bellinger 				pr_err("ITT: 0x%08x, Begrun: 0x%08x"
380e48354ceSNicholas Bellinger 					" but first_seq is NULL\n",
381e48354ceSNicholas Bellinger 					cmd->init_task_tag, begrun);
382e48354ceSNicholas Bellinger 				return -1;
383e48354ceSNicholas Bellinger 			}
384e48354ceSNicholas Bellinger 			seq_send_order = first_seq->seq_send_order;
385e48354ceSNicholas Bellinger 			seq->next_burst_len = seq->pdu_send_order = 0;
386e48354ceSNicholas Bellinger 			goto done;
387e48354ceSNicholas Bellinger 		}
388e48354ceSNicholas Bellinger 
389e48354ceSNicholas Bellinger 		pr_err("Unable to locate struct iscsi_seq for ITT: 0x%08x,"
390e48354ceSNicholas Bellinger 			" BegRun: 0x%08x, RunLength: 0x%08x while"
391e48354ceSNicholas Bellinger 			" DataSequenceInOrder=No and DataPDUInOrder=%s.\n",
392e48354ceSNicholas Bellinger 				cmd->init_task_tag, begrun, runlength,
393e48354ceSNicholas Bellinger 			(conn->sess->sess_ops->DataPDUInOrder) ? "Yes" : "No");
394e48354ceSNicholas Bellinger 		return -1;
395e48354ceSNicholas Bellinger 	}
396e48354ceSNicholas Bellinger 
397e48354ceSNicholas Bellinger done:
398e48354ceSNicholas Bellinger 	dr->read_data_done = read_data_done;
399e48354ceSNicholas Bellinger 	dr->seq_send_order = seq_send_order;
400e48354ceSNicholas Bellinger 
401e48354ceSNicholas Bellinger 	return 0;
402e48354ceSNicholas Bellinger }
403e48354ceSNicholas Bellinger 
404e48354ceSNicholas Bellinger static int iscsit_handle_recovery_datain(
405e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
406e48354ceSNicholas Bellinger 	unsigned char *buf,
407e48354ceSNicholas Bellinger 	u32 begrun,
408e48354ceSNicholas Bellinger 	u32 runlength)
409e48354ceSNicholas Bellinger {
410e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
411e48354ceSNicholas Bellinger 	struct iscsi_datain_req *dr;
412e48354ceSNicholas Bellinger 	struct se_cmd *se_cmd = &cmd->se_cmd;
413e48354ceSNicholas Bellinger 
4147d680f3bSChristoph Hellwig 	if (!(se_cmd->transport_state & CMD_T_COMPLETE)) {
415e48354ceSNicholas Bellinger 		pr_err("Ignoring ITT: 0x%08x Data SNACK\n",
416e48354ceSNicholas Bellinger 				cmd->init_task_tag);
417e48354ceSNicholas Bellinger 		return 0;
418e48354ceSNicholas Bellinger 	}
419e48354ceSNicholas Bellinger 
420e48354ceSNicholas Bellinger 	/*
421e48354ceSNicholas Bellinger 	 * Make sure the initiator is not requesting retransmission
422e48354ceSNicholas Bellinger 	 * of DataSNs already acknowledged by a Data ACK SNACK.
423e48354ceSNicholas Bellinger 	 */
424e48354ceSNicholas Bellinger 	if ((cmd->cmd_flags & ICF_GOT_DATACK_SNACK) &&
425e48354ceSNicholas Bellinger 	    (begrun <= cmd->acked_data_sn)) {
426e48354ceSNicholas Bellinger 		pr_err("ITT: 0x%08x, Data SNACK requesting"
427e48354ceSNicholas Bellinger 			" retransmission of DataSN: 0x%08x to 0x%08x but"
428e48354ceSNicholas Bellinger 			" already acked to DataSN: 0x%08x by Data ACK SNACK,"
429e48354ceSNicholas Bellinger 			" protocol error.\n", cmd->init_task_tag, begrun,
430e48354ceSNicholas Bellinger 			(begrun + runlength), cmd->acked_data_sn);
431e48354ceSNicholas Bellinger 
432ba159914SNicholas Bellinger 		return iscsit_reject_cmd(cmd, ISCSI_REASON_PROTOCOL_ERROR, buf);
433e48354ceSNicholas Bellinger 	}
434e48354ceSNicholas Bellinger 
435e48354ceSNicholas Bellinger 	/*
436e48354ceSNicholas Bellinger 	 * Make sure BegRun and RunLength in the Data SNACK are sane.
437e48354ceSNicholas Bellinger 	 * Note: (cmd->data_sn - 1) will carry the maximum DataSN sent.
438e48354ceSNicholas Bellinger 	 */
439e48354ceSNicholas Bellinger 	if ((begrun + runlength) > (cmd->data_sn - 1)) {
440e48354ceSNicholas Bellinger 		pr_err("Initiator requesting BegRun: 0x%08x, RunLength"
441e48354ceSNicholas Bellinger 			": 0x%08x greater than maximum DataSN: 0x%08x.\n",
442e48354ceSNicholas Bellinger 				begrun, runlength, (cmd->data_sn - 1));
443ba159914SNicholas Bellinger 		return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_INVALID,
444ba159914SNicholas Bellinger 					 buf);
445e48354ceSNicholas Bellinger 	}
446e48354ceSNicholas Bellinger 
447e48354ceSNicholas Bellinger 	dr = iscsit_allocate_datain_req();
448e48354ceSNicholas Bellinger 	if (!dr)
449ba159914SNicholas Bellinger 		return iscsit_reject_cmd(cmd, ISCSI_REASON_BOOKMARK_NO_RESOURCES,
450ba159914SNicholas Bellinger 					 buf);
451e48354ceSNicholas Bellinger 
452e48354ceSNicholas Bellinger 	dr->data_sn = dr->begrun = begrun;
453e48354ceSNicholas Bellinger 	dr->runlength = runlength;
454e48354ceSNicholas Bellinger 	dr->generate_recovery_values = 1;
455e48354ceSNicholas Bellinger 	dr->recovery = DATAIN_WITHIN_COMMAND_RECOVERY;
456e48354ceSNicholas Bellinger 
457e48354ceSNicholas Bellinger 	iscsit_attach_datain_req(cmd, dr);
458e48354ceSNicholas Bellinger 
459e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_DATAIN;
460e48354ceSNicholas Bellinger 	iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
461e48354ceSNicholas Bellinger 
462e48354ceSNicholas Bellinger 	return 0;
463e48354ceSNicholas Bellinger }
464e48354ceSNicholas Bellinger 
465e48354ceSNicholas Bellinger int iscsit_handle_recovery_datain_or_r2t(
466e48354ceSNicholas Bellinger 	struct iscsi_conn *conn,
467e48354ceSNicholas Bellinger 	unsigned char *buf,
46866c7db68SChristoph Hellwig 	itt_t init_task_tag,
469e48354ceSNicholas Bellinger 	u32 targ_xfer_tag,
470e48354ceSNicholas Bellinger 	u32 begrun,
471e48354ceSNicholas Bellinger 	u32 runlength)
472e48354ceSNicholas Bellinger {
473e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd;
474e48354ceSNicholas Bellinger 
475e48354ceSNicholas Bellinger 	cmd = iscsit_find_cmd_from_itt(conn, init_task_tag);
476e48354ceSNicholas Bellinger 	if (!cmd)
477e48354ceSNicholas Bellinger 		return 0;
478e48354ceSNicholas Bellinger 
479e48354ceSNicholas Bellinger 	/*
480e48354ceSNicholas Bellinger 	 * FIXME: This will not work for bidi commands.
481e48354ceSNicholas Bellinger 	 */
482e48354ceSNicholas Bellinger 	switch (cmd->data_direction) {
483e48354ceSNicholas Bellinger 	case DMA_TO_DEVICE:
484e48354ceSNicholas Bellinger 		return iscsit_handle_r2t_snack(cmd, buf, begrun, runlength);
485e48354ceSNicholas Bellinger 	case DMA_FROM_DEVICE:
486e48354ceSNicholas Bellinger 		return iscsit_handle_recovery_datain(cmd, buf, begrun,
487e48354ceSNicholas Bellinger 				runlength);
488e48354ceSNicholas Bellinger 	default:
489e48354ceSNicholas Bellinger 		pr_err("Unknown cmd->data_direction: 0x%02x\n",
490e48354ceSNicholas Bellinger 				cmd->data_direction);
491e48354ceSNicholas Bellinger 		return -1;
492e48354ceSNicholas Bellinger 	}
493e48354ceSNicholas Bellinger 
494e48354ceSNicholas Bellinger 	return 0;
495e48354ceSNicholas Bellinger }
496e48354ceSNicholas Bellinger 
497e48354ceSNicholas Bellinger /* #warning FIXME: Status SNACK needs to be dependent on OPCODE!!! */
498e48354ceSNicholas Bellinger int iscsit_handle_status_snack(
499e48354ceSNicholas Bellinger 	struct iscsi_conn *conn,
50066c7db68SChristoph Hellwig 	itt_t init_task_tag,
501e48354ceSNicholas Bellinger 	u32 targ_xfer_tag,
502e48354ceSNicholas Bellinger 	u32 begrun,
503e48354ceSNicholas Bellinger 	u32 runlength)
504e48354ceSNicholas Bellinger {
505e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = NULL;
506e48354ceSNicholas Bellinger 	u32 last_statsn;
507e48354ceSNicholas Bellinger 	int found_cmd;
508e48354ceSNicholas Bellinger 
509752d8680SNicholas Bellinger 	if (!begrun) {
510752d8680SNicholas Bellinger 		begrun = conn->exp_statsn;
511752d8680SNicholas Bellinger 	} else if (conn->exp_statsn > begrun) {
512e48354ceSNicholas Bellinger 		pr_err("Got Status SNACK Begrun: 0x%08x, RunLength:"
513e48354ceSNicholas Bellinger 			" 0x%08x but already got ExpStatSN: 0x%08x on CID:"
514e48354ceSNicholas Bellinger 			" %hu.\n", begrun, runlength, conn->exp_statsn,
515e48354ceSNicholas Bellinger 			conn->cid);
516e48354ceSNicholas Bellinger 		return 0;
517e48354ceSNicholas Bellinger 	}
518e48354ceSNicholas Bellinger 
519e48354ceSNicholas Bellinger 	last_statsn = (!runlength) ? conn->stat_sn : (begrun + runlength);
520e48354ceSNicholas Bellinger 
521e48354ceSNicholas Bellinger 	while (begrun < last_statsn) {
522e48354ceSNicholas Bellinger 		found_cmd = 0;
523e48354ceSNicholas Bellinger 
524e48354ceSNicholas Bellinger 		spin_lock_bh(&conn->cmd_lock);
5252fbb471eSAndy Grover 		list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) {
526e48354ceSNicholas Bellinger 			if (cmd->stat_sn == begrun) {
527e48354ceSNicholas Bellinger 				found_cmd = 1;
528e48354ceSNicholas Bellinger 				break;
529e48354ceSNicholas Bellinger 			}
530e48354ceSNicholas Bellinger 		}
531e48354ceSNicholas Bellinger 		spin_unlock_bh(&conn->cmd_lock);
532e48354ceSNicholas Bellinger 
533e48354ceSNicholas Bellinger 		if (!found_cmd) {
534e48354ceSNicholas Bellinger 			pr_err("Unable to find StatSN: 0x%08x for"
535e48354ceSNicholas Bellinger 				" a Status SNACK, assuming this was a"
536e48354ceSNicholas Bellinger 				" protactic SNACK for an untransmitted"
537e48354ceSNicholas Bellinger 				" StatSN, ignoring.\n", begrun);
538e48354ceSNicholas Bellinger 			begrun++;
539e48354ceSNicholas Bellinger 			continue;
540e48354ceSNicholas Bellinger 		}
541e48354ceSNicholas Bellinger 
542e48354ceSNicholas Bellinger 		spin_lock_bh(&cmd->istate_lock);
543e48354ceSNicholas Bellinger 		if (cmd->i_state == ISTATE_SEND_DATAIN) {
544e48354ceSNicholas Bellinger 			spin_unlock_bh(&cmd->istate_lock);
545e48354ceSNicholas Bellinger 			pr_err("Ignoring Status SNACK for BegRun:"
546e48354ceSNicholas Bellinger 				" 0x%08x, RunLength: 0x%08x, assuming this was"
547e48354ceSNicholas Bellinger 				" a protactic SNACK for an untransmitted"
548e48354ceSNicholas Bellinger 				" StatSN\n", begrun, runlength);
549e48354ceSNicholas Bellinger 			begrun++;
550e48354ceSNicholas Bellinger 			continue;
551e48354ceSNicholas Bellinger 		}
552e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
553e48354ceSNicholas Bellinger 
554e48354ceSNicholas Bellinger 		cmd->i_state = ISTATE_SEND_STATUS_RECOVERY;
555e48354ceSNicholas Bellinger 		iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
556e48354ceSNicholas Bellinger 		begrun++;
557e48354ceSNicholas Bellinger 	}
558e48354ceSNicholas Bellinger 
559e48354ceSNicholas Bellinger 	return 0;
560e48354ceSNicholas Bellinger }
561e48354ceSNicholas Bellinger 
562e48354ceSNicholas Bellinger int iscsit_handle_data_ack(
563e48354ceSNicholas Bellinger 	struct iscsi_conn *conn,
564e48354ceSNicholas Bellinger 	u32 targ_xfer_tag,
565e48354ceSNicholas Bellinger 	u32 begrun,
566e48354ceSNicholas Bellinger 	u32 runlength)
567e48354ceSNicholas Bellinger {
568e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = NULL;
569e48354ceSNicholas Bellinger 
570e48354ceSNicholas Bellinger 	cmd = iscsit_find_cmd_from_ttt(conn, targ_xfer_tag);
571e48354ceSNicholas Bellinger 	if (!cmd) {
572e48354ceSNicholas Bellinger 		pr_err("Data ACK SNACK for TTT: 0x%08x is"
573e48354ceSNicholas Bellinger 			" invalid.\n", targ_xfer_tag);
574e48354ceSNicholas Bellinger 		return -1;
575e48354ceSNicholas Bellinger 	}
576e48354ceSNicholas Bellinger 
577e48354ceSNicholas Bellinger 	if (begrun <= cmd->acked_data_sn) {
578e48354ceSNicholas Bellinger 		pr_err("ITT: 0x%08x Data ACK SNACK BegRUN: 0x%08x is"
579e48354ceSNicholas Bellinger 			" less than the already acked DataSN: 0x%08x.\n",
580e48354ceSNicholas Bellinger 			cmd->init_task_tag, begrun, cmd->acked_data_sn);
581e48354ceSNicholas Bellinger 		return -1;
582e48354ceSNicholas Bellinger 	}
583e48354ceSNicholas Bellinger 
584e48354ceSNicholas Bellinger 	/*
585e48354ceSNicholas Bellinger 	 * For Data ACK SNACK, BegRun is the next expected DataSN.
586e48354ceSNicholas Bellinger 	 * (see iSCSI v19: 10.16.6)
587e48354ceSNicholas Bellinger 	 */
588e48354ceSNicholas Bellinger 	cmd->cmd_flags |= ICF_GOT_DATACK_SNACK;
589e48354ceSNicholas Bellinger 	cmd->acked_data_sn = (begrun - 1);
590e48354ceSNicholas Bellinger 
591e48354ceSNicholas Bellinger 	pr_debug("Received Data ACK SNACK for ITT: 0x%08x,"
592e48354ceSNicholas Bellinger 		" updated acked DataSN to 0x%08x.\n",
593e48354ceSNicholas Bellinger 			cmd->init_task_tag, cmd->acked_data_sn);
594e48354ceSNicholas Bellinger 
595e48354ceSNicholas Bellinger 	return 0;
596e48354ceSNicholas Bellinger }
597e48354ceSNicholas Bellinger 
598e48354ceSNicholas Bellinger static int iscsit_send_recovery_r2t(
599e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
600e48354ceSNicholas Bellinger 	u32 offset,
601e48354ceSNicholas Bellinger 	u32 xfer_len)
602e48354ceSNicholas Bellinger {
603e48354ceSNicholas Bellinger 	int ret;
604e48354ceSNicholas Bellinger 
605e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->r2t_lock);
606e48354ceSNicholas Bellinger 	ret = iscsit_add_r2t_to_list(cmd, offset, xfer_len, 1, 0);
607e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->r2t_lock);
608e48354ceSNicholas Bellinger 
609e48354ceSNicholas Bellinger 	return ret;
610e48354ceSNicholas Bellinger }
611e48354ceSNicholas Bellinger 
612e48354ceSNicholas Bellinger int iscsit_dataout_datapduinorder_no_fbit(
613e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
614e48354ceSNicholas Bellinger 	struct iscsi_pdu *pdu)
615e48354ceSNicholas Bellinger {
616e48354ceSNicholas Bellinger 	int i, send_recovery_r2t = 0, recovery = 0;
617e48354ceSNicholas Bellinger 	u32 length = 0, offset = 0, pdu_count = 0, xfer_len = 0;
618e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
619e48354ceSNicholas Bellinger 	struct iscsi_pdu *first_pdu = NULL;
620e48354ceSNicholas Bellinger 
621e48354ceSNicholas Bellinger 	/*
622e48354ceSNicholas Bellinger 	 * Get an struct iscsi_pdu pointer to the first PDU, and total PDU count
623e48354ceSNicholas Bellinger 	 * of the DataOUT sequence.
624e48354ceSNicholas Bellinger 	 */
625e48354ceSNicholas Bellinger 	if (conn->sess->sess_ops->DataSequenceInOrder) {
626e48354ceSNicholas Bellinger 		for (i = 0; i < cmd->pdu_count; i++) {
627e48354ceSNicholas Bellinger 			if (cmd->pdu_list[i].seq_no == pdu->seq_no) {
628e48354ceSNicholas Bellinger 				if (!first_pdu)
629e48354ceSNicholas Bellinger 					first_pdu = &cmd->pdu_list[i];
630e48354ceSNicholas Bellinger 				xfer_len += cmd->pdu_list[i].length;
631e48354ceSNicholas Bellinger 				pdu_count++;
632e48354ceSNicholas Bellinger 			} else if (pdu_count)
633e48354ceSNicholas Bellinger 				break;
634e48354ceSNicholas Bellinger 		}
635e48354ceSNicholas Bellinger 	} else {
636e48354ceSNicholas Bellinger 		struct iscsi_seq *seq = cmd->seq_ptr;
637e48354ceSNicholas Bellinger 
638e48354ceSNicholas Bellinger 		first_pdu = &cmd->pdu_list[seq->pdu_start];
639e48354ceSNicholas Bellinger 		pdu_count = seq->pdu_count;
640e48354ceSNicholas Bellinger 	}
641e48354ceSNicholas Bellinger 
642e48354ceSNicholas Bellinger 	if (!first_pdu || !pdu_count)
643e48354ceSNicholas Bellinger 		return DATAOUT_CANNOT_RECOVER;
644e48354ceSNicholas Bellinger 
645e48354ceSNicholas Bellinger 	/*
646e48354ceSNicholas Bellinger 	 * Loop through the ending DataOUT Sequence checking each struct iscsi_pdu.
647e48354ceSNicholas Bellinger 	 * The following ugly logic does batching of not received PDUs.
648e48354ceSNicholas Bellinger 	 */
649e48354ceSNicholas Bellinger 	for (i = 0; i < pdu_count; i++) {
650e48354ceSNicholas Bellinger 		if (first_pdu[i].status == ISCSI_PDU_RECEIVED_OK) {
651e48354ceSNicholas Bellinger 			if (!send_recovery_r2t)
652e48354ceSNicholas Bellinger 				continue;
653e48354ceSNicholas Bellinger 
654e48354ceSNicholas Bellinger 			if (iscsit_send_recovery_r2t(cmd, offset, length) < 0)
655e48354ceSNicholas Bellinger 				return DATAOUT_CANNOT_RECOVER;
656e48354ceSNicholas Bellinger 
657e48354ceSNicholas Bellinger 			send_recovery_r2t = length = offset = 0;
658e48354ceSNicholas Bellinger 			continue;
659e48354ceSNicholas Bellinger 		}
660e48354ceSNicholas Bellinger 		/*
661e48354ceSNicholas Bellinger 		 * Set recovery = 1 for any missing, CRC failed, or timed
662e48354ceSNicholas Bellinger 		 * out PDUs to let the DataOUT logic know that this sequence
663e48354ceSNicholas Bellinger 		 * has not been completed yet.
664e48354ceSNicholas Bellinger 		 *
665e48354ceSNicholas Bellinger 		 * Also, only send a Recovery R2T for ISCSI_PDU_NOT_RECEIVED.
666e48354ceSNicholas Bellinger 		 * We assume if the PDU either failed CRC or timed out
667e48354ceSNicholas Bellinger 		 * that a Recovery R2T has already been sent.
668e48354ceSNicholas Bellinger 		 */
669e48354ceSNicholas Bellinger 		recovery = 1;
670e48354ceSNicholas Bellinger 
671e48354ceSNicholas Bellinger 		if (first_pdu[i].status != ISCSI_PDU_NOT_RECEIVED)
672e48354ceSNicholas Bellinger 			continue;
673e48354ceSNicholas Bellinger 
674e48354ceSNicholas Bellinger 		if (!offset)
675e48354ceSNicholas Bellinger 			offset = first_pdu[i].offset;
676e48354ceSNicholas Bellinger 		length += first_pdu[i].length;
677e48354ceSNicholas Bellinger 
678e48354ceSNicholas Bellinger 		send_recovery_r2t = 1;
679e48354ceSNicholas Bellinger 	}
680e48354ceSNicholas Bellinger 
681e48354ceSNicholas Bellinger 	if (send_recovery_r2t)
682e48354ceSNicholas Bellinger 		if (iscsit_send_recovery_r2t(cmd, offset, length) < 0)
683e48354ceSNicholas Bellinger 			return DATAOUT_CANNOT_RECOVER;
684e48354ceSNicholas Bellinger 
685e48354ceSNicholas Bellinger 	return (!recovery) ? DATAOUT_NORMAL : DATAOUT_WITHIN_COMMAND_RECOVERY;
686e48354ceSNicholas Bellinger }
687e48354ceSNicholas Bellinger 
688e48354ceSNicholas Bellinger static int iscsit_recalculate_dataout_values(
689e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
690e48354ceSNicholas Bellinger 	u32 pdu_offset,
691e48354ceSNicholas Bellinger 	u32 pdu_length,
692e48354ceSNicholas Bellinger 	u32 *r2t_offset,
693e48354ceSNicholas Bellinger 	u32 *r2t_length)
694e48354ceSNicholas Bellinger {
695e48354ceSNicholas Bellinger 	int i;
696e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
697e48354ceSNicholas Bellinger 	struct iscsi_pdu *pdu = NULL;
698e48354ceSNicholas Bellinger 
699e48354ceSNicholas Bellinger 	if (conn->sess->sess_ops->DataSequenceInOrder) {
700e48354ceSNicholas Bellinger 		cmd->data_sn = 0;
701e48354ceSNicholas Bellinger 
702e48354ceSNicholas Bellinger 		if (conn->sess->sess_ops->DataPDUInOrder) {
703e48354ceSNicholas Bellinger 			*r2t_offset = cmd->write_data_done;
704e48354ceSNicholas Bellinger 			*r2t_length = (cmd->seq_end_offset -
705e48354ceSNicholas Bellinger 					cmd->write_data_done);
706e48354ceSNicholas Bellinger 			return 0;
707e48354ceSNicholas Bellinger 		}
708e48354ceSNicholas Bellinger 
709e48354ceSNicholas Bellinger 		*r2t_offset = cmd->seq_start_offset;
710e48354ceSNicholas Bellinger 		*r2t_length = (cmd->seq_end_offset - cmd->seq_start_offset);
711e48354ceSNicholas Bellinger 
712e48354ceSNicholas Bellinger 		for (i = 0; i < cmd->pdu_count; i++) {
713e48354ceSNicholas Bellinger 			pdu = &cmd->pdu_list[i];
714e48354ceSNicholas Bellinger 
715e48354ceSNicholas Bellinger 			if (pdu->status != ISCSI_PDU_RECEIVED_OK)
716e48354ceSNicholas Bellinger 				continue;
717e48354ceSNicholas Bellinger 
718e48354ceSNicholas Bellinger 			if ((pdu->offset >= cmd->seq_start_offset) &&
719e48354ceSNicholas Bellinger 			   ((pdu->offset + pdu->length) <=
720e48354ceSNicholas Bellinger 			     cmd->seq_end_offset)) {
721e48354ceSNicholas Bellinger 				if (!cmd->unsolicited_data)
722e48354ceSNicholas Bellinger 					cmd->next_burst_len -= pdu->length;
723e48354ceSNicholas Bellinger 				else
724e48354ceSNicholas Bellinger 					cmd->first_burst_len -= pdu->length;
725e48354ceSNicholas Bellinger 
726e48354ceSNicholas Bellinger 				cmd->write_data_done -= pdu->length;
727e48354ceSNicholas Bellinger 				pdu->status = ISCSI_PDU_NOT_RECEIVED;
728e48354ceSNicholas Bellinger 			}
729e48354ceSNicholas Bellinger 		}
730e48354ceSNicholas Bellinger 	} else {
731e48354ceSNicholas Bellinger 		struct iscsi_seq *seq = NULL;
732e48354ceSNicholas Bellinger 
733e48354ceSNicholas Bellinger 		seq = iscsit_get_seq_holder(cmd, pdu_offset, pdu_length);
734e48354ceSNicholas Bellinger 		if (!seq)
735e48354ceSNicholas Bellinger 			return -1;
736e48354ceSNicholas Bellinger 
737e48354ceSNicholas Bellinger 		*r2t_offset = seq->orig_offset;
738e48354ceSNicholas Bellinger 		*r2t_length = seq->xfer_len;
739e48354ceSNicholas Bellinger 
740e48354ceSNicholas Bellinger 		cmd->write_data_done -= (seq->offset - seq->orig_offset);
741e48354ceSNicholas Bellinger 		if (cmd->immediate_data)
742e48354ceSNicholas Bellinger 			cmd->first_burst_len = cmd->write_data_done;
743e48354ceSNicholas Bellinger 
744e48354ceSNicholas Bellinger 		seq->data_sn = 0;
745e48354ceSNicholas Bellinger 		seq->offset = seq->orig_offset;
746e48354ceSNicholas Bellinger 		seq->next_burst_len = 0;
747e48354ceSNicholas Bellinger 		seq->status = DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY;
748e48354ceSNicholas Bellinger 
749e48354ceSNicholas Bellinger 		if (conn->sess->sess_ops->DataPDUInOrder)
750e48354ceSNicholas Bellinger 			return 0;
751e48354ceSNicholas Bellinger 
752e48354ceSNicholas Bellinger 		for (i = 0; i < seq->pdu_count; i++) {
753e48354ceSNicholas Bellinger 			pdu = &cmd->pdu_list[i+seq->pdu_start];
754e48354ceSNicholas Bellinger 
755e48354ceSNicholas Bellinger 			if (pdu->status != ISCSI_PDU_RECEIVED_OK)
756e48354ceSNicholas Bellinger 				continue;
757e48354ceSNicholas Bellinger 
758e48354ceSNicholas Bellinger 			pdu->status = ISCSI_PDU_NOT_RECEIVED;
759e48354ceSNicholas Bellinger 		}
760e48354ceSNicholas Bellinger 	}
761e48354ceSNicholas Bellinger 
762e48354ceSNicholas Bellinger 	return 0;
763e48354ceSNicholas Bellinger }
764e48354ceSNicholas Bellinger 
765e48354ceSNicholas Bellinger int iscsit_recover_dataout_sequence(
766e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
767e48354ceSNicholas Bellinger 	u32 pdu_offset,
768e48354ceSNicholas Bellinger 	u32 pdu_length)
769e48354ceSNicholas Bellinger {
770e48354ceSNicholas Bellinger 	u32 r2t_length = 0, r2t_offset = 0;
771e48354ceSNicholas Bellinger 
772e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->istate_lock);
773e48354ceSNicholas Bellinger 	cmd->cmd_flags |= ICF_WITHIN_COMMAND_RECOVERY;
774e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->istate_lock);
775e48354ceSNicholas Bellinger 
776e48354ceSNicholas Bellinger 	if (iscsit_recalculate_dataout_values(cmd, pdu_offset, pdu_length,
777e48354ceSNicholas Bellinger 			&r2t_offset, &r2t_length) < 0)
778e48354ceSNicholas Bellinger 		return DATAOUT_CANNOT_RECOVER;
779e48354ceSNicholas Bellinger 
780e48354ceSNicholas Bellinger 	iscsit_send_recovery_r2t(cmd, r2t_offset, r2t_length);
781e48354ceSNicholas Bellinger 
782e48354ceSNicholas Bellinger 	return DATAOUT_WITHIN_COMMAND_RECOVERY;
783e48354ceSNicholas Bellinger }
784e48354ceSNicholas Bellinger 
785e48354ceSNicholas Bellinger static struct iscsi_ooo_cmdsn *iscsit_allocate_ooo_cmdsn(void)
786e48354ceSNicholas Bellinger {
787e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn = NULL;
788e48354ceSNicholas Bellinger 
789e48354ceSNicholas Bellinger 	ooo_cmdsn = kmem_cache_zalloc(lio_ooo_cache, GFP_ATOMIC);
790e48354ceSNicholas Bellinger 	if (!ooo_cmdsn) {
791e48354ceSNicholas Bellinger 		pr_err("Unable to allocate memory for"
792e48354ceSNicholas Bellinger 			" struct iscsi_ooo_cmdsn.\n");
793e48354ceSNicholas Bellinger 		return NULL;
794e48354ceSNicholas Bellinger 	}
795e48354ceSNicholas Bellinger 	INIT_LIST_HEAD(&ooo_cmdsn->ooo_list);
796e48354ceSNicholas Bellinger 
797e48354ceSNicholas Bellinger 	return ooo_cmdsn;
798e48354ceSNicholas Bellinger }
799e48354ceSNicholas Bellinger 
800e48354ceSNicholas Bellinger /*
801e48354ceSNicholas Bellinger  *	Called with sess->cmdsn_mutex held.
802e48354ceSNicholas Bellinger  */
803e48354ceSNicholas Bellinger static int iscsit_attach_ooo_cmdsn(
804e48354ceSNicholas Bellinger 	struct iscsi_session *sess,
805e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn)
806e48354ceSNicholas Bellinger {
807e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_tail, *ooo_tmp;
808e48354ceSNicholas Bellinger 	/*
809e48354ceSNicholas Bellinger 	 * We attach the struct iscsi_ooo_cmdsn entry to the out of order
810e48354ceSNicholas Bellinger 	 * list in increasing CmdSN order.
811e48354ceSNicholas Bellinger 	 * This allows iscsi_execute_ooo_cmdsns() to detect any
812e48354ceSNicholas Bellinger 	 * additional CmdSN holes while performing delayed execution.
813e48354ceSNicholas Bellinger 	 */
814e48354ceSNicholas Bellinger 	if (list_empty(&sess->sess_ooo_cmdsn_list))
815e48354ceSNicholas Bellinger 		list_add_tail(&ooo_cmdsn->ooo_list,
816e48354ceSNicholas Bellinger 				&sess->sess_ooo_cmdsn_list);
817e48354ceSNicholas Bellinger 	else {
818e48354ceSNicholas Bellinger 		ooo_tail = list_entry(sess->sess_ooo_cmdsn_list.prev,
819e48354ceSNicholas Bellinger 				typeof(*ooo_tail), ooo_list);
820e48354ceSNicholas Bellinger 		/*
821e48354ceSNicholas Bellinger 		 * CmdSN is greater than the tail of the list.
822e48354ceSNicholas Bellinger 		 */
8233eccfdb0SShlomo Pongratz 		if (iscsi_sna_lt(ooo_tail->cmdsn, ooo_cmdsn->cmdsn))
824e48354ceSNicholas Bellinger 			list_add_tail(&ooo_cmdsn->ooo_list,
825e48354ceSNicholas Bellinger 					&sess->sess_ooo_cmdsn_list);
826e48354ceSNicholas Bellinger 		else {
827e48354ceSNicholas Bellinger 			/*
828e48354ceSNicholas Bellinger 			 * CmdSN is either lower than the head,  or somewhere
829e48354ceSNicholas Bellinger 			 * in the middle.
830e48354ceSNicholas Bellinger 			 */
831e48354ceSNicholas Bellinger 			list_for_each_entry(ooo_tmp, &sess->sess_ooo_cmdsn_list,
832e48354ceSNicholas Bellinger 						ooo_list) {
8333eccfdb0SShlomo Pongratz 				if (iscsi_sna_lt(ooo_tmp->cmdsn, ooo_cmdsn->cmdsn))
834e48354ceSNicholas Bellinger 					continue;
835e48354ceSNicholas Bellinger 
8363eccfdb0SShlomo Pongratz 				/* Insert before this entry */
837e48354ceSNicholas Bellinger 				list_add(&ooo_cmdsn->ooo_list,
8383eccfdb0SShlomo Pongratz 					ooo_tmp->ooo_list.prev);
839e48354ceSNicholas Bellinger 				break;
840e48354ceSNicholas Bellinger 			}
841e48354ceSNicholas Bellinger 		}
842e48354ceSNicholas Bellinger 	}
843e48354ceSNicholas Bellinger 
844e48354ceSNicholas Bellinger 	return 0;
845e48354ceSNicholas Bellinger }
846e48354ceSNicholas Bellinger 
847e48354ceSNicholas Bellinger /*
848e48354ceSNicholas Bellinger  *	Removes an struct iscsi_ooo_cmdsn from a session's list,
849e48354ceSNicholas Bellinger  *	called with struct iscsi_session->cmdsn_mutex held.
850e48354ceSNicholas Bellinger  */
851e48354ceSNicholas Bellinger void iscsit_remove_ooo_cmdsn(
852e48354ceSNicholas Bellinger 	struct iscsi_session *sess,
853e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn)
854e48354ceSNicholas Bellinger {
855e48354ceSNicholas Bellinger 	list_del(&ooo_cmdsn->ooo_list);
856e48354ceSNicholas Bellinger 	kmem_cache_free(lio_ooo_cache, ooo_cmdsn);
857e48354ceSNicholas Bellinger }
858e48354ceSNicholas Bellinger 
859e48354ceSNicholas Bellinger void iscsit_clear_ooo_cmdsns_for_conn(struct iscsi_conn *conn)
860e48354ceSNicholas Bellinger {
861e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn;
862e48354ceSNicholas Bellinger 	struct iscsi_session *sess = conn->sess;
863e48354ceSNicholas Bellinger 
864e48354ceSNicholas Bellinger 	mutex_lock(&sess->cmdsn_mutex);
865e48354ceSNicholas Bellinger 	list_for_each_entry(ooo_cmdsn, &sess->sess_ooo_cmdsn_list, ooo_list) {
866e48354ceSNicholas Bellinger 		if (ooo_cmdsn->cid != conn->cid)
867e48354ceSNicholas Bellinger 			continue;
868e48354ceSNicholas Bellinger 
869e48354ceSNicholas Bellinger 		ooo_cmdsn->cmd = NULL;
870e48354ceSNicholas Bellinger 	}
871e48354ceSNicholas Bellinger 	mutex_unlock(&sess->cmdsn_mutex);
872e48354ceSNicholas Bellinger }
873e48354ceSNicholas Bellinger 
874e48354ceSNicholas Bellinger /*
875e48354ceSNicholas Bellinger  *	Called with sess->cmdsn_mutex held.
876e48354ceSNicholas Bellinger  */
877e48354ceSNicholas Bellinger int iscsit_execute_ooo_cmdsns(struct iscsi_session *sess)
878e48354ceSNicholas Bellinger {
879e48354ceSNicholas Bellinger 	int ooo_count = 0;
880e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = NULL;
881e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn, *ooo_cmdsn_tmp;
882e48354ceSNicholas Bellinger 
883e48354ceSNicholas Bellinger 	list_for_each_entry_safe(ooo_cmdsn, ooo_cmdsn_tmp,
884e48354ceSNicholas Bellinger 				&sess->sess_ooo_cmdsn_list, ooo_list) {
885e48354ceSNicholas Bellinger 		if (ooo_cmdsn->cmdsn != sess->exp_cmd_sn)
886e48354ceSNicholas Bellinger 			continue;
887e48354ceSNicholas Bellinger 
888e48354ceSNicholas Bellinger 		if (!ooo_cmdsn->cmd) {
889e48354ceSNicholas Bellinger 			sess->exp_cmd_sn++;
890e48354ceSNicholas Bellinger 			iscsit_remove_ooo_cmdsn(sess, ooo_cmdsn);
891e48354ceSNicholas Bellinger 			continue;
892e48354ceSNicholas Bellinger 		}
893e48354ceSNicholas Bellinger 
894e48354ceSNicholas Bellinger 		cmd = ooo_cmdsn->cmd;
895e48354ceSNicholas Bellinger 		cmd->i_state = cmd->deferred_i_state;
896e48354ceSNicholas Bellinger 		ooo_count++;
897e48354ceSNicholas Bellinger 		sess->exp_cmd_sn++;
898e48354ceSNicholas Bellinger 		pr_debug("Executing out of order CmdSN: 0x%08x,"
899e48354ceSNicholas Bellinger 			" incremented ExpCmdSN to 0x%08x.\n",
900e48354ceSNicholas Bellinger 			cmd->cmd_sn, sess->exp_cmd_sn);
901e48354ceSNicholas Bellinger 
902e48354ceSNicholas Bellinger 		iscsit_remove_ooo_cmdsn(sess, ooo_cmdsn);
903e48354ceSNicholas Bellinger 
904e48354ceSNicholas Bellinger 		if (iscsit_execute_cmd(cmd, 1) < 0)
905e48354ceSNicholas Bellinger 			return -1;
906e48354ceSNicholas Bellinger 
907e48354ceSNicholas Bellinger 		continue;
908e48354ceSNicholas Bellinger 	}
909e48354ceSNicholas Bellinger 
910e48354ceSNicholas Bellinger 	return ooo_count;
911e48354ceSNicholas Bellinger }
912e48354ceSNicholas Bellinger 
913e48354ceSNicholas Bellinger /*
914e48354ceSNicholas Bellinger  *	Called either:
915e48354ceSNicholas Bellinger  *
916e48354ceSNicholas Bellinger  *	1. With sess->cmdsn_mutex held from iscsi_execute_ooo_cmdsns()
917e48354ceSNicholas Bellinger  *	or iscsi_check_received_cmdsn().
918e48354ceSNicholas Bellinger  *	2. With no locks held directly from iscsi_handle_XXX_pdu() functions
919e48354ceSNicholas Bellinger  *	for immediate commands.
920e48354ceSNicholas Bellinger  */
921e48354ceSNicholas Bellinger int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
922e48354ceSNicholas Bellinger {
923e48354ceSNicholas Bellinger 	struct se_cmd *se_cmd = &cmd->se_cmd;
9243e1c81a9SNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
925e48354ceSNicholas Bellinger 	int lr = 0;
926e48354ceSNicholas Bellinger 
927e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->istate_lock);
928e48354ceSNicholas Bellinger 	if (ooo)
929e48354ceSNicholas Bellinger 		cmd->cmd_flags &= ~ICF_OOO_CMDSN;
930e48354ceSNicholas Bellinger 
931e48354ceSNicholas Bellinger 	switch (cmd->iscsi_opcode) {
932e48354ceSNicholas Bellinger 	case ISCSI_OP_SCSI_CMD:
933e48354ceSNicholas Bellinger 		/*
934e48354ceSNicholas Bellinger 		 * Go ahead and send the CHECK_CONDITION status for
935de103c93SChristoph Hellwig 		 * any SCSI CDB exceptions that may have occurred.
936e48354ceSNicholas Bellinger 		 */
937de103c93SChristoph Hellwig 		if (cmd->sense_reason) {
938de103c93SChristoph Hellwig 			if (cmd->sense_reason == TCM_RESERVATION_CONFLICT) {
939e48354ceSNicholas Bellinger 				cmd->i_state = ISTATE_SEND_STATUS;
940e48354ceSNicholas Bellinger 				spin_unlock_bh(&cmd->istate_lock);
941e48354ceSNicholas Bellinger 				iscsit_add_cmd_to_response_queue(cmd, cmd->conn,
942e48354ceSNicholas Bellinger 						cmd->i_state);
943e48354ceSNicholas Bellinger 				return 0;
944e48354ceSNicholas Bellinger 			}
945e48354ceSNicholas Bellinger 			spin_unlock_bh(&cmd->istate_lock);
946e48354ceSNicholas Bellinger 			/*
947e48354ceSNicholas Bellinger 			 * Determine if delayed TASK_ABORTED status for WRITEs
948e48354ceSNicholas Bellinger 			 * should be sent now if no unsolicited data out
949e48354ceSNicholas Bellinger 			 * payloads are expected, or if the delayed status
950e48354ceSNicholas Bellinger 			 * should be sent after unsolicited data out with
951e48354ceSNicholas Bellinger 			 * ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out()
952e48354ceSNicholas Bellinger 			 */
953e48354ceSNicholas Bellinger 			if (transport_check_aborted_status(se_cmd,
954e48354ceSNicholas Bellinger 					(cmd->unsolicited_data == 0)) != 0)
955e48354ceSNicholas Bellinger 				return 0;
956e48354ceSNicholas Bellinger 			/*
957e48354ceSNicholas Bellinger 			 * Otherwise send CHECK_CONDITION and sense for
958e48354ceSNicholas Bellinger 			 * exception
959e48354ceSNicholas Bellinger 			 */
960e48354ceSNicholas Bellinger 			return transport_send_check_condition_and_sense(se_cmd,
961de103c93SChristoph Hellwig 					cmd->sense_reason, 0);
962e48354ceSNicholas Bellinger 		}
963e48354ceSNicholas Bellinger 		/*
964e48354ceSNicholas Bellinger 		 * Special case for delayed CmdSN with Immediate
965e48354ceSNicholas Bellinger 		 * Data and/or Unsolicited Data Out attached.
966e48354ceSNicholas Bellinger 		 */
967e48354ceSNicholas Bellinger 		if (cmd->immediate_data) {
968e48354ceSNicholas Bellinger 			if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) {
969e48354ceSNicholas Bellinger 				spin_unlock_bh(&cmd->istate_lock);
97067441b68SChristoph Hellwig 				target_execute_cmd(&cmd->se_cmd);
97167441b68SChristoph Hellwig 				return 0;
972e48354ceSNicholas Bellinger 			}
973e48354ceSNicholas Bellinger 			spin_unlock_bh(&cmd->istate_lock);
974e48354ceSNicholas Bellinger 
975e48354ceSNicholas Bellinger 			if (!(cmd->cmd_flags &
976e48354ceSNicholas Bellinger 					ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
977e48354ceSNicholas Bellinger 				/*
978e48354ceSNicholas Bellinger 				 * Send the delayed TASK_ABORTED status for
979e48354ceSNicholas Bellinger 				 * WRITEs if no more unsolicitied data is
980e48354ceSNicholas Bellinger 				 * expected.
981e48354ceSNicholas Bellinger 				 */
982e48354ceSNicholas Bellinger 				if (transport_check_aborted_status(se_cmd, 1)
983e48354ceSNicholas Bellinger 						!= 0)
984e48354ceSNicholas Bellinger 					return 0;
985e48354ceSNicholas Bellinger 
986e48354ceSNicholas Bellinger 				iscsit_set_dataout_sequence_values(cmd);
9873e1c81a9SNicholas Bellinger 				conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
988e48354ceSNicholas Bellinger 			}
989e48354ceSNicholas Bellinger 			return 0;
990e48354ceSNicholas Bellinger 		}
991e48354ceSNicholas Bellinger 		/*
992e48354ceSNicholas Bellinger 		 * The default handler.
993e48354ceSNicholas Bellinger 		 */
994e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
995e48354ceSNicholas Bellinger 
996e48354ceSNicholas Bellinger 		if ((cmd->data_direction == DMA_TO_DEVICE) &&
997e48354ceSNicholas Bellinger 		    !(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
998e48354ceSNicholas Bellinger 			/*
999e48354ceSNicholas Bellinger 			 * Send the delayed TASK_ABORTED status for WRITEs if
1000e48354ceSNicholas Bellinger 			 * no more nsolicitied data is expected.
1001e48354ceSNicholas Bellinger 			 */
1002e48354ceSNicholas Bellinger 			if (transport_check_aborted_status(se_cmd, 1) != 0)
1003e48354ceSNicholas Bellinger 				return 0;
1004e48354ceSNicholas Bellinger 
10053e1c81a9SNicholas Bellinger 			iscsit_set_unsoliticed_dataout(cmd);
1006e48354ceSNicholas Bellinger 		}
1007e48354ceSNicholas Bellinger 		return transport_handle_cdb_direct(&cmd->se_cmd);
1008e48354ceSNicholas Bellinger 
1009e48354ceSNicholas Bellinger 	case ISCSI_OP_NOOP_OUT:
1010e48354ceSNicholas Bellinger 	case ISCSI_OP_TEXT:
1011e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
1012e48354ceSNicholas Bellinger 		iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1013e48354ceSNicholas Bellinger 		break;
1014e48354ceSNicholas Bellinger 	case ISCSI_OP_SCSI_TMFUNC:
1015de103c93SChristoph Hellwig 		if (cmd->se_cmd.se_tmr_req->response) {
1016e48354ceSNicholas Bellinger 			spin_unlock_bh(&cmd->istate_lock);
1017e48354ceSNicholas Bellinger 			iscsit_add_cmd_to_response_queue(cmd, cmd->conn,
1018e48354ceSNicholas Bellinger 					cmd->i_state);
1019e48354ceSNicholas Bellinger 			return 0;
1020e48354ceSNicholas Bellinger 		}
1021e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
1022e48354ceSNicholas Bellinger 
1023e48354ceSNicholas Bellinger 		return transport_generic_handle_tmr(&cmd->se_cmd);
1024e48354ceSNicholas Bellinger 	case ISCSI_OP_LOGOUT:
1025e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
1026e48354ceSNicholas Bellinger 		switch (cmd->logout_reason) {
1027e48354ceSNicholas Bellinger 		case ISCSI_LOGOUT_REASON_CLOSE_SESSION:
1028e48354ceSNicholas Bellinger 			lr = iscsit_logout_closesession(cmd, cmd->conn);
1029e48354ceSNicholas Bellinger 			break;
1030e48354ceSNicholas Bellinger 		case ISCSI_LOGOUT_REASON_CLOSE_CONNECTION:
1031e48354ceSNicholas Bellinger 			lr = iscsit_logout_closeconnection(cmd, cmd->conn);
1032e48354ceSNicholas Bellinger 			break;
1033e48354ceSNicholas Bellinger 		case ISCSI_LOGOUT_REASON_RECOVERY:
1034e48354ceSNicholas Bellinger 			lr = iscsit_logout_removeconnforrecovery(cmd, cmd->conn);
1035e48354ceSNicholas Bellinger 			break;
1036e48354ceSNicholas Bellinger 		default:
1037e48354ceSNicholas Bellinger 			pr_err("Unknown iSCSI Logout Request Code:"
1038e48354ceSNicholas Bellinger 				" 0x%02x\n", cmd->logout_reason);
1039e48354ceSNicholas Bellinger 			return -1;
1040e48354ceSNicholas Bellinger 		}
1041e48354ceSNicholas Bellinger 
1042e48354ceSNicholas Bellinger 		return lr;
1043e48354ceSNicholas Bellinger 	default:
1044e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->istate_lock);
1045e48354ceSNicholas Bellinger 		pr_err("Cannot perform out of order execution for"
1046e48354ceSNicholas Bellinger 		" unknown iSCSI Opcode: 0x%02x\n", cmd->iscsi_opcode);
1047e48354ceSNicholas Bellinger 		return -1;
1048e48354ceSNicholas Bellinger 	}
1049e48354ceSNicholas Bellinger 
1050e48354ceSNicholas Bellinger 	return 0;
1051e48354ceSNicholas Bellinger }
1052e48354ceSNicholas Bellinger 
1053e48354ceSNicholas Bellinger void iscsit_free_all_ooo_cmdsns(struct iscsi_session *sess)
1054e48354ceSNicholas Bellinger {
1055e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn, *ooo_cmdsn_tmp;
1056e48354ceSNicholas Bellinger 
1057e48354ceSNicholas Bellinger 	mutex_lock(&sess->cmdsn_mutex);
1058e48354ceSNicholas Bellinger 	list_for_each_entry_safe(ooo_cmdsn, ooo_cmdsn_tmp,
1059e48354ceSNicholas Bellinger 			&sess->sess_ooo_cmdsn_list, ooo_list) {
1060e48354ceSNicholas Bellinger 
1061e48354ceSNicholas Bellinger 		list_del(&ooo_cmdsn->ooo_list);
1062e48354ceSNicholas Bellinger 		kmem_cache_free(lio_ooo_cache, ooo_cmdsn);
1063e48354ceSNicholas Bellinger 	}
1064e48354ceSNicholas Bellinger 	mutex_unlock(&sess->cmdsn_mutex);
1065e48354ceSNicholas Bellinger }
1066e48354ceSNicholas Bellinger 
1067e48354ceSNicholas Bellinger int iscsit_handle_ooo_cmdsn(
1068e48354ceSNicholas Bellinger 	struct iscsi_session *sess,
1069e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
1070e48354ceSNicholas Bellinger 	u32 cmdsn)
1071e48354ceSNicholas Bellinger {
1072e48354ceSNicholas Bellinger 	int batch = 0;
1073e48354ceSNicholas Bellinger 	struct iscsi_ooo_cmdsn *ooo_cmdsn = NULL, *ooo_tail = NULL;
1074e48354ceSNicholas Bellinger 
1075e48354ceSNicholas Bellinger 	cmd->deferred_i_state		= cmd->i_state;
1076e48354ceSNicholas Bellinger 	cmd->i_state			= ISTATE_DEFERRED_CMD;
1077e48354ceSNicholas Bellinger 	cmd->cmd_flags			|= ICF_OOO_CMDSN;
1078e48354ceSNicholas Bellinger 
1079e48354ceSNicholas Bellinger 	if (list_empty(&sess->sess_ooo_cmdsn_list))
1080e48354ceSNicholas Bellinger 		batch = 1;
1081e48354ceSNicholas Bellinger 	else {
1082e48354ceSNicholas Bellinger 		ooo_tail = list_entry(sess->sess_ooo_cmdsn_list.prev,
1083e48354ceSNicholas Bellinger 				typeof(*ooo_tail), ooo_list);
1084e48354ceSNicholas Bellinger 		if (ooo_tail->cmdsn != (cmdsn - 1))
1085e48354ceSNicholas Bellinger 			batch = 1;
1086e48354ceSNicholas Bellinger 	}
1087e48354ceSNicholas Bellinger 
1088e48354ceSNicholas Bellinger 	ooo_cmdsn = iscsit_allocate_ooo_cmdsn();
1089e48354ceSNicholas Bellinger 	if (!ooo_cmdsn)
1090561bf158SNicholas Bellinger 		return -ENOMEM;
1091e48354ceSNicholas Bellinger 
1092e48354ceSNicholas Bellinger 	ooo_cmdsn->cmd			= cmd;
1093e48354ceSNicholas Bellinger 	ooo_cmdsn->batch_count		= (batch) ?
1094e48354ceSNicholas Bellinger 					  (cmdsn - sess->exp_cmd_sn) : 1;
1095e48354ceSNicholas Bellinger 	ooo_cmdsn->cid			= cmd->conn->cid;
1096e48354ceSNicholas Bellinger 	ooo_cmdsn->exp_cmdsn		= sess->exp_cmd_sn;
1097e48354ceSNicholas Bellinger 	ooo_cmdsn->cmdsn		= cmdsn;
1098e48354ceSNicholas Bellinger 
1099e48354ceSNicholas Bellinger 	if (iscsit_attach_ooo_cmdsn(sess, ooo_cmdsn) < 0) {
1100e48354ceSNicholas Bellinger 		kmem_cache_free(lio_ooo_cache, ooo_cmdsn);
1101561bf158SNicholas Bellinger 		return -ENOMEM;
1102e48354ceSNicholas Bellinger 	}
1103e48354ceSNicholas Bellinger 
1104561bf158SNicholas Bellinger 	return 0;
1105e48354ceSNicholas Bellinger }
1106e48354ceSNicholas Bellinger 
1107e48354ceSNicholas Bellinger static int iscsit_set_dataout_timeout_values(
1108e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
1109e48354ceSNicholas Bellinger 	u32 *offset,
1110e48354ceSNicholas Bellinger 	u32 *length)
1111e48354ceSNicholas Bellinger {
1112e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1113e48354ceSNicholas Bellinger 	struct iscsi_r2t *r2t;
1114e48354ceSNicholas Bellinger 
1115e48354ceSNicholas Bellinger 	if (cmd->unsolicited_data) {
1116e48354ceSNicholas Bellinger 		*offset = 0;
1117e48354ceSNicholas Bellinger 		*length = (conn->sess->sess_ops->FirstBurstLength >
1118ebf1d95cSAndy Grover 			   cmd->se_cmd.data_length) ?
1119ebf1d95cSAndy Grover 			   cmd->se_cmd.data_length :
1120e48354ceSNicholas Bellinger 			   conn->sess->sess_ops->FirstBurstLength;
1121e48354ceSNicholas Bellinger 		return 0;
1122e48354ceSNicholas Bellinger 	}
1123e48354ceSNicholas Bellinger 
1124e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->r2t_lock);
1125e48354ceSNicholas Bellinger 	if (list_empty(&cmd->cmd_r2t_list)) {
1126e48354ceSNicholas Bellinger 		pr_err("cmd->cmd_r2t_list is empty!\n");
1127e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->r2t_lock);
1128e48354ceSNicholas Bellinger 		return -1;
1129e48354ceSNicholas Bellinger 	}
1130e48354ceSNicholas Bellinger 
1131e48354ceSNicholas Bellinger 	list_for_each_entry(r2t, &cmd->cmd_r2t_list, r2t_list) {
1132e48354ceSNicholas Bellinger 		if (r2t->sent_r2t && !r2t->recovery_r2t && !r2t->seq_complete) {
1133e48354ceSNicholas Bellinger 			*offset = r2t->offset;
1134e48354ceSNicholas Bellinger 			*length = r2t->xfer_len;
1135e48354ceSNicholas Bellinger 			spin_unlock_bh(&cmd->r2t_lock);
1136e48354ceSNicholas Bellinger 			return 0;
1137e48354ceSNicholas Bellinger 		}
1138e48354ceSNicholas Bellinger 	}
1139e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->r2t_lock);
1140e48354ceSNicholas Bellinger 
1141e48354ceSNicholas Bellinger 	pr_err("Unable to locate any incomplete DataOUT"
1142e48354ceSNicholas Bellinger 		" sequences for ITT: 0x%08x.\n", cmd->init_task_tag);
1143e48354ceSNicholas Bellinger 
1144e48354ceSNicholas Bellinger 	return -1;
1145e48354ceSNicholas Bellinger }
1146e48354ceSNicholas Bellinger 
1147e48354ceSNicholas Bellinger /*
1148e48354ceSNicholas Bellinger  *	NOTE: Called from interrupt (timer) context.
1149e48354ceSNicholas Bellinger  */
1150e48354ceSNicholas Bellinger static void iscsit_handle_dataout_timeout(unsigned long data)
1151e48354ceSNicholas Bellinger {
1152e48354ceSNicholas Bellinger 	u32 pdu_length = 0, pdu_offset = 0;
1153e48354ceSNicholas Bellinger 	u32 r2t_length = 0, r2t_offset = 0;
1154e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = (struct iscsi_cmd *) data;
1155e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1156e48354ceSNicholas Bellinger 	struct iscsi_session *sess = NULL;
1157e48354ceSNicholas Bellinger 	struct iscsi_node_attrib *na;
1158e48354ceSNicholas Bellinger 
1159e48354ceSNicholas Bellinger 	iscsit_inc_conn_usage_count(conn);
1160e48354ceSNicholas Bellinger 
1161e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->dataout_timeout_lock);
1162e48354ceSNicholas Bellinger 	if (cmd->dataout_timer_flags & ISCSI_TF_STOP) {
1163e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->dataout_timeout_lock);
1164e48354ceSNicholas Bellinger 		iscsit_dec_conn_usage_count(conn);
1165e48354ceSNicholas Bellinger 		return;
1166e48354ceSNicholas Bellinger 	}
1167e48354ceSNicholas Bellinger 	cmd->dataout_timer_flags &= ~ISCSI_TF_RUNNING;
1168e48354ceSNicholas Bellinger 	sess = conn->sess;
1169e48354ceSNicholas Bellinger 	na = iscsit_tpg_get_node_attrib(sess);
1170e48354ceSNicholas Bellinger 
1171e48354ceSNicholas Bellinger 	if (!sess->sess_ops->ErrorRecoveryLevel) {
1172e48354ceSNicholas Bellinger 		pr_debug("Unable to recover from DataOut timeout while"
1173e48354ceSNicholas Bellinger 			" in ERL=0.\n");
1174e48354ceSNicholas Bellinger 		goto failure;
1175e48354ceSNicholas Bellinger 	}
1176e48354ceSNicholas Bellinger 
1177e48354ceSNicholas Bellinger 	if (++cmd->dataout_timeout_retries == na->dataout_timeout_retries) {
1178e48354ceSNicholas Bellinger 		pr_debug("Command ITT: 0x%08x exceeded max retries"
1179e48354ceSNicholas Bellinger 			" for DataOUT timeout %u, closing iSCSI connection.\n",
1180e48354ceSNicholas Bellinger 			cmd->init_task_tag, na->dataout_timeout_retries);
1181e48354ceSNicholas Bellinger 		goto failure;
1182e48354ceSNicholas Bellinger 	}
1183e48354ceSNicholas Bellinger 
1184e48354ceSNicholas Bellinger 	cmd->cmd_flags |= ICF_WITHIN_COMMAND_RECOVERY;
1185e48354ceSNicholas Bellinger 
1186e48354ceSNicholas Bellinger 	if (conn->sess->sess_ops->DataSequenceInOrder) {
1187e48354ceSNicholas Bellinger 		if (conn->sess->sess_ops->DataPDUInOrder) {
1188e48354ceSNicholas Bellinger 			pdu_offset = cmd->write_data_done;
1189e48354ceSNicholas Bellinger 			if ((pdu_offset + (conn->sess->sess_ops->MaxBurstLength -
1190ebf1d95cSAndy Grover 			     cmd->next_burst_len)) > cmd->se_cmd.data_length)
1191ebf1d95cSAndy Grover 				pdu_length = (cmd->se_cmd.data_length -
1192e48354ceSNicholas Bellinger 					cmd->write_data_done);
1193e48354ceSNicholas Bellinger 			else
1194e48354ceSNicholas Bellinger 				pdu_length = (conn->sess->sess_ops->MaxBurstLength -
1195e48354ceSNicholas Bellinger 						cmd->next_burst_len);
1196e48354ceSNicholas Bellinger 		} else {
1197e48354ceSNicholas Bellinger 			pdu_offset = cmd->seq_start_offset;
1198e48354ceSNicholas Bellinger 			pdu_length = (cmd->seq_end_offset -
1199e48354ceSNicholas Bellinger 				cmd->seq_start_offset);
1200e48354ceSNicholas Bellinger 		}
1201e48354ceSNicholas Bellinger 	} else {
1202e48354ceSNicholas Bellinger 		if (iscsit_set_dataout_timeout_values(cmd, &pdu_offset,
1203e48354ceSNicholas Bellinger 				&pdu_length) < 0)
1204e48354ceSNicholas Bellinger 			goto failure;
1205e48354ceSNicholas Bellinger 	}
1206e48354ceSNicholas Bellinger 
1207e48354ceSNicholas Bellinger 	if (iscsit_recalculate_dataout_values(cmd, pdu_offset, pdu_length,
1208e48354ceSNicholas Bellinger 			&r2t_offset, &r2t_length) < 0)
1209e48354ceSNicholas Bellinger 		goto failure;
1210e48354ceSNicholas Bellinger 
1211e48354ceSNicholas Bellinger 	pr_debug("Command ITT: 0x%08x timed out waiting for"
1212e48354ceSNicholas Bellinger 		" completion of %sDataOUT Sequence Offset: %u, Length: %u\n",
1213e48354ceSNicholas Bellinger 		cmd->init_task_tag, (cmd->unsolicited_data) ? "Unsolicited " :
1214e48354ceSNicholas Bellinger 		"", r2t_offset, r2t_length);
1215e48354ceSNicholas Bellinger 
1216e48354ceSNicholas Bellinger 	if (iscsit_send_recovery_r2t(cmd, r2t_offset, r2t_length) < 0)
1217e48354ceSNicholas Bellinger 		goto failure;
1218e48354ceSNicholas Bellinger 
1219e48354ceSNicholas Bellinger 	iscsit_start_dataout_timer(cmd, conn);
1220e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->dataout_timeout_lock);
1221e48354ceSNicholas Bellinger 	iscsit_dec_conn_usage_count(conn);
1222e48354ceSNicholas Bellinger 
1223e48354ceSNicholas Bellinger 	return;
1224e48354ceSNicholas Bellinger 
1225e48354ceSNicholas Bellinger failure:
1226e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->dataout_timeout_lock);
1227e48354ceSNicholas Bellinger 	iscsit_cause_connection_reinstatement(conn, 0);
1228e48354ceSNicholas Bellinger 	iscsit_dec_conn_usage_count(conn);
1229e48354ceSNicholas Bellinger }
1230e48354ceSNicholas Bellinger 
1231e48354ceSNicholas Bellinger void iscsit_mod_dataout_timer(struct iscsi_cmd *cmd)
1232e48354ceSNicholas Bellinger {
1233e48354ceSNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1234e48354ceSNicholas Bellinger 	struct iscsi_session *sess = conn->sess;
1235e8904dc5SJesper Juhl 	struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess);
1236e48354ceSNicholas Bellinger 
1237e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->dataout_timeout_lock);
1238e48354ceSNicholas Bellinger 	if (!(cmd->dataout_timer_flags & ISCSI_TF_RUNNING)) {
1239e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->dataout_timeout_lock);
1240e48354ceSNicholas Bellinger 		return;
1241e48354ceSNicholas Bellinger 	}
1242e48354ceSNicholas Bellinger 
1243e48354ceSNicholas Bellinger 	mod_timer(&cmd->dataout_timer,
1244e48354ceSNicholas Bellinger 		(get_jiffies_64() + na->dataout_timeout * HZ));
1245e48354ceSNicholas Bellinger 	pr_debug("Updated DataOUT timer for ITT: 0x%08x",
1246e48354ceSNicholas Bellinger 			cmd->init_task_tag);
1247e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->dataout_timeout_lock);
1248e48354ceSNicholas Bellinger }
1249e48354ceSNicholas Bellinger 
1250e48354ceSNicholas Bellinger /*
1251e48354ceSNicholas Bellinger  *	Called with cmd->dataout_timeout_lock held.
1252e48354ceSNicholas Bellinger  */
1253e48354ceSNicholas Bellinger void iscsit_start_dataout_timer(
1254e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd,
1255e48354ceSNicholas Bellinger 	struct iscsi_conn *conn)
1256e48354ceSNicholas Bellinger {
1257e48354ceSNicholas Bellinger 	struct iscsi_session *sess = conn->sess;
1258e8904dc5SJesper Juhl 	struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess);
1259e48354ceSNicholas Bellinger 
1260e48354ceSNicholas Bellinger 	if (cmd->dataout_timer_flags & ISCSI_TF_RUNNING)
1261e48354ceSNicholas Bellinger 		return;
1262e48354ceSNicholas Bellinger 
1263e48354ceSNicholas Bellinger 	pr_debug("Starting DataOUT timer for ITT: 0x%08x on"
1264e48354ceSNicholas Bellinger 		" CID: %hu.\n", cmd->init_task_tag, conn->cid);
1265e48354ceSNicholas Bellinger 
1266e48354ceSNicholas Bellinger 	init_timer(&cmd->dataout_timer);
1267e48354ceSNicholas Bellinger 	cmd->dataout_timer.expires = (get_jiffies_64() + na->dataout_timeout * HZ);
1268e48354ceSNicholas Bellinger 	cmd->dataout_timer.data = (unsigned long)cmd;
1269e48354ceSNicholas Bellinger 	cmd->dataout_timer.function = iscsit_handle_dataout_timeout;
1270e48354ceSNicholas Bellinger 	cmd->dataout_timer_flags &= ~ISCSI_TF_STOP;
1271e48354ceSNicholas Bellinger 	cmd->dataout_timer_flags |= ISCSI_TF_RUNNING;
1272e48354ceSNicholas Bellinger 	add_timer(&cmd->dataout_timer);
1273e48354ceSNicholas Bellinger }
1274e48354ceSNicholas Bellinger 
1275e48354ceSNicholas Bellinger void iscsit_stop_dataout_timer(struct iscsi_cmd *cmd)
1276e48354ceSNicholas Bellinger {
1277e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->dataout_timeout_lock);
1278e48354ceSNicholas Bellinger 	if (!(cmd->dataout_timer_flags & ISCSI_TF_RUNNING)) {
1279e48354ceSNicholas Bellinger 		spin_unlock_bh(&cmd->dataout_timeout_lock);
1280e48354ceSNicholas Bellinger 		return;
1281e48354ceSNicholas Bellinger 	}
1282e48354ceSNicholas Bellinger 	cmd->dataout_timer_flags |= ISCSI_TF_STOP;
1283e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->dataout_timeout_lock);
1284e48354ceSNicholas Bellinger 
1285e48354ceSNicholas Bellinger 	del_timer_sync(&cmd->dataout_timer);
1286e48354ceSNicholas Bellinger 
1287e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->dataout_timeout_lock);
1288e48354ceSNicholas Bellinger 	cmd->dataout_timer_flags &= ~ISCSI_TF_RUNNING;
1289e48354ceSNicholas Bellinger 	pr_debug("Stopped DataOUT Timer for ITT: 0x%08x\n",
1290e48354ceSNicholas Bellinger 			cmd->init_task_tag);
1291e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->dataout_timeout_lock);
1292e48354ceSNicholas Bellinger }
12933e1c81a9SNicholas Bellinger EXPORT_SYMBOL(iscsit_stop_dataout_timer);
1294