netboot: make the transfer round-trip efficient

Transfer now works on hardware -- the block counter climbs -- but slowly, with
some ACKs missing.  It is ROUND-TRIP bound, not bandwidth bound: stop-and-wait
means one block per round trip, so three things dominated and all three were
conservative bring-up choices rather than considered ones.

  - Block size 256 -> 1024.  A 298 KB image is 1166 blocks at 256 but only 292
    at 1024.  256 was chosen to stay near the only multi-page frame ever proven
    on hardware (a 342-byte DHCP broadcast); large frames are now safe because
    RBFI stops a full ring being overwritten and stop-and-wait keeps exactly
    one frame in flight, so five pages of a fourteen-page budget is never
    contended.  --block 256 remains as a fallback.

  - Host ACK timeout 0.5 s -> 0.1 s.  The round trip is a few milliseconds on
    a LAN, so half a second meant every lost ACK cost half a second.

  - The GC's TI poll slept 500 us up to 20 times, costing up to 10 ms per ACK
    even when the transmit succeeded immediately -- on every block.  It now
    polls without sleeping; a bba_r8 is itself tens of microseconds, so a bare
    loop samples often enough and returns as soon as TI sets.

Absence of TI is explicitly NOT fatal.  TI only means TXFrameDrain handed the
frame to the W5100, so the frame may well have gone out; and if it did not,
the host's retransmit covers it.  Blocking longer would slow the common case
to protect against the rare one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 19:04:52 +02:00
parent e9b1a75bfe
commit ee889eb40f
3 changed files with 43 additions and 14 deletions
+16 -9
View File
@@ -25,13 +25,18 @@ import time
ETHERTYPE = 0x88B5
MAGIC = b"GCUP"
OP_DATA, OP_ACK, OP_DONE = 1, 2, 3
# Default payload 256 bytes -> a ~296-byte frame, which with the 4-byte
# descriptor occupies TWO of the SPRAM ring's 15 pages. That is deliberately
# close to the only multi-page frame ever proven on this hardware (a 342-byte
# DHCP broadcast). 1024-byte payloads make ~1050-byte frames spanning FIVE
# pages, which has never been exercised -- raise --block once small blocks are
# known to work, not before.
BLOCK_DEFAULT = 256
# 1024-byte payloads -> ~1050-byte frames, five of the SPRAM ring's 15 pages.
#
# 256 was the conservative bring-up value, chosen to stay near the only
# multi-page frame ever proven on hardware (a 342-byte DHCP broadcast). Small
# blocks are now known to work, and two things make the large ones safe:
# RBFI stops a full ring being overwritten, and stop-and-wait keeps exactly one
# frame in flight, so five pages of a fourteen-page budget is never contended.
#
# This matters for speed: a 298 KB image is 1166 blocks at 256 bytes but only
# 292 at 1024, and the transfer is round-trip bound, not bandwidth bound. Drop
# back with --block 256 if large frames misbehave.
BLOCK_DEFAULT = 1024
HDR = 26
# The GC's MAC comes from PAR0-5, which the gateware pre-populates with a
# Nintendo OUI. Discovered from the first ACK, so this is only the initial
@@ -53,8 +58,10 @@ def main():
ap = argparse.ArgumentParser()
ap.add_argument("iface", help="network interface facing the GameCube")
ap.add_argument("dol", help=".dol to send")
ap.add_argument("--timeout", type=float, default=0.5,
help="per-block ACK timeout in seconds (default 0.5)")
ap.add_argument("--timeout", type=float, default=0.1,
help="per-block ACK timeout in seconds (default 0.1). "
"The round trip is a few ms on a LAN, so 0.5 made "
"every lost ACK cost half a second.")
ap.add_argument("--retries", type=int, default=20,
help="per-block retransmits before giving up (default 20)")
ap.add_argument("--dest", default="/gc_bba_test.dol",