OASIS Virtual I/O Device (VIRTIO) TC

  • 1.  [PATCH] latexify document more.

    Posted 12-02-2013 06:37
    This change: - Turns formatted lists into real lists (itemize, etc). - Turns ascii tables into real tables. - Use ldots for ... - Moves footnote to immediately after what it refers to, otherwise we get awkward whitespace before the superscript. - List of stats for balloon contains values in () to match other lists. - Puts lstlisting around CCW code example No actual contents changed, but I haven't committed it yet to avoid stepping on MST's toes if he has outstanding commits. Signed-off-by: Rusty Russell <rusty@au.ibm.com> diff --git a/content.tex b/content.tex index 259dea1..8db13c4 100644 --- a/content.tex +++ b/content.tex @@ -5,10 +5,12 @@ A virtio device is discovered and identified by a bus-specific method
    ef{sec:Virtio Transport Options / Virtio Over MMIO}~
    ameref{sec:Virtio Transport Options / Virtio Over MMIO} and
    ef{sec:Virtio Transport Options / Virtio Over Channel I/O}~
    ameref{sec:Virtio Transport Options / Virtio Over Channel I/O}). Each device consists of the following parts: -o Device Status field -o Feature bits -o Configuration space -o One or more virtqueues +egin{itemize} +item Device Status field +item Feature bits +item Configuration space +item One or more virtqueues +end{itemize} Unless explicitly specified otherwise, all multi-byte fields are little-endian. To reinforce this the examples use typenames like "le16" instead of "uint16_t". @@ -23,25 +25,27 @@ clear a device status bit. This field is 0 upon reset, otherwise at least one bit should be set: - ACKNOWLEDGE (1) Indicates that the guest OS has found the +egin{description} +item[ACKNOWLEDGE (1)] Indicates that the guest OS has found the device and recognized it as a valid virtio device. - DRIVER (2) Indicates that the guest OS knows how to drive the +item[DRIVER (2)] Indicates that the guest OS knows how to drive the device. Under Linux, drivers can be loadable modules so there may be a significant (or infinite) delay before setting this bit. - FEATURES_OK (8) Indicates that the driver has acknowledged all the +item[FEATURES_OK (8)] Indicates that the driver has acknowledged all the features it understands, and feature negotiation is complete. - DRIVER_OK (4) Indicates that the driver is set up and ready to +item[DRIVER_OK (4)] Indicates that the driver is set up and ready to drive the device. - FAILED (128) Indicates that something went wrong in the guest, +item[FAILED (128)] Indicates that something went wrong in the guest, and it has given up on the device. This could be an internal error, or the driver didn't like the device for some reason, or even a fatal error during device operation. The driver MUST reset the device before attempting to re-initialize. +end{description} section{Feature Bits}label{sec:Basic Facilities of a Virtio Device / Feature Bits} @@ -67,12 +71,14 @@ which was not offered. Feature bits are allocated as follows: - 0 to 23: Feature bits for the specific device type +egin{description} +item[0 to 23] Feature bits for the specific device type - 24 to 32: Feature bits reserved for extensions to the queue and +item[24 to 32] Feature bits reserved for extensions to the queue and feature negotiation mechanisms - 33 and above: Feature bits reserved for future extensions. +item[33 and above] Feature bits reserved for future extensions. +end{description} For example, feature bit 0 for a network device (i.e. Subsystem Device ID 1) indicates that the device supports checksumming of @@ -91,15 +97,17 @@ Since these are widely deployed, this specification accommodates optional features to simplify transition from these earlier draft interfaces. Specifically: -Legacy Interface +egin{description} +item[Legacy Interface] is an interface specified by an earlier draft of this specification (up to 0.9.X) -Legacy Device +item[Legacy Device] is a device implemented before this specification was released, and implementing a legacy interface on the host side -Legacy Driver +item[Legacy Driver] is a driver implemented before this specification was released, and implementing a legacy interface on the guest side +end{description} Legacy devices and legacy drivers are not compliant with this specification. @@ -107,13 +115,15 @@ specification. To simplify transition from these earlier draft interfaces, it is possible to implement: -Transitional Device +egin{description} +item[Transitional Device] a device supporting both drivers conforming to this specification, and allowing legacy drivers. -Transitional Driver +item[Transitional Driver] a driver supporting both devices conforming to this specification, and legacy devices. +end{description} Transitional devices and transitional drivers can be compliant with this specification (ie. when not operating in legacy mode). @@ -196,11 +206,11 @@ of the queue. Each virtqueue consists of three parts: - Descriptor Table - - Available Ring - - Used Ring +egin{itemize} +item Descriptor Table +item Available Ring +item Used Ring +end{itemize} where each part is physically-contiguous in guest memory, and has different alignment requirements. @@ -208,18 +218,17 @@ and has different alignment requirements. The memory aligment and size requirements, in bytes, of each part of the virtqueue are summarized in the following table: -egin{verbatim} -+------------+-----------------------------------------+ - Virtqueue Part Alignment Size -+------------+-----------------------------------------+ -+------------+-----------------------------------------+ - Descriptor Table 16 16 * (Queue Size) -+------------+-----------------------------------------+ - Available Ring 2 6 + 2 * (Queue Size) -+------------+-----------------------------------------+ - Used Ring 4 6 + 4 * (Queue Size) -+------------+-----------------------------------------+ -end{verbatim} +egin{tabular}{ l l l } +hline +Virtqueue Part & Alignment & Size \ +hline hline +Descriptor Table & 16 & $16 * $(Queue Size) \ +hline +Available Ring & 2 & $6 + 2 * $(Queue Size) \ + hline +Used Ring & 4 & $6 + 4 * $(Queue Size) \ + hline +end{tabular} The Alignment column gives the miminum alignment: for each part of the virtqueue, the physical address of the first byte @@ -250,11 +259,11 @@ Each virtqueue occupies two or more physically-contiguous pages (usually defined as 4096 bytes, but depending on the transport) and consists of three parts: -egin{verbatim} -+-------------------+-----------------------------------+-----------+ - Descriptor Table Available Ring (padding) Used Ring -+-------------------+-----------------------------------+-----------+ -end{verbatim} +egin{tabular}{ l l l } +hline +Descriptor Table & Available Ring (ldots paddingldots) & Used Ring \ +hline +end{tabular} The bus-specific Queue Size field controls the total number of bytes required for the virtqueue according to the following formula: @@ -503,28 +512,30 @@ how to communicate with the specific device. The driver MUST follow this sequence to initialize a device: -1. Reset the device. +egin{enumerate} +item Reset the device. -2. Set the ACKNOWLEDGE status bit: we have noticed the device. +item Set the ACKNOWLEDGE status bit: we have noticed the device. -3. Set the DRIVER status bit: we know how to drive the device. +item Set the DRIVER status bit: we know how to drive the device. -4. Read device feature bits, and write the subset of feature bits +item Read device feature bits, and write the subset of feature bits understood by the OS and driver to the device. -5. Set the FEATURES_OK status bit. The driver MUST not accept +item Set the FEATURES_OK status bit. The driver MUST not accept new feature bits after this step. -6. Re-read the status byte to ensure the FEATURES_OK bit is still +item Re-read the status byte to ensure the FEATURES_OK bit is still set: otherwise, the device does not support our subset of features and the device is unusable. -7. Perform device-specific setup, including discovery of virtqueues for the +item Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, reading and possibly writing the device's virtio configuration space, and population of virtqueues. -8. Set the DRIVER_OK status bit. At this point the device is +item Set the DRIVER_OK status bit. At this point the device is "live". +end{enumerate} If any of these steps go irrecoverably wrong, the driver SHOULD set the FAILED status bit to indicate that it has given up on the @@ -568,27 +579,29 @@ they are used. The driver offers buffers to one of the device's virtqueues as follows: -1. The driver places the buffer into free descriptor(s) in the +egin{enumerate} +item The driver places the buffer into free descriptor(s) in the descriptor table, chaining as necessary (see
    ef{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table}~
    ameref{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table}). -2. The driver places the index of the head of the descriptor chain +item The driver places the index of the head of the descriptor chain into the next ring entry of the available ring. -3. Steps (1) and (2) may be performed repeatedly if batching +item Steps (1) and (2) may be performed repeatedly if batching is possible. -4. The driver MUST perform suitable a memory barrier to ensure the device sees +item The driver MUST perform suitable a memory barrier to ensure the device sees the updated descriptor table and available ring before the next step. -5. The available “idx” field is increased by the number of +item The available “idx” field is increased by the number of descriptor chain heads added to the available ring. -6. The driver MUST perform a suitable memory barrier to ensure that it updates +item The driver MUST perform a suitable memory barrier to ensure that it updates the "idx" field before checking for notification suppression. -7. If notifications are not suppressed, the driver MUST notify the device +item If notifications are not suppressed, the driver MUST notify the device of the new available buffers. +end{enumerate} Note that the above code does not take precautions against the available ring buffer wrapping around: this is not possible since @@ -611,21 +624,19 @@ chain: for each buffer element, b: - (a) Get the next free descriptor table entry, d - - (b) Set d.addr to the physical address of the start of b - - (c) Set d.len to the length of b. - - (d) If b is write-only, set d.flags to VRING_DESC_F_WRITE, +egin{enumerate} +item Get the next free descriptor table entry, d +item Set d.addr to the physical address of the start of b +item Set d.len to the length of b. +item If b is write-only, set d.flags to VRING_DESC_F_WRITE, otherwise 0. - - (e) If there is a buffer element after this: - - i. Set d.next to the index of the next free descriptor +item If there is a buffer element after this: + egin{enumerate} + item Set d.next to the index of the next free descriptor element. - - ii. Set the VRING_DESC_F_NEXT bit in d.flags. + item Set the VRING_DESC_F_NEXT bit in d.flags. + end{enumerate} +end{enumerate} In practice, the d.next fields are usually used to chain free descriptors, and a separate count kept to check there are enough @@ -698,24 +709,28 @@ device), it sends an interrupt, following an algorithm very similar to the algorithm used for the driver to send the device a buffer: -1. Write the head descriptor number to the next field in the used +egin{enumerate} +item Write the head descriptor number to the next field in the used ring. -2. Update the used ring index. +item Update the used ring index. -3. Deliver an interrupt if necessary: +item Deliver an interrupt if necessary: - (a) If the VIRTIO_F_RING_EVENT_IDX feature is not negotiated: + egin{enumerate} + item If the VIRTIO_F_RING_EVENT_IDX feature is not negotiated: check if the VRING_AVAIL_F_NO_INTERRUPT flag is not set in avail->flags. - (b) If the VIRTIO_F_RING_EVENT_IDX feature is negotiated: check + item If the VIRTIO_F_RING_EVENT_IDX feature is negotiated: check whether the used index crossed the used_event field value since the last update. The used_event field wraps naturally at 65536 as well: egin{lstlisting} (u16)(new_idx - used_event - 1) < (u16)(new_idx - old_idx) end{lstlisting} + end{enumerate} +end{enumerate} For each ring, the driver should then disable interrupts by writing VRING_AVAIL_F_NO_INTERRUPT flag in avail structure, if required. @@ -764,8 +779,7 @@ Virtio devices are commonly implemented as PCI devices. subsection{PCI Device Discovery}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Discovery} Any PCI device with Vendor ID 0x1AF4, and Device ID 0x1000 through -0x103F inclusive is a virtio device -footnote{The actual value within this range is ignored +0x103F inclusive is a virtio devicefootnote{The actual value within this range is ignored }. The Subsystem Device ID indicates which virtio device is @@ -830,20 +844,18 @@ Common configuration structure layout is documented below: }; end{lstlisting} -device_feature_select - +egin{description} +item[device_feature_select] The driver uses this to select which Feature Bits the device_feature field shows. Value 0x0 selects Feature Bits 0 to 31 Value 0x1 selects Feature Bits 32 to 63 The device MUST present 0 on device_feature for any other value. -device_feature - +item[device_feature] The device uses this to report Feature Bits to the driver. Device Feature Bits selected by device_feature_select. -driver_feature_select - +item[driver_feature_select] The driver uses this to select which Feature Bits the driver_feature field shows. Value 0x0 selects Feature Bits 0 to 31 Value 0x1 selects Feature Bits 32 to 63 @@ -852,72 +864,60 @@ driver_feature_select MUST not write any other value into driver_feature (a corollary of the rule that the driver can only write a subset of device features). -driver_feature - +item[driver_feature] The driver writes this to accept feature bits offered by the device. Driver Feature Bits selected by driver_feature_select. -msix_config - +item[msix_config] The driver sets the Configuration Vector for MSI-X. -num_queues - +item[num_queues] The device specifies the maximum number of virtqueues supported here. -device_status - +item[device_status] The driver writes the Device Status here. Writing 0 into this field resets the device. -config_generation - +item[config_generation] Configuration atomicity value. The device changes this every time the configuration noticeably changes. This means the device may only change the value after a configuration read operation, but MUST change it if there is any risk of a driver seeing an inconsistent configuration state. -queue_select - +item[queue_select] Queue Select. The driver selects which virtqueue the following fields refer to. -queue_size - +item[queue_size] Queue Size. On reset, specifies the maximum queue size supported by the hypervisor. This can be modified by driver to reduce memory requirements. The device MUST set this to 0 if this virtqueue is unavailable. -queue_msix_vector - +item[queue_msix_vector] The driver uses this to specify the Queue Vector for MSI-X. -queue_enable - +item[queue_enable] The driver uses this to selectively prevent the device from executing requests from this virtqueue. 1 - enabled; 0 - disabled The driver MUST configure the other virtqueue fields before enabling the virtqueue. -queue_notify_off - +item[queue_notify_off] The driver reads this to calculate the offset from start of Notification structure at which this virtqueue is located. Note: this is *not* an offset in bytes. See notify_off_multiplier below. -queue_desc - +item[queue_desc] The driver writes the physical address of Descriptor Table here. -queue_avail - +item[queue_avail] The driver writes the physical address of Available Ring here. -queue_used - +item[queue_used] The driver writes the physical address of Used Ring here. +end{description} subsubsection{ISR status structure layout}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / ISR status structure layout} ISR status structure includes a single 8-bit ISR status field. @@ -967,17 +967,15 @@ When used through the legacy interface, the virtio header looks as follows: If MSI-X is enabled for the device, two additional fields immediately follow this header: - -egin{verbatim} -+------------++----------------+--------+ - Bits 16 16 -+------------++----------------+--------+ - Read/Write R+W R+W -+------------++----------------+--------+ - Purpose Configuration Queue - (MSI-X) Vector Vector -+------------++----------------+--------+ -end{verbatim} +egin{tabular}{ l l l } +hline +Bits & 16 & 16 \ +hline +Read/Write & R+W & R+W \ +hline +Purpose (MSI-X) & Configuration Vector & Queue Vector \ +hline +end{tabular} Note: When MSI-X capability is enabled, device specific configuration starts at byte offset 24 in virtio header structure. When MSI-X capability is not @@ -988,16 +986,15 @@ If you turn it off again, they move back! Immediately following these general headers, there may be device-specific headers: -egin{verbatim} -+------------++--------------------+ - Bits Device Specific -+------------++--------------------+ - Read/Write Device Specific -+------------++--------------------+ - Purpose Device Specific... - -+------------++--------------------+ -end{verbatim} +egin{tabular}{ l l } +hline +Bits & Device Specific \ +hline +Read/Write & Device Specific \ +hline +Purpose & Device Specific... \ +hline +end{tabular} Note that only Feature Bits 0 to 31 are accessible through the Legacy Interface. When used through the Legacy Interface, @@ -1013,7 +1010,7 @@ see
    ef{sec:Basic Facilities of a Virtio Device / Configuration Space / Legacy This documents PCI-specific steps executed during Device Initialization. As the first step, driver must detect device configuration layout -to locate configuration fields in memory,I/O or configuration space of the +to locate configuration fields in memory, I/O or configuration space of the device. paragraph{Virtio Device Configuration Layout Detection}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI-specific Initialization And Device Operation / Device Initialization / Virtio Device Configuration Layout Detection} @@ -1065,18 +1062,19 @@ specified 8-bit size. The fields are interpreted as follows: -cap_vndr +egin{description} +item[cap_vndr] 0x09; Identifies a vendor-specific capability. -cap_next +item[cap_next] Link to next capability in the capability list in the configuration space. -cap_len +item[cap_len] Length of the capability structure, including the whole of struct virtio_pci_cap, and extra data if any. This length might include padding, or fields unused by the driver. -cfg_type +item[cfg_type] identifies the structure, according to the following table. egin{lstlisting} @@ -1107,7 +1105,7 @@ cfg_type Driver will use the I/O BAR if I/O resources are available, and fall back on memory BAR when I/O resources are unavailable. -bar +item[bar] values 0x0 to 0x5 specify a Base Address register (BAR) belonging to the function located beginning at 10h in Configuration Space and used to map the structure into Memory or I/O Space. @@ -1118,11 +1116,11 @@ bar ignore any vendor-specific capability structure which has a reserved bar value. -offset +item[offset] indicates where the structure begins relative to the base address associated with the BAR. -length +item[length] indicates the length of the structure. This size might include padding, or fields unused by the driver. Drivers SHOULD only map part of configuration structure @@ -1133,7 +1131,7 @@ length driver can limit the mapped structure size to e.g. 4KBytes to allow forward compatibility with such devices without loss of functionality and without wasting resources. - +end{description} If cfg_type is VIRTIO_PCI_CAP_NOTIFY_CFG this structure is immediately followed by additional fields: @@ -1145,7 +1143,8 @@ by additional fields: }; end{lstlisting} -notify_off_multiplier +egin{description} +item[notify_off_multiplier] Virtqueue offset multiplier, in bytes. Must be even and either a power of two, or 0. Value 0x1 is reserved. @@ -1155,6 +1154,7 @@ notify_off_multiplier If notify_off_multiplier is 0, all virtqueues use the same address in the Notifications structure! +end{description} If cfg_type is VIRTIO_PCI_CAP_PCI_CFG the fields bar, offset and length are RW and this structure is immediately followed by an additional field: @@ -1165,7 +1165,8 @@ and this structure is immediately followed by an additional field: }; end{lstlisting} -pci_cfg_data +egin{description} +item[pci_cfg_data] This RW field allows an indirect access to any BAR on the device using PCI configuration accesses. @@ -1182,6 +1183,7 @@ pci_cfg_data When this field is read by driver, length bytes at the selected offset in the selected BAR are read into pci_cfg_data. +end{description} subparagraph{Legacy Interface: A Note on Device Layout Detection}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI-specific Initialization And Device Operation / Device Initialization / Virtio Device Configuration Layout Detection / Legacy Interface: A Note on Device Layout Detection} @@ -1210,10 +1212,12 @@ a legacy device with the same ID might have previously existed, must take the following steps to fail gracefully when a legacy driver attempts to drive them: -1) Present an I/O BAR in BAR0, and -2) Respond to a single-byte zero write to offset 18 +egin{enumerate} +item Present an I/O BAR in BAR0, and +item Respond to a single-byte zero write to offset 18 (corresponding to Device Status register in the legacy layout) of BAR0 by presenting zeroes on every BAR and ignoring writes. +end{enumerate} paragraph{Queue Vector Configuration}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI-specific Initialization And Device Operation / Device Initialization / Queue Vector Configuration} @@ -1256,31 +1260,32 @@ configuration. The driver does this as follows, for each virtqueue a device has: -1. Write the virtqueue index (first queue is 0) to the Queue +egin{enumerate} +item Write the virtqueue index (first queue is 0) to the Queue Select field. -2. Read the virtqueue size from the Queue Size field, which MUST +item Read the virtqueue size from the Queue Size field, which MUST be a power of 2. This controls how big the virtqueue is (see
    ef{sec:Basic Facilities of a Virtio Device / Virtqueues}~
    ameref{sec:Basic Facilities of a Virtio Device / Virtqueues}). If this field is 0, the virtqueue does not exist. -3. Optionally, select a smaller virtqueue size and write it in the Queue Size +item Optionally, select a smaller virtqueue size and write it in the Queue Size field. -4. Allocate and zero Descriptor Table, Available and Used rings for the +item Allocate and zero Descriptor Table, Available and Used rings for the virtqueue in contiguous physical memory. -5. Optionally, if MSI-X capability is present and enabled on the +item Optionally, if MSI-X capability is present and enabled on the device, select a vector to use to request interrupts triggered by virtqueue events. Write the MSI-X Table entry number corresponding to this vector in Queue Vector field. Read the Queue Vector field: on success, previously written value is returned; on failure, NO_VECTOR value is returned. +end{enumerate} subparagraph{Legacy Interface: A Note on Virtqueue Configuration}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI-specific Initialization And Device Operation / Device Initialization / Virtqueue Configuration / Legacy Interface: A Note on Virtqueue Configuration} When using the legacy interface, the page size for a virtqueue on a PCI virtio device is defined as 4096 bytes. Driver writes the physical address, divided -by 4096 to the Queue Address field -footnote{The 4096 is based on the x86 page size, but it's also large +by 4096 to the Queue Address fieldfootnote{The 4096 is based on the x86 page size, but it's also large enough to ensure that the separate parts of the virtqueue are on separate cache lines. }. @@ -1294,34 +1299,40 @@ of this virtqueue to the Queue Notify field. If an interrupt is necessary: - (a) If MSI-X capability is disabled: - - i. Set the lower bit of the ISR Status field for the device. +egin{itemize} + item If MSI-X capability is disabled: + egin{enumerate} + item Set the lower bit of the ISR Status field for the device. - ii. Send the appropriate PCI interrupt for the device. + item Send the appropriate PCI interrupt for the device. + end{enumerate} - (b) If MSI-X capability is enabled: - - i. Request the appropriate MSI-X interrupt message for the + item If MSI-X capability is enabled: + egin{enumerate} + item Request the appropriate MSI-X interrupt message for the device, Queue Vector field sets the MSI-X Table entry number. - ii. If Queue Vector field value is NO_VECTOR, no interrupt + item If Queue Vector field value is NO_VECTOR, no interrupt message is requested for this event. + end{enumerate} +end{itemize} The driver interrupt handler should: -1. If MSI-X capability is disabled: read the ISR Status field, +egin{itemize} + item If MSI-X capability is disabled: read the ISR Status field, which will reset it to zero. If the lower bit is zero, the interrupt was not for this device. Otherwise, the driver should look through the used rings of each virtqueue for the device, to see if any progress has been made by the device which requires servicing. -2. If MSI-X capability is enabled: look through the used rings of + item If MSI-X capability is enabled: look through the used rings of each virtqueue mapped to the specific MSI-X vector for the device, to see if any progress has been made by the device which requires servicing. +end{itemize} subsubsection{Notification of Device Configuration Changes}label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI-specific Initialization And Device Operation / Notification of Device Configuration Changes} @@ -1329,7 +1340,8 @@ Some virtio PCI devices can change the device configuration state, as reflected in the virtio header in the PCI configuration space. In this case: -1. If MSI-X capability is disabled: an interrupt is delivered and +egin{itemize} + item If MSI-X capability is disabled: an interrupt is delivered and the second lowest bit is set in the ISR Status field to indicate that the driver should re-examine the configuration space. Note that a single interrupt can indicate both that one @@ -1337,10 +1349,11 @@ space. In this case: space has changed: even if the config bit is set, virtqueues must be scanned. -2. If MSI-X capability is enabled: an interrupt message is + item If MSI-X capability is enabled: an interrupt message is requested. The Configuration Vector field sets the MSI-X Table entry number to use. If Configuration Vector field value is NO_VECTOR, no interrupt message is requested for this event. +end{itemize} section{Virtio Over MMIO}label{sec:Virtio Transport Options / Virtio Over MMIO} @@ -1371,29 +1384,25 @@ systems using Flattened Device Trees the suggested format is: MMIO virtio devices provides a set of memory mapped control registers, all 32 bits wide, followed by device-specific -configuration space. The following list presents their layout: - -* Offset from the device base address Direction Name - Description +configuration space. The following table presents their names, +offset from the base address, and whether they are read-only (R) or write-only (W) from the driver's perspective: -* 0x000 R MagicValue +egin{description} +item[MagicValue (0x000) - R] Magic value. Must be 0x74726976 (a Little Endian equivalent of a "virt" string). - -* 0x004 R Version +item[Version (0x004) - R] Device version number. Devices compliant with this specification must return value 0x2. - -* 0x008 R DeviceID +item[DeviceID (0x008) - R] Virtio Subsystem Device ID. See
    ef{sec:Device Types}~
    ameref{sec:Device Types} for possible values. Value zero (0x0) is invalid and devices returning this ID must be ignored by the guest. - -* 0x00c R VendorID +item[VendorID (0x00c) - R] Virtio Subsystem Vendor ID. -* 0x010 R DeviceFeatures +item[DeviceFeatures (0x010) - R] Flags representing features the device supports. Reading from this register returns 32 consecutive flag bits, first bit depending on the last value written to the @@ -1403,14 +1412,14 @@ configuration space. The following list presents their layout: features bits 32 to 63 if DeviceFeaturesSel is set to 1. Also see
    ef{sec:Basic Facilities of a Virtio Device / Feature Bits}~
    ameref{sec:Basic Facilities of a Virtio Device / Feature Bits}. -* 0x014 W DeviceFeaturesSel +item[DeviceFeaturesSel (0x014) - W] Device (host) features word selection. Writing to this register selects a set of 32 device feature bits accessible by reading from the DeviceFeatures register. Device driver must write a value to the DeviceFeaturesSel register before reading from the DeviceFeatures register. -* 0x020 W DriverFeatures +item[DriverFeatures (0x020) - W] Flags representing device features understood and activated by the driver. Writing to this register sets 32 consecutive flag bits, first @@ -1420,21 +1429,21 @@ configuration space. The following list presents their layout: DriverFeaturesSel is set to 0 and features bits 32 to 63 if DriverFeaturesSel is set to 1. Also see
    ef{sec:Basic Facilities of a Virtio Device / Feature Bits}~
    ameref{sec:Basic Facilities of a Virtio Device / Feature Bits}. -* 0x024 W DriverFeaturesSel +item[DriverFeaturesSel (0x024) - W] Activated (guest) features word selection. Writing to this register selects a set of 32 activated feature bits accessible by writing to the DriverFeatures register. Device driver must write a value to the DriverFeaturesSel register before writing to the DriverFeatures register. -* 0x030 W QueueSel +item[QueueSel (0x030) - W] Virtual queue index (first queue is 0). Writing to this register selects the virtual queue that the following operations on the QueueNumMax, QueueNum, QueueReady, QueueDescLow, QueueDescHigh, QueueAvailLow, QueueAvailHigh, QueueUsedLow and QueueUsedHigh registers apply to. -* 0x034 R QueueNumMax +item[QueueNumMax (0x034) - R] Maximum virtual queue size. Reading from the register returns the maximum size of the queue the device is ready to process or zero (0x0) if the queue is not @@ -1442,7 +1451,7 @@ configuration space. The following list presents their layout: QueueSel and is allowed only when QueueReady is set to zero (0x0), so when the queue is not in use. -* 0x038 W QueueNum +item[QueueNum (0x038) - W] Virtual queue size. Queue size is the number of elements in the queue, therefore size of the Descriptor Table and both Available and Used rings. @@ -1451,7 +1460,7 @@ configuration space. The following list presents their layout: writing to QueueSel and is allowed only when QueueReady is set to zero (0x0), so when the queue is not in use. -* 0x03c RW QueueReady +item[QueueReady (0x03c) - RW] Virtual queue ready bit. Writing one (0x1) to this register notifies the device that the virtual queue is ready to be used. Reading from this register @@ -1461,12 +1470,12 @@ configuration space. The following list presents their layout: zero (0x0) to this register and read the value back to ensure synchronisation. -* 0x050 W QueueNotify +item[QueueNotify (0x050) - W] Queue notifier. Writing a queue index to this register notifies the device that there are new buffers to process in the queue. -* 0x60 R InterruptStatus +item[InterruptStatus (0x60) - R] Interrupt status. Reading from this register returns a bit mask of interrupts asserted by the device. An interrupt is asserted if the @@ -1480,13 +1489,13 @@ configuration space. The following list presents their layout: This interrupt is asserted when configuration of the device has changed. -* 0x064 W InterruptACK +item[InterruptACK (0x064) - W] Interrupt acknowledge. Writing to this register notifies the device that the Driver finished handling interrupts. Set bits in the value clear the corresponding bits of the InterruptStatus register. -* 0x070 RW Status +item[Status (0x070) - RW] Device status. Reading from this register returns the current device status flags. @@ -1497,8 +1506,8 @@ configuration space. The following list presents their layout: QueueReady register for all queues in the device. See also p.
    ef{sec:Virtio Transport Options / Virtio Over MMIO / MMIO-specific Initialization And Device Operation / Device Initialization}~
    ameref{sec:Virtio Transport Options / Virtio Over MMIO / MMIO-specific Initialization And Device Operation / Device Initialization}. -* 0x080 W QueueDescLow - 0x084 W QueueDescHigh +item[QueueDescLow (0x080) - W] +item[QueueDescHigh (0x084) - W] Virtual queue's Descriptor Table 64 bit long physical address. Writing to these two registers (lower 32 bits of the address to QueueDescLow, higher 32 bits to QueueDescHigh) notifies @@ -1507,8 +1516,8 @@ configuration space. The following list presents their layout: only when QueueReady is set to zero (0x0), so when the queue is not in use. -* 0x090 W QueueAvailLow - 0x094 W QueueAvailHigh +item[QueueAvailLow (0x090) - W] +item[QueueAvailHigh (0x094) - W] Virtual queue's Available Ring 64 bit long physical address. Writing to these two registers (lower 32 bits of the address to QueueAvailLow, higher 32 bits to QueueAvailHigh) notifies @@ -1517,8 +1526,8 @@ configuration space. The following list presents their layout: only when QueueReady is set to zero (0x0), so when the queue is not in use. -* 0x0a0 W QueueUsedLow - 0x0a4 W QueueUsedHigh +item[QueueUsedLow (0x0a0) - W] +item[QueueUsedHigh (0x0a4) - W] Virtual queue's Used Ring 64 bit long physical address. Writing to these two registers (lower 32 bits of the address to QueueUsedLow, higher 32 bits to QueueUsedHigh) notifies @@ -1527,17 +1536,18 @@ configuration space. The following list presents their layout: only when QueueReady is set to zero (0x0), so when the queue is not in use. -* 0x0fc R ConfigGeneration +item[ConfigGeneration (0x0fc) - R] Configuration atomicity value. Changes every time the configuration noticeably changes. This means the device may only change the value after a configuration read operation, but it must change if there is any risk of a device seeing an inconsistent configuration state. -* 0x100+ RW Config +item[Config (0x100) - RW] Device-specific configuration space starts at an offset 0x100 and is accessed with byte alignment. Its meaning and size depends on the device and the driver. +end{description} All register values are organized as Little Endian. @@ -1558,35 +1568,37 @@ and if its value is zero (0x0) must abort initialization and must not access any other register. Further initialization must follow the procedure described in -p.
    ef{sec:General Initialization And Device Operation / Device Initialization}~
    ameref{sec:General Initialization And Device Operation / Device Initialization}. +
    ef{sec:General Initialization And Device Operation / Device Initialization}~
    ameref{sec:General Initialization And Device Operation / Device Initialization}. subsubsection{Virtqueue Configuration}label{sec:Virtio Transport Options / Virtio Over MMIO / MMIO-specific Initialization And Device Operation / Virtqueue Configuration} -1. Select the queue writing its index (first queue is 0) to the +egin{enumerate} +item Select the queue writing its index (first queue is 0) to the QueueSel register. -2. Check if the queue is not already in use: read the QueueReady +item Check if the queue is not already in use: read the QueueReady register, returned value should be zero (0x0). -3. Read maximum queue size (number of elements) from the +item Read maximum queue size (number of elements) from the QueueNumMax register. If the returned value is zero (0x0) the queue is not available. -4. Allocate and zero the queue pages, making sure the memory +item Allocate and zero the queue pages, making sure the memory is physically contiguous. It is recommended to align the Used Ring to an optimal boundary (usually page size). Size of the allocated queue may be smaller than or equal to the maximum size returned by the device. -5. Notify the device about the queue size by writing the size to +item Notify the device about the queue size by writing the size to the QueueNum register. -6. Write physical addresses of the queue's Descriptor Table, +item Write physical addresses of the queue's Descriptor Table, Available Ring and Used Ring to (respectively) the QueueDescLow/ QueueDescHigh, QueueAvailLow/QueueAvailHigh and QueueUsedLow/ QueueUsedHigh register pairs. -7. Write 0x1 to the QueueReady register. +item Write 0x1 to the QueueReady register. +end{enumerate} subsubsection{Notifying The Device}label{sec:Virtio Transport Options / Virtio Over MMIO / MMIO-specific Initialization And Device Operation / Notifying The Device} @@ -1718,30 +1730,31 @@ p.
    ef{sec:Basic Facilities of a Virtio Device / Virtqueues / Legacy Interfaces with the alignment defined in the QueueAlign register. The virtual queue is configured as follows: - -1. Select the queue writing its index (first queue is 0) to the +egin{enumerate} +item Select the queue writing its index (first queue is 0) to the QueueSel register. -2. Check if the queue is not already in use: read the QueuePFN +item Check if the queue is not already in use: read the QueuePFN register, returned value should be zero (0x0). -3. Read maximum queue size (number of elements) from the +item Read maximum queue size (number of elements) from the QueueNumMax register. If the returned value is zero (0x0) the queue is not available. -4. Allocate and zero the queue pages in contiguous virtual +item Allocate and zero the queue pages in contiguous virtual memory, aligning the Used Ring to an optimal boundary (usually page size). Size of the allocated queue may be smaller than or equal to the maximum size returned by the device. -5. Notify the device about the queue size by writing the size to +item Notify the device about the queue size by writing the size to the QueueNum register. -6. Notify the device about the used alignment by writing its value +item Notify the device about the used alignment by writing its value in bytes to the QueueAlign register. -7. Write the physical number of the first page of the queue to +item Write the physical number of the first page of the queue to the QueuePFN register. +end{enumerate} Notification mechanisms did not change. @@ -1778,23 +1791,23 @@ importantly SENSE ID. For a virtio-ccw proxy device, SENSE ID will return the following information: -egin{verbatim} -+-------+--------------------------------------------+ - Bytes Contents - ------- -------------------------------------------- - 0 reserved 0xff - ------- ----------------------- -------------------- - 1-2 control unit type 0x3832 - ------- ----------------------- -------------------- - 3 control unit model <virtio device id> - ------- ----------------------- -------------------- - 4-5 device type zeroes (unset) - ------- ----------------------- -------------------- - 6 device model zeroes (unset) - ------- ----------------------- -------------------- - 7-255 extended SenseId data zeroes (unset) -+-------+--------------------------------------------+ -end{verbatim} +egin{tabular}{ l l l } +hline +Bytes & Description & Contents \ +hline hline +0 & reserved & 0xff \ +hline +1-2 & control unit type & 0x3832 \ +hline +3 & control unit model & <virtio device id> \ +hline +4-5 & device type & zeroes (unset) \ +hline +6 & device model & zeroes (unset) \ +hline +7-255 & extended SenseId data & zeroes (unset) \ +hline +end{tabular} A driver for virtio-ccw devices MUST check for a control unit type of 0x3832 and MUST ignore the device type and model. @@ -1821,19 +1834,21 @@ virtio: The virtio-ccw device acts like a normal channel device, as specified in hyperref[intro:S390 PoP]{[S390 PoP]} and hyperref[intro:S390 Common I/O]{[S390 Common I/O]}. In particular: -- A device must post a unit check with command reject for any command +egin{itemize} +item A device must post a unit check with command reject for any command it does not support. -- If a driver did not suppress length checks for a channel command, +item If a driver did not suppress length checks for a channel command, the device must present a subchannel status as detailed in the architecture when the actual length did not match the expected length. -- If a driver did suppress length checks for a channel command, the +item If a driver did suppress length checks for a channel command, the device must present a check condition if the transmitted data does not contain enough data to process the command. If the driver submitted a buffer that was too long, the device should accept the command. The driver should attempt to provide the correct length even if it suppresses length checks. +end{itemize} subsection{Device Initialization}label{sec:Virtio Transport Options / Virtio over channel I/O / Device Initialization} @@ -1858,18 +1873,17 @@ data portion and data revision-dependent additional desired options. The following values are supported: -egin{verbatim} -+----------+--------+-----------+--------------------------------+ - revision length data remarks - ---------- -------- ----------- -------------------------------- - 0 0 <empty> legacy interface; transitional - devices only - ---------- -------- ----------- -------------------------------- - 1 0 <empty> Virtio 1.0 - ---------- -------- ----------- -------------------------------- - 2-n reserved for later revisions -+----------+--------+-----------+--------------------------------+ -end{verbatim} +egin{tabular}{ l l l l } +hline +revision & length & data & remarks \ +hline hline +0 & 0 & <empty> & legacy interface; transitional devices only \ +hline +1 & 0 & <empty> & Virtio 1.0 \ +hline +2-n & & & reserved for later revisions \ +hline +end{tabular} Note that a change in the virtio standard does not neccessarily correspond to a change in the virtio-ccw revision. @@ -1970,11 +1984,11 @@ and align the alignment. The virtqueue is physically contiguous, with padded added to make the used ring meet the align value: -egin{verbatim} -+-------------------+-----------------------------------+-----------+ - Descriptor Table Available Ring (padding) Used Ring -+-------------------+-----------------------------------+-----------+ -end{verbatim} +egin{tabular}{ l l l } +hline +Descriptor Table & Available Ring (ldots paddingldots) & Used Ring \ +hline +end{tabular} The calculation for total size is as follows: @@ -2080,10 +2094,12 @@ guest address of the indicators in a 64 bit value. Indicators for notification via adapter I/O interrupts consist of two stages: -- a summary indicator byte covering the virtqueues for one or more +egin{itemize} +item a summary indicator byte covering the virtqueues for one or more virtio-ccw proxy devices -- a set of contigous indicator bits for the virtqueues for a +item a set of contigous indicator bits for the virtqueues for a virtio-ccw proxy device +end{itemize} To communicate the location of the summary and queue indicator bits, the driver uses the CCW_CMD_SET_IND_ADAPTER command with the following @@ -2172,29 +2188,30 @@ characteristics of channel I/O interact badly with the host block I/O backend). Instead, it uses a diagnose 0x500 call with subcode 3 specifying the queue, as follows: -egin{verbatim} -+------+-------------------+--------------+ - GPR Input Value Output Value -+------+-------------------+--------------+ -+------+-------------------+--------------+ - 1 0x3 -+------+-------------------+--------------+ - 2 Subchannel ID Host Cookie -+------+-------------------+--------------+ - 3 Virtqueue number -+------+-------------------+--------------+ - 4 Host Cookie -+------+-------------------+--------------+ -end{verbatim} +egin{tabular}{ l l l } +hline +GPR & Input Value & Output Value \ +hline hline + 1 & 0x3 & \ +hline + 2 & Subchannel ID & Host Cookie \ +hline + 3 & Virtqueue number & \ +hline + 4 & Host Cookie & \ +hline +end{tabular} Host cookie is an optional per-virtqueue 64 bit value that can be used by the hypervisor to speed up the notification execution. For each notification, the output value is returned in GPR2 and should be passed in GPR4 for the next notification: +egin{lstlisting} info->cookie = do_notify(schid, virtqueue_get_queue_index(vq), info->cookie); +end{lstlisting} subsubsection{Early printk for Virtio Consoles}label{sec:Virtio Transport Options / Virtio over channel I/O / Device Operation / Early printk for Virtio Consoles} @@ -2218,38 +2235,37 @@ defined in this standard. Discovering what devices are available and their type is bus-dependent. -egin{verbatim} -+------------+--------------------+ - Device ID Virtio Device -+------------+--------------------+ -+------------+--------------------+ - 0 reserved (invalid) -+------------+--------------------+ - 1 network card -+------------+--------------------+ - 2 block device -+------------+--------------------+ - 3 console -+------------+--------------------+ - 4 entropy source -+------------+--------------------+ - 5 memory ballooning -+------------+--------------------+ - 6 ioMemory -+------------+--------------------+ - 7 rpmsg -+------------+--------------------+ - 8 SCSI host -+------------+--------------------+ - 9 9P transport -+------------+--------------------+ - 10 mac80211 wlan -+------------+--------------------+ - 11 rproc serial -+------------+--------------------+ - 12 virtio CAIF -+------------+--------------------+ -end{verbatim} +egin{tabular} { l c } +hline +Device ID & Virtio Device \ +hline hline +0 & reserved (invalid) \ +hline +1 & network card \ +hline +2 & block device \ +hline +3 & console \ +hline +4 & entropy source \ +hline +5 & memory ballooning \ +hline +6 & ioMemory \ +hline +7 & rpmsg \ +hline +8 & SCSI host \ +hline +9 & 9P transport \ +hline +10 & mac80211 wlan \ +hline +11 & rproc serial \ +hline +12 & virtio CAIF \ +hline +end{tabular} section{Network Device}label{sec:Device Types / Network Device} @@ -2268,53 +2284,61 @@ features. subsection{Virtqueues}label{sec:Device Types / Network Device / Virtqueues} - 0:receiveq. 1:transmitq. 2:controlq +egin{description} +item[0] receiveq +item[1] transmitq +item[2] controlq +end{description} Virtqueue 2 only exists if VIRTIO_NET_F_CTRL_VQ set. subsection{Feature bits}label{sec:Device Types / Network Device / Feature bits} - VIRTIO_NET_F_CSUM (0) Device handles packets with partial checksum +egin{description} +item[VIRTIO_NET_F_CSUM (0)] Device handles packets with partial checksum - VIRTIO_NET_F_GUEST_CSUM (1) Driver handles packets with partial checksum +item[VIRTIO_NET_F_GUEST_CSUM (1)] Driver handles packets with partial checksum - VIRTIO_NET_F_CTRL_GUEST_OFFLOADS (2) Control channel offloads +item[VIRTIO_NET_F_CTRL_GUEST_OFFLOADS (2)] Control channel offloads reconfiguration support. - VIRTIO_NET_F_MAC (5) Device has given MAC address. +item[VIRTIO_NET_F_MAC (5)] Device has given MAC address. - VIRTIO_NET_F_GUEST_TSO4 (7) Driver can receive TSOv4. +item[VIRTIO_NET_F_GUEST_TSO4 (7)] Driver can receive TSOv4. - VIRTIO_NET_F_GUEST_TSO6 (8) Driver can receive TSOv6. +item[VIRTIO_NET_F_GUEST_TSO6 (8)] Driver can receive TSOv6. - VIRTIO_NET_F_GUEST_ECN (9) Driver can receive TSO with ECN. +item[VIRTIO_NET_F_GUEST_ECN (9)] Driver can receive TSO with ECN. - VIRTIO_NET_F_GUEST_UFO (10) Driver can receive UFO. +item[VIRTIO_NET_F_GUEST_UFO (10)] Driver can receive UFO. - VIRTIO_NET_F_HOST_TSO4 (11) Device can receive TSOv4. +item[VIRTIO_NET_F_HOST_TSO4 (11)] Device can receive TSOv4. - VIRTIO_NET_F_HOST_TSO6 (12) Device can receive TSOv6. +item[VIRTIO_NET_F_HOST_TSO6 (12)] Device can receive TSOv6. - VIRTIO_NET_F_HOST_ECN (13) Device can receive TSO with ECN. +item[VIRTIO_NET_F_HOST_ECN (13)] Device can receive TSO with ECN. - VIRTIO_NET_F_HOST_UFO (14) Device can receive UFO. +item[VIRTIO_NET_F_HOST_UFO (14)] Device can receive UFO. - VIRTIO_NET_F_MRG_RXBUF (15) Driver can merge receive buffers. +item[VIRTIO_NET_F_MRG_RXBUF (15)] Driver can merge receive buffers. - VIRTIO_NET_F_STATUS (16) Configuration status field is +item[VIRTIO_NET_F_STATUS (16)] Configuration status field is available. - VIRTIO_NET_F_CTRL_VQ (17) Control channel is available. +item[VIRTIO_NET_F_CTRL_VQ (17)] Control channel is available. - VIRTIO_NET_F_CTRL_RX (18) Control channel RX mode support. +item[VIRTIO_NET_F_CTRL_RX (18)] Control channel RX mode support. - VIRTIO_NET_F_CTRL_VLAN (19) Control channel VLAN filtering. +item[VIRTIO_NET_F_CTRL_VLAN (19)] Control channel VLAN filtering. - VIRTIO_NET_F_GUEST_ANNOUNCE(21) Driver can send gratuitous +item[VIRTIO_NET_F_GUEST_ANNOUNCE(21)] Driver can send gratuitous packets. +end{description} subsubsection{Legacy Interface: Feature bits}label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits} -VIRTIO_NET_F_GSO (6) Device handles packets with any GSO type. +egin{description} +item[VIRTIO_NET_F_GSO (6)] Device handles packets with any GSO type. +end{description} This was supposed to indicate segmentation offload support, but upon further investigation it became clear that multiple bits @@ -2345,32 +2369,32 @@ native endian of the guest rather than (necessarily) little-endian. subsection{Device Initialization}label{sec:Device Types / Network Device / Device Initialization} -1. The initialization routine should identify the receive and +egin{enumerate} +item The initialization routine should identify the receive and transmission virtqueues. -2. If the VIRTIO_NET_F_MAC feature bit is set, the configuration +item If the VIRTIO_NET_F_MAC feature bit is set, the configuration space “mac” entry indicates the “physical” address of the the network card, otherwise a private MAC address should be assigned. All drivers are expected to negotiate this feature if it is set. -3. If the VIRTIO_NET_F_CTRL_VQ feature bit is negotiated, +item If the VIRTIO_NET_F_CTRL_VQ feature bit is negotiated, identify the control virtqueue. -4. If the VIRTIO_NET_F_STATUS feature bit is negotiated, the link +item If the VIRTIO_NET_F_STATUS feature bit is negotiated, the link status can be read from the bottom bit of the “status” config field. Otherwise, the link should be assumed active. -5. The receive virtqueue should be filled with receive buffers. +item The receive virtqueue should be filled with receive buffers. This is described in detail below in “Setting Up Receive Buffers”. -6. A driver can indicate that it will generate checksumless - packets by negotating the VIRTIO_NET_F_CSUM feature. This “ - checksum offload” is a common feature on modern network cards. +item A driver can indicate that it will generate checksumless + packets by negotating the VIRTIO_NET_F_CSUM feature. This + “checksum offload” is a common feature on modern network cards. -7. If that feature is negotiated -footnote{ie. VIRTIO_NET_F_HOST_TSO* and VIRTIO_NET_F_HOST_UFO are +item If that feature is negotiatedfootnote{ie. VIRTIO_NET_F_HOST_TSO* and VIRTIO_NET_F_HOST_UFO are dependent on VIRTIO_NET_F_CSUM; a dvice which offers the offload features must offer the checksum feature, and a driver which accepts the offload features must accept the checksum feature. @@ -2382,13 +2406,11 @@ depending on VIRTIO_NET_F_GUEST_CSUM. (UDP fragmentation) features. It should not send TCP packets requiring segmentation offload which have the Explicit Congestion Notification bit set, unless the VIRTIO_NET_F_HOST_ECN feature is - negotiated. -footnote{This is a common restriction in real, older network cards. + negotiated.footnote{This is a common restriction in real, older network cards. } -8. The converse features are also available: a driver can save - the virtual device some work by negotiating these features. -footnote{For example, a network packet transported between two guests on +item The converse features are also available: a driver can save + the virtual device some work by negotiating these features.footnote{For example, a network packet transported between two guests on the same system may not require checksumming at all, nor segmentation, if both guests are amenable. } @@ -2398,6 +2420,7 @@ if both guests are amenable. VIRTIO_NET_F_GUEST_UFO and VIRTIO_NET_F_GUEST_ECN are the input equivalents of the features described above. See
    ef{sec:Device Types / Network Device / Device Operation / Setting Up Receive Buffers}~
    ameref{sec:Device Types / Network Device / Device Operation / Setting Up Receive Buffers} and
    ef{sec:Device Types / Network Device / Device Operation / Setting Up Receive Buffers}~
    ameref{sec:Device Types / Network Device / Device Operation / Setting Up Receive Buffers} below. +end{enumerate} subsection{Device Operation}label{sec:Device Types / Network Device / Device Operation} @@ -2436,19 +2459,22 @@ native endian of the guest rather than (necessarily) little-endian. Transmitting a single packet is simple, but varies depending on the different features the driver negotiated. -1. If the driver negotiated VIRTIO_NET_F_CSUM, and the packet has +egin{enumerate} +item If the driver negotiated VIRTIO_NET_F_CSUM, and the packet has not been fully checksummed, then the virtio_net_hdr's fields are set as follows. Otherwise, the packet must be fully checksummed, and flags is zero. + egin{itemize} + item flags has the VIRTIO_NET_HDR_F_NEEDS_CSUM set, - • flags has the VIRTIO_NET_HDR_F_NEEDS_CSUM set, - - • csum_start is set to the offset within the packet to begin checksumming, + item csum_start is set to the offset within the packet to begin checksumming, and - • csum_offset indicates how many bytes after the csum_start the + item csum_offset indicates how many bytes after the csum_start the new (16 bit ones' complement) checksum should be placed. -footnote{For example, consider a partially checksummed TCP (IPv4) packet. + end{itemize} + +For example, consider a partially checksummed TCP (IPv4) packet. It will have a 14 byte ethernet header and 20 byte IP header followed by the TCP header (with the TCP checksum field 16 bytes into that header). csum_start will be 14+20 = 34 (the TCP @@ -2457,9 +2483,8 @@ value in the TCP checksum field should be initialized to the sum of the TCP pseudo header, so that replacing it by the ones' complement checksum of the TCP header and body will give the correct result. -} -2. If the driver negotiated +item If the driver negotiated VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO, and the packet requires TCP segmentation or UDP fragmentation, then the “gso_type” field is set to VIRTIO_NET_HDR_GSO_TCPV4, TCPV6 or UDP. @@ -2468,32 +2493,32 @@ correct result. metadata indicates how to replicate the packet header to cut it into smaller packets. The other gso fields are set: - • hdr_len is a hint to the device as to how much of the header + egin{itemize} + item hdr_len is a hint to the device as to how much of the header needs to be kept to copy into each packet, usually set to the - length of the headers, including the transport header. -footnote{Due to various bugs in implementations, this field is not useful + length of the headers, including the transport header.footnote{Due to various bugs in implementations, this field is not useful as a guarantee of the transport header size. } - • gso_size is the maximum size of each packet beyond that + item gso_size is the maximum size of each packet beyond that header (ie. MSS). - • If the driver negotiated the VIRTIO_NET_F_HOST_ECN feature, + item If the driver negotiated the VIRTIO_NET_F_HOST_ECN feature, the VIRTIO_NET_HDR_GSO_ECN bit may be set in “gso_type” as - well, indicating that the TCP packet has the ECN bit set. -footnote{This case is not handled by some older hardware, so is called out + well, indicating that the TCP packet has the ECN bit set.footnote{This case is not handled by some older hardware, so is called out specifically in the protocol. } + end{itemize} -3. If the driver negotiated the VIRTIO_NET_F_MRG_RXBUF feature, +item If the driver negotiated the VIRTIO_NET_F_MRG_RXBUF feature, the num_buffers field is set to zero. -4. The header and packet are added as one output buffer to the +item The header and packet are added as one output buffer to the transmitq, and the device is notified of the new entry - (see
    ef{sec:Device Types / Network Device / Device Initialization}~
    ameref{sec:Device Types / Network Device / Device Initialization}). -footnote{Note that the header will be two bytes longer for the + (see
    ef{sec:Device Types / Network Device / Device Initialization}~
    ameref{sec:Device Types / Network Device / Device Initialization}).footnote{Note that the header will be two bytes longer for the VIRTIO_NET_F_MRG_RXBUF case. } +end{enumerate} paragraph{Packet Transmission Interrupt}label{sec:Device Types / Network Device / Device Operation / Packet Transmission / Packet Transmission Interrupt} @@ -2518,8 +2543,7 @@ VIRTIO_NET_F_GUEST_UFO features are used, the Driver will need to accept packets of up to 65550 bytes long (the maximum size of a TCP or UDP packet, plus the 14 byte ethernet header), otherwise 1514. bytes. So unless VIRTIO_NET_F_MRG_RXBUF is negotiated, every -buffer in the receive queue needs to be at least this length -footnote{Obviously each one can be split across multiple descriptor +buffer in the receive queue needs to be at least this length.footnote{Obviously each one can be split across multiple descriptor elements. } @@ -2530,12 +2554,13 @@ least the size of the struct virtio_net_hdr. When a packet is copied into a buffer in the receiveq, the optimal path is to disable further interrupts for the receiveq -(see 2.2.2.2. Receiving Used Buffers From The Device) and process +(see
    ef{sec:General Initialization And Device Operation / Device Operation / Receiving Used Buffers From The Device}~
    ameref{sec:General Initialization And Device Operation / Device Operation / Receiving Used Buffers From The Device}) and process packets until no more are found, then re-enable them. Processing packet involves: -1. If the driver negotiated the VIRTIO_NET_F_MRG_RXBUF feature, +egin{enumerate} +item If the driver negotiated the VIRTIO_NET_F_MRG_RXBUF feature, then the “num_buffers” field indicates how many descriptors this packet is spread over (including this one). This allows receipt of large packets without having to allocate large @@ -2544,21 +2569,22 @@ Processing packet involves: single packet. The other buffers will not begin with a struct virtio_net_hdr. -2. If the VIRTIO_NET_F_MRG_RXBUF feature was not negotiated, or +item If the VIRTIO_NET_F_MRG_RXBUF feature was not negotiated, or the “num_buffers” field is one, then the entire packet will be contained within this buffer, immediately following the struct virtio_net_hdr. -3. If the VIRTIO_NET_F_GUEST_CSUM feature was negotiated, the +item If the VIRTIO_NET_F_GUEST_CSUM feature was negotiated, the VIRTIO_NET_HDR_F_NEEDS_CSUM bit in the “flags” field may be set: if so, the checksum on the packet is incomplete and the “ csum_start” and “csum_offset” fields indicate how to calculate it (see Packet Transmission point 1). -4. If the VIRTIO_NET_F_GUEST_TSO4, TSO6 or UFO options were +item If the VIRTIO_NET_F_GUEST_TSO4, TSO6 or UFO options were negotiated, then the “gso_type” may be something other than VIRTIO_NET_HDR_GSO_NONE, and the “gso_size” field indicates the desired MSS (see Packet Transmission point 2). +end{enumerate} subsubsection{Control Virtqueue}label{sec:Device Types / Network Device / Device Operation / Control Virtqueue} @@ -2596,7 +2622,7 @@ and filtering of MAC addresses. Note that in general, these commands are best-effort: unwanted packets may still arrive. -Setting Promiscuous Mode +paragraph{Setting Promiscuous Mode}label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Setting Promiscuous Mode} egin{lstlisting} #define VIRTIO_NET_CTRL_RX 0 @@ -2623,8 +2649,7 @@ off. The command-specific-data is one byte containing 0 (off) or end{lstlisting} The device can filter incoming packets by any number of destination -MAC addresses. -footnote{Since there are no guarentees, it can use a hash filter or +MAC addresses.footnote{Since there are no guarentees, it can use a hash filter or silently switch to allmulti or promiscuous mode if it is given too many addresses. } This table is set using the class @@ -2679,12 +2704,14 @@ this command. Processing this notification involves: -1. Sending the gratuitous packets or marking there are pending +egin{enumerate} +item Sending the gratuitous packets or marking there are pending gratuitous packets to be sent and letting deferred routine to send them. -2. Sending VIRTIO_NET_CTRL_ANNOUNCE_ACK command through control +item Sending VIRTIO_NET_CTRL_ANNO


  • 2.  Re: [PATCH] latexify document more.

    Posted 12-02-2013 08:55
    On Mon, Dec 02, 2013 at 04:56:16PM +1030, Rusty Russell wrote: > This change: > - Turns formatted lists into real lists (itemize, etc). > - Turns ascii tables into real tables. > - Use ldots for ... > - Moves footnote to immediately after what it refers to, otherwise we > get awkward whitespace before the superscript. > - List of stats for balloon contains values in () to match other lists. > - Puts lstlisting around CCW code example > > No actual contents changed, but I haven't committed it yet to avoid > stepping on MST's toes if he has outstanding commits. > > Signed-off-by: Rusty Russell <rusty@au.ibm.com> I don't have outstanding commits so please go ahead. Did you use some script for converting these? > diff --git a/content.tex b/content.tex > index 259dea1..8db13c4 100644 > --- a/content.tex > +++ b/content.tex > @@ -5,10 +5,12 @@ A virtio device is discovered and identified by a bus-specific method >
    ef{sec:Virtio Transport Options / Virtio Over MMIO}~
    ameref{sec:Virtio Transport Options / Virtio Over MMIO} and
    ef{sec:Virtio Transport Options / Virtio Over Channel I/O}~
    ameref{sec:Virtio Transport Options / Virtio Over Channel I/O}). Each > device consists of the following parts: > > -o Device Status field > -o Feature bits > -o Configuration space > -o One or more virtqueues > +egin{itemize} > +item Device Status field > +item Feature bits > +item Configuration space > +item One or more virtqueues > +end{itemize} > > Unless explicitly specified otherwise, all multi-byte fields are little-endian. > To reinforce this the examples use typenames like "le16" instead of "uint16_t". > @@ -23,25 +25,27 @@ clear a device status bit. > > This field is 0 upon reset, otherwise at least one bit should be set: > > - ACKNOWLEDGE (1) Indicates that the guest OS has found the > +egin{description} > +item[ACKNOWLEDGE (1)] Indicates that the guest OS has found the > device and recognized it as a valid virtio device. > > - DRIVER (2) Indicates that the guest OS knows how to drive the > +item[DRIVER (2)] Indicates that the guest OS knows how to drive the > device. Under Linux, drivers can be loadable modules so there > may be a significant (or infinite) delay before setting this > bit. > > - FEATURES_OK (8) Indicates that the driver has acknowledged all the > +item[FEATURES_OK (8)] Indicates that the driver has acknowledged all the > features it understands, and feature negotiation is complete. > > - DRIVER_OK (4) Indicates that the driver is set up and ready to > +item[DRIVER_OK (4)] Indicates that the driver is set up and ready to > drive the device. > > - FAILED (128) Indicates that something went wrong in the guest, > +item[FAILED (128)] Indicates that something went wrong in the guest, > and it has given up on the device. This could be an internal > error, or the driver didn't like the device for some reason, or > even a fatal error during device operation. The driver MUST > reset the device before attempting to re-initialize. > +end{description} > > section{Feature Bits}label{sec:Basic Facilities of a Virtio Device / Feature Bits} > > @@ -67,12 +71,14 @@ which was not offered. > > Feature bits are allocated as follows: > > - 0 to 23: Feature bits for the specific device type > +egin{description} > +item[0 to 23] Feature bits for the specific device type > > - 24 to 32: Feature bits reserved for extensions to the queue and > +item[24 to 32] Feature bits reserved for extensions to the queue and > feature negotiation mechanisms > > - 33 and above: Feature bits reserved for future extensions. > +item[33 and above] Feature bits reserved for future extensions. > +end{description} > > For example, feature bit 0 for a network device (i.e. Subsystem > Device ID 1) indicates that the device supports checksumming of > @@ -91,15 +97,17 @@ Since these are widely deployed, this specification > accommodates optional features to simplify transition > from these earlier draft interfaces. Specifically: > > -Legacy Interface > +egin{description} > +item[Legacy Interface] > is an interface specified by an earlier draft of this specification > (up to 0.9.X) > -Legacy Device > +item[Legacy Device] > is a device implemented before this specification was released, > and implementing a legacy interface on the host side > -Legacy Driver > +item[Legacy Driver] > is a driver implemented before this specification was released, > and implementing a legacy interface on the guest side > +end{description} > > Legacy devices and legacy drivers are not compliant with this > specification. > @@ -107,13 +115,15 @@ specification. > To simplify transition from these earlier draft interfaces, > it is possible to implement: > > -Transitional Device > +egin{description} > +item[Transitional Device] > a device supporting both drivers conforming to this > specification, and allowing legacy drivers. > > -Transitional Driver > +item[Transitional Driver] > a driver supporting both devices conforming to this > specification, and legacy devices. > +end{description} > > Transitional devices and transitional drivers can be compliant with > this specification (ie. when not operating in legacy mode). > @@ -196,11 +206,11 @@ of the queue. > > Each virtqueue consists of three parts: > > - Descriptor Table > - > - Available Ring > - > - Used Ring > +egin{itemize} > +item Descriptor Table > +item Available Ring > +item Used Ring > +end{itemize} > > where each part is physically-contiguous in guest memory, > and has different alignment requirements. > @@ -208,18 +218,17 @@ and has different alignment requirements. > The memory aligment and size requirements, in bytes, of each part of the > virtqueue are summarized in the following table: > > -egin{verbatim} > -+------------+-----------------------------------------+ > - Virtqueue Part Alignment Size > -+------------+-----------------------------------------+ > -+------------+-----------------------------------------+ > - Descriptor Table 16 16 * (Queue Size) > -+------------+-----------------------------------------+ > - Available Ring 2 6 + 2 * (Queue Size) > -+------------+-----------------------------------------+ > - Used Ring 4 6 + 4 * (Queue Size) > -+------------+-----------------------------------------+ > -end{verbatim} > +egin{tabular}{ l l l } > +hline > +Virtqueue Part & Alignment & Size \ > +hline hline > +Descriptor Table & 16 & $16 * $(Queue Size) \ > +hline > +Available Ring & 2 & $6 + 2 * $(Queue Size) \ > + hline > +Used Ring & 4 & $6 + 4 * $(Queue Size) \ > + hline > +end{tabular} > > The Alignment column gives the miminum alignment: for each part > of the virtqueue, the physical address of the first byte > @@ -250,11 +259,11 @@ Each virtqueue occupies two or more physically-contiguous pages > (usually defined as 4096 bytes, but depending on the transport) > and consists of three parts: > > -egin{verbatim} > -+-------------------+-----------------------------------+-----------+ > - Descriptor Table Available Ring (padding) Used Ring > -+-------------------+-----------------------------------+-----------+ > -end{verbatim} > +egin{tabular}{ l l l } > +hline > +Descriptor Table & Available Ring (ldots paddingldots) & Used Ring \ > +hline > +end{tabular} > > The bus-specific Queue Size field controls the total number of bytes > required for the virtqueue according to the following formula: > @@ -503,28 +512,30 @@ how to communicate with the specific device. > > The driver MUST follow this sequence to initialize a device: > > -1. Reset the device. > +egin{enumerate} > +item Reset the device. > > -2. Set the ACKNOWLEDGE status bit: we have noticed the device. > +item Set the ACKNOWLEDGE status bit: we have noticed the device. > > -3. Set the DRIVER status bit: we know how to drive the device. > +item Set the DRIVER status bit: we know how to drive the device. > > -4. Read device feature bits, and write the subset of feature bits > +item Read device feature bits, and write the subset of feature bits > understood by the OS and driver to the device. > > -5. Set the FEATURES_OK status bit. The driver MUST not accept > +item Set the FEATURES_OK status bit. The driver MUST not accept > new feature bits after this step. > > -6. Re-read the status byte to ensure the FEATURES_OK bit is still > +item Re-read the status byte to ensure the FEATURES_OK bit is still > set: otherwise, the device does not support our subset of features > and the device is unusable. > > -7. Perform device-specific setup, including discovery of virtqueues for the > +item Perform device-specific setup, including discovery of virtqueues for the > device, optional per-bus setup, reading and possibly writing the > device's virtio configuration space, and population of virtqueues. > > -8. Set the DRIVER_OK status bit. At this point the device is > +item Set the DRIVER_OK status bit. At this point the device is > "live". > +end{enumerate} > > If any of these steps go irrecoverably wrong, the driver SHOULD > set the FAILED status bit to indicate that it has given up on the > @@ -568,27 +579,29 @@ they are used. > > The driver offers buffers to one of the device's virtqueues as follows: > > -1. The driver places the buffer into free descriptor(s) in the > +egin{enumerate} > +item The driver places the buffer into free descriptor(s) in the > descriptor table, chaining as necessary (see
    ef{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table}~
    ameref{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table}). > > -2. The driver places the index of the head of the descriptor chain > +item The driver places the index of the head of the descriptor chain > into the next ring entry of the available ring. > > -3. Steps (1) and (2) may be performed repeatedly if batching > +item Steps (1) and (2) may be performed repeatedly if batching > is possible. > > -4. The driver MUST perform suitable a memory barrier to ensure the device sees > +item The driver MUST perform suitable a memory barrier to ensure the device sees > the updated descriptor table and available ring before the next > step. > > -5. The available “idx” field is increased by the number of > +item The available “idx” field is increased by the number of > descriptor chain heads added to the available ring. > > -6. The driver MUST perform a suitable memory barrier to ensure that it updates > +item The driver MUST perform a suitable memory barrier to ensure that it updates > the "idx" field before checking for notification suppression. > > -7. If notifications are not suppressed, the driver MUST notify the device > +item If notifications are not suppressed, the driver MUST notify the device > of the new available buffers. > +end{enumerate} > > Note that the above code does not take precautions against the > available ring buffer wrapping around: this is not possible since > @@ -611,21 +624,19 @@ chain: > > for each buffer element, b: > > - (a) Get the next free descriptor table entry, d > - > - (b) Set d.addr to the physical address of the start of b > - > - (c) Set d.len to the length of b. > - > - (d) If b is write-only, set d.flags to VRING_DESC_F_WRITE, > +egin{enumerate} > +item Get the next free descriptor table entry, d > +item Set d.addr to the physical address of the start of b > +item Set d.len to the length of b. > +item If b is write-only, set d.flags to VRING_DESC_F_WRITE, > otherwise 0. > - > - (e) If there is a buffer element after this: > - > - i. Set d.next to the index of the next free descriptor > +item If there is a buffer element after this: > + egin{enumerate} > + item Set d.next to the index of the next free descriptor > element. > - > - ii. Set the VRING_DESC_F_NEXT bit in d.flags. > + item Set the VRING_DESC_F_NEXT bit in d.flags. > + end{enumerate} > +end{enumerate} > > In practice, the d.next fields are usually used to chain free > descriptors, and a separate count kept to check there are enough > @@ -698,24 +709,28 @@ device), it sends an interrupt, following an algorithm very > similar to the algorithm used for the driver to send the device a > buffer: > > -1. Write the head descriptor number to the next field in the used > +egin{enumerate} > +item Write the head descriptor number to the next field in the used > ring. > > -2. Update the used ring index. > +item Update the used ring index. > > -3. Deliver an interrupt if necessary: > +item Deliver an interrupt if necessary: > > - (a) If the VIRTIO_F_RING_EVENT_IDX feature is not negotiated: > + egin{enumerate} > + item If the VIRTIO_F_RING_EVENT_IDX feature is not negotiated: > check if the VRING_AVAIL_F_NO_INTERRUPT flag is not set in > av