|
iPXE
|
Xen netfront driver. More...
#include <stdint.h>#include <stdlib.h>#include <errno.h>#include <ipxe/netdevice.h>#include <ipxe/ethernet.h>#include <ipxe/if_ether.h>#include <ipxe/malloc.h>#include <ipxe/base16.h>#include <ipxe/xen.h>#include <ipxe/xenstore.h>#include <ipxe/xenbus.h>#include <ipxe/xengrant.h>#include <ipxe/xenevent.h>#include "netfront.h"Go to the source code of this file.
Macros | |
| #define | EIO_NETIF_RSP_ERROR __einfo_error ( EINFO_EIO_NETIF_RSP_ERROR ) |
| #define | EINFO_EIO_NETIF_RSP_ERROR |
| #define | EIO_NETIF_RSP_DROPPED __einfo_error ( EINFO_EIO_NETIF_RSP_DROPPED ) |
| #define | EINFO_EIO_NETIF_RSP_DROPPED |
| #define | EIO_NETIF_RSP(status) |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| static | LIST_HEAD (netfront_devices) |
| List of netfront devices. More... | |
| static int | netfront_reset (struct netfront_nic *netfront) |
| Reset device. More... | |
| static int | netfront_read_mac (struct netfront_nic *netfront, void *hw_addr) |
| Fetch MAC address. More... | |
| static int | netfront_write_num (struct netfront_nic *netfront, const char *subkey, unsigned long num) |
| Write XenStore numeric value. More... | |
| static int | netfront_write_flag (struct netfront_nic *netfront, const char *subkey) |
| Write XenStore flag value. More... | |
| static int | netfront_rm (struct netfront_nic *netfront, const char *subkey) |
| Delete XenStore value. More... | |
| static int | netfront_create_event (struct netfront_nic *netfront) |
| Create event channel. More... | |
| static int | netfront_send_event (struct netfront_nic *netfront) |
| Send event. More... | |
| static void | netfront_destroy_event (struct netfront_nic *netfront) |
| Destroy event channel. More... | |
| static int | netfront_create_ring (struct netfront_nic *netfront, struct netfront_ring *ring) |
| Create descriptor ring. More... | |
| static int | netfront_push (struct netfront_nic *netfront, struct netfront_ring *ring, physaddr_t addr, struct io_buffer *iobuf, uint16_t *id, grant_ref_t *ref) |
| Add buffer to descriptor ring. More... | |
| static struct io_buffer * | netfront_pull (struct netfront_nic *netfront, struct netfront_ring *ring, unsigned int id) |
| Remove buffer from descriptor ring. More... | |
| static void | netfront_destroy_ring (struct netfront_nic *netfront, struct netfront_ring *ring, void(*discard)(struct io_buffer *)) |
| Destroy descriptor ring. More... | |
| static void | netfront_discard (struct netfront_nic *netfront) |
| Discard partially received I/O buffers. More... | |
| static void | netfront_refill_rx (struct net_device *netdev) |
| Refill receive descriptor ring. More... | |
| static int | netfront_open (struct net_device *netdev) |
| Open network device. More... | |
| static void | netfront_close (struct net_device *netdev) |
| Close network device. More... | |
| static int | netfront_transmit (struct net_device *netdev, struct io_buffer *iobuf) |
| Transmit packet. More... | |
| static void | netfront_poll_tx (struct net_device *netdev) |
| Poll for completed packets. More... | |
| static void | netfront_poll_rx (struct net_device *netdev) |
| Poll for received packets. More... | |
| static void | netfront_poll (struct net_device *netdev) |
| Poll for completed and received packets. More... | |
| static int | netfront_probe (struct xen_device *xendev) |
| Probe Xen device. More... | |
| static void | netfront_remove (struct xen_device *xendev) |
| Remove Xen device. More... | |
| static int | netfront_net_probe (struct net_device *netdev, void *priv __unused) |
| Inhibit emulated PCI devices. More... | |
Variables | |
| static struct net_device_operations | netfront_operations |
| Network device operations. More... | |
| struct xen_driver netfront_driver | __xen_driver |
| Xen netfront driver. More... | |
| struct net_driver netfront_net_driver | __net_driver |
| Emulated PCI device inhibitor driver. More... | |
Xen netfront driver.
Definition in file netfront.c.
| #define EIO_NETIF_RSP_ERROR __einfo_error ( EINFO_EIO_NETIF_RSP_ERROR ) |
Definition at line 48 of file netfront.c.
| #define EINFO_EIO_NETIF_RSP_ERROR |
Definition at line 50 of file netfront.c.
| #define EIO_NETIF_RSP_DROPPED __einfo_error ( EINFO_EIO_NETIF_RSP_DROPPED ) |
Definition at line 53 of file netfront.c.
| #define EINFO_EIO_NETIF_RSP_DROPPED |
Definition at line 55 of file netfront.c.
| #define EIO_NETIF_RSP | ( | status | ) |
Definition at line 58 of file netfront.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
List of netfront devices.
|
static |
Reset device.
| netfront | Netfront device |
| rc | Return status code |
Definition at line 78 of file netfront.c.
References DBGC, xen_device::key, rc, state, strerror(), xenbus_backend_state(), xenbus_backend_wait(), xenbus_set_state(), XenbusStateClosed, XenbusStateInitialising, XenbusStateInitWait, and netfront_nic::xendev.
Referenced by netfront_close(), netfront_open(), and netfront_probe().
|
static |
Fetch MAC address.
| netfront | Netfront device |
| hw_addr | Hardware address to fill in |
| rc | Return status code |
Definition at line 128 of file netfront.c.
References DBGC, DBGC2, ETH_ALEN, free, hex_decode(), xen_device::key, len, mac, NULL, rc, strerror(), xen_device::xen, netfront_nic::xendev, and xenstore_read().
Referenced by netfront_probe().
|
static |
Write XenStore numeric value.
| netfront | Netfront device |
| subkey | Subkey |
| num | Numeric value |
| rc | Return status code |
Definition at line 170 of file netfront.c.
References DBGC, xen_device::key, NULL, num, rc, strerror(), xen_device::xen, netfront_nic::xendev, and xenstore_write_num().
Referenced by netfront_create_event(), netfront_create_ring(), and netfront_write_flag().
|
static |
Write XenStore flag value.
| netfront | Netfront device |
| subkey | Subkey |
| num | Numeric value |
| rc | Return status code |
Definition at line 195 of file netfront.c.
References netfront_write_num().
Referenced by netfront_open().
|
static |
Delete XenStore value.
| netfront | Netfront device |
| subkey | Subkey |
| rc | Return status code |
Definition at line 208 of file netfront.c.
References DBGC, xen_device::key, NULL, rc, strerror(), xen_device::xen, netfront_nic::xendev, and xenstore_rm().
Referenced by netfront_close(), netfront_create_event(), netfront_create_ring(), netfront_destroy_event(), netfront_destroy_ring(), and netfront_open().
|
static |
Create event channel.
| netfront | Netfront device |
| rc | Return status code |
Definition at line 236 of file netfront.c.
References alloc_unbound, xen_device::backend_id, close, DBGC, evtchn_alloc_unbound::dom, DOMID_SELF, netfront_nic::event, EXEN, xen_device::key, netfront_rm(), netfront_write_num(), evtchn_alloc_unbound::port, evtchn_close::port, evtchn_send::port, rc, evtchn_alloc_unbound::remote_dom, strerror(), xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_open().
|
inlinestatic |
Send event.
| netfront | Netfront device |
| rc | Return status code |
Definition at line 279 of file netfront.c.
References DBGC, netfront_nic::event, EXEN, xen_device::key, rc, strerror(), xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_refill_rx(), and netfront_transmit().
|
static |
Destroy event channel.
| netfront | Netfront device |
Definition at line 301 of file netfront.c.
References close, netfront_nic::event, netfront_rm(), evtchn_close::port, evtchn_send::port, xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_close(), and netfront_open().
|
static |
Create descriptor ring.
| netfront | Netfront device |
| ring | Descriptor ring |
| rc | Return status code |
Definition at line 328 of file netfront.c.
References addr, assert(), xen_device::backend_id, netfront_ring::count, DBGC, ENOMEM, free_phys(), netfront_ring::id_cons, netfront_ring::id_prod, netfront_ring::ids, netfront_ring::iobufs, xen_device::key, malloc_phys(), netfront_rm(), netfront_write_num(), NULL, PAGE_SIZE, netfront_ring::raw, rc, netfront_ring::ref, netfront_ring::ref_key, netfront_ring::sring, strerror(), xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_open().
|
static |
Add buffer to descriptor ring.
| netfront | Netfront device |
| ring | Descriptor ring |
| addr | Physical address |
| iobuf | Associated I/O buffer, or NULL |
| id | Buffer ID to fill in |
| ref | Grant reference to fill in |
| rc | Return status code |
The caller is responsible for ensuring that there is space in the ring.
Definition at line 392 of file netfront.c.
References addr, assert(), xen_device::backend_id, netfront_ring::count, DBGC, netfront_ring::id_prod, netfront_ring::ids, netfront_ring::iobufs, xen_device::key, NULL, rc, ref, netfront_ring::refs, strerror(), xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_refill_rx(), and netfront_transmit().
|
static |
Remove buffer from descriptor ring.
| netfront | Netfront device |
| ring | Descriptor ring |
| id | Buffer ID |
| iobuf | Associated I/O buffer, if any |
Definition at line 439 of file netfront.c.
References assert(), netfront_ring::count, count, id, netfront_ring::id_cons, netfront_ring::ids, netfront_ring::iobufs, NULL, netfront_ring::refs, xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_destroy_ring(), netfront_poll_rx(), and netfront_poll_tx().
|
static |
Destroy descriptor ring.
| netfront | Netfront device |
| ring | Descriptor ring |
| discard | Method used to discard outstanding buffer, or NULL |
Definition at line 469 of file netfront.c.
References netfront_ring::count, free_phys(), id, netfront_ring::id_cons, netfront_ring::ids, netfront_pull(), netfront_rm(), NULL, PAGE_SIZE, netfront_ring::raw, netfront_ring::ref, netfront_ring::ref_key, netfront_ring::sring, xen_device::xen, and netfront_nic::xendev.
Referenced by netfront_close(), and netfront_open().
|
static |
Discard partially received I/O buffers.
| netfront | Netfront device |
Definition at line 501 of file netfront.c.
References free_iob(), io_buffer::list, list_del, list_for_each_entry_safe, netfront_nic::rx_partial, and tmp.
Referenced by netfront_close(), and netfront_poll_rx().
|
static |
Refill receive descriptor ring.
| netdev | Network device |
Definition at line 524 of file netfront.c.
References addr, alloc_iob(), io_buffer::data, DBGC2, iob_tailroom(), xen_device::key, netdev, netdev_rx_err(), netfront_push(), NETFRONT_RX_FILL, netfront_send_event(), PAGE_SIZE, net_device::priv, rc, request, RING_GET_REQUEST, RING_PUSH_REQUESTS_AND_CHECK_NOTIFY, netfront_nic::rx, netfront_nic::rx_fring, and netfront_nic::xendev.
Referenced by netfront_open(), and netfront_poll().
|
static |
Open network device.
| netdev | Network device |
| rc | Return status code |
Definition at line 578 of file netfront.c.
References assert(), netfront_ring::count, DBGC, FRONT_RING_INIT, xen_device::key, netdev, netdev_link_up(), netfront_create_event(), netfront_create_ring(), netfront_destroy_event(), netfront_destroy_ring(), netfront_refill_rx(), netfront_reset(), netfront_rm(), netfront_write_flag(), NULL, PAGE_SIZE, net_device::priv, rc, RING_SIZE, netfront_nic::rx, netfront_nic::rx_fring, SHARED_RING_INIT, strerror(), netfront_nic::tx, netfront_nic::tx_fring, xenbus_backend_wait(), xenbus_set_state(), XenbusStateConnected, and netfront_nic::xendev.
|
static |
Close network device.
| netdev | Network device |
Definition at line 674 of file netfront.c.
References DBGC, free_iob(), xen_device::key, netdev, netdev_link_down(), netdev_link_err(), netfront_destroy_event(), netfront_destroy_ring(), netfront_discard(), netfront_reset(), netfront_rm(), NULL, net_device::priv, rc, netfront_nic::rx, strerror(), netfront_nic::tx, and netfront_nic::xendev.
|
static |
Transmit packet.
| netdev | Network device |
| iobuf | I/O buffer |
| rc | Return status code |
Definition at line 727 of file netfront.c.
References addr, count, io_buffer::data, DBGC, DBGC2, ENOBUFS, iob_len(), xen_device::key, len, netdev, netfront_push(), netfront_send_event(), NETTXF_data_validated, NETTXF_more_data, NULL, offset, PAGE_SIZE, net_device::priv, rc, request, RING_GET_REQUEST, RING_PUSH_REQUESTS_AND_CHECK_NOTIFY, netfront_nic::tx, netfront_nic::tx_fring, and netfront_nic::xendev.
|
static |
Poll for completed packets.
| netdev | Network device |
Definition at line 804 of file netfront.c.
References DBGC2, EIO_NETIF_RSP, netif_tx_response::id, xen_device::key, netdev, netdev_tx_complete(), netdev_tx_complete_err(), netfront_pull(), NETIF_RSP_OKAY, net_device::priv, rc, RING_GET_RESPONSE, RING_HAS_UNCONSUMED_RESPONSES, status, netif_tx_response::status, strerror(), netfront_nic::tx, netfront_nic::tx_fring, and netfront_nic::xendev.
Referenced by netfront_poll().
|
static |
Poll for received packets.
| netdev | Network device |
Definition at line 842 of file netfront.c.
References io_buffer::data, DBGC2, EIO_NETIF_RSP, ENOMEM, netif_rx_response::flags, netif_rx_response::id, iob_concatenate(), iob_put, iob_reserve, xen_device::key, len, io_buffer::list, list_add_tail, netdev, netdev_rx(), netdev_rx_err(), netfront_discard(), netfront_pull(), NETRXF_more_data, NULL, netif_rx_response::offset, net_device::priv, rc, RING_GET_RESPONSE, RING_HAS_UNCONSUMED_RESPONSES, netfront_nic::rx, netfront_nic::rx_fring, netfront_nic::rx_partial, status, netif_rx_response::status, strerror(), and netfront_nic::xendev.
Referenced by netfront_poll().
|
static |
Poll for completed and received packets.
| netdev | Network device |
Definition at line 909 of file netfront.c.
References netdev, netfront_poll_rx(), netfront_poll_tx(), and netfront_refill_rx().
|
static |
Probe Xen device.
| xendev | Xen device |
| rc | Return status code |
Definition at line 942 of file netfront.c.
References alloc_etherdev(), xen_device::backend, xen_device::backend_id, DBGC, xen_device::dev, net_device::dev, ENOMEM, net_device::hw_addr, INIT_LIST_HEAD, xen_device::key, netfront_nic::list, list_add_tail, list_del, netdev, netfront_nic::netdev, netdev_init(), netdev_link_down(), netdev_nullify(), netdev_put(), NETFRONT_NUM_RX_DESC, NETFRONT_NUM_TX_DESC, netfront_operations, netfront_read_mac(), NETFRONT_REF_COUNT, NETFRONT_REF_RX_BASE, NETFRONT_REF_RX_RING, NETFRONT_REF_TX_BASE, NETFRONT_REF_TX_RING, netfront_reset(), net_device::priv, rc, netfront_nic::refs, register_netdev(), netfront_nic::rx, netfront_nic::rx_ids, netfront_nic::rx_iobufs, netfront_nic::rx_partial, strerror(), netfront_nic::tx, netfront_nic::tx_ids, netfront_nic::tx_iobufs, unregister_netdev(), xen_device::xen, xen_set_drvdata(), netfront_nic::xendev, xengrant_alloc(), and xengrant_free().
|
static |
Remove Xen device.
| xendev | Xen device |
Definition at line 1021 of file netfront.c.
References netfront_nic::list, list_del, netdev, netdev_nullify(), netdev_put(), NETFRONT_REF_COUNT, net_device::priv, netfront_nic::refs, unregister_netdev(), xen_device::xen, xen_get_drvdata(), and xengrant_free().
|
static |
Inhibit emulated PCI devices.
| netdev | Network device |
| priv | Private data |
| rc | Return status code |
Definition at line 1062 of file netfront.c.
References DBGC, net_device::dev, device::driver_name, EEXIST, ETH_ALEN, net_device::hw_addr, xen_device::key, netfront_nic::list, list_for_each_entry, ll_protocol::ll_addr_len, net_device::ll_protocol, memcmp(), device::name, netdev, netfront_nic::netdev, and netfront_nic::xendev.
|
static |
Network device operations.
Definition at line 922 of file netfront.c.
Referenced by netfront_probe().
| struct xen_driver netfront_driver __xen_driver |
Xen netfront driver.
Definition at line 1041 of file netfront.c.
| struct net_driver netfront_net_driver __net_driver |
Emulated PCI device inhibitor driver.
Definition at line 1083 of file netfront.c.
1.8.15