forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/target/iscsi/iscsi_target_erl1.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*******************************************************************************
23 * This file contains error recovery level one used by the iSCSI Target driver.
34 *
....@@ -5,15 +6,6 @@
56 *
67 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
78 *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
179 ******************************************************************************/
1810
1911 #include <linux/list.h>
....@@ -48,13 +40,19 @@
4840 u32 buf_len,
4941 int dump_padding_digest)
5042 {
51
- char *buf, pad_bytes[4];
43
+ char *buf;
5244 int ret = DATAOUT_WITHIN_COMMAND_RECOVERY, rx_got;
53
- u32 length, padding, offset = 0, size;
45
+ u32 length, offset = 0, size;
5446 struct kvec iov;
5547
5648 if (conn->sess->sess_ops->RDMAExtensions)
5749 return 0;
50
+
51
+ if (dump_padding_digest) {
52
+ buf_len = ALIGN(buf_len, 4);
53
+ if (conn->conn_ops->DataDigest)
54
+ buf_len += ISCSI_CRC_LEN;
55
+ }
5856
5957 length = min(buf_len, OFFLOAD_BUF_SIZE);
6058
....@@ -75,41 +73,12 @@
7573 rx_got = rx_data(conn, &iov, 1, size);
7674 if (rx_got != size) {
7775 ret = DATAOUT_CANNOT_RECOVER;
78
- goto out;
76
+ break;
7977 }
8078
8179 offset += size;
8280 }
8381
84
- if (!dump_padding_digest)
85
- goto out;
86
-
87
- padding = ((-buf_len) & 3);
88
- if (padding != 0) {
89
- iov.iov_len = padding;
90
- iov.iov_base = pad_bytes;
91
-
92
- rx_got = rx_data(conn, &iov, 1, padding);
93
- if (rx_got != padding) {
94
- ret = DATAOUT_CANNOT_RECOVER;
95
- goto out;
96
- }
97
- }
98
-
99
- if (conn->conn_ops->DataDigest) {
100
- u32 data_crc;
101
-
102
- iov.iov_len = ISCSI_CRC_LEN;
103
- iov.iov_base = &data_crc;
104
-
105
- rx_got = rx_data(conn, &iov, 1, ISCSI_CRC_LEN);
106
- if (rx_got != ISCSI_CRC_LEN) {
107
- ret = DATAOUT_CANNOT_RECOVER;
108
- goto out;
109
- }
110
- }
111
-
112
-out:
11382 kfree(buf);
11483 return ret;
11584 }
....@@ -797,14 +766,14 @@
797766 return ooo_cmdsn;
798767 }
799768
800
-/*
801
- * Called with sess->cmdsn_mutex held.
802
- */
803769 static int iscsit_attach_ooo_cmdsn(
804770 struct iscsi_session *sess,
805771 struct iscsi_ooo_cmdsn *ooo_cmdsn)
806772 {
807773 struct iscsi_ooo_cmdsn *ooo_tail, *ooo_tmp;
774
+
775
+ lockdep_assert_held(&sess->cmdsn_mutex);
776
+
808777 /*
809778 * We attach the struct iscsi_ooo_cmdsn entry to the out of order
810779 * list in increasing CmdSN order.
....@@ -871,14 +840,13 @@
871840 mutex_unlock(&sess->cmdsn_mutex);
872841 }
873842
874
-/*
875
- * Called with sess->cmdsn_mutex held.
876
- */
877843 int iscsit_execute_ooo_cmdsns(struct iscsi_session *sess)
878844 {
879845 int ooo_count = 0;
880846 struct iscsi_cmd *cmd = NULL;
881847 struct iscsi_ooo_cmdsn *ooo_cmdsn, *ooo_cmdsn_tmp;
848
+
849
+ lockdep_assert_held(&sess->cmdsn_mutex);
882850
883851 list_for_each_entry_safe(ooo_cmdsn, ooo_cmdsn_tmp,
884852 &sess->sess_ooo_cmdsn_list, ooo_list) {
....@@ -943,20 +911,8 @@
943911 return 0;
944912 }
945913 spin_unlock_bh(&cmd->istate_lock);
946
- /*
947
- * Determine if delayed TASK_ABORTED status for WRITEs
948
- * should be sent now if no unsolicited data out
949
- * payloads are expected, or if the delayed status
950
- * should be sent after unsolicited data out with
951
- * ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out()
952
- */
953
- if (transport_check_aborted_status(se_cmd,
954
- (cmd->unsolicited_data == 0)) != 0)
914
+ if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
955915 return 0;
956
- /*
957
- * Otherwise send CHECK_CONDITION and sense for
958
- * exception
959
- */
960916 return transport_send_check_condition_and_sense(se_cmd,
961917 cmd->sense_reason, 0);
962918 }
....@@ -974,13 +930,7 @@
974930
975931 if (!(cmd->cmd_flags &
976932 ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
977
- /*
978
- * Send the delayed TASK_ABORTED status for
979
- * WRITEs if no more unsolicitied data is
980
- * expected.
981
- */
982
- if (transport_check_aborted_status(se_cmd, 1)
983
- != 0)
933
+ if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
984934 return 0;
985935
986936 iscsit_set_dataout_sequence_values(cmd);
....@@ -995,14 +945,10 @@
995945
996946 if ((cmd->data_direction == DMA_TO_DEVICE) &&
997947 !(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
998
- /*
999
- * Send the delayed TASK_ABORTED status for WRITEs if
1000
- * no more nsolicitied data is expected.
1001
- */
1002
- if (transport_check_aborted_status(se_cmd, 1) != 0)
948
+ if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
1003949 return 0;
1004950
1005
- iscsit_set_unsoliticed_dataout(cmd);
951
+ iscsit_set_unsolicited_dataout(cmd);
1006952 }
1007953 return transport_handle_cdb_direct(&cmd->se_cmd);
1008954
....@@ -1169,15 +1115,21 @@
11691115 na = iscsit_tpg_get_node_attrib(sess);
11701116
11711117 if (!sess->sess_ops->ErrorRecoveryLevel) {
1172
- pr_debug("Unable to recover from DataOut timeout while"
1173
- " in ERL=0.\n");
1118
+ pr_err("Unable to recover from DataOut timeout while"
1119
+ " in ERL=0, closing iSCSI connection for I_T Nexus"
1120
+ " %s,i,0x%6phN,%s,t,0x%02x\n",
1121
+ sess->sess_ops->InitiatorName, sess->isid,
1122
+ sess->tpg->tpg_tiqn->tiqn, (u32)sess->tpg->tpgt);
11741123 goto failure;
11751124 }
11761125
11771126 if (++cmd->dataout_timeout_retries == na->dataout_timeout_retries) {
1178
- pr_debug("Command ITT: 0x%08x exceeded max retries"
1179
- " for DataOUT timeout %u, closing iSCSI connection.\n",
1180
- cmd->init_task_tag, na->dataout_timeout_retries);
1127
+ pr_err("Command ITT: 0x%08x exceeded max retries"
1128
+ " for DataOUT timeout %u, closing iSCSI connection for"
1129
+ " I_T Nexus %s,i,0x%6phN,%s,t,0x%02x\n",
1130
+ cmd->init_task_tag, na->dataout_timeout_retries,
1131
+ sess->sess_ops->InitiatorName, sess->isid,
1132
+ sess->tpg->tpg_tiqn->tiqn, (u32)sess->tpg->tpgt);
11811133 goto failure;
11821134 }
11831135
....@@ -1224,6 +1176,7 @@
12241176
12251177 failure:
12261178 spin_unlock_bh(&cmd->dataout_timeout_lock);
1179
+ iscsit_fill_cxn_timeout_err_stats(sess);
12271180 iscsit_cause_connection_reinstatement(conn, 0);
12281181 iscsit_dec_conn_usage_count(conn);
12291182 }
....@@ -1247,9 +1200,6 @@
12471200 spin_unlock_bh(&cmd->dataout_timeout_lock);
12481201 }
12491202
1250
-/*
1251
- * Called with cmd->dataout_timeout_lock held.
1252
- */
12531203 void iscsit_start_dataout_timer(
12541204 struct iscsi_cmd *cmd,
12551205 struct iscsi_conn *conn)
....@@ -1257,6 +1207,8 @@
12571207 struct iscsi_session *sess = conn->sess;
12581208 struct iscsi_node_attrib *na = iscsit_tpg_get_node_attrib(sess);
12591209
1210
+ lockdep_assert_held(&cmd->dataout_timeout_lock);
1211
+
12601212 if (cmd->dataout_timer_flags & ISCSI_TF_RUNNING)
12611213 return;
12621214