Skip to content

Commit 57a6842

Browse files
committed
Peer review feedback (thank you Copilot)
1 parent 1102b81 commit 57a6842

36 files changed

Lines changed: 193 additions & 278 deletions

src/port/versal/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Toolchain: ARM GNU aarch64-none-elf-gcc (tested with 14.3.rel1).
66
#
7-
# UNTESTED ON HARDWARE -- structural scaffold mirroring src/port/zcu102/.
7+
# Brought up on a VMK180 (Cortex-A72): DHCP, ICMP ping and UDP echo work.
88

99
CROSS_COMPILE ?= aarch64-none-elf-
1010
CC := $(CROSS_COMPILE)gcc

src/port/versal/board.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
* and the published `versal.dtsi` device tree. No Xilinx BSP header
2525
* (xparameters.h) or xilstandalone code is referenced.
2626
*
27-
* UNTESTED ON HARDWARE -- code-only scaffold while the lab board is
28-
* unavailable. The structure mirrors src/port/zcu102/. Key
29-
* differences from ZynqMP are:
27+
* Brought up on a VMK180 (Cortex-A72). The structure mirrors
28+
* src/port/zcu102/. Key differences from ZynqMP are:
3029
* - Cortex-A72 (not A53), with PLM handoff at EL2
3130
* - GICv3 distributor + redistributor (no GICv2 legacy GICC)
3231
* - ARM PL011 UART (not Cadence)

src/port/versal/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* along with this program; if not, write to the Free Software
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*
21-
* wolfIP configuration for Xilinx ZCU102 (UltraScale+ MPSoC, A53-0 EL3
22-
* bare-metal). UDP-only profile aimed at deterministic DAL-C use.
21+
* wolfIP configuration for Xilinx Versal Gen 1 / VMK180 (Cortex-A72
22+
* EL3 bare-metal). UDP-only profile aimed at deterministic DAL-C use.
2323
*/
2424
#ifndef WOLF_CONFIG_H
2525
#define WOLF_CONFIG_H

src/port/versal/entropy.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
* along with this program; if not, write to the Free Software
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*
21-
* MemUse-pattern entropy source for the wolfIP ZCU102 port.
21+
* MemUse-pattern entropy source for the wolfIP Versal port.
2222
*
23-
* The ZCU102's UltraScale+ PS does not ship a hardware TRNG that is
24-
* usable from EL3 bare-metal without the PMU firmware and CSU helpers.
23+
* The Versal PS does not ship a hardware TRNG that is usable from EL3
24+
* bare-metal without the PLM firmware and its helpers.
2525
* This source produces non-deterministic 32-bit words by sampling the
26-
* Cortex-A53 virtual count register (CNTVCT_EL0) before and after a
26+
* Cortex-A72 virtual count register (CNTVCT_EL0) before and after a
2727
* memory-access loop that touches a state buffer larger than the L1
2828
* data cache. The cache-miss / line-fill / write-allocate timing
2929
* variance is the entropy source - the same primitive wolfCrypt's
@@ -35,19 +35,19 @@
3535
* ephemeral source ports, IP fragment ID) need unpredictable bits,
3636
* not uniformly-distributed cryptographic randomness. For crypto-
3737
* grade seeding the port should be rebuilt with the full wolfCrypt
38-
* wc_Entropy_Get() in place of zcu102_get_random32().
38+
* wc_Entropy_Get() in place of versal_get_random32().
3939
*
4040
* Algorithm per call:
4141
* 1. t0 = CNTVCT_EL0
4242
* 2. Walk state[] performing read+xor+write; ~256 accesses spans
43-
* multiple L1 cache lines on this 32 KB / 4-way A53 cache.
43+
* multiple L1 cache lines on this 32 KB / 2-way A72 cache.
4444
* 3. t1 = CNTVCT_EL0
4545
* 4. Fold (t1 - t0) into the rolling 64-bit accumulator and
4646
* perturb state[] so the next call diverges.
4747
* 5. Apply a non-cryptographic finaliser (xorshift) and return
4848
* the low 32 bits.
4949
*
50-
* The state buffer is 1024 bytes (sized to span the A53's 64-byte
50+
* The state buffer is 1024 bytes (sized to span the A72's 64-byte
5151
* line size 16 times, ensuring at least a handful of cache misses
5252
* per call even on a warm cache).
5353
*/
@@ -70,7 +70,7 @@ static inline uint64_t cntvct_el0(void)
7070
/* Return a 32-bit value with low predictability, suitable for
7171
* protocol identifiers (DHCP xid, DNS id, TCP ISN, ephemeral port,
7272
* IP fragment id). Not crypto-grade; see file header. */
73-
uint32_t zcu102_get_random32(void)
73+
uint32_t versal_get_random32(void)
7474
{
7575
uint64_t t0, t1, delta;
7676
uint64_t acc;

src/port/versal/gem.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Register set per Versal ACAP TRM (AM011) chapter "Gigabit Ethernet
3737
* MAC" / Cadence GEM.
3838
*
39-
* UNTESTED ON HARDWARE -- structural scaffold.
39+
* Brought up on a VMK180 (Cortex-A72 EL3): DHCP, ping and UDP echo.
4040
*/
4141
#include <stdint.h>
4242
#include <string.h>
@@ -48,7 +48,7 @@
4848
#include "gem.h"
4949
#include "phy_dp83867.h"
5050

51-
/* Cache maintenance helpers for GEM DMA coherency. Cortex-A53 cache
51+
/* Cache maintenance helpers for GEM DMA coherency. Cortex-A72 cache
5252
* line is 64 bytes. With D-cache enabled and BD/buffers in normal
5353
* cacheable memory, CPU writes may sit in L1 D-cache and not be
5454
* visible to the MAC's DMA path. cache_clean() writes back dirty
@@ -542,12 +542,12 @@ void gem_dump_state(void)
542542
* boots with networking up), so we deliberately do NOT touch CRL here.
543543
* The driver's per-MAC soft reset via GEM_NWCTRL is enough to put the
544544
* MAC into a known state on top of the PLM-configured clock. */
545-
static void gem3_set_ref_clk(int speed_mbps)
545+
static void gem0_set_ref_clk(int speed_mbps)
546546
{
547547
(void)speed_mbps; /* clock owned by PLM; nothing to do on Versal */
548548
}
549549

550-
static void gem3_hw_reset(void)
550+
static void gem0_hw_reset(void)
551551
{
552552
#ifdef DEBUG_GEM
553553
volatile uint32_t *gem0ref = (volatile uint32_t *)CRL_APB_GEM0_REF_CTRL;
@@ -564,7 +564,7 @@ static void gem3_hw_reset(void)
564564
/* ---------------------------------------------------------------------
565565
* Public init
566566
* ------------------------------------------------------------------- */
567-
int zcu102_eth_init(struct wolfIP_ll_dev *ll)
567+
int versal_eth_init(struct wolfIP_ll_dev *ll)
568568
{
569569
uint8_t addr;
570570
uint16_t id1;
@@ -573,7 +573,7 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
573573
int fd;
574574
int link_up;
575575

576-
gem3_hw_reset();
576+
gem0_hw_reset();
577577

578578
/* Disable everything before configuring. */
579579
GEM_NWCTRL = 0;
@@ -585,7 +585,7 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
585585

586586
/* Initial NWCFG: gigabit, full duplex, MDC=/96, 1536-byte frames,
587587
* strip FCS from RX, accept broadcasts, multicast via hash,
588-
* DWIDTH_64 because ZynqMP GEM hangs on a 64-bit AXI bus and
588+
* DWIDTH_64 because the Cadence GEM hangs on a 64-bit AXI bus and
589589
* needs this bit for TX to actually transmit (matches U-Boot
590590
* ZYNQ_GEM_DBUS_WIDTH for CONFIG_ARM64).
591591
* COPYALL temporarily on for first-bring-up so we can confirm
@@ -645,7 +645,7 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
645645
cache_clean(&dummy_tx_bd, sizeof(dummy_tx_bd));
646646
cache_clean(&dummy_rx_bd, sizeof(dummy_rx_bd));
647647

648-
/* Clear any stale RX/TX packet classification screening. ZynqMP
648+
/* Clear any stale RX/TX packet classification screening. The Cadence
649649
* GEM has SCREENING_TYPE_1 (TID match) at 0x500+ and SCREENING_TYPE_2
650650
* (compare) at 0x540+. If non-zero, frames may be routed to non-Q0
651651
* queues. Default 0 = all to Q0. */
@@ -660,9 +660,6 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
660660
/* Enable MDIO so we can talk to the PHY. */
661661
GEM_NWCTRL |= NWCTRL_MDEN;
662662

663-
/* Probe MDIO addresses 0..31 for a responsive PHY. ZCU102 routes
664-
* DP83867 to MDIO address 0x0C, but probing makes the driver
665-
* resilient to board variants. */
666663
/* Scan all 32 MDIO addresses, reporting each responsive PHY's ID and
667664
* link status (BMSR reg 1, bit 2). VMK180 can present more than one
668665
* DP83867 on the bus; prefer one that already has copper link so we
@@ -703,7 +700,7 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
703700
}
704701

705702
/* If PHY ended up at 10/100, downshift the MAC speed. The GEM0
706-
* reference clock is owned by the PLM (see gem3_set_ref_clk), so we
703+
* reference clock is owned by the PLM (see gem0_set_ref_clk), so we
707704
* only adjust the MAC config here, not the CRL clock divider. */
708705
if (speed != 1000) {
709706
uint32_t cfg = GEM_NWCFG;
@@ -715,7 +712,7 @@ int zcu102_eth_init(struct wolfIP_ll_dev *ll)
715712
if (!fd)
716713
cfg &= ~NWCFG_FDEN;
717714
GEM_NWCFG = cfg;
718-
gem3_set_ref_clk(speed);
715+
gem0_set_ref_clk(speed);
719716
}
720717

721718
/* Install RX ISR. */

src/port/versal/gem.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
*
55
* This file is part of wolfIP TCP/IP stack.
66
*
7-
* Cadence GEM driver for Xilinx UltraScale+ MPSoC GEM3 (on-board RJ45
8-
* on ZCU102). Single-instance, RGMII, gigabit, polled TX, IRQ-driven
9-
* RX.
7+
* Cadence GEM driver for Versal Gen 1 GEM0 (on-board RJ45 on VMK180).
8+
* Single-instance, RGMII, gigabit, polled TX, IRQ-registered RX that
9+
* is currently drained by polling (see gem.c / eth_poll).
1010
*/
11-
#ifndef ZCU102_GEM_H
12-
#define ZCU102_GEM_H
11+
#ifndef VERSAL_GEM_H
12+
#define VERSAL_GEM_H
1313

1414
#include <stdint.h>
1515
#include "../../../wolfip.h"
1616

17-
/* Initialize GEM3, MMIO clock + reset, PHY, and populate the wolfIP
17+
/* Initialize GEM0, MMIO clock + reset, PHY, and populate the wolfIP
1818
* link-layer device. Returns:
1919
* < 0 on error (negated TRM code)
2020
* bits [7:0] PHY MDIO address used
2121
* bit [8] link_up flag (1 = link is up at end of init)
2222
*/
23-
int zcu102_eth_init(struct wolfIP_ll_dev *ll);
23+
int versal_eth_init(struct wolfIP_ll_dev *ll);
2424

2525
/* MDIO helpers exposed for the PHY driver (phy_dp83867.c). */
2626
int gem_mdio_read(uint8_t phy_addr, uint8_t reg, uint16_t *out);
@@ -32,4 +32,4 @@ uint32_t gem_irq_count(void);
3232
uint32_t gem_rx_frames(void);
3333
uint32_t gem_tx_sent(void);
3434

35-
#endif /* ZCU102_GEM_H */
35+
#endif /* VERSAL_GEM_H */

src/port/versal/gic.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
* the per-CPU redistributor for us; we only re-prime per-INTID config
3333
* for the SPIs we use and enable the CPU interface for our EL.
3434
*
35-
* UNTESTED ON HARDWARE -- structural scaffold mirroring the GICv2
36-
* driver under src/port/zcu102/gic.c. Bring-up steps and edge cases
37-
* (interrupt routing model, security state, GIC600 vs GIC500 quirks)
38-
* will need to be validated when the VMK180 lab board is available.
35+
* Brought up on a VMK180 (Cortex-A72 EL3). Adapted from the GICv2
36+
* driver under src/port/zcu102/gic.c for GICv3 system registers and
37+
* the per-CPU redistributor.
3938
*/
4039
#include <stdint.h>
4140
#include "board.h"

src/port/versal/gic.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* This file is part of wolfIP TCP/IP stack.
66
*/
7-
#ifndef ZCU102_GIC_H
8-
#define ZCU102_GIC_H
7+
#ifndef VERSAL_GIC_H
8+
#define VERSAL_GIC_H
99

1010
#include <stdint.h>
1111

@@ -32,10 +32,10 @@ uint32_t gic_last_intid(void);
3232
* by reading GICC_IAR, calling the registered handler, and EOI'ing.
3333
* Returns the number of interrupts dispatched in this call.
3434
*
35-
* Workaround: on this ZynqMP / Cortex-A53 / GIC-400 combination,
36-
* the GIC latches pending interrupts correctly but the CPU never
37-
* takes the IRQ exception (root cause not pinned). Calling this
38-
* function from the main loop is functionally equivalent. */
35+
* Workaround: on this Versal / Cortex-A72 / GIC-600 (GICv3)
36+
* combination, the GIC latches pending interrupts correctly but the
37+
* CPU never takes the IRQ exception (root cause not pinned). Calling
38+
* this function from the main loop is functionally equivalent. */
3939
uint32_t gic_poll_dispatch(void);
4040

4141
/* Provided by startup.S, asm helpers. */
@@ -46,4 +46,4 @@ void irq_disable(void);
4646
* dispatches, and EOIs the current interrupt. */
4747
void irq_dispatch(void);
4848

49-
#endif /* ZCU102_GIC_H */
49+
#endif /* VERSAL_GIC_H */

src/port/versal/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* wolfIP UDP echo + DHCP client demo for Xilinx Versal Gen 1 (VMK180
2222
* dev board, Cortex-A72 EL3 bare-metal, GEM0 -> on-board RJ45).
2323
*
24-
* UNTESTED ON HARDWARE -- structural scaffold mirroring the ZCU102
25-
* port. See src/port/versal/README.md.
24+
* Brought up on a VMK180 (Cortex-A72 EL3): DHCP, ICMP ping and UDP
25+
* echo all work. See src/port/versal/README.md.
2626
*/
2727
#include <stdint.h>
2828
#include <string.h>
@@ -43,7 +43,7 @@ static uint8_t udp_rx_buf[RX_BUF_SIZE];
4343

4444
/* Override newlib memset/memcpy with plain bytewise versions via
4545
* linker --wrap. The aarch64 newlib memset uses 'dc zva' which hangs
46-
* on this Cortex-A53 setup (DZE=1 in SCTLR_EL3 doesn't help; the
46+
* on this Cortex-A72 setup (DZE=1 in SCTLR_EL3 doesn't help; the
4747
* instruction wedges before completing). The Makefile passes
4848
* -Wl,--wrap=memset -Wl,--wrap=memcpy so all calls get redirected
4949
* to these __wrap_ functions. */
@@ -98,11 +98,11 @@ void exception_report_serror(uint64_t esr, uint64_t elr, uint64_t far,
9898
* to the port-local memuse-pattern entropy source (entropy.c), which
9999
* follows the algorithm of wolfCrypt's wc_Entropy_Get() but is
100100
* self-contained for cert isolation. */
101-
extern uint32_t zcu102_get_random32(void);
101+
extern uint32_t versal_get_random32(void);
102102

103103
uint32_t wolfIP_getrandom(void)
104104
{
105-
return zcu102_get_random32();
105+
return versal_get_random32();
106106
}
107107

108108
static void udp_echo_cb(int fd, uint16_t event, void *arg)
@@ -147,9 +147,9 @@ int main(void)
147147

148148
uart_puts("Bringing up GEM0 (RGMII, DP83867)...\n");
149149
ll = wolfIP_getdev(IPStack);
150-
ret = zcu102_eth_init(ll);
150+
ret = versal_eth_init(ll);
151151
if (ret < 0) {
152-
uart_puts("ERROR: zcu102_eth_init failed: ");
152+
uart_puts("ERROR: versal_eth_init failed: ");
153153
uart_puthex((uint32_t)ret);
154154
uart_puts("\n");
155155
while (1)
@@ -159,8 +159,8 @@ int main(void)
159159
uart_puts(", PHY="); uart_puthex((uint32_t)(ret & 0xFF));
160160
uart_puts("\n");
161161

162-
/* Unmask IRQ at CPU now that GEM3 SPI is enabled at GICD. The CPU
163-
* IRQ exception is currently not delivered on this A53/EL3 setup
162+
/* Unmask IRQ at CPU now that GEM0 SPI is enabled at GICD. The CPU
163+
* IRQ exception is currently not delivered on this A72/EL3 setup
164164
* (open issue - see README); eth_poll() drives gem_isr() from the
165165
* main loop instead. The SGI self-test instrumentation below is
166166
* left in place behind DEBUG_GIC for further investigation. */

src/port/versal/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* along with this program; if not, write to the Free Software
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
*
21-
* Minimal MMU bring-up for A53 at EL3 with a 32-bit virtual address
21+
* Minimal MMU bring-up for A72 at EL3 with a 32-bit virtual address
2222
* space (T0SZ=32, start level L1). Static tables map the full 4 GB VA
2323
* range:
2424
*

0 commit comments

Comments
 (0)