Return-Path: <owner-ips-outgoing@ece.cmu.edu>
Received: from newbox.ece.cmu.edu (localhost [127.0.0.1])
	by newbox.ece.cmu.edu (Cyrus v2.1.12) with LMTP; Tue, 22 Jul 2003 17:31:16 -0400
X-Sieve: CMU Sieve 2.2
Received: from hazard.ece.cmu.edu (HAZARD.ECE.CMU.EDU [128.2.129.24])
	by newbox.ece.cmu.edu (Postfix) with ESMTP id 81E8D30C5
	for <ipsml@ece.cmu.edu>; Tue, 22 Jul 2003 17:31:16 -0400 (EDT)
Received: by hazard.ece.cmu.edu (Postfix, from userid 953)
	id 0EDAA158; Tue, 22 Jul 2003 17:31:16 -0400 (EDT)
Received: from sos.ece.cmu.edu (SOS.ECE.CMU.EDU [128.2.129.27])
	by hazard.ece.cmu.edu (Postfix) with ESMTP
	id 891ECF0; Tue, 22 Jul 2003 17:30:59 -0400 (EDT)
Received: by sos.ece.cmu.edu (Postfix)
	id 0390F89DB; Tue, 22 Jul 2003 17:30:45 -0400 (EDT)
Delivered-To: ips-outgoing@sos.ece.cmu.edu
Received: from bache.ece.cmu.edu (BACHE.ECE.CMU.EDU [128.2.129.23])
	by sos.ece.cmu.edu (Postfix) with ESMTP id E6E9989D8
	for <ips-outgoing@sos.ece.cmu.edu>; Tue, 22 Jul 2003 17:30:44 -0400 (EDT)
Received: by bache.ece.cmu.edu (Postfix)
	id 8CDB633; Tue, 22 Jul 2003 17:30:44 -0400 (EDT)
Delivered-To: ips-outgoing@ece.cmu.edu
Received: by bache.ece.cmu.edu (Postfix, from userid 953)
	id 598F57A; Tue, 22 Jul 2003 17:30:44 -0400 (EDT)
Received: from sos.ece.cmu.edu (SOS.ECE.CMU.EDU [128.2.129.27])
	by bache.ece.cmu.edu (Postfix) with ESMTP id EA2D633
	for <ips-outgoing@ece.cmu.edu>; Tue, 22 Jul 2003 17:30:36 -0400 (EDT)
Received: by sos.ece.cmu.edu (Postfix, from userid 363)
	id 9FA7F89DC; Tue, 22 Jul 2003 17:30:36 -0400 (EDT)
X-Original-To: ips@sos.ece.cmu.edu
Delivered-To: ips@sos.ece.cmu.edu
Received: from hazard.ece.cmu.edu (HAZARD.ECE.CMU.EDU [128.2.129.24])
	by sos.ece.cmu.edu (Postfix) with ESMTP id DB0AA89D8
	for <ips@sos.ece.cmu.edu>; Tue, 22 Jul 2003 17:30:33 -0400 (EDT)
Received: by hazard.ece.cmu.edu (Postfix)
	id 77283EF; Tue, 22 Jul 2003 17:30:33 -0400 (EDT)
Delivered-To: ips@ece.cmu.edu
Received: by hazard.ece.cmu.edu (Postfix, from userid 953)
	id 403C210B; Tue, 22 Jul 2003 17:30:33 -0400 (EDT)
Received: from ztxmail04.ztx.compaq.com (ztxmail04.ztx.compaq.com [161.114.1.208])
	by hazard.ece.cmu.edu (Postfix) with ESMTP id BFA49EF
	for <ips@ece.cmu.edu>; Tue, 22 Jul 2003 17:30:26 -0400 (EDT)
Received: from cceexg13.americas.cpqcorp.net (cceexg13.americas.cpqcorp.net [16.110.250.119])
	by ztxmail04.ztx.compaq.com (Postfix) with ESMTP
	id 31EFBBC43; Tue, 22 Jul 2003 16:30:26 -0500 (CDT)
Received: from cceexc18.americas.cpqcorp.net ([16.81.1.4]) by cceexg13.americas.cpqcorp.net with Microsoft SMTPSVC(5.0.2195.6673);
	 Tue, 22 Jul 2003 16:30:25 -0500
X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0
Content-Class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C35098.76785134"
Subject: RE: CDB/PDU inconsistencies and residual counts
Date: Tue, 22 Jul 2003 16:30:24 -0500
Message-ID: <31891B757C09184BBFEC5275F85D5595048BA228@cceexc18.americas.cpqcorp.net>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: CDB/PDU inconsistencies and residual counts
Thread-Index: AcNQcGejqNCknLxREdeLgQBQ2thomQAGmt5g
From: "Martin, Nick (Server Storage)" <nick.martin@hp.com>
To: "Dean Scoville" <dean.scoville@qlogic.com>,
	"Julian Satran" <Julian_Satran@il.ibm.com>
Cc: <ips@ece.cmu.edu>
X-OriginalArrivalTime: 22 Jul 2003 21:30:25.0949 (UTC) FILETIME=[7712FCD0:01C35098]
Sender: owner-ips@ece.cmu.edu
Precedence: bulk
X-Spam-Status: No, hits=-5.0 required=5.0
	tests=BAYES_10,HTML_30_40,HTML_FONT_COLOR_BLUE
	version=2.50
X-Spam-Level: 
X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp)

This is a multi-part message in MIME format.

------_=_NextPart_001_01C35098.76785134
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Dean,
=20
I have seen some good answers to this already, but let me try to explain
it from another point of view.  That of the layered SCSI subsystem in
the host OS. =20
=20
In a layered SCSI subsystem as found in most modern operating systems,
the HBA driver is normally given a request generated by a Target driver
(such as a SCSI Disk class driver).  The request includes a CDB,
transfer direction bits, and a buffer address and length (often in the
form of a scatter/gather list).  After scheduling and processing the
request, the HBA driver is responsible to return status to tell the
Target driver what happened with respect to the buffer of data it
requested to be transferred by the device. =20
=20
The purpose of the overflow-underflow indication is to tell the
originator of the request whether the device attempted to transfer more,
less, or exactly the same number of bytes as was specified in the buffer
length of the original request to the HBA driver.   The residual count
reports the variance from the buffer length.
=20
In the case of the iSCSI HBA driver, the length of the buffer passed to
the HBA is used as the "expected transfer length".  The iSCSI protocol
enables the transfer of this number of bytes between the initiator and
the iSCSI target over the wire.  If the SCSI layer in the target
requests or attempts to transfer more or less than this original
expected number of bytes (the length of the buffer in the original
request), an underflow or overflow should be returned over the wire to
the iSCSI HBA so that it can be reported to the SCSI Target driver.
=20
For the case of overflow iSCSI can never transport more than expected
transfer length.  For the case of underflow, iSCSI may or may not
transport bytes within expected transfer length unused by the SCSI
layer.
=20
There are cases in which the Target driver will not know how in advance
how much data the Target will attempt to return for a given CDB.  In
these cases, most Target drivers will use an oversized buffer, the
buffer is not filled, an underrun is reported, and the residual is the
difference between the buffer size and the bytes transfered by the SCSI
device.  Conversely the Target driver may intentionally or
unintentionally use an undersized buffer relative to the target devices
interpretation of the command contained in the CDB.
=20
It should be the target driver writer's job to interpret and handle the
underrun and overrun status.  These may be expected or unexpected
results.  The lengths must be reported as a byte count of variance from
the buffer length.  When buffer length is sent as "expected transfer
length" the iSCSI target can do the residual length calculation
properly.
=20
Thanks,
Nick

	-----Original Message-----
	From: Dean Scoville [mailto:dean.scoville@qlogic.com]=20
	Sent: Tuesday, July 22, 2003 11:43 AM
	To: Julian Satran
	Cc: ips@ece.cmu.edu
	Subject: CDB/PDU inconsistencies and residual counts
=09
=09

	Julian,=20
	The overflow/underflow and residual count values in Data-in and=20
	SCSI Response PDUs are set by the target based on the expected=20
	transfer length for the command, but should these values be set
based=20
	on the CDB (SCSI layer) or based on the PDU "expected data
transfer length"=20
	field (iSCSI layer)?=20

	For example, suppose an initiator sends a 4 block SCSI Read
command=20
	but for some reason thinks the block size is 1024 bytes when in
actuality=20
	the disk has 512 byte blocks. The SCSI Command PDU would have an

	"expected data transfer length" of value of 4096 bytes, but the
target would=20
	actually return 2048 bytes (based on the true block size).
Should the target=20
	set the underflow bit and return a residual count (based on the
iSCSI PDU),=20
	or should it return no underflow and no residual count (based on
the SCSI CDB)?=20

	The question comes up because I was running some iSCSI protocol
test=20
	scripts where the PDU "expected transfer length" and the
transfer length=20
	in the CDB were inconsistent in one of the scripts.=20

	Another example would be if the "allocation length" field in the
CDB for=20
	an Inquiry command doesn't match the "expected data transfer
length" field=20
	in the SCSI Command PDU.=20

	The script was in error and should be fixed, is there a desired
target=20
	behavior in such situations, given that the CDB fields are not
typically parsed=20
	by the iSCSI layer, the SCSI device may know nothing about iSCSI
PDUs,=20
	and some middle-layer may or may not know about both.=20

	If the initiator detects that an underflow has occurred, based
solely on the=20
	amount of data received and the "expected data transfer field"
in the iSCSI PDU,=20
	but the target did not report an underflow or residual count in
the SCSI response,=20
	is the initiator allowed/expected to report an underflow to the
upper layers?=20

	Thanks,=20

	Dean Scoville=20


------_=_NextPart_001_01C35098.76785134
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2>Dean,</FONT></SPAN></DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff size=3D2>I =
have seen some=20
good answers to this already, but let me try to explain it from another =
point of=20
view.&nbsp; That of the layered&nbsp;SCSI subsystem in the host =
OS.&nbsp;=20
</FONT></SPAN></DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff><FONT size=3D2><SPAN =
class=3D732033918-22072003>In a=20
layered SCSI subsystem as found in most modern operating systems, =
</SPAN><SPAN=20
class=3D732033918-22072003>the HBA driver is normally given a request =
generated by=20
a Target driver<SPAN class=3D401475219-22072003> (such as a SCSI Disk =
class=20
driver)</SPAN>.&nbsp; The request includes a CDB,&nbsp;transfer =
direction=20
bits,&nbsp;and a buffer&nbsp;address and length (often in the form of a=20
scatter/gather list).&nbsp; After scheduling and processing the request, =
the HBA=20
driver is responsible to&nbsp;return status to tell the&nbsp;Target =
driver what=20
happened with respect to the buffer of data&nbsp;it requested to be=20
transferred&nbsp;by the device.&nbsp; </SPAN></FONT></FONT></DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff><FONT size=3D2><SPAN =
class=3D732033918-22072003>The purpose=20
of the overflow-underflow indication is to tell the originator of the =
request=20
whether the device attempted to transfer more, less, or exactly the same =
number=20
of bytes as was specified in the buffer length of the original request =
to the=20
HBA driver.&nbsp;&nbsp;&nbsp;The residual count reports =
the&nbsp;variance=20
from&nbsp;the&nbsp;buffer&nbsp;length.</SPAN></FONT></FONT></DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff size=3D2>In =
the case of=20
the iSCSI HBA driver, the length of the buffer passed to the HBA is used =
as the=20
"expected transfer length".&nbsp; The iSCSI protocol&nbsp;enables the =
transfer=20
of&nbsp;this number of bytes between&nbsp;the initiator&nbsp;and the =
iSCSI=20
target over the wire.&nbsp; If the&nbsp;SCSI layer in the =
target&nbsp;<SPAN=20
class=3D401475219-22072003>requests or </SPAN>attempts to transfer more =
or less=20
than this original&nbsp;expected&nbsp;number of&nbsp;bytes (the length =
of the=20
buffer in the original request), an&nbsp;underflow or =
overflow&nbsp;should be=20
returned&nbsp;over the wire to the iSCSI HBA so that it can be reported =
to the=20
SCSI Target driver.</FONT></SPAN></DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff><FONT =
size=3D2><SPAN=20
class=3D401475219-22072003>For</SPAN>&nbsp;the case of overflow iSCSI =
can=20
never&nbsp;transport more than expected transfer =
length.&nbsp;&nbsp;<SPAN=20
class=3D401475219-22072003>For the case of underflow, =
</SPAN>iSCSI&nbsp;<SPAN=20
class=3D401475219-22072003>may or may =
not</SPAN>&nbsp;transport&nbsp;bytes within=20
expected transfer length&nbsp;unused by&nbsp;the SCSI=20
layer.</FONT></FONT></SPAN></DIV>
<DIV><FONT color=3D#0000ff><FONT size=3D2><SPAN=20
class=3D732033918-22072003></SPAN><SPAN=20
class=3D732033918-22072003></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff><FONT =
size=3D2>There are=20
cases in which the Target driver&nbsp;will not&nbsp;know how in=20
advance&nbsp;<SPAN class=3D401475219-22072003>how </SPAN>much data the =
Target=20
will&nbsp;attempt to&nbsp;return<SPAN class=3D401475219-22072003> for a =
given=20
CDB</SPAN>.<SPAN class=3D401475219-22072003>&nbsp; In these cases,=20
most&nbsp;</SPAN>Target driver<SPAN =
class=3D401475219-22072003>s</SPAN><SPAN=20
class=3D401475219-22072003> will</SPAN>&nbsp;use an oversized buffer, =
the buffer=20
is not filled, an underrun is reported, and the residual is the =
difference=20
between the&nbsp;buffer size and the bytes transfered<SPAN=20
class=3D401475219-22072003> by the SCSI device</SPAN>.<SPAN=20
class=3D401475219-22072003>&nbsp;&nbsp;</SPAN><SPAN=20
class=3D401475219-22072003>Conversely the Target driver may =
intentionally or=20
unintentionally&nbsp;use an undersized buffer relative to =
the&nbsp;target=20
devices&nbsp;interpretation of the command contained in the=20
CDB.</SPAN></FONT></FONT></SPAN></DIV>
<DIV><FONT color=3D#0000ff><FONT size=3D2><FONT face=3DTahoma><FONT =
face=3DArial><SPAN=20
class=3D732033918-22072003></SPAN></FONT></FONT><FONT =
face=3DTahoma><FONT=20
face=3DArial><SPAN=20
class=3D732033918-22072003></SPAN></FONT></FONT></FONT></FONT>&nbsp;</DIV=
>
<DIV><SPAN class=3D732033918-22072003><FONT color=3D#0000ff><FONT=20
size=3D2>It&nbsp;should be&nbsp;the target driver writer's job to =
interpret and=20
handle the underrun and overrun status.&nbsp; The<SPAN=20
class=3D401475219-22072003>se</SPAN> may be expected or unexpected =
results.&nbsp;=20
The lengths must be reported as a byte count of variance<SPAN=20
class=3D401475219-22072003> from the buffer length</SPAN>.<SPAN=20
class=3D401475219-22072003>&nbsp;&nbsp;When buffer length is&nbsp;sent =
as=20
"expected transfer length" the iSCSI target can do the residual length=20
calculation properly.</SPAN></FONT></FONT></SPAN></DIV>
<DIV><FONT face=3DTahoma><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D732033918-22072003></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTahoma><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D732033918-22072003>Thanks,</SPAN></FONT></FONT></DIV>
<DIV><FONT face=3DTahoma><FONT face=3DArial color=3D#0000ff =
size=3D2><SPAN=20
class=3D732033918-22072003>Nick</SPAN></FONT></FONT></DIV></FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT=20
  face=3DTahoma size=3D2>-----Original Message-----<BR><B>From:</B> Dean =
Scoville=20
  [mailto:dean.scoville@qlogic.com] <BR><B>Sent:</B> Tuesday, July 22, =
2003=20
  11:43 AM<BR><B>To:</B> Julian Satran<BR><B>Cc:</B>=20
  ips@ece.cmu.edu<BR><B>Subject:</B> CDB/PDU inconsistencies and =
residual=20
  counts<BR><BR></FONT></DIV><!-- Converted from text/rtf format -->
  <P><FONT face=3DArial size=3D2>Julian,</FONT> <BR><FONT face=3DArial =
size=3D2>The=20
  overflow/underflow and residual count values in Data-in and =
</FONT><BR><FONT=20
  face=3DArial size=3D2>SCSI Response PDUs are set by the target based =
on the=20
  expected</FONT> <BR><FONT face=3DArial size=3D2>transfer length for =
the command,=20
  but should these values be set based</FONT> <BR><FONT face=3DArial =
size=3D2>on the=20
  CDB (SCSI layer) or based on the PDU "expected data transfer =
length"</FONT>=20
  <BR><FONT face=3DArial size=3D2>field (iSCSI layer)?</FONT> </P>
  <P><FONT face=3DArial size=3D2>For example, suppose an initiator sends =
a 4 block=20
  SCSI Read command</FONT> <BR><FONT face=3DArial size=3D2>but for some =
reason=20
  thinks the block size is 1024 bytes when in actuality</FONT> <BR><FONT =

  face=3DArial size=3D2>the disk has 512 byte blocks. The SCSI Command =
PDU would=20
  have an </FONT><BR><FONT face=3DArial size=3D2>"expected data transfer =
length" of=20
  value of 4096 bytes, but the target would</FONT> <BR><FONT =
face=3DArial=20
  size=3D2>actually return 2048 bytes (based on the true block size). =
Should the=20
  target</FONT> <BR><FONT face=3DArial size=3D2>set the underflow bit =
and return a=20
  residual count (based on the iSCSI PDU),</FONT> <BR><FONT face=3DArial =
size=3D2>or=20
  should it return no underflow and no residual count (based on the SCSI =

  CDB)?</FONT> </P>
  <P><FONT face=3DArial size=3D2>The question comes up because I was =
running some=20
  iSCSI protocol test</FONT> <BR><FONT face=3DArial size=3D2>scripts =
where the PDU=20
  "expected transfer length" and the transfer length </FONT><BR><FONT =
face=3DArial=20
  size=3D2>in the CDB were inconsistent in one of the scripts.</FONT> =
</P>
  <P><FONT face=3DArial size=3D2>Another example would be if the =
"allocation length"=20
  field in the CDB for</FONT> <BR><FONT face=3DArial size=3D2>an Inquiry =
command=20
  doesn't match the "expected data transfer length" field</FONT> =
<BR><FONT=20
  face=3DArial size=3D2>in the SCSI Command PDU.</FONT> </P>
  <P><FONT face=3DArial size=3D2>The script was in error and should be =
fixed, is=20
  there a desired target </FONT><BR><FONT face=3DArial size=3D2>behavior =
in such=20
  situations, given that the CDB fields are not typically parsed</FONT>=20
  <BR><FONT face=3DArial size=3D2>by the iSCSI layer, the SCSI device =
may know=20
  nothing about iSCSI PDUs,</FONT> <BR><FONT face=3DArial size=3D2>and =
some=20
  middle-layer may or may not know about both.</FONT> </P>
  <P><FONT face=3DArial size=3D2>If the initiator detects that an =
underflow has=20
  occurred, based solely on the</FONT> <BR><FONT face=3DArial =
size=3D2>amount of=20
  data received and the "expected data transfer field" in the iSCSI =
PDU,</FONT>=20
  <BR><FONT face=3DArial size=3D2>but the target did not report an =
underflow or=20
  residual count in the SCSI response,</FONT> <BR><FONT face=3DArial =
size=3D2>is the=20
  initiator allowed/expected to report an underflow to the upper =
layers?</FONT>=20
  </P>
  <P><FONT face=3DArial size=3D2>Thanks,</FONT> </P>
  <P><FONT face=3DArial size=3D2>Dean Scoville</FONT> =
</P></BLOCKQUOTE></BODY></HTML>
=00
------_=_NextPart_001_01C35098.76785134--
