aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c4
-rw-r--r--drivers/scsi/iscsi_tcp.c2
-rw-r--r--drivers/scsi/libiscsi.c40
-rw-r--r--include/scsi/iscsi_proto.h46
4 files changed, 49 insertions, 43 deletions
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index 0a7d1ab60e6d..89e37283c836 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -567,7 +567,7 @@ void iser_rcv_completion(struct iser_desc *rx_desc,
567 opcode = hdr->opcode & ISCSI_OPCODE_MASK; 567 opcode = hdr->opcode & ISCSI_OPCODE_MASK;
568 568
569 if (opcode == ISCSI_OP_SCSI_CMD_RSP) { 569 if (opcode == ISCSI_OP_SCSI_CMD_RSP) {
570 itt = hdr->itt & ISCSI_ITT_MASK; /* mask out cid and age bits */ 570 itt = get_itt(hdr->itt); /* mask out cid and age bits */
571 if (!(itt < session->cmds_max)) 571 if (!(itt < session->cmds_max))
572 iser_err("itt can't be matched to task!!!" 572 iser_err("itt can't be matched to task!!!"
573 "conn %p opcode %d cmds_max %d itt %d\n", 573 "conn %p opcode %d cmds_max %d itt %d\n",
@@ -625,7 +625,7 @@ void iser_snd_completion(struct iser_desc *tx_desc)
625 /* this arithmetic is legal by libiscsi dd_data allocation */ 625 /* this arithmetic is legal by libiscsi dd_data allocation */
626 mtask = (void *) ((long)(void *)tx_desc - 626 mtask = (void *) ((long)(void *)tx_desc -
627 sizeof(struct iscsi_mgmt_task)); 627 sizeof(struct iscsi_mgmt_task));
628 if (mtask->hdr->itt == cpu_to_be32(ISCSI_RESERVED_TAG)) { 628 if (mtask->hdr->itt == RESERVED_ITT) {
629 struct iscsi_session *session = conn->session; 629 struct iscsi_session *session = conn->session;
630 630
631 spin_lock(&conn->session->lock); 631 spin_lock(&conn->session->lock);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 437684084377..8f55e1431433 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -1375,7 +1375,7 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1375 } 1375 }
1376 1376
1377 BUG_ON(tcp_mtask->xmstate != XMSTATE_IDLE); 1377 BUG_ON(tcp_mtask->xmstate != XMSTATE_IDLE);
1378 if (mtask->hdr->itt == cpu_to_be32(ISCSI_RESERVED_TAG)) { 1378 if (mtask->hdr->itt == RESERVED_ITT) {
1379 struct iscsi_session *session = conn->session; 1379 struct iscsi_session *session = conn->session;
1380 1380
1381 spin_lock_bh(&session->lock); 1381 spin_lock_bh(&session->lock);
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index d37048c96eab..7c75771c77ff 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -113,8 +113,7 @@ static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
113 hdr->opcode = ISCSI_OP_SCSI_CMD; 113 hdr->opcode = ISCSI_OP_SCSI_CMD;
114 hdr->flags = ISCSI_ATTR_SIMPLE; 114 hdr->flags = ISCSI_ATTR_SIMPLE;
115 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun); 115 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
116 hdr->itt = ctask->itt | (conn->id << ISCSI_CID_SHIFT) | 116 hdr->itt = build_itt(ctask->itt, conn->id, session->age);
117 (session->age << ISCSI_AGE_SHIFT);
118 hdr->data_length = cpu_to_be32(sc->request_bufflen); 117 hdr->data_length = cpu_to_be32(sc->request_bufflen);
119 hdr->cmdsn = cpu_to_be32(session->cmdsn); 118 hdr->cmdsn = cpu_to_be32(session->cmdsn);
120 session->cmdsn++; 119 session->cmdsn++;
@@ -270,7 +269,7 @@ invalid_datalen:
270 goto out; 269 goto out;
271 } 270 }
272 271
273 senselen = be16_to_cpu(*(uint16_t *)data); 272 senselen = be16_to_cpu(*(__be16 *)data);
274 if (datalen < senselen) 273 if (datalen < senselen)
275 goto invalid_datalen; 274 goto invalid_datalen;
276 275
@@ -338,7 +337,7 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
338 337
339 if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) { 338 if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) {
340 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr)); 339 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
341 itt = rejected_pdu.itt & ISCSI_ITT_MASK; 340 itt = get_itt(rejected_pdu.itt);
342 printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected " 341 printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected "
343 "due to DataDigest error.\n", itt, 342 "due to DataDigest error.\n", itt,
344 rejected_pdu.opcode); 343 rejected_pdu.opcode);
@@ -367,10 +366,10 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
367 struct iscsi_mgmt_task *mtask; 366 struct iscsi_mgmt_task *mtask;
368 uint32_t itt; 367 uint32_t itt;
369 368
370 if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG)) 369 if (hdr->itt != RESERVED_ITT)
371 itt = hdr->itt & ISCSI_ITT_MASK; 370 itt = get_itt(hdr->itt);
372 else 371 else
373 itt = hdr->itt; 372 itt = ~0U;
374 373
375 if (itt < session->cmds_max) { 374 if (itt < session->cmds_max) {
376 ctask = session->cmds[itt]; 375 ctask = session->cmds[itt];
@@ -440,7 +439,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
440 iscsi_tmf_rsp(conn, hdr); 439 iscsi_tmf_rsp(conn, hdr);
441 break; 440 break;
442 case ISCSI_OP_NOOP_IN: 441 case ISCSI_OP_NOOP_IN:
443 if (hdr->ttt != ISCSI_RESERVED_TAG || datalen) { 442 if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) {
444 rc = ISCSI_ERR_PROTO; 443 rc = ISCSI_ERR_PROTO;
445 break; 444 break;
446 } 445 }
@@ -457,7 +456,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
457 rc = ISCSI_ERR_BAD_OPCODE; 456 rc = ISCSI_ERR_BAD_OPCODE;
458 break; 457 break;
459 } 458 }
460 } else if (itt == ISCSI_RESERVED_TAG) { 459 } else if (itt == ~0U) {
461 rc = iscsi_check_assign_cmdsn(session, 460 rc = iscsi_check_assign_cmdsn(session,
462 (struct iscsi_nopin*)hdr); 461 (struct iscsi_nopin*)hdr);
463 if (rc) 462 if (rc)
@@ -470,7 +469,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
470 break; 469 break;
471 } 470 }
472 471
473 if (hdr->ttt == ISCSI_RESERVED_TAG) 472 if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG))
474 break; 473 break;
475 474
476 if (iscsi_recv_pdu(conn->cls_conn, hdr, NULL, 0)) 475 if (iscsi_recv_pdu(conn->cls_conn, hdr, NULL, 0))
@@ -516,24 +515,24 @@ int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
516 struct iscsi_cmd_task *ctask; 515 struct iscsi_cmd_task *ctask;
517 uint32_t itt; 516 uint32_t itt;
518 517
519 if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG)) { 518 if (hdr->itt != RESERVED_ITT) {
520 if ((hdr->itt & ISCSI_AGE_MASK) != 519 if (((__force u32)hdr->itt & ISCSI_AGE_MASK) !=
521 (session->age << ISCSI_AGE_SHIFT)) { 520 (session->age << ISCSI_AGE_SHIFT)) {
522 printk(KERN_ERR "iscsi: received itt %x expected " 521 printk(KERN_ERR "iscsi: received itt %x expected "
523 "session age (%x)\n", hdr->itt, 522 "session age (%x)\n", (__force u32)hdr->itt,
524 session->age & ISCSI_AGE_MASK); 523 session->age & ISCSI_AGE_MASK);
525 return ISCSI_ERR_BAD_ITT; 524 return ISCSI_ERR_BAD_ITT;
526 } 525 }
527 526
528 if ((hdr->itt & ISCSI_CID_MASK) != 527 if (((__force u32)hdr->itt & ISCSI_CID_MASK) !=
529 (conn->id << ISCSI_CID_SHIFT)) { 528 (conn->id << ISCSI_CID_SHIFT)) {
530 printk(KERN_ERR "iscsi: received itt %x, expected " 529 printk(KERN_ERR "iscsi: received itt %x, expected "
531 "CID (%x)\n", hdr->itt, conn->id); 530 "CID (%x)\n", (__force u32)hdr->itt, conn->id);
532 return ISCSI_ERR_BAD_ITT; 531 return ISCSI_ERR_BAD_ITT;
533 } 532 }
534 itt = hdr->itt & ISCSI_ITT_MASK; 533 itt = get_itt(hdr->itt);
535 } else 534 } else
536 itt = hdr->itt; 535 itt = ~0U;
537 536
538 if (itt < session->cmds_max) { 537 if (itt < session->cmds_max) {
539 ctask = session->cmds[itt]; 538 ctask = session->cmds[itt];
@@ -896,9 +895,8 @@ iscsi_conn_send_generic(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
896 /* 895 /*
897 * pre-format CmdSN for outgoing PDU. 896 * pre-format CmdSN for outgoing PDU.
898 */ 897 */
899 if (hdr->itt != cpu_to_be32(ISCSI_RESERVED_TAG)) { 898 if (hdr->itt != RESERVED_ITT) {
900 hdr->itt = mtask->itt | (conn->id << ISCSI_CID_SHIFT) | 899 hdr->itt = build_itt(mtask->itt, conn->id, session->age);
901 (session->age << ISCSI_AGE_SHIFT);
902 nop->cmdsn = cpu_to_be32(session->cmdsn); 900 nop->cmdsn = cpu_to_be32(session->cmdsn);
903 if (conn->c_stage == ISCSI_CONN_STARTED && 901 if (conn->c_stage == ISCSI_CONN_STARTED &&
904 !(hdr->opcode & ISCSI_OP_IMMEDIATE)) 902 !(hdr->opcode & ISCSI_OP_IMMEDIATE))
@@ -1064,7 +1062,7 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1064 1062
1065 spin_lock_bh(&session->lock); 1063 spin_lock_bh(&session->lock);
1066 ctask->mtask = (struct iscsi_mgmt_task *) 1064 ctask->mtask = (struct iscsi_mgmt_task *)
1067 session->mgmt_cmds[(hdr->itt & ISCSI_ITT_MASK) - 1065 session->mgmt_cmds[get_itt(hdr->itt) -
1068 ISCSI_MGMT_ITT_OFFSET]; 1066 ISCSI_MGMT_ITT_OFFSET];
1069 1067
1070 if (conn->tmabort_state == TMABORT_INITIAL) { 1068 if (conn->tmabort_state == TMABORT_INITIAL) {
diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
index 02f6e4b9e693..4a44278ed768 100644
--- a/include/scsi/iscsi_proto.h
+++ b/include/scsi/iscsi_proto.h
@@ -40,6 +40,14 @@
40} 40}
41#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;} 41#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
42 42
43/* initiator tags; opaque for target */
44typedef uint32_t __bitwise__ itt_t;
45/* below makes sense only for initiator that created this tag */
46#define build_itt(itt, id, age) ((__force itt_t)\
47 ((itt) | ((id) << ISCSI_CID_SHIFT) | ((age) << ISCSI_AGE_SHIFT)))
48#define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
49#define RESERVED_ITT ((__force itt_t)0xffffffff)
50
43/* 51/*
44 * iSCSI Template Message Header 52 * iSCSI Template Message Header
45 */ 53 */
@@ -50,7 +58,7 @@ struct iscsi_hdr {
50 uint8_t hlength; /* AHSs total length */ 58 uint8_t hlength; /* AHSs total length */
51 uint8_t dlength[3]; /* Data length */ 59 uint8_t dlength[3]; /* Data length */
52 uint8_t lun[8]; 60 uint8_t lun[8];
53 __be32 itt; /* Initiator Task Tag */ 61 itt_t itt; /* Initiator Task Tag, opaque for target */
54 __be32 ttt; /* Target Task Tag */ 62 __be32 ttt; /* Target Task Tag */
55 __be32 statsn; 63 __be32 statsn;
56 __be32 exp_statsn; 64 __be32 exp_statsn;
@@ -111,7 +119,7 @@ struct iscsi_cmd {
111 uint8_t hlength; 119 uint8_t hlength;
112 uint8_t dlength[3]; 120 uint8_t dlength[3];
113 uint8_t lun[8]; 121 uint8_t lun[8];
114 __be32 itt; /* Initiator Task Tag */ 122 itt_t itt; /* Initiator Task Tag */
115 __be32 data_length; 123 __be32 data_length;
116 __be32 cmdsn; 124 __be32 cmdsn;
117 __be32 exp_statsn; 125 __be32 exp_statsn;
@@ -148,7 +156,7 @@ struct iscsi_cmd_rsp {
148 uint8_t hlength; 156 uint8_t hlength;
149 uint8_t dlength[3]; 157 uint8_t dlength[3];
150 uint8_t rsvd[8]; 158 uint8_t rsvd[8];
151 __be32 itt; /* Initiator Task Tag */ 159 itt_t itt; /* Initiator Task Tag */
152 __be32 rsvd1; 160 __be32 rsvd1;
153 __be32 statsn; 161 __be32 statsn;
154 __be32 exp_cmdsn; 162 __be32 exp_cmdsn;
@@ -206,7 +214,7 @@ struct iscsi_nopout {
206 uint8_t rsvd3; 214 uint8_t rsvd3;
207 uint8_t dlength[3]; 215 uint8_t dlength[3];
208 uint8_t lun[8]; 216 uint8_t lun[8];
209 __be32 itt; /* Initiator Task Tag */ 217 itt_t itt; /* Initiator Task Tag */
210 __be32 ttt; /* Target Transfer Tag */ 218 __be32 ttt; /* Target Transfer Tag */
211 __be32 cmdsn; 219 __be32 cmdsn;
212 __be32 exp_statsn; 220 __be32 exp_statsn;
@@ -221,7 +229,7 @@ struct iscsi_nopin {
221 uint8_t rsvd3; 229 uint8_t rsvd3;
222 uint8_t dlength[3]; 230 uint8_t dlength[3];
223 uint8_t lun[8]; 231 uint8_t lun[8];
224 __be32 itt; /* Initiator Task Tag */ 232 itt_t itt; /* Initiator Task Tag */
225 __be32 ttt; /* Target Transfer Tag */ 233 __be32 ttt; /* Target Transfer Tag */
226 __be32 statsn; 234 __be32 statsn;
227 __be32 exp_cmdsn; 235 __be32 exp_cmdsn;
@@ -237,8 +245,8 @@ struct iscsi_tm {
237 uint8_t hlength; 245 uint8_t hlength;
238 uint8_t dlength[3]; 246 uint8_t dlength[3];
239 uint8_t lun[8]; 247 uint8_t lun[8];
240 __be32 itt; /* Initiator Task Tag */ 248 itt_t itt; /* Initiator Task Tag */
241 __be32 rtt; /* Reference Task Tag */ 249 itt_t rtt; /* Reference Task Tag */
242 __be32 cmdsn; 250 __be32 cmdsn;
243 __be32 exp_statsn; 251 __be32 exp_statsn;
244 __be32 refcmdsn; 252 __be32 refcmdsn;
@@ -267,8 +275,8 @@ struct iscsi_tm_rsp {
267 uint8_t hlength; 275 uint8_t hlength;
268 uint8_t dlength[3]; 276 uint8_t dlength[3];
269 uint8_t rsvd2[8]; 277 uint8_t rsvd2[8];
270 __be32 itt; /* Initiator Task Tag */ 278 itt_t itt; /* Initiator Task Tag */
271 __be32 rtt; /* Reference Task Tag */ 279 itt_t rtt; /* Reference Task Tag */
272 __be32 statsn; 280 __be32 statsn;
273 __be32 exp_cmdsn; 281 __be32 exp_cmdsn;
274 __be32 max_cmdsn; 282 __be32 max_cmdsn;
@@ -293,7 +301,7 @@ struct iscsi_r2t_rsp {
293 uint8_t hlength; 301 uint8_t hlength;
294 uint8_t dlength[3]; 302 uint8_t dlength[3];
295 uint8_t lun[8]; 303 uint8_t lun[8];
296 __be32 itt; /* Initiator Task Tag */ 304 itt_t itt; /* Initiator Task Tag */
297 __be32 ttt; /* Target Transfer Tag */ 305 __be32 ttt; /* Target Transfer Tag */
298 __be32 statsn; 306 __be32 statsn;
299 __be32 exp_cmdsn; 307 __be32 exp_cmdsn;
@@ -311,7 +319,7 @@ struct iscsi_data {
311 uint8_t rsvd3; 319 uint8_t rsvd3;
312 uint8_t dlength[3]; 320 uint8_t dlength[3];
313 uint8_t lun[8]; 321 uint8_t lun[8];
314 __be32 itt; 322 itt_t itt;
315 __be32 ttt; 323 __be32 ttt;
316 __be32 rsvd4; 324 __be32 rsvd4;
317 __be32 exp_statsn; 325 __be32 exp_statsn;
@@ -331,7 +339,7 @@ struct iscsi_data_rsp {
331 uint8_t hlength; 339 uint8_t hlength;
332 uint8_t dlength[3]; 340 uint8_t dlength[3];
333 uint8_t lun[8]; 341 uint8_t lun[8];
334 __be32 itt; 342 itt_t itt;
335 __be32 ttt; 343 __be32 ttt;
336 __be32 statsn; 344 __be32 statsn;
337 __be32 exp_cmdsn; 345 __be32 exp_cmdsn;
@@ -355,7 +363,7 @@ struct iscsi_text {
355 uint8_t hlength; 363 uint8_t hlength;
356 uint8_t dlength[3]; 364 uint8_t dlength[3];
357 uint8_t rsvd4[8]; 365 uint8_t rsvd4[8];
358 __be32 itt; 366 itt_t itt;
359 __be32 ttt; 367 __be32 ttt;
360 __be32 cmdsn; 368 __be32 cmdsn;
361 __be32 exp_statsn; 369 __be32 exp_statsn;
@@ -373,7 +381,7 @@ struct iscsi_text_rsp {
373 uint8_t hlength; 381 uint8_t hlength;
374 uint8_t dlength[3]; 382 uint8_t dlength[3];
375 uint8_t rsvd4[8]; 383 uint8_t rsvd4[8];
376 __be32 itt; 384 itt_t itt;
377 __be32 ttt; 385 __be32 ttt;
378 __be32 statsn; 386 __be32 statsn;
379 __be32 exp_cmdsn; 387 __be32 exp_cmdsn;
@@ -392,7 +400,7 @@ struct iscsi_login {
392 uint8_t dlength[3]; 400 uint8_t dlength[3];
393 uint8_t isid[6]; /* Initiator Session ID */ 401 uint8_t isid[6]; /* Initiator Session ID */
394 __be16 tsih; /* Target Session Handle */ 402 __be16 tsih; /* Target Session Handle */
395 __be32 itt; /* Initiator Task Tag */ 403 itt_t itt; /* Initiator Task Tag */
396 __be16 cid; 404 __be16 cid;
397 __be16 rsvd3; 405 __be16 rsvd3;
398 __be32 cmdsn; 406 __be32 cmdsn;
@@ -421,7 +429,7 @@ struct iscsi_login_rsp {
421 uint8_t dlength[3]; 429 uint8_t dlength[3];
422 uint8_t isid[6]; /* Initiator Session ID */ 430 uint8_t isid[6]; /* Initiator Session ID */
423 __be16 tsih; /* Target Session Handle */ 431 __be16 tsih; /* Target Session Handle */
424 __be32 itt; /* Initiator Task Tag */ 432 itt_t itt; /* Initiator Task Tag */
425 __be32 rsvd3; 433 __be32 rsvd3;
426 __be32 statsn; 434 __be32 statsn;
427 __be32 exp_cmdsn; 435 __be32 exp_cmdsn;
@@ -478,7 +486,7 @@ struct iscsi_logout {
478 uint8_t hlength; 486 uint8_t hlength;
479 uint8_t dlength[3]; 487 uint8_t dlength[3];
480 uint8_t rsvd2[8]; 488 uint8_t rsvd2[8];
481 __be32 itt; /* Initiator Task Tag */ 489 itt_t itt; /* Initiator Task Tag */
482 __be16 cid; 490 __be16 cid;
483 uint8_t rsvd3[2]; 491 uint8_t rsvd3[2];
484 __be32 cmdsn; 492 __be32 cmdsn;
@@ -505,7 +513,7 @@ struct iscsi_logout_rsp {
505 uint8_t hlength; 513 uint8_t hlength;
506 uint8_t dlength[3]; 514 uint8_t dlength[3];
507 uint8_t rsvd3[8]; 515 uint8_t rsvd3[8];
508 __be32 itt; /* Initiator Task Tag */ 516 itt_t itt; /* Initiator Task Tag */
509 __be32 rsvd4; 517 __be32 rsvd4;
510 __be32 statsn; 518 __be32 statsn;
511 __be32 exp_cmdsn; 519 __be32 exp_cmdsn;
@@ -528,7 +536,7 @@ struct iscsi_snack {
528 uint8_t opcode; 536 uint8_t opcode;
529 uint8_t flags; 537 uint8_t flags;
530 uint8_t rsvd2[14]; 538 uint8_t rsvd2[14];
531 __be32 itt; 539 itt_t itt;
532 __be32 begrun; 540 __be32 begrun;
533 __be32 runlength; 541 __be32 runlength;
534 __be32 exp_statsn; 542 __be32 exp_statsn;