[device] Provide a driver-private data field for root devices

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[iobuf] Add iob_split() to split an I/O buffer into portions

RNDIS devices may provide multiple packets encapsulated into a single
message.  Provide an API to allow the RNDIS driver to split an I/O
buffer into smaller portions.

The current implementation will always copy the underlying data,
rather than splitting the buffer in situ.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[rndis] Add generic RNDIS device abstraction

RNDIS provides an abstraction of a network device on top of a generic
packet transmission mechanism.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Add support for Hyper-V hypervisor

Add support for detecting and communicating with the Hyper-V
hypervisor.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Add support for VMBus devices

Add support for an abstraction of a VMBus device.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Add support for NetVSC paravirtual network devices

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[rndis] Send RNDIS_INITIALISE_MSG

The Hyper-V RNDIS implementation on Windows Server 2012 R2 requires
that we send an explicit RNDIS initialisation message in order to get
a working RX datapath.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[rndis] Send RNDIS_HALT_MSG

The RNDIS specification requires that we send RNDIS_HALT_MSG.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Tear down NetVSC RX buffer GPADL after closing VMBus device

On Windows Server 2012 R2, the receive buffer teardown completion
message seems to occasionally be deferred until after the VMBus
channel has been closed.  This happens even if there are no packets
currently in the receive buffer.

Work around this problem by separating the revocation and teardown of
the receive buffer, and deferring the teardown until after the VMBus
channel has been closed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[rndis] Clear receive filter when closing the device

On Windows Server 2012 R2, closing and reopening the device will
sometimes result in a non-functional RX datapath.  The root cause is
unknown.  Clearing the receive filter before closing the device seems
to fix the problem.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Receive all VMBus messages in a poll

Allow for elision of transmitted TCP ACKs by handling all received
VMBus messages in each network device poll operation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Increase TX ring size

Empirical observation suggests that 32 is a sensible size to minimise
the number of deferred packet transmissions without overflowing the
VMBus transmit ring buffer.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Assume that VMBus xfer page ranges correspond to RNDIS messages

The (undocumented) VMBus protocol seems to allow for transfer
page-based packets where the data payload is split into an arbitrary
set of ranges within the transfer page set.

The RNDIS protocol includes a length field within the header of each
message, and it is known from observation that multiple RNDIS messages
can be concatenated into a single VMBus message.

iPXE currently assumes that the transfer page range boundaries are
entirely arbitrary, and uses the RNDIS header length to determine the
RNDIS message boundaries.

Windows Server 2012 R2 generates an RNDIS_INDICATE_STATUS_MSG for an
undocumented and unknown status code (0x40020006) with a malformed
RNDIS header length: the length does not cover the StatusBuffer
portion of the message.  This causes iPXE to report a malformed RNDIS
message and to discard any further RNDIS messages within the same
VMBus message.

The Linux Hyper-V driver assumes that the transfer page range
boundaries correspond to RNDIS message boundaries, and so does not
notice the malformed length field in the RNDIS header.

Match the behaviour of the Linux Hyper-V driver: assume that the
transfer page range boundaries correspond to the RNDIS message
boundaries and ignore the RNDIS header length.  This avoids triggering
the "malformed packet" error and also avoids unnecessary data copying:
since we now have one I/O buffer per RNDIS message, there is no longer
any need to use iob_split().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[rndis] Ignore start-of-day RNDIS_INDICATE_STATUS_MSG with status 0x40020006

Windows Server 2012 R2 generates an RNDIS_INDICATE_STATUS_MSG with a
status code of 0x4002006.  This status code does not appear to be
documented anywhere within the sphere of human knowledge.

Explicitly ignore this status code in order to avoid unnecessarily
cluttering the display when RNDIS debugging is enabled.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Tidy up debug output

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[hyperv] Require support for VMBus version 3.0 or newer

We require the ability to disconnect from and reconnect to VMBus; if
we don't have this then there is no (viable) way for a loaded
operating system to continue to use any VMBus devices.  (There is also
a small but non-zero risk that the host will continue to write to our
interrupt and monitor pages, since the VMBUS_UNLOAD message in earlier
versions is essentially a no-op.)

This requires us to ensure that the host supports protocol version 3.0
(VMBUS_VERSION_WIN8_1).  However, we can't actually _use_ protocol
version 3.0, since doing so causes an iSCSI-booted Windows Server 2012
R2 VM to crash due to a NULL pointer dereference in vmbus.sys.

To work around this problem, we first ensure that we can connect using
protocol v3.0, then disconnect and reconnect using the oldest known
protocol.

This deliberately prevents the use of the iPXE native Hyper-V drivers
on older versions of Hyper-V, where we could use our drivers but in so
doing would break the loaded operating system.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Include Hyper-V driver in the all-drivers build

Signed-off-by: Michael Brown <mcb30@ipxe.org>