[build] Allow sparse to find compiler.h

sparse seems to have problems finding compiler.h when specified as
"-include compiler.h"; one possible explanation is that it ignores the
include path.  Fix by using "-include include/compiler.h".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Define __WINT_TYPE__ if necessary

sparse does not define __WCHAR_TYPE__ or __WINT_TYPE__.  We already
define __WCHAR_TYPE__ if the compiler does not do so; do the same for
__WINT_TYPE__.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Allow sparse to be invoked via "make C=1"

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Avoid sparse undeclared symbol warning for PROVIDE_SYMBOL()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[process] Mark process descriptor as static in PERMANENT_PROCESS

There is no need for the process descriptor to be a global variable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[realtek] Print bad MAC address in debug message when inferring no EEPROM

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Use -Wno-decl when running sparse

Linker table entries must be non-static in order to avoid being
completely optimised away by some versions of gcc.  Use -Wno-decl to
prevent sparse from warning about these, since the alternative would
be to litter the code with otherwise unnecessary "extern"
declarations.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Fix uses of literal 0 as a NULL pointer

Detected using sparse.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Fix dubious uses of bitwise operators

Detected by sparse.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[build] Default to short wchar_t in stddef.h

sparse does not understand -fshort-wchar.  Default to using uint16_t
as a wchar_t if not explicitly specified by the compiler, to avoid
large numbers of spurious warnings from sparse.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[realtek] Use ID word to detect EEPROM presence

Some onboard RTL8169 NICs seem to leave the EEPROM pins disconnected.
The existing is_valid_ether_addr() test will not necessarily catch
this, since it expects a missing EEPROM to show up as a MAC address of
00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff.  When the EEPROM pins are
floating the MAC address may read as e.g. 00:00:00:00:0f:00, which
will not be detected as invalid.

Check the ID word in the first two bytes of the EEPROM (which should
have the value 0x8129 for all RTL8139 and RTL8169 chips), and use this
to determine whether or not an EEPROM is present.

Reported-by: Carl Karsten <carl@nextdayvideo.com>
Tested-by: Carl Karsten <carl@nextdayvideo.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
[errdb] Strip platform error code for non-platform-generated errors

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[pxe] Convert external PXE API errors into iPXE platform-generated errors

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[realtek] Allow reaction time between writing RTL_CAPR and reading RTL_CR

Some older RTL8139 chips seem to not immediately update the
RTL_CR.BUFE bit in response to a write to RTL_CAPR.  This results in
iPXE seeing a spurious zero-length received packet, and thereafter
being out of sync with the hardware's RX ring offset.

Fix by inserting an extra PCI read cycle after writing to RTL_CAPR, to
give the chip time to react before we next read RTL_CR.

Reported-by: Gelip <mrgelip@gmail.com>
Tested-by: Gelip <mrgelip@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
[romprefix] Report failure cause when unable to open payload

Report the cause of the failure when we are unable to open the .mrom
payload.  There are two possible failure cases:

 - Unable to find a suitable memory BAR to borrow (e.g. if the NIC
   doesn't have a memory BAR that is at least as large as the
   expansion ROM BAR, or if the memory BAR has been assigned a 64-bit
   address which won't fit into the 32-bit expansion ROM BAR).  This
   will be reported as "BABABABA".

 - Unable to find correct ROM image within the BAR.  This will be
   reported as the address (within the borrowed BAR) at which we first
   fail to find a valid 55AA signature.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[realtek] Ensure EEPROM writes reach chip before starting udelay()

On some systems, it appears to be possible for writes to the EEPROM
registers to be delayed for long enough that the EEPROM's setup and
hold times are violated, resulting in invalid data being read from the
EEPROM.

Fix by inserting a PCI read cycle immediately after writes to
RTL_9346CR, to ensure that the write has completed before starting the
udelay() used to time the SPI bus transitions.

Reported-by: Gelip <mrgelip@gmail.com>
Tested-by: Gelip <mrgelip@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
[dhcp] Remove obsolete bootp.h header

Reported-by: Christian Helmuth <christian.helmuth@genode-labs.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
[netdevice] Add netdev_tx_defer() to allow drivers to defer transmissions

Devices with small transmit descriptor rings may temporarily run out
of space.  Provide netdev_tx_defer() to allow drivers to defer packets
for retransmission as soon as a descriptor becomes available.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[realtek] Defer packets when no transmit descriptors are available

Signed-off-by: Michael Brown <mcb30@ipxe.org>
[settings] Eliminate settings "tag magic"

Create an explicit concept of "settings scope" and eliminate the magic
values used for numerical setting tags.

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