FreeBSD kernel /amd64 XEN device code
netfront.c File Reference
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include <sys/param.h>
#include <sys/sockio.h>
#include <sys/limits.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/taskqueue.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <net/if_media.h>
#include <net/bpf.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/tcp_lro.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <sys/bus.h>
#include <xen/xen-os.h>
#include <xen/hypervisor.h>
#include <xen/xen_intr.h>
#include <xen/gnttab.h>
#include <contrib/xen/memory.h>
#include <contrib/xen/io/netif.h>
#include <xen/xenbus/xenbusvar.h>
#include "xenbus_if.h"
Include dependency graph for netfront.c:

Go to the source code of this file.

Data Structures

struct  netfront_rxq
 
struct  netfront_txq
 
struct  netfront_info
 
struct  netfront_rx_info
 

Macros

#define XN_CSUM_FEATURES   (CSUM_TCP | CSUM_UDP)
 
#define NET_TX_RING_SIZE   __CONST_RING_SIZE(netif_tx, PAGE_SIZE)
 
#define NET_RX_RING_SIZE   __CONST_RING_SIZE(netif_rx, PAGE_SIZE)
 
#define NET_RX_SLOTS_MIN   (XEN_NETIF_NR_SLOTS_MIN + 1)
 
#define MAX_TX_REQ_FRAGS   (65536 / PAGE_SIZE + 2)
 The maximum allowed data fragments in a single transmit request. More...
 
#define RX_COPY_THRESHOLD   256
 
#define net_ratelimit()   0
 
#define virt_to_mfn(x)   (vtophys(x) >> PAGE_SHIFT)
 
#define INVALID_P2M_ENTRY   (~0UL)
 
#define XN_QUEUE_NAME_LEN   8 /* xn{t,r}x_%u, allow for two digits */
 
#define XN_RX_LOCK(_q)   mtx_lock(&(_q)->lock)
 
#define XN_RX_UNLOCK(_q)   mtx_unlock(&(_q)->lock)
 
#define XN_TX_LOCK(_q)   mtx_lock(&(_q)->lock)
 
#define XN_TX_TRYLOCK(_q)   mtx_trylock(&(_q)->lock)
 
#define XN_TX_UNLOCK(_q)   mtx_unlock(&(_q)->lock)
 
#define XN_LOCK(_sc)   mtx_lock(&(_sc)->sc_lock);
 
#define XN_UNLOCK(_sc)   mtx_unlock(&(_sc)->sc_lock);
 
#define XN_LOCK_ASSERT(_sc)   mtx_assert(&(_sc)->sc_lock, MA_OWNED);
 
#define XN_RX_LOCK_ASSERT(_q)   mtx_assert(&(_q)->lock, MA_OWNED);
 
#define XN_TX_LOCK_ASSERT(_q)   mtx_assert(&(_q)->lock, MA_OWNED);
 
#define netfront_carrier_on(netif)   ((netif)->carrier = 1)
 
#define netfront_carrier_off(netif)   ((netif)->carrier = 0)
 
#define netfront_carrier_ok(netif)   ((netif)->carrier)
 
#define IPRINTK(fmt, args...)    printf("[XEN] " fmt, ##args)
 
#define WPRINTK(fmt, args...)
 
#define DPRINTK(fmt, args...)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 TUNABLE_INT ("hw.xn.enable_lro", &xn_enable_lro)
 
 TUNABLE_ULONG ("hw.xn.num_queues", &xn_num_queues)
 
static void xn_txeof (struct netfront_txq *)
 
static void xn_rxeof (struct netfront_rxq *)
 
static void xn_alloc_rx_buffers (struct netfront_rxq *)
 
static void xn_alloc_rx_buffers_callout (void *arg)
 
static void xn_release_rx_bufs (struct netfront_rxq *)
 
static void xn_release_tx_bufs (struct netfront_txq *)
 
static void xn_rxq_intr (struct netfront_rxq *)
 
static void xn_txq_intr (struct netfront_txq *)
 
static void xn_intr (void *)
 
static int xn_count_frags (struct mbuf *m)
 Count the number of fragments in an mbuf chain. More...
 
static int xn_assemble_tx_request (struct netfront_txq *, struct mbuf *)
 
static int xn_ioctl (struct ifnet *, u_long, caddr_t)
 
static void xn_ifinit_locked (struct netfront_info *)
 
static void xn_ifinit (void *)
 
static void xn_stop (struct netfront_info *)
 
static void xn_query_features (struct netfront_info *np)
 
static int xn_configure_features (struct netfront_info *np)
 
static void netif_free (struct netfront_info *info)
 
static int netfront_detach (device_t dev)
 
static int xn_txq_mq_start_locked (struct netfront_txq *, struct mbuf *)
 
static int xn_txq_mq_start (struct ifnet *, struct mbuf *)
 
static int talk_to_backend (device_t dev, struct netfront_info *info)
 
static int create_netdev (device_t dev)
 
static void netif_disconnect_backend (struct netfront_info *info)
 
static int setup_device (device_t dev, struct netfront_info *info, unsigned long)
 
static int xn_ifmedia_upd (struct ifnet *ifp)
 
static void xn_ifmedia_sts (struct ifnet *ifp, struct ifmediareq *ifmr)
 
static int xn_connect (struct netfront_info *)
 
static void xn_kick_rings (struct netfront_info *)
 
static int xn_get_responses (struct netfront_rxq *, struct netfront_rx_info *, RING_IDX, RING_IDX *, struct mbuf **)
 
static void add_id_to_freelist (struct mbuf **list, uintptr_t id)
 
static unsigned short get_id_from_freelist (struct mbuf **list)
 
static int xn_rxidx (RING_IDX idx)
 
static struct mbuf * xn_get_rx_mbuf (struct netfront_rxq *rxq, RING_IDX ri)
 
static grant_ref_t xn_get_rx_ref (struct netfront_rxq *rxq, RING_IDX ri)
 
static int xen_net_read_mac (device_t dev, uint8_t mac[])
 
static int netfront_probe (device_t dev)
 
static int netfront_attach (device_t dev)
 
static int netfront_suspend (device_t dev)
 
static int netfront_resume (device_t dev)
 
static int write_queue_xenstore_keys (device_t dev, struct netfront_rxq *rxq, struct netfront_txq *txq, struct xs_transaction *xst, bool hierarchy)
 
static void xn_txq_start (struct netfront_txq *txq)
 
static void xn_txq_tq_deferred (void *xtxq, int pending)
 
static void disconnect_rxq (struct netfront_rxq *rxq)
 
static void destroy_rxq (struct netfront_rxq *rxq)
 
static void destroy_rxqs (struct netfront_info *np)
 
static int setup_rxqs (device_t dev, struct netfront_info *info, unsigned long num_queues)
 
static void disconnect_txq (struct netfront_txq *txq)
 
static void destroy_txq (struct netfront_txq *txq)
 
static void destroy_txqs (struct netfront_info *np)
 
static int setup_txqs (device_t dev, struct netfront_info *info, unsigned long num_queues)
 
static void netfront_backend_changed (device_t dev, XenbusState newstate)
 
static int xn_tx_slot_available (struct netfront_txq *txq)
 Verify that there is sufficient space in the Tx ring buffer for a maximally sized request to be enqueued. More...
 
static struct mbuf * xn_alloc_one_rx_buffer (struct netfront_rxq *rxq)
 
static void xn_move_rx_slot (struct netfront_rxq *rxq, struct mbuf *m, grant_ref_t ref)
 
static int xn_get_extras (struct netfront_rxq *rxq, struct netif_extra_info *extras, RING_IDX rp, RING_IDX *cons)
 
static void xn_rebuild_rx_bufs (struct netfront_rxq *rxq)
 
static void xn_qflush (struct ifnet *ifp)
 
 DRIVER_MODULE (xe, xenbusb_front, netfront_driver, netfront_devclass, NULL, NULL)
 

Variables

static int xn_enable_lro = 1
 
static unsigned long xn_num_queues = 4
 
static device_method_t netfront_methods []
 
static driver_t netfront_driver
 
devclass_t netfront_devclass
 

Macro Definition Documentation

◆ DPRINTK

#define DPRINTK (   fmt,
  args... 
)

Definition at line 316 of file netfront.c.

◆ INVALID_P2M_ENTRY

#define INVALID_P2M_ENTRY   (~0UL)

Definition at line 160 of file netfront.c.

◆ IPRINTK

#define IPRINTK (   fmt,
  args... 
)     printf("[XEN] " fmt, ##args)

Definition at line 304 of file netfront.c.

◆ MAX_TX_REQ_FRAGS

#define MAX_TX_REQ_FRAGS   (65536 / PAGE_SIZE + 2)

The maximum allowed data fragments in a single transmit request.

This limit is imposed by the backend driver. We assume here that we are dealing with a Linux driver domain and have set our limit to mirror the Linux MAX_SKB_FRAGS constant.

Definition at line 107 of file netfront.c.

◆ net_ratelimit

#define net_ratelimit ( )    0

Definition at line 111 of file netfront.c.

◆ NET_RX_RING_SIZE

#define NET_RX_RING_SIZE   __CONST_RING_SIZE(netif_rx, PAGE_SIZE)

Definition at line 80 of file netfront.c.

◆ NET_RX_SLOTS_MIN

#define NET_RX_SLOTS_MIN   (XEN_NETIF_NR_SLOTS_MIN + 1)

Definition at line 82 of file netfront.c.

◆ NET_TX_RING_SIZE

#define NET_TX_RING_SIZE   __CONST_RING_SIZE(netif_tx, PAGE_SIZE)

Definition at line 79 of file netfront.c.

◆ netfront_carrier_off

#define netfront_carrier_off (   netif)    ((netif)->carrier = 0)

Definition at line 247 of file netfront.c.

◆ netfront_carrier_ok

#define netfront_carrier_ok (   netif)    ((netif)->carrier)

Definition at line 248 of file netfront.c.

◆ netfront_carrier_on

#define netfront_carrier_on (   netif)    ((netif)->carrier = 1)

Definition at line 246 of file netfront.c.

◆ RX_COPY_THRESHOLD

#define RX_COPY_THRESHOLD   256

Definition at line 109 of file netfront.c.

◆ virt_to_mfn

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

Definition at line 158 of file netfront.c.

◆ WPRINTK

#define WPRINTK (   fmt,
  args... 
)

Definition at line 310 of file netfront.c.

◆ XN_CSUM_FEATURES

#define XN_CSUM_FEATURES   (CSUM_TCP | CSUM_UDP)

Definition at line 77 of file netfront.c.

◆ XN_LOCK

#define XN_LOCK (   _sc)    mtx_lock(&(_sc)->sc_lock);

Definition at line 239 of file netfront.c.

◆ XN_LOCK_ASSERT

#define XN_LOCK_ASSERT (   _sc)    mtx_assert(&(_sc)->sc_lock, MA_OWNED);

Definition at line 242 of file netfront.c.

◆ XN_QUEUE_NAME_LEN

#define XN_QUEUE_NAME_LEN   8 /* xn{t,r}x_%u, allow for two digits */

Definition at line 161 of file netfront.c.

◆ XN_RX_LOCK

#define XN_RX_LOCK (   _q)    mtx_lock(&(_q)->lock)

Definition at line 232 of file netfront.c.

◆ XN_RX_LOCK_ASSERT

#define XN_RX_LOCK_ASSERT (   _q)    mtx_assert(&(_q)->lock, MA_OWNED);

Definition at line 243 of file netfront.c.

◆ XN_RX_UNLOCK

#define XN_RX_UNLOCK (   _q)    mtx_unlock(&(_q)->lock)

Definition at line 233 of file netfront.c.

◆ XN_TX_LOCK

#define XN_TX_LOCK (   _q)    mtx_lock(&(_q)->lock)

Definition at line 235 of file netfront.c.

◆ XN_TX_LOCK_ASSERT

#define XN_TX_LOCK_ASSERT (   _q)    mtx_assert(&(_q)->lock, MA_OWNED);

Definition at line 244 of file netfront.c.

◆ XN_TX_TRYLOCK

#define XN_TX_TRYLOCK (   _q)    mtx_trylock(&(_q)->lock)

Definition at line 236 of file netfront.c.

◆ XN_TX_UNLOCK

#define XN_TX_UNLOCK (   _q)    mtx_unlock(&(_q)->lock)

Definition at line 237 of file netfront.c.

◆ XN_UNLOCK

#define XN_UNLOCK (   _sc)    mtx_unlock(&(_sc)->sc_lock);

Definition at line 240 of file netfront.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ add_id_to_freelist()

static void add_id_to_freelist ( struct mbuf **  list,
uintptr_t  id 
)
inlinestatic

Definition at line 253 of file netfront.c.

Referenced by xn_release_tx_bufs(), and xn_txeof().

Here is the caller graph for this function:

◆ create_netdev()

int create_netdev ( device_t  dev)
static

Create a network device.

Parameters
devNewbus device representing this virtual NIC.

Definition at line 2204 of file netfront.c.

References ifp, netfront_info::mac, MAX_TX_REQ_FRAGS, netfront_carrier_off, netfront_info::sc_lock, netfront_info::sc_media, netfront_info::xbdev, xen_net_read_mac(), XN_CSUM_FEATURES, xn_ifinit(), xn_ifmedia_sts(), xn_ifmedia_upd(), netfront_info::xn_ifp, xn_ioctl(), xn_qflush(), and xn_txq_mq_start().

Referenced by netfront_attach().

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

◆ destroy_rxq()

static void destroy_rxq ( struct netfront_rxq rxq)
static

Definition at line 682 of file netfront.c.

References netfront_rxq::ring, and netfront_rxq::rx_refill.

Referenced by destroy_rxqs(), and setup_rxqs().

Here is the caller graph for this function:

◆ destroy_rxqs()

static void destroy_rxqs ( struct netfront_info np)
static

Definition at line 690 of file netfront.c.

References destroy_rxq(), netfront_info::num_queues, and netfront_info::rxq.

Referenced by setup_device().

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

◆ destroy_txq()

static void destroy_txq ( struct netfront_txq txq)
static

Definition at line 779 of file netfront.c.

References netfront_txq::br, netfront_txq::ring, and netfront_txq::tq.

Referenced by destroy_txqs(), and setup_txqs().

Here is the caller graph for this function:

◆ destroy_txqs()

static void destroy_txqs ( struct netfront_info np)
static

Definition at line 789 of file netfront.c.

References destroy_txq(), netfront_info::num_queues, and netfront_info::txq.

Referenced by setup_device().

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

◆ disconnect_rxq()

static void disconnect_rxq ( struct netfront_rxq rxq)
static

Definition at line 667 of file netfront.c.

References gnttab_end_foreign_access(), gnttab_free_grant_references(), netfront_rxq::gref_head, netfront_rxq::ring_ref, netfront_rxq::xen_intr_handle, and xn_release_rx_bufs().

Referenced by netif_disconnect_backend(), and setup_rxqs().

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

◆ disconnect_txq()

static void disconnect_txq ( struct netfront_txq txq)
static

Definition at line 769 of file netfront.c.

References gnttab_end_foreign_access(), gnttab_free_grant_references(), netfront_txq::gref_head, netfront_txq::ring_ref, netfront_txq::xen_intr_handle, and xn_release_tx_bufs().

Referenced by netif_disconnect_backend(), and setup_txqs().

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

◆ DRIVER_MODULE()

DRIVER_MODULE ( xe  ,
xenbusb_front  ,
netfront_driver  ,
netfront_devclass  ,
NULL  ,
NULL   
)

◆ get_id_from_freelist()

static unsigned short get_id_from_freelist ( struct mbuf **  list)
inlinestatic

Definition at line 263 of file netfront.c.

Referenced by xn_assemble_tx_request().

Here is the caller graph for this function:

◆ netfront_attach()

static int netfront_attach ( device_t  dev)
static

Definition at line 393 of file netfront.c.

References create_netdev(), xn_enable_lro, and xn_num_queues.

Here is the call graph for this function:

◆ netfront_backend_changed()

static void netfront_backend_changed ( device_t  dev,
XenbusState  newstate 
)
static

Callback received when the backend's state changes.

Definition at line 959 of file netfront.c.

References DPRINTK, netif_disconnect_backend(), netfront_info::xbdev, xn_connect(), netfront_info::xn_ifp, xn_kick_rings(), and netfront_info::xn_reset.

Here is the call graph for this function:

◆ netfront_detach()

static int netfront_detach ( device_t  dev)
static

Definition at line 2255 of file netfront.c.

References DPRINTK, and netif_free().

Here is the call graph for this function:

◆ netfront_probe()

static int netfront_probe ( device_t  dev)
static

Entry point to this code when a new device is created. Allocate the basic structures and the ring buffers for communication with the backend, and inform the backend of the appropriate details for those. Switch to Connected state.

Definition at line 378 of file netfront.c.

◆ netfront_resume()

static int netfront_resume ( device_t  dev)
static

We are reconnecting to the backend, due to a suspend/resume, or a backend driver restart. We tear down our netif structure and recreate it, but leave the device-layer structures intact so that this is transparent to the rest of the kernel.

Definition at line 441 of file netfront.c.

References netfront_carrier_on, netif_disconnect_backend(), netfront_info::num_queues, netfront_info::rxq, netfront_info::txq, xen_suspend_cancelled, XN_RX_LOCK, XN_RX_UNLOCK, XN_TX_LOCK, and XN_TX_UNLOCK.

Here is the call graph for this function:

◆ netfront_suspend()

static int netfront_suspend ( device_t  dev)
static

◆ netif_disconnect_backend()

static void netif_disconnect_backend ( struct netfront_info info)
static

Definition at line 2283 of file netfront.c.

References disconnect_rxq(), disconnect_txq(), netfront_carrier_off, netfront_info::num_queues, netfront_info::rxq, netfront_info::txq, XN_RX_LOCK, XN_RX_UNLOCK, XN_TX_LOCK, and XN_TX_UNLOCK.

Referenced by netfront_backend_changed(), netfront_resume(), and netif_free().

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

◆ netif_free()

static void netif_free ( struct netfront_info info)
static

Definition at line 2267 of file netfront.c.

References netif_disconnect_backend(), netfront_info::rxq, netfront_info::sc_media, netfront_info::txq, netfront_info::xn_ifp, XN_LOCK, xn_stop(), and XN_UNLOCK.

Referenced by netfront_detach(), and talk_to_backend().

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

◆ setup_device()

static int setup_device ( device_t  dev,
struct netfront_info info,
unsigned long  num_queues 
)
static

Definition at line 901 of file netfront.c.

References destroy_rxqs(), destroy_txqs(), netfront_txq::info, netfront_info::num_queues, netfront_info::rxq, setup_rxqs(), setup_txqs(), netfront_info::txq, netfront_rxq::xen_intr_handle, and netfront_txq::xen_intr_handle.

Referenced by talk_to_backend().

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

◆ setup_rxqs()

static int setup_rxqs ( device_t  dev,
struct netfront_info info,
unsigned long  num_queues 
)
static

◆ setup_txqs()

◆ talk_to_backend()

static int talk_to_backend ( device_t  dev,
struct netfront_info info 
)
static

◆ TUNABLE_INT()

TUNABLE_INT ( "hw.xn.enable_lro"  ,
xn_enable_lro 
)

◆ TUNABLE_ULONG()

TUNABLE_ULONG ( "hw.xn.num_queues"  ,
xn_num_queues 
)

◆ write_queue_xenstore_keys()

static int write_queue_xenstore_keys ( device_t  dev,
struct netfront_rxq rxq,
struct netfront_txq txq,
struct xs_transaction *  xst,
bool  hierarchy 
)
static

Definition at line 464 of file netfront.c.

References netfront_rxq::id, netfront_txq::id, netfront_rxq::ring_ref, netfront_txq::ring_ref, netfront_info::rxq, netfront_info::txq, netfront_rxq::xen_intr_handle, netfront_txq::xen_intr_handle, and xs_printf().

Referenced by talk_to_backend().

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

◆ xen_net_read_mac()

static int xen_net_read_mac ( device_t  dev,
uint8_t  mac[] 
)
static

Read the 'mac' node at the given device's node in the store, and parse that as colon-separated octets, placing result the given mac array. mac must be a preallocated array of length ETH_ALEN (as declared in linux/if_ether.h). Return 0 on success, or errno on error.

Definition at line 326 of file netfront.c.

References xs_read().

Referenced by create_netdev(), and talk_to_backend().

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

◆ xn_alloc_one_rx_buffer()

static struct mbuf * xn_alloc_one_rx_buffer ( struct netfront_rxq rxq)
static

Definition at line 1049 of file netfront.c.

Referenced by xn_alloc_rx_buffers().

Here is the caller graph for this function:

◆ xn_alloc_rx_buffers()

◆ xn_alloc_rx_buffers_callout()

static void xn_alloc_rx_buffers_callout ( void *  arg)
static

Definition at line 1120 of file netfront.c.

References xn_alloc_rx_buffers(), XN_RX_LOCK, and XN_RX_UNLOCK.

Referenced by xn_alloc_rx_buffers().

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

◆ xn_assemble_tx_request()

static int xn_assemble_tx_request ( struct netfront_txq txq,
struct mbuf *  m_head 
)
static

Given an mbuf chain, make sure we have enough room and then push it onto the transmit ring.

Defragment the mbuf if necessary.

It is a bit lame, but the netback driver in Linux can't deal with nfrags > MAX_TX_REQ_FRAGS, which is a quirk of the Linux network stack.

The FreeBSD TCP stack, with TSO enabled, can produce a chain of mbufs longer than Linux can handle. Make sure we don't pass a too-long chain over to the other side by dropping the packet. It doesn't look like there is currently a way to tell the TCP stack to generate a shorter chain of packets.

CSUM_TSO requires checksum offloading. Some versions of FreeBSD fail to set CSUM_TCP in the CSUM_TSO case, so we have to test for CSUM_TSO explicitly.

Definition at line 1531 of file netfront.c.

References get_id_from_freelist(), gnttab_claim_grant_reference(), gnttab_grant_foreign_access_ref(), netfront_txq::grant_ref, netfront_txq::gref_head, ifp, netfront_txq::info, MAX_TX_REQ_FRAGS, netfront_info::maxfrags, netfront_txq::mbufs, netfront_txq::mbufs_cnt, NET_TX_RING_SIZE, netfront_txq::ring, netfront_info::txq, virt_to_mfn, netfront_info::xbdev, xn_count_frags(), netfront_info::xn_ifp, and xn_txeof().

Referenced by xn_txq_mq_start_locked().

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

◆ xn_configure_features()

static int xn_configure_features ( struct netfront_info np)
static

Definition at line 2036 of file netfront.c.

References ifp, netfront_rxq::lro, netfront_info::num_queues, netfront_info::rxq, netfront_info::xbdev, XN_CSUM_FEATURES, xn_enable_lro, and netfront_info::xn_ifp.

Referenced by xn_connect().

Here is the caller graph for this function:

◆ xn_connect()

static int xn_connect ( struct netfront_info np)
static

Definition at line 1923 of file netfront.c.

References netfront_carrier_on, netfront_info::num_queues, netfront_info::rxq, talk_to_backend(), netfront_info::txq, netfront_info::xbdev, xn_configure_features(), xn_query_features(), xn_rebuild_rx_bufs(), xn_release_tx_bufs(), and xs_scanf().

Referenced by netfront_backend_changed().

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

◆ xn_count_frags()

static int xn_count_frags ( struct mbuf *  m)
inlinestatic

Count the number of fragments in an mbuf chain.

Surprisingly, there isn't an M* macro for this.

Definition at line 1516 of file netfront.c.

Referenced by xn_assemble_tx_request().

Here is the caller graph for this function:

◆ xn_get_extras()

static int xn_get_extras ( struct netfront_rxq rxq,
struct netif_extra_info *  extras,
RING_IDX  rp,
RING_IDX *  cons 
)
static

Definition at line 1369 of file netfront.c.

References netfront_rxq::ring, xn_get_rx_mbuf(), xn_get_rx_ref(), and xn_move_rx_slot().

Referenced by xn_get_responses().

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

◆ xn_get_responses()

static int xn_get_responses ( struct netfront_rxq rxq,
struct netfront_rx_info rinfo,
RING_IDX  rp,
RING_IDX *  cons,
struct mbuf **  list 
)
static

◆ xn_get_rx_mbuf()

static struct mbuf * xn_get_rx_mbuf ( struct netfront_rxq rxq,
RING_IDX  ri 
)
inlinestatic

Definition at line 282 of file netfront.c.

References netfront_rxq::mbufs, and xn_rxidx().

Referenced by xn_get_extras(), xn_get_responses(), and xn_rebuild_rx_bufs().

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

◆ xn_get_rx_ref()

static grant_ref_t xn_get_rx_ref ( struct netfront_rxq rxq,
RING_IDX  ri 
)
inlinestatic

Definition at line 294 of file netfront.c.

References netfront_rxq::grant_ref, and xn_rxidx().

Referenced by xn_get_extras(), xn_get_responses(), and xn_rebuild_rx_bufs().

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

◆ xn_ifinit()

static void xn_ifinit ( void *  xsc)
static

Definition at line 1732 of file netfront.c.

References xn_ifinit_locked(), XN_LOCK, and XN_UNLOCK.

Referenced by create_netdev(), and xn_ioctl().

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

◆ xn_ifinit_locked()

static void xn_ifinit_locked ( struct netfront_info np)
static

Definition at line 1701 of file netfront.c.

References ifp, netfront_carrier_ok, netfront_info::num_queues, netfront_rxq::ring, netfront_info::rxq, xn_alloc_rx_buffers(), netfront_info::xn_ifp, XN_LOCK_ASSERT, XN_RX_LOCK, XN_RX_UNLOCK, xn_rxeof(), and xn_stop().

Referenced by xn_ifinit(), and xn_ioctl().

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

◆ xn_ifmedia_sts()

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

Definition at line 2311 of file netfront.c.

Referenced by create_netdev().

Here is the caller graph for this function:

◆ xn_ifmedia_upd()

static int xn_ifmedia_upd ( struct ifnet *  ifp)
static

Definition at line 2304 of file netfront.c.

Referenced by create_netdev().

Here is the caller graph for this function:

◆ xn_intr()

static void xn_intr ( void *  xsc)
static

Definition at line 1343 of file netfront.c.

References netfront_txq::id, netfront_txq::info, netfront_info::rxq, netfront_info::txq, xn_rxq_intr(), and xn_txq_intr().

Referenced by setup_txqs().

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

◆ xn_ioctl()

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

Definition at line 1742 of file netfront.c.

References ifp, netfront_carrier_off, netfront_info::sc_media, netfront_info::xbdev, XN_CSUM_FEATURES, netfront_info::xn_if_flags, xn_ifinit(), xn_ifinit_locked(), XN_LOCK, netfront_info::xn_reset, xn_stop(), XN_UNLOCK, and xs_rm().

Referenced by create_netdev().

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

◆ xn_kick_rings()

static void xn_kick_rings ( struct netfront_info np)
static

Definition at line 1972 of file netfront.c.

References netfront_info::num_queues, netfront_info::rxq, netfront_info::txq, netfront_txq::xen_intr_handle, xn_alloc_rx_buffers(), XN_RX_LOCK, XN_RX_UNLOCK, XN_TX_LOCK, XN_TX_UNLOCK, and xn_txeof().

Referenced by netfront_backend_changed().

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

◆ xn_move_rx_slot()

static void xn_move_rx_slot ( struct netfront_rxq rxq,
struct mbuf *  m,
grant_ref_t  ref 
)
static

Definition at line 1355 of file netfront.c.

References netfront_rxq::grant_ref, netfront_rxq::mbufs, netfront_rxq::ring, and xn_rxidx().

Referenced by xn_get_extras(), and xn_get_responses().

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

◆ xn_qflush()

static void xn_qflush ( struct ifnet *  ifp)
static

Definition at line 2178 of file netfront.c.

References netfront_txq::br, ifp, netfront_info::num_queues, netfront_info::txq, XN_TX_LOCK, and XN_TX_UNLOCK.

Referenced by create_netdev().

Here is the caller graph for this function:

◆ xn_query_features()

static void xn_query_features ( struct netfront_info np)
static

Definition at line 1992 of file netfront.c.

References MAX_TX_REQ_FRAGS, netfront_info::maxfrags, netfront_info::xbdev, netfront_info::xn_ifp, and xs_scanf().

Referenced by xn_connect().

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

◆ xn_rebuild_rx_bufs()

static void xn_rebuild_rx_bufs ( struct netfront_rxq rxq)
static

Definition at line 1889 of file netfront.c.

References gnttab_grant_foreign_access_ref(), netfront_rxq::grant_ref, netfront_rxq::info, netfront_rxq::mbufs, NET_RX_RING_SIZE, netfront_rxq::ring, netfront_info::xbdev, xn_get_rx_mbuf(), and xn_get_rx_ref().

Referenced by xn_connect().

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

◆ xn_release_rx_bufs()

static void xn_release_rx_bufs ( struct netfront_rxq rxq)
static

Definition at line 1131 of file netfront.c.

References gnttab_end_foreign_access_ref(), gnttab_release_grant_reference(), netfront_rxq::grant_ref, netfront_rxq::gref_head, netfront_rxq::mbufs, and NET_RX_RING_SIZE.

Referenced by disconnect_rxq().

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

◆ xn_release_tx_bufs()

static void xn_release_tx_bufs ( struct netfront_txq txq)
static

Definition at line 1018 of file netfront.c.

References add_id_to_freelist(), gnttab_end_foreign_access_ref(), gnttab_release_grant_reference(), netfront_txq::grant_ref, netfront_txq::gref_head, netfront_txq::mbufs, netfront_txq::mbufs_cnt, and NET_TX_RING_SIZE.

Referenced by disconnect_txq(), and xn_connect().

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

◆ xn_rxeof()

static void xn_rxeof ( struct netfront_rxq rxq)
static

Definition at line 1155 of file netfront.c.

References netfront_rx_info::extras, ifp, netfront_rxq::info, netfront_rxq::lro, netfront_carrier_ok, netfront_rxq::ring, netfront_rx_info::rx, netfront_info::rxq, xn_alloc_rx_buffers(), xn_get_responses(), netfront_info::xn_ifp, and XN_RX_LOCK_ASSERT.

Referenced by xn_ifinit_locked(), and xn_rxq_intr().

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

◆ xn_rxidx()

static int xn_rxidx ( RING_IDX  idx)
inlinestatic

Definition at line 275 of file netfront.c.

References NET_RX_RING_SIZE.

Referenced by xn_alloc_rx_buffers(), xn_get_rx_mbuf(), xn_get_rx_ref(), and xn_move_rx_slot().

Here is the caller graph for this function:

◆ xn_rxq_intr()

static void xn_rxq_intr ( struct netfront_rxq rxq)
static

Definition at line 626 of file netfront.c.

References XN_RX_LOCK, XN_RX_UNLOCK, and xn_rxeof().

Referenced by xn_intr().

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

◆ xn_stop()

static void xn_stop ( struct netfront_info sc)
static

Definition at line 1876 of file netfront.c.

References ifp, netfront_info::xn_ifp, and XN_LOCK_ASSERT.

Referenced by netif_free(), xn_ifinit_locked(), and xn_ioctl().

Here is the caller graph for this function:

◆ xn_tx_slot_available()

static int xn_tx_slot_available ( struct netfront_txq txq)
inlinestatic

Verify that there is sufficient space in the Tx ring buffer for a maximally sized request to be enqueued.

A transmit request requires a transmit descriptor for each packet fragment, plus up to 2 entries for "options" (e.g. TSO).

Definition at line 1011 of file netfront.c.

References MAX_TX_REQ_FRAGS, netfront_txq::ring, and netfront_info::txq.

Referenced by xn_txq_mq_start_locked().

Here is the caller graph for this function:

◆ xn_txeof()

◆ xn_txq_intr()

static void xn_txq_intr ( struct netfront_txq txq)
static

Definition at line 646 of file netfront.c.

References netfront_txq::ring, XN_TX_LOCK, XN_TX_UNLOCK, xn_txeof(), and xn_txq_start().

Referenced by xn_intr().

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

◆ xn_txq_mq_start()

static int xn_txq_mq_start ( struct ifnet *  ifp,
struct mbuf *  m 
)
static

Definition at line 2144 of file netfront.c.

References netfront_txq::br, netfront_txq::defrtask, ifp, netfront_carrier_ok, netfront_info::num_queues, netfront_txq::tq, netfront_info::txq, XN_TX_TRYLOCK, XN_TX_UNLOCK, and xn_txq_mq_start_locked().

Referenced by create_netdev().

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

◆ xn_txq_mq_start_locked()

static int xn_txq_mq_start_locked ( struct netfront_txq txq,
struct mbuf *  m 
)
static

Definition at line 2090 of file netfront.c.

References netfront_txq::br, netfront_txq::full, ifp, netfront_txq::info, netfront_carrier_ok, notify(), netfront_txq::ring, netfront_txq::xen_intr_handle, xn_assemble_tx_request(), netfront_info::xn_ifp, XN_TX_LOCK_ASSERT, and xn_tx_slot_available().

Referenced by xn_txq_mq_start(), and xn_txq_start().

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

◆ xn_txq_start()

static void xn_txq_start ( struct netfront_txq txq)
static

Definition at line 635 of file netfront.c.

References netfront_txq::br, ifp, netfront_txq::info, netfront_info::txq, netfront_info::xn_ifp, XN_TX_LOCK_ASSERT, and xn_txq_mq_start_locked().

Referenced by xn_txeof(), xn_txq_intr(), and xn_txq_tq_deferred().

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

◆ xn_txq_tq_deferred()

static void xn_txq_tq_deferred ( void *  xtxq,
int  pending 
)
static

Definition at line 657 of file netfront.c.

References XN_TX_LOCK, XN_TX_UNLOCK, and xn_txq_start().

Referenced by setup_txqs().

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

Variable Documentation

◆ netfront_devclass

devclass_t netfront_devclass

Definition at line 2339 of file netfront.c.

◆ netfront_driver

driver_t netfront_driver
static
Initial value:
= {
"xn",
sizeof(struct netfront_info),
}
static device_method_t netfront_methods[]
Definition: netfront.c:2319

Definition at line 2334 of file netfront.c.

◆ netfront_methods

device_method_t netfront_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, netfront_probe),
DEVMETHOD(device_attach, netfront_attach),
DEVMETHOD(device_detach, netfront_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, netfront_suspend),
DEVMETHOD(device_resume, netfront_resume),
DEVMETHOD(xenbus_otherend_changed, netfront_backend_changed),
DEVMETHOD_END
}
static void netfront_backend_changed(device_t dev, XenbusState newstate)
Definition: netfront.c:959
static int netfront_attach(device_t dev)
Definition: netfront.c:393
static int netfront_detach(device_t dev)
Definition: netfront.c:2255
static int netfront_probe(device_t dev)
Definition: netfront.c:378
static int netfront_resume(device_t dev)
Definition: netfront.c:441
static int netfront_suspend(device_t dev)
Definition: netfront.c:417

Definition at line 2319 of file netfront.c.

◆ xn_enable_lro

int xn_enable_lro = 1
static

Definition at line 90 of file netfront.c.

Referenced by netfront_attach(), and xn_configure_features().

◆ xn_num_queues

unsigned long xn_num_queues = 4
static

Definition at line 96 of file netfront.c.

Referenced by netfront_attach(), and talk_to_backend().