NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
port-sparc64/61053: fdc(4): make the ebus (fdthree) floppy attachment work on Ultra 5/10
>Number: 61053
>Category: port-sparc64
>Synopsis: fdc(4): make the ebus (fdthree) floppy attachment work on Ultra 5/10
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: port-sparc64-maintainer
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Nov 24 00:10:00 +0000 2026
>Originator: Steffan (P.R_Aigis)
>Release: NetBSD 11.1 (patch made against netbsd-11; fdc.c is rev 1.52 on -current too)
>Organization:
>Environment:
NetBSD ultra5 11.1 NetBSD 11.1 (GENERIC) #0: Mon Nov 2 16:34:32 UTC 2026 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/sparc64/compile/GENERIC sparc64
Sun Ultra 5 (UltraSPARC-IIi 400 MHz), PCIO Ebus2 rev 0x01
fdthree at ebus0 addr 3023f0-3023f7, 706000-70600f, 720000-720003 ipl 27
Patch tested with netbsd-11 (11.1_STABLE) GENERIC kernels built from the same tree.
>Description:
The sparc64 fdc(4) driver cannot do I/O on the floppy controller used by PCI-based UltraSPARC machines: the Ultra 5 and Ultra 10, and anything else whose PROM shows the controller as "fdthree". sys/arch/sparc64/conf/GENERIC has the attachment commented out ("#fdc0 at ebus? # fdthree, EXPERIMENTAL"), and share/man/man4/man4.sparc64/fdc.4 says in BUGS that "the ebus attachment does not yet work".
Turning the attachment on is enough to get the controller and the drive attached, because fdmatch() probes the chip by polling and does not need interrupts. But no transfer ever completes:
fdc0 at ebus0 addr 3023f0-3023f7, 706000-70600f, 720000-720003 ipl 27 softpri 7: chip 82077: manual eject
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
fd0: timeout: state 10
fd0: timeout: state 13
fd0a: hard error reading fsbn 0
The driver is written for the SBus controller ("SUNW,fdtwo"): no DMA engine, so the CPU moves every byte in and out of the FIFO from the interrupt handler, TC is pulsed through the auxio register, and the DOR bits mean what Sun says they mean.
fdthree is a PC-style controller. It is an 82077-compatible core in the Super I/O chip at the standard PC offsets (0x3f0-0x3f7 within EBus space), and it does real DMA through one channel of the EBus DMA engine in the PCIO chip. Four things follow, and the driver gets all four wrong:
- The controller's interrupt is routed through its DMA channel, and the channel only passes it on when its interrupt enable bit (DCSR 0x00000010) is set. Nothing sets it, so no interrupt ever reaches the CPU. That accounts for the timeouts above and for the missing "ivec 27" line in vmstat -i.
- TC comes from the DMA channel's byte counter, not from auxio. With nothing to assert it, a read command runs on to the end of the cylinder and returns ST1 0x80 (end of cylinder) at head 1, sector 18. Moving one byte per interrupt across PCI and EBus is also too slow and produces data overruns.
- fdc_reset() writes FDO_FRST|FDO_FDMAEN|FDO_DS (0x0d) to the DOR. On PC wiring bit 0 selects drive 1, so every reset deselects the drive and leaves all motors off, and the recalibrate that follows fails with ST0 0x70 (equipment check).
- Transfers are capped at FDC_MAXIOSIZE, one 8 KB page, so a whole-track request becomes two commands and the second one usually misses its sector and waits a full revolution.
OpenBSD's sparc64 driver has the same disabled ebus attachment and the same limitation, so there is nothing to port from there. Linux drives this hardware with the EBus DMA engine (arch/sparc/include/asm/floppy_64.h).
>How-To-Repeat:
On an Ultra 5 or Ultra 10 with a floppy drive, netbsd-11 or -current:
1. Boot a stock kernel. The controller does not attach at all:
fdthree at ebus0 addr 3023f0-3023f7, 706000-70600f, 720000-720003 ipl 27 not configured
2. Enable the attachment in the kernel config (uncomment the "fdc0 at ebus?" line in GENERIC), build and boot. The controller and the drive attach, as shown in the full description.
3. Try any transfer:
dd if=/dev/rfd0a of=/dev/null bs=18432 count=1
Every request times out and then fails:
fd0: timeout: state 13
fd0a: hard error reading fsbn 0
fdformat(1) presumably fails the same way (not tried).
4. vmstat -i has no "ivec 27" counter, so the interrupt promised by the fdthree "interrupts" property never fires.
>Fix:
Patch follows by mail to gnats-bugs%NetBSD.org@localhost (fdc-ebus-full.diff), a unified diff that applies with "patch -p0" from the top of the source tree. Three files, +324/-8.
I wrote and tested against netbsd-11. fdc.c is at revision 1.52 on both netbsd-11 and -current, so it should apply to -current unchanged; I can re-test there if that helps.
Nothing changes for SBus machines. Every new line runs only when FDC_EBUS is set, and the existing ebus attach already sets that flag (it set it and never used it).
sys/arch/sparc64/dev/fdc.c
- Map reg[1] (the DMA channel) and reg[2] (the floppy aux register) with bus_space_map(), the way cs4231_ebus does, instead of using the PROM's virtual addresses from sparc_promaddr_to_handle(). Those handles access big-endian, so 32-bit values come out byte-swapped; through the bus they come out right. A bad mapping shows up at once, because the channel's top ID nibble has to read back as 0xc (0xc0000000 when the channel is idle).
- fdc_ebus_setup(), called after the drive probe: reset the channel and leave it with INT_EN|TCI_DIS|EN_CNT|BURST_SIZE_16 set, DMA off. That is what lets the controller's interrupts reach the CPU at all. It also sets bit 0x02 of the aux register (high density), which Linux does for this hardware.
- One page-aligned bounce buffer, sized for a whole cylinder (FD_MAX_NSEC * 2 * DEV_BSIZE, 36864 bytes), is allocated, mapped and loaded into DVMA once at attach and zeroed once at allocation. Transfers are copied in and out of it, so the channel never sees the caller's buffer and the floppy can only reach that one buffer.
- fdc_ebus_dma_start(): for a write, copy the data in first, then sync, reset the channel and clear TC, wait for it to go idle, and program DCSR with EN_DMA (plus WRITE for a read, since a device-to-memory transfer is a "write" from the engine's point of view), then the count in DNBR and the address in DNAR, with EN_NEXT. fdc_ebus_dma_stop() waits for the FIFO to drain, clears EN_DMA, syncs and returns the residual count. The sequence follows cs4231_ebus.
- DOIO sends SPECIFY with the no-DMA bit clear and sets itask = RESULT, because only the result phase interrupts in DMA mode. The transfer size clamp now uses the new sc_maxio, which defaults to FDC_MAXIOSIZE so SBus is unchanged and is one cylinder on ebus. That is where the speed came from: a whole cylinder (both sides, 18 KB on 1.44 MB media) is one command now.
- fdc_reset() calls fd_set_motor() afterwards on ebus, which rewrites the DOR the PC way: current drive selected, its motor on, DMA gate on.
- fdc_c_hwintr() acknowledges the DMA channel before doing anything else (DCSR is write-1-to-clear for TC and errors) and reports ERR_PEND if it is set.
- IOTIMEDOUT, DORESET and IOCOMPLETE stop the channel. IOCOMPLETE copies read data out of the bounce buffer, and only after the status check passes, so a failed read cannot hand back stale buffer contents.
- fdc_ebus_shutdown(), registered with pmf_device_register1(): stop DMA, unlock the chip configuration (LOCK with the lock bit clear), reset the chip through the DOR and release the reset, reset the DMA channel, and restore the aux register to the value saved at attach. Without it the PROM's "test floppy" fails after a halt until the next hardware reset, which appears to be because fdconf() LOCKs the chip configuration and the lock survives the resets the PROM does.
sys/arch/sparc64/conf/GENERIC: enable "fdc0 at ebus?" and drop the EXPERIMENTAL tag.
share/man/man4/man4.sparc64/fdc.4: describe the fdthree controller and manual eject, remove the BUGS section.
Testing, on my Ultra 5 at 400 MHz running netbsd-11:
- whole 1.44 MB disk read at 30.8 KB/s (15.4 KB/s before the one-cylinder transfer size), data identical to the image
- random 1.44 MB image written and read back, cmp matches
- request sizes from 512 bytes to 64 KB
- a 5-sector write across a cylinder boundary that touched only those sectors
- fdformat, newfs_msdos, file copy, unmount and remount
- FFS filled to the end and checked afterwards with fsck_ffs -f, which came back clean
- the block device /dev/fd0a giving the same data as the raw device
- no disk at all, disk removed mid-read, disk removed mid-write, write-protected disk, disk changed between reads: EIO or EROFS, no panics, next request works
- eject fd0 correctly refused with EINVAL (the PROM marks the drive "manual")
- two concurrent readers, audio playback and a 1.3 GB hard disk read alongside a floppy read: identical results at full speed
- a cold boot
- the PROM's "test floppy" passes after a halt, whether or not the drive was used
Not tested: an Ultra 10 or any other fdthree machine, SBus machines (no hardware here), 720 KB media, a DEBUG/LOCKDEBUG kernel, -current.
Known to be missing: the DMA buffer is not freed if fdcattach() itself fails (marked XXX, the same as the existing interrupt handler), and Linux's workaround for the AX/AXi floppy connector is not included.
Two things I noticed while testing, which this diff does not touch: after a fast disk swap the first read can time out once (3 s) because the drive has not come up to speed yet, and fdgetdisklabel() invents a label with no "a" partition, so plain "newfs /dev/rfd0a" fails.
Home |
Main Index |
Thread Index |
Old Index