virtio spec 0.8.9
diff --git a/virtio.lyx b/virtio.lyx
index 8fee4a9..37404b6 100644
--- a/virtio.lyx
+++ b/virtio.lyx
@@ -1,4 +1,4 @@
-#LyX 1.6.4 created this file. For more info see http://www.lyx.org/
+#LyX 1.6.5 created this file. For more info see http://www.lyx.org/
 \lyxformat 345
 \begin_document
 \begin_header
@@ -36,8 +36,7 @@
 \paperpagestyle default
 \tracking_changes true
 \output_changes true
-\author "" 
-\author "" 
+\author "Rusty Russell,,," 
 \author "" 
 \end_header
 
@@ -48,7 +47,7 @@
 \begin_inset Newline newline
 \end_inset
 
-v0.8.8 DRAFT
+v0.8.9 DRAFT
 \begin_inset Newline newline
 \end_inset
 
@@ -64,7 +63,7 @@
 \end_layout
 
 \begin_layout Date
-2010 April 29.
+2010 September 27.
 \end_layout
 
 \begin_layout Chapter
@@ -308,7 +307,7 @@
 
 \begin_layout Standard
 \begin_inset Tabular
-<lyxtabular version="3" rows="7" columns="3">
+<lyxtabular version="3" rows="8" columns="3">
 <features>
 <column alignment="center" valignment="top" width="0">
 <column alignment="center" valignment="top" width="0">
@@ -488,6 +487,35 @@
 </cell>
 </row>
 <row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+6
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+ioMemory
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+-
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
 \begin_inset Text
 
@@ -2342,7 +2370,7 @@
 before
 \emph default
  checking the suppression flag: it's OK to notify gratuitously, but not
- to skip a notification.
+ to omit a required notification.
  So again, we use a memory barrier here before reading the flags.
 \end_layout
 
@@ -4386,7 +4414,7 @@
 The device can filter incoming packets by any number of destination MAC
  addresses.
 \begin_inset Foot
-status open
+status collapsed
 
 \begin_layout Plain Layout
 Since there are no guarentees, it can use a hash filter orsilently switch
@@ -4562,6 +4590,14 @@
 \end_layout
 
 \begin_layout Description
+VIRTIO_BLK_F_SCSI (7) Device supports scsi packet commands.
+\end_layout
+
+\begin_layout Description
+VIRTIO_BLK_F_FLUSH (9) Cache flush command support.
+\end_layout
+
+\begin_layout Description
 VIRTIO_BLK_F_SECTOR_MAX
 \begin_inset space ~
 \end_inset
@@ -4710,17 +4746,6 @@
 
 \begin_layout Plain Layout
 
-#define VIRTIO_BLK_T_IN          0
-\end_layout
-
-\begin_layout Plain Layout
-
-#define VIRTIO_BLK_T_OUT         1
-\end_layout
-
-\begin_layout Plain Layout
-
-#define VIRTIO_BLK_T_BARRIER	 0x80000000
 \end_layout
 
 \begin_layout Plain Layout
@@ -4745,12 +4770,84 @@
 
 \begin_layout Plain Layout
 
-#define VIRTIO_BLK_S_OK        0
+	u8 status;
 \end_layout
 
 \begin_layout Plain Layout
 
-#define VIRTIO_BLK_S_IOERR     1
+};
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+If the device has VIRTIO_BLK_F_SCSI feature, it can also support scsi packet
+ command requests, each of these requests is of form:
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+struct virtio_scsi_pc_req {
+\end_layout
+
+\begin_layout Plain Layout
+
+	u32 type;
+\end_layout
+
+\begin_layout Plain Layout
+
+	u32 ioprio;
+\end_layout
+
+\begin_layout Plain Layout
+
+	u64 sector;
+\end_layout
+
+\begin_layout Plain Layout
+
+    char cmd[];
+\end_layout
+
+\begin_layout Plain Layout
+
+	char data[][512];
+\end_layout
+
+\begin_layout Plain Layout
+
+#define SCSI_SENSE_BUFFERSIZE   96
+\end_layout
+
+\begin_layout Plain Layout
+
+    u8 sense[SCSI_SENSE_BUFFERSIZE];
+\end_layout
+
+\begin_layout Plain Layout
+
+    u32 errors;
+\end_layout
+
+\begin_layout Plain Layout
+
+    u32 data_len;
+\end_layout
+
+\begin_layout Plain Layout
+
+    u32 sense_len;
+\end_layout
+
+\begin_layout Plain Layout
+
+    u32 residual;
 \end_layout
 
 \begin_layout Plain Layout
@@ -4769,32 +4866,270 @@
 \end_layout
 
 \begin_layout Standard
-The type of the request is either a read (VIRTIO_BLK_T_IN) or a write (VIRTIO_BL
-K_T_OUT); the high bit indicates that this request acts as a barrier and
- that all preceeding requests must be complete before this one, and all
- following requests must not be started until this is complete.
+The 
+\emph on
+type
+\emph default
+ of the request is either a read (VIRTIO_BLK_T_IN),
+\change_deleted 0 1285634492
+ 
+\change_unchanged
+ a write (VIRTIO_BLK_T_OUT), a scsi packet command (VIRTIO_BLK_T_SCSI_CMD
+ or VIRTIO_BLK_T_SCSI_CMD_OUT
+\begin_inset Foot
+status open
+
+\begin_layout Plain Layout
+the SCSI_CMD and SCSI_CMD_OUT types are equivalent, the device does not
+ distinguish between them
+\end_layout
+
+\end_inset
+
+) or a flush (VIRTIO_BLK_T_FLUSH or VIRTIO_BLK_T_FLUSH_OUT
+\begin_inset Foot
+status open
+
+\begin_layout Plain Layout
+the FLUSH and FLUSH_OUT types are equivalent, the device does not distinguish
+ between them
+\end_layout
+
+\end_inset
+
+).
+ If the device has VIRTIO_BLK_F_BARRIER feature
+\begin_inset space ~
+\end_inset
+
+the high bit (VIRTIO_BLK_T_BARRIER) indicates that this request acts as
+ a barrier and that all preceeding requests must be complete before this
+ one, and all following requests must not be started until this is complete.
+ Note that a barrier does not flush caches in the underlying backend device
+ in host, and thus does not serve as data consistency guarantee.
+ Driver must use FLUSH request to flush the host cache.
 \end_layout
 
 \begin_layout Standard
-The ioprio field is a hint about the relative priorities of requests to
- the device: higher numbers indicate more important requests.
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_IN           0
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_OUT          1
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_SCSI_CMD     2
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_SCSI_CMD_OUT 3
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_FLUSH        4
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_FLUSH_OUT    5
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_T_BARRIER	 0x80000000
+\end_layout
+
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
-The sector number indicates the offset (multiplied by 512) where the read
- or write is to occur.
+The 
+\emph on
+ioprio
+\emph default
+ field is a hint about the relative priorities of requests to the device:
+ higher numbers indicate more important requests.
 \end_layout
 
 \begin_layout Standard
-Note that these first three fields are always read-only: the data field
- is either read-only or write-only, depending on the type of the request.
+The 
+\emph on
+sector
+\emph default
+ number indicates the offset (multiplied by 512) where the read or write
+ is to occur.
+ This field is unused and set to 0 for scsi packet commands and for flush
+ commands.
+\end_layout
+
+\begin_layout Standard
+The 
+\emph on
+cmd
+\emph default
+ field is only present for scsi packet command requests, and indicates the
+ command to perform.
+ This field must reside in a single, separate read-only buffer; command
+ length can be derived from the length of this buffer.
+ 
+\end_layout
+
+\begin_layout Standard
+Note that these first three (four for scsi packet commands) fields are always
+ read-only: the 
+\emph on
+data
+\emph default
+ field is either read-only or write-only, depending on
+\change_deleted 0 1285634492
+ 
+\change_unchanged
+ the request.
  The size of the read or write can be derived from the total size of the
- request buffer.
+ request buffers.
 \end_layout
 
 \begin_layout Standard
-The final byte is written by the device: either VIRTIO_BLK_S_OK or VIRTIO_BLK_S_
-IOERR.
+The
+\emph on
+ sense
+\emph default
+ field is only present for scsi packet command requests, and indicates the
+ buffer for scsi sense data.
+\end_layout
+
+\begin_layout Standard
+The 
+\emph on
+data_len
+\emph default
+ field is only present for scsi packet command requests, this field is deprecate
+d, and should be ignored by the driver.
+ Historically, devices copied data length there.
+\end_layout
+
+\begin_layout Standard
+The 
+\emph on
+sense_len
+\emph default
+ field is only present for scsi packet command requests and indicates the
+ number of bytes actually written to the 
+\emph on
+sense
+\emph default
+ buffer.
+\end_layout
+
+\begin_layout Standard
+The 
+\emph on
+residual
+\emph default
+ field is only present for scsi packet command requests and indicates the
+ residual size, calculated as data length - number of bytes actually transferred.
+\end_layout
+
+\begin_layout Standard
+The final 
+\emph on
+status
+\emph default
+ byte is written by the device: either VIRTIO_BLK_S_OK for success, VIRTIO_BLK_S
+_IOERR for host or guest error or VIRTIO_BLK_S_UNSUPP for a request unsupported
+ by host:
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_S_OK        0
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_S_IOERR     1
+\end_layout
+
+\begin_layout Plain Layout
+
+#define VIRTIO_BLK_S_UNSUPP    2
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Historically, devices assumed that the fields 
+\emph on
+type
+\emph default
+, 
+\emph on
+ioprio
+\emph default
+ and 
+\emph on
+sector
+\emph default
+ reside in a single, separate read-only buffer; the fields 
+\emph on
+errors
+\emph default
+, 
+\emph on
+data_len
+\emph default
+, 
+\emph on
+sense_len
+\emph default
+ and 
+\emph on
+residual
+\emph default
+ reside in a single, separate write-only buffer; the 
+\emph on
+sense
+\emph default
+ field in a separate write-only buffer of size 96 bytes, by itself; the
+ fields 
+\emph on
+errors
+\emph default
+, 
+\emph on
+data_len
+\emph default
+, 
+\emph on
+sense_len
+\emph default
+ and 
+\emph on
+residual
+\emph default
+ in a single write-only buffer; and the 
+\emph on
+status
+\emph default
+ field is a separate read-only buffer of size 1 byte, by itself.
 \end_layout
 
 \begin_layout Chapter*