aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target/iscsi
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2012-09-26 08:00:40 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-10-03 17:39:22 -0400
commit50e5c87de4c244662e47b28e499ace885d62248f (patch)
tree0cd84e70a1549a8d757e6fe48a8254b6e43ab783 /drivers/target/iscsi
parent66c7db687631247b7a3493322b9aedeef3c6c7b5 (diff)
iscsit: proper endianess conversions
Make sure all on the wire types are use as big endian and big endian only so that sparse can verify all the conversions are done right. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/iscsi')
-rw-r--r--drivers/target/iscsi/iscsi_target.c121
-rw-r--r--drivers/target/iscsi/iscsi_target_core.h1
-rw-r--r--drivers/target/iscsi/iscsi_target_erl0.c80
-rw-r--r--drivers/target/iscsi/iscsi_target_erl2.c4
-rw-r--r--drivers/target/iscsi/iscsi_target_erl2.h2
-rw-r--r--drivers/target/iscsi/iscsi_target_login.c14
-rw-r--r--drivers/target/iscsi/iscsi_target_nego.c18
-rw-r--r--drivers/target/iscsi/iscsi_target_tmr.c12
-rw-r--r--drivers/target/iscsi/iscsi_target_util.c6
-rw-r--r--drivers/target/iscsi/iscsi_target_util.h2
10 files changed, 122 insertions, 138 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 1c843b51f261..d6ce2182e672 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -785,9 +785,6 @@ static int iscsit_handle_scsi_cmd(
785 785
786 hdr = (struct iscsi_scsi_req *) buf; 786 hdr = (struct iscsi_scsi_req *) buf;
787 payload_length = ntoh24(hdr->dlength); 787 payload_length = ntoh24(hdr->dlength);
788 hdr->data_length = be32_to_cpu(hdr->data_length);
789 hdr->cmdsn = be32_to_cpu(hdr->cmdsn);
790 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
791 788
792 /* FIXME; Add checks for AdditionalHeaderSegment */ 789 /* FIXME; Add checks for AdditionalHeaderSegment */
793 790
@@ -851,7 +848,7 @@ done:
851 buf, conn); 848 buf, conn);
852 } 849 }
853 850
854 if ((hdr->data_length == payload_length) && 851 if ((be32_to_cpu(hdr->data_length )== payload_length) &&
855 (!(hdr->flags & ISCSI_FLAG_CMD_FINAL))) { 852 (!(hdr->flags & ISCSI_FLAG_CMD_FINAL))) {
856 pr_err("Expected Data Transfer Length and Length of" 853 pr_err("Expected Data Transfer Length and Length of"
857 " Immediate Data are the same, but ISCSI_FLAG_CMD_FINAL" 854 " Immediate Data are the same, but ISCSI_FLAG_CMD_FINAL"
@@ -860,7 +857,7 @@ done:
860 buf, conn); 857 buf, conn);
861 } 858 }
862 859
863 if (payload_length > hdr->data_length) { 860 if (payload_length > be32_to_cpu(hdr->data_length)) {
864 pr_err("DataSegmentLength: %u is greater than" 861 pr_err("DataSegmentLength: %u is greater than"
865 " EDTL: %u, protocol error.\n", payload_length, 862 " EDTL: %u, protocol error.\n", payload_length,
866 hdr->data_length); 863 hdr->data_length);
@@ -931,8 +928,8 @@ done:
931 spin_unlock_bh(&conn->sess->ttt_lock); 928 spin_unlock_bh(&conn->sess->ttt_lock);
932 } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE) 929 } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE)
933 cmd->targ_xfer_tag = 0xFFFFFFFF; 930 cmd->targ_xfer_tag = 0xFFFFFFFF;
934 cmd->cmd_sn = hdr->cmdsn; 931 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn);
935 cmd->exp_stat_sn = hdr->exp_statsn; 932 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn);
936 cmd->first_burst_len = payload_length; 933 cmd->first_burst_len = payload_length;
937 934
938 if (cmd->data_direction == DMA_FROM_DEVICE) { 935 if (cmd->data_direction == DMA_FROM_DEVICE) {
@@ -951,8 +948,9 @@ done:
951 * Initialize struct se_cmd descriptor from target_core_mod infrastructure 948 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
952 */ 949 */
953 transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops, 950 transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops,
954 conn->sess->se_sess, hdr->data_length, cmd->data_direction, 951 conn->sess->se_sess, be32_to_cpu(hdr->data_length),
955 sam_task_attr, cmd->sense_buffer + 2); 952 cmd->data_direction, sam_task_attr,
953 cmd->sense_buffer + 2);
956 954
957 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," 955 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
958 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, 956 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -1027,7 +1025,7 @@ attach_cmd:
1027 1, 0, buf, cmd); 1025 1, 0, buf, cmd);
1028 } 1026 }
1029 1027
1030 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 1028 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn));
1031 1029
1032 /* 1030 /*
1033 * If no Immediate Data is attached, it's OK to return now. 1031 * If no Immediate Data is attached, it's OK to return now.
@@ -1193,10 +1191,6 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1193 1191
1194 hdr = (struct iscsi_data *) buf; 1192 hdr = (struct iscsi_data *) buf;
1195 payload_length = ntoh24(hdr->dlength); 1193 payload_length = ntoh24(hdr->dlength);
1196 hdr->ttt = be32_to_cpu(hdr->ttt);
1197 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
1198 hdr->datasn = be32_to_cpu(hdr->datasn);
1199 hdr->offset = be32_to_cpu(hdr->offset);
1200 1194
1201 if (!payload_length) { 1195 if (!payload_length) {
1202 pr_err("DataOUT payload is ZERO, protocol error.\n"); 1196 pr_err("DataOUT payload is ZERO, protocol error.\n");
@@ -1248,7 +1242,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1248 se_cmd = &cmd->se_cmd; 1242 se_cmd = &cmd->se_cmd;
1249 iscsit_mod_dataout_timer(cmd); 1243 iscsit_mod_dataout_timer(cmd);
1250 1244
1251 if ((hdr->offset + payload_length) > cmd->se_cmd.data_length) { 1245 if ((be32_to_cpu(hdr->offset) + payload_length) > cmd->se_cmd.data_length) {
1252 pr_err("DataOut Offset: %u, Length %u greater than" 1246 pr_err("DataOut Offset: %u, Length %u greater than"
1253 " iSCSI Command EDTL %u, protocol error.\n", 1247 " iSCSI Command EDTL %u, protocol error.\n",
1254 hdr->offset, payload_length, cmd->se_cmd.data_length); 1248 hdr->offset, payload_length, cmd->se_cmd.data_length);
@@ -1331,7 +1325,8 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1331 rx_size += payload_length; 1325 rx_size += payload_length;
1332 iov = &cmd->iov_data[0]; 1326 iov = &cmd->iov_data[0];
1333 1327
1334 iov_ret = iscsit_map_iovec(cmd, iov, hdr->offset, payload_length); 1328 iov_ret = iscsit_map_iovec(cmd, iov, be32_to_cpu(hdr->offset),
1329 payload_length);
1335 if (iov_ret < 0) 1330 if (iov_ret < 0)
1336 return -1; 1331 return -1;
1337 1332
@@ -1362,7 +1357,8 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1362 u32 data_crc; 1357 u32 data_crc;
1363 1358
1364 data_crc = iscsit_do_crypto_hash_sg(&conn->conn_rx_hash, cmd, 1359 data_crc = iscsit_do_crypto_hash_sg(&conn->conn_rx_hash, cmd,
1365 hdr->offset, payload_length, padding, 1360 be32_to_cpu(hdr->offset),
1361 payload_length, padding,
1366 cmd->pad_bytes); 1362 cmd->pad_bytes);
1367 1363
1368 if (checksum != data_crc) { 1364 if (checksum != data_crc) {
@@ -1423,9 +1419,6 @@ static int iscsit_handle_nop_out(
1423 1419
1424 hdr = (struct iscsi_nopout *) buf; 1420 hdr = (struct iscsi_nopout *) buf;
1425 payload_length = ntoh24(hdr->dlength); 1421 payload_length = ntoh24(hdr->dlength);
1426 hdr->ttt = be32_to_cpu(hdr->ttt);
1427 hdr->cmdsn = be32_to_cpu(hdr->cmdsn);
1428 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
1429 1422
1430 if (hdr->itt == RESERVED_ITT && !(hdr->opcode & ISCSI_OP_IMMEDIATE)) { 1423 if (hdr->itt == RESERVED_ITT && !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
1431 pr_err("NOPOUT ITT is reserved, but Immediate Bit is" 1424 pr_err("NOPOUT ITT is reserved, but Immediate Bit is"
@@ -1455,7 +1448,7 @@ static int iscsit_handle_nop_out(
1455 * Either way, make sure we allocate an struct iscsi_cmd, as both 1448 * Either way, make sure we allocate an struct iscsi_cmd, as both
1456 * can contain ping data. 1449 * can contain ping data.
1457 */ 1450 */
1458 if (hdr->ttt == 0xFFFFFFFF) { 1451 if (hdr->ttt == cpu_to_be32(0xFFFFFFFF)) {
1459 cmd = iscsit_allocate_cmd(conn, GFP_KERNEL); 1452 cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
1460 if (!cmd) 1453 if (!cmd)
1461 return iscsit_add_reject( 1454 return iscsit_add_reject(
@@ -1468,12 +1461,12 @@ static int iscsit_handle_nop_out(
1468 1 : 0); 1461 1 : 0);
1469 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; 1462 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt;
1470 cmd->targ_xfer_tag = 0xFFFFFFFF; 1463 cmd->targ_xfer_tag = 0xFFFFFFFF;
1471 cmd->cmd_sn = hdr->cmdsn; 1464 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn);
1472 cmd->exp_stat_sn = hdr->exp_statsn; 1465 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn);
1473 cmd->data_direction = DMA_NONE; 1466 cmd->data_direction = DMA_NONE;
1474 } 1467 }
1475 1468
1476 if (payload_length && (hdr->ttt == 0xFFFFFFFF)) { 1469 if (payload_length && hdr->ttt == cpu_to_be32(0xFFFFFFFF)) {
1477 rx_size = payload_length; 1470 rx_size = payload_length;
1478 ping_data = kzalloc(payload_length + 1, GFP_KERNEL); 1471 ping_data = kzalloc(payload_length + 1, GFP_KERNEL);
1479 if (!ping_data) { 1472 if (!ping_data) {
@@ -1566,7 +1559,7 @@ static int iscsit_handle_nop_out(
1566 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); 1559 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list);
1567 spin_unlock_bh(&conn->cmd_lock); 1560 spin_unlock_bh(&conn->cmd_lock);
1568 1561
1569 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 1562 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn));
1570 1563
1571 if (hdr->opcode & ISCSI_OP_IMMEDIATE) { 1564 if (hdr->opcode & ISCSI_OP_IMMEDIATE) {
1572 iscsit_add_cmd_to_response_queue(cmd, conn, 1565 iscsit_add_cmd_to_response_queue(cmd, conn,
@@ -1587,11 +1580,11 @@ static int iscsit_handle_nop_out(
1587 return 0; 1580 return 0;
1588 } 1581 }
1589 1582
1590 if (hdr->ttt != 0xFFFFFFFF) { 1583 if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) {
1591 /* 1584 /*
1592 * This was a response to a unsolicited NOPIN ping. 1585 * This was a response to a unsolicited NOPIN ping.
1593 */ 1586 */
1594 cmd = iscsit_find_cmd_from_ttt(conn, hdr->ttt); 1587 cmd = iscsit_find_cmd_from_ttt(conn, be32_to_cpu(hdr->ttt));
1595 if (!cmd) 1588 if (!cmd)
1596 return -1; 1589 return -1;
1597 1590
@@ -1636,10 +1629,6 @@ static int iscsit_handle_task_mgt_cmd(
1636 u8 function; 1629 u8 function;
1637 1630
1638 hdr = (struct iscsi_tm *) buf; 1631 hdr = (struct iscsi_tm *) buf;
1639 hdr->cmdsn = be32_to_cpu(hdr->cmdsn);
1640 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
1641 hdr->refcmdsn = be32_to_cpu(hdr->refcmdsn);
1642 hdr->exp_datasn = be32_to_cpu(hdr->exp_datasn);
1643 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL; 1632 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL;
1644 function = hdr->flags; 1633 function = hdr->flags;
1645 1634
@@ -1664,8 +1653,8 @@ static int iscsit_handle_task_mgt_cmd(
1664 buf, conn); 1653 buf, conn);
1665 } 1654 }
1666 if ((function != ISCSI_TM_FUNC_ABORT_TASK) && 1655 if ((function != ISCSI_TM_FUNC_ABORT_TASK) &&
1667 (hdr->refcmdsn != ISCSI_RESERVED_TAG)) 1656 be32_to_cpu(hdr->refcmdsn) != ISCSI_RESERVED_TAG)
1668 hdr->refcmdsn = ISCSI_RESERVED_TAG; 1657 hdr->refcmdsn = cpu_to_be32(ISCSI_RESERVED_TAG);
1669 1658
1670 cmd = iscsit_allocate_cmd(conn, GFP_KERNEL); 1659 cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
1671 if (!cmd) 1660 if (!cmd)
@@ -1742,8 +1731,8 @@ static int iscsit_handle_task_mgt_cmd(
1742 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); 1731 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0);
1743 cmd->init_task_tag = hdr->itt; 1732 cmd->init_task_tag = hdr->itt;
1744 cmd->targ_xfer_tag = 0xFFFFFFFF; 1733 cmd->targ_xfer_tag = 0xFFFFFFFF;
1745 cmd->cmd_sn = hdr->cmdsn; 1734 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn);
1746 cmd->exp_stat_sn = hdr->exp_statsn; 1735 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn);
1747 se_tmr = cmd->se_cmd.se_tmr_req; 1736 se_tmr = cmd->se_cmd.se_tmr_req;
1748 tmr_req = cmd->tmr_req; 1737 tmr_req = cmd->tmr_req;
1749 /* 1738 /*
@@ -1827,7 +1816,7 @@ attach:
1827 ISCSI_REASON_PROTOCOL_ERROR, 1816 ISCSI_REASON_PROTOCOL_ERROR,
1828 1, 0, buf, cmd); 1817 1, 0, buf, cmd);
1829 } 1818 }
1830 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 1819 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn));
1831 1820
1832 if (out_of_order_cmdsn || !(hdr->opcode & ISCSI_OP_IMMEDIATE)) 1821 if (out_of_order_cmdsn || !(hdr->opcode & ISCSI_OP_IMMEDIATE))
1833 return 0; 1822 return 0;
@@ -1864,9 +1853,6 @@ static int iscsit_handle_text_cmd(
1864 1853
1865 hdr = (struct iscsi_text *) buf; 1854 hdr = (struct iscsi_text *) buf;
1866 payload_length = ntoh24(hdr->dlength); 1855 payload_length = ntoh24(hdr->dlength);
1867 hdr->ttt = be32_to_cpu(hdr->ttt);
1868 hdr->cmdsn = be32_to_cpu(hdr->cmdsn);
1869 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
1870 1856
1871 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) { 1857 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) {
1872 pr_err("Unable to accept text parameter length: %u" 1858 pr_err("Unable to accept text parameter length: %u"
@@ -1983,15 +1969,15 @@ static int iscsit_handle_text_cmd(
1983 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); 1969 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0);
1984 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; 1970 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt;
1985 cmd->targ_xfer_tag = 0xFFFFFFFF; 1971 cmd->targ_xfer_tag = 0xFFFFFFFF;
1986 cmd->cmd_sn = hdr->cmdsn; 1972 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn);
1987 cmd->exp_stat_sn = hdr->exp_statsn; 1973 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn);
1988 cmd->data_direction = DMA_NONE; 1974 cmd->data_direction = DMA_NONE;
1989 1975
1990 spin_lock_bh(&conn->cmd_lock); 1976 spin_lock_bh(&conn->cmd_lock);
1991 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); 1977 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list);
1992 spin_unlock_bh(&conn->cmd_lock); 1978 spin_unlock_bh(&conn->cmd_lock);
1993 1979
1994 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 1980 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn));
1995 1981
1996 if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { 1982 if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
1997 cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn); 1983 cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn);
@@ -2125,9 +2111,6 @@ static int iscsit_handle_logout_cmd(
2125 2111
2126 hdr = (struct iscsi_logout *) buf; 2112 hdr = (struct iscsi_logout *) buf;
2127 reason_code = (hdr->flags & 0x7f); 2113 reason_code = (hdr->flags & 0x7f);
2128 hdr->cid = be16_to_cpu(hdr->cid);
2129 hdr->cmdsn = be32_to_cpu(hdr->cmdsn);
2130 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
2131 2114
2132 if (tiqn) { 2115 if (tiqn) {
2133 spin_lock(&tiqn->logout_stats.lock); 2116 spin_lock(&tiqn->logout_stats.lock);
@@ -2159,9 +2142,9 @@ static int iscsit_handle_logout_cmd(
2159 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); 2142 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0);
2160 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; 2143 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt;
2161 cmd->targ_xfer_tag = 0xFFFFFFFF; 2144 cmd->targ_xfer_tag = 0xFFFFFFFF;
2162 cmd->cmd_sn = hdr->cmdsn; 2145 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn);
2163 cmd->exp_stat_sn = hdr->exp_statsn; 2146 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn);
2164 cmd->logout_cid = hdr->cid; 2147 cmd->logout_cid = be16_to_cpu(hdr->cid);
2165 cmd->logout_reason = reason_code; 2148 cmd->logout_reason = reason_code;
2166 cmd->data_direction = DMA_NONE; 2149 cmd->data_direction = DMA_NONE;
2167 2150
@@ -2171,7 +2154,7 @@ static int iscsit_handle_logout_cmd(
2171 */ 2154 */
2172 if ((reason_code == ISCSI_LOGOUT_REASON_CLOSE_SESSION) || 2155 if ((reason_code == ISCSI_LOGOUT_REASON_CLOSE_SESSION) ||
2173 ((reason_code == ISCSI_LOGOUT_REASON_CLOSE_CONNECTION) && 2156 ((reason_code == ISCSI_LOGOUT_REASON_CLOSE_CONNECTION) &&
2174 (hdr->cid == conn->cid))) 2157 be16_to_cpu(hdr->cid) == conn->cid))
2175 logout_remove = 1; 2158 logout_remove = 1;
2176 2159
2177 spin_lock_bh(&conn->cmd_lock); 2160 spin_lock_bh(&conn->cmd_lock);
@@ -2179,7 +2162,7 @@ static int iscsit_handle_logout_cmd(
2179 spin_unlock_bh(&conn->cmd_lock); 2162 spin_unlock_bh(&conn->cmd_lock);
2180 2163
2181 if (reason_code != ISCSI_LOGOUT_REASON_RECOVERY) 2164 if (reason_code != ISCSI_LOGOUT_REASON_RECOVERY)
2182 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 2165 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn));
2183 2166
2184 /* 2167 /*
2185 * Immediate commands are executed, well, immediately. 2168 * Immediate commands are executed, well, immediately.
@@ -2212,10 +2195,6 @@ static int iscsit_handle_snack(
2212 2195
2213 hdr = (struct iscsi_snack *) buf; 2196 hdr = (struct iscsi_snack *) buf;
2214 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL; 2197 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL;
2215 hdr->ttt = be32_to_cpu(hdr->ttt);
2216 hdr->exp_statsn = be32_to_cpu(hdr->exp_statsn);
2217 hdr->begrun = be32_to_cpu(hdr->begrun);
2218 hdr->runlength = be32_to_cpu(hdr->runlength);
2219 2198
2220 pr_debug("Got ISCSI_INIT_SNACK, ITT: 0x%08x, ExpStatSN:" 2199 pr_debug("Got ISCSI_INIT_SNACK, ITT: 0x%08x, ExpStatSN:"
2221 " 0x%08x, Type: 0x%02x, BegRun: 0x%08x, RunLength: 0x%08x," 2200 " 0x%08x, Type: 0x%02x, BegRun: 0x%08x, RunLength: 0x%08x,"
@@ -2235,13 +2214,18 @@ static int iscsit_handle_snack(
2235 switch (hdr->flags & ISCSI_FLAG_SNACK_TYPE_MASK) { 2214 switch (hdr->flags & ISCSI_FLAG_SNACK_TYPE_MASK) {
2236 case 0: 2215 case 0:
2237 return iscsit_handle_recovery_datain_or_r2t(conn, buf, 2216 return iscsit_handle_recovery_datain_or_r2t(conn, buf,
2238 hdr->itt, hdr->ttt, hdr->begrun, hdr->runlength); 2217 hdr->itt,
2218 be32_to_cpu(hdr->ttt),
2219 be32_to_cpu(hdr->begrun),
2220 be32_to_cpu(hdr->runlength));
2239 case ISCSI_FLAG_SNACK_TYPE_STATUS: 2221 case ISCSI_FLAG_SNACK_TYPE_STATUS:
2240 return iscsit_handle_status_snack(conn, hdr->itt, hdr->ttt, 2222 return iscsit_handle_status_snack(conn, hdr->itt,
2241 hdr->begrun, hdr->runlength); 2223 be32_to_cpu(hdr->ttt),
2224 be32_to_cpu(hdr->begrun), be32_to_cpu(hdr->runlength));
2242 case ISCSI_FLAG_SNACK_TYPE_DATA_ACK: 2225 case ISCSI_FLAG_SNACK_TYPE_DATA_ACK:
2243 return iscsit_handle_data_ack(conn, hdr->ttt, hdr->begrun, 2226 return iscsit_handle_data_ack(conn, be32_to_cpu(hdr->ttt),
2244 hdr->runlength); 2227 be32_to_cpu(hdr->begrun),
2228 be32_to_cpu(hdr->runlength));
2245 case ISCSI_FLAG_SNACK_TYPE_RDATA: 2229 case ISCSI_FLAG_SNACK_TYPE_RDATA:
2246 /* FIXME: Support R-Data SNACK */ 2230 /* FIXME: Support R-Data SNACK */
2247 pr_err("R-Data SNACK Not Supported.\n"); 2231 pr_err("R-Data SNACK Not Supported.\n");
@@ -2529,11 +2513,16 @@ static int iscsit_send_data_in(
2529 put_unaligned_le64(0xFFFFFFFFFFFFFFFFULL, &hdr->lun); 2513 put_unaligned_le64(0xFFFFFFFFFFFFFFFFULL, &hdr->lun);
2530 2514
2531 hdr->itt = cmd->init_task_tag; 2515 hdr->itt = cmd->init_task_tag;
2532 hdr->ttt = (hdr->flags & ISCSI_FLAG_DATA_ACK) ? 2516
2533 cpu_to_be32(cmd->targ_xfer_tag) : 2517 if (hdr->flags & ISCSI_FLAG_DATA_ACK)
2534 0xFFFFFFFF; 2518 hdr->ttt = cpu_to_be32(cmd->targ_xfer_tag);
2535 hdr->statsn = (set_statsn) ? cpu_to_be32(cmd->stat_sn) : 2519 else
2536 0xFFFFFFFF; 2520 hdr->ttt = cpu_to_be32(0xFFFFFFFF);
2521 if (set_statsn)
2522 hdr->statsn = cpu_to_be32(cmd->stat_sn);
2523 else
2524 hdr->statsn = cpu_to_be32(0xFFFFFFFF);
2525
2537 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); 2526 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn);
2538 hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); 2527 hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn);
2539 hdr->datasn = cpu_to_be32(datain.data_sn); 2528 hdr->datasn = cpu_to_be32(datain.data_sn);
@@ -3088,7 +3077,7 @@ static int iscsit_send_status(
3088 cmd->se_cmd.scsi_sense_length += sizeof (__be16); 3077 cmd->se_cmd.scsi_sense_length += sizeof (__be16);
3089 3078
3090 padding = -(cmd->se_cmd.scsi_sense_length) & 3; 3079 padding = -(cmd->se_cmd.scsi_sense_length) & 3;
3091 hton24(hdr->dlength, cmd->se_cmd.scsi_sense_length); 3080 hton24(hdr->dlength, (u32)cmd->se_cmd.scsi_sense_length);
3092 iov[iov_count].iov_base = cmd->sense_buffer; 3081 iov[iov_count].iov_base = cmd->sense_buffer;
3093 iov[iov_count++].iov_len = 3082 iov[iov_count++].iov_len =
3094 (cmd->se_cmd.scsi_sense_length + padding); 3083 (cmd->se_cmd.scsi_sense_length + padding);
@@ -3418,7 +3407,7 @@ static int iscsit_send_reject(
3418 hdr->opcode = ISCSI_OP_REJECT; 3407 hdr->opcode = ISCSI_OP_REJECT;
3419 hdr->flags |= ISCSI_FLAG_CMD_FINAL; 3408 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
3420 hton24(hdr->dlength, ISCSI_HDR_LEN); 3409 hton24(hdr->dlength, ISCSI_HDR_LEN);
3421 hdr->ffffffff = 0xffffffff; 3410 hdr->ffffffff = cpu_to_be32(0xffffffff);
3422 cmd->stat_sn = conn->stat_sn++; 3411 cmd->stat_sn = conn->stat_sn++;
3423 hdr->statsn = cpu_to_be32(cmd->stat_sn); 3412 hdr->statsn = cpu_to_be32(cmd->stat_sn);
3424 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); 3413 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn);
diff --git a/drivers/target/iscsi/iscsi_target_core.h b/drivers/target/iscsi/iscsi_target_core.h
index 226fe62d4e61..ff3f482968c8 100644
--- a/drivers/target/iscsi/iscsi_target_core.h
+++ b/drivers/target/iscsi/iscsi_target_core.h
@@ -479,7 +479,6 @@ struct iscsi_cmd {
479 479
480struct iscsi_tmr_req { 480struct iscsi_tmr_req {
481 bool task_reassign:1; 481 bool task_reassign:1;
482 u32 ref_cmd_sn;
483 u32 exp_data_sn; 482 u32 exp_data_sn;
484 struct iscsi_cmd *ref_cmd; 483 struct iscsi_cmd *ref_cmd;
485 struct iscsi_conn_recovery *conn_recovery; 484 struct iscsi_conn_recovery *conn_recovery;
diff --git a/drivers/target/iscsi/iscsi_target_erl0.c b/drivers/target/iscsi/iscsi_target_erl0.c
index 0c37533ccbb5..8aacf611b86d 100644
--- a/drivers/target/iscsi/iscsi_target_erl0.c
+++ b/drivers/target/iscsi/iscsi_target_erl0.c
@@ -95,14 +95,15 @@ static int iscsit_dataout_within_command_recovery_check(
95 */ 95 */
96 if (conn->sess->sess_ops->DataSequenceInOrder) { 96 if (conn->sess->sess_ops->DataSequenceInOrder) {
97 if ((cmd->cmd_flags & ICF_WITHIN_COMMAND_RECOVERY) && 97 if ((cmd->cmd_flags & ICF_WITHIN_COMMAND_RECOVERY) &&
98 (cmd->write_data_done != hdr->offset)) 98 cmd->write_data_done != be32_to_cpu(hdr->offset))
99 goto dump; 99 goto dump;
100 100
101 cmd->cmd_flags &= ~ICF_WITHIN_COMMAND_RECOVERY; 101 cmd->cmd_flags &= ~ICF_WITHIN_COMMAND_RECOVERY;
102 } else { 102 } else {
103 struct iscsi_seq *seq; 103 struct iscsi_seq *seq;
104 104
105 seq = iscsit_get_seq_holder(cmd, hdr->offset, payload_length); 105 seq = iscsit_get_seq_holder(cmd, be32_to_cpu(hdr->offset),
106 payload_length);
106 if (!seq) 107 if (!seq)
107 return DATAOUT_CANNOT_RECOVER; 108 return DATAOUT_CANNOT_RECOVER;
108 /* 109 /*
@@ -111,15 +112,15 @@ static int iscsit_dataout_within_command_recovery_check(
111 cmd->seq_ptr = seq; 112 cmd->seq_ptr = seq;
112 113
113 if (conn->sess->sess_ops->DataPDUInOrder) { 114 if (conn->sess->sess_ops->DataPDUInOrder) {
114 if ((seq->status == 115 if (seq->status ==
115 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY) && 116 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY &&
116 ((seq->offset != hdr->offset) || 117 (seq->offset != be32_to_cpu(hdr->offset) ||
117 (seq->data_sn != hdr->datasn))) 118 seq->data_sn != be32_to_cpu(hdr->datasn)))
118 goto dump; 119 goto dump;
119 } else { 120 } else {
120 if ((seq->status == 121 if (seq->status ==
121 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY) && 122 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY &&
122 (seq->data_sn != hdr->datasn)) 123 seq->data_sn != be32_to_cpu(hdr->datasn))
123 goto dump; 124 goto dump;
124 } 125 }
125 126
@@ -148,12 +149,12 @@ static int iscsit_dataout_check_unsolicited_sequence(
148 u32 payload_length = ntoh24(hdr->dlength); 149 u32 payload_length = ntoh24(hdr->dlength);
149 150
150 151
151 if ((hdr->offset < cmd->seq_start_offset) || 152 if ((be32_to_cpu(hdr->offset) < cmd->seq_start_offset) ||
152 ((hdr->offset + payload_length) > cmd->seq_end_offset)) { 153 ((be32_to_cpu(hdr->offset) + payload_length) > cmd->seq_end_offset)) {
153 pr_err("Command ITT: 0x%08x with Offset: %u," 154 pr_err("Command ITT: 0x%08x with Offset: %u,"
154 " Length: %u outside of Unsolicited Sequence %u:%u while" 155 " Length: %u outside of Unsolicited Sequence %u:%u while"
155 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag, 156 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag,
156 hdr->offset, payload_length, cmd->seq_start_offset, 157 be32_to_cpu(hdr->offset), payload_length, cmd->seq_start_offset,
157 cmd->seq_end_offset); 158 cmd->seq_end_offset);
158 return DATAOUT_CANNOT_RECOVER; 159 return DATAOUT_CANNOT_RECOVER;
159 } 160 }
@@ -236,12 +237,12 @@ static int iscsit_dataout_check_sequence(
236 * fullfilling an Recovery R2T, it's best to just dump the 237 * fullfilling an Recovery R2T, it's best to just dump the
237 * payload here, instead of erroring out. 238 * payload here, instead of erroring out.
238 */ 239 */
239 if ((hdr->offset < cmd->seq_start_offset) || 240 if ((be32_to_cpu(hdr->offset) < cmd->seq_start_offset) ||
240 ((hdr->offset + payload_length) > cmd->seq_end_offset)) { 241 ((be32_to_cpu(hdr->offset) + payload_length) > cmd->seq_end_offset)) {
241 pr_err("Command ITT: 0x%08x with Offset: %u," 242 pr_err("Command ITT: 0x%08x with Offset: %u,"
242 " Length: %u outside of Sequence %u:%u while" 243 " Length: %u outside of Sequence %u:%u while"
243 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag, 244 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag,
244 hdr->offset, payload_length, cmd->seq_start_offset, 245 be32_to_cpu(hdr->offset), payload_length, cmd->seq_start_offset,
245 cmd->seq_end_offset); 246 cmd->seq_end_offset);
246 247
247 if (iscsit_dump_data_payload(conn, payload_length, 1) < 0) 248 if (iscsit_dump_data_payload(conn, payload_length, 1) < 0)
@@ -251,7 +252,8 @@ static int iscsit_dataout_check_sequence(
251 252
252 next_burst_len = (cmd->next_burst_len + payload_length); 253 next_burst_len = (cmd->next_burst_len + payload_length);
253 } else { 254 } else {
254 seq = iscsit_get_seq_holder(cmd, hdr->offset, payload_length); 255 seq = iscsit_get_seq_holder(cmd, be32_to_cpu(hdr->offset),
256 payload_length);
255 if (!seq) 257 if (!seq)
256 return DATAOUT_CANNOT_RECOVER; 258 return DATAOUT_CANNOT_RECOVER;
257 /* 259 /*
@@ -366,16 +368,16 @@ static int iscsit_dataout_check_datasn(
366 data_sn = seq->data_sn; 368 data_sn = seq->data_sn;
367 } 369 }
368 370
369 if (hdr->datasn > data_sn) { 371 if (be32_to_cpu(hdr->datasn) > data_sn) {
370 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x" 372 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x"
371 " higher than expected 0x%08x.\n", cmd->init_task_tag, 373 " higher than expected 0x%08x.\n", cmd->init_task_tag,
372 hdr->datasn, data_sn); 374 be32_to_cpu(hdr->datasn), data_sn);
373 recovery = 1; 375 recovery = 1;
374 goto recover; 376 goto recover;
375 } else if (hdr->datasn < data_sn) { 377 } else if (be32_to_cpu(hdr->datasn) < data_sn) {
376 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x" 378 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x"
377 " lower than expected 0x%08x, discarding payload.\n", 379 " lower than expected 0x%08x, discarding payload.\n",
378 cmd->init_task_tag, hdr->datasn, data_sn); 380 cmd->init_task_tag, be32_to_cpu(hdr->datasn), data_sn);
379 dump = 1; 381 dump = 1;
380 goto dump; 382 goto dump;
381 } 383 }
@@ -415,26 +417,27 @@ static int iscsit_dataout_pre_datapduinorder_yes(
415 * error has occured and fail the connection. 417 * error has occured and fail the connection.
416 */ 418 */
417 if (conn->sess->sess_ops->DataSequenceInOrder) { 419 if (conn->sess->sess_ops->DataSequenceInOrder) {
418 if (hdr->offset != cmd->write_data_done) { 420 if (be32_to_cpu(hdr->offset) != cmd->write_data_done) {
419 pr_err("Command ITT: 0x%08x, received offset" 421 pr_err("Command ITT: 0x%08x, received offset"
420 " %u different than expected %u.\n", cmd->init_task_tag, 422 " %u different than expected %u.\n", cmd->init_task_tag,
421 hdr->offset, cmd->write_data_done); 423 be32_to_cpu(hdr->offset), cmd->write_data_done);
422 recovery = 1; 424 recovery = 1;
423 goto recover; 425 goto recover;
424 } 426 }
425 } else { 427 } else {
426 struct iscsi_seq *seq = cmd->seq_ptr; 428 struct iscsi_seq *seq = cmd->seq_ptr;
427 429
428 if (hdr->offset > seq->offset) { 430 if (be32_to_cpu(hdr->offset) > seq->offset) {
429 pr_err("Command ITT: 0x%08x, received offset" 431 pr_err("Command ITT: 0x%08x, received offset"
430 " %u greater than expected %u.\n", cmd->init_task_tag, 432 " %u greater than expected %u.\n", cmd->init_task_tag,
431 hdr->offset, seq->offset); 433 be32_to_cpu(hdr->offset), seq->offset);
432 recovery = 1; 434 recovery = 1;
433 goto recover; 435 goto recover;
434 } else if (hdr->offset < seq->offset) { 436 } else if (be32_to_cpu(hdr->offset) < seq->offset) {
435 pr_err("Command ITT: 0x%08x, received offset" 437 pr_err("Command ITT: 0x%08x, received offset"
436 " %u less than expected %u, discarding payload.\n", 438 " %u less than expected %u, discarding payload.\n",
437 cmd->init_task_tag, hdr->offset, seq->offset); 439 cmd->init_task_tag, be32_to_cpu(hdr->offset),
440 seq->offset);
438 dump = 1; 441 dump = 1;
439 goto dump; 442 goto dump;
440 } 443 }
@@ -453,7 +456,7 @@ dump:
453 return DATAOUT_CANNOT_RECOVER; 456 return DATAOUT_CANNOT_RECOVER;
454 457
455 return (recovery) ? iscsit_recover_dataout_sequence(cmd, 458 return (recovery) ? iscsit_recover_dataout_sequence(cmd,
456 hdr->offset, payload_length) : 459 be32_to_cpu(hdr->offset), payload_length) :
457 (dump) ? DATAOUT_WITHIN_COMMAND_RECOVERY : DATAOUT_NORMAL; 460 (dump) ? DATAOUT_WITHIN_COMMAND_RECOVERY : DATAOUT_NORMAL;
458} 461}
459 462
@@ -465,7 +468,8 @@ static int iscsit_dataout_pre_datapduinorder_no(
465 struct iscsi_data *hdr = (struct iscsi_data *) buf; 468 struct iscsi_data *hdr = (struct iscsi_data *) buf;
466 u32 payload_length = ntoh24(hdr->dlength); 469 u32 payload_length = ntoh24(hdr->dlength);
467 470
468 pdu = iscsit_get_pdu_holder(cmd, hdr->offset, payload_length); 471 pdu = iscsit_get_pdu_holder(cmd, be32_to_cpu(hdr->offset),
472 payload_length);
469 if (!pdu) 473 if (!pdu)
470 return DATAOUT_CANNOT_RECOVER; 474 return DATAOUT_CANNOT_RECOVER;
471 475
@@ -479,7 +483,7 @@ static int iscsit_dataout_pre_datapduinorder_no(
479 case ISCSI_PDU_RECEIVED_OK: 483 case ISCSI_PDU_RECEIVED_OK:
480 pr_err("Command ITT: 0x%08x received already gotten" 484 pr_err("Command ITT: 0x%08x received already gotten"
481 " Offset: %u, Length: %u\n", cmd->init_task_tag, 485 " Offset: %u, Length: %u\n", cmd->init_task_tag,
482 hdr->offset, payload_length); 486 be32_to_cpu(hdr->offset), payload_length);
483 return iscsit_dump_data_payload(cmd->conn, payload_length, 1); 487 return iscsit_dump_data_payload(cmd->conn, payload_length, 1);
484 default: 488 default:
485 return DATAOUT_CANNOT_RECOVER; 489 return DATAOUT_CANNOT_RECOVER;
@@ -553,7 +557,7 @@ static int iscsit_dataout_post_crc_passed(
553 if (cmd->unsolicited_data) { 557 if (cmd->unsolicited_data) {
554 if ((cmd->first_burst_len + payload_length) == 558 if ((cmd->first_burst_len + payload_length) ==
555 conn->sess->sess_ops->FirstBurstLength) { 559 conn->sess->sess_ops->FirstBurstLength) {
556 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 560 if (iscsit_dataout_update_r2t(cmd, be32_to_cpu(hdr->offset),
557 payload_length) < 0) 561 payload_length) < 0)
558 return DATAOUT_CANNOT_RECOVER; 562 return DATAOUT_CANNOT_RECOVER;
559 send_r2t = 1; 563 send_r2t = 1;
@@ -561,7 +565,8 @@ static int iscsit_dataout_post_crc_passed(
561 565
562 if (!conn->sess->sess_ops->DataPDUInOrder) { 566 if (!conn->sess->sess_ops->DataPDUInOrder) {
563 ret = iscsit_dataout_update_datapduinorder_no(cmd, 567 ret = iscsit_dataout_update_datapduinorder_no(cmd,
564 hdr->datasn, (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 568 be32_to_cpu(hdr->datasn),
569 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
565 if (ret == DATAOUT_CANNOT_RECOVER) 570 if (ret == DATAOUT_CANNOT_RECOVER)
566 return ret; 571 return ret;
567 } 572 }
@@ -586,7 +591,8 @@ static int iscsit_dataout_post_crc_passed(
586 if (conn->sess->sess_ops->DataSequenceInOrder) { 591 if (conn->sess->sess_ops->DataSequenceInOrder) {
587 if ((cmd->next_burst_len + payload_length) == 592 if ((cmd->next_burst_len + payload_length) ==
588 conn->sess->sess_ops->MaxBurstLength) { 593 conn->sess->sess_ops->MaxBurstLength) {
589 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 594 if (iscsit_dataout_update_r2t(cmd,
595 be32_to_cpu(hdr->offset),
590 payload_length) < 0) 596 payload_length) < 0)
591 return DATAOUT_CANNOT_RECOVER; 597 return DATAOUT_CANNOT_RECOVER;
592 send_r2t = 1; 598 send_r2t = 1;
@@ -594,7 +600,7 @@ static int iscsit_dataout_post_crc_passed(
594 600
595 if (!conn->sess->sess_ops->DataPDUInOrder) { 601 if (!conn->sess->sess_ops->DataPDUInOrder) {
596 ret = iscsit_dataout_update_datapduinorder_no( 602 ret = iscsit_dataout_update_datapduinorder_no(
597 cmd, hdr->datasn, 603 cmd, be32_to_cpu(hdr->datasn),
598 (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 604 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
599 if (ret == DATAOUT_CANNOT_RECOVER) 605 if (ret == DATAOUT_CANNOT_RECOVER)
600 return ret; 606 return ret;
@@ -610,7 +616,8 @@ static int iscsit_dataout_post_crc_passed(
610 616
611 if ((seq->next_burst_len + payload_length) == 617 if ((seq->next_burst_len + payload_length) ==
612 seq->xfer_len) { 618 seq->xfer_len) {
613 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 619 if (iscsit_dataout_update_r2t(cmd,
620 be32_to_cpu(hdr->offset),
614 payload_length) < 0) 621 payload_length) < 0)
615 return DATAOUT_CANNOT_RECOVER; 622 return DATAOUT_CANNOT_RECOVER;
616 send_r2t = 1; 623 send_r2t = 1;
@@ -618,7 +625,7 @@ static int iscsit_dataout_post_crc_passed(
618 625
619 if (!conn->sess->sess_ops->DataPDUInOrder) { 626 if (!conn->sess->sess_ops->DataPDUInOrder) {
620 ret = iscsit_dataout_update_datapduinorder_no( 627 ret = iscsit_dataout_update_datapduinorder_no(
621 cmd, hdr->datasn, 628 cmd, be32_to_cpu(hdr->datasn),
622 (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 629 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
623 if (ret == DATAOUT_CANNOT_RECOVER) 630 if (ret == DATAOUT_CANNOT_RECOVER)
624 return ret; 631 return ret;
@@ -678,7 +685,8 @@ static int iscsit_dataout_post_crc_failed(
678 } 685 }
679 686
680recover: 687recover:
681 return iscsit_recover_dataout_sequence(cmd, hdr->offset, payload_length); 688 return iscsit_recover_dataout_sequence(cmd, be32_to_cpu(hdr->offset),
689 payload_length);
682} 690}
683 691
684/* 692/*
diff --git a/drivers/target/iscsi/iscsi_target_erl2.c b/drivers/target/iscsi/iscsi_target_erl2.c
index 660694544128..17d8c20094fd 100644
--- a/drivers/target/iscsi/iscsi_target_erl2.c
+++ b/drivers/target/iscsi/iscsi_target_erl2.c
@@ -36,7 +36,7 @@
36 */ 36 */
37void iscsit_create_conn_recovery_datain_values( 37void iscsit_create_conn_recovery_datain_values(
38 struct iscsi_cmd *cmd, 38 struct iscsi_cmd *cmd,
39 u32 exp_data_sn) 39 __be32 exp_data_sn)
40{ 40{
41 u32 data_sn = 0; 41 u32 data_sn = 0;
42 struct iscsi_conn *conn = cmd->conn; 42 struct iscsi_conn *conn = cmd->conn;
@@ -44,7 +44,7 @@ void iscsit_create_conn_recovery_datain_values(
44 cmd->next_burst_len = 0; 44 cmd->next_burst_len = 0;
45 cmd->read_data_done = 0; 45 cmd->read_data_done = 0;
46 46
47 while (exp_data_sn > data_sn) { 47 while (be32_to_cpu(exp_data_sn) > data_sn) {
48 if ((cmd->next_burst_len + 48 if ((cmd->next_burst_len +
49 conn->conn_ops->MaxRecvDataSegmentLength) < 49 conn->conn_ops->MaxRecvDataSegmentLength) <
50 conn->sess->sess_ops->MaxBurstLength) { 50 conn->sess->sess_ops->MaxBurstLength) {
diff --git a/drivers/target/iscsi/iscsi_target_erl2.h b/drivers/target/iscsi/iscsi_target_erl2.h
index 22f8d24780a6..63f2501f3fe0 100644
--- a/drivers/target/iscsi/iscsi_target_erl2.h
+++ b/drivers/target/iscsi/iscsi_target_erl2.h
@@ -1,7 +1,7 @@
1#ifndef ISCSI_TARGET_ERL2_H 1#ifndef ISCSI_TARGET_ERL2_H
2#define ISCSI_TARGET_ERL2_H 2#define ISCSI_TARGET_ERL2_H
3 3
4extern void iscsit_create_conn_recovery_datain_values(struct iscsi_cmd *, u32); 4extern void iscsit_create_conn_recovery_datain_values(struct iscsi_cmd *, __be32);
5extern void iscsit_create_conn_recovery_dataout_values(struct iscsi_cmd *); 5extern void iscsit_create_conn_recovery_dataout_values(struct iscsi_cmd *);
6extern struct iscsi_conn_recovery *iscsit_get_inactive_connection_recovery_entry( 6extern struct iscsi_conn_recovery *iscsit_get_inactive_connection_recovery_entry(
7 struct iscsi_session *, u16); 7 struct iscsi_session *, u16);
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index 4c83d7a39bf3..cdc8a10939c3 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -192,10 +192,10 @@ int iscsi_check_for_session_reinstatement(struct iscsi_conn *conn)
192static void iscsi_login_set_conn_values( 192static void iscsi_login_set_conn_values(
193 struct iscsi_session *sess, 193 struct iscsi_session *sess,
194 struct iscsi_conn *conn, 194 struct iscsi_conn *conn,
195 u16 cid) 195 __be16 cid)
196{ 196{
197 conn->sess = sess; 197 conn->sess = sess;
198 conn->cid = cid; 198 conn->cid = be16_to_cpu(cid);
199 /* 199 /*
200 * Generate a random Status sequence number (statsn) for the new 200 * Generate a random Status sequence number (statsn) for the new
201 * iSCSI connection. 201 * iSCSI connection.
@@ -230,7 +230,7 @@ static int iscsi_login_zero_tsih_s1(
230 iscsi_login_set_conn_values(sess, conn, pdu->cid); 230 iscsi_login_set_conn_values(sess, conn, pdu->cid);
231 sess->init_task_tag = pdu->itt; 231 sess->init_task_tag = pdu->itt;
232 memcpy(&sess->isid, pdu->isid, 6); 232 memcpy(&sess->isid, pdu->isid, 6);
233 sess->exp_cmd_sn = pdu->cmdsn; 233 sess->exp_cmd_sn = be32_to_cpu(pdu->cmdsn);
234 INIT_LIST_HEAD(&sess->sess_conn_list); 234 INIT_LIST_HEAD(&sess->sess_conn_list);
235 INIT_LIST_HEAD(&sess->sess_ooo_cmdsn_list); 235 INIT_LIST_HEAD(&sess->sess_ooo_cmdsn_list);
236 INIT_LIST_HEAD(&sess->cr_active_list); 236 INIT_LIST_HEAD(&sess->cr_active_list);
@@ -271,7 +271,7 @@ static int iscsi_login_zero_tsih_s1(
271 * The FFP CmdSN window values will be allocated from the TPG's 271 * The FFP CmdSN window values will be allocated from the TPG's
272 * Initiator Node's ACL once the login has been successfully completed. 272 * Initiator Node's ACL once the login has been successfully completed.
273 */ 273 */
274 sess->max_cmd_sn = pdu->cmdsn; 274 sess->max_cmd_sn = be32_to_cpu(pdu->cmdsn);
275 275
276 sess->sess_ops = kzalloc(sizeof(struct iscsi_sess_ops), GFP_KERNEL); 276 sess->sess_ops = kzalloc(sizeof(struct iscsi_sess_ops), GFP_KERNEL);
277 if (!sess->sess_ops) { 277 if (!sess->sess_ops) {
@@ -449,7 +449,7 @@ static int iscsi_login_non_zero_tsih_s2(
449 (sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED)) 449 (sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED))
450 continue; 450 continue;
451 if (!memcmp(sess_p->isid, pdu->isid, 6) && 451 if (!memcmp(sess_p->isid, pdu->isid, 6) &&
452 (sess_p->tsih == pdu->tsih)) { 452 (sess_p->tsih == be16_to_cpu(pdu->tsih))) {
453 iscsit_inc_session_usage_count(sess_p); 453 iscsit_inc_session_usage_count(sess_p);
454 iscsit_stop_time2retain_timer(sess_p); 454 iscsit_stop_time2retain_timer(sess_p);
455 sess = sess_p; 455 sess = sess_p;
@@ -951,10 +951,6 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
951 } 951 }
952 952
953 pdu = (struct iscsi_login_req *) buffer; 953 pdu = (struct iscsi_login_req *) buffer;
954 pdu->cid = be16_to_cpu(pdu->cid);
955 pdu->tsih = be16_to_cpu(pdu->tsih);
956 pdu->cmdsn = be32_to_cpu(pdu->cmdsn);
957 pdu->exp_statsn = be32_to_cpu(pdu->exp_statsn);
958 954
959 /* 955 /*
960 * Used by iscsit_tx_login_rsp() for Login Resonses PDUs 956 * Used by iscsit_tx_login_rsp() for Login Resonses PDUs
diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
index 33ed9b5209cd..e9053a04f24c 100644
--- a/drivers/target/iscsi/iscsi_target_nego.c
+++ b/drivers/target/iscsi/iscsi_target_nego.c
@@ -360,11 +360,9 @@ static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_log
360 return -1; 360 return -1;
361 361
362 login->rsp_length = 0; 362 login->rsp_length = 0;
363 login_rsp->tsih = be16_to_cpu(login_rsp->tsih);
364 login_rsp->statsn = be32_to_cpu(login_rsp->statsn);
365 mutex_lock(&sess->cmdsn_mutex); 363 mutex_lock(&sess->cmdsn_mutex);
366 login_rsp->exp_cmdsn = be32_to_cpu(sess->exp_cmd_sn); 364 login_rsp->exp_cmdsn = cpu_to_be32(sess->exp_cmd_sn);
367 login_rsp->max_cmdsn = be32_to_cpu(sess->max_cmd_sn); 365 login_rsp->max_cmdsn = cpu_to_be32(sess->max_cmd_sn);
368 mutex_unlock(&sess->cmdsn_mutex); 366 mutex_unlock(&sess->cmdsn_mutex);
369 367
370 return 0; 368 return 0;
@@ -380,10 +378,6 @@ static int iscsi_target_do_rx_login_io(struct iscsi_conn *conn, struct iscsi_log
380 378
381 login_req = (struct iscsi_login_req *) login->req; 379 login_req = (struct iscsi_login_req *) login->req;
382 payload_length = ntoh24(login_req->dlength); 380 payload_length = ntoh24(login_req->dlength);
383 login_req->tsih = be16_to_cpu(login_req->tsih);
384 login_req->cid = be16_to_cpu(login_req->cid);
385 login_req->cmdsn = be32_to_cpu(login_req->cmdsn);
386 login_req->exp_statsn = be32_to_cpu(login_req->exp_statsn);
387 381
388 pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x," 382 pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x,"
389 " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n", 383 " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n",
@@ -760,11 +754,11 @@ static int iscsi_target_locate_portal(
760 login->version_min = login_req->min_version; 754 login->version_min = login_req->min_version;
761 login->version_max = login_req->max_version; 755 login->version_max = login_req->max_version;
762 memcpy(login->isid, login_req->isid, 6); 756 memcpy(login->isid, login_req->isid, 6);
763 login->cmd_sn = login_req->cmdsn; 757 login->cmd_sn = be32_to_cpu(login_req->cmdsn);
764 login->init_task_tag = login_req->itt; 758 login->init_task_tag = login_req->itt;
765 login->initial_exp_statsn = login_req->exp_statsn; 759 login->initial_exp_statsn = be32_to_cpu(login_req->exp_statsn);
766 login->cid = login_req->cid; 760 login->cid = be16_to_cpu(login_req->cid);
767 login->tsih = login_req->tsih; 761 login->tsih = be16_to_cpu(login_req->tsih);
768 762
769 if (iscsi_target_get_initial_payload(conn, login) < 0) 763 if (iscsi_target_get_initial_payload(conn, login) < 0)
770 return -1; 764 return -1;
diff --git a/drivers/target/iscsi/iscsi_target_tmr.c b/drivers/target/iscsi/iscsi_target_tmr.c
index 925f829a3704..4a99820d063b 100644
--- a/drivers/target/iscsi/iscsi_target_tmr.c
+++ b/drivers/target/iscsi/iscsi_target_tmr.c
@@ -50,11 +50,11 @@ u8 iscsit_tmr_abort_task(
50 if (!ref_cmd) { 50 if (!ref_cmd) {
51 pr_err("Unable to locate RefTaskTag: 0x%08x on CID:" 51 pr_err("Unable to locate RefTaskTag: 0x%08x on CID:"
52 " %hu.\n", hdr->rtt, conn->cid); 52 " %hu.\n", hdr->rtt, conn->cid);
53 return ((hdr->refcmdsn >= conn->sess->exp_cmd_sn) && 53 return (be32_to_cpu(hdr->refcmdsn) >= conn->sess->exp_cmd_sn &&
54 (hdr->refcmdsn <= conn->sess->max_cmd_sn)) ? 54 be32_to_cpu(hdr->refcmdsn) <= conn->sess->max_cmd_sn) ?
55 ISCSI_TMF_RSP_COMPLETE : ISCSI_TMF_RSP_NO_TASK; 55 ISCSI_TMF_RSP_COMPLETE : ISCSI_TMF_RSP_NO_TASK;
56 } 56 }
57 if (ref_cmd->cmd_sn != hdr->refcmdsn) { 57 if (ref_cmd->cmd_sn != be32_to_cpu(hdr->refcmdsn)) {
58 pr_err("RefCmdSN 0x%08x does not equal" 58 pr_err("RefCmdSN 0x%08x does not equal"
59 " task's CmdSN 0x%08x. Rejecting ABORT_TASK.\n", 59 " task's CmdSN 0x%08x. Rejecting ABORT_TASK.\n",
60 hdr->refcmdsn, ref_cmd->cmd_sn); 60 hdr->refcmdsn, ref_cmd->cmd_sn);
@@ -63,8 +63,7 @@ u8 iscsit_tmr_abort_task(
63 63
64 se_tmr->ref_task_tag = (__force u32)hdr->rtt; 64 se_tmr->ref_task_tag = (__force u32)hdr->rtt;
65 tmr_req->ref_cmd = ref_cmd; 65 tmr_req->ref_cmd = ref_cmd;
66 tmr_req->ref_cmd_sn = hdr->refcmdsn; 66 tmr_req->exp_data_sn = be32_to_cpu(hdr->exp_datasn);
67 tmr_req->exp_data_sn = hdr->exp_datasn;
68 67
69 return ISCSI_TMF_RSP_COMPLETE; 68 return ISCSI_TMF_RSP_COMPLETE;
70} 69}
@@ -173,8 +172,7 @@ u8 iscsit_tmr_task_reassign(
173 172
174 se_tmr->ref_task_tag = (__force u32)hdr->rtt; 173 se_tmr->ref_task_tag = (__force u32)hdr->rtt;
175 tmr_req->ref_cmd = ref_cmd; 174 tmr_req->ref_cmd = ref_cmd;
176 tmr_req->ref_cmd_sn = hdr->refcmdsn; 175 tmr_req->exp_data_sn = be32_to_cpu(hdr->exp_datasn);
177 tmr_req->exp_data_sn = hdr->exp_datasn;
178 tmr_req->conn_recovery = cr; 176 tmr_req->conn_recovery = cr;
179 tmr_req->task_reassign = 1; 177 tmr_req->task_reassign = 1;
180 /* 178 /*
diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c
index 22bec9e899c0..afd98ccd40ae 100644
--- a/drivers/target/iscsi/iscsi_target_util.c
+++ b/drivers/target/iscsi/iscsi_target_util.c
@@ -274,14 +274,14 @@ static inline int iscsit_check_received_cmdsn(struct iscsi_session *sess, u32 cm
274int iscsit_sequence_cmd( 274int iscsit_sequence_cmd(
275 struct iscsi_conn *conn, 275 struct iscsi_conn *conn,
276 struct iscsi_cmd *cmd, 276 struct iscsi_cmd *cmd,
277 u32 cmdsn) 277 __be32 cmdsn)
278{ 278{
279 int ret; 279 int ret;
280 int cmdsn_ret; 280 int cmdsn_ret;
281 281
282 mutex_lock(&conn->sess->cmdsn_mutex); 282 mutex_lock(&conn->sess->cmdsn_mutex);
283 283
284 cmdsn_ret = iscsit_check_received_cmdsn(conn->sess, cmdsn); 284 cmdsn_ret = iscsit_check_received_cmdsn(conn->sess, be32_to_cpu(cmdsn));
285 switch (cmdsn_ret) { 285 switch (cmdsn_ret) {
286 case CMDSN_NORMAL_OPERATION: 286 case CMDSN_NORMAL_OPERATION:
287 ret = iscsit_execute_cmd(cmd, 0); 287 ret = iscsit_execute_cmd(cmd, 0);
@@ -289,7 +289,7 @@ int iscsit_sequence_cmd(
289 iscsit_execute_ooo_cmdsns(conn->sess); 289 iscsit_execute_ooo_cmdsns(conn->sess);
290 break; 290 break;
291 case CMDSN_HIGHER_THAN_EXP: 291 case CMDSN_HIGHER_THAN_EXP:
292 ret = iscsit_handle_ooo_cmdsn(conn->sess, cmd, cmdsn); 292 ret = iscsit_handle_ooo_cmdsn(conn->sess, cmd, be32_to_cpu(cmdsn));
293 break; 293 break;
294 case CMDSN_LOWER_THAN_EXP: 294 case CMDSN_LOWER_THAN_EXP:
295 cmd->i_state = ISTATE_REMOVE; 295 cmd->i_state = ISTATE_REMOVE;
diff --git a/drivers/target/iscsi/iscsi_target_util.h b/drivers/target/iscsi/iscsi_target_util.h
index 09e2f9f563a7..44054bd35437 100644
--- a/drivers/target/iscsi/iscsi_target_util.h
+++ b/drivers/target/iscsi/iscsi_target_util.h
@@ -12,7 +12,7 @@ extern struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *, gfp_t);
12extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsi_cmd *, u32); 12extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsi_cmd *, u32);
13extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsi_cmd *); 13extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsi_cmd *);
14extern struct iscsi_r2t *iscsit_get_holder_for_r2tsn(struct iscsi_cmd *, u32); 14extern struct iscsi_r2t *iscsit_get_holder_for_r2tsn(struct iscsi_cmd *, u32);
15int iscsit_sequence_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, u32 cmdsn); 15int iscsit_sequence_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, __be32 cmdsn);
16extern int iscsit_check_unsolicited_dataout(struct iscsi_cmd *, unsigned char *); 16extern int iscsit_check_unsolicited_dataout(struct iscsi_cmd *, unsigned char *);
17extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t); 17extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t);
18extern struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump(struct iscsi_conn *, 18extern struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump(struct iscsi_conn *,