Implement SCSI WRITE(10), closing the graph's highest-leverage blocker

Direct mirror of the existing READ(10) implementation (FABRIC-3.md §F.1),
data direction flipped: new XHCI_XFER_BOT_DATA_OUT/XHCI_NEXT_ACTION_BOT_DATA_OUT
states, xhci_bot_send_write10()/xhci_bot_write_block()/xhci_bot_write_data_out()
in xhci.c, new SCSI_CMD_WRITE10 opcode and BOT_CMD_WRITE10/BOT_TUR_CHAIN_WRITE10
enum values. usb_blk_write() in blkio_usb.c is real now, no longer the
BLKIO_ENOSUP stub. read_only flips to 0 in blkio_info() now that it's proven.

Verified live end-to-end on all three architectures with a genuine cold-reboot
round-trip (not just a same-session read): BLK-CONFIRM-FORMAT's BAM/reloc
writes and an explicit block content write both completed via clean WRITE10
cycles (CSW PASS), and the written byte read back correctly after a full
kernel rebuild + fresh boot -- amd64=65, aarch64=170, riscv64=201, each at
LBN 32734 on a disposable usbwrite-test.img attached via QEMU usb-storage.

Added Makefile.starkernel's QEMU_EXTRA (empty by default, no behavior change)
to attach the disposable test image for this validation; the drive must be
hotplugged via QMP after boot reaches ok>, not attached at QEMU launch --
attaching before xhci_bringup()'s controller reset means no fresh Port
Status Change event fires (see project_xhci_milestone_2d_polling memory).

Found and reported, not fixed, during testing: EMPTY-BUFFERS
(empty_all_buffers(), block_words.c) does not implement standard Forth-79
semantics -- it force-writes zero to every block on every attached device
instead of discarding cache assignments. This corrupted disk/artemis.img
during an earlier test run; restored from git, confirmed byte-identical.
Avoided in the final validation runs (detach/reattach used instead to force
a fresh read).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZGkimpfyh63EZyRkNbkPD
This commit is contained in:
Robert Allan James
2026-08-28 07:19:31 -04:00
co-authored by Claude Sonnet 5
parent ff67bbdec3
commit 5e9802845a
15 changed files with 89095 additions and 21 deletions
+23 -8
View File
@@ -59,17 +59,29 @@ static int usb_blk_read(blkio_dev_t *dev, uint32_t fblock, void *dst) {
}
static int usb_blk_write(blkio_dev_t *dev, uint32_t fblock, const void *src) {
(void)dev;
(void)fblock;
(void)src;
/* No SCSI WRITE(10) in the xHCI driver yet — read-only this increment,
* see blkio_usb.h's own doc comment. */
return BLKIO_ENOSUP;
if (!dev || !src) return BLKIO_EINVAL;
BlkioUsbState *s = (BlkioUsbState *)dev->state;
if (fblock >= s->total_forth_blocks) return BLKIO_EINVAL;
memcpy(s->xdev->bot_data_buf, src, BLKIO_FORTH_BLOCK_SIZE);
uint32_t lba = fblock * s->scsi_blocks_per_fblock;
if (xhci_bot_write_block(s->xdev, s->slot_id, lba,
(uint16_t)s->scsi_blocks_per_fblock,
s->scsi_block_size) != 0) {
return BLKIO_EIO;
}
if (xhci_bot_wait_for_idle(s->xdev, 100000u) != BOT_STATUS_PASS) {
return BLKIO_EIO;
}
return BLKIO_OK;
}
static int usb_blk_flush(blkio_dev_t *dev) {
(void)dev;
return BLKIO_OK; /* nothing buffered to flush — read-only backend */
return BLKIO_OK; /* every write above is already synchronous -- see
* usb_blk_write()'s own xhci_bot_wait_for_idle()
* call -- nothing buffered here to flush. */
}
static int usb_blk_info(blkio_dev_t *dev, blkio_info_t *out) {
@@ -79,7 +91,10 @@ static int usb_blk_info(blkio_dev_t *dev, blkio_info_t *out) {
out->total_blocks = s->total_forth_blocks;
out->phys_sector_size = s->scsi_block_size;
out->phys_size_bytes = (uint64_t)s->total_forth_blocks * BLKIO_FORTH_BLOCK_SIZE;
out->read_only = 1;
out->read_only = 0; /* WRITE(10) verified live end-to-end on amd64,
* 2026-08-28 (FABRIC-3.md §F.1): BLK-CONFIRM-FORMAT's
* BAM/reloc writes and an explicit content write both
* survived a cold reboot and read back correctly. */
return BLKIO_OK;
}