21 #include <linux/list.h>
37 #define OFFLOAD_BUF_SIZE 32768
49 int dump_padding_digest)
51 char *
buf, pad_bytes[4];
60 pr_err(
"Unable to allocate %u bytes for offload"
61 " buffer.\n", length);
66 while (offset < buf_len) {
68 (buf_len -
offset) : length;
82 if (!dump_padding_digest)
85 padding = ((-buf_len) & 3);
90 rx_got =
rx_data(conn, &iov, 1, padding);
91 if (rx_got != padding) {
118 static int iscsit_send_recovery_r2t_for_snack(
140 static int iscsit_handle_r2t_snack(
154 (begrun <= cmd->acked_data_sn)) {
155 pr_err(
"ITT: 0x%08x, R2T SNACK requesting"
156 " retransmission of R2TSN: 0x%08x to 0x%08x but already"
157 " acked to R2TSN: 0x%08x by TMR TASK_REASSIGN,"
167 if ((begrun + runlength) > cmd->
r2t_sn) {
168 pr_err(
"Command ITT: 0x%08x received R2T SNACK"
169 " with BegRun: 0x%08x, RunLength: 0x%08x, exceeds"
170 " current R2TSN: 0x%08x, protocol error.\n",
175 last_r2tsn = (begrun + runlength);
179 while (begrun < last_r2tsn) {
183 if (iscsit_send_recovery_r2t_for_snack(cmd, r2t) < 0)
204 u32 data_sn = 0, data_sn_count = 0;
209 while (begrun > data_sn++) {
212 conn->
conn_ops->MaxRecvDataSegmentLength) <
213 conn->
sess->sess_ops->MaxBurstLength) {
215 conn->
conn_ops->MaxRecvDataSegmentLength;
217 conn->
conn_ops->MaxRecvDataSegmentLength;
220 (conn->
sess->sess_ops->MaxBurstLength -
223 pdu_start += data_sn_count;
229 if (!conn->
sess->sess_ops->DataPDUInOrder) {
250 int found_seq = 0,
i;
251 u32 data_sn, read_data_done = 0, seq_send_order = 0;
258 pr_err(
"struct iscsi_cmd->seq_list is NULL!\n");
274 if (!seq->seq_send_order)
282 pr_err(
"Ignoring non-sent sequence 0x%08x ->"
283 " 0x%08x\n\n", seq->first_datasn,
293 if ((seq->first_datasn < begrun) &&
294 (seq->last_datasn < begrun)) {
295 pr_err(
"Pre BegRun sequence 0x%08x ->"
296 " 0x%08x\n", seq->first_datasn,
299 read_data_done += cmd->
seq_list[
i].xfer_len;
300 seq->next_burst_len = seq->pdu_send_order = 0;
307 if ((seq->first_datasn <= begrun) &&
308 (seq->last_datasn >= begrun)) {
309 pr_err(
"Found sequence begrun: 0x%08x in"
310 " 0x%08x -> 0x%08x\n", begrun,
311 seq->first_datasn, seq->last_datasn);
314 data_sn = seq->first_datasn;
315 seq->next_burst_len = seq->pdu_send_order = 0;
330 if (conn->
sess->sess_ops->DataPDUInOrder) {
331 while (data_sn < begrun) {
332 seq->pdu_send_order++;
334 conn->
conn_ops->MaxRecvDataSegmentLength;
335 seq->next_burst_len +=
336 conn->
conn_ops->MaxRecvDataSegmentLength;
343 while (data_sn < begrun) {
344 seq->pdu_send_order++;
346 for (j = 0; j < seq->pdu_count; j++) {
352 seq->next_burst_len +=
366 if ((seq->first_datasn > begrun) ||
367 (seq->last_datasn > begrun)) {
368 pr_err(
"Post BegRun sequence 0x%08x -> 0x%08x\n",
369 seq->first_datasn, seq->last_datasn);
371 seq->next_burst_len = seq->pdu_send_order = 0;
379 pr_err(
"ITT: 0x%08x, Begrun: 0x%08x"
380 " but first_seq is NULL\n",
385 seq->next_burst_len = seq->pdu_send_order = 0;
389 pr_err(
"Unable to locate struct iscsi_seq for ITT: 0x%08x,"
390 " BegRun: 0x%08x, RunLength: 0x%08x while"
391 " DataSequenceInOrder=No and DataPDUInOrder=%s.\n",
393 (conn->
sess->sess_ops->DataPDUInOrder) ?
"Yes" :
"No");
404 static int iscsit_handle_recovery_datain(
415 pr_err(
"Ignoring ITT: 0x%08x Data SNACK\n",
425 (begrun <= cmd->acked_data_sn)) {
426 pr_err(
"ITT: 0x%08x, Data SNACK requesting"
427 " retransmission of DataSN: 0x%08x to 0x%08x but"
428 " already acked to DataSN: 0x%08x by Data ACK SNACK,"
440 if ((begrun + runlength) > (cmd->
data_sn - 1)) {
441 pr_err(
"Initiator requesting BegRun: 0x%08x, RunLength"
442 ": 0x%08x greater than maximum DataSN: 0x%08x.\n",
443 begrun, runlength, (cmd->
data_sn - 1));
485 return iscsit_handle_r2t_snack(cmd, buf, begrun, runlength);
487 return iscsit_handle_recovery_datain(cmd, buf, begrun,
490 pr_err(
"Unknown cmd->data_direction: 0x%02x\n",
511 pr_err(
"Got Status SNACK Begrun: 0x%08x, RunLength:"
512 " 0x%08x but already got ExpStatSN: 0x%08x on CID:"
513 " %hu.\n", begrun, runlength, conn->
exp_statsn,
518 last_statsn = (!runlength) ? conn->
stat_sn : (begrun + runlength);
520 while (begrun < last_statsn) {
533 pr_err(
"Unable to find StatSN: 0x%08x for"
534 " a Status SNACK, assuming this was a"
535 " protactic SNACK for an untransmitted"
536 " StatSN, ignoring.\n", begrun);
544 pr_err(
"Ignoring Status SNACK for BegRun:"
545 " 0x%08x, RunLength: 0x%08x, assuming this was"
546 " a protactic SNACK for an untransmitted"
547 " StatSN\n", begrun, runlength);
571 pr_err(
"Data ACK SNACK for TTT: 0x%08x is"
572 " invalid.\n", targ_xfer_tag);
576 if (begrun <= cmd->acked_data_sn) {
577 pr_err(
"ITT: 0x%08x Data ACK SNACK BegRUN: 0x%08x is"
578 " less than the already acked DataSN: 0x%08x.\n",
590 pr_debug(
"Received Data ACK SNACK for ITT: 0x%08x,"
591 " updated acked DataSN to 0x%08x.\n",
597 static int iscsit_send_recovery_r2t(
615 int i, send_recovery_r2t = 0, recovery = 0;
624 if (conn->
sess->sess_ops->DataSequenceInOrder) {
631 }
else if (pdu_count)
650 if (!send_recovery_r2t)
653 if (iscsit_send_recovery_r2t(cmd,
offset, length) < 0)
656 send_recovery_r2t = length =
offset = 0;
677 send_recovery_r2t = 1;
680 if (send_recovery_r2t)
681 if (iscsit_send_recovery_r2t(cmd,
offset, length) < 0)
687 static int iscsit_recalculate_dataout_values(
698 if (conn->
sess->sess_ops->DataSequenceInOrder) {
701 if (conn->
sess->sess_ops->DataPDUInOrder) {
748 if (conn->
sess->sess_ops->DataPDUInOrder)
769 u32 r2t_length = 0, r2t_offset = 0;
775 if (iscsit_recalculate_dataout_values(cmd, pdu_offset, pdu_length,
776 &r2t_offset, &r2t_length) < 0)
779 iscsit_send_recovery_r2t(cmd, r2t_offset, r2t_length);
790 pr_err(
"Unable to allocate memory for"
791 " struct iscsi_ooo_cmdsn.\n");
794 INIT_LIST_HEAD(&ooo_cmdsn->
ooo_list);
802 static int iscsit_attach_ooo_cmdsn(
864 if (ooo_cmdsn->
cid != conn->
cid)
886 if (!ooo_cmdsn->
cmd) {
892 cmd = ooo_cmdsn->
cmd;
896 pr_debug(
"Executing out of order CmdSN: 0x%08x,"
897 " incremented ExpCmdSN to 0x%08x.\n",
921 struct se_cmd *se_cmd = &cmd->
se_cmd;
1038 pr_err(
"Unknown iSCSI Logout Request Code:"
1046 pr_err(
"Cannot perform out of order execution for"
1085 if (ooo_tail->cmdsn != (cmdsn - 1))
1089 ooo_cmdsn = iscsit_allocate_ooo_cmdsn();
1096 ooo_cmdsn->
cid = cmd->
conn->cid;
1100 if (iscsit_attach_ooo_cmdsn(sess, ooo_cmdsn) < 0) {
1108 static int iscsit_set_dataout_timeout_values(
1118 *length = (conn->
sess->sess_ops->FirstBurstLength >
1119 cmd->
se_cmd.data_length) ?
1120 cmd->
se_cmd.data_length :
1121 conn->
sess->sess_ops->FirstBurstLength;
1127 pr_err(
"cmd->cmd_r2t_list is empty!\n");
1142 pr_err(
"Unable to locate any incomplete DataOUT"
1151 static void iscsit_handle_dataout_timeout(
unsigned long data)
1153 u32 pdu_length = 0, pdu_offset = 0;
1154 u32 r2t_length = 0, r2t_offset = 0;
1172 if (!sess->
sess_ops->ErrorRecoveryLevel) {
1173 pr_debug(
"Unable to recover from DataOut timeout while"
1179 pr_debug(
"Command ITT: 0x%08x exceeded max retries"
1180 " for DataOUT timeout %u, closing iSCSI connection.\n",
1187 if (conn->
sess->sess_ops->DataSequenceInOrder) {
1188 if (conn->
sess->sess_ops->DataPDUInOrder) {
1190 if ((pdu_offset + (conn->
sess->sess_ops->MaxBurstLength -
1192 pdu_length = (cmd->
se_cmd.data_length -
1195 pdu_length = (conn->
sess->sess_ops->MaxBurstLength -
1203 if (iscsit_set_dataout_timeout_values(cmd, &pdu_offset,
1208 if (iscsit_recalculate_dataout_values(cmd, pdu_offset, pdu_length,
1209 &r2t_offset, &r2t_length) < 0)
1212 pr_debug(
"Command ITT: 0x%08x timed out waiting for"
1213 " completion of %sDataOUT Sequence Offset: %u, Length: %u\n",
1215 "", r2t_offset, r2t_length);
1217 if (iscsit_send_recovery_r2t(cmd, r2t_offset, r2t_length) < 0)
1246 pr_debug(
"Updated DataOUT timer for ITT: 0x%08x",
1264 pr_debug(
"Starting DataOUT timer for ITT: 0x%08x on"
1270 cmd->
dataout_timer.function = iscsit_handle_dataout_timeout;
1290 pr_debug(
"Stopped DataOUT Timer for ITT: 0x%08x\n",