socsvn commit: r307223 - soc2016/vincenzo/head/usr.sbin/bhyve
vincenzo at FreeBSD.org
vincenzo at FreeBSD.org
Fri Aug 5 13:59:01 UTC 2016
Author: vincenzo
Date: Fri Aug 5 13:58:59 2016
New Revision: 307223
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=307223
Log:
bhyve: ptnet: various changes
Modified:
soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c
soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.h
soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c
soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c
Modified: soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c
==============================================================================
--- soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c Fri Aug 5 13:57:46 2016 (r307222)
+++ soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.c Fri Aug 5 13:58:59 2016 (r307223)
@@ -444,13 +444,15 @@
struct ptnetmap_state *
get_ptnetmap(struct net_backend *be)
{
- struct netmap_priv *priv = be->priv;
+ struct netmap_priv *priv;
/* Check that this is a netmap backend. */
- if (be->set_cap != netmap_set_cap) {
+ if (!be || be->set_cap != netmap_set_cap) {
return NULL;
}
+ priv = be->priv;
+
return &priv->ptnetmap;
}
@@ -1075,3 +1077,26 @@
return ret;
}
+
+int
+net_parsemac(char *mac_str, uint8_t *mac_addr)
+{
+ struct ether_addr *ea;
+ char *tmpstr;
+ char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 };
+
+ tmpstr = strsep(&mac_str,"=");
+
+ if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) {
+ ea = ether_aton(mac_str);
+
+ if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) ||
+ memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) {
+ fprintf(stderr, "Invalid MAC %s\n", mac_str);
+ return (EINVAL);
+ } else
+ memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
+ }
+
+ return (0);
+}
Modified: soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.h
==============================================================================
--- soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.h Fri Aug 5 13:57:46 2016 (r307222)
+++ soc2016/vincenzo/head/usr.sbin/bhyve/net_backends.h Fri Aug 5 13:58:59 2016 (r307223)
@@ -28,6 +28,7 @@
#define __NET_BACKENDS_H__
#include <stdint.h>
+#include "mevent.h"
extern int netmap_ioctl_counter;
@@ -111,6 +112,11 @@
uint16_t num_rx_slots;
};
+int ptnetmap_get_netmap_if(struct ptnetmap_state *ptn,
+ struct netmap_if_info *nif);
+struct ptnetmap_state * get_ptnetmap(struct net_backend *be);
int ptn_memdev_attach(void *mem_ptr, uint32_t mem_size, uint16_t mem_id);
+int net_parsemac(char *mac_str, uint8_t *mac_addr);
+
#endif /* __NET_BACKENDS_H__ */
Modified: soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c
==============================================================================
--- soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Fri Aug 5 13:57:46 2016 (r307222)
+++ soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Fri Aug 5 13:58:59 2016 (r307223)
@@ -42,6 +42,7 @@
#include "bhyverun.h"
#include "pci_emul.h"
+#include "net_backends.h"
#ifndef PTNET_CSB_ALLOC
#error "Hypervisor-allocated CSB not supported"
@@ -51,12 +52,43 @@
struct ptnet_softc {
struct pci_devinst *pi;
+ struct net_backend *be;
struct ptnetmap_state *ptbe;
+
unsigned int num_rings;
uint32_t ioregs[PTNET_IO_END >> 2];
void *csb;
};
+static int
+ptnet_get_netmap_if(struct ptnet_softc *sc)
+{
+ unsigned int num_rings;
+ struct netmap_if_info nif;
+ int ret;
+
+ ret = ptnetmap_get_netmap_if(sc->ptbe, &nif);
+ if (ret) {
+ return ret;
+ }
+
+ sc->ioregs[PTNET_IO_NIFP_OFS >> 2] = nif.nifp_offset;
+ sc->ioregs[PTNET_IO_NUM_TX_RINGS >> 2] = nif.num_tx_rings;
+ sc->ioregs[PTNET_IO_NUM_RX_RINGS >> 2] = nif.num_rx_rings;
+ sc->ioregs[PTNET_IO_NUM_TX_SLOTS >> 2] = nif.num_tx_slots;
+ sc->ioregs[PTNET_IO_NUM_RX_SLOTS >> 2] = nif.num_rx_slots;
+
+ num_rings = sc->ioregs[PTNET_IO_NUM_TX_RINGS >> 2] +
+ sc->ioregs[PTNET_IO_NUM_RX_RINGS >> 2];
+ if (sc->num_rings && num_rings && sc->num_rings != num_rings) {
+ fprintf(stderr, "Number of rings changed: not supported\n");
+ return EINVAL;
+ }
+ sc->num_rings = num_rings;
+
+ return 0;
+}
+
static uint64_t
ptnet_bar_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
int baridx, uint64_t offset, int size)
@@ -95,6 +127,8 @@
ptnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
{
struct ptnet_softc *sc;
+ uint8_t macaddr[6];
+ int mac_provided = 0;
int ret;
sc = calloc(1, sizeof(*sc));
@@ -107,6 +141,31 @@
pi->pi_arg = sc;
sc->pi = pi;
+ if (opts != NULL) {
+ char *ptopts, *devname;
+
+ devname = ptopts = strdup(opts);
+ (void) strsep(&ptopts, ",");
+
+ if (ptopts != NULL) {
+ ret = net_parsemac(ptopts, macaddr);
+ if (ret != 0) {
+ free(devname);
+ return ret;
+ }
+ mac_provided = 1;
+ }
+
+ sc->be = netbe_init(devname, NULL, sc);
+ if (!sc->be) {
+ fprintf(stderr, "net backend initialization failed\n");
+ }
+
+ free(devname);
+ }
+
+ sc->ptbe = get_ptnetmap(sc->be);
+
/* Initialize PCI configuration space. */
pci_set_cfgdata16(pi, PCIR_VENDOR, PTNETMAP_PCI_VENDOR_ID);
pci_set_cfgdata16(pi, PCIR_DEVICE, PTNETMAP_PCI_NETIF_ID);
@@ -127,9 +186,14 @@
/* Initialize registers and data structures. */
memset(sc->ioregs, 0, sizeof(sc->ioregs));
sc->csb = NULL;
- sc->num_rings = 0;
sc->ptbe = NULL;
+ sc->num_rings = 0;
+ ptnet_get_netmap_if(sc);
+
+ /* Allocate a BAR for MSI-X vectors. */
+ pci_emul_add_msixcap(pi, sc->num_rings, PTNETMAP_MSIX_PCI_BAR);
+
return 0;
}
Modified: soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c
==============================================================================
--- soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c Fri Aug 5 13:57:46 2016 (r307222)
+++ soc2016/vincenzo/head/usr.sbin/bhyve/pci_virtio_net.c Fri Aug 5 13:58:59 2016 (r307223)
@@ -413,29 +413,6 @@
#endif
static int
-pci_vtnet_parsemac(char *mac_str, uint8_t *mac_addr)
-{
- struct ether_addr *ea;
- char *tmpstr;
- char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 };
-
- tmpstr = strsep(&mac_str,"=");
-
- if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) {
- ea = ether_aton(mac_str);
-
- if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) ||
- memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) {
- fprintf(stderr, "Invalid MAC %s\n", mac_str);
- return (EINVAL);
- } else
- memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
- }
-
- return (0);
-}
-
-static int
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
{
MD5_CTX mdctx;
@@ -483,7 +460,7 @@
(void) strsep(&vtopts, ",");
if (vtopts != NULL) {
- err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);
+ err = net_parsemac(vtopts, sc->vsc_config.mac);
if (err != 0) {
free(devname);
return (err);
More information about the svn-soc-all
mailing list