[block] Replace gPXE block-device API with an iPXE asynchronous interface

The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism.  Bring this old code up to
date, with the following benefits:

 o  Block device commands can be cancelled by the requestor.  The INT 13
    layer uses this to provide a global timeout on all INT 13 calls,
    with the result that an unexpected passive failure mode (such as
    an iSCSI target ACKing the request but never sending a response)
    will lead to a timeout that gets reported back to the INT 13 user,
    rather than simply freezing the system.

 o  INT 13,00 (reset drive) is now able to reset the underlying block
    device.  INT 13 users, such as DOS, that use INT 13,00 as a method
    for error recovery now have a chance of recovering.

 o  All block device commands are tagged, with a numerical tag that
    will show up in debugging output and in packet captures; this will
    allow easier interpretation of bug reports that include both
    sources of information.

 o  The extremely ugly hacks used to generate the boot firmware tables
    have been eradicated and replaced with a generic acpi_describe()
    method (exploiting the ability of iPXE interfaces to pass through
    methods to an underlying interface).  The ACPI tables are now
    built in a shared data block within .bss16, rather than each
    requiring dedicated space in .data16.

 o  The architecture-independent concept of a SAN device has been
    exposed to the iPXE core through the sanboot API, which provides
    calls to hook, unhook, boot, and describe SAN devices.  This
    allows for much more flexible usage patterns (such as hooking an
    empty SAN device and then running an OS installer via TFTP).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2010-09-03 16:11:51 +01:00
parent 46c7f99c66
commit 220495f8bf
47 changed files with 4904 additions and 3127 deletions

View File

@@ -1,3 +0,0 @@
#ifndef ELTORITO_PLATFORM
#define ELTORITO_PLATFORM ELTORITO_PLATFORM_X86
#endif /* ELTORITO_PLATFORM */

View File

@@ -0,0 +1,14 @@
#ifndef _BITS_SANBOOT_H
#define _BITS_SANBOOT_H
/** @file
*
* i386-specific sanboot API implementations
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/bios_sanboot.h>
#endif /* _BITS_SANBOOT_H */

View File

@@ -13,8 +13,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/list.h>
#include <realmode.h>
struct block_device;
/**
* @defgroup int13ops INT 13 operation codes
* @{
@@ -56,6 +54,8 @@ struct block_device;
#define INT13_STATUS_INVALID 0x01
/** Read error */
#define INT13_STATUS_READ_ERROR 0x04
/** Reset failed */
#define INT13_STATUS_RESET_FAILED 0x05
/** Write error */
#define INT13_STATUS_WRITE_ERROR 0xcc
@@ -64,57 +64,6 @@ struct block_device;
/** Block size for non-extended INT 13 calls */
#define INT13_BLKSIZE 512
/** An INT 13 emulated drive */
struct int13_drive {
/** List of all registered drives */
struct list_head list;
/** Underlying block device */
struct block_device *blockdev;
/** BIOS in-use drive number (0x80-0xff) */
unsigned int drive;
/** BIOS natural drive number (0x80-0xff)
*
* This is the drive number that would have been assigned by
* 'naturally' appending the drive to the end of the BIOS
* drive list.
*
* If the emulated drive replaces a preexisting drive, this is
* the drive number that the preexisting drive gets remapped
* to.
*/
unsigned int natural_drive;
/** Number of cylinders
*
* The cylinder number field in an INT 13 call is ten bits
* wide, giving a maximum of 1024 cylinders. Conventionally,
* when the 7.8GB limit of a CHS address is exceeded, it is
* the number of cylinders that is increased beyond the
* addressable limit.
*/
unsigned int cylinders;
/** Number of heads
*
* The head number field in an INT 13 call is eight bits wide,
* giving a maximum of 256 heads. However, apparently all
* versions of MS-DOS up to and including Win95 fail with 256
* heads, so the maximum encountered in practice is 255.
*/
unsigned int heads;
/** Number of sectors per track
*
* The sector number field in an INT 13 call is six bits wide,
* giving a maximum of 63 sectors, since sector numbering
* (unlike head and cylinder numbering) starts at 1, not 0.
*/
unsigned int sectors_per_track;
/** Status of last operation */
int last_status;
};
/** An INT 13 disk address packet */
struct int13_disk_address {
/** Size of the packet, in bytes */
@@ -147,7 +96,6 @@ struct int13_disk_parameters {
uint64_t sectors;
/** Bytes per sector */
uint16_t sector_size;
} __attribute__ (( packed ));
/**
@@ -285,8 +233,7 @@ struct master_boot_record {
uint16_t signature;
} __attribute__ (( packed ));
extern void register_int13_drive ( struct int13_drive *drive );
extern void unregister_int13_drive ( struct int13_drive *drive );
extern int int13_boot ( unsigned int drive );
/** Use natural BIOS drive number */
#define INT13_USE_NATURAL_DRIVE 0xff
#endif /* INT13_H */

View File

@@ -1,37 +0,0 @@
#ifndef _IPXE_ABFT_H
#define _IPXE_ABFT_H
/** @file
*
* AoE boot firmware table
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <ipxe/acpi.h>
#include <ipxe/if_ether.h>
/** AoE boot firmware table signature */
#define ABFT_SIG "aBFT"
/**
* AoE Boot Firmware Table (aBFT)
*/
struct abft_table {
/** ACPI header */
struct acpi_description_header acpi;
/** AoE shelf */
uint16_t shelf;
/** AoE slot */
uint8_t slot;
/** Reserved */
uint8_t reserved_a;
/** MAC address */
uint8_t mac[ETH_ALEN];
} __attribute__ (( packed ));
extern void abft_fill_data ( struct aoe_session *aoe );
#endif /* _IPXE_ABFT_H */

View File

@@ -0,0 +1,18 @@
#ifndef _IPXE_BIOS_SANBOOT_H
#define _IPXE_BIOS_SANBOOT_H
/** @file
*
* Standard PC-BIOS sanboot interface
*
*/
FILE_LICENCE ( GPL2_OR_LATER );
#ifdef SANBOOT_PCBIOS
#define SANBOOT_PREFIX_pcbios
#else
#define SANBOOT_PREFIX_pcbios __pcbios_
#endif
#endif /* _IPXE_BIOS_SANBOOT_H */

View File

@@ -1,302 +0,0 @@
#ifndef _IPXE_IBFT_H
#define _IPXE_IBFT_H
/*
* Copyright Fen Systems Ltd. 2007. Portions of this code are derived
* from IBM Corporation Sample Programs. Copyright IBM Corporation
* 2004, 2007. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
FILE_LICENCE ( BSD2 );
/** @file
*
* iSCSI boot firmware table
*
* The information in this file is derived from the document "iSCSI
* Boot Firmware Table (iBFT)" as published by IBM at
*
* ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
*
*/
#include <stdint.h>
#include <ipxe/acpi.h>
#include <ipxe/in.h>
/** iSCSI Boot Firmware Table signature */
#define IBFT_SIG "iBFT"
/** An offset from the start of the iBFT */
typedef uint16_t ibft_off_t;
/** Length of a string within the iBFT (excluding terminating NUL) */
typedef uint16_t ibft_size_t;
/** A string within the iBFT */
struct ibft_string {
/** Length of string */
ibft_size_t length;
/** Offset to string */
ibft_off_t offset;
} __attribute__ (( packed ));
/** An IP address within the iBFT */
struct ibft_ipaddr {
/** Reserved; must be zero */
uint16_t zeroes[5];
/** Must be 0xffff if IPv4 address is present, otherwise zero */
uint16_t ones;
/** The IPv4 address, or zero if not present */
struct in_addr in;
} __attribute__ (( packed ));
/**
* iBFT structure header
*
* This structure is common to several sections within the iBFT.
*/
struct ibft_header {
/** Structure ID
*
* This is an IBFT_STRUCTURE_ID_XXX constant
*/
uint8_t structure_id;
/** Version (always 1) */
uint8_t version;
/** Length, including this header */
uint16_t length;
/** Index
*
* This is the number of the NIC or Target, when applicable.
*/
uint8_t index;
/** Flags */
uint8_t flags;
} __attribute__ (( packed ));
/**
* iBFT Control structure
*
*/
struct ibft_control {
/** Common header */
struct ibft_header header;
/** Extensions */
uint16_t extensions;
/** Offset to Initiator structure */
ibft_off_t initiator;
/** Offset to NIC structure for NIC 0 */
ibft_off_t nic_0;
/** Offset to Target structure for target 0 */
ibft_off_t target_0;
/** Offset to NIC structure for NIC 1 */
ibft_off_t nic_1;
/** Offset to Target structure for target 1 */
ibft_off_t target_1;
} __attribute__ (( packed ));
/** Structure ID for Control section */
#define IBFT_STRUCTURE_ID_CONTROL 0x01
/** Attempt login only to specified target
*
* If this flag is not set, all targets will be logged in to.
*/
#define IBFT_FL_CONTROL_SINGLE_LOGIN_ONLY 0x01
/**
* iBFT Initiator structure
*
*/
struct ibft_initiator {
/** Common header */
struct ibft_header header;
/** iSNS server */
struct ibft_ipaddr isns_server;
/** SLP server */
struct ibft_ipaddr slp_server;
/** Primary and secondary Radius servers */
struct ibft_ipaddr radius[2];
/** Initiator name */
struct ibft_string initiator_name;
} __attribute__ (( packed ));
/** Structure ID for Initiator section */
#define IBFT_STRUCTURE_ID_INITIATOR 0x02
/** Initiator block valid */
#define IBFT_FL_INITIATOR_BLOCK_VALID 0x01
/** Initiator firmware boot selected */
#define IBFT_FL_INITIATOR_FIRMWARE_BOOT_SELECTED 0x02
/**
* iBFT NIC structure
*
*/
struct ibft_nic {
/** Common header */
struct ibft_header header;
/** IP address */
struct ibft_ipaddr ip_address;
/** Subnet mask
*
* This is the length of the subnet mask in bits (e.g. /24).
*/
uint8_t subnet_mask_prefix;
/** Origin */
uint8_t origin;
/** Default gateway */
struct ibft_ipaddr gateway;
/** Primary and secondary DNS servers */
struct ibft_ipaddr dns[2];
/** DHCP server */
struct ibft_ipaddr dhcp;
/** VLAN tag */
uint16_t vlan;
/** MAC address */
uint8_t mac_address[6];
/** PCI bus:dev:fn */
uint16_t pci_bus_dev_func;
/** Hostname */
struct ibft_string hostname;
} __attribute__ (( packed ));
/** Structure ID for NIC section */
#define IBFT_STRUCTURE_ID_NIC 0x03
/** NIC block valid */
#define IBFT_FL_NIC_BLOCK_VALID 0x01
/** NIC firmware boot selected */
#define IBFT_FL_NIC_FIRMWARE_BOOT_SELECTED 0x02
/** NIC global / link local */
#define IBFT_FL_NIC_GLOBAL 0x04
/**
* iBFT Target structure
*
*/
struct ibft_target {
/** Common header */
struct ibft_header header;
/** IP address */
struct ibft_ipaddr ip_address;
/** TCP port */
uint16_t socket;
/** Boot LUN */
uint64_t boot_lun;
/** CHAP type
*
* This is an IBFT_CHAP_XXX constant.
*/
uint8_t chap_type;
/** NIC association */
uint8_t nic_association;
/** Target name */
struct ibft_string target_name;
/** CHAP name */
struct ibft_string chap_name;
/** CHAP secret */
struct ibft_string chap_secret;
/** Reverse CHAP name */
struct ibft_string reverse_chap_name;
/** Reverse CHAP secret */
struct ibft_string reverse_chap_secret;
} __attribute__ (( packed ));
/** Structure ID for Target section */
#define IBFT_STRUCTURE_ID_TARGET 0x04
/** Target block valid */
#define IBFT_FL_TARGET_BLOCK_VALID 0x01
/** Target firmware boot selected */
#define IBFT_FL_TARGET_FIRMWARE_BOOT_SELECTED 0x02
/** Target use Radius CHAP */
#define IBFT_FL_TARGET_USE_CHAP 0x04
/** Target use Radius rCHAP */
#define IBFT_FL_TARGET_USE_RCHAP 0x08
/* Values for chap_type */
#define IBFT_CHAP_NONE 0 /**< No CHAP authentication */
#define IBFT_CHAP_ONE_WAY 1 /**< One-way CHAP */
#define IBFT_CHAP_MUTUAL 2 /**< Mutual CHAP */
/**
* iSCSI Boot Firmware Table (iBFT)
*/
struct ibft_table {
/** ACPI header */
struct acpi_description_header acpi;
/** Reserved */
uint8_t reserved[12];
/** Control structure */
struct ibft_control control;
} __attribute__ (( packed ));
/**
* iSCSI string block descriptor
*
* This is an internal structure that we use to keep track of the
* allocation of string data.
*/
struct ibft_string_block {
/** The iBFT containing these strings */
struct ibft_table *table;
/** Offset of first free byte within iBFT */
unsigned int offset;
};
/** Amount of space reserved for strings in a iPXE iBFT */
#define IBFT_STRINGS_SIZE 384
/**
* An iBFT created by iPXE
*
*/
struct ipxe_ibft {
/** The fixed section */
struct ibft_table table;
/** The Initiator section */
struct ibft_initiator initiator __attribute__ (( aligned ( 16 ) ));
/** The NIC section */
struct ibft_nic nic __attribute__ (( aligned ( 16 ) ));
/** The Target section */
struct ibft_target target __attribute__ (( aligned ( 16 ) ));
/** Strings block */
char strings[IBFT_STRINGS_SIZE];
} __attribute__ (( packed, aligned ( 16 ) ));
struct net_device;
struct iscsi_session;
extern int ibft_fill_data ( struct net_device *netdev,
struct iscsi_session *iscsi );
#endif /* _IPXE_IBFT_H */

View File

@@ -1,125 +0,0 @@
#ifndef _IPXE_SBFT_H
#define _IPXE_SBFT_H
/*
* Copyright (C) 2009 Fen Systems Ltd <mbrown@fensystems.co.uk>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
FILE_LICENCE ( BSD2 );
/** @file
*
* SRP boot firmware table
*
* The working draft specification for the SRP boot firmware table can
* be found at
*
* http://ipxe.org/wiki/srp/sbft
*
*/
#include <stdint.h>
#include <ipxe/acpi.h>
#include <ipxe/scsi.h>
#include <ipxe/srp.h>
#include <ipxe/ib_srp.h>
/** SRP Boot Firmware Table signature */
#define SBFT_SIG "sBFT"
/** An offset from the start of the sBFT */
typedef uint16_t sbft_off_t;
/**
* SRP Boot Firmware Table
*/
struct sbft_table {
/** ACPI header */
struct acpi_description_header acpi;
/** Offset to SCSI subtable */
sbft_off_t scsi_offset;
/** Offset to SRP subtable */
sbft_off_t srp_offset;
/** Offset to IB subtable, if present */
sbft_off_t ib_offset;
/** Reserved */
uint8_t reserved[6];
} __attribute__ (( packed ));
/**
* sBFT SCSI subtable
*/
struct sbft_scsi_subtable {
/** LUN */
struct scsi_lun lun;
} __attribute__ (( packed ));
/**
* sBFT SRP subtable
*/
struct sbft_srp_subtable {
/** Initiator and target ports */
struct srp_port_ids port_ids;
} __attribute__ (( packed ));
/**
* sBFT IB subtable
*/
struct sbft_ib_subtable {
/** Source GID */
struct ib_gid sgid;
/** Destination GID */
struct ib_gid dgid;
/** Service ID */
struct ib_gid_half service_id;
/** Partition key */
uint16_t pkey;
/** Reserved */
uint8_t reserved[6];
} __attribute__ (( packed ));
/**
* An sBFT created by iPXE
*/
struct ipxe_sbft {
/** The table header */
struct sbft_table table;
/** The SCSI subtable */
struct sbft_scsi_subtable scsi;
/** The SRP subtable */
struct sbft_srp_subtable srp;
/** The IB subtable */
struct sbft_ib_subtable ib;
} __attribute__ (( packed, aligned ( 16 ) ));
struct srp_device;
extern int sbft_fill_data ( struct srp_device *srp );
#endif /* _IPXE_SBFT_H */