NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/61012: spi(4): add ca_rescan so children attach on runtime modload / drvctl -r



The following reply was made to PR kern/61012; it has been noted by GNATS.

From: Brad Spencer <brad%anduin.eldar.org@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: kern-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: kern/61012: spi(4): add ca_rescan so children attach on runtime
 modload / drvctl -r
Date: Sun, 15 Nov 2026 14:24:19 -0500

 "thorsten.grassmann%zae-bayern.de@localhost via gnats" <gnats-admin%NetBSD.org@localhost>
 writes:
 
 >>Number:         61012
 >>Category:       kern
 >>Synopsis:       spi(4): add ca_rescan so children attach on runtime modload / drvctl -r
 >>Confidential:   no
 >>Severity:       non-critical
 >>Priority:       low
 >>Responsible:    kern-bug-people
 >>State:          open
 >>Class:          change-request
 >>Submitter-Id:   net
 >>Arrival-Date:   Sun Nov 15 17:40:00 +0000 2026
 >>Originator:     Thorsten Grassmann
 >>Release:        11.1, NetBSD-current
 >>Organization:
 > ZAE Bayern
 >>Environment:
 > NetBSD netbsdrpi 11.1 NetBSD 11.1 (GENERIC64) #4: Sun Nov 15 02:19:15 CET 2026  grass@mirrorbox:/tmp/nbsd/obj/sys/arch/evbarm/compile/GENERIC64 evbarm
 >>Description:
 > I wrote a small SNES-gamepad driver as an LKM that attaches with "snespad* at spi? slave N" (for a Raspberry Pi 3 via the SPI0 header; the driver is pure spi(4) and machine-independent; https://github.com/thgrass/NetBSD_snespad_spi ).
 > On NetBSD 11.1 evbarm GENERIC64 with bcmspi(4)/spi(4):
 >
 >     # modload snespad
 >     modload: rc=0            // module loads fine
 >     // dmesg: nothing. no snespad0 at spi0, no /dev/snespad*.
 >     # drvctl -r -a spi spi0   -> also nothing.
 >
 > Tracing config_cfdata_attach() -> rescan_with_cfdata() showed the rescan is dispatched to ca_rescan of each attached bus. But spi's cfattach is ca_rescan = NULL (CFATTACH_DECL_NEW).
 > The same driver works when built into the kernel directly.
 >
 > Is this by design? As SPI devices usually are "built-in" and there is rarely the need for loadable modules in production.
 > Adding proposed patch (see below) would at least make SPI driver development more convenient...
 >>How-To-Repeat:
 > On any system with an spi(4) bus attached:
 >
 >     # drvctl -l                  // shows spi0
 >     # drvctl -r -a spi spi0
 >     drvctl: DRVRESCANBUS: No such device or address
 >>Fix:
 > Patch spi-rescan-trunk.patch:
 > adds spi_rescan() to spi(4) and registers it as ca_rescan via CFATTACH_DECL2_NEW. (Boot-time attach is unchanged).
 
 [snip]
 
 [I am neither encouraging for discouraging this PRs desire mostly just
 pointing out a couple of things]
 
 Ya, modules with the SPI drivers have never really been a thing.  In
 particular, the main reason, I think, is that indirect config / probe of
 the device really doesn't work very well for them.  You mostly need to
 pin down the slave that the device is attached to in a kernel config.
 
 You should provide the ioconf fragment you used for your module.
 Usually that specifies all possible addresses that a device could be at.
 For SPI you would have no way to know how many you are dealing with.
 (Yes, for the RPI it would be up to 2, but any platform with USB can use
 umcpmio(4) to get SPI and then you have up to 8 possible SPI slaves.
 Think of a AMD64 Virtualbox VM that has a ucmcpmio(4) device attached to
 it.  The virtual VM gets a real SPI port.).
 
 For platforms with FDT this probably all works or seems to because the
 FDT would lock down the slave address along with the kernel config, but
 non-FDT platforms with SPI would have trouble with ghost devices on
 rescan.
 
 You can also get ghost devices with I2C and 1-Wire (onewire(4)) on
 indirect probes, unless a particular device driver has taken steps in
 its match function to see if there really is something present at a
 particular address.  For I2C that is quite possible (probably), for
 1-Wire, not so much.
 
 
 
 
 
 
 -- 
 Brad Spencer - brad%anduin.eldar.org@localhost
 



Home | Main Index | Thread Index | Old Index