]> git.ipfire.org Git - thirdparty/ipxe.git/log
thirdparty/ipxe.git
4 years ago[hermon] Limit link poll frequency in DOWN state 242/head
Michael Brown [Sun, 31 Jan 2021 23:29:45 +0000 (23:29 +0000)] 
[hermon] Limit link poll frequency in DOWN state

Some older versions of the hardware (and/or firmware) do not report an
event when an Infiniband link reaches the INIT state.  The driver
works around this missing event by calling ib_smc_update() on each
event queue poll while the link is in the DOWN state.

Commit 6cb12ee ("[hermon] Increase polling rate for command
completions") addressed this by speeding up the time taken to issue
each command invoked by ib_smc_update().  Experimentation shows that
the impact is still significant: for example, in a situation where an
unplugged port is opened, the throughput on the other port can be
reduced by over 99%.

Fix by throttling the rate at which link polling is attempted.

Debugged-by: Christian Iversen <ci@iversenit.dk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Avoid using awk to format build ID as hexadecimal
Michael Brown [Sun, 31 Jan 2021 00:41:34 +0000 (00:41 +0000)] 
[build] Avoid using awk to format build ID as hexadecimal

The version of awk used in FreeBSD seems to be incapable of formatting
unsigned 32-bit integers above 0x80000000 and will silently render any
such value as 0x80000000.  For example:

  echo 3735928559 | awk '{printf "0x%08x", $1}'

will produce 0x80000000 instead of the correct 0xdeadbeef.

This results in an approximately 50% chance of a build ID collision
when building on FreeBSD.

Work around this problem by passing the decimal value directly in the
ld --defsym argument value.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Avoid using sha1sum when calculating build ID
Michael Brown [Sun, 31 Jan 2021 00:30:10 +0000 (00:30 +0000)] 
[build] Avoid using sha1sum when calculating build ID

The sha1sum command may not be available on all systems.  Use the
POSIX-confirming cksum instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Allow BIOS linker script to be used with FreeBSD linker
Michael Brown [Sat, 30 Jan 2021 11:48:47 +0000 (11:48 +0000)] 
[build] Allow BIOS linker script to be used with FreeBSD linker

Add a few more ABSOLUTE() expressions to convince the FreeBSD linker
that already-absolute symbols are, in fact, absolute.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Check for broken elftoolchain version of objcopy
Michael Brown [Sat, 30 Jan 2021 01:56:16 +0000 (01:56 +0000)] 
[build] Check for broken elftoolchain version of objcopy

The elftoolchain version of objcopy (as used in FreeBSD) seems to be
unusable for generating a raw binary file, since it will apparently
ignore the load memory addresses specified for each section in the
input file.

The binutils version of objcopy may be used on FreeBSD by specifying

  OBJCOPY=/usr/local/bin/objcopy

Detect an attempt to use the unusable elftoolchain version of objcopy
and report it as an error.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Avoid modifying load addresses when stripping .zinfo section
Michael Brown [Sat, 30 Jan 2021 01:35:27 +0000 (01:35 +0000)] 
[build] Avoid modifying load addresses when stripping .zinfo section

Some versions of objcopy will spuriously complain when asked to
extract the .zinfo section since doing so will nominally alter the
load addresses of the (non-loadable) .bss.* sections.

Avoid these warnings by placing the .zinfo section at the very end of
the load memory address space.

Allocate non-overlapping load memory addresses for the (non-loadable)
.bss.* sections, in the hope of avoiding spurious warnings about
overlapping load addresses.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Replace random build ID with a deterministic one
Manuel Mendez [Thu, 28 Jan 2021 21:45:04 +0000 (16:45 -0500)] 
[build] Replace random build ID with a deterministic one

Calculate the build ID as a checksum over the input files.  Since the
input files include $(BIN)/version.%.o which itself includes the build
target name (from which TGT_LD_FLAGS is calculated), this should be
sufficient to meet the requirement that the build ID be unique for
each $(BIN)/%.tmp even within the same build run.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Use $(shell ...) to invoke BUILD_ID_CMD
Manuel Mendez [Fri, 29 Jan 2021 14:23:54 +0000 (09:23 -0500)] 
[build] Use $(shell ...) to invoke BUILD_ID_CMD

When using $(shell), make will first invoke BUILD_ID_CMD and then have
the value defined when calling $(LD).  This means we get to see the
_build_id when building with make V=1.  Previously the build_id was
figured out as a subshell command run during the recipe execution
without being able to see the build_id itself.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Use SOURCE_DATE_EPOCH if it exists
Manuel Mendez [Sat, 16 Jan 2021 02:29:27 +0000 (21:29 -0500)] 
[build] Use SOURCE_DATE_EPOCH if it exists

See https://reproducible-builds.org/docs/source-date-epoch/ for
rationale.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Use recursive deletion for "make clean"
Michael Brown [Sat, 30 Jan 2021 17:37:09 +0000 (17:37 +0000)] 
[build] Use recursive deletion for "make clean"

Directories may be left behind by failed filesystem image builds, and
will not currently be successfully removed by a "make clean".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Avoid shell brace expansion in "make clean"
Michael Brown [Sat, 30 Jan 2021 17:34:49 +0000 (17:34 +0000)] 
[build] Avoid shell brace expansion in "make clean"

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Allow elf2efi.c to build on FreeBSD
Michael Brown [Sat, 30 Jan 2021 00:11:33 +0000 (00:11 +0000)] 
[build] Allow elf2efi.c to build on FreeBSD

The elf.h on FreeBSD defines ELF_R_TYPE and ELF_R_SYM (based on the
host platform) and omits some but not all of the AArch64 relocation
types.

Fix by undefining ELF_R_TYPE and ELF_R_SYM in favour of our own
definitions, and by placing each potentially missing relocation type
within an individual #ifdef guard.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Ensure that isolinux.bin is modifiable
Michael Brown [Fri, 29 Jan 2021 23:55:36 +0000 (23:55 +0000)] 
[build] Ensure that isolinux.bin is modifiable

The -boot-info-table option to mkisofs will cause it to overwrite a
portion of the local copy of isolinux.bin.  Ensure that this file is
writable.

Originally-implemented-by: Nikolai Lifanov <lifanov@mail.lifanov.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Add syslinux search locations used on FreeBSD
Michael Brown [Fri, 29 Jan 2021 23:51:49 +0000 (23:51 +0000)] 
[build] Add syslinux search locations used on FreeBSD

Originally-implemented-by: Nikolai Lifanov <lifanov@mail.lifanov.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Drop timestamps from .a file
Bernhard M. Wiedemann [Fri, 29 Jan 2021 12:41:42 +0000 (13:41 +0100)] 
[build] Drop timestamps from .a file

Make the contents of $(BLIB) deterministic to allow it to be
subsequently used for calculating a build ID.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Perform clean MPT unmap on device shutdown
Christian Iversen [Tue, 26 Jan 2021 22:48:44 +0000 (23:48 +0100)] 
[hermon] Perform clean MPT unmap on device shutdown

This change is ported from Flexboot sources.  When stopping a Hermon
device, perform hermon_unmap_mpt() which runs HERMON_HCR_HW2SW_MPT to
bring the Memory Protection Table (MPT) back to software control.

Signed-off-by: Christian Iversen <ci@iversenit.dk>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Use Ethernet MAC as eIPoIB local EMAC
Christian Iversen [Tue, 26 Jan 2021 21:56:42 +0000 (22:56 +0100)] 
[hermon] Use Ethernet MAC as eIPoIB local EMAC

The eIPoIB local Ethernet MAC is currently constructed from the port
GUID.  Given a base GUID/MAC value of N, Mellanox seems to populate:

  Node GUID:   N + 0
  Port 1 GUID: N + 1
  Port 2 GUID: N + 2

and

  Port 1 MAC:  N + 0
  Port 2 MAC:  N + 1

This causes a duplicate local MAC address when port 1 is configured as
Infiniband and port 2 as Ethernet, since both will derive their MAC
address as (N + 1).

Fix by using the port's Ethernet MAC as the eIPoIB local EMAC.  This
is a behavioural change that could potentially break configurations
that rely on the local EMAC value, such as a DHCP server relying on
the chaddr field for DHCP reservations.

Signed-off-by: Christian Iversen <ci@iversenit.dk>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Increase polling rate for command completions
Christian Iversen [Tue, 26 Jan 2021 21:47:29 +0000 (22:47 +0100)] 
[hermon] Increase polling rate for command completions

Some older versions of the hardware (and/or firmware) do not report an
event when an Infiniband link reaches the INIT state.  The driver
works around this missing event by calling ib_smc_update() on each
event queue poll while the link is in the DOWN state.  This results in
a very large number of commands being issued while any open Infiniband
link is in the DOWN state (e.g. unplugged), to the point that the 1ms
delay from waiting for each command to complete will noticeably affect
responsiveness.

Fix by decreasing the command completion polling delay from 1ms to
10us.

Signed-off-by: Christian Iversen <ci@iversenit.dk>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Add event queue debug functions
Michael Brown [Thu, 28 Jan 2021 22:01:43 +0000 (22:01 +0000)] 
[hermon] Add event queue debug functions

Add hermon_dump_eqctx() for dumping the event queue context and
hermon_dump_eqes() for dumping any unconsumed event queue entries.

Originally-implemented-by: Christian Iversen <ci@iversenit.dk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Increase command timeout from 2 to 10 seconds
Christian Iversen [Mon, 25 Jan 2021 12:32:04 +0000 (13:32 +0100)] 
[hermon] Increase command timeout from 2 to 10 seconds

Some commands (particularly in relation to device initialization) can
occasionally take longer than 2 seconds, and the Mellanox documentation
recommends a 10 second timeout.

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[hermon] Add assorted debug error messages
Michael Brown [Thu, 28 Jan 2021 20:52:36 +0000 (20:52 +0000)] 
[hermon] Add assorted debug error messages

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Show "issuing command" messages only at DBGLVL_EXTRA
Michael Brown [Thu, 28 Jan 2021 17:29:36 +0000 (17:29 +0000)] 
[hermon] Show "issuing command" messages only at DBGLVL_EXTRA

Originally-implemented-by: Christian Iversen <ci@iversenit.dk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[hermon] Reorganize PCI ROM list and document well-known product names
Christian Iversen [Sat, 23 Jan 2021 12:26:24 +0000 (13:26 +0100)] 
[hermon] Reorganize PCI ROM list and document well-known product names

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[golan] Backport typo fix in nodnic_prm.h: s/HERMON/NODNIC/
Christian Iversen [Mon, 4 May 2020 19:45:29 +0000 (21:45 +0200)] 
[golan] Backport typo fix in nodnic_prm.h: s/HERMON/NODNIC/

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[arbel] Clean up whitespace in MT25218_PRM.h header
Christian Iversen [Mon, 4 May 2020 14:15:13 +0000 (16:15 +0200)] 
[arbel] Clean up whitespace in MT25218_PRM.h header

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[hermon] Clean up whitespace in MT25408_PRM.h header
Christian Iversen [Mon, 4 May 2020 13:45:11 +0000 (15:45 +0200)] 
[hermon] Clean up whitespace in MT25408_PRM.h header

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[efi] Use EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL if available
Michael Brown [Tue, 26 Jan 2021 20:46:57 +0000 (20:46 +0000)] 
[efi] Use EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL if available

The original EFI_SIMPLE_TEXT_INPUT_PROTOCOL is not technically
required to handle the use of the Ctrl key, and the long-obsolete EFI
1.10 specification lists only backspace, tab, linefeed, and carriage
return as required.  Some particularly brain-dead vendor UEFI firmware
implementations dutifully put in the extra effort of ensuring that all
other control characters (such as Ctrl-C) are impossible to type via
EFI_SIMPLE_TEXT_INPUT_PROTOCOL.

Current versions of the UEFI specification mandate that the console
input handle must support both EFI_SIMPLE_TEXT_INPUT_PROTOCOL and
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL, the latter of which at least
provides access to modifier key state.

Unlike EFI_SIMPLE_TEXT_INPUT_PROTOCOL, the pointer to the
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance does not appear within the
EFI system table and must therefore be opened explicitly.  The UEFI
specification provides no safe way to do so, since we cannot open the
handle BY_DRIVER or BY_CHILD_CONTROLLER and so nothing guarantees that
this pointer will remain valid for the lifetime of iPXE.  We must
simply hope that no UEFI firmware implementation ever discovers a
motivation for reinstalling the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
instance.

Use EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL if available, falling back to
the existing EFI_SIMPLE_TEXT_PROTOCOL otherwise.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[image] Implicitly trust first embedded image
Joe Groocock [Thu, 19 Dec 2019 13:08:50 +0000 (13:08 +0000)] 
[image] Implicitly trust first embedded image

iPXE when used as a NIC option ROM can sometimes be reloaded by the
UEFI/BIOS and any pre-initialised memory will remain loaded. When the
imgtrust command is run it sets `require_trusted_images'. Upon
reloading, iPXE tries to load the first embedded image but fails as it
is not marked trusted.

Setting this flag ensures that imgtrust with the first embedded script
is reentrant.

Signed-off-by: Joe Groocock <jgroocock@cloudflare.com>
4 years ago[infiniband] Require drivers to specify the number of ports
Christian Iversen [Tue, 26 Jan 2021 23:43:51 +0000 (00:43 +0100)] 
[infiniband] Require drivers to specify the number of ports

Require drivers to report the total number of Infiniband ports.  This
is necessary to report the correct number of ports on devices with
dynamic port types.

For example, dual-port Mellanox cards configured for (eth, ib) would
be rejected by the subnet manager, because they report using "port 2,
out of 1".

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[efi] Fix misleading debug message
Michael Brown [Tue, 26 Jan 2021 22:25:18 +0000 (22:25 +0000)] 
[efi] Fix misleading debug message

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[ifmgmt] Make "ifstat" show the link-layer protocol for each netdev
Christian Iversen [Tue, 26 Jan 2021 20:46:33 +0000 (21:46 +0100)] 
[ifmgmt] Make "ifstat" show the link-layer protocol for each netdev

This is useful on devices that perform auto-detection for ports.
Example output:

    iPXE> ifstat
    net0: 00:11:22:33:44:55 using mt4099 on 0000:00:03.0 (Ethernet) [open]
      [Link:down, TX:0 TXE:0 RX:0 RXE:0]
      [Link status: Unknown (http://ipxe.org/1a086101)]
    net1: 00:11:22:33:44:56 using mt4099 on 0000:00:03.0 (IPoIB) [open]
      [Link:down, TX:0 TXE:0 RX:0 RXE:0]
      [Link status: Initialising (http://ipxe.org/1a136101)]

Signed-off-by: Christian Iversen <ci@iversenit.dk>
4 years ago[cmdline] Expose "iflinkwait" as a command 224/head
Michael Brown [Tue, 26 Jan 2021 15:44:59 +0000 (15:44 +0000)] 
[cmdline] Expose "iflinkwait" as a command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Fix use of uninitialised variable
Michael Brown [Tue, 26 Jan 2021 11:30:50 +0000 (11:30 +0000)] 
[efi] Fix use of uninitialised variable

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Automatically load "/autoexec.ipxe" when booted from a filesystem
Michael Brown [Mon, 25 Jan 2021 16:34:22 +0000 (16:34 +0000)] 
[efi] Automatically load "/autoexec.ipxe" when booted from a filesystem

When booting iPXE from a filesystem (e.g. a FAT-formatted USB key) it
can be useful to have an iPXE script loaded automatically from the
same filesystem.  Compared to using an embedded script, this has the
advantage that the script can be edited without recompiling the iPXE
binary.

For the BIOS version of iPXE, loading from a filesystem is handled
using syslinux (or isolinux) which allows the script to be passed to
the iPXE .lkrn image as an initrd.

For the UEFI version of iPXE, the platform firmware loads the iPXE
.efi image directly and there is currently no equivalent of the BIOS
initrd mechanism.

Add support for automatically loading a file "autoexec.ipxe" (if
present) from the root of the filesystem containing the UEFI iPXE
binary.

A combined BIOS and UEFI image for a USB key can be created using e.g.

  ./util/genfsimg -o usbkey.img -s myscript.ipxe \
      bin-x86_64-efi/ipxe.efi bin/ipxe.lkrn

The file "myscript.ipxe" would appear as "autoexec.ipxe" on the USB
key, and would be loaded automatically on both BIOS and UEFI systems.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[image] Provide image_memory()
Michael Brown [Mon, 25 Jan 2021 16:18:28 +0000 (16:18 +0000)] 
[image] Provide image_memory()

Consolidate the remaining logic common to initrd_init() and imgmem()
into a shared image_memory() function.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[travis] Update to current default build environment
Michael Brown [Sun, 24 Jan 2021 12:39:46 +0000 (12:39 +0000)] 
[travis] Update to current default build environment

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Report a meaningful error message if isolinux.bin is missing
Michael Brown [Sun, 24 Jan 2021 12:31:48 +0000 (12:31 +0000)] 
[build] Report a meaningful error message if isolinux.bin is missing

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Check that mkisofs equivalent supports the required options
Michael Brown [Sun, 24 Jan 2021 12:15:20 +0000 (12:15 +0000)] 
[build] Check that mkisofs equivalent supports the required options

The "-e" option required for creating EFI boot images is supported
only by widely used patched versions of genisoimage.

Check that the required options are supported when selecting a mkisofs
equivalent, thereby allowing a fallback to the use of xorrisofs when
building a UEFI ISO image on a system with an unpatched version of
genisoimage.

Continue to prefer the use of genisoimage over xorrisofs, since there
is apparently no way to inhibit the irritatingly useless startup
banner message printed by xorrisofs even when the "-quiet" option is
specified.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[tftp] Allow for profiling of client and server turnaround times
Michael Brown [Fri, 22 Jan 2021 21:05:07 +0000 (21:05 +0000)] 
[tftp] Allow for profiling of client and server turnaround times

Provide some visibility into the turnaround times on both client and
server sides as perceived by iPXE, to assist in debugging inexplicably
slow TFTP transfers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[image] Add the "imgmem" command
Michael Brown [Wed, 20 Jan 2021 18:08:04 +0000 (18:08 +0000)] 
[image] Add the "imgmem" command

Provide the "imgmem" command to create an image from an existing block
of memory, for debugging purposes only.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[image] Provide image_set_data()
Michael Brown [Wed, 20 Jan 2021 18:03:16 +0000 (18:03 +0000)] 
[image] Provide image_set_data()

Extract part of the logic in initrd_init() to a standalone function
image_set_data().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Allow an initrd script to be provided via genfsimg
Michael Brown [Fri, 22 Jan 2021 18:33:51 +0000 (18:33 +0000)] 
[build] Allow an initrd script to be provided via genfsimg

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Fail gracefully when no input files are given to genfsimg
Michael Brown [Fri, 22 Jan 2021 18:29:01 +0000 (18:29 +0000)] 
[build] Fail gracefully when no input files are given to genfsimg

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Use explicit disk geometry for generated FAT filesystem images
Michael Brown [Fri, 22 Jan 2021 12:22:11 +0000 (12:22 +0000)] 
[build] Use explicit disk geometry for generated FAT filesystem images

For FAT filesystem images larger than a 1.44MB floppy disk, round up
the image size to a whole number of 504kB cylinders before formatting.
This avoids losing up to a cylinder's worth of expected space in the
filesystem image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Fix genfsimg incompatibility with dash shell
Michael Brown [Fri, 22 Jan 2021 09:52:57 +0000 (09:52 +0000)] 
[build] Fix genfsimg incompatibility with dash shell

Reported-by: Antony Messerli <antony@mes.ser.li>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Set volume name "iPXE" on FAT filesystem images
Michael Brown [Thu, 21 Jan 2021 21:23:06 +0000 (21:23 +0000)] 
[build] Set volume name "iPXE" on FAT filesystem images

Allow generated filesystem images to be accessed using the file:// URI
syntax by setting a defined volume name.  This allows a script placed
on the same filesystem image to be accessed using e.g.

  chain file://iPXE/script.ipxe

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Allow genfsimg to be used on third party UEFI binaries
Michael Brown [Tue, 19 Jan 2021 23:47:44 +0000 (23:47 +0000)] 
[build] Allow genfsimg to be used on third party UEFI binaries

Extract the PE header offset from the MZ header rather than assuming a
fixed offset as used in the binaries created by the iPXE build system.

This allows genfsimg to be used to create bootable filesystem images
from third party UEFI binaries such as the UEFI shell.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[ipv6] Defer router discovery timeout while link is blocked
Michael Brown [Tue, 19 Jan 2021 14:15:56 +0000 (14:15 +0000)] 
[ipv6] Defer router discovery timeout while link is blocked

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dhcp] Allow for links that remained blocked for up to three minutes
Michael Brown [Tue, 19 Jan 2021 12:54:50 +0000 (12:54 +0000)] 
[dhcp] Allow for links that remained blocked for up to three minutes

With the default timeouts for Cisco MAC Authentication Bypass, the
link will remain blocked for around 90 seconds (plus a likely
subsequent delay for STP).

Extend the maximum number of DHCP discovery deferrals to allow for up
to three minutes of waiting for a link to become unblocked.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[eap] Treat an EAP Request-Identity as indicating a blocked link
Michael Brown [Tue, 19 Jan 2021 12:37:50 +0000 (12:37 +0000)] 
[eap] Treat an EAP Request-Identity as indicating a blocked link

A switch port using 802.1x authentication will send EAP
Request-Identity packets once the physical link is up, and will not be
forwarding packets until the port identity has been established.

We do not currently support 802.1x authentication.  However, a
reasonably common configuration involves using a preset list of
permitted MAC addresses, with the "authentication" taking place
between the switch and a RADIUS server.  In this configuration, the
end device does not need to perform any authentication step, but does
need to be prepared for the switch port to fail to forward packets for
a substantial time after physical link-up.  This exactly matches the
"blocked link" semantics already used when detecting a non-forwarding
switch port via LACP or STP.

Treat a received EAP Request-Identity as indicating a blocked link.
Unlike LACP or STP, there is no way to determine the expected time
until the next EAP packet and so we must choose a fixed timeout.

Erroneously assuming that the link is blocked is relatively harmless
since we will still attempt to transmit and receive data even over a
link that is marked as blocked, and so the net effect is merely to
prolong DHCP attempts.  In contrast, erroneously assuming that the
link is unblocked will potentially cause DHCP to time out and give up,
resulting in a failed boot.

The default EAP Request-Identity interval in Cisco switches (where
this is most likely to be encountered in practice) is 30 seconds, so
choose 45 seconds as a timeout that is likely to avoid gaps during
which we falsely assume that the link is unblocked.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[eapol] Replace EAPoL code
Michael Brown [Tue, 19 Jan 2021 12:34:10 +0000 (12:34 +0000)] 
[eapol] Replace EAPoL code

Replace the GPL2+-only EAPoL code (currently used only for WPA) with
new code licensed under GPL2+-or-UBDL.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dhcp] Continue transmitting DHCPDISCOVER while link is blocked
Michael Brown [Tue, 19 Jan 2021 12:21:28 +0000 (12:21 +0000)] 
[dhcp] Continue transmitting DHCPDISCOVER while link is blocked

Continue to transmit DHCPDISCOVER while waiting for a blocked link, in
order to support mechanisms such as Cisco MAC Authentication Bypass
that require repeated transmission attempts in order to trigger the
action that will result in the link becoming unblocked.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Include xorrisofs as a viable mkisofs equivalent
Omgalof [Sat, 16 Jan 2021 12:59:23 +0000 (09:59 -0300)] 
[build] Include xorrisofs as a viable mkisofs equivalent

Add support for xorrisofs, a GNU mkisofs equivalent that is available
in most distro repositories.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Inhibit spurious array bounds warning on some versions of gcc
Michael Brown [Fri, 15 Jan 2021 20:54:27 +0000 (20:54 +0000)] 
[build] Inhibit spurious array bounds warning on some versions of gcc

Some versions of gcc (observed with gcc 9.3.0 on NixOS Linux) produce
a spurious warning about an out-of-bounds array access for the
isa_extra_probe_addrs[] array.

Work around this compiler bug by redefining the array index as a
signed long, which seems to somehow avoid this spurious warning.

Debugged-by: Manuel Mendez <mmendez534@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[isa] Add missing #include <config/isa.h>
Manuel Mendez [Wed, 13 Jan 2021 20:58:59 +0000 (15:58 -0500)] 
[isa] Add missing #include <config/isa.h>

Signed-off-by: Manuel Mendez <mmendez534@gmail.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[build] Create util/genfsimg for building filesystem-based images 204/head
Michael Brown [Wed, 13 Jan 2021 11:50:26 +0000 (11:50 +0000)] 
[build] Create util/genfsimg for building filesystem-based images

Generalise util/geniso, util/gensdsk, and util/genefidsk to create a
single script util/genfsimg that can be used to build either FAT
filesystem images or ISO images.

Extend the functionality to allow for building multi-architecture UEFI
bootable ISO images and combined BIOS+UEFI images.

For example:

  ./util/genfsimg -o combined.iso \
      bin-x86_64-efi/ipxe.efi \
      bin-arm64-efi/ipxe.efi \
      bin/ipxe.lkrn

would generate a hybrid image that could be used as a CDROM (or hard
disk or USB key) on legacy BIOS, x86_64 UEFI, or ARM64 UEFI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[xhci] Avoid false positive Coverity warning
Michael Brown [Mon, 4 Jan 2021 09:37:59 +0000 (09:37 +0000)] 
[xhci] Avoid false positive Coverity warning

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Leave asynchronous USB endpoints open until device is removed
Michael Brown [Sun, 3 Jan 2021 19:12:41 +0000 (19:12 +0000)] 
[efi] Leave asynchronous USB endpoints open until device is removed

Some UEFI device drivers will react to an asynchronous USB transfer
failure by dubiously terminating the scheduled transfer from within
the completion handler.

We already have code from commit fbb776f ("[efi] Leave USB endpoint
descriptors in existence until device is removed") that avoids freeing
memory in this situation, in order to avoid use-after-free bugs.  This
is not sufficient to avoid potential problems, since with an xHCI
controller the act of closing the endpoint requires issuing a command
and awaiting completion via the event ring, which may in turn dispatch
further USB transfer completion events.

Avoid these problems by leaving the USB endpoint open (but with the
refill timer stopped) until the device is finally removed, as is
already done for control and bulk transfers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[xhci] Show meaningful error messages after command failures
Michael Brown [Sun, 3 Jan 2021 19:10:30 +0000 (19:10 +0000)] 
[xhci] Show meaningful error messages after command failures

Ensure that any command failure messages are followed up with an error
message indicating what the failed command was attempting to perform.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[xhci] Fail attempts to issue concurrent commands
Michael Brown [Sun, 3 Jan 2021 19:08:49 +0000 (19:08 +0000)] 
[xhci] Fail attempts to issue concurrent commands

The xHCI driver can handle only a single command TRB in progress at
any one time.  Immediately fail any attempts to issue concurrent
commands (which should not occur in normal operation).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Use segment and bus number to identify PCI root bridge I/O protocol v1.21.1
Michael Brown [Thu, 31 Dec 2020 20:41:49 +0000 (20:41 +0000)] 
[efi] Use segment and bus number to identify PCI root bridge I/O protocol

There may be multiple instances of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL for
a single PCI segment.  Use the bus number range descriptor from the
ACPI resource list to identify the correct protocol instance.

There is some discrepancy between the ACPI and UEFI specifications
regarding the interpretation of values within the ACPI resource list.

The ACPI specification defines the min/max field values to be within
the secondary (device-side) address space, and defines the offset
field value as "the offset that must be added to the address on the
secondary side to obtain the address on the primary side".

The UEFI specification states instead that the offset field value is
the "offset to apply to the starting address to convert it to a PCI
address", helpfully omitting to clarify whether "to apply" in this
context means "to add" or "to subtract".  The implication of the
wording is also that the "starting address" is not already a "PCI
address" and must therefore be a host-side address rather than the
ACPI-defined device-side address.

Code comments in the EDK2 codebase seem to support the latter
(non-ACPI) interpretation of these ACPI structures.  For example, in
the PciHostBridgeDxe driver there can be found the comment

  Macros to translate device address to host address and vice versa.
  According to UEFI 2.7, device address = host address + translation
  offset.

along with a pair of macros TO_HOST_ADDRESS() and TO_DEVICE_ADDRESS()
which similarly negate the sense of the "translation offset" from the
definition found in the ACPI specification.

The existing logic in efipci_ioremap() (based on a presumed-working
externally contributed patch) applies the non-ACPI interpretation: it
assumes that min/max field values are host-side addresses and that the
offset field value is negated.

Match this existing logic by assuming that min/max field values are
host-side bus numbers.  (The bus number offset value is therefore not
required and so can be ignored.)

As noted in commit 9b25f6e ("[efi] Fall back to assuming identity
mapping of MMIO address space"), some systems seem to fail to provide
MMIO address space descriptors.  Assume that some systems may
similarly fail to provide bus number range descriptors, and fall back
in this situation to assuming that matching on segment number alone is
sufficient.

Testing any of this is unfortunately impossible without access to
esoteric hardware that actually uses non-zero translation offsets.

Originally-implemented-by: Thomas Walker <twalker@twosigma.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[smbios] Add support for the 64-bit SMBIOS3 entry point
Michael Brown [Tue, 29 Dec 2020 14:37:54 +0000 (14:37 +0000)] 
[smbios] Add support for the 64-bit SMBIOS3 entry point

Support UEFI systems that provide only 64-bit versions of the SMBIOS
entry point.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Allow for longer device paths in debug messages
b1f6c1c4 [Sun, 27 Dec 2020 00:15:54 +0000 (19:15 -0500)] 
[efi] Allow for longer device paths in debug messages

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[sfc] Update email addresses
Martin Habets [Mon, 23 Nov 2020 08:07:13 +0000 (08:07 +0000)] 
[sfc] Update email addresses

Email from solarflare.com will stop working, so update those.  Remove
email for Shradha Shah, as she is not involved with this any more.
Update copyright notices for files touched.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[x509] Clarify debug message for an untrusted X.509 issuer
Josh McSavaney [Tue, 29 Sep 2020 02:23:16 +0000 (22:23 -0400)] 
[x509] Clarify debug message for an untrusted X.509 issuer

We surface this debugging information in cases where a cert actually
lacks an issuer, but also in cases where it *has* an issuer, but we
cannot trust it (e.g. due to issues in establishing a trust chain).

Signed-off-by: Josh McSavaney <me@mcsau.cc>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[golan] Add new PCI IDs
Mohammed Taha [Mon, 14 Dec 2020 14:48:23 +0000 (14:48 +0000)] 
[golan] Add new PCI IDs

Signed-off-by: Mohammed <mohammedt@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Allow EFI_USB_IO_PROTOCOL interfaces to be nullified and leaked
Michael Brown [Thu, 17 Dec 2020 21:46:52 +0000 (21:46 +0000)] 
[efi] Allow EFI_USB_IO_PROTOCOL interfaces to be nullified and leaked

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Skip interface uninstallation during shutdown
Michael Brown [Thu, 17 Dec 2020 20:37:27 +0000 (20:37 +0000)] 
[efi] Skip interface uninstallation during shutdown

iPXE seems to be almost alone in the UEFI world in attempting to shut
down cleanly, free resources, and leave hardware in a well-defined
reset state before handing over to the booted operating system.

The UEFI driver model does allow for graceful shutdown via
uninstallation of protocol interfaces.  However, virtually no other
UEFI drivers do this, and the external code paths that react to
uninstallation are consequently poorly tested.  This leads to a
proliferation of bugs found in UEFI implementations in the wild, as
described in commits such as 1295b4a ("[efi] Allow initialisation via
SNP interface even while claimed") or b6e2ea0 ("[efi] Veto the HP
XhciDxe Driver").

Try to avoid triggering such bugs by unconditionally skipping the
protocol interface uninstallation during UEFI boot services shutdown,
leaving the interfaces present but nullified and deliberately leaking
the containing memory.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Nullify interfaces unconditionally on error and shutdown paths
Michael Brown [Thu, 17 Dec 2020 19:48:08 +0000 (19:48 +0000)] 
[efi] Nullify interfaces unconditionally on error and shutdown paths

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[iphone] Add iPhone tethering driver
Michael Brown [Wed, 16 Dec 2020 13:29:06 +0000 (13:29 +0000)] 
[iphone] Add iPhone tethering driver

USB tethering via an iPhone is unreasonably complicated due to the
requirement to perform a pairing operation that involves establishing
a TLS session over a completely unrelated USB function that speaks a
protocol that is almost, but not quite, entirely unlike TCP.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[crypto] Allow private key to be specified as a TLS connection parameter
Michael Brown [Tue, 15 Dec 2020 16:11:34 +0000 (16:11 +0000)] 
[crypto] Allow private key to be specified as a TLS connection parameter

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[tls] Include root of trust within definition of TLS session
Michael Brown [Tue, 15 Dec 2020 16:28:33 +0000 (16:28 +0000)] 
[tls] Include root of trust within definition of TLS session

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[x509] Make root of trust a reference-counted structure
Michael Brown [Wed, 9 Dec 2020 16:19:03 +0000 (16:19 +0000)] 
[x509] Make root of trust a reference-counted structure

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Avoid using potentially uninitialised driver name in veto checks
Michael Brown [Tue, 8 Dec 2020 15:52:25 +0000 (15:52 +0000)] 
[efi] Avoid using potentially uninitialised driver name in veto checks

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[x509] Record root of trust used when validating a certificate
Michael Brown [Tue, 8 Dec 2020 14:58:46 +0000 (14:58 +0000)] 
[x509] Record root of trust used when validating a certificate

Record the root of trust used at the point that a certificate is
validated, redefine validation as checking a certificate against a
specific root of trust, and pass an explicit root of trust when
creating a TLS connection.

This allows a custom TLS connection to be used with a custom root of
trust, without causing any validated certificates to be treated as
valid for normal purposes.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[ocsp] Remove dummy OCSP certificate root
Michael Brown [Tue, 8 Dec 2020 14:39:33 +0000 (14:39 +0000)] 
[ocsp] Remove dummy OCSP certificate root

OCSP currently calls x509_validate() with an empty root certificate
list, on the basis that the OCSP signer certificate (if existent) must
be signed directly by the issuer certificate.

Using an empty root certificate list is not required to achieve this
goal, since x509_validate() already accepts an explicit issuer
certificate parameter.  The explicit empty root certificate list
merely prevents the signer certificate from being evaluated as a
potential trusted root certificate.

Remove the dummy OCSP root certificate list and use the default root
certificate list when calling x509_validate().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[http] Hide HTTP transport-layer filter implementation details
Michael Brown [Tue, 8 Dec 2020 14:55:44 +0000 (14:55 +0000)] 
[http] Hide HTTP transport-layer filter implementation details

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[asn1] Define ASN1_SHORT() for constructing short tagged values
Michael Brown [Tue, 8 Dec 2020 12:31:52 +0000 (12:31 +0000)] 
[asn1] Define ASN1_SHORT() for constructing short tagged values

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[asn1] Rename ASN1_OID_CURSOR to ASN1_CURSOR
Michael Brown [Tue, 8 Dec 2020 12:30:57 +0000 (12:30 +0000)] 
[asn1] Rename ASN1_OID_CURSOR to ASN1_CURSOR

There is nothing OID-specific about the ASN1_OID_CURSOR macro.  Rename
to allow it to be used for constructing ASN.1 cursors with arbitrary
contents.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[asn1] Add constant for UTF-8 string tag
Michael Brown [Mon, 7 Dec 2020 13:55:12 +0000 (13:55 +0000)] 
[asn1] Add constant for UTF-8 string tag

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[tls] Allow provision of a client certificate chain
Michael Brown [Fri, 4 Dec 2020 15:56:13 +0000 (15:56 +0000)] 
[tls] Allow provision of a client certificate chain

Use the existing certificate store to automatically append any
available issuing certificates to the selected client certificate.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[tls] Use intf_insert() to add TLS to an interface
Michael Brown [Mon, 7 Dec 2020 13:51:46 +0000 (13:51 +0000)] 
[tls] Use intf_insert() to add TLS to an interface

Restructure the use of add_tls() to insert a TLS filter onto an
existing interface.  This allows for the possibility of using
add_tls() to start TLS on an existing connection (as used in several
protocols which will negotiate the choice to use TLS before the
ClientHello is sent).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[interface] Provide intf_insert() to insert a filter interface
Michael Brown [Mon, 7 Dec 2020 13:49:47 +0000 (13:49 +0000)] 
[interface] Provide intf_insert() to insert a filter interface

Generalise the filter interface insertion logic from block_translate()
and expose as intf_insert(), allowing a filter interface to be
inserted on any existing interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[interface] Ignore any attempts to plug in the null interface
Michael Brown [Mon, 7 Dec 2020 13:48:35 +0000 (13:48 +0000)] 
[interface] Ignore any attempts to plug in the null interface

Allow intf_plug() and intf_plug_plug() to be called safely on
interfaces that may be the null interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Veto the HP XhciDxe Driver
Michael Brown [Mon, 30 Nov 2020 17:48:52 +0000 (17:48 +0000)] 
[efi] Veto the HP XhciDxe Driver

The HP XhciDxe driver (observed on an HP EliteBook 840 G6) does not
respond correctly to driver disconnection, and will leave the PciIo
protocol instance opened with BY_DRIVER attributes even after
returning successfully from its Stop() method.  This prevents iPXE
from subsequently connecting to the PCI device handle.

Veto this driver if the iPXE build includes a native xHCI driver.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Allow vetoing of drivers that cannot be unloaded
Michael Brown [Mon, 30 Nov 2020 17:08:58 +0000 (17:08 +0000)] 
[efi] Allow vetoing of drivers that cannot be unloaded

Some UEFI drivers (observed with the "Usb Xhci Driver" on an HP
EliteBook) are particularly badly behaved: they cannot be unloaded and
will leave handles opened with BY_DRIVER attributes even after
disconnecting the driver, thereby preventing a replacement iPXE driver
from opening the handle.

Allow such drivers to be vetoed by falling back to a brute-force
mechanism that will disconnect the driver from all handles, uninstall
the driver binding protocol (to prevent it from attaching to any new
handles), and finally close any stray handles that the vetoed driver
has left open.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Provide manufacturer and driver names to all veto checking methods
Michael Brown [Mon, 30 Nov 2020 17:05:09 +0000 (17:05 +0000)] 
[efi] Provide manufacturer and driver names to all veto checking methods

Most veto checks are likely to use the manufacturer name and driver
name, so pass these as parameters to minimise code duplication.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Split out dbg_efi_opener() as a standalone function
Michael Brown [Mon, 30 Nov 2020 16:34:32 +0000 (16:34 +0000)] 
[efi] Split out dbg_efi_opener() as a standalone function

Allow external code to dump the information for an opened protocol
information entry via DBG_EFI_OPENER() et al.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[xhci] Update driver to use DMA API
Michael Brown [Wed, 25 Nov 2020 11:24:41 +0000 (11:24 +0000)] 
[xhci] Update driver to use DMA API

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dma] Provide dma_umalloc() for allocating large DMA-coherent buffers
Michael Brown [Sun, 29 Nov 2020 10:55:14 +0000 (10:55 +0000)] 
[dma] Provide dma_umalloc() for allocating large DMA-coherent buffers

Some devices (e.g. xHCI USB host controllers) may require the use of
large areas of host memory for private use by the device.  These
allocations cannot be satisfied from iPXE's limited heap space, and so
are currently allocated using umalloc() which will allocate external
system memory (and alter the system memory map as needed).

Provide dma_umalloc() to provide such allocations as part of the DMA
API, since there is otherwise no way to guarantee that the allocated
regions are usable for coherent DMA.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Avoid requesting zero-length DMA mappings
Michael Brown [Sat, 28 Nov 2020 22:44:09 +0000 (22:44 +0000)] 
[efi] Avoid requesting zero-length DMA mappings

The UEFI specification does not prohibit zero-length DMA mappings.
However, there is a reasonable chance that at least one implementation
will treat it as an invalid parameter.  As a precaution, avoid calling
EFI_PCI_IO_PROTOCOL.Map() with a length of zero.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[netdevice] Fix misleading comment on netdev_rx()
Michael Brown [Sun, 29 Nov 2020 11:23:41 +0000 (11:23 +0000)] 
[netdevice] Fix misleading comment on netdev_rx()

Unlike netdev_rx_err(), there is no valid circumstance under which
netdev_rx() may be called with a null I/O buffer, since a call to
netdev_rx() represents the successful reception of a packet.  Fix the
code comment to reflect this.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[netdevice] Do not attempt to unmap a null I/O buffer
Michael Brown [Sun, 29 Nov 2020 11:21:20 +0000 (11:21 +0000)] 
[netdevice] Do not attempt to unmap a null I/O buffer

netdev_tx_err() may be called with a null I/O buffer (e.g. to record a
transmit error with no associated buffer).  Avoid a potential null
pointer dereference in the DMA unmapping code path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dma] Move I/O buffer DMA operations to iobuf.h
Michael Brown [Thu, 26 Nov 2020 12:25:02 +0000 (12:25 +0000)] 
[dma] Move I/O buffer DMA operations to iobuf.h

Include a potential DMA mapping within the definition of an I/O
buffer, and move all I/O buffer DMA mapping functions from dma.h to
iobuf.h.  This avoids the need for drivers to maintain a separate list
of DMA mappings for each I/O buffer that they may handle.

Network device drivers typically do not keep track of transmit I/O
buffers, since the network device core already maintains a transmit
queue.  Drivers will typically call netdev_tx_complete_next() to
complete a transmission without first obtaining the relevant I/O
buffer pointer (and will rely on the network device core automatically
cancelling any pending transmissions when the device is closed).

To allow this driver design approach to be retained, update the
netdev_tx_complete() family of functions to automatically perform the
DMA unmapping operation if required.  For symmetry, also update the
netdev_rx() family of functions to behave the same way.

As a further convenience for drivers, allow the network device core to
automatically perform DMA mapping on the transmit datapath before
calling the driver's transmit() method.  This avoids the need to
introduce a mapping error handling code path into the typically
error-free transmit methods.

With these changes, the modifications required to update a typical
network device driver to use the new DMA API are fairly minimal:

- Allocate and free descriptor rings and similar coherent structures
  using dma_alloc()/dma_free() rather than malloc_phys()/free_phys()

- Allocate and free receive buffers using alloc_rx_iob()/free_rx_iob()
  rather than alloc_iob()/free_iob()

- Calculate DMA addresses using dma() or iob_dma() rather than
  virt_to_bus()

- Set a 64-bit DMA mask if needed using dma_set_mask_64bit() and
  thereafter eliminate checks on DMA address ranges

- Either record the DMA device in netdev->dma, or call iob_map_tx() as
  part of the transmit() method

- Ensure that debug messages use virt_to_phys() when displaying
  "hardware" addresses

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dma] Record DMA device as part of DMA mapping if needed
Michael Brown [Fri, 27 Nov 2020 11:27:22 +0000 (11:27 +0000)] 
[dma] Record DMA device as part of DMA mapping if needed

Allow for dma_unmap() to be called by code other than the DMA device
driver itself.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[dma] Modify DMA API to simplify calculation of medial addresses
Michael Brown [Wed, 25 Nov 2020 15:52:00 +0000 (15:52 +0000)] 
[dma] Modify DMA API to simplify calculation of medial addresses

Redefine the value stored within a DMA mapping to be the offset
between physical addresses and DMA addresses within the mapped region.

Provide a dma() wrapper function to calculate the DMA address for any
pointer within a mapped region, thereby simplifying the use cases when
a device needs to be given addresses other than the region start
address.

On a platform using the "flat" DMA implementation the DMA offset for
any mapped region is always zero, with the result that dma_map() can
be optimised away completely and dma() reduces to a straightforward
call to virt_to_phys().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[intelxl] Configure DMA mask as 64-bit
Michael Brown [Tue, 24 Nov 2020 17:47:42 +0000 (17:47 +0000)] 
[intelxl] Configure DMA mask as 64-bit

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[intel] Configure DMA mask as 64-bit
Michael Brown [Tue, 24 Nov 2020 17:46:39 +0000 (17:46 +0000)] 
[intel] Configure DMA mask as 64-bit

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Report correct error when failing to unload a vetoed driver
Michael Brown [Tue, 24 Nov 2020 15:42:43 +0000 (15:42 +0000)] 
[efi] Report correct error when failing to unload a vetoed driver

Signed-off-by: Michael Brown <mcb30@ipxe.org>
4 years ago[efi] Allow initialisation via SNP interface even while claimed 170/head
Michael Brown [Mon, 23 Nov 2020 15:34:13 +0000 (15:34 +0000)] 
[efi] Allow initialisation via SNP interface even while claimed

iPXE will currently fail all SNP interface methods with EFI_NOT_READY
while the network devices are claimed for use by iPXE's own network
stack.

As of commit c70b3e0 ("[efi] Always enable recursion when calling
ConnectController()"), this exposes latent UEFI firmware bugs on some
systems at the point of calling ExitBootServices().

With recursion enabled, the MnpDxe driver will immediately attempt to
consume the SNP protocol instance provided by iPXE.  Since the network
devices are claimed by iPXE at this point, the calls by MnpDxe to
Start() and Initialize() will both fail with EFI_NOT_READY.

This unfortunately triggers a broken error-handling code path in the
Ip6Dxe driver.  Specifically: Ip6DriverBindingStart() will call
Ip6CreateService(), which will call Ip6ServiceConfigMnp(), which will
return an error.  The subsequent error handling code path in
Ip6CreateService() simply calls Ip6CleanService().  The code in
Ip6CleanService() will attempt to leave the all-nodes multicast group,
which will fail since the group was never joined.  This will result in
Ip6CleanService() returning an error and omitting most of the required
clean-up operations.  In particular, the MNP protocol instance will
remain opened with BY_DRIVER attributes even though the Ip6Dxe driver
start method has failed.

When ExitBootServices() is eventually called, iPXE will attempt to
uninstall the SNP protocol instance.  This results in the UEFI core
calling Ip6DriverBindingStop(), which will fail since there is no
EFI_IP6_SERVICE_BINDING_PROTOCOL instance installed on the handle.

A failure during a call to UninstallMultipleProtocolInterfaces() will
result in the UEFI core attempting to reinstall any successfully
uninstalled protocols.  This is an intrinsically unsafe operation, and
represents a fundamental design flaw in UEFI.  Failure code paths
cannot be required to themselves handle failures, since there is no
well-defined correct outcome of such a situation.

With a current build of OVMF, this results in some unexpected debug
messages occurring at the time that the loaded operating system calls
ExitBootServices().  With the UEFI firmware in Hyper-V, the result is
an immediate reboot.

Work around these UEFI design and implementation flaws by allowing the
calls to our EFI_SIMPLE_NETWORK_PROTOCOL instance's Start() and
Initialize() methods to return success even when the network devices
are claimed for exclusive use by iPXE.  This is sufficient to allow
MnpDxe to believe that it has successfully initialised the device, and
thereby avoids the problematic failure code paths in Ip6Dxe.

Debugged-by: Aaron Heusser <aaron_heusser@hotmail.com>
Debugged-by: Pico Mitchell <pico@randomapplications.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>