Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_net.c
Show All 33 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/linker_set.h> | #include <sys/linker_set.h> | ||||
#include <sys/select.h> | #include <sys/select.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <machine/vmm_snapshot.h> | #include <machine/vmm_snapshot.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#include <net/if.h> /* IFNAMSIZ */ | #include <net/if.h> /* IFNAMSIZ */ | ||||
#ifndef NETMAP_WITH_LIBS | |||||
#define NETMAP_WITH_LIBS | |||||
#endif | |||||
#include <net/netmap_user.h> | |||||
#ifdef BHYVE_SNAPSHOT | |||||
#include "snapshot.h" | |||||
#endif | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
▲ Show 20 Lines • Show All 494 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | ||||
{ | { | ||||
struct pci_vtnet_softc *sc; | struct pci_vtnet_softc *sc; | ||||
char tname[MAXCOMLEN + 1]; | char tname[MAXCOMLEN + 1]; | ||||
int mac_provided; | int mac_provided; | ||||
int mtu_provided; | int mtu_provided; | ||||
unsigned long mtu = ETHERMTU; | unsigned long mtu = ETHERMTU; | ||||
#ifdef BHYVE_SNAPSHOT | |||||
struct vm_snapshot_dev_info *dev_info; | |||||
#endif | |||||
/* | /* | ||||
* Allocate data structures for further virtio initializations. | * Allocate data structures for further virtio initializations. | ||||
* sc also contains a copy of vtnet_vi_consts, since capabilities | * sc also contains a copy of vtnet_vi_consts, since capabilities | ||||
* change depending on the backend. | * change depending on the backend. | ||||
*/ | */ | ||||
sc = calloc(1, sizeof(struct pci_vtnet_softc)); | sc = calloc(1, sizeof(struct pci_vtnet_softc)); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | #endif | ||||
*/ | */ | ||||
sc->tx_in_progress = 0; | sc->tx_in_progress = 0; | ||||
pthread_mutex_init(&sc->tx_mtx, NULL); | pthread_mutex_init(&sc->tx_mtx, NULL); | ||||
pthread_cond_init(&sc->tx_cond, NULL); | pthread_cond_init(&sc->tx_cond, NULL); | ||||
pthread_create(&sc->tx_tid, NULL, pci_vtnet_tx_thread, (void *)sc); | pthread_create(&sc->tx_tid, NULL, pci_vtnet_tx_thread, (void *)sc); | ||||
snprintf(tname, sizeof(tname), "vtnet-%d:%d tx", pi->pi_slot, | snprintf(tname, sizeof(tname), "vtnet-%d:%d tx", pi->pi_slot, | ||||
pi->pi_func); | pi->pi_func); | ||||
pthread_set_name_np(sc->tx_tid, tname); | pthread_set_name_np(sc->tx_tid, tname); | ||||
#ifdef BHYVE_SNAPSHOT | |||||
dev_info = calloc(1, sizeof(*dev_info)); | |||||
if (!dev_info) { | |||||
fprintf(stderr, "Error allocating space for snapshot struct"); | |||||
free(sc); | |||||
return (1); | |||||
} | |||||
dev_info->dev_name = pi->pi_d->pe_emu; | |||||
dev_info->was_restored = 0; | |||||
dev_info->snapshot_cb = pci_snapshot; | |||||
dev_info->meta_data = pi; | |||||
insert_registered_devs(dev_info); | |||||
#endif | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
pci_vtnet_cfgwrite(void *vsc, int offset, int size, uint32_t value) | pci_vtnet_cfgwrite(void *vsc, int offset, int size, uint32_t value) | ||||
{ | { | ||||
struct pci_vtnet_softc *sc = vsc; | struct pci_vtnet_softc *sc = vsc; | ||||
void *ptr; | void *ptr; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | pci_vtnet_snapshot(void *vsc, struct vm_snapshot_meta *meta) | ||||
SNAPSHOT_VAR_OR_LEAVE(sc->vhdrlen, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(sc->vhdrlen, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(sc->be_vhdrlen, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(sc->be_vhdrlen, meta, ret, done); | ||||
done: | done: | ||||
return (ret); | return (ret); | ||||
} | } | ||||
#endif | #endif | ||||
static struct pci_devemu pci_de_vnet = { | struct pci_devemu pci_de_vnet = { | ||||
.pe_emu = "virtio-net", | .pe_emu = "virtio-net", | ||||
.pe_init = pci_vtnet_init, | .pe_init = pci_vtnet_init, | ||||
.pe_barwrite = vi_pci_write, | .pe_barwrite = vi_pci_write, | ||||
.pe_barread = vi_pci_read, | .pe_barread = vi_pci_read, | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
.pe_snapshot = vi_pci_snapshot, | .pe_snapshot = vi_pci_snapshot, | ||||
.pe_pause = vi_pci_pause, | .pe_pause = vi_pci_pause, | ||||
.pe_resume = vi_pci_resume, | .pe_resume = vi_pci_resume, | ||||
#endif | #endif | ||||
}; | }; | ||||
PCI_EMUL_SET(pci_de_vnet); | PCI_EMUL_SET(pci_de_vnet); |