Module Name: src
Committed By: bouyer
Date: Thu Sep 1 12:29:00 UTC 2022
Modified Files:
src/sys/arch/xen/x86: xen_shm_machdep.c
src/sys/arch/xen/xen: pciback.c xbdback_xenbus.c xennetback_xenbus.c
Log Message:
Add PVH support for backend drivers grant operation.
Now a domU in a PVH dom0 boots multiuser.
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/x86/xen_shm_machdep.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/xen/pciback.c
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/xen/xen/xbdback_xenbus.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/xen/xen/xennetback_xenbus.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/xen/x86/xen_shm_machdep.c
diff -u src/sys/arch/xen/x86/xen_shm_machdep.c:1.17 src/sys/arch/xen/x86/xen_shm_machdep.c:1.18
--- src/sys/arch/xen/x86/xen_shm_machdep.c:1.17 Sun Feb 21 20:11:59 2021
+++ src/sys/arch/xen/x86/xen_shm_machdep.c Thu Sep 1 12:29:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $ */
+/* $NetBSD: xen_shm_machdep.c,v 1.18 2022/09/01 12:29:00 bouyer Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.17 2021/02/21 20:11:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.18 2022/09/01 12:29:00 bouyer Exp $");
+
+#include "opt_xen.h"
#include <sys/types.h>
#include <sys/param.h>
@@ -39,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: xen_shm_mach
#include <xen/hypervisor.h>
#include <xen/xen.h>
#include <xen/evtchn.h>
+#include <xen/xenmem.h>
#include <xen/xen_shm.h>
/*
@@ -58,15 +61,28 @@ xen_shm_map(int nentries, int domid, gra
{
gnttab_map_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
int ret, i;
+#ifndef XENPV
+ paddr_t base_paddr;
+#endif
+
#ifdef DIAGNOSTIC
if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
panic("xen_shm_map: %d entries", nentries);
}
#endif
+#ifndef XENPV
+ base_paddr = xenmem_alloc_pa(nentries * PAGE_SIZE, PAGE_SIZE, false);
+ if (base_paddr == 0)
+ return ENOMEM;
+#endif
for (i = 0; i < nentries; i++) {
+#ifndef XENPV
+ op[i].host_addr = base_paddr + i * PAGE_SIZE;
+#else
op[i].host_addr = va + i * PAGE_SIZE;
+#endif
op[i].dom = domid;
op[i].ref = grefp[i];
op[i].flags = GNTMAP_host_map |
@@ -79,7 +95,8 @@ xen_shm_map(int nentries, int domid, gra
printf("%s: HYPERVISOR_grant_table_op failed %d\n", __func__,
ret);
#endif
- return EINVAL;
+ ret = EINVAL;
+ goto err1;
}
/*
@@ -116,7 +133,12 @@ xen_shm_map(int nentries, int domid, gra
*/
for (i = uncnt = 0; i < nentries; i++) {
if (op[i].status == 0) {
+#ifndef XENPV
+ unop[uncnt].host_addr =
+ base_paddr + i * PAGE_SIZE;
+#else
unop[uncnt].host_addr = va + i * PAGE_SIZE;
+#endif
unop[uncnt].dev_bus_addr = 0;
unop[uncnt].handle = handlep[i];
uncnt++;
@@ -134,10 +156,23 @@ xen_shm_map(int nentries, int domid, gra
printf("%s: HYPERVISOR_grant_table_op bad entry\n",
__func__);
#endif
- return EINVAL;
+ ret = EINVAL;
+ goto err1;
+ }
+#ifndef XENPV
+ for (i = 0; i < nentries; i++) {
+ pmap_kenter_pa(va + i * PAGE_SIZE,
+ base_paddr + i * PAGE_SIZE,
+ VM_PROT_READ | VM_PROT_WRITE, 0);
}
+#endif
return 0;
+err1:
+#ifndef XENPV
+ xenmem_free_pa(base_paddr, nentries * PAGE_SIZE);
+#endif
+ return ret;
}
void
@@ -145,6 +180,11 @@ xen_shm_unmap(vaddr_t va, int nentries,
{
gnttab_unmap_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
int ret, i;
+#ifndef XENPV
+ paddr_t base_paddr;
+ if (pmap_extract(pmap_kernel(), va, &base_paddr) != true)
+ panic("xen_shm_unmap: unmapped va");
+#endif
#ifdef DIAGNOSTIC
if (nentries > XENSHM_MAX_PAGES_PER_REQUEST) {
@@ -153,7 +193,12 @@ xen_shm_unmap(vaddr_t va, int nentries,
#endif
for (i = 0; i < nentries; i++) {
+#ifndef XENPV
+ pmap_kremove(va + i * PAGE_SIZE, PAGE_SIZE);
+ op[i].host_addr = base_paddr + i * PAGE_SIZE;
+#else
op[i].host_addr = va + i * PAGE_SIZE;
+#endif
op[i].dev_bus_addr = 0;
op[i].handle = handlep[i];
}
@@ -163,4 +208,7 @@ xen_shm_unmap(vaddr_t va, int nentries,
if (__predict_false(ret)) {
panic("xen_shm_unmap: unmap failed");
}
+#ifndef XENPV
+ xenmem_free_pa(base_paddr, PAGE_SIZE * nentries);
+#endif
}
Index: src/sys/arch/xen/xen/pciback.c
diff -u src/sys/arch/xen/xen/pciback.c:1.21 src/sys/arch/xen/xen/pciback.c:1.22
--- src/sys/arch/xen/xen/pciback.c:1.21 Tue Apr 7 11:47:06 2020
+++ src/sys/arch/xen/xen/pciback.c Thu Sep 1 12:29:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $ */
+/* $NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $ */
/*
* Copyright (c) 2009 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.22 2022/09/01 12:29:00 bouyer Exp $");
#include "opt_xen.h"
@@ -48,6 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: pciback.c,v
#include <xen/hypervisor.h>
#include <xen/evtchn.h>
#include <xen/granttables.h>
+#include <xen/xenmem.h>
#include <xen/include/public/io/pciif.h>
#include <xen/xenbus.h>
@@ -188,6 +189,7 @@ struct pb_xenbus_instance {
/* communication with the domU */
unsigned int pbx_evtchn; /* our even channel */
struct intrhand *pbx_ih;
+ paddr_t *pbx_sh_info_pa;
struct xen_pci_sharedinfo *pbx_sh_info;
struct xen_pci_op op;
grant_handle_t pbx_shinfo_handle; /* to unmap shared page */
@@ -529,8 +531,13 @@ pciback_xenbus_destroy(void *arg)
pbxi, pb_xenbus_instance, pbx_next);
mutex_exit(&pb_xenbus_lock);
+
if (pbxi->pbx_sh_info) {
+#ifndef XENPV
+ op.host_addr = pbxi->pbx_sh_info_pa;
+#else
op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
+#endif
op.handle = pbxi->pbx_shinfo_handle;
op.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -539,6 +546,12 @@ pciback_xenbus_destroy(void *arg)
aprint_error("pciback: unmap_grant_ref failed: %d\n",
err);
}
+#ifndef XENPV
+ if (pbxi->pbx_sh_info_pa) {
+ pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
+ xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+ }
+#endif
SLIST_FOREACH(pbd, &pbxi->pbx_pb_pci_dev, pb_guest_next) {
pbd->pbx_instance = NULL;
}
@@ -593,7 +606,20 @@ pciback_xenbus_frontend_changed(void *ar
xbusd->xbusd_otherend);
break;
}
+#ifndef XENPV
+ pbxi->pbx_sh_info_pa =
+ xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
+ if (pbxi->pbx_sh_info_pa == 0) {
+ xenbus_dev_fatal(xbusd, ENOMEM,
+ "can't get PA for ring", xbusd->xbusd_otherend);
+ goto err2;
+ }
+ pmap_kenter_pa((vaddr_t)pbxi->pbx_sh_info, pbxi->pbx_sh_info_pa,
+ VM_PROT_READ | VM_PROT_WRITE, 0);
+ op.host_addr = pbxi->pbx_sh_info_pa;
+#else
op.host_addr = (vaddr_t)pbxi->pbx_sh_info;
+#endif
op.flags = GNTMAP_host_map;
op.ref = shared_ref;
op.dom = pbxi->pbx_domid;
@@ -640,6 +666,11 @@ pciback_xenbus_frontend_changed(void *ar
}
return;
err1:
+#ifndef XENPV
+ pmap_kremove((vaddr_t)pbxi->pbx_sh_info, PAGE_SIZE);
+ xenmem_free_pa(pbxi->pbx_sh_info_pa, PAGE_SIZE);
+err2:
+#endif
uvm_km_free(kernel_map, (vaddr_t)pbxi->pbx_sh_info,
PAGE_SIZE, UVM_KMF_VAONLY);
}
Index: src/sys/arch/xen/xen/xbdback_xenbus.c
diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.99 src/sys/arch/xen/xen/xbdback_xenbus.c:1.100
--- src/sys/arch/xen/xen/xbdback_xenbus.c:1.99 Wed Jul 28 22:17:49 2021
+++ src/sys/arch/xen/xen/xbdback_xenbus.c Thu Sep 1 12:29:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $ */
+/* $NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.99 2021/07/28 22:17:49 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.100 2022/09/01 12:29:00 bouyer Exp $");
+
+#include "opt_xen.h"
#include <sys/buf.h>
#include <sys/condvar.h>
@@ -46,8 +48,10 @@ __KERNEL_RCSID(0, "$NetBSD: xbdback_xenb
#include <sys/types.h>
#include <sys/vnode.h>
+#include <xen/intr.h>
#include <xen/hypervisor.h>
#include <xen/xen.h>
+#include <xen/xenmem.h>
#include <xen/xen_shm.h>
#include <xen/evtchn.h>
#include <xen/xenbus.h>
@@ -207,6 +211,7 @@ struct xbdback_instance {
enum xbdi_proto xbdi_proto;
grant_handle_t xbdi_ring_handle; /* to unmap the ring */
vaddr_t xbdi_ring_va; /* to unmap the ring */
+ paddr_t xbdi_ring_pa; /* to unmap the ring */
/* disconnection must be postponed until all I/O is done */
int xbdi_refcnt;
/*
@@ -432,10 +437,18 @@ xbdback_xenbus_destroy(void *arg)
/* unregister watch */
if (xbdi->xbdi_watch.node)
xenbus_unwatch_path(&xbdi->xbdi_watch);
-
/* unmap ring */
- if (xbdi->xbdi_ring_va != 0) {
- ungrop.host_addr = xbdi->xbdi_ring_va;
+#ifndef XENPV
+ ungrop.host_addr = xbdi->xbdi_ring_pa;
+ if (xbdi->xbdi_ring_pa != 0) {
+ KASSERT(xbdi->xbdi_ring_va != 0);
+ pmap_kremove(xbdi->xbdi_ring_va, PAGE_SIZE);
+ }
+#else
+ ungrop.host_addr = xbdi->xbdi_ring_va;
+#endif
+
+ if (ungrop.host_addr != 0) {
ungrop.handle = xbdi->xbdi_ring_handle;
ungrop.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -443,9 +456,16 @@ xbdback_xenbus_destroy(void *arg)
if (err)
printf("xbdback %s: unmap_grant_ref failed: %d\n",
xbusd->xbusd_otherend, err);
+#ifndef XENPV
+ xenmem_free_pa(xbdi->xbdi_ring_pa, PAGE_SIZE);
+#endif
+ }
+
+ if (xbdi->xbdi_ring_va != 0) {
uvm_km_free(kernel_map, xbdi->xbdi_ring_va,
PAGE_SIZE, UVM_KMF_VAONLY);
}
+
/* close device */
if (xbdi->xbdi_size) {
const char *name;
@@ -542,8 +562,19 @@ xbdback_connect(struct xbdback_instance
return -1;
}
XENPRINTF(("xbdback %s: connect va 0x%" PRIxVADDR "\n", xbusd->xbusd_path, xbdi->xbdi_ring_va));
-
+#ifndef XENPV
+ xbdi->xbdi_ring_pa = xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
+ if (xbdi->xbdi_ring_pa == 0) {
+ xenbus_dev_fatal(xbusd, ENOMEM,
+ "can't get PA for ring", xbusd->xbusd_otherend);
+ goto err;
+ }
+ pmap_kenter_pa(xbdi->xbdi_ring_va, xbdi->xbdi_ring_pa,
+ VM_PROT_READ | VM_PROT_WRITE, 0);
+ grop.host_addr = xbdi->xbdi_ring_pa;
+#else
grop.host_addr = xbdi->xbdi_ring_va;
+#endif
grop.flags = GNTMAP_host_map;
grop.ref = ring_ref;
grop.dom = xbdi->xbdi_domid;
@@ -554,7 +585,7 @@ xbdback_connect(struct xbdback_instance
xbusd->xbusd_path, err, grop.status);
xenbus_dev_fatal(xbusd, EINVAL,
"can't map ring", xbusd->xbusd_otherend);
- goto err;
+ goto err1;
}
xbdi->xbdi_ring_handle = grop.handle;
XENPRINTF(("xbdback %s: connect grhandle %d\n", xbusd->xbusd_path, grop.handle));
@@ -592,12 +623,12 @@ xbdback_connect(struct xbdback_instance
"can't bind event channel", xbusd->xbusd_otherend);
goto err2;
}
- XENPRINTF(("xbdback %s: connect evchannel %d\n", xbusd->xbusd_path, xbdi->xbdi_evtchn));
xbdi->xbdi_evtchn = evop.u.bind_interdomain.local_port;
+ XENPRINTF(("xbdback %s: connect evchannel %d\n", xbusd->xbusd_path, xbdi->xbdi_evtchn));
- xbdi->xbdi_ih = intr_establish_xname(-1, &xen_pic, xbdi->xbdi_evtchn,
- IST_LEVEL, IPL_BIO, xbdback_evthandler, xbdi, true,
- xbdi->xbdi_name);
+ xbdi->xbdi_ih = xen_intr_establish_xname(-1, &xen_pic,
+ xbdi->xbdi_evtchn, IST_LEVEL, IPL_BIO, xbdback_evthandler, xbdi,
+ true, xbdi->xbdi_name);
KASSERT(xbdi->xbdi_ih != NULL);
aprint_verbose("xbd backend domain %d handle %#x (%d) "
"using event channel %d, protocol %s\n", xbdi->xbdi_domid,
@@ -614,7 +645,11 @@ xbdback_connect(struct xbdback_instance
err2:
/* unmap ring */
+#ifndef XENPV
+ ungrop.host_addr = xbdi->xbdi_ring_pa;
+#else
ungrop.host_addr = xbdi->xbdi_ring_va;
+#endif
ungrop.handle = xbdi->xbdi_ring_handle;
ungrop.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -623,7 +658,12 @@ err2:
aprint_error("xbdback %s: unmap_grant_ref failed: %d\n",
xbusd->xbusd_path, err);
+err1:
+#ifndef XENPV
+ pmap_kremove(xbdi->xbdi_ring_va, PAGE_SIZE);
+ xenmem_free_pa(xbdi->xbdi_ring_pa, PAGE_SIZE);
err:
+#endif
/* free ring VA space */
uvm_km_free(kernel_map, xbdi->xbdi_ring_va, PAGE_SIZE, UVM_KMF_VAONLY);
return -1;
@@ -651,7 +691,7 @@ xbdback_disconnect(struct xbdback_instan
cv_wait(&xbdi->xbdi_cv, &xbdi->xbdi_lock);
mutex_exit(&xbdi->xbdi_lock);
- intr_disestablish(xbdi->xbdi_ih);
+ xen_intr_disestablish(xbdi->xbdi_ih);
xenbus_switch_state(xbdi->xbdi_xbusd, NULL, XenbusStateClosing);
}
Index: src/sys/arch/xen/xen/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.105 src/sys/arch/xen/xen/xennetback_xenbus.c:1.106
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.105 Tue May 5 17:02:01 2020
+++ src/sys/arch/xen/xen/xennetback_xenbus.c Thu Sep 1 12:29:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: xennetback_xenbus.c,v 1.105 2020/05/05 17:02:01 bouyer Exp $ */
+/* $NetBSD: xennetback_xenbus.c,v 1.106 2022/09/01 12:29:00 bouyer Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.105 2020/05/05 17:02:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.106 2022/09/01 12:29:00 bouyer Exp $");
#include "opt_xen.h"
@@ -41,7 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: xennetback_x
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/device.h>
-#include <sys/intr.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -52,12 +51,14 @@ __KERNEL_RCSID(0, "$NetBSD: xennetback_x
#include <net/if_ether.h>
+#include <xen/intr.h>
#include <xen/hypervisor.h>
#include <xen/xen.h>
#include <xen/xen_shm.h>
#include <xen/evtchn.h>
#include <xen/xenbus.h>
#include <xen/xennet_checksum.h>
+#include <xen/xenmem.h>
#include <uvm/uvm.h>
@@ -119,8 +120,10 @@ struct xnetback_instance {
netif_rx_back_ring_t xni_rxring;
grant_handle_t xni_tx_ring_handle; /* to unmap the ring */
grant_handle_t xni_rx_ring_handle;
+ paddr_t xni_tx_ring_pa; /* to unmap the ring */
vaddr_t xni_tx_ring_va; /* to unmap the ring */
- vaddr_t xni_rx_ring_va;
+ paddr_t xni_rx_ring_pa;
+ vaddr_t xni_rx_ring_va;
/* arrays used in xennetback_ifstart(), used for both Rx and Tx */
gnttab_copy_t xni_gop_copy[NB_XMIT_PAGES_BATCH];
@@ -362,7 +365,7 @@ xennetback_xenbus_destroy(void *arg)
if (xneti->xni_ih != NULL) {
hypervisor_mask_event(xneti->xni_evtchn);
- intr_disestablish(xneti->xni_ih);
+ xen_intr_disestablish(xneti->xni_ih);
xneti->xni_ih = NULL;
}
@@ -387,7 +390,11 @@ xennetback_xenbus_destroy(void *arg)
}
if (xneti->xni_txring.sring) {
+#ifndef XENPV
+ op.host_addr = xneti->xni_tx_ring_pa;
+#else
op.host_addr = xneti->xni_tx_ring_va;
+#endif
op.handle = xneti->xni_tx_ring_handle;
op.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -397,7 +404,11 @@ xennetback_xenbus_destroy(void *arg)
"unmap_grant_ref failed: %d\n", err);
}
if (xneti->xni_rxring.sring) {
+#ifndef XENPV
+ op.host_addr = xneti->xni_rx_ring_pa;
+#else
op.host_addr = xneti->xni_rx_ring_va;
+#endif
op.handle = xneti->xni_rx_ring_handle;
op.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -406,6 +417,18 @@ xennetback_xenbus_destroy(void *arg)
aprint_error_ifnet(&xneti->xni_if,
"unmap_grant_ref failed: %d\n", err);
}
+#ifndef XENPV
+ if (xneti->xni_rx_ring_pa != 0) {
+ pmap_kremove(xneti->xni_rx_ring_va, PAGE_SIZE);
+ xenmem_free_pa(xneti->xni_rx_ring_pa, PAGE_SIZE);
+ xneti->xni_rx_ring_pa = 0;
+ }
+ if (xneti->xni_tx_ring_pa != 0) {
+ pmap_kremove(xneti->xni_tx_ring_va, PAGE_SIZE);
+ xenmem_free_pa(xneti->xni_tx_ring_pa, PAGE_SIZE);
+ xneti->xni_tx_ring_pa = 0;
+ }
+#endif
if (xneti->xni_tx_ring_va != 0) {
uvm_km_free(kernel_map, xneti->xni_tx_ring_va,
PAGE_SIZE, UVM_KMF_VAONLY);
@@ -487,7 +510,19 @@ xennetback_connect(struct xnetback_insta
}
rx_ring = (void *)xneti->xni_rx_ring_va;
+#ifndef XENPV
+ xneti->xni_tx_ring_pa = xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
+ if (xneti->xni_tx_ring_pa == 0) {
+ xenbus_dev_fatal(xbusd, ENOMEM,
+ "can't get PA for TX ring", xbusd->xbusd_otherend);
+ goto err2;
+ }
+ op.host_addr = xneti->xni_tx_ring_pa;
+ pmap_kenter_pa(xneti->xni_tx_ring_va, xneti->xni_tx_ring_pa,
+ VM_PROT_READ | VM_PROT_WRITE, 0);
+#else
op.host_addr = xneti->xni_tx_ring_va;
+#endif
op.flags = GNTMAP_host_map;
op.ref = tx_ring_ref;
op.dom = xneti->xni_domid;
@@ -501,7 +536,19 @@ xennetback_connect(struct xnetback_insta
xneti->xni_tx_ring_handle = op.handle;
BACK_RING_INIT(&xneti->xni_txring, tx_ring, PAGE_SIZE);
+#ifndef XENPV
+ xneti->xni_rx_ring_pa = xenmem_alloc_pa(PAGE_SIZE, PAGE_SIZE, false);
+ if (xneti->xni_rx_ring_pa == 0) {
+ xenbus_dev_fatal(xbusd, ENOMEM,
+ "can't get PA for RX ring", xbusd->xbusd_otherend);
+ goto err2;
+ }
+ op.host_addr = xneti->xni_rx_ring_pa;
+ pmap_kenter_pa(xneti->xni_rx_ring_va, xneti->xni_rx_ring_pa,
+ VM_PROT_READ | VM_PROT_WRITE, 0);
+#else
op.host_addr = xneti->xni_rx_ring_va;
+#endif
op.flags = GNTMAP_host_map;
op.ref = rx_ring_ref;
op.dom = xneti->xni_domid;
@@ -529,9 +576,9 @@ xennetback_connect(struct xnetback_insta
xneti->xni_status = CONNECTED;
xen_wmb();
- xneti->xni_ih = intr_establish_xname(-1, &xen_pic, xneti->xni_evtchn,
- IST_LEVEL, IPL_NET, xennetback_evthandler, xneti, false,
- xneti->xni_if.if_xname);
+ xneti->xni_ih = xen_intr_establish_xname(-1, &xen_pic,
+ xneti->xni_evtchn, IST_LEVEL, IPL_NET, xennetback_evthandler,
+ xneti, false, xneti->xni_if.if_xname);
KASSERT(xneti->xni_ih != NULL);
xennetback_ifinit(&xneti->xni_if);
hypervisor_unmask_event(xneti->xni_evtchn);
@@ -541,7 +588,11 @@ xennetback_connect(struct xnetback_insta
err2:
/* unmap rings */
if (xneti->xni_tx_ring_handle != 0) {
+#ifndef XENPV
+ uop.host_addr = xneti->xni_tx_ring_pa;
+#else
uop.host_addr = xneti->xni_tx_ring_va;
+#endif
uop.handle = xneti->xni_tx_ring_handle;
uop.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -552,7 +603,11 @@ err2:
}
if (xneti->xni_rx_ring_handle != 0) {
+#ifndef XENPV
+ uop.host_addr = xneti->xni_rx_ring_pa;
+#else
uop.host_addr = xneti->xni_rx_ring_va;
+#endif
uop.handle = xneti->xni_rx_ring_handle;
uop.dev_bus_addr = 0;
err = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
@@ -561,7 +616,16 @@ err2:
aprint_error_ifnet(&xneti->xni_if,
"unmap_grant_ref failed: %d\n", err);
}
-
+#ifndef XENPV
+ if (xneti->xni_rx_ring_pa != 0) {
+ pmap_kremove(xneti->xni_rx_ring_va, PAGE_SIZE);
+ xenmem_free_pa(xneti->xni_rx_ring_pa, PAGE_SIZE);
+ }
+ if (xneti->xni_tx_ring_pa != 0) {
+ pmap_kremove(xneti->xni_tx_ring_va, PAGE_SIZE);
+ xenmem_free_pa(xneti->xni_tx_ring_pa, PAGE_SIZE);
+ }
+#endif
err1:
/* free rings VA space */
if (xneti->xni_rx_ring_va != 0)
@@ -982,7 +1046,7 @@ mbuf_fail:
XENPRINTF(("%s pkt offset %d size %d id %d req_cons %d\n",
xneti->xni_if.if_xname, txreq.offset,
- txreq.size, txreq.id, MASK_NETIF_TX_IDX(req_cons)));
+ txreq.size, txreq.id, req_cons & (RING_SIZE(&xneti->xni_txring) - 1)));
xst = &xneti->xni_xstate[queued];
xst->xs_m = (m0 == NULL || m == m0) ? m : NULL;
@@ -1362,10 +1426,6 @@ xennetback_ifstop(struct ifnet *ifp, int
ifp->if_flags &= ~IFF_RUNNING;
ifp->if_timer = 0;
if (xneti->xni_status == CONNECTED) {
- XENPRINTF(("%s: req_prod 0x%x resp_prod 0x%x req_cons 0x%x "
- "event 0x%x\n", ifp->if_xname, xneti->xni_txring->req_prod,
- xneti->xni_txring->resp_prod, xneti->xni_txring->req_cons,
- xneti->xni_txring->event));
xennetback_evthandler(ifp->if_softc); /* flush pending RX requests */
}
splx(s);