iPXE
|
SNP NIC driver. More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/vsprintf.h>
#include <ipxe/timer.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/efi_snp.h>
#include "snpnet.h"
Go to the source code of this file.
Data Structures | |
struct | snp_nic |
An SNP NIC. More... | |
Macros | |
#define | SNP_RX_QUOTA 4 |
Maximum number of received packets per poll. More... | |
#define | SNP_INITIALIZE_RETRY_MAX 10 |
Maximum initialisation retry count. More... | |
#define | SNP_INITIALIZE_RETRY_DELAY_MS 10 |
Delay between each initialisation retry. More... | |
#define | SNP_RX_PAD 8 |
Additional padding for receive buffers. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER) | |
static const char * | snpnet_mac_text (EFI_MAC_ADDRESS *mac, size_t len) |
Format SNP MAC address (for debugging) More... | |
static void | snpnet_dump_mode (struct net_device *netdev) |
Dump SNP mode information (for debugging) More... | |
static void | snpnet_check_link (struct net_device *netdev) |
Check link state. More... | |
static int | snpnet_transmit (struct net_device *netdev, struct io_buffer *iobuf) |
Transmit packet. More... | |
static void | snpnet_poll_tx (struct net_device *netdev) |
Poll for completed packets. More... | |
static void | snpnet_poll_rx (struct net_device *netdev) |
Poll for received packets. More... | |
static void | snpnet_poll (struct net_device *netdev) |
Poll for completed packets. More... | |
static int | snpnet_rx_filters (struct net_device *netdev) |
Set receive filters. More... | |
static int | snpnet_open (struct net_device *netdev) |
Open network device. More... | |
static void | snpnet_close (struct net_device *netdev) |
Close network device. More... | |
int | snpnet_supported (EFI_HANDLE device, EFI_GUID *protocol) |
Check to see if driver supports a device. More... | |
int | snpnet_start (struct efi_device *efidev) |
Attach driver to device. More... | |
void | snpnet_stop (struct efi_device *efidev) |
Detach driver from device. More... | |
Variables | |
static struct net_device_operations | snpnet_operations |
SNP network device operations. More... | |
SNP NIC driver.
Definition in file snpnet.c.
#define SNP_RX_QUOTA 4 |
#define SNP_INITIALIZE_RETRY_MAX 10 |
#define SNP_INITIALIZE_RETRY_DELAY_MS 10 |
#define SNP_RX_PAD 8 |
Additional padding for receive buffers.
Some SNP implementations seem to require additional space in the allocated receive buffers, otherwise full-length packets will be silently dropped.
The EDK2 MnpDxe driver happens to allocate an additional 8 bytes of padding (4 for a VLAN tag, 4 for the Ethernet frame checksum). Match this behaviour since drivers are very likely to have been tested against MnpDxe.
FILE_LICENCE | ( | GPL2_OR_LATER | ) |
|
static |
Format SNP MAC address (for debugging)
mac | MAC address |
len | Length of MAC address |
text | MAC address as text |
Definition at line 96 of file snpnet.c.
References len, mac, and ssnprintf().
Referenced by snpnet_dump_mode().
|
static |
Dump SNP mode information (for debugging)
netdev | Network device |
Definition at line 114 of file snpnet.c.
References EFI_SIMPLE_NETWORK_MODE::BroadcastAddress, EFI_SIMPLE_NETWORK_MODE::CurrentAddress, DBG_EXTRA, DBGC2, EFI_SIMPLE_NETWORK_MODE::HwAddressSize, EFI_SIMPLE_NETWORK_MODE::IfType, EFI_SIMPLE_NETWORK_MODE::MacAddressChangeable, EFI_SIMPLE_NETWORK_MODE::MaxMCastFilterCount, EFI_SIMPLE_NETWORK_MODE::MaxPacketSize, EFI_SIMPLE_NETWORK_MODE::MCastFilter, EFI_SIMPLE_NETWORK_MODE::MCastFilterCount, EFI_SIMPLE_NETWORK_MODE::MediaHeaderSize, EFI_SIMPLE_NETWORK_MODE::MediaPresent, EFI_SIMPLE_NETWORK_MODE::MediaPresentSupported, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, EFI_SIMPLE_NETWORK_MODE::MultipleTxSupported, net_device::name, netdev, EFI_SIMPLE_NETWORK_MODE::NvRamAccessSize, EFI_SIMPLE_NETWORK_MODE::NvRamSize, EFI_SIMPLE_NETWORK_MODE::PermanentAddress, net_device::priv, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterMask, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterSetting, snp_nic::snp, snpnet_mac_text(), and EFI_SIMPLE_NETWORK_MODE::State.
Referenced by snpnet_open().
|
static |
Check link state.
netdev | Network device |
Definition at line 153 of file snpnet.c.
References EFI_SIMPLE_NETWORK_MODE::MediaPresent, EFI_SIMPLE_NETWORK_MODE::MediaPresentSupported, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, netdev, netdev_link_down(), netdev_link_ok(), netdev_link_up(), net_device::priv, and snp_nic::snp.
Referenced by snpnet_poll(), and snpnet_start().
|
static |
Transmit packet.
netdev | Network device |
iobuf | I/O buffer |
rc | Return status code |
Definition at line 176 of file snpnet.c.
References io_buffer::data, DBGC, ECANCELED, EEFI, efi_shutdown_in_progress, ETH_ZLEN, iob_len(), iob_pad(), net_device::name, netdev, netdev_tx_defer(), NULL, net_device::priv, rc, snp_nic::snp, strerror(), and _EFI_SIMPLE_NETWORK_PROTOCOL::Transmit.
|
static |
Poll for completed packets.
netdev | Network device |
Definition at line 217 of file snpnet.c.
References DBGC, EEFI, EPIPE, _EFI_SIMPLE_NETWORK_PROTOCOL::GetStatus, net_device::name, netdev, netdev_rx_err(), netdev_tx_complete(), netdev_tx_err(), NULL, net_device::priv, rc, snp_nic::snp, strerror(), snp_nic::txbuf, and VOID.
Referenced by snpnet_poll().
|
static |
Poll for received packets.
netdev | Network device |
Definition at line 258 of file snpnet.c.
References alloc_iob(), DBGC, EEFI, EFI_NOT_READY, iob_put, iob_tailroom(), len, net_device::name, netdev, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Receive, snp_nic::snp, SNP_RX_PAD, SNP_RX_QUOTA, and strerror().
Referenced by snpnet_poll().
|
static |
Poll for completed packets.
netdev | Network device |
Definition at line 309 of file snpnet.c.
References efi_shutdown_in_progress, netdev, snpnet_check_link(), snpnet_poll_rx(), and snpnet_poll_tx().
|
static |
Set receive filters.
netdev | Network device |
rc | Return status code |
Definition at line 331 of file snpnet.c.
References DBGC, EEFI, EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST, EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST, EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST, EFI_SIMPLE_NETWORK_RECEIVE_UNICAST, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, NULL, net_device::priv, rc, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterMask, _EFI_SIMPLE_NETWORK_PROTOCOL::ReceiveFilters, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterSetting, snp_nic::snp, strerror(), and TRUE.
Referenced by snpnet_open().
|
static |
Open network device.
netdev | Network device |
rc | Return status code |
Definition at line 371 of file snpnet.c.
References DBGC, EEFI, FALSE, _EFI_SIMPLE_NETWORK_PROTOCOL::Initialize, net_device::ll_addr, mac, mdelay(), EFI_SIMPLE_NETWORK_MODE::MediaPresent, EFI_SIMPLE_NETWORK_MODE::MediaPresentSupported, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, SNP_INITIALIZE_RETRY_DELAY_MS, SNP_INITIALIZE_RETRY_MAX, snpnet_dump_mode(), snpnet_rx_filters(), _EFI_SIMPLE_NETWORK_PROTOCOL::StationAddress, and strerror().
|
static |
Close network device.
netdev | Network device |
Definition at line 453 of file snpnet.c.
References DBGC, ECANCELED, EEFI, efi_shutdown_in_progress, free_iob(), net_device::name, netdev, netdev_tx_complete_err(), NULL, net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, and strerror().
int snpnet_supported | ( | EFI_HANDLE | device, |
EFI_GUID * | protocol | ||
) |
Check to see if driver supports a device.
device | EFI device handle |
protocol | Protocol GUID |
rc | Return status code |
Definition at line 495 of file snpnet.c.
References EFI_SYSTEM_TABLE::BootServices, DBGC, DBGC2, DBGCP, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, efi_locate_device(), EFI_OPEN_PROTOCOL_TEST_PROTOCOL, efi_systab, ENOTTY, find_snpdev(), NULL, EFI_BOOT_SERVICES::OpenProtocol, protocol, and rc.
Referenced by mnp_supported(), nii_supported(), and snp_supported().
int snpnet_start | ( | struct efi_device * | efidev | ) |
Attach driver to device.
efidev | EFI device |
rc | Return status code |
Definition at line 541 of file snpnet.c.
References alloc_etherdev(), EFI_SYSTEM_TABLE::BootServices, device::children, EFI_BOOT_SERVICES::CloseProtocol, EFI_SIMPLE_NETWORK_MODE::CurrentAddress, DBGC, DBGC_EFI_OPENERS, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_device_info(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_BY_DRIVER, EFI_OPEN_PROTOCOL_EXCLUSIVE, efi_simple_network_protocol_guid, efi_systab, snp_nic::efidev, efidev_set_drvdata(), EfiSimpleNetworkInitialized, EfiSimpleNetworkStopped, ENOMEM, ENOTSUP, net_device::hw_addr, ll_protocol::hw_addr_len, EFI_SIMPLE_NETWORK_MODE::HwAddressSize, INIT_LIST_HEAD, list_add, list_del, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, EFI_SIMPLE_NETWORK_MODE::MaxPacketSize, EFI_SIMPLE_NETWORK_MODE::MediaHeaderSize, EFI_SIMPLE_NETWORK_MODE::MediaPresentSupported, memcpy(), _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), EFI_BOOT_SERVICES::OpenProtocol, EFI_SIMPLE_NETWORK_MODE::PermanentAddress, net_device::priv, rc, register_netdev(), _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, snpnet_check_link(), snpnet_operations, _EFI_SIMPLE_NETWORK_PROTOCOL::Start, EFI_SIMPLE_NETWORK_MODE::State, strerror(), and unregister_netdev().
void snpnet_stop | ( | struct efi_device * | efidev | ) |
Detach driver from device.
efidev | EFI device |
Definition at line 658 of file snpnet.c.
References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, efi_device::device, EEFI, efi_handle_name(), efi_image_handle, efi_shutdown_in_progress, efi_simple_network_protocol_guid, efi_systab, snp_nic::efidev, efidev_get_drvdata(), list_del, netdev, netdev_nullify(), netdev_put(), net_device::priv, rc, snp_nic::snp, _EFI_SIMPLE_NETWORK_PROTOCOL::Stop, strerror(), and unregister_netdev().
|
static |
SNP network device operations.
Definition at line 481 of file snpnet.c.
Referenced by snpnet_start().