@@ -785,9 +785,6 @@ static int iscsit_handle_scsi_cmd(
785
785
786
786
hdr = (struct iscsi_scsi_req * ) buf ;
787
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
789
/* FIXME; Add checks for AdditionalHeaderSegment */
793
790
@@ -851,7 +848,7 @@ static int iscsit_handle_scsi_cmd(
851
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
852
(!(hdr -> flags & ISCSI_FLAG_CMD_FINAL ))) {
856
853
pr_err ("Expected Data Transfer Length and Length of"
857
854
" Immediate Data are the same, but ISCSI_FLAG_CMD_FINAL"
@@ -860,7 +857,7 @@ static int iscsit_handle_scsi_cmd(
860
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
861
pr_err ("DataSegmentLength: %u is greater than"
865
862
" EDTL: %u, protocol error.\n" , payload_length ,
866
863
hdr -> data_length );
@@ -931,8 +928,8 @@ static int iscsit_handle_scsi_cmd(
931
928
spin_unlock_bh (& conn -> sess -> ttt_lock );
932
929
} else if (hdr -> flags & ISCSI_FLAG_CMD_WRITE )
933
930
cmd -> targ_xfer_tag = 0xFFFFFFFF ;
934
- cmd -> cmd_sn = hdr -> cmdsn ;
935
- cmd -> exp_stat_sn = hdr -> exp_statsn ;
931
+ cmd -> cmd_sn = be32_to_cpu ( hdr -> cmdsn ) ;
932
+ cmd -> exp_stat_sn = be32_to_cpu ( hdr -> exp_statsn ) ;
936
933
cmd -> first_burst_len = payload_length ;
937
934
938
935
if (cmd -> data_direction == DMA_FROM_DEVICE ) {
@@ -951,8 +948,9 @@ static int iscsit_handle_scsi_cmd(
951
948
* Initialize struct se_cmd descriptor from target_core_mod infrastructure
952
949
*/
953
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 ,
955
- sam_task_attr , cmd -> sense_buffer + 2 );
951
+ conn -> sess -> se_sess , be32_to_cpu (hdr -> data_length ),
952
+ cmd -> data_direction , sam_task_attr ,
953
+ cmd -> sense_buffer + 2 );
956
954
957
955
pr_debug ("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
958
956
" ExpXferLen: %u, Length: %u, CID: %hu\n" , hdr -> itt ,
@@ -1027,7 +1025,7 @@ static int iscsit_handle_scsi_cmd(
1027
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
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
1192
hdr = (struct iscsi_data * ) buf ;
1195
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
1195
if (!payload_length ) {
1202
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
1242
se_cmd = & cmd -> se_cmd ;
1249
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
1246
pr_err ("DataOut Offset: %u, Length %u greater than"
1253
1247
" iSCSI Command EDTL %u, protocol error.\n" ,
1254
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
1325
rx_size += payload_length ;
1332
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
1330
if (iov_ret < 0 )
1336
1331
return -1 ;
1337
1332
@@ -1362,7 +1357,8 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
1362
1357
u32 data_crc ;
1363
1358
1364
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
1362
cmd -> pad_bytes );
1367
1363
1368
1364
if (checksum != data_crc ) {
@@ -1423,9 +1419,6 @@ static int iscsit_handle_nop_out(
1423
1419
1424
1420
hdr = (struct iscsi_nopout * ) buf ;
1425
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
1423
if (hdr -> itt == RESERVED_ITT && !(hdr -> opcode & ISCSI_OP_IMMEDIATE )) {
1431
1424
pr_err ("NOPOUT ITT is reserved, but Immediate Bit is"
@@ -1455,7 +1448,7 @@ static int iscsit_handle_nop_out(
1455
1448
* Either way, make sure we allocate an struct iscsi_cmd, as both
1456
1449
* can contain ping data.
1457
1450
*/
1458
- if (hdr -> ttt == 0xFFFFFFFF ) {
1451
+ if (hdr -> ttt == cpu_to_be32 ( 0xFFFFFFFF ) ) {
1459
1452
cmd = iscsit_allocate_cmd (conn , GFP_KERNEL );
1460
1453
if (!cmd )
1461
1454
return iscsit_add_reject (
@@ -1468,12 +1461,12 @@ static int iscsit_handle_nop_out(
1468
1461
1 : 0 );
1469
1462
conn -> sess -> init_task_tag = cmd -> init_task_tag = hdr -> itt ;
1470
1463
cmd -> targ_xfer_tag = 0xFFFFFFFF ;
1471
- cmd -> cmd_sn = hdr -> cmdsn ;
1472
- cmd -> exp_stat_sn = hdr -> exp_statsn ;
1464
+ cmd -> cmd_sn = be32_to_cpu ( hdr -> cmdsn ) ;
1465
+ cmd -> exp_stat_sn = be32_to_cpu ( hdr -> exp_statsn ) ;
1473
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
1470
rx_size = payload_length ;
1478
1471
ping_data = kzalloc (payload_length + 1 , GFP_KERNEL );
1479
1472
if (!ping_data ) {
@@ -1566,7 +1559,7 @@ static int iscsit_handle_nop_out(
1566
1559
list_add_tail (& cmd -> i_conn_node , & conn -> conn_cmd_list );
1567
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
1564
if (hdr -> opcode & ISCSI_OP_IMMEDIATE ) {
1572
1565
iscsit_add_cmd_to_response_queue (cmd , conn ,
@@ -1587,11 +1580,11 @@ static int iscsit_handle_nop_out(
1587
1580
return 0 ;
1588
1581
}
1589
1582
1590
- if (hdr -> ttt != 0xFFFFFFFF ) {
1583
+ if (hdr -> ttt != cpu_to_be32 ( 0xFFFFFFFF ) ) {
1591
1584
/*
1592
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
1588
if (!cmd )
1596
1589
return -1 ;
1597
1590
@@ -1636,10 +1629,6 @@ static int iscsit_handle_task_mgt_cmd(
1636
1629
u8 function ;
1637
1630
1638
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
1632
hdr -> flags &= ~ISCSI_FLAG_CMD_FINAL ;
1644
1633
function = hdr -> flags ;
1645
1634
@@ -1664,8 +1653,8 @@ static int iscsit_handle_task_mgt_cmd(
1664
1653
buf , conn );
1665
1654
}
1666
1655
if ((function != ISCSI_TM_FUNC_ABORT_TASK ) &&
1667
- (hdr -> refcmdsn != ISCSI_RESERVED_TAG ) )
1668
- hdr -> refcmdsn = ISCSI_RESERVED_TAG ;
1656
+ be32_to_cpu (hdr -> refcmdsn ) != ISCSI_RESERVED_TAG )
1657
+ hdr -> refcmdsn = cpu_to_be32 ( ISCSI_RESERVED_TAG ) ;
1669
1658
1670
1659
cmd = iscsit_allocate_cmd (conn , GFP_KERNEL );
1671
1660
if (!cmd )
@@ -1742,8 +1731,8 @@ static int iscsit_handle_task_mgt_cmd(
1742
1731
cmd -> immediate_cmd = ((hdr -> opcode & ISCSI_OP_IMMEDIATE ) ? 1 : 0 );
1743
1732
cmd -> init_task_tag = hdr -> itt ;
1744
1733
cmd -> targ_xfer_tag = 0xFFFFFFFF ;
1745
- cmd -> cmd_sn = hdr -> cmdsn ;
1746
- cmd -> exp_stat_sn = hdr -> exp_statsn ;
1734
+ cmd -> cmd_sn = be32_to_cpu ( hdr -> cmdsn ) ;
1735
+ cmd -> exp_stat_sn = be32_to_cpu ( hdr -> exp_statsn ) ;
1747
1736
se_tmr = cmd -> se_cmd .se_tmr_req ;
1748
1737
tmr_req = cmd -> tmr_req ;
1749
1738
/*
@@ -1827,7 +1816,7 @@ static int iscsit_handle_task_mgt_cmd(
1827
1816
ISCSI_REASON_PROTOCOL_ERROR ,
1828
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
1821
if (out_of_order_cmdsn || !(hdr -> opcode & ISCSI_OP_IMMEDIATE ))
1833
1822
return 0 ;
@@ -1864,9 +1853,6 @@ static int iscsit_handle_text_cmd(
1864
1853
1865
1854
hdr = (struct iscsi_text * ) buf ;
1866
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
1857
if (payload_length > conn -> conn_ops -> MaxXmitDataSegmentLength ) {
1872
1858
pr_err ("Unable to accept text parameter length: %u"
@@ -1983,15 +1969,15 @@ static int iscsit_handle_text_cmd(
1983
1969
cmd -> immediate_cmd = ((hdr -> opcode & ISCSI_OP_IMMEDIATE ) ? 1 : 0 );
1984
1970
conn -> sess -> init_task_tag = cmd -> init_task_tag = hdr -> itt ;
1985
1971
cmd -> targ_xfer_tag = 0xFFFFFFFF ;
1986
- cmd -> cmd_sn = hdr -> cmdsn ;
1987
- cmd -> exp_stat_sn = hdr -> exp_statsn ;
1972
+ cmd -> cmd_sn = be32_to_cpu ( hdr -> cmdsn ) ;
1973
+ cmd -> exp_stat_sn = be32_to_cpu ( hdr -> exp_statsn ) ;
1988
1974
cmd -> data_direction = DMA_NONE ;
1989
1975
1990
1976
spin_lock_bh (& conn -> cmd_lock );
1991
1977
list_add_tail (& cmd -> i_conn_node , & conn -> conn_cmd_list );
1992
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
1982
if (!(hdr -> opcode & ISCSI_OP_IMMEDIATE )) {
1997
1983
cmdsn_ret = iscsit_sequence_cmd (conn , cmd , hdr -> cmdsn );
@@ -2125,9 +2111,6 @@ static int iscsit_handle_logout_cmd(
2125
2111
2126
2112
hdr = (struct iscsi_logout * ) buf ;
2127
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
2115
if (tiqn ) {
2133
2116
spin_lock (& tiqn -> logout_stats .lock );
@@ -2159,9 +2142,9 @@ static int iscsit_handle_logout_cmd(
2159
2142
cmd -> immediate_cmd = ((hdr -> opcode & ISCSI_OP_IMMEDIATE ) ? 1 : 0 );
2160
2143
conn -> sess -> init_task_tag = cmd -> init_task_tag = hdr -> itt ;
2161
2144
cmd -> targ_xfer_tag = 0xFFFFFFFF ;
2162
- cmd -> cmd_sn = hdr -> cmdsn ;
2163
- cmd -> exp_stat_sn = hdr -> exp_statsn ;
2164
- cmd -> logout_cid = hdr -> cid ;
2145
+ cmd -> cmd_sn = be32_to_cpu ( hdr -> cmdsn ) ;
2146
+ cmd -> exp_stat_sn = be32_to_cpu ( hdr -> exp_statsn ) ;
2147
+ cmd -> logout_cid = be16_to_cpu ( hdr -> cid ) ;
2165
2148
cmd -> logout_reason = reason_code ;
2166
2149
cmd -> data_direction = DMA_NONE ;
2167
2150
@@ -2171,15 +2154,15 @@ static int iscsit_handle_logout_cmd(
2171
2154
*/
2172
2155
if ((reason_code == ISCSI_LOGOUT_REASON_CLOSE_SESSION ) ||
2173
2156
((reason_code == ISCSI_LOGOUT_REASON_CLOSE_CONNECTION ) &&
2174
- (hdr -> cid == conn -> cid ) ))
2157
+ be16_to_cpu (hdr -> cid ) == conn -> cid ))
2175
2158
logout_remove = 1 ;
2176
2159
2177
2160
spin_lock_bh (& conn -> cmd_lock );
2178
2161
list_add_tail (& cmd -> i_conn_node , & conn -> conn_cmd_list );
2179
2162
spin_unlock_bh (& conn -> cmd_lock );
2180
2163
2181
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
2168
* Immediate commands are executed, well, immediately.
@@ -2212,10 +2195,6 @@ static int iscsit_handle_snack(
2212
2195
2213
2196
hdr = (struct iscsi_snack * ) buf ;
2214
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
2199
pr_debug ("Got ISCSI_INIT_SNACK, ITT: 0x%08x, ExpStatSN:"
2221
2200
" 0x%08x, Type: 0x%02x, BegRun: 0x%08x, RunLength: 0x%08x,"
@@ -2235,13 +2214,18 @@ static int iscsit_handle_snack(
2235
2214
switch (hdr -> flags & ISCSI_FLAG_SNACK_TYPE_MASK ) {
2236
2215
case 0 :
2237
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
2221
case ISCSI_FLAG_SNACK_TYPE_STATUS :
2240
- return iscsit_handle_status_snack (conn , hdr -> itt , hdr -> ttt ,
2241
- hdr -> begrun , hdr -> runlength );
2222
+ return iscsit_handle_status_snack (conn , hdr -> itt ,
2223
+ be32_to_cpu (hdr -> ttt ),
2224
+ be32_to_cpu (hdr -> begrun ), be32_to_cpu (hdr -> runlength ));
2242
2225
case ISCSI_FLAG_SNACK_TYPE_DATA_ACK :
2243
- return iscsit_handle_data_ack (conn , hdr -> ttt , hdr -> begrun ,
2244
- hdr -> runlength );
2226
+ return iscsit_handle_data_ack (conn , be32_to_cpu (hdr -> ttt ),
2227
+ be32_to_cpu (hdr -> begrun ),
2228
+ be32_to_cpu (hdr -> runlength ));
2245
2229
case ISCSI_FLAG_SNACK_TYPE_RDATA :
2246
2230
/* FIXME: Support R-Data SNACK */
2247
2231
pr_err ("R-Data SNACK Not Supported.\n" );
@@ -2529,11 +2513,16 @@ static int iscsit_send_data_in(
2529
2513
put_unaligned_le64 (0xFFFFFFFFFFFFFFFFULL , & hdr -> lun );
2530
2514
2531
2515
hdr -> itt = cmd -> init_task_tag ;
2532
- hdr -> ttt = (hdr -> flags & ISCSI_FLAG_DATA_ACK ) ?
2533
- cpu_to_be32 (cmd -> targ_xfer_tag ) :
2534
- 0xFFFFFFFF ;
2535
- hdr -> statsn = (set_statsn ) ? cpu_to_be32 (cmd -> stat_sn ) :
2536
- 0xFFFFFFFF ;
2516
+
2517
+ if (hdr -> flags & ISCSI_FLAG_DATA_ACK )
2518
+ hdr -> ttt = cpu_to_be32 (cmd -> targ_xfer_tag );
2519
+ else
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
2526
hdr -> exp_cmdsn = cpu_to_be32 (conn -> sess -> exp_cmd_sn );
2538
2527
hdr -> max_cmdsn = cpu_to_be32 (conn -> sess -> max_cmd_sn );
2539
2528
hdr -> datasn = cpu_to_be32 (datain .data_sn );
@@ -3088,7 +3077,7 @@ static int iscsit_send_status(
3088
3077
cmd -> se_cmd .scsi_sense_length += sizeof (__be16 );
3089
3078
3090
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
3081
iov [iov_count ].iov_base = cmd -> sense_buffer ;
3093
3082
iov [iov_count ++ ].iov_len =
3094
3083
(cmd -> se_cmd .scsi_sense_length + padding );
@@ -3418,7 +3407,7 @@ static int iscsit_send_reject(
3418
3407
hdr -> opcode = ISCSI_OP_REJECT ;
3419
3408
hdr -> flags |= ISCSI_FLAG_CMD_FINAL ;
3420
3409
hton24 (hdr -> dlength , ISCSI_HDR_LEN );
3421
- hdr -> ffffffff = 0xffffffff ;
3410
+ hdr -> ffffffff = cpu_to_be32 ( 0xffffffff ) ;
3422
3411
cmd -> stat_sn = conn -> stat_sn ++ ;
3423
3412
hdr -> statsn = cpu_to_be32 (cmd -> stat_sn );
3424
3413
hdr -> exp_cmdsn = cpu_to_be32 (conn -> sess -> exp_cmd_sn );
0 commit comments