iPXE
|
Amazon ENA network driver. More...
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/pcibridge.h>
#include <ipxe/version.h>
#include "ena.h"
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static const char * | ena_direction (unsigned int direction) |
Get direction name (for debugging) More... | |
static int | ena_reset_wait (struct ena_nic *ena, uint32_t expected) |
Wait for reset operation to be acknowledged. More... | |
static int | ena_reset (struct ena_nic *ena) |
Reset hardware. More... | |
static void | ena_set_base (struct ena_nic *ena, unsigned int offset, void *base) |
Set queue base address. More... | |
static void | ena_set_caps (struct ena_nic *ena, unsigned int offset, unsigned int count, size_t size) |
Set queue capabilities. More... | |
static void | ena_clear_caps (struct ena_nic *ena, unsigned int offset) |
Clear queue capabilities. More... | |
static int | ena_create_admin (struct ena_nic *ena) |
Create admin queues. More... | |
static void | ena_destroy_admin (struct ena_nic *ena) |
Destroy admin queues. More... | |
static union ena_aq_req * | ena_admin_req (struct ena_nic *ena) |
Get next available admin queue request. More... | |
static int | ena_admin (struct ena_nic *ena, union ena_aq_req *req, union ena_acq_rsp **rsp) |
Issue admin queue request. More... | |
static int | ena_set_aenq_config (struct ena_nic *ena, uint32_t enabled) |
Set async event notification queue config. More... | |
static int | ena_create_async (struct ena_nic *ena) |
Create async event notification queue. More... | |
static void | ena_destroy_async (struct ena_nic *ena) |
Destroy async event notification queue. More... | |
static int | ena_create_sq (struct ena_nic *ena, struct ena_sq *sq, struct ena_cq *cq) |
Create submission queue. More... | |
static int | ena_destroy_sq (struct ena_nic *ena, struct ena_sq *sq) |
Destroy submission queue. More... | |
static int | ena_create_cq (struct ena_nic *ena, struct ena_cq *cq) |
Create completion queue. More... | |
static int | ena_destroy_cq (struct ena_nic *ena, struct ena_cq *cq) |
Destroy completion queue. More... | |
static int | ena_create_qp (struct ena_nic *ena, struct ena_qp *qp) |
Create queue pair. More... | |
static int | ena_destroy_qp (struct ena_nic *ena, struct ena_qp *qp) |
Destroy queue pair. More... | |
static int | ena_get_device_attributes (struct net_device *netdev) |
Get device attributes. More... | |
static int | ena_set_host_attributes (struct ena_nic *ena) |
Set host attributes. More... | |
static int | ena_get_stats (struct ena_nic *ena) |
Get statistics (for debugging) More... | |
static void | ena_refill_rx (struct net_device *netdev) |
Refill receive queue. More... | |
static void | ena_empty_rx (struct ena_nic *ena) |
Discard unused receive I/O buffers. More... | |
static int | ena_open (struct net_device *netdev) |
Open network device. More... | |
static void | ena_close (struct net_device *netdev) |
Close network device. More... | |
static int | ena_transmit (struct net_device *netdev, struct io_buffer *iobuf) |
Transmit packet. More... | |
static void | ena_poll_tx (struct net_device *netdev) |
Poll for completed transmissions. More... | |
static void | ena_poll_rx (struct net_device *netdev) |
Poll for received packets. More... | |
static void | ena_poll (struct net_device *netdev) |
Poll for completed and received packets. More... | |
static int | ena_membase (struct ena_nic *ena, struct pci_device *pci) |
Assign memory BAR. More... | |
static int | ena_probe (struct pci_device *pci) |
Probe PCI device. More... | |
static void | ena_remove (struct pci_device *pci) |
Remove PCI device. More... | |
Variables | |
static struct net_device_operations | ena_operations |
ENA network device operations. More... | |
static struct pci_device_id | ena_nics [] |
ENA PCI device IDs. More... | |
struct pci_driver ena_driver | __pci_driver |
ENA PCI driver. More... | |
Amazon ENA network driver.
Definition in file ena.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Get direction name (for debugging)
direction | Direction |
name | Direction name |
Definition at line 54 of file ena.c.
References direction, ENA_SQ_RX, and ENA_SQ_TX.
Referenced by ena_create_sq(), and ena_destroy_sq().
Wait for reset operation to be acknowledged.
ena | ENA device |
expected | Expected reset state |
rc | Return status code |
Definition at line 77 of file ena.c.
References DBGC, ENA_RESET_MAX_WAIT_MS, ENA_STAT, ENA_STAT_RESET, ETIMEDOUT, mdelay(), readl(), and ena_nic::regs.
Referenced by ena_reset().
|
static |
Reset hardware.
ena | ENA device |
rc | Return status code |
Definition at line 104 of file ena.c.
References ENA_CTRL, ENA_CTRL_RESET, ena_reset_wait(), ENA_STAT_RESET, rc, ena_nic::regs, and writel().
Referenced by ena_probe(), and ena_remove().
|
inlinestatic |
Set queue base address.
ena | ENA device |
offset | Register offset |
address | Base address |
Definition at line 138 of file ena.c.
References base, ENA_BASE_HI, ENA_BASE_LO, offset, phys, ena_nic::regs, virt_to_bus(), and writel().
Referenced by ena_create_admin(), and ena_create_async().
|
inlinestatic |
Set queue capabilities.
ena | ENA device |
offset | Register offset |
count | Number of entries |
size | Size of each entry |
Definition at line 162 of file ena.c.
References count, ENA_CAPS, offset, ena_nic::regs, size, and writel().
Referenced by ena_create_admin(), and ena_create_async().
|
inlinestatic |
Clear queue capabilities.
ena | ENA device |
offset | Register offset |
Definition at line 176 of file ena.c.
References offset, ena_nic::regs, and writel().
Referenced by ena_create_admin(), ena_create_async(), ena_destroy_admin(), and ena_destroy_async().
|
static |
Create admin queues.
ena | ENA device |
rc | Return status code |
Definition at line 188 of file ena.c.
References ena_nic::acq, ena_nic::aq, DBGC, ENA_ACQ_BASE, ENA_ACQ_CAPS, ENA_ACQ_COUNT, ENA_AQ_BASE, ENA_AQ_CAPS, ENA_AQ_COUNT, ena_clear_caps(), ena_set_base(), ena_set_caps(), ENOMEM, free_phys(), malloc_phys(), memset(), rc, ena_aq::req, ena_acq::rsp, and virt_to_phys().
Referenced by ena_probe().
|
static |
Destroy admin queues.
ena | ENA device |
Definition at line 238 of file ena.c.
References ena_nic::acq, ena_nic::aq, DBGC, ENA_ACQ_CAPS, ENA_ACQ_COUNT, ENA_AQ_CAPS, ENA_AQ_COUNT, ena_clear_caps(), free_phys(), ena_aq::req, ena_acq::rsp, and wmb().
Referenced by ena_probe(), and ena_remove().
|
static |
Get next available admin queue request.
ena | ENA device |
req | Admin queue request |
Definition at line 259 of file ena.c.
References ena_nic::aq, ENA_AQ_COUNT, index, memset(), ena_aq::prod, and ena_aq::req.
Referenced by ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), ena_get_device_attributes(), ena_get_stats(), ena_set_aenq_config(), and ena_set_host_attributes().
|
static |
Issue admin queue request.
ena | ENA device |
req | Admin queue request |
rsp | Admin queue response to fill in |
rc | Return status code |
Definition at line 286 of file ena.c.
References ena_nic::acq, ena_nic::aq, ena_acq::cons, DBGC, DBGC2, DBGC2_HDA, DBGC_HDA, EILSEQ, EIO, ENA_ACQ_COUNT, ENA_ACQ_PHASE, ENA_ADMIN_MAX_WAIT_MS, ENA_AQ_DB, ENA_AQ_PHASE, ETIMEDOUT, ena_aq_header::flags, ena_aq_req::header, ena_aq_header::id, index, le16_to_cpu, mdelay(), ena_acq::phase, ena_aq::prod, rc, ena_nic::regs, rsp, ena_acq::rsp, virt_to_phys(), wmb(), and writel().
Referenced by ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), ena_get_device_attributes(), ena_get_stats(), ena_set_aenq_config(), and ena_set_host_attributes().
Set async event notification queue config.
ena | ENA device |
enabled | Bitmask of the groups to enable |
rc | Return status code |
Definition at line 360 of file ena.c.
References cpu_to_le32, ena_admin(), ena_admin_req(), ENA_AENQ_CONFIG, ENA_SET_FEATURE, enabled, feature, ena_set_feature_req::feature, ena_aq_req::header, ena_set_feature_req::id, ena_aq_header::opcode, rc, rsp, and ena_aq_req::set_feature.
Referenced by ena_create_async().
|
static |
Create async event notification queue.
ena | ENA device |
rc | Return status code |
Definition at line 386 of file ena.c.
References ena_nic::aenq, DBGC, ENA_AENQ_BASE, ENA_AENQ_CAPS, ENA_AENQ_COUNT, ena_clear_caps(), ena_set_aenq_config(), ena_set_base(), ena_set_caps(), ENOMEM, ena_aenq::evt, free_phys(), malloc_phys(), memset(), rc, and virt_to_phys().
Referenced by ena_probe().
|
static |
Destroy async event notification queue.
ena | ENA device |
Definition at line 425 of file ena.c.
References ena_nic::aenq, DBGC, ENA_AENQ_CAPS, ENA_AENQ_COUNT, ena_clear_caps(), ena_aenq::evt, free_phys(), and wmb().
Referenced by ena_probe(), and ena_remove().
Create submission queue.
ena | ENA device |
sq | Submission queue |
cq | Corresponding completion queue |
rc | Return status code |
Definition at line 445 of file ena.c.
References ena_cq::actual, ena_create_sq_req::address, ena_create_sq_req::count, ena_sq::count, cpu_to_le16, cpu_to_le64, ena_create_sq_req::cq_id, ena_aq_req::create_sq, DBGC, ena_create_sq_req::direction, ena_sq::direction, ena_sq::doorbell, ena_admin(), ena_admin_req(), ENA_ALIGN, ENA_CREATE_SQ, ena_direction(), ENA_SQ_CONTIGUOUS, ENA_SQ_HOST_MEMORY, ENA_SQE_PHASE, ENOMEM, ena_sq::fill, free_phys(), ena_aq_req::header, ena_sq::id, ena_cq::id, ena_sq::ids, le16_to_cpu, le32_to_cpu, ena_sq::len, malloc_phys(), ena_sq::max, memset(), ena_aq_header::opcode, ena_sq::phase, ena_create_sq_req::policy, ena_sq::prod, ena_sq::raw, rc, rsp, ena_sq::sqe, virt_to_bus(), and virt_to_phys().
Referenced by ena_create_qp().
Destroy submission queue.
ena | ENA device |
sq | Submission queue |
rc | Return status code |
Definition at line 511 of file ena.c.
References cpu_to_le16, DBGC, ena_aq_req::destroy_sq, ena_destroy_sq_req::direction, ena_sq::direction, ena_admin(), ena_admin_req(), ENA_DESTROY_SQ, ena_direction(), free_phys(), ena_aq_req::header, ena_destroy_sq_req::id, ena_sq::id, ena_sq::len, ena_aq_header::opcode, ena_sq::raw, rc, rsp, and ena_sq::sqe.
Referenced by ena_create_qp(), and ena_destroy_qp().
Create completion queue.
ena | ENA device |
cq | Completion queue |
rc | Return status code |
Definition at line 541 of file ena.c.
References ena_cq::actual, ena_create_cq_req::address, ena_cq::cons, ena_create_cq_req::count, cpu_to_le16, cpu_to_le32, cpu_to_le64, ena_cq::cqe, ena_aq_req::create_cq, DBGC, ena_cq::doorbell, ena_admin(), ena_admin_req(), ENA_ALIGN, ENA_CQE_PHASE, ENA_CREATE_CQ, ENA_MSIX_NONE, ENOMEM, free_phys(), ena_aq_req::header, ena_cq::id, le16_to_cpu, le32_to_cpu, ena_cq::len, malloc_phys(), ena_cq::mask, memset(), ena_aq_header::opcode, ena_cq::phase, ena_cq::raw, rc, ena_cq::requested, rsp, ena_create_cq_req::size, ena_cq::size, ena_create_cq_req::vector, virt_to_bus(), and virt_to_phys().
Referenced by ena_create_qp().
Destroy completion queue.
ena | ENA device |
cq | Completion queue |
rc | Return status code |
Definition at line 601 of file ena.c.
References cpu_to_le16, ena_cq::cqe, DBGC, ena_aq_req::destroy_cq, ena_admin(), ena_admin_req(), ENA_DESTROY_CQ, free_phys(), ena_aq_req::header, ena_destroy_cq_req::id, ena_cq::id, ena_cq::len, ena_aq_header::opcode, ena_cq::raw, rc, and rsp.
Referenced by ena_create_qp(), and ena_destroy_qp().
Create queue pair.
ena | ENA device |
qp | Queue pair |
rc | Return status code |
Definition at line 629 of file ena.c.
References ena_create_cq(), ena_create_sq(), ena_destroy_cq(), ena_destroy_sq(), qp, and rc.
Referenced by ena_open().
Destroy queue pair.
ena | ENA device |
qp | Queue pair |
rc | Return status code |
Definition at line 656 of file ena.c.
References ena_destroy_cq(), ena_destroy_sq(), and qp.
Referenced by ena_close(), and ena_open().
|
static |
Get device attributes.
netdev | Network device |
rc | Return status code |
Definition at line 673 of file ena.c.
References DBGC, ena_admin(), ena_admin_req(), ENA_DEVICE_ATTRIBUTES, ENA_GET_FEATURE, ETH_ALEN, ETH_HLEN, eth_ntoa(), feature, ena_aq_req::get_feature, ena_aq_req::header, net_device::hw_addr, ena_get_feature_req::id, le32_to_cpu, net_device::max_pkt_len, memcpy(), net_device::mtu, netdev, ena_aq_header::opcode, net_device::priv, rc, and rsp.
Referenced by ena_probe().
|
static |
Set host attributes.
ena | ENA device |
rc | Return status code |
Definition at line 706 of file ena.c.
References cpu_to_le64, ena_admin(), ena_admin_req(), ENA_HOST_ATTRIBUTES, ENA_SET_FEATURE, feature, ena_set_feature_req::feature, ena_aq_req::header, ena_set_feature_req::id, ena_nic::info, ena_aq_header::opcode, rc, rsp, ena_aq_req::set_feature, and virt_to_bus().
Referenced by ena_probe().
|
static |
Get statistics (for debugging)
ena | ENA device |
rc | Return status code |
Definition at line 732 of file ena.c.
References DBG_LOG, DBGC, ena_get_stats_req::device, ena_admin(), ena_admin_req(), ENA_DEVICE_MINE, ENA_GET_STATS, ENA_STATS_SCOPE_ETH, ENA_STATS_TYPE_BASIC, ena_aq_req::get_stats, ena_aq_req::header, le64_to_cpu, ena_aq_header::opcode, rc, rsp, ena_get_stats_rsp::rx_bytes, ena_get_stats_rsp::rx_drops, ena_get_stats_rsp::rx_packets, ena_get_stats_req::scope, ena_get_stats_rsp::tx_bytes, ena_get_stats_rsp::tx_packets, and ena_get_stats_req::type.
Referenced by ena_close().
|
static |
Refill receive queue.
netdev | Network device |
Definition at line 778 of file ena.c.
References address, ena_rx_sqe::address, alloc_iob(), assert(), ena_cq::cons, cpu_to_le16, cpu_to_le64, ena_qp::cq, io_buffer::data, DBGC2, ena_sq::doorbell, ENA_RX_COUNT, ENA_SQE_CPL, ENA_SQE_FIRST, ENA_SQE_LAST, ENA_SQE_PHASE, ena_sq::fill, ena_rx_sqe::flags, id, ena_rx_sqe::id, index, len, ena_rx_sqe::len, net_device::max_pkt_len, netdev, NULL, ena_sq::phase, net_device::priv, ena_sq::prod, ena_nic::regs, ena_sq::rx, ena_nic::rx, ena_nic::rx_ids, ena_nic::rx_iobuf, ena_qp::sq, ena_sq::sqe, virt_to_bus(), wmb(), and writel().
Referenced by ena_open(), and ena_poll().
|
static |
Discard unused receive I/O buffers.
ena | ENA device |
Definition at line 839 of file ena.c.
References ENA_RX_COUNT, free_iob(), NULL, and ena_nic::rx_iobuf.
Referenced by ena_close().
|
static |
Open network device.
netdev | Network device |
rc | Return status code |
Definition at line 855 of file ena.c.
References ena_create_qp(), ena_destroy_qp(), ena_refill_rx(), netdev, net_device::priv, rc, ena_nic::rx, and ena_nic::tx.
|
static |
Close network device.
netdev | Network device |
Definition at line 884 of file ena.c.
References ena_destroy_qp(), ena_empty_rx(), ena_get_stats(), netdev, net_device::priv, ena_nic::rx, and ena_nic::tx.
|
static |
Transmit packet.
netdev | Network device |
iobuf | I/O buffer |
rc | Return status code |
Definition at line 907 of file ena.c.
References address, ena_tx_sqe::address, assert(), ena_cq::cons, cpu_to_le16, cpu_to_le64, ena_qp::cq, io_buffer::data, DBGC, DBGC2, ena_sq::doorbell, ENA_SQE_CPL, ENA_SQE_FIRST, ENA_SQE_LAST, ENA_SQE_PHASE, ENA_TX_COUNT, ENOBUFS, ena_sq::fill, ena_tx_sqe::flags, id, ena_tx_sqe::id, index, iob_len(), len, ena_tx_sqe::len, netdev, NULL, ena_sq::phase, net_device::priv, ena_sq::prod, ena_nic::regs, ena_qp::sq, ena_sq::sqe, ena_sq::tx, ena_nic::tx, ena_nic::tx_ids, ena_nic::tx_iobuf, virt_to_bus(), wmb(), and writel().
|
static |
Poll for completed transmissions.
netdev | Network device |
Definition at line 958 of file ena.c.
References assert(), ena_cq::cons, ena_qp::cq, ena_cq::cqe, DBGC2, ENA_CQE_PHASE, ENA_TX_CQE_ID, ena_tx_cqe::flags, id, ena_tx_cqe::id, index, le16_to_cpu, ena_cq::mask, netdev, netdev_tx_complete(), NULL, ena_cq::phase, net_device::priv, ena_sq::prod, ena_qp::sq, ena_cq::tx, ena_nic::tx, ena_nic::tx_ids, and ena_nic::tx_iobuf.
Referenced by ena_poll().
|
static |
Poll for received packets.
netdev | Network device |
Definition at line 1001 of file ena.c.
References assert(), ena_cq::cons, ena_qp::cq, ena_cq::cqe, DBGC2, ENA_CQE_PHASE, ena_rx_cqe::flags, id, ena_rx_cqe::id, index, iob_put, le16_to_cpu, len, ena_rx_cqe::len, ena_cq::mask, netdev, netdev_rx(), NULL, ena_cq::phase, net_device::priv, ena_sq::prod, ena_cq::rx, ena_nic::rx, ena_nic::rx_ids, ena_nic::rx_iobuf, and ena_qp::sq.
Referenced by ena_poll().
|
static |
Poll for completed and received packets.
netdev | Network device |
Definition at line 1048 of file ena.c.
References ena_poll_rx(), ena_poll_tx(), ena_refill_rx(), and netdev.
|
static |
Assign memory BAR.
ena | ENA device |
pci | PCI device |
rc | Return status code |
Some BIOSes in AWS EC2 are observed to fail to assign a base address to the ENA device. The device is the only device behind its bridge, and the BIOS does assign a memory window to the bridge. We therefore place the device at the start of the memory window.
Definition at line 1087 of file ena.c.
References pci_device::busdevfn, DBGC, ENOTCONN, ENOTSUP, pci_bridge::membase, pci_device::membase, pci_bridge::pci, PCI_ARGS, PCI_BASE_ADDRESS_0, PCI_FMT, PCI_FUNC, PCI_SLOT, pci_write_config_dword(), and pcibridge_find().
Referenced by ena_probe().
|
static |
Probe PCI device.
pci | PCI device |
rc | Return status code |
Definition at line 1120 of file ena.c.
References ena_nic::acq, adjust_pci_device(), alloc_etherdev(), pci_device::busdevfn, cpu_to_le16, cpu_to_le32, ena_qp::cq, ena_cq::cqe, DBGC2, DBGC2_HDA, pci_device::dev, net_device::dev, ENA_ACQ_PHASE, ENA_BAR_SIZE, ena_create_admin(), ena_create_async(), ena_destroy_admin(), ena_destroy_async(), ena_get_device_attributes(), ENA_HOST_INFO_SPEC_2_0, ENA_HOST_INFO_TYPE_IPXE, ENA_HOST_INFO_VERSION_WTF, ena_membase(), ena_operations, ena_reset(), ENA_RX_COUNT, ENA_RX_FILL, ena_set_host_attributes(), ENA_SQ_RX, ENA_SQ_TX, ENA_TX_COUNT, ENODEV, ENOMEM, free_phys(), info, ena_nic::info, iounmap(), malloc_phys(), pci_device::membase, memset(), netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), PAGE_SIZE, pci_ioremap(), pci_set_drvdata(), ena_acq::phase, net_device::priv, product_name, product_short_name, product_version, rc, register_netdev(), ena_nic::regs, ena_sq::rx, ena_cq::rx, ena_nic::rx, ena_nic::rx_ids, snprintf(), ena_qp::sq, ena_sq::sqe, ena_sq::tx, ena_cq::tx, ena_nic::tx, ena_nic::tx_ids, unregister_netdev(), and virt_to_phys().
|
static |
Remove PCI device.
pci | PCI device |
Definition at line 1237 of file ena.c.
References ena_destroy_admin(), ena_destroy_async(), ena_reset(), free_phys(), ena_nic::info, iounmap(), netdev, netdev_nullify(), netdev_put(), PAGE_SIZE, pci_get_drvdata(), net_device::priv, ena_nic::regs, and unregister_netdev().
|
static |
ENA network device operations.
Definition at line 1061 of file ena.c.
Referenced by ena_probe().
|
static |
struct pci_driver ena_driver __pci_driver |
ENA PCI driver.