git: 3969b51ffa1c - main - xilinx axi ethernet: allocate memory for buffers.

From: Ruslan Bukin <br_at_FreeBSD.org>
Date: Wed, 26 Mar 2025 15:15:20 UTC
The branch main has been updated by br:

URL: https://cgit.FreeBSD.org/src/commit/?id=3969b51ffa1ca8c863d9a9ddb85ad18aaf2c030c

commit 3969b51ffa1ca8c863d9a9ddb85ad18aaf2c030c
Author:     Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2025-03-26 14:52:29 +0000
Commit:     Ruslan Bukin <br@FreeBSD.org>
CommitDate: 2025-03-26 15:14:13 +0000

    xilinx axi ethernet: allocate memory for buffers.
    
    The xae(9) driver expects that the "memory-region" property is always
    provided in its DTS node, but this is not a case for every platform.
    
    If the property is not provided, then no restriction on buffer location
    is in place and busdma backend could be used.
    
    Since the Xilinx AXI DMA engine driver does not support busdma(9), then
    allocate some memory for buffers manually, so we don't panic.
    
    This fixes operation on Codasip A730.
---
 sys/dev/xilinx/if_xae.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/sys/dev/xilinx/if_xae.c b/sys/dev/xilinx/if_xae.c
index 080b13606525..97e7aa16dda4 100644
--- a/sys/dev/xilinx/if_xae.c
+++ b/sys/dev/xilinx/if_xae.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2019 Ruslan Bukin <br@bsdpad.com>
+ * Copyright (c) 2019-2025 Ruslan Bukin <br@bsdpad.com>
  *
  * This software was developed by SRI International and the University of
  * Cambridge Computer Laboratory (Department of Computer Science and
@@ -43,6 +43,9 @@
 #include <sys/socket.h>
 #include <sys/sockio.h>
 
+#include <vm/vm.h>
+#include <vm/vm_page.h>
+
 #include <net/bpf.h>
 #include <net/if.h>
 #include <net/ethernet.h>
@@ -94,6 +97,7 @@
 #define	NUM_RX_MBUF		16
 #define	BUFRING_SIZE		8192
 #define	MDIO_CLK_DIV_DEFAULT	29
+#define	BUF_NPAGES		512
 
 #define	PHY1_RD(sc, _r)		\
 	xae_miibus_read_reg(sc->dev, 1, _r)
@@ -834,6 +838,8 @@ setup_xdma(struct xae_softc *sc)
 {
 	device_t dev;
 	vmem_t *vmem;
+	vm_paddr_t phys;
+	vm_page_t m;
 	int error;
 
 	dev = sc->dev;
@@ -886,11 +892,19 @@ setup_xdma(struct xae_softc *sc)
 
 	/* Setup bounce buffer */
 	vmem = xdma_get_memory(dev);
-	if (vmem) {
-		xchan_set_memory(sc->xchan_tx, vmem);
-		xchan_set_memory(sc->xchan_rx, vmem);
+	if (!vmem) {
+		m = vm_page_alloc_noobj_contig(VM_ALLOC_WIRED | VM_ALLOC_ZERO,
+		    BUF_NPAGES, 0, BUS_SPACE_MAXADDR_32BIT, PAGE_SIZE, 0,
+		    VM_MEMATTR_DEFAULT);
+		phys = VM_PAGE_TO_PHYS(m);
+		vmem = vmem_create("xdma vmem", 0, 0, PAGE_SIZE, PAGE_SIZE,
+		    M_BESTFIT | M_WAITOK);
+		vmem_add(vmem, phys, BUF_NPAGES * PAGE_SIZE, 0);
 	}
 
+	xchan_set_memory(sc->xchan_tx, vmem);
+	xchan_set_memory(sc->xchan_rx, vmem);
+
 	xdma_prep_sg(sc->xchan_tx,
 	    TX_QUEUE_SIZE,	/* xchan requests queue size */
 	    MCLBYTES,	/* maxsegsize */