| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/******************************************************************************* |
| 3 |
* This file contains the iSCSI Target specific Task Management functions. |
| 4 |
* |
| 5 |
* (c) Copyright 2007-2013 Datera, Inc. |
| 6 |
* |
| 7 |
* Author: Nicholas A. Bellinger <[email protected]> |
| 8 |
* |
| 9 |
******************************************************************************/ |
| 10 |
|
| 11 |
#include <linux/unaligned.h> |
| 12 |
#include <scsi/scsi_proto.h> |
| 13 |
#include <scsi/iscsi_proto.h> |
| 14 |
#include <target/target_core_base.h> |
| 15 |
#include <target/target_core_fabric.h> |
| 16 |
#include <target/iscsi/iscsi_transport.h> |
| 17 |
|
| 18 |
#include <target/iscsi/iscsi_target_core.h> |
| 19 |
#include "iscsi_target_seq_pdu_list.h" |
| 20 |
#include "iscsi_target_datain_values.h" |
| 21 |
#include "iscsi_target_device.h" |
| 22 |
#include "iscsi_target_erl0.h" |
| 23 |
#include "iscsi_target_erl1.h" |
| 24 |
#include "iscsi_target_erl2.h" |
| 25 |
#include "iscsi_target_tmr.h" |
| 26 |
#include "iscsi_target_tpg.h" |
| 27 |
#include "iscsi_target_util.h" |
| 28 |
#include "iscsi_target.h" |
| 29 |
|
| 30 |
u8 iscsit_tmr_abort_task( |
| 31 |
struct iscsit_cmd *cmd, |
| 32 |
unsigned char *buf) |
| 33 |
{ |
| 34 |
struct iscsit_cmd *ref_cmd; |
| 35 |
struct iscsit_conn *conn = cmd->conn; |
| 36 |
struct iscsi_tmr_req *tmr_req = cmd->tmr_req; |
| 37 |
struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; |
| 38 |
struct iscsi_tm *hdr = (struct iscsi_tm *) buf; |
| 39 |
|
| 40 |
ref_cmd = iscsit_find_cmd_from_itt(conn, hdr->rtt); |
| 41 |
if (!ref_cmd) { |
| 42 |
pr_err("Unable to locate RefTaskTag: 0x%08x on CID:" |
| 43 |
" %hu.\n", hdr->rtt, conn->cid); |
| 44 |
return (iscsi_sna_gte(be32_to_cpu(hdr->refcmdsn), conn->sess->exp_cmd_sn) && |
| 45 |
iscsi_sna_lte(be32_to_cpu(hdr->refcmdsn), (u32) atomic_read(&conn->sess->max_cmd_sn))) ? |
| 46 |
ISCSI_TMF_RSP_COMPLETE : ISCSI_TMF_RSP_NO_TASK; |
| 47 |
} |
| 48 |
if (ref_cmd->cmd_sn != be32_to_cpu(hdr->refcmdsn)) { |
| 49 |
pr_err("RefCmdSN 0x%08x does not equal" |
| 50 |
" task's CmdSN 0x%08x. Rejecting ABORT_TASK.\n", |
| 51 |
hdr->refcmdsn, ref_cmd->cmd_sn); |
| 52 |
return ISCSI_TMF_RSP_REJECTED; |
| 53 |
} |
| 54 |
|
| 55 |
se_tmr->ref_task_tag = (__force u32)hdr->rtt; |
| 56 |
tmr_req->ref_cmd = ref_cmd; |
| 57 |
tmr_req->exp_data_sn = be32_to_cpu(hdr->exp_datasn); |
| 58 |
|
| 59 |
return ISCSI_TMF_RSP_COMPLETE; |
| 60 |
} |
| 61 |
|
| 62 |
/* |
| 63 |
* Called from iscsit_handle_task_mgt_cmd(). |
| 64 |
*/ |
| 65 |
int iscsit_tmr_task_warm_reset( |
| 66 |
struct iscsit_conn *conn, |
| 67 |
struct iscsi_tmr_req *tmr_req, |
| 68 |
unsigned char *buf) |
| 69 |
{ |
| 70 |
struct iscsit_session *sess = conn->sess; |
| 71 |
struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess); |
| 72 |
|
| 73 |
if (!na->tmr_warm_reset) { |
| 74 |
pr_err("TMR Opcode TARGET_WARM_RESET authorization" |
| 75 |
" failed for Initiator Node: %s\n", |
| 76 |
sess->se_sess->se_node_acl->initiatorname); |
| 77 |
return -1; |
| 78 |
} |
| 79 |
/* |
| 80 |
* Do the real work in transport_generic_do_tmr(). |
| 81 |
*/ |
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
int iscsit_tmr_task_cold_reset( |
| 86 |
struct iscsit_conn *conn, |
| 87 |
struct iscsi_tmr_req *tmr_req, |
| 88 |
unsigned char *buf) |
| 89 |
{ |
| 90 |
struct iscsit_session *sess = conn->sess; |
| 91 |
struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess); |
| 92 |
|
| 93 |
if (!na->tmr_cold_reset) { |
| 94 |
pr_err("TMR Opcode TARGET_COLD_RESET authorization" |
| 95 |
" failed for Initiator Node: %s\n", |
| 96 |
sess->se_sess->se_node_acl->initiatorname); |
| 97 |
return -1; |
| 98 |
} |
| 99 |
/* |
| 100 |
* Do the real work in transport_generic_do_tmr(). |
| 101 |
*/ |
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
u8 iscsit_tmr_task_reassign( |
| 106 |
struct iscsit_cmd *cmd, |
| 107 |
unsigned char *buf) |
| 108 |
{ |
| 109 |
struct iscsit_cmd *ref_cmd = NULL; |
| 110 |
struct iscsit_conn *conn = cmd->conn; |
| 111 |
struct iscsi_conn_recovery *cr = NULL; |
| 112 |
struct iscsi_tmr_req *tmr_req = cmd->tmr_req; |
| 113 |
struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; |
| 114 |
struct iscsi_tm *hdr = (struct iscsi_tm *) buf; |
| 115 |
u64 ref_lun; |
| 116 |
int ret; |
| 117 |
|
| 118 |
pr_debug("Got TASK_REASSIGN TMR ITT: 0x%08x," |
| 119 |
" RefTaskTag: 0x%08x, ExpDataSN: 0x%08x, CID: %hu\n", |
| 120 |
hdr->itt, hdr->rtt, hdr->exp_datasn, conn->cid); |
| 121 |
|
| 122 |
if (conn->sess->sess_ops->ErrorRecoveryLevel != 2) { |
| 123 |
pr_err("TMR TASK_REASSIGN not supported in ERL<2," |
| 124 |
" ignoring request.\n"); |
| 125 |
return ISCSI_TMF_RSP_NOT_SUPPORTED; |
| 126 |
} |
| 127 |
|
| 128 |
ret = iscsit_find_cmd_for_recovery(conn->sess, &ref_cmd, &cr, hdr->rtt); |
| 129 |
if (ret == -2) { |
| 130 |
pr_err("Command ITT: 0x%08x is still alligent to CID:" |
| 131 |
" %hu\n", ref_cmd->init_task_tag, cr->cid); |
| 132 |
return ISCSI_TMF_RSP_TASK_ALLEGIANT; |
| 133 |
} else if (ret == -1) { |
| 134 |
pr_err("Unable to locate RefTaskTag: 0x%08x in" |
| 135 |
" connection recovery command list.\n", hdr->rtt); |
| 136 |
return ISCSI_TMF_RSP_NO_TASK; |
| 137 |
} |
| 138 |
/* |
| 139 |
* Temporary check to prevent connection recovery for |
| 140 |
* connections with a differing Max*DataSegmentLength. |
| 141 |
*/ |
| 142 |
if (cr->maxrecvdatasegmentlength != |
| 143 |
conn->conn_ops->MaxRecvDataSegmentLength) { |
| 144 |
pr_err("Unable to perform connection recovery for" |
| 145 |
" differing MaxRecvDataSegmentLength, rejecting" |
| 146 |
" TMR TASK_REASSIGN.\n"); |
| 147 |
return ISCSI_TMF_RSP_REJECTED; |
| 148 |
} |
| 149 |
if (cr->maxxmitdatasegmentlength != |
| 150 |
conn->conn_ops->MaxXmitDataSegmentLength) { |
| 151 |
pr_err("Unable to perform connection recovery for" |
| 152 |
" differing MaxXmitDataSegmentLength, rejecting" |
| 153 |
" TMR TASK_REASSIGN.\n"); |
| 154 |
return ISCSI_TMF_RSP_REJECTED; |
| 155 |
} |
| 156 |
|
| 157 |
ref_lun = scsilun_to_int(&hdr->lun); |
| 158 |
if (ref_lun != ref_cmd->se_cmd.orig_fe_lun) { |
| 159 |
pr_err("Unable to perform connection recovery for" |
| 160 |
" differing ref_lun: %llu ref_cmd orig_fe_lun: %llu\n", |
| 161 |
ref_lun, ref_cmd->se_cmd.orig_fe_lun); |
| 162 |
return ISCSI_TMF_RSP_REJECTED; |
| 163 |
} |
| 164 |
|
| 165 |
se_tmr->ref_task_tag = (__force u32)hdr->rtt; |
| 166 |
tmr_req->ref_cmd = ref_cmd; |
| 167 |
tmr_req->exp_data_sn = be32_to_cpu(hdr->exp_datasn); |
| 168 |
tmr_req->conn_recovery = cr; |
| 169 |
tmr_req->task_reassign = 1; |
| 170 |
/* |
| 171 |
* Command can now be reassigned to a new connection. |
| 172 |
* The task management response must be sent before the |
| 173 |
* reassignment actually happens. See iscsi_tmr_post_handler(). |
| 174 |
*/ |
| 175 |
return ISCSI_TMF_RSP_COMPLETE; |
| 176 |
} |
| 177 |
|
| 178 |
static void iscsit_task_reassign_remove_cmd( |
| 179 |
struct iscsit_cmd *cmd, |
| 180 |
struct iscsi_conn_recovery *cr, |
| 181 |
struct iscsit_session *sess) |
| 182 |
{ |
| 183 |
int ret; |
| 184 |
|
| 185 |
spin_lock(&cr->conn_recovery_cmd_lock); |
| 186 |
ret = iscsit_remove_cmd_from_connection_recovery(cmd, sess); |
| 187 |
spin_unlock(&cr->conn_recovery_cmd_lock); |
| 188 |
if (!ret) { |
| 189 |
pr_debug("iSCSI connection recovery successful for CID:" |
| 190 |
" %hu on SID: %u\n", cr->cid, sess->sid); |
| 191 |
iscsit_remove_active_connection_recovery_entry(cr, sess); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
static int iscsit_task_reassign_complete_nop_out( |
| 196 |
struct iscsi_tmr_req *tmr_req, |
| 197 |
struct iscsit_conn *conn) |
| 198 |
{ |
| 199 |
struct iscsit_cmd *cmd = tmr_req->ref_cmd; |
| 200 |
struct iscsi_conn_recovery *cr; |
| 201 |
|
| 202 |
if (!cmd->cr) { |
| 203 |
pr_err("struct iscsi_conn_recovery pointer for ITT: 0x%08x" |
| 204 |
" is NULL!\n", cmd->init_task_tag); |
| 205 |
return -1; |
| 206 |
} |
| 207 |
cr = cmd->cr; |
| 208 |
|
| 209 |
/* |
| 210 |
* Reset the StatSN so a new one for this commands new connection |
| 211 |
* will be assigned. |
| 212 |
* Reset the ExpStatSN as well so we may receive Status SNACKs. |
| 213 |
*/ |
| 214 |
cmd->stat_sn = cmd->exp_stat_sn = 0; |
| 215 |
|
| 216 |
iscsit_task_reassign_remove_cmd(cmd, cr, conn->sess); |
| 217 |
|
| 218 |
spin_lock_bh(&conn->cmd_lock); |
| 219 |
list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); |
| 220 |
spin_unlock_bh(&conn->cmd_lock); |
| 221 |
|
| 222 |
cmd->i_state = ISTATE_SEND_NOPIN; |
| 223 |
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
| 224 |
return 0; |
| 225 |
} |
| 226 |
|
| 227 |
static int iscsit_task_reassign_complete_write( |
| 228 |
struct iscsit_cmd *cmd, |
| 229 |
struct iscsi_tmr_req *tmr_req) |
| 230 |
{ |
| 231 |
int no_build_r2ts = 0; |
| 232 |
u32 length = 0, offset = 0; |
| 233 |
struct iscsit_conn *conn = cmd->conn; |
| 234 |
struct se_cmd *se_cmd = &cmd->se_cmd; |
| 235 |
/* |
| 236 |
* The Initiator must not send a R2T SNACK with a Begrun less than |
| 237 |
* the TMR TASK_REASSIGN's ExpDataSN. |
| 238 |
*/ |
| 239 |
if (!tmr_req->exp_data_sn) { |
| 240 |
cmd->cmd_flags &= ~ICF_GOT_DATACK_SNACK; |
| 241 |
cmd->acked_data_sn = 0; |
| 242 |
} else { |
| 243 |
cmd->cmd_flags |= ICF_GOT_DATACK_SNACK; |
| 244 |
cmd->acked_data_sn = (tmr_req->exp_data_sn - 1); |
| 245 |
} |
| 246 |
|
| 247 |
/* |
| 248 |
* The TMR TASK_REASSIGN's ExpDataSN contains the next R2TSN the |
| 249 |
* Initiator is expecting. The Target controls all WRITE operations |
| 250 |
* so if we have received all DataOUT we can safety ignore Initiator. |
| 251 |
*/ |
| 252 |
if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) { |
| 253 |
if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) { |
| 254 |
pr_debug("WRITE ITT: 0x%08x: t_state: %d" |
| 255 |
" never sent to transport\n", |
| 256 |
cmd->init_task_tag, cmd->se_cmd.t_state); |
| 257 |
target_execute_cmd(se_cmd); |
| 258 |
return 0; |
| 259 |
} |
| 260 |
|
| 261 |
cmd->i_state = ISTATE_SEND_STATUS; |
| 262 |
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
| 263 |
return 0; |
| 264 |
} |
| 265 |
|
| 266 |
/* |
| 267 |
* Special case to deal with DataSequenceInOrder=No and Non-Immeidate |
| 268 |
* Unsolicited DataOut. |
| 269 |
*/ |
| 270 |
if (cmd->unsolicited_data) { |
| 271 |
cmd->unsolicited_data = 0; |
| 272 |
|
| 273 |
offset = cmd->next_burst_len = cmd->write_data_done; |
| 274 |
|
| 275 |
if ((conn->sess->sess_ops->FirstBurstLength - offset) >= |
| 276 |
cmd->se_cmd.data_length) { |
| 277 |
no_build_r2ts = 1; |
| 278 |
length = (cmd->se_cmd.data_length - offset); |
| 279 |
} else |
| 280 |
length = (conn->sess->sess_ops->FirstBurstLength - offset); |
| 281 |
|
| 282 |
spin_lock_bh(&cmd->r2t_lock); |
| 283 |
if (iscsit_add_r2t_to_list(cmd, offset, length, 0, 0) < 0) { |
| 284 |
spin_unlock_bh(&cmd->r2t_lock); |
| 285 |
return -1; |
| 286 |
} |
| 287 |
cmd->outstanding_r2ts++; |
| 288 |
spin_unlock_bh(&cmd->r2t_lock); |
| 289 |
|
| 290 |
if (no_build_r2ts) |
| 291 |
return 0; |
| 292 |
} |
| 293 |
/* |
| 294 |
* iscsit_build_r2ts_for_cmd() can handle the rest from here. |
| 295 |
*/ |
| 296 |
return conn->conn_transport->iscsit_get_dataout(conn, cmd, true); |
| 297 |
} |
| 298 |
|
| 299 |
static int iscsit_task_reassign_complete_read( |
| 300 |
struct iscsit_cmd *cmd, |
| 301 |
struct iscsi_tmr_req *tmr_req) |
| 302 |
{ |
| 303 |
struct iscsit_conn *conn = cmd->conn; |
| 304 |
struct iscsi_datain_req *dr; |
| 305 |
struct se_cmd *se_cmd = &cmd->se_cmd; |
| 306 |
/* |
| 307 |
* The Initiator must not send a Data SNACK with a BegRun less than |
| 308 |
* the TMR TASK_REASSIGN's ExpDataSN. |
| 309 |
*/ |
| 310 |
if (!tmr_req->exp_data_sn) { |
| 311 |
cmd->cmd_flags &= ~ICF_GOT_DATACK_SNACK; |
| 312 |
cmd->acked_data_sn = 0; |
| 313 |
} else { |
| 314 |
cmd->cmd_flags |= ICF_GOT_DATACK_SNACK; |
| 315 |
cmd->acked_data_sn = (tmr_req->exp_data_sn - 1); |
| 316 |
} |
| 317 |
|
| 318 |
if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) { |
| 319 |
pr_debug("READ ITT: 0x%08x: t_state: %d never sent to" |
| 320 |
" transport\n", cmd->init_task_tag, |
| 321 |
cmd->se_cmd.t_state); |
| 322 |
target_submit(se_cmd); |
| 323 |
return 0; |
| 324 |
} |
| 325 |
|
| 326 |
if (!(se_cmd->transport_state & CMD_T_COMPLETE)) { |
| 327 |
pr_err("READ ITT: 0x%08x: t_state: %d, never returned" |
| 328 |
" from transport\n", cmd->init_task_tag, |
| 329 |
cmd->se_cmd.t_state); |
| 330 |
return -1; |
| 331 |
} |
| 332 |
|
| 333 |
dr = iscsit_allocate_datain_req(); |
| 334 |
if (!dr) |
| 335 |
return -1; |
| 336 |
/* |
| 337 |
* The TMR TASK_REASSIGN's ExpDataSN contains the next DataSN the |
| 338 |
* Initiator is expecting. |
| 339 |
*/ |
| 340 |
dr->data_sn = dr->begrun = tmr_req->exp_data_sn; |
| 341 |
dr->runlength = 0; |
| 342 |
dr->generate_recovery_values = 1; |
| 343 |
dr->recovery = DATAIN_CONNECTION_RECOVERY; |
| 344 |
|
| 345 |
iscsit_attach_datain_req(cmd, dr); |
| 346 |
|
| 347 |
cmd->i_state = ISTATE_SEND_DATAIN; |
| 348 |
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
| 349 |
return 0; |
| 350 |
} |
| 351 |
|
| 352 |
static int iscsit_task_reassign_complete_none( |
| 353 |
struct iscsit_cmd *cmd, |
| 354 |
struct iscsi_tmr_req *tmr_req) |
| 355 |
{ |
| 356 |
struct iscsit_conn *conn = cmd->conn; |
| 357 |
|
| 358 |
cmd->i_state = ISTATE_SEND_STATUS; |
| 359 |
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
| 360 |
return 0; |
| 361 |
} |
| 362 |
|
| 363 |
static int iscsit_task_reassign_complete_scsi_cmnd( |
| 364 |
struct iscsi_tmr_req *tmr_req, |
| 365 |
struct iscsit_conn *conn) |
| 366 |
{ |
| 367 |
struct iscsit_cmd *cmd = tmr_req->ref_cmd; |
| 368 |
struct iscsi_conn_recovery *cr; |
| 369 |
|
| 370 |
if (!cmd->cr) { |
| 371 |
pr_err("struct iscsi_conn_recovery pointer for ITT: 0x%08x" |
| 372 |
" is NULL!\n", cmd->init_task_tag); |
| 373 |
return -1; |
| 374 |
} |
| 375 |
cr = cmd->cr; |
| 376 |
|
| 377 |
/* |
| 378 |
* Reset the StatSN so a new one for this commands new connection |
| 379 |
* will be assigned. |
| 380 |
* Reset the ExpStatSN as well so we may receive Status SNACKs. |
| 381 |
*/ |
| 382 |
cmd->stat_sn = cmd->exp_stat_sn = 0; |
| 383 |
|
| 384 |
iscsit_task_reassign_remove_cmd(cmd, cr, conn->sess); |
| 385 |
|
| 386 |
spin_lock_bh(&conn->cmd_lock); |
| 387 |
list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); |
| 388 |
spin_unlock_bh(&conn->cmd_lock); |
| 389 |
|
| 390 |
if (cmd->se_cmd.se_cmd_flags & SCF_SENT_CHECK_CONDITION) { |
| 391 |
cmd->i_state = ISTATE_SEND_STATUS; |
| 392 |
iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
| 393 |
return 0; |
| 394 |
} |
| 395 |
|
| 396 |
switch (cmd->data_direction) { |
| 397 |
case DMA_TO_DEVICE: |
| 398 |
return iscsit_task_reassign_complete_write(cmd, tmr_req); |
| 399 |
case DMA_FROM_DEVICE: |
| 400 |
return iscsit_task_reassign_complete_read(cmd, tmr_req); |
| 401 |
case DMA_NONE: |
| 402 |
return iscsit_task_reassign_complete_none(cmd, tmr_req); |
| 403 |
default: |
| 404 |
pr_err("Unknown cmd->data_direction: 0x%02x\n", |
| 405 |
cmd->data_direction); |
| 406 |
return -1; |
| 407 |
} |
| 408 |
|
| 409 |
return 0; |
| 410 |
} |
| 411 |
|
| 412 |
static int iscsit_task_reassign_complete( |
| 413 |
struct iscsi_tmr_req *tmr_req, |
| 414 |
struct iscsit_conn *conn) |
| 415 |
{ |
| 416 |
struct iscsit_cmd *cmd; |
| 417 |
int ret = 0; |
| 418 |
|
| 419 |
if (!tmr_req->ref_cmd) { |
| 420 |
pr_err("TMR Request is missing a RefCmd struct iscsit_cmd.\n"); |
| 421 |
return -1; |
| 422 |
} |
| 423 |
cmd = tmr_req->ref_cmd; |
| 424 |
|
| 425 |
cmd->conn = conn; |
| 426 |
|
| 427 |
switch (cmd->iscsi_opcode) { |
| 428 |
case ISCSI_OP_NOOP_OUT: |
| 429 |
ret = iscsit_task_reassign_complete_nop_out(tmr_req, conn); |
| 430 |
break; |
| 431 |
case ISCSI_OP_SCSI_CMD: |
| 432 |
ret = iscsit_task_reassign_complete_scsi_cmnd(tmr_req, conn); |
| 433 |
break; |
| 434 |
default: |
| 435 |
pr_err("Illegal iSCSI Opcode 0x%02x during" |
| 436 |
" command reallegiance\n", cmd->iscsi_opcode); |
| 437 |
return -1; |
| 438 |
} |
| 439 |
|
| 440 |
if (ret != 0) |
| 441 |
return ret; |
| 442 |
|
| 443 |
pr_debug("Completed connection reallegiance for Opcode: 0x%02x," |
| 444 |
" ITT: 0x%08x to CID: %hu.\n", cmd->iscsi_opcode, |
| 445 |
cmd->init_task_tag, conn->cid); |
| 446 |
|
| 447 |
return 0; |
| 448 |
} |
| 449 |
|
| 450 |
/* |
| 451 |
* Handles special after-the-fact actions related to TMRs. |
| 452 |
* Right now the only one that its really needed for is |
| 453 |
* connection recovery releated TASK_REASSIGN. |
| 454 |
*/ |
| 455 |
int iscsit_tmr_post_handler(struct iscsit_cmd *cmd, struct iscsit_conn *conn) |
| 456 |
{ |
| 457 |
struct iscsi_tmr_req *tmr_req = cmd->tmr_req; |
| 458 |
struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; |
| 459 |
|
| 460 |
if (tmr_req->task_reassign && |
| 461 |
(se_tmr->response == ISCSI_TMF_RSP_COMPLETE)) |
| 462 |
return iscsit_task_reassign_complete(tmr_req, conn); |
| 463 |
|
| 464 |
return 0; |
| 465 |
} |
| 466 |
EXPORT_SYMBOL(iscsit_tmr_post_handler); |
| 467 |
|
| 468 |
/* |
| 469 |
* Nothing to do here, but leave it for good measure. :-) |
| 470 |
*/ |
| 471 |
static int iscsit_task_reassign_prepare_read( |
| 472 |
struct iscsi_tmr_req *tmr_req, |
| 473 |
struct iscsit_conn *conn) |
| 474 |
{ |
| 475 |
return 0; |
| 476 |
} |
| 477 |
|
| 478 |
static void iscsit_task_reassign_prepare_unsolicited_dataout( |
| 479 |
struct iscsit_cmd *cmd, |
| 480 |
struct iscsit_conn *conn) |
| 481 |
{ |
| 482 |
int i, j; |
| 483 |
struct iscsi_pdu *pdu = NULL; |
| 484 |
struct iscsi_seq *seq = NULL; |
| 485 |
|
| 486 |
if (conn->sess->sess_ops->DataSequenceInOrder) { |
| 487 |
cmd->data_sn = 0; |
| 488 |
|
| 489 |
if (cmd->immediate_data) |
| 490 |
cmd->r2t_offset += (cmd->first_burst_len - |
| 491 |
cmd->seq_start_offset); |
| 492 |
|
| 493 |
if (conn->sess->sess_ops->DataPDUInOrder) { |
| 494 |
cmd->write_data_done -= (cmd->immediate_data) ? |
| 495 |
(cmd->first_burst_len - |
| 496 |
cmd->seq_start_offset) : |
| 497 |
cmd->first_burst_len; |
| 498 |
cmd->first_burst_len = 0; |
| 499 |
return; |
| 500 |
} |
| 501 |
|
| 502 |
for (i = 0; i < cmd->pdu_count; i++) { |
| 503 |
pdu = &cmd->pdu_list[i]; |
| 504 |
|
| 505 |
if (pdu->status != ISCSI_PDU_RECEIVED_OK) |
| 506 |
continue; |
| 507 |
|
| 508 |
if ((pdu->offset >= cmd->seq_start_offset) && |
| 509 |
((pdu->offset + pdu->length) <= |
| 510 |
cmd->seq_end_offset)) { |
| 511 |
cmd->first_burst_len -= pdu->length; |
| 512 |
cmd->write_data_done -= pdu->length; |
| 513 |
pdu->status = ISCSI_PDU_NOT_RECEIVED; |
| 514 |
} |
| 515 |
} |
| 516 |
} else { |
| 517 |
for (i = 0; i < cmd->seq_count; i++) { |
| 518 |
seq = &cmd->seq_list[i]; |
| 519 |
|
| 520 |
if (seq->type != SEQTYPE_UNSOLICITED) |
| 521 |
continue; |
| 522 |
|
| 523 |
cmd->write_data_done -= |
| 524 |
(seq->offset - seq->orig_offset); |
| 525 |
cmd->first_burst_len = 0; |
| 526 |
seq->data_sn = 0; |
| 527 |
seq->offset = seq->orig_offset; |
| 528 |
seq->next_burst_len = 0; |
| 529 |
seq->status = DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY; |
| 530 |
|
| 531 |
if (conn->sess->sess_ops->DataPDUInOrder) |
| 532 |
continue; |
| 533 |
|
| 534 |
for (j = 0; j < seq->pdu_count; j++) { |
| 535 |
pdu = &cmd->pdu_list[j+seq->pdu_start]; |
| 536 |
|
| 537 |
if (pdu->status != ISCSI_PDU_RECEIVED_OK) |
| 538 |
continue; |
| 539 |
|
| 540 |
pdu->status = ISCSI_PDU_NOT_RECEIVED; |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
static int iscsit_task_reassign_prepare_write( |
| 547 |
struct iscsi_tmr_req *tmr_req, |
| 548 |
struct iscsit_conn *conn) |
| 549 |
{ |
| 550 |
struct iscsit_cmd *cmd = tmr_req->ref_cmd; |
| 551 |
struct iscsi_pdu *pdu = NULL; |
| 552 |
struct iscsi_r2t *r2t = NULL, *r2t_tmp; |
| 553 |
int first_incomplete_r2t = 1, i = 0; |
| 554 |
|
| 555 |
/* |
| 556 |
* The command was in the process of receiving Unsolicited DataOUT when |
| 557 |
* the connection failed. |
| 558 |
*/ |
| 559 |
if (cmd->unsolicited_data) |
| 560 |
iscsit_task_reassign_prepare_unsolicited_dataout(cmd, conn); |
| 561 |
|
| 562 |
/* |
| 563 |
* The Initiator is requesting R2Ts starting from zero, skip |
| 564 |
* checking acknowledged R2Ts and start checking struct iscsi_r2ts |
| 565 |
* greater than zero. |
| 566 |
*/ |
| 567 |
if (!tmr_req->exp_data_sn) |
| 568 |
goto drop_unacknowledged_r2ts; |
| 569 |
|
| 570 |
/* |
| 571 |
* We now check that the PDUs in DataOUT sequences below |
| 572 |
* the TMR TASK_REASSIGN ExpDataSN (R2TSN the Initiator is |
| 573 |
* expecting next) have all the DataOUT they require to complete |
| 574 |
* the DataOUT sequence. First scan from R2TSN 0 to TMR |
| 575 |
* TASK_REASSIGN ExpDataSN-1. |
| 576 |
* |
| 577 |
* If we have not received all DataOUT in question, we must |
| 578 |
* make sure to make the appropriate changes to values in |
| 579 |
* struct iscsit_cmd (and elsewhere depending on session parameters) |
| 580 |
* so iscsit_build_r2ts_for_cmd() in iscsit_task_reassign_complete_write() |
| 581 |
* will resend a new R2T for the DataOUT sequences in question. |
| 582 |
*/ |
| 583 |
spin_lock_bh(&cmd->r2t_lock); |
| 584 |
if (list_empty(&cmd->cmd_r2t_list)) { |
| 585 |
spin_unlock_bh(&cmd->r2t_lock); |
| 586 |
return -1; |
| 587 |
} |
| 588 |
|
| 589 |
list_for_each_entry(r2t, &cmd->cmd_r2t_list, r2t_list) { |
| 590 |
|
| 591 |
if (r2t->r2t_sn >= tmr_req->exp_data_sn) |
| 592 |
continue; |
| 593 |
/* |
| 594 |
* Safely ignore Recovery R2Ts and R2Ts that have completed |
| 595 |
* DataOUT sequences. |
| 596 |
*/ |
| 597 |
if (r2t->seq_complete) |
| 598 |
continue; |
| 599 |
|
| 600 |
if (r2t->recovery_r2t) |
| 601 |
continue; |
| 602 |
|
| 603 |
/* |
| 604 |
* DataSequenceInOrder=Yes: |
| 605 |
* |
| 606 |
* Taking into account the iSCSI implementation requirement of |
| 607 |
* MaxOutstandingR2T=1 while ErrorRecoveryLevel>0 and |
| 608 |
* DataSequenceInOrder=Yes, we must take into consideration |
| 609 |
* the following: |
| 610 |
* |
| 611 |
* DataSequenceInOrder=No: |
| 612 |
* |
| 613 |
* Taking into account that the Initiator controls the (possibly |
| 614 |
* random) PDU Order in (possibly random) Sequence Order of |
| 615 |
* DataOUT the target requests with R2Ts, we must take into |
| 616 |
* consideration the following: |
| 617 |
* |
| 618 |
* DataPDUInOrder=Yes for DataSequenceInOrder=[Yes,No]: |
| 619 |
* |
| 620 |
* While processing non-complete R2T DataOUT sequence requests |
| 621 |
* the Target will re-request only the total sequence length |
| 622 |
* minus current received offset. This is because we must |
| 623 |
* assume the initiator will continue sending DataOUT from the |
| 624 |
* last PDU before the connection failed. |
| 625 |
* |
| 626 |
* DataPDUInOrder=No for DataSequenceInOrder=[Yes,No]: |
| 627 |
* |
| 628 |
* While processing non-complete R2T DataOUT sequence requests |
| 629 |
* the Target will re-request the entire DataOUT sequence if |
| 630 |
* any single PDU is missing from the sequence. This is because |
| 631 |
* we have no logical method to determine the next PDU offset, |
| 632 |
* and we must assume the Initiator will be sending any random |
| 633 |
* PDU offset in the current sequence after TASK_REASSIGN |
| 634 |
* has completed. |
| 635 |
*/ |
| 636 |
if (conn->sess->sess_ops->DataSequenceInOrder) { |
| 637 |
if (!first_incomplete_r2t) { |
| 638 |
cmd->r2t_offset -= r2t->xfer_len; |
| 639 |
goto next; |
| 640 |
} |
| 641 |
|
| 642 |
if (conn->sess->sess_ops->DataPDUInOrder) { |
| 643 |
cmd->data_sn = 0; |
| 644 |
cmd->r2t_offset -= (r2t->xfer_len - |
| 645 |
cmd->next_burst_len); |
| 646 |
first_incomplete_r2t = 0; |
| 647 |
goto next; |
| 648 |
} |
| 649 |
|
| 650 |
cmd->data_sn = 0; |
| 651 |
cmd->r2t_offset -= r2t->xfer_len; |
| 652 |
|
| 653 |
for (i = 0; i < cmd->pdu_count; i++) { |
| 654 |
pdu = &cmd->pdu_list[i]; |
| 655 |
|
| 656 |
if (pdu->status != ISCSI_PDU_RECEIVED_OK) |
| 657 |
continue; |
| 658 |
|
| 659 |
if ((pdu->offset >= r2t->offset) && |
| 660 |
(pdu->offset < (r2t->offset + |
| 661 |
r2t->xfer_len))) { |
| 662 |
cmd->next_burst_len -= pdu->length; |
| 663 |
cmd->write_data_done -= pdu->length; |
| 664 |
pdu->status = ISCSI_PDU_NOT_RECEIVED; |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
first_incomplete_r2t = 0; |
| 669 |
} else { |
| 670 |
struct iscsi_seq *seq; |
| 671 |
|
| 672 |
seq = iscsit_get_seq_holder(cmd, r2t->offset, |
| 673 |
r2t->xfer_len); |
| 674 |
if (!seq) { |
| 675 |
spin_unlock_bh(&cmd->r2t_lock); |
| 676 |
return -1; |
| 677 |
} |
| 678 |
|
| 679 |
cmd->write_data_done -= |
| 680 |
(seq->offset - seq->orig_offset); |
| 681 |
seq->data_sn = 0; |
| 682 |
seq->offset = seq->orig_offset; |
| 683 |
seq->next_burst_len = 0; |
| 684 |
seq->status = DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY; |
| 685 |
|
| 686 |
cmd->seq_send_order--; |
| 687 |
|
| 688 |
if (conn->sess->sess_ops->DataPDUInOrder) |
| 689 |
goto next; |
| 690 |
|
| 691 |
for (i = 0; i < seq->pdu_count; i++) { |
| 692 |
pdu = &cmd->pdu_list[i+seq->pdu_start]; |
| 693 |
|
| 694 |
if (pdu->status != ISCSI_PDU_RECEIVED_OK) |
| 695 |
continue; |
| 696 |
|
| 697 |
pdu->status = ISCSI_PDU_NOT_RECEIVED; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
next: |
| 702 |
cmd->outstanding_r2ts--; |
| 703 |
} |
| 704 |
spin_unlock_bh(&cmd->r2t_lock); |
| 705 |
|
| 706 |
/* |
| 707 |
* We now drop all unacknowledged R2Ts, ie: ExpDataSN from TMR |
| 708 |
* TASK_REASSIGN to the last R2T in the list.. We are also careful |
| 709 |
* to check that the Initiator is not requesting R2Ts for DataOUT |
| 710 |
* sequences it has already completed. |
| 711 |
* |
| 712 |
* Free each R2T in question and adjust values in struct iscsit_cmd |
| 713 |
* accordingly so iscsit_build_r2ts_for_cmd() do the rest of |
| 714 |
* the work after the TMR TASK_REASSIGN Response is sent. |
| 715 |
*/ |
| 716 |
drop_unacknowledged_r2ts: |
| 717 |
|
| 718 |
cmd->cmd_flags &= ~ICF_SENT_LAST_R2T; |
| 719 |
cmd->r2t_sn = tmr_req->exp_data_sn; |
| 720 |
|
| 721 |
spin_lock_bh(&cmd->r2t_lock); |
| 722 |
list_for_each_entry_safe(r2t, r2t_tmp, &cmd->cmd_r2t_list, r2t_list) { |
| 723 |
/* |
| 724 |
* Skip up to the R2T Sequence number provided by the |
| 725 |
* iSCSI TASK_REASSIGN TMR |
| 726 |
*/ |
| 727 |
if (r2t->r2t_sn < tmr_req->exp_data_sn) |
| 728 |
continue; |
| 729 |
|
| 730 |
if (r2t->seq_complete) { |
| 731 |
pr_err("Initiator is requesting R2Ts from" |
| 732 |
" R2TSN: 0x%08x, but R2TSN: 0x%08x, Offset: %u," |
| 733 |
" Length: %u is already complete." |
| 734 |
" BAD INITIATOR ERL=2 IMPLEMENTATION!\n", |
| 735 |
tmr_req->exp_data_sn, r2t->r2t_sn, |
| 736 |
r2t->offset, r2t->xfer_len); |
| 737 |
spin_unlock_bh(&cmd->r2t_lock); |
| 738 |
return -1; |
| 739 |
} |
| 740 |
|
| 741 |
if (r2t->recovery_r2t) { |
| 742 |
iscsit_free_r2t(r2t, cmd); |
| 743 |
continue; |
| 744 |
} |
| 745 |
|
| 746 |
/* DataSequenceInOrder=Yes: |
| 747 |
* |
| 748 |
* Taking into account the iSCSI implementation requirement of |
| 749 |
* MaxOutstandingR2T=1 while ErrorRecoveryLevel>0 and |
| 750 |
* DataSequenceInOrder=Yes, it's safe to subtract the R2Ts |
| 751 |
* entire transfer length from the commands R2T offset marker. |
| 752 |
* |
| 753 |
* DataSequenceInOrder=No: |
| 754 |
* |
| 755 |
* We subtract the difference from struct iscsi_seq between the |
| 756 |
* current offset and original offset from cmd->write_data_done |
| 757 |
* for account for DataOUT PDUs already received. Then reset |
| 758 |
* the current offset to the original and zero out the current |
| 759 |
* burst length, to make sure we re-request the entire DataOUT |
| 760 |
* sequence. |
| 761 |
*/ |
| 762 |
if (conn->sess->sess_ops->DataSequenceInOrder) |
| 763 |
cmd->r2t_offset -= r2t->xfer_len; |
| 764 |
else |
| 765 |
cmd->seq_send_order--; |
| 766 |
|
| 767 |
cmd->outstanding_r2ts--; |
| 768 |
iscsit_free_r2t(r2t, cmd); |
| 769 |
} |
| 770 |
spin_unlock_bh(&cmd->r2t_lock); |
| 771 |
|
| 772 |
return 0; |
| 773 |
} |
| 774 |
|
| 775 |
/* |
| 776 |
* Performs sanity checks TMR TASK_REASSIGN's ExpDataSN for |
| 777 |
* a given struct iscsit_cmd. |
| 778 |
*/ |
| 779 |
int iscsit_check_task_reassign_expdatasn( |
| 780 |
struct iscsi_tmr_req *tmr_req, |
| 781 |
struct iscsit_conn *conn) |
| 782 |
{ |
| 783 |
struct iscsit_cmd *ref_cmd = tmr_req->ref_cmd; |
| 784 |
|
| 785 |
if (ref_cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) |
| 786 |
return 0; |
| 787 |
|
| 788 |
if (ref_cmd->se_cmd.se_cmd_flags & SCF_SENT_CHECK_CONDITION) |
| 789 |
return 0; |
| 790 |
|
| 791 |
if (ref_cmd->data_direction == DMA_NONE) |
| 792 |
return 0; |
| 793 |
|
| 794 |
/* |
| 795 |
* For READs the TMR TASK_REASSIGNs ExpDataSN contains the next DataSN |
| 796 |
* of DataIN the Initiator is expecting. |
| 797 |
* |
| 798 |
* Also check that the Initiator is not re-requesting DataIN that has |
| 799 |
* already been acknowledged with a DataAck SNACK. |
| 800 |
*/ |
| 801 |
if (ref_cmd->data_direction == DMA_FROM_DEVICE) { |
| 802 |
if (tmr_req->exp_data_sn > ref_cmd->data_sn) { |
| 803 |
pr_err("Received ExpDataSN: 0x%08x for READ" |
| 804 |
" in TMR TASK_REASSIGN greater than command's" |
| 805 |
" DataSN: 0x%08x.\n", tmr_req->exp_data_sn, |
| 806 |
ref_cmd->data_sn); |
| 807 |
return -1; |
| 808 |
} |
| 809 |
if ((ref_cmd->cmd_flags & ICF_GOT_DATACK_SNACK) && |
| 810 |
(tmr_req->exp_data_sn <= ref_cmd->acked_data_sn)) { |
| 811 |
pr_err("Received ExpDataSN: 0x%08x for READ" |
| 812 |
" in TMR TASK_REASSIGN for previously" |
| 813 |
" acknowledged DataIN: 0x%08x," |
| 814 |
" protocol error\n", tmr_req->exp_data_sn, |
| 815 |
ref_cmd->acked_data_sn); |
| 816 |
return -1; |
| 817 |
} |
| 818 |
return iscsit_task_reassign_prepare_read(tmr_req, conn); |
| 819 |
} |
| 820 |
|
| 821 |
/* |
| 822 |
* For WRITEs the TMR TASK_REASSIGNs ExpDataSN contains the next R2TSN |
| 823 |
* for R2Ts the Initiator is expecting. |
| 824 |
* |
| 825 |
* Do the magic in iscsit_task_reassign_prepare_write(). |
| 826 |
*/ |
| 827 |
if (ref_cmd->data_direction == DMA_TO_DEVICE) { |
| 828 |
if (tmr_req->exp_data_sn > ref_cmd->r2t_sn) { |
| 829 |
pr_err("Received ExpDataSN: 0x%08x for WRITE" |
| 830 |
" in TMR TASK_REASSIGN greater than command's" |
| 831 |
" R2TSN: 0x%08x.\n", tmr_req->exp_data_sn, |
| 832 |
ref_cmd->r2t_sn); |
| 833 |
return -1; |
| 834 |
} |
| 835 |
return iscsit_task_reassign_prepare_write(tmr_req, conn); |
| 836 |
} |
| 837 |
|
| 838 |
pr_err("Unknown iSCSI data_direction: 0x%02x\n", |
| 839 |
ref_cmd->data_direction); |
| 840 |
|
| 841 |
return -1; |
| 842 |
} |