4

I'm getting started in Linux Device Driver development for a PCI device connected via a laptop's PCIe expansion slot.

On boot, everything works beautifully. However, I'm trying to get basic Hotplug support online. When I eject the card, I can see (in dmesg) that the proper remove stuff is called. However, when the card is re-inserted, nothing happens. If I manually remove the module, and then insert the card (or insert the card after boot), then I can see the module's init is called, but not probe. Also, the device doesn't appear in lspci output.

However, if I echo 1 > /sys/bus/pci/rescan then it appears in lspci output, but the module fails to load with errors (pci_enable_device failed with code -22).

Any ideas where to even start diagnosing this? The failure to exec .probe is what's really puzzling me.

I should mention that this is an FPGA board connected here, so it's possible there's something wrong in the Device itself, but i would still expect probe to run and then fail with a weird error later.

Yeraze
  • 3,269
  • 4
  • 28
  • 42
  • You need to scrutinize the exit & remove code to ensure that every resource and initialization performed during init & probe is undone (in reverse order). You may have to sprinkle the code with printk()s to find the source of the -22 error code (EINVAL). *"The failure to exec .probe is what's really puzzling me."* -- That probably means that the module's init routine returned an error. – sawdust May 18 '14 at 21:28
  • Init is running successfully, I've tested it.. But .probe never gets called. – Yeraze May 19 '14 at 00:51
  • I'm looking around and just stumbled upon [pcihp_skeleton](https://svn.dd-wrt.com/browser/src/linux/universal/linux-3.4/drivers/pci/hotplug/pcihp_skeleton.c?rev=19285). Is the hotplug interface totally different from the regular PCI interface? I thought the newer kernels merged the two. – Yeraze May 19 '14 at 00:56
  • If enable_device fails, then the probe is not going to run. Devices are being enabled by the bus interface, before the driver is activated. – oakad May 30 '14 at 03:19
  • AGain, not the question... I can't even get to the point of getting enable_device called, as Probe is not running (And enable_device is in the Probe function) – Yeraze May 30 '14 at 13:03

1 Answers1

3

If the device doesn't show in lspci there no chance that .probe function of your driver will be called because it does get listed in the kernel device tree.

When you do pci bus rescan and it is seen by lspci, that doesn't mean that the device is accessible. In fact, try to do an lspci -vv -s BB:DD (where BB:DD is the device bus id and device id as reported by lspci. I expect that you get 0xFF for many register (in particular the BARs). I guess this would be the reason why pci_enable_device fails.

I have a similar problem with an FPGA device when I reload the bitfile while running. One possible cause to your problem is that the configuration space registers are reset. You could try to save the configuration space before you remove the board (as root):

cp /sys/bus/pci/devices/0000\:BB\:DD.0/config ~/config.save

then to restore it:

cp ~/config.save /sys/bus/pci/devices/0000\:BB\:DD.0/config

I've had this method work on some hardware but not on other (newer hardware).

Claudio
  • 927
  • 7
  • 15