FreeBSD kernel /amd64 XEN device code
netback.c File Reference

Device driver supporting the vending of network access from this FreeBSD domain to other domains. More...

#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/rman.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#include <netinet/tcp.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <machine/in_cksum.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <machine/_inttypes.h>
#include <xen/xen-os.h>
#include <xen/hypervisor.h>
#include <xen/xen_intr.h>
#include <contrib/xen/io/netif.h>
#include <xen/xenbus/xenbusvar.h>
#include "netback_unit_tests.c"
Include dependency graph for netback.c:

Go to the source code of this file.

Data Structures

struct  xnb_pkt
 
struct  xnb_ring_config
 Configuration data for a shared memory request ring used to communicate with the front-end client of this this driver. More...
 
struct  xnb_softc
 

Macros

#define XNB_SG   1 /* netback driver supports feature-sg */
 
#define XNB_GSO_TCPV4   0 /* netback driver supports feature-gso-tcpv4 */
 
#define XNB_RX_COPY   1 /* netback driver supports feature-rx-copy */
 
#define XNB_RX_FLIP   0 /* netback driver does not support feature-rx-flip */
 
#define XNB_DEBUG   /* hardcode on during development */
 
#define DPRINTF(fmt, args...)    printf("xnb(%s:%d): " fmt, __FUNCTION__, __LINE__, ##args)
 
#define GNTTAB_LEN   (64)
 
#define XNB_CSUM_FEATURES   (CSUM_TCP | CSUM_UDP)
 
#define NET_TX_RING_SIZE   __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
 
#define NET_RX_RING_SIZE   __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
 
#define RING_HAS_UNCONSUMED_REQUESTS_2(_r, cons)
 
#define virt_to_mfn(x)   (vtophys(x) >> PAGE_SHIFT)
 
#define virt_to_offset(x)   ((x) & (PAGE_SIZE - 1))
 

Typedefs

typedef struct gnttab_copy gnttab_copy_table[GNTTAB_LEN]
 

Enumerations

enum  xnb_flag_t { XNBF_RING_CONNECTED = 0x01 , XNBF_RESOURCE_SHORTAGE = 0x02 , XNBF_SHUTDOWN = 0x04 , XNBF_IN_SHUTDOWN = 0x08 }
 
enum  xnb_ring_type_t { XNB_RING_TYPE_TX = 0 , XNB_RING_TYPE_RX = 1 , XNB_NUM_RING_TYPES }
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_XENNETBACK, "xnb", "Xen Net Back Driver Data")
 
static void xnb_attach_failed (struct xnb_softc *xnb, int err, const char *fmt,...) __printflike(3
 
static void static int xnb_shutdown (struct xnb_softc *xnb)
 
static int create_netdev (device_t dev)
 
static int xnb_detach (device_t dev)
 
static int xnb_ifmedia_upd (struct ifnet *ifp)
 
static void xnb_ifmedia_sts (struct ifnet *ifp, struct ifmediareq *ifmr)
 
static void xnb_intr (void *arg)
 
static int xnb_send (netif_rx_back_ring_t *rxb, domid_t otherend, const struct mbuf *mbufc, gnttab_copy_table gnttab)
 
static int xnb_recv (netif_tx_back_ring_t *txb, domid_t otherend, struct mbuf **mbufc, struct ifnet *ifnet, gnttab_copy_table gnttab)
 
static int xnb_ring2pkt (struct xnb_pkt *pkt, const netif_tx_back_ring_t *tx_ring, RING_IDX start)
 
static void xnb_txpkt2rsp (const struct xnb_pkt *pkt, netif_tx_back_ring_t *ring, int error)
 
static struct mbuf * xnb_pkt2mbufc (const struct xnb_pkt *pkt, struct ifnet *ifp)
 
static int xnb_txpkt2gnttab (const struct xnb_pkt *pkt, struct mbuf *mbufc, gnttab_copy_table gnttab, const netif_tx_back_ring_t *txb, domid_t otherend_id)
 
static void xnb_update_mbufc (struct mbuf *mbufc, const gnttab_copy_table gnttab, int n_entries)
 
static int xnb_mbufc2pkt (const struct mbuf *mbufc, struct xnb_pkt *pkt, RING_IDX start, int space)
 
static int xnb_rxpkt2gnttab (const struct xnb_pkt *pkt, const struct mbuf *mbufc, gnttab_copy_table gnttab, const netif_rx_back_ring_t *rxb, domid_t otherend_id)
 
static int xnb_rxpkt2rsp (const struct xnb_pkt *pkt, const gnttab_copy_table gnttab, int n_entries, netif_rx_back_ring_t *ring)
 
static void xnb_stop (struct xnb_softc *)
 
static int xnb_ioctl (struct ifnet *, u_long, caddr_t)
 
static void xnb_start_locked (struct ifnet *)
 
static void xnb_start (struct ifnet *)
 
static void xnb_ifinit_locked (struct xnb_softc *)
 
static void xnb_ifinit (void *)
 
static int xnb_unit_test_main (SYSCTL_HANDLER_ARGS)
 
static int xnb_dump_rings (SYSCTL_HANDLER_ARGS)
 
static void xnb_pkt_initialize (struct xnb_pkt *pxnb)
 
static void xnb_pkt_validate (struct xnb_pkt *pxnb)
 
static void xnb_pkt_invalidate (struct xnb_pkt *pxnb)
 
static int xnb_pkt_is_valid (const struct xnb_pkt *pxnb)
 
static void __unused xnb_dump_pkt (const struct xnb_pkt *pkt)
 
static void xnb_dump_txreq (RING_IDX idx, const struct netif_tx_request *txreq)
 
static void __unused xnb_dump_gnttab_copy (const struct gnttab_copy *entry)
 
static void __unused xnb_dump_mbuf (const struct mbuf *m)
 
static void xnb_free_communication_mem (struct xnb_softc *xnb)
 
static int xnb_disconnect (struct xnb_softc *xnb)
 
static int xnb_connect_ring (struct xnb_softc *xnb, xnb_ring_type_t ring_type)
 
static int xnb_connect_comms (struct xnb_softc *xnb)
 
static int xnb_alloc_communication_mem (struct xnb_softc *xnb)
 
static int xnb_collect_xenstore_info (struct xnb_softc *xnb)
 
static int xnb_publish_backend_info (struct xnb_softc *xnb)
 
static void xnb_connect (struct xnb_softc *xnb)
 
static int xnb_probe (device_t dev)
 
static void xnb_setup_sysctl (struct xnb_softc *xnb)
 
static int xnb_attach (device_t dev)
 
static int xnb_suspend (device_t dev)
 
static int xnb_resume (device_t dev)
 
static void xnb_frontend_changed (device_t dev, XenbusState frontend_state)
 
 DRIVER_MODULE (xnb, xenbusb_back, xnb_driver, xnb_devclass, 0, 0)
 

Variables

static device_method_t xnb_methods []
 
static driver_t xnb_driver
 
devclass_t xnb_devclass
 

Detailed Description

Device driver supporting the vending of network access from this FreeBSD domain to other domains.

Definition in file netback.c.

Macro Definition Documentation

◆ DPRINTF

#define DPRINTF (   fmt,
  args... 
)     printf("xnb(%s:%d): " fmt, __FUNCTION__, __LINE__, ##args)

Definition at line 105 of file netback.c.

◆ GNTTAB_LEN

#define GNTTAB_LEN   (64)

Definition at line 112 of file netback.c.

◆ NET_RX_RING_SIZE

#define NET_RX_RING_SIZE   __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)

Definition at line 118 of file netback.c.

◆ NET_TX_RING_SIZE

#define NET_TX_RING_SIZE   __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)

Definition at line 117 of file netback.c.

◆ RING_HAS_UNCONSUMED_REQUESTS_2

#define RING_HAS_UNCONSUMED_REQUESTS_2 (   _r,
  cons 
)
Value:
({ \
unsigned int req = (_r)->sring->req_prod - cons; \
unsigned int rsp = RING_SIZE(_r) - \
(cons - (_r)->rsp_prod_pvt); \
req < rsp ? req : rsp; \
})

Two argument version of the standard macro. Second argument is a tentative value of req_cons

Definition at line 124 of file netback.c.

◆ virt_to_mfn

#define virt_to_mfn (   x)    (vtophys(x) >> PAGE_SHIFT)

Definition at line 131 of file netback.c.

◆ virt_to_offset

#define virt_to_offset (   x)    ((x) & (PAGE_SIZE - 1))

Definition at line 132 of file netback.c.

◆ XNB_CSUM_FEATURES

#define XNB_CSUM_FEATURES   (CSUM_TCP | CSUM_UDP)

Definition at line 115 of file netback.c.

◆ XNB_DEBUG

#define XNB_DEBUG   /* hardcode on during development */

Definition at line 102 of file netback.c.

◆ XNB_GSO_TCPV4

#define XNB_GSO_TCPV4   0 /* netback driver supports feature-gso-tcpv4 */

Definition at line 97 of file netback.c.

◆ XNB_RX_COPY

#define XNB_RX_COPY   1 /* netback driver supports feature-rx-copy */

Definition at line 98 of file netback.c.

◆ XNB_RX_FLIP

#define XNB_RX_FLIP   0 /* netback driver does not support feature-rx-flip */

Definition at line 99 of file netback.c.

◆ XNB_SG

#define XNB_SG   1 /* netback driver supports feature-sg */

Definition at line 96 of file netback.c.

Typedef Documentation

◆ gnttab_copy_table

typedef struct gnttab_copy gnttab_copy_table[GNTTAB_LEN]

Predefined array type of grant table copy descriptors. Used to pass around statically allocated memory structures.

Definition at line 138 of file netback.c.

Enumeration Type Documentation

◆ xnb_flag_t

enum xnb_flag_t

Per-instance connection state flags.

Enumerator
XNBF_RING_CONNECTED 

Communication with the front-end has been established.

XNBF_RESOURCE_SHORTAGE 

Front-end requests exist in the ring and are waiting for xnb_xen_req objects to free up.

XNBF_SHUTDOWN 

Connection teardown has started.

XNBF_IN_SHUTDOWN 

A thread is already performing shutdown processing.

Definition at line 358 of file netback.c.

◆ xnb_ring_type_t

Types of rings. Used for array indices and to identify a ring's control data structure type

Enumerator
XNB_RING_TYPE_TX 
XNB_RING_TYPE_RX 
XNB_NUM_RING_TYPES 

Definition at line 380 of file netback.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ create_netdev()

int create_netdev ( device_t  dev)
static

Create a network device.

Parameters
handledevice handle

Definition at line 1181 of file netback.c.

References xnb_softc::carrier, xnb_softc::dev, xnb_softc::handle, xnb_softc::if_name, ifp, xnb_softc::mac, NET_RX_RING_SIZE, xnb_softc::rx_lock, xnb_softc::sc_lock, xnb_softc::sc_media, xnb_softc::tx_lock, XNB_CSUM_FEATURES, xnb_ifinit(), xnb_ifmedia_sts(), xnb_ifmedia_upd(), xnb_softc::xnb_ifp, xnb_ioctl(), xnb_start(), and xs_scanf().

Referenced by xnb_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DRIVER_MODULE()

DRIVER_MODULE ( xnb  ,
xenbusb_back  ,
xnb_driver  ,
xnb_devclass  ,
,
 
)

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_XENNETBACK  ,
"xnb"  ,
"Xen Net Back Driver Data"   
)
static

Custom malloc type for all driver allocations.

◆ xnb_alloc_communication_mem()

static int xnb_alloc_communication_mem ( struct xnb_softc xnb)
static

Size KVA and pseudo-physical address allocations based on negotiated values for the size and number of I/O requests, and the size of our communication ring.

Parameters
xnbPer-instance xnb configuration structure.

These address spaces are used to dynamically map pages in the front-end's domain into our own.

Definition at line 803 of file netback.c.

References xnb_softc::dev, xnb_softc::gnt_base_addr, xnb_softc::kva, xnb_softc::kva_size, xnb_softc::pseudo_phys_res, xnb_softc::pseudo_phys_res_id, xnb_softc::ring_configs, xnb_ring_config::ring_pages, xenmem_alloc(), and XNB_NUM_RING_TYPES.

Referenced by xnb_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_attach()

static int xnb_attach ( device_t  dev)
static

Attach to a XenBus device that has been claimed by our probe routine.

Parameters
devNewBus device object representing this Xen Net Back instance.
Returns
0 for success, errno codes for failure.

Definition at line 1255 of file netback.c.

References create_netdev(), xnb_softc::dev, DPRINTF, xnb_softc::otherend_id, xnb_softc::ring_configs, xnb_ring_config::ring_pages, xnb_attach_failed(), XNB_NUM_RING_TYPES, xnb_publish_backend_info(), xnb_setup_sysctl(), and xs_printf().

Here is the call graph for this function:

◆ xnb_attach_failed()

static void xnb_attach_failed ( struct xnb_softc xnb,
int  err,
const char *  fmt,
  ... 
)
static

Report an attach time error to the console and Xen, and cleanup this instance by forcing immediate detach processing.

Parameters
xnbPer-instance xnb configuration structure.
errErrno describing the error.
fmtPrintf style format and arguments

Definition at line 1090 of file netback.c.

References xnb_softc::dev, xnb_detach(), xs_printf(), and xs_vprintf().

Referenced by xnb_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_collect_xenstore_info()

static int xnb_collect_xenstore_info ( struct xnb_softc xnb)
static

Collect information from the XenStore related to our device and its frontend

Parameters
xnbPer-instance xnb configuration structure.
Todo:
Linux collects the following info. We should collect most of this, too: "feature-rx-notify"
Todo:
: figure out the exact meaning of this feature, and when the frontend will set it to true. It should be set to true at some point
Todo:
Collect the rx notify feature

Definition at line 837 of file netback.c.

References xnb_softc::bridge, xnb_softc::can_sg, xnb_softc::dev, xnb_softc::evtchn, xnb_softc::gso, xnb_softc::gso_prefix, xnb_softc::handle, xnb_softc::ip_csum, xnb_softc::ring_configs, xnb_ring_config::ring_ref, XNB_RING_TYPE_RX, XNB_RING_TYPE_TX, xs_gather(), xs_read(), and xs_scanf().

Referenced by xnb_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_connect()

static void xnb_connect ( struct xnb_softc xnb)
static

Connect to our netfront peer now that it has completed publishing its configuration into the XenStore.

Parameters
xnbPer-instance xnb configuration structure.

Definition at line 995 of file netback.c.

References xnb_softc::carrier, xnb_softc::dev, xnb_softc::flags, xnb_alloc_communication_mem(), xnb_collect_xenstore_info(), and xnb_connect_comms().

Referenced by xnb_frontend_changed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_connect_comms()

static int xnb_connect_comms ( struct xnb_softc xnb)
static

Setup the shared memory rings and bind an interrupt to the event channel used to notify us of ring changes.

Parameters
xnbPer-instance xnb configuration structure.

Definition at line 754 of file netback.c.

References xnb_softc::dev, DPRINTF, xnb_softc::evtchn, xnb_softc::flags, xnb_softc::otherend_id, xnb_softc::xen_intr_handle, xnb_connect_ring(), xnb_disconnect(), xnb_intr(), XNB_NUM_RING_TYPES, and XNBF_RING_CONNECTED.

Referenced by xnb_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_connect_ring()

static int xnb_connect_ring ( struct xnb_softc xnb,
xnb_ring_type_t  ring_type 
)
static

Map a single shared memory ring into domain local address space and initialize its control structure

Parameters
xnbPer-instance xnb configuration structure
ring_typeArray index of this ring in the xnb's array of rings
Returns
An errno

Definition at line 701 of file netback.c.

References xnb_ring_config::back_ring, xnb_ring_config::bus_addr, xnb_softc::dev, xnb_ring_config::gnt_addr, xnb_softc::gnt_base_addr, xnb_ring_config::handle, xnb_softc::kva, xnb_softc::otherend_id, xnb_softc::ring_configs, xnb_ring_config::ring_pages, xnb_ring_config::ring_ref, xnb_ring_config::rx_ring, xnb_ring_config::tx_ring, xnb_ring_config::va, XNB_RING_TYPE_RX, and XNB_RING_TYPE_TX.

Referenced by xnb_connect_comms().

Here is the caller graph for this function:

◆ xnb_detach()

static int xnb_detach ( device_t  dev)
static

Detach from a net back device instance.

Parameters
devNewBus device object representing this Xen Net Back instance.
Returns
0 for success, errno codes for failure.
Note
A net back device may be detached at any time in its life-cycle, including part way through the attach process. For this reason, initialization order and the initialization state checks in this routine must be carefully coupled so that attach time failures are gracefully handled.

Definition at line 1326 of file netback.c.

References xnb_softc::dev, DPRINTF, xnb_softc::rx_lock, xnb_softc::sc_lock, xnb_softc::tx_lock, and xnb_shutdown().

Referenced by xnb_attach_failed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_disconnect()

static int xnb_disconnect ( struct xnb_softc xnb)
static

Cleanup all inter-domain communication mechanisms.

Parameters
xnbPer-instance xnb configuration structure.

Definition at line 639 of file netback.c.

References xnb_softc::bridge, xnb_ring_config::bus_addr, xnb_softc::flags, xnb_ring_config::gnt_addr, xnb_ring_config::handle, xnb_softc::ring_configs, xnb_softc::rx_lock, xnb_softc::sc_lock, xnb_softc::tx_lock, xnb_softc::xen_intr_handle, xnb_free_communication_mem(), XNB_NUM_RING_TYPES, XNB_RING_TYPE_RX, and XNB_RING_TYPE_TX.

Referenced by xnb_connect_comms(), and xnb_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_dump_gnttab_copy()

static void __unused xnb_dump_gnttab_copy ( const struct gnttab_copy *  entry)
static

Definition at line 513 of file netback.c.

◆ xnb_dump_mbuf()

static void __unused xnb_dump_mbuf ( const struct mbuf *  m)
static

Definition at line 579 of file netback.c.

◆ xnb_dump_pkt()

static void __unused xnb_dump_pkt ( const struct xnb_pkt pkt)
static

xnb_pkt method: print the packet's contents in human-readable format

Definition at line 278 of file netback.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, DPRINTF, xnb_pkt::error, xnb_pkt::flags, xnb_pkt::list_len, and xnb_pkt::size.

◆ xnb_dump_rings()

static int xnb_dump_rings ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 540 of file netback.c.

References xnb_ring_config::back_ring, xnb_softc::ring_configs, xnb_ring_config::rx_ring, rxb, xnb_ring_config::tx_ring, txb, XNB_RING_TYPE_RX, and XNB_RING_TYPE_TX.

Referenced by xnb_setup_sysctl().

Here is the caller graph for this function:

◆ xnb_dump_txreq()

static void xnb_dump_txreq ( RING_IDX  idx,
const struct netif_tx_request *  txreq 
)
static

Definition at line 296 of file netback.c.

References DPRINTF.

Referenced by xnb_ring2pkt().

Here is the caller graph for this function:

◆ xnb_free_communication_mem()

static void xnb_free_communication_mem ( struct xnb_softc xnb)
static

Free dynamically allocated KVA or pseudo-physical address allocations.

Parameters
xnbPer-instance xnb configuration structure.

Definition at line 620 of file netback.c.

References xnb_softc::dev, xnb_softc::gnt_base_addr, xnb_softc::kva, xnb_softc::pseudo_phys_res, xnb_softc::pseudo_phys_res_id, and xenmem_free().

Referenced by xnb_disconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_frontend_changed()

static void xnb_frontend_changed ( device_t  dev,
XenbusState  frontend_state 
)
static

Handle state changes expressed via the XenStore by our front-end peer.

Parameters
devNewBus device object representing this Xen Net Back instance.
frontend_stateThe new state of the front-end.
Returns
0 for success, errno codes for failure.

Definition at line 1383 of file netback.c.

References xnb_softc::dev, DPRINTF, xnb_softc::sc_lock, xnb_connect(), and xnb_shutdown().

Here is the call graph for this function:

◆ xnb_ifinit()

static void xnb_ifinit ( void *  xsc)
static

Definition at line 2448 of file netback.c.

References xnb_softc::sc_lock, and xnb_ifinit_locked().

Referenced by create_netdev(), and xnb_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_ifinit_locked()

static void xnb_ifinit_locked ( struct xnb_softc xnb)
static

Definition at line 2429 of file netback.c.

References ifp, xnb_softc::sc_lock, xnb_softc::xnb_ifp, and xnb_stop().

Referenced by xnb_ifinit(), and xnb_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_ifmedia_sts()

static void xnb_ifmedia_sts ( struct ifnet *  ifp,
struct ifmediareq *  ifmr 
)
static

Callback used by the generic networking code to ask us what our carrier state is. Since we don't have a physical carrier, this is very simple

Definition at line 2472 of file netback.c.

Referenced by create_netdev().

Here is the caller graph for this function:

◆ xnb_ifmedia_upd()

static int xnb_ifmedia_upd ( struct ifnet *  ifp)
static

Callback used by the generic networking code to tell us when our carrier state has changed. Since we don't have a physical carrier, we don't care

Definition at line 2462 of file netback.c.

Referenced by create_netdev().

Here is the caller graph for this function:

◆ xnb_intr()

static void xnb_intr ( void *  arg)
static

Interrupt handler bound to the shared ring's event channel. Entry point for the xennet transmit path in netback Transfers packets from the Xen ring to the host's generic networking stack

Parameters
argCallback argument registerd during event channel binding - the xnb_softc for this instance.

Definition at line 1425 of file netback.c.

References xnb_ring_config::back_ring, ifp, notify(), xnb_softc::otherend_id, xnb_softc::ring_configs, xnb_softc::tx_gnttab, xnb_softc::tx_lock, xnb_ring_config::tx_ring, txb, xnb_softc::xen_intr_handle, xnb_softc::xnb_ifp, xnb_recv(), XNB_RING_TYPE_TX, and xnb_start().

Referenced by xnb_connect_comms().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_ioctl()

static int xnb_ioctl ( struct ifnet *  ifp,
u_long  cmd,
caddr_t  data 
)
static

Definition at line 2201 of file netback.c.

References ifp, xnb_softc::sc_lock, xnb_softc::sc_media, XNB_CSUM_FEATURES, xnb_ifinit(), xnb_ifinit_locked(), and xnb_stop().

Referenced by create_netdev().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_mbufc2pkt()

static int xnb_mbufc2pkt ( const struct mbuf *  mbufc,
struct xnb_pkt pkt,
RING_IDX  start,
int  space 
)
static

Create an xnb_pkt based on the contents of an mbuf chain.

Parameters
[in]mbufcmbuf chain to transform into a packet
[out]pktStorage for the newly generated xnb_pkt
[in]startThe ring index of the first available slot in the rx ring
[in]spaceThe number of free slots in the rx ring
Return values
0Success
EINVALmbufc was corrupt or not convertible into a pkt
EAGAINThere was not enough space in the ring to queue the packet

Definition at line 1879 of file netback.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::extra, xnb_pkt::flags, xnb_pkt::list_len, xnb_pkt::size, xnb_pkt_invalidate(), and xnb_pkt_validate().

Referenced by xnb_mbufc2pkt_1cluster(), xnb_mbufc2pkt_2short(), xnb_mbufc2pkt_empty(), xnb_mbufc2pkt_extra(), xnb_mbufc2pkt_long(), xnb_mbufc2pkt_nospace(), xnb_mbufc2pkt_short(), xnb_rxpkt2gnttab_2req(), xnb_rxpkt2gnttab_empty(), xnb_rxpkt2gnttab_short(), xnb_rxpkt2rsp_2short(), xnb_rxpkt2rsp_2slots(), xnb_rxpkt2rsp_copyerror(), xnb_rxpkt2rsp_empty(), xnb_rxpkt2rsp_extra(), xnb_rxpkt2rsp_short(), and xnb_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_pkt2mbufc()

static struct mbuf * xnb_pkt2mbufc ( const struct xnb_pkt pkt,
struct ifnet *  ifp 
)
static

Create an mbuf chain to represent a packet. Initializes all of the headers in the mbuf chain, but does not copy the data. The returned chain must be free()'d when no longer needed

Parameters
[in]pktA packet to model the mbuf chain after
Returns
A newly allocated mbuf chain, possibly with clusters attached. NULL on failure
Todo:
consider using a memory pool for mbufs instead of reallocating them for every packet
Todo:
handle extra data

Definition at line 1656 of file netback.c.

References xnb_pkt::flags, ifp, and xnb_pkt::size.

Referenced by xnb_pkt2mbufc_1cluster(), xnb_pkt2mbufc_2cluster(), xnb_pkt2mbufc_csum(), xnb_pkt2mbufc_empty(), xnb_pkt2mbufc_largecluster(), xnb_pkt2mbufc_short(), xnb_recv(), xnb_txpkt2gnttab_2cluster(), xnb_txpkt2gnttab_2req(), xnb_txpkt2gnttab_empty(), xnb_txpkt2gnttab_short(), xnb_update_mbufc_2cluster(), xnb_update_mbufc_2req(), and xnb_update_mbufc_short().

Here is the caller graph for this function:

◆ xnb_pkt_initialize()

static void xnb_pkt_initialize ( struct xnb_pkt pxnb)
inlinestatic

xnb_pkt method: initialize it

Definition at line 249 of file netback.c.

Referenced by xnb_ring2pkt().

Here is the caller graph for this function:

◆ xnb_pkt_invalidate()

static void xnb_pkt_invalidate ( struct xnb_pkt pxnb)
inlinestatic

xnb_pkt method: mark the packet as invalid

Definition at line 263 of file netback.c.

References xnb_pkt::error.

Referenced by xnb_mbufc2pkt(), and xnb_ring2pkt().

Here is the caller graph for this function:

◆ xnb_pkt_is_valid()

◆ xnb_pkt_validate()

static void xnb_pkt_validate ( struct xnb_pkt pxnb)
inlinestatic

xnb_pkt method: mark the packet as valid

Definition at line 256 of file netback.c.

References xnb_pkt::error.

Referenced by xnb_mbufc2pkt().

Here is the caller graph for this function:

◆ xnb_probe()

static int xnb_probe ( device_t  dev)
static

Inspect a XenBus device and claim it if is of the appropriate type.

Parameters
devNewBus device object representing a candidate XenBus device.
Returns
0 for success, errno codes for failure.

Definition at line 1119 of file netback.c.

References DPRINTF.

◆ xnb_publish_backend_info()

static int xnb_publish_backend_info ( struct xnb_softc xnb)
static

Supply information about the physical device to the frontend via XenBus.

Parameters
xnbPer-instance xnb configuration structure.

Definition at line 940 of file netback.c.

References xnb_softc::dev, XNB_GSO_TCPV4, XNB_RX_COPY, XNB_RX_FLIP, XNB_SG, xs_printf(), xs_transaction_end(), and xs_transaction_start().

Referenced by xnb_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_recv()

static int xnb_recv ( netif_tx_back_ring_t *  txb,
domid_t  otherend,
struct mbuf **  mbufc,
struct ifnet *  ifnet,
gnttab_copy_table  gnttab 
)
static

Dequeue at most one packet from the shared ring

Parameters
[in,out]txbNetif tx ring. A packet will be removed from it, and its private indices will be updated. But the indices will not be pushed to the shared ring.
[in]ifnetInterface to which the packet will be sent
[in]otherendDomain ID of the other end of the ring
[out]mbufcThe assembled mbuf chain, ready to send to the generic networking stack
[in,out]gnttabPointer to enough memory for a grant table. We make this a function parameter so that we will take less stack space.
Returns
An error code

Definition at line 1807 of file netback.c.

References DPRINTF, gnttab, txb, xnb_pkt2mbufc(), xnb_pkt_is_valid(), xnb_ring2pkt(), xnb_txpkt2gnttab(), xnb_txpkt2rsp(), and xnb_update_mbufc().

Referenced by xnb_intr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_resume()

static int xnb_resume ( device_t  dev)
static

Perform any processing required to recover from a suspended state.

Parameters
devNewBus device object representing this Xen Net Back instance.
Returns
0 for success, errno codes for failure.

Definition at line 1368 of file netback.c.

◆ xnb_ring2pkt()

static int xnb_ring2pkt ( struct xnb_pkt pkt,
const netif_tx_back_ring_t *  tx_ring,
RING_IDX  start 
)
static

Build a struct xnb_pkt based on netif_tx_request's from a netif tx ring. Will read exactly 0 or 1 packets from the ring; never a partial packet.

Parameters
[out]pktThe returned packet. If there is an error building the packet, pkt.list_len will be set to 0.
[in]tx_ringPointer to the Ring that is the input to this function
[in]startThe ring index of the first potential request
Returns
The number of requests consumed to build this packet

Definition at line 1477 of file netback.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, xnb_pkt::extra, xnb_pkt::flags, xnb_pkt::list_len, RING_HAS_UNCONSUMED_REQUESTS_2, xnb_pkt::size, xnb_dump_txreq(), xnb_pkt_initialize(), and xnb_pkt_invalidate().

Referenced by xnb_get1pkt(), xnb_pkt2mbufc_empty(), xnb_recv(), xnb_ring2pkt_1req(), xnb_ring2pkt_2req(), xnb_ring2pkt_3req(), xnb_ring2pkt_emptyring(), xnb_ring2pkt_extra(), xnb_ring2pkt_partial(), xnb_ring2pkt_wraps(), xnb_txpkt2gnttab_2cluster(), xnb_txpkt2gnttab_2req(), xnb_txpkt2gnttab_empty(), xnb_txpkt2gnttab_short(), xnb_txpkt2rsp_1req(), xnb_txpkt2rsp_emptypkt(), xnb_txpkt2rsp_error(), xnb_txpkt2rsp_extra(), xnb_txpkt2rsp_invalid(), xnb_txpkt2rsp_long(), xnb_txpkt2rsp_wraps(), xnb_update_mbufc_2cluster(), xnb_update_mbufc_2req(), and xnb_update_mbufc_short().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_rxpkt2gnttab()

static int xnb_rxpkt2gnttab ( const struct xnb_pkt pkt,
const struct mbuf *  mbufc,
gnttab_copy_table  gnttab,
const netif_rx_back_ring_t *  rxb,
domid_t  otherend_id 
)
static

Build a gnttab_copy table that can be used to copy data from an mbuf chain to the frontend's shared buffers. Does not actually perform the copy. Always uses gref's on the other end's side.

Parameters
[in]pktpkt's associated responses form the dest for the copy operatoin
[in]mbufcThe source for the copy operation
[out]gnttabStorage for the returned grant table
[in]rxbPointer to the backend ring structure
[in]otherend_idThe domain ID of the other end of the copy
Returns
The number of gnttab entries filled

Definition at line 1952 of file netback.c.

References xnb_pkt::car, xnb_pkt::cdr, gnttab, GNTTAB_LEN, rxb, xnb_pkt::size, virt_to_mfn, virt_to_offset, and xnb_pkt_is_valid().

Referenced by xnb_rxpkt2gnttab_2req(), xnb_rxpkt2gnttab_empty(), xnb_rxpkt2gnttab_short(), xnb_rxpkt2rsp_2short(), xnb_rxpkt2rsp_2slots(), xnb_rxpkt2rsp_copyerror(), xnb_rxpkt2rsp_empty(), xnb_rxpkt2rsp_extra(), xnb_rxpkt2rsp_short(), and xnb_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_rxpkt2rsp()

static int xnb_rxpkt2rsp ( const struct xnb_pkt pkt,
const gnttab_copy_table  gnttab,
int  n_entries,
netif_rx_back_ring_t *  ring 
)
static

Generates responses for all the requests that constituted pkt. Builds responses and writes them to the ring, but doesn't push the shared ring indices.

Parameters
[in]pktthe packet that needs a response
[in]gnttabThe grant copy table corresponding to this packet. Used to determine how many rsp->netif_rx_response_t's to generate.
[in]n_entriesNumber of relevant entries in the grant table
[out]ringResponses go here
Returns
The number of RX requests that were consumed to generate the responses

Definition at line 2027 of file netback.c.

References DPRINTF, xnb_pkt::extra, xnb_pkt::flags, and gnttab.

Referenced by xnb_rxpkt2rsp_2short(), xnb_rxpkt2rsp_2slots(), xnb_rxpkt2rsp_copyerror(), xnb_rxpkt2rsp_empty(), xnb_rxpkt2rsp_extra(), xnb_rxpkt2rsp_short(), and xnb_send().

Here is the caller graph for this function:

◆ xnb_send()

static int xnb_send ( netif_rx_back_ring_t *  ring,
domid_t  otherend,
const struct mbuf *  mbufc,
gnttab_copy_table  gnttab 
)
static

Sends one packet to the ring. Blocks until the packet is on the ring

Parameters
[in]mbufcContains one packet to send. Caller must free
[in,out]rxbThe packet will be pushed onto this ring, but the otherend will not be notified.
[in]otherendThe domain ID of the other end of the connection
Return values
EAGAINThe ring did not have enough space for the packet. The ring has not been modified
Parameters
[in,out]gnttabPointer to enough memory for a grant table. We make this a function parameter so that we will take less stack space.
Return values
EINVALmbufc was corrupt or not convertible into a pkt

Definition at line 2392 of file netback.c.

References xnb_pkt::error, gnttab, xnb_mbufc2pkt(), xnb_rxpkt2gnttab(), and xnb_rxpkt2rsp().

Referenced by xnb_start_locked().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_setup_sysctl()

static void xnb_setup_sysctl ( struct xnb_softc xnb)
static

Setup sysctl variables to control various Network Back parameters.

Parameters
xnbXen Net Back softc.

Definition at line 1138 of file netback.c.

References xnb_softc::dev, xnb_dump_rings(), and xnb_unit_test_main().

Referenced by xnb_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_shutdown()

static int xnb_shutdown ( struct xnb_softc xnb)
static

Perform device shutdown functions.

Parameters
xnbPer-instance xnb configuration structure.

Mark this instance as shutting down, wait for any active requests to drain, disconnect from the front-end, and notify any waiters (e.g. a thread invoking our detach method) that detach can now proceed.

Definition at line 1042 of file netback.c.

References xnb_softc::carrier, xnb_softc::dev, xnb_softc::flags, xnb_softc::sc_lock, xnb_disconnect(), xnb_softc::xnb_ifp, XNBF_IN_SHUTDOWN, and XNBF_SHUTDOWN.

Referenced by xnb_detach(), and xnb_frontend_changed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_start()

static void xnb_start ( struct ifnet *  ifp)
static

Definition at line 2417 of file netback.c.

References ifp, xnb_softc::rx_lock, and xnb_start_locked().

Referenced by create_netdev(), and xnb_intr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_start_locked()

static void xnb_start_locked ( struct ifnet *  ifp)
static

Definition at line 2312 of file netback.c.

References xnb_ring_config::back_ring, xnb_softc::carrier, ifp, notify(), xnb_softc::otherend_id, xnb_softc::ring_configs, xnb_softc::rx_gnttab, xnb_ring_config::rx_ring, rxb, xnb_softc::xen_intr_handle, XNB_RING_TYPE_RX, and xnb_send().

Referenced by xnb_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_stop()

static void xnb_stop ( struct xnb_softc xnb)
static

Definition at line 2190 of file netback.c.

References ifp, xnb_softc::sc_lock, and xnb_softc::xnb_ifp.

Referenced by xnb_ifinit_locked(), and xnb_ioctl().

Here is the caller graph for this function:

◆ xnb_suspend()

static int xnb_suspend ( device_t  dev)
static

Prepare this net back device for suspension of this VM.

Parameters
devNewBus device object representing this Xen net Back instance.
Returns
0 for success, errno codes for failure.

Definition at line 1355 of file netback.c.

◆ xnb_txpkt2gnttab()

static int xnb_txpkt2gnttab ( const struct xnb_pkt pkt,
struct mbuf *  mbufc,
gnttab_copy_table  gnttab,
const netif_tx_back_ring_t *  txb,
domid_t  otherend_id 
)
static

Build a gnttab_copy table that can be used to copy data from a pkt to an mbufc. Does not actually perform the copy. Always uses gref's on the packet side.

Parameters
[in]pktpkt's associated requests form the src for the copy operation
[in]mbufcmbufc's storage forms the dest for the copy operation
[out]gnttabStorage for the returned grant table
[in]txbPointer to the backend ring structure
[in]otherend_idThe domain ID of the other end of the copy
Returns
The number of gnttab entries filled

Definition at line 1700 of file netback.c.

References xnb_pkt::car, xnb_pkt::car_size, xnb_pkt::cdr, gnttab, GNTTAB_LEN, xnb_pkt::size, txb, virt_to_mfn, and virt_to_offset.

Referenced by xnb_recv(), xnb_txpkt2gnttab_2cluster(), xnb_txpkt2gnttab_2req(), xnb_txpkt2gnttab_empty(), xnb_txpkt2gnttab_short(), xnb_update_mbufc_2cluster(), xnb_update_mbufc_2req(), and xnb_update_mbufc_short().

Here is the caller graph for this function:

◆ xnb_txpkt2rsp()

static void xnb_txpkt2rsp ( const struct xnb_pkt pkt,
netif_tx_back_ring_t *  ring,
int  error 
)
static

Respond to all the requests that constituted pkt. Builds the responses and writes them to the ring, but doesn't push them to the shared ring.

Parameters
[in]pktthe packet that needs a response
[in]errortrue if there was an error handling the packet, such as in the hypervisor copy op or mbuf allocation
[out]ringResponses go here

Definition at line 1599 of file netback.c.

References xnb_pkt::car, xnb_pkt::flags, xnb_pkt::list_len, and xnb_pkt_is_valid().

Referenced by xnb_recv(), xnb_txpkt2rsp_1req(), xnb_txpkt2rsp_emptypkt(), xnb_txpkt2rsp_error(), xnb_txpkt2rsp_extra(), xnb_txpkt2rsp_invalid(), xnb_txpkt2rsp_long(), and xnb_txpkt2rsp_wraps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xnb_unit_test_main()

static int xnb_unit_test_main ( SYSCTL_HANDLER_ARGS  )
static

Referenced by xnb_setup_sysctl().

Here is the caller graph for this function:

◆ xnb_update_mbufc()

static void xnb_update_mbufc ( struct mbuf *  mbufc,
const gnttab_copy_table  gnttab,
int  n_entries 
)
static

Check the status of the grant copy operations, and update mbufs various non-data fields to reflect the data present.

Parameters
[in,out]mbufcmbuf chain to update. The chain must be valid and of the correct length, and data should already be present
[in]gnttabA grant table for a just completed copy op
[in]n_entriesThe number of valid entries in the grant table

Definition at line 1767 of file netback.c.

References gnttab.

Referenced by xnb_recv(), xnb_update_mbufc_2cluster(), xnb_update_mbufc_2req(), and xnb_update_mbufc_short().

Here is the caller graph for this function:

Variable Documentation

◆ xnb_devclass

devclass_t xnb_devclass

Definition at line 2498 of file netback.c.

◆ xnb_driver

driver_t xnb_driver
static
Initial value:
= {
"xnb",
sizeof(struct xnb_softc),
}
static device_method_t xnb_methods[]
Definition: netback.c:2479

Definition at line 2493 of file netback.c.

◆ xnb_methods

device_method_t xnb_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, xnb_probe),
DEVMETHOD(device_attach, xnb_attach),
DEVMETHOD(device_detach, xnb_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, xnb_suspend),
DEVMETHOD(device_resume, xnb_resume),
DEVMETHOD(xenbus_otherend_changed, xnb_frontend_changed),
{ 0, 0 }
}
static void xnb_frontend_changed(device_t dev, XenbusState frontend_state)
Definition: netback.c:1383
static int xnb_resume(device_t dev)
Definition: netback.c:1368
static int xnb_detach(device_t dev)
Definition: netback.c:1326
static int xnb_probe(device_t dev)
Definition: netback.c:1119
static int xnb_attach(device_t dev)
Definition: netback.c:1255
static int xnb_suspend(device_t dev)
Definition: netback.c:1355

Definition at line 2479 of file netback.c.